use of org.lanternpowered.server.game.version.LanternMinecraftVersion in project LanternServer by LanternPowered.
the class HandlerStatusRequest method handle.
@Override
public void handle(NetworkContext context, MessageStatusInRequest message) {
final NetworkSession session = context.getSession();
final LanternServer server = session.getServer();
final Gson gson = new Gson();
final Text description = server.getMotd();
final InetSocketAddress address = session.getAddress();
final InetSocketAddress virtualAddress = session.getVirtualHost();
final int protocol = session.getProtocolVersion();
final MinecraftVersion clientVersion = Lantern.getGame().getMinecraftVersionCache().getVersionOrUnknown(protocol, false);
if (clientVersion == LanternMinecraftVersion.UNKNOWN) {
Lantern.getLogger().debug("Client with unknown protocol version {} pinged the server.", protocol);
}
final LanternStatusClient client = new LanternStatusClient(address, clientVersion, virtualAddress);
final ClientPingServerEvent.Response.Players players = LanternStatusHelper.createPlayers(server);
final LanternStatusResponse response = new LanternStatusResponse(Lantern.getGame().getPlatform().getMinecraftVersion(), server.getFavicon(), description, players);
final Cause cause = Cause.of(EventContext.empty(), new WrappedRemoteConnection(session));
final ClientPingServerEvent event = SpongeEventFactory.createClientPingServerEvent(cause, client, response);
Sponge.getEventManager().post(event);
// Cancelled, we are done here
if (event.isCancelled()) {
context.getChannel().close();
return;
}
final JsonObject rootObject = new JsonObject();
final JsonObject versionObject = new JsonObject();
checkState(response.getVersion() instanceof LanternMinecraftVersion);
final LanternMinecraftVersion serverVersion = (LanternMinecraftVersion) response.getVersion();
versionObject.addProperty("name", serverVersion.getName());
versionObject.addProperty("protocol", serverVersion.getProtocol());
if (response.getPlayers().isPresent()) {
final JsonObject playersObject = new JsonObject();
playersObject.addProperty("max", players.getMax());
playersObject.addProperty("online", players.getOnline());
List<GameProfile> profiles = players.getProfiles();
if (!profiles.isEmpty()) {
final JsonArray array = new JsonArray();
for (GameProfile profile : profiles) {
Optional<String> optName = profile.getName();
if (!optName.isPresent()) {
continue;
}
final JsonObject profileObject = new JsonObject();
profileObject.addProperty("name", optName.get());
profileObject.addProperty("id", profile.getUniqueId().toString());
array.add(profileObject);
}
playersObject.add("sample", array);
}
rootObject.add("players", playersObject);
}
rootObject.add("version", versionObject);
rootObject.add("description", ((LanternJsonTextSerializer) TextSerializers.JSON).getGson().toJsonTree(response.getDescription()));
response.getFavicon().ifPresent(icon -> rootObject.addProperty("favicon", ((LanternFavicon) icon).getEncoded()));
final JsonObject fmlObject = new JsonObject();
// Trick the client that the server is fml, we support fml channels anyway
fmlObject.addProperty("type", "FML");
// The client shouldn't know the plugins (mods) list
fmlObject.add("modList", new JsonArray());
// Add the fml info
rootObject.add("modinfo", fmlObject);
session.send(new MessageStatusOutResponse(gson.toJson(rootObject)));
}
use of org.lanternpowered.server.game.version.LanternMinecraftVersion in project LanternServer by LanternPowered.
the class LanternGame method initialize.
public void initialize() throws IOException {
final LanternMinecraftVersion versionCacheEntry = this.minecraftVersionCache.getVersionOrUnknown(Protocol.CURRENT_VERSION, false);
if (!LanternMinecraftVersion.CURRENT.equals(versionCacheEntry)) {
throw new RuntimeException("The current version and version in the cache don't match: " + LanternMinecraftVersion.CURRENT + " != " + versionCacheEntry);
}
// Load the plugin instances
try {
// By default, use the '--scanClasspath <true|false>' option, if it can't
// be found, fall back to a environment based decision
Boolean scanClasspath = this.scanClasspath;
if (scanClasspath == null) {
scanClasspath = Environment.get() == Environment.DEVELOPMENT;
}
this.pluginManager.loadPlugins(scanClasspath);
} catch (IOException e) {
throw new RuntimeException("An error occurred while loading the plugins.", e);
}
this.gameRegistry.registerDefaults();
this.gameRegistry.earlyRegistry();
// Load the global configuration
this.globalConfig.load();
// Save missing settings
this.globalConfig.save();
// They should not be replaced by now
this.whitelistService.extended(WhitelistConfig.class).get().load();
this.banService.extended(BanConfig.class).get().load();
// Create the event manager instance
this.eventManager.registerListeners(this.implContainer, LanternServiceListeners.getInstance());
this.pluginManager.registerPluginInstances();
// Call pre registry phase.
this.gameRegistry.preRegistry();
// Register temporarily a empty rcon service
registerService(RconService.class, new EmptyRconService(this.globalConfig.getRconPassword()));
// Create the cause to post events...
final CauseStack causeStack = CauseStack.current();
causeStack.pushCause(this);
final Cause gameCause = causeStack.getCurrentCause();
// Call the construction events
postGameStateChange(SpongeEventFactory.createGameConstructionEvent(gameCause));
// Call pre init phase for registry
this.gameRegistry.preInit();
LanternServiceListeners.getInstance().registerServiceCallback(PermissionService.class, input -> {
this.server.getConsole().getContainingCollection();
input.registerContextCalculator(new LanternContextCalculator());
});
// Pre-init phase
postGameStateChange(SpongeEventFactory.createGamePreInitializationEvent(gameCause));
// Call init phase for registry
this.gameRegistry.init();
final PermissionService permissionService = this.permissionService.get();
if (permissionService instanceof LanternPermissionService) {
final LanternPermissionService service = (LanternPermissionService) permissionService;
service.getGroupForOpLevel(Permissions.SELECTOR_LEVEL).getSubjectData().setPermission(SubjectData.GLOBAL_CONTEXT, Permissions.SELECTOR_PERMISSION, Tristate.TRUE);
service.getGroupForOpLevel(Permissions.COMMAND_BLOCK_LEVEL).getSubjectData().setPermission(SubjectData.GLOBAL_CONTEXT, Permissions.COMMAND_BLOCK_PERMISSION, Tristate.TRUE);
service.getGroupForOpLevel(Permissions.Login.BYPASS_PLAYER_LIMIT_LEVEL).getSubjectData().setPermission(SubjectData.GLOBAL_CONTEXT, Permissions.Login.BYPASS_PLAYER_LIMIT_PERMISSION, Tristate.FALSE);
service.getGroupForOpLevel(Permissions.Login.BYPASS_WHITELIST_LEVEL).getSubjectData().setPermission(SubjectData.GLOBAL_CONTEXT, Permissions.Login.BYPASS_WHITELIST_PERMISSION, Tristate.TRUE);
service.getGroupForOpLevel(Permissions.Chat.FORMAT_URLS_LEVEL).getSubjectData().setPermission(SubjectData.GLOBAL_CONTEXT, Permissions.Chat.FORMAT_URLS, Tristate.TRUE);
}
// Load the default commands
this.injector.getInstance(DefaultCommandsCollection.class).load();
// Init phase
postGameStateChange(SpongeEventFactory.createGameInitializationEvent(gameCause));
// Call post init phase for registry
this.gameRegistry.postInit();
// Post-init phase
postGameStateChange(SpongeEventFactory.createGamePostInitializationEvent(gameCause));
// Load-complete phase
postGameStateChange(SpongeEventFactory.createGameLoadCompleteEvent(gameCause));
// Pop off the game instance
causeStack.popCause();
}
Aggregations