mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2025-03-02 10:41:43 +01:00
Merge pull request #1 from Xephi/master
Merge https://github.com/Xephi/AuthMeReloaded/tree/master
This commit is contained in:
commit
362fd45ace
@ -9,6 +9,8 @@
|
|||||||
|
|
||||||
- Build status (CircleCI): [](https://circleci.com/gh/Xephi/AuthMeReloaded)
|
- Build status (CircleCI): [](https://circleci.com/gh/Xephi/AuthMeReloaded)
|
||||||
|
|
||||||
|
- Issue Tracking : [](https://waffle.io/Xephi/AuthMeReloaded) [](https://waffle.io/Xephi/AuthMeReloaded) [](https://waffle.io/Xephi/AuthMeReloaded)
|
||||||
|
|
||||||
- Build Server (<strong>DEVELOPMENT BUILDS</strong>): <a href="http://ci.xephi.fr/job/AuthMeReloaded">Xephi's Jenkins</a>
|
- Build Server (<strong>DEVELOPMENT BUILDS</strong>): <a href="http://ci.xephi.fr/job/AuthMeReloaded">Xephi's Jenkins</a>
|
||||||
|
|
||||||
- JavaDocs: <a href="http://xephi.github.io/AuthMeReloaded/index.html">AuthMe Javadoc</a>
|
- JavaDocs: <a href="http://xephi.github.io/AuthMeReloaded/index.html">AuthMe Javadoc</a>
|
||||||
|
@ -47,8 +47,8 @@ public class AdminCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command cmnd, String label,
|
public boolean onCommand(final CommandSender sender, Command cmnd,
|
||||||
String[] args) {
|
String label, String[] args) {
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
sender.sendMessage("Usage:");
|
sender.sendMessage("Usage:");
|
||||||
sender.sendMessage("/authme reload - Reload the config");
|
sender.sendMessage("/authme reload - Reload the config");
|
||||||
@ -434,34 +434,43 @@ public class AdminCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
final String name = args[1].toLowerCase();
|
||||||
String name = args[1].toLowerCase();
|
final String raw = args[2];
|
||||||
String hash = PasswordSecurity.getHash(Settings.getPasswordHash, args[2], name);
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||||
PlayerAuth auth = null;
|
|
||||||
if (PlayerCache.getInstance().isAuthenticated(name)) {
|
@Override
|
||||||
auth = PlayerCache.getInstance().getAuth(name);
|
public void run() {
|
||||||
} else if (plugin.database.isAuthAvailable(name)) {
|
String hash;
|
||||||
auth = plugin.database.getAuth(name);
|
try {
|
||||||
|
hash = PasswordSecurity.getHash(Settings.getPasswordHash, raw, name);
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
m.send(sender, "error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
PlayerAuth auth = null;
|
||||||
|
if (PlayerCache.getInstance().isAuthenticated(name)) {
|
||||||
|
auth = PlayerCache.getInstance().getAuth(name);
|
||||||
|
} else if (plugin.database.isAuthAvailable(name)) {
|
||||||
|
auth = plugin.database.getAuth(name);
|
||||||
|
}
|
||||||
|
if (auth == null) {
|
||||||
|
m.send(sender, "unknown_user");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auth.setHash(hash);
|
||||||
|
if (PasswordSecurity.userSalt.containsKey(name)) {
|
||||||
|
auth.setSalt(PasswordSecurity.userSalt.get(name));
|
||||||
|
plugin.database.updateSalt(auth);
|
||||||
|
}
|
||||||
|
if (!plugin.database.updatePassword(auth)) {
|
||||||
|
m.send(sender, "error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sender.sendMessage("pwd_changed");
|
||||||
|
ConsoleLogger.info(name + "'s password changed");
|
||||||
}
|
}
|
||||||
if (auth == null) {
|
|
||||||
m.send(sender, "unknown_user");
|
});
|
||||||
return true;
|
|
||||||
}
|
|
||||||
auth.setHash(hash);
|
|
||||||
if (PasswordSecurity.userSalt.containsKey(name)) {
|
|
||||||
auth.setSalt(PasswordSecurity.userSalt.get(name));
|
|
||||||
plugin.database.updateSalt(auth);
|
|
||||||
}
|
|
||||||
if (!plugin.database.updatePassword(auth)) {
|
|
||||||
m.send(sender, "error");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
sender.sendMessage("pwd_changed");
|
|
||||||
ConsoleLogger.info(args[1] + "'s password changed");
|
|
||||||
} catch (NoSuchAlgorithmException ex) {
|
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
|
||||||
m.send(sender, "error");
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
} else if (args[0].equalsIgnoreCase("unregister") || args[0].equalsIgnoreCase("unreg") || args[0].equalsIgnoreCase("del")) {
|
} else if (args[0].equalsIgnoreCase("unregister") || args[0].equalsIgnoreCase("unreg") || args[0].equalsIgnoreCase("del")) {
|
||||||
if (args.length != 2) {
|
if (args.length != 2) {
|
||||||
|
@ -113,6 +113,7 @@ public class MySQL implements DataSource {
|
|||||||
throws ClassNotFoundException, SQLException, TimeoutException,
|
throws ClassNotFoundException, SQLException, TimeoutException,
|
||||||
NumberFormatException, PoolInitializationException {
|
NumberFormatException, PoolInitializationException {
|
||||||
HikariConfig config = new HikariConfig();
|
HikariConfig config = new HikariConfig();
|
||||||
|
config.setDriverClassName("com.mysql.jdbc.Driver");
|
||||||
config.setJdbcUrl("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database);
|
config.setJdbcUrl("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database);
|
||||||
config.setUsername(this.username);
|
config.setUsername(this.username);
|
||||||
config.setPassword(this.password);
|
config.setPassword(this.password);
|
||||||
@ -121,6 +122,7 @@ public class MySQL implements DataSource {
|
|||||||
config.addDataSourceProperty("prepStmtCacheSize", "250");
|
config.addDataSourceProperty("prepStmtCacheSize", "250");
|
||||||
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
|
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
|
||||||
config.addDataSourceProperty("autoReconnect", true);
|
config.addDataSourceProperty("autoReconnect", true);
|
||||||
|
config.setMaxLifetime(30000);
|
||||||
config.setInitializationFailFast(false);
|
config.setInitializationFailFast(false);
|
||||||
ds = new HikariDataSource(config);
|
ds = new HikariDataSource(config);
|
||||||
ConsoleLogger.info("Connection pool ready");
|
ConsoleLogger.info("Connection pool ready");
|
||||||
@ -196,7 +198,7 @@ public class MySQL 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 (Exception ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
@ -246,7 +248,7 @@ public class MySQL implements DataSource {
|
|||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} catch (SQLException ex) {
|
} catch (Exception ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return null;
|
return null;
|
||||||
} finally {
|
} finally {
|
||||||
@ -456,7 +458,7 @@ public class MySQL implements DataSource {
|
|||||||
if (rs != null && !rs.isClosed())
|
if (rs != null && !rs.isClosed())
|
||||||
rs.close();
|
rs.close();
|
||||||
}
|
}
|
||||||
} catch (SQLException ex) {
|
} catch (Exception ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
@ -501,7 +503,7 @@ public class MySQL implements DataSource {
|
|||||||
if (rs != null && !rs.isClosed())
|
if (rs != null && !rs.isClosed())
|
||||||
rs.close();
|
rs.close();
|
||||||
}
|
}
|
||||||
} catch (SQLException ex) {
|
} catch (Exception ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
@ -523,7 +525,7 @@ public class MySQL 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 (Exception ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
@ -542,7 +544,7 @@ public class MySQL implements DataSource {
|
|||||||
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 (Exception ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return 0;
|
return 0;
|
||||||
} finally {
|
} finally {
|
||||||
@ -570,7 +572,7 @@ public class MySQL implements DataSource {
|
|||||||
pst.setLong(1, until);
|
pst.setLong(1, until);
|
||||||
pst.executeUpdate();
|
pst.executeUpdate();
|
||||||
return list;
|
return list;
|
||||||
} catch (SQLException ex) {
|
} catch (Exception ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return new ArrayList<String>();
|
return new ArrayList<String>();
|
||||||
} finally {
|
} finally {
|
||||||
@ -606,7 +608,7 @@ public class MySQL implements DataSource {
|
|||||||
pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;");
|
pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;");
|
||||||
pst.setString(1, user);
|
pst.setString(1, user);
|
||||||
pst.executeUpdate();
|
pst.executeUpdate();
|
||||||
} catch (SQLException ex) {
|
} catch (Exception ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
@ -629,7 +631,7 @@ public class MySQL 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 (Exception ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
@ -654,7 +656,7 @@ public class MySQL implements DataSource {
|
|||||||
countIp++;
|
countIp++;
|
||||||
}
|
}
|
||||||
return countIp;
|
return countIp;
|
||||||
} catch (SQLException ex) {
|
} catch (Exception ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return 0;
|
return 0;
|
||||||
} finally {
|
} finally {
|
||||||
@ -674,7 +676,7 @@ public class MySQL implements DataSource {
|
|||||||
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 (Exception ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
@ -697,7 +699,7 @@ public class MySQL 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 (Exception ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
@ -709,8 +711,11 @@ public class MySQL implements DataSource {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void close() {
|
public synchronized void close() {
|
||||||
if (ds != null)
|
try {
|
||||||
ds.close();
|
if (ds != null)
|
||||||
|
ds.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -732,7 +737,7 @@ public class MySQL implements DataSource {
|
|||||||
if (st != null) {
|
if (st != null) {
|
||||||
try {
|
try {
|
||||||
st.close();
|
st.close();
|
||||||
} catch (SQLException ex) {
|
} catch (Exception ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -742,7 +747,7 @@ public class MySQL implements DataSource {
|
|||||||
if (rs != null) {
|
if (rs != null) {
|
||||||
try {
|
try {
|
||||||
rs.close();
|
rs.close();
|
||||||
} catch (SQLException ex) {
|
} catch (Exception ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -752,7 +757,7 @@ public class MySQL implements DataSource {
|
|||||||
if (con != null) {
|
if (con != null) {
|
||||||
try {
|
try {
|
||||||
con.close();
|
con.close();
|
||||||
} catch (SQLException ex) {
|
} catch (Exception ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -773,7 +778,7 @@ public class MySQL implements DataSource {
|
|||||||
countIp.add(rs.getString(columnName));
|
countIp.add(rs.getString(columnName));
|
||||||
}
|
}
|
||||||
return countIp;
|
return countIp;
|
||||||
} catch (SQLException ex) {
|
} catch (Exception ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return new ArrayList<String>();
|
return new ArrayList<String>();
|
||||||
} finally {
|
} finally {
|
||||||
@ -798,7 +803,7 @@ public class MySQL implements DataSource {
|
|||||||
countIp.add(rs.getString(columnName));
|
countIp.add(rs.getString(columnName));
|
||||||
}
|
}
|
||||||
return countIp;
|
return countIp;
|
||||||
} catch (SQLException ex) {
|
} catch (Exception ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return new ArrayList<String>();
|
return new ArrayList<String>();
|
||||||
} finally {
|
} finally {
|
||||||
@ -823,7 +828,7 @@ public class MySQL implements DataSource {
|
|||||||
countEmail.add(rs.getString(columnName));
|
countEmail.add(rs.getString(columnName));
|
||||||
}
|
}
|
||||||
return countEmail;
|
return countEmail;
|
||||||
} catch (SQLException ex) {
|
} catch (Exception ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return new ArrayList<String>();
|
return new ArrayList<String>();
|
||||||
} finally {
|
} finally {
|
||||||
@ -844,7 +849,7 @@ public class MySQL implements DataSource {
|
|||||||
pst.setString(1, name);
|
pst.setString(1, name);
|
||||||
pst.executeUpdate();
|
pst.executeUpdate();
|
||||||
}
|
}
|
||||||
} catch (SQLException ex) {
|
} catch (Exception ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
close(pst);
|
close(pst);
|
||||||
@ -890,7 +895,7 @@ public class MySQL implements DataSource {
|
|||||||
while (con == null)
|
while (con == null)
|
||||||
try {
|
try {
|
||||||
con = ds.getConnection();
|
con = ds.getConnection();
|
||||||
} catch (SQLException e) {
|
} catch (Exception e) {
|
||||||
try {
|
try {
|
||||||
reconnect(false);
|
reconnect(false);
|
||||||
con = ds.getConnection();
|
con = ds.getConnection();
|
||||||
@ -914,6 +919,7 @@ public class MySQL implements DataSource {
|
|||||||
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
|
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
|
||||||
config.addDataSourceProperty("autoReconnect", true);
|
config.addDataSourceProperty("autoReconnect", true);
|
||||||
config.setInitializationFailFast(false);
|
config.setInitializationFailFast(false);
|
||||||
|
config.setMaxLifetime(12000);
|
||||||
config.setPoolName("AuthMeMYSQLPool");
|
config.setPoolName("AuthMeMYSQLPool");
|
||||||
ds = new HikariDataSource(config);
|
ds = new HikariDataSource(config);
|
||||||
if (!reload)
|
if (!reload)
|
||||||
@ -937,7 +943,7 @@ public class MySQL implements DataSource {
|
|||||||
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 (Exception ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
@ -958,7 +964,7 @@ public class MySQL implements DataSource {
|
|||||||
pst.setInt(1, 1);
|
pst.setInt(1, 1);
|
||||||
pst.setString(2, user);
|
pst.setString(2, user);
|
||||||
pst.executeUpdate();
|
pst.executeUpdate();
|
||||||
} catch (SQLException ex) {
|
} catch (Exception ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return;
|
return;
|
||||||
} finally {
|
} finally {
|
||||||
@ -979,7 +985,7 @@ public class MySQL implements DataSource {
|
|||||||
pst.setInt(1, 0);
|
pst.setInt(1, 0);
|
||||||
pst.setString(2, user);
|
pst.setString(2, user);
|
||||||
pst.executeUpdate();
|
pst.executeUpdate();
|
||||||
} catch (SQLException ex) {
|
} catch (Exception ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return;
|
return;
|
||||||
} finally {
|
} finally {
|
||||||
@ -999,7 +1005,7 @@ public class MySQL 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 (Exception ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return;
|
return;
|
||||||
} finally {
|
} finally {
|
||||||
@ -1022,7 +1028,7 @@ public class MySQL implements DataSource {
|
|||||||
if (rs != null && rs.next()) {
|
if (rs != null && rs.next()) {
|
||||||
result = rs.getInt(1);
|
result = rs.getInt(1);
|
||||||
}
|
}
|
||||||
} catch (SQLException ex) {
|
} catch (Exception ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return result;
|
return result;
|
||||||
} finally {
|
} finally {
|
||||||
@ -1042,7 +1048,7 @@ public class MySQL implements DataSource {
|
|||||||
pst.setString(1, newone);
|
pst.setString(1, newone);
|
||||||
pst.setString(2, oldone);
|
pst.setString(2, oldone);
|
||||||
pst.executeUpdate();
|
pst.executeUpdate();
|
||||||
} catch (SQLException ex) {
|
} catch (Exception ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return;
|
return;
|
||||||
} finally {
|
} finally {
|
||||||
@ -1092,7 +1098,7 @@ public class MySQL implements DataSource {
|
|||||||
if (pAuth != null)
|
if (pAuth != null)
|
||||||
auths.add(pAuth);
|
auths.add(pAuth);
|
||||||
}
|
}
|
||||||
} catch (SQLException ex) {
|
} catch (Exception ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return auths;
|
return auths;
|
||||||
} finally {
|
} finally {
|
||||||
@ -1143,7 +1149,7 @@ public class MySQL implements DataSource {
|
|||||||
if (pAuth != null)
|
if (pAuth != null)
|
||||||
auths.add(pAuth);
|
auths.add(pAuth);
|
||||||
}
|
}
|
||||||
} catch (SQLException ex) {
|
} catch (Exception ex) {
|
||||||
ConsoleLogger.showError(ex.getMessage());
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
return auths;
|
return auths;
|
||||||
} finally {
|
} finally {
|
||||||
|
804
src/main/java/fr/xephi/authme/datasource/SQLite_HIKARI.java
Normal file
804
src/main/java/fr/xephi/authme/datasource/SQLite_HIKARI.java
Normal file
@ -0,0 +1,804 @@
|
|||||||
|
package fr.xephi.authme.datasource;
|
||||||
|
|
||||||
|
import java.io.EOFException;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import com.zaxxer.hikari.HikariConfig;
|
||||||
|
import com.zaxxer.hikari.HikariDataSource;
|
||||||
|
|
||||||
|
import fr.xephi.authme.AuthMe;
|
||||||
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
|
||||||
|
public class SQLite_HIKARI implements DataSource {
|
||||||
|
|
||||||
|
private String database;
|
||||||
|
private String tableName;
|
||||||
|
private String columnName;
|
||||||
|
private String columnPassword;
|
||||||
|
private String columnIp;
|
||||||
|
private String columnLastLogin;
|
||||||
|
private String columnSalt;
|
||||||
|
private String columnGroup;
|
||||||
|
private String lastlocX;
|
||||||
|
private String lastlocY;
|
||||||
|
private String lastlocZ;
|
||||||
|
private String lastlocWorld;
|
||||||
|
private String columnEmail;
|
||||||
|
private String columnID;
|
||||||
|
private HikariDataSource ds;
|
||||||
|
private String columnLogged;
|
||||||
|
private String columnRealName;
|
||||||
|
|
||||||
|
public SQLite_HIKARI() {
|
||||||
|
this.database = Settings.getMySQLDatabase;
|
||||||
|
this.tableName = Settings.getMySQLTablename;
|
||||||
|
this.columnName = Settings.getMySQLColumnName;
|
||||||
|
this.columnPassword = Settings.getMySQLColumnPassword;
|
||||||
|
this.columnIp = Settings.getMySQLColumnIp;
|
||||||
|
this.columnLastLogin = Settings.getMySQLColumnLastLogin;
|
||||||
|
this.columnSalt = Settings.getMySQLColumnSalt;
|
||||||
|
this.columnGroup = Settings.getMySQLColumnGroup;
|
||||||
|
this.lastlocX = Settings.getMySQLlastlocX;
|
||||||
|
this.lastlocY = Settings.getMySQLlastlocY;
|
||||||
|
this.lastlocZ = Settings.getMySQLlastlocZ;
|
||||||
|
this.lastlocWorld = Settings.getMySQLlastlocWorld;
|
||||||
|
this.columnEmail = Settings.getMySQLColumnEmail;
|
||||||
|
this.columnID = Settings.getMySQLColumnId;
|
||||||
|
this.columnLogged = Settings.getMySQLColumnLogged;
|
||||||
|
this.columnRealName = Settings.getMySQLColumnRealName;
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.connect();
|
||||||
|
this.setup();
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
ConsoleLogger.showError(e.getMessage());
|
||||||
|
if (Settings.isStopEnabled) {
|
||||||
|
ConsoleLogger.showError("Can't use SQLITE... ! SHUTDOWN...");
|
||||||
|
AuthMe.getInstance().getServer().shutdown();
|
||||||
|
}
|
||||||
|
if (!Settings.isStopEnabled)
|
||||||
|
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
||||||
|
return;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
ConsoleLogger.showError(e.getMessage());
|
||||||
|
if (Settings.isStopEnabled) {
|
||||||
|
ConsoleLogger.showError("Can't use SQLITE... ! SHUTDOWN...");
|
||||||
|
AuthMe.getInstance().getServer().shutdown();
|
||||||
|
}
|
||||||
|
if (!Settings.isStopEnabled)
|
||||||
|
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
||||||
|
return;
|
||||||
|
} catch (EOFException e) {
|
||||||
|
ConsoleLogger.showError(e.getMessage());
|
||||||
|
if (Settings.isStopEnabled) {
|
||||||
|
ConsoleLogger.showError("Can't use SQLITE... ! SHUTDOWN...");
|
||||||
|
AuthMe.getInstance().getServer().shutdown();
|
||||||
|
}
|
||||||
|
if (!Settings.isStopEnabled)
|
||||||
|
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Connection getConnection() throws SQLException, EOFException {
|
||||||
|
return this.ds.getConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized void connect()
|
||||||
|
throws ClassNotFoundException, SQLException, EOFException {
|
||||||
|
/*
|
||||||
|
* Class.forName("org.sqlite.JDBC"); ConsoleLogger.info(
|
||||||
|
* "SQLite driver loaded"); this.con =
|
||||||
|
* DriverManager.getConnection("jdbc:sqlite:plugins/AuthMe/" + database
|
||||||
|
* + ".db");
|
||||||
|
*/
|
||||||
|
Properties props = new Properties();
|
||||||
|
props.setProperty("dataSourceClassName", "org.sqlite.SQLiteDataSource");
|
||||||
|
HikariConfig config = new HikariConfig(props);
|
||||||
|
config.setPoolName("AuthMeSQLiteLPool");
|
||||||
|
ds = new HikariDataSource(config);
|
||||||
|
ConsoleLogger.info("Connection pool ready");
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized void setup() throws SQLException, EOFException {
|
||||||
|
Connection con = null;
|
||||||
|
Statement st = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try {
|
||||||
|
con = getConnection();
|
||||||
|
st = con.createStatement();
|
||||||
|
st.executeUpdate("CREATE TABLE IF NOT EXISTS " + tableName + " (" + columnID + " INTEGER AUTO_INCREMENT," + columnName + " VARCHAR(255) NOT NULL UNIQUE," + columnPassword + " VARCHAR(255) NOT NULL," + columnIp + " VARCHAR(40) NOT NULL," + columnLastLogin + " BIGINT," + lastlocX + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocY + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocZ + " DOUBLE NOT NULL DEFAULT '0.0'," + lastlocWorld + " VARCHAR(255) NOT NULL DEFAULT '" + Settings.defaultWorld + "'," + columnEmail + " VARCHAR(255) DEFAULT 'your@email.com'," + "CONSTRAINT table_const_prim PRIMARY KEY (" + columnID + "));");
|
||||||
|
rs = con.getMetaData().getColumns(null, null, tableName, columnPassword);
|
||||||
|
if (!rs.next()) {
|
||||||
|
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnPassword + " VARCHAR(255) NOT NULL;");
|
||||||
|
}
|
||||||
|
rs.close();
|
||||||
|
rs = con.getMetaData().getColumns(null, null, tableName, columnIp);
|
||||||
|
if (!rs.next()) {
|
||||||
|
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnIp + " VARCHAR(40) NOT NULL;");
|
||||||
|
}
|
||||||
|
rs.close();
|
||||||
|
rs = con.getMetaData().getColumns(null, null, tableName, columnLastLogin);
|
||||||
|
if (!rs.next()) {
|
||||||
|
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnLastLogin + " BIGINT DEFAULT '0';");
|
||||||
|
}
|
||||||
|
rs.close();
|
||||||
|
rs = con.getMetaData().getColumns(null, null, tableName, lastlocX);
|
||||||
|
if (!rs.next()) {
|
||||||
|
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocX + " DOUBLE NOT NULL DEFAULT '0.0';");
|
||||||
|
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocY + " DOUBLE NOT NULL DEFAULT '0.0';");
|
||||||
|
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocZ + " DOUBLE NOT NULL DEFAULT '0.0';");
|
||||||
|
}
|
||||||
|
rs.close();
|
||||||
|
rs = con.getMetaData().getColumns(null, null, tableName, lastlocWorld);
|
||||||
|
if (!rs.next()) {
|
||||||
|
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + lastlocWorld + " VARCHAR(255) NOT NULL DEFAULT 'world';");
|
||||||
|
}
|
||||||
|
rs.close();
|
||||||
|
rs = con.getMetaData().getColumns(null, null, tableName, columnEmail);
|
||||||
|
if (!rs.next()) {
|
||||||
|
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnEmail + " VARCHAR(255) DEFAULT 'your@email.com';");
|
||||||
|
}
|
||||||
|
rs.close();
|
||||||
|
rs = con.getMetaData().getColumns(null, null, tableName, columnLogged);
|
||||||
|
if (!rs.next()) {
|
||||||
|
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnLogged + " BIGINT DEFAULT '0';");
|
||||||
|
}
|
||||||
|
rs.close();
|
||||||
|
rs = con.getMetaData().getColumns(null, null, tableName, columnRealName);
|
||||||
|
if (!rs.next()) {
|
||||||
|
st.executeUpdate("ALTER TABLE " + tableName + " ADD COLUMN " + columnRealName + " VARCHAR(255) NOT NULL DEFAULT 'Player';");
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
close(rs);
|
||||||
|
close(st);
|
||||||
|
close(con);
|
||||||
|
}
|
||||||
|
ConsoleLogger.info("SQLite Setup finished");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void close(Connection con) {
|
||||||
|
try {
|
||||||
|
if (con != null)
|
||||||
|
con.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized boolean isAuthAvailable(String user) {
|
||||||
|
Connection con = null;
|
||||||
|
PreparedStatement pst = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try {
|
||||||
|
con = getConnection();
|
||||||
|
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=LOWER(?);");
|
||||||
|
pst.setString(1, user);
|
||||||
|
rs = pst.executeQuery();
|
||||||
|
return rs.next();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
close(rs);
|
||||||
|
close(pst);
|
||||||
|
close(con);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized PlayerAuth getAuth(String user) {
|
||||||
|
Connection con = null;
|
||||||
|
PreparedStatement pst = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try {
|
||||||
|
con = getConnection();
|
||||||
|
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=LOWER(?);");
|
||||||
|
pst.setString(1, user);
|
||||||
|
rs = pst.executeQuery();
|
||||||
|
if (rs.next()) {
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
return null;
|
||||||
|
} finally {
|
||||||
|
close(rs);
|
||||||
|
close(pst);
|
||||||
|
close(con);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized boolean saveAuth(PlayerAuth auth) {
|
||||||
|
PreparedStatement pst = null;
|
||||||
|
Connection con = null;
|
||||||
|
try {
|
||||||
|
con = getConnection();
|
||||||
|
if (columnSalt.isEmpty() && auth.getSalt().isEmpty()) {
|
||||||
|
pst = con.prepareStatement("INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + "," + columnRealName + ") VALUES (?,?,?,?,?);");
|
||||||
|
pst.setString(1, auth.getNickname());
|
||||||
|
pst.setString(2, auth.getHash());
|
||||||
|
pst.setString(3, auth.getIp());
|
||||||
|
pst.setLong(4, auth.getLastLogin());
|
||||||
|
pst.setString(5, auth.getRealName());
|
||||||
|
pst.executeUpdate();
|
||||||
|
} else {
|
||||||
|
pst = con.prepareStatement("INSERT INTO " + tableName + "(" + columnName + "," + columnPassword + "," + columnIp + "," + columnLastLogin + "," + columnSalt + "," + columnRealName + ") VALUES (?,?,?,?,?,?);");
|
||||||
|
pst.setString(1, auth.getNickname());
|
||||||
|
pst.setString(2, auth.getHash());
|
||||||
|
pst.setString(3, auth.getIp());
|
||||||
|
pst.setLong(4, auth.getLastLogin());
|
||||||
|
pst.setString(5, auth.getSalt());
|
||||||
|
pst.setString(6, auth.getRealName());
|
||||||
|
pst.executeUpdate();
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
close(pst);
|
||||||
|
close(con);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized boolean updatePassword(PlayerAuth auth) {
|
||||||
|
Connection con = null;
|
||||||
|
PreparedStatement pst = null;
|
||||||
|
try {
|
||||||
|
con = getConnection();
|
||||||
|
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnPassword + "=? WHERE " + columnName + "=?;");
|
||||||
|
pst.setString(1, auth.getHash());
|
||||||
|
pst.setString(2, auth.getNickname());
|
||||||
|
pst.executeUpdate();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
close(pst);
|
||||||
|
close(con);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean updateSession(PlayerAuth auth) {
|
||||||
|
Connection con = null;
|
||||||
|
PreparedStatement pst = null;
|
||||||
|
try {
|
||||||
|
con = getConnection();
|
||||||
|
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnIp + "=?, " + columnLastLogin + "=?, " + columnRealName + "=? WHERE " + columnName + "=?;");
|
||||||
|
pst.setString(1, auth.getIp());
|
||||||
|
pst.setLong(2, auth.getLastLogin());
|
||||||
|
pst.setString(3, auth.getRealName());
|
||||||
|
pst.setString(4, auth.getNickname());
|
||||||
|
pst.executeUpdate();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
close(pst);
|
||||||
|
close(con);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int purgeDatabase(long until) {
|
||||||
|
Connection con = null;
|
||||||
|
PreparedStatement pst = null;
|
||||||
|
try {
|
||||||
|
con = getConnection();
|
||||||
|
pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnLastLogin + "<?;");
|
||||||
|
pst.setLong(1, until);
|
||||||
|
return pst.executeUpdate();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
return 0;
|
||||||
|
} finally {
|
||||||
|
close(pst);
|
||||||
|
close(con);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> autoPurgeDatabase(long until) {
|
||||||
|
Connection con = null;
|
||||||
|
PreparedStatement pst = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
List<String> list = new ArrayList<String>();
|
||||||
|
try {
|
||||||
|
con = getConnection();
|
||||||
|
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLastLogin + "<?;");
|
||||||
|
pst.setLong(1, until);
|
||||||
|
rs = pst.executeQuery();
|
||||||
|
while (rs.next()) {
|
||||||
|
list.add(rs.getString(columnName));
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
return new ArrayList<String>();
|
||||||
|
} finally {
|
||||||
|
close(rs);
|
||||||
|
close(pst);
|
||||||
|
close(con);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized boolean removeAuth(String user) {
|
||||||
|
PreparedStatement pst = null;
|
||||||
|
Connection con = null;
|
||||||
|
try {
|
||||||
|
con = getConnection();
|
||||||
|
pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnName + "=?;");
|
||||||
|
pst.setString(1, user);
|
||||||
|
pst.executeUpdate();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
close(pst);
|
||||||
|
close(con);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean updateQuitLoc(PlayerAuth auth) {
|
||||||
|
PreparedStatement pst = null;
|
||||||
|
Connection con = null;
|
||||||
|
try {
|
||||||
|
con = getConnection();
|
||||||
|
pst = con.prepareStatement("UPDATE " + tableName + " SET " + lastlocX + "=?, " + lastlocY + "=?, " + lastlocZ + "=?, " + lastlocWorld + "=? WHERE " + columnName + "=?;");
|
||||||
|
pst.setDouble(1, auth.getQuitLocX());
|
||||||
|
pst.setDouble(2, auth.getQuitLocY());
|
||||||
|
pst.setDouble(3, auth.getQuitLocZ());
|
||||||
|
pst.setString(4, auth.getWorld());
|
||||||
|
pst.setString(5, auth.getNickname());
|
||||||
|
pst.executeUpdate();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
close(pst);
|
||||||
|
close(con);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getIps(String ip) {
|
||||||
|
PreparedStatement pst = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
Connection con = null;
|
||||||
|
int countIp = 0;
|
||||||
|
try {
|
||||||
|
con = getConnection();
|
||||||
|
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;");
|
||||||
|
pst.setString(1, ip);
|
||||||
|
rs = pst.executeQuery();
|
||||||
|
while (rs.next()) {
|
||||||
|
countIp++;
|
||||||
|
}
|
||||||
|
return countIp;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
return 0;
|
||||||
|
} finally {
|
||||||
|
close(rs);
|
||||||
|
close(pst);
|
||||||
|
close(con);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean updateEmail(PlayerAuth auth) {
|
||||||
|
PreparedStatement pst = null;
|
||||||
|
Connection con = null;
|
||||||
|
try {
|
||||||
|
con = getConnection();
|
||||||
|
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnEmail + "=? WHERE " + columnName + "=?;");
|
||||||
|
pst.setString(1, auth.getEmail());
|
||||||
|
pst.setString(2, auth.getNickname());
|
||||||
|
pst.executeUpdate();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
close(pst);
|
||||||
|
close(con);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean updateSalt(PlayerAuth auth) {
|
||||||
|
if (columnSalt.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Connection con = null;
|
||||||
|
PreparedStatement pst = null;
|
||||||
|
try {
|
||||||
|
con = getConnection();
|
||||||
|
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnSalt + "=? WHERE " + columnName + "=?;");
|
||||||
|
pst.setString(1, auth.getSalt());
|
||||||
|
pst.setString(2, auth.getNickname());
|
||||||
|
pst.executeUpdate();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
close(pst);
|
||||||
|
close(con);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized void close() {
|
||||||
|
try {
|
||||||
|
if (ds != null)
|
||||||
|
ds.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reload() {
|
||||||
|
try {
|
||||||
|
connect();
|
||||||
|
setup();
|
||||||
|
} catch (Exception e) {
|
||||||
|
ConsoleLogger.showError(e.getMessage());
|
||||||
|
if (Settings.isStopEnabled) {
|
||||||
|
ConsoleLogger.showError("Can't reconnect to SQLite database... SHUTDOWN...");
|
||||||
|
AuthMe.getInstance().getServer().shutdown();
|
||||||
|
}
|
||||||
|
if (!Settings.isStopEnabled)
|
||||||
|
AuthMe.getInstance().getServer().getPluginManager().disablePlugin(AuthMe.getInstance());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void close(Statement st) {
|
||||||
|
if (st != null) {
|
||||||
|
try {
|
||||||
|
st.close();
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void close(ResultSet rs) {
|
||||||
|
if (rs != null) {
|
||||||
|
try {
|
||||||
|
rs.close();
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getAllAuthsByName(PlayerAuth auth) {
|
||||||
|
PreparedStatement pst = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
Connection con = null;
|
||||||
|
List<String> countIp = new ArrayList<String>();
|
||||||
|
try {
|
||||||
|
con = getConnection();
|
||||||
|
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;");
|
||||||
|
pst.setString(1, auth.getIp());
|
||||||
|
rs = pst.executeQuery();
|
||||||
|
while (rs.next()) {
|
||||||
|
countIp.add(rs.getString(columnName));
|
||||||
|
}
|
||||||
|
return countIp;
|
||||||
|
} catch (NullPointerException ex) {
|
||||||
|
return new ArrayList<String>();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
return new ArrayList<String>();
|
||||||
|
} finally {
|
||||||
|
close(rs);
|
||||||
|
close(pst);
|
||||||
|
close(con);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getAllAuthsByIp(String ip) {
|
||||||
|
PreparedStatement pst = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
Connection con = null;
|
||||||
|
List<String> countIp = new ArrayList<String>();
|
||||||
|
try {
|
||||||
|
con = getConnection();
|
||||||
|
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;");
|
||||||
|
pst.setString(1, ip);
|
||||||
|
rs = pst.executeQuery();
|
||||||
|
while (rs.next()) {
|
||||||
|
countIp.add(rs.getString(columnName));
|
||||||
|
}
|
||||||
|
return countIp;
|
||||||
|
} catch (NullPointerException ex) {
|
||||||
|
return new ArrayList<String>();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
return new ArrayList<String>();
|
||||||
|
} finally {
|
||||||
|
close(rs);
|
||||||
|
close(pst);
|
||||||
|
close(con);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getAllAuthsByEmail(String email) {
|
||||||
|
PreparedStatement pst = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
Connection con = null;
|
||||||
|
List<String> countEmail = new ArrayList<String>();
|
||||||
|
try {
|
||||||
|
con = getConnection();
|
||||||
|
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnEmail + "=?;");
|
||||||
|
pst.setString(1, email);
|
||||||
|
rs = pst.executeQuery();
|
||||||
|
while (rs.next()) {
|
||||||
|
countEmail.add(rs.getString(columnName));
|
||||||
|
}
|
||||||
|
return countEmail;
|
||||||
|
} catch (NullPointerException ex) {
|
||||||
|
return new ArrayList<String>();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
return new ArrayList<String>();
|
||||||
|
} finally {
|
||||||
|
close(rs);
|
||||||
|
close(pst);
|
||||||
|
close(con);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void purgeBanned(List<String> banned) {
|
||||||
|
PreparedStatement pst = null;
|
||||||
|
Connection con = null;
|
||||||
|
try {
|
||||||
|
con = getConnection();
|
||||||
|
for (String name : banned) {
|
||||||
|
pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + columnName + "=?;");
|
||||||
|
pst.setString(1, name);
|
||||||
|
pst.executeUpdate();
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
} finally {
|
||||||
|
close(pst);
|
||||||
|
close(con);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DataSourceType getType() {
|
||||||
|
return DataSourceType.SQLITE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLogged(String user) {
|
||||||
|
PreparedStatement pst = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
Connection con = null;
|
||||||
|
try {
|
||||||
|
con = getConnection();
|
||||||
|
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE LOWER(" + columnName + ")=?;");
|
||||||
|
pst.setString(1, user);
|
||||||
|
rs = pst.executeQuery();
|
||||||
|
if (rs.next())
|
||||||
|
return (rs.getInt(columnLogged) == 1);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
close(rs);
|
||||||
|
close(pst);
|
||||||
|
close(con);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setLogged(String user) {
|
||||||
|
PreparedStatement pst = null;
|
||||||
|
Connection con = null;
|
||||||
|
try {
|
||||||
|
con = getConnection();
|
||||||
|
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE LOWER(" + columnName + ")=?;");
|
||||||
|
pst.setInt(1, 1);
|
||||||
|
pst.setString(2, user);
|
||||||
|
pst.executeUpdate();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
return;
|
||||||
|
} finally {
|
||||||
|
close(pst);
|
||||||
|
close(con);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setUnlogged(String user) {
|
||||||
|
PreparedStatement pst = null;
|
||||||
|
Connection con = null;
|
||||||
|
if (user != null)
|
||||||
|
try {
|
||||||
|
con = getConnection();
|
||||||
|
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE LOWER(" + columnName + ")=?;");
|
||||||
|
pst.setInt(1, 0);
|
||||||
|
pst.setString(2, user);
|
||||||
|
pst.executeUpdate();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
return;
|
||||||
|
} finally {
|
||||||
|
close(pst);
|
||||||
|
close(con);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void purgeLogged() {
|
||||||
|
PreparedStatement pst = null;
|
||||||
|
Connection con = null;
|
||||||
|
try {
|
||||||
|
con = getConnection();
|
||||||
|
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnLogged + "=? WHERE " + columnLogged + "=?;");
|
||||||
|
pst.setInt(1, 0);
|
||||||
|
pst.setInt(2, 1);
|
||||||
|
pst.executeUpdate();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
return;
|
||||||
|
} finally {
|
||||||
|
close(pst);
|
||||||
|
close(con);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAccountsRegistered() {
|
||||||
|
int result = 0;
|
||||||
|
PreparedStatement pst = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
Connection con = null;
|
||||||
|
try {
|
||||||
|
con = getConnection();
|
||||||
|
pst = con.prepareStatement("SELECT COUNT(*) FROM " + tableName + ";");
|
||||||
|
rs = pst.executeQuery();
|
||||||
|
if (rs != null && rs.next()) {
|
||||||
|
result = rs.getInt(1);
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
return result;
|
||||||
|
} finally {
|
||||||
|
close(pst);
|
||||||
|
close(con);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateName(String oldone, String newone) {
|
||||||
|
PreparedStatement pst = null;
|
||||||
|
Connection con = null;
|
||||||
|
try {
|
||||||
|
con = getConnection();
|
||||||
|
pst = con.prepareStatement("UPDATE " + tableName + " SET " + columnName + "=? WHERE " + columnName + "=?;");
|
||||||
|
pst.setString(1, newone);
|
||||||
|
pst.setString(2, oldone);
|
||||||
|
pst.executeUpdate();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
return;
|
||||||
|
} finally {
|
||||||
|
close(pst);
|
||||||
|
close(con);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<PlayerAuth> getAllAuths() {
|
||||||
|
List<PlayerAuth> auths = new ArrayList<PlayerAuth>();
|
||||||
|
PreparedStatement pst = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
Connection con = null;
|
||||||
|
try {
|
||||||
|
con = getConnection();
|
||||||
|
pst = con.prepareStatement("SELECT * FROM " + tableName + ";");
|
||||||
|
rs = pst.executeQuery();
|
||||||
|
while (rs.next()) {
|
||||||
|
PlayerAuth pAuth = null;
|
||||||
|
if (rs.getString(columnIp).isEmpty()) {
|
||||||
|
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "127.0.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()) {
|
||||||
|
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), rs.getString(columnRealName));
|
||||||
|
} 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), rs.getString(columnRealName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (pAuth != null)
|
||||||
|
auths.add(pAuth);
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
return auths;
|
||||||
|
} finally {
|
||||||
|
close(pst);
|
||||||
|
close(con);
|
||||||
|
}
|
||||||
|
return auths;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<PlayerAuth> getLoggedPlayers() {
|
||||||
|
List<PlayerAuth> auths = new ArrayList<PlayerAuth>();
|
||||||
|
PreparedStatement pst = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
Connection con = null;
|
||||||
|
try {
|
||||||
|
con = getConnection();
|
||||||
|
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnLogged + "=1;");
|
||||||
|
rs = pst.executeQuery();
|
||||||
|
while (rs.next()) {
|
||||||
|
PlayerAuth pAuth = null;
|
||||||
|
if (rs.getString(columnIp).isEmpty()) {
|
||||||
|
pAuth = new PlayerAuth(rs.getString(columnName), rs.getString(columnPassword), "127.0.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()) {
|
||||||
|
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), rs.getString(columnRealName));
|
||||||
|
} 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), rs.getString(columnRealName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (pAuth != null)
|
||||||
|
auths.add(pAuth);
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ConsoleLogger.showError(ex.getMessage());
|
||||||
|
return auths;
|
||||||
|
} finally {
|
||||||
|
close(pst);
|
||||||
|
close(con);
|
||||||
|
}
|
||||||
|
return auths;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
package fr.xephi.authme.events;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* This event is call when a player try to /login
|
||||||
|
*
|
||||||
|
* @author Xephi59
|
||||||
|
*/
|
||||||
|
public class AuthMeAsyncPreLoginEvent extends Event {
|
||||||
|
|
||||||
|
private Player player;
|
||||||
|
private boolean canLogin = true;
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
public AuthMeAsyncPreLoginEvent(Player player) {
|
||||||
|
super(true);
|
||||||
|
this.player = player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getPlayer() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canLogin() {
|
||||||
|
return canLogin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCanLogin(boolean canLogin) {
|
||||||
|
this.canLogin = canLogin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -13,6 +13,14 @@ public class CustomEvent extends Event implements Cancellable {
|
|||||||
private boolean isCancelled;
|
private boolean isCancelled;
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
public CustomEvent() {
|
||||||
|
super(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CustomEvent(boolean b) {
|
||||||
|
super(b);
|
||||||
|
}
|
||||||
|
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ public class FirstSpawnTeleportEvent extends CustomEvent {
|
|||||||
private Location from;
|
private Location from;
|
||||||
|
|
||||||
public FirstSpawnTeleportEvent(Player player, Location from, Location to) {
|
public FirstSpawnTeleportEvent(Player player, Location from, Location to) {
|
||||||
|
super(true);
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.from = from;
|
this.from = from;
|
||||||
this.to = to;
|
this.to = to;
|
||||||
|
@ -22,6 +22,7 @@ public class PasswordEncryptionEvent extends Event {
|
|||||||
private String playerName = "";
|
private String playerName = "";
|
||||||
|
|
||||||
public PasswordEncryptionEvent(EncryptionMethod method, String playerName) {
|
public PasswordEncryptionEvent(EncryptionMethod method, String playerName) {
|
||||||
|
super(true);
|
||||||
this.method = method;
|
this.method = method;
|
||||||
this.playerName = playerName;
|
this.playerName = playerName;
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ public class ProtectInventoryEvent extends CustomEvent {
|
|||||||
|
|
||||||
public ProtectInventoryEvent(Player player, ItemStack[] storedinventory,
|
public ProtectInventoryEvent(Player player, ItemStack[] storedinventory,
|
||||||
ItemStack[] storedarmor) {
|
ItemStack[] storedarmor) {
|
||||||
|
super(true);
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.storedinventory = storedinventory;
|
this.storedinventory = storedinventory;
|
||||||
this.storedarmor = storedarmor;
|
this.storedarmor = storedarmor;
|
||||||
|
@ -13,6 +13,7 @@ public class ResetInventoryEvent extends CustomEvent {
|
|||||||
private Player player;
|
private Player player;
|
||||||
|
|
||||||
public ResetInventoryEvent(Player player) {
|
public ResetInventoryEvent(Player player) {
|
||||||
|
super(true);
|
||||||
this.player = player;
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,14 @@ public class RestoreInventoryEvent extends CustomEvent {
|
|||||||
this.armor = armor;
|
this.armor = armor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RestoreInventoryEvent(Player player, ItemStack[] inventory,
|
||||||
|
ItemStack[] armor, boolean b) {
|
||||||
|
super(b);
|
||||||
|
this.player = player;
|
||||||
|
this.inventory = inventory;
|
||||||
|
this.armor = armor;
|
||||||
|
}
|
||||||
|
|
||||||
public ItemStack[] getInventory() {
|
public ItemStack[] getInventory() {
|
||||||
return this.inventory;
|
return this.inventory;
|
||||||
}
|
}
|
||||||
|
@ -28,8 +28,7 @@ public class StoreInventoryEvent extends CustomEvent {
|
|||||||
try {
|
try {
|
||||||
this.inventory = fileCache.readCache(player).getInventory();
|
this.inventory = fileCache.readCache(player).getInventory();
|
||||||
this.armor = fileCache.readCache(player).getArmour();
|
this.armor = fileCache.readCache(player).getArmour();
|
||||||
} catch (Exception e)
|
} catch (Exception e) {
|
||||||
{
|
|
||||||
this.inventory = player.getInventory().getContents();
|
this.inventory = player.getInventory().getContents();
|
||||||
this.armor = player.getInventory().getArmorContents();
|
this.armor = player.getInventory().getArmorContents();
|
||||||
}
|
}
|
||||||
|
100
src/main/java/fr/xephi/authme/modules/ModuleManager.java
Normal file
100
src/main/java/fr/xephi/authme/modules/ModuleManager.java
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
package fr.xephi.authme.modules;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.jar.JarEntry;
|
||||||
|
import java.util.jar.JarFile;
|
||||||
|
|
||||||
|
import fr.xephi.authme.AuthMe;
|
||||||
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
|
|
||||||
|
public class ModuleManager implements Module {
|
||||||
|
|
||||||
|
private AuthMe plugin;
|
||||||
|
private ModuleManager instance;
|
||||||
|
private List<Module> modules = new ArrayList<Module>();
|
||||||
|
|
||||||
|
public ModuleManager(AuthMe plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "AuthMe Module Manager";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AuthMe getInstanceOfAuthMe() {
|
||||||
|
return this.plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Module getInstance() {
|
||||||
|
if (this.instance == null)
|
||||||
|
instance = new ModuleManager(AuthMe.getInstance());
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ModuleType getType() {
|
||||||
|
return (Module.ModuleType.MANAGER);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean load() {
|
||||||
|
File dir = new File(plugin.getDataFolder() + File.separator + "modules");
|
||||||
|
if (dir == null || !dir.exists() || !dir.isDirectory() || dir.listFiles() == null || dir.listFiles().length <= 0)
|
||||||
|
return false;
|
||||||
|
for (File pathToJar : dir.listFiles()) {
|
||||||
|
JarFile jarFile = null;
|
||||||
|
try {
|
||||||
|
jarFile = new JarFile(pathToJar);
|
||||||
|
Enumeration<?> e = jarFile.entries();
|
||||||
|
URL[] urls = { new URL("jar:file:" + pathToJar.getAbsolutePath() + "!/") };
|
||||||
|
URLClassLoader cl = URLClassLoader.newInstance(urls);
|
||||||
|
|
||||||
|
while (e.hasMoreElements()) {
|
||||||
|
JarEntry je = (JarEntry) e.nextElement();
|
||||||
|
if (je.isDirectory() || !je.getName().endsWith("Main.class")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String className = je.getName().substring(0, je.getName().length() - 6);
|
||||||
|
className = className.replace('/', '.');
|
||||||
|
Class<?> c = cl.loadClass(className);
|
||||||
|
Module mod = (Module) c.newInstance();
|
||||||
|
mod.load();
|
||||||
|
modules.add(mod);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ConsoleLogger.showError("Cannot load " + pathToJar.getName() + " jar file !");
|
||||||
|
} finally {
|
||||||
|
if (jarFile != null)
|
||||||
|
try {
|
||||||
|
jarFile.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean unload() {
|
||||||
|
try {
|
||||||
|
for (Module mod : modules) {
|
||||||
|
mod.unload();
|
||||||
|
modules.remove(mod);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -6,6 +6,7 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
@ -176,25 +177,27 @@ public class AsyncronousJoin {
|
|||||||
|
|
||||||
}
|
}
|
||||||
if (Settings.protectInventoryBeforeLogInEnabled) {
|
if (Settings.protectInventoryBeforeLogInEnabled) {
|
||||||
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
|
try {
|
||||||
|
LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(player.getName().toLowerCase());
|
||||||
|
ProtectInventoryEvent ev = new ProtectInventoryEvent(player, limbo.getInventory(), limbo.getArmour());
|
||||||
|
plugin.getServer().getPluginManager().callEvent(ev);
|
||||||
|
if (ev.isCancelled()) {
|
||||||
|
if (!Settings.noConsoleSpam)
|
||||||
|
ConsoleLogger.info("ProtectInventoryEvent has been cancelled for " + player.getName() + " ...");
|
||||||
|
} else {
|
||||||
|
final ItemStack[] inv = ev.getEmptyArmor();
|
||||||
|
final ItemStack[] armor = ev.getEmptyArmor();
|
||||||
|
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
plugin.api.setPlayerInventory(player, inv, armor);
|
||||||
LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(player.getName().toLowerCase());
|
|
||||||
ProtectInventoryEvent ev = new ProtectInventoryEvent(player, limbo.getInventory(), limbo.getArmour());
|
|
||||||
plugin.getServer().getPluginManager().callEvent(ev);
|
|
||||||
if (ev.isCancelled()) {
|
|
||||||
if (!Settings.noConsoleSpam)
|
|
||||||
ConsoleLogger.info("ProtectInventoryEvent has been cancelled for " + player.getName() + " ...");
|
|
||||||
} else {
|
|
||||||
plugin.api.setPlayerInventory(player, ev.getEmptyInventory(), ev.getEmptyArmor());
|
|
||||||
}
|
}
|
||||||
} catch (NullPointerException ex) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
} catch (NullPointerException ex) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
String[] msg;
|
String[] msg;
|
||||||
if (Settings.emailRegistration) {
|
if (Settings.emailRegistration) {
|
||||||
@ -262,21 +265,21 @@ public class AsyncronousJoin {
|
|||||||
else {
|
else {
|
||||||
if (Spawn.getInstance().getFirstSpawn() == null || Spawn.getInstance().getFirstSpawn().getWorld() == null)
|
if (Spawn.getInstance().getFirstSpawn() == null || Spawn.getInstance().getFirstSpawn().getWorld() == null)
|
||||||
return false;
|
return false;
|
||||||
final Location loc = Spawn.getInstance().getFirstSpawn();
|
FirstSpawnTeleportEvent tpEvent = new FirstSpawnTeleportEvent(player, player.getLocation(), Spawn.getInstance().getFirstSpawn());
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
plugin.getServer().getPluginManager().callEvent(tpEvent);
|
||||||
|
if (!tpEvent.isCancelled()) {
|
||||||
|
if (player.isOnline() && tpEvent.getTo() != null && tpEvent.getTo().getWorld() != null) {
|
||||||
|
final Location fLoc = tpEvent.getTo();
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
FirstSpawnTeleportEvent tpEvent = new FirstSpawnTeleportEvent(player, player.getLocation(), loc);
|
player.teleport(fLoc);
|
||||||
plugin.getServer().getPluginManager().callEvent(tpEvent);
|
|
||||||
if (!tpEvent.isCancelled()) {
|
|
||||||
if (player.isOnline() && tpEvent.getTo() != null && tpEvent.getTo().getWorld() != null) {
|
|
||||||
player.teleport(tpEvent.getTo());
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ import fr.xephi.authme.cache.auth.PlayerAuth;
|
|||||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
|
import fr.xephi.authme.events.AuthMeAsyncPreLoginEvent;
|
||||||
import fr.xephi.authme.listener.AuthMePlayerListener;
|
import fr.xephi.authme.listener.AuthMePlayerListener;
|
||||||
import fr.xephi.authme.security.PasswordSecurity;
|
import fr.xephi.authme.security.PasswordSecurity;
|
||||||
import fr.xephi.authme.security.RandomString;
|
import fr.xephi.authme.security.RandomString;
|
||||||
@ -113,6 +114,10 @@ public class AsyncronousLogin {
|
|||||||
m.send(player, "vb_nonActiv");
|
m.send(player, "vb_nonActiv");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
AuthMeAsyncPreLoginEvent event = new AuthMeAsyncPreLoginEvent(player);
|
||||||
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
|
if (!event.canLogin())
|
||||||
|
return null;
|
||||||
return pAuth;
|
return pAuth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,13 +56,7 @@ public class ProcessSyncronousPlayerLogout implements Runnable {
|
|||||||
player.setFlying(true);
|
player.setFlying(true);
|
||||||
}
|
}
|
||||||
// Player is now logout... Time to fire event !
|
// Player is now logout... Time to fire event !
|
||||||
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
|
Bukkit.getServer().getPluginManager().callEvent(new LogoutEvent(player));
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Bukkit.getServer().getPluginManager().callEvent(new LogoutEvent(player));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
m.send(player, "logout");
|
m.send(player, "logout");
|
||||||
ConsoleLogger.info(player.getDisplayName() + " logged out");
|
ConsoleLogger.info(player.getDisplayName() + " logged out");
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ import fr.xephi.authme.cache.auth.PlayerCache;
|
|||||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||||
import fr.xephi.authme.cache.limbo.LimboPlayer;
|
import fr.xephi.authme.cache.limbo.LimboPlayer;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
|
import fr.xephi.authme.events.RestoreInventoryEvent;
|
||||||
import fr.xephi.authme.listener.AuthMePlayerListener;
|
import fr.xephi.authme.listener.AuthMePlayerListener;
|
||||||
import fr.xephi.authme.plugin.manager.CombatTagComunicator;
|
import fr.xephi.authme.plugin.manager.CombatTagComunicator;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
@ -21,7 +22,7 @@ public class AsyncronousQuit {
|
|||||||
|
|
||||||
protected AuthMe plugin;
|
protected AuthMe plugin;
|
||||||
protected DataSource database;
|
protected DataSource database;
|
||||||
protected Player p;
|
protected Player player;
|
||||||
protected Utils utils = Utils.getInstance();
|
protected Utils utils = Utils.getInstance();
|
||||||
private String name;
|
private String name;
|
||||||
private ItemStack[] armor = null;
|
private ItemStack[] armor = null;
|
||||||
@ -33,7 +34,7 @@ public class AsyncronousQuit {
|
|||||||
|
|
||||||
public AsyncronousQuit(Player p, AuthMe plugin, DataSource database,
|
public AsyncronousQuit(Player p, AuthMe plugin, DataSource database,
|
||||||
boolean isKick) {
|
boolean isKick) {
|
||||||
this.p = p;
|
this.player = p;
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.database = database;
|
this.database = database;
|
||||||
this.name = p.getName().toLowerCase();
|
this.name = p.getName().toLowerCase();
|
||||||
@ -41,7 +42,8 @@ public class AsyncronousQuit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void process() {
|
public void process() {
|
||||||
final Player player = p;
|
if (player == null)
|
||||||
|
return;
|
||||||
if (plugin.getCitizensCommunicator().isNPC(player) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) {
|
if (plugin.getCitizensCommunicator().isNPC(player) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -64,7 +66,8 @@ public class AsyncronousQuit {
|
|||||||
inv = limbo.getInventory();
|
inv = limbo.getInventory();
|
||||||
armor = limbo.getArmour();
|
armor = limbo.getArmour();
|
||||||
}
|
}
|
||||||
utils.addNormal(player, limbo.getGroup());
|
if (limbo.getGroup() != null && !limbo.getGroup().equals(""))
|
||||||
|
utils.addNormal(player, limbo.getGroup());
|
||||||
needToChange = true;
|
needToChange = true;
|
||||||
isOp = limbo.getOperator();
|
isOp = limbo.getOperator();
|
||||||
isFlying = limbo.isFlying();
|
isFlying = limbo.isFlying();
|
||||||
@ -94,6 +97,16 @@ public class AsyncronousQuit {
|
|||||||
database.setUnlogged(name);
|
database.setUnlogged(name);
|
||||||
}
|
}
|
||||||
AuthMePlayerListener.gameMode.remove(name);
|
AuthMePlayerListener.gameMode.remove(name);
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new ProcessSyncronousPlayerQuit(plugin, player, inv, armor, isOp, isFlying, needToChange));
|
final Player p = player;
|
||||||
|
RestoreInventoryEvent ev = new RestoreInventoryEvent(player, inv, armor, true);
|
||||||
|
Bukkit.getPluginManager().callEvent(ev);
|
||||||
|
if (ev.isCancelled()) {
|
||||||
|
inv = null;
|
||||||
|
armor = null;
|
||||||
|
} else {
|
||||||
|
inv = ev.getInventory();
|
||||||
|
armor = ev.getArmor();
|
||||||
|
}
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new ProcessSyncronousPlayerQuit(plugin, p, inv, armor, isOp, isFlying, needToChange));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.events.RestoreInventoryEvent;
|
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
|
|
||||||
public class ProcessSyncronousPlayerQuit implements Runnable {
|
public class ProcessSyncronousPlayerQuit implements Runnable {
|
||||||
@ -32,13 +31,8 @@ public class ProcessSyncronousPlayerQuit implements Runnable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (inv != null && armor != null) {
|
if (inv != null && armor != null)
|
||||||
RestoreInventoryEvent ev = new RestoreInventoryEvent(player, inv, armor);
|
plugin.api.setPlayerInventory(player, inv, armor);
|
||||||
player.getServer().getPluginManager().callEvent(ev);
|
|
||||||
if (!ev.isCancelled()) {
|
|
||||||
plugin.api.setPlayerInventory(player, ev.getInventory(), ev.getArmor());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (needToChange) {
|
if (needToChange) {
|
||||||
player.setOp(isOp);
|
player.setOp(isOp);
|
||||||
if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) {
|
if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) {
|
||||||
|
@ -29,6 +29,7 @@ public enum HashAlgorithm {
|
|||||||
ROYALAUTH(fr.xephi.authme.security.crypts.ROYALAUTH.class),
|
ROYALAUTH(fr.xephi.authme.security.crypts.ROYALAUTH.class),
|
||||||
CRAZYCRYPT1(fr.xephi.authme.security.crypts.CRAZYCRYPT1.class),
|
CRAZYCRYPT1(fr.xephi.authme.security.crypts.CRAZYCRYPT1.class),
|
||||||
BCRYPT2Y(fr.xephi.authme.security.crypts.BCRYPT2Y.class),
|
BCRYPT2Y(fr.xephi.authme.security.crypts.BCRYPT2Y.class),
|
||||||
|
SALTEDSHA512(fr.xephi.authme.security.crypts.SALTEDSHA512.class),
|
||||||
CUSTOM(Null.class);
|
CUSTOM(Null.class);
|
||||||
|
|
||||||
Class<?> classe;
|
Class<?> classe;
|
||||||
|
@ -96,7 +96,12 @@ public class PasswordSecurity {
|
|||||||
userSalt.put(playerName, salt);
|
userSalt.put(playerName, salt);
|
||||||
break;
|
break;
|
||||||
case BCRYPT2Y:
|
case BCRYPT2Y:
|
||||||
salt = createSalt(22);
|
salt = createSalt(16);
|
||||||
|
userSalt.put(playerName, salt);
|
||||||
|
break;
|
||||||
|
case SALTEDSHA512:
|
||||||
|
salt = createSalt(32);
|
||||||
|
userSalt.put(playerName, salt);
|
||||||
break;
|
break;
|
||||||
case MD5:
|
case MD5:
|
||||||
case SHA1:
|
case SHA1:
|
||||||
@ -165,7 +170,7 @@ public class PasswordSecurity {
|
|||||||
PlayerAuth nAuth = AuthMe.getInstance().database.getAuth(playerName);
|
PlayerAuth nAuth = AuthMe.getInstance().database.getAuth(playerName);
|
||||||
if (nAuth != null) {
|
if (nAuth != null) {
|
||||||
nAuth.setHash(getHash(Settings.getPasswordHash, password, playerName));
|
nAuth.setHash(getHash(Settings.getPasswordHash, password, playerName));
|
||||||
nAuth.setSalt(userSalt.get(playerName));
|
nAuth.setSalt(userSalt.containsKey(playerName) ? userSalt.get(playerName) : "");
|
||||||
AuthMe.getInstance().database.updatePassword(nAuth);
|
AuthMe.getInstance().database.updatePassword(nAuth);
|
||||||
AuthMe.getInstance().database.updateSalt(nAuth);
|
AuthMe.getInstance().database.updateSalt(nAuth);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,32 @@
|
|||||||
|
package fr.xephi.authme.security.crypts;
|
||||||
|
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
|
import fr.xephi.authme.AuthMe;
|
||||||
|
|
||||||
|
public class SALTEDSHA512 implements EncryptionMethod {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHash(String password, String salt, String name)
|
||||||
|
throws NoSuchAlgorithmException {
|
||||||
|
return getSHA512(password + salt);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean comparePassword(String hash, String password,
|
||||||
|
String playerName) throws NoSuchAlgorithmException {
|
||||||
|
String salt = AuthMe.getInstance().database.getAuth(playerName).getSalt();
|
||||||
|
return hash.equals(getHash(password, salt, ""));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getSHA512(String message)
|
||||||
|
throws NoSuchAlgorithmException {
|
||||||
|
MessageDigest sha512 = MessageDigest.getInstance("SHA-512");
|
||||||
|
sha512.reset();
|
||||||
|
sha512.update(message.getBytes());
|
||||||
|
byte[] digest = sha512.digest();
|
||||||
|
return String.format("%0" + (digest.length << 1) + "x", new BigInteger(1, digest));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user