From bea43b3140d37b7138ecf7970115471fd2ef477c Mon Sep 17 00:00:00 2001 From: games647 Date: Mon, 21 Mar 2016 14:40:37 +0100 Subject: [PATCH] Fix possible race condition on login processing (Fixes Xephi/AuthMeReloaded#619) --- .../authme/listener/AuthMeInventoryPacketAdapter.java | 8 ++++---- .../fr/xephi/authme/process/login/AsynchronousLogin.java | 9 ++++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/fr/xephi/authme/listener/AuthMeInventoryPacketAdapter.java b/src/main/java/fr/xephi/authme/listener/AuthMeInventoryPacketAdapter.java index e64d3dddc..62dcf7e5b 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMeInventoryPacketAdapter.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMeInventoryPacketAdapter.java @@ -103,12 +103,12 @@ public class AuthMeInventoryPacketAdapter extends PacketAdapter { ItemStack[] completeInventory = new ItemStack[inventorySize]; - System.arraycopy(playerCrafting, 0, completeInventory, 0, playerCrafting.length); - System.arraycopy(armorContents, 0, completeInventory, CRAFTING_SIZE, armorContents.length); + System.arraycopy(playerCrafting, 0, completeInventory, 0, CRAFTING_SIZE); + System.arraycopy(armorContents, 0, completeInventory, CRAFTING_SIZE, ARMOR_SIZE); // storedInventory and hotbar - System.arraycopy(storedInventory, 0, completeInventory, CRAFTING_SIZE + ARMOR_SIZE, storedInventory.length); - System.arraycopy(hotbar, 0, completeInventory, CRAFTING_SIZE + ARMOR_SIZE + MAIN_SIZE, hotbar.length); + System.arraycopy(storedInventory, 0, completeInventory, CRAFTING_SIZE + ARMOR_SIZE, MAIN_SIZE); + System.arraycopy(hotbar, 0, completeInventory, CRAFTING_SIZE + ARMOR_SIZE + MAIN_SIZE, HOTBAR_SIZE); if (offHandSupported) { completeInventory[OFF_HAND_POSITION] = player.getInventory().getItemInOffHand(); diff --git a/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java b/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java index 45bc3fe0b..bb039bf10 100644 --- a/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java +++ b/src/main/java/fr/xephi/authme/process/login/AsynchronousLogin.java @@ -5,6 +5,7 @@ import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.limbo.LimboCache; +import fr.xephi.authme.cache.limbo.LimboPlayer; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.events.AuthMeAsyncPreLoginEvent; import fr.xephi.authme.output.MessageKey; @@ -88,14 +89,16 @@ public class AsynchronousLogin implements Process { PlayerAuth pAuth = database.getAuth(name); if (pAuth == null) { service.send(player, MessageKey.USER_NOT_REGISTERED); - if (LimboCache.getInstance().hasLimboPlayer(name)) { - LimboCache.getInstance().getLimboPlayer(name).getMessageTask().cancel(); + + LimboPlayer limboPlayer = LimboCache.getInstance().getLimboPlayer(name); + if (limboPlayer != null) { + limboPlayer.getMessageTask().cancel(); String[] msg = service.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION) ? service.retrieveMessage(MessageKey.REGISTER_EMAIL_MESSAGE) : service.retrieveMessage(MessageKey.REGISTER_MESSAGE); BukkitTask messageTask = service.runTask( new MessageTask(plugin, name, msg, service.getProperty(RegistrationSettings.MESSAGE_INTERVAL))); - LimboCache.getInstance().getLimboPlayer(name).setMessageTask(messageTask); + limboPlayer.setMessageTask(messageTask); } return null; }