forked from MagicBane/Server
chore: baseline subdate2 snapshot for AI refactoring
This commit is contained in:
commit
69aa91d403
827 files changed
+161223
No files matched your search
@@ -0,0 +1,382 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.archive;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.Bane;
|
||||
import engine.objects.City;
|
||||
import engine.workthreads.WarehousePushThread;
|
||||
import org.joda.time.DateTime;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
import static engine.Enum.RecordEventType;
|
||||
|
||||
public class BaneRecord extends DataRecord {
|
||||
|
||||
private static final LinkedBlockingQueue<BaneRecord> recordPool = new LinkedBlockingQueue<>();
|
||||
private RecordEventType eventType;
|
||||
private String cityHash;
|
||||
private String cityName;
|
||||
private String cityGuildHash;
|
||||
private String cityNationHash;
|
||||
private String baneDropperHash;
|
||||
private String baneGuildHash;
|
||||
private String baneNationHash;
|
||||
private DateTime baneLiveTime;
|
||||
private DateTime baneDropTime;
|
||||
|
||||
private BaneRecord(Bane bane) {
|
||||
this.recordType = Enum.DataRecordType.BANE;
|
||||
this.eventType = RecordEventType.PENDING;
|
||||
}
|
||||
|
||||
public static BaneRecord borrow(Bane bane, RecordEventType eventType) {
|
||||
BaneRecord baneRecord;
|
||||
|
||||
baneRecord = recordPool.poll();
|
||||
|
||||
if (baneRecord == null) {
|
||||
baneRecord = new BaneRecord(bane);
|
||||
baneRecord.eventType = eventType;
|
||||
} else {
|
||||
baneRecord.recordType = Enum.DataRecordType.BANE;
|
||||
baneRecord.eventType = eventType;
|
||||
|
||||
}
|
||||
|
||||
baneRecord.cityHash = bane.getCity().getHash();
|
||||
baneRecord.cityName = bane.getCity().getCityName();
|
||||
baneRecord.cityGuildHash = bane.getCity().getGuild().getHash();
|
||||
baneRecord.cityNationHash = bane.getCity().getGuild().getNation().getHash();
|
||||
|
||||
|
||||
if (bane.getOwner() == null) {
|
||||
baneRecord.baneDropperHash = "ERRANT";
|
||||
baneRecord.baneGuildHash = "ERRANT";
|
||||
baneRecord.baneNationHash = "ERRANT";
|
||||
} else {
|
||||
baneRecord.baneDropperHash = DataWarehouse.hasher.encrypt(bane.getOwner().getObjectUUID()); // getPlayerCharacter didn't check hash first? OMFG
|
||||
|
||||
|
||||
baneRecord.baneGuildHash = bane.getOwner().getGuild().getHash();
|
||||
baneRecord.baneNationHash = bane.getOwner().getGuild().getNation().getHash();
|
||||
|
||||
|
||||
baneRecord.baneLiveTime = bane.getLiveDate();
|
||||
baneRecord.baneDropTime = bane.getPlacementDate();
|
||||
}
|
||||
|
||||
|
||||
return baneRecord;
|
||||
}
|
||||
|
||||
public static PreparedStatement buildBanePushStatement(Connection connection, ResultSet rs) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_banehistory` (`event_number`, `city_id`, `city_name`, `char_id`, `offGuild_id`, `offNat_id`, `defGuild_id`, `defNat_id`, `dropDatetime`, `liveDateTime`, `resolution`) VALUES(?,?,?,?,?,?,?,?,?,?,?)";
|
||||
java.util.Date sqlDateTime;
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
// Bind record data
|
||||
|
||||
outStatement.setInt(1, rs.getInt("event_number"));
|
||||
outStatement.setString(2, rs.getString("city_id"));
|
||||
outStatement.setString(3, rs.getString("city_name"));
|
||||
outStatement.setString(4, rs.getString("char_id"));
|
||||
outStatement.setString(5, rs.getString("offGuild_id"));
|
||||
outStatement.setString(6, rs.getString("offNat_id"));
|
||||
outStatement.setString(7, rs.getString("defGuild_id"));
|
||||
outStatement.setString(8, rs.getString("defNat_id"));
|
||||
|
||||
sqlDateTime = rs.getTimestamp("dropDatetime");
|
||||
|
||||
if (sqlDateTime == null)
|
||||
outStatement.setNull(9, Types.DATE);
|
||||
else
|
||||
outStatement.setTimestamp(9, rs.getTimestamp("dropDatetime"));
|
||||
|
||||
sqlDateTime = rs.getTimestamp("dropDatetime");
|
||||
|
||||
if (sqlDateTime == null)
|
||||
outStatement.setNull(10, Types.DATE);
|
||||
else
|
||||
outStatement.setTimestamp(10, rs.getTimestamp("liveDateTime"));
|
||||
|
||||
outStatement.setString(11, rs.getString("resolution"));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public static PreparedStatement buildBaneQueryStatement(Connection connection) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "SELECT * FROM `warehouse_banehistory` WHERE `event_number` > ?";
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setInt(1, WarehousePushThread.baneIndex);
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public static DateTime getLastBaneDateTime(City city) {
|
||||
|
||||
DateTime outDateTime = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = buildDateTimeQueryStatement(connection, city);
|
||||
ResultSet rs = statement.executeQuery()) {
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
outDateTime = new DateTime(rs.getTimestamp("endDatetime"));
|
||||
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
|
||||
return outDateTime;
|
||||
}
|
||||
|
||||
|
||||
private static PreparedStatement buildDateTimeQueryStatement(Connection connection, City city) throws SQLException {
|
||||
PreparedStatement outStatement;
|
||||
String queryString = "SELECT `endDatetime` FROM `warehouse_banehistory` WHERE `city_id` = ? ORDER BY `endDatetime` DESC LIMIT 1";
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setString(1, city.getHash());
|
||||
return outStatement;
|
||||
|
||||
}
|
||||
|
||||
public static void updateLiveDate(Bane bane, DateTime dateTime) {
|
||||
|
||||
if (bane == null)
|
||||
return;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = buildUpdateLiveDateStatement(connection, bane, dateTime)) {
|
||||
|
||||
statement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private static PreparedStatement buildUpdateLiveDateStatement(Connection connection, Bane bane, DateTime dateTime) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "UPDATE `warehouse_banehistory` SET `liveDatetime` = ?, `dirty` = 1 WHERE `city_id` = ? AND `resolution` = 'PENDING'";
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setTimestamp(1, new java.sql.Timestamp(dateTime.getMillis()));
|
||||
outStatement.setString(2, bane.getCity().getHash());
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
private static PreparedStatement buildUpdateResolutionStatement(Connection connection, Bane bane, RecordEventType eventType) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "UPDATE `warehouse_banehistory` SET `endDatetime` = ?, `resolution` = ?, `dirty` = 1 WHERE `city_id` = ? AND `resolution` = 'PENDING'";
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setTimestamp(1, Timestamp.valueOf(LocalDateTime.now()));
|
||||
outStatement.setString(2, eventType.name());
|
||||
outStatement.setString(3, bane.getCity().getHash());
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public static void updateResolution(Bane bane, RecordEventType eventType) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = buildUpdateResolutionStatement(connection, bane, eventType)) {
|
||||
|
||||
statement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public static String getBaneHistoryString() {
|
||||
|
||||
String outString;
|
||||
String queryString;
|
||||
String dividerString;
|
||||
String newLine = System.getProperty("line.separator");
|
||||
outString = "[LUA_BANES() DATA WAREHOUSE]" + newLine;
|
||||
dividerString = "--------------------------------" + newLine;
|
||||
queryString = "CALL `baneHistory`()";
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = connection.prepareCall(queryString);
|
||||
ResultSet rs = statement.executeQuery()) {
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
outString += "Magicbane unresolved banes: " + rs.getInt("PENDING") + '/' + rs.getInt("TOTAL") + newLine;
|
||||
outString += dividerString;
|
||||
outString += "Bane Resolution History" + newLine;
|
||||
outString += dividerString;
|
||||
|
||||
outString += "Destruction: " + rs.getInt("DESTROY") + newLine;
|
||||
outString += "Capture: " + rs.getInt("CAPTURE") + newLine;
|
||||
outString += "Defended: " + rs.getInt("DEFEND") + newLine;
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return outString;
|
||||
}
|
||||
|
||||
public static void updateDirtyRecords() {
|
||||
|
||||
String queryString = "SELECT * FROM `warehouse_banehistory` where `dirty` = 1";
|
||||
|
||||
// Reset character delta
|
||||
|
||||
WarehousePushThread.baneDelta = 0;
|
||||
|
||||
try (Connection localConnection = DbManager.getConnection();
|
||||
PreparedStatement statement = localConnection.prepareStatement(queryString, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); // Make this an updatable result set as we'll reset the dirty flag as we go along
|
||||
ResultSet rs = statement.executeQuery()) {
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
// Only update the index and dirty flag
|
||||
// if the remote database update succeeded
|
||||
|
||||
if (updateDirtyRecord(rs) == true)
|
||||
WarehousePushThread.baneDelta++;
|
||||
else
|
||||
continue;
|
||||
|
||||
// Reset the dirty flag in the local database
|
||||
|
||||
rs.updateInt("dirty", 0);
|
||||
rs.updateRow();
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean updateDirtyRecord(ResultSet rs) {
|
||||
|
||||
try (Connection remoteConnection = DataWarehouse.remoteConnectionPool.getConnection();
|
||||
PreparedStatement statement = buildUpdateDirtyStatement(remoteConnection, rs)) {
|
||||
|
||||
statement.execute();
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static PreparedStatement buildUpdateDirtyStatement(Connection connection, ResultSet rs) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement;
|
||||
String queryString = "UPDATE `warehouse_banehistory` SET `liveDateTime` = ?, `endDateTime` = ?, `resolution` = ? WHERE `event_number` = ?";
|
||||
java.util.Date sqlDateTime;
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
// Bind record data
|
||||
|
||||
sqlDateTime = rs.getTimestamp("liveDateTime");
|
||||
|
||||
if (sqlDateTime == null)
|
||||
outStatement.setNull(1, Types.DATE);
|
||||
else
|
||||
outStatement.setTimestamp(1, rs.getTimestamp("liveDateTime"));
|
||||
|
||||
sqlDateTime = rs.getTimestamp("endDateTime");
|
||||
|
||||
if (sqlDateTime == null)
|
||||
outStatement.setNull(2, Types.DATE);
|
||||
else
|
||||
outStatement.setTimestamp(2, rs.getTimestamp("endDateTime"));
|
||||
|
||||
outStatement.setString(3, rs.getString("resolution"));
|
||||
outStatement.setInt(4, rs.getInt("event_number"));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
this.cityHash = null;
|
||||
this.cityGuildHash = null;
|
||||
this.cityNationHash = null;
|
||||
this.baneDropperHash = null;
|
||||
this.baneGuildHash = null;
|
||||
this.baneNationHash = null;
|
||||
this.baneLiveTime = null;
|
||||
}
|
||||
|
||||
public void release() {
|
||||
this.reset();
|
||||
recordPool.add(this);
|
||||
}
|
||||
|
||||
public void write() {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = buildBaneInsertStatement(connection)) {
|
||||
|
||||
statement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private PreparedStatement buildBaneInsertStatement(Connection connection) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_banehistory` (`city_id`, `city_name`, `char_id`, `offGuild_id`, `offNat_id`, `defGuild_id`, `defNat_id`, `dropDatetime`, `liveDateTime`, `resolution`) VALUES(?,?,?,?,?,?,?,?,?,?)";
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
outStatement.setString(1, this.cityHash);
|
||||
outStatement.setString(2, this.cityName);
|
||||
outStatement.setString(3, this.baneDropperHash);
|
||||
outStatement.setString(4, this.baneGuildHash);
|
||||
outStatement.setString(5, this.baneNationHash);
|
||||
outStatement.setString(6, this.cityGuildHash);
|
||||
outStatement.setString(7, this.cityNationHash);
|
||||
|
||||
if (this.baneDropTime == null)
|
||||
outStatement.setNull(8, java.sql.Types.DATE);
|
||||
else
|
||||
outStatement.setTimestamp(8, new java.sql.Timestamp(this.baneDropTime.getMillis()));
|
||||
|
||||
if (this.baneLiveTime == null)
|
||||
outStatement.setNull(9, java.sql.Types.DATE);
|
||||
else
|
||||
outStatement.setTimestamp(9, new java.sql.Timestamp(this.baneLiveTime.getMillis()));
|
||||
|
||||
outStatement.setString(10, this.eventType.name());
|
||||
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
} // END CLASS
|
||||
|
||||
@@ -0,0 +1,284 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.archive;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.Guild;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import engine.workthreads.WarehousePushThread;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
/*
|
||||
* This class warehouses character creation events. It also tracks
|
||||
* updates to summary kills/death data and their promotion class.
|
||||
*/
|
||||
public class CharacterRecord extends DataRecord {
|
||||
|
||||
// Local object pool for class
|
||||
|
||||
private static final LinkedBlockingQueue<CharacterRecord> recordPool = new LinkedBlockingQueue<>();
|
||||
|
||||
private PlayerCharacter player;
|
||||
|
||||
private CharacterRecord(PlayerCharacter player) {
|
||||
this.recordType = Enum.DataRecordType.CHARACTER;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public static CharacterRecord borrow(PlayerCharacter player) {
|
||||
CharacterRecord characterRecord;
|
||||
|
||||
characterRecord = recordPool.poll();
|
||||
|
||||
if (characterRecord == null) {
|
||||
characterRecord = new CharacterRecord(player);
|
||||
} else {
|
||||
characterRecord.recordType = Enum.DataRecordType.CHARACTER;
|
||||
characterRecord.player = player;
|
||||
|
||||
}
|
||||
|
||||
return characterRecord;
|
||||
}
|
||||
|
||||
private static PreparedStatement buildCharacterInsertStatement(Connection connection, PlayerCharacter player) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_characterhistory` (`char_id`, `char_fname`, `char_lname`, `baseClass`, `race`, `promoteClass`, `startingGuild`, `datetime`) VALUES(?,?,?,?,?,?,?,?)";
|
||||
Guild charGuild;
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
charGuild = player.getGuild();
|
||||
|
||||
// Bind character data
|
||||
|
||||
outStatement.setString(1, DataWarehouse.hasher.encrypt(player.getObjectUUID()));
|
||||
outStatement.setString(2, player.getFirstName());
|
||||
outStatement.setString(3, player.getLastName());
|
||||
outStatement.setInt(4, player.getBaseClassID());
|
||||
outStatement.setInt(5, player.getRaceID());
|
||||
outStatement.setInt(6, player.getPromotionClassID());
|
||||
outStatement.setString(7, DataWarehouse.hasher.encrypt(charGuild.getObjectUUID()));
|
||||
outStatement.setTimestamp(8, Timestamp.valueOf(LocalDateTime.now()));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public static PreparedStatement buildCharacterPushStatement(Connection connection, ResultSet rs) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_characterhistory` (`event_number`, `char_id`, `char_fname`, `char_lname`, `baseClass`, `race`, `promoteClass`, `startingGuild`, `datetime`) VALUES(?,?,?,?,?,?,?,?,?)";
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
// Bind record data
|
||||
|
||||
outStatement.setInt(1, rs.getInt("event_number"));
|
||||
outStatement.setString(2, rs.getString("char_id"));
|
||||
outStatement.setString(3, rs.getString("char_fname"));
|
||||
outStatement.setString(4, rs.getString("char_lname"));
|
||||
outStatement.setInt(5, rs.getInt("baseClass"));
|
||||
outStatement.setInt(6, rs.getInt("race"));
|
||||
outStatement.setInt(7, rs.getInt("promoteClass"));
|
||||
outStatement.setString(8, rs.getString("startingGuild"));
|
||||
outStatement.setTimestamp(9, rs.getTimestamp("datetime"));
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public static PreparedStatement buildCharacterQueryStatement(Connection connection) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "SELECT * FROM `warehouse_characterhistory` WHERE `event_number` > ?";
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setInt(1, WarehousePushThread.charIndex);
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public static void advanceKillCounter(PlayerCharacter player) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = buildKillCounterStatement(connection, player)) {
|
||||
|
||||
statement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static PreparedStatement buildKillCounterStatement(Connection connection, PlayerCharacter player) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "UPDATE `warehouse_characterhistory` SET `kills` = `kills` +1, `dirty` = 1 WHERE `char_id` = ?";
|
||||
|
||||
if (player == null)
|
||||
return outStatement;
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setString(1, player.getHash());
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public static void advanceDeathCounter(PlayerCharacter player) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = buildDeathCounterStatement(connection, player)) {
|
||||
|
||||
statement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static PreparedStatement buildDeathCounterStatement(Connection connection, PlayerCharacter player) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "UPDATE `warehouse_characterhistory` SET `deaths` = `deaths` +1, `dirty` = 1 WHERE `char_id` = ?";
|
||||
|
||||
if (player == null)
|
||||
return outStatement;
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setString(1, player.getHash());
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public static void updatePromotionClass(PlayerCharacter player) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = buildUpdatePromotionStatement(connection, player)) {
|
||||
|
||||
statement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static PreparedStatement buildUpdatePromotionStatement(Connection connection, PlayerCharacter player) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "UPDATE `warehouse_characterhistory` SET `promoteClass` = ?, `dirty` = 1 WHERE `char_id` = ?";
|
||||
|
||||
if (player == null)
|
||||
return outStatement;
|
||||
|
||||
outStatement = connection.prepareStatement(queryString, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
|
||||
outStatement.setInt(1, player.getPromotionClassID());
|
||||
outStatement.setString(2, player.getHash());
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public static void updateDirtyRecords() {
|
||||
|
||||
String queryString = "SELECT * FROM `warehouse_characterhistory` where `dirty` = 1";
|
||||
|
||||
// Reset character delta
|
||||
|
||||
WarehousePushThread.charDelta = 0;
|
||||
|
||||
try (Connection localConnection = DbManager.getConnection();
|
||||
PreparedStatement statement = localConnection.prepareStatement(queryString, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); // Make this an updatable result set as we'll reset the dirty flag as we go along
|
||||
ResultSet rs = statement.executeQuery()) {
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
// Only update the index and dirty flag
|
||||
// if the remote database update succeeded
|
||||
|
||||
if (updateDirtyRecord(rs) == true)
|
||||
WarehousePushThread.charDelta++;
|
||||
else
|
||||
continue;
|
||||
|
||||
// Reset the dirty flag in the local database
|
||||
|
||||
rs.updateInt("dirty", 0);
|
||||
rs.updateRow();
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean updateDirtyRecord(ResultSet rs) {
|
||||
|
||||
try (Connection remoteConnection = DataWarehouse.remoteConnectionPool.getConnection();
|
||||
PreparedStatement statement = buildUpdateDirtyStatement(remoteConnection, rs)) {
|
||||
|
||||
statement.execute();
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static PreparedStatement buildUpdateDirtyStatement(Connection connection, ResultSet rs) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement;
|
||||
String queryString = "UPDATE `warehouse_characterhistory` SET `promoteClass` = ?, `kills` = ?, `deaths` = ? WHERE `char_id` = ?";
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
// Bind record data
|
||||
|
||||
outStatement.setInt(1, rs.getInt("promoteClass"));
|
||||
outStatement.setInt(2, rs.getInt("kills"));
|
||||
outStatement.setInt(3, rs.getInt("deaths"));
|
||||
outStatement.setString(4, rs.getString("char_id"));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
this.player = null;
|
||||
}
|
||||
|
||||
public void release() {
|
||||
this.reset();
|
||||
recordPool.add(this);
|
||||
}
|
||||
|
||||
public void write() {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = buildCharacterInsertStatement(connection, this.player)) {
|
||||
|
||||
statement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error("Error writing character record " + e.toString());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,161 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.archive;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.City;
|
||||
import engine.workthreads.WarehousePushThread;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
public class CityRecord extends DataRecord {
|
||||
|
||||
private static final LinkedBlockingQueue<CityRecord> recordPool = new LinkedBlockingQueue<>();
|
||||
private Enum.RecordEventType eventType;
|
||||
private City city;
|
||||
private String cityHash;
|
||||
private String cityGuildHash;
|
||||
private String cityName;
|
||||
private String cityMotto;
|
||||
private float locX;
|
||||
private float locY;
|
||||
private String zoneHash;
|
||||
private java.time.LocalDateTime establishedDatetime;
|
||||
|
||||
private CityRecord(City city) {
|
||||
this.recordType = Enum.DataRecordType.CITY;
|
||||
this.city = city;
|
||||
this.eventType = Enum.RecordEventType.CREATE;
|
||||
|
||||
}
|
||||
|
||||
public static CityRecord borrow(City city, Enum.RecordEventType eventType) {
|
||||
CityRecord cityRecord;
|
||||
|
||||
cityRecord = recordPool.poll();
|
||||
|
||||
if (cityRecord == null) {
|
||||
cityRecord = new CityRecord(city);
|
||||
cityRecord.eventType = eventType;
|
||||
} else {
|
||||
cityRecord.recordType = Enum.DataRecordType.CITY;
|
||||
cityRecord.eventType = eventType;
|
||||
cityRecord.city = city;
|
||||
|
||||
}
|
||||
|
||||
if (cityRecord.city.getHash() == null)
|
||||
cityRecord.city.setHash(DataWarehouse.hasher.encrypt(cityRecord.city.getObjectUUID()));
|
||||
|
||||
cityRecord.cityHash = cityRecord.city.getHash();
|
||||
|
||||
|
||||
cityRecord.cityName = cityRecord.city.getCityName();
|
||||
cityRecord.cityMotto = cityRecord.city.getMotto();
|
||||
|
||||
cityRecord.cityGuildHash = cityRecord.city.getGuild().getHash();
|
||||
|
||||
cityRecord.locX = cityRecord.city.getTOL().getLoc().x;
|
||||
cityRecord.locY = -cityRecord.city.getTOL().getLoc().z; // flip sign on 'y' coordinate
|
||||
|
||||
cityRecord.zoneHash = cityRecord.city.getParent().getHash();
|
||||
|
||||
if (cityRecord.eventType.equals(Enum.RecordEventType.CREATE))
|
||||
cityRecord.establishedDatetime = cityRecord.city.established;
|
||||
else
|
||||
cityRecord.establishedDatetime = java.time.LocalDateTime.now();
|
||||
|
||||
return cityRecord;
|
||||
}
|
||||
|
||||
public static PreparedStatement buildCityPushStatement(Connection connection, ResultSet rs) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_cityhistory` (`event_number`, `city_id`, `city_name`, `city_motto`, `guild_id`, `loc_x`, `loc_y`, `zone_id`, `eventType`, `datetime`) VALUES(?,?,?,?,?,?,?,?,?,?)";
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
// Bind record data
|
||||
|
||||
outStatement.setInt(1, rs.getInt("event_number"));
|
||||
outStatement.setString(2, rs.getString("city_id"));
|
||||
outStatement.setString(3, rs.getString("city_name"));
|
||||
outStatement.setString(4, rs.getString("city_motto"));
|
||||
outStatement.setString(5, rs.getString("guild_id"));
|
||||
|
||||
outStatement.setFloat(6, rs.getFloat("loc_x"));
|
||||
outStatement.setFloat(7, rs.getFloat("loc_y"));
|
||||
outStatement.setString(8, rs.getString("zone_id"));
|
||||
outStatement.setString(9, rs.getString("eventType"));
|
||||
outStatement.setTimestamp(10, rs.getTimestamp("datetime"));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public static PreparedStatement buildCityQueryStatement(Connection connection) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "SELECT * FROM `warehouse_cityhistory` WHERE `event_number` > ?";
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setInt(1, WarehousePushThread.cityIndex);
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
this.city = null;
|
||||
this.cityHash = null;
|
||||
this.cityGuildHash = null;
|
||||
this.cityMotto = null;
|
||||
this.zoneHash = null;
|
||||
this.establishedDatetime = null;
|
||||
|
||||
}
|
||||
|
||||
public void release() {
|
||||
this.reset();
|
||||
recordPool.add(this);
|
||||
}
|
||||
|
||||
public void write() {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = this.buildCityInsertStatement(connection)) {
|
||||
|
||||
statement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private PreparedStatement buildCityInsertStatement(Connection connection) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_cityhistory` (`city_id`, `city_name`, `city_motto`, `guild_id`, `loc_x`, `loc_y`, `zone_id`, `eventType`, `datetime`) VALUES(?,?,?,?,?,?,?,?,?)";
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
// Bind character data
|
||||
|
||||
outStatement.setString(1, this.cityHash);
|
||||
outStatement.setString(2, this.cityName);
|
||||
outStatement.setString(3, this.cityMotto);
|
||||
outStatement.setString(4, this.cityGuildHash);
|
||||
|
||||
outStatement.setFloat(5, this.locX);
|
||||
outStatement.setFloat(6, this.locY);
|
||||
outStatement.setString(7, this.zoneHash);
|
||||
outStatement.setString(8, this.eventType.name());
|
||||
outStatement.setTimestamp(9, Timestamp.valueOf(this.establishedDatetime));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.archive;
|
||||
|
||||
import engine.Enum;
|
||||
|
||||
class DataRecord {
|
||||
|
||||
public Enum.DataRecordType recordType;
|
||||
|
||||
DataRecord() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,290 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.archive;
|
||||
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import engine.gameManager.ConfigManager;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.util.Hasher;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
import static engine.Enum.DataRecordType;
|
||||
|
||||
public class DataWarehouse implements Runnable {
|
||||
|
||||
public static final Hasher hasher = new Hasher("Cthulhu Owns Joo");
|
||||
private static final LinkedBlockingQueue<DataRecord> recordQueue = new LinkedBlockingQueue<>();
|
||||
public static HikariDataSource remoteConnectionPool = null;
|
||||
|
||||
public DataWarehouse() {
|
||||
|
||||
// If WarehousePush is disabled
|
||||
// then early exit
|
||||
|
||||
if (ConfigManager.MB_WORLD_WAREHOUSE_PUSH.getValue().equalsIgnoreCase("false")) {
|
||||
Logger.info("Warehouse Remote Connection disabled along with push");
|
||||
return;
|
||||
}
|
||||
|
||||
Logger.info("Configuring remote Database Connection Pool...");
|
||||
configureRemoteConnectionPool();
|
||||
}
|
||||
|
||||
public static void bootStrap() {
|
||||
Thread warehousingThread;
|
||||
warehousingThread = new Thread(new DataWarehouse());
|
||||
|
||||
warehousingThread.setName("DataWarehouse");
|
||||
warehousingThread.setPriority(Thread.NORM_PRIORITY - 1);
|
||||
warehousingThread.start();
|
||||
}
|
||||
|
||||
public static void pushToWarehouse(DataRecord dataRecord) {
|
||||
|
||||
DataWarehouse.recordQueue.add(dataRecord);
|
||||
}
|
||||
|
||||
public static void writeHash(DataRecordType recordType, int uuid) {
|
||||
|
||||
// Member variable declaration
|
||||
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
String queryString;
|
||||
String hashString;
|
||||
|
||||
connection = DbManager.getConnection();
|
||||
|
||||
if (connection == null) {
|
||||
Logger.error("Null connection when writing zone hash.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Build query string
|
||||
|
||||
switch (recordType) {
|
||||
case CHARACTER:
|
||||
queryString = "UPDATE `obj_character` SET hash = ? WHERE `UID` = ?";
|
||||
break;
|
||||
case GUILD:
|
||||
queryString = "UPDATE `obj_guild` SET hash = ? WHERE `UID` = ?";
|
||||
break;
|
||||
case ZONE:
|
||||
queryString = "UPDATE `obj_zone` SET hash = ? WHERE `UID` = ?";
|
||||
break;
|
||||
case CITY:
|
||||
queryString = "UPDATE `obj_city` SET hash = ? WHERE `UID` = ?";
|
||||
break;
|
||||
case REALM:
|
||||
queryString = "UPDATE `obj_realm` SET hash = ? WHERE `realmID` = ?";
|
||||
break;
|
||||
default:
|
||||
queryString = null;
|
||||
break;
|
||||
}
|
||||
|
||||
hashString = hasher.encrypt(uuid);
|
||||
|
||||
// Write this record to the warehouse
|
||||
|
||||
try {
|
||||
|
||||
statement = connection.prepareStatement(queryString);
|
||||
|
||||
statement.setString(1, hashString);
|
||||
statement.setLong(2, uuid);
|
||||
statement.execute();
|
||||
} catch (SQLException e) {
|
||||
Logger.error("Error writing hash for uuid" + uuid + " of type " + recordType.name() + ' ' + e.toString());
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (connection != null) {
|
||||
try {
|
||||
connection.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean recordExists(DataRecordType recordType, int uuid) {
|
||||
|
||||
// Member variable declaration
|
||||
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
String queryString;
|
||||
ResultSet resultSet;
|
||||
|
||||
connection = DbManager.getConnection();
|
||||
|
||||
if (connection == null) {
|
||||
Logger.error("Null connection during char record lookup");
|
||||
return true; // False positive here, so as not to try and write the record twice.
|
||||
// will refactor out once we write hashes to object tables
|
||||
}
|
||||
|
||||
// Build query string
|
||||
|
||||
switch (recordType) {
|
||||
case CHARACTER:
|
||||
queryString = "SELECT COUNT(*) from warehouse_characterhistory where char_id = ?";
|
||||
break;
|
||||
case GUILD:
|
||||
queryString = "SELECT COUNT(*) from warehouse_guildhistory where guild_id = ?";
|
||||
break;
|
||||
case CITY:
|
||||
queryString = "SELECT COUNT(*) from warehouse_cityhistory where city_id = ?";
|
||||
break;
|
||||
case REALM:
|
||||
queryString = "SELECT COUNT(*) from warehouse_realmhistory where realm_id = ?";
|
||||
break;
|
||||
case BANE:
|
||||
queryString = "SELECT COUNT(*) from warehouse_banehistory where city_id = ? AND `resolution` = 'PENDING'";
|
||||
break;
|
||||
case ZONE: // Does not really exist but enum acts as a proxy for hash lookup
|
||||
case MINE: // Does not really exist but enum acts as a proxy for hash lookup
|
||||
default:
|
||||
queryString = null;
|
||||
break;
|
||||
}
|
||||
|
||||
try {
|
||||
statement = connection.prepareStatement(queryString);
|
||||
statement.setString(1, DataWarehouse.hasher.encrypt(uuid));
|
||||
resultSet = statement.executeQuery();
|
||||
|
||||
while (resultSet.next()) {
|
||||
return resultSet.getInt("COUNT(*)") > 0;
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error("Error in record lookup for " + recordType.name() + " of uuid:" + uuid + e.toString());
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (connection != null) {
|
||||
try {
|
||||
connection.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void configureRemoteConnectionPool() {
|
||||
|
||||
HikariConfig config = new HikariConfig();
|
||||
|
||||
config.setMaximumPoolSize(1); // Only the server talks to remote, so yeah.
|
||||
config.setJdbcUrl(ConfigManager.MB_WAREHOUSE_ADDR.getValue());
|
||||
config.setUsername(ConfigManager.MB_WAREHOUSE_USER.getValue());
|
||||
config.setPassword(ConfigManager.MB_WAREHOUSE_PASS.getValue());
|
||||
config.addDataSourceProperty("characterEncoding", "utf8");
|
||||
config.addDataSourceProperty("cachePrepStmts", "true");
|
||||
config.addDataSourceProperty("prepStmtCacheSize", "250");
|
||||
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
|
||||
|
||||
remoteConnectionPool = new HikariDataSource(config); // setup the connection pool
|
||||
|
||||
Logger.info("remote warehouse connection configured");
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
||||
// Working variable set
|
||||
|
||||
DataRecord dataRecord;
|
||||
PvpRecord pvpRecord;
|
||||
GuildRecord guildRecord;
|
||||
CharacterRecord characterRecord;
|
||||
CityRecord cityRecord;
|
||||
BaneRecord baneRecord;
|
||||
RealmRecord realmRecord;
|
||||
MineRecord mineRecord;
|
||||
|
||||
Logger.info("DataWarehouse is running.");
|
||||
|
||||
while (true) {
|
||||
|
||||
dataRecord = null;
|
||||
pvpRecord = null;
|
||||
guildRecord = null;
|
||||
characterRecord = null;
|
||||
cityRecord = null;
|
||||
baneRecord = null;
|
||||
realmRecord = null;
|
||||
mineRecord = null;
|
||||
|
||||
try {
|
||||
dataRecord = recordQueue.take();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Write record to appropriate warehousing table
|
||||
|
||||
if (dataRecord != null) {
|
||||
|
||||
switch (dataRecord.recordType) {
|
||||
case PVP:
|
||||
pvpRecord = (PvpRecord) dataRecord;
|
||||
pvpRecord.write();
|
||||
pvpRecord.release();
|
||||
break;
|
||||
case CHARACTER:
|
||||
characterRecord = (CharacterRecord) dataRecord;
|
||||
characterRecord.write();
|
||||
characterRecord.release();
|
||||
break;
|
||||
case GUILD:
|
||||
guildRecord = (GuildRecord) dataRecord;
|
||||
guildRecord.write();
|
||||
guildRecord.release();
|
||||
break;
|
||||
case CITY:
|
||||
cityRecord = (CityRecord) dataRecord;
|
||||
cityRecord.write();
|
||||
cityRecord.release();
|
||||
break;
|
||||
case BANE:
|
||||
baneRecord = (BaneRecord) dataRecord;
|
||||
baneRecord.write();
|
||||
baneRecord.release();
|
||||
break;
|
||||
case REALM:
|
||||
realmRecord = (RealmRecord) dataRecord;
|
||||
realmRecord.write();
|
||||
realmRecord.release();
|
||||
break;
|
||||
case MINE:
|
||||
mineRecord = (MineRecord) dataRecord;
|
||||
mineRecord.write();
|
||||
mineRecord.release();
|
||||
break;
|
||||
default:
|
||||
Logger.error("Unhandled record type");
|
||||
break;
|
||||
|
||||
} // end switch
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.archive;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.RecordEventType;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.Guild;
|
||||
import engine.workthreads.WarehousePushThread;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
public class GuildRecord extends DataRecord {
|
||||
|
||||
private static final LinkedBlockingQueue<GuildRecord> recordPool = new LinkedBlockingQueue<>();
|
||||
public static HashMap<Integer, GuildRecord> GuildRecordCache = null;
|
||||
public String guildHash;
|
||||
public int guildID;
|
||||
private Enum.RecordEventType eventType;
|
||||
private Guild guild;
|
||||
private String guildName;
|
||||
private String charterName;
|
||||
private String GLHash;
|
||||
private String guildMotto;
|
||||
private int bgIcon;
|
||||
private int bgColour1;
|
||||
private int bgColour2;
|
||||
private int fgIcon;
|
||||
private int fgColour;
|
||||
private java.time.LocalDateTime eventDatetime;
|
||||
|
||||
private GuildRecord(Guild guild) {
|
||||
this.recordType = Enum.DataRecordType.GUILD;
|
||||
this.guild = guild;
|
||||
this.eventType = Enum.RecordEventType.CREATE;
|
||||
}
|
||||
|
||||
|
||||
public GuildRecord(ResultSet rs) throws SQLException {
|
||||
super();
|
||||
this.eventType = RecordEventType.valueOf(rs.getString("eventType"));
|
||||
this.guildHash = rs.getString("guild_id");
|
||||
this.guildName = rs.getString("guild_name");
|
||||
this.charterName = rs.getString("charter");
|
||||
GLHash = rs.getString("guild_founder");
|
||||
this.guildMotto = rs.getString("guild_motto");
|
||||
this.bgIcon = rs.getInt("bgicon");
|
||||
this.bgColour1 = rs.getInt("bgcoloura");
|
||||
this.bgColour2 = rs.getInt("bgcolourb");
|
||||
this.fgIcon = rs.getInt("fgicon");
|
||||
this.fgColour = rs.getInt("fgcolour");
|
||||
|
||||
java.sql.Timestamp eventTimeStamp = rs.getTimestamp("upgradeDate");
|
||||
|
||||
if (eventTimeStamp != null)
|
||||
this.eventDatetime = LocalDateTime.ofInstant(eventTimeStamp.toInstant(), ZoneId.systemDefault());
|
||||
}
|
||||
|
||||
|
||||
public static GuildRecord borrow(Guild guild, Enum.RecordEventType eventType) {
|
||||
GuildRecord guildRecord;
|
||||
//add
|
||||
guildRecord = recordPool.poll();
|
||||
|
||||
if (guildRecord == null) {
|
||||
guildRecord = new GuildRecord(guild);
|
||||
guildRecord.eventType = eventType;
|
||||
} else {
|
||||
guildRecord.guild = guild;
|
||||
guildRecord.recordType = Enum.DataRecordType.GUILD;
|
||||
guildRecord.eventType = eventType;
|
||||
|
||||
}
|
||||
|
||||
guildRecord.guildHash = guildRecord.guild.getHash();
|
||||
guildRecord.guildID = guildRecord.guild.getObjectUUID();
|
||||
guildRecord.guildName = guildRecord.guild.getName();
|
||||
guildRecord.charterName = Enum.GuildType.getGuildTypeFromInt(guildRecord.guild.getCharter()).getCharterName();
|
||||
|
||||
guildRecord.GLHash = DataWarehouse.hasher.encrypt(guildRecord.guild.getGuildLeaderUUID());
|
||||
|
||||
guildRecord.guildMotto = guildRecord.guild.getMotto();
|
||||
guildRecord.bgIcon = guildRecord.guild.getBgDesign();
|
||||
guildRecord.bgColour1 = guildRecord.guild.getBgc1();
|
||||
guildRecord.bgColour2 = guildRecord.guild.getBgc2();
|
||||
guildRecord.fgIcon = guildRecord.guild.getSymbol();
|
||||
guildRecord.fgColour = guildRecord.guild.getSc();
|
||||
|
||||
if (guild.getOwnedCity() != null)
|
||||
guildRecord.eventDatetime = guild.getOwnedCity().established;
|
||||
else
|
||||
guildRecord.eventDatetime = LocalDateTime.now();
|
||||
|
||||
return guildRecord;
|
||||
}
|
||||
|
||||
public static PreparedStatement buildGuildPushStatement(Connection connection, ResultSet rs) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_guildhistory` (`event_number`, `guild_id`, `guild_name`, `guild_motto`, `guild_founder`, `charter`, `bgicon`, `bgcoloura`, `bgcolourb`, `fgicon`, `fgcolour`, `eventtype`, `datetime`) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
// Bind record data
|
||||
|
||||
outStatement.setInt(1, rs.getInt("event_number"));
|
||||
outStatement.setString(2, rs.getString("guild_id"));
|
||||
outStatement.setString(3, rs.getString("guild_name"));
|
||||
outStatement.setString(4, rs.getString("guild_motto"));
|
||||
outStatement.setString(5, rs.getString("guild_founder"));
|
||||
outStatement.setString(6, rs.getString("charter"));
|
||||
outStatement.setInt(7, rs.getInt("bgicon"));
|
||||
outStatement.setInt(8, rs.getInt("bgcoloura"));
|
||||
outStatement.setInt(9, rs.getInt("bgcolourb"));
|
||||
outStatement.setInt(10, rs.getInt("fgicon"));
|
||||
outStatement.setInt(11, rs.getInt("fgcolour"));
|
||||
outStatement.setString(12, rs.getString("eventtype"));
|
||||
outStatement.setTimestamp(13, rs.getTimestamp("datetime"));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public static PreparedStatement buildGuildQueryStatement(Connection connection) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "SELECT * FROM `warehouse_guildhistory` WHERE `event_number` > ?";
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setInt(1, WarehousePushThread.guildIndex);
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
|
||||
this.guild = null;
|
||||
this.guildHash = null;
|
||||
this.GLHash = null;
|
||||
this.guildMotto = null;
|
||||
this.charterName = null;
|
||||
this.eventDatetime = null;
|
||||
}
|
||||
|
||||
public void release() {
|
||||
this.reset();
|
||||
recordPool.add(this);
|
||||
}
|
||||
|
||||
public void write() {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = this.buildGuildInsertStatement(connection)) {
|
||||
|
||||
statement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private PreparedStatement buildGuildInsertStatement(Connection connection) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_guildhistory` (`guild_id`, `guild_name`, `guild_motto`, `guild_founder`, `charter`, `bgicon`, `bgcoloura`, `bgcolourb`, `fgicon`, `fgcolour`, `eventtype`, `datetime`) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
// Bind character data
|
||||
|
||||
outStatement.setString(1, this.guildHash);
|
||||
outStatement.setString(2, this.guildName);
|
||||
outStatement.setString(3, this.guildMotto);
|
||||
outStatement.setString(4, this.GLHash);
|
||||
outStatement.setString(5, this.charterName);
|
||||
|
||||
outStatement.setInt(6, this.bgIcon);
|
||||
outStatement.setInt(7, this.bgColour1);
|
||||
outStatement.setInt(8, this.bgColour2);
|
||||
outStatement.setInt(9, this.fgIcon);
|
||||
outStatement.setInt(10, this.fgColour);
|
||||
outStatement.setString(11, this.eventType.name());
|
||||
outStatement.setTimestamp(12, new java.sql.Timestamp(this.eventDatetime.atZone(ZoneId.systemDefault())
|
||||
.toInstant().toEpochMilli()));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
// public static void InitializeGuildRecords(){
|
||||
// GuildRecord.GuildRecordCache = DbManager.GuildQueries.GET_WAREHOUSE_GUILD_HISTORY();
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.archive;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.AbstractCharacter;
|
||||
import engine.objects.Mine;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import engine.workthreads.WarehousePushThread;
|
||||
|
||||
import java.sql.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
public class MineRecord extends DataRecord {
|
||||
|
||||
private static final LinkedBlockingQueue<MineRecord> recordPool = new LinkedBlockingQueue<>();
|
||||
private Enum.RecordEventType eventType;
|
||||
private String zoneHash;
|
||||
private String charHash;
|
||||
private String mineGuildHash;
|
||||
private String mineNationHash;
|
||||
private String mineType;
|
||||
private float locX;
|
||||
private float locY;
|
||||
|
||||
private MineRecord() {
|
||||
this.recordType = Enum.DataRecordType.MINE;
|
||||
this.eventType = Enum.RecordEventType.CAPTURE;
|
||||
|
||||
}
|
||||
|
||||
public static MineRecord borrow(Mine mine, AbstractCharacter character, Enum.RecordEventType eventType) {
|
||||
|
||||
MineRecord mineRecord;
|
||||
mineRecord = recordPool.poll();
|
||||
PlayerCharacter player;
|
||||
|
||||
if (mineRecord == null) {
|
||||
mineRecord = new MineRecord();
|
||||
mineRecord.eventType = eventType;
|
||||
} else {
|
||||
mineRecord.recordType = Enum.DataRecordType.MINE;
|
||||
mineRecord.eventType = eventType;
|
||||
}
|
||||
|
||||
mineRecord.zoneHash = mine.getParentZone().getHash();
|
||||
|
||||
if (character.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) {
|
||||
player = (PlayerCharacter) character;
|
||||
mineRecord.charHash = player.getHash();
|
||||
} else
|
||||
mineRecord.charHash = character.getName();
|
||||
|
||||
DataWarehouse.hasher.encrypt(0);
|
||||
|
||||
if (mine.getOwningGuild() == null)
|
||||
mineRecord.mineGuildHash = "ERRANT";
|
||||
else
|
||||
mineRecord.mineGuildHash = mine.getOwningGuild().getHash();
|
||||
|
||||
if (mine.getOwningGuild() == null)
|
||||
mineRecord.mineNationHash = "ERRANT";
|
||||
else
|
||||
mineRecord.mineNationHash = mine.getOwningGuild().getNation().getHash();
|
||||
|
||||
mineRecord.locX = mine.getParentZone().getLoc().x;
|
||||
mineRecord.locY = -mine.getParentZone().getLoc().z;
|
||||
|
||||
mineRecord.mineType = mine.getMineType().name;
|
||||
|
||||
return mineRecord;
|
||||
}
|
||||
|
||||
public static PreparedStatement buildMinePushStatement(Connection connection, ResultSet rs) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_minehistory` (`event_number`, `zone_id`, `mine_type`, `char_id`, `mine_guildID`, `mine_nationID`, `loc_x`, `loc_y`, `eventType`, `datetime`) VALUES(?,?,?,?,?,?,?,?,?,?)";
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
// Bind record data
|
||||
|
||||
outStatement.setInt(1, rs.getInt("event_number"));
|
||||
outStatement.setString(2, rs.getString("zone_id"));
|
||||
outStatement.setString(3, rs.getString("char_id"));
|
||||
outStatement.setString(4, rs.getString("mine_type"));
|
||||
outStatement.setString(5, rs.getString("mine_guildID"));
|
||||
outStatement.setString(6, rs.getString("mine_nationID"));
|
||||
|
||||
outStatement.setFloat(7, rs.getFloat("loc_x"));
|
||||
outStatement.setFloat(8, rs.getFloat("loc_y"));
|
||||
outStatement.setString(9, rs.getString("eventType"));
|
||||
outStatement.setTimestamp(10, rs.getTimestamp("datetime"));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public static PreparedStatement buildMineQueryStatement(Connection connection) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "SELECT * FROM `warehouse_minehistory` WHERE `event_number` > ?";
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setInt(1, WarehousePushThread.mineIndex);
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
this.zoneHash = null;
|
||||
this.charHash = null;
|
||||
this.mineGuildHash = null;
|
||||
this.mineNationHash = null;
|
||||
this.mineType = null;
|
||||
this.locX = 0.0f;
|
||||
this.locY = 0.0f;
|
||||
|
||||
}
|
||||
|
||||
public void release() {
|
||||
this.reset();
|
||||
recordPool.add(this);
|
||||
}
|
||||
|
||||
public void write() {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = this.buildMineInsertStatement(connection)) {
|
||||
|
||||
statement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private PreparedStatement buildMineInsertStatement(Connection connection) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_minehistory` (`zone_id`, `mine_type`, `char_id`, `mine_guildID`, `mine_nationID`, `loc_x`, `loc_y`, `eventType`, `datetime`) VALUES(?,?,?,?,?,?,?,?,?)";
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
// Bind character data
|
||||
|
||||
outStatement.setString(1, this.zoneHash);
|
||||
outStatement.setString(2, this.mineType);
|
||||
outStatement.setString(3, this.charHash);
|
||||
outStatement.setString(4, this.mineGuildHash);
|
||||
outStatement.setString(5, this.mineNationHash);
|
||||
|
||||
outStatement.setFloat(6, this.locX);
|
||||
outStatement.setFloat(7, this.locY);
|
||||
outStatement.setString(8, this.eventType.name());
|
||||
outStatement.setTimestamp(9, Timestamp.valueOf(LocalDateTime.now()));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,312 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.archive;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.gameManager.ZoneManager;
|
||||
import engine.math.Vector3fImmutable;
|
||||
import engine.objects.Guild;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import engine.objects.Zone;
|
||||
import engine.workthreads.WarehousePushThread;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.LinkedList;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
import static engine.Enum.DataRecordType;
|
||||
import static engine.Enum.PvpHistoryType;
|
||||
|
||||
public class PvpRecord extends DataRecord {
|
||||
|
||||
private static final LinkedBlockingQueue<PvpRecord> recordPool = new LinkedBlockingQueue<>();
|
||||
|
||||
private PlayerCharacter player;
|
||||
private PlayerCharacter victim;
|
||||
private Vector3fImmutable location;
|
||||
private boolean pvpExp;
|
||||
|
||||
private PvpRecord(PlayerCharacter player, PlayerCharacter victim, Vector3fImmutable location, boolean pvpExp) {
|
||||
this.recordType = DataRecordType.PVP;
|
||||
this.player = player;
|
||||
this.victim = victim;
|
||||
this.location = new Vector3fImmutable(location);
|
||||
this.pvpExp = pvpExp;
|
||||
}
|
||||
|
||||
public static PvpRecord borrow(PlayerCharacter player, PlayerCharacter victim, Vector3fImmutable location, boolean pvpExp) {
|
||||
|
||||
PvpRecord pvpRecord;
|
||||
|
||||
pvpRecord = recordPool.poll();
|
||||
|
||||
if (pvpRecord == null) {
|
||||
pvpRecord = new PvpRecord(player, victim, location, pvpExp);
|
||||
} else {
|
||||
pvpRecord.recordType = DataRecordType.PVP;
|
||||
pvpRecord.player = player;
|
||||
pvpRecord.victim = victim;
|
||||
pvpRecord.location = new Vector3fImmutable(location);
|
||||
pvpRecord.pvpExp = pvpExp;
|
||||
}
|
||||
|
||||
return pvpRecord;
|
||||
}
|
||||
|
||||
private static PreparedStatement buildHistoryStatement(Connection connection, int charUUID, PvpHistoryType historyType) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "";
|
||||
|
||||
switch (historyType) {
|
||||
case KILLS:
|
||||
queryString = "SELECT DISTINCT `victim_id`, `datetime` FROM warehouse_pvphistory where char_id = ? " +
|
||||
"ORDER BY `datetime` DESC LIMIT 10";
|
||||
break;
|
||||
case DEATHS:
|
||||
queryString = "SELECT DISTINCT `char_id`,`datetime` FROM warehouse_pvphistory where `victim_id` = ? " +
|
||||
"ORDER BY `datetime` DESC LIMIT 10";
|
||||
break;
|
||||
}
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setString(1, DataWarehouse.hasher.encrypt(charUUID));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public static LinkedList<Integer> getCharacterPvPHistory(int charUUID, PvpHistoryType historyType) {
|
||||
|
||||
// Member variable declaration
|
||||
|
||||
LinkedList<Integer> outList = new LinkedList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = buildHistoryStatement(connection, charUUID, historyType);
|
||||
ResultSet rs = statement.executeQuery()) {
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
switch (historyType) {
|
||||
case KILLS:
|
||||
outList.add((int) DataWarehouse.hasher.decrypt(rs.getString("victim_id"))[0]);
|
||||
break;
|
||||
case DEATHS:
|
||||
outList.add((int) DataWarehouse.hasher.decrypt(rs.getString("char_id"))[0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return outList;
|
||||
}
|
||||
|
||||
private static PreparedStatement buildLuaHistoryQueryStatement(Connection connection, int charUUID) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "CALL `pvpHistory`(?)";
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setString(1, DataWarehouse.hasher.encrypt(charUUID));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public static String getPvpHistoryString(int charUUID) {
|
||||
|
||||
String outString;
|
||||
String dividerString;
|
||||
|
||||
String newLine = System.getProperty("line.separator");
|
||||
|
||||
outString = "[LUA_PVP() DATA WAREHOUSE]" + newLine;
|
||||
dividerString = "--------------------------------" + newLine;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = buildLuaHistoryQueryStatement(connection, charUUID);
|
||||
ResultSet rs = statement.executeQuery()) {
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
int killCount;
|
||||
int deathCount;
|
||||
float killRatio;
|
||||
|
||||
outString += "Total Magicbane murdered souls: " + rs.getInt("TOTALDEATHS") + newLine;
|
||||
outString += dividerString;
|
||||
outString += String.format("%-8s %-8s %-8s %-8s %n", "Period", "Kills", "Deaths", "K/D");
|
||||
outString += dividerString;
|
||||
|
||||
killCount = rs.getInt("KILLCOUNT");
|
||||
deathCount = rs.getInt("DEATHCOUNT");
|
||||
|
||||
if (deathCount == 0)
|
||||
killRatio = (float) killCount;
|
||||
else
|
||||
killRatio = (float) killCount / deathCount;
|
||||
|
||||
try {
|
||||
outString += String.format("%-8s %-8d %-8d %.2f %n", "Total", killCount, deathCount, killRatio);
|
||||
|
||||
killCount = rs.getInt("DAILYKILLS");
|
||||
deathCount = rs.getInt("DAILYDEATHS");
|
||||
|
||||
if (deathCount == 0)
|
||||
killRatio = (float) killCount;
|
||||
else
|
||||
killRatio = (float) killCount / deathCount;
|
||||
|
||||
outString += String.format("%-8s %-8d %-8d %.2f %n", "24hrs", killCount, deathCount, killRatio);
|
||||
|
||||
killCount = rs.getInt("HOURLYKILLS");
|
||||
deathCount = rs.getInt("HOURLYDEATHS");
|
||||
|
||||
if (deathCount == 0)
|
||||
killRatio = (float) killCount;
|
||||
else
|
||||
killRatio = (float) killCount / deathCount;
|
||||
|
||||
outString += String.format("%-8s %-8d %-8d %.2f %n", "1hr", killCount, deathCount, killRatio);
|
||||
} catch (Exception e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return outString;
|
||||
}
|
||||
|
||||
public static PreparedStatement buildPvpPushStatement(Connection connection, ResultSet rs) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_pvphistory` (`event_number`, `char_id`, `char_guild_id`, `char_nation_id`, `char_level`," +
|
||||
" `victim_id`, `victim_guild_id`, `victim_nation_id`, `victim_level`," +
|
||||
" `zone_id`, `zone_name`, `loc_x`, `loc_y`, `gave_exp`, `datetime`) " +
|
||||
" VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
// Bind record data
|
||||
|
||||
outStatement.setInt(1, rs.getInt("event_number"));
|
||||
outStatement.setString(2, rs.getString("char_id"));
|
||||
outStatement.setString(3, rs.getString("char_guild_id"));
|
||||
outStatement.setString(4, rs.getString("char_nation_id"));
|
||||
outStatement.setInt(5, rs.getInt("char_level"));
|
||||
|
||||
// Bind victim data
|
||||
|
||||
outStatement.setString(6, rs.getString("victim_id"));
|
||||
outStatement.setString(7, rs.getString("victim_guild_id"));
|
||||
outStatement.setString(8, rs.getString("victim_nation_id"));
|
||||
outStatement.setInt(9, rs.getInt("victim_level"));
|
||||
|
||||
outStatement.setString(10, rs.getString("zone_id"));
|
||||
outStatement.setString(11, rs.getString("zone_name"));
|
||||
outStatement.setFloat(12, rs.getFloat("loc_x"));
|
||||
outStatement.setFloat(13, rs.getFloat("loc_y"));
|
||||
outStatement.setBoolean(14, rs.getBoolean("gave_exp"));
|
||||
outStatement.setTimestamp(15, rs.getTimestamp("datetime"));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public static PreparedStatement buildPvpQueryStatement(Connection connection) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "SELECT * FROM `warehouse_pvphistory` WHERE `event_number` > ?";
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setInt(1, WarehousePushThread.pvpIndex);
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
this.player = null;
|
||||
this.victim = null;
|
||||
this.location = Vector3fImmutable.ZERO;
|
||||
pvpExp = false;
|
||||
}
|
||||
|
||||
public void release() {
|
||||
this.reset();
|
||||
recordPool.add(this);
|
||||
}
|
||||
|
||||
private PreparedStatement buildPvPInsertStatement(Connection connection) throws SQLException {
|
||||
|
||||
Guild charGuild;
|
||||
Guild victimGuild;
|
||||
Zone zone;
|
||||
PreparedStatement outStatement = null;
|
||||
|
||||
String queryString = "INSERT INTO `warehouse_pvphistory` (`char_id`, `char_guild_id`, `char_nation_id`, `char_level`," +
|
||||
" `victim_id`, `victim_guild_id`, `victim_nation_id`, `victim_level`," +
|
||||
" `zone_id`, `zone_name`, `loc_x`, `loc_y`, `gave_exp`, `datetime`) " +
|
||||
" VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
charGuild = this.player.getGuild();
|
||||
victimGuild = this.victim.getGuild();
|
||||
|
||||
// Use a proxy in the situation where a char guild is null (errant)
|
||||
|
||||
|
||||
// Retrieve the zone name where the PvP event occurred
|
||||
|
||||
zone = ZoneManager.findSmallestZone(this.location);
|
||||
|
||||
outStatement.setString(1, DataWarehouse.hasher.encrypt(this.player.getObjectUUID()));
|
||||
outStatement.setString(2, DataWarehouse.hasher.encrypt(charGuild.getObjectUUID()));
|
||||
outStatement.setString(3, DataWarehouse.hasher.encrypt(charGuild.getNation().getObjectUUID()));
|
||||
outStatement.setInt(4, this.player.getLevel());
|
||||
|
||||
// Bind victim data
|
||||
|
||||
outStatement.setString(5, DataWarehouse.hasher.encrypt(this.victim.getObjectUUID()));
|
||||
outStatement.setString(6, DataWarehouse.hasher.encrypt(victimGuild.getObjectUUID()));
|
||||
outStatement.setString(7, DataWarehouse.hasher.encrypt(victimGuild.getNation().getObjectUUID()));
|
||||
outStatement.setInt(8, this.victim.getLevel());
|
||||
|
||||
outStatement.setString(9, DataWarehouse.hasher.encrypt(zone.getObjectUUID()));
|
||||
outStatement.setString(10, zone.getName());
|
||||
outStatement.setFloat(11, this.location.getX());
|
||||
outStatement.setFloat(12, -this.location.getZ()); // flip sign on 'y' coordinate
|
||||
outStatement.setBoolean(13, this.pvpExp);
|
||||
outStatement.setTimestamp(14, Timestamp.valueOf(LocalDateTime.now()));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
|
||||
public void write() {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = buildPvPInsertStatement(connection)) {
|
||||
|
||||
statement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
|
||||
// Warehouse record for this pvp event written if code path reaches here.
|
||||
// Time to update the respective kill counters.
|
||||
|
||||
CharacterRecord.advanceKillCounter(this.player);
|
||||
CharacterRecord.advanceDeathCounter(this.victim);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.archive;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.Realm;
|
||||
import engine.workthreads.WarehousePushThread;
|
||||
|
||||
import java.sql.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
public class RealmRecord extends DataRecord {
|
||||
|
||||
private static final LinkedBlockingQueue<RealmRecord> recordPool = new LinkedBlockingQueue<>();
|
||||
|
||||
private Realm realm;
|
||||
private Enum.RecordEventType eventType;
|
||||
private String cityHash;
|
||||
private String guildHash;
|
||||
private String charterType;
|
||||
private LocalDateTime eventDateTime;
|
||||
|
||||
private RealmRecord(Realm realm) {
|
||||
this.recordType = Enum.DataRecordType.REALM;
|
||||
this.realm = realm;
|
||||
this.eventType = Enum.RecordEventType.CAPTURE;
|
||||
|
||||
}
|
||||
|
||||
public static RealmRecord borrow(Realm realm, Enum.RecordEventType eventType) {
|
||||
RealmRecord realmRecord;
|
||||
|
||||
realmRecord = recordPool.poll();
|
||||
|
||||
if (realmRecord == null) {
|
||||
realmRecord = new RealmRecord(realm);
|
||||
realmRecord.eventType = eventType;
|
||||
} else {
|
||||
realmRecord.recordType = Enum.DataRecordType.REALM;
|
||||
realmRecord.eventType = eventType;
|
||||
realmRecord.realm = realm;
|
||||
|
||||
}
|
||||
|
||||
realmRecord.cityHash = realm.getRulingCity().getHash();
|
||||
realmRecord.guildHash = realm.getRulingCity().getGuild().getHash();
|
||||
realmRecord.charterType = Enum.CharterType.getCharterTypeByID(realmRecord.realm.getCharterType()).name();
|
||||
|
||||
if (realmRecord.eventType.equals(Enum.RecordEventType.CAPTURE))
|
||||
realmRecord.eventDateTime = realm.ruledSince;
|
||||
else
|
||||
realmRecord.eventDateTime = LocalDateTime.now();
|
||||
|
||||
return realmRecord;
|
||||
}
|
||||
|
||||
public static PreparedStatement buildRealmPushStatement(Connection connection, ResultSet rs) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_realmhistory` (`event_number`, `realm_id`, `realm_name`, `charter`, `city_id`, `guild_id`, `eventType`, `datetime`) VALUES(?,?,?,?,?,?,?,?)";
|
||||
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
// Bind record data
|
||||
|
||||
outStatement.setInt(1, rs.getInt("event_number"));
|
||||
outStatement.setString(2, rs.getString("realm_id"));
|
||||
outStatement.setString(3, rs.getString("realm_name"));
|
||||
outStatement.setString(4, rs.getString("charter"));
|
||||
outStatement.setString(5, rs.getString("city_id"));
|
||||
outStatement.setString(6, rs.getString("guild_id"));
|
||||
outStatement.setString(7, rs.getString("eventType"));
|
||||
outStatement.setTimestamp(8, rs.getTimestamp("datetime"));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public static PreparedStatement buildRealmQueryStatement(Connection connection) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "SELECT * FROM `warehouse_realmhistory` WHERE `event_number` > ?";
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
outStatement.setInt(1, WarehousePushThread.realmIndex);
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
|
||||
this.realm = null;
|
||||
this.cityHash = null;
|
||||
this.guildHash = null;
|
||||
this.eventDateTime = null;
|
||||
this.charterType = null;
|
||||
}
|
||||
|
||||
public void release() {
|
||||
this.reset();
|
||||
recordPool.add(this);
|
||||
}
|
||||
|
||||
private PreparedStatement buildRealmInsertStatement(Connection connection) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "INSERT INTO `warehouse_realmhistory` (`realm_id`, `realm_name`, `charter`, `city_id`, `guild_id`, `eventType`, `datetime`) VALUES(?,?,?,?,?,?,?)";
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
// Bind Record Data
|
||||
|
||||
outStatement.setString(1, realm.getHash());
|
||||
outStatement.setString(2, realm.getRealmName());
|
||||
outStatement.setString(3, charterType);
|
||||
outStatement.setString(4, cityHash);
|
||||
outStatement.setString(5, guildHash);
|
||||
outStatement.setString(6, eventType.name());
|
||||
outStatement.setTimestamp(7, Timestamp.valueOf(this.eventDateTime));
|
||||
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public void write() {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = this.buildRealmInsertStatement(connection)) {
|
||||
|
||||
statement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,273 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.gameManager.ConfigManager;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.Account;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class dbAccountHandler extends dbHandlerBase {
|
||||
|
||||
public dbAccountHandler() {
|
||||
this.localClass = Account.class;
|
||||
this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public Account GET_ACCOUNT(int accountID) {
|
||||
|
||||
Account account;
|
||||
|
||||
if (accountID == 0)
|
||||
return null;
|
||||
|
||||
account = (Account) DbManager.getFromCache(GameObjectType.Account, accountID);
|
||||
|
||||
if (account != null)
|
||||
return account;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `obj_account` WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setLong(1, accountID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
account = (Account) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
if (account != null)
|
||||
account.runAfterLoad();
|
||||
|
||||
return account;
|
||||
}
|
||||
|
||||
public void WRITE_ADMIN_LOG(String adminName, String logEntry) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO dyn_admin_log(`dateTime`, `charName`, `eventString`)"
|
||||
+ " VALUES (?, ?, ?)")) {
|
||||
|
||||
preparedStatement.setTimestamp(1, new java.sql.Timestamp(System.currentTimeMillis()));
|
||||
preparedStatement.setString(2, adminName);
|
||||
preparedStatement.setString(3, logEntry);
|
||||
|
||||
preparedStatement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void SET_TRASH(String machineID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO dyn_trash(`machineID`, `count`)"
|
||||
+ " VALUES (?, 1) ON DUPLICATE KEY UPDATE `count` = `count` + 1;")) {
|
||||
|
||||
preparedStatement.setString(1, machineID);
|
||||
preparedStatement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<String> GET_TRASH_LIST() {
|
||||
|
||||
ArrayList<String> machineList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("select `machineID` from `dyn_trash`")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next())
|
||||
machineList.add(rs.getString(1));
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return machineList;
|
||||
}
|
||||
|
||||
public void DELETE_VAULT_FOR_ACCOUNT(final int accountID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `object` WHERE `parent`=? && `type`='item'")) {
|
||||
|
||||
preparedStatement.setLong(1, accountID);
|
||||
preparedStatement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<PlayerCharacter> GET_ALL_CHARS_FOR_MACHINE(String machineID) {
|
||||
|
||||
ArrayList<PlayerCharacter> trashList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("select DISTINCT UID from object \n" +
|
||||
"where parent IN (select AccountID from dyn_login_history " +
|
||||
" WHERE`machineID`=?)")) {
|
||||
|
||||
preparedStatement.setString(1, machineID);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
PlayerCharacter trashPlayer;
|
||||
int playerID;
|
||||
|
||||
playerID = rs.getInt(1);
|
||||
trashPlayer = PlayerCharacter.getPlayerCharacter(playerID);
|
||||
|
||||
if (trashPlayer == null)
|
||||
continue;
|
||||
|
||||
if (trashPlayer.isDeleted() == false)
|
||||
trashList.add(trashPlayer);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return trashList;
|
||||
}
|
||||
|
||||
public void CLEAR_TRASH_TABLE() {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM dyn_trash")) {
|
||||
|
||||
preparedStatement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void CREATE_SINGLE(String accountName, String password) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("CALL singleAccountCreate(?,?)")) {
|
||||
|
||||
preparedStatement.setString(1, accountName);
|
||||
preparedStatement.setString(2, password);
|
||||
|
||||
preparedStatement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public Account GET_ACCOUNT(String uname) {
|
||||
|
||||
Account account = null;
|
||||
|
||||
if (Account.AccountsMap.get(uname) != null)
|
||||
return this.GET_ACCOUNT(Account.AccountsMap.get(uname));
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `obj_account` WHERE `acct_uname`=?")) {
|
||||
|
||||
preparedStatement.setString(1, uname);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
account = (Account) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
if (account != null) {
|
||||
account.runAfterLoad();
|
||||
|
||||
if (ConfigManager.serverType.equals(Enum.ServerType.LOGINSERVER))
|
||||
Account.AccountsMap.put(uname, account.getObjectUUID());
|
||||
|
||||
}
|
||||
return account;
|
||||
}
|
||||
|
||||
public void SET_ACCOUNT_LOGIN(final Account acc, String playerName, final String ip, final String machineID) {
|
||||
|
||||
if (acc.getObjectUUID() == 0 || ip == null || ip.length() == 0)
|
||||
return;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO dyn_login_history(`AccountID`, `accountName`, `characterName`, `ip`, `machineID`, `timeStamp`)"
|
||||
+ " VALUES (?, ?, ?, ?, ?, ?)")) {
|
||||
|
||||
preparedStatement.setInt(1, acc.getObjectUUID());
|
||||
preparedStatement.setString(2, acc.getUname());
|
||||
preparedStatement.setString(3, playerName);
|
||||
preparedStatement.setString(4, ip);
|
||||
preparedStatement.setString(5, machineID);
|
||||
preparedStatement.setTimestamp(6, new java.sql.Timestamp(System.currentTimeMillis()));
|
||||
|
||||
preparedStatement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateDatabase(final Account acc) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_account` SET `acct_passwd`=?, "
|
||||
+ " `acct_lastCharUID`=?, `acct_salt`=?, `discordAccount`=?, " +
|
||||
" status = ? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setString(1, acc.getPasswd());
|
||||
preparedStatement.setInt(2, acc.getLastCharIDUsed());
|
||||
preparedStatement.setString(3, acc.getSalt());
|
||||
preparedStatement.setString(4, acc.discordAccount);
|
||||
preparedStatement.setString(5, acc.status.name());
|
||||
preparedStatement.setInt(6, acc.getObjectUUID());
|
||||
|
||||
preparedStatement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void INVALIDATE_LOGIN_CACHE(long accountUID, String objectType) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT IGNORE INTO login_cachelist (`UID`, `type`) VALUES(?,?);")) {
|
||||
|
||||
preparedStatement.setLong(1, accountUID);
|
||||
preparedStatement.setString(2, objectType);
|
||||
|
||||
preparedStatement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.Bane;
|
||||
import engine.objects.Building;
|
||||
import engine.objects.City;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import org.joda.time.DateTime;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class dbBaneHandler extends dbHandlerBase {
|
||||
|
||||
public dbBaneHandler() {
|
||||
|
||||
}
|
||||
|
||||
public boolean CREATE_BANE(City city, PlayerCharacter owner, Building stone) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_banes` (`cityUUID`, `ownerUUID`, `stoneUUID`, `placementDate`) VALUES(?,?,?,?)")) {
|
||||
|
||||
preparedStatement.setLong(1, city.getObjectUUID());
|
||||
preparedStatement.setLong(2, owner.getObjectUUID());
|
||||
preparedStatement.setLong(3, stone.getObjectUUID());
|
||||
preparedStatement.setTimestamp(4, new java.sql.Timestamp(System.currentTimeMillis()));
|
||||
|
||||
preparedStatement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public Bane LOAD_BANE(int cityUUID) {
|
||||
|
||||
Bane bane = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * from dyn_banes WHERE `dyn_banes`.`cityUUID` = ?")) {
|
||||
|
||||
preparedStatement.setLong(1, cityUUID);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (rs.next()) {
|
||||
bane = new Bane(rs);
|
||||
Bane.addBane(bane);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return bane;
|
||||
}
|
||||
|
||||
|
||||
public boolean SET_BANE_TIME(DateTime toSet, int cityUUID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_banes` SET `liveDate`=? WHERE `cityUUID`=?")) {
|
||||
|
||||
preparedStatement.setTimestamp(1, new java.sql.Timestamp(toSet.getMillis()));
|
||||
preparedStatement.setLong(2, cityUUID);
|
||||
|
||||
preparedStatement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean REMOVE_BANE(Bane bane) {
|
||||
|
||||
if (bane == null)
|
||||
return false;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_banes` WHERE `cityUUID` = ?")) {
|
||||
|
||||
preparedStatement.setLong(1, bane.getCity().getObjectUUID());
|
||||
preparedStatement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.BaseClass;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class dbBaseClassHandler extends dbHandlerBase {
|
||||
|
||||
public dbBaseClassHandler() {
|
||||
this.localClass = BaseClass.class;
|
||||
this.localObjectType = Enum.GameObjectType.BaseClass;
|
||||
}
|
||||
|
||||
public BaseClass GET_BASE_CLASS(final int id) {
|
||||
|
||||
if (id == 0)
|
||||
return null;
|
||||
|
||||
BaseClass baseClass = (BaseClass) DbManager.getFromCache(GameObjectType.BaseClass, id);
|
||||
|
||||
if (baseClass != null)
|
||||
return baseClass;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `obj_account` WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setLong(1, id);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
baseClass = (BaseClass) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return baseClass;
|
||||
}
|
||||
|
||||
public ArrayList<BaseClass> GET_BASECLASS_FOR_RACE(final int id) {
|
||||
|
||||
ArrayList<BaseClass> baseClasses = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT b.* FROM `static_rune_baseclass` b, `static_rune_racebaseclass` r WHERE b.`ID` = r.`BaseClassID` && r.`RaceID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, id);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
baseClasses = getObjectsFromRs(rs, 20);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return baseClasses;
|
||||
}
|
||||
|
||||
public ArrayList<BaseClass> GET_ALL_BASE_CLASSES() {
|
||||
|
||||
ArrayList<BaseClass> baseClasses = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_baseclass`;")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
baseClasses = getObjectsFromRs(rs, 20);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return baseClasses;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.Blueprint;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class dbBlueprintHandler extends dbHandlerBase {
|
||||
|
||||
public dbBlueprintHandler() {
|
||||
|
||||
}
|
||||
|
||||
public HashMap<Integer, Integer> LOAD_ALL_DOOR_NUMBERS() {
|
||||
|
||||
HashMap<Integer, Integer> doorInfo;
|
||||
doorInfo = new HashMap<>();
|
||||
|
||||
int doorUUID;
|
||||
int doorNum;
|
||||
int recordsRead = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_building_doors ORDER BY doorMeshUUID ASC")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
recordsRead++;
|
||||
doorUUID = rs.getInt("doorMeshUUID");
|
||||
doorNum = rs.getInt("doorNumber");
|
||||
doorInfo.put(doorUUID, doorNum);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
Logger.info("read: " + recordsRead + " cached: " + doorInfo.size());
|
||||
return doorInfo;
|
||||
}
|
||||
|
||||
public HashMap<Integer, Blueprint> LOAD_ALL_BLUEPRINTS() {
|
||||
|
||||
HashMap<Integer, Blueprint> blueprints;
|
||||
Blueprint thisBlueprint;
|
||||
|
||||
blueprints = new HashMap<>();
|
||||
int recordsRead = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_building_blueprint")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
recordsRead++;
|
||||
thisBlueprint = new Blueprint(rs);
|
||||
|
||||
blueprints.put(thisBlueprint.getBlueprintUUID(), thisBlueprint);
|
||||
|
||||
// load mesh cache
|
||||
Blueprint._meshLookup.putIfAbsent(thisBlueprint.getMeshForRank(-1), thisBlueprint);
|
||||
Blueprint._meshLookup.putIfAbsent(thisBlueprint.getMeshForRank(0), thisBlueprint);
|
||||
Blueprint._meshLookup.putIfAbsent(thisBlueprint.getMeshForRank(1), thisBlueprint);
|
||||
Blueprint._meshLookup.putIfAbsent(thisBlueprint.getMeshForRank(3), thisBlueprint);
|
||||
Blueprint._meshLookup.putIfAbsent(thisBlueprint.getMeshForRank(7), thisBlueprint);
|
||||
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
Logger.info("read: " + recordsRead + " cached: " + blueprints.size());
|
||||
return blueprints;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.Boon;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class dbBoonHandler extends dbHandlerBase {
|
||||
|
||||
public dbBoonHandler() {
|
||||
}
|
||||
|
||||
|
||||
public ArrayList<Boon> GET_BOON_AMOUNTS_FOR_ITEMBASE(int itemBaseUUID) {
|
||||
|
||||
ArrayList<Boon> boons = new ArrayList<>();
|
||||
Boon thisBoon;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_item_boons` WHERE `itemBaseID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, itemBaseUUID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
thisBoon = new Boon(rs);
|
||||
boons.add(thisBoon);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return boons;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,855 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.DbObjectType;
|
||||
import engine.Enum.ProtectionState;
|
||||
import engine.Enum.TaxType;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.math.Vector3fImmutable;
|
||||
import engine.objects.*;
|
||||
import org.joda.time.DateTime;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class dbBuildingHandler extends dbHandlerBase {
|
||||
|
||||
public dbBuildingHandler() {
|
||||
this.localClass = Building.class;
|
||||
this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public Building CREATE_BUILDING(int parentZoneID, int OwnerUUID, String name, int meshUUID,
|
||||
Vector3fImmutable location, float meshScale, int currentHP,
|
||||
ProtectionState protectionState, int currentGold, int rank,
|
||||
DateTime upgradeDate, int blueprintUUID, float w, float rotY) {
|
||||
|
||||
Building building = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("CALL `building_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ,? ,? ,?, ?);")) {
|
||||
|
||||
preparedStatement.setInt(1, parentZoneID);
|
||||
preparedStatement.setInt(2, OwnerUUID);
|
||||
preparedStatement.setString(3, name);
|
||||
preparedStatement.setInt(4, meshUUID);
|
||||
preparedStatement.setFloat(5, location.x);
|
||||
preparedStatement.setFloat(6, location.y);
|
||||
preparedStatement.setFloat(7, location.z);
|
||||
preparedStatement.setFloat(8, meshScale);
|
||||
preparedStatement.setInt(9, currentHP);
|
||||
preparedStatement.setString(10, protectionState.name());
|
||||
preparedStatement.setInt(11, currentGold);
|
||||
preparedStatement.setInt(12, rank);
|
||||
|
||||
if (upgradeDate != null)
|
||||
preparedStatement.setTimestamp(13, new java.sql.Timestamp(upgradeDate.getMillis()));
|
||||
else
|
||||
preparedStatement.setNull(13, java.sql.Types.DATE);
|
||||
|
||||
preparedStatement.setInt(14, blueprintUUID);
|
||||
preparedStatement.setFloat(15, w);
|
||||
preparedStatement.setFloat(16, rotY);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (rs.next()) {
|
||||
int objectUUID = (int) rs.getLong("UID");
|
||||
|
||||
if (objectUUID > 0)
|
||||
building = GET_BUILDINGBYUUID(objectUUID);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return building;
|
||||
}
|
||||
|
||||
public boolean DELETE_FROM_DATABASE(final Building b) {
|
||||
|
||||
return removeFromBuildings(b);
|
||||
}
|
||||
|
||||
public ArrayList<Building> GET_ALL_BUILDINGS_FOR_ZONE(Zone zone) {
|
||||
|
||||
ArrayList<Building> buildings = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_building`.*, `object`.`parent` FROM `object` INNER JOIN `obj_building` ON `obj_building`.`UID` = `object`.`UID` WHERE `object`.`parent` = ?;")) {
|
||||
|
||||
preparedStatement.setLong(1, zone.getObjectUUID());
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
buildings = getObjectsFromRs(rs, 1000);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return buildings;
|
||||
}
|
||||
|
||||
public Building GET_BUILDINGBYUUID(int uuid) {
|
||||
|
||||
if (uuid == 0)
|
||||
return null;
|
||||
|
||||
Building building = (Building) DbManager.getFromCache(Enum.GameObjectType.Building, uuid);
|
||||
|
||||
if (building != null)
|
||||
return building;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_building`.*, `object`.`parent` FROM `object` INNER JOIN `obj_building` ON `obj_building`.`UID` = `object`.`UID` WHERE `object`.`UID` = ?;")) {
|
||||
|
||||
preparedStatement.setLong(1, uuid);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
building = (Building) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return building;
|
||||
}
|
||||
|
||||
public Building GET_BUILDING_BY_MESH(final int meshID) {
|
||||
|
||||
Building building = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("CALL building_GETBYMESH(?)")) {
|
||||
|
||||
preparedStatement.setInt(1, meshID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (rs.next())
|
||||
building = new Building(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error("Building", e);
|
||||
}
|
||||
|
||||
return building;
|
||||
}
|
||||
|
||||
public String SET_PROPERTY(final Building b, String name, Object new_value) {
|
||||
|
||||
String result = "";
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("CALL building_SETPROP(?,?,?)")) {
|
||||
|
||||
preparedStatement.setLong(1, b.getObjectUUID());
|
||||
preparedStatement.setString(2, name);
|
||||
preparedStatement.setString(3, String.valueOf(new_value));
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (rs.next())
|
||||
result = rs.getString("result");
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public int MOVE_BUILDING(long buildingID, long parentID, float locX, float locY, float locZ) {
|
||||
|
||||
int rowCount;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `object` INNER JOIN `obj_building` On `object`.`UID` = `obj_building`.`UID` SET `object`.`parent`=?, `obj_building`.`locationX`=?, `obj_building`.`locationY`=?, `obj_building`.`locationZ`=? WHERE `obj_building`.`UID`=?;")) {
|
||||
|
||||
preparedStatement.setLong(1, parentID);
|
||||
preparedStatement.setFloat(2, locX);
|
||||
preparedStatement.setFloat(3, locY);
|
||||
preparedStatement.setFloat(4, locZ);
|
||||
preparedStatement.setLong(5, buildingID);
|
||||
|
||||
rowCount = preparedStatement.executeUpdate();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return rowCount;
|
||||
}
|
||||
|
||||
private boolean removeFromBuildings(final Building b) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `object` WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setLong(1, b.getObjectUUID());
|
||||
preparedStatement.execute();
|
||||
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean CHANGE_NAME(Building b, String newName) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_building` SET `name`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setString(1, newName);
|
||||
preparedStatement.setLong(2, b.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean SET_RESERVE(Building b, int reserveAmount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_building` SET `reserve`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, reserveAmount);
|
||||
preparedStatement.setLong(2, b.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//CAS update to rank
|
||||
public boolean CHANGE_RANK(final long buildingID, int newRank) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_building` SET `rank`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, newRank);
|
||||
preparedStatement.setLong(2, buildingID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean UPDATE_BUILDING_HEALTH(final long buildingID, int NewHealth) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_building` SET `currentHP`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, NewHealth);
|
||||
preparedStatement.setLong(2, buildingID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean UPDATE_BUILDING_ALTITUDE(final long buildingID, float newAltitude) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_building` SET `locationY`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setFloat(1, newAltitude);
|
||||
preparedStatement.setLong(2, buildingID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean UPDATE_PROTECTIONSTATE(final long buildingUUID, ProtectionState protectionState) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_building` SET `protectionState`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setString(1, protectionState.name());
|
||||
preparedStatement.setLong(2, buildingUUID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean UPDATE_DOOR_LOCK(final int buildingUUID, int doorFlags) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE obj_building SET doorState = ? WHERE UID = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, doorFlags);
|
||||
preparedStatement.setInt(2, buildingUUID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean ADD_TO_FRIENDS_LIST(final long buildingID, final long friendID, final long guildID, final int friendType) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_building_friends` (`buildingUID`, `playerUID`,`guildUID`, `friendType`) VALUES (?,?,?,?)")) {
|
||||
|
||||
preparedStatement.setLong(1, buildingID);
|
||||
preparedStatement.setLong(2, friendID);
|
||||
preparedStatement.setLong(3, guildID);
|
||||
preparedStatement.setInt(4, friendType);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean REMOVE_FROM_FRIENDS_LIST(final long buildingID, long friendID, long guildID, int friendType) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_building_friends` WHERE `buildingUID`=? AND `playerUID`=? AND `guildUID` =? AND `friendType` = ?")) {
|
||||
|
||||
preparedStatement.setLong(1, buildingID);
|
||||
preparedStatement.setLong(2, friendID);
|
||||
preparedStatement.setLong(3, guildID);
|
||||
preparedStatement.setInt(4, friendType);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean REMOVE_FROM_CONDEMNED_LIST(final long buildingID, long friendID, long guildID, int friendType) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_building_condemned` WHERE `buildingUID`=? AND `playerUID`=? AND `guildUID` =? AND `friendType` = ?")) {
|
||||
|
||||
preparedStatement.setLong(1, buildingID);
|
||||
preparedStatement.setLong(2, friendID);
|
||||
preparedStatement.setLong(3, guildID);
|
||||
preparedStatement.setInt(4, friendType);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void CLEAR_FRIENDS_LIST(final long buildingID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_building_friends` WHERE `buildingUID`=?")) {
|
||||
|
||||
preparedStatement.setLong(1, buildingID);
|
||||
preparedStatement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void CLEAR_CONDEMNED_LIST(final long buildingID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_building_condemned` WHERE `buildingUID`=?")) {
|
||||
|
||||
preparedStatement.setLong(1, buildingID);
|
||||
preparedStatement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean CLEAR_PATROL(final long buildingID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_building_patrol_points` WHERE `buildingUID`=?")) {
|
||||
|
||||
preparedStatement.setLong(1, buildingID);
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void LOAD_ALL_FRIENDS_FOR_BUILDING(Building building) {
|
||||
|
||||
if (building == null)
|
||||
return;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_building_friends` WHERE `buildingUID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, building.getObjectUUID());
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
BuildingFriends friend = new BuildingFriends(rs);
|
||||
switch (friend.getFriendType()) {
|
||||
case 7:
|
||||
building.getFriends().put(friend.getPlayerUID(), friend);
|
||||
break;
|
||||
case 8:
|
||||
case 9:
|
||||
building.getFriends().put(friend.getGuildUID(), friend);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void LOAD_ALL_CONDEMNED_FOR_BUILDING(Building building) {
|
||||
|
||||
if (building == null)
|
||||
return;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_building_condemned` WHERE `buildingUID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, building.getObjectUUID());
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
Condemned condemned = new Condemned(rs);
|
||||
switch (condemned.getFriendType()) {
|
||||
case 2:
|
||||
building.getCondemned().put(condemned.getPlayerUID(), condemned);
|
||||
break;
|
||||
case 4:
|
||||
case 5:
|
||||
building.getCondemned().put(condemned.getGuildUID(), condemned);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<Vector3fImmutable> LOAD_PATROL_POINTS(Building building) {
|
||||
|
||||
if (building == null)
|
||||
return null;
|
||||
|
||||
ArrayList<Vector3fImmutable> patrolPoints = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_building_patrol_points` WHERE `buildingUID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, building.getObjectUUID());
|
||||
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
float x1 = rs.getFloat("patrolX");
|
||||
float y1 = rs.getFloat("patrolY");
|
||||
float z1 = rs.getFloat("patrolZ");
|
||||
Vector3fImmutable patrolPoint = new Vector3fImmutable(x1, y1, z1);
|
||||
patrolPoints.add(patrolPoint);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return patrolPoints;
|
||||
|
||||
}
|
||||
|
||||
public boolean ADD_TO_CONDEMNLIST(final long parentUID, final long playerUID, final long guildID, final int friendType) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_building_condemned` (`buildingUID`, `playerUID`,`guildUID`, `friendType`) VALUES (?,?,?,?)")) {
|
||||
|
||||
preparedStatement.setLong(1, parentUID);
|
||||
preparedStatement.setLong(2, playerUID);
|
||||
preparedStatement.setLong(3, guildID);
|
||||
preparedStatement.setInt(4, friendType);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean ADD_TO_PATROL(final long parentUID, final Vector3fImmutable patrolPoint) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_building_patrol_points` (`buildingUID`, `patrolX`,`patrolY`, `patrolZ`) VALUES (?,?,?,?)")) {
|
||||
|
||||
preparedStatement.setLong(1, parentUID);
|
||||
preparedStatement.setFloat(2, (int) patrolPoint.x);
|
||||
preparedStatement.setFloat(3, (int) patrolPoint.y);
|
||||
preparedStatement.setFloat(4, (int) patrolPoint.z);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public HashMap<Integer, ArrayList<BuildingRegions>> LOAD_BUILDING_REGIONS() {
|
||||
|
||||
HashMap<Integer, ArrayList<BuildingRegions>> regionList = new HashMap<>();
|
||||
BuildingRegions buildingRegions;
|
||||
int recordsRead = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_building_regions")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
recordsRead++;
|
||||
buildingRegions = new BuildingRegions(rs);
|
||||
|
||||
if (regionList.get(buildingRegions.getBuildingID()) == null) {
|
||||
ArrayList<BuildingRegions> regionsList = new ArrayList<>();
|
||||
regionsList.add(buildingRegions);
|
||||
regionList.put(buildingRegions.getBuildingID(), regionsList);
|
||||
} else {
|
||||
ArrayList<BuildingRegions> regionsList = regionList.get(buildingRegions.getBuildingID());
|
||||
regionsList.add(buildingRegions);
|
||||
regionList.put(buildingRegions.getBuildingID(), regionsList);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
Logger.info("read: " + recordsRead + " cached: " + regionList.size());
|
||||
return regionList;
|
||||
}
|
||||
|
||||
public HashMap<Integer, MeshBounds> LOAD_MESH_BOUNDS() {
|
||||
|
||||
HashMap<Integer, MeshBounds> meshBoundsMap = new HashMap<>();
|
||||
MeshBounds meshBounds;
|
||||
int recordsRead = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_mesh_bounds")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
recordsRead++;
|
||||
meshBounds = new MeshBounds(rs);
|
||||
meshBoundsMap.put(meshBounds.meshID, meshBounds);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
Logger.info("read: " + recordsRead + " cached: " + meshBoundsMap.size());
|
||||
return meshBoundsMap;
|
||||
}
|
||||
|
||||
public HashMap<Integer, ArrayList<StaticColliders>> LOAD_ALL_STATIC_COLLIDERS() {
|
||||
|
||||
HashMap<Integer, ArrayList<StaticColliders>> colliders = new HashMap<>();
|
||||
StaticColliders thisColliders;
|
||||
int recordsRead = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_building_colliders")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
recordsRead++;
|
||||
thisColliders = new StaticColliders(rs);
|
||||
|
||||
if (colliders.get(thisColliders.getMeshID()) == null) {
|
||||
ArrayList<StaticColliders> colliderList = new ArrayList<>();
|
||||
colliderList.add(thisColliders);
|
||||
colliders.put(thisColliders.getMeshID(), colliderList);
|
||||
} else {
|
||||
ArrayList<StaticColliders> colliderList = colliders.get(thisColliders.getMeshID());
|
||||
colliderList.add(thisColliders);
|
||||
colliders.put(thisColliders.getMeshID(), colliderList);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
Logger.info("read: " + recordsRead + " cached: " + colliders.size());
|
||||
return colliders;
|
||||
}
|
||||
|
||||
// This public class inserted here as it's a generic utility function
|
||||
// with no other good place for it. If you find a good home for it
|
||||
// feel free to move it. -
|
||||
|
||||
public final DbObjectType GET_UID_ENUM(long object_UID) {
|
||||
|
||||
DbObjectType objectType = DbObjectType.INVALID;
|
||||
String typeString = "INVALID";
|
||||
|
||||
if (object_UID == 0)
|
||||
return objectType;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `type` FROM `object` WHERE `object`.`UID` = ? LIMIT 1;")) {
|
||||
|
||||
preparedStatement.setLong(1, object_UID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (rs.next()) {
|
||||
typeString = rs.getString("type").toUpperCase();
|
||||
objectType = DbObjectType.valueOf(typeString);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return DbObjectType.INVALID;
|
||||
}
|
||||
|
||||
return objectType;
|
||||
}
|
||||
|
||||
public boolean updateBuildingRank(final Building b, int Rank) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_building` SET `rank`=?,"
|
||||
+ "`upgradeDate`=?, `meshUUID`=?, `currentHP`=? "
|
||||
+ "WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, Rank);
|
||||
preparedStatement.setNull(2, java.sql.Types.DATE);
|
||||
preparedStatement.setInt(3, b.getBlueprint().getMeshForRank(Rank));
|
||||
preparedStatement.setInt(4, b.getBlueprint().getMaxHealth(Rank));
|
||||
preparedStatement.setInt(5, b.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateReverseKOS(final Building b, boolean reverse) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_building` SET `reverseKOS`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setBoolean(1, reverse);
|
||||
preparedStatement.setInt(2, b.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateActiveCondemn(final Condemned condemn, boolean active) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_building_condemned` SET `active`=? "
|
||||
+ "WHERE`buildingUID` = ? AND `playerUID` = ? AND `guildUID` = ? AND `friendType` = ?")) {
|
||||
|
||||
preparedStatement.setBoolean(1, active);
|
||||
preparedStatement.setInt(2, condemn.getParent());
|
||||
preparedStatement.setInt(3, condemn.getPlayerUID());
|
||||
preparedStatement.setInt(4, condemn.getGuildUID());
|
||||
preparedStatement.setInt(5, condemn.getFriendType());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateBuildingOwner(final Building building, int ownerUUID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_building` SET `ownerUUID`=? "
|
||||
+ " WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, ownerUUID);
|
||||
preparedStatement.setInt(2, building.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateBuildingUpgradeTime(LocalDateTime upgradeDateTime, Building toUpgrade, int costToUpgrade) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE obj_building SET upgradeDate=?, currentGold=? "
|
||||
+ "WHERE UID = ?")) {
|
||||
|
||||
if (upgradeDateTime == null)
|
||||
preparedStatement.setNull(1, java.sql.Types.DATE);
|
||||
else
|
||||
preparedStatement.setTimestamp(1, new java.sql.Timestamp(upgradeDateTime.atZone(ZoneId.systemDefault())
|
||||
.toInstant().toEpochMilli()));
|
||||
|
||||
preparedStatement.setInt(2, toUpgrade.getStrongboxValue() - costToUpgrade);
|
||||
preparedStatement.setInt(3, toUpgrade.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateMaintDate(Building building) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE obj_building SET maintDate=? "
|
||||
+ "WHERE UID = ?")) {
|
||||
|
||||
if (building.maintDateTime == null)
|
||||
preparedStatement.setNull(1, java.sql.Types.DATE);
|
||||
else
|
||||
preparedStatement.setTimestamp(1, new java.sql.Timestamp(building.maintDateTime.atZone(ZoneId.systemDefault())
|
||||
.toInstant().toEpochMilli()));
|
||||
preparedStatement.setInt(2, building.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean addTaxes(Building building, TaxType taxType, int amount, boolean enforceKOS) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE obj_building SET taxType=?, taxAmount = ?, enforceKOS = ? "
|
||||
+ "WHERE UID = ?")) {
|
||||
|
||||
preparedStatement.setString(1, taxType.name());
|
||||
preparedStatement.setInt(2, amount);
|
||||
preparedStatement.setBoolean(3, enforceKOS);
|
||||
preparedStatement.setInt(4, building.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean removeTaxes(Building building) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE obj_building SET taxType=?, taxAmount = ?, enforceKOS = ?, taxDate = ? "
|
||||
+ "WHERE UID = ?")) {
|
||||
|
||||
preparedStatement.setString(1, TaxType.NONE.name());
|
||||
preparedStatement.setInt(2, 0);
|
||||
preparedStatement.setBoolean(3, false);
|
||||
preparedStatement.setNull(4, java.sql.Types.DATE);
|
||||
preparedStatement.setInt(5, building.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean acceptTaxes(Building building) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE obj_building SET taxDate=? "
|
||||
+ "WHERE UID = ?")) {
|
||||
|
||||
preparedStatement.setTimestamp(1, new java.sql.Timestamp(DateTime.now().plusDays(7).getMillis()));
|
||||
preparedStatement.setInt(2, building.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.BuildingLocation;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class dbBuildingLocationHandler extends dbHandlerBase {
|
||||
|
||||
public dbBuildingLocationHandler() {
|
||||
this.localClass = BuildingLocation.class;
|
||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public ArrayList<BuildingLocation> LOAD_BUILDING_LOCATIONS() {
|
||||
|
||||
ArrayList<BuildingLocation> buildingLocations = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("select `ID`, `BuildingID`, `type`, `slot`, `unknown`, `locX`, `locY`, `locZ`, `w`, `rotX`, `rotY`, `rotZ` from static_building_location " +
|
||||
"where type = 6 or type = 8 " +
|
||||
"GROUP BY buildingID, slot " +
|
||||
"ORDER BY buildingID, slot ASC;")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
buildingLocations = getObjectsFromRs(rs, 20);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return buildingLocations;
|
||||
}
|
||||
|
||||
return buildingLocations;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.Account;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import engine.session.CSSession;
|
||||
import engine.util.StringUtils;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class dbCSSessionHandler extends dbHandlerBase {
|
||||
|
||||
public dbCSSessionHandler() {
|
||||
this.localClass = CSSession.class;
|
||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public boolean ADD_CSSESSION(String secKey, Account acc, InetAddress inet, String machineID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_session` (`secretKey`, `accountID`, `discordAccount`, `sessionIP`, machineID) VALUES (?,?,?,INET_ATON(?),?)")) {
|
||||
|
||||
preparedStatement.setString(1, secKey);
|
||||
preparedStatement.setLong(2, acc.getObjectUUID());
|
||||
preparedStatement.setString(3, acc.discordAccount);
|
||||
preparedStatement.setString(4, StringUtils.InetAddressToClientString(inet));
|
||||
preparedStatement.setString(5, machineID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean DELETE_UNUSED_CSSESSION(String secKey) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_session` WHERE `secretKey`=? && `characterID` IS NULL")) {
|
||||
|
||||
preparedStatement.setString(1, secKey);
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean DELETE_CSSESSION(String secKey) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_session` WHERE `secretKey`=?")) {
|
||||
|
||||
preparedStatement.setString(1, secKey);
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean UPDATE_CSSESSION(String secKey, int charID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_session` SET `characterID`=? WHERE `secretKey`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, charID);
|
||||
preparedStatement.setString(2, secKey);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public CSSession GET_CSSESSION(String secKey) {
|
||||
|
||||
CSSession css = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `accountID`, `characterID`, `machineID` FROM `dyn_session` WHERE `secretKey`=?")) {
|
||||
|
||||
preparedStatement.setString(1, secKey);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (rs.next())
|
||||
css = new CSSession(secKey, DbManager.AccountQueries.GET_ACCOUNT(rs.getInt("accountID")), PlayerCharacter.getPlayerCharacter(rs.getInt("characterID")), rs.getString("machineID"));
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return css;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.CharacterPower;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import engine.server.MBServerStatics;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class dbCharacterPowerHandler extends dbHandlerBase {
|
||||
|
||||
public dbCharacterPowerHandler() {
|
||||
this.localClass = CharacterPower.class;
|
||||
this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public CharacterPower ADD_CHARACTER_POWER(CharacterPower toAdd) {
|
||||
|
||||
CharacterPower characterPower = null;
|
||||
|
||||
if (CharacterPower.getOwner(toAdd) == null || toAdd.getPower() == null) {
|
||||
Logger.error("dbCharacterSkillHandler.ADD_Power", toAdd.getObjectUUID() + " missing owner or powersBase");
|
||||
return null;
|
||||
}
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_character_power` (`CharacterID`, `powersBaseToken`, `trains`) VALUES (?, ?, ?);", Statement.RETURN_GENERATED_KEYS)) {
|
||||
|
||||
preparedStatement.setLong(1, CharacterPower.getOwner(toAdd).getObjectUUID());
|
||||
preparedStatement.setInt(2, toAdd.getPower().getToken());
|
||||
preparedStatement.setInt(3, toAdd.getTrains());
|
||||
|
||||
preparedStatement.executeUpdate();
|
||||
ResultSet rs = preparedStatement.getGeneratedKeys();
|
||||
|
||||
if (rs.next())
|
||||
characterPower = GET_CHARACTER_POWER(rs.getInt(1));
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return null;
|
||||
}
|
||||
return characterPower;
|
||||
}
|
||||
|
||||
public int DELETE_CHARACTER_POWER(final int objectUUID) {
|
||||
|
||||
int rowCount = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_character_power` WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setLong(1, objectUUID);
|
||||
rowCount = preparedStatement.executeUpdate();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return rowCount;
|
||||
}
|
||||
|
||||
public CharacterPower GET_CHARACTER_POWER(int objectUUID) {
|
||||
|
||||
CharacterPower characterPower = (CharacterPower) DbManager.getFromCache(Enum.GameObjectType.CharacterPower, objectUUID);
|
||||
|
||||
if (characterPower != null)
|
||||
return characterPower;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_power` WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setLong(1, objectUUID);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
characterPower = (CharacterPower) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return characterPower;
|
||||
}
|
||||
|
||||
public ConcurrentHashMap<Integer, CharacterPower> GET_POWERS_FOR_CHARACTER(PlayerCharacter pc) {
|
||||
|
||||
ConcurrentHashMap<Integer, CharacterPower> powers = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
|
||||
int objectUUID = pc.getObjectUUID();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_power` WHERE CharacterID = ?")) {
|
||||
|
||||
preparedStatement.setLong(1, objectUUID);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
CharacterPower cp = new CharacterPower(rs, pc);
|
||||
if (cp.getPower() != null)
|
||||
powers.put(cp.getPower().getToken(), cp);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return powers;
|
||||
}
|
||||
|
||||
public void UPDATE_TRAINS(final CharacterPower characterPower) {
|
||||
|
||||
//skip update if nothing changed
|
||||
|
||||
if (!characterPower.isTrained())
|
||||
return;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_character_power` SET `trains`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setShort(1, (short) characterPower.getTrains());
|
||||
preparedStatement.setInt(2, characterPower.getObjectUUID());
|
||||
|
||||
preparedStatement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
characterPower.setTrained(false);
|
||||
}
|
||||
|
||||
public void updateDatabase(final CharacterPower pow) {
|
||||
|
||||
if (pow.getPower() == null) {
|
||||
Logger.error("Failed to find powersBase for Power " + pow.getObjectUUID());
|
||||
return;
|
||||
}
|
||||
|
||||
if (CharacterPower.getOwner(pow) == null) {
|
||||
Logger.error("Failed to find owner for Power " + pow.getObjectUUID());
|
||||
return;
|
||||
}
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_character_power` SET `PowersBaseToken`=?, `CharacterID`=?, `trains`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, pow.getPower().getToken());
|
||||
preparedStatement.setInt(2, CharacterPower.getOwner(pow).getObjectUUID());
|
||||
preparedStatement.setShort(3, (short) pow.getTrains());
|
||||
preparedStatement.setInt(4, pow.getObjectUUID());
|
||||
preparedStatement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
pow.setTrained(false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.CharacterRune;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class dbCharacterRuneHandler extends dbHandlerBase {
|
||||
|
||||
public dbCharacterRuneHandler() {
|
||||
this.localClass = CharacterRune.class;
|
||||
this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public CharacterRune ADD_CHARACTER_RUNE(final CharacterRune toAdd) {
|
||||
|
||||
CharacterRune characterRune = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_character_rune` (`CharacterID`, `RuneBaseID`) VALUES (?, ?);", Statement.RETURN_GENERATED_KEYS)) {
|
||||
|
||||
preparedStatement.setLong(1, toAdd.getPlayerID());
|
||||
preparedStatement.setInt(2, toAdd.getRuneBaseID());
|
||||
|
||||
preparedStatement.executeUpdate();
|
||||
ResultSet rs = preparedStatement.getGeneratedKeys();
|
||||
|
||||
if (rs.next())
|
||||
characterRune = GET_CHARACTER_RUNE(rs.getInt(1));
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return characterRune;
|
||||
}
|
||||
|
||||
public CharacterRune GET_CHARACTER_RUNE(int runeID) {
|
||||
|
||||
CharacterRune characterRune = (CharacterRune) DbManager.getFromCache(Enum.GameObjectType.CharacterRune, runeID);
|
||||
|
||||
if (characterRune != null)
|
||||
return characterRune;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_rune` WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, runeID);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
characterRune = (CharacterRune) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return characterRune;
|
||||
}
|
||||
|
||||
public boolean DELETE_CHARACTER_RUNE(final CharacterRune characterRune) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_character_rune` WHERE `UID`=?;")) {
|
||||
|
||||
preparedStatement.setLong(1, characterRune.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public ArrayList<CharacterRune> GET_RUNES_FOR_CHARACTER(final int characterId) {
|
||||
|
||||
ArrayList<CharacterRune> characterRunes = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_rune` WHERE `CharacterID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, characterId);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
characterRunes = getObjectsFromRs(rs, 10);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return characterRunes;
|
||||
}
|
||||
|
||||
public void updateDatabase(final CharacterRune characterRune) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_character_rune` SET `CharacterID`=?, `RuneBaseID`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, characterRune.getPlayerID());
|
||||
preparedStatement.setInt(2, characterRune.getRuneBaseID());
|
||||
preparedStatement.setLong(3, characterRune.getObjectUUID());
|
||||
|
||||
preparedStatement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.AbstractCharacter;
|
||||
import engine.objects.CharacterSkill;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import engine.server.MBServerStatics;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class dbCharacterSkillHandler extends dbHandlerBase {
|
||||
|
||||
public dbCharacterSkillHandler() {
|
||||
this.localClass = CharacterSkill.class;
|
||||
this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public CharacterSkill ADD_SKILL(CharacterSkill toAdd) {
|
||||
|
||||
CharacterSkill characterSkill = null;
|
||||
|
||||
if (CharacterSkill.GetOwner(toAdd) == null || toAdd.getSkillsBase() == null) {
|
||||
Logger.error("dbCharacterSkillHandler.ADD_SKILL", toAdd.getObjectUUID() + " missing owner or skillsBase");
|
||||
return null;
|
||||
}
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_character_skill` (`CharacterID`, `skillsBaseID`, `trains`) VALUES (?, ?, ?);", Statement.RETURN_GENERATED_KEYS)) {
|
||||
|
||||
preparedStatement.setLong(1, CharacterSkill.GetOwner(toAdd).getObjectUUID());
|
||||
preparedStatement.setInt(2, toAdd.getSkillsBase().getObjectUUID());
|
||||
preparedStatement.setInt(3, toAdd.getNumTrains());
|
||||
|
||||
preparedStatement.executeUpdate();
|
||||
ResultSet rs = preparedStatement.getGeneratedKeys();
|
||||
|
||||
if (rs.next())
|
||||
characterSkill = GET_SKILL(rs.getInt(1));
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return characterSkill;
|
||||
}
|
||||
|
||||
public boolean DELETE_SKILL(final int objectUUID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_character_skill` WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setLong(1, objectUUID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public CharacterSkill GET_SKILL(final int objectUUID) {
|
||||
|
||||
CharacterSkill characterSkill = (CharacterSkill) DbManager.getFromCache(Enum.GameObjectType.CharacterSkill, objectUUID);
|
||||
|
||||
if (characterSkill != null)
|
||||
return characterSkill;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_skill` WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, objectUUID);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
characterSkill = (CharacterSkill) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return characterSkill;
|
||||
}
|
||||
|
||||
public ConcurrentHashMap<String, CharacterSkill> GET_SKILLS_FOR_CHARACTER(final AbstractCharacter ac) {
|
||||
|
||||
ConcurrentHashMap<String, CharacterSkill> characterSkills = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
|
||||
|
||||
if (ac == null || (!(ac.getObjectType().equals(Enum.GameObjectType.PlayerCharacter))))
|
||||
return characterSkills;
|
||||
|
||||
PlayerCharacter playerCharacter = (PlayerCharacter) ac;
|
||||
int characterId = playerCharacter.getObjectUUID();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_skill` WHERE `CharacterID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, characterId);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
CharacterSkill cs = new CharacterSkill(rs, playerCharacter);
|
||||
if (cs.getSkillsBase() != null)
|
||||
characterSkills.put(cs.getSkillsBase().getName(), cs);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return characterSkills;
|
||||
}
|
||||
|
||||
|
||||
public void UPDATE_TRAINS(final CharacterSkill characterSkill) {
|
||||
|
||||
if (!characterSkill.isTrained())
|
||||
return;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_character_skill` SET `trains`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setShort(1, (short) characterSkill.getNumTrains());
|
||||
preparedStatement.setLong(2, characterSkill.getObjectUUID());
|
||||
|
||||
if (preparedStatement.executeUpdate() != 0)
|
||||
characterSkill.syncTrains();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateDatabase(final CharacterSkill characterSkill) {
|
||||
|
||||
if (characterSkill.getSkillsBase() == null) {
|
||||
Logger.error("Failed to find skillsBase for Skill " + characterSkill.getObjectUUID());
|
||||
return;
|
||||
}
|
||||
|
||||
if (CharacterSkill.GetOwner(characterSkill) == null) {
|
||||
Logger.error("Failed to find owner for Skill " + characterSkill.getObjectUUID());
|
||||
return;
|
||||
}
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_character_skill` SET `skillsBaseID`=?, `CharacterID`=?, `trains`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, characterSkill.getSkillsBase().getObjectUUID());
|
||||
preparedStatement.setInt(2, CharacterSkill.GetOwner(characterSkill).getObjectUUID());
|
||||
preparedStatement.setShort(3, (short) characterSkill.getNumTrains());
|
||||
preparedStatement.setLong(4, characterSkill.getObjectUUID());
|
||||
|
||||
if (preparedStatement.executeUpdate() != 0)
|
||||
characterSkill.syncTrains();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.AbstractGameObject;
|
||||
import engine.objects.Building;
|
||||
import engine.objects.City;
|
||||
import engine.objects.Zone;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class dbCityHandler extends dbHandlerBase {
|
||||
|
||||
public dbCityHandler() {
|
||||
this.localClass = City.class;
|
||||
this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public static void addObject(ArrayList<AbstractGameObject> list, ResultSet rs) throws SQLException {
|
||||
String type = rs.getString("type");
|
||||
switch (type) {
|
||||
case "zone":
|
||||
Zone zone = new Zone(rs);
|
||||
DbManager.addToCache(zone);
|
||||
list.add(zone);
|
||||
break;
|
||||
case "building":
|
||||
Building building = new Building(rs);
|
||||
DbManager.addToCache(building);
|
||||
list.add(building);
|
||||
break;
|
||||
case "city":
|
||||
City city = new City(rs);
|
||||
DbManager.addToCache(city);
|
||||
list.add(city);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<AbstractGameObject> CREATE_CITY(int ownerID, int parentZoneID, int realmID, float xCoord, float yCoord, float zCoord, float rotation, float W, String name, LocalDateTime established) {
|
||||
|
||||
LocalDateTime upgradeTime = LocalDateTime.now().plusHours(2);
|
||||
ArrayList<AbstractGameObject> objectList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("CALL `city_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?,?,?)")) {
|
||||
|
||||
preparedStatement.setLong(1, ownerID); //objectUUID of owning player
|
||||
preparedStatement.setLong(2, parentZoneID); //objectUUID of parent (continent) zone
|
||||
preparedStatement.setLong(3, realmID); //objectUUID of realm city belongs in
|
||||
preparedStatement.setFloat(4, xCoord); //xOffset from parentZone center
|
||||
preparedStatement.setFloat(5, yCoord); //yOffset from parentZone center
|
||||
preparedStatement.setFloat(6, zCoord); //zOffset from parentZone center
|
||||
preparedStatement.setString(7, name); //city name
|
||||
preparedStatement.setTimestamp(8, Timestamp.valueOf(established));
|
||||
preparedStatement.setFloat(9, rotation);
|
||||
preparedStatement.setFloat(10, W);
|
||||
preparedStatement.setTimestamp(11, Timestamp.valueOf(upgradeTime));
|
||||
|
||||
boolean work = preparedStatement.execute();
|
||||
|
||||
if (work) {
|
||||
|
||||
ResultSet rs = preparedStatement.getResultSet();
|
||||
|
||||
while (rs.next())
|
||||
addObject(objectList, rs);
|
||||
rs.close();
|
||||
} else {
|
||||
Logger.info("City Placement Failed: " + preparedStatement);
|
||||
return objectList; //city creation failure
|
||||
}
|
||||
while (preparedStatement.getMoreResults()) {
|
||||
ResultSet rs = preparedStatement.getResultSet();
|
||||
while (rs.next()) {
|
||||
addObject(objectList, rs);
|
||||
}
|
||||
rs.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return objectList;
|
||||
}
|
||||
|
||||
public ArrayList<City> GET_CITIES_BY_ZONE(final int objectUUID) {
|
||||
|
||||
ArrayList<City> cityList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_city`.*, `object`.`parent` FROM `obj_city` INNER JOIN `object` ON `object`.`UID` = `obj_city`.`UID` WHERE `object`.`parent`=?;")) {
|
||||
|
||||
preparedStatement.setLong(1, objectUUID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
cityList = getObjectsFromRs(rs, 100);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return cityList;
|
||||
}
|
||||
|
||||
public City GET_CITY(final int cityId) {
|
||||
|
||||
City city = (City) DbManager.getFromCache(Enum.GameObjectType.City, cityId);
|
||||
|
||||
if (city != null)
|
||||
return city;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_city`.*, `object`.`parent` FROM `obj_city` INNER JOIN `object` ON `object`.`UID` = `obj_city`.`UID` WHERE `object`.`UID`=?;")) {
|
||||
|
||||
preparedStatement.setLong(1, cityId);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
city = (City) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return city;
|
||||
}
|
||||
|
||||
public boolean updateforceRename(City city, boolean value) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_city` SET `forceRename`=?"
|
||||
+ " WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setByte(1, (value == true) ? (byte) 1 : (byte) 0);
|
||||
preparedStatement.setInt(2, city.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean updateOpenCity(City city, boolean value) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_city` SET `open`=?"
|
||||
+ " WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setByte(1, (value == true) ? (byte) 1 : (byte) 0);
|
||||
preparedStatement.setInt(2, city.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean updateTOL(City city, int tolID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_city` SET `treeOfLifeUUID`=?"
|
||||
+ " WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, tolID);
|
||||
preparedStatement.setInt(2, city.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean renameCity(City city, String name) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_city` SET `name`=?"
|
||||
+ " WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setString(1, name);
|
||||
preparedStatement.setInt(2, city.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean updateSiegesWithstood(City city, int value) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_city` SET `name`=?"
|
||||
+ " WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, value);
|
||||
preparedStatement.setInt(2, city.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean updateRealmTaxDate(City city, LocalDateTime localDateTime) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_city` SET `realmTaxDate` =?"
|
||||
+ " WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setTimestamp(1, Timestamp.valueOf(localDateTime));
|
||||
preparedStatement.setInt(2, city.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.Contract;
|
||||
import engine.objects.ItemBase;
|
||||
import engine.objects.MobEquipment;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class dbContractHandler extends dbHandlerBase {
|
||||
|
||||
public dbContractHandler() {
|
||||
this.localClass = Contract.class;
|
||||
this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public Contract GET_CONTRACT(final int objectUUID) {
|
||||
|
||||
Contract contract = (Contract) DbManager.getFromCache(Enum.GameObjectType.Contract, objectUUID);
|
||||
|
||||
if (contract != null)
|
||||
return contract;
|
||||
|
||||
if (objectUUID == 0)
|
||||
return null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_contract` WHERE `ID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, objectUUID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
contract = (Contract) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return contract;
|
||||
}
|
||||
|
||||
public void LOAD_CONTRACT_INVENTORY(final Contract contract) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_inventoryset` WHERE `inventorySet` = ?;")) {
|
||||
|
||||
preparedStatement.setInt(1, contract.inventorySet);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
//handle item base
|
||||
int itemBaseID = rs.getInt("itembaseID");
|
||||
|
||||
ItemBase ib = ItemBase.getItemBase(itemBaseID);
|
||||
|
||||
if (ib != null) {
|
||||
|
||||
MobEquipment me = new MobEquipment(ib, 0, 0);
|
||||
contract.getSellInventory().add(me);
|
||||
|
||||
//handle magic effects
|
||||
String prefix = rs.getString("prefix");
|
||||
int pRank = rs.getInt("pRank");
|
||||
String suffix = rs.getString("suffix");
|
||||
int sRank = rs.getInt("sRank");
|
||||
|
||||
if (prefix != null) {
|
||||
me.setPrefix(prefix, pRank);
|
||||
me.setIsID(true);
|
||||
}
|
||||
|
||||
if (suffix != null) {
|
||||
me.setSuffix(suffix, sRank);
|
||||
me.setIsID(true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void LOAD_SELL_LIST_FOR_CONTRACT(final Contract contract) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_contract_selltype` WHERE `contractID` = ?;")) {
|
||||
|
||||
preparedStatement.setInt(1, contract.getObjectUUID());
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
int type = rs.getInt("type");
|
||||
int value = rs.getInt("value");
|
||||
|
||||
switch (type) {
|
||||
case 1:
|
||||
contract.getBuyItemType().add(value);
|
||||
break;
|
||||
case 2:
|
||||
contract.getBuySkillToken().add(value);
|
||||
break;
|
||||
case 3:
|
||||
contract.getBuyUnknownToken().add(value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean updateAllowedBuildings(final Contract con, final long slotbitvalue) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `static_npc_contract` SET `allowedBuildingTypeID`=? WHERE `contractID`=?")) {
|
||||
|
||||
preparedStatement.setLong(1, slotbitvalue);
|
||||
preparedStatement.setInt(2, con.getContractID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateDatabase(final Contract con) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `static_npc_contract` SET `contractID`=?, `name`=?, "
|
||||
+ "`mobbaseID`=?, `classID`=?, vendorDialog=?, iconID=?, allowedBuildingTypeID=? WHERE `ID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, con.getContractID());
|
||||
preparedStatement.setString(2, con.getName());
|
||||
preparedStatement.setInt(3, con.getMobbaseID());
|
||||
preparedStatement.setInt(4, con.getClassID());
|
||||
preparedStatement.setInt(5, (con.getVendorDialog() != null) ? con.getVendorDialog().getObjectUUID() : 0);
|
||||
preparedStatement.setInt(6, con.getIconID());
|
||||
preparedStatement.setInt(8, con.getObjectUUID());
|
||||
preparedStatement.setLong(7, con.getAllowedBuildings().toLong());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,303 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.gameManager.PowersManager;
|
||||
import engine.powers.EffectsBase;
|
||||
import engine.powers.effectmodifiers.*;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class dbEffectsBaseHandler extends dbHandlerBase {
|
||||
|
||||
public dbEffectsBaseHandler() {
|
||||
|
||||
}
|
||||
|
||||
public static ArrayList<EffectsBase> getAllEffectsBase() {
|
||||
|
||||
ArrayList<EffectsBase> effectList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement prepareStatement = connection.prepareStatement("SELECT * FROM static_power_effectbase ORDER BY `IDString` DESC")) {
|
||||
|
||||
ResultSet rs = prepareStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
EffectsBase effectBase = new EffectsBase(rs);
|
||||
effectList.add(effectBase);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
|
||||
return effectList;
|
||||
}
|
||||
|
||||
public static void cacheAllEffectModifiers() {
|
||||
|
||||
String IDString;
|
||||
AbstractEffectModifier abstractEffectModifier = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement prepareStatement = connection.prepareStatement("SELECT * FROM static_power_effectmod")) {
|
||||
|
||||
ResultSet rs = prepareStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
IDString = rs.getString("IDString");
|
||||
EffectsBase effectBase = PowersManager.getEffectByIDString(IDString);
|
||||
Enum.ModType modifier = Enum.ModType.GetModType(rs.getString("modType"));
|
||||
|
||||
//combine item prefix and suffix effect modifiers
|
||||
|
||||
abstractEffectModifier = getCombinedModifiers(abstractEffectModifier, rs, effectBase, modifier);
|
||||
|
||||
if (abstractEffectModifier != null) {
|
||||
|
||||
if (EffectsBase.modifiersMap.containsKey(effectBase.getIDString()) == false)
|
||||
EffectsBase.modifiersMap.put(effectBase.getIDString(), new HashSet<>());
|
||||
|
||||
EffectsBase.modifiersMap.get(effectBase.getIDString()).add(abstractEffectModifier);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static AbstractEffectModifier getCombinedModifiers(AbstractEffectModifier abstractEffectModifier, ResultSet rs, EffectsBase effectBase, Enum.ModType modifier) throws SQLException {
|
||||
switch (modifier) {
|
||||
case AdjustAboveDmgCap:
|
||||
abstractEffectModifier = new AdjustAboveDmgCapEffectModifier(rs);
|
||||
break;
|
||||
case Ambidexterity:
|
||||
abstractEffectModifier = new AmbidexterityEffectModifier(rs);
|
||||
break;
|
||||
case AnimOverride:
|
||||
break;
|
||||
case ArmorPiercing:
|
||||
abstractEffectModifier = new ArmorPiercingEffectModifier(rs);
|
||||
break;
|
||||
case AttackDelay:
|
||||
abstractEffectModifier = new AttackDelayEffectModifier(rs);
|
||||
break;
|
||||
case Attr:
|
||||
abstractEffectModifier = new AttributeEffectModifier(rs);
|
||||
break;
|
||||
case BlackMantle:
|
||||
abstractEffectModifier = new BlackMantleEffectModifier(rs);
|
||||
break;
|
||||
case BladeTrails:
|
||||
abstractEffectModifier = new BladeTrailsEffectModifier(rs);
|
||||
break;
|
||||
case Block:
|
||||
abstractEffectModifier = new BlockEffectModifier(rs);
|
||||
break;
|
||||
case BlockedPowerType:
|
||||
abstractEffectModifier = new BlockedPowerTypeEffectModifier(rs);
|
||||
break;
|
||||
case CannotAttack:
|
||||
abstractEffectModifier = new CannotAttackEffectModifier(rs);
|
||||
break;
|
||||
case CannotCast:
|
||||
abstractEffectModifier = new CannotCastEffectModifier(rs);
|
||||
break;
|
||||
case CannotMove:
|
||||
abstractEffectModifier = new CannotMoveEffectModifier(rs);
|
||||
break;
|
||||
case CannotTrack:
|
||||
abstractEffectModifier = new CannotTrackEffectModifier(rs);
|
||||
break;
|
||||
case Charmed:
|
||||
abstractEffectModifier = new CharmedEffectModifier(rs);
|
||||
break;
|
||||
case ConstrainedAmbidexterity:
|
||||
abstractEffectModifier = new ConstrainedAmbidexterityEffectModifier(rs);
|
||||
break;
|
||||
case DamageCap:
|
||||
abstractEffectModifier = new DamageCapEffectModifier(rs);
|
||||
break;
|
||||
case DamageShield:
|
||||
abstractEffectModifier = new DamageShieldEffectModifier(rs);
|
||||
break;
|
||||
case DCV:
|
||||
abstractEffectModifier = new DCVEffectModifier(rs);
|
||||
break;
|
||||
case Dodge:
|
||||
abstractEffectModifier = new DodgeEffectModifier(rs);
|
||||
break;
|
||||
case DR:
|
||||
abstractEffectModifier = new DREffectModifier(rs);
|
||||
break;
|
||||
case Durability:
|
||||
abstractEffectModifier = new DurabilityEffectModifier(rs);
|
||||
break;
|
||||
case ExclusiveDamageCap:
|
||||
abstractEffectModifier = new ExclusiveDamageCapEffectModifier(rs);
|
||||
break;
|
||||
case Fade:
|
||||
abstractEffectModifier = new FadeEffectModifier(rs);
|
||||
break;
|
||||
case Fly:
|
||||
abstractEffectModifier = new FlyEffectModifier(rs);
|
||||
break;
|
||||
case Health:
|
||||
abstractEffectModifier = new HealthEffectModifier(rs);
|
||||
break;
|
||||
case HealthFull:
|
||||
abstractEffectModifier = new HealthFullEffectModifier(rs);
|
||||
break;
|
||||
case HealthRecoverRate:
|
||||
abstractEffectModifier = new HealthRecoverRateEffectModifier(rs);
|
||||
break;
|
||||
case IgnoreDamageCap:
|
||||
abstractEffectModifier = new IgnoreDamageCapEffectModifier(rs);
|
||||
break;
|
||||
case IgnorePassiveDefense:
|
||||
abstractEffectModifier = new IgnorePassiveDefenseEffectModifier(rs);
|
||||
break;
|
||||
case ImmuneTo:
|
||||
abstractEffectModifier = new ImmuneToEffectModifier(rs);
|
||||
break;
|
||||
case ImmuneToAttack:
|
||||
abstractEffectModifier = new ImmuneToAttackEffectModifier(rs);
|
||||
break;
|
||||
case ImmuneToPowers:
|
||||
abstractEffectModifier = new ImmuneToPowersEffectModifier(rs);
|
||||
break;
|
||||
case Invisible:
|
||||
abstractEffectModifier = new InvisibleEffectModifier(rs);
|
||||
break;
|
||||
case ItemName:
|
||||
abstractEffectModifier = new ItemNameEffectModifier(rs);
|
||||
if (((ItemNameEffectModifier) abstractEffectModifier).name.isEmpty())
|
||||
break;
|
||||
if (effectBase != null)
|
||||
effectBase.setName((((ItemNameEffectModifier) abstractEffectModifier).name));
|
||||
break;
|
||||
case Mana:
|
||||
abstractEffectModifier = new ManaEffectModifier(rs);
|
||||
break;
|
||||
case ManaFull:
|
||||
abstractEffectModifier = new ManaFullEffectModifier(rs);
|
||||
break;
|
||||
case ManaRecoverRate:
|
||||
abstractEffectModifier = new ManaRecoverRateEffectModifier(rs);
|
||||
break;
|
||||
case MaxDamage:
|
||||
abstractEffectModifier = new MaxDamageEffectModifier(rs);
|
||||
break;
|
||||
case MeleeDamageModifier:
|
||||
abstractEffectModifier = new MeleeDamageEffectModifier(rs);
|
||||
break;
|
||||
case MinDamage:
|
||||
abstractEffectModifier = new MinDamageEffectModifier(rs);
|
||||
break;
|
||||
case NoMod:
|
||||
abstractEffectModifier = new NoModEffectModifier(rs);
|
||||
break;
|
||||
case OCV:
|
||||
abstractEffectModifier = new OCVEffectModifier(rs);
|
||||
break;
|
||||
case Parry:
|
||||
abstractEffectModifier = new ParryEffectModifier(rs);
|
||||
break;
|
||||
case PassiveDefense:
|
||||
abstractEffectModifier = new PassiveDefenseEffectModifier(rs);
|
||||
break;
|
||||
case PowerCost:
|
||||
abstractEffectModifier = new PowerCostEffectModifier(rs);
|
||||
break;
|
||||
case PowerCostHealth:
|
||||
abstractEffectModifier = new PowerCostHealthEffectModifier(rs);
|
||||
break;
|
||||
case PowerDamageModifier:
|
||||
abstractEffectModifier = new PowerDamageEffectModifier(rs);
|
||||
break;
|
||||
case ProtectionFrom:
|
||||
abstractEffectModifier = new ProtectionFromEffectModifier(rs);
|
||||
break;
|
||||
case Resistance:
|
||||
abstractEffectModifier = new ResistanceEffectModifier(rs);
|
||||
break;
|
||||
case ScaleHeight:
|
||||
abstractEffectModifier = new ScaleHeightEffectModifier(rs);
|
||||
break;
|
||||
case ScaleWidth:
|
||||
abstractEffectModifier = new ScaleWidthEffectModifier(rs);
|
||||
break;
|
||||
case ScanRange:
|
||||
abstractEffectModifier = new ScanRangeEffectModifier(rs);
|
||||
break;
|
||||
case SeeInvisible:
|
||||
abstractEffectModifier = new SeeInvisibleEffectModifier(rs);
|
||||
break;
|
||||
case Silenced:
|
||||
abstractEffectModifier = new SilencedEffectModifier(rs);
|
||||
break;
|
||||
case Skill:
|
||||
abstractEffectModifier = new SkillEffectModifier(rs);
|
||||
break;
|
||||
case Slay:
|
||||
abstractEffectModifier = new SlayEffectModifier(rs);
|
||||
break;
|
||||
case Speed:
|
||||
abstractEffectModifier = new SpeedEffectModifier(rs);
|
||||
break;
|
||||
case SpireBlock:
|
||||
abstractEffectModifier = new SpireBlockEffectModifier(rs);
|
||||
break;
|
||||
case Stamina:
|
||||
abstractEffectModifier = new StaminaEffectModifier(rs);
|
||||
break;
|
||||
case StaminaFull:
|
||||
abstractEffectModifier = new StaminaFullEffectModifier(rs);
|
||||
break;
|
||||
case StaminaRecoverRate:
|
||||
abstractEffectModifier = new StaminaRecoverRateEffectModifier(rs);
|
||||
break;
|
||||
case Stunned:
|
||||
abstractEffectModifier = new StunnedEffectModifier(rs);
|
||||
break;
|
||||
case Value:
|
||||
abstractEffectModifier = new ValueEffectModifier(rs);
|
||||
if (effectBase != null) {
|
||||
ValueEffectModifier valueEffect = (ValueEffectModifier) abstractEffectModifier;
|
||||
effectBase.setValue(valueEffect.minMod);
|
||||
}
|
||||
break;
|
||||
case WeaponProc:
|
||||
abstractEffectModifier = new WeaponProcEffectModifier(rs);
|
||||
break;
|
||||
case WeaponRange:
|
||||
abstractEffectModifier = new WeaponRangeEffectModifier(rs);
|
||||
break;
|
||||
case WeaponSpeed:
|
||||
abstractEffectModifier = new WeaponSpeedEffectModifier(rs);
|
||||
break;
|
||||
|
||||
}
|
||||
return abstractEffectModifier;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.EffectsResourceCosts;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class dbEffectsResourceCostHandler extends dbHandlerBase {
|
||||
|
||||
public dbEffectsResourceCostHandler() {
|
||||
this.localClass = EffectsResourceCosts.class;
|
||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public ArrayList<EffectsResourceCosts> GET_ALL_EFFECT_RESOURCES(String idString) {
|
||||
|
||||
ArrayList<EffectsResourceCosts> effectsResourceCosts = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_power_effectcost` WHERE `IDString` = ?")) {
|
||||
|
||||
preparedStatement.setString(1, idString);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
effectsResourceCosts = getObjectsFromRs(rs, 1000);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return effectsResourceCosts;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.server.MBServerStatics;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class dbEnchantmentHandler extends dbHandlerBase {
|
||||
|
||||
public ConcurrentHashMap<String, Integer> GET_ENCHANTMENTS_FOR_ITEM(final int id) {
|
||||
|
||||
ConcurrentHashMap<String, Integer> enchants = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_item_enchantment` WHERE `ItemID`=?;")) {
|
||||
|
||||
preparedStatement.setLong(1, id);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next())
|
||||
enchants.put(rs.getString("powerAction"), rs.getInt("rank"));
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return enchants;
|
||||
}
|
||||
|
||||
public boolean CREATE_ENCHANTMENT_FOR_ITEM(long itemID, String powerAction, int rank) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_item_enchantment` (`itemID`, `powerAction`, `rank`) VALUES (?, ?, ?);")) {
|
||||
|
||||
preparedStatement.setLong(1, itemID);
|
||||
preparedStatement.setString(2, powerAction);
|
||||
preparedStatement.setInt(3, rank);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean CLEAR_ENCHANTMENTS(long itemID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_item_enchantment` WHERE `itemID`=?;")) {
|
||||
|
||||
preparedStatement.setLong(1, itemID);
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,718 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.GuildHistoryType;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.*;
|
||||
import engine.server.world.WorldServer;
|
||||
import org.joda.time.DateTime;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class dbGuildHandler extends dbHandlerBase {
|
||||
|
||||
public dbGuildHandler() {
|
||||
this.localClass = Guild.class;
|
||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public static ArrayList<PlayerCharacter> GET_GUILD_BANISHED(final int id) {
|
||||
|
||||
return new ArrayList<>();
|
||||
|
||||
// Bugfix
|
||||
// prepareCallable("SELECT * FROM `obj_character`, `dyn_guild_banishlist` WHERE `obj_character.char_isActive` = 1 AND `dyn_guild_banishlist.CharacterID` = `obj_character.UID` AND `obj_character.GuildID`=?");
|
||||
|
||||
//prepareCallable("SELECT * FROM `obj_character` `,` `dyn_guild_banishlist` WHERE obj_character.char_isActive = 1 AND dyn_guild_banishlist.CharacterID = obj_character.UID AND dyn_guild_banishlist.GuildID = ?");
|
||||
//setLong(1, (long) id);
|
||||
|
||||
//return getObjectList();
|
||||
}
|
||||
|
||||
public static void LOAD_GUILD_HISTORY_FOR_PLAYER(PlayerCharacter playerCharacter) {
|
||||
|
||||
if (playerCharacter == null)
|
||||
return;
|
||||
|
||||
ArrayList<GuildHistory> guildList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_guild_allianceenemylist` WHERE `GuildID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, playerCharacter.getObjectUUID());
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
GuildHistory guildEntry = new GuildHistory(rs);
|
||||
guildList.add(guildEntry);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
playerCharacter.setGuildHistory(guildList);
|
||||
}
|
||||
|
||||
public int BANISH_FROM_GUILD_OFFLINE(final int target, boolean sourceIsGuildLeader) {
|
||||
|
||||
String queryString;
|
||||
int rowCount;
|
||||
|
||||
// Only a Guild Leader can remove inner council
|
||||
|
||||
if (sourceIsGuildLeader)
|
||||
queryString = "UPDATE `obj_character` SET `guildUID`=NULL, `guild_isInnerCouncil`=0, `guild_isTaxCollector`=0,"
|
||||
+ " `guild_isRecruiter`=0, `guild_isFullMember`=0, `guild_title`=0 WHERE `UID`=?";
|
||||
else
|
||||
queryString = "UPDATE `obj_character` SET `guildUID`=NULL, `guild_isInnerCouncil`=0, `guild_isTaxCollector`=0,"
|
||||
+ " `guild_isRecruiter`=0, `guild_isFullMember`=0, `guild_title`=0 WHERE `UID`=? && `guild_isInnerCouncil`=0";
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement(queryString)) {
|
||||
|
||||
preparedStatement.setLong(1, target);
|
||||
rowCount = preparedStatement.executeUpdate();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return rowCount;
|
||||
}
|
||||
|
||||
public boolean ADD_TO_BANISHED_FROM_GUILDLIST(int target, long characterID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_guild_banishlist` (`GuildID`, `CharacterID`) VALUES (?,?)")) {
|
||||
|
||||
preparedStatement.setLong(1, target);
|
||||
preparedStatement.setLong(2, characterID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean REMOVE_FROM_BANISH_LIST(int target, long characterID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_guild_banishlist` (`GuildID`, `CharacterID`) VALUES (?,?)")) {
|
||||
|
||||
preparedStatement.setLong(1, target);
|
||||
preparedStatement.setLong(2, characterID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean ADD_TO_GUILDHISTORY(int target, PlayerCharacter playerCharacter, DateTime historyDate, GuildHistoryType historyType) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_character_guildhistory` (`GuildID`, `CharacterID`, `historyDate`, `historyType`) VALUES (?,?,?,?)")) {
|
||||
|
||||
preparedStatement.setLong(1, target);
|
||||
preparedStatement.setLong(2, playerCharacter.getObjectUUID());
|
||||
|
||||
if (historyDate == null)
|
||||
preparedStatement.setNull(3, java.sql.Types.DATE);
|
||||
else
|
||||
preparedStatement.setTimestamp(3, new Timestamp(historyDate.getMillis()));
|
||||
|
||||
preparedStatement.setString(4, historyType.name());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//TODO Need to get this working.
|
||||
public ArrayList<Guild> GET_GUILD_HISTORY_OF_PLAYER(final int id) {
|
||||
|
||||
ArrayList<Guild> guildList = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT g.* FROM `obj_guild` g, `dyn_character_guildhistory` l WHERE g.`UID` = l.`GuildID` && l.`CharacterID` = ?")) {
|
||||
|
||||
preparedStatement.setLong(1, id);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
guildList = getObjectsFromRs(rs, 20);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return guildList;
|
||||
}
|
||||
|
||||
public ArrayList<Guild> GET_GUILD_ALLIES(final int id) {
|
||||
|
||||
ArrayList<Guild> guildList = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT g.* FROM `obj_guild` g, `dyn_guild_allianceenemylist` l "
|
||||
+ "WHERE l.isAlliance = 1 && l.OtherGuildID = g.UID && l.GuildID=?")) {
|
||||
|
||||
preparedStatement.setLong(1, id);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
guildList = getObjectsFromRs(rs, 20);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return guildList;
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<Guild> GET_GUILD_ENEMIES(final int id) {
|
||||
|
||||
ArrayList<Guild> guildList = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT g.* FROM `obj_guild` g, `dyn_guild_allianceenemylist` l "
|
||||
+ "WHERE l.isAlliance = 0 && l.OtherGuildID = g.UID && l.GuildID=?")) {
|
||||
|
||||
preparedStatement.setLong(1, id);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
guildList = getObjectsFromRs(rs, 20);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return guildList;
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<PlayerCharacter> GET_GUILD_KOS_CHARACTER(final int id) {
|
||||
|
||||
ArrayList<PlayerCharacter> kosList = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT c.* FROM `obj_character` c, `dyn_guild_characterkoslist` l WHERE c.`char_isActive` = 1 && l.`KOSCharacterID` = c.`UID` && l.`GuildID`=?")) {
|
||||
|
||||
preparedStatement.setLong(1, id);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
int playerUUID = rs.getInt(1);
|
||||
PlayerCharacter kosPlayer = PlayerCharacter.getPlayerCharacter(playerUUID);
|
||||
|
||||
if (kosPlayer != null)
|
||||
kosList.add(kosPlayer);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return kosList;
|
||||
}
|
||||
|
||||
public ArrayList<Guild> GET_GUILD_KOS_GUILD(final int id) {
|
||||
|
||||
ArrayList<Guild> guildList = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT g.* FROM `obj_guild` g, `dyn_guild_guildkoslist` l "
|
||||
+ "WHERE l.KOSGuildID = g.UID && l.GuildID = ?")) {
|
||||
|
||||
preparedStatement.setLong(1, id);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
guildList = getObjectsFromRs(rs, 20);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return guildList;
|
||||
}
|
||||
|
||||
public ArrayList<Guild> GET_SUB_GUILDS(final int guildID) {
|
||||
|
||||
ArrayList<Guild> guildList = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_guild`.*, `object`.`parent` FROM `object` INNER JOIN `obj_guild` ON `obj_guild`.`UID` = `object`.`UID` WHERE `object`.`parent` = ?;")) {
|
||||
|
||||
preparedStatement.setInt(1, guildID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
guildList = getObjectsFromRs(rs, 20);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return guildList;
|
||||
}
|
||||
|
||||
public Guild GET_GUILD(int id) {
|
||||
|
||||
Guild guild = (Guild) DbManager.getFromCache(Enum.GameObjectType.Guild, id);
|
||||
|
||||
if (guild != null)
|
||||
return guild;
|
||||
|
||||
if (id == 0)
|
||||
return Guild.getErrantGuild();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_guild`.*, `object`.`parent` FROM `obj_guild` INNER JOIN `object` ON `object`.`UID` = `obj_guild`.`UID` WHERE `object`.`UID`=?")) {
|
||||
|
||||
preparedStatement.setLong(1, id);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
guild = (Guild) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return guild;
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<Guild> GET_ALL_GUILDS() {
|
||||
|
||||
ArrayList<Guild> guildList = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_guild`.*, `object`.`parent` FROM `obj_guild` INNER JOIN `object` ON `object`.`UID` = `obj_guild`.`UID`")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
guildList = getObjectsFromRs(rs, 100);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return guildList;
|
||||
}
|
||||
|
||||
public boolean IS_CREST_UNIQUE(final GuildTag gt) {
|
||||
|
||||
boolean valid = false;
|
||||
String queryString;
|
||||
|
||||
// Ignore bg symbol if bg color is the same as fg color.
|
||||
|
||||
if (gt.backgroundColor01 == gt.backgroundColor02)
|
||||
queryString = "SELECT `name` FROM `obj_guild` WHERE `backgroundColor01`=? && `backgroundColor02`=? && `symbolColor`=? && `symbol`=?;";
|
||||
else
|
||||
queryString = "SELECT `name` FROM `obj_guild` WHERE `backgroundColor01`=? && `backgroundColor02`=? && `symbolColor`=? && `backgroundDesign`=? && `symbol`=?;";
|
||||
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement(queryString)) {
|
||||
|
||||
if (gt.backgroundColor01 == gt.backgroundColor02) {
|
||||
preparedStatement.setInt(1, gt.backgroundColor01);
|
||||
preparedStatement.setInt(2, gt.backgroundColor02);
|
||||
preparedStatement.setInt(3, gt.symbolColor);
|
||||
preparedStatement.setInt(4, gt.symbol);
|
||||
} else {
|
||||
preparedStatement.setInt(1, gt.backgroundColor01);
|
||||
preparedStatement.setInt(2, gt.backgroundColor02);
|
||||
preparedStatement.setInt(3, gt.symbolColor);
|
||||
preparedStatement.setInt(4, gt.backgroundDesign);
|
||||
preparedStatement.setInt(5, gt.symbol);
|
||||
}
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (!rs.next())
|
||||
valid = true;
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
||||
public boolean SET_GUILD_OWNED_CITY(int guildID, int cityID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_guild` SET `ownedCity`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setLong(1, cityID);
|
||||
preparedStatement.setLong(2, guildID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean SET_GUILD_LEADER(int objectUUID, int guildID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_guild` SET `leaderUID`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setLong(1, objectUUID);
|
||||
preparedStatement.setLong(2, guildID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean IS_NAME_UNIQUE(final String name) {
|
||||
|
||||
boolean valid = false;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `name` FROM `obj_guild` WHERE `name`=?;")) {
|
||||
|
||||
preparedStatement.setString(1, name);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (!rs.next())
|
||||
valid = true;
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
||||
public Guild SAVE_TO_DATABASE(Guild g) {
|
||||
|
||||
Guild guild = null;
|
||||
GuildTag guildTag = g.getGuildTag();
|
||||
|
||||
if (guildTag == null)
|
||||
return null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("CALL `guild_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) {
|
||||
|
||||
preparedStatement.setLong(1, WorldServer.worldUUID);
|
||||
preparedStatement.setLong(2, g.getGuildLeaderUUID());
|
||||
preparedStatement.setString(3, g.getName());
|
||||
preparedStatement.setInt(4, guildTag.backgroundColor01);
|
||||
preparedStatement.setInt(5, guildTag.backgroundColor02);
|
||||
preparedStatement.setInt(6, guildTag.symbolColor);
|
||||
preparedStatement.setInt(7, guildTag.backgroundDesign);
|
||||
preparedStatement.setInt(8, guildTag.symbol);
|
||||
preparedStatement.setInt(9, g.getCharter());
|
||||
preparedStatement.setString(10, g.getLeadershipType());
|
||||
preparedStatement.setString(11, g.getMotto());
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (rs.next()) {
|
||||
int objectUUID = (int) rs.getLong("UID");
|
||||
|
||||
if (objectUUID > 0)
|
||||
guild = GET_GUILD(objectUUID);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return guild;
|
||||
}
|
||||
|
||||
public boolean UPDATE_GUILD_RANK_OFFLINE(int target, int newRank, int guildId) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_title`=? WHERE `UID`=? && `guildUID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, newRank);
|
||||
preparedStatement.setInt(2, target);
|
||||
preparedStatement.setInt(3, guildId);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean UPDATE_PARENT(int guildUID, int parentUID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `object` SET `parent`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, parentUID);
|
||||
preparedStatement.setInt(2, guildUID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int DELETE_GUILD(final Guild guild) {
|
||||
|
||||
int row_count = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `object` WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setLong(1, guild.getObjectUUID());
|
||||
row_count = preparedStatement.executeUpdate();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return row_count;
|
||||
}
|
||||
|
||||
public boolean UPDATE_MINETIME(int guildUID, int mineTime) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_guild` SET `mineTime`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, mineTime);
|
||||
preparedStatement.setInt(2, guildUID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// *** Refactor: Why are we saving tags/charter in update?
|
||||
// It's not like this shit ever changes.
|
||||
|
||||
public int UPDATE_GUILD_STATUS_OFFLINE(int target, boolean isInnerCouncil, boolean isRecruiter, boolean isTaxCollector, int guildId) {
|
||||
|
||||
int updateMask = 0;
|
||||
int row_count = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `guild_isInnerCouncil`, `guild_isTaxCollector`, `guild_isRecruiter` FROM `obj_character` WHERE `UID`=? && `guildUID`=?")) {
|
||||
|
||||
preparedStatement.setLong(1, target);
|
||||
preparedStatement.setLong(2, guildId);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
//If the first query had no results, neither will the second
|
||||
|
||||
//Determine what is different
|
||||
|
||||
if (rs.first()) {
|
||||
if (rs.getBoolean("guild_isInnerCouncil") != isInnerCouncil)
|
||||
updateMask |= 4;
|
||||
if (rs.getBoolean("guild_isRecruiter") != isRecruiter)
|
||||
updateMask |= 2;
|
||||
if (rs.getBoolean("guild_isTaxCollector") != isTaxCollector)
|
||||
updateMask |= 1;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_isInnerCouncil`=?, `guild_isTaxCollector`=?, `guild_isRecruiter`=?, `guild_isFullMember`=? WHERE `UID`=? && `guildUID`=?")) {
|
||||
|
||||
preparedStatement.setBoolean(1, isInnerCouncil);
|
||||
preparedStatement.setBoolean(2, isRecruiter);
|
||||
preparedStatement.setBoolean(3, isTaxCollector);
|
||||
preparedStatement.setBoolean(4, ((updateMask > 0))); //If you are becoming an officer, or where an officer, your a full member...
|
||||
preparedStatement.setLong(5, target);
|
||||
preparedStatement.setLong(6, guildId);
|
||||
|
||||
row_count = preparedStatement.executeUpdate();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return row_count;
|
||||
}
|
||||
|
||||
public boolean updateDatabase(final Guild g) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_guild` SET `name`=?, `backgroundColor01`=?, `backgroundColor02`=?, `symbolColor`=?, `backgroundDesign`=?, `symbol`=?, `charter`=?, `motd`=?, `icMotd`=?, `nationMotd`=?, `leaderUID`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setString(1, g.getName());
|
||||
preparedStatement.setInt(2, g.getGuildTag().backgroundColor01);
|
||||
preparedStatement.setInt(3, g.getGuildTag().backgroundColor02);
|
||||
preparedStatement.setInt(4, g.getGuildTag().symbolColor);
|
||||
preparedStatement.setInt(5, g.getGuildTag().backgroundDesign);
|
||||
preparedStatement.setInt(6, g.getGuildTag().symbol);
|
||||
preparedStatement.setInt(7, g.getCharter());
|
||||
preparedStatement.setString(8, g.getMOTD());
|
||||
preparedStatement.setString(9, g.getICMOTD());
|
||||
preparedStatement.setString(10, "");
|
||||
preparedStatement.setInt(11, g.getGuildLeaderUUID());
|
||||
preparedStatement.setLong(12, g.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean ADD_TO_ALLIANCE_LIST(final long sourceGuildID, final long targetGuildID, boolean isRecommended, boolean isAlly, String recommender) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_guild_allianceenemylist` (`GuildID`, `OtherGuildID`,`isRecommended`, `isAlliance`, `recommender`) VALUES (?,?,?,?,?)")) {
|
||||
|
||||
preparedStatement.setLong(1, sourceGuildID);
|
||||
preparedStatement.setLong(2, targetGuildID);
|
||||
preparedStatement.setBoolean(3, isRecommended);
|
||||
preparedStatement.setBoolean(4, isAlly);
|
||||
preparedStatement.setString(5, recommender);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean REMOVE_FROM_ALLIANCE_LIST(final long sourceGuildID, long targetGuildID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_guild_allianceenemylist` WHERE `GuildID`=? AND `OtherGuildID`=?")) {
|
||||
|
||||
preparedStatement.setLong(1, sourceGuildID);
|
||||
preparedStatement.setLong(2, targetGuildID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean UPDATE_RECOMMENDED(final long sourceGuildID, long targetGuildID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_guild_allianceenemylist` SET `isRecommended` = ? WHERE `GuildID`=? AND `OtherGuildID`=?")) {
|
||||
|
||||
preparedStatement.setLong(1, sourceGuildID);
|
||||
preparedStatement.setLong(2, targetGuildID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean UPDATE_ALLIANCE(final long sourceGuildID, long targetGuildID, boolean isAlly) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_guild_allianceenemylist` SET `isAlliance` = ? WHERE `GuildID`=? AND `OtherGuildID`=?")) {
|
||||
|
||||
preparedStatement.setLong(1, sourceGuildID);
|
||||
preparedStatement.setLong(2, targetGuildID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean UPDATE_ALLIANCE_AND_RECOMMENDED(final long sourceGuildID, long targetGuildID, boolean isAlly) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_guild_allianceenemylist` SET `isRecommended` = ?, `isAlliance` = ? WHERE `GuildID`=? AND `OtherGuildID`=?")) {
|
||||
|
||||
preparedStatement.setByte(1, (byte) 0);
|
||||
preparedStatement.setBoolean(2, isAlly);
|
||||
preparedStatement.setLong(3, sourceGuildID);
|
||||
preparedStatement.setLong(4, targetGuildID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void LOAD_ALL_ALLIANCES_FOR_GUILD(Guild guild) {
|
||||
|
||||
if (guild == null)
|
||||
return;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_guild_allianceenemylist` WHERE `GuildID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, guild.getObjectUUID());
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
GuildAlliances guildAlliance = new GuildAlliances(rs);
|
||||
guild.guildAlliances.put(guildAlliance.getAllianceGuild(), guildAlliance);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
//TODO uncomment this when finished with guild history warehouse integration
|
||||
// public HashMap<Integer, GuildRecord> GET_WAREHOUSE_GUILD_HISTORY(){
|
||||
//
|
||||
// HashMap<Integer, GuildRecord> tempMap = new HashMap<>();
|
||||
// prepareCallable("SELECT * FROM `warehouse_guildhistory` WHERE `eventType` = 'CREATE'");
|
||||
// try {
|
||||
// ResultSet rs = executeQuery();
|
||||
//
|
||||
// while (rs.next()) {
|
||||
// GuildRecord guildRecord = new GuildRecord(rs);
|
||||
// tempMap.put(guildRecord.guildID, guildRecord);
|
||||
// }
|
||||
// }catch (Exception e){
|
||||
// Logger.error(e);
|
||||
// }
|
||||
// return tempMap;
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.gameManager.ConfigManager;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.AbstractGameObject;
|
||||
import engine.objects.AbstractWorldObject;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public abstract class dbHandlerBase {
|
||||
|
||||
protected Class<? extends AbstractGameObject> localClass = null;
|
||||
protected GameObjectType localObjectType;
|
||||
|
||||
protected <T extends AbstractGameObject> AbstractGameObject getObjectFromRs(ResultSet rs) {
|
||||
|
||||
AbstractGameObject abstractGameObject = null;
|
||||
|
||||
try {
|
||||
if (rs.next()) {
|
||||
abstractGameObject = localClass.getConstructor(ResultSet.class).newInstance(rs);
|
||||
|
||||
DbManager.addToCache(abstractGameObject);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
// Only call runAfterLoad() for objects instanced on the world server
|
||||
|
||||
if ((abstractGameObject != null && abstractGameObject instanceof AbstractWorldObject) &&
|
||||
(ConfigManager.serverType.equals(Enum.ServerType.WORLDSERVER) ||
|
||||
(abstractGameObject.getObjectType() == GameObjectType.Guild)))
|
||||
((AbstractWorldObject) abstractGameObject).runAfterLoad();
|
||||
|
||||
return abstractGameObject;
|
||||
}
|
||||
|
||||
protected <T extends AbstractGameObject> ArrayList<T> getObjectsFromRs(ResultSet rs, int listSize) {
|
||||
|
||||
ArrayList<T> objectList = new ArrayList<>(listSize);
|
||||
|
||||
try {
|
||||
while (rs.next()) {
|
||||
|
||||
int id = rs.getInt(1);
|
||||
|
||||
if (DbManager.inCache(localObjectType, id)) {
|
||||
objectList.add((T) DbManager.getFromCache(localObjectType, id));
|
||||
} else {
|
||||
AbstractGameObject toAdd = localClass.getConstructor(ResultSet.class).newInstance(rs);
|
||||
DbManager.addToCache(toAdd);
|
||||
objectList.add((T) toAdd);
|
||||
|
||||
if (toAdd != null && toAdd instanceof AbstractWorldObject)
|
||||
((AbstractWorldObject) toAdd).runAfterLoad();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return objectList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.InterestManagement.HeightMap;
|
||||
import engine.gameManager.DbManager;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class dbHeightMapHandler extends dbHandlerBase {
|
||||
|
||||
public dbHeightMapHandler() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void LOAD_ALL_HEIGHTMAPS() {
|
||||
|
||||
HeightMap thisHeightmap;
|
||||
HeightMap.heightMapsCreated = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_zone_heightmap INNER JOIN static_zone_size ON static_zone_size.loadNum = static_zone_heightmap.zoneLoadID")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
thisHeightmap = new HeightMap(rs);
|
||||
|
||||
if (thisHeightmap.getHeightmapImage() == null) {
|
||||
Logger.info("Imagemap for " + thisHeightmap.getHeightMapID() + " was null");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.ItemBase;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class dbItemBaseHandler extends dbHandlerBase {
|
||||
|
||||
public dbItemBaseHandler() {
|
||||
|
||||
}
|
||||
|
||||
public void LOAD_BAKEDINSTATS(ItemBase itemBase) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_item_bakedinstat` WHERE `itemID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, itemBase.getUUID());
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
if (rs.getBoolean("fromUse"))
|
||||
itemBase.getUsedStats().put(rs.getInt("token"), rs.getInt("numTrains"));
|
||||
else
|
||||
itemBase.getBakedInStats().put(rs.getInt("token"), rs.getInt("numTrains"));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void LOAD_ANIMATIONS(ItemBase itemBase) {
|
||||
|
||||
ArrayList<Integer> tempList = new ArrayList<>();
|
||||
ArrayList<Integer> tempListOff = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_itembase_animations` WHERE `itemBaseUUID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, itemBase.getUUID());
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
int animation = rs.getInt("animation");
|
||||
boolean rightHand = rs.getBoolean("rightHand");
|
||||
|
||||
if (rightHand)
|
||||
tempList.add(animation);
|
||||
else
|
||||
tempListOff.add(animation);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
itemBase.setAnimations(tempList);
|
||||
itemBase.setOffHandAnimations(tempListOff);
|
||||
}
|
||||
|
||||
public void LOAD_ALL_ITEMBASES() {
|
||||
|
||||
ItemBase itemBase;
|
||||
int recordsRead = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_itembase")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
recordsRead++;
|
||||
itemBase = new ItemBase(rs);
|
||||
ItemBase.addToCache(itemBase);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
Logger.info("read: " + recordsRead + " cached: " + ItemBase.getUUIDCache().size());
|
||||
}
|
||||
|
||||
public HashMap<Integer, ArrayList<Integer>> LOAD_RUNES_FOR_NPC_AND_MOBS() {
|
||||
|
||||
HashMap<Integer, ArrayList<Integer>> runeSets = new HashMap<>();
|
||||
int runeSetID;
|
||||
int runeBaseID;
|
||||
int recordsRead = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_npc_runeSet")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
recordsRead++;
|
||||
|
||||
runeSetID = rs.getInt("runeSet");
|
||||
runeBaseID = rs.getInt("runeBase");
|
||||
|
||||
if (runeSets.get(runeSetID) == null) {
|
||||
ArrayList<Integer> runeList = new ArrayList<>();
|
||||
runeList.add(runeBaseID);
|
||||
runeSets.put(runeSetID, runeList);
|
||||
} else {
|
||||
ArrayList<Integer> runeList = runeSets.get(runeSetID);
|
||||
runeList.add(runeSetID);
|
||||
runeSets.put(runeSetID, runeList);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return runeSets;
|
||||
}
|
||||
|
||||
Logger.info("read: " + recordsRead + " cached: " + runeSets.size());
|
||||
return runeSets;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,499 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum.ItemContainerType;
|
||||
import engine.Enum.ItemType;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.AbstractCharacter;
|
||||
import engine.objects.CharacterItemManager;
|
||||
import engine.objects.Item;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
||||
|
||||
public class dbItemHandler extends dbHandlerBase {
|
||||
|
||||
public dbItemHandler() {
|
||||
this.localClass = Item.class;
|
||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
private static String formatTradeString(HashSet<Integer> list) {
|
||||
int size = list.size();
|
||||
|
||||
String ret = "";
|
||||
|
||||
if (size == 0)
|
||||
return ret;
|
||||
|
||||
boolean start = true;
|
||||
|
||||
for (int i : list) {
|
||||
if (start) {
|
||||
ret += i;
|
||||
start = false;
|
||||
} else
|
||||
ret += "," + i;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Item ADD_ITEM(Item toAdd) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("CALL `item_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?,?);")) {
|
||||
|
||||
preparedStatement.setInt(1, toAdd.getOwnerID());
|
||||
preparedStatement.setInt(2, toAdd.getItemBaseID());
|
||||
preparedStatement.setInt(3, toAdd.getChargesRemaining());
|
||||
preparedStatement.setInt(4, toAdd.getDurabilityCurrent());
|
||||
preparedStatement.setInt(5, toAdd.getDurabilityMax());
|
||||
|
||||
if (toAdd.getNumOfItems() < 1)
|
||||
preparedStatement.setInt(6, 1);
|
||||
else
|
||||
preparedStatement.setInt(6, toAdd.getNumOfItems());
|
||||
|
||||
switch (toAdd.containerType) {
|
||||
case INVENTORY:
|
||||
preparedStatement.setString(7, "inventory");
|
||||
break;
|
||||
case EQUIPPED:
|
||||
preparedStatement.setString(7, "equip");
|
||||
break;
|
||||
case BANK:
|
||||
preparedStatement.setString(7, "bank");
|
||||
break;
|
||||
case VAULT:
|
||||
preparedStatement.setString(7, "vault");
|
||||
break;
|
||||
case FORGE:
|
||||
preparedStatement.setString(7, "forge");
|
||||
break;
|
||||
default:
|
||||
preparedStatement.setString(7, "none"); //Shouldn't be here
|
||||
break;
|
||||
}
|
||||
|
||||
preparedStatement.setByte(8, toAdd.getEquipSlot());
|
||||
preparedStatement.setInt(9, toAdd.getFlags());
|
||||
preparedStatement.setString(10, toAdd.getCustomName());
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (rs.next()) {
|
||||
int objectUUID = (int) rs.getLong("UID");
|
||||
|
||||
if (objectUUID > 0)
|
||||
return GET_ITEM(objectUUID);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean DO_TRADE(HashSet<Integer> from1, HashSet<Integer> from2,
|
||||
CharacterItemManager man1, CharacterItemManager man2,
|
||||
Item inventoryGold1, Item inventoryGold2, int goldFrom1, int goldFrom2) {
|
||||
|
||||
AbstractCharacter ac1 = man1.getOwner();
|
||||
AbstractCharacter ac2 = man2.getOwner();
|
||||
boolean worked = false;
|
||||
|
||||
if (ac1 == null || ac2 == null || inventoryGold1 == null || inventoryGold2 == null)
|
||||
return false;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("CALL `item_TRADE`(?, ?, ?, ?, ?, ?, ?, ?)")) {
|
||||
|
||||
preparedStatement.setString(1, formatTradeString(from1));
|
||||
preparedStatement.setLong(2, ac1.getObjectUUID());
|
||||
preparedStatement.setString(3, formatTradeString(from2));
|
||||
preparedStatement.setLong(4, ac2.getObjectUUID());
|
||||
preparedStatement.setInt(5, goldFrom1);
|
||||
preparedStatement.setLong(6, inventoryGold1.getObjectUUID());
|
||||
preparedStatement.setInt(7, goldFrom2);
|
||||
preparedStatement.setLong(8, inventoryGold2.getObjectUUID());
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (rs.next())
|
||||
worked = rs.getBoolean("result");
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return worked;
|
||||
}
|
||||
|
||||
public ArrayList<Item> GET_EQUIPPED_ITEMS(final int targetId) {
|
||||
|
||||
ArrayList<Item> itemList;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_item`.*, `object`.`parent`, `object`.`type` FROM `object` INNER JOIN `obj_item` ON `object`.`UID` = `obj_item`.`UID` WHERE `object`.`parent`=? && `obj_item`.`item_container`='equip';")) {
|
||||
|
||||
preparedStatement.setLong(1, targetId);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
itemList = getObjectsFromRs(rs, 10);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return null;
|
||||
}
|
||||
|
||||
return itemList;
|
||||
}
|
||||
|
||||
public Item GET_ITEM(final int itemUUID) {
|
||||
|
||||
Item item;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_item`.*, `object`.`parent`, `object`.`type` FROM `object` INNER JOIN `obj_item` ON `object`.`UID` = `obj_item`.`UID` WHERE `object`.`UID`=?;")) {
|
||||
|
||||
preparedStatement.setLong(1, itemUUID);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
item = (Item) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return null;
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
public ArrayList<Item> GET_ITEMS_FOR_ACCOUNT(final int accountId) {
|
||||
|
||||
ArrayList<Item> itemList;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_item`.*, `object`.`parent`, `object`.`type` FROM `object` INNER JOIN `obj_item` ON `object`.`UID` = `obj_item`.`UID` WHERE `object`.`parent`=?;")) {
|
||||
|
||||
preparedStatement.setLong(1, accountId);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
itemList = getObjectsFromRs(rs, 100);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return null;
|
||||
}
|
||||
return itemList;
|
||||
}
|
||||
|
||||
public ArrayList<Item> GET_ITEMS_FOR_NPC(final int npcId) {
|
||||
|
||||
ArrayList<Item> itemList;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_item`.*, `object`.`parent`, `object`.`type` FROM `object` INNER JOIN `obj_item` ON `object`.`UID` = `obj_item`.`UID` WHERE `object`.`parent`=?;")) {
|
||||
|
||||
preparedStatement.setLong(1, npcId);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
itemList = getObjectsFromRs(rs, 20);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return null;
|
||||
}
|
||||
return itemList;
|
||||
}
|
||||
|
||||
public ArrayList<Item> GET_ITEMS_FOR_PC(final int id) {
|
||||
|
||||
ArrayList<Item> itemList;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_item`.*, `object`.`parent`, `object`.`type` FROM `object` INNER JOIN `obj_item` ON `object`.`UID` = `obj_item`.`UID` WHERE `object`.`parent`=?")) {
|
||||
|
||||
preparedStatement.setLong(1, id);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
itemList = getObjectsFromRs(rs, 100);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return null;
|
||||
}
|
||||
return itemList;
|
||||
}
|
||||
|
||||
public boolean MOVE_GOLD(final Item from, final Item to, final int amt) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_numberOfItems` = CASE WHEN `UID`=? THEN ? WHEN `UID`=? THEN ? END WHERE `UID` IN (?, ?);")) {
|
||||
|
||||
int newFromAmt = from.getNumOfItems() - amt;
|
||||
int newToAmt = to.getNumOfItems() + amt;
|
||||
|
||||
preparedStatement.setLong(1, from.getObjectUUID());
|
||||
preparedStatement.setInt(2, newFromAmt);
|
||||
preparedStatement.setLong(3, to.getObjectUUID());
|
||||
preparedStatement.setInt(4, newToAmt);
|
||||
preparedStatement.setLong(5, from.getObjectUUID());
|
||||
preparedStatement.setLong(6, to.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean ORPHAN_INVENTORY(final HashSet<Item> inventory) {
|
||||
|
||||
boolean worked = true;
|
||||
|
||||
for (Item item : inventory) {
|
||||
|
||||
if (item.getItemBase().getType().equals(ItemType.GOLD))
|
||||
continue;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` LEFT JOIN `object` ON `object`.`UID` = `obj_item`.`UID` SET `object`.`parent`=NULL, `obj_item`.`item_container`='none' WHERE `object`.`UID`=?;")) {
|
||||
|
||||
preparedStatement.setLong(1, item.getObjectUUID());
|
||||
worked = (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
if (worked)
|
||||
item.zeroItem();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return worked;
|
||||
}
|
||||
|
||||
public HashSet<Integer> GET_ITEMS_FOR_VENDOR(final int vendorID) {
|
||||
|
||||
HashSet<Integer> itemSet = new HashSet<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT ID FROM static_itembase WHERE vendorType = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, vendorID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next())
|
||||
itemSet.add(rs.getInt(1));
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return itemSet;
|
||||
}
|
||||
|
||||
return itemSet;
|
||||
}
|
||||
|
||||
//Used to transfer a single item between owners or equip or vault or bank or inventory
|
||||
public boolean UPDATE_OWNER(final Item item, int newOwnerID, boolean ownerNPC, boolean ownerPlayer,
|
||||
boolean ownerAccount, ItemContainerType containerType, int slot) {
|
||||
|
||||
boolean worked = false;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("CALL `item_TRANSFER_OWNER`(?, ?, ?, ? )")) {
|
||||
|
||||
preparedStatement.setLong(1, item.getObjectUUID());
|
||||
|
||||
if (newOwnerID != 0)
|
||||
preparedStatement.setLong(2, newOwnerID);
|
||||
else
|
||||
preparedStatement.setNull(2, java.sql.Types.BIGINT);
|
||||
|
||||
switch (containerType) {
|
||||
case INVENTORY:
|
||||
preparedStatement.setString(3, "inventory");
|
||||
break;
|
||||
case EQUIPPED:
|
||||
preparedStatement.setString(3, "equip");
|
||||
break;
|
||||
case BANK:
|
||||
preparedStatement.setString(3, "bank");
|
||||
break;
|
||||
case VAULT:
|
||||
preparedStatement.setString(3, "vault");
|
||||
break;
|
||||
case FORGE:
|
||||
preparedStatement.setString(3, "forge");
|
||||
break;
|
||||
default:
|
||||
preparedStatement.setString(3, "none"); //Shouldn't be here
|
||||
break;
|
||||
}
|
||||
preparedStatement.setInt(4, slot);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (rs.next())
|
||||
worked = rs.getBoolean("result");
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
return worked;
|
||||
}
|
||||
|
||||
public boolean SET_DURABILITY(final Item item, int value) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_durabilityCurrent`=? WHERE `UID`=? AND `item_durabilityCurrent`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, value);
|
||||
preparedStatement.setLong(2, item.getObjectUUID());
|
||||
preparedStatement.setInt(3, item.getDurabilityCurrent());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean UPDATE_FORGE_TO_INVENTORY(final Item item) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_container` = ? WHERE `UID` = ? AND `item_container` = 'forge';")) {
|
||||
|
||||
preparedStatement.setString(1, "inventory");
|
||||
preparedStatement.setLong(2, item.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to update the quantity of this gold item
|
||||
*
|
||||
* @param value New quantity of gold
|
||||
* @return True on success
|
||||
*/
|
||||
public boolean UPDATE_GOLD(final Item item, int value) {
|
||||
if (item == null)
|
||||
return false;
|
||||
return UPDATE_GOLD(item, value, item.getNumOfItems());
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to update the quantity of this gold item using CAS
|
||||
*
|
||||
* @return True on success
|
||||
*/
|
||||
public boolean UPDATE_GOLD(final Item item, int newValue, int oldValue) {
|
||||
|
||||
if (!item.getItemBase().getType().equals(ItemType.GOLD))
|
||||
return false;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_numberOfItems`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, newValue);
|
||||
preparedStatement.setLong(2, item.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean UPDATE_REMAINING_CHARGES(final Item item) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_chargesRemaining` = ? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, item.getChargesRemaining());
|
||||
preparedStatement.setLong(2, item.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// This is necessary because default number of items is 1.
|
||||
// When we create gold, we want it to start at 0 quantity.
|
||||
|
||||
public boolean ZERO_ITEM_STACK(Item item) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_numberOfItems`=0 WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setLong(1, item.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean UPDATE_FLAGS(Item item) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_flags`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, item.getFlags());
|
||||
preparedStatement.setLong(2, item.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean UPDATE_VALUE(Item item, int value) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_value`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, value);
|
||||
preparedStatement.setLong(2, item.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.Kit;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class dbKitHandler extends dbHandlerBase {
|
||||
|
||||
public dbKitHandler() {
|
||||
this.localClass = Kit.class;
|
||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public ArrayList<Kit> GET_ALL_KITS() {
|
||||
|
||||
ArrayList<Kit> kitList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_validkit`")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
kitList = getObjectsFromRs(rs, 20);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return kitList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,240 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.loot.*;
|
||||
import engine.objects.Item;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class dbLootHandler extends dbHandlerBase {
|
||||
|
||||
public dbLootHandler() {
|
||||
|
||||
}
|
||||
|
||||
public HashMap<Integer, ArrayList<GenTableEntry>> LOAD_GEN_ITEM_TABLES() {
|
||||
|
||||
HashMap<Integer, ArrayList<GenTableEntry>> genTables = new HashMap<>();
|
||||
GenTableEntry genTableEntry;
|
||||
|
||||
int genTableID;
|
||||
int recordsRead = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_loot_gen`")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
recordsRead++;
|
||||
|
||||
genTableID = rs.getInt("genTable");
|
||||
genTableEntry = new GenTableEntry(rs);
|
||||
|
||||
if (genTables.get(genTableID) == null) {
|
||||
ArrayList<GenTableEntry> genItemList = new ArrayList<>();
|
||||
genItemList.add(genTableEntry);
|
||||
genTables.put(genTableID, genItemList);
|
||||
} else {
|
||||
ArrayList<GenTableEntry> genItemList = genTables.get(genTableID);
|
||||
genItemList.add(genTableEntry);
|
||||
genTables.put(genTableID, genItemList);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return genTables;
|
||||
}
|
||||
|
||||
Logger.info("read: " + recordsRead + " cached: " + genTables.size());
|
||||
return genTables;
|
||||
}
|
||||
|
||||
public HashMap<Integer, ArrayList<ItemTableEntry>> LOAD_ITEM_TABLES() {
|
||||
|
||||
HashMap<Integer, ArrayList<ItemTableEntry>> itemTables = new HashMap<>();
|
||||
ItemTableEntry itemTableEntry;
|
||||
|
||||
int itemTableID;
|
||||
int recordsRead = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_loot_item`")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
recordsRead++;
|
||||
|
||||
itemTableID = rs.getInt("itemTable");
|
||||
itemTableEntry = new ItemTableEntry(rs);
|
||||
|
||||
if (itemTables.get(itemTableID) == null) {
|
||||
ArrayList<ItemTableEntry> itemTableList = new ArrayList<>();
|
||||
itemTableList.add(itemTableEntry);
|
||||
itemTables.put(itemTableID, itemTableList);
|
||||
} else {
|
||||
ArrayList<ItemTableEntry> itemTableList = itemTables.get(itemTableID);
|
||||
itemTableList.add(itemTableEntry);
|
||||
itemTables.put(itemTableID, itemTableList);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return itemTables;
|
||||
}
|
||||
|
||||
Logger.info("read: " + recordsRead + " cached: " + itemTables.size());
|
||||
return itemTables;
|
||||
}
|
||||
|
||||
public HashMap<Integer, ArrayList<ModTableEntry>> LOAD_MOD_TABLES() {
|
||||
|
||||
HashMap<Integer, ArrayList<ModTableEntry>> modTables = new HashMap<>();
|
||||
ModTableEntry modTableEntry;
|
||||
|
||||
int modTableID;
|
||||
int recordsRead = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_loot_mod`")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
recordsRead++;
|
||||
|
||||
modTableID = rs.getInt("modTable");
|
||||
modTableEntry = new ModTableEntry(rs);
|
||||
|
||||
if (modTables.get(modTableID) == null) {
|
||||
ArrayList<ModTableEntry> modTableList = new ArrayList<>();
|
||||
modTableList.add(modTableEntry);
|
||||
modTables.put(modTableID, modTableList);
|
||||
} else {
|
||||
ArrayList<ModTableEntry> modTableList = modTables.get(modTableID);
|
||||
modTableList.add(modTableEntry);
|
||||
modTables.put(modTableID, modTableList);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return modTables;
|
||||
}
|
||||
|
||||
Logger.info("read: " + recordsRead + " cached: " + modTables.size());
|
||||
return modTables;
|
||||
}
|
||||
|
||||
public HashMap<Integer, ArrayList<ModTypeTableEntry>> LOAD_MOD_TYPE_TABLES() {
|
||||
|
||||
HashMap<Integer, ArrayList<ModTypeTableEntry>> modTypeTables = new HashMap<>();
|
||||
ModTypeTableEntry modTypeTableEntry;
|
||||
|
||||
int modTableID;
|
||||
int recordsRead = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_loot_modtype`")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
recordsRead++;
|
||||
|
||||
modTableID = rs.getInt("modType");
|
||||
modTypeTableEntry = new ModTypeTableEntry(rs);
|
||||
|
||||
if (modTypeTables.get(modTableID) == null) {
|
||||
ArrayList<ModTypeTableEntry> modTypeTableList = new ArrayList<>();
|
||||
modTypeTableList.add(modTypeTableEntry);
|
||||
modTypeTables.put(modTableID, modTypeTableList);
|
||||
} else {
|
||||
ArrayList<ModTypeTableEntry> modTypeTableList = modTypeTables.get(modTableID);
|
||||
modTypeTableList.add(modTypeTableEntry);
|
||||
modTypeTables.put(modTableID, modTypeTableList);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return modTypeTables;
|
||||
}
|
||||
|
||||
Logger.info("read: " + recordsRead + " cached: " + modTypeTables.size());
|
||||
return modTypeTables;
|
||||
}
|
||||
|
||||
public HashMap<Integer, ArrayList<BootySetEntry>> LOAD_BOOTY_TABLES() {
|
||||
|
||||
HashMap<Integer, ArrayList<BootySetEntry>> bootySets = new HashMap<>();
|
||||
BootySetEntry bootySetEntry;
|
||||
int bootySetID;
|
||||
int recordsRead = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_loot_bootySet")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
recordsRead++;
|
||||
|
||||
bootySetID = rs.getInt("bootySet");
|
||||
bootySetEntry = new BootySetEntry(rs);
|
||||
|
||||
if (bootySets.get(bootySetID) == null) {
|
||||
ArrayList<BootySetEntry> bootyList = new ArrayList<>();
|
||||
bootyList.add(bootySetEntry);
|
||||
bootySets.put(bootySetID, bootyList);
|
||||
} else {
|
||||
ArrayList<BootySetEntry> bootyList = bootySets.get(bootySetID);
|
||||
bootyList.add(bootySetEntry);
|
||||
bootySets.put(bootySetID, bootyList);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return bootySets;
|
||||
}
|
||||
|
||||
Logger.info("read: " + recordsRead + " cached: " + bootySets.size());
|
||||
return bootySets;
|
||||
}
|
||||
|
||||
public void LOAD_ENCHANT_VALUES() {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `IDString`, `minMod` FROM `static_power_effectmod` WHERE `modType` = ?")) {
|
||||
|
||||
preparedStatement.setString(1, "Value");
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next())
|
||||
Item.addEnchantValue(rs.getString("IDString"), rs.getInt("minMod"));
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.MenuOption;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class dbMenuHandler extends dbHandlerBase {
|
||||
|
||||
public dbMenuHandler() {
|
||||
this.localClass = MenuOption.class;
|
||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public ArrayList<MenuOption> GET_MENU_OPTIONS(final int id) {
|
||||
|
||||
ArrayList<MenuOption> menuOptions = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_menuoption` WHERE menuID = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, id);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
menuOptions = getObjectsFromRs(rs, 1000);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return menuOptions;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.Mine;
|
||||
import engine.objects.MineProduction;
|
||||
import engine.objects.Resource;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class dbMineHandler extends dbHandlerBase {
|
||||
|
||||
public dbMineHandler() {
|
||||
this.localClass = Mine.class;
|
||||
this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public Mine GET_MINE(int id) {
|
||||
|
||||
if (id == 0)
|
||||
return null;
|
||||
|
||||
Mine mine = (Mine) DbManager.getFromCache(Enum.GameObjectType.Mine, id);
|
||||
|
||||
if (mine != null)
|
||||
return mine;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_building`.*, `object`.`parent` FROM `object` INNER JOIN `obj_building` ON `obj_building`.`UID` = `object`.`UID` WHERE `object`.`UID` = ?;")) {
|
||||
|
||||
preparedStatement.setLong(1, id);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
mine = (Mine) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return mine;
|
||||
}
|
||||
|
||||
public ArrayList<Mine> GET_ALL_MINES_FOR_SERVER() {
|
||||
|
||||
ArrayList<Mine> mines = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_mine`.*, `object`.`parent` FROM `object` INNER JOIN `obj_mine` ON `obj_mine`.`UID` = `object`.`UID`")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
mines = getObjectsFromRs(rs, 1000);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return mines;
|
||||
}
|
||||
|
||||
public boolean CHANGE_OWNER(Mine mine, int playerUID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_mine` SET `mine_ownerUID`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, playerUID);
|
||||
preparedStatement.setLong(2, mine.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean CHANGE_RESOURCE(Mine mine, Resource resource) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_mine` SET `mine_resource`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setString(1, resource.name());
|
||||
preparedStatement.setLong(2, mine.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean CHANGE_TYPE(Mine mine, MineProduction productionType) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_mine` SET `mine_type`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setString(1, productionType.name());
|
||||
preparedStatement.setLong(2, mine.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean SET_FLAGS(Mine mine, int newFlags) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_mine` SET `flags`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, newFlags);
|
||||
preparedStatement.setLong(2, mine.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.MobBase;
|
||||
import engine.objects.MobBaseEffects;
|
||||
import engine.objects.MobBaseStats;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class dbMobBaseHandler extends dbHandlerBase {
|
||||
|
||||
public dbMobBaseHandler() {
|
||||
this.localClass = MobBase.class;
|
||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public MobBase GET_MOBBASE(int id) {
|
||||
|
||||
if (id == 0)
|
||||
return null;
|
||||
|
||||
MobBase mobBase = (MobBase) DbManager.getFromCache(GameObjectType.MobBase, id);
|
||||
|
||||
if (mobBase != null)
|
||||
return mobBase;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mobbase` WHERE `ID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, id);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
mobBase = (MobBase) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return mobBase;
|
||||
}
|
||||
|
||||
|
||||
public ArrayList<MobBase> GET_ALL_MOBBASES() {
|
||||
|
||||
ArrayList<MobBase> mobbaseList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mobbase`;")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
mobbaseList = getObjectsFromRs(rs, 1000);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return mobbaseList;
|
||||
}
|
||||
|
||||
public ArrayList<MobBaseEffects> GET_RUNEBASE_EFFECTS(int runeID) {
|
||||
|
||||
ArrayList<MobBaseEffects> effectsList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mobbase_effects` WHERE `mobbaseUUID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, runeID);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
MobBaseEffects mbs = new MobBaseEffects(rs);
|
||||
effectsList.add(mbs);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return effectsList;
|
||||
}
|
||||
|
||||
public MobBaseStats LOAD_STATS(int mobBaseUUID) {
|
||||
|
||||
MobBaseStats mobBaseStats = MobBaseStats.GetGenericStats();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mobbase_stats` WHERE `mobbaseUUID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, mobBaseUUID);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next())
|
||||
mobBaseStats = new MobBaseStats(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return mobBaseStats;
|
||||
}
|
||||
|
||||
public void LOAD_ALL_MOBBASE_SPEEDS(MobBase mobBase) {
|
||||
|
||||
if (mobBase.getLoadID() == 0)
|
||||
return;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mobbase_race` WHERE `mobbaseID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, mobBase.getLoadID());
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
float walk = rs.getFloat("walkStandard");
|
||||
float walkCombat = rs.getFloat("walkCombat");
|
||||
float run = rs.getFloat("runStandard");
|
||||
float runCombat = rs.getFloat("runCombat");
|
||||
mobBase.updateSpeeds(walk, walkCombat, run, runCombat);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,250 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.Mob;
|
||||
import engine.objects.Zone;
|
||||
import org.joda.time.DateTime;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class dbMobHandler extends dbHandlerBase {
|
||||
|
||||
public dbMobHandler() {
|
||||
this.localClass = Mob.class;
|
||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public Mob ADD_MOB(Mob toAdd) {
|
||||
|
||||
Mob mobile = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("CALL `mob_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);")) {
|
||||
|
||||
preparedStatement.setLong(1, toAdd.getParentZoneID());
|
||||
preparedStatement.setInt(2, toAdd.getMobBaseID());
|
||||
preparedStatement.setInt(3, toAdd.getGuildUUID());
|
||||
preparedStatement.setFloat(4, toAdd.getSpawnX());
|
||||
preparedStatement.setFloat(5, toAdd.getSpawnY());
|
||||
preparedStatement.setFloat(6, toAdd.getSpawnZ());
|
||||
preparedStatement.setInt(7, 0);
|
||||
preparedStatement.setFloat(8, toAdd.getSpawnRadius());
|
||||
preparedStatement.setInt(9, toAdd.getTrueSpawnTime());
|
||||
|
||||
if (toAdd.getContract() != null)
|
||||
preparedStatement.setInt(10, toAdd.getContract().getContractID());
|
||||
else
|
||||
preparedStatement.setInt(10, 0);
|
||||
|
||||
preparedStatement.setInt(11, toAdd.getBuildingID());
|
||||
preparedStatement.setInt(12, toAdd.getLevel());
|
||||
preparedStatement.setString(13, toAdd.getFirstName());
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (rs.next()) {
|
||||
int objectUUID = (int) rs.getLong("UID");
|
||||
|
||||
if (objectUUID > 0)
|
||||
mobile = GET_MOB(objectUUID);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return mobile;
|
||||
}
|
||||
|
||||
public boolean updateUpgradeTime(Mob mob, DateTime upgradeDateTime) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE obj_mob SET upgradeDate=? "
|
||||
+ "WHERE UID = ?")) {
|
||||
|
||||
if (upgradeDateTime == null)
|
||||
preparedStatement.setNull(1, java.sql.Types.DATE);
|
||||
else
|
||||
preparedStatement.setTimestamp(1, new java.sql.Timestamp(upgradeDateTime.getMillis()));
|
||||
|
||||
preparedStatement.setInt(2, mob.getObjectUUID());
|
||||
|
||||
preparedStatement.execute();
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int DELETE_MOB(final Mob mob) {
|
||||
|
||||
int row_count = 0;
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `object` WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setLong(1, mob.getDBID());
|
||||
row_count = preparedStatement.executeUpdate();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
|
||||
}
|
||||
return row_count;
|
||||
}
|
||||
|
||||
public void LOAD_PATROL_POINTS(Mob captain) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_guards` WHERE `captainUID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, captain.getObjectUUID());
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
String name = rs.getString("name");
|
||||
Mob toCreate = Mob.createGuardMob(captain, captain.getGuild(), captain.getParentZone(), captain.building.getLoc(), captain.getLevel(), name);
|
||||
|
||||
if (toCreate == null)
|
||||
return;
|
||||
|
||||
if (toCreate != null)
|
||||
toCreate.setDeathTime(System.currentTimeMillis());
|
||||
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean ADD_TO_GUARDS(final long captainUID, final int mobBaseID, final String name, final int slot) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_guards` (`captainUID`, `mobBaseID`,`name`, `slot`) VALUES (?,?,?,?)")) {
|
||||
|
||||
preparedStatement.setLong(1, captainUID);
|
||||
preparedStatement.setInt(2, mobBaseID);
|
||||
preparedStatement.setString(3, name);
|
||||
preparedStatement.setInt(4, slot);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean REMOVE_FROM_GUARDS(final long captainUID, final int mobBaseID, final int slot) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_guards` WHERE `captainUID`=? AND `mobBaseID`=? AND `slot` =?")) {
|
||||
|
||||
preparedStatement.setLong(1, captainUID);
|
||||
preparedStatement.setInt(2, mobBaseID);
|
||||
preparedStatement.setInt(3, slot);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ArrayList<Mob> GET_ALL_MOBS_FOR_ZONE(Zone zone) {
|
||||
|
||||
ArrayList<Mob> mobileList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_mob`.*, `object`.`parent` FROM `object` INNER JOIN `obj_mob` ON `obj_mob`.`UID` = `object`.`UID` WHERE `object`.`parent` = ?;")) {
|
||||
|
||||
preparedStatement.setLong(1, zone.getObjectUUID());
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
mobileList = getObjectsFromRs(rs, 1000);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return mobileList;
|
||||
}
|
||||
|
||||
public Mob GET_MOB(final int objectUUID) {
|
||||
|
||||
Mob mobile = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_mob`.*, `object`.`parent` FROM `object` INNER JOIN `obj_mob` ON `obj_mob`.`UID` = `object`.`UID` WHERE `object`.`UID` = ?;")) {
|
||||
|
||||
preparedStatement.setLong(1, objectUUID);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
mobile = (Mob) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return mobile;
|
||||
}
|
||||
|
||||
public int MOVE_MOB(long mobID, long parentID, float locX, float locY, float locZ) {
|
||||
|
||||
int row_count = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `object` INNER JOIN `obj_mob` On `object`.`UID` = `obj_mob`.`UID` SET `object`.`parent`=?, `obj_mob`.`mob_spawnX`=?, `obj_mob`.`mob_spawnY`=?, `obj_mob`.`mob_spawnZ`=? WHERE `obj_mob`.`UID`=?;")) {
|
||||
|
||||
preparedStatement.setLong(1, parentID);
|
||||
preparedStatement.setFloat(2, locX);
|
||||
preparedStatement.setFloat(3, locY);
|
||||
preparedStatement.setFloat(4, locZ);
|
||||
preparedStatement.setLong(5, mobID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
row_count = preparedStatement.executeUpdate();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return row_count;
|
||||
}
|
||||
|
||||
public String SET_PROPERTY(final Mob m, String name, Object new_value) {
|
||||
|
||||
String result = "";
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("CALL mob_SETPROP(?,?,?)")) {
|
||||
|
||||
preparedStatement.setLong(1, m.getObjectUUID());
|
||||
preparedStatement.setString(2, name);
|
||||
preparedStatement.setString(3, String.valueOf(new_value));
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (rs.next())
|
||||
result = rs.getString("result");
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,470 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum.ProfitType;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.math.Vector3fImmutable;
|
||||
import engine.objects.NPC;
|
||||
import engine.objects.NPCProfits;
|
||||
import engine.objects.ProducedItem;
|
||||
import engine.objects.Zone;
|
||||
import org.joda.time.DateTime;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class dbNPCHandler extends dbHandlerBase {
|
||||
|
||||
public dbNPCHandler() {
|
||||
this.localClass = NPC.class;
|
||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public NPC PERSIST(NPC toAdd) {
|
||||
|
||||
NPC npc = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("CALL `npc_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);")) {
|
||||
|
||||
Vector3fImmutable bindLocation;
|
||||
|
||||
if (toAdd.buildingUUID == 0)
|
||||
bindLocation = toAdd.bindLoc;
|
||||
else
|
||||
bindLocation = Vector3fImmutable.ZERO;
|
||||
|
||||
preparedStatement.setLong(1, toAdd.parentZoneUUID);
|
||||
preparedStatement.setString(2, toAdd.getName());
|
||||
preparedStatement.setInt(3, toAdd.contractUUID);
|
||||
preparedStatement.setInt(4, toAdd.guildUUID);
|
||||
preparedStatement.setFloat(5, bindLocation.x);
|
||||
preparedStatement.setFloat(6, bindLocation.y);
|
||||
preparedStatement.setFloat(7, bindLocation.z);
|
||||
preparedStatement.setInt(8, toAdd.level);
|
||||
preparedStatement.setFloat(9, toAdd.buyPercent);
|
||||
preparedStatement.setFloat(10, toAdd.sellPercent);
|
||||
|
||||
preparedStatement.setInt(11, Math.max(toAdd.buildingUUID, 0));
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (rs.next()) {
|
||||
int objectUUID = (int) rs.getLong("UID");
|
||||
|
||||
if (objectUUID > 0)
|
||||
npc = GET_NPC(objectUUID);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return npc;
|
||||
}
|
||||
|
||||
public int DELETE_NPC(final NPC npc) {
|
||||
|
||||
int row_count = 0;
|
||||
|
||||
npc.removeFromZone();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `object` WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setLong(1, npc.getDBID());
|
||||
row_count = preparedStatement.executeUpdate();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
|
||||
}
|
||||
return row_count;
|
||||
}
|
||||
|
||||
public ArrayList<NPC> GET_ALL_NPCS_FOR_ZONE(Zone zone) {
|
||||
|
||||
ArrayList<NPC> npcList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_npc`.*, `object`.`parent` FROM `object` INNER JOIN `obj_npc` ON `obj_npc`.`UID` = `object`.`UID` WHERE `object`.`parent` = ?;")) {
|
||||
|
||||
preparedStatement.setLong(1, zone.getObjectUUID());
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
npcList = getObjectsFromRs(rs, 1000);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return npcList;
|
||||
}
|
||||
|
||||
public NPC GET_NPC(final int objectUUID) {
|
||||
|
||||
NPC npc = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_npc`.*, `object`.`parent` FROM `object` INNER JOIN `obj_npc` ON `obj_npc`.`UID` = `object`.`UID` WHERE `object`.`UID` = ?;")) {
|
||||
|
||||
preparedStatement.setLong(1, objectUUID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
npc = (NPC) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return npc;
|
||||
}
|
||||
|
||||
public int MOVE_NPC(long npcID, long parentID, float locX, float locY, float locZ) {
|
||||
|
||||
int rowCount;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `object` INNER JOIN `obj_npc` On `object`.`UID` = `obj_npc`.`UID` SET `object`.`parent`=?, `obj_npc`.`npc_spawnX`=?, `obj_npc`.`npc_spawnY`=?, `obj_npc`.`npc_spawnZ`=? WHERE `obj_npc`.`UID`=?;")) {
|
||||
|
||||
preparedStatement.setLong(1, parentID);
|
||||
preparedStatement.setFloat(2, locX);
|
||||
preparedStatement.setFloat(3, locY);
|
||||
preparedStatement.setFloat(4, locZ);
|
||||
preparedStatement.setLong(5, npcID);
|
||||
|
||||
rowCount = preparedStatement.executeUpdate();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return 0;
|
||||
}
|
||||
return rowCount;
|
||||
}
|
||||
|
||||
|
||||
public String SET_PROPERTY(final NPC n, String name, Object new_value) {
|
||||
|
||||
String result = "";
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("CALL npc_SETPROP(?,?,?)")) {
|
||||
|
||||
preparedStatement.setLong(1, n.getDBID());
|
||||
preparedStatement.setString(2, name);
|
||||
preparedStatement.setString(3, String.valueOf(new_value));
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (rs.next())
|
||||
result = rs.getString("result");
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void updateDatabase(final NPC npc) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE obj_npc SET npc_name=?, npc_contractID=?, npc_typeID=?, npc_guildID=?,"
|
||||
+ " npc_spawnX=?, npc_spawnY=?, npc_spawnZ=?, npc_level=? ,"
|
||||
+ " npc_buyPercent=?, npc_sellPercent=?, npc_buildingID=? WHERE UID = ?")) {
|
||||
|
||||
preparedStatement.setString(1, npc.getName());
|
||||
preparedStatement.setInt(2, (npc.getContract() != null) ? npc.getContract().getObjectUUID() : 0);
|
||||
preparedStatement.setInt(3, 0);
|
||||
preparedStatement.setInt(4, (npc.getGuild() != null) ? npc.getGuild().getObjectUUID() : 0);
|
||||
preparedStatement.setFloat(5, npc.getBindLoc().x);
|
||||
preparedStatement.setFloat(6, npc.getBindLoc().y);
|
||||
preparedStatement.setFloat(7, npc.getBindLoc().z);
|
||||
preparedStatement.setShort(8, npc.getLevel());
|
||||
preparedStatement.setFloat(9, npc.getBuyPercent());
|
||||
preparedStatement.setFloat(10, npc.getSellPercent());
|
||||
preparedStatement.setInt(11, (npc.getBuilding() != null) ? npc.getBuilding().getObjectUUID() : 0);
|
||||
preparedStatement.setInt(12, npc.getDBID());
|
||||
|
||||
preparedStatement.executeUpdate();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean updateUpgradeTime(NPC npc, DateTime upgradeDateTime) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE obj_npc SET upgradeDate=? "
|
||||
+ "WHERE UID = ?")) {
|
||||
|
||||
if (upgradeDateTime == null)
|
||||
preparedStatement.setNull(1, java.sql.Types.DATE);
|
||||
else
|
||||
preparedStatement.setTimestamp(1, new java.sql.Timestamp(upgradeDateTime.getMillis()));
|
||||
|
||||
preparedStatement.setInt(2, npc.getObjectUUID());
|
||||
|
||||
preparedStatement.execute();
|
||||
return true;
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean UPDATE_MOBBASE(NPC npc, int mobBaseID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_npc` SET `npc_raceID`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setLong(1, mobBaseID);
|
||||
preparedStatement.setLong(2, npc.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean UPDATE_EQUIPSET(NPC npc, int equipSetID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_npc` SET `equipsetID`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, equipSetID);
|
||||
preparedStatement.setLong(2, npc.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean UPDATE_NAME(NPC npc, String name) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_npc` SET `npc_name`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setString(1, name);
|
||||
preparedStatement.setLong(2, npc.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void LOAD_PIRATE_NAMES() {
|
||||
|
||||
String pirateName;
|
||||
int mobBase;
|
||||
int recordsRead = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_piratenames")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
recordsRead++;
|
||||
mobBase = rs.getInt("mobbase");
|
||||
pirateName = rs.getString("first_name");
|
||||
|
||||
// Handle new mobbbase entries
|
||||
|
||||
if (NPC._pirateNames.get(mobBase) == null)
|
||||
NPC._pirateNames.putIfAbsent(mobBase, new ArrayList<>());
|
||||
|
||||
// Insert name into proper arraylist
|
||||
|
||||
NPC._pirateNames.get(mobBase).add(pirateName);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
Logger.info("names read: " + recordsRead + " for "
|
||||
+ NPC._pirateNames.size() + " mobBases");
|
||||
}
|
||||
|
||||
public boolean ADD_TO_PRODUCTION_LIST(final long ID, final long npcUID, final long itemBaseID, DateTime dateTime, String prefix, String suffix, String name, boolean isRandom, int playerID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_npc_production` (`ID`,`npcUID`, `itemBaseID`,`dateToUpgrade`, `isRandom`, `prefix`, `suffix`, `name`,`playerID`) VALUES (?,?,?,?,?,?,?,?,?)")) {
|
||||
|
||||
preparedStatement.setLong(1, ID);
|
||||
preparedStatement.setLong(2, npcUID);
|
||||
preparedStatement.setLong(3, itemBaseID);
|
||||
preparedStatement.setTimestamp(4, new java.sql.Timestamp(dateTime.getMillis()));
|
||||
preparedStatement.setBoolean(5, isRandom);
|
||||
preparedStatement.setString(6, prefix);
|
||||
preparedStatement.setString(7, suffix);
|
||||
preparedStatement.setString(8, name);
|
||||
preparedStatement.setInt(9, playerID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean REMOVE_FROM_PRODUCTION_LIST(final long ID, final long npcUID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_npc_production` WHERE `ID`=? AND `npcUID`=?;")) {
|
||||
|
||||
preparedStatement.setLong(1, ID);
|
||||
preparedStatement.setLong(2, npcUID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean UPDATE_ITEM_TO_INVENTORY(final long ID, final long npcUID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_npc_production` SET `inForge`=? WHERE `ID`=? AND `npcUID`=?;")) {
|
||||
|
||||
preparedStatement.setByte(1, (byte) 0);
|
||||
preparedStatement.setLong(2, ID);
|
||||
preparedStatement.setLong(3, npcUID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean UPDATE_ITEM_PRICE(final long ID, final long npcUID, int value) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_npc_production` SET `value`=? WHERE `ID`=? AND `npcUID`=?;")) {
|
||||
|
||||
preparedStatement.setInt(1, value);
|
||||
preparedStatement.setLong(2, ID);
|
||||
preparedStatement.setLong(3, npcUID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean UPDATE_ITEM_ID(final long ID, final long npcUID, final long value) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_npc_production` SET `ID`=? WHERE `ID`=? AND `npcUID`=? LIMIT 1;")) {
|
||||
|
||||
preparedStatement.setLong(1, value);
|
||||
preparedStatement.setLong(2, ID);
|
||||
preparedStatement.setLong(3, npcUID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void LOAD_ALL_ITEMS_TO_PRODUCE(NPC npc) {
|
||||
|
||||
if (npc == null)
|
||||
return;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_npc_production` WHERE `npcUID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, npc.getObjectUUID());
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
ProducedItem producedItem = new ProducedItem(rs);
|
||||
npc.forgedItems.add(producedItem);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean UPDATE_PROFITS(NPC npc, ProfitType profitType, float value) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_npc_profits` SET `" + profitType.dbField + "` = ? WHERE `npcUID`=?")) {
|
||||
|
||||
preparedStatement.setFloat(1, value);
|
||||
preparedStatement.setInt(2, npc.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void LOAD_NPC_PROFITS() {
|
||||
|
||||
NPCProfits npcProfit;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM dyn_npc_profits")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
npcProfit = new NPCProfits(rs);
|
||||
NPCProfits.ProfitCache.put(npcProfit.npcUID, npcProfit);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean CREATE_PROFITS(NPC npc) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_npc_profits` (`npcUID`) VALUES (?)")) {
|
||||
|
||||
preparedStatement.setLong(1, npc.getObjectUUID());
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// 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("CREATE TABLE IF NOT EXISTS dyn_petition " +
|
||||
" (petitionNumber INT AUTO_INCREMENT NOT NULL," +
|
||||
" petitionTime DATETIME," +
|
||||
" primaryType VARCHAR(50)," +
|
||||
" subType VARCHAR(50)," +
|
||||
" message VARCHAR(255)," +
|
||||
" accountID INT," +
|
||||
" accountName VARCHAR(255)," +
|
||||
" characterID INT," +
|
||||
" characterName VARCHAR(255)," +
|
||||
" location VARCHAR(255), " +
|
||||
" PRIMARY KEY (petitionNumber))" +
|
||||
" ENGINE = innodb ROW_FORMAT = DEFAULT;")) {
|
||||
|
||||
preparedStatement.executeUpdate();
|
||||
|
||||
} 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`, `accountName`, `characterID`, `characterName`, `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());
|
||||
|
||||
String messageCleaned = petition.message.substring(0, Math.min(petition.message.length(), 255));
|
||||
preparedStatement.setString(9, messageCleaned);
|
||||
|
||||
preparedStatement.executeUpdate();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error("CREATE PETITION FAILED: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,571 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.AbstractWorldObject;
|
||||
import engine.objects.Heraldry;
|
||||
import engine.objects.PlayerCharacter;
|
||||
import engine.objects.PlayerFriends;
|
||||
import engine.server.MBServerStatics;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class dbPlayerCharacterHandler extends dbHandlerBase {
|
||||
|
||||
public dbPlayerCharacterHandler() {
|
||||
this.localClass = PlayerCharacter.class;
|
||||
this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public PlayerCharacter ADD_PLAYER_CHARACTER(final PlayerCharacter toAdd) {
|
||||
|
||||
PlayerCharacter playerCharacter = null;
|
||||
|
||||
if (toAdd.getAccount() == null)
|
||||
return null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("CALL `character_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);")) {
|
||||
|
||||
preparedStatement.setLong(1, toAdd.getAccount().getObjectUUID());
|
||||
preparedStatement.setString(2, toAdd.getFirstName());
|
||||
preparedStatement.setString(3, toAdd.getLastName());
|
||||
preparedStatement.setInt(4, toAdd.getRace().getRaceRuneID());
|
||||
preparedStatement.setInt(5, toAdd.getBaseClass().getObjectUUID());
|
||||
preparedStatement.setInt(6, toAdd.getStrMod());
|
||||
preparedStatement.setInt(7, toAdd.getDexMod());
|
||||
preparedStatement.setInt(8, toAdd.getConMod());
|
||||
preparedStatement.setInt(9, toAdd.getIntMod());
|
||||
preparedStatement.setInt(10, toAdd.getSpiMod());
|
||||
preparedStatement.setInt(11, toAdd.getExp());
|
||||
preparedStatement.setInt(12, toAdd.getSkinColor());
|
||||
preparedStatement.setInt(13, toAdd.getHairColor());
|
||||
preparedStatement.setByte(14, toAdd.getHairStyle());
|
||||
preparedStatement.setInt(15, toAdd.getBeardColor());
|
||||
preparedStatement.setByte(16, toAdd.getBeardStyle());
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (rs.next()) {
|
||||
int objectUUID = (int) rs.getLong("UID");
|
||||
|
||||
if (objectUUID > 0)
|
||||
playerCharacter = GET_PLAYER_CHARACTER(objectUUID);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return playerCharacter;
|
||||
}
|
||||
|
||||
public boolean SET_IGNORE_LIST(int sourceID, int targetID, boolean toIgnore, String charName) {
|
||||
|
||||
String queryString = "";
|
||||
|
||||
if (toIgnore)
|
||||
queryString = "INSERT INTO `dyn_character_ignore` (`accountUID`, `ignoringUID`, `characterName`) VALUES (?, ?, ?)";
|
||||
else
|
||||
queryString = "DELETE FROM `dyn_character_ignore` WHERE `accountUID` = ? && `ignoringUID` = ?";
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement(queryString)) {
|
||||
|
||||
preparedStatement.setLong(1, sourceID);
|
||||
preparedStatement.setLong(2, targetID);
|
||||
|
||||
if (toIgnore)
|
||||
preparedStatement.setString(3, charName);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public ArrayList<PlayerCharacter> GET_CHARACTERS_FOR_ACCOUNT(final int id) {
|
||||
|
||||
ArrayList<PlayerCharacter> characterList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_character`.*, `object`.`parent` FROM `object` INNER JOIN `obj_character` ON `obj_character`.`UID` = `object`.`UID` WHERE `object`.`parent`=? && `obj_character`.`char_isActive`='1';")) {
|
||||
|
||||
preparedStatement.setLong(1, id);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
characterList = getObjectsFromRs(rs, 10);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return characterList;
|
||||
}
|
||||
|
||||
public ArrayList<PlayerCharacter> GET_ALL_CHARACTERS() {
|
||||
|
||||
ArrayList<PlayerCharacter> characterList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_character`.*, `object`.`parent` FROM `object` INNER JOIN `obj_character` ON `obj_character`.`UID` = `object`.`UID` WHERE `obj_character`.`char_isActive`='1';")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
characterList = getObjectsFromRs(rs, 2000);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return characterList;
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>getFirstName</code> looks up the first name of a PlayerCharacter by
|
||||
* first checking the GOM cache and then querying the database.
|
||||
* PlayerCharacter objects that are not already cached won't be instantiated
|
||||
* and cached.
|
||||
*/
|
||||
|
||||
public ConcurrentHashMap<Integer, String> GET_IGNORE_LIST(final int objectUUID, final boolean skipActiveCheck) {
|
||||
|
||||
ConcurrentHashMap<Integer, String> ignoreList = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_ignore` WHERE `accountUID` = ?;")) {
|
||||
|
||||
preparedStatement.setLong(1, objectUUID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
int ignoreCharacterID = rs.getInt("ignoringUID");
|
||||
|
||||
if (ignoreCharacterID == 0)
|
||||
continue;
|
||||
|
||||
String name = rs.getString("characterName");
|
||||
ignoreList.put(ignoreCharacterID, name);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return ignoreList;
|
||||
}
|
||||
|
||||
public PlayerCharacter GET_PLAYER_CHARACTER(final int objectUUID) {
|
||||
|
||||
if (objectUUID == 0)
|
||||
return null;
|
||||
|
||||
PlayerCharacter playerCharacter = (PlayerCharacter) DbManager.getFromCache(Enum.GameObjectType.PlayerCharacter, objectUUID);
|
||||
|
||||
if (playerCharacter != null)
|
||||
return playerCharacter;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_character`.*, `object`.`parent` FROM `object` INNER JOIN `obj_character` ON `obj_character`.`UID` = `object`.`UID` WHERE `object`.`UID` = ?")) {
|
||||
|
||||
preparedStatement.setLong(1, objectUUID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
playerCharacter = (PlayerCharacter) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return playerCharacter;
|
||||
}
|
||||
|
||||
public boolean IS_CHARACTER_NAME_UNIQUE(final String firstName) {
|
||||
|
||||
boolean unique = true;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `char_firstname` FROM `obj_character` WHERE `char_isActive`=1 && `char_firstname`=?")) {
|
||||
|
||||
preparedStatement.setString(1, firstName);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (rs.next())
|
||||
unique = false;
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return unique;
|
||||
}
|
||||
|
||||
public boolean UPDATE_NAME(String oldFirstName, String newFirstName, String newLastName) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_firstname`=?, `char_lastname`=? WHERE `char_firstname`=? AND `char_isActive`='1'")) {
|
||||
|
||||
preparedStatement.setString(1, newFirstName);
|
||||
preparedStatement.setString(2, newLastName);
|
||||
preparedStatement.setString(3, oldFirstName);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean SET_DELETED(final PlayerCharacter pc) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_isActive`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setBoolean(1, !pc.isDeleted());
|
||||
preparedStatement.setLong(2, pc.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean SET_ACTIVE(final PlayerCharacter pc, boolean status) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_isActive`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setBoolean(1, status);
|
||||
preparedStatement.setLong(2, pc.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean SET_BIND_BUILDING(final PlayerCharacter pc, int bindBuildingID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_bindBuilding`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, bindBuildingID);
|
||||
preparedStatement.setLong(2, pc.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean SET_ANNIVERSERY(final PlayerCharacter pc, boolean flag) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `anniversery`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setBoolean(1, flag);
|
||||
preparedStatement.setLong(2, pc.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean UPDATE_CHARACTER_EXPERIENCE(final PlayerCharacter pc) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_experience`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, pc.getExp());
|
||||
preparedStatement.setLong(2, pc.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean UPDATE_GUILD(final PlayerCharacter pc, int guildUUID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guildUID`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, guildUUID);
|
||||
preparedStatement.setLong(2, pc.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean UPDATE_CHARACTER_STATS(final PlayerCharacter pc) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_strMod`=?, `char_dexMod`=?, `char_conMod`=?, `char_intMod`=?, `char_spiMod`=? WHERE `UID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, pc.getStrMod());
|
||||
preparedStatement.setInt(2, pc.getDexMod());
|
||||
preparedStatement.setInt(3, pc.getConMod());
|
||||
preparedStatement.setInt(4, pc.getIntMod());
|
||||
preparedStatement.setInt(5, pc.getSpiMod());
|
||||
preparedStatement.setLong(6, pc.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String SET_PROPERTY(final PlayerCharacter playerCharacter, String name, Object new_value) {
|
||||
|
||||
String result = "";
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("CALL character_SETPROP(?,?,?)")) {
|
||||
|
||||
preparedStatement.setLong(1, playerCharacter.getObjectUUID());
|
||||
preparedStatement.setString(2, name);
|
||||
preparedStatement.setString(3, String.valueOf(new_value));
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (rs.next())
|
||||
result = rs.getString("result");
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean SET_PROMOTION_CLASS(PlayerCharacter player, int promotionClassID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_promotionClassID`=? WHERE `UID`=?;")) {
|
||||
|
||||
preparedStatement.setInt(1, promotionClassID);
|
||||
preparedStatement.setInt(2, player.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean SET_INNERCOUNCIL(PlayerCharacter player, boolean isInnerCouncil) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_isInnerCouncil`=? WHERE `UID`=?;")) {
|
||||
|
||||
preparedStatement.setBoolean(1, isInnerCouncil);
|
||||
preparedStatement.setInt(2, player.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean SET_FULL_MEMBER(PlayerCharacter player, boolean isFullMember) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_isFullMember`=? WHERE `UID`=?;")) {
|
||||
|
||||
preparedStatement.setBoolean(1, isFullMember);
|
||||
preparedStatement.setInt(2, player.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean SET_TAX_COLLECTOR(PlayerCharacter player, boolean isTaxCollector) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_isTaxCollector`=? WHERE `UID`=?;")) {
|
||||
|
||||
preparedStatement.setBoolean(1, isTaxCollector);
|
||||
preparedStatement.setInt(2, player.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean SET_RECRUITER(PlayerCharacter player, boolean isRecruiter) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_isRecruiter`=? WHERE `UID`=?;")) {
|
||||
|
||||
preparedStatement.setBoolean(1, isRecruiter);
|
||||
preparedStatement.setInt(2, player.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean SET_GUILD_TITLE(PlayerCharacter player, int title) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_title`=? WHERE `UID`=?;")) {
|
||||
|
||||
preparedStatement.setInt(1, title);
|
||||
preparedStatement.setInt(2, player.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean ADD_FRIEND(int source, long friend) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_character_friends` (`playerUID`, `friendUID`) VALUES (?, ?)")) {
|
||||
|
||||
preparedStatement.setLong(1, source);
|
||||
preparedStatement.setLong(2, friend);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean REMOVE_FRIEND(int source, int friend) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_character_friends` WHERE (`playerUID`=?) AND (`friendUID`=?)")) {
|
||||
|
||||
preparedStatement.setLong(1, source);
|
||||
preparedStatement.setLong(2, friend);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void LOAD_PLAYER_FRIENDS() {
|
||||
|
||||
PlayerFriends playerFriend;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM dyn_character_friends")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next())
|
||||
playerFriend = new PlayerFriends(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean ADD_HERALDY(int source, AbstractWorldObject character) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_character_heraldy` (`playerUID`, `characterUID`,`characterType`) VALUES (?, ?,?)")) {
|
||||
|
||||
preparedStatement.setLong(1, source);
|
||||
preparedStatement.setLong(2, character.getObjectUUID());
|
||||
preparedStatement.setInt(3, character.getObjectType().ordinal());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean REMOVE_HERALDY(int source, int characterUID) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_character_heraldy` WHERE (`playerUID`=?) AND (`characterUID`=?)")) {
|
||||
|
||||
preparedStatement.setLong(1, source);
|
||||
preparedStatement.setLong(2, characterUID);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void LOAD_HERALDY() {
|
||||
|
||||
Heraldry heraldy;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM dyn_character_heraldy")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next())
|
||||
heraldy = new Heraldry(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.gameManager.PowersManager;
|
||||
import engine.objects.Mob;
|
||||
import engine.objects.PreparedStatementShared;
|
||||
import engine.powers.EffectsBase;
|
||||
import engine.powers.MobPowerEntry;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class dbPowerHandler extends dbHandlerBase {
|
||||
|
||||
public dbPowerHandler() {
|
||||
this.localClass = Mob.class;
|
||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public static void addAllSourceTypes() {
|
||||
PreparedStatementShared ps = null;
|
||||
try {
|
||||
ps = new PreparedStatementShared("SELECT * FROM static_power_sourcetype");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
String IDString, source;
|
||||
while (rs.next()) {
|
||||
IDString = rs.getString("IDString");
|
||||
int token = DbManager.hasher.SBStringHash(IDString);
|
||||
|
||||
|
||||
source = rs.getString("source").replace("-", "").trim();
|
||||
Enum.EffectSourceType effectSourceType = Enum.EffectSourceType.GetEffectSourceType(source);
|
||||
|
||||
if (EffectsBase.effectSourceTypeMap.containsKey(token) == false)
|
||||
EffectsBase.effectSourceTypeMap.put(token, new HashSet<>());
|
||||
|
||||
EffectsBase.effectSourceTypeMap.get(token).add(effectSourceType);
|
||||
}
|
||||
rs.close();
|
||||
} catch (Exception e) {
|
||||
Logger.error(e);
|
||||
} finally {
|
||||
ps.release();
|
||||
}
|
||||
}
|
||||
|
||||
public static void addAllAnimationOverrides() {
|
||||
PreparedStatementShared ps = null;
|
||||
try {
|
||||
ps = new PreparedStatementShared("SELECT * FROM static_power_animation_override");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
String IDString;
|
||||
int animation;
|
||||
while (rs.next()) {
|
||||
IDString = rs.getString("IDString");
|
||||
|
||||
EffectsBase eb = PowersManager.getEffectByIDString(IDString);
|
||||
if (eb != null)
|
||||
IDString = eb.getIDString();
|
||||
|
||||
animation = rs.getInt("animation");
|
||||
PowersManager.AnimationOverrides.put(IDString, animation);
|
||||
|
||||
}
|
||||
rs.close();
|
||||
} catch (Exception e) {
|
||||
Logger.error(e);
|
||||
} finally {
|
||||
ps.release();
|
||||
}
|
||||
}
|
||||
|
||||
public static HashMap<Integer, ArrayList<MobPowerEntry>> LOAD_MOB_POWERS() {
|
||||
|
||||
HashMap<Integer, ArrayList<MobPowerEntry>> mobPowers = new HashMap<>();
|
||||
MobPowerEntry mobPowerEntry;
|
||||
|
||||
int mobbaseID;
|
||||
int recordsRead = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_npc_mobbase_powers ORDER BY `id` ASC;")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
recordsRead++;
|
||||
|
||||
mobbaseID = rs.getInt("mobbaseUUID");
|
||||
mobPowerEntry = new MobPowerEntry(rs);
|
||||
|
||||
if (mobPowers.get(mobbaseID) == null) {
|
||||
ArrayList<MobPowerEntry> powerList = new ArrayList<>();
|
||||
powerList.add(mobPowerEntry);
|
||||
mobPowers.put(mobbaseID, powerList);
|
||||
} else {
|
||||
ArrayList<MobPowerEntry> powerList = mobPowers.get(mobbaseID);
|
||||
powerList.add(mobPowerEntry);
|
||||
mobPowers.put(mobbaseID, powerList);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return mobPowers;
|
||||
}
|
||||
|
||||
Logger.info("read: " + recordsRead + " cached: " + mobPowers.size());
|
||||
return mobPowers;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.PromotionClass;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class dbPromotionClassHandler extends dbHandlerBase {
|
||||
|
||||
public dbPromotionClassHandler() {
|
||||
this.localClass = PromotionClass.class;
|
||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public ArrayList<Integer> GET_ALLOWED_RUNES(final PromotionClass pc) {
|
||||
|
||||
ArrayList<Integer> runeList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_promotionrunereq` WHERE `promoID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, pc.getObjectUUID());
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next())
|
||||
runeList.add(rs.getInt("runereqID"));
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
|
||||
}
|
||||
return runeList;
|
||||
}
|
||||
|
||||
public PromotionClass GET_PROMOTION_CLASS(final int objectUUID) {
|
||||
|
||||
PromotionClass promotionClass = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_promotion` WHERE `ID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, objectUUID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
promotionClass = (PromotionClass) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return promotionClass;
|
||||
}
|
||||
|
||||
public ArrayList<PromotionClass> GET_ALL_PROMOTIONS() {
|
||||
|
||||
ArrayList<PromotionClass> promotionList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_promotion`")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
promotionList = getObjectsFromRs(rs, 30);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return promotionList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.Race;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashSet;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class dbRaceHandler extends dbHandlerBase {
|
||||
|
||||
public dbRaceHandler() {
|
||||
}
|
||||
|
||||
public HashSet<Integer> BEARD_COLORS_FOR_RACE(final int id) {
|
||||
|
||||
HashSet<Integer> integerSet = new HashSet<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `color` FROM `static_rune_racebeardcolor` WHERE `RaceID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, id);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next())
|
||||
integerSet.add(rs.getInt(1));
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return integerSet;
|
||||
}
|
||||
|
||||
public HashSet<Integer> BEARD_STYLES_FOR_RACE(final int id) {
|
||||
|
||||
HashSet<Integer> integerSet = new HashSet<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `beardStyle` FROM `static_rune_racebeardstyle` WHERE `RaceID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, id);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next())
|
||||
integerSet.add(rs.getInt(1));
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return integerSet;
|
||||
}
|
||||
|
||||
public HashSet<Integer> HAIR_COLORS_FOR_RACE(final int id) {
|
||||
|
||||
HashSet<Integer> integerSet = new HashSet<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `color` FROM `static_rune_racehaircolor` WHERE `RaceID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, id);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next())
|
||||
integerSet.add(rs.getInt(1));
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return integerSet;
|
||||
|
||||
}
|
||||
|
||||
public HashSet<Integer> HAIR_STYLES_FOR_RACE(final int id) {
|
||||
|
||||
HashSet<Integer> integerSet = new HashSet<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `hairStyle` FROM `static_rune_racehairstyle` WHERE `RaceID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, id);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next())
|
||||
integerSet.add(rs.getInt(1));
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return integerSet;
|
||||
|
||||
}
|
||||
|
||||
public HashSet<Integer> SKIN_COLOR_FOR_RACE(final int id) {
|
||||
|
||||
HashSet<Integer> integerSet = new HashSet<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `color` FROM `static_rune_raceskincolor` WHERE `RaceID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, id);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next())
|
||||
integerSet.add(rs.getInt(1));
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return integerSet;
|
||||
}
|
||||
|
||||
public ConcurrentHashMap<Integer, Race> LOAD_ALL_RACES() {
|
||||
|
||||
ConcurrentHashMap<Integer, Race> races;
|
||||
Race thisRace;
|
||||
|
||||
races = new ConcurrentHashMap<>();
|
||||
int recordsRead = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_rune_race")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
recordsRead++;
|
||||
thisRace = new Race(rs);
|
||||
|
||||
races.put(thisRace.getRaceRuneID(), thisRace);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
Logger.info("read: " + recordsRead + " cached: " + races.size());
|
||||
return races;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.Realm;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class dbRealmHandler extends dbHandlerBase {
|
||||
|
||||
public dbRealmHandler() {
|
||||
|
||||
}
|
||||
|
||||
public ConcurrentHashMap<Integer, Realm> LOAD_ALL_REALMS() {
|
||||
|
||||
ConcurrentHashMap<Integer, Realm> realmList;
|
||||
Realm thisRealm;
|
||||
|
||||
realmList = new ConcurrentHashMap<>();
|
||||
int recordsRead = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM obj_realm")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
recordsRead++;
|
||||
thisRealm = new Realm(rs);
|
||||
realmList.put(thisRealm.getRealmID(), thisRealm);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
Logger.info("read: " + recordsRead + " cached: " + realmList.size());
|
||||
return realmList;
|
||||
}
|
||||
|
||||
public void REALM_UPDATE(Realm realm) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("CALL realm_UPDATE(?,?,?,?)")) {
|
||||
|
||||
preparedStatement.setInt(1, realm.getRealmID());
|
||||
preparedStatement.setInt(2, (realm.getRulingCity() == null) ? 0 : realm.getRulingCity().getObjectUUID());
|
||||
preparedStatement.setInt(3, realm.getCharterType());
|
||||
|
||||
if (realm.ruledSince != null)
|
||||
preparedStatement.setTimestamp(4, Timestamp.valueOf(realm.ruledSince));
|
||||
else
|
||||
preparedStatement.setNull(4, java.sql.Types.DATE);
|
||||
|
||||
preparedStatement.execute();
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.Resists;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class dbResistHandler extends dbHandlerBase {
|
||||
|
||||
public dbResistHandler() {
|
||||
|
||||
}
|
||||
|
||||
public Resists GET_RESISTS_FOR_MOB(int resistID) {
|
||||
|
||||
Resists resists = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mob_resists` WHERE `ID` = ?;")) {
|
||||
|
||||
preparedStatement.setInt(1, resistID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (rs.next())
|
||||
resists = new Resists(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return resists;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.RuneBaseAttribute;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class dbRuneBaseAttributeHandler extends dbHandlerBase {
|
||||
|
||||
public dbRuneBaseAttributeHandler() {
|
||||
this.localClass = RuneBaseAttribute.class;
|
||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public ArrayList<RuneBaseAttribute> GET_ATTRIBUTES_FOR_RUNEBASE() {
|
||||
|
||||
ArrayList<RuneBaseAttribute> runeBaseAttributesList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_runebaseattribute`")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
runeBaseAttributesList = getObjectsFromRs(rs, 10);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return runeBaseAttributesList;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.AbstractGameObject;
|
||||
import engine.objects.RuneBaseEffect;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class dbRuneBaseEffectHandler extends dbHandlerBase {
|
||||
|
||||
public dbRuneBaseEffectHandler() {
|
||||
this.localClass = RuneBaseEffect.class;
|
||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public ArrayList<RuneBaseEffect> GET_EFFECTS_FOR_RUNEBASE(int id) {
|
||||
|
||||
ArrayList<RuneBaseEffect> runeBaseEffectsList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_baseeffect` WHERE `runeID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, id);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
runeBaseEffectsList = getObjectsFromRs(rs, 250);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return runeBaseEffectsList;
|
||||
}
|
||||
|
||||
public ArrayList<RuneBaseEffect> GET_ALL_RUNEBASE_EFFECTS() {
|
||||
|
||||
ArrayList<RuneBaseEffect> runeBaseEffectsList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_baseeffect`;")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
runeBaseEffectsList = getObjectsFromRs(rs, 250);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return runeBaseEffectsList;
|
||||
}
|
||||
|
||||
//This calls from cache only. Call this AFTER caching all runebase effects;
|
||||
|
||||
public HashMap<Integer, ArrayList<RuneBaseEffect>> LOAD_BASEEFFECTS_FOR_RUNEBASE() {
|
||||
|
||||
HashMap<Integer, ArrayList<RuneBaseEffect>> runeBaseEffectSet;
|
||||
runeBaseEffectSet = new HashMap<>();
|
||||
|
||||
for (AbstractGameObject runeBaseEffect : DbManager.getList(GameObjectType.RuneBaseEffect)) {
|
||||
|
||||
int runeBaseID = ((RuneBaseEffect) runeBaseEffect).getRuneBaseID();
|
||||
if (runeBaseEffectSet.get(runeBaseID) == null) {
|
||||
ArrayList<RuneBaseEffect> runeBaseEffectList = new ArrayList<>();
|
||||
runeBaseEffectList.add((RuneBaseEffect) runeBaseEffect);
|
||||
runeBaseEffectSet.put(runeBaseID, runeBaseEffectList);
|
||||
} else {
|
||||
ArrayList<RuneBaseEffect> runeBaseEffectList = runeBaseEffectSet.get(runeBaseID);
|
||||
runeBaseEffectList.add((RuneBaseEffect) runeBaseEffect);
|
||||
runeBaseEffectSet.put(runeBaseID, runeBaseEffectList);
|
||||
}
|
||||
}
|
||||
return runeBaseEffectSet;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.RuneBase;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class dbRuneBaseHandler extends dbHandlerBase {
|
||||
|
||||
public dbRuneBaseHandler() {
|
||||
this.localClass = RuneBase.class;
|
||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public void GET_RUNE_REQS(final RuneBase rb) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_runereq` WHERE `runeID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, rb.getObjectUUID());
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
int type = rs.getInt("type");
|
||||
|
||||
switch (type) {
|
||||
case 1:
|
||||
rb.getRace().put(rs.getInt("requiredRuneID"), rs.getBoolean("isAllowed"));
|
||||
break;
|
||||
case 2:
|
||||
rb.getBaseClass().put(rs.getInt("requiredRuneID"), rs.getBoolean("isAllowed"));
|
||||
break;
|
||||
case 3:
|
||||
rb.getPromotionClass().put(rs.getInt("requiredRuneID"), rs.getBoolean("isAllowed"));
|
||||
break;
|
||||
case 4:
|
||||
rb.getDiscipline().put(rs.getInt("requiredRuneID"), rs.getBoolean("isAllowed"));
|
||||
break;
|
||||
case 5:
|
||||
rb.getOverwrite().add(rs.getInt("requiredRuneID"));
|
||||
break;
|
||||
case 6:
|
||||
rb.setLevelRequired(rs.getInt("requiredRuneID"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public RuneBase GET_RUNEBASE(final int id) {
|
||||
|
||||
RuneBase runeBase = null;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_runebase` WHERE `ID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, id);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
runeBase = (RuneBase) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return runeBase;
|
||||
}
|
||||
|
||||
public ArrayList<RuneBase> LOAD_ALL_RUNEBASES() {
|
||||
|
||||
ArrayList<RuneBase> runeBasesList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_runebase`;")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
runeBasesList = getObjectsFromRs(rs, 1000);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return runeBasesList;
|
||||
}
|
||||
|
||||
public HashMap<Integer, ArrayList<Integer>> LOAD_ALLOWED_STARTING_RUNES_FOR_BASECLASS() {
|
||||
|
||||
HashMap<Integer, ArrayList<Integer>> runeSets = new HashMap<>();
|
||||
|
||||
int recordsRead = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_rune_baseclassrune")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
recordsRead++;
|
||||
|
||||
int baseClassID = rs.getInt("BaseClassesID");
|
||||
int runeBaseID = rs.getInt("RuneBaseID");
|
||||
|
||||
if (runeSets.get(baseClassID) == null) {
|
||||
ArrayList<Integer> runeList = new ArrayList<>();
|
||||
runeList.add(runeBaseID);
|
||||
runeSets.put(baseClassID, runeList);
|
||||
} else {
|
||||
ArrayList<Integer> runeList = runeSets.get(baseClassID);
|
||||
runeList.add(runeBaseID);
|
||||
runeSets.put(baseClassID, runeList);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
Logger.info("read: " + recordsRead + " cached: " + runeSets.size());
|
||||
|
||||
return runeSets;
|
||||
}
|
||||
|
||||
public HashMap<Integer, ArrayList<Integer>> LOAD_ALLOWED_STARTING_RUNES_FOR_RACE() {
|
||||
|
||||
HashMap<Integer, ArrayList<Integer>> runeSets;
|
||||
|
||||
runeSets = new HashMap<>();
|
||||
int recordsRead = 0;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_rune_racerune")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
recordsRead++;
|
||||
|
||||
int raceID = rs.getInt("RaceID");
|
||||
int runeBaseID = rs.getInt("RuneBaseID");
|
||||
|
||||
if (runeSets.get(raceID) == null) {
|
||||
ArrayList<Integer> runeList = new ArrayList<>();
|
||||
runeList.add(runeBaseID);
|
||||
runeSets.put(raceID, runeList);
|
||||
} else {
|
||||
ArrayList<Integer> runeList = runeSets.get(raceID);
|
||||
runeList.add(runeBaseID);
|
||||
runeSets.put(raceID, runeList);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
Logger.info("read: " + recordsRead + " cached: " + runeSets.size());
|
||||
return runeSets;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.Building;
|
||||
import engine.objects.Portal;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class dbRunegateHandler extends dbHandlerBase {
|
||||
|
||||
public dbRunegateHandler() {
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<Integer> GET_RUNEGATE_LIST() {
|
||||
|
||||
ArrayList<Integer> gateList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT DISTINCT `sourceBuilding` FROM `static_runegate_portals`;")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next())
|
||||
gateList.add(rs.getInt("sourceBuilding"));
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return gateList;
|
||||
}
|
||||
|
||||
public ArrayList<Portal> GET_PORTAL_LIST(int gateUID) {
|
||||
|
||||
ArrayList<Portal> portalList = new ArrayList<>();
|
||||
Building sourceBuilding = (Building) DbManager.getObject(Enum.GameObjectType.Building, gateUID);
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_runegate_portals` WHERE `sourceBuilding` = ?;")) {
|
||||
|
||||
preparedStatement.setInt(1, gateUID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
int targetBuildingID = rs.getInt("targetBuilding");
|
||||
Building targetBuilding = (Building) DbManager.getObject(Enum.GameObjectType.Building, targetBuildingID);
|
||||
Enum.PortalType portalType = Enum.PortalType.valueOf(rs.getString("portalType"));
|
||||
Portal portal = new Portal(sourceBuilding, portalType, targetBuilding);
|
||||
portalList.add(portal);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return portalList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum.ProtectionState;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.math.Vector3fImmutable;
|
||||
import engine.objects.AbstractGameObject;
|
||||
import engine.objects.Building;
|
||||
import engine.objects.Shrine;
|
||||
import org.joda.time.DateTime;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class dbShrineHandler extends dbHandlerBase {
|
||||
|
||||
public dbShrineHandler() {
|
||||
this.localClass = Shrine.class;
|
||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public static void addObject(ArrayList<AbstractGameObject> list, ResultSet rs) throws SQLException {
|
||||
|
||||
String type = rs.getString("type");
|
||||
|
||||
switch (type) {
|
||||
case "building":
|
||||
Building building = new Building(rs);
|
||||
DbManager.addToCache(building);
|
||||
list.add(building);
|
||||
break;
|
||||
case "shrine":
|
||||
Shrine shrine = new Shrine(rs);
|
||||
DbManager.addToCache(shrine);
|
||||
list.add(shrine);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<AbstractGameObject> CREATE_SHRINE(int parentZoneID, int OwnerUUID, String name, int meshUUID,
|
||||
Vector3fImmutable location, float meshScale, int currentHP,
|
||||
ProtectionState protectionState, int currentGold, int rank,
|
||||
DateTime upgradeDate, int blueprintUUID, float w, float rotY, String shrineType) {
|
||||
|
||||
ArrayList<AbstractGameObject> shrineList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("CALL `shrine_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ,? ,? ,?, ?,?);")) {
|
||||
|
||||
preparedStatement.setInt(1, parentZoneID);
|
||||
preparedStatement.setInt(2, OwnerUUID);
|
||||
preparedStatement.setString(3, name);
|
||||
preparedStatement.setInt(4, meshUUID);
|
||||
preparedStatement.setFloat(5, location.x);
|
||||
preparedStatement.setFloat(6, location.y);
|
||||
preparedStatement.setFloat(7, location.z);
|
||||
preparedStatement.setFloat(8, meshScale);
|
||||
preparedStatement.setInt(9, currentHP);
|
||||
preparedStatement.setString(10, protectionState.name());
|
||||
preparedStatement.setInt(11, currentGold);
|
||||
preparedStatement.setInt(12, rank);
|
||||
|
||||
if (upgradeDate != null)
|
||||
preparedStatement.setTimestamp(13, new java.sql.Timestamp(upgradeDate.getMillis()));
|
||||
else
|
||||
preparedStatement.setNull(13, java.sql.Types.DATE);
|
||||
|
||||
preparedStatement.setInt(14, blueprintUUID);
|
||||
preparedStatement.setFloat(15, w);
|
||||
preparedStatement.setFloat(16, rotY);
|
||||
preparedStatement.setString(17, shrineType);
|
||||
|
||||
preparedStatement.execute();
|
||||
|
||||
ResultSet rs = preparedStatement.getResultSet();
|
||||
|
||||
while (rs.next())
|
||||
addObject(shrineList, rs);
|
||||
|
||||
while (preparedStatement.getMoreResults()) {
|
||||
rs = preparedStatement.getResultSet();
|
||||
|
||||
while (rs.next())
|
||||
addObject(shrineList, rs);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return shrineList;
|
||||
}
|
||||
|
||||
public boolean updateFavors(Shrine shrine, int amount, int oldAmount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_shrine` SET `shrine_favors`=? WHERE `UID` = ? AND `shrine_favors` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setLong(2, shrine.getObjectUUID());
|
||||
preparedStatement.setInt(3, oldAmount);
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void LOAD_ALL_SHRINES() {
|
||||
|
||||
Shrine shrine;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_shrine`.*, `object`.`parent`, `object`.`type` FROM `object` LEFT JOIN `obj_shrine` ON `object`.`UID` = `obj_shrine`.`UID` WHERE `object`.`type` = 'shrine';")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
shrine = new Shrine(rs);
|
||||
shrine.getShrineType().addShrineToServerList(shrine);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.MaxSkills;
|
||||
import engine.objects.SkillsBase;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class dbSkillBaseHandler extends dbHandlerBase {
|
||||
|
||||
public dbSkillBaseHandler() {
|
||||
this.localClass = SkillsBase.class;
|
||||
this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public SkillsBase GET_BASE(final int objectUUID) {
|
||||
|
||||
SkillsBase skillsBase = (SkillsBase) DbManager.getFromCache(GameObjectType.SkillsBase, objectUUID);
|
||||
|
||||
if (skillsBase != null)
|
||||
return skillsBase;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_skill_skillsbase WHERE ID = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, objectUUID);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
skillsBase = (SkillsBase) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
SkillsBase.putInCache(skillsBase);
|
||||
return skillsBase;
|
||||
}
|
||||
|
||||
public SkillsBase GET_BASE_BY_NAME(String name) {
|
||||
|
||||
SkillsBase skillsBase = SkillsBase.getFromCache(name);
|
||||
|
||||
if (skillsBase != null)
|
||||
return skillsBase;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_skill_skillsbase WHERE name = ?")) {
|
||||
|
||||
preparedStatement.setString(1, name);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
skillsBase = (SkillsBase) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
SkillsBase.putInCache(skillsBase);
|
||||
return skillsBase;
|
||||
}
|
||||
|
||||
public SkillsBase GET_BASE_BY_TOKEN(final int token) {
|
||||
|
||||
SkillsBase skillsBase = SkillsBase.getFromCache(token);
|
||||
|
||||
if (skillsBase != null)
|
||||
return skillsBase;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_skill_skillsbase WHERE token = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, token);
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
skillsBase = (SkillsBase) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
SkillsBase.putInCache(skillsBase);
|
||||
return skillsBase;
|
||||
}
|
||||
|
||||
public void LOAD_ALL_MAX_SKILLS_FOR_CONTRACT() {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_maxskills`")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
MaxSkills maxSKills = new MaxSkills(rs);
|
||||
|
||||
if (MaxSkills.MaxSkillsSet.get(maxSKills.getRuneID()) == null) {
|
||||
ArrayList<MaxSkills> newMaxSkillsList = new ArrayList<>();
|
||||
newMaxSkillsList.add(maxSKills);
|
||||
MaxSkills.MaxSkillsSet.put(maxSKills.getRuneID(), newMaxSkillsList);
|
||||
} else
|
||||
MaxSkills.MaxSkillsSet.get(maxSKills.getRuneID()).add(maxSKills);
|
||||
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void LOAD_ALL_RUNE_SKILLS() {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_skill_skillsgranted`")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
int runeID = rs.getInt("runeID");
|
||||
int token = rs.getInt("token");
|
||||
int amount = rs.getInt("amount");
|
||||
|
||||
if (SkillsBase.runeSkillsCache.get(runeID) == null)
|
||||
SkillsBase.runeSkillsCache.put(runeID, new HashMap<>());
|
||||
|
||||
SkillsBase.runeSkillsCache.get(runeID).put(token, amount);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.SkillReq;
|
||||
import engine.powers.PowersBase;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class dbSkillReqHandler extends dbHandlerBase {
|
||||
|
||||
public dbSkillReqHandler() {
|
||||
this.localClass = SkillReq.class;
|
||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public static ArrayList<PowersBase> getAllPowersBase() {
|
||||
|
||||
ArrayList<PowersBase> powerBaseList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_power_powerbase")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
PowersBase toAdd = new PowersBase(rs);
|
||||
powerBaseList.add(toAdd);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return powerBaseList;
|
||||
}
|
||||
|
||||
public static void getFailConditions(HashMap<String, PowersBase> powers) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT IDString, type FROM static_power_failcondition where powerOrEffect = 'Power'")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
String type = rs.getString("type");
|
||||
String IDString = rs.getString("IDString");
|
||||
PowersBase pb = powers.get(IDString);
|
||||
|
||||
if (pb != null)
|
||||
switch (type) {
|
||||
case "CastSpell":
|
||||
pb.cancelOnCastSpell = true;
|
||||
break;
|
||||
case "TakeDamage":
|
||||
pb.cancelOnTakeDamage = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<SkillReq> GET_REQS_FOR_RUNE(final int objectUUID) {
|
||||
|
||||
ArrayList<SkillReq> skillReqsList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_skill_skillreq` WHERE `runeID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, objectUUID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
skillReqsList = getObjectsFromRs(rs, 5);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return skillReqsList;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.objects.VendorDialog;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class dbVendorDialogHandler extends dbHandlerBase {
|
||||
|
||||
public dbVendorDialogHandler() {
|
||||
this.localClass = VendorDialog.class;
|
||||
this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public VendorDialog GET_VENDORDIALOG(final int objectUUID) {
|
||||
|
||||
VendorDialog vendorDialog = (VendorDialog) DbManager.getFromCache(Enum.GameObjectType.VendorDialog, objectUUID);
|
||||
|
||||
if (vendorDialog != null)
|
||||
return vendorDialog;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_vendordialog` WHERE `ID`=?")) {
|
||||
|
||||
preparedStatement.setInt(1, objectUUID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
vendorDialog = (VendorDialog) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return vendorDialog;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,555 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.Enum.ProtectionState;
|
||||
import engine.Enum.TransactionType;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.math.Vector3fImmutable;
|
||||
import engine.objects.*;
|
||||
import engine.server.MBServerStatics;
|
||||
import org.joda.time.DateTime;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class dbWarehouseHandler extends dbHandlerBase {
|
||||
|
||||
private static final ConcurrentHashMap<Integer, String> columns = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
|
||||
|
||||
public dbWarehouseHandler() {
|
||||
this.localClass = Warehouse.class;
|
||||
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
|
||||
}
|
||||
|
||||
public static void addObject(ArrayList<AbstractGameObject> list, ResultSet rs) throws SQLException {
|
||||
String type = rs.getString("type");
|
||||
switch (type) {
|
||||
case "building":
|
||||
Building building = new Building(rs);
|
||||
DbManager.addToCache(building);
|
||||
list.add(building);
|
||||
break;
|
||||
case "warehouse":
|
||||
Warehouse warehouse = new Warehouse(rs);
|
||||
DbManager.addToCache(warehouse);
|
||||
list.add(warehouse);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<AbstractGameObject> CREATE_WAREHOUSE(int parentZoneID, int OwnerUUID, String name, int meshUUID,
|
||||
Vector3fImmutable location, float meshScale, int currentHP,
|
||||
ProtectionState protectionState, int currentGold, int rank,
|
||||
DateTime upgradeDate, int blueprintUUID, float w, float rotY) {
|
||||
|
||||
ArrayList<AbstractGameObject> warehouseList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("CALL `WAREHOUSE_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ,? ,? ,?, ?);")) {
|
||||
|
||||
preparedStatement.setInt(1, parentZoneID);
|
||||
preparedStatement.setInt(2, OwnerUUID);
|
||||
preparedStatement.setString(3, name);
|
||||
preparedStatement.setInt(4, meshUUID);
|
||||
preparedStatement.setFloat(5, location.x);
|
||||
preparedStatement.setFloat(6, location.y);
|
||||
preparedStatement.setFloat(7, location.z);
|
||||
preparedStatement.setFloat(8, meshScale);
|
||||
preparedStatement.setInt(9, currentHP);
|
||||
preparedStatement.setString(10, protectionState.name());
|
||||
preparedStatement.setInt(11, currentGold);
|
||||
preparedStatement.setInt(12, rank);
|
||||
|
||||
if (upgradeDate != null)
|
||||
preparedStatement.setTimestamp(13, new java.sql.Timestamp(upgradeDate.getMillis()));
|
||||
else
|
||||
preparedStatement.setNull(13, java.sql.Types.DATE);
|
||||
|
||||
preparedStatement.setInt(14, blueprintUUID);
|
||||
preparedStatement.setFloat(15, w);
|
||||
preparedStatement.setFloat(16, rotY);
|
||||
|
||||
preparedStatement.execute();
|
||||
ResultSet rs = preparedStatement.getResultSet();
|
||||
|
||||
while (rs.next())
|
||||
addObject(warehouseList, rs);
|
||||
|
||||
while (preparedStatement.getMoreResults()) {
|
||||
rs = preparedStatement.getResultSet();
|
||||
|
||||
while (rs.next())
|
||||
addObject(warehouseList, rs);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return warehouseList;
|
||||
}
|
||||
|
||||
public boolean updateLocks(final Warehouse wh, long locks) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_locks`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setLong(1, locks);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateGold(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_gold`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateStone(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_stone`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateTruesteel(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_truesteel`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateIron(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_iron`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateAdamant(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_adamant`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateLumber(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_lumber`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateOak(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_oak`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateBronzewood(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_bronzewood`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateMandrake(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_mandrake`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateCoal(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_coal`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateAgate(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_agate`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateDiamond(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_diamond`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateOnyx(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_onyx`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateAzoth(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_azoth`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateOrichalk(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_orichalk`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateAntimony(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_antimony`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateSulfur(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_sulfur`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateQuicksilver(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_quicksilver`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateGalvor(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_galvor`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateWormwood(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_wormwood`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateObsidian(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_obsidian`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateBloodstone(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_bloodstone`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateMithril(final Warehouse wh, int amount) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_mithril`=? WHERE `UID` = ?")) {
|
||||
|
||||
preparedStatement.setInt(1, amount);
|
||||
preparedStatement.setInt(2, wh.getUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean CREATE_TRANSACTION(int warehouseBuildingID, GameObjectType targetType, int targetUUID, TransactionType transactionType, Resource resource, int amount, DateTime date) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_warehouse_transactions` (`warehouseUID`, `targetType`,`targetUID`, `type`,`resource`,`amount`,`date` ) VALUES (?,?,?,?,?,?,?)")) {
|
||||
|
||||
preparedStatement.setLong(1, warehouseBuildingID);
|
||||
preparedStatement.setString(2, targetType.name());
|
||||
preparedStatement.setLong(3, targetUUID);
|
||||
preparedStatement.setString(4, transactionType.name());
|
||||
preparedStatement.setString(5, resource.name());
|
||||
preparedStatement.setInt(6, amount);
|
||||
preparedStatement.setTimestamp(7, new java.sql.Timestamp(date.getMillis()));
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public ArrayList<Transaction> GET_TRANSACTIONS_FOR_WAREHOUSE(final int warehouseUUID) {
|
||||
|
||||
ArrayList<Transaction> transactionsList = new ArrayList<>();
|
||||
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM dyn_warehouse_transactions WHERE `warehouseUID` = ?;")) {
|
||||
|
||||
preparedStatement.setInt(1, warehouseUUID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
Transaction transactions = new Transaction(rs);
|
||||
transactionsList.add(transactions);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return transactionsList;
|
||||
}
|
||||
|
||||
public void LOAD_ALL_WAREHOUSES() {
|
||||
|
||||
Warehouse warehouse;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_warehouse`.*, `object`.`parent`, `object`.`type` FROM `object` LEFT JOIN `obj_warehouse` ON `object`.`UID` = `obj_warehouse`.`UID` WHERE `object`.`type` = 'warehouse';")) {
|
||||
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
warehouse = new Warehouse(rs);
|
||||
warehouse.runAfterLoad();
|
||||
warehouse.loadAllTransactions();
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2022
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
package engine.db.handlers;
|
||||
|
||||
import engine.Enum;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.gameManager.ZoneManager;
|
||||
import engine.math.Vector2f;
|
||||
import engine.objects.Zone;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class dbZoneHandler extends dbHandlerBase {
|
||||
|
||||
public dbZoneHandler() {
|
||||
this.localClass = Zone.class;
|
||||
this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
|
||||
}
|
||||
|
||||
public ArrayList<Zone> GET_ALL_NODES(Zone zone) {
|
||||
ArrayList<Zone> wsmList = new ArrayList<>();
|
||||
wsmList.addAll(zone.getNodes());
|
||||
if (zone.absX == 0.0f) {
|
||||
zone.absX = zone.getXCoord();
|
||||
}
|
||||
if (zone.absY == 0.0f) {
|
||||
zone.absY = zone.getYCoord();
|
||||
}
|
||||
if (zone.absZ == 0.0f) {
|
||||
zone.absZ = zone.getZCoord();
|
||||
}
|
||||
for (Zone child : zone.getNodes()) {
|
||||
child.absX = child.getXCoord() + zone.absX;
|
||||
child.absY = child.getYCoord() + zone.absY;
|
||||
child.absZ = child.getZCoord() + zone.absZ;
|
||||
wsmList.addAll(this.GET_ALL_NODES(child));
|
||||
}
|
||||
return wsmList;
|
||||
}
|
||||
|
||||
public Zone GET_BY_UID(long ID) {
|
||||
|
||||
Zone zone = (Zone) DbManager.getFromCache(Enum.GameObjectType.Zone, (int) ID);
|
||||
|
||||
if (zone != null)
|
||||
return zone;
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_zone`.*, `object`.`parent` FROM `object` INNER JOIN `obj_zone` ON `obj_zone`.`UID` = `object`.`UID` WHERE `object`.`UID` = ?;")) {
|
||||
|
||||
preparedStatement.setLong(1, ID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
zone = (Zone) getObjectFromRs(rs);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return zone;
|
||||
}
|
||||
|
||||
public ArrayList<Zone> GET_MAP_NODES(final int objectUUID) {
|
||||
|
||||
ArrayList<Zone> zoneList = new ArrayList<>();
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_zone`.*, `object`.`parent` FROM `object` INNER JOIN `obj_zone` ON `obj_zone`.`UID` = `object`.`UID` WHERE `object`.`parent` = ?;")) {
|
||||
|
||||
preparedStatement.setLong(1, objectUUID);
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
zoneList = getObjectsFromRs(rs, 2000);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return zoneList;
|
||||
}
|
||||
|
||||
public void LOAD_ZONE_EXTENTS() {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_zone_size`;")) {
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
Vector2f zoneSize = new Vector2f();
|
||||
int loadNum = rs.getInt("loadNum");
|
||||
zoneSize.x = rs.getFloat("xRadius");
|
||||
zoneSize.y = rs.getFloat("zRadius");
|
||||
ZoneManager._zone_size_data.put(loadNum, zoneSize);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean DELETE_ZONE(final Zone zone) {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `object` WHERE `UID` = ? AND `type` = 'zone'")) {
|
||||
|
||||
preparedStatement.setInt(1, zone.getObjectUUID());
|
||||
|
||||
return (preparedStatement.executeUpdate() > 0);
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user