Cleanup login handling & reduce the amount of unnecessary logging output on startup

This commit is contained in:
Luck
2017-05-18 22:30:01 +01:00
Unverified
parent cc907b6530
commit 139dd5302b
8 changed files with 66 additions and 65 deletions
@@ -201,14 +201,16 @@ public class LPSpongePlugin implements LuckPermsPlugin {
if (messagingType.equals("none") && getConfiguration().get(ConfigKeys.REDIS_ENABLED)) {
messagingType = "redis";
}
if (!messagingType.equals("none")) {
getLog().info("Loading messaging service... [" + messagingType.toUpperCase() + "]");
}
if (messagingType.equals("redis")) {
getLog().info("Loading redis...");
if (getConfiguration().get(ConfigKeys.REDIS_ENABLED)) {
RedisMessaging redis = new RedisMessaging(this);
try {
redis.init(getConfiguration().get(ConfigKeys.REDIS_ADDRESS), getConfiguration().get(ConfigKeys.REDIS_PASSWORD));
getLog().info("Loaded redis successfully...");
messagingService = redis;
} catch (Exception e) {
getLog().warn("Couldn't load redis...");
@@ -218,7 +220,6 @@ public class LPSpongePlugin implements LuckPermsPlugin {
getLog().warn("Messaging Service was set to redis, but redis is not enabled!");
}
} else if (messagingType.equals("bungee")) {
getLog().info("Loading bungee messaging service...");
BungeeMessagingService bungeeMessaging = new BungeeMessagingService(this);
bungeeMessaging.init();
messagingService = bungeeMessaging;
@@ -243,7 +244,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
localeManager = new SimpleLocaleManager();
File locale = new File(getDataDirectory(), "lang.yml");
if (locale.exists()) {
getLog().info("Found locale file. Attempting to load from it.");
getLog().info("Found lang.yml - loading messages...");
try {
localeManager.loadFromFile(locale);
} catch (Exception e) {
@@ -252,7 +253,6 @@ public class LPSpongePlugin implements LuckPermsPlugin {
}
// register commands
getLog().info("Registering commands...");
CommandManager cmdService = game.getCommandManager();
commandManager = new SpongeCommand(this);
cmdService.register(this, commandManager, "luckperms", "lp", "perm", "perms", "permission", "permissions");
@@ -288,7 +288,6 @@ public class LPSpongePlugin implements LuckPermsPlugin {
}
// register with the LP API
getLog().info("Registering API...");
apiProvider = new ApiProvider(this);
ApiHandler.registerProvider(apiProvider);
game.getServiceManager().setProvider(this, LuckPermsApi.class, apiProvider);
@@ -302,6 +301,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
scheduler.asyncLater(() -> updateTaskBuffer.request(), 40L);
// run an update instantly.
getLog().info("Performing initial data load...");
updateTaskBuffer.requestDirectly();
// register tasks
@@ -310,7 +310,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
scheduler.asyncRepeating(new ServiceCacheHousekeepingTask(service), 2400L);
// scheduler.asyncRepeating(() -> userManager.performCleanup(), 2400L);
getLog().info("Successfully loaded.");
getLog().info("Successfully enabled.");
}
@Listener(order = Order.LATE)
@@ -325,7 +325,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
@Listener
public void onDisable(GameStoppingServerEvent event) {
getLog().info("Closing datastore...");
getLog().info("Closing storage...");
storage.shutdown();
if (fileWatcher != null) {
@@ -337,9 +337,9 @@ public class LPSpongePlugin implements LuckPermsPlugin {
messagingService.close();
}
getLog().info("Unregistering API...");
ApiHandler.unregisterProvider();
getLog().info("Shutting down internal scheduler...");
scheduler.shutdown();
}
@@ -75,7 +75,6 @@ public class SpongeListener {
/* the player was denied entry to the server before this priority.
log this, so we can handle appropriately later. */
if (e.isCancelled()) {
plugin.getLog().warn("Connection from " + p.getUniqueId() + " was already denied. No permissions data will be loaded.");
deniedAsyncLogin.add(p.getUniqueId());
return;
}
@@ -90,9 +89,9 @@ public class SpongeListener {
deniedAsyncLogin.add(p.getUniqueId());
// actually deny the connection.
plugin.getLog().warn("Permissions storage is not loaded yet. Denying connection from: " + p.getUniqueId() + " - " + p.getName());
plugin.getLog().warn("Permissions storage is not loaded. Denying connection from: " + p.getUniqueId() + " - " + p.getName());
e.setCancelled(true);
e.setMessageCancelled(true);
e.setMessageCancelled(false);
//noinspection deprecation
e.setMessage(TextSerializers.LEGACY_FORMATTING_CODE.deserialize(Message.LOADING_ERROR.asString(plugin.getLocaleManager())));
return;
@@ -112,8 +111,10 @@ public class SpongeListener {
} catch (Exception ex) {
ex.printStackTrace();
deniedAsyncLogin.add(p.getUniqueId());
e.setCancelled(true);
e.setMessageCancelled(true);
e.setMessageCancelled(false);
//noinspection deprecation
e.setMessage(TextSerializers.LEGACY_FORMATTING_CODE.deserialize(Message.LOADING_ERROR.asString(plugin.getLocaleManager())));
}
@@ -149,7 +150,6 @@ public class SpongeListener {
/* the player was denied entry to the server before this priority.
log this, so we can handle appropriately later. */
if (e.isCancelled()) {
plugin.getLog().warn("Login from " + player.getUniqueId() + " was denied before an attachment could be injected.");
deniedLogin.add(player.getUniqueId());
return;
}
@@ -162,7 +162,7 @@ public class SpongeListener {
plugin.getLog().warn("User " + player.getUniqueId() + " - " + player.getName() + " doesn't have data pre-loaded. - denying login.");
e.setCancelled(true);
e.setMessageCancelled(true);
e.setMessageCancelled(false);
//noinspection deprecation
e.setMessage(TextSerializers.LEGACY_FORMATTING_CODE.deserialize(Message.LOADING_ERROR.asString(plugin.getLocaleManager())));
return;
@@ -192,6 +192,22 @@ public class SpongeListener {
}
}
@Listener(order = Order.BEFORE_POST)
@IsCancelled(Tristate.UNDEFINED)
public void onClientLoginMonitor(ClientConnectionEvent.Login e) {
/* Listen to see if the event was cancelled after we initially handled the login
If the connection was cancelled here, we need to do something to clean up the data that was loaded. */
// Check to see if this connection was denied at LOW. Even if it was denied at LOW, their data will still be present.
if (deniedLogin.remove(e.getProfile().getUniqueId())) {
// This is a problem, as they were denied at low priority, but are now being allowed.
if (!e.isCancelled()) {
plugin.getLog().severe("Player connection was re-allowed for " + e.getProfile().getUniqueId());
e.setCancelled(true);
}
}
}
@Listener(order = Order.EARLY)
public void onClientJoin(ClientConnectionEvent.Join e) {
// Refresh permissions again