Browse Source

Petition db update including table creation.

master
MagicBot 1 year ago
parent
commit
7aa63a65b6
  1. 77
      src/engine/db/handlers/dbPetitionHandler.java
  2. 1
      src/engine/gameManager/DbManager.java
  3. 7
      src/engine/net/client/handlers/PetitionReceivedMsgHandler.java
  4. 46
      src/engine/objects/Petition.java
  5. 3
      src/engine/server/world/WorldServer.java

77
src/engine/db/handlers/dbPetitionHandler.java

@ -0,0 +1,77 @@
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.db.handlers;
import engine.Enum;
import engine.gameManager.DbManager;
import engine.objects.Petition;
import org.pmw.tinylog.Logger;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class dbPetitionHandler extends dbHandlerBase {
public dbPetitionHandler() {
}
public void CREATE_PETITION_TABLE() {
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SET sql_notes = 0; CREATE TABLE IF NOT EXISTS dyn_petition (\n" +
" petitionNumber INT AUTO_INCREMENT NOT NULL,\n" +
" petitionTime DATETIME,\n" +
" primaryType VARCHAR(50),\n" +
" subType VARCHAR(50),\n" +
" message VARCHAR(255),\n" +
" accountID INT,\n" +
" account VARCHAR(255),\n" +
" characterID INT,\n" +
" `character` VARCHAR(255),\n" +
" location VARCHAR(255),\n" +
" PRIMARY KEY (petitionNumber)\n" +
") ENGINE = innodb ROW_FORMAT = DEFAULT; SET sql_notes = 1;")) {
preparedStatement.executeQuery();
} catch (SQLException e) {
Logger.error(e);
}
}
public void WRITE_PETITION_TO_TABLE(Petition petition) {
try (Connection connection = DbManager.getConnection();
//check that table exists
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_petition` (`petitionTime`, `primaryType`, `subType`, `accountID`, `account`, `characterID`, `character`, `location`, `message`)" +
" VALUES (?,?,?,?,?,?,?,?,?);")) {
preparedStatement.setTimestamp(1, new java.sql.Timestamp(System.currentTimeMillis()));
preparedStatement.setString(2, Enum.PetitionType.values()[petition.primaryType].name());
preparedStatement.setString(3, Enum.PetitionSubType.values()[petition.subType].name());
preparedStatement.setInt(4, petition.reportAccount.getObjectUUID());
preparedStatement.setString(5, petition.reportAccount.getUname());
preparedStatement.setInt(6, petition.reportPlayer.getObjectUUID());
preparedStatement.setString(7, petition.reportPlayer.getFirstName());
preparedStatement.setString(8, petition.playerLocation.toString());
preparedStatement.setString(9, petition.message);
preparedStatement.executeUpdate();
} catch (SQLException e) {
Logger.error("CREATE PETITION FAILED: " + e);
}
}
}

1
src/engine/gameManager/DbManager.java

@ -74,6 +74,7 @@ public enum DbManager {
public static final dbRunegateHandler RunegateQueries = new dbRunegateHandler(); public static final dbRunegateHandler RunegateQueries = new dbRunegateHandler();
public static final dbPowerHandler PowerQueries = new dbPowerHandler(); public static final dbPowerHandler PowerQueries = new dbPowerHandler();
public static final dbPetitionHandler PetitionQueries = new dbPetitionHandler();
private static final EnumMap<GameObjectType, ConcurrentHashMap<Integer, AbstractGameObject>> objectCache = new EnumMap<>(GameObjectType.class); private static final EnumMap<GameObjectType, ConcurrentHashMap<Integer, AbstractGameObject>> objectCache = new EnumMap<>(GameObjectType.class);
public static Hasher hasher; public static Hasher hasher;
private static HikariDataSource connectionPool = null; private static HikariDataSource connectionPool = null;

7
src/engine/net/client/handlers/PetitionReceivedMsgHandler.java

@ -1,6 +1,7 @@
package engine.net.client.handlers; package engine.net.client.handlers;
import engine.exception.MsgSendException; import engine.exception.MsgSendException;
import engine.gameManager.DbManager;
import engine.net.client.ClientConnection; import engine.net.client.ClientConnection;
import engine.net.client.msg.ClientNetMsg; import engine.net.client.msg.ClientNetMsg;
import engine.net.client.msg.PetitionReceivedMsg; import engine.net.client.msg.PetitionReceivedMsg;
@ -20,13 +21,13 @@ public class PetitionReceivedMsgHandler extends AbstractClientMsgHandler {
if (origin == null) if (origin == null)
return false; return false;
Petition report = new Petition(msg, origin); Petition petition = new Petition(msg, origin);
if (report == null) if (petition == null)
return false; return false;
try { try {
report.updateDatabase(); DbManager.PetitionQueries.WRITE_PETITION_TO_TABLE(petition);
} catch (Exception e) { } catch (Exception e) {
return false; return false;
} }

46
src/engine/objects/Petition.java

@ -6,22 +6,13 @@
// Magicbane Emulator Project © 2013 - 2022 // Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com // www.magicbane.com
package engine.objects; package engine.objects;
import engine.Enum;
import engine.gameManager.DbManager;
import engine.math.Vector3fImmutable; import engine.math.Vector3fImmutable;
import engine.net.client.ClientConnection; import engine.net.client.ClientConnection;
import engine.net.client.msg.ClientNetMsg; import engine.net.client.msg.ClientNetMsg;
import engine.net.client.msg.PetitionReceivedMsg; import engine.net.client.msg.PetitionReceivedMsg;
import org.pmw.tinylog.Logger;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class Petition extends AbstractGameObject { public class Petition {
public int primaryType; public int primaryType;
public int subType; public int subType;
public Account reportAccount; public Account reportAccount;
@ -29,42 +20,13 @@ public class Petition extends AbstractGameObject {
public Vector3fImmutable playerLocation; public Vector3fImmutable playerLocation;
public String message; public String message;
public Petition(ClientNetMsg msg, ClientConnection origin){ public Petition(ClientNetMsg msg, ClientConnection origin) {
this.primaryType = ((PetitionReceivedMsg)msg).getType(); this.primaryType = ((PetitionReceivedMsg) msg).getType();
this.subType = ((PetitionReceivedMsg)msg).getSubType(); this.subType = ((PetitionReceivedMsg) msg).getSubType();
this.reportAccount = origin.getAccount(); this.reportAccount = origin.getAccount();
this.reportPlayer = origin.getPlayerCharacter(); this.reportPlayer = origin.getPlayerCharacter();
this.playerLocation = origin.getPlayerCharacter().getLoc(); this.playerLocation = origin.getPlayerCharacter().getLoc();
this.message = ((PetitionReceivedMsg) msg).getMessage(); this.message = ((PetitionReceivedMsg) msg).getMessage();
} }
public static String getLocationString(Vector3fImmutable loc){
return loc.x + "," + loc.y + "," + loc.z;
}
@Override
public void updateDatabase() {
try (Connection connection = DbManager.getConnection();
//check that table exists
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_petition` (`petitionTime`=?, `primaryType`=?, `subType`=?, `accountID`=?, `account`=?, `characterID`=?, `character`=?, `location`=?, `message`=?);")) {
preparedStatement.setTimestamp(1, new java.sql.Timestamp(System.currentTimeMillis()));
preparedStatement.setString(2, Enum.PetitionType.values()[this.primaryType].name());
preparedStatement.setString(3, Enum.PetitionSubType.values()[this.subType].name());
preparedStatement.setInt(4, this.reportAccount.getObjectUUID());
preparedStatement.setString(5, this.reportAccount.getUname());
preparedStatement.setInt(6, this.reportPlayer.getObjectUUID());
preparedStatement.setString(7, this.reportPlayer.getFirstName());
preparedStatement.setString(8, getLocationString(this.playerLocation));
preparedStatement.setString(9, this.message);
preparedStatement.executeUpdate();
} catch (SQLException e) {
Logger.error("CREATE PETITION FAILED: " + e);
}
}
} }

3
src/engine/server/world/WorldServer.java

@ -321,6 +321,9 @@ public class WorldServer {
Logger.info("Initializing NPC Profits"); Logger.info("Initializing NPC Profits");
DbManager.NPCQueries.LOAD_NPC_PROFITS(); DbManager.NPCQueries.LOAD_NPC_PROFITS();
Logger.info("Initializing Petition Table");
DbManager.PetitionQueries.CREATE_PETITION_TABLE();
Logger.info("Initializing MeshBounds"); Logger.info("Initializing MeshBounds");
MeshBounds.InitializeBuildingBounds(); MeshBounds.InitializeBuildingBounds();

Loading…
Cancel
Save