diff --git a/pom.xml b/pom.xml index 3aaa8692..7f791907 100644 --- a/pom.xml +++ b/pom.xml @@ -1,6 +1,6 @@ 4.0.0 - uk.org.whoami.authme.AuthMe + fr.xephi.authme.AuthMe AuthMe jar AuthMe @@ -24,12 +24,12 @@ - 2.9.4 + 3.0 org.bukkit bukkit - 1.6.2-R1.0 + 1.6.4-R0.1-SNAPSHOT net.milkbowl.vault diff --git a/src/main/java/uk/org/whoami/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java similarity index 78% rename from src/main/java/uk/org/whoami/authme/AuthMe.java rename to src/main/java/fr/xephi/authme/AuthMe.java index 88af05fe..0ab39478 100644 --- a/src/main/java/uk/org/whoami/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -1,25 +1,6 @@ -/* - * Copyright 2011 Sebastian Köhler . - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.org.whoami.authme; +package fr.xephi.authme; import java.io.File; -import java.io.IOException; -import java.sql.SQLException; -import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -34,40 +15,6 @@ import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.java.JavaPlugin; -import uk.org.whoami.authme.api.API; -import uk.org.whoami.authme.cache.auth.PlayerAuth; -import uk.org.whoami.authme.cache.auth.PlayerCache; -import uk.org.whoami.authme.cache.backup.FileCache; -import uk.org.whoami.authme.cache.limbo.LimboCache; -import uk.org.whoami.authme.cache.limbo.LimboPlayer; -import uk.org.whoami.authme.commands.AdminCommand; -import uk.org.whoami.authme.commands.CaptchaCommand; -import uk.org.whoami.authme.commands.ChangePasswordCommand; -import uk.org.whoami.authme.commands.EmailCommand; -import uk.org.whoami.authme.commands.LoginCommand; -import uk.org.whoami.authme.commands.LogoutCommand; -import uk.org.whoami.authme.commands.RegisterCommand; -import uk.org.whoami.authme.commands.UnregisterCommand; -import uk.org.whoami.authme.datasource.CacheDataSource; -import uk.org.whoami.authme.datasource.DataSource; -import uk.org.whoami.authme.datasource.FileDataSource; -import uk.org.whoami.authme.datasource.MiniConnectionPoolManager.TimeoutException; -import uk.org.whoami.authme.datasource.MySQLDataSource; -import uk.org.whoami.authme.listener.AuthMeBlockListener; -import uk.org.whoami.authme.listener.AuthMeChestShopListener; -import uk.org.whoami.authme.listener.AuthMeEntityListener; -import uk.org.whoami.authme.listener.AuthMePlayerListener; -import uk.org.whoami.authme.listener.AuthMeSpoutListener; -import uk.org.whoami.authme.plugin.manager.BungeeCordMessage; -import uk.org.whoami.authme.plugin.manager.CitizensCommunicator; -import uk.org.whoami.authme.plugin.manager.CombatTagComunicator; -import uk.org.whoami.authme.plugin.manager.EssSpawn; -import uk.org.whoami.authme.settings.Messages; -import uk.org.whoami.authme.settings.PlayersLogs; -import uk.org.whoami.authme.settings.Settings; -import uk.org.whoami.authme.threads.FlatFileThread; -import uk.org.whoami.authme.threads.MySQLThread; -import uk.org.whoami.authme.threads.SQLiteThread; import me.muizers.Notifications.Notifications; import net.citizensnpcs.Citizens; @@ -76,11 +23,47 @@ import net.milkbowl.vault.permission.Permission; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Server; +import org.bukkit.World; import com.onarandombox.MultiverseCore.MultiverseCore; -import uk.org.whoami.authme.commands.PasspartuCommand; -import uk.org.whoami.authme.datasource.SqliteDataSource; +import fr.xephi.authme.api.API; +import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.cache.backup.FileCache; +import fr.xephi.authme.cache.limbo.LimboCache; +import fr.xephi.authme.cache.limbo.LimboPlayer; +import fr.xephi.authme.commands.AdminCommand; +import fr.xephi.authme.commands.CaptchaCommand; +import fr.xephi.authme.commands.ChangePasswordCommand; +import fr.xephi.authme.commands.EmailCommand; +import fr.xephi.authme.commands.LoginCommand; +import fr.xephi.authme.commands.LogoutCommand; +import fr.xephi.authme.commands.PasspartuCommand; +import fr.xephi.authme.commands.RegisterCommand; +import fr.xephi.authme.commands.UnregisterCommand; +import fr.xephi.authme.datasource.CacheDataSource; +import fr.xephi.authme.datasource.DataSource; +import fr.xephi.authme.datasource.FileDataSource; +import fr.xephi.authme.datasource.MySQLDataSource; +import fr.xephi.authme.datasource.SqliteDataSource; +import fr.xephi.authme.listener.AuthMeBlockListener; +import fr.xephi.authme.listener.AuthMeChestShopListener; +import fr.xephi.authme.listener.AuthMeEntityListener; +import fr.xephi.authme.listener.AuthMePlayerListener; +import fr.xephi.authme.listener.AuthMeSpoutListener; +import fr.xephi.authme.plugin.manager.BungeeCordMessage; +import fr.xephi.authme.plugin.manager.CitizensCommunicator; +import fr.xephi.authme.plugin.manager.CombatTagComunicator; +import fr.xephi.authme.plugin.manager.EssSpawn; +import fr.xephi.authme.settings.Messages; +import fr.xephi.authme.settings.PlayersLogs; +import fr.xephi.authme.settings.Settings; +import fr.xephi.authme.settings.Spawn; +import fr.xephi.authme.threads.FlatFileThread; +import fr.xephi.authme.threads.MySQLThread; +import fr.xephi.authme.threads.SQLiteThread; + public class AuthMe extends JavaPlugin { @@ -108,8 +91,7 @@ public class AuthMe extends JavaPlugin { public HashMap captcha = new HashMap(); public HashMap cap = new HashMap(); public HashMap realIp = new HashMap(); - public List premium = new ArrayList(); - public MultiverseCore mv = null; + public MultiverseCore multiverse = null; public Location essentialsSpawn; public Thread databaseThread = null; @@ -177,7 +159,7 @@ public class AuthMe extends JavaPlugin { } try { database = new FileDataSource(); - } catch (IOException ex) { + } catch (Exception ex) { ConsoleLogger.showError(ex.getMessage()); if (Settings.isStopEnabled) { ConsoleLogger.showError("Can't use FLAT FILE... SHUTDOWN..."); @@ -198,7 +180,7 @@ public class AuthMe extends JavaPlugin { } try { database = new MySQLDataSource(); - } catch (ClassNotFoundException ex) { + } catch (Exception ex) { ConsoleLogger.showError(ex.getMessage()); if (Settings.isStopEnabled) { ConsoleLogger.showError("Can't use MySQL... Please input correct MySQL informations ! SHUTDOWN..."); @@ -207,24 +189,6 @@ public class AuthMe extends JavaPlugin { if (!Settings.isStopEnabled) this.getServer().getPluginManager().disablePlugin(this); return; - } catch (SQLException ex) { - ConsoleLogger.showError(ex.getMessage()); - if (Settings.isStopEnabled) { - ConsoleLogger.showError("Can't use MySQL... Please input correct MySQL informations ! SHUTDOWN..."); - server.shutdown(); - } - if (!Settings.isStopEnabled) - this.getServer().getPluginManager().disablePlugin(this); - return; - } catch(TimeoutException ex) { - ConsoleLogger.showError(ex.getMessage()); - if (Settings.isStopEnabled) { - ConsoleLogger.showError("Can't use MySQL... Please input correct MySQL informations ! SHUTDOWN..."); - server.shutdown(); - } - if (!Settings.isStopEnabled) - this.getServer().getPluginManager().disablePlugin(this); - return; } break; case SQLITE: @@ -237,16 +201,7 @@ public class AuthMe extends JavaPlugin { } try { database = new SqliteDataSource(); - } catch (ClassNotFoundException ex) { - ConsoleLogger.showError(ex.getMessage()); - if (Settings.isStopEnabled) { - ConsoleLogger.showError("Can't use SQLITE... ! SHUTDOWN..."); - server.shutdown(); - } - if (!Settings.isStopEnabled) - this.getServer().getPluginManager().disablePlugin(this); - return; - } catch (SQLException ex) { + } catch (Exception ex) { ConsoleLogger.showError(ex.getMessage()); if (Settings.isStopEnabled) { ConsoleLogger.showError("Can't use SQLITE... ! SHUTDOWN..."); @@ -328,6 +283,8 @@ public class AuthMe extends JavaPlugin { } } catch (NullPointerException ex) { } + if (Settings.usePurge) + autoPurge(); ConsoleLogger.info("Authme " + this.getDescription().getVersion() + " enabled"); } @@ -365,19 +322,19 @@ public class AuthMe extends JavaPlugin { private void checkMultiverse() { if(!Settings.multiverse) { - mv = null; + multiverse = null; return; } if (this.getServer().getPluginManager().getPlugin("Multiverse-Core") != null && this.getServer().getPluginManager().getPlugin("Multiverse-Core").isEnabled()) { try { - mv = (MultiverseCore) this.getServer().getPluginManager().getPlugin("Multiverse-Core"); + multiverse = (MultiverseCore) this.getServer().getPluginManager().getPlugin("Multiverse-Core"); ConsoleLogger.info("Hook with Multiverse-Core for SpawnLocations"); } catch (NullPointerException npe) { - mv = null; + multiverse = null; } catch (ClassCastException cce) { - mv = null; + multiverse = null; } catch (NoClassDefFoundError ncdfe) { - mv = null; + multiverse = null; } } } @@ -579,5 +536,65 @@ public class AuthMe extends JavaPlugin { } return false; } + + private void autoPurge() { + if (!Settings.usePurge) { + return; + } + long days = Settings.purgeDelay * 86400000; + long until = new Date().getTime() - days; + List cleared = this.database.autoPurgeDatabase(until); + ConsoleLogger.info("AutoPurgeDatabase : " + cleared.size() + " accounts removed."); + if (cleared.isEmpty()) + return; + if (Settings.purgeEssentialsFile && this.ess != null) + purgeEssentials(cleared); + if (Settings.purgePlayerDat) + purgeDat(cleared); + } + private void purgeDat(List cleared) { + int i = 0; + for (String name : cleared) { + org.bukkit.OfflinePlayer player = Bukkit.getOfflinePlayer(name); + if (player == null) continue; + String playerName = player.getName(); + File playerFile = new File (this.getServer().getWorldContainer() + File.separator + Settings.defaultWorld + File.separator + "players" + File.separator + playerName + ".dat"); + if (playerFile.exists()) { + playerFile.delete(); + i++; + } + } + ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " .dat Files"); + } + + private void purgeEssentials(List cleared) { + int i = 0; + for (String name : cleared) { + File playerFile = new File(this.ess.getDataFolder() + File.separator + "userdata" + File.separator + name + ".yml"); + if (playerFile.exists()) { + playerFile.delete(); + i++; + } + } + ConsoleLogger.info("AutoPurgeDatabase : Remove " + i + " EssentialsFiles"); + } + + public Location getSpawnLocation(World world) { + Location spawnLoc = world.getSpawnLocation(); + if (multiverse != null) { + try { + spawnLoc = multiverse.getMVWorldManager().getMVWorld(world).getSpawnLocation(); + } catch (NullPointerException npe) { + } catch (ClassCastException cce) { + } catch (NoClassDefFoundError ncdfe) { + } + } + if (essentialsSpawn != null) { + spawnLoc = essentialsSpawn; + } + if (Spawn.getInstance().getLocation() != null) + spawnLoc = Spawn.getInstance().getLocation(); + return spawnLoc; + } } diff --git a/src/main/java/uk/org/whoami/authme/ConsoleFilter.java b/src/main/java/fr/xephi/authme/ConsoleFilter.java similarity index 97% rename from src/main/java/uk/org/whoami/authme/ConsoleFilter.java rename to src/main/java/fr/xephi/authme/ConsoleFilter.java index 15077152..689bc5f6 100644 --- a/src/main/java/uk/org/whoami/authme/ConsoleFilter.java +++ b/src/main/java/fr/xephi/authme/ConsoleFilter.java @@ -1,4 +1,4 @@ -package uk.org.whoami.authme; +package fr.xephi.authme; import java.util.logging.Filter; import java.util.logging.LogRecord; diff --git a/src/main/java/uk/org/whoami/authme/ConsoleLogger.java b/src/main/java/fr/xephi/authme/ConsoleLogger.java similarity index 74% rename from src/main/java/uk/org/whoami/authme/ConsoleLogger.java rename to src/main/java/fr/xephi/authme/ConsoleLogger.java index e3b9f1b2..47e11786 100644 --- a/src/main/java/uk/org/whoami/authme/ConsoleLogger.java +++ b/src/main/java/fr/xephi/authme/ConsoleLogger.java @@ -1,20 +1,4 @@ -/* - * Copyright 2011 Sebastian Köhler . - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.org.whoami.authme; +package fr.xephi.authme; import java.io.BufferedWriter; import java.io.File; @@ -26,7 +10,8 @@ import java.util.logging.Logger; import org.bukkit.Bukkit; -import uk.org.whoami.authme.settings.Settings; +import fr.xephi.authme.settings.Settings; + public class ConsoleLogger { diff --git a/src/main/java/fr/xephi/authme/Management.java b/src/main/java/fr/xephi/authme/Management.java new file mode 100644 index 00000000..6f718635 --- /dev/null +++ b/src/main/java/fr/xephi/authme/Management.java @@ -0,0 +1,436 @@ +package fr.xephi.authme; + +import java.util.Date; +import java.util.List; + +import me.muizers.Notifications.Notification; + +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.plugin.PluginManager; + +import fr.xephi.authme.api.API; +import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.cache.backup.FileCache; +import fr.xephi.authme.cache.limbo.LimboCache; +import fr.xephi.authme.cache.limbo.LimboPlayer; +import fr.xephi.authme.datasource.DataSource; +import fr.xephi.authme.events.AuthMeTeleportEvent; +import fr.xephi.authme.events.LoginEvent; +import fr.xephi.authme.events.RestoreInventoryEvent; +import fr.xephi.authme.events.SpawnTeleportEvent; +import fr.xephi.authme.listener.AuthMePlayerListener; +import fr.xephi.authme.security.PasswordSecurity; +import fr.xephi.authme.security.RandomString; +import fr.xephi.authme.settings.Messages; +import fr.xephi.authme.settings.PlayersLogs; +import fr.xephi.authme.settings.Settings; + +/** + * + * @authors Xephi59, Possible + * + */ +public class Management { + private Messages m = Messages.getInstance(); + private PlayersLogs pllog = PlayersLogs.getInstance(); + private Utils utils = Utils.getInstance(); + private FileCache playerCache = new FileCache(); + private DataSource database; + public AuthMe plugin; + public static RandomString rdm = new RandomString(Settings.captchaLength); + public PluginManager pm; + + public Management(DataSource database, AuthMe plugin) { + this.database = database; + this.plugin = plugin; + this.pm = plugin.getServer().getPluginManager(); + } + + public void performLogin(final Player player, final String password, final boolean passpartu) { + if (passpartu) { + // Passpartu-Login Bypasses Password-Authentication. + Bukkit.getScheduler().runTaskAsynchronously(plugin, new AsyncronousPasspartuLogin(player)); + } else { + Bukkit.getScheduler().runTaskAsynchronously(plugin, new AsyncronousLogin(player, password)); + } + } + + class AsyncronousLogin implements Runnable { + protected Player player; + protected String name; + protected String password; + + public AsyncronousLogin(Player player, String password) { + this.player = player; + this.password = password; + name = player.getName().toLowerCase(); + } + + protected String getIP() { + String ip = player.getAddress().getAddress().getHostAddress(); + if (Settings.bungee) { + if (plugin.realIp.containsKey(name)) + ip = plugin.realIp.get(name); + } + return ip; + } + protected boolean needsCaptcha() { + if (Settings.useCaptcha) { + if (!plugin.captcha.containsKey(name)) { + plugin.captcha.put(name, 1); + } else { + int i = plugin.captcha.get(name) + 1; + plugin.captcha.remove(name); + plugin.captcha.put(name, i); + } + if (plugin.captcha.containsKey(name) && plugin.captcha.get(name) > Settings.maxLoginTry) { + player.sendMessage(m._("need_captcha")); + plugin.cap.put(name, rdm.nextString()); + player.sendMessage("Type : /captcha " + plugin.cap.get(name)); + return true; + } else if (plugin.captcha.containsKey(name) && plugin.captcha.get(name) > Settings.maxLoginTry) { + try { + plugin.captcha.remove(name); + plugin.cap.remove(name); + } catch (NullPointerException npe) { + } + } + } + return false; + } + + /** + * Checks the precondition for authentication (like user known) and returns the playerAuth-State + */ + protected PlayerAuth preAuth() { + if (PlayerCache.getInstance().isAuthenticated(name)) { + player.sendMessage(m._("logged_in")); + return null; + } + if (!database.isAuthAvailable(name)) { + player.sendMessage(m._("user_unknown")); + return null; + } + PlayerAuth pAuth = database.getAuth(name); + if (pAuth == null) { + player.sendMessage(m._("user_unknown")); + return null; + } + if (!Settings.getMySQLColumnGroup.isEmpty() && pAuth.getGroupId() == Settings.getNonActivatedGroup) { + player.sendMessage(m._("vb_nonActiv")); + return null; + } + return pAuth; + } + + @Override + public void run() { + PlayerAuth pAuth = preAuth(); + if (pAuth == null || needsCaptcha()) + return; + + String hash = pAuth.getHash(); + String email = pAuth.getEmail(); + boolean passwordVerified = true; + try { + passwordVerified = PasswordSecurity.comparePasswordWithHash(password, hash, name); + } catch (Exception ex) { + ConsoleLogger.showError(ex.getMessage()); + player.sendMessage(m._("error")); + return; + } + if (passwordVerified && player.isOnline()) { + PlayerAuth auth = new PlayerAuth(name, hash, getIP(), new Date().getTime(), email); + 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) { + if (plugin.captcha.containsKey(name)) { + plugin.captcha.remove(name); + } + if (plugin.cap.containsKey(name)) { + plugin.cap.remove(name); + } + } + + player.setNoDamageTicks(0); + player.sendMessage(m._("login")); + + displayOtherAccounts(auth); + + if (!Settings.noConsoleSpam) + ConsoleLogger.info(player.getName() + " logged in!"); + + if (plugin.notifications != null) { + plugin.notifications.showNotification(new Notification("[AuthMe] " + player.getName() + " logged in!")); + } + + // makes player isLoggedin via API + PlayerCache.getInstance().addPlayer(auth); + + // As the scheduling executes the Task most likely after the current task, we schedule it in the end + // so that we can be sure, and have not to care if it might be processed in other order. + ProcessSyncronousPlayerLogin syncronousPlayerLogin = new ProcessSyncronousPlayerLogin(player); + if (syncronousPlayerLogin.getLimbo() != null) { + player.getServer().getScheduler().cancelTask(syncronousPlayerLogin.getLimbo().getTimeoutTaskId()); + player.getServer().getScheduler().cancelTask(syncronousPlayerLogin.getLimbo().getMessageTaskId()); + } + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, syncronousPlayerLogin); + } else if (player.isOnline()) { + if (!Settings.noConsoleSpam) + ConsoleLogger.info(player.getName() + " used the wrong password"); + if (Settings.isKickOnWrongPasswordEnabled) { + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + if (AuthMePlayerListener.gameMode != null && AuthMePlayerListener.gameMode.containsKey(name)) { + player.setGameMode(GameMode.getByValue(AuthMePlayerListener.gameMode.get(name))); + } + player.kickPlayer(m._("wrong_pwd")); + } + }); + } else { + player.sendMessage(m._("wrong_pwd")); + return; + } + } else { + ConsoleLogger.showError("Player " + name + " wasn't online during login process, aborted... "); + } + } + } + + class AsyncronousPasspartuLogin extends AsyncronousLogin implements Runnable { + public AsyncronousPasspartuLogin(Player player) { + super(player, null); + } + + @Override + public void run() { + PlayerAuth pAuth = preAuth(); + if (pAuth == null) + return; + + String hash = pAuth.getHash(); + String email = pAuth.getEmail(); + + PlayerAuth auth = new PlayerAuth(name, hash, getIP(), new Date().getTime(), email); + 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) { + if (plugin.captcha.containsKey(name)) { + plugin.captcha.remove(name); + } + if (plugin.cap.containsKey(name)) { + plugin.cap.remove(name); + } + } + + player.setNoDamageTicks(0); + player.sendMessage(m._("login")); + + displayOtherAccounts(auth); + + if (!Settings.noConsoleSpam) + ConsoleLogger.info(player.getName() + " logged in!"); + + if (plugin.notifications != null) { + plugin.notifications.showNotification(new Notification("[AuthMe] " + player.getName() + " logged in!")); + } + + // makes player isLoggedin via API + PlayerCache.getInstance().addPlayer(auth); + + // As the scheduling executes the Task most likely after the current task, we schedule it in the end + // so that we can be sure, and have not to care if it might be processed in other order. + ProcessSyncronousPlayerLogin syncronousPlayerLogin = new ProcessSyncronousPlayerLogin(player); + if (syncronousPlayerLogin.getLimbo() != null) { + player.getServer().getScheduler().cancelTask(syncronousPlayerLogin.getLimbo().getTimeoutTaskId()); + player.getServer().getScheduler().cancelTask(syncronousPlayerLogin.getLimbo().getMessageTaskId()); + } + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, syncronousPlayerLogin); + } + } + + class ProcessSyncronousPlayerLogin implements Runnable { + private LimboPlayer limbo; + private Player player; + private String name; + private PlayerAuth auth; + public ProcessSyncronousPlayerLogin(Player player) { + this.player = player; + this.name = player.getName().toLowerCase(); + this.limbo = LimboCache.getInstance().getLimboPlayer(name); + this.auth = database.getAuth(name); + } + + public LimboPlayer getLimbo() { + return limbo; + } + + protected void restoreOpState() { + player.setOp(limbo.getOperator()); + if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) { + player.setAllowFlight(limbo.isFlying()); + player.setFlying(limbo.isFlying()); + } + } + protected void packQuitLocation() { + utils.packCoords(auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ(), auth.getWorld(), player); + } + protected void teleportBackFromSpawn() { + AuthMeTeleportEvent tpEvent = new AuthMeTeleportEvent(player, limbo.getLoc()); + pm.callEvent(tpEvent); + if (!tpEvent.isCancelled()) { + Location fLoc = tpEvent.getTo(); + if (!fLoc.getChunk().isLoaded()) { + fLoc.getChunk().load(); + } + player.teleport(fLoc); + } + } + protected void teleportToSpawn() { + Location spawnL = plugin.getSpawnLocation(player.getWorld()); + SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawnL, true); + pm.callEvent(tpEvent); + if (!tpEvent.isCancelled()) { + Location fLoc = tpEvent.getTo(); + if (!fLoc.getChunk().isLoaded()) { + fLoc.getChunk().load(); + } + player.teleport(fLoc); + } + } + protected void restoreInventory() { + RestoreInventoryEvent event = new RestoreInventoryEvent(player, limbo.getInventory(), limbo.getArmour()); + Bukkit.getServer().getPluginManager().callEvent(event); + if (!event.isCancelled()) { + API.setPlayerInventory(player, event.getInventory(), event.getArmor()); + } + } + + @Override + public void run() { + // Limbo contains the State of the Player before /login + if (limbo != null) { + // Op & Flying + restoreOpState(); + + /* + * Restore Inventories and GameMode + * We need to restore them before teleport the player + * Cause in AuthMePlayerListener, we call ProtectInventoryEvent after Teleporting + * Also it's the current world inventory ! + */ + if (!Settings.forceOnlyAfterLogin) { + player.setGameMode(GameMode.getByValue(limbo.getGameMode())); + // Inventory - Make it after restore GameMode , cause we need to restore the + // right inventory in the right gamemode + if (Settings.protectInventoryBeforeLogInEnabled && player.hasPlayedBefore()) { + restoreInventory(); + } + } + else { + // Inventory - Make it before force the survival GameMode to cancel all + // inventory problem + if (Settings.protectInventoryBeforeLogInEnabled && player.hasPlayedBefore()) { + restoreInventory(); + } + player.setGameMode(GameMode.SURVIVAL); + } + + // Teleport + if (Settings.isTeleportToSpawnEnabled && !Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName())) { + if (Settings.isSaveQuitLocationEnabled && auth.getQuitLocY() != 0) { + packQuitLocation(); + } else { + teleportBackFromSpawn(); + } + } else if (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName())) { + teleportToSpawn(); + } else if (Settings.isSaveQuitLocationEnabled && auth.getQuitLocY() != 0) { + packQuitLocation(); + } else { + teleportBackFromSpawn(); + } + + // Re-Force Survival GameMode if we need due to world change specification + if (Settings.isForceSurvivalModeEnabled) + player.setGameMode(GameMode.SURVIVAL); + + // Cleanup no longer used temporary data + LimboCache.getInstance().deleteLimboPlayer(name); + if (playerCache.doesCacheExist(name)) { + playerCache.removeCache(name); + } + } + // The Loginevent now fires (as intended) after everything is processed + Bukkit.getServer().getPluginManager().callEvent(new LoginEvent(player, true)); + player.saveData(); + } + } + + private void displayOtherAccounts(PlayerAuth auth) { + if (!Settings.displayOtherAccounts) { + return; + } + if (auth == null) { + return; + } + if (this.database.getAllAuthsByName(auth).isEmpty() || this.database.getAllAuthsByName(auth) == null) { + return; + } + if (this.database.getAllAuthsByName(auth).size() == 1) { + return; + } + List accountList = this.database.getAllAuthsByName(auth); + String message = "[AuthMe] "; + int i = 0; + for (String account : accountList) { + i++; + message = message + account; + if (i != accountList.size()) { + message = message + ", "; + } else { + message = message + "."; + } + } + for (Player player : AuthMe.getInstance().getServer().getOnlinePlayers()) { + if (plugin.authmePermissible(player, "authme.seeOtherAccounts")) { + player.sendMessage("[AuthMe] The player " + auth.getNickname() + " has " + + String.valueOf(accountList.size()) + " accounts"); + player.sendMessage(message); + } + } + } +} diff --git a/src/main/java/uk/org/whoami/authme/PerformBackup.java b/src/main/java/fr/xephi/authme/PerformBackup.java similarity index 95% rename from src/main/java/uk/org/whoami/authme/PerformBackup.java rename to src/main/java/fr/xephi/authme/PerformBackup.java index dd69ceb2..8f3ecfc0 100644 --- a/src/main/java/uk/org/whoami/authme/PerformBackup.java +++ b/src/main/java/fr/xephi/authme/PerformBackup.java @@ -1,8 +1,4 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package uk.org.whoami.authme; +package fr.xephi.authme; import java.io.File; import java.io.FileInputStream; @@ -12,7 +8,8 @@ import java.io.InputStream; import java.io.OutputStream; import java.text.SimpleDateFormat; import java.util.Date; -import uk.org.whoami.authme.settings.Settings; + +import fr.xephi.authme.settings.Settings; /** * diff --git a/src/main/java/uk/org/whoami/authme/SendMailSSL.java b/src/main/java/fr/xephi/authme/SendMailSSL.java similarity index 95% rename from src/main/java/uk/org/whoami/authme/SendMailSSL.java rename to src/main/java/fr/xephi/authme/SendMailSSL.java index dc8cbb89..c2672b4c 100644 --- a/src/main/java/uk/org/whoami/authme/SendMailSSL.java +++ b/src/main/java/fr/xephi/authme/SendMailSSL.java @@ -1,4 +1,4 @@ -package uk.org.whoami.authme; +package fr.xephi.authme; import java.io.UnsupportedEncodingException; import java.util.Date; @@ -13,8 +13,8 @@ import javax.mail.internet.MimeMessage; import org.bukkit.Bukkit; -import uk.org.whoami.authme.cache.auth.PlayerAuth; -import uk.org.whoami.authme.settings.Settings; +import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.settings.Settings; /** * diff --git a/src/main/java/uk/org/whoami/authme/Utils.java b/src/main/java/fr/xephi/authme/Utils.java similarity index 69% rename from src/main/java/uk/org/whoami/authme/Utils.java rename to src/main/java/fr/xephi/authme/Utils.java index b1ea1d71..ccc301ad 100644 --- a/src/main/java/uk/org/whoami/authme/Utils.java +++ b/src/main/java/fr/xephi/authme/Utils.java @@ -1,4 +1,4 @@ -package uk.org.whoami.authme; +package fr.xephi.authme; import java.io.File; import java.io.FileWriter; @@ -10,20 +10,16 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitTask; -import uk.org.whoami.authme.events.AuthMeTeleportEvent; -import uk.org.whoami.authme.settings.Settings; +import fr.xephi.authme.api.API; +import fr.xephi.authme.events.AuthMeTeleportEvent; +import fr.xephi.authme.settings.Settings; -/** - * - * @author stefano - */ public class Utils { private String currentGroup; private static Utils singleton; private String unLoggedGroup = Settings.getUnloggedinGroup; - BukkitTask id; + int id; public void setGroup(Player player, groupType group) { if (!player.isOnline()) @@ -43,13 +39,12 @@ public class Utils { AuthMe.permission.playerRemoveGroup(player, currentGroup); AuthMe.permission.playerAddGroup(player, Settings.getRegisteredGroup); break; - } + } } return; } public String removeAll(Player player) { - if(!Utils.getInstance().useGroupSystem()){ return null; } @@ -64,9 +59,9 @@ public class Utils { } public boolean addNormal(Player player, String group) { - if(!Utils.getInstance().useGroupSystem()){ + 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; } @@ -74,7 +69,6 @@ public class Utils { } private String hasPermOnJoin(Player player) { - Iterator iter = Settings.getJoinPermissions.iterator(); while (iter.hasNext()) { String permission = iter.next(); @@ -86,25 +80,19 @@ public class Utils { } 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 static Utils getInstance() { - singleton = new Utils(); - return singleton; - } + } private boolean useGroupSystem() { - if(Settings.isPermissionCheckEnabled && !Settings.getUnloggedinGroup.isEmpty()) { return true; } return false; @@ -122,7 +110,7 @@ public class Utils { theWorld = pl.getWorld(); final World world = theWorld; final int fY = y; - final Location locat = new Location(world, x, y + 0.6D, z); + final Location locat = new Location(world, x, y + 0.4D, z); final Location loc = locat.getBlock().getLocation(); Bukkit.getScheduler().scheduleSyncDelayedTask(AuthMe.getInstance(), new Runnable() { @@ -138,7 +126,7 @@ public class Utils { } }); - id = Bukkit.getScheduler().runTaskTimer(AuthMe.authme, new Runnable() + id = Bukkit.getScheduler().scheduleSyncRepeatingTask(AuthMe.getInstance(), new Runnable() { @Override public void run() { @@ -149,12 +137,12 @@ public class Utils { } } }, 1L, 20L); - Bukkit.getScheduler().scheduleSyncDelayedTask(AuthMe.authme, new Runnable() + Bukkit.getScheduler().scheduleSyncDelayedTask(AuthMe.getInstance(), new Runnable() { - @Override - public void run() { - id.cancel(); - } + @Override + public void run() { + Bukkit.getScheduler().cancelTask(id); + } }, 60L); } @@ -163,71 +151,71 @@ public class Utils { * */ public boolean obtainToken() { - File file = new File("plugins/AuthMe/passpartu.token"); - - if (file.exists()) - file.delete(); + File file = new File("plugins/AuthMe/passpartu.token"); + if (file.exists()) + file.delete(); FileWriter writer = null; try { file.createNewFile(); writer = new FileWriter(file); - String token = generateToken(); - writer.write(token+":"+System.currentTimeMillis()/1000+"\r\n"); - writer.flush(); - ConsoleLogger.info("[AuthMe] Security passpartu token: "+ token); - writer.close(); - return true; - } catch(Exception e) { - e.printStackTrace(); - } + String token = generateToken(); + writer.write(token + ":" + System.currentTimeMillis() / 1000 + API.newline); + writer.flush(); + ConsoleLogger.info("[AuthMe] Security passpartu token: "+ token); + writer.close(); + return true; + } catch(Exception e) { + e.printStackTrace(); + } return false; } /* - * Read Toekn + * Read Token */ public boolean readToken(String inputToken) { File file = new File("plugins/AuthMe/passpartu.token"); - if (!file.exists()) + if (!file.exists()) return false; - if (inputToken.isEmpty() ) + if (inputToken.isEmpty()) return false; Scanner reader = null; try { reader = new Scanner(file); while (reader.hasNextLine()) { final String line = reader.nextLine(); - if (line.contains(":")) { - String[] tokenInfo = line.split(":"); - if(tokenInfo[0].equals(inputToken) && System.currentTimeMillis()/1000-30 <= Integer.parseInt(tokenInfo[1]) ) { - file.delete(); - reader.close(); - return true; - } - } - } - } catch(Exception e) { - e.printStackTrace(); - } - reader.close(); - return false; + if (line.contains(":")) { + String[] tokenInfo = line.split(":"); + if(tokenInfo[0].equals(inputToken) && System.currentTimeMillis()/1000-30 <= Integer.parseInt(tokenInfo[1]) ) { + file.delete(); + reader.close(); + return true; + } + } + } + } catch(Exception e) { + e.printStackTrace(); + } + reader.close(); + return false; } + /* * Generate Random Token */ private String generateToken() { - // obtain new random token - Random rnd = new Random (); - char[] arr = new char[5]; - for (int i=0; i<5; i++) { - int n = rnd.nextInt (36); - arr[i] = (char) (n < 10 ? '0'+n : 'a'+n-10); - } - return new String(arr); - } + // obtain new random token + Random rnd = new Random (); + char[] arr = new char[5]; + for (int i=0; i<5; i++) { + int n = rnd.nextInt (36); + arr[i] = (char) (n < 10 ? '0'+n : 'a'+n-10); + } + return new String(arr); + } public enum groupType { UNREGISTERED, REGISTERED, NOTLOGGEDIN, LOGGEDIN diff --git a/src/main/java/uk/org/whoami/authme/api/API.java b/src/main/java/fr/xephi/authme/api/API.java similarity index 89% rename from src/main/java/uk/org/whoami/authme/api/API.java rename to src/main/java/fr/xephi/authme/api/API.java index 851f2c62..723b23f9 100644 --- a/src/main/java/uk/org/whoami/authme/api/API.java +++ b/src/main/java/fr/xephi/authme/api/API.java @@ -1,4 +1,4 @@ -package uk.org.whoami.authme.api; +package fr.xephi.authme.api; import java.security.NoSuchAlgorithmException; import org.bukkit.Bukkit; @@ -7,17 +7,19 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.Plugin; -import uk.org.whoami.authme.AuthMe; -import uk.org.whoami.authme.Utils; -import uk.org.whoami.authme.cache.auth.PlayerAuth; -import uk.org.whoami.authme.cache.auth.PlayerCache; -import uk.org.whoami.authme.datasource.DataSource; -import uk.org.whoami.authme.plugin.manager.CombatTagComunicator; -import uk.org.whoami.authme.security.PasswordSecurity; -import uk.org.whoami.authme.settings.Settings; +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.Utils; +import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.datasource.DataSource; +import fr.xephi.authme.plugin.manager.CombatTagComunicator; +import fr.xephi.authme.security.PasswordSecurity; +import fr.xephi.authme.settings.Settings; + public class API { + public static final String newline = System.getProperty("line.separator"); public static AuthMe instance; public static DataSource database; diff --git a/src/main/java/uk/org/whoami/authme/cache/auth/PlayerAuth.java b/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java similarity index 86% rename from src/main/java/uk/org/whoami/authme/cache/auth/PlayerAuth.java rename to src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java index c4016ef6..6b6d477a 100644 --- a/src/main/java/uk/org/whoami/authme/cache/auth/PlayerAuth.java +++ b/src/main/java/fr/xephi/authme/cache/auth/PlayerAuth.java @@ -1,23 +1,7 @@ -/* - * Copyright 2011 Sebastian Köhler . - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +package fr.xephi.authme.cache.auth; -package uk.org.whoami.authme.cache.auth; - -import uk.org.whoami.authme.security.PasswordSecurity; -import uk.org.whoami.authme.settings.Settings; +import fr.xephi.authme.security.HashAlgorithm; +import fr.xephi.authme.settings.Settings; public class PlayerAuth { @@ -134,7 +118,7 @@ public class PlayerAuth { } public String getHash() { - if(!salt.isEmpty() && Settings.getPasswordHash == PasswordSecurity.HashAlgorithm.MD5VB) { + if(!salt.isEmpty() && Settings.getPasswordHash == HashAlgorithm.MD5VB) { vBhash = "$MD5vb$"+salt+"$"+hash; return vBhash; } diff --git a/src/main/java/uk/org/whoami/authme/cache/auth/PlayerCache.java b/src/main/java/fr/xephi/authme/cache/auth/PlayerCache.java similarity index 59% rename from src/main/java/uk/org/whoami/authme/cache/auth/PlayerCache.java rename to src/main/java/fr/xephi/authme/cache/auth/PlayerCache.java index 34ca5a7c..9acaae44 100644 --- a/src/main/java/uk/org/whoami/authme/cache/auth/PlayerCache.java +++ b/src/main/java/fr/xephi/authme/cache/auth/PlayerCache.java @@ -1,20 +1,4 @@ -/* - * Copyright 2011 Sebastian Köhler . - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.org.whoami.authme.cache.auth; +package fr.xephi.authme.cache.auth; import java.util.HashMap; diff --git a/src/main/java/uk/org/whoami/authme/cache/backup/DataFileCache.java b/src/main/java/fr/xephi/authme/cache/backup/DataFileCache.java similarity index 82% rename from src/main/java/uk/org/whoami/authme/cache/backup/DataFileCache.java rename to src/main/java/fr/xephi/authme/cache/backup/DataFileCache.java index e443f1a6..f2f20b6b 100644 --- a/src/main/java/uk/org/whoami/authme/cache/backup/DataFileCache.java +++ b/src/main/java/fr/xephi/authme/cache/backup/DataFileCache.java @@ -1,13 +1,5 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package uk.org.whoami.authme.cache.backup; +package fr.xephi.authme.cache.backup; -/** - * - * @author stefano - */ import org.bukkit.inventory.ItemStack; public class DataFileCache { diff --git a/src/main/java/uk/org/whoami/authme/cache/backup/FileCache.java b/src/main/java/fr/xephi/authme/cache/backup/FileCache.java similarity index 95% rename from src/main/java/uk/org/whoami/authme/cache/backup/FileCache.java rename to src/main/java/fr/xephi/authme/cache/backup/FileCache.java index c4110cfb..02f35dec 100644 --- a/src/main/java/uk/org/whoami/authme/cache/backup/FileCache.java +++ b/src/main/java/fr/xephi/authme/cache/backup/FileCache.java @@ -1,13 +1,5 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package uk.org.whoami.authme.cache.backup; +package fr.xephi.authme.cache.backup; -/** - * - * @author stefano - */ import java.io.File; import java.io.FileWriter; @@ -15,6 +7,8 @@ import java.util.Scanner; import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; +import fr.xephi.authme.api.API; + public class FileCache { public FileCache() { @@ -45,8 +39,8 @@ public class FileCache { // line format Group|OperatorStatus|isFlying if(flying) - writer.write(s+";1\r\n"); - else writer.write(s+";0\r\n"); + writer.write(s+";1" + API.newline); + else writer.write(s+";0" + API.newline); writer.flush(); ItemStack[] invstack = playerData.getInventory(); diff --git a/src/main/java/uk/org/whoami/authme/cache/limbo/LimboCache.java b/src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java similarity index 72% rename from src/main/java/uk/org/whoami/authme/cache/limbo/LimboCache.java rename to src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java index ba3153d1..301813f2 100644 --- a/src/main/java/uk/org/whoami/authme/cache/limbo/LimboCache.java +++ b/src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java @@ -1,20 +1,4 @@ -/* - * Copyright 2011 Sebastian Köhler . - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.org.whoami.authme.cache.limbo; +package fr.xephi.authme.cache.limbo; import java.util.HashMap; @@ -23,17 +7,18 @@ import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import uk.org.whoami.authme.AuthMe; -import uk.org.whoami.authme.cache.backup.FileCache; -import uk.org.whoami.authme.events.ResetInventoryEvent; -import uk.org.whoami.authme.events.StoreInventoryEvent; -import uk.org.whoami.authme.settings.Settings; -import uk.org.whoami.authme.settings.Spawn; +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.api.API; +import fr.xephi.authme.cache.backup.FileCache; +import fr.xephi.authme.events.ResetInventoryEvent; +import fr.xephi.authme.events.StoreInventoryEvent; +import fr.xephi.authme.settings.Settings; + public class LimboCache { private static LimboCache singleton = null; - private HashMap cache; + public HashMap cache; private FileCache playerData = new FileCache(); public AuthMe plugin; @@ -88,21 +73,14 @@ public class LimboCache { ResetInventoryEvent event = new ResetInventoryEvent(player); Bukkit.getServer().getPluginManager().callEvent(event); if (!event.isCancelled()) { + API.setPlayerInventory(player, new ItemStack[36], new ItemStack[4]); player.sendMessage("Your inventory has been cleaned!"); } } gameMode = 0; - } + } if(player.isDead()) { - loc = player.getWorld().getSpawnLocation(); - if (plugin.mv != null) - { - try { - loc = plugin.mv.getMVWorldManager().getMVWorld(player.getWorld().getName()).getSpawnLocation(); - } catch (NullPointerException npe) {} - } - if (Spawn.getInstance().getLocation() != null) - loc = Spawn.getInstance().getLocation(); + loc = plugin.getSpawnLocation(player.getWorld()); } try { if(cache.containsKey(name) && playerGroup.isEmpty()) { diff --git a/src/main/java/uk/org/whoami/authme/cache/limbo/LimboPlayer.java b/src/main/java/fr/xephi/authme/cache/limbo/LimboPlayer.java similarity index 75% rename from src/main/java/uk/org/whoami/authme/cache/limbo/LimboPlayer.java rename to src/main/java/fr/xephi/authme/cache/limbo/LimboPlayer.java index d95bdf83..8abab470 100644 --- a/src/main/java/uk/org/whoami/authme/cache/limbo/LimboPlayer.java +++ b/src/main/java/fr/xephi/authme/cache/limbo/LimboPlayer.java @@ -1,20 +1,4 @@ -/* - * Copyright 2011 Sebastian Köhler . - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.org.whoami.authme.cache.limbo; +package fr.xephi.authme.cache.limbo; import org.bukkit.Location; import org.bukkit.inventory.ItemStack; @@ -73,6 +57,14 @@ public class LimboPlayer { return inventory; } + public void setArmour(ItemStack[] armour) { + this.armour = armour; + } + + public void setInventory(ItemStack[] inventory) { + this.inventory = inventory; + } + public int getGameMode() { return gameMode; } diff --git a/src/main/java/uk/org/whoami/authme/commands/AdminCommand.java b/src/main/java/fr/xephi/authme/commands/AdminCommand.java similarity index 88% rename from src/main/java/uk/org/whoami/authme/commands/AdminCommand.java rename to src/main/java/fr/xephi/authme/commands/AdminCommand.java index e9071059..74a402fa 100644 --- a/src/main/java/uk/org/whoami/authme/commands/AdminCommand.java +++ b/src/main/java/fr/xephi/authme/commands/AdminCommand.java @@ -1,20 +1,4 @@ -/* - * Copyright 2011 Sebastian Köhler . - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.org.whoami.authme.commands; +package fr.xephi.authme.commands; import java.io.File; import java.io.FileOutputStream; @@ -38,21 +22,22 @@ import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; -import uk.org.whoami.authme.AuthMe; -import uk.org.whoami.authme.ConsoleLogger; -import uk.org.whoami.authme.Utils; -import uk.org.whoami.authme.cache.auth.PlayerAuth; -import uk.org.whoami.authme.cache.auth.PlayerCache; -import uk.org.whoami.authme.converter.FlatToSql; -import uk.org.whoami.authme.converter.FlatToSqlite; -import uk.org.whoami.authme.converter.RakamakConverter; -import uk.org.whoami.authme.converter.xAuthToFlat; -import uk.org.whoami.authme.datasource.DataSource; -import uk.org.whoami.authme.security.PasswordSecurity; -import uk.org.whoami.authme.settings.Messages; -import uk.org.whoami.authme.settings.Settings; -import uk.org.whoami.authme.settings.Spawn; -import uk.org.whoami.authme.settings.SpoutCfg; +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.ConsoleLogger; +import fr.xephi.authme.Utils; +import fr.xephi.authme.cache.auth.PlayerAuth; +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.xAuthToFlat; +import fr.xephi.authme.datasource.DataSource; +import fr.xephi.authme.security.PasswordSecurity; +import fr.xephi.authme.settings.Messages; +import fr.xephi.authme.settings.Settings; +import fr.xephi.authme.settings.Spawn; +import fr.xephi.authme.settings.SpoutCfg; + public class AdminCommand implements CommandExecutor { @@ -76,12 +61,17 @@ public class AdminCommand implements CommandExecutor { sender.sendMessage("/authme purge - Purge Database"); sender.sendMessage("/authme version - Get AuthMe version infos"); sender.sendMessage("/authme lastlogin - Display Date about the Player's LastLogin"); + sender.sendMessage("/authme accounts - Display all player's accounts"); + sender.sendMessage("/authme setSpawn - Set AuthMe spawn to your current pos"); + sender.sendMessage("/authme spawn - Teleport you to the AuthMe SpawnPoint"); + sender.sendMessage("/authme chgemail - Change player email"); + sender.sendMessage("/authme getemail - Get player email"); return true; } if((sender instanceof ConsoleCommandSender) && args[0].equalsIgnoreCase("passpartuToken")) { if(args.length > 1) { - System.out.println("[AuthMe] command usage: authme passpartuToken"); + System.out.println("[AuthMe] command usage: /authme passpartuToken"); return true; } if(Utils.getInstance().obtainToken()) { @@ -146,8 +136,8 @@ public class AdminCommand implements CommandExecutor { } YamlConfiguration newConfig = YamlConfiguration.loadConfiguration(newConfigFile); Settings.reloadConfigOptions(newConfig); - m.reload(); - s.reload(); + m.reLoad(); + s.reLoad(); sender.sendMessage(m._("reload")); } else if (args[0].equalsIgnoreCase("lastlogin")) { if (args.length != 2) { @@ -165,9 +155,13 @@ public class AdminCommand implements CommandExecutor { sender.sendMessage("[AuthMe] " + args[1].toLowerCase() + " lastlogin : " + d.toString()); sender.sendMessage("[AuthMe] The player : " + player.getNickname() + " is unlogged since " + msg); sender.sendMessage("[AuthMe] LastPlayer IP : " + lastIP); - } + } else { + sender.sendMessage("This player does not exist"); + return true; + } } catch (NullPointerException e) { sender.sendMessage("This player does not exist"); + return true; } } else if (args[0].equalsIgnoreCase("accounts")) { if (args.length != 2) { @@ -268,10 +262,12 @@ public class AdminCommand implements CommandExecutor { return true; } PlayerAuth auth = new PlayerAuth(name, hash, "198.18.0.1", 0); + auth.setSalt(PasswordSecurity.userSalt.get(name)); if (!database.saveAuth(auth)) { sender.sendMessage(m._("error")); return true; } + database.updateSalt(auth); sender.sendMessage(m._("registered")); ConsoleLogger.info(args[1] + " registered"); } catch (NoSuchAlgorithmException ex) { @@ -311,7 +307,11 @@ public class AdminCommand implements CommandExecutor { return true; } String playername = args[1].toLowerCase(); - PlayerAuth getAuth = PlayerCache.getInstance().getAuth(playername); + PlayerAuth getAuth = database.getAuth(playername); + if (getAuth == null) { + sender.sendMessage("This player does not exist"); + return true; + } sender.sendMessage("[AuthMe] " + args[1] + " email : " + getAuth.getEmail()); return true; } else if (args[0].equalsIgnoreCase("chgemail")) { @@ -320,13 +320,18 @@ public class AdminCommand implements CommandExecutor { return true; } String playername = args[1].toLowerCase(); - PlayerAuth getAuth = PlayerCache.getInstance().getAuth(playername); + PlayerAuth getAuth = database.getAuth(playername); + if (getAuth == null) { + sender.sendMessage("This player does not exist"); + return true; + } getAuth.setEmail(args[2]); if (!database.updateEmail(getAuth)) { sender.sendMessage(m._("error")); return true; } - PlayerCache.getInstance().updatePlayer(getAuth); + if (PlayerCache.getInstance().getAuth(playername) != null) + PlayerCache.getInstance().updatePlayer(getAuth); return true; } else if (args[0].equalsIgnoreCase("convertfromrakamak")) { try { @@ -396,10 +401,12 @@ public class AdminCommand implements CommandExecutor { return true; } auth.setHash(hash); + auth.setSalt(PasswordSecurity.userSalt.get(name)); if (!database.updatePassword(auth)) { sender.sendMessage(m._("error")); return true; } + database.updateSalt(auth); sender.sendMessage("pwd_changed"); ConsoleLogger.info(args[1] + "'s password changed"); } catch (NoSuchAlgorithmException ex) { diff --git a/src/main/java/uk/org/whoami/authme/commands/CaptchaCommand.java b/src/main/java/fr/xephi/authme/commands/CaptchaCommand.java similarity index 87% rename from src/main/java/uk/org/whoami/authme/commands/CaptchaCommand.java rename to src/main/java/fr/xephi/authme/commands/CaptchaCommand.java index d76170b4..e837de42 100644 --- a/src/main/java/uk/org/whoami/authme/commands/CaptchaCommand.java +++ b/src/main/java/fr/xephi/authme/commands/CaptchaCommand.java @@ -1,15 +1,16 @@ -package uk.org.whoami.authme.commands; +package fr.xephi.authme.commands; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import uk.org.whoami.authme.AuthMe; -import uk.org.whoami.authme.cache.auth.PlayerCache; -import uk.org.whoami.authme.security.RandomString; -import uk.org.whoami.authme.settings.Messages; -import uk.org.whoami.authme.settings.Settings; +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.security.RandomString; +import fr.xephi.authme.settings.Messages; +import fr.xephi.authme.settings.Settings; + public class CaptchaCommand implements CommandExecutor { diff --git a/src/main/java/uk/org/whoami/authme/commands/ChangePasswordCommand.java b/src/main/java/fr/xephi/authme/commands/ChangePasswordCommand.java similarity index 70% rename from src/main/java/uk/org/whoami/authme/commands/ChangePasswordCommand.java rename to src/main/java/fr/xephi/authme/commands/ChangePasswordCommand.java index 570b1830..dcfbe6a5 100644 --- a/src/main/java/uk/org/whoami/authme/commands/ChangePasswordCommand.java +++ b/src/main/java/fr/xephi/authme/commands/ChangePasswordCommand.java @@ -1,20 +1,4 @@ -/* - * Copyright 2011 Sebastian Köhler . - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.org.whoami.authme.commands; +package fr.xephi.authme.commands; import java.security.NoSuchAlgorithmException; @@ -25,14 +9,15 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import uk.org.whoami.authme.AuthMe; -import uk.org.whoami.authme.ConsoleLogger; -import uk.org.whoami.authme.cache.auth.PlayerAuth; -import uk.org.whoami.authme.cache.auth.PlayerCache; -import uk.org.whoami.authme.datasource.DataSource; -import uk.org.whoami.authme.security.PasswordSecurity; -import uk.org.whoami.authme.settings.Messages; -import uk.org.whoami.authme.settings.Settings; +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.ConsoleLogger; +import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.datasource.DataSource; +import fr.xephi.authme.security.PasswordSecurity; +import fr.xephi.authme.settings.Messages; +import fr.xephi.authme.settings.Settings; + public class ChangePasswordCommand implements CommandExecutor { @@ -74,10 +59,12 @@ public class ChangePasswordCommand implements CommandExecutor { if (PasswordSecurity.comparePasswordWithHash(args[0], PlayerCache.getInstance().getAuth(name).getHash(), name)) { PlayerAuth auth = PlayerCache.getInstance().getAuth(name); auth.setHash(hashnew); + auth.setSalt(PasswordSecurity.userSalt.get(name)); if (!database.updatePassword(auth)) { player.sendMessage(m._("error")); return true; } + database.updateSalt(auth); PlayerCache.getInstance().updatePlayer(auth); player.sendMessage(m._("pwd_changed")); ConsoleLogger.info(player.getName() + " changed his password"); diff --git a/src/main/java/uk/org/whoami/authme/commands/EmailCommand.java b/src/main/java/fr/xephi/authme/commands/EmailCommand.java similarity index 83% rename from src/main/java/uk/org/whoami/authme/commands/EmailCommand.java rename to src/main/java/fr/xephi/authme/commands/EmailCommand.java index 98b81587..17499236 100644 --- a/src/main/java/uk/org/whoami/authme/commands/EmailCommand.java +++ b/src/main/java/fr/xephi/authme/commands/EmailCommand.java @@ -1,19 +1,4 @@ -/* - * Copyright 2012 darkwarriors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package uk.org.whoami.authme.commands; +package fr.xephi.authme.commands; import java.security.NoSuchAlgorithmException; @@ -22,15 +7,16 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import uk.org.whoami.authme.AuthMe; -import uk.org.whoami.authme.ConsoleLogger; -import uk.org.whoami.authme.cache.auth.PlayerAuth; -import uk.org.whoami.authme.cache.auth.PlayerCache; -import uk.org.whoami.authme.datasource.DataSource; -import uk.org.whoami.authme.security.PasswordSecurity; -import uk.org.whoami.authme.security.RandomString; -import uk.org.whoami.authme.settings.Messages; -import uk.org.whoami.authme.settings.Settings; + +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.ConsoleLogger; +import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.datasource.DataSource; +import fr.xephi.authme.security.PasswordSecurity; +import fr.xephi.authme.security.RandomString; +import fr.xephi.authme.settings.Messages; +import fr.xephi.authme.settings.Settings; /** * @@ -75,7 +61,7 @@ public class EmailCommand implements CommandExecutor { } if(args[1].equals(args[2]) && PlayerCache.getInstance().isAuthenticated(name)) { PlayerAuth auth = PlayerCache.getInstance().getAuth(name); - if (auth.getEmail() == null || !auth.getEmail().contains("your@email.com")) { + if (auth.getEmail() == null || (!auth.getEmail().equals("your@email.com") && !auth.getEmail().isEmpty())) { player.sendMessage("usage_email_change"); return true; } @@ -103,7 +89,7 @@ public class EmailCommand implements CommandExecutor { } else if(args[0].equalsIgnoreCase("change") && args.length == 3 ) { if(PlayerCache.getInstance().isAuthenticated(name)) { PlayerAuth auth = PlayerCache.getInstance().getAuth(name); - if (auth.getEmail() == null || auth.getEmail().equals("your@email.com")) { + if (auth.getEmail() == null || auth.getEmail().equals("your@email.com") || auth.getEmail().isEmpty()) { player.sendMessage(m._("usage_email_add")); return true; } @@ -140,7 +126,6 @@ public class EmailCommand implements CommandExecutor { } if (plugin.mail == null) { player.sendMessage(m._("error")); - ConsoleLogger.info("Missed mail.jar in lib folder"); return true; } if (data.isAuthAvailable(name)) { diff --git a/src/main/java/uk/org/whoami/authme/commands/LoginCommand.java b/src/main/java/fr/xephi/authme/commands/LoginCommand.java similarity index 56% rename from src/main/java/uk/org/whoami/authme/commands/LoginCommand.java rename to src/main/java/fr/xephi/authme/commands/LoginCommand.java index 6fb714ea..58cf2e7d 100644 --- a/src/main/java/uk/org/whoami/authme/commands/LoginCommand.java +++ b/src/main/java/fr/xephi/authme/commands/LoginCommand.java @@ -1,28 +1,13 @@ -/* - * Copyright 2011 Sebastian Köhler . - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.org.whoami.authme.commands; +package fr.xephi.authme.commands; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import uk.org.whoami.authme.AuthMe; -import uk.org.whoami.authme.settings.Messages; +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.settings.Messages; + public class LoginCommand implements CommandExecutor { diff --git a/src/main/java/uk/org/whoami/authme/commands/LogoutCommand.java b/src/main/java/fr/xephi/authme/commands/LogoutCommand.java similarity index 72% rename from src/main/java/uk/org/whoami/authme/commands/LogoutCommand.java rename to src/main/java/fr/xephi/authme/commands/LogoutCommand.java index 2197b97c..ce1e8149 100644 --- a/src/main/java/uk/org/whoami/authme/commands/LogoutCommand.java +++ b/src/main/java/fr/xephi/authme/commands/LogoutCommand.java @@ -1,20 +1,4 @@ -/* - * Copyright 2011 Sebastian Köhler . - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.org.whoami.authme.commands; +package fr.xephi.authme.commands; import me.muizers.Notifications.Notification; @@ -27,22 +11,23 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.scheduler.BukkitScheduler; import org.bukkit.scheduler.BukkitTask; -import uk.org.whoami.authme.AuthMe; -import uk.org.whoami.authme.Utils; -import uk.org.whoami.authme.ConsoleLogger; -import uk.org.whoami.authme.cache.auth.PlayerAuth; -import uk.org.whoami.authme.cache.auth.PlayerCache; -import uk.org.whoami.authme.cache.backup.DataFileCache; -import uk.org.whoami.authme.cache.backup.FileCache; -import uk.org.whoami.authme.cache.limbo.LimboCache; -import uk.org.whoami.authme.datasource.DataSource; -import uk.org.whoami.authme.events.AuthMeTeleportEvent; -import uk.org.whoami.authme.settings.Messages; -import uk.org.whoami.authme.settings.PlayersLogs; -import uk.org.whoami.authme.settings.Settings; -import uk.org.whoami.authme.settings.Spawn; -import uk.org.whoami.authme.task.MessageTask; -import uk.org.whoami.authme.task.TimeoutTask; +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.ConsoleLogger; +import fr.xephi.authme.Utils; +import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.cache.backup.DataFileCache; +import fr.xephi.authme.cache.backup.FileCache; +import fr.xephi.authme.cache.limbo.LimboCache; +import fr.xephi.authme.datasource.DataSource; +import fr.xephi.authme.events.AuthMeTeleportEvent; +import fr.xephi.authme.settings.Messages; +import fr.xephi.authme.settings.PlayersLogs; +import fr.xephi.authme.settings.Settings; +import fr.xephi.authme.settings.Spawn; +import fr.xephi.authme.task.MessageTask; +import fr.xephi.authme.task.TimeoutTask; + public class LogoutCommand implements CommandExecutor { @@ -119,10 +104,12 @@ public class LogoutCommand implements CommandExecutor { BukkitTask msgT = sched.runTask(plugin, new MessageTask(plugin, name, m._("login_msg"), interval)); LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT.getTaskId()); try { - if (PlayersLogs.players.contains(player.getName())) { - PlayersLogs.players.remove(player.getName()); - pllog.save(); - } + if (PlayersLogs.players.contains(player.getName())) { + PlayersLogs.players.remove(player.getName()); + pllog.save(); + } + if (player.isInsideVehicle()) + player.getVehicle().eject(); } catch (NullPointerException npe) { } player.sendMessage(m._("logout")); diff --git a/src/main/java/uk/org/whoami/authme/commands/PasspartuCommand.java b/src/main/java/fr/xephi/authme/commands/PasspartuCommand.java similarity index 74% rename from src/main/java/uk/org/whoami/authme/commands/PasspartuCommand.java rename to src/main/java/fr/xephi/authme/commands/PasspartuCommand.java index 0ba33151..ea85a9c2 100644 --- a/src/main/java/uk/org/whoami/authme/commands/PasspartuCommand.java +++ b/src/main/java/fr/xephi/authme/commands/PasspartuCommand.java @@ -1,18 +1,15 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package uk.org.whoami.authme.commands; +package fr.xephi.authme.commands; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import uk.org.whoami.authme.AuthMe; -import uk.org.whoami.authme.Utils; -import uk.org.whoami.authme.cache.auth.PlayerCache; -import uk.org.whoami.authme.settings.Messages; +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.Utils; +import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.settings.Messages; + /** * @@ -30,7 +27,7 @@ public class PasspartuCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command cmnd, String label, String[] args) { - if (!plugin.authmePermissible(sender, "authme.admin." + args[0].toLowerCase())) { + if (!plugin.authmePermissible(sender, "authme." + label.toLowerCase())) { sender.sendMessage(m._("no_perm")); return true; } diff --git a/src/main/java/uk/org/whoami/authme/commands/RegisterCommand.java b/src/main/java/fr/xephi/authme/commands/RegisterCommand.java similarity index 79% rename from src/main/java/uk/org/whoami/authme/commands/RegisterCommand.java rename to src/main/java/fr/xephi/authme/commands/RegisterCommand.java index 116d21c2..2341b1a9 100644 --- a/src/main/java/uk/org/whoami/authme/commands/RegisterCommand.java +++ b/src/main/java/fr/xephi/authme/commands/RegisterCommand.java @@ -1,20 +1,4 @@ -/* - * Copyright 2011 Sebastian Khler . - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.org.whoami.authme.commands; +package fr.xephi.authme.commands; import java.security.NoSuchAlgorithmException; import java.util.Date; @@ -31,23 +15,23 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitTask; -import uk.org.whoami.authme.AuthMe; -import uk.org.whoami.authme.ConsoleLogger; -import uk.org.whoami.authme.Utils; -import uk.org.whoami.authme.cache.auth.PlayerAuth; -import uk.org.whoami.authme.cache.auth.PlayerCache; -import uk.org.whoami.authme.cache.limbo.LimboCache; -import uk.org.whoami.authme.cache.limbo.LimboPlayer; -import uk.org.whoami.authme.datasource.DataSource; -import uk.org.whoami.authme.events.RegisterTeleportEvent; -import uk.org.whoami.authme.security.PasswordSecurity; -import uk.org.whoami.authme.security.RandomString; -import uk.org.whoami.authme.settings.Messages; -import uk.org.whoami.authme.settings.PlayersLogs; -import uk.org.whoami.authme.settings.Settings; -import uk.org.whoami.authme.settings.Spawn; -import uk.org.whoami.authme.task.MessageTask; -import uk.org.whoami.authme.task.TimeoutTask; +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.ConsoleLogger; +import fr.xephi.authme.Utils; +import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.cache.limbo.LimboCache; +import fr.xephi.authme.cache.limbo.LimboPlayer; +import fr.xephi.authme.datasource.DataSource; +import fr.xephi.authme.events.RegisterTeleportEvent; +import fr.xephi.authme.security.PasswordSecurity; +import fr.xephi.authme.security.RandomString; +import fr.xephi.authme.settings.Messages; +import fr.xephi.authme.settings.PlayersLogs; +import fr.xephi.authme.settings.Settings; +import fr.xephi.authme.task.MessageTask; +import fr.xephi.authme.task.TimeoutTask; + public class RegisterCommand implements CommandExecutor { @@ -185,20 +169,7 @@ public class RegisterCommand implements CommandExecutor { LimboCache.getInstance().deleteLimboPlayer(name); if (Settings.isTeleportToSpawnEnabled) { World world = player.getWorld(); - Location loca = world.getSpawnLocation(); - if (plugin.mv != null) { - try { - loca = plugin.mv.getMVWorldManager().getMVWorld(world).getSpawnLocation(); - } catch (NullPointerException npe) { - } catch (ClassCastException cce) { - } catch (NoClassDefFoundError ncdfe) { - } - } - if (plugin.essentialsSpawn != null) { - loca = plugin.essentialsSpawn; - } - if (Spawn.getInstance().getLocation() != null) - loca = Spawn.getInstance().getLocation(); + Location loca = plugin.getSpawnLocation(world); RegisterTeleportEvent tpEvent = new RegisterTeleportEvent(player, loca); plugin.getServer().getPluginManager().callEvent(tpEvent); if(!tpEvent.isCancelled()) { @@ -209,6 +180,10 @@ public class RegisterCommand implements CommandExecutor { } } this.isFirstTimeJoin = true; + if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) { + player.setAllowFlight(false); + player.setFlying(false); + } player.saveData(); if (!Settings.noConsoleSpam) ConsoleLogger.info(player.getName() + " registered "+player.getAddress().getAddress().getHostAddress()); @@ -255,23 +230,7 @@ public class RegisterCommand implements CommandExecutor { player.setGameMode(GameMode.getByValue(limbo.getGameMode())); if (Settings.isTeleportToSpawnEnabled) { World world = player.getWorld(); - Location loca = world.getSpawnLocation(); - if (plugin.mv != null) { - try { - loca = plugin.mv.getMVWorldManager().getMVWorld(world).getSpawnLocation(); - } catch (NullPointerException npe) { - - } catch (ClassCastException cce) { - - } catch (NoClassDefFoundError ncdfe) { - - } - } - if (plugin.essentialsSpawn != null) { - loca = plugin.essentialsSpawn; - } - if (Spawn.getInstance().getLocation() != null) - loca = Spawn.getInstance().getLocation(); + Location loca = plugin.getSpawnLocation(world); RegisterTeleportEvent tpEvent = new RegisterTeleportEvent(player, loca); plugin.getServer().getPluginManager().callEvent(tpEvent); if(!tpEvent.isCancelled()) { @@ -293,6 +252,10 @@ public class RegisterCommand implements CommandExecutor { if (!Settings.getmailAccount.isEmpty()) player.sendMessage(m._("add_email")); this.isFirstTimeJoin = true; + if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) { + player.setAllowFlight(false); + player.setFlying(false); + } player.saveData(); if (!Settings.noConsoleSpam) ConsoleLogger.info(player.getName() + " registered "+player.getAddress().getAddress().getHostAddress()); diff --git a/src/main/java/uk/org/whoami/authme/commands/UnregisterCommand.java b/src/main/java/fr/xephi/authme/commands/UnregisterCommand.java similarity index 71% rename from src/main/java/uk/org/whoami/authme/commands/UnregisterCommand.java rename to src/main/java/fr/xephi/authme/commands/UnregisterCommand.java index e2b2b9db..3388e2ce 100644 --- a/src/main/java/uk/org/whoami/authme/commands/UnregisterCommand.java +++ b/src/main/java/fr/xephi/authme/commands/UnregisterCommand.java @@ -1,20 +1,4 @@ -/* - * Copyright 2011 Sebastian Köhler . - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.org.whoami.authme.commands; +package fr.xephi.authme.commands; import java.security.NoSuchAlgorithmException; @@ -29,21 +13,21 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.scheduler.BukkitScheduler; import org.bukkit.scheduler.BukkitTask; -import uk.org.whoami.authme.AuthMe; -import uk.org.whoami.authme.ConsoleLogger; -import uk.org.whoami.authme.Utils; -import uk.org.whoami.authme.cache.auth.PlayerCache; -import uk.org.whoami.authme.cache.backup.FileCache; -import uk.org.whoami.authme.cache.limbo.LimboCache; -import uk.org.whoami.authme.datasource.DataSource; -import uk.org.whoami.authme.events.SpawnTeleportEvent; -import uk.org.whoami.authme.security.PasswordSecurity; -import uk.org.whoami.authme.settings.Messages; -import uk.org.whoami.authme.settings.PlayersLogs; -import uk.org.whoami.authme.settings.Settings; -import uk.org.whoami.authme.settings.Spawn; -import uk.org.whoami.authme.task.MessageTask; -import uk.org.whoami.authme.task.TimeoutTask; +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.ConsoleLogger; +import fr.xephi.authme.Utils; +import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.cache.backup.FileCache; +import fr.xephi.authme.cache.limbo.LimboCache; +import fr.xephi.authme.datasource.DataSource; +import fr.xephi.authme.events.SpawnTeleportEvent; +import fr.xephi.authme.security.PasswordSecurity; +import fr.xephi.authme.settings.Messages; +import fr.xephi.authme.settings.PlayersLogs; +import fr.xephi.authme.settings.Settings; +import fr.xephi.authme.task.MessageTask; +import fr.xephi.authme.task.TimeoutTask; + public class UnregisterCommand implements CommandExecutor { @@ -129,20 +113,7 @@ public class UnregisterCommand implements CommandExecutor { plugin.notifications.showNotification(new Notification("[AuthMe] " + player.getName() + " unregistered himself!")); } if (Settings.isTeleportToSpawnEnabled) { - Location spawn = player.getWorld().getSpawnLocation(); - if (plugin.mv != null) { - try { - spawn = plugin.mv.getMVWorldManager().getMVWorld(player.getWorld()).getSpawnLocation(); - } catch (NullPointerException npe) { - } catch (ClassCastException cce) { - } catch (NoClassDefFoundError ncdfe) { - } - } - if (plugin.essentialsSpawn != null) { - spawn = plugin.essentialsSpawn; - } - if (Spawn.getInstance().getLocation() != null) - spawn = Spawn.getInstance().getLocation(); + Location spawn = plugin.getSpawnLocation(player.getWorld()); SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawn, false); plugin.getServer().getPluginManager().callEvent(tpEvent); if(!tpEvent.isCancelled()) { diff --git a/src/main/java/uk/org/whoami/authme/converter/FlatToSql.java b/src/main/java/fr/xephi/authme/converter/FlatToSql.java similarity index 95% rename from src/main/java/uk/org/whoami/authme/converter/FlatToSql.java rename to src/main/java/fr/xephi/authme/converter/FlatToSql.java index 3f1485de..ac0cdeab 100644 --- a/src/main/java/uk/org/whoami/authme/converter/FlatToSql.java +++ b/src/main/java/fr/xephi/authme/converter/FlatToSql.java @@ -1,4 +1,4 @@ -package uk.org.whoami.authme.converter; +package fr.xephi.authme.converter; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -8,9 +8,10 @@ import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; -import uk.org.whoami.authme.AuthMe; -import uk.org.whoami.authme.ConsoleLogger; -import uk.org.whoami.authme.settings.Settings; +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.ConsoleLogger; +import fr.xephi.authme.settings.Settings; + /** * diff --git a/src/main/java/uk/org/whoami/authme/converter/FlatToSqlite.java b/src/main/java/fr/xephi/authme/converter/FlatToSqlite.java similarity index 98% rename from src/main/java/uk/org/whoami/authme/converter/FlatToSqlite.java rename to src/main/java/fr/xephi/authme/converter/FlatToSqlite.java index d19652d0..613a1b4a 100644 --- a/src/main/java/uk/org/whoami/authme/converter/FlatToSqlite.java +++ b/src/main/java/fr/xephi/authme/converter/FlatToSqlite.java @@ -1,4 +1,4 @@ -package uk.org.whoami.authme.converter; +package fr.xephi.authme.converter; import java.io.BufferedReader; import java.io.File; @@ -12,9 +12,10 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -import uk.org.whoami.authme.AuthMe; -import uk.org.whoami.authme.ConsoleLogger; -import uk.org.whoami.authme.settings.Settings; +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.ConsoleLogger; +import fr.xephi.authme.settings.Settings; + public class FlatToSqlite { diff --git a/src/main/java/uk/org/whoami/authme/converter/RakamakConverter.java b/src/main/java/fr/xephi/authme/converter/RakamakConverter.java similarity index 92% rename from src/main/java/uk/org/whoami/authme/converter/RakamakConverter.java rename to src/main/java/fr/xephi/authme/converter/RakamakConverter.java index 546d4e97..5c0c7c60 100644 --- a/src/main/java/uk/org/whoami/authme/converter/RakamakConverter.java +++ b/src/main/java/fr/xephi/authme/converter/RakamakConverter.java @@ -1,4 +1,4 @@ -package uk.org.whoami.authme.converter; +package fr.xephi.authme.converter; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -11,11 +11,12 @@ import java.security.NoSuchAlgorithmException; import java.util.HashMap; import java.util.Map.Entry; -import uk.org.whoami.authme.AuthMe; -import uk.org.whoami.authme.ConsoleLogger; -import uk.org.whoami.authme.security.PasswordSecurity; -import uk.org.whoami.authme.security.PasswordSecurity.HashAlgorithm; -import uk.org.whoami.authme.settings.Settings; +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.ConsoleLogger; +import fr.xephi.authme.security.HashAlgorithm; +import fr.xephi.authme.security.PasswordSecurity; +import fr.xephi.authme.settings.Settings; + /** * diff --git a/src/main/java/uk/org/whoami/authme/converter/xAuthToFlat.java b/src/main/java/fr/xephi/authme/converter/xAuthToFlat.java similarity index 95% rename from src/main/java/uk/org/whoami/authme/converter/xAuthToFlat.java rename to src/main/java/fr/xephi/authme/converter/xAuthToFlat.java index 25531343..dbb3b4c4 100644 --- a/src/main/java/uk/org/whoami/authme/converter/xAuthToFlat.java +++ b/src/main/java/fr/xephi/authme/converter/xAuthToFlat.java @@ -1,4 +1,4 @@ -package uk.org.whoami.authme.converter; +package fr.xephi.authme.converter; import java.io.File; import java.sql.Connection; @@ -14,9 +14,10 @@ import com.cypherx.xauth.xAuth; import com.cypherx.xauth.database.Table; import com.cypherx.xauth.utils.xAuthLog; -import uk.org.whoami.authme.AuthMe; -import uk.org.whoami.authme.cache.auth.PlayerAuth; -import uk.org.whoami.authme.datasource.DataSource; +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.datasource.DataSource; + /** * diff --git a/src/main/java/uk/org/whoami/authme/datasource/CacheDataSource.java b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java similarity index 77% rename from src/main/java/uk/org/whoami/authme/datasource/CacheDataSource.java rename to src/main/java/fr/xephi/authme/datasource/CacheDataSource.java index 234d84f1..ac5e5d01 100644 --- a/src/main/java/uk/org/whoami/authme/datasource/CacheDataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java @@ -1,29 +1,14 @@ -/* - * Copyright 2011 Sebastian Köhler . - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.org.whoami.authme.datasource; +package fr.xephi.authme.datasource; import java.util.HashMap; import java.util.List; import org.bukkit.entity.Player; -import uk.org.whoami.authme.AuthMe; -import uk.org.whoami.authme.cache.auth.PlayerAuth; -import uk.org.whoami.authme.cache.auth.PlayerCache; +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.cache.auth.PlayerCache; + public class CacheDataSource implements DataSource { @@ -110,6 +95,19 @@ public class CacheDataSource implements DataSource { return cleared; } + @Override + public List autoPurgeDatabase(long until) { + List cleared = source.autoPurgeDatabase(until); + if (cleared.size() > 0) { + for (PlayerAuth auth : cache.values()) { + if(auth.getLastLogin() < until) { + cache.remove(auth.getNickname()); + } + } + } + return cleared; + } + @Override public synchronized boolean removeAuth(String user) { if (source.removeAuth(user)) { @@ -141,7 +139,7 @@ public class CacheDataSource implements DataSource { } @Override - public boolean updateEmail(PlayerAuth auth) { + public synchronized boolean updateEmail(PlayerAuth auth) { if(source.updateEmail(auth)) { cache.get(auth.getNickname()).setEmail(auth.getEmail()); return true; @@ -150,7 +148,7 @@ public class CacheDataSource implements DataSource { } @Override - public boolean updateSalt(PlayerAuth auth) { + public synchronized boolean updateSalt(PlayerAuth auth) { if(source.updateSalt(auth)) { cache.get(auth.getNickname()).setSalt(auth.getSalt()); return true; @@ -159,22 +157,22 @@ public class CacheDataSource implements DataSource { } @Override - public List getAllAuthsByName(PlayerAuth auth) { + public synchronized List getAllAuthsByName(PlayerAuth auth) { return source.getAllAuthsByName(auth); } @Override - public List getAllAuthsByIp(String ip) { + public synchronized List getAllAuthsByIp(String ip) { return source.getAllAuthsByIp(ip); } @Override - public List getAllAuthsByEmail(String email) { + public synchronized List getAllAuthsByEmail(String email) { return source.getAllAuthsByEmail(email); } @Override - public void purgeBanned(List banned) { + public synchronized void purgeBanned(List banned) { source.purgeBanned(banned); for (PlayerAuth auth : cache.values()) { if (banned.contains(auth.getNickname())) { diff --git a/src/main/java/uk/org/whoami/authme/datasource/DataSource.java b/src/main/java/fr/xephi/authme/datasource/DataSource.java similarity index 52% rename from src/main/java/uk/org/whoami/authme/datasource/DataSource.java rename to src/main/java/fr/xephi/authme/datasource/DataSource.java index b3b5a830..c1e6d0b2 100644 --- a/src/main/java/uk/org/whoami/authme/datasource/DataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/DataSource.java @@ -1,24 +1,9 @@ -/* - * Copyright 2011 Sebastian Köhler . - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.org.whoami.authme.datasource; +package fr.xephi.authme.datasource; import java.util.List; -import uk.org.whoami.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.cache.auth.PlayerAuth; + public interface DataSource { @@ -38,6 +23,8 @@ public interface DataSource { boolean updatePassword(PlayerAuth auth); int purgeDatabase(long until); + + List autoPurgeDatabase(long until); boolean removeAuth(String user); diff --git a/src/main/java/uk/org/whoami/authme/datasource/FileDataSource.java b/src/main/java/fr/xephi/authme/datasource/FileDataSource.java similarity index 79% rename from src/main/java/uk/org/whoami/authme/datasource/FileDataSource.java rename to src/main/java/fr/xephi/authme/datasource/FileDataSource.java index c9179e20..0afdbab4 100644 --- a/src/main/java/uk/org/whoami/authme/datasource/FileDataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/FileDataSource.java @@ -1,20 +1,4 @@ -/* - * Copyright 2011 Sebastian Köhler . - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.org.whoami.authme.datasource; +package fr.xephi.authme.datasource; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -26,17 +10,19 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import uk.org.whoami.authme.ConsoleLogger; -import uk.org.whoami.authme.cache.auth.PlayerAuth; -import uk.org.whoami.authme.settings.Settings; +import fr.xephi.authme.ConsoleLogger; +import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.settings.Settings; + public class FileDataSource implements DataSource { /* file layout: * - * PLAYERNAME:HASHSUM:IP:LOGININMILLIESECONDS:COORDS + * PLAYERNAME:HASHSUM:IP:LOGININMILLIESECONDS:LASTPOSX:LASTPOSY:LASTPOSZ:LASTPOSWORLD * * Old but compatible: + * PLAYERNAME:HASHSUM:IP:LOGININMILLIESECONDS * PLAYERNAME:HASHSUM:IP * PLAYERNAME:HASHSUM * @@ -84,13 +70,8 @@ public class FileDataSource implements DataSource { } BufferedWriter bw = null; try { - if( auth.getQuitLocY() == 0 ) { - bw = new BufferedWriter(new FileWriter(source, true)); - bw.write(auth.getNickname() + ":" + auth.getHash() + ":" + auth.getIp() + ":" + auth.getLastLogin() + "\n"); - } else { bw = new BufferedWriter(new FileWriter(source, true)); bw.write(auth.getNickname() + ":" + auth.getHash() + ":" + auth.getIp() + ":" + auth.getLastLogin() + ":" + auth.getQuitLocX() + ":" + auth.getQuitLocY() + ":" + auth.getQuitLocZ() + ":" + auth.getWorld() + "\n"); - } } catch (IOException ex) { ConsoleLogger.showError(ex.getMessage()); return false; @@ -118,7 +99,24 @@ public class FileDataSource implements DataSource { while ((line = br.readLine()) != null) { String[] args = line.split(":"); if (args[0].equals(auth.getNickname())) { - newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3])); + switch (args.length) { + case 4: { + newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), 0, 0, 0, "world"); + break; + } + case 7: { + newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), Integer.parseInt(args[4]), Integer.parseInt(args[5]), Integer.parseInt(args[6]), "world"); + break; + } + case 8: { + newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), Integer.parseInt(args[4]), Integer.parseInt(args[5]), Integer.parseInt(args[6]), args[7]); + break; + } + default: { + newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], 0, 0, 0, 0, "world"); + break; + } + } break; } } @@ -154,7 +152,24 @@ public class FileDataSource implements DataSource { while ((line = br.readLine()) != null) { String[] args = line.split(":"); if (args[0].equals(auth.getNickname())) { - newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin()); + switch (args.length) { + case 4: { + newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), 0, 0, 0, "world"); + break; + } + case 7: { + newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Integer.parseInt(args[4]), Integer.parseInt(args[5]), Integer.parseInt(args[6]), "world"); + break; + } + case 8: { + newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Integer.parseInt(args[4]), Integer.parseInt(args[5]), Integer.parseInt(args[6]), args[7]); + break; + } + default: { + newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), 0, 0, 0, "world"); + break; + } + } break; } } @@ -254,7 +269,7 @@ public class FileDataSource implements DataSource { String line; while ((line = br.readLine()) != null) { String[] args = line.split(":"); - if (args.length == 4) { + if (args.length >= 4) { if (Long.parseLong(args[3]) >= until) { lines.add(line); continue; @@ -289,6 +304,54 @@ public class FileDataSource implements DataSource { return cleared; } + @Override + public List autoPurgeDatabase(long until) { + BufferedReader br = null; + BufferedWriter bw = null; + ArrayList lines = new ArrayList(); + List cleared = new ArrayList(); + try { + br = new BufferedReader(new FileReader(source)); + String line; + while ((line = br.readLine()) != null) { + String[] args = line.split(":"); + if (args.length >= 4) { + if (Long.parseLong(args[3]) >= until) { + lines.add(line); + continue; + } else { + cleared.add(args[0]); + } + } + + } + bw = new BufferedWriter(new FileWriter(source)); + for (String l : lines) { + bw.write(l + "\n"); + } + } catch (FileNotFoundException ex) { + ConsoleLogger.showError(ex.getMessage()); + return cleared; + } catch (IOException ex) { + ConsoleLogger.showError(ex.getMessage()); + return cleared; + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException ex) { + } + } + if (bw != null) { + try { + bw.close(); + } catch (IOException ex) { + } + } + } + return cleared; + } + @Override public synchronized boolean removeAuth(String user) { if (!isAuthAvailable(user)) { diff --git a/src/main/java/uk/org/whoami/authme/datasource/MiniConnectionPoolManager.java b/src/main/java/fr/xephi/authme/datasource/MiniConnectionPoolManager.java similarity index 99% rename from src/main/java/uk/org/whoami/authme/datasource/MiniConnectionPoolManager.java rename to src/main/java/fr/xephi/authme/datasource/MiniConnectionPoolManager.java index 306031c3..9f8fe6c1 100644 --- a/src/main/java/uk/org/whoami/authme/datasource/MiniConnectionPoolManager.java +++ b/src/main/java/fr/xephi/authme/datasource/MiniConnectionPoolManager.java @@ -11,7 +11,7 @@ // Please contact the author if you need another license. // This module is provided "as is", without warranties of any kind. -package uk.org.whoami.authme.datasource; +package fr.xephi.authme.datasource; import java.io.PrintWriter; import java.sql.Connection; diff --git a/src/main/java/uk/org/whoami/authme/datasource/MySQLDataSource.java b/src/main/java/fr/xephi/authme/datasource/MySQLDataSource.java similarity index 77% rename from src/main/java/uk/org/whoami/authme/datasource/MySQLDataSource.java rename to src/main/java/fr/xephi/authme/datasource/MySQLDataSource.java index cd07d85f..587735e3 100644 --- a/src/main/java/uk/org/whoami/authme/datasource/MySQLDataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/MySQLDataSource.java @@ -1,23 +1,14 @@ -/* - * Copyright 2011 Sebastian Köhler . - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.org.whoami.authme.datasource; +package fr.xephi.authme.datasource; import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource; +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.ConsoleLogger; +import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.datasource.MiniConnectionPoolManager.TimeoutException; +import fr.xephi.authme.security.HashAlgorithm; +import fr.xephi.authme.settings.Settings; + import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -26,11 +17,6 @@ import java.sql.Statement; import java.util.ArrayList; import java.util.List; -import uk.org.whoami.authme.AuthMe; -import uk.org.whoami.authme.ConsoleLogger; -import uk.org.whoami.authme.cache.auth.PlayerAuth; -import uk.org.whoami.authme.datasource.MiniConnectionPoolManager.TimeoutException; -import uk.org.whoami.authme.settings.Settings; public class MySQLDataSource implements DataSource { @@ -247,6 +233,104 @@ public class MySQLDataSource implements DataSource { pst.executeUpdate(); } } + if (Settings.getPasswordHash == HashAlgorithm.PHPBB) { + int id; + ResultSet rs = null; + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnName + "=?;"); + pst.setString(1, auth.getNickname()); + rs = pst.executeQuery(); + if (rs.next()) { + id = rs.getInt(columnID); + pst = con.prepareStatement("INSERT INTO " + Settings.getPhpbbPrefix + "user_group (group_id, user_id, group_leader, user_pending) VALUES (?,?,?,?);"); + pst.setInt(1, Settings.getPhpbbGroup); + pst.setInt(2, id); + pst.setInt(3, 0); + pst.setInt(4, 0); + pst.executeUpdate(); + } + } + if (Settings.getPasswordHash == HashAlgorithm.WORDPRESS) { + int id; + ResultSet rs = null; + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnName + "=?;"); + pst.setString(1, auth.getNickname()); + rs = pst.executeQuery(); + if (rs.next()) { + id = rs.getInt(columnID); + // First Name + pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); + pst.setInt(1, id); + pst.setString(2, "first_name"); + pst.setString(3, ""); + pst.executeUpdate(); + // Last Name + pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); + pst.setInt(1, id); + pst.setString(2, "last_name"); + pst.setString(3, ""); + pst.executeUpdate(); + // Nick Name + pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); + pst.setInt(1, id); + pst.setString(2, "nickname"); + pst.setString(3, auth.getNickname()); + pst.executeUpdate(); + // Description + pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); + pst.setInt(1, id); + pst.setString(2, "description"); + pst.setString(3, ""); + pst.executeUpdate(); + // Rich_Editing + pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); + pst.setInt(1, id); + pst.setString(2, "rich_editing"); + pst.setString(3, "true"); + pst.executeUpdate(); + // Comments_Shortcuts + pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); + pst.setInt(1, id); + pst.setString(2, "comment_shortcuts"); + pst.setString(3, "false"); + pst.executeUpdate(); + // admin_color + pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); + pst.setInt(1, id); + pst.setString(2, "admin_color"); + pst.setString(3, "fresh"); + pst.executeUpdate(); + // use_ssl + pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); + pst.setInt(1, id); + pst.setString(2, "use_ssl"); + pst.setString(3, "0"); + pst.executeUpdate(); + // show_admin_bar_front + pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); + pst.setInt(1, id); + pst.setString(2, "show_admin_bar_front"); + pst.setString(3, "true"); + pst.executeUpdate(); + // wp_capabilities + pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); + pst.setInt(1, id); + pst.setString(2, "wp_capabilities"); + pst.setString(3, "a:1:{s:10:\"subscriber\";b:1;}"); + pst.executeUpdate(); + // wp_user_level + pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); + pst.setInt(1, id); + pst.setString(2, "wp_user_level"); + pst.setString(3, "0"); + pst.executeUpdate(); + // default_password_nag + pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); + pst.setInt(1, id); + pst.setString(2, "default_password_nag"); + pst.setString(3, ""); + pst.executeUpdate(); + } + } } catch (SQLException ex) { ConsoleLogger.showError(ex.getMessage()); return false; @@ -328,6 +412,34 @@ public class MySQLDataSource implements DataSource { } } + @Override + public synchronized List autoPurgeDatabase(long until) { + Connection con = null; + PreparedStatement pst = null; + ResultSet rs = null; + List list = new ArrayList(); + try { + con = makeSureConnectionIsReady(); + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLastLogin + "(); + } catch (TimeoutException ex) { + ConsoleLogger.showError(ex.getMessage()); + return new ArrayList(); + } finally { + close(rs); + close(pst); + close(con); + } + } + @Override public synchronized boolean removeAuth(String user) { Connection con = null; @@ -430,7 +542,7 @@ public class MySQLDataSource implements DataSource { @Override public synchronized boolean updateSalt(PlayerAuth auth) { - if (columnSalt.isEmpty()) { + if (columnSalt.isEmpty() || auth.getSalt() == null || auth.getSalt().isEmpty()) { return false; } Connection con = null; @@ -654,4 +766,5 @@ public class MySQLDataSource implements DataSource { conPool = new MiniConnectionPoolManager(dataSource, 10); ConsoleLogger.info("ConnectionPool was unavailable... Reconnected!"); } + } diff --git a/src/main/java/uk/org/whoami/authme/datasource/SqliteDataSource.java b/src/main/java/fr/xephi/authme/datasource/SqliteDataSource.java similarity index 94% rename from src/main/java/uk/org/whoami/authme/datasource/SqliteDataSource.java rename to src/main/java/fr/xephi/authme/datasource/SqliteDataSource.java index 074edc72..d9a7cd12 100644 --- a/src/main/java/uk/org/whoami/authme/datasource/SqliteDataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/SqliteDataSource.java @@ -1,14 +1,15 @@ -package uk.org.whoami.authme.datasource; +package fr.xephi.authme.datasource; import java.sql.*; import java.util.ArrayList; import java.util.List; import org.sqlite.*; -import uk.org.whoami.authme.ConsoleLogger; -import uk.org.whoami.authme.cache.auth.PlayerAuth; -import uk.org.whoami.authme.datasource.MiniConnectionPoolManager.TimeoutException; -import uk.org.whoami.authme.settings.Settings; + +import fr.xephi.authme.ConsoleLogger; +import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.datasource.MiniConnectionPoolManager.TimeoutException; +import fr.xephi.authme.settings.Settings; /** * @@ -103,7 +104,7 @@ public class SqliteDataSource implements DataSource { rs.close(); rs = con.getMetaData().getColumns(null, null, tableName, lastlocWorld); if (!rs.next()) { - st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocWorld + " VARCHAR(255) NOT NULL DEFAULT 'world' AFTER " + lastlocZ + ";"); + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocWorld + " VARCHAR(255) NOT NULL DEFAULT 'world';"); } rs.close(); rs = con.getMetaData().getColumns(null, null, tableName, columnEmail); @@ -246,6 +247,28 @@ public class SqliteDataSource implements DataSource { } } + @Override + public List autoPurgeDatabase(long until) { + PreparedStatement pst = null; + ResultSet rs = null; + List list = new ArrayList(); + try { + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLastLogin + "(); + } finally { + close(rs); + close(pst); + } + } + @Override public synchronized boolean removeAuth(String user) { PreparedStatement pst = null; diff --git a/src/main/java/uk/org/whoami/authme/events/AuthMeTeleportEvent.java b/src/main/java/fr/xephi/authme/events/AuthMeTeleportEvent.java similarity index 93% rename from src/main/java/uk/org/whoami/authme/events/AuthMeTeleportEvent.java rename to src/main/java/fr/xephi/authme/events/AuthMeTeleportEvent.java index 7f8b9a33..3427c7bd 100644 --- a/src/main/java/uk/org/whoami/authme/events/AuthMeTeleportEvent.java +++ b/src/main/java/fr/xephi/authme/events/AuthMeTeleportEvent.java @@ -1,4 +1,4 @@ -package uk.org.whoami.authme.events; +package fr.xephi.authme.events; import org.bukkit.Location; import org.bukkit.entity.Player; diff --git a/src/main/java/uk/org/whoami/authme/events/CustomEvent.java b/src/main/java/fr/xephi/authme/events/CustomEvent.java similarity index 81% rename from src/main/java/uk/org/whoami/authme/events/CustomEvent.java rename to src/main/java/fr/xephi/authme/events/CustomEvent.java index 31bdee99..0661ecd2 100644 --- a/src/main/java/uk/org/whoami/authme/events/CustomEvent.java +++ b/src/main/java/fr/xephi/authme/events/CustomEvent.java @@ -1,6 +1,7 @@ -package uk.org.whoami.authme.events; +package fr.xephi.authme.events; import org.bukkit.Server; +import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; @@ -8,7 +9,7 @@ import org.bukkit.event.HandlerList; * * @author Xephi59 */ -public class CustomEvent extends Event { +public class CustomEvent extends Event implements Cancellable { private boolean isCancelled; private static final HandlerList handlers = new HandlerList(); diff --git a/src/main/java/uk/org/whoami/authme/events/LoginEvent.java b/src/main/java/fr/xephi/authme/events/LoginEvent.java similarity index 61% rename from src/main/java/uk/org/whoami/authme/events/LoginEvent.java rename to src/main/java/fr/xephi/authme/events/LoginEvent.java index b7d0f7d4..87f2d33e 100644 --- a/src/main/java/uk/org/whoami/authme/events/LoginEvent.java +++ b/src/main/java/fr/xephi/authme/events/LoginEvent.java @@ -1,15 +1,18 @@ -package uk.org.whoami.authme.events; +package fr.xephi.authme.events; import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; /** * * @author Xephi59 */ -public class LoginEvent extends UncancellableEvent { +public class LoginEvent extends Event { private Player player; private boolean isLogin; + private static final HandlerList handlers = new HandlerList(); public LoginEvent(Player player, boolean isLogin) { this.player = player; @@ -24,6 +27,7 @@ public class LoginEvent extends UncancellableEvent { this.player = player; } + @Deprecated public void setLogin(boolean isLogin) { this.isLogin = isLogin; } @@ -32,4 +36,9 @@ public class LoginEvent extends UncancellableEvent { return isLogin; } + @Override + public HandlerList getHandlers() { + return handlers; + } + } diff --git a/src/main/java/fr/xephi/authme/events/PasswordEncryptionEvent.java b/src/main/java/fr/xephi/authme/events/PasswordEncryptionEvent.java new file mode 100644 index 00000000..950baa1d --- /dev/null +++ b/src/main/java/fr/xephi/authme/events/PasswordEncryptionEvent.java @@ -0,0 +1,44 @@ +package fr.xephi.authme.events; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +import fr.xephi.authme.security.crypts.EncryptionMethod; + +/** + *

This event is called when we need to compare or get an hash password, + * for set a custom EncryptionMethod

+ * + * @see 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; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public void setMethod(EncryptionMethod method) { + this.method = method; + } + + public EncryptionMethod getMethod() { + return method; + } + + public String getPlayerName() { + return playerName; + } + +} diff --git a/src/main/java/uk/org/whoami/authme/events/ProtectInventoryEvent.java b/src/main/java/fr/xephi/authme/events/ProtectInventoryEvent.java similarity index 68% rename from src/main/java/uk/org/whoami/authme/events/ProtectInventoryEvent.java rename to src/main/java/fr/xephi/authme/events/ProtectInventoryEvent.java index db4ca261..0ff9f6ea 100644 --- a/src/main/java/uk/org/whoami/authme/events/ProtectInventoryEvent.java +++ b/src/main/java/fr/xephi/authme/events/ProtectInventoryEvent.java @@ -1,10 +1,8 @@ -package uk.org.whoami.authme.events; +package fr.xephi.authme.events; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import uk.org.whoami.authme.api.API; - /** * * @author Xephi59 @@ -21,15 +19,8 @@ public class ProtectInventoryEvent extends CustomEvent { this.player = player; this.storedinventory = storedinventory; this.storedarmor = storedarmor; - } - - public ProtectInventoryEvent(Player player, ItemStack[] storedinventory, ItemStack[] storedarmor, int newInventory, int newArmor) { - this.player = player; - this.storedinventory = storedinventory; - this.storedarmor = storedarmor; - this.setNewInventory(new ItemStack[newInventory]); - this.setNewArmor(new ItemStack[newArmor]); - API.setPlayerInventory(player, new ItemStack[newInventory], new ItemStack[newArmor]); + this.emptyInventory = new ItemStack[36]; + this.emptyArmor = new ItemStack[4]; } public ItemStack[] getStoredInventory() { diff --git a/src/main/java/uk/org/whoami/authme/events/RegisterTeleportEvent.java b/src/main/java/fr/xephi/authme/events/RegisterTeleportEvent.java similarity index 93% rename from src/main/java/uk/org/whoami/authme/events/RegisterTeleportEvent.java rename to src/main/java/fr/xephi/authme/events/RegisterTeleportEvent.java index fb553b90..5185eb2d 100644 --- a/src/main/java/uk/org/whoami/authme/events/RegisterTeleportEvent.java +++ b/src/main/java/fr/xephi/authme/events/RegisterTeleportEvent.java @@ -1,4 +1,4 @@ -package uk.org.whoami.authme.events; +package fr.xephi.authme.events; import org.bukkit.Location; import org.bukkit.entity.Player; diff --git a/src/main/java/uk/org/whoami/authme/events/ResetInventoryEvent.java b/src/main/java/fr/xephi/authme/events/ResetInventoryEvent.java similarity index 64% rename from src/main/java/uk/org/whoami/authme/events/ResetInventoryEvent.java rename to src/main/java/fr/xephi/authme/events/ResetInventoryEvent.java index cbb6f823..1a8c2361 100644 --- a/src/main/java/uk/org/whoami/authme/events/ResetInventoryEvent.java +++ b/src/main/java/fr/xephi/authme/events/ResetInventoryEvent.java @@ -1,9 +1,6 @@ -package uk.org.whoami.authme.events; +package fr.xephi.authme.events; import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -import uk.org.whoami.authme.api.API; /** * @@ -15,7 +12,6 @@ public class ResetInventoryEvent extends CustomEvent { public ResetInventoryEvent(Player player) { this.player = player; - API.setPlayerInventory(player, new ItemStack[36], new ItemStack[4]); } public Player getPlayer() { diff --git a/src/main/java/uk/org/whoami/authme/events/RestoreInventoryEvent.java b/src/main/java/fr/xephi/authme/events/RestoreInventoryEvent.java similarity index 95% rename from src/main/java/uk/org/whoami/authme/events/RestoreInventoryEvent.java rename to src/main/java/fr/xephi/authme/events/RestoreInventoryEvent.java index c1442315..5ae4334a 100644 --- a/src/main/java/uk/org/whoami/authme/events/RestoreInventoryEvent.java +++ b/src/main/java/fr/xephi/authme/events/RestoreInventoryEvent.java @@ -1,4 +1,4 @@ -package uk.org.whoami.authme.events; +package fr.xephi.authme.events; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; diff --git a/src/main/java/uk/org/whoami/authme/events/SessionEvent.java b/src/main/java/fr/xephi/authme/events/SessionEvent.java similarity index 82% rename from src/main/java/uk/org/whoami/authme/events/SessionEvent.java rename to src/main/java/fr/xephi/authme/events/SessionEvent.java index 0259716d..8cefc846 100644 --- a/src/main/java/uk/org/whoami/authme/events/SessionEvent.java +++ b/src/main/java/fr/xephi/authme/events/SessionEvent.java @@ -1,6 +1,6 @@ -package uk.org.whoami.authme.events; +package fr.xephi.authme.events; -import uk.org.whoami.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.cache.auth.PlayerAuth; /** * diff --git a/src/main/java/uk/org/whoami/authme/events/SpawnTeleportEvent.java b/src/main/java/fr/xephi/authme/events/SpawnTeleportEvent.java similarity index 95% rename from src/main/java/uk/org/whoami/authme/events/SpawnTeleportEvent.java rename to src/main/java/fr/xephi/authme/events/SpawnTeleportEvent.java index f615b618..3685b36a 100644 --- a/src/main/java/uk/org/whoami/authme/events/SpawnTeleportEvent.java +++ b/src/main/java/fr/xephi/authme/events/SpawnTeleportEvent.java @@ -1,4 +1,4 @@ -package uk.org.whoami.authme.events; +package fr.xephi.authme.events; import org.bukkit.Location; import org.bukkit.entity.Player; diff --git a/src/main/java/uk/org/whoami/authme/events/StoreInventoryEvent.java b/src/main/java/fr/xephi/authme/events/StoreInventoryEvent.java similarity index 92% rename from src/main/java/uk/org/whoami/authme/events/StoreInventoryEvent.java rename to src/main/java/fr/xephi/authme/events/StoreInventoryEvent.java index a7387f24..82463378 100644 --- a/src/main/java/uk/org/whoami/authme/events/StoreInventoryEvent.java +++ b/src/main/java/fr/xephi/authme/events/StoreInventoryEvent.java @@ -1,9 +1,10 @@ -package uk.org.whoami.authme.events; +package fr.xephi.authme.events; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import uk.org.whoami.authme.cache.backup.FileCache; +import fr.xephi.authme.cache.backup.FileCache; + /** * diff --git a/src/main/java/uk/org/whoami/authme/gui/Clickable.java b/src/main/java/fr/xephi/authme/gui/Clickable.java similarity index 80% rename from src/main/java/uk/org/whoami/authme/gui/Clickable.java rename to src/main/java/fr/xephi/authme/gui/Clickable.java index 7787c9a5..5321a238 100644 --- a/src/main/java/uk/org/whoami/authme/gui/Clickable.java +++ b/src/main/java/fr/xephi/authme/gui/Clickable.java @@ -1,4 +1,4 @@ -package uk.org.whoami.authme.gui; +package fr.xephi.authme.gui; import org.getspout.spoutapi.event.screen.ButtonClickEvent; diff --git a/src/main/java/uk/org/whoami/authme/gui/CustomButton.java b/src/main/java/fr/xephi/authme/gui/CustomButton.java similarity index 93% rename from src/main/java/uk/org/whoami/authme/gui/CustomButton.java rename to src/main/java/fr/xephi/authme/gui/CustomButton.java index 9ba873a8..8bf5002a 100644 --- a/src/main/java/uk/org/whoami/authme/gui/CustomButton.java +++ b/src/main/java/fr/xephi/authme/gui/CustomButton.java @@ -1,4 +1,4 @@ -package uk.org.whoami.authme.gui; +package fr.xephi.authme.gui; import org.getspout.spoutapi.event.screen.ButtonClickEvent; import org.getspout.spoutapi.gui.GenericButton; diff --git a/src/main/java/uk/org/whoami/authme/gui/screens/LoginScreen.java b/src/main/java/fr/xephi/authme/gui/screens/LoginScreen.java similarity index 93% rename from src/main/java/uk/org/whoami/authme/gui/screens/LoginScreen.java rename to src/main/java/fr/xephi/authme/gui/screens/LoginScreen.java index 5215b698..c5758890 100644 --- a/src/main/java/uk/org/whoami/authme/gui/screens/LoginScreen.java +++ b/src/main/java/fr/xephi/authme/gui/screens/LoginScreen.java @@ -1,8 +1,5 @@ -package uk.org.whoami.authme.gui.screens; +package fr.xephi.authme.gui.screens; -/** - * @Author Hoezef - */ import java.util.List; import org.bukkit.event.EventHandler; @@ -18,10 +15,11 @@ import org.getspout.spoutapi.gui.Widget; import org.getspout.spoutapi.gui.WidgetAnchor; import org.getspout.spoutapi.player.SpoutPlayer; -import uk.org.whoami.authme.AuthMe; -import uk.org.whoami.authme.gui.Clickable; -import uk.org.whoami.authme.gui.CustomButton; -import uk.org.whoami.authme.settings.SpoutCfg; +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.gui.Clickable; +import fr.xephi.authme.gui.CustomButton; +import fr.xephi.authme.settings.SpoutCfg; + public class LoginScreen extends GenericPopup implements Clickable{ diff --git a/src/main/java/uk/org/whoami/authme/listener/AuthMeBlockListener.java b/src/main/java/fr/xephi/authme/listener/AuthMeBlockListener.java similarity index 66% rename from src/main/java/uk/org/whoami/authme/listener/AuthMeBlockListener.java rename to src/main/java/fr/xephi/authme/listener/AuthMeBlockListener.java index 7f351965..d6ab29dd 100644 --- a/src/main/java/uk/org/whoami/authme/listener/AuthMeBlockListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMeBlockListener.java @@ -1,20 +1,4 @@ -/* - * Copyright 2011 Sebastian Köhler . - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.org.whoami.authme.listener; +package fr.xephi.authme.listener; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -22,11 +6,12 @@ import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; -import uk.org.whoami.authme.AuthMe; -import uk.org.whoami.authme.Utils; -import uk.org.whoami.authme.cache.auth.PlayerCache; -import uk.org.whoami.authme.datasource.DataSource; -import uk.org.whoami.authme.settings.Settings; +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.Utils; +import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.datasource.DataSource; +import fr.xephi.authme.settings.Settings; + public class AuthMeBlockListener implements Listener { diff --git a/src/main/java/fr/xephi/authme/listener/AuthMeBungeeCordListener.java b/src/main/java/fr/xephi/authme/listener/AuthMeBungeeCordListener.java new file mode 100644 index 00000000..d5306eab --- /dev/null +++ b/src/main/java/fr/xephi/authme/listener/AuthMeBungeeCordListener.java @@ -0,0 +1,53 @@ +package fr.xephi.authme.listener; + +import net.md_5.bungee.api.event.ChatEvent; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; + +import fr.xephi.authme.Utils; +import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.datasource.DataSource; +import fr.xephi.authme.settings.Settings; + + +public class AuthMeBungeeCordListener implements Listener { + private DataSource data; + + public AuthMeBungeeCordListener(DataSource data) { + this.data = data; + } + + @EventHandler (priority = EventPriority.LOWEST) + public void onBungeeChatEvent(ChatEvent event) { + if (!Settings.bungee) return; + if (event.isCancelled()) return; + if (!event.isCommand()) return; + Player player = null; + for (Player p : Bukkit.getServer().getOnlinePlayers()) { + if (p.getAddress().getAddress().equals(event.getReceiver().getAddress().getAddress())) { + player = p; + } + } + String name = player.getName().toLowerCase(); + + if (Utils.getInstance().isUnrestricted(player)) { + return; + } + + if (PlayerCache.getInstance().isAuthenticated(name)) { + return; + } + + if (!data.isAuthAvailable(name)) { + if (!Settings.isForcedRegistrationEnabled) { + return; + } + } + event.setMessage("/unreacheablecommand"); + event.setCancelled(true); + } +} diff --git a/src/main/java/uk/org/whoami/authme/listener/AuthMeChestShopListener.java b/src/main/java/fr/xephi/authme/listener/AuthMeChestShopListener.java similarity index 82% rename from src/main/java/uk/org/whoami/authme/listener/AuthMeChestShopListener.java rename to src/main/java/fr/xephi/authme/listener/AuthMeChestShopListener.java index 73cd37bc..ce9b12b7 100644 --- a/src/main/java/uk/org/whoami/authme/listener/AuthMeChestShopListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMeChestShopListener.java @@ -1,4 +1,4 @@ -package uk.org.whoami.authme.listener; +package fr.xephi.authme.listener; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -8,11 +8,12 @@ import org.bukkit.event.Listener; import com.Acrobot.ChestShop.Events.PreTransactionEvent; import com.Acrobot.ChestShop.Events.PreTransactionEvent.TransactionOutcome; -import uk.org.whoami.authme.AuthMe; -import uk.org.whoami.authme.Utils; -import uk.org.whoami.authme.cache.auth.PlayerCache; -import uk.org.whoami.authme.datasource.DataSource; -import uk.org.whoami.authme.settings.Settings; +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.Utils; +import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.datasource.DataSource; +import fr.xephi.authme.settings.Settings; + public class AuthMeChestShopListener implements Listener { diff --git a/src/main/java/uk/org/whoami/authme/listener/AuthMeEntityListener.java b/src/main/java/fr/xephi/authme/listener/AuthMeEntityListener.java similarity index 84% rename from src/main/java/uk/org/whoami/authme/listener/AuthMeEntityListener.java rename to src/main/java/fr/xephi/authme/listener/AuthMeEntityListener.java index fcf8fbf0..7220a0ba 100644 --- a/src/main/java/uk/org/whoami/authme/listener/AuthMeEntityListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMeEntityListener.java @@ -1,20 +1,4 @@ -/* - * Copyright 2011 Sebastian Köhler . - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.org.whoami.authme.listener; +package fr.xephi.authme.listener; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -27,12 +11,13 @@ import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.entity.EntityTargetEvent; import org.bukkit.event.entity.FoodLevelChangeEvent; -import uk.org.whoami.authme.AuthMe; -import uk.org.whoami.authme.Utils; -import uk.org.whoami.authme.cache.auth.PlayerCache; -import uk.org.whoami.authme.datasource.DataSource; -import uk.org.whoami.authme.plugin.manager.CombatTagComunicator; -import uk.org.whoami.authme.settings.Settings; +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.Utils; +import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.datasource.DataSource; +import fr.xephi.authme.plugin.manager.CombatTagComunicator; +import fr.xephi.authme.settings.Settings; + public class AuthMeEntityListener implements Listener{ @@ -58,6 +43,9 @@ public class AuthMeEntityListener implements Listener{ if(Utils.getInstance().isUnrestricted((Player)entity)) { return; } + + if(instance.citizens.isNPC(entity, instance)) + return; Player player = (Player) entity; String name = player.getName().toLowerCase(); @@ -88,6 +76,9 @@ public class AuthMeEntityListener implements Listener{ if (!(entity instanceof Player)) { return; } + + if(instance.citizens.isNPC(entity, instance)) + return; Player player = (Player) entity; String name = player.getName().toLowerCase(); @@ -115,6 +106,9 @@ public class AuthMeEntityListener implements Listener{ if (!(entity instanceof Player)) { return; } + + if(instance.citizens.isNPC(entity, instance)) + return; Player player = (Player) entity; String name = player.getName().toLowerCase(); @@ -143,6 +137,9 @@ public class AuthMeEntityListener implements Listener{ if (!(entity instanceof Player)) { return; } + + if(instance.citizens.isNPC(entity, instance)) + return; Player player = (Player) entity; String name = player.getName().toLowerCase(); @@ -177,6 +174,9 @@ public class AuthMeEntityListener implements Listener{ return; } + if(instance.citizens.isNPC(player, instance)) + return; + if (PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) { return; } @@ -205,6 +205,9 @@ public class AuthMeEntityListener implements Listener{ if (Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) { return; } + + if(instance.citizens.isNPC(player, instance)) + return; if (PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) { return; diff --git a/src/main/java/uk/org/whoami/authme/listener/AuthMePlayerListener.java b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java similarity index 70% rename from src/main/java/uk/org/whoami/authme/listener/AuthMePlayerListener.java rename to src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java index 27bc0be9..acc99559 100644 --- a/src/main/java/uk/org/whoami/authme/listener/AuthMePlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java @@ -1,20 +1,4 @@ -/* - * Copyright 2011 Sebastian Köhler . - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.org.whoami.authme.listener; +package fr.xephi.authme.listener; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; @@ -53,29 +37,29 @@ import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.scheduler.BukkitScheduler; import org.bukkit.scheduler.BukkitTask; -import uk.org.whoami.authme.AuthMe; -import uk.org.whoami.authme.ConsoleLogger; -import uk.org.whoami.authme.Utils; -import uk.org.whoami.authme.api.API; -import uk.org.whoami.authme.cache.auth.PlayerAuth; -import uk.org.whoami.authme.cache.auth.PlayerCache; -import uk.org.whoami.authme.cache.backup.DataFileCache; -import uk.org.whoami.authme.cache.backup.FileCache; -import uk.org.whoami.authme.cache.limbo.LimboCache; -import uk.org.whoami.authme.cache.limbo.LimboPlayer; -import uk.org.whoami.authme.datasource.DataSource; -import uk.org.whoami.authme.events.AuthMeTeleportEvent; -import uk.org.whoami.authme.events.ProtectInventoryEvent; -import uk.org.whoami.authme.events.RestoreInventoryEvent; -import uk.org.whoami.authme.events.SessionEvent; -import uk.org.whoami.authme.events.SpawnTeleportEvent; -import uk.org.whoami.authme.plugin.manager.CombatTagComunicator; -import uk.org.whoami.authme.settings.Messages; -import uk.org.whoami.authme.settings.PlayersLogs; -import uk.org.whoami.authme.settings.Settings; -import uk.org.whoami.authme.settings.Spawn; -import uk.org.whoami.authme.task.MessageTask; -import uk.org.whoami.authme.task.TimeoutTask; +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.ConsoleLogger; +import fr.xephi.authme.Utils; +import fr.xephi.authme.api.API; +import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.cache.backup.DataFileCache; +import fr.xephi.authme.cache.backup.FileCache; +import fr.xephi.authme.cache.limbo.LimboCache; +import fr.xephi.authme.cache.limbo.LimboPlayer; +import fr.xephi.authme.datasource.DataSource; +import fr.xephi.authme.events.AuthMeTeleportEvent; +import fr.xephi.authme.events.ProtectInventoryEvent; +import fr.xephi.authme.events.RestoreInventoryEvent; +import fr.xephi.authme.events.SessionEvent; +import fr.xephi.authme.events.SpawnTeleportEvent; +import fr.xephi.authme.plugin.manager.CombatTagComunicator; +import fr.xephi.authme.settings.Messages; +import fr.xephi.authme.settings.PlayersLogs; +import fr.xephi.authme.settings.Settings; +import fr.xephi.authme.task.MessageTask; +import fr.xephi.authme.task.TimeoutTask; + public class AuthMePlayerListener implements Listener { @@ -142,328 +126,209 @@ public class AuthMePlayerListener implements Listener { return; String cmd = event.getMessage().split(" ")[0]; + + if (data.isAuthAvailable(name)) { + player.sendMessage(m._("login_msg")); + } else { + if (!Settings.isForcedRegistrationEnabled) { + return; + } + if (Settings.emailRegistration) { + player.sendMessage(m._("reg_email_msg")); + return; + } else { + player.sendMessage(m._("reg_msg")); + return; + } + } if (!Settings.isChatAllowed && !(Settings.allowCommands.contains(cmd))) { event.setCancelled(true); return; } - - if (!event.isAsynchronous()) { - if (data.isAuthAvailable(name)) { - player.sendMessage(m._("login_msg")); - } else { - if (!Settings.isForcedRegistrationEnabled) { - return; - } - if (Settings.emailRegistration) { - player.sendMessage(m._("reg_email_msg")); - } else { - player.sendMessage(m._("reg_msg")); - } - } - } else { - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() - { - @Override - public void run() { - if (data.isAuthAvailable(name)) { - player.sendMessage(m._("login_msg")); - } else { - if (Settings.isForcedRegistrationEnabled) { - if (Settings.emailRegistration) { - player.sendMessage(m._("reg_email_msg")); - } else { - player.sendMessage(m._("reg_msg")); - } - } - } - }}); - } } @EventHandler( priority = EventPriority.HIGH) public void onPlayerHighChat(AsyncPlayerChatEvent event) { - if (event.isCancelled() || event.getPlayer() == null) { + if (event.isCancelled() || event.getPlayer() == null) return; - } final Player player = event.getPlayer(); final String name = player.getName().toLowerCase(); - if (Utils.getInstance().isUnrestricted(player)) { + if (Utils.getInstance().isUnrestricted(player)) return; - } - if (PlayerCache.getInstance().isAuthenticated(name)) { + if (PlayerCache.getInstance().isAuthenticated(name)) return; - } String cmd = event.getMessage().split(" ")[0]; + + if (data.isAuthAvailable(name)) { + player.sendMessage(m._("login_msg")); + } else { + if (!Settings.isForcedRegistrationEnabled) { + return; + } + if (Settings.emailRegistration) { + player.sendMessage(m._("reg_email_msg")); + return; + } else { + player.sendMessage(m._("reg_msg")); + return; + } + } if (!Settings.isChatAllowed && !(Settings.allowCommands.contains(cmd))) { event.setCancelled(true); return; } - - if (!event.isAsynchronous()) { - if (data.isAuthAvailable(name)) { - player.sendMessage(m._("login_msg")); - } else { - if (!Settings.isForcedRegistrationEnabled) { - return; - } - if (Settings.emailRegistration) { - player.sendMessage(m._("reg_email_msg")); - } else { - player.sendMessage(m._("reg_msg")); - } - } - } else { - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() - { - @Override - public void run() { - if (data.isAuthAvailable(name)) { - player.sendMessage(m._("login_msg")); - } else { - if (Settings.isForcedRegistrationEnabled) { - if (Settings.emailRegistration) { - player.sendMessage(m._("reg_email_msg")); - } else { - player.sendMessage(m._("reg_msg")); - } - } - } - }}); - } } @EventHandler( priority = EventPriority.MONITOR) public void onPlayerChat(AsyncPlayerChatEvent event) { - if (event.isCancelled() || event.getPlayer() == null) { + if (event.isCancelled() || event.getPlayer() == null) return; - } final Player player = event.getPlayer(); final String name = player.getName().toLowerCase(); - if (Utils.getInstance().isUnrestricted(player)) { + if (Utils.getInstance().isUnrestricted(player)) return; - } - if (PlayerCache.getInstance().isAuthenticated(name)) { + if (PlayerCache.getInstance().isAuthenticated(name)) return; - } String cmd = event.getMessage().split(" ")[0]; + + if (data.isAuthAvailable(name)) { + player.sendMessage(m._("login_msg")); + } else { + if (!Settings.isForcedRegistrationEnabled) { + return; + } + if (Settings.emailRegistration) { + player.sendMessage(m._("reg_email_msg")); + return; + } else { + player.sendMessage(m._("reg_msg")); + return; + } + } if (!Settings.isChatAllowed && !(Settings.allowCommands.contains(cmd))) { event.setCancelled(true); return; } - - if (!event.isAsynchronous()) { - if (data.isAuthAvailable(name)) { - player.sendMessage(m._("login_msg")); - } else { - if (!Settings.isForcedRegistrationEnabled) { - return; - } - if (Settings.emailRegistration) { - player.sendMessage(m._("reg_email_msg")); - } else { - player.sendMessage(m._("reg_msg")); - } - } - } else { - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() - { - @Override - public void run() { - if (data.isAuthAvailable(name)) { - player.sendMessage(m._("login_msg")); - } else { - if (Settings.isForcedRegistrationEnabled) { - if (Settings.emailRegistration) { - player.sendMessage(m._("reg_email_msg")); - } else { - player.sendMessage(m._("reg_msg")); - } - } - } - }}); - } } @EventHandler( priority = EventPriority.HIGHEST) public void onPlayerHighestChat(AsyncPlayerChatEvent event) { - if (event.isCancelled() || event.getPlayer() == null) { + if (event.isCancelled() || event.getPlayer() == null) return; - } final Player player = event.getPlayer(); final String name = player.getName().toLowerCase(); - if (Utils.getInstance().isUnrestricted(player)) { + if (Utils.getInstance().isUnrestricted(player)) return; - } - if (PlayerCache.getInstance().isAuthenticated(name)) { + if (PlayerCache.getInstance().isAuthenticated(name)) return; - } String cmd = event.getMessage().split(" ")[0]; + + if (data.isAuthAvailable(name)) { + player.sendMessage(m._("login_msg")); + } else { + if (!Settings.isForcedRegistrationEnabled) { + return; + } + if (Settings.emailRegistration) { + player.sendMessage(m._("reg_email_msg")); + return; + } else { + player.sendMessage(m._("reg_msg")); + return; + } + } if (!Settings.isChatAllowed && !(Settings.allowCommands.contains(cmd))) { event.setCancelled(true); return; } - - if (!event.isAsynchronous()) { - if (data.isAuthAvailable(name)) { - player.sendMessage(m._("login_msg")); - } else { - if (!Settings.isForcedRegistrationEnabled) { - return; - } - if (Settings.emailRegistration) { - player.sendMessage(m._("reg_email_msg")); - } else { - player.sendMessage(m._("reg_msg")); - } - } - } else { - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() - { - @Override - public void run() { - if (data.isAuthAvailable(name)) { - player.sendMessage(m._("login_msg")); - } else { - if (Settings.isForcedRegistrationEnabled) { - if (Settings.emailRegistration) { - player.sendMessage(m._("reg_email_msg")); - } else { - player.sendMessage(m._("reg_msg")); - } - } - } - }}); - } } @EventHandler( priority = EventPriority.LOWEST) public void onPlayerEarlyChat(AsyncPlayerChatEvent event) { - if (event.isCancelled() || event.getPlayer() == null) { + if (event.isCancelled() || event.getPlayer() == null) return; - } final Player player = event.getPlayer(); final String name = player.getName().toLowerCase(); - if (Utils.getInstance().isUnrestricted(player)) { + if (Utils.getInstance().isUnrestricted(player)) return; - } - if (PlayerCache.getInstance().isAuthenticated(name)) { + if (PlayerCache.getInstance().isAuthenticated(name)) return; - } String cmd = event.getMessage().split(" ")[0]; + + if (data.isAuthAvailable(name)) { + player.sendMessage(m._("login_msg")); + } else { + if (!Settings.isForcedRegistrationEnabled) { + return; + } + if (Settings.emailRegistration) { + player.sendMessage(m._("reg_email_msg")); + return; + } else { + player.sendMessage(m._("reg_msg")); + return; + } + } if (!Settings.isChatAllowed && !(Settings.allowCommands.contains(cmd))) { event.setCancelled(true); return; } - - if (!event.isAsynchronous()) { - if (data.isAuthAvailable(name)) { - player.sendMessage(m._("login_msg")); - } else { - if (!Settings.isForcedRegistrationEnabled) { - return; - } - if (Settings.emailRegistration) { - player.sendMessage(m._("reg_email_msg")); - } else { - player.sendMessage(m._("reg_msg")); - } - } - } else { - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() - { - @Override - public void run() { - if (data.isAuthAvailable(name)) { - player.sendMessage(m._("login_msg")); - } else { - if (Settings.isForcedRegistrationEnabled) { - if (Settings.emailRegistration) { - player.sendMessage(m._("reg_email_msg")); - } else { - player.sendMessage(m._("reg_msg")); - } - } - } - }}); - } } @EventHandler( priority = EventPriority.LOW) public void onPlayerLowChat(AsyncPlayerChatEvent event) { - if (event.isCancelled() || event.getPlayer() == null) { + if (event.isCancelled() || event.getPlayer() == null) return; - } final Player player = event.getPlayer(); final String name = player.getName().toLowerCase(); - if (Utils.getInstance().isUnrestricted(player)) { + if (Utils.getInstance().isUnrestricted(player)) return; - } - if (PlayerCache.getInstance().isAuthenticated(name)) { + if (PlayerCache.getInstance().isAuthenticated(name)) return; - } String cmd = event.getMessage().split(" ")[0]; + + if (data.isAuthAvailable(name)) { + player.sendMessage(m._("login_msg")); + } else { + if (!Settings.isForcedRegistrationEnabled) { + return; + } + if (Settings.emailRegistration) { + player.sendMessage(m._("reg_email_msg")); + } else { + player.sendMessage(m._("reg_msg")); + } + } if (!Settings.isChatAllowed && !(Settings.allowCommands.contains(cmd))) { event.setCancelled(true); return; } - - if (!event.isAsynchronous()) { - if (data.isAuthAvailable(name)) { - player.sendMessage(m._("login_msg")); - } else { - if (!Settings.isForcedRegistrationEnabled) { - return; - } - if (Settings.emailRegistration) { - player.sendMessage(m._("reg_email_msg")); - } else { - player.sendMessage(m._("reg_msg")); - } - } - } else { - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() - { - @Override - public void run() { - if (data.isAuthAvailable(name)) { - player.sendMessage(m._("login_msg")); - } else { - if (Settings.isForcedRegistrationEnabled) { - if (Settings.emailRegistration) { - player.sendMessage(m._("reg_email_msg")); - } else { - player.sendMessage(m._("reg_msg")); - } - } - } - }}); - } } @EventHandler(priority = EventPriority.MONITOR) @@ -497,20 +362,7 @@ public class AuthMePlayerListener implements Listener { } int radius = Settings.getMovementRadius; - Location spawn = player.getWorld().getSpawnLocation(); - if (plugin.mv != null) { - try { - spawn = plugin.mv.getMVWorldManager().getMVWorld(player.getWorld()).getSpawnLocation(); - } catch (NullPointerException npe) { - } catch (ClassCastException cce) { - } catch (NoClassDefFoundError ncdfe) { - } - } - if (plugin.essentialsSpawn != null) { - spawn = plugin.essentialsSpawn; - } - if (Spawn.getInstance().getLocation() != null && Spawn.getInstance().getLocation().getWorld().equals(player.getWorld())) - spawn = Spawn.getInstance().getLocation(); + Location spawn = plugin.getSpawnLocation(player.getWorld()); if (!event.getPlayer().getWorld().equals(spawn.getWorld())) { event.getPlayer().teleport(spawn); @@ -653,20 +505,7 @@ public class AuthMePlayerListener implements Listener { Player player = event.getPlayer(); World world = player.getWorld(); - Location spawnLoc = world.getSpawnLocation(); - if (plugin.mv != null) { - try { - spawnLoc = plugin.mv.getMVWorldManager().getMVWorld(player.getWorld()).getSpawnLocation(); - } catch (NullPointerException npe) { - } catch (ClassCastException cce) { - } catch (NoClassDefFoundError ncdfe) { - } - } - if (plugin.essentialsSpawn != null) { - spawnLoc = plugin.essentialsSpawn; - } - if (Spawn.getInstance().getLocation() != null) - spawnLoc = Spawn.getInstance().getLocation(); + Location spawnLoc = plugin.getSpawnLocation(world); gm = player.getGameMode().getValue(); final String name = player.getName().toLowerCase(); gameMode.put(name, gm); @@ -739,9 +578,20 @@ public class AuthMePlayerListener implements Listener { // isent in session or session was ended correctly if (Settings.isForceSurvivalModeEnabled && !Settings.forceOnlyAfterLogin) e.getPlayer().setGameMode(GameMode.SURVIVAL); - LimboCache.getInstance().updateLimboPlayer(player); - DataFileCache dataFile = new DataFileCache(LimboCache.getInstance().getLimboPlayer(name).getInventory(),LimboCache.getInstance().getLimboPlayer(name).getArmour()); - playerBackup.createCache(name, dataFile, LimboCache.getInstance().getLimboPlayer(name).getGroup(),LimboCache.getInstance().getLimboPlayer(name).getOperator(),LimboCache.getInstance().getLimboPlayer(name).isFlying()); + if (Settings.isTeleportToSpawnEnabled || (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName()))) { + SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawnLoc, PlayerCache.getInstance().isAuthenticated(name)); + plugin.getServer().getPluginManager().callEvent(tpEvent); + if(!tpEvent.isCancelled()) { + if (!tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).isLoaded()) { + tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).load(); + } + player.teleport(tpEvent.getTo()); + } + } + placePlayerSafely(player, spawnLoc); + LimboCache.getInstance().updateLimboPlayer(player); + DataFileCache dataFile = new DataFileCache(LimboCache.getInstance().getLimboPlayer(name).getInventory(),LimboCache.getInstance().getLimboPlayer(name).getArmour()); + playerBackup.createCache(name, dataFile, LimboCache.getInstance().getLimboPlayer(name).getGroup(),LimboCache.getInstance().getLimboPlayer(name).getOperator(),LimboCache.getInstance().getLimboPlayer(name).isFlying()); } else { if (Settings.isForceSurvivalModeEnabled && !Settings.forceOnlyAfterLogin) e.getPlayer().setGameMode(GameMode.SURVIVAL); @@ -752,30 +602,20 @@ public class AuthMePlayerListener implements Listener { return; } } - if(Settings.protectInventoryBeforeLogInEnabled) { try { LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(player.getName().toLowerCase()); - ProtectInventoryEvent ev = new ProtectInventoryEvent(player, limbo.getInventory(), limbo.getArmour(), 36, 4); + ProtectInventoryEvent ev = new ProtectInventoryEvent(player, limbo.getInventory(), limbo.getArmour()); plugin.getServer().getPluginManager().callEvent(ev); if (ev.isCancelled()) { if (!Settings.noConsoleSpam) - ConsoleLogger.info("ProtectInventoryEvent has been cancelled for " + player.getName() + " ..."); + ConsoleLogger.info("ProtectInventoryEvent has been cancelled for " + player.getName() + " ..."); + } else { + API.setPlayerInventory(player, ev.getEmptyInventory(), ev.getEmptyArmor()); } } catch (NullPointerException ex) { } } - if (Settings.isTeleportToSpawnEnabled || (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName()))) { - SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawnLoc, PlayerCache.getInstance().isAuthenticated(name)); - plugin.getServer().getPluginManager().callEvent(tpEvent); - if(!tpEvent.isCancelled()) { - if (!tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).isLoaded()) { - tpEvent.getTo().getWorld().getChunkAt(tpEvent.getTo()).load(); - } - player.teleport(tpEvent.getTo()); - } - } - placePlayerSafely(player, spawnLoc); String msg = ""; if(Settings.emailRegistration) { msg = data.isAuthAvailable(name) ? m._("login_msg") : m._("reg_email_msg"); @@ -794,8 +634,10 @@ public class AuthMePlayerListener implements Listener { LimboCache.getInstance().addLimboPlayer(player); if(player.isOp()) player.setOp(false); - player.setAllowFlight(true); - player.setFlying(true); + if (!Settings.isMovementAllowed) { + player.setAllowFlight(true); + player.setFlying(true); + } BukkitTask msgT = sched.runTask(plugin, new MessageTask(plugin, name, msg, msgInterval)); LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT.getTaskId()); player.setNoDamageTicks(Settings.getRegistrationTimeout * 20); @@ -832,12 +674,12 @@ public class AuthMePlayerListener implements Listener { if (PlayerCache.getInstance().isAuthenticated(name) && !player.isDead()) { if(Settings.isSaveQuitLocationEnabled && data.isAuthAvailable(name)) { - final PlayerAuth auth = new PlayerAuth(event.getPlayer().getName().toLowerCase(),loc.getBlockX(),loc.getBlockY(),loc.getBlockZ(),loc.getWorld().getName()); + final PlayerAuth auth = new PlayerAuth(name,loc.getBlockX(),loc.getBlockY(),loc.getBlockZ(),loc.getWorld().getName()); try { if (data instanceof Thread) { data.updateQuitLoc(auth); } else { - Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable(){ + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ @Override public void run() { data.updateQuitLoc(auth); @@ -859,9 +701,10 @@ public class AuthMePlayerListener implements Listener { } utils.addNormal(player, limbo.getGroup()); player.setOp(limbo.getOperator()); - if (player.getGameMode() != GameMode.CREATIVE) - player.setAllowFlight(limbo.isFlying()); - player.setFlying(limbo.isFlying()); + if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) { + player.setAllowFlight(limbo.isFlying()); + player.setFlying(limbo.isFlying()); + } this.plugin.getServer().getScheduler().cancelTask(limbo.getTimeoutTaskId()); LimboCache.getInstance().deleteLimboPlayer(name); if(playerBackup.doesCacheExist(name)) { @@ -876,7 +719,6 @@ public class AuthMePlayerListener implements Listener { } catch (NullPointerException ex) { } if (gameMode.containsKey(name)) gameMode.remove(name); - plugin.premium.remove(player.getName()); player.saveData(); } @@ -907,12 +749,12 @@ public class AuthMePlayerListener implements Listener { String name = player.getName().toLowerCase(); if ((PlayerCache.getInstance().isAuthenticated(name)) && (!player.isDead()) && (Settings.isSaveQuitLocationEnabled) && data.isAuthAvailable(name)) { - final PlayerAuth auth = new PlayerAuth(event.getPlayer().getName().toLowerCase(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(),loc.getWorld().getName()); + final PlayerAuth auth = new PlayerAuth(name, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(),loc.getWorld().getName()); try { if (data instanceof Thread) { data.updateQuitLoc(auth); } else { - Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable(){ + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ @Override public void run() { data.updateQuitLoc(auth); @@ -949,9 +791,10 @@ public class AuthMePlayerListener implements Listener { } this.utils.addNormal(player, limbo.getGroup()); player.setOp(limbo.getOperator()); - if (player.getGameMode() != GameMode.CREATIVE) - player.setAllowFlight(limbo.isFlying()); - player.setFlying(limbo.isFlying()); + if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) { + player.setAllowFlight(limbo.isFlying()); + player.setFlying(limbo.isFlying()); + } this.plugin.getServer().getScheduler().cancelTask(limbo.getTimeoutTaskId()); LimboCache.getInstance().deleteLimboPlayer(name); if (this.playerBackup.doesCacheExist(name)) { @@ -965,7 +808,6 @@ public class AuthMePlayerListener implements Listener { if (gameMode.containsKey(name)) gameMode.remove(name); player.getVehicle().eject(); player.saveData(); - plugin.premium.remove(player.getName()); } catch (NullPointerException ex) {} } @@ -982,6 +824,9 @@ public class AuthMePlayerListener implements Listener { return; } + if(plugin.getCitizensCommunicator().isNPC(player, plugin)) + return; + if (PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) { return; } @@ -1006,6 +851,9 @@ public class AuthMePlayerListener implements Listener { return; } + if(plugin.getCitizensCommunicator().isNPC(player, plugin)) + return; + if (PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) { return; } @@ -1032,6 +880,9 @@ public class AuthMePlayerListener implements Listener { return; } + if(plugin.getCitizensCommunicator().isNPC(player, plugin)) + return; + if (PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) { return; } @@ -1055,6 +906,9 @@ public class AuthMePlayerListener implements Listener { return; } + if(plugin.getCitizensCommunicator().isNPC(player, plugin)) + return; + if (PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) { return; } @@ -1105,6 +959,9 @@ public class AuthMePlayerListener implements Listener { return; } + if(plugin.getCitizensCommunicator().isNPC(player, plugin)) + return; + if (PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) { return; } @@ -1174,6 +1031,9 @@ public class AuthMePlayerListener implements Listener { if (Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) return; + if(plugin.getCitizensCommunicator().isNPC(player, plugin)) + return; + if (PlayerCache.getInstance().isAuthenticated(name)) return; @@ -1184,20 +1044,7 @@ public class AuthMePlayerListener implements Listener { if (!Settings.isTeleportToSpawnEnabled && !Settings.isForceSpawnLocOnJoinEnabled) return; - Location spawn = player.getWorld().getSpawnLocation(); - if (plugin.mv != null) { - try { - spawn = plugin.mv.getMVWorldManager().getMVWorld(player.getWorld()).getSpawnLocation(); - } catch (NullPointerException npe) { - } catch (ClassCastException cce) { - } catch (NoClassDefFoundError ncdfe) { - } - } - if (plugin.essentialsSpawn != null) { - spawn = plugin.essentialsSpawn; - } - if (Spawn.getInstance().getLocation() != null && Spawn.getInstance().getLocation().getWorld().equals(player.getWorld())) - spawn = Spawn.getInstance().getLocation(); + Location spawn = plugin.getSpawnLocation(player.getWorld()); event.setRespawnLocation(spawn); } diff --git a/src/main/java/uk/org/whoami/authme/listener/AuthMeSpoutListener.java b/src/main/java/fr/xephi/authme/listener/AuthMeSpoutListener.java similarity index 72% rename from src/main/java/uk/org/whoami/authme/listener/AuthMeSpoutListener.java rename to src/main/java/fr/xephi/authme/listener/AuthMeSpoutListener.java index ec260452..8d7776c1 100644 --- a/src/main/java/uk/org/whoami/authme/listener/AuthMeSpoutListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMeSpoutListener.java @@ -1,18 +1,13 @@ -package uk.org.whoami.authme.listener; - -/** - * @Author Hoezef - */ +package fr.xephi.authme.listener; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.getspout.spoutapi.event.spout.SpoutCraftEnableEvent; - -import uk.org.whoami.authme.cache.auth.PlayerCache; -import uk.org.whoami.authme.datasource.DataSource; -import uk.org.whoami.authme.gui.screens.LoginScreen; -import uk.org.whoami.authme.settings.SpoutCfg; +import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.datasource.DataSource; +import fr.xephi.authme.gui.screens.LoginScreen; +import fr.xephi.authme.settings.SpoutCfg; public class AuthMeSpoutListener implements Listener { private DataSource data; diff --git a/src/main/java/uk/org/whoami/authme/plugin/manager/BungeeCordMessage.java b/src/main/java/fr/xephi/authme/plugin/manager/BungeeCordMessage.java similarity index 90% rename from src/main/java/uk/org/whoami/authme/plugin/manager/BungeeCordMessage.java rename to src/main/java/fr/xephi/authme/plugin/manager/BungeeCordMessage.java index 27a37498..d64e3c9f 100644 --- a/src/main/java/uk/org/whoami/authme/plugin/manager/BungeeCordMessage.java +++ b/src/main/java/fr/xephi/authme/plugin/manager/BungeeCordMessage.java @@ -1,4 +1,4 @@ -package uk.org.whoami.authme.plugin.manager; +package fr.xephi.authme.plugin.manager; import java.io.ByteArrayInputStream; import java.io.DataInputStream; @@ -7,17 +7,17 @@ import java.io.IOException; import org.bukkit.entity.Player; import org.bukkit.plugin.messaging.PluginMessageListener; -import uk.org.whoami.authme.AuthMe; - +import fr.xephi.authme.AuthMe; + public class BungeeCordMessage implements PluginMessageListener { public AuthMe plugin; - + public BungeeCordMessage(AuthMe plugin) { this.plugin = plugin; } - + @Override public void onPluginMessageReceived(String channel, Player player, byte[] message) { try { diff --git a/src/main/java/uk/org/whoami/authme/plugin/manager/CitizensCommunicator.java b/src/main/java/fr/xephi/authme/plugin/manager/CitizensCommunicator.java similarity index 85% rename from src/main/java/uk/org/whoami/authme/plugin/manager/CitizensCommunicator.java rename to src/main/java/fr/xephi/authme/plugin/manager/CitizensCommunicator.java index be20207e..a2c67a20 100644 --- a/src/main/java/uk/org/whoami/authme/plugin/manager/CitizensCommunicator.java +++ b/src/main/java/fr/xephi/authme/plugin/manager/CitizensCommunicator.java @@ -1,11 +1,11 @@ -package uk.org.whoami.authme.plugin.manager; +package fr.xephi.authme.plugin.manager; import net.citizensnpcs.api.CitizensAPI; import net.citizensnpcs.api.CitizensManager; import org.bukkit.entity.Entity; -import uk.org.whoami.authme.AuthMe; +import fr.xephi.authme.AuthMe; public class CitizensCommunicator { @@ -26,7 +26,7 @@ public class CitizensCommunicator { } } catch (NoClassDefFoundError ncdfe) { return false; - } catch (NullPointerException npe) { + } catch (Exception npe) { return false; } } diff --git a/src/main/java/uk/org/whoami/authme/plugin/manager/CombatTagComunicator.java b/src/main/java/fr/xephi/authme/plugin/manager/CombatTagComunicator.java similarity index 91% rename from src/main/java/uk/org/whoami/authme/plugin/manager/CombatTagComunicator.java rename to src/main/java/fr/xephi/authme/plugin/manager/CombatTagComunicator.java index caa7b5a5..a5c372eb 100644 --- a/src/main/java/uk/org/whoami/authme/plugin/manager/CombatTagComunicator.java +++ b/src/main/java/fr/xephi/authme/plugin/manager/CombatTagComunicator.java @@ -1,8 +1,4 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package uk.org.whoami.authme.plugin.manager; +package fr.xephi.authme.plugin.manager; import com.trc202.CombatTag.CombatTag; import com.trc202.CombatTagApi.CombatTagApi; @@ -11,10 +7,6 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; -/** - * - * @author stefano - */ public abstract class CombatTagComunicator { static CombatTagApi combatApi; diff --git a/src/main/java/uk/org/whoami/authme/plugin/manager/EssSpawn.java b/src/main/java/fr/xephi/authme/plugin/manager/EssSpawn.java similarity index 88% rename from src/main/java/uk/org/whoami/authme/plugin/manager/EssSpawn.java rename to src/main/java/fr/xephi/authme/plugin/manager/EssSpawn.java index 3540e1a3..e5f0fa1b 100644 --- a/src/main/java/uk/org/whoami/authme/plugin/manager/EssSpawn.java +++ b/src/main/java/fr/xephi/authme/plugin/manager/EssSpawn.java @@ -1,16 +1,12 @@ -package uk.org.whoami.authme.plugin.manager; +package fr.xephi.authme.plugin.manager; import java.io.File; import org.bukkit.Bukkit; import org.bukkit.Location; -import uk.org.whoami.authme.settings.CustomConfiguration; +import fr.xephi.authme.settings.CustomConfiguration; -/** -* -* @author Xephi59 -*/ public class EssSpawn extends CustomConfiguration { private static EssSpawn spawn; diff --git a/src/main/java/fr/xephi/authme/security/HashAlgorithm.java b/src/main/java/fr/xephi/authme/security/HashAlgorithm.java new file mode 100644 index 00000000..65ec1327 --- /dev/null +++ b/src/main/java/fr/xephi/authme/security/HashAlgorithm.java @@ -0,0 +1,39 @@ +package fr.xephi.authme.security; + +import org.apache.commons.lang.ObjectUtils.Null; + +public enum HashAlgorithm { + + MD5(fr.xephi.authme.security.crypts.MD5.class), + SHA1(fr.xephi.authme.security.crypts.SHA1.class), + SHA256(fr.xephi.authme.security.crypts.SHA256.class), + WHIRLPOOL(fr.xephi.authme.security.crypts.WHIRLPOOL.class), + XAUTH(fr.xephi.authme.security.crypts.XAUTH.class), + MD5VB(fr.xephi.authme.security.crypts.MD5VB.class), + PHPBB(fr.xephi.authme.security.crypts.PHPBB.class), + PLAINTEXT(fr.xephi.authme.security.crypts.PLAINTEXT.class), + MYBB(fr.xephi.authme.security.crypts.MYBB.class), + IPB3(fr.xephi.authme.security.crypts.IPB3.class), + PHPFUSION(fr.xephi.authme.security.crypts.PHPFUSION.class), + SMF(fr.xephi.authme.security.crypts.SMF.class), + XENFORO(fr.xephi.authme.security.crypts.XF.class), + SALTED2MD5(fr.xephi.authme.security.crypts.SALTED2MD5.class), + JOOMLA(fr.xephi.authme.security.crypts.JOOMLA.class), + BCRYPT(fr.xephi.authme.security.crypts.BCRYPT.class), + WBB3(fr.xephi.authme.security.crypts.WBB3.class), + SHA512(fr.xephi.authme.security.crypts.SHA512.class), + DOUBLEMD5(fr.xephi.authme.security.crypts.DOUBLEMD5.class), + PBKDF2(fr.xephi.authme.security.crypts.CryptPBKDF2.class), + WORDPRESS(fr.xephi.authme.security.crypts.WORDPRESS.class), + CUSTOM(Null.class); + + Class classe; + + HashAlgorithm(Class classe) { + this.classe = classe; + } + + public Class getclass() { + return classe; + } +} \ No newline at end of file diff --git a/src/main/java/fr/xephi/authme/security/PasswordSecurity.java b/src/main/java/fr/xephi/authme/security/PasswordSecurity.java new file mode 100644 index 00000000..ff963dda --- /dev/null +++ b/src/main/java/fr/xephi/authme/security/PasswordSecurity.java @@ -0,0 +1,156 @@ +package fr.xephi.authme.security; + +import java.math.BigInteger; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.util.HashMap; + +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.events.PasswordEncryptionEvent; +import fr.xephi.authme.security.crypts.BCRYPT; +import fr.xephi.authme.security.crypts.EncryptionMethod; +import fr.xephi.authme.settings.Settings; + + +public class PasswordSecurity { + + private static SecureRandom rnd = new SecureRandom(); + public static HashMap userSalt = new HashMap(); + + private static String createSalt(int length) throws NoSuchAlgorithmException { + byte[] msg = new byte[40]; + rnd.nextBytes(msg); + MessageDigest sha1 = MessageDigest.getInstance("SHA1"); + sha1.reset(); + byte[] digest = sha1.digest(msg); + return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1,digest)).substring(0, length); + } + + public static String getHash(HashAlgorithm alg, String password, String playerName) throws NoSuchAlgorithmException { + EncryptionMethod method; + try { + if (alg != HashAlgorithm.CUSTOM) + method = (EncryptionMethod) alg.getclass().newInstance(); + else method = null; + } catch (InstantiationException e) { + throw new NoSuchAlgorithmException("Problem with this hash algorithm"); + } catch (IllegalAccessException e) { + throw new NoSuchAlgorithmException("Problem with this hash algorithm"); + } + String salt = ""; + switch (alg) { + case MD5: + case SHA1: + case WHIRLPOOL: + case PHPBB: + case PLAINTEXT: + case XENFORO: + case SHA512: + case DOUBLEMD5: + case WORDPRESS: + case CUSTOM: + break; + case SHA256: + salt = createSalt(16); + break; + case MD5VB: + salt = createSalt(16); + break; + case XAUTH: + salt = createSalt(12); + break; + case MYBB: + salt = createSalt(8); + userSalt.put(playerName, salt); + break; + case IPB3: + salt = createSalt(5); + userSalt.put(playerName, salt); + break; + case PHPFUSION: + salt = createSalt(12); + userSalt.put(playerName, salt); + break; + case SALTED2MD5: + salt = createSalt(Settings.saltLength); + userSalt.put(playerName, salt); + break; + case JOOMLA: + salt = createSalt(32); + userSalt.put(playerName, salt); + break; + case BCRYPT: + salt = BCRYPT.gensalt(Settings.bCryptLog2Rounds); + userSalt.put(playerName, salt); + break; + case WBB3: + salt = createSalt(40); + userSalt.put(playerName, salt); + break; + case PBKDF2: + salt = createSalt(12); + userSalt.put(playerName, salt); + break; + case SMF: + return method.getHash(password, playerName.toLowerCase()); + default: + throw new NoSuchAlgorithmException("Unknown hash algorithm"); + } + PasswordEncryptionEvent event = new PasswordEncryptionEvent(method, playerName); + method = event.getMethod(); + if (method == null) + throw new NoSuchAlgorithmException("Unknown hash algorithm"); + return method.getHash(password, salt); + } + + public static boolean comparePasswordWithHash(String password, String hash, String playerName) throws NoSuchAlgorithmException { + HashAlgorithm algo = Settings.getPasswordHash; + EncryptionMethod method; + try { + if (algo != HashAlgorithm.CUSTOM) + method = (EncryptionMethod) algo.getclass().newInstance(); + else method = null; + } catch (InstantiationException e) { + throw new NoSuchAlgorithmException("Problem with this hash algorithm"); + } catch (IllegalAccessException e) { + throw new NoSuchAlgorithmException("Problem with this hash algorithm"); + } + PasswordEncryptionEvent event = new PasswordEncryptionEvent(method, playerName); + method = event.getMethod(); + if (method == null) + throw new NoSuchAlgorithmException("Unknown hash algorithm"); + + if (method.comparePassword(hash, password, playerName)) + return true; + if (Settings.supportOldPassword) { + try { + if (compareWithAllEncryptionMethod(password, hash, playerName)) + return true; + } catch (Exception e) {} + } + return false; + } + + private static boolean compareWithAllEncryptionMethod(String password, String hash, String playerName) throws NoSuchAlgorithmException { + for (HashAlgorithm algo : HashAlgorithm.values()) { + try { + if (algo != HashAlgorithm.CUSTOM) + if (((EncryptionMethod) algo.getclass().newInstance()).comparePassword(hash, password, playerName)) { + PlayerAuth nAuth = AuthMe.getInstance().database.getAuth(playerName); + if (nAuth != null) { + nAuth.setHash(getHash(Settings.getPasswordHash, password, playerName)); + nAuth.setSalt(userSalt.get(playerName)); + AuthMe.getInstance().database.updatePassword(nAuth); + AuthMe.getInstance().database.updateSalt(nAuth); + } + return true; + } + } catch (InstantiationException e) { + } catch (IllegalAccessException e) { + } + } + return false; + } +} diff --git a/src/main/java/uk/org/whoami/authme/security/RandomString.java b/src/main/java/fr/xephi/authme/security/RandomString.java similarity index 94% rename from src/main/java/uk/org/whoami/authme/security/RandomString.java rename to src/main/java/fr/xephi/authme/security/RandomString.java index 744a8cac..7ffb2859 100644 --- a/src/main/java/uk/org/whoami/authme/security/RandomString.java +++ b/src/main/java/fr/xephi/authme/security/RandomString.java @@ -1,4 +1,4 @@ -package uk.org.whoami.authme.security; +package fr.xephi.authme.security; import java.util.Random; diff --git a/src/main/java/uk/org/whoami/authme/security/BCrypt.java b/src/main/java/fr/xephi/authme/security/crypts/BCRYPT.java similarity index 97% rename from src/main/java/uk/org/whoami/authme/security/BCrypt.java rename to src/main/java/fr/xephi/authme/security/crypts/BCRYPT.java index 9f5aeba7..d0077fd0 100644 --- a/src/main/java/uk/org/whoami/authme/security/BCrypt.java +++ b/src/main/java/fr/xephi/authme/security/crypts/BCRYPT.java @@ -11,12 +11,16 @@ // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -package uk.org.whoami.authme.security; +package fr.xephi.authme.security.crypts; import java.io.UnsupportedEncodingException; +import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; +import fr.xephi.authme.AuthMe; + + /** * BCrypt implements OpenBSD-style Blowfish password hashing using * the scheme described in "A Future-Adaptable Password Scheme" by @@ -60,7 +64,7 @@ import java.security.SecureRandom; * @author Damien Miller * @version 0.2 */ -public class BCrypt { +public class BCRYPT implements EncryptionMethod { // BCrypt parameters private static final int GENSALT_DEFAULT_LOG2_ROUNDS = 10; private static final int BCRYPT_SALT_LEN = 16; @@ -645,7 +649,7 @@ public class BCrypt { * @return the hashed password */ public static String hashpw(String password, String salt) { - BCrypt B; + BCRYPT B; String real_salt; byte passwordb[], saltb[], hashed[]; char minor = (char)0; @@ -677,7 +681,7 @@ public class BCrypt { saltb = decode_base64(real_salt, BCRYPT_SALT_LEN); - B = new BCrypt(); + B = new BCRYPT(); hashed = B.crypt_raw(passwordb, saltb, rounds); rs.append("$2"); @@ -748,4 +752,17 @@ public class BCrypt { public static boolean checkpw(String plaintext, String hashed) { return (hashed.compareTo(hashpw(plaintext, hashed)) == 0); } + + @Override + public String getHash(String password, String salt) + throws NoSuchAlgorithmException { + return hashpw(password, salt); + } + + @Override + public boolean comparePassword(String hash, String password, + String playerName) throws NoSuchAlgorithmException { + String salt = AuthMe.getInstance().database.getAuth(playerName).getSalt(); + return hash.equals(hashpw(password, salt)); + } } diff --git a/src/main/java/fr/xephi/authme/security/crypts/CryptPBKDF2.java b/src/main/java/fr/xephi/authme/security/crypts/CryptPBKDF2.java new file mode 100644 index 00000000..78f09c3d --- /dev/null +++ b/src/main/java/fr/xephi/authme/security/crypts/CryptPBKDF2.java @@ -0,0 +1,32 @@ +package fr.xephi.authme.security.crypts; + +import java.security.NoSuchAlgorithmException; + +import fr.xephi.authme.security.pbkdf2.PBKDF2Engine; +import fr.xephi.authme.security.pbkdf2.PBKDF2Parameters; + + +public class CryptPBKDF2 implements EncryptionMethod { + + @Override + public String getHash(String password, String salt) + throws NoSuchAlgorithmException { + String result = "pbkdf2_sha256$10000$"+salt+"$"; + PBKDF2Parameters params = new PBKDF2Parameters("HmacSHA256", "ASCII", salt.getBytes(), 10000); + PBKDF2Engine engine = new PBKDF2Engine(params); + + return result + engine.deriveKey(password,64).toString(); + } + + @Override + public boolean comparePassword(String hash, String password, + String playerName) throws NoSuchAlgorithmException { + String[] line = hash.split("\\$"); + String salt = line[2]; + String derivedKey = line[3]; + PBKDF2Parameters params = new PBKDF2Parameters("HmacSHA256", "ASCII", salt.getBytes(), 10000, derivedKey.getBytes()); + PBKDF2Engine engine = new PBKDF2Engine(params); + return engine.verifyKey(password); + } + +} diff --git a/src/main/java/fr/xephi/authme/security/crypts/DOUBLEMD5.java b/src/main/java/fr/xephi/authme/security/crypts/DOUBLEMD5.java new file mode 100644 index 00000000..f35541c9 --- /dev/null +++ b/src/main/java/fr/xephi/authme/security/crypts/DOUBLEMD5.java @@ -0,0 +1,29 @@ +package fr.xephi.authme.security.crypts; + +import java.math.BigInteger; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +public class DOUBLEMD5 implements EncryptionMethod { + + @Override + public String getHash(String password, String salt) + throws NoSuchAlgorithmException { + return getMD5(getMD5(password)); + } + + @Override + public boolean comparePassword(String hash, String password, + String playerName) throws NoSuchAlgorithmException { + return hash.equals(getHash(password, "")); + } + + private String getMD5(String message) throws NoSuchAlgorithmException { + MessageDigest md5 = MessageDigest.getInstance("MD5"); + md5.reset(); + md5.update(message.getBytes()); + byte[] digest = md5.digest(); + return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1,digest)); + } + +} diff --git a/src/main/java/fr/xephi/authme/security/crypts/EncryptionMethod.java b/src/main/java/fr/xephi/authme/security/crypts/EncryptionMethod.java new file mode 100644 index 00000000..d320eaa8 --- /dev/null +++ b/src/main/java/fr/xephi/authme/security/crypts/EncryptionMethod.java @@ -0,0 +1,30 @@ +package fr.xephi.authme.security.crypts; + +import java.security.NoSuchAlgorithmException; + +/** + *

Public interface for Custom Password encryption method

+ *

The getHash function is called when we need to crypt the password (/register usually)

+ *

The comparePassword is called when we need to match password (/login usually)

+ */ +public interface EncryptionMethod { + + /** + * @param password + * @param salt (can be an other data like playerName;salt , playerName, etc... + * for customs methods) + * @return Hashing password + * @throws NoSuchAlgorithmException + */ + String getHash(String password, String salt) throws NoSuchAlgorithmException; + + /** + * @param hash + * @param password + * @param playerName + * @return true if password match, false else + * @throws NoSuchAlgorithmException + */ + boolean comparePassword(String hash, String password, String playerName) throws NoSuchAlgorithmException; + +} diff --git a/src/main/java/fr/xephi/authme/security/crypts/IPB3.java b/src/main/java/fr/xephi/authme/security/crypts/IPB3.java new file mode 100644 index 00000000..86a6754d --- /dev/null +++ b/src/main/java/fr/xephi/authme/security/crypts/IPB3.java @@ -0,0 +1,32 @@ +package fr.xephi.authme.security.crypts; + +import java.math.BigInteger; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +import fr.xephi.authme.AuthMe; + + +public class IPB3 implements EncryptionMethod { + + @Override + public String getHash(String password, String salt) + throws NoSuchAlgorithmException { + return getMD5(getMD5(salt) + getMD5(password)); + } + + @Override + public boolean comparePassword(String hash, String password, + String playerName) throws NoSuchAlgorithmException { + String salt = AuthMe.getInstance().database.getAuth(playerName).getSalt(); + return hash.equals(getHash(password, salt)); + } + + private String getMD5(String message) throws NoSuchAlgorithmException { + MessageDigest md5 = MessageDigest.getInstance("MD5"); + md5.reset(); + md5.update(message.getBytes()); + byte[] digest = md5.digest(); + return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1,digest)); + } +} diff --git a/src/main/java/fr/xephi/authme/security/crypts/JOOMLA.java b/src/main/java/fr/xephi/authme/security/crypts/JOOMLA.java new file mode 100644 index 00000000..0d40feeb --- /dev/null +++ b/src/main/java/fr/xephi/authme/security/crypts/JOOMLA.java @@ -0,0 +1,29 @@ +package fr.xephi.authme.security.crypts; + +import java.math.BigInteger; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +public class JOOMLA implements EncryptionMethod { + + @Override + public String getHash(String password, String salt) + throws NoSuchAlgorithmException { + return getMD5(password + salt) + ":" + salt; + } + + @Override + public boolean comparePassword(String hash, String password, + String playerName) throws NoSuchAlgorithmException { + String salt = hash.split(":")[1]; + return hash.equals(getMD5(password + salt) + ":" + salt); + } + + private String getMD5(String message) throws NoSuchAlgorithmException { + MessageDigest md5 = MessageDigest.getInstance("MD5"); + md5.reset(); + md5.update(message.getBytes()); + byte[] digest = md5.digest(); + return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1,digest)); + } +} diff --git a/src/main/java/fr/xephi/authme/security/crypts/MD5.java b/src/main/java/fr/xephi/authme/security/crypts/MD5.java new file mode 100644 index 00000000..758eb40e --- /dev/null +++ b/src/main/java/fr/xephi/authme/security/crypts/MD5.java @@ -0,0 +1,23 @@ +package fr.xephi.authme.security.crypts; + +import java.math.BigInteger; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +public class MD5 implements EncryptionMethod { + + @Override + public String getHash(String password, String salt) throws NoSuchAlgorithmException { + MessageDigest md5 = MessageDigest.getInstance("MD5"); + md5.reset(); + md5.update(password.getBytes()); + byte[] digest = md5.digest(); + return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1,digest)); + } + + @Override + public boolean comparePassword(String hash, String password, String playerName) throws NoSuchAlgorithmException { + return hash.equals(getHash(password, "")); + } + +} diff --git a/src/main/java/fr/xephi/authme/security/crypts/MD5VB.java b/src/main/java/fr/xephi/authme/security/crypts/MD5VB.java new file mode 100644 index 00000000..6022c999 --- /dev/null +++ b/src/main/java/fr/xephi/authme/security/crypts/MD5VB.java @@ -0,0 +1,30 @@ +package fr.xephi.authme.security.crypts; + +import java.math.BigInteger; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +public class MD5VB implements EncryptionMethod { + + @Override + public String getHash(String password, String salt) + throws NoSuchAlgorithmException { + return "$MD5vb$" + salt + "$" + getMD5(getMD5(password) + salt); + } + + @Override + public boolean comparePassword(String hash, String password, + String playerName) throws NoSuchAlgorithmException { + String[] line = hash.split("\\$"); + return hash.equals(getHash(password, line[2])); + } + + private String getMD5(String password) throws NoSuchAlgorithmException { + MessageDigest md5 = MessageDigest.getInstance("MD5"); + md5.reset(); + md5.update(password.getBytes()); + byte[] digest = md5.digest(); + return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1,digest)); + } + +} diff --git a/src/main/java/fr/xephi/authme/security/crypts/MYBB.java b/src/main/java/fr/xephi/authme/security/crypts/MYBB.java new file mode 100644 index 00000000..023fa599 --- /dev/null +++ b/src/main/java/fr/xephi/authme/security/crypts/MYBB.java @@ -0,0 +1,32 @@ +package fr.xephi.authme.security.crypts; + +import java.math.BigInteger; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +import fr.xephi.authme.AuthMe; + + +public class MYBB implements EncryptionMethod { + + @Override + public String getHash(String password, String salt) + throws NoSuchAlgorithmException { + return getMD5(getMD5(salt)+ getMD5(password)); + } + + @Override + public boolean comparePassword(String hash, String password, + String playerName) throws NoSuchAlgorithmException { + String salt = AuthMe.getInstance().database.getAuth(playerName).getSalt(); + return hash.equals(getHash(password, salt)); + } + + private String getMD5(String message) throws NoSuchAlgorithmException { + MessageDigest md5 = MessageDigest.getInstance("MD5"); + md5.reset(); + md5.update(message.getBytes()); + byte[] digest = md5.digest(); + return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1,digest)); + } +} diff --git a/src/main/java/uk/org/whoami/authme/security/PhpBB.java b/src/main/java/fr/xephi/authme/security/crypts/PHPBB.java similarity index 91% rename from src/main/java/uk/org/whoami/authme/security/PhpBB.java rename to src/main/java/fr/xephi/authme/security/crypts/PHPBB.java index e9af72c6..207b2140 100644 --- a/src/main/java/uk/org/whoami/authme/security/PhpBB.java +++ b/src/main/java/fr/xephi/authme/security/crypts/PHPBB.java @@ -2,17 +2,18 @@ * To change this template, choose Tools | Templates * and open the template in the editor. */ -package uk.org.whoami.authme.security; +package fr.xephi.authme.security.crypts; import java.io.UnsupportedEncodingException; import java.security.GeneralSecurityException; import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; /** * * @author stefano */ -public class PhpBB { +public class PHPBB implements EncryptionMethod { private static final int PHP_VERSION = 4; private String itoa64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; @@ -157,4 +158,16 @@ private String _hash_gensalt_private( } return buf.toString(); } + +@Override +public String getHash(String password, String salt) + throws NoSuchAlgorithmException { + return phpbb_hash(password); +} + +@Override +public boolean comparePassword(String hash, String password, String playerName) + throws NoSuchAlgorithmException { + return phpbb_check_hash(password, hash); +} } diff --git a/src/main/java/fr/xephi/authme/security/crypts/PHPFUSION.java b/src/main/java/fr/xephi/authme/security/crypts/PHPFUSION.java new file mode 100644 index 00000000..ccca57c5 --- /dev/null +++ b/src/main/java/fr/xephi/authme/security/crypts/PHPFUSION.java @@ -0,0 +1,59 @@ +package fr.xephi.authme.security.crypts; + +import java.io.UnsupportedEncodingException; +import java.math.BigInteger; +import java.security.InvalidKeyException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +import javax.crypto.Mac; +import javax.crypto.spec.SecretKeySpec; + +import fr.xephi.authme.AuthMe; + + +public class PHPFUSION implements EncryptionMethod { + + @Override + public String getHash(String password, String salt) + throws NoSuchAlgorithmException { + String digest = null; + String algo = "HmacSHA256"; + String keyString = getSHA1(salt); + try { + SecretKeySpec key = new SecretKeySpec((keyString).getBytes("UTF-8"), algo); + Mac mac = Mac.getInstance(algo); + mac.init(key); + byte[] bytes = mac.doFinal(password.getBytes("ASCII")); + StringBuffer hash = new StringBuffer(); + for (int i = 0; i < bytes.length; i++) { + String hex = Integer.toHexString(0xFF & bytes[i]); + if (hex.length() == 1) { + hash.append('0'); + } + hash.append(hex); + } + digest = hash.toString(); + } catch (UnsupportedEncodingException e) { + } catch (InvalidKeyException e) { + } catch (NoSuchAlgorithmException e) { + } + return digest; + } + + @Override + public boolean comparePassword(String hash, String password, + String playerName) throws NoSuchAlgorithmException { + String salt = AuthMe.getInstance().database.getAuth(playerName).getSalt(); + return hash.equals(getHash(password, salt)); + } + + private String getSHA1(String message) throws NoSuchAlgorithmException { + MessageDigest sha1 = MessageDigest.getInstance("SHA1"); + sha1.reset(); + sha1.update(message.getBytes()); + byte[] digest = sha1.digest(); + return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1,digest)); + } + +} diff --git a/src/main/java/fr/xephi/authme/security/crypts/PLAINTEXT.java b/src/main/java/fr/xephi/authme/security/crypts/PLAINTEXT.java new file mode 100644 index 00000000..c69cada4 --- /dev/null +++ b/src/main/java/fr/xephi/authme/security/crypts/PLAINTEXT.java @@ -0,0 +1,19 @@ +package fr.xephi.authme.security.crypts; + +import java.security.NoSuchAlgorithmException; + +public class PLAINTEXT implements EncryptionMethod { + + @Override + public String getHash(String password, String salt) + throws NoSuchAlgorithmException { + return password; + } + + @Override + public boolean comparePassword(String hash, String password, + String playerName) throws NoSuchAlgorithmException { + return hash.equals(password); + } + +} diff --git a/src/main/java/fr/xephi/authme/security/crypts/SALTED2MD5.java b/src/main/java/fr/xephi/authme/security/crypts/SALTED2MD5.java new file mode 100644 index 00000000..00bb81aa --- /dev/null +++ b/src/main/java/fr/xephi/authme/security/crypts/SALTED2MD5.java @@ -0,0 +1,32 @@ +package fr.xephi.authme.security.crypts; + +import java.math.BigInteger; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +import fr.xephi.authme.AuthMe; + + +public class SALTED2MD5 implements EncryptionMethod { + + @Override + public String getHash(String password, String salt) + throws NoSuchAlgorithmException { + return getMD5(getMD5(password) + salt); + } + + @Override + public boolean comparePassword(String hash, String password, + String playerName) throws NoSuchAlgorithmException { + String salt = AuthMe.getInstance().database.getAuth(playerName).getSalt(); + return hash.equals(getMD5(getMD5(password) + salt)); + } + + private String getMD5(String message) throws NoSuchAlgorithmException { + MessageDigest md5 = MessageDigest.getInstance("MD5"); + md5.reset(); + md5.update(message.getBytes()); + byte[] digest = md5.digest(); + return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1,digest)); + } +} diff --git a/src/main/java/fr/xephi/authme/security/crypts/SHA1.java b/src/main/java/fr/xephi/authme/security/crypts/SHA1.java new file mode 100644 index 00000000..2705c3bb --- /dev/null +++ b/src/main/java/fr/xephi/authme/security/crypts/SHA1.java @@ -0,0 +1,24 @@ +package fr.xephi.authme.security.crypts; + +import java.math.BigInteger; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +public class SHA1 implements EncryptionMethod { + + @Override + public String getHash(String password, String salt) throws NoSuchAlgorithmException { + MessageDigest sha1 = MessageDigest.getInstance("SHA1"); + sha1.reset(); + sha1.update(password.getBytes()); + byte[] digest = sha1.digest(); + return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1,digest)); + } + + @Override + public boolean comparePassword(String hash, String password, String playerName) + throws NoSuchAlgorithmException { + return hash.equals(getHash(password, "")); + } + +} diff --git a/src/main/java/fr/xephi/authme/security/crypts/SHA256.java b/src/main/java/fr/xephi/authme/security/crypts/SHA256.java new file mode 100644 index 00000000..1aea0ee0 --- /dev/null +++ b/src/main/java/fr/xephi/authme/security/crypts/SHA256.java @@ -0,0 +1,29 @@ +package fr.xephi.authme.security.crypts; + +import java.math.BigInteger; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +public class SHA256 implements EncryptionMethod { + + @Override + public String getHash(String password, String salt) throws NoSuchAlgorithmException { + return "$SHA$" + salt + "$" + getSha256(getSha256(password) + salt); + } + + @Override + public boolean comparePassword(String hash, String password, String playerName) + throws NoSuchAlgorithmException { + String[] line = hash.split("\\$"); + return hash.equals(getHash(password, line[2])); + } + + private String getSha256(String password) throws NoSuchAlgorithmException { + MessageDigest sha256 = MessageDigest.getInstance("SHA-256"); + sha256.reset(); + sha256.update(password.getBytes()); + byte[] digest = sha256.digest(); + return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1,digest)); + } + +} diff --git a/src/main/java/fr/xephi/authme/security/crypts/SHA512.java b/src/main/java/fr/xephi/authme/security/crypts/SHA512.java new file mode 100644 index 00000000..87fdd841 --- /dev/null +++ b/src/main/java/fr/xephi/authme/security/crypts/SHA512.java @@ -0,0 +1,25 @@ +package fr.xephi.authme.security.crypts; + +import java.math.BigInteger; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +public class SHA512 implements EncryptionMethod { + + @Override + public String getHash(String password, String salt) + throws NoSuchAlgorithmException { + MessageDigest sha512 = MessageDigest.getInstance("SHA-512"); + sha512.reset(); + sha512.update(password.getBytes()); + byte[] digest = sha512.digest(); + return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1,digest)); + } + + @Override + public boolean comparePassword(String hash, String password, + String playerName) throws NoSuchAlgorithmException { + return hash.equals(getHash(password, "")); + } + +} diff --git a/src/main/java/fr/xephi/authme/security/crypts/SMF.java b/src/main/java/fr/xephi/authme/security/crypts/SMF.java new file mode 100644 index 00000000..3ef93b9b --- /dev/null +++ b/src/main/java/fr/xephi/authme/security/crypts/SMF.java @@ -0,0 +1,28 @@ +package fr.xephi.authme.security.crypts; + +import java.math.BigInteger; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +public class SMF implements EncryptionMethod { + + @Override + public String getHash(String password, String salt) + throws NoSuchAlgorithmException { + return getSHA1(salt.toLowerCase() + password); + } + + @Override + public boolean comparePassword(String hash, String password, + String playerName) throws NoSuchAlgorithmException { + return hash.equals(getHash(password, playerName.toLowerCase())); + } + + private String getSHA1(String message) throws NoSuchAlgorithmException { + MessageDigest sha1 = MessageDigest.getInstance("SHA1"); + sha1.reset(); + sha1.update(message.getBytes()); + byte[] digest = sha1.digest(); + return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1,digest)); + } +} diff --git a/src/main/java/fr/xephi/authme/security/crypts/WBB3.java b/src/main/java/fr/xephi/authme/security/crypts/WBB3.java new file mode 100644 index 00000000..95267fd8 --- /dev/null +++ b/src/main/java/fr/xephi/authme/security/crypts/WBB3.java @@ -0,0 +1,32 @@ +package fr.xephi.authme.security.crypts; + +import java.math.BigInteger; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +import fr.xephi.authme.AuthMe; + + +public class WBB3 implements EncryptionMethod { + + @Override + public String getHash(String password, String salt) + throws NoSuchAlgorithmException { + return getSHA1(salt.concat(getSHA1(salt.concat(getSHA1(password))))); + } + + @Override + public boolean comparePassword(String hash, String password, + String playerName) throws NoSuchAlgorithmException { + String salt = AuthMe.getInstance().database.getAuth(playerName).getSalt(); + return hash.equals(getHash(password, salt)); + } + + private String getSHA1(String message) throws NoSuchAlgorithmException { + MessageDigest sha1 = MessageDigest.getInstance("SHA1"); + sha1.reset(); + sha1.update(message.getBytes()); + byte[] digest = sha1.digest(); + return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1,digest)); + } +} diff --git a/src/main/java/uk/org/whoami/authme/security/Whirlpool.java b/src/main/java/fr/xephi/authme/security/crypts/WHIRLPOOL.java similarity index 95% rename from src/main/java/uk/org/whoami/authme/security/Whirlpool.java rename to src/main/java/fr/xephi/authme/security/crypts/WHIRLPOOL.java index 0066bfa3..54934a58 100644 --- a/src/main/java/uk/org/whoami/authme/security/Whirlpool.java +++ b/src/main/java/fr/xephi/authme/security/crypts/WHIRLPOOL.java @@ -1,4 +1,4 @@ -package uk.org.whoami.authme.security; +package fr.xephi.authme.security.crypts; /** * The Whirlpool hashing function. @@ -57,9 +57,12 @@ package uk.org.whoami.authme.security; * */ +import java.security.NoSuchAlgorithmException; import java.util.Arrays; -class Whirlpool { +public class WHIRLPOOL implements EncryptionMethod { + + public WHIRLPOOL() {} /** * The message digest size (in bits) @@ -178,9 +181,6 @@ class Whirlpool { protected long[] block = new long[8]; protected long[] state = new long[8]; - public Whirlpool() { - } - /** * The core Whirlpool transform. */ @@ -405,4 +405,20 @@ class Whirlpool { } return String.valueOf(val); } + + @Override + public String getHash(String password, String salt) + throws NoSuchAlgorithmException { + byte[] digest = new byte[DIGESTBYTES]; + NESSIEinit(); + NESSIEadd(password); + NESSIEfinalize(digest); + return display(digest); + } + + @Override + public boolean comparePassword(String hash, String password, + String playerName) throws NoSuchAlgorithmException { + return hash.equals(getHash(password, "")); + } } diff --git a/src/main/java/fr/xephi/authme/security/crypts/WORDPRESS.java b/src/main/java/fr/xephi/authme/security/crypts/WORDPRESS.java new file mode 100644 index 00000000..ebd9772a --- /dev/null +++ b/src/main/java/fr/xephi/authme/security/crypts/WORDPRESS.java @@ -0,0 +1,115 @@ +package fr.xephi.authme.security.crypts; + +import java.io.UnsupportedEncodingException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.util.Arrays; + +public class WORDPRESS implements EncryptionMethod { + private static String itoa64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; + private int iterationCountLog2 = 8; + private SecureRandom randomGen = new SecureRandom(); + + private String encode64(byte[] src, int count) { + int i, value; + String output = ""; + i = 0; + + if (src.length < count) { + byte[] t = new byte[count]; + System.arraycopy(src, 0, t, 0, src.length); + Arrays.fill(t, src.length, count - 1, (byte) 0); + } + + do { + value = src[i] + (src[i] < 0 ? 256 : 0); + ++i; + output += itoa64.charAt(value & 63); + if (i < count) { + value |= (src[i] + (src[i] < 0 ? 256 : 0)) << 8; + } + output += itoa64.charAt((value >> 6) & 63); + if (i++ >= count) { + break; + } + if (i < count) { + value |= (src[i] + (src[i] < 0 ? 256 : 0)) << 16; + } + output += itoa64.charAt((value >> 12) & 63); + if (i++ >= count) { + break; + } + output += itoa64.charAt((value >> 18) & 63); + } while (i < count); + return output; + } + + private String crypt(String password, String setting) { + String output = "*0"; + if (((setting.length() < 2) ? setting : setting.substring(0, 2)).equalsIgnoreCase(output)) { + output = "*1"; + } + String id = (setting.length() < 3) ? setting : setting.substring(0, 3); + if (!(id.equals("$P$") || id.equals("$H$"))) { + return output; + } + int countLog2 = itoa64.indexOf(setting.charAt(3)); + if (countLog2 < 7 || countLog2 > 30) { + return output; + } + int count = 1 << countLog2; + String salt = setting.substring(4, 4 + 8); + if (salt.length() != 8) { + return output; + } + MessageDigest md; + try { + md = MessageDigest.getInstance("MD5"); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + return output; + } + byte[] pass = stringToUtf8(password); + byte[] hash = md.digest(stringToUtf8(salt + password)); + do { + byte[] t = new byte[hash.length + pass.length]; + System.arraycopy(hash, 0, t, 0, hash.length); + System.arraycopy(pass, 0, t, hash.length, pass.length); + hash = md.digest(t); + } while (--count > 0); + output = setting.substring(0, 12); + output += encode64(hash, 16); + return output; + } + + private String gensaltPrivate(byte[] input) { + String output = "$P$"; + output += itoa64.charAt(Math.min(this.iterationCountLog2 + 5, 30)); + output += encode64(input, 6); + return output; + } + + private byte[] stringToUtf8(String string) { + try { + return string.getBytes("UTF-8"); + } catch (UnsupportedEncodingException e) { + throw new UnsupportedOperationException("This system doesn't support UTF-8!", e); + } + } + + @Override + public String getHash(String password, String salt) throws NoSuchAlgorithmException { + byte random[] = new byte[6]; + this.randomGen.nextBytes(random); + return crypt(password, gensaltPrivate(stringToUtf8(new String(random)))); + } + + @Override + public boolean comparePassword(String hash, String password, + String playerName) throws NoSuchAlgorithmException { + String comparedHash = crypt(password, hash); + return comparedHash.equals(hash); + } + +} diff --git a/src/main/java/fr/xephi/authme/security/crypts/XAUTH.java b/src/main/java/fr/xephi/authme/security/crypts/XAUTH.java new file mode 100644 index 00000000..47d7377d --- /dev/null +++ b/src/main/java/fr/xephi/authme/security/crypts/XAUTH.java @@ -0,0 +1,24 @@ +package fr.xephi.authme.security.crypts; + +import java.security.NoSuchAlgorithmException; + +public class XAUTH implements EncryptionMethod { + + @Override + public String getHash(String password, String salt) + throws NoSuchAlgorithmException { + WHIRLPOOL w = new WHIRLPOOL(); + String hash = w.getHash((salt + password).toLowerCase(), ""); + int saltPos = (password.length() >= hash.length() ? hash.length() - 1 : password.length()); + return hash.substring(0, saltPos) + salt + hash.substring(saltPos); + } + + @Override + public boolean comparePassword(String hash, String password, + String playerName) throws NoSuchAlgorithmException { + int saltPos = (password.length() >= hash.length() ? hash.length() - 1 : password.length()); + String salt = hash.substring(saltPos, saltPos + 12); + return hash.equals(getHash(password, salt)); + } + +} diff --git a/src/main/java/fr/xephi/authme/security/crypts/XF.java b/src/main/java/fr/xephi/authme/security/crypts/XF.java new file mode 100644 index 00000000..d522a413 --- /dev/null +++ b/src/main/java/fr/xephi/authme/security/crypts/XF.java @@ -0,0 +1,61 @@ +package fr.xephi.authme.security.crypts; + +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import fr.xephi.authme.AuthMe; + + +public class XF implements EncryptionMethod { + + @Override + public String getHash(String password, String salt) + throws NoSuchAlgorithmException { + return getSHA256(getSHA256(password) + regmatch("\"salt\";.:..:\"(.*)\";.:.:\"hashFunc\"", salt)); + } + + @Override + public boolean comparePassword(String hash, String password, + String playerName) throws NoSuchAlgorithmException { + String salt = AuthMe.getInstance().database.getAuth(playerName).getSalt(); + return hash.equals(regmatch("\"hash\";.:..:\"(.*)\";.:.:\"salt\"", salt)); + } + + public String getSHA256(String password) throws NoSuchAlgorithmException + { + MessageDigest md = MessageDigest.getInstance("SHA-256"); + md.update(password.getBytes()); + byte byteData[] = md.digest(); + StringBuffer sb = new StringBuffer(); + for (byte element : byteData) + { + sb.append(Integer.toString((element & 0xff) + 0x100, 16).substring(1)); + } + StringBuffer hexString = new StringBuffer(); + for (byte element : byteData) + { + String hex = Integer.toHexString(0xff & element); + if (hex.length() == 1) + { + hexString.append('0'); + } + hexString.append(hex); + } + return hexString.toString(); + } + + public String regmatch(String pattern, String line) + { + List allMatches = new ArrayList(); + Matcher m = Pattern.compile(pattern).matcher(line); + while (m.find()) + { + allMatches.add(m.group(1)); + } + return allMatches.get(0); + } +} diff --git a/src/main/java/uk/org/whoami/authme/security/pbkdf2/BinTools.java b/src/main/java/fr/xephi/authme/security/pbkdf2/BinTools.java similarity index 98% rename from src/main/java/uk/org/whoami/authme/security/pbkdf2/BinTools.java rename to src/main/java/fr/xephi/authme/security/pbkdf2/BinTools.java index b3da28f6..43eed16c 100644 --- a/src/main/java/uk/org/whoami/authme/security/pbkdf2/BinTools.java +++ b/src/main/java/fr/xephi/authme/security/pbkdf2/BinTools.java @@ -1,4 +1,4 @@ -package uk.org.whoami.authme.security.pbkdf2; +package fr.xephi.authme.security.pbkdf2; /** *

diff --git a/src/main/java/uk/org/whoami/authme/security/pbkdf2/MacBasedPRF.java b/src/main/java/fr/xephi/authme/security/pbkdf2/MacBasedPRF.java similarity index 98% rename from src/main/java/uk/org/whoami/authme/security/pbkdf2/MacBasedPRF.java rename to src/main/java/fr/xephi/authme/security/pbkdf2/MacBasedPRF.java index a2cee838..7a7f9b7a 100644 --- a/src/main/java/uk/org/whoami/authme/security/pbkdf2/MacBasedPRF.java +++ b/src/main/java/fr/xephi/authme/security/pbkdf2/MacBasedPRF.java @@ -1,4 +1,4 @@ -package uk.org.whoami.authme.security.pbkdf2; +package fr.xephi.authme.security.pbkdf2; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; diff --git a/src/main/java/uk/org/whoami/authme/security/pbkdf2/PBKDF2.java b/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2.java similarity index 98% rename from src/main/java/uk/org/whoami/authme/security/pbkdf2/PBKDF2.java rename to src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2.java index 6ac40380..5feadd13 100644 --- a/src/main/java/uk/org/whoami/authme/security/pbkdf2/PBKDF2.java +++ b/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2.java @@ -1,4 +1,4 @@ -package uk.org.whoami.authme.security.pbkdf2; +package fr.xephi.authme.security.pbkdf2; /** *

diff --git a/src/main/java/uk/org/whoami/authme/security/pbkdf2/PBKDF2Engine.java b/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2Engine.java similarity index 99% rename from src/main/java/uk/org/whoami/authme/security/pbkdf2/PBKDF2Engine.java rename to src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2Engine.java index b2bc80ae..07da6d18 100644 --- a/src/main/java/uk/org/whoami/authme/security/pbkdf2/PBKDF2Engine.java +++ b/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2Engine.java @@ -1,4 +1,4 @@ -package uk.org.whoami.authme.security.pbkdf2; +package fr.xephi.authme.security.pbkdf2; import java.io.IOException; import java.io.UnsupportedEncodingException; diff --git a/src/main/java/uk/org/whoami/authme/security/pbkdf2/PBKDF2Formatter.java b/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2Formatter.java similarity index 97% rename from src/main/java/uk/org/whoami/authme/security/pbkdf2/PBKDF2Formatter.java rename to src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2Formatter.java index 678bb6b9..bf0ff49a 100644 --- a/src/main/java/uk/org/whoami/authme/security/pbkdf2/PBKDF2Formatter.java +++ b/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2Formatter.java @@ -1,4 +1,4 @@ -package uk.org.whoami.authme.security.pbkdf2; +package fr.xephi.authme.security.pbkdf2; /** *

diff --git a/src/main/java/uk/org/whoami/authme/security/pbkdf2/PBKDF2HexFormatter.java b/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2HexFormatter.java similarity index 97% rename from src/main/java/uk/org/whoami/authme/security/pbkdf2/PBKDF2HexFormatter.java rename to src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2HexFormatter.java index b4b2f46d..1e12b5f9 100644 --- a/src/main/java/uk/org/whoami/authme/security/pbkdf2/PBKDF2HexFormatter.java +++ b/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2HexFormatter.java @@ -1,4 +1,4 @@ -package uk.org.whoami.authme.security.pbkdf2; +package fr.xephi.authme.security.pbkdf2; /** *

diff --git a/src/main/java/uk/org/whoami/authme/security/pbkdf2/PBKDF2Parameters.java b/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2Parameters.java similarity index 98% rename from src/main/java/uk/org/whoami/authme/security/pbkdf2/PBKDF2Parameters.java rename to src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2Parameters.java index 6732b1dd..6eb41b0a 100644 --- a/src/main/java/uk/org/whoami/authme/security/pbkdf2/PBKDF2Parameters.java +++ b/src/main/java/fr/xephi/authme/security/pbkdf2/PBKDF2Parameters.java @@ -1,4 +1,4 @@ -package uk.org.whoami.authme.security.pbkdf2; +package fr.xephi.authme.security.pbkdf2; /** *

diff --git a/src/main/java/uk/org/whoami/authme/security/pbkdf2/PRF.java b/src/main/java/fr/xephi/authme/security/pbkdf2/PRF.java similarity index 97% rename from src/main/java/uk/org/whoami/authme/security/pbkdf2/PRF.java rename to src/main/java/fr/xephi/authme/security/pbkdf2/PRF.java index a7ab142b..00e1e39c 100644 --- a/src/main/java/uk/org/whoami/authme/security/pbkdf2/PRF.java +++ b/src/main/java/fr/xephi/authme/security/pbkdf2/PRF.java @@ -1,4 +1,4 @@ -package uk.org.whoami.authme.security.pbkdf2; +package fr.xephi.authme.security.pbkdf2; /** *

diff --git a/src/main/java/uk/org/whoami/authme/settings/CustomConfiguration.java b/src/main/java/fr/xephi/authme/settings/CustomConfiguration.java similarity index 96% rename from src/main/java/uk/org/whoami/authme/settings/CustomConfiguration.java rename to src/main/java/fr/xephi/authme/settings/CustomConfiguration.java index c98e5895..1709e2c6 100644 --- a/src/main/java/uk/org/whoami/authme/settings/CustomConfiguration.java +++ b/src/main/java/fr/xephi/authme/settings/CustomConfiguration.java @@ -1,4 +1,4 @@ -package uk.org.whoami.authme.settings; +package fr.xephi.authme.settings; import java.io.File; import java.io.FileNotFoundException; @@ -29,7 +29,7 @@ public class CustomConfiguration extends YamlConfiguration{ super.load(configFile); } catch (FileNotFoundException e) { Logger.getLogger(JavaPlugin.class.getName()).log(Level.SEVERE, "Could not find " + configFile.getName() + ", creating new one..."); - reload(); + reLoad(); } catch (IOException e) { Logger.getLogger(JavaPlugin.class.getName()).log(Level.SEVERE, "Could not load " + configFile.getName(), e); } catch (InvalidConfigurationException e) { @@ -37,7 +37,7 @@ public class CustomConfiguration extends YamlConfiguration{ } } - public boolean reload() { + public boolean reLoad() { boolean out = true; if (!configFile.exists()) { diff --git a/src/main/java/uk/org/whoami/authme/settings/Messages.java b/src/main/java/fr/xephi/authme/settings/Messages.java similarity index 86% rename from src/main/java/uk/org/whoami/authme/settings/Messages.java rename to src/main/java/fr/xephi/authme/settings/Messages.java index 21437786..5d9a1b76 100644 --- a/src/main/java/uk/org/whoami/authme/settings/Messages.java +++ b/src/main/java/fr/xephi/authme/settings/Messages.java @@ -1,20 +1,4 @@ -/* - * Copyright 2011 Sebastian Köhler . - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.org.whoami.authme.settings; +package fr.xephi.authme.settings; import java.io.File; @@ -96,10 +80,17 @@ public class Messages extends CustomConfiguration { if (loc != null) { return loc.replace("&", "\u00a7"); } - return msg; + if (loc == null && !contains(msg)) { + set(msg, this.getDefault(msg)); + save(); + loc = (String) this.get(msg); + } + if (loc == null) + return "Error with Translation files; Please contact the admin"; + return loc.replace("&", "\u00a7"); } - public static Messages getInstance() { + public static Messages getInstance() { if (singleton == null) { singleton = new Messages(); } diff --git a/src/main/java/uk/org/whoami/authme/settings/PlayersLogs.java b/src/main/java/fr/xephi/authme/settings/PlayersLogs.java similarity index 60% rename from src/main/java/uk/org/whoami/authme/settings/PlayersLogs.java rename to src/main/java/fr/xephi/authme/settings/PlayersLogs.java index d439d012..73bb9780 100644 --- a/src/main/java/uk/org/whoami/authme/settings/PlayersLogs.java +++ b/src/main/java/fr/xephi/authme/settings/PlayersLogs.java @@ -1,14 +1,15 @@ -package uk.org.whoami.authme.settings; +package fr.xephi.authme.settings; import java.io.File; import java.util.List; +import org.bukkit.entity.Player; + /** * * @author Xephi59 */ public class PlayersLogs extends CustomConfiguration { - private static PlayersLogs pllog = null; public static List players; @@ -24,8 +25,16 @@ public class PlayersLogs extends CustomConfiguration { public static PlayersLogs getInstance() { if (pllog == null) { pllog = new PlayersLogs(); - } + } return pllog; } - + + public void addPlayer(Player player) { + List players = this.getStringList("players"); + if (!players.contains(player.getName())) { + players.add(player.getName()); + this.set("players", players); + save(); + } + } } diff --git a/src/main/java/uk/org/whoami/authme/settings/Settings.java b/src/main/java/fr/xephi/authme/settings/Settings.java similarity index 90% rename from src/main/java/uk/org/whoami/authme/settings/Settings.java rename to src/main/java/fr/xephi/authme/settings/Settings.java index 7e19748e..5a2be839 100644 --- a/src/main/java/uk/org/whoami/authme/settings/Settings.java +++ b/src/main/java/fr/xephi/authme/settings/Settings.java @@ -1,20 +1,4 @@ -/* - * Copyright 2011 Sebastian Köhler . - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.org.whoami.authme.settings; +package fr.xephi.authme.settings; import java.io.File; import java.io.InputStream; @@ -26,11 +10,11 @@ import org.bukkit.configuration.MemoryConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.plugin.Plugin; -import uk.org.whoami.authme.ConsoleLogger; -import uk.org.whoami.authme.datasource.DataSource; -import uk.org.whoami.authme.datasource.DataSource.DataSourceType; -import uk.org.whoami.authme.security.PasswordSecurity; -import uk.org.whoami.authme.security.PasswordSecurity.HashAlgorithm; +import fr.xephi.authme.ConsoleLogger; +import fr.xephi.authme.datasource.DataSource; +import fr.xephi.authme.datasource.DataSource.DataSourceType; +import fr.xephi.authme.security.HashAlgorithm; + public final class Settings extends YamlConfiguration { @@ -60,7 +44,8 @@ public final class Settings extends YamlConfiguration { getEnablePasswordVerifier, protectInventoryBeforeLogInEnabled, isBackupActivated, isBackupOnStart, isBackupOnStop, enablePasspartu, isStopEnabled, reloadSupport, rakamakUseIp, noConsoleSpam, removePassword, displayOtherAccounts, useCaptcha, emailRegistration, multiverse, notifications, chestshop, bungee, banUnsafeIp, doubleEmailCheck, sessionExpireOnIpChange, - disableSocialSpy, useMultiThreading, forceOnlyAfterLogin, useEssentialsMotd; + disableSocialSpy, useMultiThreading, forceOnlyAfterLogin, useEssentialsMotd, + usePurge, purgePlayerDat, purgeEssentialsFile, supportOldPassword; public static String getNickRegex, getUnloggedinGroup, getMySQLHost, getMySQLPort, getMySQLUsername, getMySQLPassword, getMySQLDatabase, getMySQLTablename, @@ -68,12 +53,13 @@ public final class Settings extends YamlConfiguration { getMySQLColumnSalt, getMySQLColumnGroup, getMySQLColumnEmail, unRegisteredGroup, backupWindowsPath, getcUnrestrictedName, getRegisteredGroup, messagesLanguage, getMySQLlastlocX, getMySQLlastlocY, getMySQLlastlocZ, rakamakUsers, rakamakUsersIp, getmailAccount, getmailPassword, getmailSMTP, getMySQLColumnId, getmailSenderName, - getPredefinedSalt, getMailSubject, getMailText, getMySQLlastlocWorld; + getMailSubject, getMailText, getMySQLlastlocWorld, defaultWorld, + getPhpbbPrefix, getWordPressPrefix; public static int getWarnMessageInterval, getSessionTimeout, getRegistrationTimeout, getMaxNickLength, getMinNickLength, getPasswordMinLen, getMovementRadius, getmaxRegPerIp, getNonActivatedGroup, passwordMaxLength, getRecoveryPassLength, getMailPort, maxLoginTry, captchaLength, saltLength, getmaxRegPerEmail, - bCryptLog2Rounds; + bCryptLog2Rounds, purgeDelay, getPhpbbGroup; protected static YamlConfiguration configFile; @@ -81,7 +67,7 @@ public final class Settings extends YamlConfiguration { this.file = new File(plugin.getDataFolder(),"config.yml"); this.plugin = plugin; if(exists()) { - load(); + load(); } else { loadDefaults(file.getName()); @@ -189,7 +175,6 @@ public void loadConfigOptions() { displayOtherAccounts = configFile.getBoolean("settings.restrictions.displayOtherAccounts", true); getMySQLColumnId = configFile.getString("DataSource.mySQLColumnId", "id"); getmailSenderName = configFile.getString("Email.mailSenderName", ""); - getPredefinedSalt = configFile.getString("Xenoforo.predefinedSalt", ""); useCaptcha = configFile.getBoolean("Security.captcha.useCaptcha", false); maxLoginTry = configFile.getInt("Security.captcha.maxLoginTry", 5); captchaLength = configFile.getInt("Security.captcha.captchaLength", 5); @@ -208,10 +193,19 @@ public void loadConfigOptions() { sessionExpireOnIpChange = configFile.getBoolean("settings.sessions.sessionExpireOnIpChange", false); useLogging = configFile.getBoolean("Security.console.logConsole", false); disableSocialSpy = configFile.getBoolean("Hooks.disableSocialSpy", true); - useMultiThreading = configFile.getBoolean("Performances.useMultiThreading", false); + useMultiThreading = configFile.getBoolean("Performances.useMultiThreading", true); bCryptLog2Rounds = configFile.getInt("ExternalBoardOptions.bCryptLog2Round", 10); forceOnlyAfterLogin = configFile.getBoolean("settings.GameMode.ForceOnlyAfterLogin", false); useEssentialsMotd = configFile.getBoolean("Hooks.useEssentialsMotd", false); + usePurge = configFile.getBoolean("Purge.useAutoPurge", false); + purgeDelay = configFile.getInt("Purge.daysBeforeRemovePlayer", 60); + purgePlayerDat = configFile.getBoolean("Purge.removePlayerDat", false); + purgeEssentialsFile = configFile.getBoolean("Purge.removeEssentialsFile", false); + defaultWorld = configFile.getString("Purge.defaultWorld", "world"); + getPhpbbPrefix = configFile.getString("ExternalBoardOptions.phpbbTablePrefix", "phpbb_"); + getPhpbbGroup = configFile.getInt("ExternalBoardOptions.phpbbActivatedGroupId", 2); + supportOldPassword = configFile.getBoolean("settings.security.supportOldPasswordHash", false); + getWordPressPrefix = configFile.getString("ExternalBoardOptions.wordpressTablePrefix", "wp_"); saveDefaults(); } @@ -314,7 +308,6 @@ public static void reloadConfigOptions(YamlConfiguration newConfig) { displayOtherAccounts = configFile.getBoolean("settings.restrictions.displayOtherAccounts", true); getMySQLColumnId = configFile.getString("DataSource.mySQLColumnId", "id"); getmailSenderName = configFile.getString("Email.mailSenderName", ""); - getPredefinedSalt = configFile.getString("Xenoforo.predefinedSalt", ""); useCaptcha = configFile.getBoolean("Security.captcha.useCaptcha", false); maxLoginTry = configFile.getInt("Security.captcha.maxLoginTry", 5); captchaLength = configFile.getInt("Security.captcha.captchaLength", 5); @@ -333,25 +326,24 @@ public static void reloadConfigOptions(YamlConfiguration newConfig) { sessionExpireOnIpChange = configFile.getBoolean("settings.sessions.sessionExpireOnIpChange", false); useLogging = configFile.getBoolean("Security.console.logConsole", false); disableSocialSpy = configFile.getBoolean("Hooks.disableSocialSpy", true); - useMultiThreading = configFile.getBoolean("Performances.useMultiThreading", false); + useMultiThreading = configFile.getBoolean("Performances.useMultiThreading", true); bCryptLog2Rounds = configFile.getInt("ExternalBoardOptions.bCryptLog2Round", 10); forceOnlyAfterLogin = configFile.getBoolean("settings.GameMode.ForceOnlyAfterLogin", false); useEssentialsMotd = configFile.getBoolean("Hooks.useEssentialsMotd", false); + usePurge = configFile.getBoolean("Purge.useAutoPurge", false); + purgeDelay = configFile.getInt("Purge.daysBeforeRemovePlayer", 60); + purgePlayerDat = configFile.getBoolean("Purge.removePlayerDat", false); + purgeEssentialsFile = configFile.getBoolean("Purge.removeEssentialsFile", false); + defaultWorld = configFile.getString("Purge.defaultWorld", "world"); + getPhpbbPrefix = configFile.getString("ExternalBoardOptions.phpbbTablePrefix", "phpbb_"); + getPhpbbGroup = configFile.getInt("ExternalBoardOptions.phpbbActivatedGroupId", 2); + supportOldPassword = configFile.getBoolean("settings.security.supportOldPasswordHash", false); + getWordPressPrefix = configFile.getString("ExternalBoardOptions.wordpressTablePrefix", "wp_"); } public void mergeConfig() { - if (contains("settings.restrictions.allowedPluginTeleportHandler")) - set("settings.restrictions.allowedPluginTeleportHandler", null); if(!contains("DataSource.mySQLColumnEmail")) set("DataSource.mySQLColumnEmail","email"); - if(contains("Email.GmailAccount")) { - set("Email.mailAccount", getString("Email.GmailAccount")); - set("Email.GmailAccount", null); - } - if(contains("Email.GmailPassword")) { - set("Email.mailPassword", getString("Email.GmailPassword")); - set("Email.GmailPassword", null); - } if(!contains("Email.RecoveryPasswordLength")) set("Email.RecoveryPasswordLength", 8); if(!contains("Email.mailPort")) @@ -370,8 +362,6 @@ public void mergeConfig() { set("DataSource.mySQLColumnId", "id"); if(!contains("Email.mailSenderName")) set("Email.mailSenderName", ""); - if(!contains("Xenoforo.predefinedSalt")) - set("Xenoforo.predefinedSalt", ""); if(!contains("Security.captcha.useCaptcha")) set("Security.captcha.useCaptcha", false); if(!contains("Security.captcha.maxLoginTry")) @@ -415,7 +405,7 @@ public void mergeConfig() { if(!contains("Hooks.disableSocialSpy")) set("Hooks.disableSocialSpy", true); if(!contains("Performances.useMultiThreading")) - set("Performances.useMultiThreading", false); + set("Performances.useMultiThreading", true); if(!contains("ExternalBoardOptions.bCryptLog2Round")) set("ExternalBoardOptions.bCryptLog2Round", 10); if(!contains("DataSource.mySQLlastlocWorld")) @@ -424,6 +414,25 @@ public void mergeConfig() { set("settings.GameMode.ForceOnlyAfterLogin", false); if(!contains("Hooks.useEssentialsMotd")) set("Hooks.useEssentialsMotd", false); + if(!contains("Purge.useAutoPurge")) { + set("Purge.useAutoPurge", false); + set("Purge.daysBeforeRemovePlayer", 60); + set("Purge.removePlayerDat", false); + set("Purge.removeEssentialsFile", false); + set("Purge.defaultWorld", "world"); + } + if(!contains("ExternalBoardOptions.phpbbTablePrefix")) { + set("ExternalBoardOptions.phpbbTablePrefix", "phpbb_"); + set("ExternalBoardOptions.phpbbActivatedGroupId", 2); + } + if(!contains("settings.security.supportOldPasswordHash")) + set("settings.security.supportOldPasswordHash", false); + if(!contains("ExternalBoardOptions.wordpressTablePrefix")) + set("ExternalBoardOptions.wordpressTablePrefix", "wp_"); + if(contains("Xenoforo.predefinedSalt")) + set("Xenoforo.predefinedSalt", null); + if(configFile.getString("settings.security.passwordHash","SHA256").toUpperCase().equals("XFSHA1") || configFile.getString("settings.security.passwordHash","SHA256").toUpperCase().equals("XFSHA256")) + set("settings.security.passwordHash", "XENFORO"); plugin.getLogger().info("Merge new Config Options if needed.."); plugin.saveConfig(); @@ -434,10 +443,10 @@ public void mergeConfig() { private static HashAlgorithm getPasswordHash() { String key = "settings.security.passwordHash"; try { - return PasswordSecurity.HashAlgorithm.valueOf(configFile.getString(key,"SHA256").toUpperCase()); + return HashAlgorithm.valueOf(configFile.getString(key,"SHA256").toUpperCase()); } catch (IllegalArgumentException ex) { ConsoleLogger.showError("Unknown Hash Algorithm; defaulting to SHA256"); - return PasswordSecurity.HashAlgorithm.SHA256; + return HashAlgorithm.SHA256; } } @@ -445,10 +454,10 @@ public void mergeConfig() { String key = "Converter.Rakamak.newPasswordHash"; try { - return PasswordSecurity.HashAlgorithm.valueOf(configFile.getString(key,"SHA256").toUpperCase()); + return HashAlgorithm.valueOf(configFile.getString(key,"SHA256").toUpperCase()); } catch (IllegalArgumentException ex) { ConsoleLogger.showError("Unknown Hash Algorithm; defaulting to SHA256"); - return PasswordSecurity.HashAlgorithm.SHA256; + return HashAlgorithm.SHA256; } } diff --git a/src/main/java/uk/org/whoami/authme/settings/Spawn.java b/src/main/java/fr/xephi/authme/settings/Spawn.java similarity index 97% rename from src/main/java/uk/org/whoami/authme/settings/Spawn.java rename to src/main/java/fr/xephi/authme/settings/Spawn.java index 44939e14..4223a672 100644 --- a/src/main/java/uk/org/whoami/authme/settings/Spawn.java +++ b/src/main/java/fr/xephi/authme/settings/Spawn.java @@ -1,4 +1,4 @@ -package uk.org.whoami.authme.settings; +package fr.xephi.authme.settings; import java.io.File; import java.util.ArrayList; diff --git a/src/main/java/uk/org/whoami/authme/settings/SpoutCfg.java b/src/main/java/fr/xephi/authme/settings/SpoutCfg.java similarity index 93% rename from src/main/java/uk/org/whoami/authme/settings/SpoutCfg.java rename to src/main/java/fr/xephi/authme/settings/SpoutCfg.java index 55a0d4b3..083bbb9e 100644 --- a/src/main/java/uk/org/whoami/authme/settings/SpoutCfg.java +++ b/src/main/java/fr/xephi/authme/settings/SpoutCfg.java @@ -1,8 +1,5 @@ -package uk.org.whoami.authme.settings; +package fr.xephi.authme.settings; -/** - * @Author Hoezef - */ import java.io.File; import java.util.ArrayList; diff --git a/src/main/java/uk/org/whoami/authme/task/MessageTask.java b/src/main/java/fr/xephi/authme/task/MessageTask.java similarity index 58% rename from src/main/java/uk/org/whoami/authme/task/MessageTask.java rename to src/main/java/fr/xephi/authme/task/MessageTask.java index 44d08ea4..34171e77 100644 --- a/src/main/java/uk/org/whoami/authme/task/MessageTask.java +++ b/src/main/java/fr/xephi/authme/task/MessageTask.java @@ -1,28 +1,13 @@ -/* - * Copyright 2011 Sebastian Köhler . - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.org.whoami.authme.task; +package fr.xephi.authme.task; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitScheduler; import org.bukkit.scheduler.BukkitTask; -import uk.org.whoami.authme.AuthMe; -import uk.org.whoami.authme.cache.auth.PlayerCache; -import uk.org.whoami.authme.cache.limbo.LimboCache; +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.cache.limbo.LimboCache; + public class MessageTask implements Runnable { diff --git a/src/main/java/uk/org/whoami/authme/task/TimeoutTask.java b/src/main/java/fr/xephi/authme/task/TimeoutTask.java similarity index 59% rename from src/main/java/uk/org/whoami/authme/task/TimeoutTask.java rename to src/main/java/fr/xephi/authme/task/TimeoutTask.java index ff899313..22ef7ab9 100644 --- a/src/main/java/uk/org/whoami/authme/task/TimeoutTask.java +++ b/src/main/java/fr/xephi/authme/task/TimeoutTask.java @@ -1,32 +1,17 @@ -/* - * Copyright 2011 Sebastian Köhler . - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.org.whoami.authme.task; +package fr.xephi.authme.task; import org.bukkit.GameMode; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; -import uk.org.whoami.authme.ConsoleLogger; -import uk.org.whoami.authme.cache.backup.FileCache; -import uk.org.whoami.authme.cache.auth.PlayerCache; -import uk.org.whoami.authme.cache.limbo.LimboPlayer; -import uk.org.whoami.authme.cache.limbo.LimboCache; -import uk.org.whoami.authme.listener.AuthMePlayerListener; -import uk.org.whoami.authme.settings.Messages; +import fr.xephi.authme.ConsoleLogger; +import fr.xephi.authme.cache.auth.PlayerCache; +import fr.xephi.authme.cache.backup.FileCache; +import fr.xephi.authme.cache.limbo.LimboCache; +import fr.xephi.authme.cache.limbo.LimboPlayer; +import fr.xephi.authme.listener.AuthMePlayerListener; +import fr.xephi.authme.settings.Messages; + public class TimeoutTask implements Runnable { diff --git a/src/main/java/uk/org/whoami/authme/threads/FlatFileThread.java b/src/main/java/fr/xephi/authme/threads/FlatFileThread.java similarity index 79% rename from src/main/java/uk/org/whoami/authme/threads/FlatFileThread.java rename to src/main/java/fr/xephi/authme/threads/FlatFileThread.java index a4bf3509..6dfddba4 100644 --- a/src/main/java/uk/org/whoami/authme/threads/FlatFileThread.java +++ b/src/main/java/fr/xephi/authme/threads/FlatFileThread.java @@ -1,4 +1,4 @@ -package uk.org.whoami.authme.threads; +package fr.xephi.authme.threads; import java.io.BufferedReader; import java.io.BufferedWriter; @@ -10,19 +10,21 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import uk.org.whoami.authme.AuthMe; -import uk.org.whoami.authme.ConsoleLogger; -import uk.org.whoami.authme.cache.auth.PlayerAuth; -import uk.org.whoami.authme.datasource.DataSource; -import uk.org.whoami.authme.settings.Settings; +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.ConsoleLogger; +import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.datasource.DataSource; +import fr.xephi.authme.settings.Settings; + public class FlatFileThread extends Thread implements DataSource { /* file layout: * - * PLAYERNAME:HASHSUM:IP:LOGININMILLIESECONDS:COORDS + * PLAYERNAME:HASHSUM:IP:LOGININMILLIESECONDS:LASTPOSX:LASTPOSY:LASTPOSZ:LASTPOSWORLD * * Old but compatible: + * PLAYERNAME:HASHSUM:IP:LOGININMILLIESECONDS * PLAYERNAME:HASHSUM:IP * PLAYERNAME:HASHSUM * @@ -81,13 +83,8 @@ public class FlatFileThread extends Thread implements DataSource { } BufferedWriter bw = null; try { - if( auth.getQuitLocY() == 0 ) { - bw = new BufferedWriter(new FileWriter(source, true)); - bw.write(auth.getNickname() + ":" + auth.getHash() + ":" + auth.getIp() + ":" + auth.getLastLogin() + "\n"); - } else { bw = new BufferedWriter(new FileWriter(source, true)); bw.write(auth.getNickname() + ":" + auth.getHash() + ":" + auth.getIp() + ":" + auth.getLastLogin() + ":" + auth.getQuitLocX() + ":" + auth.getQuitLocY() + ":" + auth.getQuitLocZ() + ":" + auth.getWorld() + "\n"); - } } catch (IOException ex) { ConsoleLogger.showError(ex.getMessage()); return false; @@ -115,7 +112,24 @@ public class FlatFileThread extends Thread implements DataSource { while ((line = br.readLine()) != null) { String[] args = line.split(":"); if (args[0].equals(auth.getNickname())) { - newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3])); + switch (args.length) { + case 4: { + newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), 0, 0, 0, "world"); + break; + } + case 7: { + newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), Integer.parseInt(args[4]), Integer.parseInt(args[5]), Integer.parseInt(args[6]), "world"); + break; + } + case 8: { + newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), Integer.parseInt(args[4]), Integer.parseInt(args[5]), Integer.parseInt(args[6]), args[7]); + break; + } + default: { + newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], 0, 0, 0, 0, "world"); + break; + } + } break; } } @@ -151,7 +165,24 @@ public class FlatFileThread extends Thread implements DataSource { while ((line = br.readLine()) != null) { String[] args = line.split(":"); if (args[0].equals(auth.getNickname())) { - newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin()); + switch (args.length) { + case 4: { + newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), 0, 0, 0, "world"); + break; + } + case 7: { + newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Integer.parseInt(args[4]), Integer.parseInt(args[5]), Integer.parseInt(args[6]), "world"); + break; + } + case 8: { + newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Integer.parseInt(args[4]), Integer.parseInt(args[5]), Integer.parseInt(args[6]), args[7]); + break; + } + default: { + newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), 0, 0, 0, "world"); + break; + } + } break; } } @@ -251,7 +282,7 @@ public class FlatFileThread extends Thread implements DataSource { String line; while ((line = br.readLine()) != null) { String[] args = line.split(":"); - if (args.length == 4) { + if (args.length >= 4) { if (Long.parseLong(args[3]) >= until) { lines.add(line); continue; @@ -286,6 +317,54 @@ public class FlatFileThread extends Thread implements DataSource { return cleared; } + @Override + public List autoPurgeDatabase(long until) { + BufferedReader br = null; + BufferedWriter bw = null; + ArrayList lines = new ArrayList(); + List cleared = new ArrayList(); + try { + br = new BufferedReader(new FileReader(source)); + String line; + while ((line = br.readLine()) != null) { + String[] args = line.split(":"); + if (args.length >= 4) { + if (Long.parseLong(args[3]) >= until) { + lines.add(line); + continue; + } else { + cleared.add(args[0]); + } + } + + } + bw = new BufferedWriter(new FileWriter(source)); + for (String l : lines) { + bw.write(l + "\n"); + } + } catch (FileNotFoundException ex) { + ConsoleLogger.showError(ex.getMessage()); + return cleared; + } catch (IOException ex) { + ConsoleLogger.showError(ex.getMessage()); + return cleared; + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException ex) { + } + } + if (bw != null) { + try { + bw.close(); + } catch (IOException ex) { + } + } + } + return cleared; + } + @Override public synchronized boolean removeAuth(String user) { if (!isAuthAvailable(user)) { diff --git a/src/main/java/uk/org/whoami/authme/threads/MySQLThread.java b/src/main/java/fr/xephi/authme/threads/MySQLThread.java similarity index 78% rename from src/main/java/uk/org/whoami/authme/threads/MySQLThread.java rename to src/main/java/fr/xephi/authme/threads/MySQLThread.java index 6d08e093..b6a8b94b 100644 --- a/src/main/java/uk/org/whoami/authme/threads/MySQLThread.java +++ b/src/main/java/fr/xephi/authme/threads/MySQLThread.java @@ -1,4 +1,4 @@ -package uk.org.whoami.authme.threads; +package fr.xephi.authme.threads; import java.sql.Connection; import java.sql.PreparedStatement; @@ -8,16 +8,18 @@ import java.sql.Statement; import java.util.ArrayList; import java.util.List; -import uk.org.whoami.authme.AuthMe; -import uk.org.whoami.authme.ConsoleLogger; -import uk.org.whoami.authme.cache.auth.PlayerAuth; -import uk.org.whoami.authme.datasource.DataSource; -import uk.org.whoami.authme.datasource.MiniConnectionPoolManager; -import uk.org.whoami.authme.datasource.MiniConnectionPoolManager.TimeoutException; -import uk.org.whoami.authme.settings.Settings; import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource; +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.ConsoleLogger; +import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.datasource.DataSource; +import fr.xephi.authme.datasource.MiniConnectionPoolManager; +import fr.xephi.authme.datasource.MiniConnectionPoolManager.TimeoutException; +import fr.xephi.authme.security.HashAlgorithm; +import fr.xephi.authme.settings.Settings; + public class MySQLThread extends Thread implements DataSource { private String host; @@ -262,6 +264,104 @@ public class MySQLThread extends Thread implements DataSource { pst.executeUpdate(); } } + if (Settings.getPasswordHash == HashAlgorithm.PHPBB) { + int id; + ResultSet rs = null; + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnName + "=?;"); + pst.setString(1, auth.getNickname()); + rs = pst.executeQuery(); + if (rs.next()) { + id = rs.getInt(columnID); + pst = con.prepareStatement("INSERT INTO " + Settings.getPhpbbPrefix + "user_group (group_id, user_id, group_leader, user_pending) VALUES (?,?,?,?);"); + pst.setInt(1, Settings.getPhpbbGroup); + pst.setInt(2, id); + pst.setInt(3, 0); + pst.setInt(4, 0); + pst.executeUpdate(); + } + } + if (Settings.getPasswordHash == HashAlgorithm.WORDPRESS) { + int id; + ResultSet rs = null; + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnName + "=?;"); + pst.setString(1, auth.getNickname()); + rs = pst.executeQuery(); + if (rs.next()) { + id = rs.getInt(columnID); + // First Name + pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); + pst.setInt(1, id); + pst.setString(2, "first_name"); + pst.setString(3, ""); + pst.executeUpdate(); + // Last Name + pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); + pst.setInt(1, id); + pst.setString(2, "last_name"); + pst.setString(3, ""); + pst.executeUpdate(); + // Nick Name + pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); + pst.setInt(1, id); + pst.setString(2, "nickname"); + pst.setString(3, auth.getNickname()); + pst.executeUpdate(); + // Description + pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); + pst.setInt(1, id); + pst.setString(2, "description"); + pst.setString(3, ""); + pst.executeUpdate(); + // Rich_Editing + pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); + pst.setInt(1, id); + pst.setString(2, "rich_editing"); + pst.setString(3, "true"); + pst.executeUpdate(); + // Comments_Shortcuts + pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); + pst.setInt(1, id); + pst.setString(2, "comment_shortcuts"); + pst.setString(3, "false"); + pst.executeUpdate(); + // admin_color + pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); + pst.setInt(1, id); + pst.setString(2, "admin_color"); + pst.setString(3, "fresh"); + pst.executeUpdate(); + // use_ssl + pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); + pst.setInt(1, id); + pst.setString(2, "use_ssl"); + pst.setString(3, "0"); + pst.executeUpdate(); + // show_admin_bar_front + pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); + pst.setInt(1, id); + pst.setString(2, "show_admin_bar_front"); + pst.setString(3, "true"); + pst.executeUpdate(); + // wp_capabilities + pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); + pst.setInt(1, id); + pst.setString(2, "wp_capabilities"); + pst.setString(3, "a:1:{s:10:\"subscriber\";b:1;}"); + pst.executeUpdate(); + // wp_user_level + pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); + pst.setInt(1, id); + pst.setString(2, "wp_user_level"); + pst.setString(3, "0"); + pst.executeUpdate(); + // default_password_nag + pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); + pst.setInt(1, id); + pst.setString(2, "default_password_nag"); + pst.setString(3, ""); + pst.executeUpdate(); + } + } } catch (SQLException ex) { ConsoleLogger.showError(ex.getMessage()); return false; @@ -343,6 +443,34 @@ public class MySQLThread extends Thread implements DataSource { } } + @Override + public synchronized List autoPurgeDatabase(long until) { + Connection con = null; + PreparedStatement pst = null; + ResultSet rs = null; + List list = new ArrayList(); + try { + con = makeSureConnectionIsReady(); + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLastLogin + "(); + } catch (TimeoutException ex) { + ConsoleLogger.showError(ex.getMessage()); + return new ArrayList(); + } finally { + close(rs); + close(pst); + close(con); + } + } + @Override public synchronized boolean removeAuth(String user) { Connection con = null; diff --git a/src/main/java/uk/org/whoami/authme/threads/SQLiteThread.java b/src/main/java/fr/xephi/authme/threads/SQLiteThread.java similarity index 94% rename from src/main/java/uk/org/whoami/authme/threads/SQLiteThread.java rename to src/main/java/fr/xephi/authme/threads/SQLiteThread.java index b1c82ef3..acc09ac8 100644 --- a/src/main/java/uk/org/whoami/authme/threads/SQLiteThread.java +++ b/src/main/java/fr/xephi/authme/threads/SQLiteThread.java @@ -1,4 +1,4 @@ -package uk.org.whoami.authme.threads; +package fr.xephi.authme.threads; import java.sql.Connection; import java.sql.DriverManager; @@ -9,12 +9,13 @@ import java.sql.Statement; import java.util.ArrayList; import java.util.List; -import uk.org.whoami.authme.AuthMe; -import uk.org.whoami.authme.ConsoleLogger; -import uk.org.whoami.authme.cache.auth.PlayerAuth; -import uk.org.whoami.authme.datasource.DataSource; -import uk.org.whoami.authme.datasource.MiniConnectionPoolManager.TimeoutException; -import uk.org.whoami.authme.settings.Settings; +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.ConsoleLogger; +import fr.xephi.authme.cache.auth.PlayerAuth; +import fr.xephi.authme.datasource.DataSource; +import fr.xephi.authme.datasource.MiniConnectionPoolManager.TimeoutException; +import fr.xephi.authme.settings.Settings; + public class SQLiteThread extends Thread implements DataSource { @@ -125,7 +126,7 @@ public class SQLiteThread extends Thread implements DataSource { rs.close(); rs = con.getMetaData().getColumns(null, null, tableName, lastlocWorld); if (!rs.next()) { - st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocWorld + " VARCHAR(255) NOT NULL DEFAULT 'world' AFTER " + lastlocZ + ";"); + st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocWorld + " VARCHAR(255) NOT NULL DEFAULT 'world';"); } rs.close(); rs = con.getMetaData().getColumns(null, null, tableName, columnEmail); @@ -268,6 +269,28 @@ public class SQLiteThread extends Thread implements DataSource { } } + @Override + public List autoPurgeDatabase(long until) { + PreparedStatement pst = null; + ResultSet rs = null; + List list = new ArrayList(); + try { + pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLastLogin + "(); + } finally { + close(rs); + close(pst); + } + } + @Override public synchronized boolean removeAuth(String user) { PreparedStatement pst = null; diff --git a/src/main/java/uk/org/whoami/authme/Management.java b/src/main/java/uk/org/whoami/authme/Management.java deleted file mode 100644 index ed98ac08..00000000 --- a/src/main/java/uk/org/whoami/authme/Management.java +++ /dev/null @@ -1,725 +0,0 @@ -package uk.org.whoami.authme; - -import java.security.NoSuchAlgorithmException; -import java.util.Date; -import java.util.List; - -import me.muizers.Notifications.Notification; - -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.entity.Player; -import org.bukkit.plugin.PluginManager; - -import uk.org.whoami.authme.api.API; -import uk.org.whoami.authme.cache.auth.PlayerAuth; -import uk.org.whoami.authme.cache.auth.PlayerCache; -import uk.org.whoami.authme.cache.backup.FileCache; -import uk.org.whoami.authme.cache.limbo.LimboCache; -import uk.org.whoami.authme.cache.limbo.LimboPlayer; -import uk.org.whoami.authme.datasource.DataSource; -import uk.org.whoami.authme.events.AuthMeTeleportEvent; -import uk.org.whoami.authme.events.LoginEvent; -import uk.org.whoami.authme.events.RestoreInventoryEvent; -import uk.org.whoami.authme.events.SpawnTeleportEvent; -import uk.org.whoami.authme.listener.AuthMePlayerListener; -import uk.org.whoami.authme.security.PasswordSecurity; -import uk.org.whoami.authme.security.RandomString; -import uk.org.whoami.authme.settings.Messages; -import uk.org.whoami.authme.settings.PlayersLogs; -import uk.org.whoami.authme.settings.Settings; -import uk.org.whoami.authme.settings.Spawn; - -public class Management { - - private Messages m = Messages.getInstance(); - private PlayersLogs pllog = PlayersLogs.getInstance(); - private Utils utils = Utils.getInstance(); - private FileCache playerCache = new FileCache(); - private DataSource database; - public AuthMe plugin; - public static RandomString rdm = new RandomString(Settings.captchaLength); - public PluginManager pm; - - public Management(DataSource database, AuthMe plugin) { - this.database = database; - this.plugin = plugin; - this.pm = plugin.getServer().getPluginManager(); - } - - public void performLogin(final Player player, final String password, - final boolean passpartu) { - final String name = player.getName().toLowerCase(); - - Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { - - @Override - public void run() { - String ip = player.getAddress().getAddress().getHostAddress(); - if (Settings.bungee) { - if (plugin.realIp.containsKey(name)) - ip = plugin.realIp.get(name); - } - World world = player.getWorld(); - Location spawnLoc = world.getSpawnLocation(); - if (plugin.mv != null) { - try { - spawnLoc = plugin.mv.getMVWorldManager() - .getMVWorld(world).getSpawnLocation(); - } catch (NullPointerException npe) { - } catch (ClassCastException cce) { - } catch (NoClassDefFoundError ncdfe) { - } - } - if (plugin.essentialsSpawn != null) { - spawnLoc = plugin.essentialsSpawn; - } - if (Spawn.getInstance().getLocation() != null) - spawnLoc = Spawn.getInstance().getLocation(); - if (PlayerCache.getInstance().isAuthenticated(name)) { - player.sendMessage(m._("logged_in")); - return; - } - if (!database.isAuthAvailable(player.getName().toLowerCase())) { - player.sendMessage(m._("user_unknown")); - return; - } - PlayerAuth pAuth = database.getAuth(name); - if (pAuth == null) { - player.sendMessage(m._("user_unknown")); - return; - } - if (!Settings.getMySQLColumnGroup.isEmpty() - && pAuth.getGroupId() == Settings.getNonActivatedGroup) { - player.sendMessage(m._("vb_nonActiv")); - return; - } - String hash = pAuth.getHash(); - String email = pAuth.getEmail(); - try { - if (!passpartu) { - if (Settings.useCaptcha) { - if (!plugin.captcha.containsKey(name)) { - plugin.captcha.put(name, 1); - } else { - int i = plugin.captcha.get(name) + 1; - plugin.captcha.remove(name); - plugin.captcha.put(name, i); - } - if (plugin.captcha.containsKey(name) - && plugin.captcha.get(name) > Settings.maxLoginTry) { - player.sendMessage(m._("need_captcha")); - plugin.cap.put(name, rdm.nextString()); - player.sendMessage("Type : /captcha " - + plugin.cap.get(name)); - return; - } else if (plugin.captcha.containsKey(name) - && plugin.captcha.get(name) > Settings.maxLoginTry) { - try { - plugin.captcha.remove(name); - plugin.cap.remove(name); - } catch (NullPointerException npe) { - } - } - } - if (PasswordSecurity.comparePasswordWithHash(password, - hash, name) && player.isOnline()) { - PlayerAuth auth = new PlayerAuth(name, hash, ip, - new Date().getTime(), email); - database.updateSession(auth); - final LimboPlayer limbo = LimboCache.getInstance() - .getLimboPlayer(name); - final PlayerAuth getAuth = database.getAuth(name); - if (limbo != null) { - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, - new Runnable() { - @Override - public void run() { - player.setOp(limbo.getOperator()); - if (player.getGameMode() != GameMode.CREATIVE) - player.setAllowFlight(limbo.isFlying()); - player.setFlying(limbo.isFlying()); - } - }); - - utils.addNormal(player, limbo.getGroup()); - - if ((Settings.isTeleportToSpawnEnabled) - && (!Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds - .contains(player.getWorld() - .getName()))) { - if ((Settings.isSaveQuitLocationEnabled) - && (getAuth.getQuitLocY() != 0)) { - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { - @Override - public void run() { - utils.packCoords(getAuth.getQuitLocX(), - getAuth.getQuitLocY(), - getAuth.getQuitLocZ(), - getAuth.getWorld(), player); - } - }); - } else { - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, - new Runnable() { - @Override - public void run() { - AuthMeTeleportEvent tpEvent = new AuthMeTeleportEvent( - player, - limbo.getLoc()); - pm.callEvent(tpEvent); - Location fLoc = tpEvent - .getTo(); - if (!tpEvent - .isCancelled()) { - if (!fLoc - .getChunk() - .isLoaded()) { - fLoc.getChunk() - .load(); - } - player.teleport(fLoc); - } - } - }); - } - } else if (Settings.isForceSpawnLocOnJoinEnabled - && Settings.getForcedWorlds - .contains(player.getWorld() - .getName())) { - final Location spawnL = spawnLoc; - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, - new Runnable() { - @Override - public void run() { - SpawnTeleportEvent tpEvent = new SpawnTeleportEvent( - player, - player.getLocation(), - spawnL, true); - pm.callEvent(tpEvent); - if (!tpEvent.isCancelled()) { - Location fLoc = tpEvent - .getTo(); - if (!fLoc.getChunk() - .isLoaded()) { - fLoc.getChunk() - .load(); - } - player.teleport(fLoc); - } - } - }); - } else if ((Settings.isSaveQuitLocationEnabled) - && (getAuth.getQuitLocY() != 0)) { - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { - @Override - public void run() { - utils.packCoords(getAuth.getQuitLocX(), - getAuth.getQuitLocY(), - getAuth.getQuitLocZ(), - getAuth.getWorld(), player); - } - }); - } else { - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, - new Runnable() { - @Override - public void run() { - AuthMeTeleportEvent tpEvent = new AuthMeTeleportEvent( - player, limbo - .getLoc()); - pm.callEvent(tpEvent); - Location fLoc = tpEvent - .getTo(); - if (!tpEvent.isCancelled()) { - if (!fLoc.getChunk() - .isLoaded()) { - fLoc.getChunk() - .load(); - } - player.teleport(fLoc); - } - } - }); - } - - if(!Settings.forceOnlyAfterLogin) - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, - new Runnable() { - @Override - public void run() { - player.setGameMode(GameMode - .getByValue(limbo - .getGameMode())); - } - }); - else - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, - new Runnable() { - @Override - public void run() { - player.setGameMode(GameMode.SURVIVAL); - } - }); - - if (Settings.protectInventoryBeforeLogInEnabled - && player.hasPlayedBefore()) { - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, - new Runnable() { - @Override - public void run() { - RestoreInventoryEvent event = new RestoreInventoryEvent( - player, - limbo.getInventory(), - limbo.getArmour()); - Bukkit.getServer() - .getPluginManager() - .callEvent(event); - if (!event.isCancelled()) { - API.setPlayerInventory( - player, - limbo.getInventory(), - limbo.getArmour()); - } - } - }); - } - - player.getServer().getScheduler() - .cancelTask(limbo.getTimeoutTaskId()); - player.getServer().getScheduler() - .cancelTask(limbo.getMessageTaskId()); - LimboCache.getInstance() - .deleteLimboPlayer(name); - if (playerCache.doesCacheExist(name)) { - playerCache.removeCache(name); - } - } - - /* - * 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); - } - - try { - if (!PlayersLogs.players.contains(player - .getName())) - PlayersLogs.players.add(player.getName()); - pllog.save(); - } catch (NullPointerException ex) { - } - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, - new Runnable() { - @Override - public void run() { - Bukkit.getServer() - .getPluginManager() - .callEvent( - new LoginEvent( - player, - true)); - } - }); - if (Settings.useCaptcha) { - if (plugin.captcha.containsKey(name)) { - plugin.captcha.remove(name); - } - if (plugin.cap.containsKey(name)) { - plugin.cap.containsKey(name); - } - } - player.setNoDamageTicks(0); - player.sendMessage(m._("login")); - displayOtherAccounts(auth); - if (!Settings.noConsoleSpam) - ConsoleLogger.info(player.getName() - + " logged in!"); - if (plugin.notifications != null) { - plugin.notifications - .showNotification(new Notification( - "[AuthMe] " + player.getName() - + " logged in!")); - } - PlayerCache.getInstance().addPlayer(auth); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, - new Runnable() { - @Override - public void run() { - player.saveData(); - } - }); - - } else if (player.isOnline()) { - if (!Settings.noConsoleSpam) - ConsoleLogger.info(player.getName() - + " used the wrong password"); - if (Settings.isKickOnWrongPasswordEnabled) { - try { - final int gm = AuthMePlayerListener.gameMode - .get(name); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, - new Runnable() { - @Override - public void run() { - player.setGameMode(GameMode - .getByValue(gm)); - } - }); - } catch (NullPointerException npe) { - } - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, - new Runnable() { - @Override - public void run() { - player.kickPlayer(m - ._("wrong_pwd")); - } - }); - } else { - player.sendMessage(m._("wrong_pwd")); - return; - } - } else { - ConsoleLogger.showError("Player " + name + " wasn't online during login process , aborded... "); - } - } else { - // need for bypass password check if passpartu command - // is enabled - PlayerAuth auth = new PlayerAuth(name, hash, ip, - new Date().getTime(), email); - database.updateSession(auth); - final LimboPlayer limbo = LimboCache.getInstance() - .getLimboPlayer(name); - if (limbo != null) { - - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, - new Runnable() { - @Override - public void run() { - player.setOp(limbo.getOperator()); - if (player.getGameMode() != GameMode.CREATIVE) - player.setAllowFlight(limbo.isFlying()); - player.setFlying(limbo.isFlying()); - } - }); - - utils.addNormal(player, limbo.getGroup()); - - if ((Settings.isTeleportToSpawnEnabled) - && (!Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds - .contains(player.getWorld() - .getName()))) { - if ((Settings.isSaveQuitLocationEnabled) - && (database.getAuth(name) - .getQuitLocY() != 0)) { - String worldname = database.getAuth(name) - .getWorld(); - World theWorld; - if (worldname.equals("unavailableworld")) { - theWorld = player.getWorld(); - } else { - theWorld = Bukkit.getWorld(worldname); - } - if (theWorld == null) - theWorld = player.getWorld(); - final Location quitLoc = new Location( - theWorld, database.getAuth(name) - .getQuitLocX() + 0.5D, - database.getAuth(name) - .getQuitLocY() + 0.5D, - database.getAuth(name) - .getQuitLocZ() + 0.5D); - - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, - new Runnable() { - @Override - public void run() { - AuthMeTeleportEvent tpEvent = new AuthMeTeleportEvent( - player, quitLoc); - pm.callEvent(tpEvent); - Location fLoc = tpEvent - .getTo(); - if (!tpEvent.isCancelled()) { - if (!fLoc.getChunk() - .isLoaded()) { - fLoc.getChunk() - .load(); - } - player.teleport(fLoc); - } - } - }); - } else { - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, - new Runnable() { - @Override - public void run() { - AuthMeTeleportEvent tpEvent = new AuthMeTeleportEvent( - player, limbo - .getLoc()); - pm.callEvent(tpEvent); - Location fLoc = tpEvent - .getTo(); - if (!tpEvent.isCancelled()) { - if (!fLoc.getChunk() - .isLoaded()) { - fLoc.getChunk() - .load(); - } - player.teleport(fLoc); - } - } - }); - } - } else if (Settings.isForceSpawnLocOnJoinEnabled - && Settings.getForcedWorlds.contains(player - .getWorld().getName())) { - final Location spawnL = spawnLoc; - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, - new Runnable() { - @Override - public void run() { - SpawnTeleportEvent tpEvent = new SpawnTeleportEvent( - player, player - .getLocation(), - spawnL, true); - pm.callEvent(tpEvent); - if (!tpEvent.isCancelled()) { - Location fLoc = tpEvent - .getTo(); - if (!fLoc.getChunk() - .isLoaded()) { - fLoc.getChunk().load(); - } - player.teleport(fLoc); - } - } - }); - } else if ((Settings.isSaveQuitLocationEnabled) - && (database.getAuth(name).getQuitLocY() != 0)) { - String worldname = database.getAuth(name) - .getWorld(); - World theWorld; - if (worldname.equals("unavailableworld")) { - theWorld = player.getWorld(); - } else { - theWorld = Bukkit.getWorld(worldname); - } - if (theWorld == null) - theWorld = player.getWorld(); - final Location quitLoc = new Location( - theWorld, - database.getAuth(name).getQuitLocX() + 0.5D, - database.getAuth(name).getQuitLocY() + 0.5D, - database.getAuth(name).getQuitLocZ() + 0.5D); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, - new Runnable() { - @Override - public void run() { - AuthMeTeleportEvent tpEvent = new AuthMeTeleportEvent( - player, quitLoc); - pm.callEvent(tpEvent); - Location fLoc = tpEvent.getTo(); - if (!tpEvent.isCancelled()) { - if (!fLoc.getChunk() - .isLoaded()) { - fLoc.getChunk().load(); - } - player.teleport(fLoc); - } - } - }); - } else { - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, - new Runnable() { - @Override - public void run() { - AuthMeTeleportEvent tpEvent = new AuthMeTeleportEvent( - player, limbo.getLoc()); - pm.callEvent(tpEvent); - Location fLoc = tpEvent.getTo(); - if (!tpEvent.isCancelled()) { - if (!fLoc.getChunk() - .isLoaded()) { - fLoc.getChunk().load(); - } - player.teleport(fLoc); - } - } - }); - } - - if(!Settings.forceOnlyAfterLogin) - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, - new Runnable() { - @Override - public void run() { - player.setGameMode(GameMode - .getByValue(limbo - .getGameMode())); - } - }); - else - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, - new Runnable() { - @Override - public void run() { - player.setGameMode(GameMode.SURVIVAL); - } - }); - - if (Settings.protectInventoryBeforeLogInEnabled - && player.hasPlayedBefore()) { - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, - new Runnable() { - @Override - public void run() { - RestoreInventoryEvent event = new RestoreInventoryEvent( - player, - limbo.getInventory(), - limbo.getArmour()); - Bukkit.getServer() - .getPluginManager() - .callEvent(event); - if (!event.isCancelled()) { - API.setPlayerInventory( - player, - limbo.getInventory(), - limbo.getArmour()); - } - } - }); - } - - player.getServer().getScheduler() - .cancelTask(limbo.getTimeoutTaskId()); - player.getServer().getScheduler() - .cancelTask(limbo.getMessageTaskId()); - LimboCache.getInstance().deleteLimboPlayer(name); - if (playerCache.doesCacheExist(name)) { - playerCache.removeCache(name); - } - } - - /* - * 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); - } - - try { - if (!PlayersLogs.players.contains(player.getName())) - PlayersLogs.players.add(player.getName()); - pllog.save(); - } catch (NullPointerException ex) { - } - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { - @Override - public void run() { - Bukkit.getServer() - .getPluginManager() - .callEvent(new LoginEvent(player, true)); - } - }); - if (Settings.useCaptcha) { - if (plugin.captcha.containsKey(name)) { - plugin.captcha.remove(name); - } - if (plugin.cap.containsKey(name)) { - plugin.cap.containsKey(name); - } - } - player.setNoDamageTicks(0); - player.sendMessage(m._("login")); - displayOtherAccounts(auth); - if (!Settings.noConsoleSpam) - ConsoleLogger.info(player.getName() + " logged in!"); - if (plugin.notifications != null) { - plugin.notifications - .showNotification(new Notification( - "[AuthMe] " + player.getName() - + " logged in!")); - } - PlayerCache.getInstance().addPlayer(auth); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { - @Override - public void run() { - player.saveData(); - } - }); - } - } catch (NoSuchAlgorithmException ex) { - ConsoleLogger.showError(ex.getMessage()); - player.sendMessage(m._("error")); - return; - } - return; - } - - }); - - } - - private void displayOtherAccounts(PlayerAuth auth) { - if (!Settings.displayOtherAccounts) { - return; - } - if (auth == null) { - return; - } - if (this.database.getAllAuthsByName(auth).isEmpty() - || this.database.getAllAuthsByName(auth) == null) { - return; - } - if (this.database.getAllAuthsByName(auth).size() == 1) { - return; - } - List accountList = this.database.getAllAuthsByName(auth); - String message = "[AuthMe] "; - int i = 0; - for (String account : accountList) { - i++; - message = message + account; - if (i != accountList.size()) { - message = message + ", "; - } else { - message = message + "."; - } - - } - for (Player player : AuthMe.getInstance().getServer() - .getOnlinePlayers()) { - if (plugin.authmePermissible(player, "authme.seeOtherAccounts")) { - player.sendMessage("[AuthMe] The player " + auth.getNickname() - + " has " + String.valueOf(accountList.size()) - + " accounts"); - player.sendMessage(message); - } - } - } - -} diff --git a/src/main/java/uk/org/whoami/authme/events/UncancellableEvent.java b/src/main/java/uk/org/whoami/authme/events/UncancellableEvent.java deleted file mode 100644 index c746ac73..00000000 --- a/src/main/java/uk/org/whoami/authme/events/UncancellableEvent.java +++ /dev/null @@ -1,28 +0,0 @@ -package uk.org.whoami.authme.events; - -import org.bukkit.Server; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; - -/** -* -* @author Xephi59 -*/ -public class UncancellableEvent extends Event { - - private static final HandlerList handlers = new HandlerList(); - private static Server s; - - public HandlerList getHandlers() { - return handlers; - } - - public static HandlerList getHandlerList() { - return handlers; - } - - public static Server getServer() { - return s; - } - -} diff --git a/src/main/java/uk/org/whoami/authme/security/PasswordSecurity.java b/src/main/java/uk/org/whoami/authme/security/PasswordSecurity.java deleted file mode 100644 index 230d5bfc..00000000 --- a/src/main/java/uk/org/whoami/authme/security/PasswordSecurity.java +++ /dev/null @@ -1,364 +0,0 @@ -/* - * Copyright 2011 Sebastian Köhler . - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package uk.org.whoami.authme.security; - -import java.io.UnsupportedEncodingException; -import java.math.BigInteger; -import java.security.InvalidKeyException; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.security.SecureRandom; -import java.util.HashMap; - -import javax.crypto.Mac; -import javax.crypto.spec.SecretKeySpec; - -import uk.org.whoami.authme.AuthMe; -import uk.org.whoami.authme.security.pbkdf2.BinTools; -import uk.org.whoami.authme.security.pbkdf2.PBKDF2Engine; -import uk.org.whoami.authme.security.pbkdf2.PBKDF2Parameters; -import uk.org.whoami.authme.settings.Settings; - -public class PasswordSecurity { - - private static SecureRandom rnd = new SecureRandom(); - public static HashMap userSalt = new HashMap(); - - private static String getMD5(String message) throws NoSuchAlgorithmException { - MessageDigest md5 = MessageDigest.getInstance("MD5"); - md5.reset(); - md5.update(message.getBytes()); - byte[] digest = md5.digest(); - return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1,digest)); - } - - private static String getSHA1(String message) throws NoSuchAlgorithmException { - MessageDigest sha1 = MessageDigest.getInstance("SHA1"); - sha1.reset(); - sha1.update(message.getBytes()); - byte[] digest = sha1.digest(); - return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1,digest)); - } - - private static String getSHA256(String message) throws NoSuchAlgorithmException { - MessageDigest sha256 = MessageDigest.getInstance("SHA-256"); - sha256.reset(); - sha256.update(message.getBytes()); - byte[] digest = sha256.digest(); - return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1,digest)); - } - - private static String getSHA512(String message) throws NoSuchAlgorithmException { - MessageDigest sha512 = MessageDigest.getInstance("SHA-512"); - sha512.reset(); - sha512.update(message.getBytes()); - byte[] digest = sha512.digest(); - return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1,digest)); - } - - public static String getWhirlpool(String message) { - Whirlpool w = new Whirlpool(); - byte[] digest = new byte[Whirlpool.DIGESTBYTES]; - w.NESSIEinit(); - w.NESSIEadd(message); - w.NESSIEfinalize(digest); - return Whirlpool.display(digest); - } - - private static String getSaltedHash(String message, String salt) throws NoSuchAlgorithmException { - return "$SHA$" + salt + "$" + getSHA256(getSHA256(message) + salt); - } - - private static String getSaltedMd5(String message, String salt) throws NoSuchAlgorithmException { - return "$MD5vb$" + salt + "$" + getMD5(getMD5(message) + salt); - } - - private static String getSaltedMyBB(String message, String salt) throws NoSuchAlgorithmException { - return getMD5(getMD5(salt)+ getMD5(message)); - } - - private static String getXAuth(String message, String salt) { - String hash = getWhirlpool(salt + message).toLowerCase(); - int saltPos = (message.length() >= hash.length() ? hash.length() - 1 : message.length()); - return hash.substring(0, saltPos) + salt + hash.substring(saltPos); - } - - private static String getSaltedIPB3(String message, String salt) throws NoSuchAlgorithmException { - return getMD5(getMD5(salt) + getMD5(message)); - } - - private static String getBCrypt(String message, String salt) throws NoSuchAlgorithmException { - return BCrypt.hashpw(message, salt); - } - - private static String getWBB3(String message, String salt) throws NoSuchAlgorithmException { - return getSHA1(salt.concat(getSHA1(salt.concat(getSHA1(message))))); - } - - private static String getPBKDF2(String password, String salt) throws NoSuchAlgorithmException { - String result = "pbkdf2_sha256$10000$"+salt+"$"; - PBKDF2Parameters params = new PBKDF2Parameters("HmacSHA256", "ASCII", BinTools.hex2bin(salt), 10000); - PBKDF2Engine engine = new PBKDF2Engine(params); - - return result + BinTools.bin2hex(engine.deriveKey(password,64)); - } - - private static String createSalt(int length) throws NoSuchAlgorithmException { - byte[] msg = new byte[40]; - rnd.nextBytes(msg); - MessageDigest sha1 = MessageDigest.getInstance("SHA1"); - sha1.reset(); - byte[] digest = sha1.digest(msg); - return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1,digest)).substring(0, length); - } - - public static String getHash(HashAlgorithm alg, String password, String name) throws NoSuchAlgorithmException { - switch (alg) { - case MD5: - return getMD5(password); - case SHA1: - return getSHA1(password); - case SHA256: - String salt = createSalt(16); - return getSaltedHash(password, salt); - case MD5VB: - String salt2 = createSalt(16); - return getSaltedMd5(password, salt2); - case WHIRLPOOL: - return getWhirlpool(password); - case XAUTH: - String xsalt = createSalt(12); - return getXAuth(password, xsalt); - case PHPBB: - return getPhpBB(password); - case PLAINTEXT: - return getPlainText(password); - case MYBB: - String salt3 = ""; - try { - salt3 = AuthMe.getInstance().database.getAuth(name).getSalt(); - } catch (NullPointerException npe) { - } - if (salt3.isEmpty() || salt3 == null) { - salt3 = createSalt(8); - userSalt.put(name, salt3); - } - return getSaltedMyBB(password, salt3); - case IPB3: - String salt4 = ""; - try { - salt4 = AuthMe.getInstance().database.getAuth(name).getSalt(); - } catch (NullPointerException npe) { - } - if (salt4.isEmpty() || salt4 == null) { - salt4 = createSalt(5); - userSalt.put(name, salt4); - } - return getSaltedIPB3(password, salt4); - case PHPFUSION: - String salt5 = ""; - try { - salt5 = AuthMe.getInstance().database.getAuth(name).getSalt(); - } catch (NullPointerException npe) { - } - if (salt5.isEmpty() || salt5 == null) { - salt5 = createSalt(12); - userSalt.put(name, getSHA1(salt5)); - } - return getPhPFusion(password, getSHA1(salt5)); - case SMF: - return getSHA1(name.toLowerCase() + password); - case XFSHA1: - return getSHA1(getSHA1(password) + Settings.getPredefinedSalt); - case XFSHA256: - return getSHA256(getSHA256(password) + Settings.getPredefinedSalt); - case SALTED2MD5: - String salt6 = ""; - try { - salt6 = AuthMe.getInstance().database.getAuth(name).getSalt(); - } catch (NullPointerException npe) { - } - if (salt6.isEmpty() || salt6 == null) { - salt6 = createSalt(Settings.saltLength); - userSalt.put(name, salt6); - } - return getMD5(getMD5(password) + salt6); - case JOOMLA: - String saltj = ""; - try { - saltj = AuthMe.getInstance().database.getAuth(name).getHash().split(":")[1]; - } catch (NullPointerException npe) { - } catch (ArrayIndexOutOfBoundsException aioobe) { - } - if (saltj.isEmpty() || saltj == null) { - saltj = createSalt(32); - userSalt.put(name, saltj); - } - return getMD5(password + saltj) + ":" + saltj; - case BCRYPT: - String saltbcrypt = ""; - try { - saltbcrypt = AuthMe.getInstance().database.getAuth(name).getSalt(); - } catch (NullPointerException npe) { - } catch (ArrayIndexOutOfBoundsException aioobe) { - } - if(saltbcrypt.isEmpty() || saltbcrypt == null) { - saltbcrypt = BCrypt.gensalt(Settings.bCryptLog2Rounds); - userSalt.put(name, saltbcrypt); - } - return getBCrypt(password, saltbcrypt); - case WBB3: - String saltwbb = ""; - try { - saltbcrypt = AuthMe.getInstance().database.getAuth(name).getSalt(); - } catch (NullPointerException npe) { - } catch (ArrayIndexOutOfBoundsException aioobe) { - } - if(saltwbb.isEmpty() || saltwbb == null) { - saltwbb = createSalt(40); - userSalt.put(name, saltwbb); - } - return getWBB3(password, saltwbb); - case SHA512: - return getSHA512(password); - case DOUBLEMD5: - return getMD5(getMD5(password)); - case PBKDF2: - String saltpbkdf2 = createSalt(12); - return getPBKDF2(password, saltpbkdf2); - default: - throw new NoSuchAlgorithmException("Unknown hash algorithm"); - } - } - - public static boolean comparePasswordWithHash(String password, String hash, String playername) throws NoSuchAlgorithmException { - if(hash.contains("$H$")) { - PhpBB checkHash = new PhpBB(); - return checkHash.phpbb_check_hash(password, hash); - } - if(!Settings.getMySQLColumnSalt.isEmpty() && Settings.getPasswordHash == HashAlgorithm.WBB3) { - String salt = AuthMe.getInstance().database.getAuth(playername).getSalt(); - return hash.equals(getWBB3(password, salt)); - } - if(!Settings.getMySQLColumnSalt.isEmpty() && Settings.getPasswordHash == HashAlgorithm.IPB3) { - String salt = AuthMe.getInstance().database.getAuth(playername).getSalt(); - return hash.equals(getSaltedIPB3(password, salt)); - } - if(!Settings.getMySQLColumnSalt.isEmpty() && Settings.getPasswordHash == HashAlgorithm.BCRYPT) { - String salt = AuthMe.getInstance().database.getAuth(playername).getSalt(); - return hash.equals(BCrypt.hashpw(password, salt)); - } - if(!Settings.getMySQLColumnSalt.isEmpty() && Settings.getPasswordHash == HashAlgorithm.PHPFUSION) { - String salt = AuthMe.getInstance().database.getAuth(playername).getSalt(); - return hash.equals(getPhPFusion(password, salt)); - } - if(!Settings.getMySQLColumnSalt.isEmpty() && Settings.getPasswordHash == HashAlgorithm.MYBB) { - String salt = AuthMe.getInstance().database.getAuth(playername).getSalt(); - return hash.equals(getSaltedMyBB(password, salt)); - } - if(Settings.getPasswordHash == HashAlgorithm.SMF) - return hash.equals(getSHA1(playername.toLowerCase() + password)); - if(Settings.getPasswordHash == HashAlgorithm.XFSHA1) - return hash.equals(getSHA1(getSHA1(password) + Settings.getPredefinedSalt)); - if(Settings.getPasswordHash == HashAlgorithm.XFSHA256) - return hash.equals(getSHA256(getSHA256(password)+ Settings.getPredefinedSalt)); - if(Settings.getPasswordHash == HashAlgorithm.DOUBLEMD5) - return hash.equals(getMD5(getMD5(password))); - if(!Settings.getMySQLColumnSalt.isEmpty() && Settings.getPasswordHash == HashAlgorithm.SALTED2MD5) { - String salt = AuthMe.getInstance().database.getAuth(playername).getSalt(); - return hash.equals(getMD5(getMD5(password) + salt)); - } - if(Settings.getPasswordHash == HashAlgorithm.JOOMLA) { - String salt = hash.split(":")[1]; - return hash.equals(getMD5(password + salt) + ":" + salt); - } - if(Settings.getPasswordHash == HashAlgorithm.SHA512) - return hash.equals(getSHA512(password)); - if(Settings.getPasswordHash == HashAlgorithm.PBKDF2) { - String[] line = hash.split("\\$"); - String salt = line[2]; - String derivedKey = line[3]; - PBKDF2Parameters params = new PBKDF2Parameters("HmacSHA256", "ASCII", BinTools.hex2bin(salt), 10000, BinTools.hex2bin(derivedKey)); - PBKDF2Engine engine = new PBKDF2Engine(params); - return engine.verifyKey(password); - } - // PlainText Password - if(hash.length() < 32 ) - return hash.equals(password); - if (hash.length() == 32) - return hash.equals(getMD5(password)); - if (hash.length() == 40) - return hash.equals(getSHA1(password)); - if (hash.length() == 140) { - int saltPos = (password.length() >= hash.length() ? hash.length() - 1 : password.length()); - String salt = hash.substring(saltPos, saltPos + 12); - return hash.equals(getXAuth(password, salt)); - } - if (hash.contains("$")) { - String[] line = hash.split("\\$"); - if (line.length > 3 && line[1].equals("SHA")) { - return hash.equals(getSaltedHash(password, line[2])); - } else { - if(line[1].equals("MD5vb")) { - return hash.equals(getSaltedMd5(password, line[2])); - } - } - } - return false; - } - - private static String getPhpBB(String password) { - PhpBB hash = new PhpBB(); - String phpBBhash = hash.phpbb_hash(password); - return phpBBhash; - } - - private static String getPlainText(String password) { - return password; - } - - public static String getPhPFusion(String msg, String keyString) { - String digest = null; - String algo = "HmacSHA256"; - try { - SecretKeySpec key = new SecretKeySpec((keyString).getBytes("UTF-8"), algo); - Mac mac = Mac.getInstance(algo); - mac.init(key); - byte[] bytes = mac.doFinal(msg.getBytes("ASCII")); - StringBuffer hash = new StringBuffer(); - for (int i = 0; i < bytes.length; i++) { - String hex = Integer.toHexString(0xFF & bytes[i]); - if (hex.length() == 1) { - hash.append('0'); - } - hash.append(hex); - } - digest = hash.toString(); - } catch (UnsupportedEncodingException e) { - } catch (InvalidKeyException e) { - } catch (NoSuchAlgorithmException e) { - } - return digest; - } - - public enum HashAlgorithm { - - MD5, SHA1, SHA256, WHIRLPOOL, XAUTH, MD5VB, PHPBB, PLAINTEXT, MYBB, IPB3, PHPFUSION, SMF, XFSHA1, - XFSHA256, SALTED2MD5, JOOMLA, BCRYPT, WBB3, SHA512, DOUBLEMD5, PBKDF2 - } - -} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 8a438a73..eb93cea9 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,34 +1,80 @@ DataSource: + # Column for storing or checking players nickname mySQLColumnName: username + # Table of the database mySQLTablename: authme + # Username about Database Connection Infos mySQLUsername: authme + # Can be set to : file, sqlite, mysql backend: file + # Column for storing players lastlogins mySQLColumnLastLogin: lastlogin + # Database Name, use with converters or as SQLITE database name mySQLDatabase: authme + # Database Port mySQLPort: '3306' + # Column for storing players IPs mySQLColumnIp: ip + # Database location mySQLHost: 127.0.0.1 + # Column for storing players passwords mySQLColumnPassword: password + # Password about Database Connection Infos mySQLPassword: '12345' + # Do we need to cache all things ? Not Recommanded with multiThreading enable caching: true + # Column for SaveQuitLocation - X mySQLlastlocX: x + # Column for SaveQuitLocation - Y mySQLlastlocY: y + # Column for SaveQuitLocation - Z mySQLlastlocZ: z + # Column for SaveQuitLocation - World name mySQLlastlocWorld: world + # Column for storing players emails mySQLColumnEmail: email + # Column of IDs to sort data mySQLColumnId: id GroupOptions: + # if you want to set up a particulary Permission Group for + # users that arent registered yet. Pay attention this option + # is casesensitive! + # Example: UnregisteredPlayerGroup: GuestUser UnregisteredPlayerGroup: '' + # Same as UnregisteredGroup if u want to set a switch + # between unregistered and registered player group + # set the group name below RegisteredPlayerGroup: '' + # with this option you can add specified permission onJoin + # like for example LoginBonus from another plugins, AuthMe + # will check onJoin if player has that permissions in his Group + # if true it add a temporany permissions to that user. This Field + # is needed beacuse AuthMe switch all unlogged players on a + # specified restricted Permission Group, so plugins that will use + # some particolary permissions on join doesnt work, without + # compiling option below! Permissions: PermissionsOnJoin: [] settings: sessions: + # Do you want to enable session? When enabled + # the ip of a player will be bound to the nickname + # of the player on login. As long as neither of those + # two change players don't have to login on a reconnect enabled: false + # After how many minutes a session should timeout? + # 0 for unlimitted sessions, use 0 at your own risk! + # consider that session will end only after timeout, and + # if player's ip is changed but the timeout treshould isent + # ended, player will kick out of sever for unvalidSession! timeout: 10 + # Do we need to timeout the session if the player is offline + # And try to login with an another IP Address? sessionExpireOnIpChange: false restrictions: + # Can unregistered players chat, care , that block all commands except followers allowChat: false + # Commands allowed when a player is unlogged allowCommands: - /login - /register @@ -37,99 +83,267 @@ settings: - /passpartu - /email - /captcha + # Maximum Registraion per IP default: 1 maxRegPerIp: 1 + # max allowed nick length (Warning when you use + # mysql and choose a value >20 you have to + # increase the size of the nickname column in your + # mysql table) maxNicknameLength: 20 + # Player that is online arent + # kick out for "logged in from another + # Location", this options will prevent players that would exploit + # your account when you are playing ForceSingleSession: true + # Teleport every time player join at World Spawn location, + # even if they loggedin successfully, + # all quit and previus location will + # overwrite with World Spawn. Different From + # "teleportUnAuthedToSpawn" + # that teleport player back to his quit or kick position, + # when he loggedin ForceSpawnLocOnJoinEnabled: false + # This will prevent all lost of quit position, when player + # isent loggedin SaveQuitLocation: false + # For activate Restricted user by ip u need + # to set True this option and configure the field + # AllowedRestrctedUser as show below AllowRestrictedUser: false - AllowedRestrictedUser: [] + # Restricted user will kick players that + # is listed below and they dont + # meet the match of username;ip + # Example playername;127.0.0.1 , if playername + # hasent 127.0.0.1 as ip address + # he will not be allowed to join the server + AllowedRestrictedUser: + - playername;127.0.0.1 + # Should unregistered players be kicked immediatly? kickNonRegistered: false + # Should fail password players be kicked immediatly? kickOnWrongPassword: false + # should not loged in players be teleported to spawn? + # On login they will be teleported back to their normal + # position teleportUnAuthedToSpawn: false + # min allowed nick length minNicknameLength: 3 + # Can unregistered players walk around? allowMovement: false + # After what time players who fail to login or register + # should be kicked. Set to 0 to disable. timeout: 30 + # Regex sintax for allowed Char in player name. allowedNicknameCharacters: '[a-zA-Z0-9_?]*' + # How far can unregistered players walk? Set to 0 + # for unlimited radius allowedMovementRadius: 100 + # Enable double check of password when you register + # when it's true, registration require that kind of command: + # /register enablePasswordVerifier: true + # Should we protect the player inventory before logging in? ProtectInventoryBeforeLogIn: true + # Should we display all other accounts from a player when he joins? + # permission: /authme.admin.accounts displayOtherAccounts: true + # WorldNames where we need to force the spawn location for ForceSpawnLocOnJoinEnabled ForceSpawnOnTheseWorlds: - world - world_nether - world_the_end + # Ban ip when the ip is not the ip registered in database banUnsafedIP: false GameMode: + # ForceSurvivalMode to player when join ? ForceSurvivalMode: false + # if player join with CreativeMode and ForceSurvivalMode: true + # inventory will be wipped ResetInventoryIfCreative: false + # Do we need to force the survival mode ONLY after /login process ? ForceOnlyAfterLogin: false security: + # minimum Length of password minPasswordLength: 4 + # this is very important options, + # every time player join the server, + # if they are registered, AuthMe will switch him + # to unLoggedInGroup, this + # should prevent all major exploit. + # So you can set up on your Permission Plugin + # this special group with 0 permissions, or permissions to chat, + # or permission to + # send private message or all other perms that you want, + # the better way is to set up + # this group with few permissions, + # so if player try to exploit some account, + # they can + # do anything except what you set in perm Group. + # After a correct logged-in player will be + # moved to his correct permissions group! + # Pay attention group name is case sensitive, + # so Admin is different from admin, + # otherwise your group will be wiped, + # and player join in default group []! + # Example unLoggedinGroup: NotLogged unLoggedinGroup: unLoggedinGroup + # 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) passwordHash: SHA256 + # salt length for the SALTED2MD5 MD5(MD5(password)+salt) doubleMD5SaltLength: 8 + # If password checking return false , do we need to check with all + # other password algorithm to check an old password ? + # AuthMe will update the password to the new passwordHash ! + supportOldPasswordHash: false registration: + # enable registration on the server? enabled: true + # Send every X seconds a message to a player to + # remind him that he has to login/register messageInterval: 5 + # Only registered and logged in players can play. + # See restrictions for exceptions force: true + # Does we replace password registration by an Email registration method ? enableEmailRegistrationSystem: false + # Enable double check of email when you register + # when it's true, registration require that kind of command: + # /register doubleEmailCheck: false unrestrictions: + # below you can list all your account name, that + # AuthMe will ignore for registration or login, configure it + # at your own risk!! Remember that if you are going to add + # nickname with [], you have to delimit name with ' '. + # this option add compatibility with BuildCraft and some + # other mods. + # It is CaseSensitive! UnrestrictedName: [] + # Message language, available : en, de, br, cz, pl, fr, ru, hu, sk, es, zhtw, fi, zhcn, lt, it, ko, pt messagesLanguage: en ExternalBoardOptions: + # MySQL column for the salt , needed for some forum/cms support mySQLColumnSalt: '' + # MySQL column for the group, needed for some forum/cms support mySQLColumnGroup: '' + # -1 mean disabled. If u want that only + # activated player can login in your server + # 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 mySQLOtherUsernameColumns: [] + # How much Log to Round needed in BCrypt(do not change it if you do not know what's your doing) bCryptLog2Round: 10 -Xenoforo: - predefinedSalt: '' + # phpBB prefix defined during phpbb installation process + phpbbTablePrefix: 'phpbb_' + # phpBB activated group id , 2 is default registered group defined by phpbb + phpbbActivatedGroupId: 2 + # WordPress prefix defined during WordPress installation process + wordpressTablePrefix: 'wp_' permission: + # take care with this options, if u dont want + # to use Vault and Group Switching of + # AuthMe for unloggedIn players put False + # below, default is true. EnablePermissionCheck: false BackupSystem: + # Enable or Disable Automatic Backup ActivateBackup: false + # set Backup at every start of Server OnServerStart: false + # set Backup at every stop of Server OnServerStop: true + # Windows only mysql installation Path MysqlWindowsPath: 'C:\\Program Files\\MySQL\\MySQL Server 5.1\\' Passpartu: + # Enable or Disable Passpartu Feature, + # this feature let Admin Login with all registered + # Account they need, for example inspecting Player that + # is doing shit, they can login without know any + # Player password! More info on How TO enablePasspartu: false Security: SQLProblem: + # Stop the server if we can't contact the sql database + # Take care with this, if you set that to false, + # AuthMe automatically disable and the server is not protected! stopServer: true ReloadCommand: + # /reload support useReloadCommandSupport: true console: + # Remove spam console noConsoleSpam: false + # Replace passwords in the console when player type a command like /login removePassword: true - logConsole: false captcha: + # Player need to put a captcha when he fails too lot the password useCaptcha: false + # Max allowed tries before request a captcha maxLoginTry: 5 + # Captcha length captchaLength: 5 Converter: Rakamak: + # Rakamak file name fileName: users.rak + # Rakamak use ip ? useIP: false + # IP file name for rakamak ipFileName: UsersIp.rak + # 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) newPasswordHash: SHA256 Email: + # Email SMTP server host mailSMTP: smtp.gmail.com + # Email SMTP server port mailPort: 465 + # Email account that send the mail mailAccount: '' + # Email account password mailPassword: '' + # Custom SenderName, that replace the mailAccount name in the email mailSenderName: '' + # Random password length RecoveryPasswordLength: 8 + # Email subject of password get mailSubject: 'Your new AuthMe Password' + # Email text here mailText: 'Dear ,

This is your new AuthMe password for the server

:



Do not forget to change password after login!
/changepassword newPassword' + # Like maxRegPerIp but with email maxRegPerEmail: 1 Hooks: + # Do we need to hook with multiverse for spawn checking? multiverse: true + # Do we need to hook with ChestShop for prevent buy or selling ? chestshop: true + # Do we need to hook with BungeeCord for get the real Player ip ? bungeecord: false + # Do we need to hook with Notifications for Notifs sending ? notifications: true + # Do we need to disable Essentials SocialSpy on join ? disableSocialSpy: true + # Do we need to force /motd Essentials command on join ? useEssentialsMotd: false Performances: - useMultiThreading: false \ No newline at end of file + # HIGHLY recommended to use this! This will increase database performance + # Default is false due to little servers + useMultiThreading: false +Purge: + # On Enable , does AuthMe need to purge automatically old accounts unused ? + useAutoPurge: false + # Number of Days an account become Unused + daysBeforeRemovePlayer: 60 + # Do we need to remove the player.dat file during purge process ? + removePlayerDat: false + # Do we need to remove the Essentials/users/player.yml file during purge proecess ? + removeEssentialsFile: false + # World where are players.dat stores + defaultWorld: 'world' \ No newline at end of file diff --git a/src/main/resources/messages_cz.yml b/src/main/resources/messages_cz.yml index 92ee54e7..d64336df 100644 --- a/src/main/resources/messages_cz.yml +++ b/src/main/resources/messages_cz.yml @@ -3,14 +3,14 @@ not_logged_in: '&cNeprihlasen!' reg_voluntarily: '&cRegistruj se prikazem "/register heslo heslo".' usage_log: '&cPouzij: "/login TvojeHeslo".' wrong_pwd: '&cSpatne heslo.' -unregistered: '&cUspesna unregistrace!' +unregistered: '&cUspesne odregistrovan!' reg_disabled: '&cRegistrace je zakazana!' valid_session: '&cAutomaticke znovuprihlaseni.' login: '&cUspesne prihlaseni!' user_regged: '&cUzivatelske jmeno je jiz registrovano.' usage_reg: '&cPouzij: "/register heslo heslo".' no_perm: '&cNemas opravneni.' -error: '&cVyskytla se chyba kontaktujte admina ...' +error: '&cVyskytla se chyba - kontaktujte administratora ...' login_msg: '&cProsim prihlas se "/login TvojeHeslo".' reg_msg: '&cProsim zaregistruj se "/register heslo heslo".' reg_email_msg: '&cProsim registruj se pomoci "/register "' @@ -18,20 +18,20 @@ usage_unreg: '&cPouzij: "/unregister TvojeHeslo".' pwd_changed: '&cHeslo zmeneno!' user_unknown: '&cUzivatelske jmeno neni registrovano.' reg_only: '&cServer je pouze pro registrovane! Navstivte http://bit.ly/zyEzzS.' -logged_in: '&cSes jiz prihlasen!' +logged_in: '&cJiz jsi prihlasen!' logout: '&cOdhlaseni bylo uspesne.' -same_nick: '&cNekdo jiz hraje se stejnym nickem.' +same_nick: '&cUzivatel s timto jmenem jiz hraje.' registered: '&cRegistrace byla uspesna!' -reload: '&cPrenacteni AuthMe probehlo uspesne.' -timeout: '&cCas na prihlaseni vyprsel!' +reload: '&cZnovu nacteni nastaveni AuthMe probehlo uspesne.' +timeout: '&cCas pro prihlaseni vyprsel!' unsafe_spawn: '&cTvoje pozice pri odpojeni byla nebezpecna, teleportuji na spawn!' unvalid_session: '&cChybna data pri cteni pockejte do vyprseni.' max_reg: '&cJiz jsi prekrocil(a) limit pro pocet uctu z jedne IP.' password_error: '&cHesla se neshoduji!' pass_len: '&cTvoje heslo nedosahuje minimalni delky (4).' -vb_nonActiv: '&cTvuj ucet neni aktivovany, zkontrolujte si vas E-mail.' +vb_nonActiv: '&cTvuj ucet neni aktivovany, zkontrolujte si svuj E-mail.' usage_changepassword: '&cPouzij: "/changepassword stareHeslo noveHeslo".' -name_len: '&cTvuj nick je priliz kratky, nebo priliz dlouhy' +name_len: '&cTvuj nick je prilis kratky, nebo prilis dlouhy' regex: '&cTvuj nick obsahuje nepovolene znaky. Pripustne znaky jsou: REG_EX' add_email: '&cPridej prosim svuj email pomoci : /email add TvujEmail TvujEmail' bad_database_email: '[AuthMe] Prikaz /email je mozno pouzit jen s MySQL a SQLite, kontaktuj Admina' diff --git a/src/main/resources/messages_fi.yml b/src/main/resources/messages_fi.yml index 0e0d8a0a..82af59d2 100644 --- a/src/main/resources/messages_fi.yml +++ b/src/main/resources/messages_fi.yml @@ -1,53 +1,53 @@ unknown_user: '&fKäyttäjä ei ole tietokannassa!' unsafe_spawn: '&fHengenvaarallinen poistumispaikka! Siirsimme sinut spawnille!' not_logged_in: '&cEt ole kirjautunut sisään!' -reg_voluntarily: '&fNyt voit rekisteröidä pelaajasi serverillemme: "/register salasana salasana"' -usage_log: '&cKäyttö: /login salasana' +reg_voluntarily: '&fNyt voit rekisteröidä pelaajasi palvelimellemme: "/register salasana salasana"' +usage_log: '&cKäyttötapa: /login salasana' wrong_pwd: '&cVäärä salasana' -unregistered: '&cOnnistuneesti poistettu pelaajatili!' -reg_disabled: '&cRekisteröinti suljettu!' -valid_session: '&cSession kirjautuminen!' +unregistered: '&cPelaajatili poistettu onnistuneesti!' +reg_disabled: '&cRekisteröinti on suljettu!' +valid_session: '&cIstunto jatkettu!' login: '&cKirjauduit onnistuneesti' vb_nonActiv: '&fKäyttäjäsi ei ole vahvistettu!' user_regged: '&cPelaaja on jo rekisteröity' -usage_reg: '&cKäyttö: /register salasana salasana' +usage_reg: '&cKäyttötapa: /register salasana salasana' max_reg: '&fSinulla ei ole oikeuksia tehdä enempää pelaajatilejä!' no_perm: '&cEi oikeuksia' -error: '&fVirhe: Ota yhteys operaattoriin!' -login_msg: '&cKirjaudu palvelimmelle "/login salasana"' -reg_msg: '&cRekisteröidy palvelimellemme "/register salasana salasana"' -reg_email_msg: '&cPlease register with "/register "' -usage_unreg: '&cKäyttö: /unregister password' +error: '&fVirhe: Ota yhteys palveluntarjoojaan!' +login_msg: '&cKirjaudu palvelimmelle komennolla "/login salasana"' +reg_msg: '&cRekisteröidy palvelimellemme komennolla "/register salasana salasana"' +reg_email_msg: '&cRekisteröi sähköpostisi komennolla "/register "' +usage_unreg: '&cKäyttötapa: /unregister password' pwd_changed: '&cSalasana vaihdettu!!' user_unknown: '&cSalasanat eivät täsmää' -password_error: '&fSalasanat eivät vastaa' -unvalid_session: '&fSession Dataes doesnt corrispond Plaese wait the end of session' +password_error: '&fSalasanat ei täsmää' +unvalid_session: '&fIstunto ei täsmää! Ole hyvä ja odota istunnon loppuun' reg_only: '&fMene sivustolle: http://example.com rekisteröityäksesi!' logged_in: '&cOlet jo kirjautunut!' logout: '&cKirjauduit ulos palvelimelta.' -same_nick: '&COlet jo serverillä! &COdota clientin aikakatkaisua tai ota yhteyttä operaattoriin.' +same_nick: '&COlet jo palvelimella! &COdota käyttäjän aikakatkaisua tai ota yhteyttä palveluntarjoojaan.' registered: '&cRekisteröidyit onnistuneesti!' pass_len: '&fSalasanasi on liian pitkä tai lyhyt.' -reload: '&fConfigit ja plugin uudelleenladattu' +reload: '&fAsetukset uudelleenladattu' timeout: '&fKirjautumisaika meni umpeen.' -usage_changepassword: '&fKäyttö: /changepassword vanhaSalasana uusiSalasana' +usage_changepassword: '&fKäyttötapa: /changepassword vanhaSalasana uusiSalasana' name_len: '&cPelaajanimesi on liian lyhyt tai pitkä' regex: '&cPelaajanimesi sisältää luvattomia merkkejä. Hyväksytyt merkit: REG_EX' -add_email: '&cLisää sähköpostisi : /email add sähköpostisi varmistasähköpostisi' -bad_database_email: '[AuthMe] Tämä /email komento on vain käytössä MySQLlän kanssa. Ota yhteys operaattoriin' -recovery_email: '&cUnohtuiko salasana?' -usage_captcha: '&cKäyttö: /captcha ' -wrong_captcha: '&cVäärä varmistus, käytä : /captcha THE_CAPTCHA' -valid_captcha: '&cSinun varmistus epäonnistui.!' -kick_forvip: '&cA VIP Player join the full server!' -kick_fullserver: '&cThe server is actually full, Sorry!' -usage_email_add: '&fUsage: /email add ' -usage_email_change: '&fUsage: /email change ' -usage_email_recovery: '&fUsage: /email recovery ' -new_email_invalid: '[AuthMe] New email invalid!' -old_email_invalid: '[AuthMe] Old email invalid!' -email_invalid: '[AuthMe] Invalid Email' -email_added: '[AuthMe] Email Added !' -email_confirm: '[AuthMe] Confirm your Email !' -email_changed: '[AuthMe] Email Change !' -email_send: '[AuthMe] Recovery Email Send !' +add_email: '&cLisää sähköpostisi: /email add sähköpostisi sähköpostisiUudelleen' +bad_database_email: '[AuthMe] Tämä /email komento on vain käytössä MySQLlän kanssa. Ota yhteys palveluntarjoojaan' +recovery_email: '&cUnohtuiko salasana? Käytä komentoa: /email recovery ' +usage_captcha: '&cKäyttötapa: /captcha ' +wrong_captcha: '&cVäärä varmistus, käytä : /captcha CAPTCHA' +valid_captcha: '&cSinun varmistus onnistui.!' +kick_forvip: '&cVIP pelaaja liittyi täyteen palvelimeen!' +kick_fullserver: '&cPalvelin on täynnä, Yritä pian uudelleen!' +usage_email_add: '&fKäyttötapa: /email add ' +usage_email_change: '&fKäyttötapa: /email change ' +usage_email_recovery: '&fKäyttötapa: /email recovery ' +new_email_invalid: '[AuthMe] Uusi sähköposti on väärä!' +old_email_invalid: '[AuthMe] Vanha sähköposti on väärä!' +email_invalid: '[AuthMe] Väärä sähköposti' +email_added: '[AuthMe] Sähköposti lisätty!' +email_confirm: '[AuthMe] Vahvistuta sähköposti!' +email_changed: '[AuthMe] Sähköposti vaihdettu!' +email_send: '[AuthMe] Palautus sähköposti lähetetty!' diff --git a/src/main/resources/messages_ko.yml b/src/main/resources/messages_ko.yml index fd65f870..194332b1 100644 --- a/src/main/resources/messages_ko.yml +++ b/src/main/resources/messages_ko.yml @@ -1,53 +1,53 @@ -unknown_user: 사용자는 데이터베이스에 없습니다 -unsafe_spawn: 당신이 나갔던 위치는 안전하지 않았습니다, 당신을 윌드 스폰으로 텔레포트시킵니다 -not_logged_in: '&c로그인하지 않았습니다!' -reg_voluntarily: 당신이 서버에 게정을 등록하고 싶다면 "/register 비밀번호 비밀번호재입력"을 치세요 -usage_log: '&c사용법: /login 비밀번호' -wrong_pwd: '&c잘못된 비밀번호입니다' -unregistered: '&c성공적으로 회원탈퇴되었습니다!' -reg_disabled: '&c회원가입이 성공적으로 비활성화되었습니다' -valid_session: '&c세션 로그인' -login: '&c성공적으로 로그인 되었습니다!' -vb_nonActiv: 당신의 계정은 활성화되어 있지 않습니다 당신의 이메일을 체크해주세요! -user_regged: '&c사용자 이름은 이미 등록되어 있습니다' -usage_reg: '&c사용법: /register 비밀번호 비밀번호재입력' -max_reg: 당신은 가입할 수 있는 계정의 최대 한도 수를 넘었습니다 -no_perm: '&c권한이 없습니다' -error: 오류가 발생했습니다; 관리자한테 문의하세요 -login_msg: '&c로그인 하실려면 "/login 비밀번호"를 치세요' -reg_msg: '&c가입하실려면 "/register 비밀번호 비밀번호재입력"을 치세요' -reg_email_msg: '&c가입하실려면 "/register <이메일> <이메일재입력>을 치세요"' -usage_unreg: '&c사용법: /unregister 비밀번호' -pwd_changed: '&c비밀번호가 변경되었습니다!' -user_unknown: '&c사용자 이름은 등록되지 않았습니다' -password_error: 비밀번호가 일치하지 않습니다 -unvalid_session: 세션 데이터베이스가 일치하지 않습니다 세션이 끝날때 까지 기달려주세요 -reg_only: 회원가입은 플레이어만 할 수 있습니다! http://example.com 에 가입해주세요 -logged_in: '&c이미 로그인되어 있습니다!' -logout: '&c성공적으로 로그아웃되었습니다' -same_nick: 같은 닉네임이 이미 게임중입니다 -registered: '&c성공적으로 회원가입되었습니다!' -pass_len: 당신의 비밀번호는 최소 글자나 최대글자를 초과하였습니다 적당한 비밀번호 글자로 해주세요 -reload: 설정과 데이터베이스가 리로드되었습니다 -timeout: 로그인 시간 초과 -usage_changepassword: '사용법: /changepassword 기존비밀번호 새비밀번호' -name_len: '&c당신의 닉네임은 너무 길거나 짧습니다' -regex: '&c당신의 닉네임에 잘못된 문자가 포함되어 있습니다. 허용된 글자: REG_EX' -add_email: '&c당신의 이메일을 : /email add yourEmail confirmEmail 명령어로 추가해주세요' -bad_database_email: '[AuthMe] /email 명령어는 오직 MySQL 와 SQLite에서만 가능합니다, 관리자에게 문의해보세요' -recovery_email: '&c비밀번호를 잊어버리셨다고요? /email recovery <자신의이메일>을 사용해서 복구해보세요' -usage_captcha: '&c사용법: /captcha <캡차>' -wrong_captcha: '&c잘못된 캡차입니다, 올바른 사용법 : /captcha THE_CAPTCHA' -valid_captcha: '&c당신의 캡차는 올바릅니다 !' -kick_forvip: '&c한 VIP 플레이어가 만원인 서버에 입장했습니다!!' -kick_fullserver: '&c그 서버는 실제로 만원입니다, 미안!' -usage_email_add: '&f사용법: /email add <이메일> <이메일재입력> ' -usage_email_change: '&f사용법: /email change ' -usage_email_recovery: '&f사용법: /email recovery <이메일>' -new_email_invalid: '[AuthMe] 새 이메일이 잘못되었습니다!' -old_email_invalid: '[AuthMe] 기존 이메일이 잘못되었습니다!' -email_invalid: '[AuthMe] 이메일이 잘못되었습니다' -email_added: '[AuthMe] 이메일 추가됨 !' -email_confirm: '[AuthMe] 이메일을 확인해주세요 !' -email_changed: '[AuthMe] 이메일 변경됨 !' -email_send: '[AuthMe] 복구 이메일 발송됨 !' +unknown_user: 사용자는 데이터베이스에 없습니다 +unsafe_spawn: 당신이 나갔던 위치는 안전하지 않았습니다, 당신을 윌드 스폰으로 텔레포트시킵니다 +not_logged_in: '&c로그인하지 않았습니다!' +reg_voluntarily: 당신이 서버에 게정을 등록하고 싶다면 "/register 비밀번호 비밀번호재입력"을 치세요 +usage_log: '&c사용법: /login 비밀번호' +wrong_pwd: '&c잘못된 비밀번호입니다' +unregistered: '&c성공적으로 회원탈퇴되었습니다!' +reg_disabled: '&c회원가입이 성공적으로 비활성화되었습니다' +valid_session: '&c세션 로그인' +login: '&c성공적으로 로그인 되었습니다!' +vb_nonActiv: 당신의 계정은 활성화되어 있지 않습니다 당신의 이메일을 체크해주세요! +user_regged: '&c사용자 이름은 이미 등록되어 있습니다' +usage_reg: '&c사용법: /register 비밀번호 비밀번호재입력' +max_reg: 당신은 가입할 수 있는 계정의 최대 한도 수를 넘었습니다 +no_perm: '&c권한이 없습니다' +error: 오류가 발생했습니다; 관리자한테 문의하세요 +login_msg: '&c로그인 하실려면 "/login 비밀번호"를 치세요' +reg_msg: '&c가입하실려면 "/register 비밀번호 비밀번호재입력"을 치세요' +reg_email_msg: '&c가입하실려면 "/register <이메일> <이메일재입력>을 치세요"' +usage_unreg: '&c사용법: /unregister 비밀번호' +pwd_changed: '&c비밀번호가 변경되었습니다!' +user_unknown: '&c사용자 이름은 등록되지 않았습니다' +password_error: 비밀번호가 일치하지 않습니다 +unvalid_session: 세션 데이터베이스가 일치하지 않습니다 세션이 끝날때 까지 기달려주세요 +reg_only: 회원가입은 플레이어만 할 수 있습니다! http://example.com 에 가입해주세요 +logged_in: '&c이미 로그인되어 있습니다!' +logout: '&c성공적으로 로그아웃되었습니다' +same_nick: 같은 닉네임이 이미 게임중입니다 +registered: '&c성공적으로 회원가입되었습니다!' +pass_len: 당신의 비밀번호는 최소 글자나 최대글자를 초과하였습니다 적당한 비밀번호 글자로 해주세요 +reload: 설정과 데이터베이스가 리로드되었습니다 +timeout: 로그인 시간 초과 +usage_changepassword: '사용법: /changepassword 기존비밀번호 새비밀번호' +name_len: '&c당신의 닉네임은 너무 길거나 짧습니다' +regex: '&c당신의 닉네임에 잘못된 문자가 포함되어 있습니다. 허용된 글자: REG_EX' +add_email: '&c당신의 이메일을 : /email add yourEmail confirmEmail 명령어로 추가해주세요' +bad_database_email: '[AuthMe] /email 명령어는 오직 MySQL 와 SQLite에서만 가능합니다, 관리자에게 문의해보세요' +recovery_email: '&c비밀번호를 잊어버리셨다고요? /email recovery <자신의이메일>을 사용해서 복구해보세요' +usage_captcha: '&c사용법: /captcha <캡차>' +wrong_captcha: '&c잘못된 캡차입니다, 올바른 사용법 : /captcha THE_CAPTCHA' +valid_captcha: '&c당신의 캡차는 올바릅니다 !' +kick_forvip: '&c한 VIP 플레이어가 만원인 서버에 입장했습니다!!' +kick_fullserver: '&c그 서버는 실제로 만원입니다, 미안!' +usage_email_add: '&f사용법: /email add <이메일> <이메일재입력> ' +usage_email_change: '&f사용법: /email change ' +usage_email_recovery: '&f사용법: /email recovery <이메일>' +new_email_invalid: '[AuthMe] 새 이메일이 잘못되었습니다!' +old_email_invalid: '[AuthMe] 기존 이메일이 잘못되었습니다!' +email_invalid: '[AuthMe] 이메일이 잘못되었습니다' +email_added: '[AuthMe] 이메일 추가됨 !' +email_confirm: '[AuthMe] 이메일을 확인해주세요 !' +email_changed: '[AuthMe] 이메일 변경됨 !' +email_send: '[AuthMe] 복구 이메일 발송됨 !' diff --git a/src/main/resources/messages_pl.yml b/src/main/resources/messages_pl.yml index a0297567..3175dcba 100644 --- a/src/main/resources/messages_pl.yml +++ b/src/main/resources/messages_pl.yml @@ -2,15 +2,15 @@ logged_in: '&fJestes juz zalogowany!' not_logged_in: '&4Nie jestes zalogowany!' reg_disabled: '&4Rejestracja jest wylaczona' user_regged: '&4Gracz juz jest zarejestrowany' -usage_reg: '&4Uzycie: /register haslo ponownie_haslo' +usage_reg: '&4Uzycie: /register haslo powtorzHaslo' usage_log: '&cUzycie: /login haslo' user_unknown: '&fGracz nie jest zarejestrowany' pwd_changed: '&fHaslo zostalo zmienione!' reg_only: '&fTylko zarejestrowani uzytkownicy maja do tego dostep!' valid_session: '&cSesja logowania' login_msg: '&2Prosze sie zalogowac przy uzyciu &6/login ' -reg_msg: '&2Prosze sie zarejestrowac przy uzyciu &6/register ' -reg_email_msg: '&cPlease register with "/register "' +reg_msg: '&2Prosze sie zarejestrowac przy uzyciu &6/register ' +reg_email_msg: '&cStworz prosze konto komenda "/register "' timeout: '&fUplynal limit czasu zalogowania' wrong_pwd: '&cNiepoprawne haslo' logout: '&cPomyslnie wylogowany' @@ -20,7 +20,7 @@ unregistered: '&4Pomyslnie odrejestrowany!' login: '&aHaslo zaakceptowane!' no_perm: '&4Nie masz uprawnien' same_nick: '&fTen nick juz gra' -reg_voluntarily: '&fMozesz zarejestrowac swoj nick na serwerze przy uzyciu "/register haslo ponownie_haslo"' +reg_voluntarily: '&fMozesz zarejestrowac swoj nick na serwerze przy uzyciu "/register haslo powtorzHaslo"' reload: '&fKonfiguracja bazy danych zostala przeladowana' error: '&fBlad prosimy napisac do aministracji' unknown_user: '&fUzytkownika nie ma w bazie danych' @@ -28,26 +28,26 @@ unsafe_spawn: '&fTwoje pozycja jest niebezpieczna. Zostaniesz przeniesiony na be unvalid_session: '&fSesja zakonczona!' max_reg: '&fPrzekroczyles limit zarejestrowanych kont na serwerze.' password_error: '&fHaslo niepoprawne!' -pass_len: '&fTwoje haslo jest za krotkie lub za dlugie! Sprobuj ponownie..' +pass_len: '&fTwoje haslo jest za krotkie lub za dlugie! Sprobuj ponownie...' vb_nonActiv: '&fTwoje konto nie zostalo aktywowane! Sprawdz maila.' usage_changepassword: '&fUzycie: /changepassword starehaslo nowehaslo' -name_len: '&cYour nickname is too Short or too long' -regex: '&cYour nickname contains illegal characters. Allowed chars: REG_EX' -add_email: '&cPlease add your email with : /email add yourEmail confirmEmail' -bad_database_email: '[AuthMe] This /email command only available with MySQL and SQLite, contact an Admin' -recovery_email: '&cForgot your password? Please use /email recovery ' -usage_captcha: '&cUsage: /captcha ' -wrong_captcha: '&cWrong Captcha, please use : /captcha THE_CAPTCHA' -valid_captcha: '&cYour captcha is valid !' -kick_forvip: '&cA VIP Player join the full server!' -kick_fullserver: '&cThe server is actually full, Sorry!' -usage_email_add: '&fUsage: /email add ' -usage_email_change: '&fUsage: /email change ' -usage_email_recovery: '&fUsage: /email recovery ' -new_email_invalid: '[AuthMe] New email invalid!' -old_email_invalid: '[AuthMe] Old email invalid!' -email_invalid: '[AuthMe] Invalid Email' -email_added: '[AuthMe] Email Added !' -email_confirm: '[AuthMe] Confirm your Email !' -email_changed: '[AuthMe] Email Change !' -email_send: '[AuthMe] Recovery Email Send !' +name_len: '&cTwoje konto ma za dluga badz za krotka nazwe' +regex: '&cTwoje konto ma w nazwie niedozwolone znaki. Dozwolone znaki: REG_EX' +add_email: '&cProsze dodac swoj email: /email add twojEmail powtorzEmail' +bad_database_email: '[AuthMe] Ta komenda /email dostepna jedynie z baza adnych MySQL lub SQLite, skontaktuj sie z Administratorem' +recovery_email: '&cZapomniales hasla? Prosze uzyj komendy /email recovery ' +usage_captcha: '&cWpisz: /captcha ' +wrong_captcha: '&cZly kod, prosze wpisac: /captcha THE_CAPTCHA' +valid_captcha: '&cTwoj kod jest nieprawidlowy!' +kick_forvip: '&cA Gracz VIP dolaczyl do gry!' +kick_fullserver: '&cSerwer jest teraz zapelniony, przepraszamy!' +usage_email_add: '&fWpisz: /email add ' +usage_email_change: '&fWpisz: /email change ' +usage_email_recovery: '&fWpisz: /email recovery ' +new_email_invalid: '[AuthMe] Nowy email niepoprawny!' +old_email_invalid: '[AuthMe] Stary email niepoprawny!' +email_invalid: '[AuthMe] Nieprawidlowy email' +email_added: '[AuthMe] Email dodany!' +email_confirm: '[AuthMe] Potwierdz swoj email!' +email_changed: '[AuthMe] Email zmieniony!' +email_send: '[AuthMe] Email z odzyskaniem wyslany!' diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 43328a2d..abfe7881 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-reloaded/ +website: http://dev.bukkit.org/bukkit-plugins/authme-recoded/ 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: uk.org.whoami.authme.AuthMe -version: 2.9.4 +main: fr.xephi.authme.AuthMe +version: 3.0 softdepend: [Vault, ChestShop, Spout, Multiverse-Core, Notifications, Citizens, CombatTag, Essentials, EssentialsSpawn] commands: register: diff --git a/src/main/resources/scripts/auth_db_to_mysql.pl b/src/main/resources/scripts/auth_db_to_mysql.pl deleted file mode 100644 index 11565e86..00000000 --- a/src/main/resources/scripts/auth_db_to_mysql.pl +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/perl - -use strict; -use warnings; -use DBI; - -############################## -# EDIT THESE CONFIG SETTINGS # -############################## - -my $host = "localhost"; -my $database = "authme"; -my $username = "authme"; -my $password = "password"; -my $auth_file = "/opt/craftbukkit/plugins/auths.db"; - -############################### -# DO NOT EDIT BELOW THIS LINE # -############################### - -open FILE, "$auth_file" or die $!; -my $dbh = DBI->connect("DBI:mysql:$database;host=$host", "$username", "$password") or die "Could not connect to database: $DBI::errstr"; - -$dbh->do('CREATE TABLE `authme` ( - `id` INTEGER AUTO_INCREMENT, - `username` VARCHAR(255) NOT NULL, - `password` VARCHAR(255) NOT NULL, - `ip` VARCHAR(40) NOT NULL, - `lastlogin` BIGINT, - CONSTRAINT `table_const_prim` PRIMARY KEY (`id`));'); - -my $st = 'INSERT INTO `authme` (`username`, `password`, `ip`, `lastlogin`) VALUES '; -my $i = 0; - -while() { - if($i == 1000) { - $i = 0; - $dbh->do($st); - $st = 'INSERT INTO `authme` (`username`, `password`, `ip`, `lastlogin`) VALUES '; - } - my @auth = split(':'); - - if($i != 0) { - $st .= ", "; - } - - $st .= "(\"$auth[0]\", \"$auth[1]\", "; - $st .= "\"" . ($auth[2] || '198.18.0.1') . "\", "; - $st .= ($auth[3] || '0') . ")"; - $i++; -} - -if($i > 0) { - $dbh->do($st); -} - -$dbh->disconnect(); -close FILE; -