Merge pull request #11 from Xephi/master

Up
This commit is contained in:
Gabriele C. 2015-07-23 16:41:34 +02:00
commit 759bc8221e
21 changed files with 407 additions and 174 deletions

View File

@ -12,6 +12,7 @@ import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collection; import java.util.Collection;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -71,7 +72,6 @@ import fr.xephi.authme.plugin.manager.EssSpawn;
import fr.xephi.authme.process.Management; import fr.xephi.authme.process.Management;
import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.OtherAccounts; import fr.xephi.authme.settings.OtherAccounts;
import fr.xephi.authme.settings.PlayersLogs;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.Spawn; import fr.xephi.authme.settings.Spawn;
import net.milkbowl.vault.permission.Permission; import net.milkbowl.vault.permission.Permission;
@ -253,8 +253,6 @@ public class AuthMe extends JavaPlugin {
ConsoleLogger.showError("WARNING!!! By disabling ForceSingleSession, your server protection is inadequate!"); ConsoleLogger.showError("WARNING!!! By disabling ForceSingleSession, your server protection is inadequate!");
} }
PlayersLogs.getInstance();
if (Settings.reloadSupport) if (Settings.reloadSupport)
try { try {
int playersOnline = 0; int playersOnline = 0;
@ -269,7 +267,15 @@ public class AuthMe extends JavaPlugin {
database.purgeLogged(); database.purgeLogged();
} catch (NullPointerException npe) { } catch (NullPointerException npe) {
} }
} else PlayersLogs.getInstance().loadPlayers(); } else {
for (PlayerAuth auth : database.getLoggedPlayers()) {
if (auth == null)
continue;
auth.setLastLogin(new Date().getTime());
database.updateSession(auth);
PlayerCache.getInstance().addPlayer(auth);
}
}
} catch (Exception ex) { } catch (Exception ex) {
} }
@ -428,7 +434,10 @@ public class AuthMe extends JavaPlugin {
} }
if (database != null) { if (database != null) {
try {
database.close(); database.close();
} catch (Exception e) {
}
} }
if (Settings.isBackupActivated && Settings.isBackupOnStop) { if (Settings.isBackupActivated && Settings.isBackupOnStop) {
@ -444,8 +453,7 @@ public class AuthMe extends JavaPlugin {
return authme; return authme;
} }
public void savePlayer(Player player) public void savePlayer(Player player) {
throws IllegalStateException, NullPointerException {
try { try {
if ((citizens.isNPC(player)) || (Utils.getInstance().isUnrestricted(player)) || (CombatTagComunicator.isNPC(player))) { if ((citizens.isNPC(player)) || (Utils.getInstance().isUnrestricted(player)) || (CombatTagComunicator.isNPC(player))) {
return; return;
@ -455,7 +463,7 @@ public class AuthMe extends JavaPlugin {
try { try {
String name = player.getName().toLowerCase(); String name = player.getName().toLowerCase();
if (PlayerCache.getInstance().isAuthenticated(name) && !player.isDead() && Settings.isSaveQuitLocationEnabled) { if (PlayerCache.getInstance().isAuthenticated(name) && !player.isDead() && Settings.isSaveQuitLocationEnabled) {
final PlayerAuth auth = new PlayerAuth(player.getName().toLowerCase(), player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ(), player.getWorld().getName()); final PlayerAuth auth = new PlayerAuth(player.getName().toLowerCase(), player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ(), player.getWorld().getName(), player.getName());
database.updateQuitLoc(auth); database.updateQuitLoc(auth);
} }
if (LimboCache.getInstance().hasLimboPlayer(name)) { if (LimboCache.getInstance().hasLimboPlayer(name)) {

View File

@ -116,11 +116,9 @@ public class Utils {
public boolean isUnrestricted(Player player) { public boolean isUnrestricted(Player player) {
if (!Settings.isAllowRestrictedIp) if (!Settings.isAllowRestrictedIp)
return false; return false;
if (Settings.getUnrestrictedName.isEmpty() || Settings.getUnrestrictedName == null) if (Settings.getUnrestrictedName == null || Settings.getUnrestrictedName.isEmpty())
return false;
if (Settings.getUnrestrictedName.contains(player.getName()))
return true;
return false; return false;
return (Settings.getUnrestrictedName.contains(player.getName()));
} }
public static Utils getInstance() { public static Utils getInstance() {

View File

@ -17,30 +17,33 @@ public class PlayerAuth {
private String vBhash = null; private String vBhash = null;
private int groupId = -1; private int groupId = -1;
private String email = "your@email.com"; private String email = "your@email.com";
private String realName;
public PlayerAuth(String nickname, String hash, String ip, long lastLogin, public PlayerAuth(String nickname, String hash, String ip, long lastLogin,
String email) { String email, String realName) {
this.nickname = nickname; this.nickname = nickname;
this.hash = hash; this.hash = hash;
this.ip = ip; this.ip = ip;
this.lastLogin = lastLogin; this.lastLogin = lastLogin;
this.email = email; this.email = email;
this.realName = realName;
} }
public PlayerAuth(String nickname, double x, double y, double z, public PlayerAuth(String nickname, double x, double y, double z,
String world) { String world, String realName) {
this.nickname = nickname; this.nickname = nickname;
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
this.world = world; this.world = world;
this.realName = realName;
this.lastLogin = System.currentTimeMillis(); this.lastLogin = System.currentTimeMillis();
} }
public PlayerAuth(String nickname, String hash, String ip, long lastLogin, public PlayerAuth(String nickname, String hash, String ip, long lastLogin,
double x, double y, double z, String world, String email) { double x, double y, double z, String world, String email,
String realName) {
this.nickname = nickname; this.nickname = nickname;
this.hash = hash; this.hash = hash;
this.ip = ip; this.ip = ip;
@ -50,12 +53,12 @@ public class PlayerAuth {
this.z = z; this.z = z;
this.world = world; this.world = world;
this.email = email; this.email = email;
this.realName = realName;
} }
public PlayerAuth(String nickname, String hash, String salt, int groupId, public PlayerAuth(String nickname, String hash, String salt, int groupId,
String ip, long lastLogin, double x, double y, double z, String ip, long lastLogin, double x, double y, double z,
String world, String email) { String world, String email, String realName) {
this.nickname = nickname; this.nickname = nickname;
this.hash = hash; this.hash = hash;
this.ip = ip; this.ip = ip;
@ -67,33 +70,33 @@ public class PlayerAuth {
this.salt = salt; this.salt = salt;
this.groupId = groupId; this.groupId = groupId;
this.email = email; this.email = email;
this.realName = realName;
} }
public PlayerAuth(String nickname, String hash, String salt, int groupId, public PlayerAuth(String nickname, String hash, String salt, int groupId,
String ip, long lastLogin) { String ip, long lastLogin, String realName) {
this.nickname = nickname; this.nickname = nickname;
this.hash = hash; this.hash = hash;
this.ip = ip; this.ip = ip;
this.lastLogin = lastLogin; this.lastLogin = lastLogin;
this.salt = salt; this.salt = salt;
this.groupId = groupId; this.groupId = groupId;
this.realName = realName;
} }
public PlayerAuth(String nickname, String hash, String salt, String ip, public PlayerAuth(String nickname, String hash, String salt, String ip,
long lastLogin) { long lastLogin, String realName) {
this.nickname = nickname; this.nickname = nickname;
this.hash = hash; this.hash = hash;
this.ip = ip; this.ip = ip;
this.lastLogin = lastLogin; this.lastLogin = lastLogin;
this.salt = salt; this.salt = salt;
this.realName = realName;
} }
public PlayerAuth(String nickname, String hash, String salt, String ip, public PlayerAuth(String nickname, String hash, String salt, String ip,
long lastLogin, double x, double y, double z, String world, long lastLogin, double x, double y, double z, String world,
String email) { String email, String realName) {
this.nickname = nickname; this.nickname = nickname;
this.hash = hash; this.hash = hash;
this.ip = ip; this.ip = ip;
@ -104,21 +107,24 @@ public class PlayerAuth {
this.world = world; this.world = world;
this.salt = salt; this.salt = salt;
this.email = email; this.email = email;
this.realName = realName;
} }
public PlayerAuth(String nickname, String ip, long lastLogin) { public PlayerAuth(String nickname, String ip, long lastLogin,
String realName) {
this.nickname = nickname; this.nickname = nickname;
this.ip = ip; this.ip = ip;
this.lastLogin = lastLogin; this.lastLogin = lastLogin;
this.realName = realName;
} }
public PlayerAuth(String nickname, String hash, String ip, long lastLogin) { public PlayerAuth(String nickname, String hash, String ip, long lastLogin,
String realName) {
this.nickname = nickname; this.nickname = nickname;
this.ip = ip; this.ip = ip;
this.lastLogin = lastLogin; this.lastLogin = lastLogin;
this.hash = hash; this.hash = hash;
this.realName = realName;
} }
public String getIp() { public String getIp() {
@ -234,7 +240,7 @@ public class PlayerAuth {
@Override @Override
public String toString() { public String toString() {
String s = "Player : " + nickname + " ! IP : " + ip + " ! LastLogin : " + lastLogin + " ! LastPosition : " + x + "," + y + "," + z + "," + world + " ! Email : " + email + " ! Hash : " + hash + " ! Salt : " + salt; String s = "Player : " + nickname + " | " + realName + " ! IP : " + ip + " ! LastLogin : " + lastLogin + " ! LastPosition : " + x + "," + y + "," + z + "," + world + " ! Email : " + email + " ! Hash : " + hash + " ! Salt : " + salt;
return s; return s;
} }
@ -254,6 +260,15 @@ public class PlayerAuth {
this.setQuitLocZ(auth.getQuitLocZ()); this.setQuitLocZ(auth.getQuitLocZ());
this.setSalt(auth.getSalt()); this.setSalt(auth.getSalt());
this.setWorld(auth.getWorld()); this.setWorld(auth.getWorld());
this.setRealName(auth.getRealName());
}
public String getRealName() {
return realName;
}
public void setRealName(String realName) {
this.realName = realName;
} }
} }

View File

@ -61,7 +61,7 @@ public class CrazyLoginConverter implements Converter {
String psw = args[1]; String psw = args[1];
try { try {
if (player != null && psw != null) { if (player != null && psw != null) {
PlayerAuth auth = new PlayerAuth(player, psw, "127.0.0.1", System.currentTimeMillis()); PlayerAuth auth = new PlayerAuth(player, psw, "127.0.0.1", System.currentTimeMillis(), player);
database.saveAuth(auth); database.saveAuth(auth);
} }
} catch (Exception e) { } catch (Exception e) {

View File

@ -93,7 +93,7 @@ public class RakamakConverter implements Converter {
} else { } else {
ip = "127.0.0.1"; ip = "127.0.0.1";
} }
PlayerAuth auth = new PlayerAuth(player, psw, ip, System.currentTimeMillis()); PlayerAuth auth = new PlayerAuth(player, psw, ip, System.currentTimeMillis(), player);
if (PasswordSecurity.userSalt.containsKey(player)) if (PasswordSecurity.userSalt.containsKey(player))
auth.setSalt(PasswordSecurity.userSalt.get(player)); auth.setSalt(PasswordSecurity.userSalt.get(player));
database.saveAuth(auth); database.saveAuth(auth);

View File

@ -240,4 +240,9 @@ public class CacheDataSource implements DataSource {
public List<PlayerAuth> getAllAuths() { public List<PlayerAuth> getAllAuths() {
return source.getAllAuths(); return source.getAllAuths();
} }
@Override
public List<PlayerAuth> getLoggedPlayers() {
return source.getLoggedPlayers();
}
} }

View File

@ -65,4 +65,6 @@ public interface DataSource {
List<PlayerAuth> getAllAuths(); List<PlayerAuth> getAllAuths();
List<PlayerAuth> getLoggedPlayers();
} }

View File

@ -534,4 +534,25 @@ public class DatabaseCalls implements DataSource {
return result; return result;
} }
@Override
public List<PlayerAuth> getLoggedPlayers() {
ExecutorService executor = Executors.newSingleThreadExecutor();
List<PlayerAuth> result;
try {
result = executor.submit(new Callable<List<PlayerAuth>>() {
public List<PlayerAuth> call() throws Exception {
return database.getLoggedPlayers();
}
}).get();
} catch (InterruptedException e1) {
return (new ArrayList<PlayerAuth>());
} catch (ExecutionException e1) {
return (new ArrayList<PlayerAuth>());
} finally {
executor.shutdown();
}
return result;
}
} }

View File

@ -14,7 +14,6 @@ import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.settings.PlayersLogs;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
public class FlatFile implements DataSource { public class FlatFile implements DataSource {
@ -115,23 +114,23 @@ public class FlatFile implements DataSource {
if (args[0].equals(auth.getNickname())) { if (args[0].equals(auth.getNickname())) {
switch (args.length) { switch (args.length) {
case 4: { case 4: {
newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), 0, 0, 0, "world", "your@email.com"); newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), 0, 0, 0, "world", "your@email.com", args[0]);
break; break;
} }
case 7: { case 7: {
newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), "world", "your@email.com"); newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), "world", "your@email.com", args[0]);
break; break;
} }
case 8: { case 8: {
newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], "your@email.com"); newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], "your@email.com", args[0]);
break; break;
} }
case 9: { case 9: {
newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], args[8]); newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], args[8], args[0]);
break; break;
} }
default: { default: {
newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], 0, 0, 0, 0, "world", "your@email.com"); newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], 0, 0, 0, 0, "world", "your@email.com", args[0]);
break; break;
} }
} }
@ -174,23 +173,23 @@ public class FlatFile implements DataSource {
if (args[0].equalsIgnoreCase(auth.getNickname())) { if (args[0].equalsIgnoreCase(auth.getNickname())) {
switch (args.length) { switch (args.length) {
case 4: { case 4: {
newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), 0, 0, 0, "world", "your@email.com"); newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), 0, 0, 0, "world", "your@email.com", args[0]);
break; break;
} }
case 7: { case 7: {
newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), "world", "your@email.com"); newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), "world", "your@email.com", args[0]);
break; break;
} }
case 8: { case 8: {
newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], "your@email.com"); newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], "your@email.com", args[0]);
break; break;
} }
case 9: { case 9: {
newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], args[8]); newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], args[8], args[0]);
break; break;
} }
default: { default: {
newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), 0, 0, 0, "world", "your@email.com"); newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), 0, 0, 0, "world", "your@email.com", args[0]);
break; break;
} }
} }
@ -231,7 +230,7 @@ public class FlatFile implements DataSource {
while ((line = br.readLine()) != null) { while ((line = br.readLine()) != null) {
String[] args = line.split(":"); String[] args = line.split(":");
if (args[0].equalsIgnoreCase(auth.getNickname())) { if (args[0].equalsIgnoreCase(auth.getNickname())) {
newAuth = new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ(), auth.getWorld(), auth.getEmail()); newAuth = new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ(), auth.getWorld(), auth.getEmail(), args[0]);
break; break;
} }
} }
@ -433,17 +432,17 @@ public class FlatFile implements DataSource {
if (args[0].equalsIgnoreCase(user)) { if (args[0].equalsIgnoreCase(user)) {
switch (args.length) { switch (args.length) {
case 2: case 2:
return new PlayerAuth(args[0], args[1], "192.168.0.1", 0, "your@email.com"); return new PlayerAuth(args[0], args[1], "192.168.0.1", 0, "your@email.com", args[0]);
case 3: case 3:
return new PlayerAuth(args[0], args[1], args[2], 0, "your@email.com"); return new PlayerAuth(args[0], args[1], args[2], 0, "your@email.com", args[0]);
case 4: case 4:
return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), "your@email.com"); return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), "your@email.com", args[0]);
case 7: case 7:
return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), "unavailableworld", "your@email.com"); return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), "unavailableworld", "your@email.com", args[0]);
case 8: case 8:
return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], "your@email.com"); return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], "your@email.com", args[0]);
case 9: case 9:
return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], args[8]); return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], args[8], args[0]);
} }
} }
} }
@ -485,7 +484,7 @@ public class FlatFile 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], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], auth.getEmail()); newAuth = new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], auth.getEmail(), args[0]);
break; break;
} }
} }
@ -662,17 +661,14 @@ public class FlatFile implements DataSource {
@Override @Override
public void setLogged(String user) { public void setLogged(String user) {
PlayersLogs.getInstance().savePlayerLogs();
} }
@Override @Override
public void setUnlogged(String user) { public void setUnlogged(String user) {
PlayersLogs.getInstance().savePlayerLogs();
} }
@Override @Override
public void purgeLogged() { public void purgeLogged() {
PlayersLogs.getInstance().clear();
} }
@Override @Override
@ -717,17 +713,17 @@ public class FlatFile implements DataSource {
String[] args = line.split(":"); String[] args = line.split(":");
switch (args.length) { switch (args.length) {
case 2: case 2:
auths.add(new PlayerAuth(args[0], args[1], "192.168.0.1", 0, "your@email.com")); auths.add(new PlayerAuth(args[0], args[1], "192.168.0.1", 0, "your@email.com", args[0]));
case 3: case 3:
auths.add(new PlayerAuth(args[0], args[1], args[2], 0, "your@email.com")); auths.add(new PlayerAuth(args[0], args[1], args[2], 0, "your@email.com", args[0]));
case 4: case 4:
auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), "your@email.com")); auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), "your@email.com", args[0]));
case 7: case 7:
auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), "unavailableworld", "your@email.com")); auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), "unavailableworld", "your@email.com", args[0]));
case 8: case 8:
auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], "your@email.com")); auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], "your@email.com", args[0]));
case 9: case 9:
auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], args[8])); auths.add(new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], args[8], args[0]));
} }
} }
} catch (FileNotFoundException ex) { } catch (FileNotFoundException ex) {
@ -746,4 +742,9 @@ public class FlatFile implements DataSource {
} }
return auths; return auths;
} }
@Override
public List<PlayerAuth> getLoggedPlayers() {
return new ArrayList<PlayerAuth>();
}
} }

View File

@ -41,6 +41,7 @@ public class MySQL implements DataSource {
private String columnLogged; private String columnLogged;
private List<String> columnOthers; private List<String> columnOthers;
private MiniConnectionPoolManager conPool; private MiniConnectionPoolManager conPool;
private String columnRealName;
public MySQL() { public MySQL() {
this.host = Settings.getMySQLHost; this.host = Settings.getMySQLHost;
@ -63,6 +64,7 @@ public class MySQL implements DataSource {
this.columnOthers = Settings.getMySQLOtherUsernameColumn; this.columnOthers = Settings.getMySQLOtherUsernameColumn;
this.columnID = Settings.getMySQLColumnId; this.columnID = Settings.getMySQLColumnId;
this.columnLogged = Settings.getMySQLColumnLogged; this.columnLogged = Settings.getMySQLColumnLogged;
this.columnRealName = Settings.getMySQLColumnRealName;
try { try {
this.connect(); this.connect();
this.setup(); this.setup();
@ -157,6 +159,11 @@ public class MySQL implements DataSource {
if (rs.next()) { if (rs.next()) {
st.executeUpdate("ALTER TABLE " + tableName + " MODIFY " + lastlocX + " DOUBLE NOT NULL DEFAULT '0.0', MODIFY " + lastlocY + " DOUBLE NOT NULL DEFAULT '0.0', MODIFY " + lastlocZ + " DOUBLE NOT NULL DEFAULT '0.0';"); st.executeUpdate("ALTER TABLE " + tableName + " MODIFY " + lastlocX + " DOUBLE NOT NULL DEFAULT '0.0', MODIFY " + lastlocY + " DOUBLE NOT NULL DEFAULT '0.0', MODIFY " + lastlocZ + " DOUBLE NOT NULL DEFAULT '0.0';");
} }
rs.close();
rs = con.getMetaData().getColumns(null, null, tableName, columnRealName);
if (!rs.next()) {
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnRealName + " VARCHAR(255) DEFAULT 'Player' AFTER " + columnLogged + ";");
}
} finally { } finally {
close(rs); close(rs);
close(st); close(st);
@ -204,14 +211,14 @@ public class MySQL implements DataSource {
if (rs.next()) { if (rs.next()) {
id = rs.getInt(columnID); id = rs.getInt(columnID);
if (rs.getString(columnIp).isEmpty() && rs.getString(columnIp) != null) { if (rs.getString(columnIp).isEmpty() && rs.getString(columnIp) != null) {
pAuth = new PlayerAuth(rs.getString(columnName).toLowerCase(), rs.getString(columnPassword), "192.168.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail)); pAuth = new PlayerAuth(rs.getString(columnName).toLowerCase(), rs.getString(columnPassword), "192.168.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
} else { } else {
if (!columnSalt.isEmpty()) { if (!columnSalt.isEmpty()) {
if (!columnGroup.isEmpty()) if (!columnGroup.isEmpty())
pAuth = new PlayerAuth(rs.getString(columnName).toLowerCase(), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail)); pAuth = new PlayerAuth(rs.getString(columnName).toLowerCase(), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
else pAuth = new PlayerAuth(rs.getString(columnName).toLowerCase(), rs.getString(columnPassword), rs.getString(columnSalt), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail)); else pAuth = new PlayerAuth(rs.getString(columnName).toLowerCase(), rs.getString(columnPassword), rs.getString(columnSalt), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
} else { } else {
pAuth = new PlayerAuth(rs.getString(columnName).toLowerCase(), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail)); pAuth = new PlayerAuth(rs.getString(columnName).toLowerCase(), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
} }
} }
if (Settings.getPasswordHash == HashAlgorithm.XENFORO) { if (Settings.getPasswordHash == HashAlgorithm.XENFORO) {
@ -249,27 +256,29 @@ public class MySQL implements DataSource {
try { try {
con = makeSureConnectionIsReady(); con = makeSureConnectionIsReady();
if ((columnSalt == null || columnSalt.isEmpty()) || (auth.getSalt() == null || auth.getSalt().isEmpty())) { if ((columnSalt == null || columnSalt.isEmpty()) || (auth.getSalt() == null || auth.getSalt().isEmpty())) {
pst = con.prepareStatement("INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + ") VALUES (?,?,?,?);"); pst = con.prepareStatement("INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + "," + columnRealName + ") VALUES (?,?,?,?,?);");
pst.setString(1, auth.getNickname()); pst.setString(1, auth.getNickname());
pst.setString(2, auth.getHash()); pst.setString(2, auth.getHash());
pst.setString(3, auth.getIp()); pst.setString(3, auth.getIp());
pst.setLong(4, auth.getLastLogin()); pst.setLong(4, auth.getLastLogin());
pst.setString(5, auth.getRealName());
pst.executeUpdate(); pst.executeUpdate();
pst.close(); pst.close();
} else { } else {
pst = con.prepareStatement("INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + "," + columnSalt + ") VALUES (?,?,?,?,?);"); pst = con.prepareStatement("INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + "," + columnSalt + "," + columnRealName + ") VALUES (?,?,?,?,?,?);");
pst.setString(1, auth.getNickname()); pst.setString(1, auth.getNickname());
pst.setString(2, auth.getHash()); pst.setString(2, auth.getHash());
pst.setString(3, auth.getIp()); pst.setString(3, auth.getIp());
pst.setLong(4, auth.getLastLogin()); pst.setLong(4, auth.getLastLogin());
pst.setString(5, auth.getSalt()); pst.setString(5, auth.getSalt());
pst.setString(6, auth.getRealName());
pst.executeUpdate(); pst.executeUpdate();
pst.close(); pst.close();
} }
if (!columnOthers.isEmpty()) { if (!columnOthers.isEmpty()) {
for (String column : columnOthers) { for (String column : columnOthers) {
pst = con.prepareStatement("UPDATE " + tableName + " SET " + column + "=? WHERE " + columnName + "=?;"); pst = con.prepareStatement("UPDATE " + tableName + " SET " + column + "=? WHERE " + columnName + "=?;");
pst.setString(1, auth.getNickname()); pst.setString(1, auth.getRealName());
pst.setString(2, auth.getNickname()); pst.setString(2, auth.getNickname());
pst.executeUpdate(); pst.executeUpdate();
pst.close(); pst.close();
@ -338,72 +347,84 @@ public class MySQL implements DataSource {
pst.setString(2, "first_name"); pst.setString(2, "first_name");
pst.setString(3, ""); pst.setString(3, "");
pst.executeUpdate(); pst.executeUpdate();
pst.close();
// Last Name // Last Name
pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);");
pst.setInt(1, id); pst.setInt(1, id);
pst.setString(2, "last_name"); pst.setString(2, "last_name");
pst.setString(3, ""); pst.setString(3, "");
pst.executeUpdate(); pst.executeUpdate();
pst.close();
// Nick Name // Nick Name
pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);");
pst.setInt(1, id); pst.setInt(1, id);
pst.setString(2, "nickname"); pst.setString(2, "nickname");
pst.setString(3, auth.getNickname()); pst.setString(3, auth.getNickname());
pst.executeUpdate(); pst.executeUpdate();
pst.close();
// Description // Description
pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);");
pst.setInt(1, id); pst.setInt(1, id);
pst.setString(2, "description"); pst.setString(2, "description");
pst.setString(3, ""); pst.setString(3, "");
pst.executeUpdate(); pst.executeUpdate();
pst.close();
// Rich_Editing // Rich_Editing
pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);");
pst.setInt(1, id); pst.setInt(1, id);
pst.setString(2, "rich_editing"); pst.setString(2, "rich_editing");
pst.setString(3, "true"); pst.setString(3, "true");
pst.executeUpdate(); pst.executeUpdate();
pst.close();
// Comments_Shortcuts // Comments_Shortcuts
pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);");
pst.setInt(1, id); pst.setInt(1, id);
pst.setString(2, "comment_shortcuts"); pst.setString(2, "comment_shortcuts");
pst.setString(3, "false"); pst.setString(3, "false");
pst.executeUpdate(); pst.executeUpdate();
pst.close();
// admin_color // admin_color
pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);");
pst.setInt(1, id); pst.setInt(1, id);
pst.setString(2, "admin_color"); pst.setString(2, "admin_color");
pst.setString(3, "fresh"); pst.setString(3, "fresh");
pst.executeUpdate(); pst.executeUpdate();
pst.close();
// use_ssl // use_ssl
pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);");
pst.setInt(1, id); pst.setInt(1, id);
pst.setString(2, "use_ssl"); pst.setString(2, "use_ssl");
pst.setString(3, "0"); pst.setString(3, "0");
pst.executeUpdate(); pst.executeUpdate();
pst.close();
// show_admin_bar_front // show_admin_bar_front
pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);");
pst.setInt(1, id); pst.setInt(1, id);
pst.setString(2, "show_admin_bar_front"); pst.setString(2, "show_admin_bar_front");
pst.setString(3, "true"); pst.setString(3, "true");
pst.executeUpdate(); pst.executeUpdate();
pst.close();
// wp_capabilities // wp_capabilities
pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);");
pst.setInt(1, id); pst.setInt(1, id);
pst.setString(2, "wp_capabilities"); pst.setString(2, "wp_capabilities");
pst.setString(3, "a:1:{s:10:\"subscriber\";b:1;}"); pst.setString(3, "a:1:{s:10:\"subscriber\";b:1;}");
pst.executeUpdate(); pst.executeUpdate();
pst.close();
// wp_user_level // wp_user_level
pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);");
pst.setInt(1, id); pst.setInt(1, id);
pst.setString(2, "wp_user_level"); pst.setString(2, "wp_user_level");
pst.setString(3, "0"); pst.setString(3, "0");
pst.executeUpdate(); pst.executeUpdate();
pst.close();
// default_password_nag // default_password_nag
pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);"); pst = con.prepareStatement("INSERT INTO " + Settings.getWordPressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?);");
pst.setInt(1, id); pst.setInt(1, id);
pst.setString(2, "default_password_nag"); pst.setString(2, "default_password_nag");
pst.setString(3, ""); pst.setString(3, "");
pst.executeUpdate(); pst.executeUpdate();
pst.close();
} }
} }
if (Settings.getPasswordHash == HashAlgorithm.XENFORO) { if (Settings.getPasswordHash == HashAlgorithm.XENFORO) {
@ -424,6 +445,8 @@ public class MySQL implements DataSource {
pst.setBlob(3, blob); pst.setBlob(3, blob);
pst.executeUpdate(); pst.executeUpdate();
} }
if (rs != null && !rs.isClosed())
rs.close();
} }
} catch (SQLException ex) { } catch (SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
@ -470,6 +493,8 @@ public class MySQL implements DataSource {
pst.setInt(2, id); pst.setInt(2, id);
pst.executeUpdate(); pst.executeUpdate();
} }
if (rs != null && !rs.isClosed())
rs.close();
} }
} catch (SQLException ex) { } catch (SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
@ -1079,26 +1104,28 @@ public class MySQL implements DataSource {
PlayerAuth pAuth = null; PlayerAuth pAuth = null;
int id = rs.getInt(columnID); int id = rs.getInt(columnID);
if (rs.getString(columnIp).isEmpty() && rs.getString(columnIp) != null) { if (rs.getString(columnIp).isEmpty() && rs.getString(columnIp) != null) {
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "192.168.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail)); pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "192.168.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
} else { } else {
if (!columnSalt.isEmpty()) { if (!columnSalt.isEmpty()) {
if (!columnGroup.isEmpty()) if (!columnGroup.isEmpty())
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail)); pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
else pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail)); else pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
} else { } else {
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail)); pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
} }
} }
if (Settings.getPasswordHash == HashAlgorithm.XENFORO) { if (Settings.getPasswordHash == HashAlgorithm.XENFORO) {
rs.close(); ResultSet rsid = null;
pst = con.prepareStatement("SELECT * FROM xf_user_authenticate WHERE " + columnID + "=?;"); pst = con.prepareStatement("SELECT * FROM xf_user_authenticate WHERE " + columnID + "=?;");
pst.setInt(1, id); pst.setInt(1, id);
rs = pst.executeQuery(); rsid = pst.executeQuery();
if (rs.next()) { if (rsid.next()) {
Blob blob = rs.getBlob("data"); Blob blob = rsid.getBlob("data");
byte[] bytes = blob.getBytes(1, (int) blob.length()); byte[] bytes = blob.getBytes(1, (int) blob.length());
pAuth.setHash(new String(bytes)); pAuth.setHash(new String(bytes));
} }
if (rsid != null)
rsid.close();
} }
if (pAuth != null) if (pAuth != null)
auths.add(pAuth); auths.add(pAuth);
@ -1112,6 +1139,61 @@ public class MySQL implements DataSource {
} finally { } finally {
close(pst); close(pst);
close(con); close(con);
close(rs);
}
return auths;
}
@Override
public List<PlayerAuth> getLoggedPlayers() {
List<PlayerAuth> auths = new ArrayList<PlayerAuth>();
Connection con = null;
PreparedStatement pst = null;
ResultSet rs = null;
try {
con = makeSureConnectionIsReady();
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLogged + "=1;");
rs = pst.executeQuery();
while (rs.next()) {
PlayerAuth pAuth = null;
int id = rs.getInt(columnID);
if (rs.getString(columnIp).isEmpty() && rs.getString(columnIp) != null) {
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "192.168.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
} else {
if (!columnSalt.isEmpty()) {
if (!columnGroup.isEmpty())
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
else pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
} else {
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
}
}
if (Settings.getPasswordHash == HashAlgorithm.XENFORO) {
ResultSet rsid = null;
pst = con.prepareStatement("SELECT * FROM xf_user_authenticate WHERE " + columnID + "=?;");
pst.setInt(1, id);
rsid = pst.executeQuery();
if (rsid.next()) {
Blob blob = rsid.getBlob("data");
byte[] bytes = blob.getBytes(1, (int) blob.length());
pAuth.setHash(new String(bytes));
}
if (rsid != null)
rsid.close();
}
if (pAuth != null)
auths.add(pAuth);
}
} catch (SQLException ex) {
ConsoleLogger.showError(ex.getMessage());
return auths;
} catch (TimeoutException ex) {
ConsoleLogger.showError(ex.getMessage());
return auths;
} finally {
close(pst);
close(rs);
close(con);
} }
return auths; return auths;
} }

View File

@ -12,9 +12,7 @@ import java.util.List;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.datasource.MiniConnectionPoolManager.TimeoutException; import fr.xephi.authme.datasource.MiniConnectionPoolManager.TimeoutException;
import fr.xephi.authme.settings.PlayersLogs;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
public class SQLite implements DataSource { public class SQLite implements DataSource {
@ -34,6 +32,8 @@ public class SQLite implements DataSource {
private String columnEmail; private String columnEmail;
private String columnID; private String columnID;
private Connection con; private Connection con;
private String columnLogged;
private String columnRealName;
public SQLite() { public SQLite() {
this.database = Settings.getMySQLDatabase; this.database = Settings.getMySQLDatabase;
@ -50,6 +50,8 @@ public class SQLite implements DataSource {
this.lastlocWorld = Settings.getMySQLlastlocWorld; this.lastlocWorld = Settings.getMySQLlastlocWorld;
this.columnEmail = Settings.getMySQLColumnEmail; this.columnEmail = Settings.getMySQLColumnEmail;
this.columnID = Settings.getMySQLColumnId; this.columnID = Settings.getMySQLColumnId;
this.columnLogged = Settings.getMySQLColumnLogged;
this.columnRealName = Settings.getMySQLColumnRealName;
try { try {
this.connect(); this.connect();
@ -101,7 +103,7 @@ public class SQLite implements DataSource {
rs.close(); rs.close();
rs = con.getMetaData().getColumns(null, null, tableName, columnLastLogin); rs = con.getMetaData().getColumns(null, null, tableName, columnLastLogin);
if (!rs.next()) { if (!rs.next()) {
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnLastLogin + " BIGINT;"); st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnLastLogin + " BIGINT DEFAULT '0';");
} }
rs.close(); rs.close();
rs = con.getMetaData().getColumns(null, null, tableName, lastlocX); rs = con.getMetaData().getColumns(null, null, tableName, lastlocX);
@ -120,6 +122,16 @@ public class SQLite implements DataSource {
if (!rs.next()) { if (!rs.next()) {
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnEmail + " VARCHAR(255) DEFAULT 'your@email.com';"); st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnEmail + " VARCHAR(255) DEFAULT 'your@email.com';");
} }
rs.close();
rs = con.getMetaData().getColumns(null, null, tableName, columnLogged);
if (!rs.next()) {
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnLogged + " BIGINT DEFAULT '0';");
}
rs.close();
rs = con.getMetaData().getColumns(null, null, tableName, columnRealName);
if (!rs.next()) {
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnRealName + " VARCHAR(255) DEFAULT 'Player';");
}
} finally { } finally {
close(rs); close(rs);
close(st); close(st);
@ -155,12 +167,12 @@ public class SQLite implements DataSource {
rs = pst.executeQuery(); rs = pst.executeQuery();
if (rs.next()) { if (rs.next()) {
if (rs.getString(columnIp).isEmpty()) { if (rs.getString(columnIp).isEmpty()) {
return new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "192.168.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail)); return new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "192.168.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
} else { } else {
if (!columnSalt.isEmpty()) { if (!columnSalt.isEmpty()) {
return new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail)); return new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
} else { } else {
return new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail)); return new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
} }
} }
} else { } else {
@ -180,19 +192,21 @@ public class SQLite implements DataSource {
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
if (columnSalt.isEmpty() && auth.getSalt().isEmpty()) { if (columnSalt.isEmpty() && auth.getSalt().isEmpty()) {
pst = con.prepareStatement("INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + ") VALUES (?,?,?,?);"); pst = con.prepareStatement("INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + "," + columnRealName + ") VALUES (?,?,?,?,?);");
pst.setString(1, auth.getNickname()); pst.setString(1, auth.getNickname());
pst.setString(2, auth.getHash()); pst.setString(2, auth.getHash());
pst.setString(3, auth.getIp()); pst.setString(3, auth.getIp());
pst.setLong(4, auth.getLastLogin()); pst.setLong(4, auth.getLastLogin());
pst.setString(5, auth.getRealName());
pst.executeUpdate(); pst.executeUpdate();
} else { } else {
pst = con.prepareStatement("INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + "," + columnSalt + ") VALUES (?,?,?,?,?);"); pst = con.prepareStatement("INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + "," + columnSalt + "," + columnRealName + ") VALUES (?,?,?,?,?,?);");
pst.setString(1, auth.getNickname()); pst.setString(1, auth.getNickname());
pst.setString(2, auth.getHash()); pst.setString(2, auth.getHash());
pst.setString(3, auth.getIp()); pst.setString(3, auth.getIp());
pst.setLong(4, auth.getLastLogin()); pst.setLong(4, auth.getLastLogin());
pst.setString(5, auth.getSalt()); pst.setString(5, auth.getSalt());
pst.setString(6, auth.getRealName());
pst.executeUpdate(); pst.executeUpdate();
} }
} catch (SQLException ex) { } catch (SQLException ex) {
@ -225,10 +239,11 @@ public class SQLite implements DataSource {
public boolean updateSession(PlayerAuth auth) { public boolean updateSession(PlayerAuth auth) {
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnIp + "=?, " + columnLastLogin + "=? WHERE " + columnName + "=?;"); pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnIp + "=?, " + columnLastLogin + "=?, " + columnRealName + "=? WHERE " + columnName + "=?;");
pst.setString(1, auth.getIp()); pst.setString(1, auth.getIp());
pst.setLong(2, auth.getLastLogin()); pst.setLong(2, auth.getLastLogin());
pst.setString(3, auth.getNickname()); pst.setString(3, auth.getRealName());
pst.setString(4, auth.getNickname());
pst.executeUpdate(); pst.executeUpdate();
} catch (SQLException ex) { } catch (SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
@ -509,22 +524,86 @@ public class SQLite implements DataSource {
@Override @Override
public boolean isLogged(String user) { public boolean isLogged(String user) {
return PlayerCache.getInstance().isAuthenticated(user); PreparedStatement pst = null;
ResultSet rs = null;
try {
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;");
pst.setString(1, user);
rs = pst.executeQuery();
if (rs.next())
return (rs.getInt(columnLogged) == 1);
} catch (SQLException ex) {
ConsoleLogger.showError(ex.getMessage());
return false;
} catch (TimeoutException ex) {
ConsoleLogger.showError(ex.getMessage());
return false;
} finally {
close(rs);
close(pst);
}
return false;
} }
@Override @Override
public void setLogged(String user) { public void setLogged(String user) {
PlayersLogs.getInstance().savePlayerLogs(); PreparedStatement pst = null;
try {
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE LOWER(" + columnName + ")=?;");
pst.setInt(1, 1);
pst.setString(2, user);
pst.executeUpdate();
} catch (SQLException ex) {
ConsoleLogger.showError(ex.getMessage());
return;
} catch (TimeoutException ex) {
ConsoleLogger.showError(ex.getMessage());
return;
} finally {
close(pst);
}
return;
} }
@Override @Override
public void setUnlogged(String user) { public void setUnlogged(String user) {
PlayersLogs.getInstance().savePlayerLogs(); PreparedStatement pst = null;
if (user != null)
try {
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE LOWER(" + columnName + ")=?;");
pst.setInt(1, 0);
pst.setString(2, user);
pst.executeUpdate();
} catch (SQLException ex) {
ConsoleLogger.showError(ex.getMessage());
return;
} catch (TimeoutException ex) {
ConsoleLogger.showError(ex.getMessage());
return;
} finally {
close(pst);
}
return;
} }
@Override @Override
public void purgeLogged() { public void purgeLogged() {
PlayersLogs.getInstance().clear(); PreparedStatement pst = null;
try {
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE " + columnLogged + "=?;");
pst.setInt(1, 0);
pst.setInt(2, 1);
pst.executeUpdate();
} catch (SQLException ex) {
ConsoleLogger.showError(ex.getMessage());
return;
} catch (TimeoutException ex) {
ConsoleLogger.showError(ex.getMessage());
return;
} finally {
close(pst);
}
return;
} }
@Override @Override
@ -581,12 +660,46 @@ public class SQLite implements DataSource {
while (rs.next()) { while (rs.next()) {
PlayerAuth pAuth = null; PlayerAuth pAuth = null;
if (rs.getString(columnIp).isEmpty()) { if (rs.getString(columnIp).isEmpty()) {
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "127.0.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail)); pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "127.0.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
} else { } else {
if (!columnSalt.isEmpty()) { if (!columnSalt.isEmpty()) {
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail)); pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
} else { } else {
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail)); pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
}
}
if (pAuth != null)
auths.add(pAuth);
}
} catch (SQLException ex) {
ConsoleLogger.showError(ex.getMessage());
return auths;
} catch (TimeoutException ex) {
ConsoleLogger.showError(ex.getMessage());
return auths;
} finally {
close(pst);
}
return auths;
}
@Override
public List<PlayerAuth> getLoggedPlayers() {
List<PlayerAuth> auths = new ArrayList<PlayerAuth>();
PreparedStatement pst = null;
ResultSet rs = null;
try {
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLogged + "=1;");
rs = pst.executeQuery();
while (rs.next()) {
PlayerAuth pAuth = null;
if (rs.getString(columnIp).isEmpty()) {
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "127.0.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
} else {
if (!columnSalt.isEmpty()) {
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnSalt), rs.getInt(columnGroup), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
} else {
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), rs.getString(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
} }
} }
if (pAuth != null) if (pAuth != null)

View File

@ -827,7 +827,7 @@ public class AuthMePlayerListener implements Listener {
Location spawn = plugin.getSpawnLocation(player); Location spawn = plugin.getSpawnLocation(player);
if (Settings.isSaveQuitLocationEnabled && plugin.database.isAuthAvailable(name)) { if (Settings.isSaveQuitLocationEnabled && plugin.database.isAuthAvailable(name)) {
final PlayerAuth auth = new PlayerAuth(name, spawn.getX(), spawn.getY(), spawn.getZ(), spawn.getWorld().getName()); final PlayerAuth auth = new PlayerAuth(name, spawn.getX(), spawn.getY(), spawn.getZ(), spawn.getWorld().getName(), player.getName());
try { try {
plugin.database.updateQuitLoc(auth); plugin.database.updateQuitLoc(auth);
} catch (NullPointerException npe) { } catch (NullPointerException npe) {

View File

@ -0,0 +1,27 @@
package fr.xephi.authme.modules;
import fr.xephi.authme.AuthMe;
public interface Module {
public String getName();
public AuthMe getInstanceOfAuthMe();
public Module getInstance();
public enum ModuleType {
MANAGER,
MYSQL,
ACTIONS,
CONVERTERS,
EMAILS,
CUSTOM;
}
public ModuleType getType();
public boolean load();
public boolean unload();
}

View File

@ -100,6 +100,26 @@ public class AsyncronousJoin {
} }
final Location spawnLoc = plugin.getSpawnLocation(player); final Location spawnLoc = plugin.getSpawnLocation(player);
if (database.isAuthAvailable(name)) { if (database.isAuthAvailable(name)) {
PlayerAuth auth = database.getAuth(name);
if (!auth.getRealName().equals("Player") && !auth.getRealName().equals(player.getName())) {
final GameMode gM = AuthMePlayerListener.gameMode.get(name);
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
@Override
public void run() {
if (gM != null) {
AuthMePlayerListener.causeByAuthMe.put(name, true);
player.setGameMode(gM);
AuthMePlayerListener.causeByAuthMe.put(name, false);
}
player.kickPlayer("You are not the Owner of this account, please try another name!");
if (Settings.banUnsafeIp)
plugin.getServer().banIP(ip);
}
}, 1);
return;
}
if (Settings.isForceSurvivalModeEnabled && !Settings.forceOnlyAfterLogin) { if (Settings.isForceSurvivalModeEnabled && !Settings.forceOnlyAfterLogin) {
sched.scheduleSyncDelayedTask(plugin, new Runnable() { sched.scheduleSyncDelayedTask(plugin, new Runnable() {

View File

@ -50,11 +50,11 @@ public class AsyncronousLogin {
protected boolean needsCaptcha() { protected boolean needsCaptcha() {
if (Settings.useCaptcha) { if (Settings.useCaptcha) {
if (!plugin.captcha.containsKey(name)) { if (!plugin.captcha.containsKey(name)) {
plugin.captcha.put(name, 1); plugin.captcha.putIfAbsent(name, 1);
} else { } else {
int i = plugin.captcha.get(name) + 1; int i = plugin.captcha.get(name) + 1;
plugin.captcha.remove(name); plugin.captcha.remove(name);
plugin.captcha.put(name, i); plugin.captcha.putIfAbsent(name, i);
} }
if (plugin.captcha.containsKey(name) && plugin.captcha.get(name) >= Settings.maxLoginTry) { if (plugin.captcha.containsKey(name) && plugin.captcha.get(name) >= Settings.maxLoginTry) {
plugin.cap.put(name, rdm.nextString()); plugin.cap.put(name, rdm.nextString());
@ -133,7 +133,7 @@ public class AsyncronousLogin {
return; return;
} }
if (passwordVerified && player.isOnline()) { if (passwordVerified && player.isOnline()) {
PlayerAuth auth = new PlayerAuth(name, hash, getIP(), new Date().getTime(), email); PlayerAuth auth = new PlayerAuth(name, hash, getIP(), new Date().getTime(), email, realName);
database.updateSession(auth); database.updateSession(auth);
if (Settings.useCaptcha) { if (Settings.useCaptcha) {
@ -157,7 +157,7 @@ public class AsyncronousLogin {
} }
if (!Settings.noConsoleSpam) if (!Settings.noConsoleSpam)
ConsoleLogger.info(player.getName() + " logged in!"); ConsoleLogger.info(realName + " logged in!");
// makes player isLoggedin via API // makes player isLoggedin via API
PlayerCache.getInstance().addPlayer(auth); PlayerCache.getInstance().addPlayer(auth);
@ -178,7 +178,7 @@ public class AsyncronousLogin {
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, syncronousPlayerLogin); Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, syncronousPlayerLogin);
} else if (player.isOnline()) { } else if (player.isOnline()) {
if (!Settings.noConsoleSpam) if (!Settings.noConsoleSpam)
ConsoleLogger.info(player.getName() + " used the wrong password"); ConsoleLogger.info(realName + " used the wrong password");
if (Settings.isKickOnWrongPasswordEnabled) { if (Settings.isKickOnWrongPasswordEnabled) {
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {

View File

@ -51,13 +51,13 @@ public class AsyncronousQuit {
if (PlayerCache.getInstance().isAuthenticated(name) && !player.isDead()) { if (PlayerCache.getInstance().isAuthenticated(name) && !player.isDead()) {
if (Settings.isSaveQuitLocationEnabled && database.isAuthAvailable(name)) { if (Settings.isSaveQuitLocationEnabled && database.isAuthAvailable(name)) {
final PlayerAuth auth = new PlayerAuth(name, loc.getX(), loc.getY(), loc.getZ(), loc.getWorld().getName()); final PlayerAuth auth = new PlayerAuth(name, loc.getX(), loc.getY(), loc.getZ(), loc.getWorld().getName(), player.getName());
try { try {
database.updateQuitLoc(auth); database.updateQuitLoc(auth);
} catch (NullPointerException npe) { } catch (NullPointerException npe) {
} }
} }
PlayerAuth auth = new PlayerAuth(name, ip, System.currentTimeMillis()); PlayerAuth auth = new PlayerAuth(name, ip, System.currentTimeMillis(), player.getName());
database.updateSession(auth); database.updateSession(auth);
} }

View File

@ -12,7 +12,6 @@ import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.PlayersLogs;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
public class AsyncronousRegister { public class AsyncronousRegister {
@ -77,7 +76,6 @@ public class AsyncronousRegister {
else if (database.isAuthAvailable(name)) { else if (database.isAuthAvailable(name)) {
m.send(player, "user_regged"); m.send(player, "user_regged");
PlayersLogs.getInstance().savePlayerLogs();
allowRegister = false; allowRegister = false;
} }
@ -117,7 +115,7 @@ public class AsyncronousRegister {
PlayerAuth auth = null; PlayerAuth auth = null;
try { try {
final String hashnew = PasswordSecurity.getHash(Settings.getPasswordHash, password, name); final String hashnew = PasswordSecurity.getHash(Settings.getPasswordHash, password, name);
auth = new PlayerAuth(name, hashnew, getIp(), 0, (int) player.getLocation().getX(), (int) player.getLocation().getY(), (int) player.getLocation().getZ(), player.getLocation().getWorld().getName(), email); auth = new PlayerAuth(name, hashnew, getIp(), 0, (int) player.getLocation().getX(), (int) player.getLocation().getY(), (int) player.getLocation().getZ(), player.getLocation().getWorld().getName(), email, player.getName());
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
ConsoleLogger.showError(e.getMessage()); ConsoleLogger.showError(e.getMessage());
m.send(player, "error"); m.send(player, "error");
@ -146,9 +144,9 @@ public class AsyncronousRegister {
return; return;
} }
if (Settings.getMySQLColumnSalt.isEmpty() && !PasswordSecurity.userSalt.containsKey(name)) { if (Settings.getMySQLColumnSalt.isEmpty() && !PasswordSecurity.userSalt.containsKey(name)) {
auth = new PlayerAuth(name, hash, getIp(), new Date().getTime(), "your@email.com"); auth = new PlayerAuth(name, hash, getIp(), new Date().getTime(), "your@email.com", player.getName());
} else { } else {
auth = new PlayerAuth(name, hash, PasswordSecurity.userSalt.get(name), getIp(), new Date().getTime()); auth = new PlayerAuth(name, hash, PasswordSecurity.userSalt.get(name), getIp(), new Date().getTime(), player.getName());
} }
if (!database.saveAuth(auth)) { if (!database.saveAuth(auth)) {
m.send(player, "error"); m.send(player, "error");

View File

@ -18,7 +18,6 @@ import fr.xephi.authme.events.LoginEvent;
import fr.xephi.authme.events.RegisterTeleportEvent; import fr.xephi.authme.events.RegisterTeleportEvent;
import fr.xephi.authme.events.RestoreInventoryEvent; import fr.xephi.authme.events.RestoreInventoryEvent;
import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.PlayersLogs;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.task.MessageTask; import fr.xephi.authme.task.MessageTask;
import fr.xephi.authme.task.TimeoutTask; import fr.xephi.authme.task.TimeoutTask;
@ -73,7 +72,6 @@ public class ProcessSyncronousPasswordRegister implements Runnable {
BukkitTask msgT = sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, m.send("login_msg"), interval)); BukkitTask msgT = sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, m.send("login_msg"), interval));
LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT); LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT);
try { try {
PlayersLogs.getInstance().save();
if (player.isInsideVehicle()) if (player.isInsideVehicle())
player.getVehicle().eject(); player.getVehicle().eject();
} catch (NullPointerException npe) { } catch (NullPointerException npe) {

View File

@ -1,64 +0,0 @@
package fr.xephi.authme.settings;
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.datasource.DataSource;
/**
*
* @author Xephi59
*/
public class PlayersLogs extends CustomConfiguration {
private static PlayersLogs pllog = null;
public PlayersLogs() {
super(new File("." + File.separator + "plugins" + File.separator + "AuthMe" + File.separator + "players.yml"));
pllog = this;
load();
save();
}
public void loadPlayers() {
DataSource database = AuthMe.getInstance().database;
List<String> list = this.getStringList("players");
if (list == null || list.isEmpty())
return;
for (String s : list) {
PlayerAuth auth = database.getAuth(s);
if (auth == null)
continue;
auth.setLastLogin(new Date().getTime());
database.updateSession(auth);
PlayerCache.getInstance().addPlayer(auth);
}
}
public static PlayersLogs getInstance() {
if (pllog == null) {
pllog = new PlayersLogs();
}
return pllog;
}
public void savePlayerLogs() {
List<String> players = new ArrayList<String>();
for (String s : PlayerCache.getInstance().getCache().keySet()) {
players.add(s);
}
this.set("players", players);
this.save();
}
public void clear() {
this.set("players", new ArrayList<String>());
this.save();
}
}

View File

@ -82,7 +82,8 @@ public final class Settings extends YamlConfiguration {
getmailPassword, getmailSMTP, getMySQLColumnId, getmailSenderName, getmailPassword, getmailSMTP, getMySQLColumnId, getmailSenderName,
getMailSubject, getMailText, getMySQLlastlocWorld, defaultWorld, getMailSubject, getMailText, getMySQLlastlocWorld, defaultWorld,
getPhpbbPrefix, getWordPressPrefix, getMySQLColumnLogged, getPhpbbPrefix, getWordPressPrefix, getMySQLColumnLogged,
spawnPriority, crazyloginFileName, getPassRegex; spawnPriority, crazyloginFileName, getPassRegex,
getMySQLColumnRealName;
public static int getWarnMessageInterval, getSessionTimeout, public static int getWarnMessageInterval, getSessionTimeout,
getRegistrationTimeout, getMaxNickLength, getMinNickLength, getRegistrationTimeout, getMaxNickLength, getMinNickLength,
@ -161,6 +162,7 @@ public final class Settings extends YamlConfiguration {
getMySQLlastlocY = configFile.getString("DataSource.mySQLlastlocY", "y"); getMySQLlastlocY = configFile.getString("DataSource.mySQLlastlocY", "y");
getMySQLlastlocZ = configFile.getString("DataSource.mySQLlastlocZ", "z"); getMySQLlastlocZ = configFile.getString("DataSource.mySQLlastlocZ", "z");
getMySQLlastlocWorld = configFile.getString("DataSource.mySQLlastlocWorld", "world"); getMySQLlastlocWorld = configFile.getString("DataSource.mySQLlastlocWorld", "world");
getMySQLColumnRealName = configFile.getString("DataSource.mySQLRealName", "realname");
getNonActivatedGroup = configFile.getInt("ExternalBoardOptions.nonActivedUserGroup", -1); getNonActivatedGroup = configFile.getInt("ExternalBoardOptions.nonActivedUserGroup", -1);
unRegisteredGroup = configFile.getString("GroupOptions.UnregisteredPlayerGroup", ""); unRegisteredGroup = configFile.getString("GroupOptions.UnregisteredPlayerGroup", "");
getUnrestrictedName = configFile.getStringList("settings.unrestrictions.UnrestrictedName"); getUnrestrictedName = configFile.getStringList("settings.unrestrictions.UnrestrictedName");
@ -328,6 +330,7 @@ public final class Settings extends YamlConfiguration {
getMySQLlastlocY = configFile.getString("DataSource.mySQLlastlocY", "y"); getMySQLlastlocY = configFile.getString("DataSource.mySQLlastlocY", "y");
getMySQLlastlocZ = configFile.getString("DataSource.mySQLlastlocZ", "z"); getMySQLlastlocZ = configFile.getString("DataSource.mySQLlastlocZ", "z");
getMySQLlastlocWorld = configFile.getString("DataSource.mySQLlastlocWorld", "world"); getMySQLlastlocWorld = configFile.getString("DataSource.mySQLlastlocWorld", "world");
getMySQLColumnRealName = configFile.getString("DataSource.mySQLRealName", "realname");
getNonActivatedGroup = configFile.getInt("ExternalBoardOptions.nonActivedUserGroup", -1); getNonActivatedGroup = configFile.getInt("ExternalBoardOptions.nonActivedUserGroup", -1);
unRegisteredGroup = configFile.getString("GroupOptions.UnregisteredPlayerGroup", ""); unRegisteredGroup = configFile.getString("GroupOptions.UnregisteredPlayerGroup", "");
getUnrestrictedName = configFile.getStringList("settings.unrestrictions.UnrestrictedName"); getUnrestrictedName = configFile.getStringList("settings.unrestrictions.UnrestrictedName");
@ -592,6 +595,10 @@ public final class Settings extends YamlConfiguration {
set("Email.generateImage", true); set("Email.generateImage", true);
changes = true; changes = true;
} }
if (!contains("DataSource.mySQLRealName")) {
set("DataSource.mySQLRealName", "realname");
changes = true;
}
if (changes) { if (changes) {
plugin.getLogger().warning("Merge new Config Options - I'm not an error, please don't report me"); plugin.getLogger().warning("Merge new Config Options - I'm not an error, please don't report me");

View File

@ -37,6 +37,8 @@ DataSource:
mySQLlastlocZ: z mySQLlastlocZ: z
# Column for SaveQuitLocation - World name # Column for SaveQuitLocation - World name
mySQLlastlocWorld: world mySQLlastlocWorld: world
# Column for RealName
mySQLRealName: realname
GroupOptions: GroupOptions:
# if you want to set up a particulary Permission Group for # if you want to set up a particulary Permission Group for
# users that arent registered yet. Pay attention this option # users that arent registered yet. Pay attention this option