update and cleanup PlayerAuth

This commit is contained in:
DNx5 2015-11-17 05:04:34 +07:00
parent 4a49809ff2
commit f6c6a7c6d4
2 changed files with 108 additions and 175 deletions

View File

@ -5,60 +5,52 @@ import fr.xephi.authme.settings.Settings;
public class PlayerAuth { public class PlayerAuth {
private String nickname = ""; private String nickname;
private String hash = ""; private String hash;
private String ip = "192.168.0.1"; private String ip;
private long lastLogin = 0; private long lastLogin;
private double x = 0; private double x;
private double y = 0; private double y;
private double z = 0; private double z;
private String world = "world"; private String world;
private String salt = ""; private String salt;
private String vBhash = null; private int groupId;
private int groupId = -1; private String email;
private String email = "your@email.com";
private String realName; private String realName;
public PlayerAuth(String nickname, String hash, String ip, long lastLogin, public PlayerAuth(String nickname, String ip, long lastLogin, String realName) {
String email, String realName) { this(nickname, "", "", -1, ip, lastLogin, 0, 0, 0, "world", "your@email.com", realName);
this.nickname = nickname;
this.hash = hash;
this.ip = ip;
this.lastLogin = lastLogin;
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 realName) {
String world, String realName) { this(nickname, "", "", -1, "127.0.0.1", System.currentTimeMillis(), x, y, z, world, "your@email.com", realName);
this.nickname = nickname;
this.x = x;
this.y = y;
this.z = z;
this.world = world;
this.realName = realName;
this.lastLogin = System.currentTimeMillis();
} }
public PlayerAuth(String nickname, String hash, String ip, long lastLogin, public PlayerAuth(String nickname, String hash, String ip, long lastLogin, String realName) {
double x, double y, double z, String world, String email, this(nickname, hash, "", -1, ip, lastLogin, 0, 0, 0, "world", "your@email.com", realName);
String realName) {
this.nickname = nickname;
this.hash = hash;
this.ip = ip;
this.lastLogin = lastLogin;
this.x = x;
this.y = y;
this.z = z;
this.world = world;
this.email = email;
this.realName = realName;
} }
public PlayerAuth(String nickname, String hash, String salt, int groupId, public PlayerAuth(String nickname, String hash, String ip, long lastLogin, String email, String realName) {
String ip, long lastLogin, double x, double y, double z, this(nickname, hash, "", -1, ip, lastLogin, 0, 0, 0, "world", email, realName);
String world, String email, String realName) { }
public PlayerAuth(String nickname, String hash, String salt, String ip, long lastLogin, String realName) {
this(nickname, hash, salt, -1, ip, lastLogin, 0, 0, 0, "world", "your@email.com", realName);
}
public PlayerAuth(String nickname, String hash, String ip, long lastLogin, double x, double y, double z, String world, String email, String realName) {
this(nickname, hash, "", -1, ip, lastLogin, x, y, z, world, email, realName);
}
public PlayerAuth(String nickname, String hash, String salt, String ip, long lastLogin, double x, double y, double z, String world, String email, String realName) {
this(nickname, hash, salt, -1, ip, lastLogin, x, y, z, world, email, realName);
}
public PlayerAuth(String nickname, String hash, String salt, int groupId, String ip, long lastLogin, String realName) {
this(nickname, hash, salt, groupId, ip, lastLogin, 0, 0, 0, "world", "your@email.com", realName);
}
public PlayerAuth(String nickname, String hash, String salt, int groupId, String ip, long lastLogin, double x, double y, double z, String world, String email, String realName) {
this.nickname = nickname; this.nickname = nickname;
this.hash = hash; this.hash = hash;
this.ip = ip; this.ip = ip;
@ -73,146 +65,117 @@ public class PlayerAuth {
this.realName = realName; this.realName = realName;
} }
public PlayerAuth(String nickname, String hash, String salt, int groupId, public void set(PlayerAuth auth) {
String ip, long lastLogin, String realName) { this.setEmail(auth.getEmail());
this.nickname = nickname; this.setHash(auth.getHash());
this.hash = hash; this.setIp(auth.getIp());
this.ip = ip; this.setLastLogin(auth.getLastLogin());
this.lastLogin = lastLogin; this.setName(auth.getNickname());
this.salt = salt; this.setQuitLocX(auth.getQuitLocX());
this.groupId = groupId; this.setQuitLocY(auth.getQuitLocY());
this.realName = realName; this.setQuitLocZ(auth.getQuitLocZ());
this.setSalt(auth.getSalt());
this.setWorld(auth.getWorld());
this.setRealName(auth.getRealName());
} }
public PlayerAuth(String nickname, String hash, String salt, String ip, public void setName(String nickname) {
long lastLogin, String realName) {
this.nickname = nickname; this.nickname = nickname;
this.hash = hash;
this.ip = ip;
this.lastLogin = lastLogin;
this.salt = salt;
this.realName = realName;
}
public PlayerAuth(String nickname, String hash, String salt, String ip,
long lastLogin, double x, double y, double z, String world,
String email, String realName) {
this.nickname = nickname;
this.hash = hash;
this.ip = ip;
this.lastLogin = lastLogin;
this.x = x;
this.y = y;
this.z = z;
this.world = world;
this.salt = salt;
this.email = email;
this.realName = realName;
}
public PlayerAuth(String nickname, String ip, long lastLogin,
String realName) {
this.nickname = nickname;
this.ip = ip;
this.lastLogin = lastLogin;
this.realName = realName;
}
public PlayerAuth(String nickname, String hash, String ip, long lastLogin,
String realName) {
this.nickname = nickname;
this.ip = ip;
this.lastLogin = lastLogin;
this.hash = hash;
this.realName = realName;
}
public String getIp() {
if (ip == null || ip.isEmpty())
ip = "127.0.0.1";
return ip;
} }
public String getNickname() { public String getNickname() {
return nickname; return nickname;
} }
public String getHash() { public String getRealName() {
if (Settings.getPasswordHash == HashAlgorithm.MD5VB) { return realName;
if (salt != null && !salt.isEmpty() && Settings.getPasswordHash == HashAlgorithm.MD5VB) {
vBhash = "$MD5vb$" + salt + "$" + hash;
return vBhash;
}
}
return hash;
} }
public String getSalt() { public void setRealName(String realName) {
return this.salt; this.realName = realName;
} }
public int getGroupId() { public int getGroupId() {
return groupId; return groupId;
} }
public double getQuitLocX() {
return x;
}
public double getQuitLocY() {
return y;
}
public double getQuitLocZ() {
return z;
}
public String getEmail() {
return email;
}
public void setQuitLocX(double d) { public void setQuitLocX(double d) {
this.x = d; this.x = d;
} }
public double getQuitLocX() {
return x;
}
public void setQuitLocY(double d) { public void setQuitLocY(double d) {
this.y = d; this.y = d;
} }
public double getQuitLocY() {
return y;
}
public void setQuitLocZ(double d) { public void setQuitLocZ(double d) {
this.z = d; this.z = d;
} }
public long getLastLogin() { public double getQuitLocZ() {
try { return z;
if (Long.valueOf(lastLogin) == null)
lastLogin = 0L;
} catch (NullPointerException e) {
lastLogin = 0L;
}
return lastLogin;
} }
public void setHash(String hash) { public void setWorld(String world) {
this.hash = hash; this.world = world;
}
public String getWorld() {
return world;
} }
public void setIp(String ip) { public void setIp(String ip) {
this.ip = ip; this.ip = ip;
} }
public String getIp() {
return ip;
}
public void setLastLogin(long lastLogin) { public void setLastLogin(long lastLogin) {
this.lastLogin = lastLogin; this.lastLogin = lastLogin;
} }
public long getLastLogin() {
return lastLogin;
}
public void setEmail(String email) { public void setEmail(String email) {
this.email = email; this.email = email;
} }
public String getEmail() {
return email;
}
public void setSalt(String salt) { public void setSalt(String salt) {
this.salt = salt; this.salt = salt;
} }
public String getSalt() {
return this.salt;
}
public void setHash(String hash) {
this.hash = hash;
}
public String getHash() {
if (Settings.getPasswordHash == HashAlgorithm.MD5VB) {
if (salt != null && !salt.isEmpty() && Settings.getPasswordHash == HashAlgorithm.MD5VB) {
return "$MD5vb$" + salt + "$" + hash;
}
}
return hash;
}
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (!(obj instanceof PlayerAuth)) { if (!(obj instanceof PlayerAuth)) {
@ -230,45 +193,15 @@ public class PlayerAuth {
return hashCode; return hashCode;
} }
public void setWorld(String world) {
this.world = world;
}
public String getWorld() {
return world;
}
@Override @Override
public String toString() { public String toString() {
String s = "Player : " + nickname + " | " + realName + " ! IP : " + ip + " ! LastLogin : " + lastLogin + " ! LastPosition : " + x + "," + y + "," + z + "," + world + " ! Email : " + email + " ! Hash : " + hash + " ! Salt : " + salt; return ("Player : " + nickname + " | " + realName
return s; + " ! IP : " + ip
+ " ! LastLogin : " + lastLogin
} + " ! LastPosition : " + x + "," + y + "," + z + "," + world
+ " ! Email : " + email
public void setName(String nickname) { + " ! Hash : " + hash
this.nickname = nickname; + " ! Salt : " + salt);
}
public void set(PlayerAuth auth) {
this.setEmail(auth.getEmail());
this.setHash(auth.getHash());
this.setIp(auth.getIp());
this.setLastLogin(auth.getLastLogin());
this.setName(auth.getNickname());
this.setQuitLocX(auth.getQuitLocX());
this.setQuitLocY(auth.getQuitLocY());
this.setQuitLocZ(auth.getQuitLocZ());
this.setSalt(auth.getSalt());
this.setWorld(auth.getWorld());
this.setRealName(auth.getRealName());
}
public String getRealName() {
return realName;
}
public void setRealName(String realName) {
this.realName = realName;
} }
} }

View File

@ -4,7 +4,7 @@ import java.util.concurrent.ConcurrentHashMap;
public class PlayerCache { public class PlayerCache {
private volatile static PlayerCache singleton = null; private volatile static PlayerCache singleton;
private ConcurrentHashMap<String, PlayerAuth> cache; private ConcurrentHashMap<String, PlayerAuth> cache;
private PlayerCache() { private PlayerCache() {