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

View File

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

View File

@ -122,9 +122,8 @@ public class UnregisterCommand implements CommandExecutor {
Utils.safeTP(player, spawn);
}
return;
} else {
m.send(player, "wrong_pwd");
}
m.send(player, "wrong_pwd");
} catch (final NoSuchAlgorithmException ex) {
ConsoleLogger.showError(ex.getMessage());
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()) {
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 {
}
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), rs
.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;
}
} catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage());
return null;

View File

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

View File

@ -276,12 +276,11 @@ public class AuthMePlayerListener implements Listener {
event.setKickMessage(m.send("antibot_no_register")[0]);
event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
return;
} else {
}
event.setKickMessage(m.send("reg_only")[0]);
event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
return;
}
}
final int min = Settings.getMinNickLength;
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 {
private String itoa64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
private final String itoa64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
public static String md5(String data) {
public static String md5(final String data) {
try {
byte[] bytes = data.getBytes("ISO-8859-1");
MessageDigest md5er = MessageDigest.getInstance("MD5");
byte[] hash = md5er.digest(bytes);
final byte[] bytes = data.getBytes("ISO-8859-1");
final MessageDigest md5er = MessageDigest.getInstance("MD5");
final byte[] hash = md5er.digest(bytes);
return bytes2hex(hash);
} catch (GeneralSecurityException | UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
private static String bytes2hex(byte[] bytes) {
StringBuilder r = new StringBuilder(32);
for (byte b : bytes) {
String x = Integer.toHexString(b & 0xff);
private static String bytes2hex(final byte[] bytes) {
final StringBuilder r = new StringBuilder(32);
for (final byte b : bytes) {
final String x = Integer.toHexString(b & 0xff);
if (x.length() < 2)
r.append("0");
r.append(x);
@ -47,43 +47,42 @@ public class PHPBB implements EncryptionMethod {
throw new IllegalArgumentException("Not a hex character: " + ch);
}
static String pack(String hex) {
StringBuilder buf = new StringBuilder();
static String pack(final String hex) {
final StringBuilder buf = new StringBuilder();
for (int i = 0; i < hex.length(); i += 2) {
char c1 = hex.charAt(i);
char c2 = hex.charAt(i + 1);
char packed = (char) (hexToInt(c1) * 16 + hexToInt(c2));
final char c1 = hex.charAt(i);
final char c2 = hex.charAt(i + 1);
final char packed = (char) (hexToInt(c1) * 16 + hexToInt(c2));
buf.append(packed);
}
return buf.toString();
}
@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);
}
@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);
}
public boolean phpbb_check_hash(String password, String hash) {
public boolean phpbb_check_hash(final String password, final String hash) {
if (hash.length() == 34)
return _hash_crypt_private(password, hash).equals(hash);
else
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;
StringBuilder random = new StringBuilder();
int count = 6;
final StringBuilder random = new StringBuilder();
final int count = 6;
for (int i = 0; i < count; i += 16) {
random_state = md5(salt + 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) {
return hash;
}
@ -93,8 +92,8 @@ public class PHPBB implements EncryptionMethod {
/**
* Encode hash
*/
private String _hash_encode64(String input, int count) {
StringBuilder output = new StringBuilder();
private String _hash_encode64(final String input, final int count) {
final StringBuilder output = new StringBuilder();
int i = 0;
do {
int value = input.charAt(i++);
@ -114,11 +113,11 @@ public class PHPBB implements EncryptionMethod {
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);
}
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) {
iteration_count_log2 = 8;
}
@ -128,18 +127,18 @@ public class PHPBB implements EncryptionMethod {
return output;
}
String _hash_crypt_private(String password, String setting) {
String _hash_crypt_private(final String password, final String setting) {
String output = "*";
if (!setting.substring(0, 3).equals("$H$"))
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)
return output;
int count = 1 << count_log2;
String salt = setting.substring(4, 12);
final String salt = setting.substring(4, 12);
if (salt.length() != 8)
return output;
String m1 = md5(salt + password);
final String m1 = md5(salt + password);
String hash = pack(m1);
do {
hash = pack(md5(hash + password));

View File

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

View File

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