From d9d9b926c1be1b5317793af070c66e53298e0963 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Fri, 23 Aug 2013 10:05:41 +0200 Subject: [PATCH] Force one player name case. Prevents bugs with offline mode servers and case sensitive file systems. --- src/com/massivecraft/mcore/ConfServer.java | 1 + .../massivecraft/mcore/InternalListener.java | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/com/massivecraft/mcore/ConfServer.java b/src/com/massivecraft/mcore/ConfServer.java index a3056119..fe8299d5 100644 --- a/src/com/massivecraft/mcore/ConfServer.java +++ b/src/com/massivecraft/mcore/ConfServer.java @@ -32,6 +32,7 @@ public class ConfServer extends SimpleConfig public static String dburi = "default"; public static boolean usingPlayerConnectionWrap = true; + public static boolean forceOnePlayerNameCase = true; public static List aliasesOuterMCore = MUtil.list("mcore"); public static List aliasesOuterMCoreUsys = MUtil.list("usys"); diff --git a/src/com/massivecraft/mcore/InternalListener.java b/src/com/massivecraft/mcore/InternalListener.java index 11dd1ce0..beee2edc 100644 --- a/src/com/massivecraft/mcore/InternalListener.java +++ b/src/com/massivecraft/mcore/InternalListener.java @@ -31,8 +31,10 @@ import com.massivecraft.mcore.event.MCoreSenderUnregisterEvent; import com.massivecraft.mcore.mixin.Mixin; import com.massivecraft.mcore.store.Coll; import com.massivecraft.mcore.store.SenderColl; +import com.massivecraft.mcore.util.MUtil; import com.massivecraft.mcore.util.SenderUtil; import com.massivecraft.mcore.util.SmokeUtil; +import com.massivecraft.mcore.util.Txt; import com.massivecraft.mcore.wrap.PlayerConnectionWrapMCore; public class InternalListener implements Listener @@ -54,6 +56,44 @@ public class InternalListener implements Listener Bukkit.getPluginManager().registerEvents(this, MCore.get()); } + // -------------------------------------------- // + // FORCE ONE PLAYER NAME CASE + // -------------------------------------------- // + // This is used with offline servers to prevent bugs on case sensitive file systems. + + @EventHandler(priority = EventPriority.LOWEST) + public void forceOnePlayerNameCase(PlayerLoginEvent event) + { + // If we are enforcing one player name case ... + if (!ConfServer.forceOnePlayerNameCase) return; + + // ... and the server is running in offline mode ... + if (Bukkit.getOnlineMode()) return; + + // ... prepare vars ... + Player player = event.getPlayer(); + String playerName = player.getName(); + + // ... is the player already online? ... + for (Player onlinePlayer: Bukkit.getOnlinePlayers()) + { + if (!playerName.equalsIgnoreCase(onlinePlayer.getName())) continue; + event.setResult(Result.KICK_OTHER); + event.setKickMessage(Txt.parse("The player %s is already online.", onlinePlayer.getName())); + return; + } + + // ... is the first found file name different? + for (String pdname : MUtil.getPlayerDirectoryNames()) + { + if (!playerName.equalsIgnoreCase(pdname)) continue; + if (playerName.equals(pdname)) break; + event.setResult(Result.KICK_OTHER); + event.setKickMessage(Txt.parse("Invalid uppercase and lowercase letters in name.\nPlease spell this name like \"%s\".", pdname)); + } + + } + // -------------------------------------------- // // PLAYER CONNECTION WRAP INJECTION // -------------------------------------------- //