diff --git a/pom.xml b/pom.xml index f45129894..b0aa34b6f 100644 --- a/pom.xml +++ b/pom.xml @@ -24,12 +24,12 @@ - 3.2.1-DEV-2 + 3.3.1-DEV-1 org.bukkit craftbukkit - 1.7.2-R0.2 + 1.7.2-R0.3-SNAPSHOT net.milkbowl.vault diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index 2a0fb2f8c..9f1bdb686 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -15,26 +15,22 @@ import java.util.Random; import java.util.logging.Logger; import java.util.zip.GZIPInputStream; -import com.earth2me.essentials.Essentials; - -import org.apache.logging.log4j.LogManager; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.PluginManager; -import org.bukkit.plugin.RegisteredServiceProvider; -import org.bukkit.plugin.java.JavaPlugin; - - import me.muizers.Notifications.Notifications; import net.citizensnpcs.Citizens; import net.milkbowl.vault.permission.Permission; +import org.apache.logging.log4j.LogManager; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.World; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.RegisteredServiceProvider; +import org.bukkit.plugin.java.JavaPlugin; +import com.earth2me.essentials.Essentials; import com.maxmind.geoip.LookupService; import com.onarandombox.MultiverseCore.MultiverseCore; @@ -63,6 +59,7 @@ import fr.xephi.authme.listener.AuthMeBungeeCordListener; import fr.xephi.authme.listener.AuthMeChestShopListener; import fr.xephi.authme.listener.AuthMeEntityListener; import fr.xephi.authme.listener.AuthMePlayerListener; +import fr.xephi.authme.listener.AuthMeServerListener; import fr.xephi.authme.listener.AuthMeSpoutListener; import fr.xephi.authme.plugin.manager.BungeeCordMessage; import fr.xephi.authme.plugin.manager.CitizensCommunicator; @@ -85,8 +82,8 @@ public class AuthMe extends JavaPlugin { private PlayersLogs pllog; public static Server server; public static Logger authmeLogger = Logger.getLogger("AuthMe"); - public static Plugin authme; - public static Permission permission; + public static AuthMe authme; + public Permission permission; private static AuthMe instance; private Utils utils = Utils.getInstance(); private JavaPlugin plugin; @@ -149,10 +146,15 @@ public class AuthMe extends JavaPlugin { Bukkit.getLogger().setFilter(new ConsoleFilter()); Logger.getLogger("Minecraft").setFilter(new ConsoleFilter()); authmeLogger.setFilter(new ConsoleFilter()); - // Set Log4J Filter - org.apache.logging.log4j.core.Logger coreLogger = (org.apache.logging.log4j.core.Logger) LogManager.getRootLogger(); - coreLogger.addFilter(new Log4JFilter()); + try { + Class.forName("org.apache.logging.log4j.core.Filter"); + setLog4JFilter(); + } catch (ClassNotFoundException e) { + ConsoleLogger.info("You're using Minecraft 1.6.x or older, Log4J support is disabled"); + } catch (NoClassDefFoundError e) { + ConsoleLogger.info("You're using Minecraft 1.6.x or older, Log4J support is disabled"); + } } //Load MailApi @@ -271,11 +273,12 @@ public class AuthMe extends JavaPlugin { Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); Bukkit.getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new BungeeCordMessage(this)); try { - if (Class.forName("net.md_5.bungee.api.event.ChatEvent") != null) + if (Class.forName("net.md_5.bungee.api.event.ChatEvent") != null) { pm.registerEvents(new AuthMeBungeeCordListener(database, this), this); + ConsoleLogger.info("Successfully hook with BungeeCord!"); + } } catch (ClassNotFoundException e) { } - ConsoleLogger.info("Successfully hook with BungeeCord!"); } if (pm.isPluginEnabled("Spout")) { pm.registerEvents(new AuthMeSpoutListener(database), this); @@ -284,23 +287,14 @@ public class AuthMe extends JavaPlugin { pm.registerEvents(new AuthMePlayerListener(this,database),this); pm.registerEvents(new AuthMeBlockListener(database, this),this); pm.registerEvents(new AuthMeEntityListener(database, this),this); + pm.registerEvents(new AuthMeServerListener(this), this); if (ChestShop != 0) { pm.registerEvents(new AuthMeChestShopListener(database, this), this); ConsoleLogger.info("Successfully hook with ChestShop!"); } //Find Permissions - if (pm.getPlugin("Vault") != null) { - RegisteredServiceProvider permissionProvider = - getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class); - if (permissionProvider != null) { - permission = permissionProvider.getProvider(); - ConsoleLogger.info("Vault plugin detected, hook with " + permission.getName() + " system"); - } - else { - ConsoleLogger.showError("Vault plugin is detected but not the permissions plugin!"); - } - } + checkVault(); this.getCommand("authme").setExecutor(new AdminCommand(this, database)); this.getCommand("register").setExecutor(new RegisterCommand(database, this)); @@ -331,23 +325,51 @@ public class AuthMe extends JavaPlugin { } } catch (NullPointerException ex) { } - if (Settings.enableProtection) - enableProtection(); + if (Settings.usePurge) autoPurge(); + // Download GeoIp.dat file + downloadGeoIp(); + // Start Email recall task if needed recallEmail(); ConsoleLogger.info("Authme " + this.getDescription().getVersion() + " enabled"); } - private void checkChestShop() { + private void setLog4JFilter() { + Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() { + @Override + public void run() { + org.apache.logging.log4j.core.Logger coreLogger = (org.apache.logging.log4j.core.Logger) LogManager.getRootLogger(); + coreLogger.addFilter(new Log4JFilter()); + } + }); + } + + public void checkVault() { + if (this.getServer().getPluginManager().getPlugin("Vault") != null && this.getServer().getPluginManager().getPlugin("Vault").isEnabled()) { + RegisteredServiceProvider permissionProvider = + getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class); + if (permissionProvider != null) { + permission = permissionProvider.getProvider(); + ConsoleLogger.info("Vault plugin detected, hook with " + permission.getName() + " system"); + } + else { + ConsoleLogger.showError("Vault plugin is detected but not the permissions plugin!"); + } + } else { + permission = null; + } + } + + public void checkChestShop() { if (!Settings.chestshop) { this.ChestShop = 0; return; } - if (this.getServer().getPluginManager().isPluginEnabled("ChestShop")) { + if (this.getServer().getPluginManager().getPlugin("ChestShop") != null && this.getServer().getPluginManager().getPlugin("ChestShop").isEnabled()) { try { String ver = com.Acrobot.ChestShop.ChestShop.getVersion(); try { @@ -369,10 +391,12 @@ public class AuthMe extends JavaPlugin { } } } catch (Exception e) {} + } else { + this.ChestShop = 0; } } - private void checkMultiverse() { + public void checkMultiverse() { if(!Settings.multiverse) { multiverse = null; return; @@ -388,10 +412,12 @@ public class AuthMe extends JavaPlugin { } catch (NoClassDefFoundError ncdfe) { multiverse = null; } + } else { + multiverse = null; } } - private void checkEssentials() { + public void checkEssentials() { if (this.getServer().getPluginManager().getPlugin("Essentials") != null && this.getServer().getPluginManager().getPlugin("Essentials").isEnabled()) { try { ess = (Essentials) this.getServer().getPluginManager().getPlugin("Essentials"); @@ -403,14 +429,18 @@ public class AuthMe extends JavaPlugin { } catch (NoClassDefFoundError ncdfe) { ess = null; } + } else { + ess = null; } if (this.getServer().getPluginManager().getPlugin("EssentialsSpawn") != null && this.getServer().getPluginManager().getPlugin("EssentialsSpawn").isEnabled()) { this.essentialsSpawn = new EssSpawn().getLocation(); ConsoleLogger.info("Hook with EssentialsSpawn plugin"); + } else { + ess = null; } } - private void checkNotifications() { + public void checkNotifications() { if (!Settings.notifications) { this.notifications = null; return; @@ -423,7 +453,7 @@ public class AuthMe extends JavaPlugin { } } - private void combatTag() { + public void combatTag() { if (this.getServer().getPluginManager().getPlugin("CombatTag") != null && this.getServer().getPluginManager().getPlugin("CombatTag").isEnabled()) { this.CombatTag = 1; } else { @@ -431,7 +461,7 @@ public class AuthMe extends JavaPlugin { } } - private void citizensVersion() { + public void citizensVersion() { if (this.getServer().getPluginManager().getPlugin("Citizens") != null && this.getServer().getPluginManager().getPlugin("Citizens").isEnabled()) { Citizens cit = (Citizens) this.getServer().getPluginManager().getPlugin("Citizens"); String ver = cit.getDescription().getVersion(); @@ -710,7 +740,7 @@ public class AuthMe extends JavaPlugin { return spawnLoc; } - private void enableProtection() { + public void downloadGeoIp() { ConsoleLogger.info(" This product includes GeoLite data created by MaxMind, available from http://www.maxmind.com"); File file = new File(getDataFolder(), "GeoIP.dat"); if (!file.exists()) { @@ -747,6 +777,17 @@ public class AuthMe extends JavaPlugin { return null; } + public String getCountryName(InetAddress ip) { + try { + if (ls == null) + ls = new LookupService(new File(getDataFolder(), "GeoIP.dat")); + String code = ls.getCountry(ip).getName(); + if (code != null && !code.isEmpty()) + return code; + } catch (Exception e) {} + return null; + } + public void switchAntiBotMod(boolean mode) { this.antibotMod = mode; Settings.switchAntiBotMod(mode); @@ -773,4 +814,17 @@ public class AuthMe extends JavaPlugin { }, 1, 1200 * Settings.delayRecall); } + public String replaceAllInfos(String message, Player player) { + message = message.replace("&", "\u00a7"); + message = message.replace("{PLAYER}", player.getName()); + message = message.replace("{ONLINE}", ""+this.getServer().getOnlinePlayers().length); + message = message.replace("{MAXPLAYERS}", ""+this.getServer().getMaxPlayers()); + message = message.replace("{IP}", player.getAddress().getAddress().getHostAddress()); + message = message.replace("{LOGINS}", ""+PlayerCache.getInstance().getLogged()); + message = message.replace("{WORLD}", player.getWorld().getName()); + message = message.replace("{SERVER}", this.getServer().getServerName()); + message = message.replace("{VERSION}", this.getServer().getBukkitVersion()); + message = message.replace("{COUNTRY}", this.getCountryName(player.getAddress().getAddress())); + return message; + } } diff --git a/src/main/java/fr/xephi/authme/ConsoleLogger.java b/src/main/java/fr/xephi/authme/ConsoleLogger.java index 41f2f61c7..48b1427bf 100644 --- a/src/main/java/fr/xephi/authme/ConsoleLogger.java +++ b/src/main/java/fr/xephi/authme/ConsoleLogger.java @@ -35,7 +35,7 @@ public class ConsoleLogger { public static void showError(String message) { if (AuthMe.getInstance().isEnabled()) { - log.severe(" ERROR: " + message); + log.warning(" ERROR: " + message); if (Settings.useLogging) { Calendar date = Calendar.getInstance(); final String actually = "[" + DateFormat.getDateInstance().format(date.getTime()) + ", " + date.get(Calendar.HOUR_OF_DAY) + ":" + date.get(Calendar.MINUTE) + ":" + date.get(Calendar.SECOND) + "] ERROR : " + message; @@ -52,8 +52,7 @@ public class ConsoleLogger { public static void writeLog(String string) { try { FileWriter fw = new FileWriter(AuthMe.getInstance().getDataFolder() + File.separator + "authme.log", true); - BufferedWriter w = null; - w = new BufferedWriter(fw); + BufferedWriter w = new BufferedWriter(fw); w.write(string); w.newLine(); w.close(); diff --git a/src/main/java/fr/xephi/authme/Log4JFilter.java b/src/main/java/fr/xephi/authme/Log4JFilter.java index c6de672e3..53a7f173d 100644 --- a/src/main/java/fr/xephi/authme/Log4JFilter.java +++ b/src/main/java/fr/xephi/authme/Log4JFilter.java @@ -1,7 +1,5 @@ package fr.xephi.authme; -import java.util.logging.LogRecord; - import org.apache.logging.log4j.Level; import org.apache.logging.log4j.Marker; import org.apache.logging.log4j.core.LogEvent; @@ -12,26 +10,10 @@ import org.apache.logging.log4j.message.Message; * * @author Xephi59 */ -public class Log4JFilter implements java.util.logging.Filter, org.apache.logging.log4j.core.Filter { +public class Log4JFilter implements org.apache.logging.log4j.core.Filter { public Log4JFilter() {} - @Override - public boolean isLoggable(LogRecord record) { - try { - if (record == null || record.getMessage() == null) return true; - String logM = record.getMessage().toLowerCase(); - if (!logM.contains("issued server command:")) return true; - if (!logM.contains("/login ") && !logM.contains("/l ") && !logM.contains("/reg ") && !logM.contains("/changepassword ") && !logM.contains("/unregister ") - && !logM.contains("/authme register ") && !logM.contains("/authme changepassword ")&& !logM.contains("/authme reg ")&& !logM.contains("/authme cp ") && !logM.contains("/register ")) return true; - String playername = record.getMessage().split(" ")[0]; - record.setMessage(playername + " issued an AuthMe command!"); - return true; - } catch (NullPointerException npe) { - return true; - } - } - @Override public Result filter(LogEvent record) { try { diff --git a/src/main/java/fr/xephi/authme/Management.java b/src/main/java/fr/xephi/authme/Management.java index e91a29d4a..aa9d8fabf 100644 --- a/src/main/java/fr/xephi/authme/Management.java +++ b/src/main/java/fr/xephi/authme/Management.java @@ -11,6 +11,7 @@ import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.plugin.PluginManager; +import fr.xephi.authme.Utils.groupType; import fr.xephi.authme.api.API; import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerCache; @@ -49,7 +50,7 @@ public class Management extends Thread { this.plugin = plugin; this.pm = plugin.getServer().getPluginManager(); } - + public void run() { } @@ -96,7 +97,9 @@ public class Management extends Thread { } if (plugin.captcha.containsKey(name) && plugin.captcha.get(name) >= Settings.maxLoginTry) { plugin.cap.put(name, rdm.nextString()); - player.sendMessage(m._("need_captcha").replace("THE_CAPTCHA", plugin.cap.get(name)).replace("", plugin.cap.get(name))); + for (String s : m._("need_captcha")) { + player.sendMessage(s.replace("THE_CAPTCHA", plugin.cap.get(name)).replace("", plugin.cap.get(name))); + } return true; } else if (plugin.captcha.containsKey(name) && plugin.captcha.get(name) >= Settings.maxLoginTry) { try { @@ -153,18 +156,6 @@ public class Management extends Thread { PlayerAuth auth = new PlayerAuth(name, hash, getIP(), new Date().getTime(), email, realName); database.updateSession(auth); - /* - * Little Work Around under Registration Group Switching for - * admins that add Registration thru a web Scripts. - */ - if (Settings.isPermissionCheckEnabled - && AuthMe.permission.playerInGroup(player, Settings.unRegisteredGroup) - && !Settings.unRegisteredGroup.isEmpty()) { - AuthMe.permission - .playerRemoveGroup(player.getWorld(), player.getName(), Settings.unRegisteredGroup); - AuthMe.permission.playerAddGroup(player.getWorld(), player.getName(), Settings.getRegisteredGroup); - } - pllog.addPlayer(player); if (Settings.useCaptcha) { @@ -209,7 +200,7 @@ public class Management extends Thread { if (AuthMePlayerListener.gameMode != null && AuthMePlayerListener.gameMode.containsKey(name)) { player.setGameMode(AuthMePlayerListener.gameMode.get(name)); } - player.kickPlayer(m._("wrong_pwd")); + player.kickPlayer(m._("wrong_pwd")[0]); } }); } else { @@ -238,18 +229,6 @@ public class Management extends Thread { PlayerAuth auth = new PlayerAuth(name, hash, getIP(), new Date().getTime(), email, realName); database.updateSession(auth); - /* - * Little Work Around under Registration Group Switching for - * admins that add Registration thru a web Scripts. - */ - if (Settings.isPermissionCheckEnabled - && AuthMe.permission.playerInGroup(player, Settings.unRegisteredGroup) - && !Settings.unRegisteredGroup.isEmpty()) { - AuthMe.permission - .playerRemoveGroup(player.getWorld(), player.getName(), Settings.unRegisteredGroup); - AuthMe.permission.playerAddGroup(player.getWorld(), player.getName(), Settings.getRegisteredGroup); - } - pllog.addPlayer(player); if (Settings.useCaptcha) { @@ -381,6 +360,23 @@ public class Management extends Thread { player.setGameMode(GameMode.SURVIVAL); } + // Teleport the player + if(Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName())) { + // If we have force the spawn location on join + teleportToSpawn(); + } else { + if (Settings.isTeleportToSpawnEnabled) { + // If and only if teleport unauthed to spawn is activate + teleportBackFromSpawn(); + } else { + if (Settings.isSaveQuitLocationEnabled && auth.getQuitLocY() != 0) { + // Teleport the player on the saved location + packQuitLocation(); + } else { + // Do not move the player from his position + } + } + } // Teleport if (Settings.isTeleportToSpawnEnabled && !Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName())) { if (Settings.isSaveQuitLocationEnabled && auth.getQuitLocY() != 0) { @@ -395,31 +391,38 @@ public class Management extends Thread { } else { teleportBackFromSpawn(); } - + // Re-Force Survival GameMode if we need due to world change specification if (Settings.isForceSurvivalModeEnabled) Utils.forceGM(player); + // Restore Permission Group + utils.setGroup(player, groupType.LOGGEDIN); + // Cleanup no longer used temporary data LimboCache.getInstance().deleteLimboPlayer(name); if (playerCache.doesCacheExist(name)) { playerCache.removeCache(name); } } - + // We can now display the join message - if (AuthMePlayerListener.joinMessage.containsKey(name) && AuthMePlayerListener.joinMessage.get(name) != null) { + if (AuthMePlayerListener.joinMessage.containsKey(name) && AuthMePlayerListener.joinMessage.get(name) != null && !AuthMePlayerListener.joinMessage.get(name).isEmpty()) { for (Player p : Bukkit.getServer().getOnlinePlayers()) { if (p.isOnline()) p.sendMessage(AuthMePlayerListener.joinMessage.get(name)); } AuthMePlayerListener.joinMessage.remove(name); } - + // The Loginevent now fires (as intended) after everything is processed Bukkit.getServer().getPluginManager().callEvent(new LoginEvent(player, true)); player.saveData(); + // Login is finish, display welcome message + for (String s : Settings.welcomeMsg) + player.sendMessage(plugin.replaceAllInfos(s, player)); + // Login is now finish , we can force all commands forceCommands(); } diff --git a/src/main/java/fr/xephi/authme/Utils.java b/src/main/java/fr/xephi/authme/Utils.java index f9ec7c191..19fbe909d 100644 --- a/src/main/java/fr/xephi/authme/Utils.java +++ b/src/main/java/fr/xephi/authme/Utils.java @@ -13,90 +13,103 @@ import org.bukkit.World; import org.bukkit.entity.Player; import fr.xephi.authme.api.API; +import fr.xephi.authme.cache.limbo.LimboCache; +import fr.xephi.authme.cache.limbo.LimboPlayer; import fr.xephi.authme.events.AuthMeTeleportEvent; import fr.xephi.authme.settings.Settings; public class Utils { private String currentGroup; private static Utils singleton; - private String unLoggedGroup = Settings.getUnloggedinGroup; int id; + public AuthMe plugin; - public void setGroup(Player player, groupType group) { - if (!player.isOnline()) - return; - if(!Settings.isPermissionCheckEnabled) - return; + public Utils(AuthMe plugin) { + this.plugin = plugin; + } - switch(group) { - case UNREGISTERED: { - currentGroup = AuthMe.permission.getPrimaryGroup(player); - AuthMe.permission.playerRemoveGroup(player, currentGroup); - AuthMe.permission.playerAddGroup(player, Settings.unRegisteredGroup); - break; - } - case REGISTERED: { - currentGroup = AuthMe.permission.getPrimaryGroup(player); - AuthMe.permission.playerRemoveGroup(player, currentGroup); - AuthMe.permission.playerAddGroup(player, Settings.getRegisteredGroup); - break; - } - } - return; - } + public void setGroup(Player player, groupType group) { + if (!player.isOnline()) + return; + if(!Settings.isPermissionCheckEnabled) + return; + if(plugin.permission == null) + return; + currentGroup = plugin.permission.getPrimaryGroup(player); + World world = null; + String name = player.getName(); + switch(group) { + case UNREGISTERED: { + plugin.permission.playerRemoveGroup(world, name, currentGroup); + plugin.permission.playerAddGroup(world, name, Settings.unRegisteredGroup); + break; + } + case REGISTERED: { + plugin.permission.playerRemoveGroup(world, name, currentGroup); + plugin.permission.playerAddGroup(world, name, Settings.getRegisteredGroup); + break; + } + case NOTLOGGEDIN: { + if(!useGroupSystem()) break; + plugin.permission.playerRemoveGroup(world, name, currentGroup); + plugin.permission.playerAddGroup(world, name, Settings.getUnloggedinGroup); + break; + } + case LOGGEDIN: { + if(!useGroupSystem()) break; + LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(player.getName().toLowerCase()); + if (limbo == null) break; + String realGroup = limbo.getGroup(); + plugin.permission.playerRemoveGroup(world, name, currentGroup); + plugin.permission.playerAddGroup(world, name, realGroup); + break; + } + } + return; + } + + public boolean addNormal(Player player, String group) { + if(!Utils.getInstance().useGroupSystem()){ + return false; + } + if(plugin.permission == null) return false; + World world = null; + if(plugin.permission.playerRemoveGroup(world,player.getName().toString(),Settings.getUnloggedinGroup) && plugin.permission.playerAddGroup(world,player.getName().toString(),group)) { + return true; + } + return false; + } - public String removeAll(Player player) { - if(!Utils.getInstance().useGroupSystem()){ - return null; - } - if( !Settings.getJoinPermissions.isEmpty() ) { - hasPermOnJoin(player); - } - this.currentGroup = AuthMe.permission.getPrimaryGroup(player.getWorld(),player.getName().toString()); - if(AuthMe.permission.playerRemoveGroup(player.getWorld(),player.getName().toString(), currentGroup) && AuthMe.permission.playerAddGroup(player.getWorld(),player.getName().toString(),this.unLoggedGroup)) { - return currentGroup; - } - return null; - } + public void hasPermOnJoin(Player player) { + if (plugin.permission == null) return; + Iterator iter = Settings.getJoinPermissions.iterator(); + while (iter.hasNext()) { + String permission = iter.next(); + if(plugin.permission.playerHas(player, permission)){ + plugin.permission.playerAddTransient(player, permission); + } + } + } - public boolean addNormal(Player player, String group) { - if(!Utils.getInstance().useGroupSystem()){ - return false; - } - if(AuthMe.permission.playerRemoveGroup(player.getWorld(),player.getName().toString(),this.unLoggedGroup) && AuthMe.permission.playerAddGroup(player.getWorld(),player.getName().toString(),group)) { - return true; - } - return false; - } - - private String hasPermOnJoin(Player player) { - Iterator iter = Settings.getJoinPermissions.iterator(); - while (iter.hasNext()) { - String permission = iter.next(); - if(AuthMe.permission.playerHas(player, permission)){ - AuthMe.permission.playerAddTransient(player, permission); - } - } - return null; - } - - public boolean isUnrestricted(Player player) { - if(Settings.getUnrestrictedName.isEmpty() || Settings.getUnrestrictedName == null) - return false; - if(Settings.getUnrestrictedName.contains(player.getName())) - return true; - return false; + public boolean isUnrestricted(Player player) { + if(!Settings.isAllowRestrictedIp) + return false; + if(Settings.getUnrestrictedName.isEmpty() || Settings.getUnrestrictedName == null) + return false; + if(Settings.getUnrestrictedName.contains(player.getName())) + return true; + return false; } public static Utils getInstance() { - singleton = new Utils(); + singleton = new Utils(AuthMe.getInstance()); return singleton; } private boolean useGroupSystem() { - if(Settings.isPermissionCheckEnabled && !Settings.getUnloggedinGroup.isEmpty()) { + if(Settings.isPermissionCheckEnabled && !Settings.getUnloggedinGroup.isEmpty()) return true; - } return false; + return false; } public void packCoords(double x, double y, double z, String w, final Player pl) @@ -112,11 +125,11 @@ public class Utils { final World world = theWorld; final Location locat = new Location(world, x, y, z); - Bukkit.getScheduler().scheduleSyncDelayedTask(AuthMe.getInstance(), new Runnable() { + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { AuthMeTeleportEvent tpEvent = new AuthMeTeleportEvent(pl, locat); - AuthMe.getInstance().getServer().getPluginManager().callEvent(tpEvent); + plugin.getServer().getPluginManager().callEvent(tpEvent); if(!tpEvent.isCancelled()) { if (!tpEvent.getTo().getChunk().isLoaded()) tpEvent.getTo().getChunk().load(); diff --git a/src/main/java/fr/xephi/authme/api/API.java b/src/main/java/fr/xephi/authme/api/API.java index 6b45387f3..3bdeff739 100644 --- a/src/main/java/fr/xephi/authme/api/API.java +++ b/src/main/java/fr/xephi/authme/api/API.java @@ -63,7 +63,7 @@ public class API { return true; return CombatTagComunicator.isNPC(player); } - + /** * * @param player @@ -154,7 +154,7 @@ public class API { return false; } } - + /** * Get Player realName from lowerCase nickname * @param String playerName diff --git a/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java b/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java index f7a7e85fe..64139648e 100644 --- a/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java +++ b/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java @@ -192,7 +192,7 @@ public class PlayerAuth { public String getWorld() { return world; } - + @Override public String toString() { String s = "Player : " + nickname + " ! IP : " + ip + " ! LastLogin : " + lastLogin + " ! LastPosition : " + x + "," + y + "," + z + "," + world diff --git a/src/main/java/fr/xephi/authme/cache/auth/PlayerCache.java b/src/main/java/fr/xephi/authme/cache/auth/PlayerCache.java index 9acaae442..58129ed6b 100644 --- a/src/main/java/fr/xephi/authme/cache/auth/PlayerCache.java +++ b/src/main/java/fr/xephi/authme/cache/auth/PlayerCache.java @@ -39,4 +39,8 @@ public class PlayerCache { return singleton; } + public int getLogged() { + return cache.size(); + } + } diff --git a/src/main/java/fr/xephi/authme/cache/backup/FileCache.java b/src/main/java/fr/xephi/authme/cache/backup/FileCache.java index 6a0bb42f3..ad62aa4e5 100644 --- a/src/main/java/fr/xephi/authme/cache/backup/FileCache.java +++ b/src/main/java/fr/xephi/authme/cache/backup/FileCache.java @@ -38,7 +38,7 @@ public class FileCache { if (operator) s = s + "1"; else s = s + "0"; - + // line format Group|OperatorStatus|isFlying if(flying) writer.write(s+";1" + API.newline); @@ -134,7 +134,7 @@ public class FileCache { if (!in[0].equals("i") && !in[0].equals("w")) { continue; } - // can enchant item? size ofstring in file - 4 all / 2 = number of enchant + // can enchant item? size ofstring in file - 4 all / 2 = number of enchant if (in[0].equals("i")) { stacki[i] = new ItemStack(Material.getMaterial(in[1]), Integer.parseInt(in[2]), Short.parseShort((in[3]))); diff --git a/src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java b/src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java index 350c0fc00..fe4841439 100644 --- a/src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java +++ b/src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java @@ -30,7 +30,6 @@ public class LimboCache { public void addLimboPlayer(Player player) { String name = player.getName().toLowerCase(); Location loc = player.getLocation(); - loc.setY(loc.getY() + 0.4D); GameMode gameMode = player.getGameMode(); ItemStack[] arm; ItemStack[] inv; @@ -67,6 +66,8 @@ public class LimboCache { if(player.isFlying()) flying = true; else flying = false; + if (plugin.permission != null) + playerGroup = plugin.permission.getPrimaryGroup(player); } if(Settings.isForceSurvivalModeEnabled) { @@ -83,13 +84,6 @@ public class LimboCache { if(player.isDead()) { loc = plugin.getSpawnLocation(player.getWorld()); } - try { - if(cache.containsKey(name) && playerGroup.isEmpty()) { - LimboPlayer groupLimbo = cache.get(name); - playerGroup = groupLimbo.getGroup(); - } - } catch (NullPointerException ex) { - } cache.put(player.getName().toLowerCase(), new LimboPlayer(name, loc, inv, arm, gameMode, operator, playerGroup, flying)); } diff --git a/src/main/java/fr/xephi/authme/commands/AdminCommand.java b/src/main/java/fr/xephi/authme/commands/AdminCommand.java index 675c0eaf1..46ae03f71 100644 --- a/src/main/java/fr/xephi/authme/commands/AdminCommand.java +++ b/src/main/java/fr/xephi/authme/commands/AdminCommand.java @@ -32,6 +32,7 @@ import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.converter.FlatToSql; import fr.xephi.authme.converter.FlatToSqlite; import fr.xephi.authme.converter.RakamakConverter; +import fr.xephi.authme.converter.RoyalAuthConverter; import fr.xephi.authme.converter.newxAuthToFlat; import fr.xephi.authme.converter.oldxAuthToFlat; import fr.xephi.authme.datasource.DataSource; @@ -435,17 +436,20 @@ public class AdminCommand implements CommandExecutor { auth = PlayerCache.getInstance().getAuth(name); } else if (database.isAuthAvailable(name)) { auth = database.getAuth(name); - } else { + } + if (auth == null) { m._(sender, "unknown_user"); return true; } auth.setHash(hash); - auth.setSalt(PasswordSecurity.userSalt.get(name)); + if (PasswordSecurity.userSalt.containsKey(name)) { + auth.setSalt(PasswordSecurity.userSalt.get(name)); + database.updateSalt(auth); + } if (!database.updatePassword(auth)) { m._(sender, "error"); return true; } - database.updateSalt(auth); sender.sendMessage("pwd_changed"); ConsoleLogger.info(args[1] + "'s password changed"); } catch (NoSuchAlgorithmException ex) { @@ -509,6 +513,10 @@ public class AdminCommand implements CommandExecutor { } sender.sendMessage("Usage : /authme switchantibot on/off"); return true; + } else if (args[0].equalsIgnoreCase("royalauth")) { + new RoyalAuthConverter(plugin); + sender.sendMessage("[AuthMe] RoyalAuth database has been imported correctly"); + return true; } else { sender.sendMessage("Usage: /authme reload|register playername password|changepassword playername password|unregister playername"); } diff --git a/src/main/java/fr/xephi/authme/commands/CaptchaCommand.java b/src/main/java/fr/xephi/authme/commands/CaptchaCommand.java index 48cf146ed..e3ae28c90 100644 --- a/src/main/java/fr/xephi/authme/commands/CaptchaCommand.java +++ b/src/main/java/fr/xephi/authme/commands/CaptchaCommand.java @@ -61,7 +61,9 @@ public class CaptchaCommand implements CommandExecutor { if(Settings.useCaptcha && !args[0].equals(plugin.cap.get(name))) { plugin.cap.remove(name); plugin.cap.put(name, rdm.nextString()); - player.sendMessage(m._("wrong_captcha").replaceAll("THE_CAPTCHA", plugin.cap.get(name))); + for (String s : m._("wrong_captcha")) { + player.sendMessage(s.replace("THE_CAPTCHA", plugin.cap.get(name))); + } return true; } try { diff --git a/src/main/java/fr/xephi/authme/commands/LogoutCommand.java b/src/main/java/fr/xephi/authme/commands/LogoutCommand.java index 2db572865..5183a87a9 100644 --- a/src/main/java/fr/xephi/authme/commands/LogoutCommand.java +++ b/src/main/java/fr/xephi/authme/commands/LogoutCommand.java @@ -8,11 +8,11 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitScheduler; -import org.bukkit.scheduler.BukkitTask; import fr.xephi.authme.AuthMe; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.Utils; +import fr.xephi.authme.Utils.groupType; import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.backup.DataFileCache; @@ -91,8 +91,8 @@ public class LogoutCommand implements CommandExecutor { if (LimboCache.getInstance().hasLimboPlayer(name)) LimboCache.getInstance().deleteLimboPlayer(name); - LimboCache.getInstance().addLimboPlayer(player , utils.removeAll(player)); LimboCache.getInstance().addLimboPlayer(player); + utils.setGroup(player, groupType.NOTLOGGEDIN); if(Settings.protectInventoryBeforeLogInEnabled) { player.getInventory().clear(); // create cache file for handling lost of inventories on unlogged in status @@ -104,11 +104,11 @@ public class LogoutCommand implements CommandExecutor { int interval = Settings.getWarnMessageInterval; BukkitScheduler sched = sender.getServer().getScheduler(); if (delay != 0) { - BukkitTask id = sched.runTaskLater(plugin, new TimeoutTask(plugin, name), delay); - LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id.getTaskId()); + int id = sched.scheduleSyncDelayedTask(plugin, new TimeoutTask(plugin, name), delay); + LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id); } - BukkitTask msgT = sched.runTask(plugin, new MessageTask(plugin, name, m._("login_msg"), interval)); - LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT.getTaskId()); + int msgT = sched.scheduleSyncDelayedTask(plugin, new MessageTask(plugin, name, m._("login_msg"), interval)); + LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT); try { if (PlayersLogs.players.contains(player.getName())) { PlayersLogs.players.remove(player.getName()); diff --git a/src/main/java/fr/xephi/authme/commands/PasspartuCommand.java b/src/main/java/fr/xephi/authme/commands/PasspartuCommand.java index 292dab939..dbbbdd844 100644 --- a/src/main/java/fr/xephi/authme/commands/PasspartuCommand.java +++ b/src/main/java/fr/xephi/authme/commands/PasspartuCommand.java @@ -16,7 +16,7 @@ import fr.xephi.authme.settings.Messages; * @author stefano */ public class PasspartuCommand implements CommandExecutor { - private Utils utils = new Utils(); + private Utils utils = Utils.getInstance(); public AuthMe plugin; private Messages m = Messages.getInstance(); @@ -26,7 +26,7 @@ public class PasspartuCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command cmnd, String label, String[] args) { - + if (!plugin.authmePermissible(sender, "authme." + label.toLowerCase())) { m._(sender, "no_perm"); return true; diff --git a/src/main/java/fr/xephi/authme/commands/RegisterCommand.java b/src/main/java/fr/xephi/authme/commands/RegisterCommand.java index 832df74e5..1260179ea 100644 --- a/src/main/java/fr/xephi/authme/commands/RegisterCommand.java +++ b/src/main/java/fr/xephi/authme/commands/RegisterCommand.java @@ -38,13 +38,11 @@ public class RegisterCommand implements CommandExecutor { private Messages m = Messages.getInstance(); private PlayersLogs pllog = PlayersLogs.getInstance(); private DataSource database; - public boolean isFirstTimeJoin; public PlayerAuth auth; public AuthMe plugin; public RegisterCommand(DataSource database, AuthMe plugin) { this.database = database; - this.isFirstTimeJoin = false; this.plugin = plugin; } @@ -69,7 +67,7 @@ public class RegisterCommand implements CommandExecutor { } final String ip = ipA; - + if (PlayerCache.getInstance().isAuthenticated(name)) { m._(player, "logged_in"); return true; @@ -153,7 +151,6 @@ public class RegisterCommand implements CommandExecutor { Utils.getInstance().setGroup(player, Utils.groupType.REGISTERED); } m._(player, "vb_nonActiv"); - String msg = m._("login_msg"); int time = Settings.getRegistrationTimeout * 20; int msgInterval = Settings.getWarnMessageInterval; if (time != 0) { @@ -163,10 +160,9 @@ public class RegisterCommand implements CommandExecutor { } Bukkit.getScheduler().cancelTask(LimboCache.getInstance().getLimboPlayer(name).getMessageTaskId()); - int nwMsg = Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new MessageTask(plugin, name, msg, msgInterval)); + int nwMsg = Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new MessageTask(plugin, name, m._("login_msg"), msgInterval)); LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(nwMsg); - LimboCache.getInstance().deleteLimboPlayer(name); if (Settings.isTeleportToSpawnEnabled) { World world = player.getWorld(); Location loca = plugin.getSpawnLocation(world); @@ -179,7 +175,6 @@ public class RegisterCommand implements CommandExecutor { player.teleport(tpEvent.getTo()); } } - this.isFirstTimeJoin = true; if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) { player.setAllowFlight(false); player.setFlying(false); @@ -188,7 +183,7 @@ public class RegisterCommand implements CommandExecutor { if (!Settings.noConsoleSpam) ConsoleLogger.info(player.getName() + " registered "+player.getAddress().getAddress().getHostAddress()); if(plugin.notifications != null) { - plugin.notifications.showNotification(new Notification("[AuthMe] " + player.getName() + " has registered!")); + plugin.notifications.showNotification(new Notification("[AuthMe] " + player.getName() + " has registered by email!")); } return true; } @@ -203,6 +198,13 @@ public class RegisterCommand implements CommandExecutor { m._(player, "pass_len"); return true; } + if(!Settings.unsafePasswords.isEmpty()) { + if (Settings.unsafePasswords.contains(args[0].toLowerCase())) { + m._(player, "password_error"); + return true; + } + + } try { String hash; if(Settings.getEnablePasswordVerifier) { @@ -251,7 +253,6 @@ public class RegisterCommand implements CommandExecutor { m._(player, "registered"); if (!Settings.getmailAccount.isEmpty()) m._(player, "add_email"); - this.isFirstTimeJoin = true; if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) { player.setAllowFlight(false); player.setFlying(false); @@ -260,6 +261,10 @@ public class RegisterCommand implements CommandExecutor { Bukkit.getServer().getPluginManager().callEvent(new LoginEvent(player, true)); player.saveData(); + // Register is finish and player is logged, display welcome message + for (String s : Settings.welcomeMsg) + player.sendMessage(plugin.replaceAllInfos(s, player)); + // Register is now finish , we can force all commands forceCommands(player); if (!Settings.noConsoleSpam) @@ -273,7 +278,7 @@ public class RegisterCommand implements CommandExecutor { } return true; } - + protected void forceCommands(Player player) { for (String command : Settings.forceCommands) { try { diff --git a/src/main/java/fr/xephi/authme/commands/UnregisterCommand.java b/src/main/java/fr/xephi/authme/commands/UnregisterCommand.java index 7b526f8a7..e5ab602d4 100644 --- a/src/main/java/fr/xephi/authme/commands/UnregisterCommand.java +++ b/src/main/java/fr/xephi/authme/commands/UnregisterCommand.java @@ -11,11 +11,11 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.scheduler.BukkitScheduler; -import org.bukkit.scheduler.BukkitTask; import fr.xephi.authme.AuthMe; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.Utils; +import fr.xephi.authme.Utils.groupType; import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.backup.FileCache; import fr.xephi.authme.cache.limbo.LimboCache; @@ -77,12 +77,13 @@ public class UnregisterCommand implements CommandExecutor { player.saveData(); PlayerCache.getInstance().removePlayer(player.getName().toLowerCase()); LimboCache.getInstance().addLimboPlayer(player); + Utils.getInstance().setGroup(player, groupType.UNREGISTERED); int delay = Settings.getRegistrationTimeout * 20; int interval = Settings.getWarnMessageInterval; BukkitScheduler sched = sender.getServer().getScheduler(); if (delay != 0) { - BukkitTask id = sched.runTaskLater(plugin, new TimeoutTask(plugin, name), delay); - LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id.getTaskId()); + int id = sched.scheduleSyncDelayedTask(plugin, new TimeoutTask(plugin, name), delay); + LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id); } sched.scheduleSyncDelayedTask(plugin, new MessageTask(plugin, name, m._("reg_msg"), interval)); if(!Settings.unRegisteredGroup.isEmpty()){ diff --git a/src/main/java/fr/xephi/authme/converter/RoyalAuthConverter.java b/src/main/java/fr/xephi/authme/converter/RoyalAuthConverter.java new file mode 100644 index 000000000..f5ad9d85b --- /dev/null +++ b/src/main/java/fr/xephi/authme/converter/RoyalAuthConverter.java @@ -0,0 +1,43 @@ +package fr.xephi.authme.converter; + +import java.io.File; + +import org.bukkit.OfflinePlayer; + +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.ConsoleLogger; +import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.datasource.DataSource; + +public class RoyalAuthConverter extends Thread { + + public AuthMe plugin; + private DataSource data; + + public RoyalAuthConverter(AuthMe plugin) { + this.plugin = plugin; + this.data = plugin.database; + this.start(); + } + + public void run() { + for (OfflinePlayer o : plugin.getServer().getOfflinePlayers()) { + try { + String name = o.getName().toLowerCase(); + String separator = File.separator; + File file = new File("." + separator + "plugins" + separator + "RoyalAuth" + separator + "userdata" + separator + name + ".yml"); + if (data.isAuthAvailable(name)) + continue; + if (!file.exists()) + continue; + RoyalAuthYamlReader ra = new RoyalAuthYamlReader(file); + PlayerAuth auth = new PlayerAuth(name, ra.getHash(), "127.0.0.1", ra.getLastLogin(), "your@email.com", o.getName()); + data.saveAuth(auth); + } catch (Exception e) { + ConsoleLogger.showError("Error while trying to import "+ o.getName() + " RoyalAuth datas"); + } + } + this.interrupt(); + } + +} diff --git a/src/main/java/fr/xephi/authme/converter/RoyalAuthYamlReader.java b/src/main/java/fr/xephi/authme/converter/RoyalAuthYamlReader.java new file mode 100644 index 000000000..05e309fdf --- /dev/null +++ b/src/main/java/fr/xephi/authme/converter/RoyalAuthYamlReader.java @@ -0,0 +1,22 @@ +package fr.xephi.authme.converter; + +import java.io.File; + +import fr.xephi.authme.settings.CustomConfiguration; + +public class RoyalAuthYamlReader extends CustomConfiguration { + + public RoyalAuthYamlReader(File file) { + super(file); + load(); + save(); + } + + public long getLastLogin() { + return getLong("timestamps.quit"); + } + + public String getHash() { + return getString("login.password"); + } +} diff --git a/src/main/java/fr/xephi/authme/datasource/FileDataSource.java b/src/main/java/fr/xephi/authme/datasource/FileDataSource.java index a7fcc9978..091d42647 100644 --- a/src/main/java/fr/xephi/authme/datasource/FileDataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/FileDataSource.java @@ -329,11 +329,9 @@ public class FileDataSource implements DataSource { if (Long.parseLong(args[3]) >= until) { lines.add(line); continue; - } else { - cleared.add(args[0]); } } - + cleared.add(args[0]); } bw = new BufferedWriter(new FileWriter(source)); for (String l : lines) { diff --git a/src/main/java/fr/xephi/authme/datasource/SqliteDataSource.java b/src/main/java/fr/xephi/authme/datasource/SqliteDataSource.java index f5bde13ed..bbc716b38 100644 --- a/src/main/java/fr/xephi/authme/datasource/SqliteDataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/SqliteDataSource.java @@ -112,13 +112,6 @@ public class SqliteDataSource implements DataSource { if (!rs.next()) { st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnEmail + " VARCHAR(255) DEFAULT 'your@email.com';"); } - rs.close(); - rs = con.getMetaData().getColumns(null, null, tableName, lastlocX); - if (rs.next()) { - st.executeUpdate("ALTER TABLE " + tableName + " MODIFY " + lastlocX + " DOUBLE NOT NULL DEFAULT '0.0';"); - st.executeUpdate("ALTER TABLE " + tableName + " MODIFY " + lastlocY + " DOUBLE NOT NULL DEFAULT '0.0';"); - st.executeUpdate("ALTER TABLE " + tableName + " MODIFY " + lastlocZ + " DOUBLE NOT NULL DEFAULT '0.0';"); - } } finally { close(rs); close(st); diff --git a/src/main/java/fr/xephi/authme/events/PasswordEncryptionEvent.java b/src/main/java/fr/xephi/authme/events/PasswordEncryptionEvent.java index 8cb82ea8a..7611746e6 100644 --- a/src/main/java/fr/xephi/authme/events/PasswordEncryptionEvent.java +++ b/src/main/java/fr/xephi/authme/events/PasswordEncryptionEvent.java @@ -14,11 +14,11 @@ import fr.xephi.authme.security.crypts.EncryptionMethod; * @author Xephi59 */ public class PasswordEncryptionEvent extends Event { - + private static final HandlerList handlers = new HandlerList(); private EncryptionMethod method = null; private String playerName = ""; - + public PasswordEncryptionEvent(EncryptionMethod method, String playerName) { this.method = method; this.playerName = playerName; diff --git a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java index 3d6e7a5c5..ae44ae693 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java @@ -40,6 +40,7 @@ import org.bukkit.scheduler.BukkitScheduler; import fr.xephi.authme.AuthMe; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.Utils; +import fr.xephi.authme.Utils.groupType; import fr.xephi.authme.api.API; import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerCache; @@ -387,41 +388,46 @@ public class AuthMePlayerListener implements Listener { return; } + if (!Settings.countriesBlacklist.isEmpty()) { + String code = plugin.getCountryCode(event.getAddress()); + if (((code == null) || (Settings.countriesBlacklist.contains(code) && !API.isRegistered(name))) && !plugin.authmePermissible(player, "authme.bypassantibot")) { + event.disallow(PlayerLoginEvent.Result.KICK_OTHER, m._("country_banned")[0]); + return; + } + } if (Settings.enableProtection && !Settings.countries.isEmpty()) { String code = plugin.getCountryCode(event.getAddress()); if (((code == null) || (!Settings.countries.contains(code) && !API.isRegistered(name))) && !plugin.authmePermissible(player, "authme.bypassantibot")) { - event.disallow(PlayerLoginEvent.Result.KICK_OTHER, m._("country_banned")); + event.disallow(PlayerLoginEvent.Result.KICK_OTHER, m._("country_banned")[0]); return; } } if (Settings.isKickNonRegisteredEnabled) { if (!data.isAuthAvailable(name)) { - event.disallow(PlayerLoginEvent.Result.KICK_OTHER, m._("reg_only")); + event.disallow(PlayerLoginEvent.Result.KICK_OTHER, m._("reg_only")[0]); return; } } if (player.isOnline() && Settings.isForceSingleSessionEnabled) { - event.disallow(PlayerLoginEvent.Result.KICK_OTHER, m._("same_nick")); + event.disallow(PlayerLoginEvent.Result.KICK_OTHER, m._("same_nick")[0]); return; } if(data.isAuthAvailable(name) && !LimboCache.getInstance().hasLimboPlayer(name)) { if(!Settings.isSessionsEnabled) { - LimboCache.getInstance().addLimboPlayer(player , utils.removeAll(player)); } else if(PlayerCache.getInstance().isAuthenticated(name)) { if(!Settings.sessionExpireOnIpChange) if(LimboCache.getInstance().hasLimboPlayer(player.getName().toLowerCase())) { LimboCache.getInstance().deleteLimboPlayer(name); } - LimboCache.getInstance().addLimboPlayer(player , utils.removeAll(player)); } } //Check if forceSingleSession is set to true, so kick player that has joined with same nick of online player if(player.isOnline() && Settings.isForceSingleSessionEnabled ) { LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(player.getName().toLowerCase()); - event.disallow(PlayerLoginEvent.Result.KICK_OTHER, m._("same_nick")); + event.disallow(PlayerLoginEvent.Result.KICK_OTHER, m._("same_nick")[0]); if(PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) { utils.addNormal(player, limbo.getGroup()); LimboCache.getInstance().deleteLimboPlayer(player.getName().toLowerCase()); @@ -435,14 +441,14 @@ public class AuthMePlayerListener implements Listener { if (name.length() > max || name.length() < min) { - event.disallow(PlayerLoginEvent.Result.KICK_OTHER, m._("name_len")); + event.disallow(PlayerLoginEvent.Result.KICK_OTHER, m._("name_len")[0]); return; } try { if (!player.getName().matches(regex) || name.equals("Player")) { try { - event.disallow(PlayerLoginEvent.Result.KICK_OTHER, m._("regex").replaceAll("REG_EX", regex)); - } catch (StringIndexOutOfBoundsException exc) { + event.disallow(PlayerLoginEvent.Result.KICK_OTHER, m._("regex")[0].replace("REG_EX", regex)); + } catch (Exception exc) { event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "allowed char : " + regex); } return; @@ -453,8 +459,8 @@ public class AuthMePlayerListener implements Listener { return; } try { - event.disallow(PlayerLoginEvent.Result.KICK_OTHER, m._("regex").replaceAll("REG_EX", regex)); - } catch (StringIndexOutOfBoundsException exc) { + event.disallow(PlayerLoginEvent.Result.KICK_OTHER, m._("regex")[0].replace("REG_EX", regex)); + } catch (Exception exc) { event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "allowed char : " + regex); } return; @@ -477,7 +483,7 @@ public class AuthMePlayerListener implements Listener { if (event.getResult() != PlayerLoginEvent.Result.KICK_FULL) return; if (player.isBanned()) return; if (!plugin.authmePermissible(player, "authme.vip")) { - event.disallow(Result.KICK_FULL, m._("kick_fullserver")); + event.disallow(Result.KICK_FULL, m._("kick_fullserver")[0]); return; } @@ -487,12 +493,12 @@ public class AuthMePlayerListener implements Listener { } else { final Player pl = plugin.generateKickPlayer(plugin.getServer().getOnlinePlayers()); if (pl != null) { - pl.kickPlayer(m._("kick_forvip")); + pl.kickPlayer(m._("kick_forvip")[0]); event.allow(); return; } else { ConsoleLogger.info("The player " + player.getName() + " wants to join, but the server is full"); - event.disallow(Result.KICK_FULL, m._("kick_fullserver")); + event.disallow(Result.KICK_FULL, m._("kick_fullserver")[0]); return; } } @@ -505,14 +511,16 @@ public class AuthMePlayerListener implements Listener { return; if (antibot.keySet().size() > Settings.antiBotSensibility) { plugin.switchAntiBotMod(true); - Bukkit.broadcastMessage(m._("antibot_auto_enabled")); + for (String s : m._("antibot_auto_enabled")) + Bukkit.broadcastMessage(s); Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ @Override public void run() { if (plugin.antibotMod) { plugin.switchAntiBotMod(false); antibot.clear(); - Bukkit.broadcastMessage(m._("antibot_auto_disabled").replace("%m", "" + Settings.antiBotDuration)); + for (String s : m._("antibot_auto_disabled")) + Bukkit.broadcastMessage(s.replace("%m", "" + Settings.antiBotDuration)); } } }, Settings.antiBotDuration * 1200); @@ -532,7 +540,6 @@ public class AuthMePlayerListener implements Listener { if (event.getPlayer() == null) { return; } - Player player = event.getPlayer(); World world = player.getWorld(); Location spawnLoc = plugin.getSpawnLocation(world); @@ -587,7 +594,7 @@ public class AuthMePlayerListener implements Listener { this.causeByAuthMe = true; player.setGameMode(gM); this.causeByAuthMe = false; - player.kickPlayer(m._("unvalid_session")); + player.kickPlayer(m._("unvalid_session")[0]); return; } else if (auth.getNickname().equalsIgnoreCase(name)){ if (Settings.isForceSurvivalModeEnabled && !Settings.forceOnlyAfterLogin) { @@ -597,19 +604,17 @@ public class AuthMePlayerListener implements Listener { } //Player change his IP between 2 relog-in PlayerCache.getInstance().removePlayer(name); - LimboCache.getInstance().addLimboPlayer(player , utils.removeAll(player)); } else { GameMode gM = gameMode.get(name); this.causeByAuthMe = true; player.setGameMode(gM); this.causeByAuthMe = false; - player.kickPlayer(m._("unvalid_session")); + player.kickPlayer(m._("unvalid_session")[0]); return; } } else { //Session is ended correctly PlayerCache.getInstance().removePlayer(name); - LimboCache.getInstance().addLimboPlayer(player , utils.removeAll(player)); } } // isent in session or session was ended correctly @@ -659,7 +664,7 @@ public class AuthMePlayerListener implements Listener { } catch (NullPointerException ex) { } } - String msg = ""; + String[] msg; if(Settings.emailRegistration) { msg = data.isAuthAvailable(name) ? m._("login_msg") : m._("reg_email_msg"); } else { @@ -675,6 +680,11 @@ public class AuthMePlayerListener implements Listener { } if(!LimboCache.getInstance().hasLimboPlayer(name)) LimboCache.getInstance().addLimboPlayer(player); + if (data.isAuthAvailable(name)) { + utils.setGroup(player, groupType.NOTLOGGEDIN); + } else { + utils.setGroup(player, groupType.UNREGISTERED); + } if(player.isOp()) player.setOp(false); if (!Settings.isMovementAllowed) { @@ -712,8 +722,6 @@ public class AuthMePlayerListener implements Listener { Player player = event.getPlayer(); String name = player.getName().toLowerCase(); Location loc = player.getLocation(); - if (loc.getY() % 1 != 0) - loc.add(0, 0.5, 0); if (plugin.getCitizensCommunicator().isNPC(player, plugin) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) { return; @@ -723,21 +731,13 @@ public class AuthMePlayerListener implements Listener { if(Settings.isSaveQuitLocationEnabled && data.isAuthAvailable(name)) { final PlayerAuth auth = new PlayerAuth(name,loc.getX(),loc.getY(),loc.getZ(),loc.getWorld().getName()); try { - if (data instanceof Thread) { - data.updateQuitLoc(auth); - } else { - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ - @Override - public void run() { - data.updateQuitLoc(auth); - } - }); - } + data.updateQuitLoc(auth); } catch (NullPointerException npe) { } } - } else { - event.setQuitMessage(null); } + + if (data.getAuth(name) != null && !PlayerCache.getInstance().isAuthenticated(name)) + event.setQuitMessage(null); if (LimboCache.getInstance().hasLimboPlayer(name)) { LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(name); @@ -757,7 +757,7 @@ public class AuthMePlayerListener implements Listener { this.plugin.getServer().getScheduler().cancelTask(limbo.getTimeoutTaskId()); LimboCache.getInstance().deleteLimboPlayer(name); if(playerBackup.doesCacheExist(name)) { - playerBackup.removeCache(name); + playerBackup.removeCache(name); } } try { @@ -782,8 +782,6 @@ public class AuthMePlayerListener implements Listener { Player player = event.getPlayer(); Location loc = player.getLocation(); - if (loc.getY() % 1 != 0) - loc.add(0, 0.5, 0); if ((plugin.getCitizensCommunicator().isNPC(player, plugin)) || (Utils.getInstance().isUnrestricted(player)) || (CombatTagComunicator.isNPC(player))) { return; @@ -800,21 +798,13 @@ public class AuthMePlayerListener implements Listener { (Settings.isSaveQuitLocationEnabled) && data.isAuthAvailable(name)) { final PlayerAuth auth = new PlayerAuth(name, loc.getX(), loc.getY(), loc.getZ(),loc.getWorld().getName()); try { - if (data instanceof Thread) { - data.updateQuitLoc(auth); - } else { - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ - @Override - public void run() { - data.updateQuitLoc(auth); - } - }); - } + data.updateQuitLoc(auth); } catch (NullPointerException npe) { } - } else if (!PlayerCache.getInstance().isAuthenticated(name)){ - event.setLeaveMessage(null); } + if (data.getAuth(name) != null && !PlayerCache.getInstance().isAuthenticated(name)) + event.setLeaveMessage(null); + if (LimboCache.getInstance().hasLimboPlayer(name)) { LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(name); diff --git a/src/main/java/fr/xephi/authme/listener/AuthMeServerListener.java b/src/main/java/fr/xephi/authme/listener/AuthMeServerListener.java new file mode 100644 index 000000000..a3cf7f0a5 --- /dev/null +++ b/src/main/java/fr/xephi/authme/listener/AuthMeServerListener.java @@ -0,0 +1,97 @@ +package fr.xephi.authme.listener; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.server.PluginDisableEvent; +import org.bukkit.event.server.PluginEnableEvent; +import org.bukkit.event.server.ServerListPingEvent; + +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.ConsoleLogger; +import fr.xephi.authme.settings.Messages; +import fr.xephi.authme.settings.Settings; + +public class AuthMeServerListener implements Listener { + + public AuthMe plugin; + private Messages m = Messages.getInstance(); + + public AuthMeServerListener(AuthMe plugin) { + this.plugin = plugin; + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onServerPing(ServerListPingEvent event) { + if (!Settings.enableProtection) return; + if (Settings.countries.isEmpty()) return; + if (!Settings.countriesBlacklist.isEmpty()) { + if(Settings.countriesBlacklist.contains(plugin.getCountryCode(event.getAddress()))) + event.setMotd(m._("country_banned")[0]); + } + if(Settings.countries.contains(plugin.getCountryCode(event.getAddress()))) { + event.setMotd(plugin.getServer().getMotd()); + } else { + event.setMotd(m._("country_banned")[0]); + } + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onPluginDisable(PluginDisableEvent event) { + String pluginName = event.getPlugin().getName(); + if(pluginName.equalsIgnoreCase("Essentials")) { + plugin.ess = null; + ConsoleLogger.info("Essentials has been disabled, unhook!"); + return; + } + if(pluginName.equalsIgnoreCase("EssentialsSpawn")) { + plugin.essentialsSpawn = null; + ConsoleLogger.info("EssentialsSpawn has been disabled, unhook!"); + return; + } + if(pluginName.equalsIgnoreCase("Multiverse-Core")) { + plugin.multiverse = null; + ConsoleLogger.info("Multiverse-Core has been disabled, unhook!"); + return; + } + if(pluginName.equalsIgnoreCase("Notifications")) { + plugin.notifications = null; + ConsoleLogger.info("Notifications has been disabled, unhook!"); + } + if(pluginName.equalsIgnoreCase("ChestShop")) { + plugin.ChestShop = 0; + ConsoleLogger.info("ChestShop has been disabled, unhook!"); + } + if(pluginName.equalsIgnoreCase("CombatTag")) { + plugin.CombatTag = 0; + ConsoleLogger.info("CombatTag has been disabled, unhook!"); + } + if(pluginName.equalsIgnoreCase("Citizens")) { + plugin.CitizensVersion = 0; + ConsoleLogger.info("Citizens has been disabled, unhook!"); + } + if(pluginName.equalsIgnoreCase("Vault")) { + plugin.permission = null; + ConsoleLogger.showError("Vault has been disabled, unhook permissions!"); + } + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onPluginEnable(PluginEnableEvent event) { + String pluginName = event.getPlugin().getName(); + if(pluginName.equalsIgnoreCase("Essentials") || pluginName.equalsIgnoreCase("EssentialsSpawn")) + plugin.checkEssentials(); + if(pluginName.equalsIgnoreCase("Multiverse-Core")) + plugin.checkMultiverse(); + if(pluginName.equalsIgnoreCase("Notifications")) + plugin.checkNotifications(); + if(pluginName.equalsIgnoreCase("ChestShop")) + plugin.checkChestShop(); + if(pluginName.equalsIgnoreCase("CombatTag")) + plugin.combatTag(); + if(pluginName.equalsIgnoreCase("Citizens")) + plugin.citizensVersion(); + if(pluginName.equalsIgnoreCase("Vault")) + plugin.checkVault(); + } +} diff --git a/src/main/java/fr/xephi/authme/security/HashAlgorithm.java b/src/main/java/fr/xephi/authme/security/HashAlgorithm.java index fd8b56328..f75780b10 100644 --- a/src/main/java/fr/xephi/authme/security/HashAlgorithm.java +++ b/src/main/java/fr/xephi/authme/security/HashAlgorithm.java @@ -25,6 +25,7 @@ public enum HashAlgorithm { DOUBLEMD5(fr.xephi.authme.security.crypts.DOUBLEMD5.class), PBKDF2(fr.xephi.authme.security.crypts.CryptPBKDF2.class), WORDPRESS(fr.xephi.authme.security.crypts.WORDPRESS.class), + ROYALAUTH(fr.xephi.authme.security.crypts.ROYALAUTH.class), CUSTOM(Null.class); Class classe; diff --git a/src/main/java/fr/xephi/authme/security/crypts/ROYALAUTH.java b/src/main/java/fr/xephi/authme/security/crypts/ROYALAUTH.java new file mode 100644 index 000000000..675cbd99c --- /dev/null +++ b/src/main/java/fr/xephi/authme/security/crypts/ROYALAUTH.java @@ -0,0 +1,25 @@ +package fr.xephi.authme.security.crypts; + +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +public class ROYALAUTH implements EncryptionMethod { + + @Override + public String getHash(String password, String salt) + throws NoSuchAlgorithmException { + MessageDigest md = MessageDigest.getInstance("SHA-512"); + md.update(password.getBytes()); + byte byteData[] = md.digest(); + StringBuilder sb = new StringBuilder(); + for (byte aByteData : byteData) sb.append(Integer.toString((aByteData & 0xff) + 0x100, 16).substring(1)); + return sb.toString(); + } + + @Override + public boolean comparePassword(String hash, String password, + String playerName) throws NoSuchAlgorithmException { + return hash.equalsIgnoreCase(getHash(password, "")); + } + +} diff --git a/src/main/java/fr/xephi/authme/settings/Messages.java b/src/main/java/fr/xephi/authme/settings/Messages.java index 64e201f89..851e99e71 100644 --- a/src/main/java/fr/xephi/authme/settings/Messages.java +++ b/src/main/java/fr/xephi/authme/settings/Messages.java @@ -5,6 +5,7 @@ import java.io.InputStream; import org.bukkit.command.CommandSender; import org.bukkit.configuration.file.YamlConfiguration; import fr.xephi.authme.AuthMe; +import fr.xephi.authme.ConsoleLogger; public class Messages extends CustomConfiguration { @@ -66,31 +67,28 @@ public class Messages extends CustomConfiguration { } public void _(CommandSender sender, String msg) { - String loc = (String) this.get(msg, this.getDefault(msg)); - if (loc == null && !contains(msg)) { - set(msg, this.getDefault(msg)); - save(); - load(); - loc = (String) this.get(msg, this.getDefault(msg)); + String loc = (String) this.get(msg); + if (loc == null) { + loc = "Error with Translation files; Please contact the admin for verify or update translation"; + ConsoleLogger.showError("Error with the " + msg + " translation, verify in your " + Settings.MESSAGE_FILE + "_" + Settings.messagesLanguage + ".yml !"); } - if (loc == null) - loc = "Error with Translation files; Please contact the admin "; for (String l : loc.split("&n")) { sender.sendMessage(l.replace("&", "\u00a7")); } } - public String _(String msg) { - String loc = (String) this.get(msg, this.getDefault(msg)); - if (loc == null && !contains(msg)) { - set(msg, this.getDefault(msg)); - save(); - load(); - loc = (String) this.get(msg, this.getDefault(msg)); + public String[] _(String msg) { + int i = ((String) this.get(msg)).split("&n").length; + String[] loc = new String[i]; + int a; + for (a = 0 ; a < i ; a++) { + loc[a] = ((String) this.get(msg)).split("&n")[a].replace("&", "\u00a7"); } - if (loc == null) - loc = "Error with Translation files; Please contact the admin "; - return loc.replace("&", "\u00a7"); + if (loc == null || loc.length == 0) { + loc[0] = "Error with " + msg + " translation; Please contact the admin for verify or update translation files"; + ConsoleLogger.showError("Error with the " + msg + " translation, verify in your " + Settings.MESSAGE_FILE + "_" + Settings.messagesLanguage + ".yml !"); + } + return loc; } public static Messages getInstance() { diff --git a/src/main/java/fr/xephi/authme/settings/Settings.java b/src/main/java/fr/xephi/authme/settings/Settings.java index f045c1636..65868ee29 100644 --- a/src/main/java/fr/xephi/authme/settings/Settings.java +++ b/src/main/java/fr/xephi/authme/settings/Settings.java @@ -1,6 +1,12 @@ package fr.xephi.authme.settings; +import java.io.BufferedReader; +import java.io.BufferedWriter; import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Iterator; @@ -8,8 +14,8 @@ import java.util.List; import org.bukkit.configuration.MemoryConfiguration; import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.plugin.Plugin; +import fr.xephi.authme.AuthMe; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource.DataSourceType; @@ -30,14 +36,18 @@ public final class Settings extends YamlConfiguration { public static List getMySQLOtherUsernameColumn = null; public static List getForcedWorlds = null; public static List countries = null; + public static List countriesBlacklist = null; public static List forceCommands = null; - public final Plugin plugin; + private AuthMe plugin; private final File file; public static DataSourceType getDataSource; public static HashAlgorithm getPasswordHash; public static HashAlgorithm rakamakHash; public static Boolean useLogging = false; - + public static int purgeDelay = 60; + public static List welcomeMsg = null; + public static List unsafePasswords; + public static Boolean isPermissionCheckEnabled, isRegistrationEnabled, isForcedRegistrationEnabled, isTeleportToSpawnEnabled, isSessionsEnabled, isChatAllowed, isAllowRestrictedIp, isMovementAllowed, isKickNonRegisteredEnabled, isForceSingleSessionEnabled, @@ -48,7 +58,7 @@ public final class Settings extends YamlConfiguration { useCaptcha, emailRegistration, multiverse, notifications, chestshop, bungee, banUnsafeIp, doubleEmailCheck, sessionExpireOnIpChange, disableSocialSpy, useMultiThreading, forceOnlyAfterLogin, useEssentialsMotd, usePurge, purgePlayerDat, purgeEssentialsFile, supportOldPassword, purgeLimitedCreative, - purgeAntiXray, purgePermissions, enableProtection, enableAntiBot, recallEmail; + purgeAntiXray, purgePermissions, enableProtection, enableAntiBot, recallEmail, useWelcomeMessage; public static String getNickRegex, getUnloggedinGroup, getMySQLHost, getMySQLPort, getMySQLUsername, getMySQLPassword, getMySQLDatabase, getMySQLTablename, @@ -62,11 +72,11 @@ public final class Settings extends YamlConfiguration { public static int getWarnMessageInterval, getSessionTimeout, getRegistrationTimeout, getMaxNickLength, getMinNickLength, getPasswordMinLen, getMovementRadius, getmaxRegPerIp, getNonActivatedGroup, passwordMaxLength, getRecoveryPassLength, getMailPort, maxLoginTry, captchaLength, saltLength, getmaxRegPerEmail, - bCryptLog2Rounds, purgeDelay, getPhpbbGroup, antiBotSensibility, antiBotDuration, delayRecall; + bCryptLog2Rounds, getPhpbbGroup, antiBotSensibility, antiBotDuration, delayRecall; protected static YamlConfiguration configFile; - public Settings(Plugin plugin) { + public Settings(AuthMe plugin) { this.file = new File(plugin.getDataFolder(),"config.yml"); this.plugin = plugin; if(exists()) { @@ -220,6 +230,12 @@ public void loadConfigOptions() { forceCommands = (List) configFile.getList("settings.forceCommands", new ArrayList()); recallEmail = configFile.getBoolean("Email.recallPlayers", false); delayRecall = configFile.getInt("Email.delayRecall", 5); + useWelcomeMessage = configFile.getBoolean("settings.useWelcomeMessage", true); + unsafePasswords = (List) configFile.getList("settings.security.unsafePasswords", new ArrayList()); + countriesBlacklist = (List) configFile.getList("Protection.countriesBlacklist", new ArrayList()); + + // Load the welcome message + getWelcomeMessage(plugin); saveDefaults(); } @@ -364,6 +380,13 @@ public static void reloadConfigOptions(YamlConfiguration newConfig) { forceCommands = (List) configFile.getList("settings.forceCommands", new ArrayList()); recallEmail = configFile.getBoolean("Email.recallPlayers", false); delayRecall = configFile.getInt("Email.delayRecall", 5); + useWelcomeMessage = configFile.getBoolean("settings.useWelcomeMessage", true); + unsafePasswords = (List) configFile.getList("settings.security.unsafePasswords", new ArrayList()); + countriesBlacklist = (List) configFile.getList("Protection.countriesBlacklist", new ArrayList()); + + // Reload the welcome message + getWelcomeMessage(AuthMe.getInstance()); + } public void mergeConfig() { @@ -484,7 +507,16 @@ public void mergeConfig() { set("Email.recallPlayers", false); if(!contains("Email.delayRecall")) set("Email.delayRecall", 5); - + if(!contains("settings.useWelcomeMessage")) + set("settings.useWelcomeMessage", true); + if(!contains("settings.security.unsafePasswords")) + set("settings.security.unsafePasswords", new ArrayList()); + if(!contains("Protection.countriesBlacklist")) { + countriesBlacklist = new ArrayList(); + countriesBlacklist.add("A1"); + set("Protection.countriesBlacklist", countriesBlacklist); + } + plugin.getLogger().warning("Merge new Config Options if needed.."); plugin.getLogger().warning("Please check your config.yml file!"); plugin.saveConfig(); @@ -663,6 +695,35 @@ public void mergeConfig() { isKickNonRegisteredEnabled = configFile.getBoolean("settings.restrictions.kickNonRegistered",false); } + private static void getWelcomeMessage(AuthMe plugin) { + if (!(new File(plugin.getDataFolder() + File.separator + "welcome.txt").exists())) { + try { + FileWriter fw = new FileWriter(plugin.getDataFolder() + File.separator + "welcome.txt", true); + BufferedWriter w = new BufferedWriter(fw); + w.write("Welcome {PLAYER} on {SERVER} server"); + w.newLine(); + w.write("This server use AuthMe protection!"); + w.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + List msg = new ArrayList(); + try { + FileReader fr = new FileReader(plugin.getDataFolder() + File.separator + "welcome.txt"); + BufferedReader br = new BufferedReader(fr); + String line = ""; + while((line = br.readLine()) != null) { + msg.add(line); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + welcomeMsg = msg; + } + public enum messagesLang { en, de, br, cz, pl, fr, uk, ru, hu, sk, es, fi, zhtw, zhhk, zhcn, lt, it, ko, pt, nl } diff --git a/src/main/java/fr/xephi/authme/task/MessageTask.java b/src/main/java/fr/xephi/authme/task/MessageTask.java index 1fce22e39..d4b9c19f2 100644 --- a/src/main/java/fr/xephi/authme/task/MessageTask.java +++ b/src/main/java/fr/xephi/authme/task/MessageTask.java @@ -12,13 +12,13 @@ public class MessageTask implements Runnable { private AuthMe plugin; private String name; - private String msg; + private String[] msg; private int interval; - public MessageTask(AuthMe plugin, String name, String msg, int interval) { + public MessageTask(AuthMe plugin, String name, String[] strings, int interval) { this.plugin = plugin; this.name = name; - this.msg = msg; + this.msg = strings; this.interval = interval; } @@ -29,7 +29,7 @@ public class MessageTask implements Runnable { for (Player player : plugin.getServer().getOnlinePlayers()) { if (player.getName().toLowerCase().equals(name)) { - for (String ms : msg.split("\u00a7n")) { + for (String ms : msg) { player.sendMessage(ms); } BukkitScheduler sched = plugin.getServer().getScheduler(); diff --git a/src/main/java/fr/xephi/authme/task/TimeoutTask.java b/src/main/java/fr/xephi/authme/task/TimeoutTask.java index 2ec4bae2e..ad38a55b5 100644 --- a/src/main/java/fr/xephi/authme/task/TimeoutTask.java +++ b/src/main/java/fr/xephi/authme/task/TimeoutTask.java @@ -48,7 +48,7 @@ public class TimeoutTask implements Runnable { GameMode gm = AuthMePlayerListener.gameMode.get(name); player.setGameMode(gm); ConsoleLogger.info("Set " + player.getName() + " to gamemode: " + gm.name()); - player.kickPlayer(m._("timeout")); + player.kickPlayer(m._("timeout")[0]); break; } } diff --git a/src/main/java/fr/xephi/authme/threads/FlatFileThread.java b/src/main/java/fr/xephi/authme/threads/FlatFileThread.java index e3a2c21be..bbc14d257 100644 --- a/src/main/java/fr/xephi/authme/threads/FlatFileThread.java +++ b/src/main/java/fr/xephi/authme/threads/FlatFileThread.java @@ -342,11 +342,9 @@ public class FlatFileThread extends Thread implements DataSource { if (Long.parseLong(args[3]) >= until) { lines.add(line); continue; - } else { - cleared.add(args[0]); } } - + cleared.add(args[0]); } bw = new BufferedWriter(new FileWriter(source)); for (String l : lines) { diff --git a/src/main/java/fr/xephi/authme/threads/SQLiteThread.java b/src/main/java/fr/xephi/authme/threads/SQLiteThread.java index 601c18cad..db465bbaa 100644 --- a/src/main/java/fr/xephi/authme/threads/SQLiteThread.java +++ b/src/main/java/fr/xephi/authme/threads/SQLiteThread.java @@ -134,13 +134,6 @@ public class SQLiteThread extends Thread implements DataSource { if (!rs.next()) { st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnEmail + " VARCHAR(255) DEFAULT 'your@email.com';"); } - rs.close(); - rs = con.getMetaData().getColumns(null, null, tableName, lastlocX); - if (rs.next()) { - st.executeUpdate("ALTER TABLE " + tableName + " MODIFY " + lastlocX + " DOUBLE NOT NULL DEFAULT '0.0';"); - st.executeUpdate("ALTER TABLE " + tableName + " MODIFY " + lastlocY + " DOUBLE NOT NULL DEFAULT '0.0';"); - st.executeUpdate("ALTER TABLE " + tableName + " MODIFY " + lastlocZ + " DOUBLE NOT NULL DEFAULT '0.0';"); - } } finally { close(rs); close(st); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 695f4bdbb..6d14e1e3e 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -190,7 +190,7 @@ settings: # possible values: MD5, SHA1, SHA256, WHIRLPOOL, XAUTH, MD5VB, PHPBB, # PLAINTEXT ( unhashed password), # MYBB, IPB3, PHPFUSION, SMF, XENFORO, SALTED2MD5, JOOMLA, BCRYPT, WBB3, SHA512, - # DOUBLEMD5, PBKDF2, WORDPRESS, CUSTOM(for developpers only) + # DOUBLEMD5, PBKDF2, WORDPRESS, ROYALAUTH, CUSTOM(for developpers only) passwordHash: SHA256 # salt length for the SALTED2MD5 MD5(MD5(password)+salt) doubleMD5SaltLength: 8 @@ -198,6 +198,11 @@ settings: # other password algorithm to check an old password ? # AuthMe will update the password to the new passwordHash ! supportOldPasswordHash: false + # Cancel unsafe passwords for being used, put them on lowercase! + unsafePasswords: [] + #unsafePasswords: + #- '123456' + #- 'password' registration: # enable registration on the server? enabled: true @@ -224,8 +229,14 @@ settings: UnrestrictedName: [] # Message language, available : en, de, br, cz, pl, fr, ru, hu, sk, es, zhtw, fi, zhcn, lt, it, ko, pt messagesLanguage: en - #Force these commands after /login, without any '/', use %p for replace with player name + # Force these commands after /login, without any '/', use %p for replace with player name forceCommands: [] + # Do we need to display the welcome message (welcome.txt) after a register or a login? + # You can use colors in this welcome.txt + some replaced strings : + # {PLAYER} : player name, {ONLINE} : display number of online players, {MAXPLAYERS} : display server slots, + # {IP} : player ip, {LOGINS} : number of players logged, {WORLD} : player current world, {SERVER} : server name + # {VERSION} : get current bukkit version, {COUNTRY} : player country + useWelcomeMessage: true ExternalBoardOptions: # MySQL column for the salt , needed for some forum/cms support mySQLColumnSalt: '' @@ -236,7 +247,7 @@ ExternalBoardOptions: # u can put in this options the group number # of unactivated user, needed for some forum/cms support nonActivedUserGroup: -1 - # Other MySQL columns where we need to put the Username + # Other MySQL columns where we need to put the Username (case sensitive) mySQLOtherUsernameColumns: [] # How much Log to Round needed in BCrypt(do not change it if you do not know what's your doing) bCryptLog2Round: 10 @@ -360,10 +371,13 @@ Purge: Protection: # Enable some servers protection ( country based login, antibot ) enableProtection: false - # Countries allowed to join the server and register, see http://dev.maxmind.com/geoip/legacy/codes/iso3166/ for countries' codes + # Countries allowed to join the server and register, see http://dev.bukkit.org/bukkit-plugins/authme-reloaded/pages/countries-codes/ for countries' codes countries: - US - GB + # Countries blacklisted automatically ( without any needed to enable protection ) + countriesBlacklist: + - A1 # Do we need to enable automatic antibot system? enableAntiBot: false # Max number of player allowed to login in 5 secs before enable AntiBot system automatically diff --git a/src/main/resources/messages_ko.yml b/src/main/resources/messages_ko.yml index b173f2990..8342a56b6 100644 --- a/src/main/resources/messages_ko.yml +++ b/src/main/resources/messages_ko.yml @@ -51,6 +51,6 @@ email_added: '[AuthMe] 이메일 추가됨 !' email_confirm: '[AuthMe] 이메일을 확인해주세요 !' email_changed: '[AuthMe] 이메일 변경됨 !' email_send: '[AuthMe] 복구 이메일 발송됨 !' -country_banned: 'Your country is banned from this server' -antibot_auto_enabled: '[AuthMe] AntiBotMod automatically enabled due to massive connections!' -antibot_auto_disabled: '[AuthMe] AntiBotMod automatically disabled after %m Minutes, hope invasion stopped' +country_banned: '당신의 나라는 이 서버에서 차단되어 있습니다' +antibot_auto_enabled: '[AuthMe] 안티봇모드는 많은 양의 연결 때문에 자동적으로 활성화됩니다!' +antibot_auto_disabled: '[AuthMe] 안티봇모드는 %m 분 후에 자동적으로 비활성화됩니다, 침입이 없습니다' diff --git a/src/main/resources/messages_ru.yml b/src/main/resources/messages_ru.yml index e251a0d8d..e34b38da9 100644 --- a/src/main/resources/messages_ru.yml +++ b/src/main/resources/messages_ru.yml @@ -1,3 +1,4 @@ +# Translate by AlexMerser / Перевод от AlexMerser unknown_user: '&cТакой игрок не зарегестрирован' unsafe_spawn: '&6Ваше расположение перед выходом было опасным - &aВы перенесены на спавн.' not_logged_in: '&cВы еще не вошли!' @@ -51,6 +52,6 @@ email_added: '[AuthMe] Email добавлен!' email_confirm: '[AuthMe] Подтвердите ваш email!' email_changed: '[AuthMe] Email изменен!' email_send: '[AuthMe] Восстановительное письмо отправлено!' -country_banned: 'Your country is banned from this server' -antibot_auto_enabled: '[AuthMe] AntiBotMod automatically enabled due to massive connections!' -antibot_auto_disabled: '[AuthMe] AntiBotMod automatically disabled after %m Minutes, hope invasion stopped' \ No newline at end of file +country_banned: 'Ваша страна запрещена на этом сервере' +antibot_auto_enabled: '[AuthMe] AntiBot-режим автоматически включен из-за большого количества входов!' +antibot_auto_disabled: '[AuthMe] AntiBot-режим автоматичски отключен после %m мин. Надеюсь, атака закончилась' diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index a04e9f995..3f8f4db85 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,9 +1,9 @@ name: AuthMe author: Xephi59 -website: http://dev.bukkit.org/bukkit-plugins/authme-recoded/ +website: http://dev.bukkit.org/bukkit-plugins/authme-reloaded/ description: AuthMe prevents people, which aren't logged in, from doing stuff like placing blocks, moving, typing commands or seeing the inventory of the current player. main: fr.xephi.authme.AuthMe -version: 3.2.1-DEV-2 +version: 3.3.1 softdepend: [Vault, ChestShop, Spout, Multiverse-Core, Notifications, Citizens, CombatTag, Essentials, EssentialsSpawn] commands: register: @@ -155,4 +155,7 @@ permissions: default: op authme.bypassantibot: description: Bypass the AntiBot check + default: op + authme.admin.royalauth: + description: Import RoyalAuth database into AuthMe default: op \ No newline at end of file