AuthMe 3.0

//Changes 3.0://
* Repackaging from uk.org.whoami.authme to fr.xephi.authme, please
developpers, update!
* Rewrite some of parts of the plugin
* Some code was already perfect , also did not change it :p
* Full support for phpbb3
* Add full support for WordPress + passwordHash: WORDPRESS
* Completely rewrite Management system for inventories and tp issues,
Thanks to : [[http://dev.bukkit.org/profiles/Possible/|Possible]]
* Rework on /passpartu command
* Completely rewrite the password encryption method
* Add a way for developers to add their own Password Encryption Method
on AuthMe via event way (please see
fr.xephi.authme.events.PasswordEncryptionEvent)
* Add an auto purge with players.dat removing method and essentials
files removing ( if you want authme to hook with an another plugin let
me know )
* Complete Hook with BungeeCord by removing the /server command before
login
* message_lang.yml will never be overwritten with English Strings , but
correctly update the message_lang.yml when needed to
* Fix a lot of issues mentioned in tickets , commants , or by mp, Thanks
for all your reports!
This commit is contained in:
Xephi 2013-10-17 05:14:46 +02:00
parent e6467eccf2
commit 10b4eaeca7
112 changed files with 3142 additions and 2640 deletions

View File

@ -1,6 +1,6 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>uk.org.whoami.authme.AuthMe</groupId> <groupId>fr.xephi.authme.AuthMe</groupId>
<artifactId>AuthMe</artifactId> <artifactId>AuthMe</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>AuthMe</name> <name>AuthMe</name>
@ -24,12 +24,12 @@
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
<version>2.9.4</version> <version>3.0</version>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.bukkit</groupId> <groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId> <artifactId>bukkit</artifactId>
<version>1.6.2-R1.0</version> <version>1.6.4-R0.1-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.milkbowl.vault</groupId> <groupId>net.milkbowl.vault</groupId>

View File

@ -1,25 +1,6 @@
/* package fr.xephi.authme;
* Copyright 2011 Sebastian Köhler <sebkoehler@whoami.org.uk>.
*
* 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;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -34,40 +15,6 @@ import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin; 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 me.muizers.Notifications.Notifications;
import net.citizensnpcs.Citizens; import net.citizensnpcs.Citizens;
@ -76,11 +23,47 @@ import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.World;
import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.MultiverseCore;
import uk.org.whoami.authme.commands.PasspartuCommand; import fr.xephi.authme.api.API;
import uk.org.whoami.authme.datasource.SqliteDataSource; 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 { public class AuthMe extends JavaPlugin {
@ -108,8 +91,7 @@ public class AuthMe extends JavaPlugin {
public HashMap<String, Integer> captcha = new HashMap<String, Integer>(); public HashMap<String, Integer> captcha = new HashMap<String, Integer>();
public HashMap<String, String> cap = new HashMap<String, String>(); public HashMap<String, String> cap = new HashMap<String, String>();
public HashMap<String, String> realIp = new HashMap<String, String>(); public HashMap<String, String> realIp = new HashMap<String, String>();
public List<String> premium = new ArrayList<String>(); public MultiverseCore multiverse = null;
public MultiverseCore mv = null;
public Location essentialsSpawn; public Location essentialsSpawn;
public Thread databaseThread = null; public Thread databaseThread = null;
@ -177,7 +159,7 @@ public class AuthMe extends JavaPlugin {
} }
try { try {
database = new FileDataSource(); database = new FileDataSource();
} catch (IOException ex) { } catch (Exception ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
if (Settings.isStopEnabled) { if (Settings.isStopEnabled) {
ConsoleLogger.showError("Can't use FLAT FILE... SHUTDOWN..."); ConsoleLogger.showError("Can't use FLAT FILE... SHUTDOWN...");
@ -198,25 +180,7 @@ public class AuthMe extends JavaPlugin {
} }
try { try {
database = new MySQLDataSource(); 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...");
server.shutdown();
}
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()); ConsoleLogger.showError(ex.getMessage());
if (Settings.isStopEnabled) { if (Settings.isStopEnabled) {
ConsoleLogger.showError("Can't use MySQL... Please input correct MySQL informations ! SHUTDOWN..."); ConsoleLogger.showError("Can't use MySQL... Please input correct MySQL informations ! SHUTDOWN...");
@ -237,16 +201,7 @@ public class AuthMe extends JavaPlugin {
} }
try { try {
database = new SqliteDataSource(); database = new SqliteDataSource();
} catch (ClassNotFoundException ex) { } catch (Exception 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) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
if (Settings.isStopEnabled) { if (Settings.isStopEnabled) {
ConsoleLogger.showError("Can't use SQLITE... ! SHUTDOWN..."); ConsoleLogger.showError("Can't use SQLITE... ! SHUTDOWN...");
@ -328,6 +283,8 @@ public class AuthMe extends JavaPlugin {
} }
} catch (NullPointerException ex) { } catch (NullPointerException ex) {
} }
if (Settings.usePurge)
autoPurge();
ConsoleLogger.info("Authme " + this.getDescription().getVersion() + " enabled"); ConsoleLogger.info("Authme " + this.getDescription().getVersion() + " enabled");
} }
@ -365,19 +322,19 @@ public class AuthMe extends JavaPlugin {
private void checkMultiverse() { private void checkMultiverse() {
if(!Settings.multiverse) { if(!Settings.multiverse) {
mv = null; multiverse = null;
return; return;
} }
if (this.getServer().getPluginManager().getPlugin("Multiverse-Core") != null && this.getServer().getPluginManager().getPlugin("Multiverse-Core").isEnabled()) { if (this.getServer().getPluginManager().getPlugin("Multiverse-Core") != null && this.getServer().getPluginManager().getPlugin("Multiverse-Core").isEnabled()) {
try { 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"); ConsoleLogger.info("Hook with Multiverse-Core for SpawnLocations");
} catch (NullPointerException npe) { } catch (NullPointerException npe) {
mv = null; multiverse = null;
} catch (ClassCastException cce) { } catch (ClassCastException cce) {
mv = null; multiverse = null;
} catch (NoClassDefFoundError ncdfe) { } catch (NoClassDefFoundError ncdfe) {
mv = null; multiverse = null;
} }
} }
} }
@ -580,4 +537,64 @@ public class AuthMe extends JavaPlugin {
return false; return false;
} }
private void autoPurge() {
if (!Settings.usePurge) {
return;
}
long days = Settings.purgeDelay * 86400000;
long until = new Date().getTime() - days;
List<String> 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<String> 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<String> 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;
}
} }

View File

@ -1,4 +1,4 @@
package uk.org.whoami.authme; package fr.xephi.authme;
import java.util.logging.Filter; import java.util.logging.Filter;
import java.util.logging.LogRecord; import java.util.logging.LogRecord;

View File

@ -1,20 +1,4 @@
/* package fr.xephi.authme;
* Copyright 2011 Sebastian Köhler <sebkoehler@whoami.org.uk>.
*
* 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;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.File; import java.io.File;
@ -26,7 +10,8 @@ import java.util.logging.Logger;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import uk.org.whoami.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
public class ConsoleLogger { public class ConsoleLogger {

View File

@ -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, <a href="http://dev.bukkit.org/profiles/Possible/">Possible</a>
*
*/
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<String> 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);
}
}
}
}

View File

@ -1,8 +1,4 @@
/* package fr.xephi.authme;
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package uk.org.whoami.authme;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -12,7 +8,8 @@ import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import uk.org.whoami.authme.settings.Settings;
import fr.xephi.authme.settings.Settings;
/** /**
* *

View File

@ -1,4 +1,4 @@
package uk.org.whoami.authme; package fr.xephi.authme;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.Date; import java.util.Date;
@ -13,8 +13,8 @@ import javax.mail.internet.MimeMessage;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import uk.org.whoami.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import uk.org.whoami.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
/** /**
* *

View File

@ -1,4 +1,4 @@
package uk.org.whoami.authme; package fr.xephi.authme;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
@ -10,20 +10,16 @@ import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitTask;
import uk.org.whoami.authme.events.AuthMeTeleportEvent; import fr.xephi.authme.api.API;
import uk.org.whoami.authme.settings.Settings; import fr.xephi.authme.events.AuthMeTeleportEvent;
import fr.xephi.authme.settings.Settings;
/**
*
* @author stefano
*/
public class Utils { public class Utils {
private String currentGroup; private String currentGroup;
private static Utils singleton; private static Utils singleton;
private String unLoggedGroup = Settings.getUnloggedinGroup; private String unLoggedGroup = Settings.getUnloggedinGroup;
BukkitTask id; int id;
public void setGroup(Player player, groupType group) { public void setGroup(Player player, groupType group) {
if (!player.isOnline()) if (!player.isOnline())
@ -49,7 +45,6 @@ public class Utils {
} }
public String removeAll(Player player) { public String removeAll(Player player) {
if(!Utils.getInstance().useGroupSystem()){ if(!Utils.getInstance().useGroupSystem()){
return null; return null;
} }
@ -64,7 +59,7 @@ public class Utils {
} }
public boolean addNormal(Player player, String group) { public boolean addNormal(Player player, String group) {
if(!Utils.getInstance().useGroupSystem()){ if(!Utils.getInstance().useGroupSystem()){
return false; return false;
} }
if(AuthMe.permission.playerRemoveGroup(player.getWorld(),player.getName().toString(),this.unLoggedGroup) && AuthMe.permission.playerAddGroup(player.getWorld(),player.getName().toString(),group)) { if(AuthMe.permission.playerRemoveGroup(player.getWorld(),player.getName().toString(),this.unLoggedGroup) && AuthMe.permission.playerAddGroup(player.getWorld(),player.getName().toString(),group)) {
@ -74,7 +69,6 @@ public class Utils {
} }
private String hasPermOnJoin(Player player) { private String hasPermOnJoin(Player player) {
Iterator<String> iter = Settings.getJoinPermissions.iterator(); Iterator<String> iter = Settings.getJoinPermissions.iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
String permission = iter.next(); String permission = iter.next();
@ -86,25 +80,19 @@ public class Utils {
} }
public boolean isUnrestricted(Player player) { public boolean isUnrestricted(Player player) {
if(Settings.getUnrestrictedName.isEmpty() || Settings.getUnrestrictedName == null) if(Settings.getUnrestrictedName.isEmpty() || Settings.getUnrestrictedName == null)
return false; return false;
if(Settings.getUnrestrictedName.contains(player.getName())) if(Settings.getUnrestrictedName.contains(player.getName()))
return true; return true;
return false; return false;
} }
public static Utils getInstance() { public static Utils getInstance() {
singleton = new Utils(); singleton = new Utils();
return singleton; return singleton;
} }
private boolean useGroupSystem() { private boolean useGroupSystem() {
if(Settings.isPermissionCheckEnabled && !Settings.getUnloggedinGroup.isEmpty()) { if(Settings.isPermissionCheckEnabled && !Settings.getUnloggedinGroup.isEmpty()) {
return true; return true;
} return false; } return false;
@ -122,7 +110,7 @@ public class Utils {
theWorld = pl.getWorld(); theWorld = pl.getWorld();
final World world = theWorld; final World world = theWorld;
final int fY = y; 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(); final Location loc = locat.getBlock().getLocation();
Bukkit.getScheduler().scheduleSyncDelayedTask(AuthMe.getInstance(), new Runnable() { 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 @Override
public void run() { public void run() {
@ -149,12 +137,12 @@ public class Utils {
} }
} }
}, 1L, 20L); }, 1L, 20L);
Bukkit.getScheduler().scheduleSyncDelayedTask(AuthMe.authme, new Runnable() Bukkit.getScheduler().scheduleSyncDelayedTask(AuthMe.getInstance(), new Runnable()
{ {
@Override @Override
public void run() { public void run() {
id.cancel(); Bukkit.getScheduler().cancelTask(id);
} }
}, 60L); }, 60L);
} }
@ -163,37 +151,36 @@ public class Utils {
* *
*/ */
public boolean obtainToken() { public boolean obtainToken() {
File file = new File("plugins/AuthMe/passpartu.token"); File file = new File("plugins/AuthMe/passpartu.token");
if (file.exists())
if (file.exists()) file.delete();
file.delete();
FileWriter writer = null; FileWriter writer = null;
try { try {
file.createNewFile(); file.createNewFile();
writer = new FileWriter(file); writer = new FileWriter(file);
String token = generateToken(); String token = generateToken();
writer.write(token+":"+System.currentTimeMillis()/1000+"\r\n"); writer.write(token + ":" + System.currentTimeMillis() / 1000 + API.newline);
writer.flush(); writer.flush();
ConsoleLogger.info("[AuthMe] Security passpartu token: "+ token); ConsoleLogger.info("[AuthMe] Security passpartu token: "+ token);
writer.close(); writer.close();
return true; return true;
} catch(Exception e) { } catch(Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return false; return false;
} }
/* /*
* Read Toekn * Read Token
*/ */
public boolean readToken(String inputToken) { public boolean readToken(String inputToken) {
File file = new File("plugins/AuthMe/passpartu.token"); File file = new File("plugins/AuthMe/passpartu.token");
if (!file.exists()) if (!file.exists())
return false; return false;
if (inputToken.isEmpty() ) if (inputToken.isEmpty())
return false; return false;
Scanner reader = null; Scanner reader = null;
try { try {
@ -201,33 +188,34 @@ public class Utils {
while (reader.hasNextLine()) { while (reader.hasNextLine()) {
final String line = reader.nextLine(); final String line = reader.nextLine();
if (line.contains(":")) { if (line.contains(":")) {
String[] tokenInfo = line.split(":"); String[] tokenInfo = line.split(":");
if(tokenInfo[0].equals(inputToken) && System.currentTimeMillis()/1000-30 <= Integer.parseInt(tokenInfo[1]) ) { if(tokenInfo[0].equals(inputToken) && System.currentTimeMillis()/1000-30 <= Integer.parseInt(tokenInfo[1]) ) {
file.delete(); file.delete();
reader.close(); reader.close();
return true; return true;
} }
} }
} }
} catch(Exception e) { } catch(Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
reader.close(); reader.close();
return false; return false;
} }
/* /*
* Generate Random Token * Generate Random Token
*/ */
private String generateToken() { private String generateToken() {
// obtain new random token // obtain new random token
Random rnd = new Random (); Random rnd = new Random ();
char[] arr = new char[5]; char[] arr = new char[5];
for (int i=0; i<5; i++) { for (int i=0; i<5; i++) {
int n = rnd.nextInt (36); int n = rnd.nextInt (36);
arr[i] = (char) (n < 10 ? '0'+n : 'a'+n-10); arr[i] = (char) (n < 10 ? '0'+n : 'a'+n-10);
} }
return new String(arr); return new String(arr);
} }
public enum groupType { public enum groupType {
UNREGISTERED, REGISTERED, NOTLOGGEDIN, LOGGEDIN UNREGISTERED, REGISTERED, NOTLOGGEDIN, LOGGEDIN

View File

@ -1,4 +1,4 @@
package uk.org.whoami.authme.api; package fr.xephi.authme.api;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -7,17 +7,19 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import uk.org.whoami.authme.AuthMe; import fr.xephi.authme.AuthMe;
import uk.org.whoami.authme.Utils; import fr.xephi.authme.Utils;
import uk.org.whoami.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import uk.org.whoami.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerCache;
import uk.org.whoami.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
import uk.org.whoami.authme.plugin.manager.CombatTagComunicator; import fr.xephi.authme.plugin.manager.CombatTagComunicator;
import uk.org.whoami.authme.security.PasswordSecurity; import fr.xephi.authme.security.PasswordSecurity;
import uk.org.whoami.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
public class API { public class API {
public static final String newline = System.getProperty("line.separator");
public static AuthMe instance; public static AuthMe instance;
public static DataSource database; public static DataSource database;

View File

@ -1,23 +1,7 @@
/* package fr.xephi.authme.cache.auth;
* Copyright 2011 Sebastian Köhler <sebkoehler@whoami.org.uk>.
*
* 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; import fr.xephi.authme.security.HashAlgorithm;
import fr.xephi.authme.settings.Settings;
import uk.org.whoami.authme.security.PasswordSecurity;
import uk.org.whoami.authme.settings.Settings;
public class PlayerAuth { public class PlayerAuth {
@ -134,7 +118,7 @@ public class PlayerAuth {
} }
public String getHash() { public String getHash() {
if(!salt.isEmpty() && Settings.getPasswordHash == PasswordSecurity.HashAlgorithm.MD5VB) { if(!salt.isEmpty() && Settings.getPasswordHash == HashAlgorithm.MD5VB) {
vBhash = "$MD5vb$"+salt+"$"+hash; vBhash = "$MD5vb$"+salt+"$"+hash;
return vBhash; return vBhash;
} }

View File

@ -1,20 +1,4 @@
/* package fr.xephi.authme.cache.auth;
* Copyright 2011 Sebastian Köhler <sebkoehler@whoami.org.uk>.
*
* 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;
import java.util.HashMap; import java.util.HashMap;

View File

@ -1,13 +1,5 @@
/* package fr.xephi.authme.cache.backup;
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package uk.org.whoami.authme.cache.backup;
/**
*
* @author stefano
*/
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
public class DataFileCache { public class DataFileCache {

View File

@ -1,13 +1,5 @@
/* package fr.xephi.authme.cache.backup;
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package uk.org.whoami.authme.cache.backup;
/**
*
* @author stefano
*/
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
@ -15,6 +7,8 @@ import java.util.Scanner;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import fr.xephi.authme.api.API;
public class FileCache { public class FileCache {
public FileCache() { public FileCache() {
@ -45,8 +39,8 @@ public class FileCache {
// line format Group|OperatorStatus|isFlying // line format Group|OperatorStatus|isFlying
if(flying) if(flying)
writer.write(s+";1\r\n"); writer.write(s+";1" + API.newline);
else writer.write(s+";0\r\n"); else writer.write(s+";0" + API.newline);
writer.flush(); writer.flush();
ItemStack[] invstack = playerData.getInventory(); ItemStack[] invstack = playerData.getInventory();

View File

@ -1,20 +1,4 @@
/* package fr.xephi.authme.cache.limbo;
* Copyright 2011 Sebastian Köhler <sebkoehler@whoami.org.uk>.
*
* 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;
import java.util.HashMap; import java.util.HashMap;
@ -23,17 +7,18 @@ import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import uk.org.whoami.authme.AuthMe; import fr.xephi.authme.AuthMe;
import uk.org.whoami.authme.cache.backup.FileCache; import fr.xephi.authme.api.API;
import uk.org.whoami.authme.events.ResetInventoryEvent; import fr.xephi.authme.cache.backup.FileCache;
import uk.org.whoami.authme.events.StoreInventoryEvent; import fr.xephi.authme.events.ResetInventoryEvent;
import uk.org.whoami.authme.settings.Settings; import fr.xephi.authme.events.StoreInventoryEvent;
import uk.org.whoami.authme.settings.Spawn; import fr.xephi.authme.settings.Settings;
public class LimboCache { public class LimboCache {
private static LimboCache singleton = null; private static LimboCache singleton = null;
private HashMap<String, LimboPlayer> cache; public HashMap<String, LimboPlayer> cache;
private FileCache playerData = new FileCache(); private FileCache playerData = new FileCache();
public AuthMe plugin; public AuthMe plugin;
@ -88,21 +73,14 @@ public class LimboCache {
ResetInventoryEvent event = new ResetInventoryEvent(player); ResetInventoryEvent event = new ResetInventoryEvent(player);
Bukkit.getServer().getPluginManager().callEvent(event); Bukkit.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) { if (!event.isCancelled()) {
API.setPlayerInventory(player, new ItemStack[36], new ItemStack[4]);
player.sendMessage("Your inventory has been cleaned!"); player.sendMessage("Your inventory has been cleaned!");
} }
} }
gameMode = 0; gameMode = 0;
} }
if(player.isDead()) { if(player.isDead()) {
loc = player.getWorld().getSpawnLocation(); loc = plugin.getSpawnLocation(player.getWorld());
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();
} }
try { try {
if(cache.containsKey(name) && playerGroup.isEmpty()) { if(cache.containsKey(name) && playerGroup.isEmpty()) {

View File

@ -1,20 +1,4 @@
/* package fr.xephi.authme.cache.limbo;
* Copyright 2011 Sebastian Köhler <sebkoehler@whoami.org.uk>.
*
* 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;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -73,6 +57,14 @@ public class LimboPlayer {
return inventory; return inventory;
} }
public void setArmour(ItemStack[] armour) {
this.armour = armour;
}
public void setInventory(ItemStack[] inventory) {
this.inventory = inventory;
}
public int getGameMode() { public int getGameMode() {
return gameMode; return gameMode;
} }

View File

@ -1,20 +1,4 @@
/* package fr.xephi.authme.commands;
* Copyright 2011 Sebastian Köhler <sebkoehler@whoami.org.uk>.
*
* 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;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -38,21 +22,22 @@ import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import uk.org.whoami.authme.AuthMe; import fr.xephi.authme.AuthMe;
import uk.org.whoami.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import uk.org.whoami.authme.Utils; import fr.xephi.authme.Utils;
import uk.org.whoami.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import uk.org.whoami.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerCache;
import uk.org.whoami.authme.converter.FlatToSql; import fr.xephi.authme.converter.FlatToSql;
import uk.org.whoami.authme.converter.FlatToSqlite; import fr.xephi.authme.converter.FlatToSqlite;
import uk.org.whoami.authme.converter.RakamakConverter; import fr.xephi.authme.converter.RakamakConverter;
import uk.org.whoami.authme.converter.xAuthToFlat; import fr.xephi.authme.converter.xAuthToFlat;
import uk.org.whoami.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
import uk.org.whoami.authme.security.PasswordSecurity; import fr.xephi.authme.security.PasswordSecurity;
import uk.org.whoami.authme.settings.Messages; import fr.xephi.authme.settings.Messages;
import uk.org.whoami.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import uk.org.whoami.authme.settings.Spawn; import fr.xephi.authme.settings.Spawn;
import uk.org.whoami.authme.settings.SpoutCfg; import fr.xephi.authme.settings.SpoutCfg;
public class AdminCommand implements CommandExecutor { public class AdminCommand implements CommandExecutor {
@ -76,12 +61,17 @@ public class AdminCommand implements CommandExecutor {
sender.sendMessage("/authme purge <days> - Purge Database"); sender.sendMessage("/authme purge <days> - Purge Database");
sender.sendMessage("/authme version - Get AuthMe version infos"); sender.sendMessage("/authme version - Get AuthMe version infos");
sender.sendMessage("/authme lastlogin <playername> - Display Date about the Player's LastLogin"); sender.sendMessage("/authme lastlogin <playername> - Display Date about the Player's LastLogin");
sender.sendMessage("/authme accounts <playername> - 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 <playername> <email> - Change player email");
sender.sendMessage("/authme getemail <playername> - Get player email");
return true; return true;
} }
if((sender instanceof ConsoleCommandSender) && args[0].equalsIgnoreCase("passpartuToken")) { if((sender instanceof ConsoleCommandSender) && args[0].equalsIgnoreCase("passpartuToken")) {
if(args.length > 1) { if(args.length > 1) {
System.out.println("[AuthMe] command usage: authme passpartuToken"); System.out.println("[AuthMe] command usage: /authme passpartuToken");
return true; return true;
} }
if(Utils.getInstance().obtainToken()) { if(Utils.getInstance().obtainToken()) {
@ -146,8 +136,8 @@ public class AdminCommand implements CommandExecutor {
} }
YamlConfiguration newConfig = YamlConfiguration.loadConfiguration(newConfigFile); YamlConfiguration newConfig = YamlConfiguration.loadConfiguration(newConfigFile);
Settings.reloadConfigOptions(newConfig); Settings.reloadConfigOptions(newConfig);
m.reload(); m.reLoad();
s.reload(); s.reLoad();
sender.sendMessage(m._("reload")); sender.sendMessage(m._("reload"));
} else if (args[0].equalsIgnoreCase("lastlogin")) { } else if (args[0].equalsIgnoreCase("lastlogin")) {
if (args.length != 2) { 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] " + args[1].toLowerCase() + " lastlogin : " + d.toString());
sender.sendMessage("[AuthMe] The player : " + player.getNickname() + " is unlogged since " + msg); sender.sendMessage("[AuthMe] The player : " + player.getNickname() + " is unlogged since " + msg);
sender.sendMessage("[AuthMe] LastPlayer IP : " + lastIP); sender.sendMessage("[AuthMe] LastPlayer IP : " + lastIP);
} else {
sender.sendMessage("This player does not exist");
return true;
} }
} catch (NullPointerException e) { } catch (NullPointerException e) {
sender.sendMessage("This player does not exist"); sender.sendMessage("This player does not exist");
return true;
} }
} else if (args[0].equalsIgnoreCase("accounts")) { } else if (args[0].equalsIgnoreCase("accounts")) {
if (args.length != 2) { if (args.length != 2) {
@ -268,10 +262,12 @@ public class AdminCommand implements CommandExecutor {
return true; return true;
} }
PlayerAuth auth = new PlayerAuth(name, hash, "198.18.0.1", 0); PlayerAuth auth = new PlayerAuth(name, hash, "198.18.0.1", 0);
auth.setSalt(PasswordSecurity.userSalt.get(name));
if (!database.saveAuth(auth)) { if (!database.saveAuth(auth)) {
sender.sendMessage(m._("error")); sender.sendMessage(m._("error"));
return true; return true;
} }
database.updateSalt(auth);
sender.sendMessage(m._("registered")); sender.sendMessage(m._("registered"));
ConsoleLogger.info(args[1] + " registered"); ConsoleLogger.info(args[1] + " registered");
} catch (NoSuchAlgorithmException ex) { } catch (NoSuchAlgorithmException ex) {
@ -311,7 +307,11 @@ public class AdminCommand implements CommandExecutor {
return true; return true;
} }
String playername = args[1].toLowerCase(); 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()); sender.sendMessage("[AuthMe] " + args[1] + " email : " + getAuth.getEmail());
return true; return true;
} else if (args[0].equalsIgnoreCase("chgemail")) { } else if (args[0].equalsIgnoreCase("chgemail")) {
@ -320,13 +320,18 @@ public class AdminCommand implements CommandExecutor {
return true; return true;
} }
String playername = args[1].toLowerCase(); 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]); getAuth.setEmail(args[2]);
if (!database.updateEmail(getAuth)) { if (!database.updateEmail(getAuth)) {
sender.sendMessage(m._("error")); sender.sendMessage(m._("error"));
return true; return true;
} }
PlayerCache.getInstance().updatePlayer(getAuth); if (PlayerCache.getInstance().getAuth(playername) != null)
PlayerCache.getInstance().updatePlayer(getAuth);
return true; return true;
} else if (args[0].equalsIgnoreCase("convertfromrakamak")) { } else if (args[0].equalsIgnoreCase("convertfromrakamak")) {
try { try {
@ -396,10 +401,12 @@ public class AdminCommand implements CommandExecutor {
return true; return true;
} }
auth.setHash(hash); auth.setHash(hash);
auth.setSalt(PasswordSecurity.userSalt.get(name));
if (!database.updatePassword(auth)) { if (!database.updatePassword(auth)) {
sender.sendMessage(m._("error")); sender.sendMessage(m._("error"));
return true; return true;
} }
database.updateSalt(auth);
sender.sendMessage("pwd_changed"); sender.sendMessage("pwd_changed");
ConsoleLogger.info(args[1] + "'s password changed"); ConsoleLogger.info(args[1] + "'s password changed");
} catch (NoSuchAlgorithmException ex) { } catch (NoSuchAlgorithmException ex) {

View File

@ -1,15 +1,16 @@
package uk.org.whoami.authme.commands; package fr.xephi.authme.commands;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import uk.org.whoami.authme.AuthMe; import fr.xephi.authme.AuthMe;
import uk.org.whoami.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerCache;
import uk.org.whoami.authme.security.RandomString; import fr.xephi.authme.security.RandomString;
import uk.org.whoami.authme.settings.Messages; import fr.xephi.authme.settings.Messages;
import uk.org.whoami.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
public class CaptchaCommand implements CommandExecutor { public class CaptchaCommand implements CommandExecutor {

View File

@ -1,20 +1,4 @@
/* package fr.xephi.authme.commands;
* Copyright 2011 Sebastian Köhler <sebkoehler@whoami.org.uk>.
*
* 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;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
@ -25,14 +9,15 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import uk.org.whoami.authme.AuthMe; import fr.xephi.authme.AuthMe;
import uk.org.whoami.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import uk.org.whoami.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import uk.org.whoami.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerCache;
import uk.org.whoami.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
import uk.org.whoami.authme.security.PasswordSecurity; import fr.xephi.authme.security.PasswordSecurity;
import uk.org.whoami.authme.settings.Messages; import fr.xephi.authme.settings.Messages;
import uk.org.whoami.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
public class ChangePasswordCommand implements CommandExecutor { 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)) { if (PasswordSecurity.comparePasswordWithHash(args[0], PlayerCache.getInstance().getAuth(name).getHash(), name)) {
PlayerAuth auth = PlayerCache.getInstance().getAuth(name); PlayerAuth auth = PlayerCache.getInstance().getAuth(name);
auth.setHash(hashnew); auth.setHash(hashnew);
auth.setSalt(PasswordSecurity.userSalt.get(name));
if (!database.updatePassword(auth)) { if (!database.updatePassword(auth)) {
player.sendMessage(m._("error")); player.sendMessage(m._("error"));
return true; return true;
} }
database.updateSalt(auth);
PlayerCache.getInstance().updatePlayer(auth); PlayerCache.getInstance().updatePlayer(auth);
player.sendMessage(m._("pwd_changed")); player.sendMessage(m._("pwd_changed"));
ConsoleLogger.info(player.getName() + " changed his password"); ConsoleLogger.info(player.getName() + " changed his password");

View File

@ -1,19 +1,4 @@
/* package fr.xephi.authme.commands;
* 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;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
@ -22,15 +7,16 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import uk.org.whoami.authme.AuthMe;
import uk.org.whoami.authme.ConsoleLogger; import fr.xephi.authme.AuthMe;
import uk.org.whoami.authme.cache.auth.PlayerAuth; import fr.xephi.authme.ConsoleLogger;
import uk.org.whoami.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerAuth;
import uk.org.whoami.authme.datasource.DataSource; import fr.xephi.authme.cache.auth.PlayerCache;
import uk.org.whoami.authme.security.PasswordSecurity; import fr.xephi.authme.datasource.DataSource;
import uk.org.whoami.authme.security.RandomString; import fr.xephi.authme.security.PasswordSecurity;
import uk.org.whoami.authme.settings.Messages; import fr.xephi.authme.security.RandomString;
import uk.org.whoami.authme.settings.Settings; 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)) { if(args[1].equals(args[2]) && PlayerCache.getInstance().isAuthenticated(name)) {
PlayerAuth auth = PlayerCache.getInstance().getAuth(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"); player.sendMessage("usage_email_change");
return true; return true;
} }
@ -103,7 +89,7 @@ public class EmailCommand implements CommandExecutor {
} else if(args[0].equalsIgnoreCase("change") && args.length == 3 ) { } else if(args[0].equalsIgnoreCase("change") && args.length == 3 ) {
if(PlayerCache.getInstance().isAuthenticated(name)) { if(PlayerCache.getInstance().isAuthenticated(name)) {
PlayerAuth auth = PlayerCache.getInstance().getAuth(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")); player.sendMessage(m._("usage_email_add"));
return true; return true;
} }
@ -140,7 +126,6 @@ public class EmailCommand implements CommandExecutor {
} }
if (plugin.mail == null) { if (plugin.mail == null) {
player.sendMessage(m._("error")); player.sendMessage(m._("error"));
ConsoleLogger.info("Missed mail.jar in lib folder");
return true; return true;
} }
if (data.isAuthAvailable(name)) { if (data.isAuthAvailable(name)) {

View File

@ -1,28 +1,13 @@
/* package fr.xephi.authme.commands;
* Copyright 2011 Sebastian Köhler <sebkoehler@whoami.org.uk>.
*
* 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;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import uk.org.whoami.authme.AuthMe; import fr.xephi.authme.AuthMe;
import uk.org.whoami.authme.settings.Messages; import fr.xephi.authme.settings.Messages;
public class LoginCommand implements CommandExecutor { public class LoginCommand implements CommandExecutor {

View File

@ -1,20 +1,4 @@
/* package fr.xephi.authme.commands;
* Copyright 2011 Sebastian Köhler <sebkoehler@whoami.org.uk>.
*
* 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;
import me.muizers.Notifications.Notification; import me.muizers.Notifications.Notification;
@ -27,22 +11,23 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitScheduler; import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import uk.org.whoami.authme.AuthMe; import fr.xephi.authme.AuthMe;
import uk.org.whoami.authme.Utils; import fr.xephi.authme.ConsoleLogger;
import uk.org.whoami.authme.ConsoleLogger; import fr.xephi.authme.Utils;
import uk.org.whoami.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import uk.org.whoami.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerCache;
import uk.org.whoami.authme.cache.backup.DataFileCache; import fr.xephi.authme.cache.backup.DataFileCache;
import uk.org.whoami.authme.cache.backup.FileCache; import fr.xephi.authme.cache.backup.FileCache;
import uk.org.whoami.authme.cache.limbo.LimboCache; import fr.xephi.authme.cache.limbo.LimboCache;
import uk.org.whoami.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
import uk.org.whoami.authme.events.AuthMeTeleportEvent; import fr.xephi.authme.events.AuthMeTeleportEvent;
import uk.org.whoami.authme.settings.Messages; import fr.xephi.authme.settings.Messages;
import uk.org.whoami.authme.settings.PlayersLogs; import fr.xephi.authme.settings.PlayersLogs;
import uk.org.whoami.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import uk.org.whoami.authme.settings.Spawn; import fr.xephi.authme.settings.Spawn;
import uk.org.whoami.authme.task.MessageTask; import fr.xephi.authme.task.MessageTask;
import uk.org.whoami.authme.task.TimeoutTask; import fr.xephi.authme.task.TimeoutTask;
public class LogoutCommand implements CommandExecutor { 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)); BukkitTask msgT = sched.runTask(plugin, new MessageTask(plugin, name, m._("login_msg"), interval));
LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT.getTaskId()); LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT.getTaskId());
try { try {
if (PlayersLogs.players.contains(player.getName())) { if (PlayersLogs.players.contains(player.getName())) {
PlayersLogs.players.remove(player.getName()); PlayersLogs.players.remove(player.getName());
pllog.save(); pllog.save();
} }
if (player.isInsideVehicle())
player.getVehicle().eject();
} catch (NullPointerException npe) { } catch (NullPointerException npe) {
} }
player.sendMessage(m._("logout")); player.sendMessage(m._("logout"));

View File

@ -1,18 +1,15 @@
/* package fr.xephi.authme.commands;
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package uk.org.whoami.authme.commands;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import uk.org.whoami.authme.AuthMe; import fr.xephi.authme.AuthMe;
import uk.org.whoami.authme.Utils; import fr.xephi.authme.Utils;
import uk.org.whoami.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerCache;
import uk.org.whoami.authme.settings.Messages; import fr.xephi.authme.settings.Messages;
/** /**
* *
@ -30,7 +27,7 @@ public class PasspartuCommand implements CommandExecutor {
@Override @Override
public boolean onCommand(CommandSender sender, Command cmnd, String label, String[] args) { 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")); sender.sendMessage(m._("no_perm"));
return true; return true;
} }

View File

@ -1,20 +1,4 @@
/* package fr.xephi.authme.commands;
* Copyright 2011 Sebastian Köhler <sebkoehler@whoami.org.uk>.
*
* 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;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.Date; import java.util.Date;
@ -31,23 +15,23 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import uk.org.whoami.authme.AuthMe; import fr.xephi.authme.AuthMe;
import uk.org.whoami.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import uk.org.whoami.authme.Utils; import fr.xephi.authme.Utils;
import uk.org.whoami.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import uk.org.whoami.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerCache;
import uk.org.whoami.authme.cache.limbo.LimboCache; import fr.xephi.authme.cache.limbo.LimboCache;
import uk.org.whoami.authme.cache.limbo.LimboPlayer; import fr.xephi.authme.cache.limbo.LimboPlayer;
import uk.org.whoami.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
import uk.org.whoami.authme.events.RegisterTeleportEvent; import fr.xephi.authme.events.RegisterTeleportEvent;
import uk.org.whoami.authme.security.PasswordSecurity; import fr.xephi.authme.security.PasswordSecurity;
import uk.org.whoami.authme.security.RandomString; import fr.xephi.authme.security.RandomString;
import uk.org.whoami.authme.settings.Messages; import fr.xephi.authme.settings.Messages;
import uk.org.whoami.authme.settings.PlayersLogs; import fr.xephi.authme.settings.PlayersLogs;
import uk.org.whoami.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import uk.org.whoami.authme.settings.Spawn; import fr.xephi.authme.task.MessageTask;
import uk.org.whoami.authme.task.MessageTask; import fr.xephi.authme.task.TimeoutTask;
import uk.org.whoami.authme.task.TimeoutTask;
public class RegisterCommand implements CommandExecutor { public class RegisterCommand implements CommandExecutor {
@ -185,20 +169,7 @@ public class RegisterCommand implements CommandExecutor {
LimboCache.getInstance().deleteLimboPlayer(name); LimboCache.getInstance().deleteLimboPlayer(name);
if (Settings.isTeleportToSpawnEnabled) { if (Settings.isTeleportToSpawnEnabled) {
World world = player.getWorld(); World world = player.getWorld();
Location loca = world.getSpawnLocation(); Location loca = plugin.getSpawnLocation(world);
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();
RegisterTeleportEvent tpEvent = new RegisterTeleportEvent(player, loca); RegisterTeleportEvent tpEvent = new RegisterTeleportEvent(player, loca);
plugin.getServer().getPluginManager().callEvent(tpEvent); plugin.getServer().getPluginManager().callEvent(tpEvent);
if(!tpEvent.isCancelled()) { if(!tpEvent.isCancelled()) {
@ -209,6 +180,10 @@ public class RegisterCommand implements CommandExecutor {
} }
} }
this.isFirstTimeJoin = true; this.isFirstTimeJoin = true;
if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) {
player.setAllowFlight(false);
player.setFlying(false);
}
player.saveData(); player.saveData();
if (!Settings.noConsoleSpam) if (!Settings.noConsoleSpam)
ConsoleLogger.info(player.getName() + " registered "+player.getAddress().getAddress().getHostAddress()); ConsoleLogger.info(player.getName() + " registered "+player.getAddress().getAddress().getHostAddress());
@ -255,23 +230,7 @@ public class RegisterCommand implements CommandExecutor {
player.setGameMode(GameMode.getByValue(limbo.getGameMode())); player.setGameMode(GameMode.getByValue(limbo.getGameMode()));
if (Settings.isTeleportToSpawnEnabled) { if (Settings.isTeleportToSpawnEnabled) {
World world = player.getWorld(); World world = player.getWorld();
Location loca = world.getSpawnLocation(); Location loca = plugin.getSpawnLocation(world);
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();
RegisterTeleportEvent tpEvent = new RegisterTeleportEvent(player, loca); RegisterTeleportEvent tpEvent = new RegisterTeleportEvent(player, loca);
plugin.getServer().getPluginManager().callEvent(tpEvent); plugin.getServer().getPluginManager().callEvent(tpEvent);
if(!tpEvent.isCancelled()) { if(!tpEvent.isCancelled()) {
@ -293,6 +252,10 @@ public class RegisterCommand implements CommandExecutor {
if (!Settings.getmailAccount.isEmpty()) if (!Settings.getmailAccount.isEmpty())
player.sendMessage(m._("add_email")); player.sendMessage(m._("add_email"));
this.isFirstTimeJoin = true; this.isFirstTimeJoin = true;
if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) {
player.setAllowFlight(false);
player.setFlying(false);
}
player.saveData(); player.saveData();
if (!Settings.noConsoleSpam) if (!Settings.noConsoleSpam)
ConsoleLogger.info(player.getName() + " registered "+player.getAddress().getAddress().getHostAddress()); ConsoleLogger.info(player.getName() + " registered "+player.getAddress().getAddress().getHostAddress());

View File

@ -1,20 +1,4 @@
/* package fr.xephi.authme.commands;
* Copyright 2011 Sebastian Köhler <sebkoehler@whoami.org.uk>.
*
* 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;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
@ -29,21 +13,21 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitScheduler; import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import uk.org.whoami.authme.AuthMe; import fr.xephi.authme.AuthMe;
import uk.org.whoami.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import uk.org.whoami.authme.Utils; import fr.xephi.authme.Utils;
import uk.org.whoami.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerCache;
import uk.org.whoami.authme.cache.backup.FileCache; import fr.xephi.authme.cache.backup.FileCache;
import uk.org.whoami.authme.cache.limbo.LimboCache; import fr.xephi.authme.cache.limbo.LimboCache;
import uk.org.whoami.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
import uk.org.whoami.authme.events.SpawnTeleportEvent; import fr.xephi.authme.events.SpawnTeleportEvent;
import uk.org.whoami.authme.security.PasswordSecurity; import fr.xephi.authme.security.PasswordSecurity;
import uk.org.whoami.authme.settings.Messages; import fr.xephi.authme.settings.Messages;
import uk.org.whoami.authme.settings.PlayersLogs; import fr.xephi.authme.settings.PlayersLogs;
import uk.org.whoami.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import uk.org.whoami.authme.settings.Spawn; import fr.xephi.authme.task.MessageTask;
import uk.org.whoami.authme.task.MessageTask; import fr.xephi.authme.task.TimeoutTask;
import uk.org.whoami.authme.task.TimeoutTask;
public class UnregisterCommand implements CommandExecutor { public class UnregisterCommand implements CommandExecutor {
@ -129,20 +113,7 @@ public class UnregisterCommand implements CommandExecutor {
plugin.notifications.showNotification(new Notification("[AuthMe] " + player.getName() + " unregistered himself!")); plugin.notifications.showNotification(new Notification("[AuthMe] " + player.getName() + " unregistered himself!"));
} }
if (Settings.isTeleportToSpawnEnabled) { if (Settings.isTeleportToSpawnEnabled) {
Location spawn = player.getWorld().getSpawnLocation(); Location spawn = plugin.getSpawnLocation(player.getWorld());
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();
SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawn, false); SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawn, false);
plugin.getServer().getPluginManager().callEvent(tpEvent); plugin.getServer().getPluginManager().callEvent(tpEvent);
if(!tpEvent.isCancelled()) { if(!tpEvent.isCancelled()) {

View File

@ -1,4 +1,4 @@
package uk.org.whoami.authme.converter; package fr.xephi.authme.converter;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.BufferedWriter; import java.io.BufferedWriter;
@ -8,9 +8,10 @@ import java.io.FileReader;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import uk.org.whoami.authme.AuthMe; import fr.xephi.authme.AuthMe;
import uk.org.whoami.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import uk.org.whoami.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
/** /**
* *

View File

@ -1,4 +1,4 @@
package uk.org.whoami.authme.converter; package fr.xephi.authme.converter;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
@ -12,9 +12,10 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import uk.org.whoami.authme.AuthMe; import fr.xephi.authme.AuthMe;
import uk.org.whoami.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import uk.org.whoami.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
public class FlatToSqlite { public class FlatToSqlite {

View File

@ -1,4 +1,4 @@
package uk.org.whoami.authme.converter; package fr.xephi.authme.converter;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.BufferedWriter; import java.io.BufferedWriter;
@ -11,11 +11,12 @@ import java.security.NoSuchAlgorithmException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map.Entry; import java.util.Map.Entry;
import uk.org.whoami.authme.AuthMe; import fr.xephi.authme.AuthMe;
import uk.org.whoami.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import uk.org.whoami.authme.security.PasswordSecurity; import fr.xephi.authme.security.HashAlgorithm;
import uk.org.whoami.authme.security.PasswordSecurity.HashAlgorithm; import fr.xephi.authme.security.PasswordSecurity;
import uk.org.whoami.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
/** /**
* *

View File

@ -1,4 +1,4 @@
package uk.org.whoami.authme.converter; package fr.xephi.authme.converter;
import java.io.File; import java.io.File;
import java.sql.Connection; import java.sql.Connection;
@ -14,9 +14,10 @@ import com.cypherx.xauth.xAuth;
import com.cypherx.xauth.database.Table; import com.cypherx.xauth.database.Table;
import com.cypherx.xauth.utils.xAuthLog; import com.cypherx.xauth.utils.xAuthLog;
import uk.org.whoami.authme.AuthMe; import fr.xephi.authme.AuthMe;
import uk.org.whoami.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import uk.org.whoami.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
/** /**
* *

View File

@ -1,29 +1,14 @@
/* package fr.xephi.authme.datasource;
* Copyright 2011 Sebastian Köhler <sebkoehler@whoami.org.uk>.
*
* 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;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import uk.org.whoami.authme.AuthMe; import fr.xephi.authme.AuthMe;
import uk.org.whoami.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import uk.org.whoami.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerCache;
public class CacheDataSource implements DataSource { public class CacheDataSource implements DataSource {
@ -110,6 +95,19 @@ public class CacheDataSource implements DataSource {
return cleared; return cleared;
} }
@Override
public List<String> autoPurgeDatabase(long until) {
List<String> cleared = source.autoPurgeDatabase(until);
if (cleared.size() > 0) {
for (PlayerAuth auth : cache.values()) {
if(auth.getLastLogin() < until) {
cache.remove(auth.getNickname());
}
}
}
return cleared;
}
@Override @Override
public synchronized boolean removeAuth(String user) { public synchronized boolean removeAuth(String user) {
if (source.removeAuth(user)) { if (source.removeAuth(user)) {
@ -141,7 +139,7 @@ public class CacheDataSource implements DataSource {
} }
@Override @Override
public boolean updateEmail(PlayerAuth auth) { public synchronized boolean updateEmail(PlayerAuth auth) {
if(source.updateEmail(auth)) { if(source.updateEmail(auth)) {
cache.get(auth.getNickname()).setEmail(auth.getEmail()); cache.get(auth.getNickname()).setEmail(auth.getEmail());
return true; return true;
@ -150,7 +148,7 @@ public class CacheDataSource implements DataSource {
} }
@Override @Override
public boolean updateSalt(PlayerAuth auth) { public synchronized boolean updateSalt(PlayerAuth auth) {
if(source.updateSalt(auth)) { if(source.updateSalt(auth)) {
cache.get(auth.getNickname()).setSalt(auth.getSalt()); cache.get(auth.getNickname()).setSalt(auth.getSalt());
return true; return true;
@ -159,22 +157,22 @@ public class CacheDataSource implements DataSource {
} }
@Override @Override
public List<String> getAllAuthsByName(PlayerAuth auth) { public synchronized List<String> getAllAuthsByName(PlayerAuth auth) {
return source.getAllAuthsByName(auth); return source.getAllAuthsByName(auth);
} }
@Override @Override
public List<String> getAllAuthsByIp(String ip) { public synchronized List<String> getAllAuthsByIp(String ip) {
return source.getAllAuthsByIp(ip); return source.getAllAuthsByIp(ip);
} }
@Override @Override
public List<String> getAllAuthsByEmail(String email) { public synchronized List<String> getAllAuthsByEmail(String email) {
return source.getAllAuthsByEmail(email); return source.getAllAuthsByEmail(email);
} }
@Override @Override
public void purgeBanned(List<String> banned) { public synchronized void purgeBanned(List<String> banned) {
source.purgeBanned(banned); source.purgeBanned(banned);
for (PlayerAuth auth : cache.values()) { for (PlayerAuth auth : cache.values()) {
if (banned.contains(auth.getNickname())) { if (banned.contains(auth.getNickname())) {

View File

@ -1,24 +1,9 @@
/* package fr.xephi.authme.datasource;
* Copyright 2011 Sebastian Köhler <sebkoehler@whoami.org.uk>.
*
* 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;
import java.util.List; import java.util.List;
import uk.org.whoami.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
public interface DataSource { public interface DataSource {
@ -39,6 +24,8 @@ public interface DataSource {
int purgeDatabase(long until); int purgeDatabase(long until);
List<String> autoPurgeDatabase(long until);
boolean removeAuth(String user); boolean removeAuth(String user);
boolean updateQuitLoc(PlayerAuth auth); boolean updateQuitLoc(PlayerAuth auth);

View File

@ -1,20 +1,4 @@
/* package fr.xephi.authme.datasource;
* Copyright 2011 Sebastian Köhler <sebkoehler@whoami.org.uk>.
*
* 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;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.BufferedWriter; import java.io.BufferedWriter;
@ -26,17 +10,19 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import uk.org.whoami.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import uk.org.whoami.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import uk.org.whoami.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
public class FileDataSource implements DataSource { public class FileDataSource implements DataSource {
/* file layout: /* file layout:
* *
* PLAYERNAME:HASHSUM:IP:LOGININMILLIESECONDS:COORDS * PLAYERNAME:HASHSUM:IP:LOGININMILLIESECONDS:LASTPOSX:LASTPOSY:LASTPOSZ:LASTPOSWORLD
* *
* Old but compatible: * Old but compatible:
* PLAYERNAME:HASHSUM:IP:LOGININMILLIESECONDS
* PLAYERNAME:HASHSUM:IP * PLAYERNAME:HASHSUM:IP
* PLAYERNAME:HASHSUM * PLAYERNAME:HASHSUM
* *
@ -84,13 +70,8 @@ public class FileDataSource implements DataSource {
} }
BufferedWriter bw = null; BufferedWriter bw = null;
try { 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 = 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"); bw.write(auth.getNickname() + ":" + auth.getHash() + ":" + auth.getIp() + ":" + auth.getLastLogin() + ":" + auth.getQuitLocX() + ":" + auth.getQuitLocY() + ":" + auth.getQuitLocZ() + ":" + auth.getWorld() + "\n");
}
} catch (IOException ex) { } catch (IOException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
@ -118,7 +99,24 @@ public class FileDataSource implements DataSource {
while ((line = br.readLine()) != null) { while ((line = br.readLine()) != null) {
String[] args = line.split(":"); String[] args = line.split(":");
if (args[0].equals(auth.getNickname())) { 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; break;
} }
} }
@ -154,7 +152,24 @@ public class FileDataSource implements DataSource {
while ((line = br.readLine()) != null) { while ((line = br.readLine()) != null) {
String[] args = line.split(":"); String[] args = line.split(":");
if (args[0].equals(auth.getNickname())) { 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; break;
} }
} }
@ -254,7 +269,7 @@ public class FileDataSource implements DataSource {
String line; String line;
while ((line = br.readLine()) != null) { while ((line = br.readLine()) != null) {
String[] args = line.split(":"); String[] args = line.split(":");
if (args.length == 4) { if (args.length >= 4) {
if (Long.parseLong(args[3]) >= until) { if (Long.parseLong(args[3]) >= until) {
lines.add(line); lines.add(line);
continue; continue;
@ -289,6 +304,54 @@ public class FileDataSource implements DataSource {
return cleared; return cleared;
} }
@Override
public List<String> autoPurgeDatabase(long until) {
BufferedReader br = null;
BufferedWriter bw = null;
ArrayList<String> lines = new ArrayList<String>();
List<String> cleared = new ArrayList<String>();
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 @Override
public synchronized boolean removeAuth(String user) { public synchronized boolean removeAuth(String user) {
if (!isAuthAvailable(user)) { if (!isAuthAvailable(user)) {

View File

@ -11,7 +11,7 @@
// Please contact the author if you need another license. // Please contact the author if you need another license.
// This module is provided "as is", without warranties of any kind. // 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.io.PrintWriter;
import java.sql.Connection; import java.sql.Connection;

View File

@ -1,23 +1,14 @@
/* package fr.xephi.authme.datasource;
* Copyright 2011 Sebastian Köhler <sebkoehler@whoami.org.uk>.
*
* 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;
import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource; 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.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
@ -26,11 +17,6 @@ import java.sql.Statement;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; 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 { public class MySQLDataSource implements DataSource {
@ -247,6 +233,104 @@ public class MySQLDataSource implements DataSource {
pst.executeUpdate(); 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) { } catch (SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
@ -328,6 +412,34 @@ public class MySQLDataSource implements DataSource {
} }
} }
@Override
public synchronized List<String> autoPurgeDatabase(long until) {
Connection con = null;
PreparedStatement pst = null;
ResultSet rs = null;
List<String> list = new ArrayList<String>();
try {
con = makeSureConnectionIsReady();
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLastLogin + "<?;");
pst.setLong(1, until);
rs = pst.executeQuery();
while (rs.next()) {
list.add(rs.getString(columnName));
}
return list;
} catch (SQLException ex) {
ConsoleLogger.showError(ex.getMessage());
return new ArrayList<String>();
} catch (TimeoutException ex) {
ConsoleLogger.showError(ex.getMessage());
return new ArrayList<String>();
} finally {
close(rs);
close(pst);
close(con);
}
}
@Override @Override
public synchronized boolean removeAuth(String user) { public synchronized boolean removeAuth(String user) {
Connection con = null; Connection con = null;
@ -430,7 +542,7 @@ public class MySQLDataSource implements DataSource {
@Override @Override
public synchronized boolean updateSalt(PlayerAuth auth) { public synchronized boolean updateSalt(PlayerAuth auth) {
if (columnSalt.isEmpty()) { if (columnSalt.isEmpty() || auth.getSalt() == null || auth.getSalt().isEmpty()) {
return false; return false;
} }
Connection con = null; Connection con = null;
@ -654,4 +766,5 @@ public class MySQLDataSource implements DataSource {
conPool = new MiniConnectionPoolManager(dataSource, 10); conPool = new MiniConnectionPoolManager(dataSource, 10);
ConsoleLogger.info("ConnectionPool was unavailable... Reconnected!"); ConsoleLogger.info("ConnectionPool was unavailable... Reconnected!");
} }
} }

View File

@ -1,14 +1,15 @@
package uk.org.whoami.authme.datasource; package fr.xephi.authme.datasource;
import java.sql.*; import java.sql.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.sqlite.*; import org.sqlite.*;
import uk.org.whoami.authme.ConsoleLogger;
import uk.org.whoami.authme.cache.auth.PlayerAuth; import fr.xephi.authme.ConsoleLogger;
import uk.org.whoami.authme.datasource.MiniConnectionPoolManager.TimeoutException; import fr.xephi.authme.cache.auth.PlayerAuth;
import uk.org.whoami.authme.settings.Settings; 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.close();
rs = con.getMetaData().getColumns(null, null, tableName, lastlocWorld); rs = con.getMetaData().getColumns(null, null, tableName, lastlocWorld);
if (!rs.next()) { 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.close();
rs = con.getMetaData().getColumns(null, null, tableName, columnEmail); rs = con.getMetaData().getColumns(null, null, tableName, columnEmail);
@ -246,6 +247,28 @@ public class SqliteDataSource implements DataSource {
} }
} }
@Override
public List<String> autoPurgeDatabase(long until) {
PreparedStatement pst = null;
ResultSet rs = null;
List<String> list = new ArrayList<String>();
try {
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLastLogin + "<?;");
pst.setLong(1, until);
rs = pst.executeQuery();
while (rs.next()) {
list.add(rs.getString(columnName));
}
return list;
} catch (SQLException ex) {
ConsoleLogger.showError(ex.getMessage());
return new ArrayList<String>();
} finally {
close(rs);
close(pst);
}
}
@Override @Override
public synchronized boolean removeAuth(String user) { public synchronized boolean removeAuth(String user) {
PreparedStatement pst = null; PreparedStatement pst = null;

View File

@ -1,4 +1,4 @@
package uk.org.whoami.authme.events; package fr.xephi.authme.events;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View File

@ -1,6 +1,7 @@
package uk.org.whoami.authme.events; package fr.xephi.authme.events;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
@ -8,7 +9,7 @@ import org.bukkit.event.HandlerList;
* *
* @author Xephi59 * @author Xephi59
*/ */
public class CustomEvent extends Event { public class CustomEvent extends Event implements Cancellable {
private boolean isCancelled; private boolean isCancelled;
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();

View File

@ -1,15 +1,18 @@
package uk.org.whoami.authme.events; package fr.xephi.authme.events;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
/** /**
* *
* @author Xephi59 * @author Xephi59
*/ */
public class LoginEvent extends UncancellableEvent { public class LoginEvent extends Event {
private Player player; private Player player;
private boolean isLogin; private boolean isLogin;
private static final HandlerList handlers = new HandlerList();
public LoginEvent(Player player, boolean isLogin) { public LoginEvent(Player player, boolean isLogin) {
this.player = player; this.player = player;
@ -24,6 +27,7 @@ public class LoginEvent extends UncancellableEvent {
this.player = player; this.player = player;
} }
@Deprecated
public void setLogin(boolean isLogin) { public void setLogin(boolean isLogin) {
this.isLogin = isLogin; this.isLogin = isLogin;
} }
@ -32,4 +36,9 @@ public class LoginEvent extends UncancellableEvent {
return isLogin; return isLogin;
} }
@Override
public HandlerList getHandlers() {
return handlers;
}
} }

View File

@ -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;
/**
* <p>This event is called when we need to compare or get an hash password,
* for set a custom EncryptionMethod</p>
*
* @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;
}
}

View File

@ -1,10 +1,8 @@
package uk.org.whoami.authme.events; package fr.xephi.authme.events;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import uk.org.whoami.authme.api.API;
/** /**
* *
* @author Xephi59 * @author Xephi59
@ -21,15 +19,8 @@ public class ProtectInventoryEvent extends CustomEvent {
this.player = player; this.player = player;
this.storedinventory = storedinventory; this.storedinventory = storedinventory;
this.storedarmor = storedarmor; this.storedarmor = storedarmor;
} this.emptyInventory = new ItemStack[36];
this.emptyArmor = new ItemStack[4];
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]);
} }
public ItemStack[] getStoredInventory() { public ItemStack[] getStoredInventory() {

View File

@ -1,4 +1,4 @@
package uk.org.whoami.authme.events; package fr.xephi.authme.events;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View File

@ -1,9 +1,6 @@
package uk.org.whoami.authme.events; package fr.xephi.authme.events;
import org.bukkit.entity.Player; 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) { public ResetInventoryEvent(Player player) {
this.player = player; this.player = player;
API.setPlayerInventory(player, new ItemStack[36], new ItemStack[4]);
} }
public Player getPlayer() { public Player getPlayer() {

View File

@ -1,4 +1,4 @@
package uk.org.whoami.authme.events; package fr.xephi.authme.events;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;

View File

@ -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;
/** /**
* *

View File

@ -1,4 +1,4 @@
package uk.org.whoami.authme.events; package fr.xephi.authme.events;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View File

@ -1,9 +1,10 @@
package uk.org.whoami.authme.events; package fr.xephi.authme.events;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import uk.org.whoami.authme.cache.backup.FileCache; import fr.xephi.authme.cache.backup.FileCache;
/** /**
* *

View File

@ -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.event.screen.ButtonClickEvent;

View File

@ -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.event.screen.ButtonClickEvent;
import org.getspout.spoutapi.gui.GenericButton; import org.getspout.spoutapi.gui.GenericButton;

View File

@ -1,8 +1,5 @@
package uk.org.whoami.authme.gui.screens; package fr.xephi.authme.gui.screens;
/**
* @Author Hoezef
*/
import java.util.List; import java.util.List;
import org.bukkit.event.EventHandler; 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.gui.WidgetAnchor;
import org.getspout.spoutapi.player.SpoutPlayer; import org.getspout.spoutapi.player.SpoutPlayer;
import uk.org.whoami.authme.AuthMe; import fr.xephi.authme.AuthMe;
import uk.org.whoami.authme.gui.Clickable; import fr.xephi.authme.gui.Clickable;
import uk.org.whoami.authme.gui.CustomButton; import fr.xephi.authme.gui.CustomButton;
import uk.org.whoami.authme.settings.SpoutCfg; import fr.xephi.authme.settings.SpoutCfg;
public class LoginScreen extends GenericPopup implements Clickable{ public class LoginScreen extends GenericPopup implements Clickable{

View File

@ -1,20 +1,4 @@
/* package fr.xephi.authme.listener;
* Copyright 2011 Sebastian Köhler <sebkoehler@whoami.org.uk>.
*
* 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;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; 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.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import uk.org.whoami.authme.AuthMe; import fr.xephi.authme.AuthMe;
import uk.org.whoami.authme.Utils; import fr.xephi.authme.Utils;
import uk.org.whoami.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerCache;
import uk.org.whoami.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
import uk.org.whoami.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
public class AuthMeBlockListener implements Listener { public class AuthMeBlockListener implements Listener {

View File

@ -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);
}
}

View File

@ -1,4 +1,4 @@
package uk.org.whoami.authme.listener; package fr.xephi.authme.listener;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; 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;
import com.Acrobot.ChestShop.Events.PreTransactionEvent.TransactionOutcome; import com.Acrobot.ChestShop.Events.PreTransactionEvent.TransactionOutcome;
import uk.org.whoami.authme.AuthMe; import fr.xephi.authme.AuthMe;
import uk.org.whoami.authme.Utils; import fr.xephi.authme.Utils;
import uk.org.whoami.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerCache;
import uk.org.whoami.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
import uk.org.whoami.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
public class AuthMeChestShopListener implements Listener { public class AuthMeChestShopListener implements Listener {

View File

@ -1,20 +1,4 @@
/* package fr.xephi.authme.listener;
* Copyright 2011 Sebastian Köhler <sebkoehler@whoami.org.uk>.
*
* 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;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; 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.EntityTargetEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.entity.FoodLevelChangeEvent;
import uk.org.whoami.authme.AuthMe; import fr.xephi.authme.AuthMe;
import uk.org.whoami.authme.Utils; import fr.xephi.authme.Utils;
import uk.org.whoami.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerCache;
import uk.org.whoami.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
import uk.org.whoami.authme.plugin.manager.CombatTagComunicator; import fr.xephi.authme.plugin.manager.CombatTagComunicator;
import uk.org.whoami.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
public class AuthMeEntityListener implements Listener{ public class AuthMeEntityListener implements Listener{
@ -59,6 +44,9 @@ public class AuthMeEntityListener implements Listener{
return; return;
} }
if(instance.citizens.isNPC(entity, instance))
return;
Player player = (Player) entity; Player player = (Player) entity;
String name = player.getName().toLowerCase(); String name = player.getName().toLowerCase();
@ -89,6 +77,9 @@ public class AuthMeEntityListener implements Listener{
return; return;
} }
if(instance.citizens.isNPC(entity, instance))
return;
Player player = (Player) entity; Player player = (Player) entity;
String name = player.getName().toLowerCase(); String name = player.getName().toLowerCase();
@ -116,6 +107,9 @@ public class AuthMeEntityListener implements Listener{
return; return;
} }
if(instance.citizens.isNPC(entity, instance))
return;
Player player = (Player) entity; Player player = (Player) entity;
String name = player.getName().toLowerCase(); String name = player.getName().toLowerCase();
@ -144,6 +138,9 @@ public class AuthMeEntityListener implements Listener{
return; return;
} }
if(instance.citizens.isNPC(entity, instance))
return;
Player player = (Player) entity; Player player = (Player) entity;
String name = player.getName().toLowerCase(); String name = player.getName().toLowerCase();
@ -177,6 +174,9 @@ public class AuthMeEntityListener implements Listener{
return; return;
} }
if(instance.citizens.isNPC(player, instance))
return;
if (PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) { if (PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) {
return; return;
} }
@ -206,6 +206,9 @@ public class AuthMeEntityListener implements Listener{
return; return;
} }
if(instance.citizens.isNPC(player, instance))
return;
if (PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) { if (PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) {
return; return;
} }

View File

@ -1,20 +1,4 @@
/* package fr.xephi.authme.listener;
* Copyright 2011 Sebastian Köhler <sebkoehler@whoami.org.uk>.
*
* 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;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
@ -53,29 +37,29 @@ import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.scheduler.BukkitScheduler; import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import uk.org.whoami.authme.AuthMe; import fr.xephi.authme.AuthMe;
import uk.org.whoami.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import uk.org.whoami.authme.Utils; import fr.xephi.authme.Utils;
import uk.org.whoami.authme.api.API; import fr.xephi.authme.api.API;
import uk.org.whoami.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import uk.org.whoami.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerCache;
import uk.org.whoami.authme.cache.backup.DataFileCache; import fr.xephi.authme.cache.backup.DataFileCache;
import uk.org.whoami.authme.cache.backup.FileCache; import fr.xephi.authme.cache.backup.FileCache;
import uk.org.whoami.authme.cache.limbo.LimboCache; import fr.xephi.authme.cache.limbo.LimboCache;
import uk.org.whoami.authme.cache.limbo.LimboPlayer; import fr.xephi.authme.cache.limbo.LimboPlayer;
import uk.org.whoami.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
import uk.org.whoami.authme.events.AuthMeTeleportEvent; import fr.xephi.authme.events.AuthMeTeleportEvent;
import uk.org.whoami.authme.events.ProtectInventoryEvent; import fr.xephi.authme.events.ProtectInventoryEvent;
import uk.org.whoami.authme.events.RestoreInventoryEvent; import fr.xephi.authme.events.RestoreInventoryEvent;
import uk.org.whoami.authme.events.SessionEvent; import fr.xephi.authme.events.SessionEvent;
import uk.org.whoami.authme.events.SpawnTeleportEvent; import fr.xephi.authme.events.SpawnTeleportEvent;
import uk.org.whoami.authme.plugin.manager.CombatTagComunicator; import fr.xephi.authme.plugin.manager.CombatTagComunicator;
import uk.org.whoami.authme.settings.Messages; import fr.xephi.authme.settings.Messages;
import uk.org.whoami.authme.settings.PlayersLogs; import fr.xephi.authme.settings.PlayersLogs;
import uk.org.whoami.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import uk.org.whoami.authme.settings.Spawn; import fr.xephi.authme.task.MessageTask;
import uk.org.whoami.authme.task.MessageTask; import fr.xephi.authme.task.TimeoutTask;
import uk.org.whoami.authme.task.TimeoutTask;
public class AuthMePlayerListener implements Listener { public class AuthMePlayerListener implements Listener {
@ -143,327 +127,208 @@ public class AuthMePlayerListener implements Listener {
String cmd = event.getMessage().split(" ")[0]; 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))) { if (!Settings.isChatAllowed && !(Settings.allowCommands.contains(cmd))) {
event.setCancelled(true); event.setCancelled(true);
return; 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) @EventHandler( priority = EventPriority.HIGH)
public void onPlayerHighChat(AsyncPlayerChatEvent event) { public void onPlayerHighChat(AsyncPlayerChatEvent event) {
if (event.isCancelled() || event.getPlayer() == null) { if (event.isCancelled() || event.getPlayer() == null)
return; return;
}
final Player player = event.getPlayer(); final Player player = event.getPlayer();
final String name = player.getName().toLowerCase(); final String name = player.getName().toLowerCase();
if (Utils.getInstance().isUnrestricted(player)) { if (Utils.getInstance().isUnrestricted(player))
return; return;
}
if (PlayerCache.getInstance().isAuthenticated(name)) { if (PlayerCache.getInstance().isAuthenticated(name))
return; return;
}
String cmd = event.getMessage().split(" ")[0]; 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))) { if (!Settings.isChatAllowed && !(Settings.allowCommands.contains(cmd))) {
event.setCancelled(true); event.setCancelled(true);
return; 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) @EventHandler( priority = EventPriority.MONITOR)
public void onPlayerChat(AsyncPlayerChatEvent event) { public void onPlayerChat(AsyncPlayerChatEvent event) {
if (event.isCancelled() || event.getPlayer() == null) { if (event.isCancelled() || event.getPlayer() == null)
return; return;
}
final Player player = event.getPlayer(); final Player player = event.getPlayer();
final String name = player.getName().toLowerCase(); final String name = player.getName().toLowerCase();
if (Utils.getInstance().isUnrestricted(player)) { if (Utils.getInstance().isUnrestricted(player))
return; return;
}
if (PlayerCache.getInstance().isAuthenticated(name)) { if (PlayerCache.getInstance().isAuthenticated(name))
return; return;
}
String cmd = event.getMessage().split(" ")[0]; 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))) { if (!Settings.isChatAllowed && !(Settings.allowCommands.contains(cmd))) {
event.setCancelled(true); event.setCancelled(true);
return; 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) @EventHandler( priority = EventPriority.HIGHEST)
public void onPlayerHighestChat(AsyncPlayerChatEvent event) { public void onPlayerHighestChat(AsyncPlayerChatEvent event) {
if (event.isCancelled() || event.getPlayer() == null) { if (event.isCancelled() || event.getPlayer() == null)
return; return;
}
final Player player = event.getPlayer(); final Player player = event.getPlayer();
final String name = player.getName().toLowerCase(); final String name = player.getName().toLowerCase();
if (Utils.getInstance().isUnrestricted(player)) { if (Utils.getInstance().isUnrestricted(player))
return; return;
}
if (PlayerCache.getInstance().isAuthenticated(name)) { if (PlayerCache.getInstance().isAuthenticated(name))
return; return;
}
String cmd = event.getMessage().split(" ")[0]; 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))) { if (!Settings.isChatAllowed && !(Settings.allowCommands.contains(cmd))) {
event.setCancelled(true); event.setCancelled(true);
return; 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) @EventHandler( priority = EventPriority.LOWEST)
public void onPlayerEarlyChat(AsyncPlayerChatEvent event) { public void onPlayerEarlyChat(AsyncPlayerChatEvent event) {
if (event.isCancelled() || event.getPlayer() == null) { if (event.isCancelled() || event.getPlayer() == null)
return; return;
}
final Player player = event.getPlayer(); final Player player = event.getPlayer();
final String name = player.getName().toLowerCase(); final String name = player.getName().toLowerCase();
if (Utils.getInstance().isUnrestricted(player)) { if (Utils.getInstance().isUnrestricted(player))
return; return;
}
if (PlayerCache.getInstance().isAuthenticated(name)) { if (PlayerCache.getInstance().isAuthenticated(name))
return; return;
}
String cmd = event.getMessage().split(" ")[0]; 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))) { if (!Settings.isChatAllowed && !(Settings.allowCommands.contains(cmd))) {
event.setCancelled(true); event.setCancelled(true);
return; 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) @EventHandler( priority = EventPriority.LOW)
public void onPlayerLowChat(AsyncPlayerChatEvent event) { public void onPlayerLowChat(AsyncPlayerChatEvent event) {
if (event.isCancelled() || event.getPlayer() == null) { if (event.isCancelled() || event.getPlayer() == null)
return; return;
}
final Player player = event.getPlayer(); final Player player = event.getPlayer();
final String name = player.getName().toLowerCase(); final String name = player.getName().toLowerCase();
if (Utils.getInstance().isUnrestricted(player)) { if (Utils.getInstance().isUnrestricted(player))
return; return;
}
if (PlayerCache.getInstance().isAuthenticated(name)) { if (PlayerCache.getInstance().isAuthenticated(name))
return; return;
}
String cmd = event.getMessage().split(" ")[0]; 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))) { if (!Settings.isChatAllowed && !(Settings.allowCommands.contains(cmd))) {
event.setCancelled(true); event.setCancelled(true);
return; 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) @EventHandler(priority = EventPriority.MONITOR)
@ -497,20 +362,7 @@ public class AuthMePlayerListener implements Listener {
} }
int radius = Settings.getMovementRadius; int radius = Settings.getMovementRadius;
Location spawn = player.getWorld().getSpawnLocation(); Location spawn = plugin.getSpawnLocation(player.getWorld());
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();
if (!event.getPlayer().getWorld().equals(spawn.getWorld())) { if (!event.getPlayer().getWorld().equals(spawn.getWorld())) {
event.getPlayer().teleport(spawn); event.getPlayer().teleport(spawn);
@ -653,20 +505,7 @@ public class AuthMePlayerListener implements Listener {
Player player = event.getPlayer(); Player player = event.getPlayer();
World world = player.getWorld(); World world = player.getWorld();
Location spawnLoc = world.getSpawnLocation(); Location spawnLoc = plugin.getSpawnLocation(world);
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();
gm = player.getGameMode().getValue(); gm = player.getGameMode().getValue();
final String name = player.getName().toLowerCase(); final String name = player.getName().toLowerCase();
gameMode.put(name, gm); gameMode.put(name, gm);
@ -739,9 +578,20 @@ public class AuthMePlayerListener implements Listener {
// isent in session or session was ended correctly // isent in session or session was ended correctly
if (Settings.isForceSurvivalModeEnabled && !Settings.forceOnlyAfterLogin) if (Settings.isForceSurvivalModeEnabled && !Settings.forceOnlyAfterLogin)
e.getPlayer().setGameMode(GameMode.SURVIVAL); e.getPlayer().setGameMode(GameMode.SURVIVAL);
LimboCache.getInstance().updateLimboPlayer(player); if (Settings.isTeleportToSpawnEnabled || (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName()))) {
DataFileCache dataFile = new DataFileCache(LimboCache.getInstance().getLimboPlayer(name).getInventory(),LimboCache.getInstance().getLimboPlayer(name).getArmour()); SpawnTeleportEvent tpEvent = new SpawnTeleportEvent(player, player.getLocation(), spawnLoc, PlayerCache.getInstance().isAuthenticated(name));
playerBackup.createCache(name, dataFile, LimboCache.getInstance().getLimboPlayer(name).getGroup(),LimboCache.getInstance().getLimboPlayer(name).getOperator(),LimboCache.getInstance().getLimboPlayer(name).isFlying()); 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 { } else {
if (Settings.isForceSurvivalModeEnabled && !Settings.forceOnlyAfterLogin) if (Settings.isForceSurvivalModeEnabled && !Settings.forceOnlyAfterLogin)
e.getPlayer().setGameMode(GameMode.SURVIVAL); e.getPlayer().setGameMode(GameMode.SURVIVAL);
@ -752,30 +602,20 @@ public class AuthMePlayerListener implements Listener {
return; return;
} }
} }
if(Settings.protectInventoryBeforeLogInEnabled) { if(Settings.protectInventoryBeforeLogInEnabled) {
try { try {
LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(player.getName().toLowerCase()); 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); plugin.getServer().getPluginManager().callEvent(ev);
if (ev.isCancelled()) { if (ev.isCancelled()) {
if (!Settings.noConsoleSpam) 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) { } 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 = ""; String msg = "";
if(Settings.emailRegistration) { if(Settings.emailRegistration) {
msg = data.isAuthAvailable(name) ? m._("login_msg") : m._("reg_email_msg"); msg = data.isAuthAvailable(name) ? m._("login_msg") : m._("reg_email_msg");
@ -794,8 +634,10 @@ public class AuthMePlayerListener implements Listener {
LimboCache.getInstance().addLimboPlayer(player); LimboCache.getInstance().addLimboPlayer(player);
if(player.isOp()) if(player.isOp())
player.setOp(false); player.setOp(false);
player.setAllowFlight(true); if (!Settings.isMovementAllowed) {
player.setFlying(true); player.setAllowFlight(true);
player.setFlying(true);
}
BukkitTask msgT = sched.runTask(plugin, new MessageTask(plugin, name, msg, msgInterval)); BukkitTask msgT = sched.runTask(plugin, new MessageTask(plugin, name, msg, msgInterval));
LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT.getTaskId()); LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT.getTaskId());
player.setNoDamageTicks(Settings.getRegistrationTimeout * 20); player.setNoDamageTicks(Settings.getRegistrationTimeout * 20);
@ -832,12 +674,12 @@ public class AuthMePlayerListener implements Listener {
if (PlayerCache.getInstance().isAuthenticated(name) && !player.isDead()) { if (PlayerCache.getInstance().isAuthenticated(name) && !player.isDead()) {
if(Settings.isSaveQuitLocationEnabled && data.isAuthAvailable(name)) { 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 { try {
if (data instanceof Thread) { if (data instanceof Thread) {
data.updateQuitLoc(auth); data.updateQuitLoc(auth);
} else { } else {
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable(){ Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
@Override @Override
public void run() { public void run() {
data.updateQuitLoc(auth); data.updateQuitLoc(auth);
@ -859,9 +701,10 @@ public class AuthMePlayerListener implements Listener {
} }
utils.addNormal(player, limbo.getGroup()); utils.addNormal(player, limbo.getGroup());
player.setOp(limbo.getOperator()); player.setOp(limbo.getOperator());
if (player.getGameMode() != GameMode.CREATIVE) if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) {
player.setAllowFlight(limbo.isFlying()); player.setAllowFlight(limbo.isFlying());
player.setFlying(limbo.isFlying()); player.setFlying(limbo.isFlying());
}
this.plugin.getServer().getScheduler().cancelTask(limbo.getTimeoutTaskId()); this.plugin.getServer().getScheduler().cancelTask(limbo.getTimeoutTaskId());
LimboCache.getInstance().deleteLimboPlayer(name); LimboCache.getInstance().deleteLimboPlayer(name);
if(playerBackup.doesCacheExist(name)) { if(playerBackup.doesCacheExist(name)) {
@ -876,7 +719,6 @@ public class AuthMePlayerListener implements Listener {
} catch (NullPointerException ex) { } catch (NullPointerException ex) {
} }
if (gameMode.containsKey(name)) gameMode.remove(name); if (gameMode.containsKey(name)) gameMode.remove(name);
plugin.premium.remove(player.getName());
player.saveData(); player.saveData();
} }
@ -907,12 +749,12 @@ public class AuthMePlayerListener implements Listener {
String name = player.getName().toLowerCase(); String name = player.getName().toLowerCase();
if ((PlayerCache.getInstance().isAuthenticated(name)) && (!player.isDead()) && if ((PlayerCache.getInstance().isAuthenticated(name)) && (!player.isDead()) &&
(Settings.isSaveQuitLocationEnabled) && data.isAuthAvailable(name)) { (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 { try {
if (data instanceof Thread) { if (data instanceof Thread) {
data.updateQuitLoc(auth); data.updateQuitLoc(auth);
} else { } else {
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable(){ Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
@Override @Override
public void run() { public void run() {
data.updateQuitLoc(auth); data.updateQuitLoc(auth);
@ -949,9 +791,10 @@ public class AuthMePlayerListener implements Listener {
} }
this.utils.addNormal(player, limbo.getGroup()); this.utils.addNormal(player, limbo.getGroup());
player.setOp(limbo.getOperator()); player.setOp(limbo.getOperator());
if (player.getGameMode() != GameMode.CREATIVE) if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) {
player.setAllowFlight(limbo.isFlying()); player.setAllowFlight(limbo.isFlying());
player.setFlying(limbo.isFlying()); player.setFlying(limbo.isFlying());
}
this.plugin.getServer().getScheduler().cancelTask(limbo.getTimeoutTaskId()); this.plugin.getServer().getScheduler().cancelTask(limbo.getTimeoutTaskId());
LimboCache.getInstance().deleteLimboPlayer(name); LimboCache.getInstance().deleteLimboPlayer(name);
if (this.playerBackup.doesCacheExist(name)) { if (this.playerBackup.doesCacheExist(name)) {
@ -965,7 +808,6 @@ public class AuthMePlayerListener implements Listener {
if (gameMode.containsKey(name)) gameMode.remove(name); if (gameMode.containsKey(name)) gameMode.remove(name);
player.getVehicle().eject(); player.getVehicle().eject();
player.saveData(); player.saveData();
plugin.premium.remove(player.getName());
} catch (NullPointerException ex) {} } catch (NullPointerException ex) {}
} }
@ -982,6 +824,9 @@ public class AuthMePlayerListener implements Listener {
return; return;
} }
if(plugin.getCitizensCommunicator().isNPC(player, plugin))
return;
if (PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) { if (PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) {
return; return;
} }
@ -1006,6 +851,9 @@ public class AuthMePlayerListener implements Listener {
return; return;
} }
if(plugin.getCitizensCommunicator().isNPC(player, plugin))
return;
if (PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) { if (PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) {
return; return;
} }
@ -1032,6 +880,9 @@ public class AuthMePlayerListener implements Listener {
return; return;
} }
if(plugin.getCitizensCommunicator().isNPC(player, plugin))
return;
if (PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) { if (PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) {
return; return;
} }
@ -1055,6 +906,9 @@ public class AuthMePlayerListener implements Listener {
return; return;
} }
if(plugin.getCitizensCommunicator().isNPC(player, plugin))
return;
if (PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) { if (PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) {
return; return;
} }
@ -1105,6 +959,9 @@ public class AuthMePlayerListener implements Listener {
return; return;
} }
if(plugin.getCitizensCommunicator().isNPC(player, plugin))
return;
if (PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) { if (PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) {
return; return;
} }
@ -1174,6 +1031,9 @@ public class AuthMePlayerListener implements Listener {
if (Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) if (Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player))
return; return;
if(plugin.getCitizensCommunicator().isNPC(player, plugin))
return;
if (PlayerCache.getInstance().isAuthenticated(name)) if (PlayerCache.getInstance().isAuthenticated(name))
return; return;
@ -1184,20 +1044,7 @@ public class AuthMePlayerListener implements Listener {
if (!Settings.isTeleportToSpawnEnabled && !Settings.isForceSpawnLocOnJoinEnabled) if (!Settings.isTeleportToSpawnEnabled && !Settings.isForceSpawnLocOnJoinEnabled)
return; return;
Location spawn = player.getWorld().getSpawnLocation(); Location spawn = plugin.getSpawnLocation(player.getWorld());
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();
event.setRespawnLocation(spawn); event.setRespawnLocation(spawn);
} }

View File

@ -1,18 +1,13 @@
package uk.org.whoami.authme.listener; package fr.xephi.authme.listener;
/**
* @Author Hoezef
*/
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.getspout.spoutapi.event.spout.SpoutCraftEnableEvent; import org.getspout.spoutapi.event.spout.SpoutCraftEnableEvent;
import fr.xephi.authme.cache.auth.PlayerCache;
import uk.org.whoami.authme.cache.auth.PlayerCache; import fr.xephi.authme.datasource.DataSource;
import uk.org.whoami.authme.datasource.DataSource; import fr.xephi.authme.gui.screens.LoginScreen;
import uk.org.whoami.authme.gui.screens.LoginScreen; import fr.xephi.authme.settings.SpoutCfg;
import uk.org.whoami.authme.settings.SpoutCfg;
public class AuthMeSpoutListener implements Listener { public class AuthMeSpoutListener implements Listener {
private DataSource data; private DataSource data;

View File

@ -1,4 +1,4 @@
package uk.org.whoami.authme.plugin.manager; package fr.xephi.authme.plugin.manager;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.DataInputStream; import java.io.DataInputStream;
@ -7,7 +7,7 @@ import java.io.IOException;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.messaging.PluginMessageListener; import org.bukkit.plugin.messaging.PluginMessageListener;
import uk.org.whoami.authme.AuthMe; import fr.xephi.authme.AuthMe;
public class BungeeCordMessage implements PluginMessageListener { public class BungeeCordMessage implements PluginMessageListener {

View File

@ -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.CitizensAPI;
import net.citizensnpcs.api.CitizensManager; import net.citizensnpcs.api.CitizensManager;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import uk.org.whoami.authme.AuthMe; import fr.xephi.authme.AuthMe;
public class CitizensCommunicator { public class CitizensCommunicator {
@ -26,7 +26,7 @@ public class CitizensCommunicator {
} }
} catch (NoClassDefFoundError ncdfe) { } catch (NoClassDefFoundError ncdfe) {
return false; return false;
} catch (NullPointerException npe) { } catch (Exception npe) {
return false; return false;
} }
} }

View File

@ -1,8 +1,4 @@
/* package fr.xephi.authme.plugin.manager;
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package uk.org.whoami.authme.plugin.manager;
import com.trc202.CombatTag.CombatTag; import com.trc202.CombatTag.CombatTag;
import com.trc202.CombatTagApi.CombatTagApi; import com.trc202.CombatTagApi.CombatTagApi;
@ -11,10 +7,6 @@ import org.bukkit.Bukkit;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
/**
*
* @author stefano
*/
public abstract class CombatTagComunicator { public abstract class CombatTagComunicator {
static CombatTagApi combatApi; static CombatTagApi combatApi;

View File

@ -1,16 +1,12 @@
package uk.org.whoami.authme.plugin.manager; package fr.xephi.authme.plugin.manager;
import java.io.File; import java.io.File;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import uk.org.whoami.authme.settings.CustomConfiguration; import fr.xephi.authme.settings.CustomConfiguration;
/**
*
* @author Xephi59
*/
public class EssSpawn extends CustomConfiguration { public class EssSpawn extends CustomConfiguration {
private static EssSpawn spawn; private static EssSpawn spawn;

View File

@ -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;
}
}

View File

@ -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<String, String> userSalt = new HashMap<String, String>();
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;
}
}

View File

@ -1,4 +1,4 @@
package uk.org.whoami.authme.security; package fr.xephi.authme.security;
import java.util.Random; import java.util.Random;

View File

@ -11,12 +11,16 @@
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. // 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.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom; import java.security.SecureRandom;
import fr.xephi.authme.AuthMe;
/** /**
* BCrypt implements OpenBSD-style Blowfish password hashing using * BCrypt implements OpenBSD-style Blowfish password hashing using
* the scheme described in "A Future-Adaptable Password Scheme" by * the scheme described in "A Future-Adaptable Password Scheme" by
@ -60,7 +64,7 @@ import java.security.SecureRandom;
* @author Damien Miller * @author Damien Miller
* @version 0.2 * @version 0.2
*/ */
public class BCrypt { public class BCRYPT implements EncryptionMethod {
// BCrypt parameters // BCrypt parameters
private static final int GENSALT_DEFAULT_LOG2_ROUNDS = 10; private static final int GENSALT_DEFAULT_LOG2_ROUNDS = 10;
private static final int BCRYPT_SALT_LEN = 16; private static final int BCRYPT_SALT_LEN = 16;
@ -645,7 +649,7 @@ public class BCrypt {
* @return the hashed password * @return the hashed password
*/ */
public static String hashpw(String password, String salt) { public static String hashpw(String password, String salt) {
BCrypt B; BCRYPT B;
String real_salt; String real_salt;
byte passwordb[], saltb[], hashed[]; byte passwordb[], saltb[], hashed[];
char minor = (char)0; char minor = (char)0;
@ -677,7 +681,7 @@ public class BCrypt {
saltb = decode_base64(real_salt, BCRYPT_SALT_LEN); saltb = decode_base64(real_salt, BCRYPT_SALT_LEN);
B = new BCrypt(); B = new BCRYPT();
hashed = B.crypt_raw(passwordb, saltb, rounds); hashed = B.crypt_raw(passwordb, saltb, rounds);
rs.append("$2"); rs.append("$2");
@ -748,4 +752,17 @@ public class BCrypt {
public static boolean checkpw(String plaintext, String hashed) { public static boolean checkpw(String plaintext, String hashed) {
return (hashed.compareTo(hashpw(plaintext, hashed)) == 0); 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));
}
} }

View File

@ -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);
}
}

View File

@ -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));
}
}

View File

@ -0,0 +1,30 @@
package fr.xephi.authme.security.crypts;
import java.security.NoSuchAlgorithmException;
/**
* <p>Public interface for Custom Password encryption method</p>
* <p>The getHash function is called when we need to crypt the password (/register usually)</p>
* <p>The comparePassword is called when we need to match password (/login usually)</p>
*/
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;
}

View File

@ -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));
}
}

View File

@ -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));
}
}

View File

@ -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, ""));
}
}

View File

@ -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));
}
}

View File

@ -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));
}
}

View File

@ -2,17 +2,18 @@
* To change this template, choose Tools | Templates * To change this template, choose Tools | Templates
* and open the template in the editor. * 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.io.UnsupportedEncodingException;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/** /**
* *
* @author stefano * @author stefano
*/ */
public class PhpBB { public class PHPBB implements EncryptionMethod {
private static final int PHP_VERSION = 4; private static final int PHP_VERSION = 4;
private String itoa64 = private String itoa64 =
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
@ -157,4 +158,16 @@ private String _hash_gensalt_private(
} }
return buf.toString(); 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);
}
} }

View File

@ -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));
}
}

View File

@ -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);
}
}

View File

@ -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));
}
}

View File

@ -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, ""));
}
}

View File

@ -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));
}
}

View File

@ -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, ""));
}
}

View File

@ -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));
}
}

View File

@ -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));
}
}

View File

@ -1,4 +1,4 @@
package uk.org.whoami.authme.security; package fr.xephi.authme.security.crypts;
/** /**
* The Whirlpool hashing function. * The Whirlpool hashing function.
@ -57,9 +57,12 @@ package uk.org.whoami.authme.security;
* *
*/ */
import java.security.NoSuchAlgorithmException;
import java.util.Arrays; import java.util.Arrays;
class Whirlpool { public class WHIRLPOOL implements EncryptionMethod {
public WHIRLPOOL() {}
/** /**
* The message digest size (in bits) * The message digest size (in bits)
@ -178,9 +181,6 @@ class Whirlpool {
protected long[] block = new long[8]; protected long[] block = new long[8];
protected long[] state = new long[8]; protected long[] state = new long[8];
public Whirlpool() {
}
/** /**
* The core Whirlpool transform. * The core Whirlpool transform.
*/ */
@ -405,4 +405,20 @@ class Whirlpool {
} }
return String.valueOf(val); 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, ""));
}
} }

View File

@ -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);
}
}

View File

@ -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));
}
}

View File

@ -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<String> allMatches = new ArrayList<String>();
Matcher m = Pattern.compile(pattern).matcher(line);
while (m.find())
{
allMatches.add(m.group(1));
}
return allMatches.get(0);
}
}

View File

@ -1,4 +1,4 @@
package uk.org.whoami.authme.security.pbkdf2; package fr.xephi.authme.security.pbkdf2;
/** /**
* <p> * <p>

View File

@ -1,4 +1,4 @@
package uk.org.whoami.authme.security.pbkdf2; package fr.xephi.authme.security.pbkdf2;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;

View File

@ -1,4 +1,4 @@
package uk.org.whoami.authme.security.pbkdf2; package fr.xephi.authme.security.pbkdf2;
/** /**
* <p> * <p>

View File

@ -1,4 +1,4 @@
package uk.org.whoami.authme.security.pbkdf2; package fr.xephi.authme.security.pbkdf2;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;

View File

@ -1,4 +1,4 @@
package uk.org.whoami.authme.security.pbkdf2; package fr.xephi.authme.security.pbkdf2;
/** /**
* <p> * <p>

View File

@ -1,4 +1,4 @@
package uk.org.whoami.authme.security.pbkdf2; package fr.xephi.authme.security.pbkdf2;
/** /**
* <p> * <p>

View File

@ -1,4 +1,4 @@
package uk.org.whoami.authme.security.pbkdf2; package fr.xephi.authme.security.pbkdf2;
/** /**
* <p> * <p>

View File

@ -1,4 +1,4 @@
package uk.org.whoami.authme.security.pbkdf2; package fr.xephi.authme.security.pbkdf2;
/** /**
* <p> * <p>

View File

@ -1,4 +1,4 @@
package uk.org.whoami.authme.settings; package fr.xephi.authme.settings;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -29,7 +29,7 @@ public class CustomConfiguration extends YamlConfiguration{
super.load(configFile); super.load(configFile);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
Logger.getLogger(JavaPlugin.class.getName()).log(Level.SEVERE, "Could not find " + configFile.getName() + ", creating new one..."); Logger.getLogger(JavaPlugin.class.getName()).log(Level.SEVERE, "Could not find " + configFile.getName() + ", creating new one...");
reload(); reLoad();
} catch (IOException e) { } catch (IOException e) {
Logger.getLogger(JavaPlugin.class.getName()).log(Level.SEVERE, "Could not load " + configFile.getName(), e); Logger.getLogger(JavaPlugin.class.getName()).log(Level.SEVERE, "Could not load " + configFile.getName(), e);
} catch (InvalidConfigurationException e) { } catch (InvalidConfigurationException e) {
@ -37,7 +37,7 @@ public class CustomConfiguration extends YamlConfiguration{
} }
} }
public boolean reload() { public boolean reLoad() {
boolean out = true; boolean out = true;
if (!configFile.exists()) if (!configFile.exists())
{ {

View File

@ -1,20 +1,4 @@
/* package fr.xephi.authme.settings;
* Copyright 2011 Sebastian Köhler <sebkoehler@whoami.org.uk>.
*
* 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;
import java.io.File; import java.io.File;
@ -96,10 +80,17 @@ public class Messages extends CustomConfiguration {
if (loc != null) { if (loc != null) {
return loc.replace("&", "\u00a7"); 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) { if (singleton == null) {
singleton = new Messages(); singleton = new Messages();
} }

View File

@ -1,14 +1,15 @@
package uk.org.whoami.authme.settings; package fr.xephi.authme.settings;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
import org.bukkit.entity.Player;
/** /**
* *
* @author Xephi59 * @author Xephi59
*/ */
public class PlayersLogs extends CustomConfiguration { public class PlayersLogs extends CustomConfiguration {
private static PlayersLogs pllog = null; private static PlayersLogs pllog = null;
public static List<String> players; public static List<String> players;
@ -28,4 +29,12 @@ public class PlayersLogs extends CustomConfiguration {
return pllog; return pllog;
} }
public void addPlayer(Player player) {
List<String> players = this.getStringList("players");
if (!players.contains(player.getName())) {
players.add(player.getName());
this.set("players", players);
save();
}
}
} }

View File

@ -1,20 +1,4 @@
/* package fr.xephi.authme.settings;
* Copyright 2011 Sebastian Köhler <sebkoehler@whoami.org.uk>.
*
* 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;
import java.io.File; import java.io.File;
import java.io.InputStream; import java.io.InputStream;
@ -26,11 +10,11 @@ import org.bukkit.configuration.MemoryConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import uk.org.whoami.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import uk.org.whoami.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
import uk.org.whoami.authme.datasource.DataSource.DataSourceType; import fr.xephi.authme.datasource.DataSource.DataSourceType;
import uk.org.whoami.authme.security.PasswordSecurity; import fr.xephi.authme.security.HashAlgorithm;
import uk.org.whoami.authme.security.PasswordSecurity.HashAlgorithm;
public final class Settings extends YamlConfiguration { public final class Settings extends YamlConfiguration {
@ -60,7 +44,8 @@ public final class Settings extends YamlConfiguration {
getEnablePasswordVerifier, protectInventoryBeforeLogInEnabled, isBackupActivated, isBackupOnStart, getEnablePasswordVerifier, protectInventoryBeforeLogInEnabled, isBackupActivated, isBackupOnStart,
isBackupOnStop, enablePasspartu, isStopEnabled, reloadSupport, rakamakUseIp, noConsoleSpam, removePassword, displayOtherAccounts, isBackupOnStop, enablePasspartu, isStopEnabled, reloadSupport, rakamakUseIp, noConsoleSpam, removePassword, displayOtherAccounts,
useCaptcha, emailRegistration, multiverse, notifications, chestshop, bungee, banUnsafeIp, doubleEmailCheck, sessionExpireOnIpChange, 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, public static String getNickRegex, getUnloggedinGroup, getMySQLHost, getMySQLPort,
getMySQLUsername, getMySQLPassword, getMySQLDatabase, getMySQLTablename, getMySQLUsername, getMySQLPassword, getMySQLDatabase, getMySQLTablename,
@ -68,12 +53,13 @@ public final class Settings extends YamlConfiguration {
getMySQLColumnSalt, getMySQLColumnGroup, getMySQLColumnEmail, unRegisteredGroup, backupWindowsPath, getMySQLColumnSalt, getMySQLColumnGroup, getMySQLColumnEmail, unRegisteredGroup, backupWindowsPath,
getcUnrestrictedName, getRegisteredGroup, messagesLanguage, getMySQLlastlocX, getMySQLlastlocY, getMySQLlastlocZ, getcUnrestrictedName, getRegisteredGroup, messagesLanguage, getMySQLlastlocX, getMySQLlastlocY, getMySQLlastlocZ,
rakamakUsers, rakamakUsersIp, getmailAccount, getmailPassword, getmailSMTP, getMySQLColumnId, getmailSenderName, rakamakUsers, rakamakUsersIp, getmailAccount, getmailPassword, getmailSMTP, getMySQLColumnId, getmailSenderName,
getPredefinedSalt, getMailSubject, getMailText, getMySQLlastlocWorld; getMailSubject, getMailText, getMySQLlastlocWorld, defaultWorld,
getPhpbbPrefix, getWordPressPrefix;
public static int getWarnMessageInterval, getSessionTimeout, getRegistrationTimeout, getMaxNickLength, public static int getWarnMessageInterval, getSessionTimeout, getRegistrationTimeout, getMaxNickLength,
getMinNickLength, getPasswordMinLen, getMovementRadius, getmaxRegPerIp, getNonActivatedGroup, getMinNickLength, getPasswordMinLen, getMovementRadius, getmaxRegPerIp, getNonActivatedGroup,
passwordMaxLength, getRecoveryPassLength, getMailPort, maxLoginTry, captchaLength, saltLength, getmaxRegPerEmail, passwordMaxLength, getRecoveryPassLength, getMailPort, maxLoginTry, captchaLength, saltLength, getmaxRegPerEmail,
bCryptLog2Rounds; bCryptLog2Rounds, purgeDelay, getPhpbbGroup;
protected static YamlConfiguration configFile; protected static YamlConfiguration configFile;
@ -189,7 +175,6 @@ public void loadConfigOptions() {
displayOtherAccounts = configFile.getBoolean("settings.restrictions.displayOtherAccounts", true); displayOtherAccounts = configFile.getBoolean("settings.restrictions.displayOtherAccounts", true);
getMySQLColumnId = configFile.getString("DataSource.mySQLColumnId", "id"); getMySQLColumnId = configFile.getString("DataSource.mySQLColumnId", "id");
getmailSenderName = configFile.getString("Email.mailSenderName", ""); getmailSenderName = configFile.getString("Email.mailSenderName", "");
getPredefinedSalt = configFile.getString("Xenoforo.predefinedSalt", "");
useCaptcha = configFile.getBoolean("Security.captcha.useCaptcha", false); useCaptcha = configFile.getBoolean("Security.captcha.useCaptcha", false);
maxLoginTry = configFile.getInt("Security.captcha.maxLoginTry", 5); maxLoginTry = configFile.getInt("Security.captcha.maxLoginTry", 5);
captchaLength = configFile.getInt("Security.captcha.captchaLength", 5); captchaLength = configFile.getInt("Security.captcha.captchaLength", 5);
@ -208,10 +193,19 @@ public void loadConfigOptions() {
sessionExpireOnIpChange = configFile.getBoolean("settings.sessions.sessionExpireOnIpChange", false); sessionExpireOnIpChange = configFile.getBoolean("settings.sessions.sessionExpireOnIpChange", false);
useLogging = configFile.getBoolean("Security.console.logConsole", false); useLogging = configFile.getBoolean("Security.console.logConsole", false);
disableSocialSpy = configFile.getBoolean("Hooks.disableSocialSpy", true); disableSocialSpy = configFile.getBoolean("Hooks.disableSocialSpy", true);
useMultiThreading = configFile.getBoolean("Performances.useMultiThreading", false); useMultiThreading = configFile.getBoolean("Performances.useMultiThreading", true);
bCryptLog2Rounds = configFile.getInt("ExternalBoardOptions.bCryptLog2Round", 10); bCryptLog2Rounds = configFile.getInt("ExternalBoardOptions.bCryptLog2Round", 10);
forceOnlyAfterLogin = configFile.getBoolean("settings.GameMode.ForceOnlyAfterLogin", false); forceOnlyAfterLogin = configFile.getBoolean("settings.GameMode.ForceOnlyAfterLogin", false);
useEssentialsMotd = configFile.getBoolean("Hooks.useEssentialsMotd", 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(); saveDefaults();
} }
@ -314,7 +308,6 @@ public static void reloadConfigOptions(YamlConfiguration newConfig) {
displayOtherAccounts = configFile.getBoolean("settings.restrictions.displayOtherAccounts", true); displayOtherAccounts = configFile.getBoolean("settings.restrictions.displayOtherAccounts", true);
getMySQLColumnId = configFile.getString("DataSource.mySQLColumnId", "id"); getMySQLColumnId = configFile.getString("DataSource.mySQLColumnId", "id");
getmailSenderName = configFile.getString("Email.mailSenderName", ""); getmailSenderName = configFile.getString("Email.mailSenderName", "");
getPredefinedSalt = configFile.getString("Xenoforo.predefinedSalt", "");
useCaptcha = configFile.getBoolean("Security.captcha.useCaptcha", false); useCaptcha = configFile.getBoolean("Security.captcha.useCaptcha", false);
maxLoginTry = configFile.getInt("Security.captcha.maxLoginTry", 5); maxLoginTry = configFile.getInt("Security.captcha.maxLoginTry", 5);
captchaLength = configFile.getInt("Security.captcha.captchaLength", 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); sessionExpireOnIpChange = configFile.getBoolean("settings.sessions.sessionExpireOnIpChange", false);
useLogging = configFile.getBoolean("Security.console.logConsole", false); useLogging = configFile.getBoolean("Security.console.logConsole", false);
disableSocialSpy = configFile.getBoolean("Hooks.disableSocialSpy", true); disableSocialSpy = configFile.getBoolean("Hooks.disableSocialSpy", true);
useMultiThreading = configFile.getBoolean("Performances.useMultiThreading", false); useMultiThreading = configFile.getBoolean("Performances.useMultiThreading", true);
bCryptLog2Rounds = configFile.getInt("ExternalBoardOptions.bCryptLog2Round", 10); bCryptLog2Rounds = configFile.getInt("ExternalBoardOptions.bCryptLog2Round", 10);
forceOnlyAfterLogin = configFile.getBoolean("settings.GameMode.ForceOnlyAfterLogin", false); forceOnlyAfterLogin = configFile.getBoolean("settings.GameMode.ForceOnlyAfterLogin", false);
useEssentialsMotd = configFile.getBoolean("Hooks.useEssentialsMotd", 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() { public void mergeConfig() {
if (contains("settings.restrictions.allowedPluginTeleportHandler"))
set("settings.restrictions.allowedPluginTeleportHandler", null);
if(!contains("DataSource.mySQLColumnEmail")) if(!contains("DataSource.mySQLColumnEmail"))
set("DataSource.mySQLColumnEmail","email"); 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")) if(!contains("Email.RecoveryPasswordLength"))
set("Email.RecoveryPasswordLength", 8); set("Email.RecoveryPasswordLength", 8);
if(!contains("Email.mailPort")) if(!contains("Email.mailPort"))
@ -370,8 +362,6 @@ public void mergeConfig() {
set("DataSource.mySQLColumnId", "id"); set("DataSource.mySQLColumnId", "id");
if(!contains("Email.mailSenderName")) if(!contains("Email.mailSenderName"))
set("Email.mailSenderName", ""); set("Email.mailSenderName", "");
if(!contains("Xenoforo.predefinedSalt"))
set("Xenoforo.predefinedSalt", "");
if(!contains("Security.captcha.useCaptcha")) if(!contains("Security.captcha.useCaptcha"))
set("Security.captcha.useCaptcha", false); set("Security.captcha.useCaptcha", false);
if(!contains("Security.captcha.maxLoginTry")) if(!contains("Security.captcha.maxLoginTry"))
@ -415,7 +405,7 @@ public void mergeConfig() {
if(!contains("Hooks.disableSocialSpy")) if(!contains("Hooks.disableSocialSpy"))
set("Hooks.disableSocialSpy", true); set("Hooks.disableSocialSpy", true);
if(!contains("Performances.useMultiThreading")) if(!contains("Performances.useMultiThreading"))
set("Performances.useMultiThreading", false); set("Performances.useMultiThreading", true);
if(!contains("ExternalBoardOptions.bCryptLog2Round")) if(!contains("ExternalBoardOptions.bCryptLog2Round"))
set("ExternalBoardOptions.bCryptLog2Round", 10); set("ExternalBoardOptions.bCryptLog2Round", 10);
if(!contains("DataSource.mySQLlastlocWorld")) if(!contains("DataSource.mySQLlastlocWorld"))
@ -424,6 +414,25 @@ public void mergeConfig() {
set("settings.GameMode.ForceOnlyAfterLogin", false); set("settings.GameMode.ForceOnlyAfterLogin", false);
if(!contains("Hooks.useEssentialsMotd")) if(!contains("Hooks.useEssentialsMotd"))
set("Hooks.useEssentialsMotd", false); 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.getLogger().info("Merge new Config Options if needed..");
plugin.saveConfig(); plugin.saveConfig();
@ -434,10 +443,10 @@ public void mergeConfig() {
private static HashAlgorithm getPasswordHash() { private static HashAlgorithm getPasswordHash() {
String key = "settings.security.passwordHash"; String key = "settings.security.passwordHash";
try { try {
return PasswordSecurity.HashAlgorithm.valueOf(configFile.getString(key,"SHA256").toUpperCase()); return HashAlgorithm.valueOf(configFile.getString(key,"SHA256").toUpperCase());
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
ConsoleLogger.showError("Unknown Hash Algorithm; defaulting to SHA256"); 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"; String key = "Converter.Rakamak.newPasswordHash";
try { try {
return PasswordSecurity.HashAlgorithm.valueOf(configFile.getString(key,"SHA256").toUpperCase()); return HashAlgorithm.valueOf(configFile.getString(key,"SHA256").toUpperCase());
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
ConsoleLogger.showError("Unknown Hash Algorithm; defaulting to SHA256"); ConsoleLogger.showError("Unknown Hash Algorithm; defaulting to SHA256");
return PasswordSecurity.HashAlgorithm.SHA256; return HashAlgorithm.SHA256;
} }
} }

View File

@ -1,4 +1,4 @@
package uk.org.whoami.authme.settings; package fr.xephi.authme.settings;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -1,8 +1,5 @@
package uk.org.whoami.authme.settings; package fr.xephi.authme.settings;
/**
* @Author Hoezef
*/
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -1,28 +1,13 @@
/* package fr.xephi.authme.task;
* Copyright 2011 Sebastian Köhler <sebkoehler@whoami.org.uk>.
*
* 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;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitScheduler; import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import uk.org.whoami.authme.AuthMe; import fr.xephi.authme.AuthMe;
import uk.org.whoami.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerCache;
import uk.org.whoami.authme.cache.limbo.LimboCache; import fr.xephi.authme.cache.limbo.LimboCache;
public class MessageTask implements Runnable { public class MessageTask implements Runnable {

View File

@ -1,32 +1,17 @@
/* package fr.xephi.authme.task;
* Copyright 2011 Sebastian Köhler <sebkoehler@whoami.org.uk>.
*
* 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;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import uk.org.whoami.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import uk.org.whoami.authme.cache.backup.FileCache; import fr.xephi.authme.cache.auth.PlayerCache;
import uk.org.whoami.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.backup.FileCache;
import uk.org.whoami.authme.cache.limbo.LimboPlayer; import fr.xephi.authme.cache.limbo.LimboCache;
import uk.org.whoami.authme.cache.limbo.LimboCache; import fr.xephi.authme.cache.limbo.LimboPlayer;
import uk.org.whoami.authme.listener.AuthMePlayerListener; import fr.xephi.authme.listener.AuthMePlayerListener;
import uk.org.whoami.authme.settings.Messages; import fr.xephi.authme.settings.Messages;
public class TimeoutTask implements Runnable { public class TimeoutTask implements Runnable {

View File

@ -1,4 +1,4 @@
package uk.org.whoami.authme.threads; package fr.xephi.authme.threads;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.BufferedWriter; import java.io.BufferedWriter;
@ -10,19 +10,21 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import uk.org.whoami.authme.AuthMe; import fr.xephi.authme.AuthMe;
import uk.org.whoami.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import uk.org.whoami.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import uk.org.whoami.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
import uk.org.whoami.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
public class FlatFileThread extends Thread implements DataSource { public class FlatFileThread extends Thread implements DataSource {
/* file layout: /* file layout:
* *
* PLAYERNAME:HASHSUM:IP:LOGININMILLIESECONDS:COORDS * PLAYERNAME:HASHSUM:IP:LOGININMILLIESECONDS:LASTPOSX:LASTPOSY:LASTPOSZ:LASTPOSWORLD
* *
* Old but compatible: * Old but compatible:
* PLAYERNAME:HASHSUM:IP:LOGININMILLIESECONDS
* PLAYERNAME:HASHSUM:IP * PLAYERNAME:HASHSUM:IP
* PLAYERNAME:HASHSUM * PLAYERNAME:HASHSUM
* *
@ -81,13 +83,8 @@ public class FlatFileThread extends Thread implements DataSource {
} }
BufferedWriter bw = null; BufferedWriter bw = null;
try { 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 = 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"); bw.write(auth.getNickname() + ":" + auth.getHash() + ":" + auth.getIp() + ":" + auth.getLastLogin() + ":" + auth.getQuitLocX() + ":" + auth.getQuitLocY() + ":" + auth.getQuitLocZ() + ":" + auth.getWorld() + "\n");
}
} catch (IOException ex) { } catch (IOException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
@ -115,7 +112,24 @@ public class FlatFileThread extends Thread implements DataSource {
while ((line = br.readLine()) != null) { while ((line = br.readLine()) != null) {
String[] args = line.split(":"); String[] args = line.split(":");
if (args[0].equals(auth.getNickname())) { 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; break;
} }
} }
@ -151,7 +165,24 @@ public class FlatFileThread extends Thread implements DataSource {
while ((line = br.readLine()) != null) { while ((line = br.readLine()) != null) {
String[] args = line.split(":"); String[] args = line.split(":");
if (args[0].equals(auth.getNickname())) { 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; break;
} }
} }
@ -251,7 +282,7 @@ public class FlatFileThread extends Thread implements DataSource {
String line; String line;
while ((line = br.readLine()) != null) { while ((line = br.readLine()) != null) {
String[] args = line.split(":"); String[] args = line.split(":");
if (args.length == 4) { if (args.length >= 4) {
if (Long.parseLong(args[3]) >= until) { if (Long.parseLong(args[3]) >= until) {
lines.add(line); lines.add(line);
continue; continue;
@ -286,6 +317,54 @@ public class FlatFileThread extends Thread implements DataSource {
return cleared; return cleared;
} }
@Override
public List<String> autoPurgeDatabase(long until) {
BufferedReader br = null;
BufferedWriter bw = null;
ArrayList<String> lines = new ArrayList<String>();
List<String> cleared = new ArrayList<String>();
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 @Override
public synchronized boolean removeAuth(String user) { public synchronized boolean removeAuth(String user) {
if (!isAuthAvailable(user)) { if (!isAuthAvailable(user)) {

Some files were not shown because too many files have changed in this diff Show More