1
0
mirror of https://e.coding.net/circlecloud/AuthMe.git synced 2024-12-22 06:48:55 +00:00

代码清理...

Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
502647092 2015-12-12 10:58:05 +08:00
parent f9037706ee
commit aa5f01c3ed
10 changed files with 1363 additions and 236 deletions

View File

@ -62,14 +62,12 @@ public class PerformBackup {
if (isWin.indexOf("win") >= 0) { if (isWin.indexOf("win") >= 0) {
if (new File(windowsPath + "\\bin\\mysqldump.exe").exists()) { if (new File(windowsPath + "\\bin\\mysqldump.exe").exists()) {
return true; return true;
} else { }
ConsoleLogger.showError("Mysql Windows Path is incorrect please check it"); ConsoleLogger.showError("Mysql Windows Path is incorrect please check it");
return true; return true;
} }
} else {
return false; return false;
} }
}
private boolean FileBackup(final String backend) { private boolean FileBackup(final String backend) {
final File dirBackup = new File(AuthMe.getInstance().getDataFolder() + "/backups"); final File dirBackup = new File(AuthMe.getInstance().getDataFolder() + "/backups");
@ -102,9 +100,8 @@ public class PerformBackup {
if (processComplete == 0) { if (processComplete == 0) {
ConsoleLogger.info("备份创建成功."); ConsoleLogger.info("备份创建成功.");
return true; return true;
} else {
ConsoleLogger.showError("无法创建备份!");
} }
ConsoleLogger.showError("无法创建备份!");
} catch (final Exception ex) { } catch (final Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
@ -117,9 +114,8 @@ public class PerformBackup {
if (processComplete == 0) { if (processComplete == 0) {
ConsoleLogger.info("备份创建成功."); ConsoleLogger.info("备份创建成功.");
return true; return true;
} else {
ConsoleLogger.showError("无法创建备份!");
} }
ConsoleLogger.showError("无法创建备份!");
} catch (final Exception ex) { } catch (final Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }

View File

@ -195,7 +195,7 @@ public class AdminCommand implements CommandExecutor {
} }
}); });
return true; return true;
} else { }
final String[] arguments = args; final String[] arguments = args;
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
@Override @Override
@ -229,7 +229,6 @@ public class AdminCommand implements CommandExecutor {
} }
}); });
return true; return true;
}
} else if (args[0].equalsIgnoreCase("register") || args[0].equalsIgnoreCase("reg")) { } else if (args[0].equalsIgnoreCase("register") || args[0].equalsIgnoreCase("reg")) {
if (args.length != 3) { if (args.length != 3) {
sender.sendMessage("Usage: /authme register <playername> <password>"); sender.sendMessage("Usage: /authme register <playername> <password>");

View File

@ -122,9 +122,8 @@ public class UnregisterCommand implements CommandExecutor {
Utils.safeTP(player, spawn); Utils.safeTP(player, spawn);
} }
return; return;
} else {
m.send(player, "wrong_pwd");
} }
m.send(player, "wrong_pwd");
} catch (final NoSuchAlgorithmException ex) { } catch (final NoSuchAlgorithmException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
sender.sendMessage("Internal Error please read the server log"); sender.sendMessage("Internal Error please read the server log");

View File

@ -229,19 +229,16 @@ public class SQLite implements DataSource {
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 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)); .getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
} 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 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 .getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs
.getString(columnRealName)); .getString(columnRealName));
} 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), rs.getString(columnRealName));
} }
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 {
return null; return null;
}
} catch (final SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return null; return null;

View File

@ -260,19 +260,16 @@ public class SQLite_HIKARI implements DataSource {
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 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)); .getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs.getString(columnRealName));
} 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 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 .getLong(columnLastLogin), rs.getDouble(lastlocX), rs.getDouble(lastlocY), rs.getDouble(lastlocZ), rs.getString(lastlocWorld), rs.getString(columnEmail), rs
.getString(columnRealName)); .getString(columnRealName));
} 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), rs.getString(columnRealName));
} }
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 {
return null; return null;
}
} catch (final SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return null; return null;

View File

@ -276,12 +276,11 @@ public class AuthMePlayerListener implements Listener {
event.setKickMessage(m.send("antibot_no_register")[0]); event.setKickMessage(m.send("antibot_no_register")[0]);
event.setResult(PlayerLoginEvent.Result.KICK_OTHER); event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
return; return;
} else { }
event.setKickMessage(m.send("reg_only")[0]); event.setKickMessage(m.send("reg_only")[0]);
event.setResult(PlayerLoginEvent.Result.KICK_OTHER); event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
return; return;
} }
}
final int min = Settings.getMinNickLength; final int min = Settings.getMinNickLength;
final int max = Settings.getMaxNickLength; final int max = Settings.getMaxNickLength;

File diff suppressed because it is too large Load Diff

View File

@ -14,23 +14,23 @@ import java.security.NoSuchAlgorithmException;
*/ */
public class PHPBB implements EncryptionMethod { public class PHPBB implements EncryptionMethod {
private String itoa64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; private final String itoa64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
public static String md5(String data) { public static String md5(final String data) {
try { try {
byte[] bytes = data.getBytes("ISO-8859-1"); final byte[] bytes = data.getBytes("ISO-8859-1");
MessageDigest md5er = MessageDigest.getInstance("MD5"); final MessageDigest md5er = MessageDigest.getInstance("MD5");
byte[] hash = md5er.digest(bytes); final byte[] hash = md5er.digest(bytes);
return bytes2hex(hash); return bytes2hex(hash);
} catch (GeneralSecurityException | UnsupportedEncodingException e) { } catch (GeneralSecurityException | UnsupportedEncodingException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
private static String bytes2hex(byte[] bytes) { private static String bytes2hex(final byte[] bytes) {
StringBuilder r = new StringBuilder(32); final StringBuilder r = new StringBuilder(32);
for (byte b : bytes) { for (final byte b : bytes) {
String x = Integer.toHexString(b & 0xff); final String x = Integer.toHexString(b & 0xff);
if (x.length() < 2) if (x.length() < 2)
r.append("0"); r.append("0");
r.append(x); r.append(x);
@ -47,43 +47,42 @@ public class PHPBB implements EncryptionMethod {
throw new IllegalArgumentException("Not a hex character: " + ch); throw new IllegalArgumentException("Not a hex character: " + ch);
} }
static String pack(String hex) { static String pack(final String hex) {
StringBuilder buf = new StringBuilder(); final StringBuilder buf = new StringBuilder();
for (int i = 0; i < hex.length(); i += 2) { for (int i = 0; i < hex.length(); i += 2) {
char c1 = hex.charAt(i); final char c1 = hex.charAt(i);
char c2 = hex.charAt(i + 1); final char c2 = hex.charAt(i + 1);
char packed = (char) (hexToInt(c1) * 16 + hexToInt(c2)); final char packed = (char) (hexToInt(c1) * 16 + hexToInt(c2));
buf.append(packed); buf.append(packed);
} }
return buf.toString(); return buf.toString();
} }
@Override @Override
public boolean comparePassword(String hash, String password, String playerName) throws NoSuchAlgorithmException { public boolean comparePassword(final String hash, final String password, final String playerName) throws NoSuchAlgorithmException {
return phpbb_check_hash(password, hash); return phpbb_check_hash(password, hash);
} }
@Override @Override
public String getHash(String password, String salt, String name) throws NoSuchAlgorithmException { public String getHash(final String password, final String salt, final String name) throws NoSuchAlgorithmException {
return phpbb_hash(password, salt); return phpbb_hash(password, salt);
} }
public boolean phpbb_check_hash(String password, String hash) { public boolean phpbb_check_hash(final String password, final String hash) {
if (hash.length() == 34) if (hash.length() == 34)
return _hash_crypt_private(password, hash).equals(hash); return _hash_crypt_private(password, hash).equals(hash);
else
return md5(password).equals(hash); return md5(password).equals(hash);
} }
public String phpbb_hash(String password, String salt) { public String phpbb_hash(final String password, final String salt) {
String random_state = salt; String random_state = salt;
StringBuilder random = new StringBuilder(); final StringBuilder random = new StringBuilder();
int count = 6; final int count = 6;
for (int i = 0; i < count; i += 16) { for (int i = 0; i < count; i += 16) {
random_state = md5(salt + random_state); random_state = md5(salt + random_state);
random.append(pack(md5(random_state))); random.append(pack(md5(random_state)));
} }
String hash = _hash_crypt_private(password, _hash_gensalt_private(random.substring(0, count), itoa64)); final String hash = _hash_crypt_private(password, _hash_gensalt_private(random.substring(0, count), itoa64));
if (hash.length() == 34) { if (hash.length() == 34) {
return hash; return hash;
} }
@ -93,8 +92,8 @@ public class PHPBB implements EncryptionMethod {
/** /**
* Encode hash * Encode hash
*/ */
private String _hash_encode64(String input, int count) { private String _hash_encode64(final String input, final int count) {
StringBuilder output = new StringBuilder(); final StringBuilder output = new StringBuilder();
int i = 0; int i = 0;
do { do {
int value = input.charAt(i++); int value = input.charAt(i++);
@ -114,11 +113,11 @@ public class PHPBB implements EncryptionMethod {
return output.toString(); return output.toString();
} }
private String _hash_gensalt_private(String input, String itoa64) { private String _hash_gensalt_private(final String input, final String itoa64) {
return _hash_gensalt_private(input, itoa64, 6); return _hash_gensalt_private(input, itoa64, 6);
} }
private String _hash_gensalt_private(String input, String itoa64, int iteration_count_log2) { private String _hash_gensalt_private(final String input, final String itoa64, int iteration_count_log2) {
if (iteration_count_log2 < 4 || iteration_count_log2 > 31) { if (iteration_count_log2 < 4 || iteration_count_log2 > 31) {
iteration_count_log2 = 8; iteration_count_log2 = 8;
} }
@ -128,18 +127,18 @@ public class PHPBB implements EncryptionMethod {
return output; return output;
} }
String _hash_crypt_private(String password, String setting) { String _hash_crypt_private(final String password, final String setting) {
String output = "*"; String output = "*";
if (!setting.substring(0, 3).equals("$H$")) if (!setting.substring(0, 3).equals("$H$"))
return output; return output;
int count_log2 = itoa64.indexOf(setting.charAt(3)); final int count_log2 = itoa64.indexOf(setting.charAt(3));
if (count_log2 < 7 || count_log2 > 30) if (count_log2 < 7 || count_log2 > 30)
return output; return output;
int count = 1 << count_log2; int count = 1 << count_log2;
String salt = setting.substring(4, 12); final String salt = setting.substring(4, 12);
if (salt.length() != 8) if (salt.length() != 8)
return output; return output;
String m1 = md5(salt + password); final String m1 = md5(salt + password);
String hash = pack(m1); String hash = pack(m1);
do { do {
hash = pack(md5(hash + password)); hash = pack(md5(hash + password));

View File

@ -59,17 +59,13 @@ public class API {
public static Location getLastLocation(final Player player) { public static Location getLastLocation(final Player player) {
try { try {
final PlayerAuth auth = PlayerCache.getInstance().getAuth(player.getName().toLowerCase()); final PlayerAuth auth = PlayerCache.getInstance().getAuth(player.getName().toLowerCase());
if (auth != null) { if (auth != null) {
final Location loc = new Location(Bukkit.getWorld(auth.getWorld()), auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ()); final Location loc = new Location(Bukkit.getWorld(auth.getWorld()), auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ());
return loc; return loc;
} else {
return null;
} }
} catch (final NullPointerException ex) { } catch (final NullPointerException ex) {
return null;
} }
return null;
} }
/** /**

View File

@ -81,13 +81,10 @@ public class NewAPI {
if (auth != null) { if (auth != null) {
return new Location(Bukkit.getWorld(auth.getWorld()), auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ()); return new Location(Bukkit.getWorld(auth.getWorld()), auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ());
} else {
return null;
} }
} catch (final NullPointerException ex) { } catch (final NullPointerException ex) {
return null;
} }
return null;
} }
public AuthMe getPlugin() { public AuthMe getPlugin() {