|
|
@ -15,33 +15,34 @@ import org.pmw.tinylog.Logger; |
|
|
|
|
|
|
|
|
|
|
|
import java.sql.*; |
|
|
|
import java.sql.*; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
public class Database { |
|
|
|
public class Database { |
|
|
|
|
|
|
|
|
|
|
|
public String sqlURI; |
|
|
|
|
|
|
|
public static Boolean online; |
|
|
|
public static Boolean online; |
|
|
|
|
|
|
|
|
|
|
|
// Load and instance the JDBC Driver
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static { |
|
|
|
static { |
|
|
|
try { |
|
|
|
try { |
|
|
|
Class.forName("com.mysql.cj.jdbc.Driver").newInstance(); |
|
|
|
Class.forName("com.mysql.cj.jdbc.Driver").newInstance(); |
|
|
|
} catch (InstantiationException | ClassNotFoundException | IllegalAccessException e) { |
|
|
|
} catch (InstantiationException | ClassNotFoundException | IllegalAccessException e) { |
|
|
|
// TODO Auto-generated catch block
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
Logger.error(e.toString()); |
|
|
|
Logger.error(e.toString()); |
|
|
|
; |
|
|
|
|
|
|
|
online = false; |
|
|
|
online = false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Load and instance the JDBC Driver
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String sqlURI; |
|
|
|
|
|
|
|
|
|
|
|
public void configureDatabase() { |
|
|
|
public void configureDatabase() { |
|
|
|
|
|
|
|
|
|
|
|
// Build connection string from JSON object.
|
|
|
|
// Build connection string from JSON object.
|
|
|
|
|
|
|
|
|
|
|
|
sqlURI = "jdbc:mysql://"; |
|
|
|
sqlURI = "jdbc:mysql://"; |
|
|
|
sqlURI += ConfigManager.MB_DATABASE_ADDRESS.getValue() + ':' + ConfigManager.MB_DATABASE_PORT.getValue(); |
|
|
|
sqlURI += ConfigManager.MB_DATABASE_ADDRESS.getValue() + ':' + ConfigManager.MB_DATABASE_PORT.getValue(); |
|
|
|
sqlURI += '/' + (String) ConfigManager.MB_DATABASE_NAME.getValue() + '?'; |
|
|
|
sqlURI += '/' + ConfigManager.MB_DATABASE_NAME.getValue() + '?'; |
|
|
|
sqlURI += "useServerPrepStmts=true"; |
|
|
|
sqlURI += "useServerPrepStmts=true"; |
|
|
|
sqlURI += "&cachePrepStmts=false"; |
|
|
|
sqlURI += "&cachePrepStmts=false"; |
|
|
|
sqlURI += "&cacheCallableStmts=true"; |
|
|
|
sqlURI += "&cacheCallableStmts=true"; |
|
|
@ -66,8 +67,7 @@ public class Database { |
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) { |
|
|
|
} catch (SQLException e) { |
|
|
|
Logger.error(e.toString()); |
|
|
|
Logger.error(e.toString()); |
|
|
|
; |
|
|
|
online = false; |
|
|
|
this.online = false; |
|
|
|
|
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -88,8 +88,7 @@ public class Database { |
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) { |
|
|
|
} catch (SQLException e) { |
|
|
|
Logger.error(e.toString()); |
|
|
|
Logger.error(e.toString()); |
|
|
|
; |
|
|
|
online = false; |
|
|
|
this.online = false; |
|
|
|
|
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -111,7 +110,7 @@ public class Database { |
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) { |
|
|
|
} catch (SQLException e) { |
|
|
|
Logger.error(e.toString()); |
|
|
|
Logger.error(e.toString()); |
|
|
|
this.online = false; |
|
|
|
online = false; |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -157,7 +156,7 @@ public class Database { |
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) { |
|
|
|
} catch (SQLException e) { |
|
|
|
Logger.error(e.toString()); |
|
|
|
Logger.error(e.toString()); |
|
|
|
this.online = false; |
|
|
|
online = false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return discordAccounts; |
|
|
|
return discordAccounts; |
|
|
@ -188,7 +187,7 @@ public class Database { |
|
|
|
} catch (SQLException e) { |
|
|
|
} catch (SQLException e) { |
|
|
|
Logger.error(e.toString()); |
|
|
|
Logger.error(e.toString()); |
|
|
|
|
|
|
|
|
|
|
|
this.online = false; |
|
|
|
online = false; |
|
|
|
} |
|
|
|
} |
|
|
|
return outString; |
|
|
|
return outString; |
|
|
|
} |
|
|
|
} |
|
|
@ -214,15 +213,15 @@ public class Database { |
|
|
|
|
|
|
|
|
|
|
|
if (counter > 2) { |
|
|
|
if (counter > 2) { |
|
|
|
outString += "\n"; |
|
|
|
outString += "\n"; |
|
|
|
counter = 0; } |
|
|
|
counter = 0; |
|
|
|
else |
|
|
|
} else |
|
|
|
outString += " "; |
|
|
|
outString += " "; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} catch (SQLException e) { |
|
|
|
} catch (SQLException e) { |
|
|
|
Logger.error(e.toString()); |
|
|
|
Logger.error(e.toString()); |
|
|
|
|
|
|
|
|
|
|
|
this.online = false; |
|
|
|
online = false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (outString.length() > 1500) |
|
|
|
if (outString.length() > 1500) |
|
|
@ -230,6 +229,7 @@ public class Database { |
|
|
|
else |
|
|
|
else |
|
|
|
return outString; |
|
|
|
return outString; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public int getTrashCount() { |
|
|
|
public int getTrashCount() { |
|
|
|
|
|
|
|
|
|
|
|
int trashCount = 0; |
|
|
|
int trashCount = 0; |
|
|
@ -251,12 +251,40 @@ public class Database { |
|
|
|
} catch (SQLException e) { |
|
|
|
} catch (SQLException e) { |
|
|
|
Logger.error(e.toString()); |
|
|
|
Logger.error(e.toString()); |
|
|
|
|
|
|
|
|
|
|
|
this.online = false; |
|
|
|
online = false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return trashCount; |
|
|
|
return trashCount; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public HashMap<Integer, String> getAdminEvents() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HashMap<Integer, String> outMap = new HashMap<>(); |
|
|
|
|
|
|
|
String queryString = "SELECT * from dyn_admin_log where `SentFlag` = 0"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try (Connection connection = DriverManager.getConnection(sqlURI, ConfigManager.MB_DATABASE_USER.getValue(), |
|
|
|
|
|
|
|
ConfigManager.MB_DATABASE_PASS.getValue())) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Discord Admin Log lookup of unreported events
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PreparedStatement adminLogQuery = connection.prepareStatement(queryString); |
|
|
|
|
|
|
|
ResultSet rs = adminLogQuery.executeQuery(); |
|
|
|
|
|
|
|
String workString; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (rs.next()) { |
|
|
|
|
|
|
|
workString = "___Admin Event___\n" + |
|
|
|
|
|
|
|
"Character: " + rs.getString("charName") + "\n" + |
|
|
|
|
|
|
|
"Event: " + rs.getString("eventString"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
outMap.put(rs.getInt("entry"), workString); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
|
|
|
Logger.error(e.toString()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return outMap; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public String getTrashFile() { |
|
|
|
public String getTrashFile() { |
|
|
|
|
|
|
|
|
|
|
|
String outString = "machineID : count\n"; |
|
|
|
String outString = "machineID : count\n"; |
|
|
@ -278,7 +306,7 @@ public class Database { |
|
|
|
} catch (SQLException e) { |
|
|
|
} catch (SQLException e) { |
|
|
|
Logger.error(e.toString()); |
|
|
|
Logger.error(e.toString()); |
|
|
|
|
|
|
|
|
|
|
|
this.online = false; |
|
|
|
online = false; |
|
|
|
} |
|
|
|
} |
|
|
|
return outString; |
|
|
|
return outString; |
|
|
|
} |
|
|
|
} |
|
|
@ -332,8 +360,7 @@ public class Database { |
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) { |
|
|
|
} catch (SQLException e) { |
|
|
|
Logger.error(e.toString()); |
|
|
|
Logger.error(e.toString()); |
|
|
|
; |
|
|
|
online = false; |
|
|
|
this.online = false; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return discordAccounts; |
|
|
|
return discordAccounts; |
|
|
@ -355,7 +382,7 @@ public class Database { |
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) { |
|
|
|
} catch (SQLException e) { |
|
|
|
Logger.error(e.toString()); |
|
|
|
Logger.error(e.toString()); |
|
|
|
this.online = false; |
|
|
|
online = false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return popString; |
|
|
|
return popString; |
|
|
@ -374,7 +401,7 @@ public class Database { |
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) { |
|
|
|
} catch (SQLException e) { |
|
|
|
Logger.error(e.toString()); |
|
|
|
Logger.error(e.toString()); |
|
|
|
this.online = false; |
|
|
|
online = false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|