1
0
mirror of https://e.coding.net/circlecloud/AuthMe.git synced 2025-11-24 21:26:20 +00:00

Translation message and clean up ...

Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
502647092
2015-10-12 16:32:54 +08:00
parent 497b0154b2
commit 2480d905f2
7 changed files with 190 additions and 156 deletions

View File

@@ -408,7 +408,7 @@ public class AuthMe extends JavaPlugin {
if (Settings.isBackupActivated && Settings.isBackupOnStart) { if (Settings.isBackupActivated && Settings.isBackupOnStart) {
// Do backup and check return value! // Do backup and check return value!
if (new PerformBackup(this).doBackup()) { if (new PerformBackup(this).doBackup()) {
ConsoleLogger.info("数据备份完成"); ConsoleLogger.info("数据备份完成...");
} else { } else {
ConsoleLogger.showError("Error while performing the backup!"); ConsoleLogger.showError("Error while performing the backup!");
} }
@@ -420,7 +420,7 @@ public class AuthMe extends JavaPlugin {
} catch (final Exception e) { } catch (final Exception e) {
ConsoleLogger.writeStackTrace(e); ConsoleLogger.writeStackTrace(e);
ConsoleLogger.showError(e.getMessage()); ConsoleLogger.showError(e.getMessage());
ConsoleLogger.showError("连接数据库期间发生错误! Authme 初始化 中断 关闭服务器!"); ConsoleLogger.showError("连接数据库期间发生错误! Authme 初始化 中断!");
stopOrUnload(); stopOrUnload();
return; return;
} }
@@ -587,20 +587,17 @@ public class AuthMe extends JavaPlugin {
isSQLite = true; isSQLite = true;
break; break;
} }
if (isSQLite) { if (isSQLite) {
server.getScheduler().runTaskAsynchronously(this, new Runnable() { server.getScheduler().runTaskAsynchronously(this, new Runnable() {
@Override @Override
public void run() { public void run() {
final int accounts = database.getAccountsRegistered(); final int accounts = database.getAccountsRegistered();
if (accounts >= 4000) { if (accounts >= 4000) {
ConsoleLogger.showError("YOU'RE USING THE SQLITE DATABASE WITH " + accounts + "+ ACCOUNTS, FOR BETTER PERFORMANCES, PLEASE UPGRADE TO MYSQL!!"); ConsoleLogger.showError("您使用 SQLite 存储了超过 " + accounts + " 个账户, 为了获得更好的性能, 建议使用MySQL!!!");
} }
} }
}); });
} }
if (Settings.isCachingEnabled) { if (Settings.isCachingEnabled) {
database = new CacheDataSource(this, database); database = new CacheDataSource(this, database);
} else { } else {
@@ -610,16 +607,19 @@ public class AuthMe extends JavaPlugin {
if (Settings.getDataSource == DataSource.DataSourceType.FILE) { if (Settings.getDataSource == DataSource.DataSourceType.FILE) {
final Converter converter = new ForceFlatToSqlite(database, this); final Converter converter = new ForceFlatToSqlite(database, this);
server.getScheduler().runTaskAsynchronously(this, converter); server.getScheduler().runTaskAsynchronously(this, converter);
ConsoleLogger.showError( ConsoleLogger.info("数据格式 FlatFile 已经过时并且被弃用...");
"FlatFile backend has been detected and is now deprecated, next time server starts up, it will be changed to SQLite... Conversion will be started Asynchronously, it will not drop down your performance !"); ConsoleLogger.info("下一次启动服务器, 数据格式将被转换为 SQLite...");
ConsoleLogger.showError("If you want to keep FlatFile, set file again into config at backend, but this message and this change will appear again at the next restart"); ConsoleLogger.info("转换过程将会在后台异步进行...");
ConsoleLogger.info("这不会影响您的服务器性能...");
ConsoleLogger.info("如果你想继续使用 FlatFile 格式 请修改配置文件...");
ConsoleLogger.info("但是下次重启 插件仍然会进行此操作...");
} }
} }
// Stop/unload the server/plugin as defined in the configuration // Stop/unload the server/plugin as defined in the configuration
public void stopOrUnload() { public void stopOrUnload() {
if (Settings.isStopEnabled) { if (Settings.isStopEnabled) {
ConsoleLogger.showError("根据您的配置 服务器即将关闭..."); ConsoleLogger.showError("插件载入发生错误 根据您的配置 服务器即将关闭...");
server.shutdown(); server.shutdown();
} else { } else {
server.getPluginManager().disablePlugin(AuthMe.getInstance()); server.getPluginManager().disablePlugin(AuthMe.getInstance());
@@ -713,7 +713,7 @@ public class AuthMe extends JavaPlugin {
if (database.isAuthAvailable(name)) { if (database.isAuthAvailable(name)) {
if (PlayerCache.getInstance().isAuthenticated(name)) { if (PlayerCache.getInstance().isAuthenticated(name)) {
final String email = database.getAuth(name).getEmail(); final String email = database.getAuth(name).getEmail();
if (email == null || email.isEmpty() || email.equalsIgnoreCase("mc@mc.com")) { if (email == null || email.isEmpty() || email.equalsIgnoreCase("your@email.com")) {
m.send(player, "add_email"); m.send(player, "add_email");
} }
} }

View File

@@ -22,7 +22,7 @@ public class CrazyLoginConverter implements Converter {
public AuthMe instance; public AuthMe instance;
public CommandSender sender; public CommandSender sender;
public CrazyLoginConverter(AuthMe instance, CommandSender sender) { public CrazyLoginConverter(final AuthMe instance, final CommandSender sender) {
this.instance = instance; this.instance = instance;
this.database = instance.database; this.database = instance.database;
this.sender = sender; this.sender = sender;
@@ -34,35 +34,37 @@ public class CrazyLoginConverter implements Converter {
@Override @Override
public void run() { public void run() {
String fileName = Settings.crazyloginFileName; final String fileName = Settings.crazyloginFileName;
try { try {
File source = new File(AuthMe.getInstance().getDataFolder() + File.separator + fileName); final File source = new File(AuthMe.getInstance().getDataFolder() + File.separator + fileName);
if (!source.exists()) { if (!source.exists()) {
sender.sendMessage("Error while trying to import datas, please put " + fileName + " in AuthMe folder!"); sender.sendMessage("转换 CrazyLogin 数据时发生错误, 请把文件 " + fileName + " 放在 plugin/AuthMe 文件夹!");
return; return;
} }
String line; String line;
BufferedReader users = new BufferedReader(new FileReader(source)); final BufferedReader users = new BufferedReader(new FileReader(source));
while ((line = users.readLine()) != null) { while ((line = users.readLine()) != null) {
if (line.contains("|")) { if (line.contains("|")) {
String[] args = line.split("\\|"); final String[] args = line.split("\\|");
if (args.length < 2) if (args.length < 2) {
continue; continue;
if (args[0].equalsIgnoreCase("name")) }
if (args[0].equalsIgnoreCase("name")) {
continue; continue;
String playerName = args[0].toLowerCase(); }
String psw = args[1]; final String playerName = args[0].toLowerCase();
final String psw = args[1];
if (psw != null) { if (psw != null) {
PlayerAuth auth = new PlayerAuth(playerName, psw, "127.0.0.1", System.currentTimeMillis(), playerName); final PlayerAuth auth = new PlayerAuth(playerName, psw, "127.0.0.1", System.currentTimeMillis(), playerName);
database.saveAuth(auth); database.saveAuth(auth);
} }
} }
} }
users.close(); users.close();
ConsoleLogger.info("CrazyLogin database has been imported correctly"); ConsoleLogger.info("CrazyLogin 数据导入完成...");
} catch (IOException ex) { } catch (final IOException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
ConsoleLogger.showError("Can't open the crazylogin database file! Does it exist?"); ConsoleLogger.showError("转换 CrazyLogin 数据时发生错误, 请确认文件是否正确...");
} }
} }

View File

@@ -9,9 +9,9 @@ import fr.xephi.authme.settings.Settings;
public class ForceFlatToSqlite implements Converter { public class ForceFlatToSqlite implements Converter {
private DataSource data; private final DataSource data;
public ForceFlatToSqlite(DataSource data, AuthMe plugin) { public ForceFlatToSqlite(final DataSource data, final AuthMe plugin) {
this.data = data; this.data = data;
} }
@@ -20,17 +20,18 @@ public class ForceFlatToSqlite implements Converter {
DataSource sqlite = null; DataSource sqlite = null;
try { try {
sqlite = new SQLite(); sqlite = new SQLite();
for (PlayerAuth auth : data.getAllAuths()) { for (final PlayerAuth auth : data.getAllAuths()) {
auth.setRealName("Player"); auth.setRealName("Player");
sqlite.saveAuth(auth); sqlite.saveAuth(auth);
} }
Settings.setValue("DataSource.backend", "sqlite"); Settings.setValue("DataSource.backend", "sqlite");
ConsoleLogger.info("Database successfully converted to sqlite !"); ConsoleLogger.info("数据库已成功转换为 sqlite !");
} catch (Exception e) { } catch (final Exception e) {
ConsoleLogger.showError("An error appeared while trying to convert flatfile to sqlite ..."); ConsoleLogger.showError("一个错误发生了 当尝试将数据从 flatfile 转换为时 sqlite ...");
} finally { } finally {
if (sqlite != null) if (sqlite != null) {
sqlite.close(); sqlite.close();
}
} }
} }
} }

View File

@@ -15,23 +15,23 @@ import fr.xephi.authme.settings.Settings;
public class SQLite implements DataSource { public class SQLite implements DataSource {
private String columnEmail; private final String columnEmail;
private String columnGroup; private final String columnGroup;
private String columnID; private final String columnID;
private String columnIp; private final String columnIp;
private String columnLastLogin; private final String columnLastLogin;
private String columnLogged; private final String columnLogged;
private String columnName; private final String columnName;
private String columnPassword; private final String columnPassword;
private String columnRealName; private final String columnRealName;
private String columnSalt; private final String columnSalt;
private Connection con; private Connection con;
private String database; private final String database;
private String lastlocWorld; private final String lastlocWorld;
private String lastlocX; private final String lastlocX;
private String lastlocY; private final String lastlocY;
private String lastlocZ; private final String lastlocZ;
private String tableName; private final String tableName;
public SQLite() throws ClassNotFoundException, SQLException { public SQLite() throws ClassNotFoundException, SQLException {
this.database = Settings.getMySQLDatabase; this.database = Settings.getMySQLDatabase;
@@ -55,16 +55,16 @@ public class SQLite implements DataSource {
this.connect(); this.connect();
this.setup(); this.setup();
} catch (ClassNotFoundException | SQLException cnf) { } catch (ClassNotFoundException | SQLException cnf) {
ConsoleLogger.showError("Can't use SQLITE... !"); ConsoleLogger.showError("无法使用 SQLite 保存用户数据... !");
throw cnf; throw cnf;
} }
} }
@Override @Override
public List<String> autoPurgeDatabase(long until) { public List<String> autoPurgeDatabase(final long until) {
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs = null; ResultSet rs = null;
List<String> list = new ArrayList<>(); final List<String> list = new ArrayList<>();
try { try {
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLastLogin + "<?;"); pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLastLogin + "<?;");
pst.setLong(1, until); pst.setLong(1, until);
@@ -73,7 +73,7 @@ public class SQLite implements DataSource {
list.add(rs.getString(columnName)); list.add(rs.getString(columnName));
} }
return list; return list;
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return new ArrayList<>(); return new ArrayList<>();
} finally { } finally {
@@ -86,7 +86,7 @@ public class SQLite implements DataSource {
public synchronized void close() { public synchronized void close() {
try { try {
con.close(); con.close();
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
} }
} }
@@ -102,7 +102,7 @@ public class SQLite implements DataSource {
if (rs != null && rs.next()) { if (rs != null && rs.next()) {
result = rs.getInt(1); result = rs.getInt(1);
} }
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return result; return result;
} finally { } finally {
@@ -113,7 +113,7 @@ public class SQLite implements DataSource {
@Override @Override
public List<PlayerAuth> getAllAuths() { public List<PlayerAuth> getAllAuths() {
List<PlayerAuth> auths = new ArrayList<>(); final List<PlayerAuth> auths = new ArrayList<>();
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs; ResultSet rs;
try { try {
@@ -136,7 +136,7 @@ public class SQLite implements DataSource {
} }
auths.add(pAuth); auths.add(pAuth);
} }
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return auths; return auths;
} finally { } finally {
@@ -146,10 +146,10 @@ public class SQLite implements DataSource {
} }
@Override @Override
public List<String> getAllAuthsByEmail(String email) { public List<String> getAllAuthsByEmail(final String email) {
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs = null; ResultSet rs = null;
List<String> countEmail = new ArrayList<>(); final List<String> countEmail = new ArrayList<>();
try { try {
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnEmail + "=?;"); pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnEmail + "=?;");
pst.setString(1, email); pst.setString(1, email);
@@ -158,10 +158,10 @@ public class SQLite implements DataSource {
countEmail.add(rs.getString(columnName)); countEmail.add(rs.getString(columnName));
} }
return countEmail; return countEmail;
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return new ArrayList<>(); return new ArrayList<>();
} catch (NullPointerException npe) { } catch (final NullPointerException npe) {
return new ArrayList<>(); return new ArrayList<>();
} finally { } finally {
close(rs); close(rs);
@@ -170,10 +170,10 @@ public class SQLite implements DataSource {
} }
@Override @Override
public List<String> getAllAuthsByIp(String ip) { public List<String> getAllAuthsByIp(final String ip) {
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs = null; ResultSet rs = null;
List<String> countIp = new ArrayList<>(); final List<String> countIp = new ArrayList<>();
try { try {
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;"); pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;");
pst.setString(1, ip); pst.setString(1, ip);
@@ -182,10 +182,10 @@ public class SQLite implements DataSource {
countIp.add(rs.getString(columnName)); countIp.add(rs.getString(columnName));
} }
return countIp; return countIp;
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return new ArrayList<>(); return new ArrayList<>();
} catch (NullPointerException npe) { } catch (final NullPointerException npe) {
return new ArrayList<>(); return new ArrayList<>();
} finally { } finally {
close(rs); close(rs);
@@ -194,10 +194,10 @@ public class SQLite implements DataSource {
} }
@Override @Override
public List<String> getAllAuthsByName(PlayerAuth auth) { public List<String> getAllAuthsByName(final PlayerAuth auth) {
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs = null; ResultSet rs = null;
List<String> countIp = new ArrayList<>(); final List<String> countIp = new ArrayList<>();
try { try {
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;"); pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;");
pst.setString(1, auth.getIp()); pst.setString(1, auth.getIp());
@@ -206,10 +206,10 @@ public class SQLite implements DataSource {
countIp.add(rs.getString(columnName)); countIp.add(rs.getString(columnName));
} }
return countIp; return countIp;
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return new ArrayList<>(); return new ArrayList<>();
} catch (NullPointerException npe) { } catch (final NullPointerException npe) {
return new ArrayList<>(); return new ArrayList<>();
} finally { } finally {
close(rs); close(rs);
@@ -218,7 +218,7 @@ public class SQLite implements DataSource {
} }
@Override @Override
public synchronized PlayerAuth getAuth(String user) { public synchronized PlayerAuth getAuth(final String user) {
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs = null; ResultSet rs = null;
try { try {
@@ -242,7 +242,7 @@ public class SQLite implements DataSource {
} else { } else {
return null; return null;
} }
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return null; return null;
} finally { } finally {
@@ -252,7 +252,7 @@ public class SQLite implements DataSource {
} }
@Override @Override
public int getIps(String ip) { public int getIps(final String ip) {
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs = null; ResultSet rs = null;
int countIp = 0; int countIp = 0;
@@ -264,7 +264,7 @@ public class SQLite implements DataSource {
countIp++; countIp++;
} }
return countIp; return countIp;
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return 0; return 0;
} finally { } finally {
@@ -275,7 +275,7 @@ public class SQLite implements DataSource {
@Override @Override
public List<PlayerAuth> getLoggedPlayers() { public List<PlayerAuth> getLoggedPlayers() {
List<PlayerAuth> auths = new ArrayList<>(); final List<PlayerAuth> auths = new ArrayList<>();
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs; ResultSet rs;
try { try {
@@ -298,7 +298,7 @@ public class SQLite implements DataSource {
} }
auths.add(pAuth); auths.add(pAuth);
} }
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return auths; return auths;
} finally { } finally {
@@ -313,7 +313,7 @@ public class SQLite implements DataSource {
} }
@Override @Override
public synchronized boolean isAuthAvailable(String user) { public synchronized boolean isAuthAvailable(final String user) {
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs = null; ResultSet rs = null;
try { try {
@@ -321,7 +321,7 @@ public class SQLite implements DataSource {
pst.setString(1, user); pst.setString(1, user);
rs = pst.executeQuery(); rs = pst.executeQuery();
return rs.next(); return rs.next();
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
@@ -331,16 +331,17 @@ public class SQLite implements DataSource {
} }
@Override @Override
public boolean isLogged(String user) { public boolean isLogged(final String user) {
PreparedStatement pst = null; PreparedStatement pst = null;
ResultSet rs = null; ResultSet rs = null;
try { try {
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;"); pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;");
pst.setString(1, user); pst.setString(1, user);
rs = pst.executeQuery(); rs = pst.executeQuery();
if (rs.next()) if (rs.next()) {
return (rs.getInt(columnLogged) == 1); return (rs.getInt(columnLogged) == 1);
} catch (SQLException ex) { }
} catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
@@ -351,15 +352,15 @@ public class SQLite implements DataSource {
} }
@Override @Override
public void purgeBanned(List<String> banned) { public void purgeBanned(final List<String> banned) {
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
for (String name : banned) { for (final String name : banned) {
pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnName + "=?;"); pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnName + "=?;");
pst.setString(1, name); pst.setString(1, name);
pst.executeUpdate(); pst.executeUpdate();
} }
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
} finally { } finally {
close(pst); close(pst);
@@ -367,14 +368,14 @@ public class SQLite implements DataSource {
} }
@Override @Override
public int purgeDatabase(long until) { public int purgeDatabase(final long until) {
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnLastLogin + "<?;"); pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnLastLogin + "<?;");
pst.setLong(1, until); pst.setLong(1, until);
return pst.executeUpdate(); return pst.executeUpdate();
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return 0; return 0;
} finally { } finally {
@@ -390,7 +391,7 @@ public class SQLite implements DataSource {
pst.setInt(1, 0); pst.setInt(1, 0);
pst.setInt(2, 1); pst.setInt(2, 1);
pst.executeUpdate(); pst.executeUpdate();
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
} finally { } finally {
close(pst); close(pst);
@@ -402,13 +403,13 @@ public class SQLite implements DataSource {
} }
@Override @Override
public synchronized boolean removeAuth(String user) { public synchronized boolean removeAuth(final String user) {
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnName + "=?;"); pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnName + "=?;");
pst.setString(1, user); pst.setString(1, user);
pst.executeUpdate(); pst.executeUpdate();
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
@@ -418,7 +419,7 @@ public class SQLite implements DataSource {
} }
@Override @Override
public synchronized boolean saveAuth(PlayerAuth auth) { public synchronized boolean saveAuth(final PlayerAuth auth) {
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
if (columnSalt.isEmpty() && auth.getSalt().isEmpty()) { if (columnSalt.isEmpty() && auth.getSalt().isEmpty()) {
@@ -441,7 +442,7 @@ public class SQLite implements DataSource {
pst.setString(6, auth.getRealName()); pst.setString(6, auth.getRealName());
pst.executeUpdate(); pst.executeUpdate();
} }
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
@@ -451,14 +452,14 @@ public class SQLite implements DataSource {
} }
@Override @Override
public void setLogged(String user) { public void setLogged(final String user) {
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE LOWER(" + columnName + ")=?;"); pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE LOWER(" + columnName + ")=?;");
pst.setInt(1, 1); pst.setInt(1, 1);
pst.setString(2, user); pst.setString(2, user);
pst.executeUpdate(); pst.executeUpdate();
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
} finally { } finally {
close(pst); close(pst);
@@ -466,30 +467,31 @@ public class SQLite implements DataSource {
} }
@Override @Override
public void setUnlogged(String user) { public void setUnlogged(final String user) {
PreparedStatement pst = null; PreparedStatement pst = null;
if (user != null) if (user != null) {
try { try {
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE LOWER(" + columnName + ")=?;"); pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE LOWER(" + columnName + ")=?;");
pst.setInt(1, 0); pst.setInt(1, 0);
pst.setString(2, user); pst.setString(2, user);
pst.executeUpdate(); pst.executeUpdate();
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
} finally { } finally {
close(pst); close(pst);
} }
}
} }
@Override @Override
public boolean updateEmail(PlayerAuth auth) { public boolean updateEmail(final PlayerAuth auth) {
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnEmail + "=? WHERE " + columnName + "=?;"); pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnEmail + "=? WHERE " + columnName + "=?;");
pst.setString(1, auth.getEmail()); pst.setString(1, auth.getEmail());
pst.setString(2, auth.getNickname()); pst.setString(2, auth.getNickname());
pst.executeUpdate(); pst.executeUpdate();
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
@@ -499,14 +501,14 @@ public class SQLite implements DataSource {
} }
@Override @Override
public void updateName(String oldone, String newone) { public void updateName(final String oldone, final String newone) {
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnName + "=? WHERE " + columnName + "=?;"); pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnName + "=? WHERE " + columnName + "=?;");
pst.setString(1, newone); pst.setString(1, newone);
pst.setString(2, oldone); pst.setString(2, oldone);
pst.executeUpdate(); pst.executeUpdate();
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
} finally { } finally {
close(pst); close(pst);
@@ -514,14 +516,14 @@ public class SQLite implements DataSource {
} }
@Override @Override
public synchronized boolean updatePassword(PlayerAuth auth) { public synchronized boolean updatePassword(final PlayerAuth auth) {
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnPassword + "=? WHERE " + columnName + "=?;"); pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnPassword + "=? WHERE " + columnName + "=?;");
pst.setString(1, auth.getHash()); pst.setString(1, auth.getHash());
pst.setString(2, auth.getNickname()); pst.setString(2, auth.getNickname());
pst.executeUpdate(); pst.executeUpdate();
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
@@ -531,7 +533,7 @@ public class SQLite implements DataSource {
} }
@Override @Override
public boolean updateQuitLoc(PlayerAuth auth) { public boolean updateQuitLoc(final PlayerAuth auth) {
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
pst = con.prepareStatement("UPDATE " + tableName + " SET " + lastlocX + "=?, " + lastlocY + "=?, " + lastlocZ + "=?, " + lastlocWorld + "=? WHERE " + columnName + "=?;"); pst = con.prepareStatement("UPDATE " + tableName + " SET " + lastlocX + "=?, " + lastlocY + "=?, " + lastlocZ + "=?, " + lastlocWorld + "=? WHERE " + columnName + "=?;");
@@ -541,7 +543,7 @@ public class SQLite implements DataSource {
pst.setString(4, auth.getWorld()); pst.setString(4, auth.getWorld());
pst.setString(5, auth.getNickname()); pst.setString(5, auth.getNickname());
pst.executeUpdate(); pst.executeUpdate();
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
@@ -551,7 +553,7 @@ public class SQLite implements DataSource {
} }
@Override @Override
public boolean updateSalt(PlayerAuth auth) { public boolean updateSalt(final PlayerAuth auth) {
if (columnSalt.isEmpty()) { if (columnSalt.isEmpty()) {
return false; return false;
} }
@@ -561,7 +563,7 @@ public class SQLite implements DataSource {
pst.setString(1, auth.getSalt()); pst.setString(1, auth.getSalt());
pst.setString(2, auth.getNickname()); pst.setString(2, auth.getNickname());
pst.executeUpdate(); pst.executeUpdate();
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
@@ -571,7 +573,7 @@ public class SQLite implements DataSource {
} }
@Override @Override
public boolean updateSession(PlayerAuth auth) { public boolean updateSession(final PlayerAuth auth) {
PreparedStatement pst = null; PreparedStatement pst = null;
try { try {
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnIp + "=?, " + columnLastLogin + "=?, " + columnRealName + "=? WHERE " + columnName + "=?;"); pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnIp + "=?, " + columnLastLogin + "=?, " + columnRealName + "=? WHERE " + columnName + "=?;");
@@ -580,7 +582,7 @@ public class SQLite implements DataSource {
pst.setString(3, auth.getRealName()); pst.setString(3, auth.getRealName());
pst.setString(4, auth.getNickname()); pst.setString(4, auth.getNickname());
pst.executeUpdate(); pst.executeUpdate();
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
return false; return false;
} finally { } finally {
@@ -589,21 +591,21 @@ public class SQLite implements DataSource {
return true; return true;
} }
private void close(ResultSet rs) { private void close(final ResultSet rs) {
if (rs != null) { if (rs != null) {
try { try {
rs.close(); rs.close();
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
} }
} }
} }
private void close(Statement st) { private void close(final Statement st) {
if (st != null) { if (st != null) {
try { try {
st.close(); st.close();
} catch (SQLException ex) { } catch (final SQLException ex) {
ConsoleLogger.showError(ex.getMessage()); ConsoleLogger.showError(ex.getMessage());
} }
} }

View File

@@ -2,40 +2,68 @@ package fr.xephi.authme.security;
import org.apache.commons.lang.ObjectUtils.Null; import org.apache.commons.lang.ObjectUtils.Null;
import fr.xephi.authme.security.crypts.BCRYPT;
import fr.xephi.authme.security.crypts.BCRYPT2Y;
import fr.xephi.authme.security.crypts.CRAZYCRYPT1;
import fr.xephi.authme.security.crypts.CryptPBKDF2;
import fr.xephi.authme.security.crypts.CryptPBKDF2Django;
import fr.xephi.authme.security.crypts.DOUBLEMD5;
import fr.xephi.authme.security.crypts.IPB3;
import fr.xephi.authme.security.crypts.JOOMLA;
import fr.xephi.authme.security.crypts.MD5;
import fr.xephi.authme.security.crypts.MD5VB;
import fr.xephi.authme.security.crypts.MYBB;
import fr.xephi.authme.security.crypts.PHPBB;
import fr.xephi.authme.security.crypts.PHPFUSION;
import fr.xephi.authme.security.crypts.PLAINTEXT;
import fr.xephi.authme.security.crypts.ROYALAUTH;
import fr.xephi.authme.security.crypts.SALTED2MD5;
import fr.xephi.authme.security.crypts.SALTEDSHA512;
import fr.xephi.authme.security.crypts.SHA1;
import fr.xephi.authme.security.crypts.SHA256;
import fr.xephi.authme.security.crypts.SHA512;
import fr.xephi.authme.security.crypts.SMF;
import fr.xephi.authme.security.crypts.WBB3;
import fr.xephi.authme.security.crypts.WBB4;
import fr.xephi.authme.security.crypts.WHIRLPOOL;
import fr.xephi.authme.security.crypts.WORDPRESS;
import fr.xephi.authme.security.crypts.XAUTH;
import fr.xephi.authme.security.crypts.XF;
public enum HashAlgorithm { public enum HashAlgorithm {
BCRYPT(fr.xephi.authme.security.crypts.BCRYPT.class), BCRYPT(BCRYPT.class),
BCRYPT2Y(fr.xephi.authme.security.crypts.BCRYPT2Y.class), BCRYPT2Y(BCRYPT2Y.class),
CRAZYCRYPT1(fr.xephi.authme.security.crypts.CRAZYCRYPT1.class), CRAZYCRYPT1(CRAZYCRYPT1.class),
CUSTOM(Null.class), CUSTOM(Null.class),
DOUBLEMD5(fr.xephi.authme.security.crypts.DOUBLEMD5.class), DOUBLEMD5(DOUBLEMD5.class),
IPB3(fr.xephi.authme.security.crypts.IPB3.class), IPB3(IPB3.class),
JOOMLA(fr.xephi.authme.security.crypts.JOOMLA.class), JOOMLA(JOOMLA.class),
MD5(fr.xephi.authme.security.crypts.MD5.class), MD5(MD5.class),
MD5VB(fr.xephi.authme.security.crypts.MD5VB.class), MD5VB(MD5VB.class),
MYBB(fr.xephi.authme.security.crypts.MYBB.class), MYBB(MYBB.class),
PBKDF2(fr.xephi.authme.security.crypts.CryptPBKDF2.class), PBKDF2(CryptPBKDF2.class),
PBKDF2DJANGO(fr.xephi.authme.security.crypts.CryptPBKDF2Django.class), PBKDF2DJANGO(CryptPBKDF2Django.class),
PHPBB(fr.xephi.authme.security.crypts.PHPBB.class), PHPBB(PHPBB.class),
PHPFUSION(fr.xephi.authme.security.crypts.PHPFUSION.class), PHPFUSION(PHPFUSION.class),
PLAINTEXT(fr.xephi.authme.security.crypts.PLAINTEXT.class), PLAINTEXT(PLAINTEXT.class),
ROYALAUTH(fr.xephi.authme.security.crypts.ROYALAUTH.class), ROYALAUTH(ROYALAUTH.class),
SALTED2MD5(fr.xephi.authme.security.crypts.SALTED2MD5.class), SALTED2MD5(SALTED2MD5.class),
SALTEDSHA512(fr.xephi.authme.security.crypts.SALTEDSHA512.class), SALTEDSHA512(SALTEDSHA512.class),
SHA1(fr.xephi.authme.security.crypts.SHA1.class), SHA1(SHA1.class),
SHA256(fr.xephi.authme.security.crypts.SHA256.class), SHA256(SHA256.class),
SHA512(fr.xephi.authme.security.crypts.SHA512.class), SHA512(SHA512.class),
SMF(fr.xephi.authme.security.crypts.SMF.class), SMF(SMF.class),
WBB3(fr.xephi.authme.security.crypts.WBB3.class), WBB3(WBB3.class),
WBB4(fr.xephi.authme.security.crypts.WBB4.class), WBB4(WBB4.class),
WHIRLPOOL(fr.xephi.authme.security.crypts.WHIRLPOOL.class), WHIRLPOOL(WHIRLPOOL.class),
WORDPRESS(fr.xephi.authme.security.crypts.WORDPRESS.class), WORDPRESS(WORDPRESS.class),
XAUTH(fr.xephi.authme.security.crypts.XAUTH.class), XAUTH(XAUTH.class),
XENFORO(fr.xephi.authme.security.crypts.XF.class); XENFORO(XF.class);
Class<?> classe; Class<?> classe;
HashAlgorithm(Class<?> classe) { HashAlgorithm(final Class<?> classe) {
this.classe = classe; this.classe = classe;
} }

View File

@@ -15,9 +15,9 @@ import fr.xephi.authme.ConsoleLogger;
public class CustomConfiguration extends YamlConfiguration { public class CustomConfiguration extends YamlConfiguration {
private File configFile; private final File configFile;
public CustomConfiguration(File file) { public CustomConfiguration(final File file) {
this.configFile = file; this.configFile = file;
load(); load();
} }
@@ -29,32 +29,32 @@ public class CustomConfiguration extends YamlConfiguration {
public void load() { public void load() {
try { try {
super.load(configFile); super.load(configFile);
} catch (FileNotFoundException e) { } catch (final FileNotFoundException e) {
ConsoleLogger.showError("Could not find " + configFile.getName() + ", creating new one..."); ConsoleLogger.showError("未找到配置文件 " + configFile.getName() + ", 创建新文件...");
reLoad(); reLoad();
} catch (IOException e) { } catch (final IOException e) {
ConsoleLogger.showError("Could not load " + configFile.getName()); ConsoleLogger.showError("无法载入配置文件 " + configFile.getName());
} catch (InvalidConfigurationException e) { } catch (final InvalidConfigurationException e) {
ConsoleLogger.showError(configFile.getName() + " is no valid configuration file"); ConsoleLogger.showError(configFile.getName() + " 不是一个有效的配置文件");
} }
} }
public boolean loadResource(File file) { public boolean loadResource(final File file) {
if (!file.exists()) { if (!file.exists()) {
try { try {
if (!file.getParentFile().exists() && !file.getParentFile().mkdirs()) { if (!file.getParentFile().exists() && !file.getParentFile().mkdirs()) {
return false; return false;
} }
int i = file.getPath().indexOf("AuthMe"); final int i = file.getPath().indexOf("AuthMe");
if (i > -1) { if (i > -1) {
String path = file.getPath().substring(i + 6).replace('\\', '/'); final String path = file.getPath().substring(i + 6).replace('\\', '/');
InputStream is = AuthMe.class.getResourceAsStream(path); final InputStream is = AuthMe.class.getResourceAsStream(path);
Files.copy(is, file.toPath(), StandardCopyOption.REPLACE_EXISTING); Files.copy(is, file.toPath(), StandardCopyOption.REPLACE_EXISTING);
return true; return true;
} }
} catch (Exception e) { } catch (final Exception e) {
ConsoleLogger.writeStackTrace(e); ConsoleLogger.writeStackTrace(e);
ConsoleLogger.showError("Failed to load config from JAR"); ConsoleLogger.showError("从 JAR 载入配置文件失败...");
} }
} }
return false; return false;
@@ -65,16 +65,17 @@ public class CustomConfiguration extends YamlConfiguration {
if (!configFile.exists()) { if (!configFile.exists()) {
out = loadResource(configFile); out = loadResource(configFile);
} }
if (out) if (out) {
load(); load();
}
return out; return out;
} }
public void save() { public void save() {
try { try {
super.save(configFile); super.save(configFile);
} catch (IOException ex) { } catch (final IOException ex) {
ConsoleLogger.showError("Could not save config to " + configFile.getName()); ConsoleLogger.showError("无法保存配置文件 " + configFile.getName());
} }
} }
} }

View File

@@ -122,7 +122,7 @@ public final class Settings extends YamlConfiguration {
if (!email.contains("@")) { if (!email.contains("@")) {
return false; return false;
} }
if (email.equalsIgnoreCase("mc@mc.com")) { if (email.equalsIgnoreCase("your@email.com")) {
return false; return false;
} }
final String emailDomain = email.split("@")[1]; final String emailDomain = email.split("@")[1];