Remove Case dependance, auto-update name on join into database (care

forums users!)
This commit is contained in:
Xephi
2014-08-27 07:03:11 +02:00
parent 0d8ce9e3d8
commit 6cfd3f0a0b
37 changed files with 243 additions and 202 deletions
@@ -22,19 +22,19 @@ public class CacheDataSource implements DataSource {
@Override
public synchronized boolean isAuthAvailable(String user) {
if (cache.containsKey(user.toLowerCase()))
if (cache.containsKey(user))
return true;
return source.isAuthAvailable(user.toLowerCase());
return source.isAuthAvailable(user);
}
@Override
public synchronized PlayerAuth getAuth(String user) {
if (cache.containsKey(user.toLowerCase())) {
return cache.get(user.toLowerCase());
if (cache.containsKey(user)) {
return cache.get(user);
} else {
PlayerAuth auth = source.getAuth(user.toLowerCase());
PlayerAuth auth = source.getAuth(user);
if (auth != null)
cache.put(user.toLowerCase(), auth);
cache.put(user, auth);
return auth;
}
}
@@ -51,7 +51,7 @@ public class CacheDataSource implements DataSource {
@Override
public synchronized boolean updatePassword(PlayerAuth auth) {
if (source.updatePassword(auth)) {
if (cache.containsKey(auth.getNickname().toLowerCase()))
if (cache.containsKey(auth.getNickname()))
cache.get(auth.getNickname()).setHash(auth.getHash());
return true;
}
@@ -61,7 +61,7 @@ public class CacheDataSource implements DataSource {
@Override
public boolean updateSession(PlayerAuth auth) {
if (source.updateSession(auth)) {
if (cache.containsKey(auth.getNickname().toLowerCase())) {
if (cache.containsKey(auth.getNickname())) {
cache.get(auth.getNickname()).setIp(auth.getIp());
cache.get(auth.getNickname()).setLastLogin(auth.getLastLogin());
}
@@ -73,7 +73,7 @@ public class CacheDataSource implements DataSource {
@Override
public boolean updateQuitLoc(PlayerAuth auth) {
if (source.updateQuitLoc(auth)) {
if (cache.containsKey(auth.getNickname().toLowerCase())) {
if (cache.containsKey(auth.getNickname())) {
cache.get(auth.getNickname()).setQuitLocX(auth.getQuitLocX());
cache.get(auth.getNickname()).setQuitLocY(auth.getQuitLocY());
cache.get(auth.getNickname()).setQuitLocZ(auth.getQuitLocZ());
@@ -117,8 +117,8 @@ public class CacheDataSource implements DataSource {
@Override
public synchronized boolean removeAuth(String user) {
if (source.removeAuth(user.toLowerCase())) {
cache.remove(user.toLowerCase());
if (source.removeAuth(user)) {
cache.remove(user);
return true;
}
return false;
@@ -134,7 +134,7 @@ public class CacheDataSource implements DataSource {
cache.clear();
source.reload();
for (Player player : plugin.getServer().getOnlinePlayers()) {
String user = player.getName().toLowerCase();
String user = player.getName();
if (PlayerCache.getInstance().isAuthenticated(user)) {
try {
PlayerAuth auth = source.getAuth(user);
@@ -149,7 +149,7 @@ public class CacheDataSource implements DataSource {
@Override
public synchronized boolean updateEmail(PlayerAuth auth) {
if (source.updateEmail(auth)) {
if (cache.containsKey(auth.getNickname().toLowerCase()))
if (cache.containsKey(auth.getNickname()))
cache.get(auth.getNickname()).setEmail(auth.getEmail());
return true;
}
@@ -159,7 +159,7 @@ public class CacheDataSource implements DataSource {
@Override
public synchronized boolean updateSalt(PlayerAuth auth) {
if (source.updateSalt(auth)) {
if (cache.containsKey(auth.getNickname().toLowerCase()))
if (cache.containsKey(auth.getNickname()))
cache.get(auth.getNickname()).setSalt(auth.getSalt());
return true;
}
@@ -220,4 +220,13 @@ public class CacheDataSource implements DataSource {
public int getAccountsRegistered() {
return source.getAccountsRegistered();
}
@Override
public void updateName(String oldone, String newone) {
if (cache.containsKey(oldone)) {
cache.put(newone, cache.get(oldone));
cache.remove(oldone);
}
source.updateName(oldone, newone);
}
}
@@ -61,4 +61,6 @@ public interface DataSource {
int getAccountsRegistered();
void updateName(String oldone, String newone);
}
@@ -115,23 +115,23 @@ public class FlatFileThread extends Thread implements DataSource {
if (args[0].equals(auth.getNickname())) {
switch (args.length) {
case 4: {
newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), 0, 0, 0, "world", "your@email.com", API.getPlayerRealName(args[0]));
newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], Long.parseLong(args[3]), 0, 0, 0, "world", "your@email.com");
break;
}
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", API.getPlayerRealName(args[0]));
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");
break;
}
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", API.getPlayerRealName(args[0]));
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");
break;
}
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], API.getPlayerRealName(args[0]));
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]);
break;
}
default: {
newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], 0, 0, 0, 0, "world", "your@email.com", API.getPlayerRealName(args[0]));
newAuth = new PlayerAuth(args[0], auth.getHash(), args[2], 0, 0, 0, 0, "world", "your@email.com");
break;
}
}
@@ -172,23 +172,23 @@ public class FlatFileThread extends Thread implements DataSource {
if (args[0].equals(auth.getNickname())) {
switch (args.length) {
case 4: {
newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), 0, 0, 0, "world", "your@email.com", API.getPlayerRealName(args[0]));
newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), 0, 0, 0, "world", "your@email.com");
break;
}
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", API.getPlayerRealName(args[0]));
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");
break;
}
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", API.getPlayerRealName(args[0]));
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");
break;
}
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], API.getPlayerRealName(args[0]));
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]);
break;
}
default: {
newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), 0, 0, 0, "world", "your@email.com", API.getPlayerRealName(args[0]));
newAuth = new PlayerAuth(args[0], args[1], auth.getIp(), auth.getLastLogin(), 0, 0, 0, "world", "your@email.com");
break;
}
}
@@ -227,7 +227,7 @@ public class FlatFileThread extends Thread implements DataSource {
while ((line = br.readLine()) != null) {
String[] args = line.split(":");
if (args[0].equals(auth.getNickname())) {
newAuth = new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ(), auth.getWorld(), auth.getEmail(), API.getPlayerRealName(args[0]));
newAuth = new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ(), auth.getWorld(), auth.getEmail());
break;
}
}
@@ -427,17 +427,17 @@ public class FlatFileThread extends Thread implements DataSource {
if (args[0].equals(user)) {
switch (args.length) {
case 2:
return new PlayerAuth(args[0], args[1], "198.18.0.1", 0, "your@email.com", API.getPlayerRealName(args[0]));
return new PlayerAuth(args[0], args[1], "198.18.0.1", 0, "your@email.com");
case 3:
return new PlayerAuth(args[0], args[1], args[2], 0, "your@email.com", API.getPlayerRealName(args[0]));
return new PlayerAuth(args[0], args[1], args[2], 0, "your@email.com");
case 4:
return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), "your@email.com", API.getPlayerRealName(args[0]));
return new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), "your@email.com");
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", API.getPlayerRealName(args[0]));
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");
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", API.getPlayerRealName(args[0]));
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");
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], API.getPlayerRealName(args[0]));
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]);
}
}
}
@@ -479,7 +479,7 @@ public class FlatFileThread extends Thread implements DataSource {
while ((line = br.readLine()) != null) {
String[] args = line.split(":");
if (args[0].equals(auth.getNickname())) {
newAuth = new PlayerAuth(args[0], args[1], args[2], Long.parseLong(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), Double.parseDouble(args[6]), args[7], auth.getEmail(), API.getPlayerRealName(args[0]));
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());
break;
}
}
@@ -649,7 +649,7 @@ public class FlatFileThread extends Thread implements DataSource {
@Override
public boolean isLogged(String user) {
return PlayersLogs.getInstance().players.contains(user.toLowerCase());
return PlayersLogs.getInstance().players.contains(user);
}
@Override
@@ -692,4 +692,12 @@ public class FlatFileThread extends Thread implements DataSource {
}
return result;
}
@Override
public void updateName(String oldone, String newone) {
PlayerAuth auth = this.getAuth(oldone);
auth.setName(newone);
this.saveAuth(auth);
this.removeAuth(oldone);
}
}
@@ -205,14 +205,14 @@ public class MySQLThread extends Thread implements DataSource {
if (rs.next()) {
id = rs.getInt(columnID);
if (rs.getString(columnIp).isEmpty() && rs.getString(columnIp) != null) {
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "198.18.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), API.getPlayerRealName(rs.getString(columnName)));
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "198.18.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail));
} 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), API.getPlayerRealName(rs.getString(columnName)));
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), API.getPlayerRealName(rs.getString(columnName)));
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));
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(columnIp), rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), API.getPlayerRealName(rs.getString(columnName)));
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));
}
}
if (Settings.getPasswordHash == HashAlgorithm.XENFORO) {
@@ -268,7 +268,7 @@ public class MySQLThread extends Thread implements DataSource {
if (!columnOthers.isEmpty()) {
for (String column : columnOthers) {
pst = con.prepareStatement("UPDATE " + tableName + " SET " + column + "=? WHERE " + columnName + "=?;");
pst.setString(1, auth.getRealname());
pst.setString(1, auth.getNickname());
pst.setString(2, auth.getNickname());
pst.executeUpdate();
}
@@ -1018,4 +1018,27 @@ public class MySQLThread extends Thread implements DataSource {
return result;
}
@Override
public void updateName(String oldone, String newone) {
Connection con = null;
PreparedStatement pst = null;
try {
con = makeSureConnectionIsReady();
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnName + "=? WHERE " + columnName + "=?;");
pst.setString(1, newone);
pst.setString(2, oldone);
pst.executeUpdate();
} catch (SQLException ex) {
ConsoleLogger.showError(ex.getMessage());
return;
} catch (TimeoutException ex) {
ConsoleLogger.showError(ex.getMessage());
return;
} finally {
close(pst);
close(con);
}
return;
}
}
@@ -155,12 +155,12 @@ public class SQLiteThread extends Thread implements DataSource {
rs = pst.executeQuery();
if (rs.next()) {
if (rs.getString(columnIp).isEmpty()) {
return new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "198.18.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), API.getPlayerRealName(rs.getString(columnName)));
return new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "198.18.0.1", rs.getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail));
} else {
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), API.getPlayerRealName(rs.getString(columnName)));
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));
} 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), API.getPlayerRealName(rs.getString(columnName)));
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));
}
}
} else {
@@ -509,7 +509,7 @@ public class SQLiteThread extends Thread implements DataSource {
@Override
public boolean isLogged(String user) {
return PlayersLogs.getInstance().players.contains(user.toLowerCase());
return PlayersLogs.getInstance().players.contains(user);
}
@Override
@@ -549,4 +549,24 @@ public class SQLiteThread extends Thread implements DataSource {
}
return result;
}
@Override
public void updateName(String oldone, String newone) {
PreparedStatement pst = null;
try {
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnName + "=? WHERE " + columnName + "=?;");
pst.setString(1, newone);
pst.setString(2, oldone);
pst.executeUpdate();
} catch (SQLException ex) {
ConsoleLogger.showError(ex.getMessage());
return;
} catch (TimeoutException ex) {
ConsoleLogger.showError(ex.getMessage());
return;
} finally {
close(pst);
}
return;
}
}