From 5127d5e70a4b441a7b1abd902816591603a5bc31 Mon Sep 17 00:00:00 2001 From: Xephi Date: Tue, 7 Jan 2014 02:59:08 +0100 Subject: [PATCH] Update 3.2 //Changes 3.2:// * Fix Password showed in console ( support for Log4J ) * Quit Location will be more precise ( now double instead of int ) * Force command after the /register too * Close inventory when player try to open one unlogged * Fix old password supports * Remove some Magic Values ( 1.7.2+ ) * Fix threads not start correctly * Add a recall email adding message * Fix catpcha messages * Add multilines messages ( add &n ) * Fix some inventory problem * Fix some events problem * Call login event after /register --- pom.xml | 4 +- src/main/java/fr/xephi/authme/AuthMe.java | 28 +++-- .../java/fr/xephi/authme/ConsoleLogger.java | 6 +- .../java/fr/xephi/authme/Log4JFilter.java | 104 ++++++++++++++++++ src/main/java/fr/xephi/authme/Utils.java | 32 +----- .../xephi/authme/cache/auth/PlayerAuth.java | 32 +++--- .../xephi/authme/cache/backup/FileCache.java | 12 +- .../xephi/authme/commands/LogoutCommand.java | 6 +- .../authme/commands/RegisterCommand.java | 22 +++- .../authme/datasource/FileDataSource.java | 24 ++-- .../authme/datasource/MySQLDataSource.java | 31 +++--- .../authme/datasource/SqliteDataSource.java | 31 ++++-- .../authme/listener/AuthMePlayerListener.java | 17 ++- .../authme/security/PasswordSecurity.java | 16 +-- .../authme/security/crypts/DOUBLEMD5.java | 2 +- .../fr/xephi/authme/security/crypts/IPB3.java | 2 +- .../xephi/authme/security/crypts/JOOMLA.java | 2 +- .../fr/xephi/authme/security/crypts/MD5.java | 13 ++- .../xephi/authme/security/crypts/MD5VB.java | 6 +- .../fr/xephi/authme/security/crypts/MYBB.java | 2 +- .../authme/security/crypts/PHPFUSION.java | 2 +- .../authme/security/crypts/SALTED2MD5.java | 2 +- .../fr/xephi/authme/security/crypts/SHA1.java | 14 ++- .../xephi/authme/security/crypts/SHA256.java | 8 +- .../xephi/authme/security/crypts/SHA512.java | 13 ++- .../fr/xephi/authme/security/crypts/SMF.java | 2 +- .../fr/xephi/authme/security/crypts/WBB3.java | 2 +- .../fr/xephi/authme/task/MessageTask.java | 5 +- .../xephi/authme/threads/FlatFileThread.java | 20 ++-- .../fr/xephi/authme/threads/MySQLThread.java | 29 +++-- .../fr/xephi/authme/threads/SQLiteThread.java | 31 ++++-- src/main/resources/plugin.yml | 2 +- 32 files changed, 329 insertions(+), 193 deletions(-) create mode 100644 src/main/java/fr/xephi/authme/Log4JFilter.java diff --git a/pom.xml b/pom.xml index 8252cd72..fbba9fcd 100644 --- a/pom.xml +++ b/pom.xml @@ -24,11 +24,11 @@ - 3.1.2-DEV-3 + 3.2 org.bukkit - bukkit + craftbukkit 1.7.2-R0.2 diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index e44b94d3..310e0e3e 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -11,10 +11,12 @@ import java.util.Date; import java.util.HashMap; import java.util.List; 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; @@ -81,6 +83,7 @@ public class AuthMe extends JavaPlugin { private Messages m; private PlayersLogs pllog; public static Server server; + public static Logger authmeLogger = Logger.getLogger("AuthMe"); public static Plugin authme; public static Permission permission; private static AuthMe instance; @@ -107,15 +110,21 @@ public class AuthMe extends JavaPlugin { public boolean antibotMod = false; public boolean delayedAntiBot = true; - @Override + public Settings getSettings() { + return settings; + } + + @Override public void onEnable() { instance = this; authme = instance; + + authmeLogger.setParent(this.getLogger()); citizens = new CitizensCommunicator(this); - settings = new Settings(this); - settings.loadConfigOptions(); + settings = new Settings(this); + settings.loadConfigOptions(); if (Settings.enableAntiBot) { Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() { @@ -135,14 +144,15 @@ public class AuthMe extends JavaPlugin { //Set Console Filter if (Settings.removePassword) { + this.getLogger().setFilter(new ConsoleFilter()); Bukkit.getLogger().setFilter(new ConsoleFilter()); - /*// Check the log4j usage and apply a filter + Logger.getLogger("Minecraft").setFilter(new ConsoleFilter()); + Logger.getLogger("AuthMe").setFilter(new ConsoleFilter()); try { - if (Class.forName("org.apache.logging.log4j.LogManager") != null) { - - } - } catch (Exception e) {} - */ + org.apache.logging.log4j.core.Logger coreLogger = (org.apache.logging.log4j.core.Logger) LogManager.getRootLogger(); + coreLogger.addFilter(new Log4JFilter()); + } catch (Exception e) { + } catch (NoClassDefFoundError e) {} } //Load MailApi diff --git a/src/main/java/fr/xephi/authme/ConsoleLogger.java b/src/main/java/fr/xephi/authme/ConsoleLogger.java index 47e11786..41f2f61c 100644 --- a/src/main/java/fr/xephi/authme/ConsoleLogger.java +++ b/src/main/java/fr/xephi/authme/ConsoleLogger.java @@ -15,11 +15,11 @@ import fr.xephi.authme.settings.Settings; public class ConsoleLogger { - private static final Logger log = Logger.getLogger("Minecraft"); + private static final Logger log = Logger.getLogger("AuthMe"); public static void info(String message) { if (AuthMe.getInstance().isEnabled()) { - log.info("[AuthMe] " + message); + log.info(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) + "] " + message; @@ -35,7 +35,7 @@ public class ConsoleLogger { public static void showError(String message) { if (AuthMe.getInstance().isEnabled()) { - log.severe("[AuthMe] ERROR: " + message); + log.severe(" 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; diff --git a/src/main/java/fr/xephi/authme/Log4JFilter.java b/src/main/java/fr/xephi/authme/Log4JFilter.java new file mode 100644 index 00000000..c6de672e --- /dev/null +++ b/src/main/java/fr/xephi/authme/Log4JFilter.java @@ -0,0 +1,104 @@ +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; +import org.apache.logging.log4j.core.Logger; +import org.apache.logging.log4j.message.Message; + +/** +* +* @author Xephi59 +*/ +public class Log4JFilter implements java.util.logging.Filter, 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 { + if (record == null || record.getMessage() == null) return Result.NEUTRAL; + String logM = record.getMessage().getFormattedMessage().toLowerCase(); + if (!logM.contains("issued server command:")) return Result.NEUTRAL; + 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 Result.NEUTRAL; + return Result.DENY; + } catch (NullPointerException npe) { + return Result.NEUTRAL; + } + } + + @Override + public Result filter(Logger arg0, Level arg1, Marker arg2, String message, + Object... arg4) { + try { + if (message == null) return Result.NEUTRAL; + String logM = message.toLowerCase(); + if (!logM.contains("issued server command:")) return Result.NEUTRAL; + 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 Result.NEUTRAL; + return Result.DENY; + } catch (NullPointerException npe) { + return Result.NEUTRAL; + } + } + + @Override + public Result filter(Logger arg0, Level arg1, Marker arg2, Object message, + Throwable arg4) { + try { + if (message == null) return Result.NEUTRAL; + String logM = message.toString().toLowerCase(); + if (!logM.contains("issued server command:")) return Result.NEUTRAL; + 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 Result.NEUTRAL; + return Result.DENY; + } catch (NullPointerException npe) { + return Result.NEUTRAL; + } + } + + @Override + public Result filter(Logger arg0, Level arg1, Marker arg2, Message message, + Throwable arg4) { + try { + if (message == null) return Result.NEUTRAL; + String logM = message.getFormattedMessage().toLowerCase(); + if (!logM.contains("issued server command:")) return Result.NEUTRAL; + 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 Result.NEUTRAL; + return Result.DENY; + } catch (NullPointerException npe) { + return Result.NEUTRAL; + } + } + + @Override + public Result getOnMatch() { + return Result.NEUTRAL; + } + + @Override + public Result getOnMismatch() { + return Result.NEUTRAL; + } + +} \ No newline at end of file diff --git a/src/main/java/fr/xephi/authme/Utils.java b/src/main/java/fr/xephi/authme/Utils.java index 4aef4532..f9ec7c19 100644 --- a/src/main/java/fr/xephi/authme/Utils.java +++ b/src/main/java/fr/xephi/authme/Utils.java @@ -13,7 +13,6 @@ import org.bukkit.World; import org.bukkit.entity.Player; import fr.xephi.authme.api.API; -import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.events.AuthMeTeleportEvent; import fr.xephi.authme.settings.Settings; @@ -100,7 +99,7 @@ public class Utils { } return false; } - public void packCoords(int x, int y, int z, String w, final Player pl) + public void packCoords(double x, double y, double z, String w, final Player pl) { World theWorld; if (w.equals("unavailableworld")) { @@ -111,14 +110,12 @@ public class Utils { if (theWorld == null) theWorld = pl.getWorld(); final World world = theWorld; - final int fY = y; - final Location locat = new Location(world, x, y + 0.4D, z); - final Location loc = locat.getBlock().getLocation(); + final Location locat = new Location(world, x, y, z); Bukkit.getScheduler().scheduleSyncDelayedTask(AuthMe.getInstance(), new Runnable() { @Override public void run() { - AuthMeTeleportEvent tpEvent = new AuthMeTeleportEvent(pl, loc); + AuthMeTeleportEvent tpEvent = new AuthMeTeleportEvent(pl, locat); AuthMe.getInstance().getServer().getPluginManager().callEvent(tpEvent); if(!tpEvent.isCancelled()) { if (!tpEvent.getTo().getChunk().isLoaded()) @@ -127,29 +124,6 @@ public class Utils { } } }); - - if (!PlayerCache.getInstance().isAuthenticated(pl.getName().toLowerCase())) { - id = Bukkit.getScheduler().scheduleSyncRepeatingTask(AuthMe.getInstance(), new Runnable() - { - @Override - public void run() { - if (!PlayerCache.getInstance().isAuthenticated(pl.getName().toLowerCase())) { - int current = (int)pl.getLocation().getY(); - World currentWorld = pl.getWorld(); - if (current != fY && world.getName() == currentWorld.getName()) { - pl.teleport(loc); - } - } - } - }, 1L, 20L); - Bukkit.getScheduler().scheduleSyncDelayedTask(AuthMe.getInstance(), new Runnable() - { - @Override - public void run() { - Bukkit.getScheduler().cancelTask(id); - } - }, 60L); - } } /* 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 ce1937d0..f7a7e85f 100644 --- a/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java +++ b/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java @@ -9,9 +9,9 @@ public class PlayerAuth { private String hash = ""; private String ip = "198.18.0.1"; private long lastLogin = 0; - private int x = 0; - private int y = 0; - private int z = 0; + private double x = 0; + private double y = 0; + private double z = 0; private String world = "world"; private String salt = ""; private String vBhash = null; @@ -28,7 +28,7 @@ public class PlayerAuth { this.realName = realName; } - public PlayerAuth(String nickname, int x, int y, int z, String world) { + public PlayerAuth(String nickname, double x, double y, double z, String world) { this.nickname = nickname; this.x = x; this.y = y; @@ -36,7 +36,7 @@ public class PlayerAuth { this.world = world; } - public PlayerAuth(String nickname, String hash, String ip, long lastLogin, int x, int y, int z, String world, String email, String realName) { + public PlayerAuth(String nickname, String hash, String ip, long lastLogin, double x, double y, double z, String world, String email, String realName) { this.nickname = nickname; this.hash = hash; this.ip = ip; @@ -49,7 +49,7 @@ public class PlayerAuth { this.realName = realName; } - public PlayerAuth(String nickname, String hash, String salt, int groupId, String ip, long lastLogin, int x, int y, int z, String world, String email, String realName) { + public PlayerAuth(String nickname, String hash, String salt, int groupId, String ip, long lastLogin, double x, double y, double z, String world, String email, String realName) { this.nickname = nickname; this.hash = hash; this.ip = ip; @@ -83,7 +83,7 @@ public class PlayerAuth { this.realName = realName; } - public PlayerAuth(String nickname, String hash, String salt, String ip, long lastLogin, int x, int y, int z, String world, String email, String realName) { + public PlayerAuth(String nickname, String hash, String salt, String ip, long lastLogin, double x, double y, double z, String world, String email, String realName) { this.nickname = nickname; this.hash = hash; this.ip = ip; @@ -123,26 +123,26 @@ public class PlayerAuth { return groupId; } - public int getQuitLocX() { + public double getQuitLocX() { return x; } - public int getQuitLocY() { + public double getQuitLocY() { return y; } - public int getQuitLocZ() { + public double getQuitLocZ() { return z; } public String getEmail() { return email; } - public void setQuitLocX(int x) { - this.x = x; + public void setQuitLocX(double d) { + this.x = d; } - public void setQuitLocY(int y) { - this.y = y; + public void setQuitLocY(double d) { + this.y = d; } - public void setQuitLocZ(int z) { - this.z = z; + public void setQuitLocZ(double d) { + this.z = d; } public long getLastLogin() { return lastLogin; 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 63b5d35c..6a0bb42f 100644 --- a/src/main/java/fr/xephi/authme/cache/backup/FileCache.java +++ b/src/main/java/fr/xephi/authme/cache/backup/FileCache.java @@ -49,12 +49,12 @@ public class FileCache { for (int i = 0; i < invstack.length; i++) { - int itemid = 0; + String itemid = "AIR"; int amount = 0; int durability = 0; String enchList = ""; if (invstack[i] != null) { - itemid = invstack[i].getTypeId(); + itemid = invstack[i].getType().name(); amount = invstack[i].getAmount(); durability = invstack[i].getDurability(); for(Enchantment e : invstack[i].getEnchantments().keySet()) { @@ -69,12 +69,12 @@ public class FileCache { ItemStack[] armorstack = playerData.getArmour(); for (int i = 0; i < armorstack.length; i++) { - int itemid = 0; + String itemid = "AIR"; int amount = 0; int durability = 0; String enchList = ""; if (armorstack[i] != null) { - itemid = armorstack[i].getTypeId(); + itemid = armorstack[i].getType().name(); amount = armorstack[i].getAmount(); durability = armorstack[i].getDurability(); for(Enchantment e : armorstack[i].getEnchantments().keySet()) { @@ -136,7 +136,7 @@ public class FileCache { } // can enchant item? size ofstring in file - 4 all / 2 = number of enchant if (in[0].equals("i")) { - stacki[i] = new ItemStack(Material.getMaterial(Integer.parseInt(in[1])), + stacki[i] = new ItemStack(Material.getMaterial(in[1]), Integer.parseInt(in[2]), Short.parseShort((in[3]))); if(in.length > 4 && !in[4].isEmpty()) { for(int k=4;k 4 && !in[4].isEmpty()) { for(int k=4;k