Browse Source

Popstring to trywithresources

master
MagicBot 2 years ago
parent
commit
3c5ffed352
  1. 2
      src/discord/Database.java
  2. 2
      src/discord/handlers/StatusRequestHandler.java
  3. 21
      src/engine/db/handlers/dbCSSessionHandler.java
  4. 32
      src/engine/gameManager/SimulationManager.java

2
src/discord/Database.java

@ -355,7 +355,7 @@ public class Database {
return discordAccounts; return discordAccounts;
} }
public String getPopulationSTring() { public String getPopulationString() {
String popString = ""; String popString = "";

2
src/discord/handlers/StatusRequestHandler.java

@ -29,7 +29,7 @@ public class StatusRequestHandler {
outString += "OFFLINE\n"; outString += "OFFLINE\n";
if (Database.online == true) if (Database.online == true)
outString += MagicBot.database.getPopulationSTring(); outString += MagicBot.database.getPopulationString();
else else
outString += "Database offline: no population data."; outString += "Database offline: no population data.";

21
src/engine/db/handlers/dbCSSessionHandler.java

@ -36,27 +36,6 @@ public class dbCSSessionHandler extends dbHandlerBase {
setString(5, machineID); setString(5, machineID);
return (executeUpdate() != 0); return (executeUpdate() != 0);
} }
// This method returns population metrics from the database
public String GET_POPULATION_STRING() {
String outString = null;
// Set up call to stored procedure
prepareCallable("CALL GET_POPULATION_STRING()");
try {
// Evaluate database ordinal and return enum
outString = getString("popstring");
} catch (Exception e) {
Logger.error( "Failure in stored procedure:" + e.getMessage());
} finally {
closeCallable();
}
return outString;
}
public boolean DELETE_UNUSED_CSSESSION(String secKey) { public boolean DELETE_UNUSED_CSSESSION(String secKey) {
prepareCallable("DELETE FROM `dyn_session` WHERE `secretKey`=? && `characterID` IS NULL"); prepareCallable("DELETE FROM `dyn_session` WHERE `secretKey`=? && `characterID` IS NULL");

32
src/engine/gameManager/SimulationManager.java

@ -10,12 +10,17 @@ package engine.gameManager;
import engine.Enum; import engine.Enum;
import engine.Enum.GameObjectType; import engine.Enum.GameObjectType;
import engine.db.archive.DataWarehouse;
import engine.objects.AbstractGameObject; import engine.objects.AbstractGameObject;
import engine.objects.City; import engine.objects.City;
import engine.objects.PlayerCharacter; import engine.objects.PlayerCharacter;
import engine.objects.Runegate; import engine.objects.Runegate;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import java.util.Collection; import java.util.Collection;
@ -49,15 +54,26 @@ public enum SimulationManager {
// don't allow instantiation. // don't allow instantiation.
} }
public static String getPopulationString() { public static String getPopulationString() {
String outString;
String newLine = System.getProperty("line.separator");
outString = "[LUA_POPULATION()]" + newLine;
outString += DbManager.CSSessionQueries.GET_POPULATION_STRING();
return outString;
}
/* String popString = "";
try (Connection connection = DataWarehouse.connectionPool.getConnection();
PreparedStatement getPopString = connection.prepareStatement("CALL GET_POPULATION_STRING()");) {
ResultSet rs = getPopString.executeQuery();
if (rs.next())
popString = rs.getString("popstring");
} catch (SQLException e) {
Logger.error(e.toString());
}
return popString;
}
/*
* Update the simulation. *** Important: Whatever you do in here, do it damn * Update the simulation. *** Important: Whatever you do in here, do it damn
* quick! * quick!
*/ */

Loading…
Cancel
Save