use of org.spongepowered.api.profile.GameProfileCache in project LanternServer by LanternPowered.
the class LanternServer method shutdown.
@SuppressWarnings("deprecation")
@Override
public void shutdown(Text kickMessage) {
checkNotNull(kickMessage, "kickMessage");
if (this.shuttingDown) {
return;
}
this.shuttingDown = true;
// Stop the console
this.consoleManager.shutdown();
final Cause gameCause = Cause.of(EventContext.empty(), this.game);
this.game.postGameStateChange(SpongeEventFactory.createGameStoppingServerEvent(gameCause));
// Debug a message
this.logger.info("Stopping the server... ({})", LanternTexts.toLegacy(kickMessage));
// Kick all the online players
getOnlinePlayers().forEach(player -> ((LanternPlayer) player).getConnection().disconnect(kickMessage));
// Stop the network servers - starts the shutdown process
// It may take a second or two for Netty to totally clean up
this.networkManager.shutdown();
if (this.queryServer != null) {
this.queryServer.shutdown();
}
if (this.rconServer != null) {
this.rconServer.shutdown();
}
// Stop the world manager
this.worldManager.shutdown();
// Shutdown the executor
this.executor.shutdown();
// Stop the async scheduler
this.game.getScheduler().shutdownAsyncScheduler(10, TimeUnit.SECONDS);
final Collection<ProviderRegistration<?>> serviceRegistrations;
try {
final ServiceManager serviceManager = this.game.getServiceManager();
checkState(serviceManager instanceof SimpleServiceManager || serviceManager instanceof LanternServiceManager);
final Field field = (serviceManager instanceof SimpleServiceManager ? SimpleServiceManager.class : LanternServiceManager.class).getDeclaredField("providers");
field.setAccessible(true);
// noinspection unchecked
final Map<Class<?>, ProviderRegistration<?>> map = (Map<Class<?>, ProviderRegistration<?>>) field.get(serviceManager);
serviceRegistrations = map.values();
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new IllegalStateException(e);
}
// Close all the services if possible
serviceRegistrations.forEach(provider -> {
final Object service = provider.getProvider();
if (service instanceof CloseableService) {
try {
((CloseableService) service).close();
} catch (Exception e) {
this.logger.error("A error occurred while closing the {}.", provider.getService().getName(), e);
}
}
});
// Shutdown the game profile manager
this.game.getGameProfileManager().getDefaultCache().save();
final GameProfileCache cache = this.game.getGameProfileManager().getCache();
if (cache instanceof CloseableService) {
try {
((CloseableService) cache).close();
} catch (Exception e) {
this.logger.error("A error occurred while closing the GameProfileCache.", e);
}
}
try {
this.game.getOpsConfig().save();
} catch (IOException e) {
this.logger.error("A error occurred while saving the ops config.", e);
}
this.game.postGameStateChange(SpongeEventFactory.createGameStoppedServerEvent(gameCause));
this.game.postGameStateChange(SpongeEventFactory.createGameStoppingEvent(gameCause));
this.game.postGameStateChange(SpongeEventFactory.createGameStoppedEvent(gameCause));
// Wait for a while and terminate any rogue threads
new ShutdownMonitorThread().start();
}
use of org.spongepowered.api.profile.GameProfileCache in project LanternServer by LanternPowered.
the class HandlerLoginFinish method handle.
@Override
public void handle(NetworkContext context, MessageLoginInFinish message) {
final LanternGameProfile gameProfile = message.getGameProfile();
final NetworkSession session = context.getSession();
int compressionThreshold = Lantern.getGame().getGlobalConfig().getNetworkCompressionThreshold();
if (compressionThreshold != -1) {
session.sendWithFuture(new MessageLoginOutSetCompression(compressionThreshold)).addListener(future -> context.getChannel().pipeline().replace(NetworkSession.COMPRESSION, NetworkSession.COMPRESSION, new MessageCompressionHandler(compressionThreshold)));
} else {
// Remove the compression handler placeholder
context.getChannel().pipeline().remove(NetworkSession.COMPRESSION);
}
final GameProfileCache gameProfileCache = Lantern.getGame().getGameProfileManager().getCache();
// Store the old profile temporarily
gameProfileCache.getById(gameProfile.getUniqueId()).ifPresent(profile -> context.getChannel().attr(NetworkSession.PREVIOUS_GAME_PROFILE).set(profile));
// Cache the new profile
gameProfileCache.add(gameProfile, true, (Instant) null);
session.sendWithFuture(new MessageLoginOutSuccess(gameProfile.getUniqueId(), gameProfile.getName().get())).addListener(future -> {
session.setGameProfile(gameProfile);
session.setProtocolState(ProtocolState.FORGE_HANDSHAKE);
session.messageReceived(new MessageForgeHandshakeInStart());
});
}
Aggregations