Browse Source

Garbage cleanup in SetZone().

Package reformat.
master
MagicBot 2 years ago
parent
commit
6dd7315786
  1. 338
      src/engine/db/handlers/dbAccountHandler.java
  2. 86
      src/engine/db/handlers/dbBaseClassHandler.java
  3. 36
      src/engine/db/handlers/dbBuildingLocationHandler.java
  4. 204
      src/engine/db/handlers/dbCharacterPowerHandler.java
  5. 132
      src/engine/db/handlers/dbCharacterRuneHandler.java
  6. 4
      src/engine/db/handlers/dbCharacterSkillHandler.java
  7. 2
      src/engine/db/handlers/dbEffectsBaseHandler.java
  8. 30
      src/engine/db/handlers/dbEffectsResourceCostHandler.java
  9. 70
      src/engine/db/handlers/dbEnchantmentHandler.java
  10. 933
      src/engine/db/handlers/dbGuildHandler.java
  11. 835
      src/engine/db/handlers/dbHandlerBase.java
  12. 2
      src/engine/db/handlers/dbItemBaseHandler.java
  13. 724
      src/engine/db/handlers/dbItemHandler.java
  14. 30
      src/engine/db/handlers/dbKitHandler.java
  15. 30
      src/engine/db/handlers/dbMenuHandler.java
  16. 150
      src/engine/db/handlers/dbMineHandler.java
  17. 240
      src/engine/db/handlers/dbMobBaseHandler.java
  18. 316
      src/engine/db/handlers/dbMobHandler.java
  19. 744
      src/engine/db/handlers/dbPlayerCharacterHandler.java
  20. 30
      src/engine/db/handlers/dbRuneBaseAttributeHandler.java
  21. 91
      src/engine/db/handlers/dbRuneBaseEffectHandler.java
  22. 224
      src/engine/db/handlers/dbRuneBaseHandler.java
  23. 44
      src/engine/db/handlers/dbShrineHandler.java
  24. 215
      src/engine/db/handlers/dbSkillBaseHandler.java
  25. 36
      src/engine/db/handlers/dbVendorDialogHandler.java
  26. 19
      src/engine/db/handlers/dbZoneHandler.java
  27. 26
      src/engine/gameManager/ZoneManager.java
  28. 261
      src/engine/objects/Zone.java

338
src/engine/db/handlers/dbAccountHandler.java

@ -25,249 +25,249 @@ import java.util.ArrayList;
public class dbAccountHandler extends dbHandlerBase { public class dbAccountHandler extends dbHandlerBase {
public dbAccountHandler() { public dbAccountHandler() {
this.localClass = Account.class; this.localClass = Account.class;
this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
} }
public Account GET_ACCOUNT(int accountID) { public Account GET_ACCOUNT(int accountID) {
Account account; Account account;
if (accountID == 0) if (accountID == 0)
return null; return null;
account = (Account) DbManager.getFromCache(GameObjectType.Account, accountID); account = (Account) DbManager.getFromCache(GameObjectType.Account, accountID);
if (account != null) if (account != null)
return account; return account;
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `obj_account` WHERE `UID`=?")) { PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `obj_account` WHERE `UID`=?")) {
preparedStatement.setLong(1, accountID); preparedStatement.setLong(1, accountID);
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
account = (Account) getObjectFromRs(rs); account = (Account) getObjectFromRs(rs);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
if (account != null) if (account != null)
account.runAfterLoad(); account.runAfterLoad();
return account; return account;
} }
public void WRITE_ADMIN_LOG(String adminName, String logEntry) { public void WRITE_ADMIN_LOG(String adminName, String logEntry) {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO dyn_admin_log(`dateTime`, `charName`, `eventString`)" PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO dyn_admin_log(`dateTime`, `charName`, `eventString`)"
+ " VALUES (?, ?, ?)")) { + " VALUES (?, ?, ?)")) {
preparedStatement.setTimestamp(1, new java.sql.Timestamp(System.currentTimeMillis())); preparedStatement.setTimestamp(1, new java.sql.Timestamp(System.currentTimeMillis()));
preparedStatement.setString(2, adminName); preparedStatement.setString(2, adminName);
preparedStatement.setString(3, logEntry); preparedStatement.setString(3, logEntry);
preparedStatement.execute(); preparedStatement.execute();
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
} }
public void SET_TRASH(String machineID) { public void SET_TRASH(String machineID) {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO dyn_trash(`machineID`, `count`)" PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO dyn_trash(`machineID`, `count`)"
+ " VALUES (?, 1) ON DUPLICATE KEY UPDATE `count` = `count` + 1;")) { + " VALUES (?, 1) ON DUPLICATE KEY UPDATE `count` = `count` + 1;")) {
preparedStatement.setString(1, machineID); preparedStatement.setString(1, machineID);
preparedStatement.execute(); preparedStatement.execute();
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
} }
public ArrayList<String> GET_TRASH_LIST() { public ArrayList<String> GET_TRASH_LIST() {
ArrayList<String> machineList = new ArrayList<>(); ArrayList<String> machineList = new ArrayList<>();
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("select `machineID` from `dyn_trash`")) { PreparedStatement preparedStatement = connection.prepareStatement("select `machineID` from `dyn_trash`")) {
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) while (rs.next())
machineList.add(rs.getString(1)); machineList.add(rs.getString(1));
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return machineList; return machineList;
} }
public void DELETE_VAULT_FOR_ACCOUNT(final int accountID) { public void DELETE_VAULT_FOR_ACCOUNT(final int accountID) {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `object` WHERE `parent`=? && `type`='item'")) { PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `object` WHERE `parent`=? && `type`='item'")) {
preparedStatement.setLong(1, accountID); preparedStatement.setLong(1, accountID);
preparedStatement.execute(); preparedStatement.execute();
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
} }
public ArrayList<PlayerCharacter> GET_ALL_CHARS_FOR_MACHINE(String machineID) { public ArrayList<PlayerCharacter> GET_ALL_CHARS_FOR_MACHINE(String machineID) {
ArrayList<PlayerCharacter> trashList = new ArrayList<>(); ArrayList<PlayerCharacter> trashList = new ArrayList<>();
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("select DISTINCT UID from object \n" + PreparedStatement preparedStatement = connection.prepareStatement("select DISTINCT UID from object \n" +
"where parent IN (select AccountID from dyn_login_history " + "where parent IN (select AccountID from dyn_login_history " +
" WHERE`machineID`=?)")) { " WHERE`machineID`=?)")) {
preparedStatement.setString(1, machineID); preparedStatement.setString(1, machineID);
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) { while (rs.next()) {
PlayerCharacter trashPlayer; PlayerCharacter trashPlayer;
int playerID; int playerID;
playerID = rs.getInt(1); playerID = rs.getInt(1);
trashPlayer = PlayerCharacter.getPlayerCharacter(playerID); trashPlayer = PlayerCharacter.getPlayerCharacter(playerID);
if (trashPlayer == null) if (trashPlayer == null)
continue; continue;
if (trashPlayer.isDeleted() == false) if (trashPlayer.isDeleted() == false)
trashList.add(trashPlayer); trashList.add(trashPlayer);
} }
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return trashList; return trashList;
} }
public void CLEAR_TRASH_TABLE() { public void CLEAR_TRASH_TABLE() {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM dyn_trash")) { PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM dyn_trash")) {
preparedStatement.execute(); preparedStatement.execute();
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
} }
public void CREATE_SINGLE(String accountName, String password) { public void CREATE_SINGLE(String accountName, String password) {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("CALL singleAccountCreate(?,?)")) { PreparedStatement preparedStatement = connection.prepareStatement("CALL singleAccountCreate(?,?)")) {
preparedStatement.setString(1, accountName); preparedStatement.setString(1, accountName);
preparedStatement.setString(2, password); preparedStatement.setString(2, password);
preparedStatement.execute(); preparedStatement.execute();
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
} }
public Account GET_ACCOUNT(String uname) { public Account GET_ACCOUNT(String uname) {
Account account = null; Account account = null;
if (Account.AccountsMap.get(uname) != null) if (Account.AccountsMap.get(uname) != null)
return this.GET_ACCOUNT(Account.AccountsMap.get(uname)); return this.GET_ACCOUNT(Account.AccountsMap.get(uname));
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `obj_account` WHERE `acct_uname`=?")) { PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `obj_account` WHERE `acct_uname`=?")) {
preparedStatement.setString(1, uname); preparedStatement.setString(1, uname);
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
account = (Account) getObjectFromRs(rs); account = (Account) getObjectFromRs(rs);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
if (account != null) { if (account != null) {
account.runAfterLoad(); account.runAfterLoad();
if (ConfigManager.serverType.equals(Enum.ServerType.LOGINSERVER)) if (ConfigManager.serverType.equals(Enum.ServerType.LOGINSERVER))
Account.AccountsMap.put(uname, account.getObjectUUID()); Account.AccountsMap.put(uname, account.getObjectUUID());
} }
return account; return account;
} }
public void SET_ACCOUNT_LOGIN(final Account acc, String playerName, final String ip, final String machineID) { 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) if (acc.getObjectUUID() == 0 || ip == null || ip.length() == 0)
return; return;
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO dyn_login_history(`AccountID`, `accountName`, `characterName`, `ip`, `machineID`, `timeStamp`)" PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO dyn_login_history(`AccountID`, `accountName`, `characterName`, `ip`, `machineID`, `timeStamp`)"
+ " VALUES (?, ?, ?, ?, ?, ?)")) { + " VALUES (?, ?, ?, ?, ?, ?)")) {
preparedStatement.setInt(1, acc.getObjectUUID()); preparedStatement.setInt(1, acc.getObjectUUID());
preparedStatement.setString(2, acc.getUname()); preparedStatement.setString(2, acc.getUname());
preparedStatement.setString(3, playerName); preparedStatement.setString(3, playerName);
preparedStatement.setString(4, ip); preparedStatement.setString(4, ip);
preparedStatement.setString(5, machineID); preparedStatement.setString(5, machineID);
preparedStatement.setTimestamp(6, new java.sql.Timestamp(System.currentTimeMillis())); preparedStatement.setTimestamp(6, new java.sql.Timestamp(System.currentTimeMillis()));
preparedStatement.execute(); preparedStatement.execute();
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
} }
public void updateDatabase(final Account acc) { public void updateDatabase(final Account acc) {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_account` SET `acct_passwd`=?, " PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_account` SET `acct_passwd`=?, "
+ " `acct_lastCharUID`=?, `acct_salt`=?, `discordAccount`=?, " + + " `acct_lastCharUID`=?, `acct_salt`=?, `discordAccount`=?, " +
" status = ? WHERE `UID`=?")) { " status = ? WHERE `UID`=?")) {
preparedStatement.setString(1, acc.getPasswd()); preparedStatement.setString(1, acc.getPasswd());
preparedStatement.setInt(2, acc.getLastCharIDUsed()); preparedStatement.setInt(2, acc.getLastCharIDUsed());
preparedStatement.setString(3, acc.getSalt()); preparedStatement.setString(3, acc.getSalt());
preparedStatement.setString(4, acc.discordAccount); preparedStatement.setString(4, acc.discordAccount);
preparedStatement.setString(5, acc.status.name()); preparedStatement.setString(5, acc.status.name());
preparedStatement.setInt(6, acc.getObjectUUID()); preparedStatement.setInt(6, acc.getObjectUUID());
preparedStatement.execute(); preparedStatement.execute();
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
} }
public void INVALIDATE_LOGIN_CACHE(long accountUID, String objectType) { public void INVALIDATE_LOGIN_CACHE(long accountUID, String objectType) {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("INSERT IGNORE INTO login_cachelist (`UID`, `type`) VALUES(?,?);")) { PreparedStatement preparedStatement = connection.prepareStatement("INSERT IGNORE INTO login_cachelist (`UID`, `type`) VALUES(?,?);")) {
preparedStatement.setLong(1, accountUID); preparedStatement.setLong(1, accountUID);
preparedStatement.setString(2, objectType); preparedStatement.setString(2, objectType);
preparedStatement.execute(); preparedStatement.execute();
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
} }
} }

86
src/engine/db/handlers/dbBaseClassHandler.java

@ -23,69 +23,69 @@ import java.util.ArrayList;
public class dbBaseClassHandler extends dbHandlerBase { public class dbBaseClassHandler extends dbHandlerBase {
public dbBaseClassHandler() { public dbBaseClassHandler() {
this.localClass = BaseClass.class; this.localClass = BaseClass.class;
this.localObjectType = Enum.GameObjectType.BaseClass; this.localObjectType = Enum.GameObjectType.BaseClass;
} }
public BaseClass GET_BASE_CLASS(final int id) { public BaseClass GET_BASE_CLASS(final int id) {
if (id == 0) if (id == 0)
return null; return null;
BaseClass baseClass = (BaseClass) DbManager.getFromCache(GameObjectType.BaseClass, id); BaseClass baseClass = (BaseClass) DbManager.getFromCache(GameObjectType.BaseClass, id);
if (baseClass != null) if (baseClass != null)
return baseClass; return baseClass;
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `obj_account` WHERE `UID`=?")) { PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `obj_account` WHERE `UID`=?")) {
preparedStatement.setLong(1, id); preparedStatement.setLong(1, id);
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
baseClass = (BaseClass) getObjectFromRs(rs); baseClass = (BaseClass) getObjectFromRs(rs);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return baseClass; return baseClass;
} }
public ArrayList<BaseClass> GET_BASECLASS_FOR_RACE(final int id) { public ArrayList<BaseClass> GET_BASECLASS_FOR_RACE(final int id) {
ArrayList<BaseClass> baseClasses = new ArrayList<>(); ArrayList<BaseClass> baseClasses = new ArrayList<>();
try (Connection connection = DbManager.getConnection(); 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 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); preparedStatement.setInt(1, id);
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
baseClasses = getObjectsFromRs(rs, 20); baseClasses = getObjectsFromRs(rs, 20);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return baseClasses; return baseClasses;
} }
public ArrayList<BaseClass> GET_ALL_BASE_CLASSES() { public ArrayList<BaseClass> GET_ALL_BASE_CLASSES() {
ArrayList<BaseClass> baseClasses = new ArrayList<>(); ArrayList<BaseClass> baseClasses = new ArrayList<>();
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_baseclass`;")) { PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_baseclass`;")) {
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
baseClasses = getObjectsFromRs(rs, 20); baseClasses = getObjectsFromRs(rs, 20);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return baseClasses; return baseClasses;
} }
} }

36
src/engine/db/handlers/dbBuildingLocationHandler.java

@ -21,29 +21,29 @@ import java.util.ArrayList;
public class dbBuildingLocationHandler extends dbHandlerBase { public class dbBuildingLocationHandler extends dbHandlerBase {
public dbBuildingLocationHandler() { public dbBuildingLocationHandler() {
this.localClass = BuildingLocation.class; this.localClass = BuildingLocation.class;
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
} }
public ArrayList<BuildingLocation> LOAD_BUILDING_LOCATIONS() { public ArrayList<BuildingLocation> LOAD_BUILDING_LOCATIONS() {
ArrayList<BuildingLocation> buildingLocations = new ArrayList<>(); ArrayList<BuildingLocation> buildingLocations = new ArrayList<>();
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("select * from static_building_location " + PreparedStatement preparedStatement = connection.prepareStatement("select * from static_building_location " +
"where type = 6 or type = 8 " + "where type = 6 or type = 8 " +
"GROUP BY buildingID, slot " + "GROUP BY buildingID, slot " +
"ORDER BY buildingID, slot ASC;")) { "ORDER BY buildingID, slot ASC;")) {
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
buildingLocations = getObjectsFromRs(rs, 20); buildingLocations = getObjectsFromRs(rs, 20);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
return buildingLocations; return buildingLocations;
} }
return buildingLocations; return buildingLocations;
} }
} }

204
src/engine/db/handlers/dbCharacterPowerHandler.java

@ -24,149 +24,149 @@ import java.util.concurrent.ConcurrentHashMap;
public class dbCharacterPowerHandler extends dbHandlerBase { public class dbCharacterPowerHandler extends dbHandlerBase {
public dbCharacterPowerHandler() { public dbCharacterPowerHandler() {
this.localClass = CharacterPower.class; this.localClass = CharacterPower.class;
this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
} }
public CharacterPower ADD_CHARACTER_POWER(CharacterPower toAdd) { public CharacterPower ADD_CHARACTER_POWER(CharacterPower toAdd) {
CharacterPower characterPower = null; CharacterPower characterPower = null;
if (CharacterPower.getOwner(toAdd) == null || toAdd.getPower() == null) { if (CharacterPower.getOwner(toAdd) == null || toAdd.getPower() == null) {
Logger.error("dbCharacterSkillHandler.ADD_Power", toAdd.getObjectUUID() + " missing owner or powersBase"); Logger.error("dbCharacterSkillHandler.ADD_Power", toAdd.getObjectUUID() + " missing owner or powersBase");
return null; return null;
} }
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_character_power` (`CharacterID`, `powersBaseToken`, `trains`) VALUES (?, ?, ?);")) { PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_character_power` (`CharacterID`, `powersBaseToken`, `trains`) VALUES (?, ?, ?);")) {
preparedStatement.setLong(1, CharacterPower.getOwner(toAdd).getObjectUUID()); preparedStatement.setLong(1, CharacterPower.getOwner(toAdd).getObjectUUID());
preparedStatement.setInt(2, toAdd.getPower().getToken()); preparedStatement.setInt(2, toAdd.getPower().getToken());
preparedStatement.setInt(3, toAdd.getTrains()); preparedStatement.setInt(3, toAdd.getTrains());
preparedStatement.executeUpdate(); preparedStatement.executeUpdate();
ResultSet rs = preparedStatement.getGeneratedKeys(); ResultSet rs = preparedStatement.getGeneratedKeys();
if (rs.next()) if (rs.next())
characterPower = GET_CHARACTER_POWER(rs.getInt(1)); characterPower = GET_CHARACTER_POWER(rs.getInt(1));
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
return null; return null;
} }
return characterPower; return characterPower;
} }
public int DELETE_CHARACTER_POWER(final int objectUUID) { public int DELETE_CHARACTER_POWER(final int objectUUID) {
int rowCount = 0; int rowCount = 0;
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_character_power` WHERE `UID` = ?")) { PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_character_power` WHERE `UID` = ?")) {
preparedStatement.setLong(1, objectUUID); preparedStatement.setLong(1, objectUUID);
rowCount = preparedStatement.executeUpdate(); rowCount = preparedStatement.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return rowCount; return rowCount;
} }
public CharacterPower GET_CHARACTER_POWER(int objectUUID) { public CharacterPower GET_CHARACTER_POWER(int objectUUID) {
CharacterPower characterPower = (CharacterPower) DbManager.getFromCache(Enum.GameObjectType.CharacterPower, objectUUID); CharacterPower characterPower = (CharacterPower) DbManager.getFromCache(Enum.GameObjectType.CharacterPower, objectUUID);
if (characterPower != null) if (characterPower != null)
return characterPower; return characterPower;
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_power` WHERE `UID` = ?")) { PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_power` WHERE `UID` = ?")) {
preparedStatement.setLong(1, objectUUID); preparedStatement.setLong(1, objectUUID);
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
characterPower = (CharacterPower) getObjectFromRs(rs); characterPower = (CharacterPower) getObjectFromRs(rs);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return characterPower; return characterPower;
} }
public ConcurrentHashMap<Integer, CharacterPower> GET_POWERS_FOR_CHARACTER(PlayerCharacter pc) { 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); ConcurrentHashMap<Integer, CharacterPower> powers = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
int objectUUID = pc.getObjectUUID(); int objectUUID = pc.getObjectUUID();
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_power` WHERE CharacterID = ?")) { PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_power` WHERE CharacterID = ?")) {
preparedStatement.setLong(1, (long) objectUUID); preparedStatement.setLong(1, objectUUID);
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) { while (rs.next()) {
CharacterPower cp = new CharacterPower(rs, pc); CharacterPower cp = new CharacterPower(rs, pc);
if (cp.getPower() != null) if (cp.getPower() != null)
powers.put(cp.getPower().getToken(), cp); powers.put(cp.getPower().getToken(), cp);
} }
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return powers; return powers;
} }
public void UPDATE_TRAINS(final CharacterPower characterPower) { public void UPDATE_TRAINS(final CharacterPower characterPower) {
//skip update if nothing changed //skip update if nothing changed
if (!characterPower.isTrained()) if (!characterPower.isTrained())
return; return;
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_character_power` SET `trains`=? WHERE `UID`=?")) { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_character_power` SET `trains`=? WHERE `UID`=?")) {
preparedStatement.setShort(1, (short) characterPower.getTrains()); preparedStatement.setShort(1, (short) characterPower.getTrains());
preparedStatement.setInt(2, characterPower.getObjectUUID()); preparedStatement.setInt(2, characterPower.getObjectUUID());
preparedStatement.execute(); preparedStatement.execute();
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
characterPower.setTrained(false); characterPower.setTrained(false);
} }
public void updateDatabase(final CharacterPower pow) { public void updateDatabase(final CharacterPower pow) {
if (pow.getPower() == null) { if (pow.getPower() == null) {
Logger.error("Failed to find powersBase for Power " + pow.getObjectUUID()); Logger.error("Failed to find powersBase for Power " + pow.getObjectUUID());
return; return;
} }
if (CharacterPower.getOwner(pow) == null) { if (CharacterPower.getOwner(pow) == null) {
Logger.error("Failed to find owner for Power " + pow.getObjectUUID()); Logger.error("Failed to find owner for Power " + pow.getObjectUUID());
return; return;
} }
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_character_power` SET `PowersBaseToken`=?, `CharacterID`=?, `trains`=? WHERE `UID`=?")) { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_character_power` SET `PowersBaseToken`=?, `CharacterID`=?, `trains`=? WHERE `UID`=?")) {
preparedStatement.setInt(1, pow.getPower().getToken()); preparedStatement.setInt(1, pow.getPower().getToken());
preparedStatement.setInt(2, CharacterPower.getOwner(pow).getObjectUUID()); preparedStatement.setInt(2, CharacterPower.getOwner(pow).getObjectUUID());
preparedStatement.setShort(3, (short) pow.getTrains()); preparedStatement.setShort(3, (short) pow.getTrains());
preparedStatement.setInt(4, pow.getObjectUUID()); preparedStatement.setInt(4, pow.getObjectUUID());
preparedStatement.execute(); preparedStatement.execute();
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
pow.setTrained(false); pow.setTrained(false);
} }
} }

132
src/engine/db/handlers/dbCharacterRuneHandler.java

@ -22,103 +22,103 @@ import java.util.ArrayList;
public class dbCharacterRuneHandler extends dbHandlerBase { public class dbCharacterRuneHandler extends dbHandlerBase {
public dbCharacterRuneHandler() { public dbCharacterRuneHandler() {
this.localClass = CharacterRune.class; this.localClass = CharacterRune.class;
this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
} }
public CharacterRune ADD_CHARACTER_RUNE(final CharacterRune toAdd) { public CharacterRune ADD_CHARACTER_RUNE(final CharacterRune toAdd) {
CharacterRune characterRune = null; CharacterRune characterRune = null;
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_character_rune` (`CharacterID`, `RuneBaseID`) VALUES (?, ?);")) { PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_character_rune` (`CharacterID`, `RuneBaseID`) VALUES (?, ?);")) {
preparedStatement.setLong(1, toAdd.getPlayerID()); preparedStatement.setLong(1, toAdd.getPlayerID());
preparedStatement.setInt(2, toAdd.getRuneBaseID()); preparedStatement.setInt(2, toAdd.getRuneBaseID());
preparedStatement.executeUpdate(); preparedStatement.executeUpdate();
ResultSet rs = preparedStatement.getGeneratedKeys(); ResultSet rs = preparedStatement.getGeneratedKeys();
if (rs.next()) if (rs.next())
characterRune = GET_CHARACTER_RUNE(rs.getInt(1)); characterRune = GET_CHARACTER_RUNE(rs.getInt(1));
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return characterRune; return characterRune;
} }
public CharacterRune GET_CHARACTER_RUNE(int runeID) { public CharacterRune GET_CHARACTER_RUNE(int runeID) {
CharacterRune characterRune = (CharacterRune) DbManager.getFromCache(Enum.GameObjectType.CharacterRune, runeID); CharacterRune characterRune = (CharacterRune) DbManager.getFromCache(Enum.GameObjectType.CharacterRune, runeID);
if (characterRune != null) if (characterRune != null)
return characterRune; return characterRune;
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_rune` WHERE `UID`=?")) { PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_rune` WHERE `UID`=?")) {
preparedStatement.setInt(1, runeID); preparedStatement.setInt(1, runeID);
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
characterRune = (CharacterRune) getObjectFromRs(rs); characterRune = (CharacterRune) getObjectFromRs(rs);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return characterRune; return characterRune;
} }
public boolean DELETE_CHARACTER_RUNE(final CharacterRune characterRune) { public boolean DELETE_CHARACTER_RUNE(final CharacterRune characterRune) {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_character_rune` WHERE `UID`=?;")) { PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_character_rune` WHERE `UID`=?;")) {
preparedStatement.setLong(1, characterRune.getObjectUUID()); preparedStatement.setLong(1, characterRune.getObjectUUID());
return (preparedStatement.executeUpdate() > 0); return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return false; return false;
} }
public ArrayList<CharacterRune> GET_RUNES_FOR_CHARACTER(final int characterId) { public ArrayList<CharacterRune> GET_RUNES_FOR_CHARACTER(final int characterId) {
ArrayList<CharacterRune> characterRunes = new ArrayList<>(); ArrayList<CharacterRune> characterRunes = new ArrayList<>();
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_rune` WHERE `CharacterID` = ?")) { PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_rune` WHERE `CharacterID` = ?")) {
preparedStatement.setInt(1, characterId); preparedStatement.setInt(1, characterId);
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
characterRunes = getObjectsFromRs(rs, 10); characterRunes = getObjectsFromRs(rs, 10);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return characterRunes; return characterRunes;
} }
public void updateDatabase(final CharacterRune characterRune) { public void updateDatabase(final CharacterRune characterRune) {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_character_rune` SET `CharacterID`=?, `RuneBaseID`=? WHERE `UID` = ?")) { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_character_rune` SET `CharacterID`=?, `RuneBaseID`=? WHERE `UID` = ?")) {
preparedStatement.setInt(1, characterRune.getPlayerID()); preparedStatement.setInt(1, characterRune.getPlayerID());
preparedStatement.setInt(2, characterRune.getRuneBaseID()); preparedStatement.setInt(2, characterRune.getRuneBaseID());
preparedStatement.setLong(3, (long) characterRune.getObjectUUID()); preparedStatement.setLong(3, characterRune.getObjectUUID());
preparedStatement.execute(); preparedStatement.execute();
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
} }
} }

4
src/engine/db/handlers/dbCharacterSkillHandler.java

@ -134,7 +134,7 @@ public class dbCharacterSkillHandler extends dbHandlerBase {
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_character_skill` SET `trains`=? WHERE `UID` = ?")) { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_character_skill` SET `trains`=? WHERE `UID` = ?")) {
preparedStatement.setShort(1, (short) characterSkill.getNumTrains()); preparedStatement.setShort(1, (short) characterSkill.getNumTrains());
preparedStatement.setLong(2, (long) characterSkill.getObjectUUID()); preparedStatement.setLong(2, characterSkill.getObjectUUID());
if (preparedStatement.executeUpdate() != 0) if (preparedStatement.executeUpdate() != 0)
characterSkill.syncTrains(); characterSkill.syncTrains();
@ -162,7 +162,7 @@ public class dbCharacterSkillHandler extends dbHandlerBase {
preparedStatement.setInt(1, characterSkill.getSkillsBase().getObjectUUID()); preparedStatement.setInt(1, characterSkill.getSkillsBase().getObjectUUID());
preparedStatement.setInt(2, CharacterSkill.GetOwner(characterSkill).getObjectUUID()); preparedStatement.setInt(2, CharacterSkill.GetOwner(characterSkill).getObjectUUID());
preparedStatement.setShort(3, (short) characterSkill.getNumTrains()); preparedStatement.setShort(3, (short) characterSkill.getNumTrains());
preparedStatement.setLong(4, (long) characterSkill.getObjectUUID()); preparedStatement.setLong(4, characterSkill.getObjectUUID());
if (preparedStatement.executeUpdate() != 0) if (preparedStatement.executeUpdate() != 0)
characterSkill.syncTrains(); characterSkill.syncTrains();

2
src/engine/db/handlers/dbEffectsBaseHandler.java

@ -25,7 +25,7 @@ import java.util.HashSet;
public class dbEffectsBaseHandler extends dbHandlerBase { public class dbEffectsBaseHandler extends dbHandlerBase {
public dbEffectsBaseHandler() { public dbEffectsBaseHandler() {
} }

30
src/engine/db/handlers/dbEffectsResourceCostHandler.java

@ -21,27 +21,27 @@ import java.util.ArrayList;
public class dbEffectsResourceCostHandler extends dbHandlerBase { public class dbEffectsResourceCostHandler extends dbHandlerBase {
public dbEffectsResourceCostHandler() { public dbEffectsResourceCostHandler() {
this.localClass = EffectsResourceCosts.class; this.localClass = EffectsResourceCosts.class;
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
} }
public ArrayList<EffectsResourceCosts> GET_ALL_EFFECT_RESOURCES(String idString) { public ArrayList<EffectsResourceCosts> GET_ALL_EFFECT_RESOURCES(String idString) {
ArrayList<EffectsResourceCosts> effectsResourceCosts = new ArrayList<>(); ArrayList<EffectsResourceCosts> effectsResourceCosts = new ArrayList<>();
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_power_effectcost` WHERE `IDString` = ?")) { PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_power_effectcost` WHERE `IDString` = ?")) {
preparedStatement.setString(1, idString); preparedStatement.setString(1, idString);
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
effectsResourceCosts = getObjectsFromRs(rs, 1000); effectsResourceCosts = getObjectsFromRs(rs, 1000);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return effectsResourceCosts; return effectsResourceCosts;
} }
} }

70
src/engine/db/handlers/dbEnchantmentHandler.java

@ -21,55 +21,55 @@ import java.util.concurrent.ConcurrentHashMap;
public class dbEnchantmentHandler extends dbHandlerBase { public class dbEnchantmentHandler extends dbHandlerBase {
public ConcurrentHashMap<String, Integer> GET_ENCHANTMENTS_FOR_ITEM(final int id) { 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); ConcurrentHashMap<String, Integer> enchants = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_item_enchantment` WHERE `ItemID`=?;")) { PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_item_enchantment` WHERE `ItemID`=?;")) {
preparedStatement.setLong(1, id); preparedStatement.setLong(1, id);
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) while (rs.next())
enchants.put(rs.getString("powerAction"), rs.getInt("rank")); enchants.put(rs.getString("powerAction"), rs.getInt("rank"));
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return enchants; return enchants;
} }
public boolean CREATE_ENCHANTMENT_FOR_ITEM(long itemID, String powerAction, int rank) { public boolean CREATE_ENCHANTMENT_FOR_ITEM(long itemID, String powerAction, int rank) {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_item_enchantment` (`itemID`, `powerAction`, `rank`) VALUES (?, ?, ?);")) { PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_item_enchantment` (`itemID`, `powerAction`, `rank`) VALUES (?, ?, ?);")) {
preparedStatement.setLong(1, itemID); preparedStatement.setLong(1, itemID);
preparedStatement.setString(2, powerAction); preparedStatement.setString(2, powerAction);
preparedStatement.setInt(3, rank); preparedStatement.setInt(3, rank);
return (preparedStatement.executeUpdate() > 0); return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return false; return false;
} }
public boolean CLEAR_ENCHANTMENTS(long itemID) { public boolean CLEAR_ENCHANTMENTS(long itemID) {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_item_enchantment` WHERE `itemID`=?;")) { PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_item_enchantment` WHERE `itemID`=?;")) {
preparedStatement.setLong(1, itemID); preparedStatement.setLong(1, itemID);
return (preparedStatement.executeUpdate() > 0); return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return false; return false;
} }
} }

933
src/engine/db/handlers/dbGuildHandler.java

File diff suppressed because it is too large Load Diff

835
src/engine/db/handlers/dbHandlerBase.java

@ -25,455 +25,456 @@ import java.util.HashSet;
public abstract class dbHandlerBase { public abstract class dbHandlerBase {
/* protected final ThreadLocal<CallableStatement> callableStatement = new ThreadLocal<>();
* CallableStatements handled below this line! protected final ThreadLocal<Connection> connection = new ThreadLocal<>();
*/ /*
protected Class<? extends AbstractGameObject> localClass = null; * CallableStatements handled below this line!
protected GameObjectType localObjectType; */
protected final ThreadLocal<CallableStatement> callableStatement = new ThreadLocal<>(); protected Class<? extends AbstractGameObject> localClass = null;
protected final ThreadLocal<Connection> connection = new ThreadLocal<>(); protected GameObjectType localObjectType;
protected final void prepareCallable(final String sql) { protected final void prepareCallable(final String sql) {
try { try {
this.connection.set(DbManager.getConnection()); this.connection.set(DbManager.getConnection());
this.callableStatement.set(this.connection.get().prepareCall(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY)); this.callableStatement.set(this.connection.get().prepareCall(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY));
} catch (SQLException e) { } catch (SQLException e) {
Logger.error("DbManager.getConn", e); Logger.error("DbManager.getConn", e);
Logger.error("SQL Error number: " + e.getErrorCode()); Logger.error("SQL Error number: " + e.getErrorCode());
} }
} }
protected final void setInt(int parameterIndex, int value) { protected final void setInt(int parameterIndex, int value) {
try { try {
this.callableStatement.get().setInt(parameterIndex, value); this.callableStatement.get().setInt(parameterIndex, value);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error("SQL Error number: " + e.getErrorCode()); Logger.error("SQL Error number: " + e.getErrorCode());
} }
} }
protected final void setLong(int parameterIndex, long value) { protected final void setLong(int parameterIndex, long value) {
try { try {
this.callableStatement.get().setLong(parameterIndex, value); this.callableStatement.get().setLong(parameterIndex, value);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error("SQL Error number: " + e.getErrorCode()); Logger.error("SQL Error number: " + e.getErrorCode());
} }
} }
protected final void setFloat(int parameterIndex, float value) { protected final void setFloat(int parameterIndex, float value) {
try { try {
this.callableStatement.get().setFloat(parameterIndex, value); this.callableStatement.get().setFloat(parameterIndex, value);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error("SQL Error number: " + e.getErrorCode()); Logger.error("SQL Error number: " + e.getErrorCode());
} }
} }
protected final void setShort(int parameterIndex, short value) { protected final void setShort(int parameterIndex, short value) {
try { try {
this.callableStatement.get().setShort(parameterIndex, value); this.callableStatement.get().setShort(parameterIndex, value);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error("SQL Error number: " + e.getErrorCode()); Logger.error("SQL Error number: " + e.getErrorCode());
} }
} }
protected final void setString(int parameterIndex, String value) { protected final void setString(int parameterIndex, String value) {
try { try {
this.callableStatement.get().setString(parameterIndex, value); this.callableStatement.get().setString(parameterIndex, value);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error("SQL Error number: " + e.getErrorCode()); Logger.error("SQL Error number: " + e.getErrorCode());
} }
} }
protected final void setByte(int parameterIndex, byte value) { protected final void setByte(int parameterIndex, byte value) {
try { try {
this.callableStatement.get().setByte(parameterIndex, value); this.callableStatement.get().setByte(parameterIndex, value);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error("SQL Error number: " + e.getErrorCode()); Logger.error("SQL Error number: " + e.getErrorCode());
} }
} }
protected final void setBoolean(int parameterIndex, boolean value) { protected final void setBoolean(int parameterIndex, boolean value) {
try { try {
this.callableStatement.get().setBoolean(parameterIndex, value); this.callableStatement.get().setBoolean(parameterIndex, value);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error("SQL Error number: " + e.getErrorCode()); Logger.error("SQL Error number: " + e.getErrorCode());
} }
} }
protected final void setNULL(int parameterIndex, int type) { protected final void setNULL(int parameterIndex, int type) {
try { try {
this.callableStatement.get().setNull(parameterIndex, type); this.callableStatement.get().setNull(parameterIndex, type);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error("SQL Error number: " + e.getErrorCode()); Logger.error("SQL Error number: " + e.getErrorCode());
} }
} }
protected final void setLocalDateTime(int parameterIndex, LocalDateTime localDateTime) { protected final void setLocalDateTime(int parameterIndex, LocalDateTime localDateTime) {
try { try {
this.callableStatement.get().setTimestamp(parameterIndex, Timestamp.valueOf(localDateTime)); this.callableStatement.get().setTimestamp(parameterIndex, Timestamp.valueOf(localDateTime));
} catch (SQLException e) { } catch (SQLException e) {
Logger.error("SQL Error number: " + e.getErrorCode()); Logger.error("SQL Error number: " + e.getErrorCode());
} }
} }
protected final void setTimeStamp(int parameterIndex, long time) { protected final void setTimeStamp(int parameterIndex, long time) {
try { try {
this.callableStatement.get().setTimestamp(parameterIndex, new java.sql.Timestamp(time)); this.callableStatement.get().setTimestamp(parameterIndex, new java.sql.Timestamp(time));
} catch (SQLException e) { } catch (SQLException e) {
Logger.error("SQL Error number: " + e.getErrorCode()); Logger.error("SQL Error number: " + e.getErrorCode());
} }
} }
protected final boolean execute() { protected final boolean execute() {
try { try {
return this.callableStatement.get().execute(); return this.callableStatement.get().execute();
} catch (SQLException e) { } catch (SQLException e) {
Logger.error("SQL Error number: " + e.getErrorCode()); Logger.error("SQL Error number: " + e.getErrorCode());
logSQLCommand(); logSQLCommand();
} }
return false; return false;
} }
protected final ResultSet executeQuery() { protected final ResultSet executeQuery() {
try { try {
return this.callableStatement.get().executeQuery(); return this.callableStatement.get().executeQuery();
} catch (SQLException e) { } catch (SQLException e) {
Logger.error("SQL Error number: " + e.getErrorCode()); Logger.error("SQL Error number: " + e.getErrorCode());
logSQLCommand(); logSQLCommand();
} }
return null; return null;
} }
protected final int executeUpdate() { protected final int executeUpdate() {
return executeUpdate(true); return executeUpdate(true);
} }
protected final int executeUpdate(boolean close) { protected final int executeUpdate(boolean close) {
try { try {
return this.callableStatement.get().executeUpdate(); return this.callableStatement.get().executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
Logger.error("SQL Error number: " + e.getErrorCode()); Logger.error("SQL Error number: " + e.getErrorCode());
logSQLCommand(); logSQLCommand();
} finally { } finally {
if (close) if (close)
closeCallable(); closeCallable();
} }
return 0; return 0;
} }
protected final void logSQLCommand() { protected final void logSQLCommand() {
try { try {
Logger.error("Failed SQL Command: " + this.callableStatement.get().toString()); Logger.error("Failed SQL Command: " + this.callableStatement.get().toString());
} catch (Exception e) { } catch (Exception e) {
} }
} }
// Common return values from the database when calling stored procedures, abstracted to this layer // Common return values from the database when calling stored procedures, abstracted to this layer
protected final String getResult(){ protected final String getResult() {
try { try {
ResultSet rs = this.executeQuery(); ResultSet rs = this.executeQuery();
if (rs.next() && !isError(rs)) if (rs.next() && !isError(rs))
return rs.getString("result"); return rs.getString("result");
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
logSQLCommand(); logSQLCommand();
} finally { } finally {
closeCallable(); closeCallable();
} }
return null; return null;
} }
// Used for Stored procedures that return true when they succeed. // Used for Stored procedures that return true when they succeed.
protected final boolean worked() { protected final boolean worked() {
try { try {
ResultSet rs = this.executeQuery(); ResultSet rs = this.executeQuery();
if (rs.next() && !isError(rs)) if (rs.next() && !isError(rs))
return rs.getBoolean("result"); return rs.getBoolean("result");
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
logSQLCommand(); logSQLCommand();
} finally { } finally {
closeCallable(); closeCallable();
} }
return false; return false;
} }
// Common return values from the database when calling stored procedures, abstracted to this layer // Common return values from the database when calling stored procedures, abstracted to this layer
protected final long getUUID(){ protected final long getUUID() {
try { try {
ResultSet rs = this.executeQuery(); ResultSet rs = this.executeQuery();
if (rs.next() && !isError(rs)) if (rs.next() && !isError(rs))
return rs.getLong("UID"); return rs.getLong("UID");
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
logSQLCommand(); logSQLCommand();
} finally { } finally {
closeCallable(); closeCallable();
} }
return -1; return -1;
} }
protected final String getString(String field) { protected final String getString(String field) {
try { try {
ResultSet rs = this.executeQuery(); ResultSet rs = this.executeQuery();
if (rs.next()) if (rs.next())
return rs.getString(field); return rs.getString(field);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
logSQLCommand(); logSQLCommand();
} finally { } finally {
closeCallable(); closeCallable();
} }
return ""; return "";
} }
protected final long getLong(String field) { protected final long getLong(String field) {
try { try {
ResultSet rs = this.executeQuery(); ResultSet rs = this.executeQuery();
if (rs.next()) if (rs.next())
return rs.getLong(field); return rs.getLong(field);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
logSQLCommand(); logSQLCommand();
} finally { } finally {
closeCallable(); closeCallable();
} }
return 0L; return 0L;
} }
protected final int getInt(String field) { protected final int getInt(String field) {
try { try {
ResultSet rs = this.executeQuery(); ResultSet rs = this.executeQuery();
if (rs.next()) if (rs.next())
return rs.getInt(field); return rs.getInt(field);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
logSQLCommand(); logSQLCommand();
} finally { } finally {
closeCallable(); closeCallable();
} }
return 0; return 0;
} }
protected final int insertGetUUID() { protected final int insertGetUUID() {
int key = 0; int key = 0;
try { try {
this.callableStatement.get().executeUpdate(); this.callableStatement.get().executeUpdate();
ResultSet rs = this.callableStatement.get().getGeneratedKeys(); ResultSet rs = this.callableStatement.get().getGeneratedKeys();
if (rs.next()) if (rs.next())
key = rs.getInt(1); key = rs.getInt(1);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
logSQLCommand(); logSQLCommand();
} finally { } finally {
closeCallable(); closeCallable();
} }
return key; return key;
} }
protected final boolean isError(ResultSet rs) throws SQLException { protected final boolean isError(ResultSet rs) throws SQLException {
ResultSetMetaData rsmd = rs.getMetaData(); ResultSetMetaData rsmd = rs.getMetaData();
if (rsmd.getColumnCount() > 0 && !rsmd.getColumnName(1).equals("errorno")) if (rsmd.getColumnCount() > 0 && !rsmd.getColumnName(1).equals("errorno"))
return false; return false;
printError(rs); printError(rs);
return true; return true;
} }
protected final void printError(ResultSet rs) { protected final void printError(ResultSet rs) {
try { try {
int errorNum = rs.getInt("errorno"); int errorNum = rs.getInt("errorno");
String errorMsg = rs.getString("errormsg"); String errorMsg = rs.getString("errormsg");
Logger.error("SQLError: errorNum: " + errorNum + ", errorMsg: " + errorMsg); Logger.error("SQLError: errorNum: " + errorNum + ", errorMsg: " + errorMsg);
logSQLCommand(); logSQLCommand();
} catch (SQLException e) { } catch (SQLException e) {
} }
} }
protected <T extends AbstractGameObject> AbstractGameObject getObjectFromRs(ResultSet rs) { protected <T extends AbstractGameObject> AbstractGameObject getObjectFromRs(ResultSet rs) {
AbstractGameObject abstractGameObject = null; AbstractGameObject abstractGameObject = null;
try { try {
if (rs.next()) { if (rs.next()) {
abstractGameObject = localClass.getConstructor(ResultSet.class).newInstance(rs); abstractGameObject = localClass.getConstructor(ResultSet.class).newInstance(rs);
DbManager.addToCache(abstractGameObject); DbManager.addToCache(abstractGameObject);
} }
} catch (Exception e) { } catch (Exception e) {
Logger.error(e); Logger.error(e);
} }
return abstractGameObject; return abstractGameObject;
} }
protected <T extends AbstractGameObject> ArrayList<T> getObjectsFromRs(ResultSet rs, int listSize) { protected <T extends AbstractGameObject> ArrayList<T> getObjectsFromRs(ResultSet rs, int listSize) {
ArrayList<T> objectList = new ArrayList<>(listSize); ArrayList<T> objectList = new ArrayList<>(listSize);
try { try {
while (rs.next()) { while (rs.next()) {
int id = rs.getInt(1); int id = rs.getInt(1);
if (DbManager.inCache(localObjectType, id)) { if (DbManager.inCache(localObjectType, id)) {
objectList.add((T) DbManager.getFromCache(localObjectType, id)); objectList.add((T) DbManager.getFromCache(localObjectType, id));
} else { } else {
AbstractGameObject toAdd = localClass.getConstructor(ResultSet.class).newInstance(rs); AbstractGameObject toAdd = localClass.getConstructor(ResultSet.class).newInstance(rs);
DbManager.addToCache(toAdd); DbManager.addToCache(toAdd);
objectList.add((T) toAdd); objectList.add((T) toAdd);
if (toAdd != null && toAdd instanceof AbstractWorldObject) if (toAdd != null && toAdd instanceof AbstractWorldObject)
((AbstractWorldObject) toAdd).runAfterLoad(); ((AbstractWorldObject) toAdd).runAfterLoad();
} }
} }
} catch (Exception e) { } catch (Exception e) {
Logger.error(e); Logger.error(e);
} }
return objectList; return objectList;
} }
protected <T extends AbstractGameObject> AbstractGameObject getObjectSingle(int id) { protected <T extends AbstractGameObject> AbstractGameObject getObjectSingle(int id) {
return getObjectSingle(id, false, true); return getObjectSingle(id, false, true);
} }
protected <T extends AbstractGameObject> AbstractGameObject getObjectSingle(int id, boolean forceFromDB, boolean storeInCache) { protected <T extends AbstractGameObject> AbstractGameObject getObjectSingle(int id, boolean forceFromDB, boolean storeInCache) {
if (callableStatement.get() == null) { if (callableStatement.get() == null) {
return null; return null;
} }
if (!forceFromDB) { if (!forceFromDB) {
if (DbManager.inCache(localObjectType, id)) { if (DbManager.inCache(localObjectType, id)) {
closeCallable(); closeCallable();
return DbManager.getFromCache(localObjectType, id); return DbManager.getFromCache(localObjectType, id);
} }
} }
AbstractGameObject out = null; AbstractGameObject out = null;
try {
if (MBServerStatics.DB_ENABLE_QUERY_OUTPUT)
Logger.info("[GetObjectList] Executing query:" + callableStatement.get().toString());
try { ResultSet rs = callableStatement.get().executeQuery();
if (MBServerStatics.DB_ENABLE_QUERY_OUTPUT)
Logger.info("[GetObjectList] Executing query:" + callableStatement.get().toString());
ResultSet rs = callableStatement.get().executeQuery(); if (rs.next()) {
out = localClass.getConstructor(ResultSet.class).newInstance(rs);
if (rs.next()) { if (storeInCache)
out = localClass.getConstructor(ResultSet.class).newInstance(rs); DbManager.addToCache(out);
}
if (storeInCache) rs.close();
DbManager.addToCache(out);
}
rs.close(); } catch (Exception e) {
Logger.error("AbstractGameObject", e);
out = null;
} finally {
closeCallable();
}
} catch (Exception e) { // Only call runAfterLoad() for objects instanced on the world server
Logger.error("AbstractGameObject", e);
out = null;
} finally {
closeCallable();
}
// Only call runAfterLoad() for objects instanced on the world server if ((out != null && out instanceof AbstractWorldObject) &&
(ConfigManager.serverType.equals(Enum.ServerType.WORLDSERVER) ||
(out.getObjectType() == GameObjectType.Guild)))
((AbstractWorldObject) out).runAfterLoad();
if ((out != null && out instanceof AbstractWorldObject) && return out;
(ConfigManager.serverType.equals(Enum.ServerType.WORLDSERVER) || }
(out.getObjectType() == GameObjectType.Guild)))
((AbstractWorldObject)out).runAfterLoad();
return out; protected void closeCallable() {
} try {
if (this.callableStatement.get() != null)
this.callableStatement.get().close();
protected void closeCallable() { this.connection.get().close();
try {
if (this.callableStatement.get() != null)
this.callableStatement.get().close();
this.connection.get().close(); } catch (SQLException e) {
}
}
} catch (SQLException e) {} protected <T extends AbstractGameObject> ArrayList<T> getObjectList() {
} return getObjectList(20, false);
}
protected <T extends AbstractGameObject> ArrayList<T> getObjectList() { protected <T extends AbstractGameObject> ArrayList<T> getLargeObjectList() {
return getObjectList(20, false); return getObjectList(2000, false);
} }
protected <T extends AbstractGameObject> ArrayList<T> getLargeObjectList() { @SuppressWarnings("unchecked")
return getObjectList(2000, false); protected <T extends AbstractGameObject> ArrayList<T> getObjectList(int listSize, boolean forceFromDB) {
}
@SuppressWarnings("unchecked") String query = "No Callable Statement accessable.";
protected <T extends AbstractGameObject> ArrayList<T> getObjectList(int listSize, boolean forceFromDB) {
String query = "No Callable Statement accessable."; ArrayList<T> out = new ArrayList<>(listSize);
ArrayList<T> out = new ArrayList<>(listSize); if (this.callableStatement.get() == null)
return out;
if (this.callableStatement.get() == null) try {
return out;
try { CallableStatement css = this.callableStatement.get();
CallableStatement css = this.callableStatement.get(); if (css != null)
query = this.callableStatement.get().toString();
if (css != null) if (MBServerStatics.DB_ENABLE_QUERY_OUTPUT)
query = this.callableStatement.get().toString(); Logger.info("[GetObjectList] Executing query:" + query);
if (MBServerStatics.DB_ENABLE_QUERY_OUTPUT) ResultSet rs = this.callableStatement.get().executeQuery();
Logger.info( "[GetObjectList] Executing query:" + query);
ResultSet rs = this.callableStatement.get().executeQuery(); while (rs.next()) {
while (rs.next()) { int id = rs.getInt(1);
int id = rs.getInt(1); if (!forceFromDB && DbManager.inCache(localObjectType, id)) {
out.add((T) DbManager.getFromCache(localObjectType, id));
} else {
AbstractGameObject toAdd = localClass.getConstructor(ResultSet.class).newInstance(rs);
DbManager.addToCache(toAdd);
out.add((T) toAdd);
if (!forceFromDB && DbManager.inCache(localObjectType, id)) { if (toAdd != null && toAdd instanceof AbstractWorldObject)
out.add((T) DbManager.getFromCache(localObjectType, id)); ((AbstractWorldObject) toAdd).runAfterLoad();
} else {
AbstractGameObject toAdd = localClass.getConstructor(ResultSet.class).newInstance(rs);
DbManager.addToCache(toAdd);
out.add((T) toAdd);
if (toAdd != null && toAdd instanceof AbstractWorldObject) }
((AbstractWorldObject)toAdd).runAfterLoad(); }
rs.close();
} catch (Exception e) {
Logger.error(localClass.getCanonicalName(), "List Failure: " + query, e);
e.printStackTrace();
return new ArrayList<>(); // Do we want a null return on error?
} finally {
closeCallable();
}
} return out;
} }
rs.close();
} catch (Exception e) {
Logger.error(localClass.getCanonicalName(), "List Failure: " + query, e);
e.printStackTrace();
return new ArrayList<>(); // Do we want a null return on error?
} finally {
closeCallable();
}
return out; /* Prepared Statements handled below this line */
}
/* Prepared Statements handled below this line */ protected HashSet<Integer> getIntegerList(final int columnNumber) {
protected HashSet<Integer> getIntegerList(final int columnNumber) { if (MBServerStatics.DB_ENABLE_QUERY_OUTPUT)
Logger.info("[GetIntegerList] Executing query:" + this.callableStatement);
if (MBServerStatics.DB_ENABLE_QUERY_OUTPUT) HashSet<Integer> out = new HashSet<>();
Logger.info("[GetIntegerList] Executing query:" + this.callableStatement.toString());
HashSet<Integer> out = new HashSet<>(); try {
ResultSet rs = executeQuery();
try { while (rs.next()) {
ResultSet rs = executeQuery(); out.add(rs.getInt(columnNumber));
}
while (rs.next()) { rs.close();
out.add(rs.getInt(columnNumber)); } catch (SQLException e) {
} Logger.error("SQL Error number: " + e.getErrorCode());
rs.close(); } finally {
} catch (SQLException e) { closeCallable();
Logger.error("SQL Error number: " + e.getErrorCode()); }
} finally { return out;
closeCallable(); }
}
return out;
}
} }

2
src/engine/db/handlers/dbItemBaseHandler.java

@ -23,7 +23,7 @@ import java.util.HashMap;
public class dbItemBaseHandler extends dbHandlerBase { public class dbItemBaseHandler extends dbHandlerBase {
public dbItemBaseHandler() { public dbItemBaseHandler() {
} }

724
src/engine/db/handlers/dbItemHandler.java

@ -27,491 +27,491 @@ import java.util.HashSet;
public class dbItemHandler extends dbHandlerBase { public class dbItemHandler extends dbHandlerBase {
public dbItemHandler() { public dbItemHandler() {
this.localClass = Item.class; this.localClass = Item.class;
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
} }
public Item ADD_ITEM(Item toAdd) { private static String formatTradeString(HashSet<Integer> list) {
int size = list.size();
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("CALL `item_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?,?);")) { String ret = "";
preparedStatement.setInt(1, toAdd.getOwnerID()); if (size == 0)
preparedStatement.setInt(2, toAdd.getItemBaseID()); return ret;
preparedStatement.setInt(3, toAdd.getChargesRemaining());
preparedStatement.setInt(4, toAdd.getDurabilityCurrent()); boolean start = true;
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()); for (int i : list) {
preparedStatement.setInt(9, toAdd.getFlags()); if (start) {
preparedStatement.setString(10, toAdd.getCustomName()); 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());
ResultSet rs = preparedStatement.executeQuery(); 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;
}
int objectUUID = (int) rs.getLong("UID"); preparedStatement.setByte(8, toAdd.getEquipSlot());
preparedStatement.setInt(9, toAdd.getFlags());
preparedStatement.setString(10, toAdd.getCustomName());
if (objectUUID > 0) ResultSet rs = preparedStatement.executeQuery();
return GET_ITEM(objectUUID);
} catch (SQLException e) { int objectUUID = (int) rs.getLong("UID");
Logger.error(e);
}
return null; if (objectUUID > 0)
} return GET_ITEM(objectUUID);
public String GET_OWNER(int ownerID) { } catch (SQLException e) {
Logger.error(e);
}
String ownerType; return null;
}
try (Connection connection = DbManager.getConnection(); public String GET_OWNER(int ownerID) {
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `type` FROM `object` WHERE `UID`=?")) {
preparedStatement.setInt(1, ownerID); String ownerType;
ResultSet rs = preparedStatement.executeQuery();
ownerType = rs.getString("type"); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `type` FROM `object` WHERE `UID`=?")) {
} catch (SQLException e) { preparedStatement.setInt(1, ownerID);
Logger.error(e); ResultSet rs = preparedStatement.executeQuery();
return "";
}
return ownerType; ownerType = rs.getString("type");
}
public boolean DO_TRADE(HashSet<Integer> from1, HashSet<Integer> from2, } catch (SQLException e) {
CharacterItemManager man1, CharacterItemManager man2, Logger.error(e);
Item inventoryGold1, Item inventoryGold2, int goldFrom1, int goldFrom2) { return "";
}
AbstractCharacter ac1 = man1.getOwner(); return ownerType;
AbstractCharacter ac2 = man2.getOwner(); }
boolean worked = false;
if (ac1 == null || ac2 == null || inventoryGold1 == null || inventoryGold2 == null) public boolean DO_TRADE(HashSet<Integer> from1, HashSet<Integer> from2,
return false; CharacterItemManager man1, CharacterItemManager man2,
Item inventoryGold1, Item inventoryGold2, int goldFrom1, int goldFrom2) {
try (Connection connection = DbManager.getConnection(); AbstractCharacter ac1 = man1.getOwner();
PreparedStatement preparedStatement = connection.prepareStatement("CALL `item_TRADE`(?, ?, ?, ?, ?, ?, ?, ?)")) { AbstractCharacter ac2 = man2.getOwner();
boolean worked = false;
preparedStatement.setString(1, formatTradeString(from1)); if (ac1 == null || ac2 == null || inventoryGold1 == null || inventoryGold2 == null)
preparedStatement.setLong(2, (long) ac1.getObjectUUID()); return false;
preparedStatement.setString(3, formatTradeString(from2));
preparedStatement.setLong(4, (long) ac2.getObjectUUID());
preparedStatement.setInt(5, goldFrom1);
preparedStatement.setLong(6, (long) inventoryGold1.getObjectUUID());
preparedStatement.setInt(7, goldFrom2);
preparedStatement.setLong(8, (long) inventoryGold2.getObjectUUID());
ResultSet rs = preparedStatement.executeQuery(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("CALL `item_TRADE`(?, ?, ?, ?, ?, ?, ?, ?)")) {
if (rs.next()) preparedStatement.setString(1, formatTradeString(from1));
worked = rs.getBoolean("result"); 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());
} catch (SQLException e) { ResultSet rs = preparedStatement.executeQuery();
Logger.error(e);
}
return worked;
}
private static String formatTradeString(HashSet<Integer> list) { if (rs.next())
int size = list.size(); worked = rs.getBoolean("result");
String ret = ""; } catch (SQLException e) {
Logger.error(e);
}
return worked;
}
if (size == 0) public ArrayList<Item> GET_EQUIPPED_ITEMS(final int targetId) {
return ret;
boolean start = true; ArrayList<Item> itemList;
for (int i : list) { try (Connection connection = DbManager.getConnection();
if (start) { 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';")) {
ret += i;
start = false;
} else
ret += "," + i;
}
return ret;
}
public ArrayList<Item> GET_EQUIPPED_ITEMS(final int targetId) { preparedStatement.setLong(1, targetId);
ResultSet rs = preparedStatement.executeQuery();
ArrayList<Item> itemList; itemList = getObjectsFromRs(rs, 10);
try (Connection connection = DbManager.getConnection(); } catch (SQLException e) {
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';")) { Logger.error(e);
return null;
}
preparedStatement.setLong(1, (long) targetId); return itemList;
ResultSet rs = preparedStatement.executeQuery(); }
itemList = getObjectsFromRs(rs, 10); public Item GET_ITEM(final int itemUUID) {
} catch (SQLException e) { Item item;
Logger.error(e);
return null;
}
return 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`.`UID`=?;")) {
public Item GET_ITEM(final int itemUUID) { preparedStatement.setLong(1, itemUUID);
ResultSet rs = preparedStatement.executeQuery();
Item item; item = (Item) getObjectFromRs(rs);
try (Connection connection = DbManager.getConnection(); } catch (SQLException e) {
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`=?;")) { Logger.error(e);
return null;
}
return item;
}
preparedStatement.setLong(1, itemUUID); public ArrayList<Item> GET_ITEMS_FOR_ACCOUNT(final int accountId) {
ResultSet rs = preparedStatement.executeQuery();
item = (Item) getObjectFromRs(rs); ArrayList<Item> itemList;
} catch (SQLException e) { try (Connection connection = DbManager.getConnection();
Logger.error(e); 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`=?;")) {
return null;
}
return item;
}
public ArrayList<Item> GET_ITEMS_FOR_ACCOUNT(final int accountId) { preparedStatement.setLong(1, accountId);
ResultSet rs = preparedStatement.executeQuery();
ArrayList<Item> itemList; itemList = getObjectsFromRs(rs, 100);
try (Connection connection = DbManager.getConnection(); } catch (SQLException e) {
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`=?;")) { Logger.error(e);
return null;
}
return itemList;
}
preparedStatement.setLong(1, (long) accountId); public ArrayList<Item> GET_ITEMS_FOR_NPC(final int npcId) {
ResultSet rs = preparedStatement.executeQuery();
itemList = getObjectsFromRs(rs, 100); ArrayList<Item> itemList;
} catch (SQLException e) { try (Connection connection = DbManager.getConnection();
Logger.error(e); 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`=?;")) {
return null;
}
return itemList;
}
public ArrayList<Item> GET_ITEMS_FOR_NPC(final int npcId) { preparedStatement.setLong(1, npcId);
ResultSet rs = preparedStatement.executeQuery();
ArrayList<Item> itemList; itemList = getObjectsFromRs(rs, 20);
try (Connection connection = DbManager.getConnection(); } catch (SQLException e) {
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`=?;")) { Logger.error(e);
return null;
}
return itemList;
}
preparedStatement.setLong(1, npcId); public ArrayList<Item> GET_ITEMS_FOR_PC(final int id) {
ResultSet rs = preparedStatement.executeQuery();
itemList = getObjectsFromRs(rs, 20); ArrayList<Item> itemList;
} catch (SQLException e) { try (Connection connection = DbManager.getConnection();
Logger.error(e); 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`=?")) {
return null;
}
return itemList;
}
public ArrayList<Item> GET_ITEMS_FOR_PC(final int id) { preparedStatement.setLong(1, id);
ResultSet rs = preparedStatement.executeQuery();
ArrayList<Item> itemList; itemList = getObjectsFromRs(rs, 100);
try (Connection connection = DbManager.getConnection(); } catch (SQLException e) {
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`=?")) { Logger.error(e);
return null;
}
return itemList;
}
preparedStatement.setLong(1, (long) id); public boolean MOVE_GOLD(final Item from, final Item to, final int amt) {
ResultSet rs = preparedStatement.executeQuery();
itemList = getObjectsFromRs(rs, 100); 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 (?, ?);")) {
} catch (SQLException e) { int newFromAmt = from.getNumOfItems() - amt;
Logger.error(e); int newToAmt = to.getNumOfItems() + amt;
return null;
}
return itemList;
}
public boolean MOVE_GOLD(final Item from, final Item to, final int 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());
try (Connection connection = DbManager.getConnection(); return (preparedStatement.executeUpdate() > 0);
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; } catch (SQLException e) {
int newToAmt = to.getNumOfItems() + amt; Logger.error(e);
}
return false;
}
preparedStatement.setLong(1, (long) from.getObjectUUID()); public boolean ORPHAN_INVENTORY(final HashSet<Item> inventory) {
preparedStatement.setInt(2, newFromAmt);
preparedStatement.setLong(3, (long) to.getObjectUUID());
preparedStatement.setInt(4, newToAmt);
preparedStatement.setLong(5, (long) from.getObjectUUID());
preparedStatement.setLong(6, (long) to.getObjectUUID());
return (preparedStatement.executeUpdate() > 0); boolean worked = true;
} catch (SQLException e) { for (Item item : inventory) {
Logger.error(e);
}
return false;
}
public boolean ORPHAN_INVENTORY(final HashSet<Item> inventory) { if (item.getItemBase().getType().equals(ItemType.GOLD))
continue;
boolean worked = true; 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`=?;")) {
for (Item item : inventory) { preparedStatement.setLong(1, item.getObjectUUID());
worked = (preparedStatement.executeUpdate() > 0);
if (item.getItemBase().getType().equals(ItemType.GOLD)) if (worked)
continue; item.zeroItem();
try (Connection connection = DbManager.getConnection(); } catch (SQLException e) {
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`=?;")) { Logger.error(e);
return false;
}
}
return worked;
}
preparedStatement.setLong(1, (long) item.getObjectUUID()); public HashSet<Integer> GET_ITEMS_FOR_VENDOR(final int vendorID) {
worked = (preparedStatement.executeUpdate() > 0);
if (worked) HashSet<Integer> itemSet = new HashSet<>();
item.zeroItem();
} catch (SQLException e) { try (Connection connection = DbManager.getConnection();
Logger.error(e); PreparedStatement preparedStatement = connection.prepareStatement("SELECT ID FROM static_itembase WHERE vendorType = ?")) {
return false;
}
}
return worked;
}
public HashSet<Integer> GET_ITEMS_FOR_VENDOR(final int vendorID) { preparedStatement.setInt(1, vendorID);
HashSet<Integer> itemSet = new HashSet<>(); ResultSet rs = preparedStatement.executeQuery();
try (Connection connection = DbManager.getConnection(); while (rs.next())
PreparedStatement preparedStatement = connection.prepareStatement("SELECT ID FROM static_itembase WHERE vendorType = ?")) { itemSet.add(rs.getInt(1));
preparedStatement.setInt(1, vendorID); } catch (SQLException e) {
Logger.error(e);
return itemSet;
}
ResultSet rs = preparedStatement.executeQuery(); return itemSet;
}
while (rs.next()) //Used to transfer a single item between owners or equip or vault or bank or inventory
itemSet.add(rs.getInt(1)); public boolean UPDATE_OWNER(final Item item, int newOwnerID, boolean ownerNPC, boolean ownerPlayer,
boolean ownerAccount, ItemContainerType containerType, int slot) {
} catch (SQLException e) { boolean worked = false;
Logger.error(e);
return itemSet;
}
return itemSet; try (Connection connection = DbManager.getConnection();
} PreparedStatement preparedStatement = connection.prepareStatement("CALL `item_TRANSFER_OWNER`(?, ?, ?, ? )")) {
//Used to transfer a single item between owners or equip or vault or bank or inventory preparedStatement.setLong(1, item.getObjectUUID());
public boolean UPDATE_OWNER(final Item item, int newOwnerID, boolean ownerNPC, boolean ownerPlayer,
boolean ownerAccount, ItemContainerType containerType, int slot) {
boolean worked = false; if (newOwnerID != 0)
preparedStatement.setLong(2, newOwnerID);
else
preparedStatement.setNull(2, java.sql.Types.BIGINT);
try (Connection connection = DbManager.getConnection(); switch (containerType) {
PreparedStatement preparedStatement = connection.prepareStatement("CALL `item_TRANSFER_OWNER`(?, ?, ?, ? )")) { 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();
preparedStatement.setLong(1, item.getObjectUUID()); if (rs.next())
worked = rs.getBoolean("result");
if (newOwnerID != 0) } catch (SQLException e) {
preparedStatement.setLong(2, newOwnerID); Logger.error(e);
else return false;
preparedStatement.setNull(2, java.sql.Types.BIGINT); }
return worked;
}
switch (containerType) { public boolean SET_DURABILITY(final Item item, int value) {
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()) try (Connection connection = DbManager.getConnection();
worked = rs.getBoolean("result"); PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_durabilityCurrent`=? WHERE `UID`=? AND `item_durabilityCurrent`=?")) {
} catch (SQLException e) { preparedStatement.setInt(1, value);
Logger.error(e); preparedStatement.setLong(2, item.getObjectUUID());
return false; preparedStatement.setInt(3, item.getDurabilityCurrent());
}
return worked;
}
public boolean SET_DURABILITY(final Item item, int value) { return (preparedStatement.executeUpdate() > 0);
try (Connection connection = DbManager.getConnection(); } catch (SQLException e) {
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_durabilityCurrent`=? WHERE `UID`=? AND `item_durabilityCurrent`=?")) { Logger.error(e);
return false;
}
}
preparedStatement.setInt(1, value); public boolean UPDATE_FORGE_TO_INVENTORY(final Item item) {
preparedStatement.setLong(2, (long) item.getObjectUUID());
preparedStatement.setInt(3, (int) item.getDurabilityCurrent());
return (preparedStatement.executeUpdate() > 0); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_container` = ? WHERE `UID` = ? AND `item_container` = 'forge';")) {
} catch (SQLException e) { preparedStatement.setString(1, "inventory");
Logger.error(e); preparedStatement.setLong(2, item.getObjectUUID());
return false;
}
}
public boolean UPDATE_FORGE_TO_INVENTORY(final Item item) { return (preparedStatement.executeUpdate() > 0);
try (Connection connection = DbManager.getConnection(); } catch (SQLException e) {
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_container` = ? WHERE `UID` = ? AND `item_container` = 'forge';")) { Logger.error(e);
return false;
}
preparedStatement.setString(1, "inventory"); }
preparedStatement.setLong(2, (long) item.getObjectUUID());
return (preparedStatement.executeUpdate() > 0); /**
* 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());
}
} catch (SQLException e) { /**
Logger.error(e); * Attempts to update the quantity of this gold item using CAS
return false; *
} * @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();
* Attempts to update the quantity of this gold item PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_numberOfItems`=? WHERE `UID`=?")) {
*
* @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());
}
/** preparedStatement.setInt(1, newValue);
* Attempts to update the quantity of this gold item using CAS preparedStatement.setLong(2, item.getObjectUUID());
*
* @return True on success
*/
public boolean UPDATE_GOLD(final Item item, int newValue, int oldValue) {
if (!item.getItemBase().getType().equals(ItemType.GOLD)) return (preparedStatement.executeUpdate() > 0);
return false;
try (Connection connection = DbManager.getConnection(); } catch (SQLException e) {
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_numberOfItems`=? WHERE `UID`=?")) { Logger.error(e);
return false;
}
preparedStatement.setInt(1, newValue); }
preparedStatement.setLong(2, (long) item.getObjectUUID());
return (preparedStatement.executeUpdate() > 0); public boolean UPDATE_REMAINING_CHARGES(final Item item) {
} catch (SQLException e) { try (Connection connection = DbManager.getConnection();
Logger.error(e); PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_chargesRemaining` = ? WHERE `UID` = ?")) {
return false;
}
} preparedStatement.setInt(1, item.getChargesRemaining());
preparedStatement.setLong(2, item.getObjectUUID());
public boolean UPDATE_REMAINING_CHARGES(final Item item) { return (preparedStatement.executeUpdate() > 0);
try (Connection connection = DbManager.getConnection(); } catch (SQLException e) {
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_chargesRemaining` = ? WHERE `UID` = ?")) { Logger.error(e);
return false;
}
preparedStatement.setInt(1, item.getChargesRemaining()); }
preparedStatement.setLong(2, (long) item.getObjectUUID());
return (preparedStatement.executeUpdate() > 0); // This is necessary because default number of items is 1.
// When we create gold, we want it to start at 0 quantity.
} catch (SQLException e) { public boolean ZERO_ITEM_STACK(Item item) {
Logger.error(e);
return false;
}
} try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_numberOfItems`=0 WHERE `UID` = ?")) {
// This is necessary because default number of items is 1. preparedStatement.setLong(1, item.getObjectUUID());
// When we create gold, we want it to start at 0 quantity.
public boolean ZERO_ITEM_STACK(Item item) { return (preparedStatement.executeUpdate() > 0);
try (Connection connection = DbManager.getConnection(); } catch (SQLException e) {
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_numberOfItems`=0 WHERE `UID` = ?")) { Logger.error(e);
return false;
}
}
preparedStatement.setLong(1, (long) item.getObjectUUID()); public boolean UPDATE_FLAGS(Item item) {
return (preparedStatement.executeUpdate() > 0); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_flags`=? WHERE `UID` = ?")) {
} catch (SQLException e) { preparedStatement.setInt(1, item.getFlags());
Logger.error(e); preparedStatement.setLong(2, item.getObjectUUID());
return false;
}
}
public boolean UPDATE_FLAGS(Item item) { return (preparedStatement.executeUpdate() > 0);
try (Connection connection = DbManager.getConnection(); } catch (SQLException e) {
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_flags`=? WHERE `UID` = ?")) { Logger.error(e);
return false;
}
}
preparedStatement.setInt(1, item.getFlags()); public boolean UPDATE_VALUE(Item item, int value) {
preparedStatement.setLong(2, (long) item.getObjectUUID());
return (preparedStatement.executeUpdate() > 0); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_value`=? WHERE `UID` = ?")) {
} catch (SQLException e) { preparedStatement.setInt(1, value);
Logger.error(e); preparedStatement.setLong(2, item.getObjectUUID());
return false;
}
}
public boolean UPDATE_VALUE(Item item,int value) { return (preparedStatement.executeUpdate() > 0);
try (Connection connection = DbManager.getConnection(); } catch (SQLException e) {
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_value`=? WHERE `UID` = ?")) { Logger.error(e);
return false;
preparedStatement.setInt(1, value); }
preparedStatement.setLong(2, (long) item.getObjectUUID()); }
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
return false;
}
}
} }

30
src/engine/db/handlers/dbKitHandler.java

@ -21,25 +21,25 @@ import java.util.ArrayList;
public class dbKitHandler extends dbHandlerBase { public class dbKitHandler extends dbHandlerBase {
public dbKitHandler() { public dbKitHandler() {
this.localClass = Kit.class; this.localClass = Kit.class;
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
} }
public ArrayList<Kit> GET_ALL_KITS() { public ArrayList<Kit> GET_ALL_KITS() {
ArrayList<Kit> kitList = new ArrayList<>(); ArrayList<Kit> kitList = new ArrayList<>();
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_validkit`")) { PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_validkit`")) {
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
kitList = getObjectsFromRs(rs, 20); kitList = getObjectsFromRs(rs, 20);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return kitList; return kitList;
} }
} }

30
src/engine/db/handlers/dbMenuHandler.java

@ -21,27 +21,27 @@ import java.util.ArrayList;
public class dbMenuHandler extends dbHandlerBase { public class dbMenuHandler extends dbHandlerBase {
public dbMenuHandler() { public dbMenuHandler() {
this.localClass = MenuOption.class; this.localClass = MenuOption.class;
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
} }
public ArrayList<MenuOption> GET_MENU_OPTIONS(final int id) { public ArrayList<MenuOption> GET_MENU_OPTIONS(final int id) {
ArrayList<MenuOption> menuOptions = new ArrayList<>(); ArrayList<MenuOption> menuOptions = new ArrayList<>();
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_menuoption` WHERE menuID = ?")) { PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_menuoption` WHERE menuID = ?")) {
preparedStatement.setInt(1, id); preparedStatement.setInt(1, id);
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
menuOptions = getObjectsFromRs(rs, 1000); menuOptions = getObjectsFromRs(rs, 1000);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return menuOptions; return menuOptions;
} }
} }

150
src/engine/db/handlers/dbMineHandler.java

@ -23,113 +23,113 @@ import java.util.ArrayList;
public class dbMineHandler extends dbHandlerBase { public class dbMineHandler extends dbHandlerBase {
public dbMineHandler() { public dbMineHandler() {
this.localClass = Mine.class; this.localClass = Mine.class;
this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
} }
public Mine GET_MINE(int id) { public Mine GET_MINE(int id) {
if (id == 0) if (id == 0)
return null; return null;
Mine mine = (Mine) DbManager.getFromCache(Enum.GameObjectType.Mine, id); Mine mine = (Mine) DbManager.getFromCache(Enum.GameObjectType.Mine, id);
if (mine != null) if (mine != null)
return mine; return mine;
try (Connection connection = DbManager.getConnection(); 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 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); preparedStatement.setLong(1, id);
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
mine = (Mine) getObjectFromRs(rs); mine = (Mine) getObjectFromRs(rs);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return mine; return mine;
} }
public ArrayList<Mine> GET_ALL_MINES_FOR_SERVER() { public ArrayList<Mine> GET_ALL_MINES_FOR_SERVER() {
ArrayList<Mine> mines = new ArrayList<>(); ArrayList<Mine> mines = new ArrayList<>();
try (Connection connection = DbManager.getConnection(); 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`")) { 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(); ResultSet rs = preparedStatement.executeQuery();
mines = getObjectsFromRs(rs, 1000); mines = getObjectsFromRs(rs, 1000);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return mines; return mines;
} }
public boolean CHANGE_OWNER(Mine mine, int playerUID) { public boolean CHANGE_OWNER(Mine mine, int playerUID) {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_mine` SET `mine_ownerUID`=? WHERE `UID`=?")) { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_mine` SET `mine_ownerUID`=? WHERE `UID`=?")) {
preparedStatement.setInt(1, playerUID); preparedStatement.setInt(1, playerUID);
preparedStatement.setLong(2, mine.getObjectUUID()); preparedStatement.setLong(2, mine.getObjectUUID());
return (preparedStatement.executeUpdate() > 0); return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return false; return false;
} }
public boolean CHANGE_RESOURCE(Mine mine, Resource resource) { public boolean CHANGE_RESOURCE(Mine mine, Resource resource) {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_mine` SET `mine_resource`=? WHERE `UID`=?")) { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_mine` SET `mine_resource`=? WHERE `UID`=?")) {
preparedStatement.setString(1, resource.name()); preparedStatement.setString(1, resource.name());
preparedStatement.setLong(2, mine.getObjectUUID()); preparedStatement.setLong(2, mine.getObjectUUID());
return (preparedStatement.executeUpdate() > 0); return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return false; return false;
} }
public boolean CHANGE_TYPE(Mine mine, MineProduction productionType) { public boolean CHANGE_TYPE(Mine mine, MineProduction productionType) {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_mine` SET `mine_type`=? WHERE `UID`=?")) { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_mine` SET `mine_type`=? WHERE `UID`=?")) {
preparedStatement.setString(1, productionType.name()); preparedStatement.setString(1, productionType.name());
preparedStatement.setLong(2, mine.getObjectUUID()); preparedStatement.setLong(2, mine.getObjectUUID());
return (preparedStatement.executeUpdate() > 0); return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return false; return false;
} }
public boolean SET_FLAGS(Mine mine, int newFlags) { public boolean SET_FLAGS(Mine mine, int newFlags) {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_mine` SET `flags`=? WHERE `UID`=?")) { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_mine` SET `flags`=? WHERE `UID`=?")) {
preparedStatement.setInt(1, newFlags); preparedStatement.setInt(1, newFlags);
preparedStatement.setLong(2, mine.getObjectUUID()); preparedStatement.setLong(2, mine.getObjectUUID());
return (preparedStatement.executeUpdate() > 0); return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return false; return false;
} }
} }

240
src/engine/db/handlers/dbMobBaseHandler.java

@ -26,173 +26,173 @@ import java.util.HashMap;
public class dbMobBaseHandler extends dbHandlerBase { public class dbMobBaseHandler extends dbHandlerBase {
public dbMobBaseHandler() { public dbMobBaseHandler() {
this.localClass = MobBase.class; this.localClass = MobBase.class;
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
} }
public MobBase GET_MOBBASE(int id) { public MobBase GET_MOBBASE(int id) {
if (id == 0) if (id == 0)
return null; return null;
MobBase mobBase = (MobBase) DbManager.getFromCache(GameObjectType.MobBase, id); MobBase mobBase = (MobBase) DbManager.getFromCache(GameObjectType.MobBase, id);
if (mobBase != null) if (mobBase != null)
return mobBase; return mobBase;
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mobbase` WHERE `ID`=?")) { PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mobbase` WHERE `ID`=?")) {
preparedStatement.setInt(1, id); preparedStatement.setInt(1, id);
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
mobBase = (MobBase) getObjectFromRs(rs); mobBase = (MobBase) getObjectFromRs(rs);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return mobBase; return mobBase;
} }
public ArrayList<MobBase> GET_ALL_MOBBASES() { public ArrayList<MobBase> GET_ALL_MOBBASES() {
ArrayList<MobBase> mobbaseList = new ArrayList<>(); ArrayList<MobBase> mobbaseList = new ArrayList<>();
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mobbase`;")) { PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mobbase`;")) {
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
mobbaseList = getObjectsFromRs(rs, 1000); mobbaseList = getObjectsFromRs(rs, 1000);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return mobbaseList; return mobbaseList;
} }
public void SET_AI_DEFAULTS() { public void SET_AI_DEFAULTS() {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_ai_defaults`")) { PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_ai_defaults`")) {
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) { while (rs.next()) {
MBServerStatics.AI_BASE_AGGRO_RANGE = rs.getInt("aggro_range"); MBServerStatics.AI_BASE_AGGRO_RANGE = rs.getInt("aggro_range");
MBServerStatics.AI_PATROL_DIVISOR = rs.getInt("patrol_chance"); MBServerStatics.AI_PATROL_DIVISOR = rs.getInt("patrol_chance");
MBServerStatics.AI_DROP_AGGRO_RANGE = rs.getInt("drop_aggro_range"); MBServerStatics.AI_DROP_AGGRO_RANGE = rs.getInt("drop_aggro_range");
MBServerStatics.AI_POWER_DIVISOR = rs.getInt("cast_chance"); MBServerStatics.AI_POWER_DIVISOR = rs.getInt("cast_chance");
MBServerStatics.AI_RECALL_RANGE = rs.getInt("recall_range"); MBServerStatics.AI_RECALL_RANGE = rs.getInt("recall_range");
MBServerStatics.AI_PET_HEEL_DISTANCE = rs.getInt("pet_heel_distance"); MBServerStatics.AI_PET_HEEL_DISTANCE = rs.getInt("pet_heel_distance");
} }
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
} }
public boolean UPDATE_AI_DEFAULTS() { public boolean UPDATE_AI_DEFAULTS() {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `static_ai_defaults` SET `aggro_range` = ?,`patrol_chance`= ?,`drop_aggro_range`= ?,`cast_chance`= ?,`recall_range`= ? WHERE `ID` = 1")) { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `static_ai_defaults` SET `aggro_range` = ?,`patrol_chance`= ?,`drop_aggro_range`= ?,`cast_chance`= ?,`recall_range`= ? WHERE `ID` = 1")) {
preparedStatement.setInt(1, MBServerStatics.AI_BASE_AGGRO_RANGE); preparedStatement.setInt(1, MBServerStatics.AI_BASE_AGGRO_RANGE);
preparedStatement.setInt(2, MBServerStatics.AI_PATROL_DIVISOR); preparedStatement.setInt(2, MBServerStatics.AI_PATROL_DIVISOR);
preparedStatement.setInt(3, MBServerStatics.AI_DROP_AGGRO_RANGE); preparedStatement.setInt(3, MBServerStatics.AI_DROP_AGGRO_RANGE);
preparedStatement.setInt(4, MBServerStatics.AI_POWER_DIVISOR); preparedStatement.setInt(4, MBServerStatics.AI_POWER_DIVISOR);
preparedStatement.setInt(5, MBServerStatics.AI_RECALL_RANGE); preparedStatement.setInt(5, MBServerStatics.AI_RECALL_RANGE);
return (preparedStatement.executeUpdate() > 0); return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return false; return false;
} }
public HashMap<Integer, Integer> LOAD_STATIC_POWERS(int mobBaseUUID) { public HashMap<Integer, Integer> LOAD_STATIC_POWERS(int mobBaseUUID) {
HashMap<Integer, Integer> powersList = new HashMap<>(); HashMap<Integer, Integer> powersList = new HashMap<>();
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mobbase_powers` WHERE `mobbaseUUID`=?")) { PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mobbase_powers` WHERE `mobbaseUUID`=?")) {
preparedStatement.setInt(1, mobBaseUUID); preparedStatement.setInt(1, mobBaseUUID);
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) while (rs.next())
powersList.put(rs.getInt("token"), rs.getInt("rank")); powersList.put(rs.getInt("token"), rs.getInt("rank"));
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return powersList; return powersList;
} }
public ArrayList<MobBaseEffects> GET_RUNEBASE_EFFECTS(int runeID) { public ArrayList<MobBaseEffects> GET_RUNEBASE_EFFECTS(int runeID) {
ArrayList<MobBaseEffects> effectsList = new ArrayList<>(); ArrayList<MobBaseEffects> effectsList = new ArrayList<>();
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mobbase_effects` WHERE `mobbaseUUID` = ?")) { PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mobbase_effects` WHERE `mobbaseUUID` = ?")) {
preparedStatement.setInt(1, runeID); preparedStatement.setInt(1, runeID);
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) { while (rs.next()) {
MobBaseEffects mbs = new MobBaseEffects(rs); MobBaseEffects mbs = new MobBaseEffects(rs);
effectsList.add(mbs); effectsList.add(mbs);
} }
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return effectsList; return effectsList;
} }
public MobBaseStats LOAD_STATS(int mobBaseUUID) { public MobBaseStats LOAD_STATS(int mobBaseUUID) {
MobBaseStats mobBaseStats = MobBaseStats.GetGenericStats(); MobBaseStats mobBaseStats = MobBaseStats.GetGenericStats();
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mobbase_stats` WHERE `mobbaseUUID` = ?")) { PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mobbase_stats` WHERE `mobbaseUUID` = ?")) {
preparedStatement.setInt(1, mobBaseUUID); preparedStatement.setInt(1, mobBaseUUID);
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) while (rs.next())
mobBaseStats = new MobBaseStats(rs); mobBaseStats = new MobBaseStats(rs);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return mobBaseStats; return mobBaseStats;
} }
public void LOAD_ALL_MOBBASE_SPEEDS(MobBase mobBase) { public void LOAD_ALL_MOBBASE_SPEEDS(MobBase mobBase) {
if (mobBase.getLoadID() == 0) if (mobBase.getLoadID() == 0)
return; return;
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mobbase_race` WHERE `mobbaseID` = ?")) { PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_mobbase_race` WHERE `mobbaseID` = ?")) {
preparedStatement.setInt(1, mobBase.getLoadID()); preparedStatement.setInt(1, mobBase.getLoadID());
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) { while (rs.next()) {
float walk = rs.getFloat("walkStandard"); float walk = rs.getFloat("walkStandard");
float walkCombat = rs.getFloat("walkCombat"); float walkCombat = rs.getFloat("walkCombat");
float run = rs.getFloat("runStandard"); float run = rs.getFloat("runStandard");
float runCombat = rs.getFloat("runCombat"); float runCombat = rs.getFloat("runCombat");
mobBase.updateSpeeds(walk, walkCombat, run, runCombat); mobBase.updateSpeeds(walk, walkCombat, run, runCombat);
} }
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
} }
} }

316
src/engine/db/handlers/dbMobHandler.java

@ -24,225 +24,225 @@ import java.util.ArrayList;
public class dbMobHandler extends dbHandlerBase { public class dbMobHandler extends dbHandlerBase {
public dbMobHandler() { public dbMobHandler() {
this.localClass = Mob.class; this.localClass = Mob.class;
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
} }
public Mob ADD_MOB(Mob toAdd) { public Mob ADD_MOB(Mob toAdd) {
Mob mobile = null; Mob mobile = null;
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("CALL `mob_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);")) { PreparedStatement preparedStatement = connection.prepareStatement("CALL `mob_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);")) {
preparedStatement.setLong(1, toAdd.getParentZoneID()); preparedStatement.setLong(1, toAdd.getParentZoneID());
preparedStatement.setInt(2, toAdd.getMobBaseID()); preparedStatement.setInt(2, toAdd.getMobBaseID());
preparedStatement.setInt(3, toAdd.getGuildUUID()); preparedStatement.setInt(3, toAdd.getGuildUUID());
preparedStatement.setFloat(4, toAdd.getSpawnX()); preparedStatement.setFloat(4, toAdd.getSpawnX());
preparedStatement.setFloat(5, toAdd.getSpawnY()); preparedStatement.setFloat(5, toAdd.getSpawnY());
preparedStatement.setFloat(6, toAdd.getSpawnZ()); preparedStatement.setFloat(6, toAdd.getSpawnZ());
preparedStatement.setInt(7, 0); preparedStatement.setInt(7, 0);
preparedStatement.setFloat(8, toAdd.getSpawnRadius()); preparedStatement.setFloat(8, toAdd.getSpawnRadius());
preparedStatement.setInt(9, toAdd.getTrueSpawnTime()); preparedStatement.setInt(9, toAdd.getTrueSpawnTime());
if (toAdd.getContract() != null) if (toAdd.getContract() != null)
preparedStatement.setInt(10, toAdd.getContract().getContractID()); preparedStatement.setInt(10, toAdd.getContract().getContractID());
else else
preparedStatement.setInt(10, 0); preparedStatement.setInt(10, 0);
preparedStatement.setInt(11, toAdd.getBuildingID()); preparedStatement.setInt(11, toAdd.getBuildingID());
preparedStatement.setInt(12, toAdd.getLevel()); preparedStatement.setInt(12, toAdd.getLevel());
preparedStatement.setString(13, toAdd.getFirstName()); preparedStatement.setString(13, toAdd.getFirstName());
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
int objectUUID = (int) rs.getLong("UID"); int objectUUID = (int) rs.getLong("UID");
if (objectUUID > 0) if (objectUUID > 0)
mobile = GET_MOB(objectUUID); mobile = GET_MOB(objectUUID);
} catch (SQLException e) { } catch (SQLException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
return mobile; return mobile;
} }
public boolean updateUpgradeTime(Mob mob, DateTime upgradeDateTime) { public boolean updateUpgradeTime(Mob mob, DateTime upgradeDateTime) {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE obj_mob SET upgradeDate=? " PreparedStatement preparedStatement = connection.prepareStatement("UPDATE obj_mob SET upgradeDate=? "
+ "WHERE UID = ?")) { + "WHERE UID = ?")) {
if (upgradeDateTime == null) if (upgradeDateTime == null)
preparedStatement.setNull(1, java.sql.Types.DATE); preparedStatement.setNull(1, java.sql.Types.DATE);
else else
preparedStatement.setTimestamp(1, new java.sql.Timestamp(upgradeDateTime.getMillis())); preparedStatement.setTimestamp(1, new java.sql.Timestamp(upgradeDateTime.getMillis()));
preparedStatement.setInt(2, mob.getObjectUUID()); preparedStatement.setInt(2, mob.getObjectUUID());
preparedStatement.execute(); preparedStatement.execute();
return true; return true;
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return false; return false;
} }
public int DELETE_MOB(final Mob mob) { public int DELETE_MOB(final Mob mob) {
int row_count = 0; int row_count = 0;
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `object` WHERE `UID` = ?")) { PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `object` WHERE `UID` = ?")) {
preparedStatement.setLong(1, mob.getDBID()); preparedStatement.setLong(1, mob.getDBID());
row_count = preparedStatement.executeUpdate(); row_count = preparedStatement.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return row_count; return row_count;
} }
public void LOAD_PATROL_POINTS(Mob captain) { public void LOAD_PATROL_POINTS(Mob captain) {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_guards` WHERE `captainUID` = ?")) { PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_guards` WHERE `captainUID` = ?")) {
preparedStatement.setInt(1, captain.getObjectUUID()); preparedStatement.setInt(1, captain.getObjectUUID());
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) { while (rs.next()) {
String name = rs.getString("name"); String name = rs.getString("name");
Mob toCreate = Mob.createGuardMob(captain, captain.getGuild(), captain.getParentZone(), captain.building.getLoc(), captain.getLevel(), name); Mob toCreate = Mob.createGuardMob(captain, captain.getGuild(), captain.getParentZone(), captain.building.getLoc(), captain.getLevel(), name);
if (toCreate == null) if (toCreate == null)
return; return;
if (toCreate != null) { if (toCreate != null) {
toCreate.setTimeToSpawnSiege(System.currentTimeMillis() + MBServerStatics.FIFTEEN_MINUTES); toCreate.setTimeToSpawnSiege(System.currentTimeMillis() + MBServerStatics.FIFTEEN_MINUTES);
toCreate.setDeathTime(System.currentTimeMillis()); toCreate.setDeathTime(System.currentTimeMillis());
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
} }
public boolean ADD_TO_GUARDS(final long captainUID, final int mobBaseID, final String name, final int slot) { public boolean ADD_TO_GUARDS(final long captainUID, final int mobBaseID, final String name, final int slot) {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_guards` (`captainUID`, `mobBaseID`,`name`, `slot`) VALUES (?,?,?,?)")) { PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_guards` (`captainUID`, `mobBaseID`,`name`, `slot`) VALUES (?,?,?,?)")) {
preparedStatement.setLong(1, captainUID); preparedStatement.setLong(1, captainUID);
preparedStatement.setInt(2, mobBaseID); preparedStatement.setInt(2, mobBaseID);
preparedStatement.setString(3, name); preparedStatement.setString(3, name);
preparedStatement.setInt(4, slot); preparedStatement.setInt(4, slot);
return (preparedStatement.executeUpdate() > 0); return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
return false; return false;
} }
} }
public boolean REMOVE_FROM_GUARDS(final long captainUID, final int mobBaseID, final int slot) { public boolean REMOVE_FROM_GUARDS(final long captainUID, final int mobBaseID, final int slot) {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_guards` WHERE `captainUID`=? AND `mobBaseID`=? AND `slot` =?")) { PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_guards` WHERE `captainUID`=? AND `mobBaseID`=? AND `slot` =?")) {
preparedStatement.setLong(1, captainUID); preparedStatement.setLong(1, captainUID);
preparedStatement.setInt(2, mobBaseID); preparedStatement.setInt(2, mobBaseID);
preparedStatement.setInt(3, slot); preparedStatement.setInt(3, slot);
return (preparedStatement.executeUpdate() > 0); return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
return false; return false;
} }
} }
public ArrayList<Mob> GET_ALL_MOBS_FOR_ZONE(Zone zone) { public ArrayList<Mob> GET_ALL_MOBS_FOR_ZONE(Zone zone) {
ArrayList<Mob> mobileList = new ArrayList<>(); ArrayList<Mob> mobileList = new ArrayList<>();
try (Connection connection = DbManager.getConnection(); 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 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()); preparedStatement.setLong(1, zone.getObjectUUID());
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
mobileList = getObjectsFromRs(rs, 1000); mobileList = getObjectsFromRs(rs, 1000);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return mobileList; return mobileList;
} }
public Mob GET_MOB(final int objectUUID) { public Mob GET_MOB(final int objectUUID) {
Mob mobile = null; Mob mobile = null;
try (Connection connection = DbManager.getConnection(); 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 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); preparedStatement.setLong(1, objectUUID);
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
mobile = (Mob) getObjectFromRs(rs); mobile = (Mob) getObjectFromRs(rs);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return mobile; return mobile;
} }
public int MOVE_MOB(long mobID, long parentID, float locX, float locY, float locZ) { public int MOVE_MOB(long mobID, long parentID, float locX, float locY, float locZ) {
int row_count = 0; int row_count = 0;
try (Connection connection = DbManager.getConnection(); 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 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.setLong(1, parentID);
preparedStatement.setFloat(2, locX); preparedStatement.setFloat(2, locX);
preparedStatement.setFloat(3, locY); preparedStatement.setFloat(3, locY);
preparedStatement.setFloat(4, locZ); preparedStatement.setFloat(4, locZ);
preparedStatement.setLong(5, mobID); preparedStatement.setLong(5, mobID);
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
row_count = preparedStatement.executeUpdate(); row_count = preparedStatement.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return row_count; return row_count;
} }
public String SET_PROPERTY(final Mob m, String name, Object new_value) { public String SET_PROPERTY(final Mob m, String name, Object new_value) {
String result = ""; String result = "";
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("CALL mob_SETPROP(?,?,?)")) { PreparedStatement preparedStatement = connection.prepareStatement("CALL mob_SETPROP(?,?,?)")) {
preparedStatement.setLong(1, m.getObjectUUID()); preparedStatement.setLong(1, m.getObjectUUID());
preparedStatement.setString(2, name); preparedStatement.setString(2, name);
preparedStatement.setString(3, String.valueOf(new_value)); preparedStatement.setString(3, String.valueOf(new_value));
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
result = rs.getString("result"); result = rs.getString("result");
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return result; return result;
} }
} }

744
src/engine/db/handlers/dbPlayerCharacterHandler.java

@ -27,546 +27,542 @@ import java.util.concurrent.ConcurrentHashMap;
public class dbPlayerCharacterHandler extends dbHandlerBase { public class dbPlayerCharacterHandler extends dbHandlerBase {
public dbPlayerCharacterHandler() { public dbPlayerCharacterHandler() {
this.localClass = PlayerCharacter.class; this.localClass = PlayerCharacter.class;
this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
} }
public PlayerCharacter ADD_PLAYER_CHARACTER(final PlayerCharacter toAdd) { public PlayerCharacter ADD_PLAYER_CHARACTER(final PlayerCharacter toAdd) {
PlayerCharacter playerCharacter = null; PlayerCharacter playerCharacter = null;
if (toAdd.getAccount() == null) if (toAdd.getAccount() == null)
return null; return null;
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("CALL `character_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);")) { PreparedStatement preparedStatement = connection.prepareStatement("CALL `character_CREATE`(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);")) {
preparedStatement.setLong(1, toAdd.getAccount().getObjectUUID()); preparedStatement.setLong(1, toAdd.getAccount().getObjectUUID());
preparedStatement.setString(2, toAdd.getFirstName()); preparedStatement.setString(2, toAdd.getFirstName());
preparedStatement.setString(3, toAdd.getLastName()); preparedStatement.setString(3, toAdd.getLastName());
preparedStatement.setInt(4, toAdd.getRace().getRaceRuneID()); preparedStatement.setInt(4, toAdd.getRace().getRaceRuneID());
preparedStatement.setInt(5, toAdd.getBaseClass().getObjectUUID()); preparedStatement.setInt(5, toAdd.getBaseClass().getObjectUUID());
preparedStatement.setInt(6, toAdd.getStrMod()); preparedStatement.setInt(6, toAdd.getStrMod());
preparedStatement.setInt(7, toAdd.getDexMod()); preparedStatement.setInt(7, toAdd.getDexMod());
preparedStatement.setInt(8, toAdd.getConMod()); preparedStatement.setInt(8, toAdd.getConMod());
preparedStatement.setInt(9, toAdd.getIntMod()); preparedStatement.setInt(9, toAdd.getIntMod());
preparedStatement.setInt(10, toAdd.getSpiMod()); preparedStatement.setInt(10, toAdd.getSpiMod());
preparedStatement.setInt(11, toAdd.getExp()); preparedStatement.setInt(11, toAdd.getExp());
preparedStatement.setInt(12, toAdd.getSkinColor()); preparedStatement.setInt(12, toAdd.getSkinColor());
preparedStatement.setInt(13, toAdd.getHairColor()); preparedStatement.setInt(13, toAdd.getHairColor());
preparedStatement.setByte(14, toAdd.getHairStyle()); preparedStatement.setByte(14, toAdd.getHairStyle());
preparedStatement.setInt(15, toAdd.getBeardColor()); preparedStatement.setInt(15, toAdd.getBeardColor());
preparedStatement.setByte(16, toAdd.getBeardStyle()); preparedStatement.setByte(16, toAdd.getBeardStyle());
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
int objectUUID = (int) rs.getLong("UID"); int objectUUID = (int) rs.getLong("UID");
if (objectUUID > 0) if (objectUUID > 0)
playerCharacter = GET_PLAYER_CHARACTER(objectUUID); playerCharacter = GET_PLAYER_CHARACTER(objectUUID);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return playerCharacter; return playerCharacter;
} }
public boolean SET_IGNORE_LIST(int sourceID, int targetID, boolean toIgnore, String charName) { public boolean SET_IGNORE_LIST(int sourceID, int targetID, boolean toIgnore, String charName) {
String queryString = ""; String queryString = "";
if (toIgnore) if (toIgnore)
queryString = "INSERT INTO `dyn_character_ignore` (`accountUID`, `ignoringUID`, `characterName`) VALUES (?, ?, ?)"; queryString = "INSERT INTO `dyn_character_ignore` (`accountUID`, `ignoringUID`, `characterName`) VALUES (?, ?, ?)";
else else
queryString = "DELETE FROM `dyn_character_ignore` WHERE `accountUID` = ? && `ignoringUID` = ?"; queryString = "DELETE FROM `dyn_character_ignore` WHERE `accountUID` = ? && `ignoringUID` = ?";
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(queryString)) { PreparedStatement preparedStatement = connection.prepareStatement(queryString)) {
preparedStatement.setLong(1, sourceID); preparedStatement.setLong(1, sourceID);
preparedStatement.setLong(2, targetID); preparedStatement.setLong(2, targetID);
if (toIgnore) if (toIgnore)
preparedStatement.setString(3, charName); preparedStatement.setString(3, charName);
return (preparedStatement.executeUpdate() > 0); return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return false; return false;
} }
public ArrayList<PlayerCharacter> GET_CHARACTERS_FOR_ACCOUNT(final int id) { public ArrayList<PlayerCharacter> GET_CHARACTERS_FOR_ACCOUNT(final int id) {
ArrayList<PlayerCharacter> characterList = new ArrayList<>(); ArrayList<PlayerCharacter> characterList = new ArrayList<>();
try (Connection connection = DbManager.getConnection(); 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 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, (long) id); preparedStatement.setLong(1, id);
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
characterList = getObjectsFromRs(rs, 10); characterList = getObjectsFromRs(rs, 10);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return characterList; return characterList;
} }
public ArrayList<PlayerCharacter> GET_ALL_CHARACTERS() { public ArrayList<PlayerCharacter> GET_ALL_CHARACTERS() {
ArrayList<PlayerCharacter> characterList = new ArrayList<>(); ArrayList<PlayerCharacter> characterList = new ArrayList<>();
try (Connection connection = DbManager.getConnection(); 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';")) { 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(); ResultSet rs = preparedStatement.executeQuery();
characterList = getObjectsFromRs(rs, 2000); characterList = getObjectsFromRs(rs, 2000);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return characterList; return characterList;
} }
/** /**
* * <code>getFirstName</code> looks up the first name of a PlayerCharacter by
* <code>getFirstName</code> looks up the first name of a PlayerCharacter by * first checking the GOM cache and then querying the database.
* first checking the GOM cache and then querying the database. * PlayerCharacter objects that are not already cached won't be instantiated
* PlayerCharacter objects that are not already cached won't be instantiated * and cached.
* and cached. */
*
*/
public ConcurrentHashMap<Integer, String> GET_IGNORE_LIST(final int objectUUID, final boolean skipActiveCheck) { 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); ConcurrentHashMap<Integer, String> ignoreList = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_ignore` WHERE `accountUID` = ?;")) { PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_ignore` WHERE `accountUID` = ?;")) {
preparedStatement.setLong(1, objectUUID); preparedStatement.setLong(1, objectUUID);
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) { while (rs.next()) {
int ignoreCharacterID = rs.getInt("ignoringUID"); int ignoreCharacterID = rs.getInt("ignoringUID");
if (ignoreCharacterID == 0) if (ignoreCharacterID == 0)
continue; continue;
String name = rs.getString("characterName"); String name = rs.getString("characterName");
ignoreList.put(ignoreCharacterID, name); ignoreList.put(ignoreCharacterID, name);
} }
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return ignoreList; return ignoreList;
} }
public PlayerCharacter GET_PLAYER_CHARACTER(final int objectUUID) { public PlayerCharacter GET_PLAYER_CHARACTER(final int objectUUID) {
if (objectUUID == 0) if (objectUUID == 0)
return null; return null;
PlayerCharacter playerCharacter = (PlayerCharacter) DbManager.getFromCache(Enum.GameObjectType.PlayerCharacter, objectUUID); PlayerCharacter playerCharacter = (PlayerCharacter) DbManager.getFromCache(Enum.GameObjectType.PlayerCharacter, objectUUID);
if (playerCharacter != null) if (playerCharacter != null)
return playerCharacter; return playerCharacter;
try (Connection connection = DbManager.getConnection(); 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 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); preparedStatement.setLong(1, objectUUID);
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
playerCharacter = (PlayerCharacter) getObjectFromRs(rs); playerCharacter = (PlayerCharacter) getObjectFromRs(rs);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
; return playerCharacter;
return playerCharacter; }
}
public boolean IS_CHARACTER_NAME_UNIQUE(final String firstName) { public boolean IS_CHARACTER_NAME_UNIQUE(final String firstName) {
boolean unique = true; boolean unique = true;
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `char_firstname` FROM `obj_character` WHERE `char_isActive`=1 && `char_firstname`=?")) { PreparedStatement preparedStatement = connection.prepareStatement("SELECT `char_firstname` FROM `obj_character` WHERE `char_isActive`=1 && `char_firstname`=?")) {
preparedStatement.setString(1, firstName); preparedStatement.setString(1, firstName);
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
if (rs.next()) if (rs.next())
unique = false; unique = false;
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return unique; return unique;
} }
public boolean UPDATE_NAME(String oldFirstName, String newFirstName, String newLastName) { public boolean UPDATE_NAME(String oldFirstName, String newFirstName, String newLastName) {
try (Connection connection = DbManager.getConnection(); 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 preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_firstname`=?, `char_lastname`=? WHERE `char_firstname`=? AND `char_isActive`='1'")) {
preparedStatement.setString(1, newFirstName); preparedStatement.setString(1, newFirstName);
preparedStatement.setString(2, newLastName); preparedStatement.setString(2, newLastName);
preparedStatement.setString(3, oldFirstName); preparedStatement.setString(3, oldFirstName);
return (preparedStatement.executeUpdate() > 0); return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return false; return false;
} }
public boolean SET_DELETED(final PlayerCharacter pc) { public boolean SET_DELETED(final PlayerCharacter pc) {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_isActive`=? WHERE `UID` = ?")) { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_isActive`=? WHERE `UID` = ?")) {
preparedStatement.setBoolean(1, !pc.isDeleted()); preparedStatement.setBoolean(1, !pc.isDeleted());
preparedStatement.setLong(2, pc.getObjectUUID()); preparedStatement.setLong(2, pc.getObjectUUID());
return (preparedStatement.executeUpdate() > 0); return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return false; return false;
} }
public boolean SET_ACTIVE(final PlayerCharacter pc, boolean status) { public boolean SET_ACTIVE(final PlayerCharacter pc, boolean status) {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_isActive`=? WHERE `UID` = ?")) { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_isActive`=? WHERE `UID` = ?")) {
preparedStatement.setBoolean(1, status); preparedStatement.setBoolean(1, status);
preparedStatement.setLong(2, (long) pc.getObjectUUID()); preparedStatement.setLong(2, pc.getObjectUUID());
return (preparedStatement.executeUpdate() > 0); return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return false; return false;
} }
public boolean SET_BIND_BUILDING(final PlayerCharacter pc, int bindBuildingID) { public boolean SET_BIND_BUILDING(final PlayerCharacter pc, int bindBuildingID) {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_bindBuilding`=? WHERE `UID` = ?")) { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_bindBuilding`=? WHERE `UID` = ?")) {
preparedStatement.setInt(1, bindBuildingID); preparedStatement.setInt(1, bindBuildingID);
preparedStatement.setLong(2, (long) pc.getObjectUUID()); preparedStatement.setLong(2, pc.getObjectUUID());
return (preparedStatement.executeUpdate() > 0); return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return false; return false;
} }
public boolean SET_ANNIVERSERY(final PlayerCharacter pc, boolean flag) { public boolean SET_ANNIVERSERY(final PlayerCharacter pc, boolean flag) {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `anniversery`=? WHERE `UID` = ?")) { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `anniversery`=? WHERE `UID` = ?")) {
preparedStatement.setBoolean(1, flag); preparedStatement.setBoolean(1, flag);
preparedStatement.setLong(2, (long) pc.getObjectUUID()); preparedStatement.setLong(2, pc.getObjectUUID());
return (preparedStatement.executeUpdate() > 0); return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return false; return false;
} }
public boolean UPDATE_CHARACTER_EXPERIENCE(final PlayerCharacter pc) { public boolean UPDATE_CHARACTER_EXPERIENCE(final PlayerCharacter pc) {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_experience`=? WHERE `UID` = ?")) { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_experience`=? WHERE `UID` = ?")) {
preparedStatement.setInt(1, pc.getExp()); preparedStatement.setInt(1, pc.getExp());
preparedStatement.setLong(2, (long) pc.getObjectUUID()); preparedStatement.setLong(2, pc.getObjectUUID());
return (preparedStatement.executeUpdate() > 0); return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return false; return false;
} }
public boolean UPDATE_GUILD(final PlayerCharacter pc, int guildUUID) { public boolean UPDATE_GUILD(final PlayerCharacter pc, int guildUUID) {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guildUID`=? WHERE `UID` = ?")) { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guildUID`=? WHERE `UID` = ?")) {
preparedStatement.setInt(1, guildUUID); preparedStatement.setInt(1, guildUUID);
preparedStatement.setLong(2, (long) pc.getObjectUUID()); preparedStatement.setLong(2, pc.getObjectUUID());
return (preparedStatement.executeUpdate() > 0); return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return false; return false;
} }
public boolean UPDATE_CHARACTER_STATS(final PlayerCharacter pc) { public boolean UPDATE_CHARACTER_STATS(final PlayerCharacter pc) {
try (Connection connection = DbManager.getConnection(); 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 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(1, pc.getStrMod());
preparedStatement.setInt(2, pc.getDexMod()); preparedStatement.setInt(2, pc.getDexMod());
preparedStatement.setInt(3, pc.getConMod()); preparedStatement.setInt(3, pc.getConMod());
preparedStatement.setInt(4, pc.getIntMod()); preparedStatement.setInt(4, pc.getIntMod());
preparedStatement.setInt(5, pc.getSpiMod()); preparedStatement.setInt(5, pc.getSpiMod());
preparedStatement.setLong(6, (long) pc.getObjectUUID()); preparedStatement.setLong(6, pc.getObjectUUID());
return (preparedStatement.executeUpdate() > 0); return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return false; return false;
} }
public String SET_PROPERTY(final PlayerCharacter playerCharacter, String name, Object new_value) { public String SET_PROPERTY(final PlayerCharacter playerCharacter, String name, Object new_value) {
String result = ""; String result = "";
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("CALL character_SETPROP(?,?,?)")) { PreparedStatement preparedStatement = connection.prepareStatement("CALL character_SETPROP(?,?,?)")) {
preparedStatement.setLong(1, playerCharacter.getObjectUUID()); preparedStatement.setLong(1, playerCharacter.getObjectUUID());
preparedStatement.setString(2, name); preparedStatement.setString(2, name);
; preparedStatement.setString(3, String.valueOf(new_value));
preparedStatement.setString(3, String.valueOf(new_value));
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
result = rs.getString("result"); result = rs.getString("result");
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return result; return result;
} }
public boolean SET_PROMOTION_CLASS(PlayerCharacter player, int promotionClassID) { public boolean SET_PROMOTION_CLASS(PlayerCharacter player, int promotionClassID) {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_promotionClassID`=? WHERE `UID`=?;")) { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_promotionClassID`=? WHERE `UID`=?;")) {
preparedStatement.setInt(1, promotionClassID); preparedStatement.setInt(1, promotionClassID);
preparedStatement.setInt(2, player.getObjectUUID()); preparedStatement.setInt(2, player.getObjectUUID());
return (preparedStatement.executeUpdate() > 0); return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return false; return false;
} }
public boolean SET_INNERCOUNCIL(PlayerCharacter player, boolean isInnerCouncil) { public boolean SET_INNERCOUNCIL(PlayerCharacter player, boolean isInnerCouncil) {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_isInnerCouncil`=? WHERE `UID`=?;")) { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_isInnerCouncil`=? WHERE `UID`=?;")) {
preparedStatement.setBoolean(1, isInnerCouncil); preparedStatement.setBoolean(1, isInnerCouncil);
preparedStatement.setInt(2, player.getObjectUUID()); preparedStatement.setInt(2, player.getObjectUUID());
return (preparedStatement.executeUpdate() > 0); return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return false; return false;
} }
public boolean SET_FULL_MEMBER(PlayerCharacter player, boolean isFullMember) { public boolean SET_FULL_MEMBER(PlayerCharacter player, boolean isFullMember) {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_isFullMember`=? WHERE `UID`=?;")) { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_isFullMember`=? WHERE `UID`=?;")) {
preparedStatement.setBoolean(1, isFullMember); preparedStatement.setBoolean(1, isFullMember);
preparedStatement.setInt(2, player.getObjectUUID()); preparedStatement.setInt(2, player.getObjectUUID());
return (preparedStatement.executeUpdate() > 0); return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return false; return false;
} }
public boolean SET_TAX_COLLECTOR(PlayerCharacter player, boolean isTaxCollector) { public boolean SET_TAX_COLLECTOR(PlayerCharacter player, boolean isTaxCollector) {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_isTaxCollector`=? WHERE `UID`=?;")) { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_isTaxCollector`=? WHERE `UID`=?;")) {
preparedStatement.setBoolean(1, isTaxCollector); preparedStatement.setBoolean(1, isTaxCollector);
preparedStatement.setInt(2, player.getObjectUUID()); preparedStatement.setInt(2, player.getObjectUUID());
return (preparedStatement.executeUpdate() > 0); return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return false; return false;
} }
public boolean SET_RECRUITER(PlayerCharacter player, boolean isRecruiter) { public boolean SET_RECRUITER(PlayerCharacter player, boolean isRecruiter) {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_isRecruiter`=? WHERE `UID`=?;")) { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_isRecruiter`=? WHERE `UID`=?;")) {
preparedStatement.setBoolean(1, isRecruiter); preparedStatement.setBoolean(1, isRecruiter);
preparedStatement.setInt(2, player.getObjectUUID()); preparedStatement.setInt(2, player.getObjectUUID());
return (preparedStatement.executeUpdate() > 0); return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return false; return false;
} }
public boolean SET_GUILD_TITLE(PlayerCharacter player, int title) { public boolean SET_GUILD_TITLE(PlayerCharacter player, int title) {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_title`=? WHERE `UID`=?;")) { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_title`=? WHERE `UID`=?;")) {
preparedStatement.setInt(1, title); preparedStatement.setInt(1, title);
preparedStatement.setInt(2, player.getObjectUUID()); preparedStatement.setInt(2, player.getObjectUUID());
return (preparedStatement.executeUpdate() > 0); return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return false; return false;
} }
public boolean ADD_FRIEND(int source, long friend) { public boolean ADD_FRIEND(int source, long friend) {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_character_friends` (`playerUID`, `friendUID`) VALUES (?, ?)")) { PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_character_friends` (`playerUID`, `friendUID`) VALUES (?, ?)")) {
preparedStatement.setLong(1, source); preparedStatement.setLong(1, source);
preparedStatement.setLong(2, friend); preparedStatement.setLong(2, friend);
return (preparedStatement.executeUpdate() > 0); return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return false; return false;
} }
public boolean REMOVE_FRIEND(int source, int friend) { public boolean REMOVE_FRIEND(int source, int friend) {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_character_friends` WHERE (`playerUID`=?) AND (`friendUID`=?)")) { PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_character_friends` WHERE (`playerUID`=?) AND (`friendUID`=?)")) {
preparedStatement.setLong(1, source); preparedStatement.setLong(1, source);
preparedStatement.setLong(2, friend); preparedStatement.setLong(2, friend);
return (preparedStatement.executeUpdate() > 0); return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return false; return false;
} }
public void LOAD_PLAYER_FRIENDS() { public void LOAD_PLAYER_FRIENDS() {
PlayerFriends playerFriend; PlayerFriends playerFriend;
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM dyn_character_friends")) { PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM dyn_character_friends")) {
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) while (rs.next())
playerFriend = new PlayerFriends(rs); playerFriend = new PlayerFriends(rs);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
prepareCallable("SELECT * FROM dyn_character_friends"); prepareCallable("SELECT * FROM dyn_character_friends");
} }
public boolean ADD_HERALDY(int source, AbstractWorldObject character) { public boolean ADD_HERALDY(int source, AbstractWorldObject character) {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_character_heraldy` (`playerUID`, `characterUID`,`characterType`) VALUES (?, ?,?)")) { PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_character_heraldy` (`playerUID`, `characterUID`,`characterType`) VALUES (?, ?,?)")) {
preparedStatement.setLong(1, source); preparedStatement.setLong(1, source);
preparedStatement.setLong(2, character.getObjectUUID()); preparedStatement.setLong(2, character.getObjectUUID());
preparedStatement.setInt(3, character.getObjectType().ordinal()); preparedStatement.setInt(3, character.getObjectType().ordinal());
return (preparedStatement.executeUpdate() > 0); return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return false; return false;
} }
public boolean REMOVE_HERALDY(int source, int characterUID) { public boolean REMOVE_HERALDY(int source, int characterUID) {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_character_heraldy` WHERE (`playerUID`=?) AND (`characterUID`=?)")) { PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_character_heraldy` WHERE (`playerUID`=?) AND (`characterUID`=?)")) {
preparedStatement.setLong(1, source); preparedStatement.setLong(1, source);
preparedStatement.setLong(2, characterUID); preparedStatement.setLong(2, characterUID);
return (preparedStatement.executeUpdate() > 0); return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return false; return false;
} }
public void LOAD_HERALDY() { public void LOAD_HERALDY() {
Heraldry heraldy; Heraldry heraldy;
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM dyn_character_heraldy")) { PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM dyn_character_heraldy")) {
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) while (rs.next())
heraldy = new Heraldry(rs); heraldy = new Heraldry(rs);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
} }
} }

30
src/engine/db/handlers/dbRuneBaseAttributeHandler.java

@ -21,27 +21,27 @@ import java.util.ArrayList;
public class dbRuneBaseAttributeHandler extends dbHandlerBase { public class dbRuneBaseAttributeHandler extends dbHandlerBase {
public dbRuneBaseAttributeHandler() { public dbRuneBaseAttributeHandler() {
this.localClass = RuneBaseAttribute.class; this.localClass = RuneBaseAttribute.class;
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
} }
public ArrayList<RuneBaseAttribute> GET_ATTRIBUTES_FOR_RUNEBASE() { public ArrayList<RuneBaseAttribute> GET_ATTRIBUTES_FOR_RUNEBASE() {
ArrayList<RuneBaseAttribute> runeBaseAttributesList = new ArrayList<>(); ArrayList<RuneBaseAttribute> runeBaseAttributesList = new ArrayList<>();
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_runebaseattribute`")) { PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_runebaseattribute`")) {
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
runeBaseAttributesList = getObjectsFromRs(rs, 10); runeBaseAttributesList = getObjectsFromRs(rs, 10);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return runeBaseAttributesList; return runeBaseAttributesList;
} }
} }

91
src/engine/db/handlers/dbRuneBaseEffectHandler.java

@ -24,69 +24,68 @@ import java.util.HashMap;
public class dbRuneBaseEffectHandler extends dbHandlerBase { public class dbRuneBaseEffectHandler extends dbHandlerBase {
public dbRuneBaseEffectHandler() { public dbRuneBaseEffectHandler() {
this.localClass = RuneBaseEffect.class; this.localClass = RuneBaseEffect.class;
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
} }
public ArrayList<RuneBaseEffect> GET_EFFECTS_FOR_RUNEBASE(int id) { public ArrayList<RuneBaseEffect> GET_EFFECTS_FOR_RUNEBASE(int id) {
ArrayList<RuneBaseEffect> runeBaseEffectsList = new ArrayList<>(); ArrayList<RuneBaseEffect> runeBaseEffectsList = new ArrayList<>();
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_baseeffect` WHERE `runeID`=?")) { PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_baseeffect` WHERE `runeID`=?")) {
preparedStatement.setInt(1, id); preparedStatement.setInt(1, id);
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
runeBaseEffectsList = getObjectsFromRs(rs, 250); runeBaseEffectsList = getObjectsFromRs(rs, 250);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return runeBaseEffectsList; return runeBaseEffectsList;
} }
public ArrayList<RuneBaseEffect> GET_ALL_RUNEBASE_EFFECTS() { public ArrayList<RuneBaseEffect> GET_ALL_RUNEBASE_EFFECTS() {
ArrayList<RuneBaseEffect> runeBaseEffectsList = new ArrayList<>(); ArrayList<RuneBaseEffect> runeBaseEffectsList = new ArrayList<>();
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_baseeffect`;")) { PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_baseeffect`;")) {
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
runeBaseEffectsList = getObjectsFromRs(rs, 250); runeBaseEffectsList = getObjectsFromRs(rs, 250);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return runeBaseEffectsList; return runeBaseEffectsList;
} }
//This calls from cache only. Call this AFTER caching all runebase effects; //This calls from cache only. Call this AFTER caching all runebase effects;
public HashMap<Integer, ArrayList<RuneBaseEffect>> LOAD_BASEEFFECTS_FOR_RUNEBASE() { public HashMap<Integer, ArrayList<RuneBaseEffect>> LOAD_BASEEFFECTS_FOR_RUNEBASE() {
HashMap<Integer, ArrayList<RuneBaseEffect>> runeBaseEffectSet; HashMap<Integer, ArrayList<RuneBaseEffect>> runeBaseEffectSet;
runeBaseEffectSet = new HashMap<>(); runeBaseEffectSet = new HashMap<>();
for (AbstractGameObject runeBaseEffect:DbManager.getList(GameObjectType.RuneBaseEffect)){ for (AbstractGameObject runeBaseEffect : DbManager.getList(GameObjectType.RuneBaseEffect)) {
int runeBaseID = ((RuneBaseEffect)runeBaseEffect).getRuneBaseID(); int runeBaseID = ((RuneBaseEffect) runeBaseEffect).getRuneBaseID();
if (runeBaseEffectSet.get(runeBaseID) == null){ if (runeBaseEffectSet.get(runeBaseID) == null) {
ArrayList<RuneBaseEffect> runeBaseEffectList = new ArrayList<>(); ArrayList<RuneBaseEffect> runeBaseEffectList = new ArrayList<>();
runeBaseEffectList.add((RuneBaseEffect)runeBaseEffect); runeBaseEffectList.add((RuneBaseEffect) runeBaseEffect);
runeBaseEffectSet.put(runeBaseID, runeBaseEffectList); runeBaseEffectSet.put(runeBaseID, runeBaseEffectList);
} } else {
else{ ArrayList<RuneBaseEffect> runeBaseEffectList = runeBaseEffectSet.get(runeBaseID);
ArrayList<RuneBaseEffect>runeBaseEffectList = runeBaseEffectSet.get(runeBaseID); runeBaseEffectList.add((RuneBaseEffect) runeBaseEffect);
runeBaseEffectList.add((RuneBaseEffect)runeBaseEffect); runeBaseEffectSet.put(runeBaseID, runeBaseEffectList);
runeBaseEffectSet.put(runeBaseID, runeBaseEffectList); }
} }
} return runeBaseEffectSet;
return runeBaseEffectSet; }
}
} }

224
src/engine/db/handlers/dbRuneBaseHandler.java

@ -22,158 +22,158 @@ import java.util.HashMap;
public class dbRuneBaseHandler extends dbHandlerBase { public class dbRuneBaseHandler extends dbHandlerBase {
public dbRuneBaseHandler() { public dbRuneBaseHandler() {
this.localClass = RuneBase.class; this.localClass = RuneBase.class;
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
} }
public void GET_RUNE_REQS(final RuneBase rb) { public void GET_RUNE_REQS(final RuneBase rb) {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_runereq` WHERE `runeID` = ?")) { PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_runereq` WHERE `runeID` = ?")) {
preparedStatement.setInt(1, rb.getObjectUUID()); preparedStatement.setInt(1, rb.getObjectUUID());
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) { while (rs.next()) {
int type = rs.getInt("type"); int type = rs.getInt("type");
switch (type) { switch (type) {
case 1: case 1:
rb.getRace().put(rs.getInt("requiredRuneID"), rs.getBoolean("isAllowed")); rb.getRace().put(rs.getInt("requiredRuneID"), rs.getBoolean("isAllowed"));
break; break;
case 2: case 2:
rb.getBaseClass().put(rs.getInt("requiredRuneID"), rs.getBoolean("isAllowed")); rb.getBaseClass().put(rs.getInt("requiredRuneID"), rs.getBoolean("isAllowed"));
break; break;
case 3: case 3:
rb.getPromotionClass().put(rs.getInt("requiredRuneID"), rs.getBoolean("isAllowed")); rb.getPromotionClass().put(rs.getInt("requiredRuneID"), rs.getBoolean("isAllowed"));
break; break;
case 4: case 4:
rb.getDiscipline().put(rs.getInt("requiredRuneID"), rs.getBoolean("isAllowed")); rb.getDiscipline().put(rs.getInt("requiredRuneID"), rs.getBoolean("isAllowed"));
break; break;
case 5: case 5:
rb.getOverwrite().add(rs.getInt("requiredRuneID")); rb.getOverwrite().add(rs.getInt("requiredRuneID"));
break; break;
case 6: case 6:
rb.setLevelRequired(rs.getInt("requiredRuneID")); rb.setLevelRequired(rs.getInt("requiredRuneID"));
break; break;
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
} }
public RuneBase GET_RUNEBASE(final int id) { public RuneBase GET_RUNEBASE(final int id) {
RuneBase runeBase = null; RuneBase runeBase = null;
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_runebase` WHERE `ID` = ?")) { PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_runebase` WHERE `ID` = ?")) {
preparedStatement.setInt(1, id); preparedStatement.setInt(1, id);
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
runeBase = (RuneBase) getObjectFromRs(rs); runeBase = (RuneBase) getObjectFromRs(rs);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return runeBase; return runeBase;
} }
public ArrayList<RuneBase> LOAD_ALL_RUNEBASES() { public ArrayList<RuneBase> LOAD_ALL_RUNEBASES() {
ArrayList<RuneBase> runeBasesList = new ArrayList<>(); ArrayList<RuneBase> runeBasesList = new ArrayList<>();
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_runebase`;")) { PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_runebase`;")) {
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
runeBasesList = getObjectsFromRs(rs, 1000); runeBasesList = getObjectsFromRs(rs, 1000);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return runeBasesList; return runeBasesList;
} }
public HashMap<Integer, ArrayList<Integer>> LOAD_ALLOWED_STARTING_RUNES_FOR_BASECLASS() { public HashMap<Integer, ArrayList<Integer>> LOAD_ALLOWED_STARTING_RUNES_FOR_BASECLASS() {
HashMap<Integer, ArrayList<Integer>> runeSets = new HashMap<>(); HashMap<Integer, ArrayList<Integer>> runeSets = new HashMap<>();
int recordsRead = 0; int recordsRead = 0;
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_rune_baseclassrune")) { PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_rune_baseclassrune")) {
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) { while (rs.next()) {
recordsRead++; recordsRead++;
int baseClassID = rs.getInt("BaseClassesID"); int baseClassID = rs.getInt("BaseClassesID");
int runeBaseID = rs.getInt("RuneBaseID"); int runeBaseID = rs.getInt("RuneBaseID");
if (runeSets.get(baseClassID) == null) { if (runeSets.get(baseClassID) == null) {
ArrayList<Integer> runeList = new ArrayList<>(); ArrayList<Integer> runeList = new ArrayList<>();
runeList.add(runeBaseID); runeList.add(runeBaseID);
runeSets.put(baseClassID, runeList); runeSets.put(baseClassID, runeList);
} else { } else {
ArrayList<Integer> runeList = runeSets.get(baseClassID); ArrayList<Integer> runeList = runeSets.get(baseClassID);
runeList.add(runeBaseID); runeList.add(runeBaseID);
runeSets.put(baseClassID, runeList); runeSets.put(baseClassID, runeList);
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
Logger.info("read: " + recordsRead + " cached: " + runeSets.size()); Logger.info("read: " + recordsRead + " cached: " + runeSets.size());
return runeSets; return runeSets;
} }
public HashMap<Integer, ArrayList<Integer>> LOAD_ALLOWED_STARTING_RUNES_FOR_RACE() { public HashMap<Integer, ArrayList<Integer>> LOAD_ALLOWED_STARTING_RUNES_FOR_RACE() {
HashMap<Integer, ArrayList<Integer>> runeSets; HashMap<Integer, ArrayList<Integer>> runeSets;
runeSets = new HashMap<>(); runeSets = new HashMap<>();
int recordsRead = 0; int recordsRead = 0;
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_rune_racerune")) { PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_rune_racerune")) {
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) { while (rs.next()) {
recordsRead++; recordsRead++;
int raceID = rs.getInt("RaceID"); int raceID = rs.getInt("RaceID");
int runeBaseID = rs.getInt("RuneBaseID"); int runeBaseID = rs.getInt("RuneBaseID");
if (runeSets.get(raceID) == null) { if (runeSets.get(raceID) == null) {
ArrayList<Integer> runeList = new ArrayList<>(); ArrayList<Integer> runeList = new ArrayList<>();
runeList.add(runeBaseID); runeList.add(runeBaseID);
runeSets.put(raceID, runeList); runeSets.put(raceID, runeList);
} else { } else {
ArrayList<Integer> runeList = runeSets.get(raceID); ArrayList<Integer> runeList = runeSets.get(raceID);
runeList.add(runeBaseID); runeList.add(runeBaseID);
runeSets.put(raceID, runeList); runeSets.put(raceID, runeList);
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
Logger.info("read: " + recordsRead + " cached: " + runeSets.size()); Logger.info("read: " + recordsRead + " cached: " + runeSets.size());
return runeSets; return runeSets;
} }
} }

44
src/engine/db/handlers/dbShrineHandler.java

@ -31,10 +31,28 @@ public class dbShrineHandler extends dbHandlerBase {
this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); this.localObjectType = engine.Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
} }
public ArrayList<AbstractGameObject> CREATE_SHRINE( int parentZoneID, int OwnerUUID, String name, int meshUUID, public static void addObject(ArrayList<AbstractGameObject> list, ResultSet rs) throws SQLException {
Vector3fImmutable location, float meshScale, int currentHP,
ProtectionState protectionState, int currentGold, int rank, String type = rs.getString("type");
DateTime upgradeDate, int blueprintUUID, float w, float rotY, String shrineType) {
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<>(); ArrayList<AbstractGameObject> shrineList = new ArrayList<>();
@ -103,24 +121,6 @@ public class dbShrineHandler extends dbHandlerBase {
} }
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 void LOAD_ALL_SHRINES() { public void LOAD_ALL_SHRINES() {
Shrine shrine; Shrine shrine;

215
src/engine/db/handlers/dbSkillBaseHandler.java

@ -26,113 +26,112 @@ import java.util.HashMap;
public class dbSkillBaseHandler extends dbHandlerBase { public class dbSkillBaseHandler extends dbHandlerBase {
public dbSkillBaseHandler() { public dbSkillBaseHandler() {
this.localClass = SkillsBase.class; this.localClass = SkillsBase.class;
this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
} }
public SkillsBase GET_BASE(final int objectUUID) { public SkillsBase GET_BASE(final int objectUUID) {
SkillsBase skillsBase = (SkillsBase) DbManager.getFromCache(GameObjectType.SkillsBase, objectUUID); SkillsBase skillsBase = (SkillsBase) DbManager.getFromCache(GameObjectType.SkillsBase, objectUUID);
if (skillsBase != null) if (skillsBase != null)
return skillsBase; return skillsBase;
prepareCallable("SELECT * FROM static_skill_skillsbase WHERE ID = ?"); prepareCallable("SELECT * FROM static_skill_skillsbase WHERE ID = ?");
setInt(1, objectUUID); setInt(1, objectUUID);
SkillsBase sb; SkillsBase sb;
sb = (SkillsBase) getObjectSingle(objectUUID); sb = (SkillsBase) getObjectSingle(objectUUID);
SkillsBase.putInCache(sb); SkillsBase.putInCache(sb);
return sb; return sb;
} }
public SkillsBase GET_BASE_BY_NAME(String name) { public SkillsBase GET_BASE_BY_NAME(String name) {
SkillsBase sb = SkillsBase.getFromCache(name); SkillsBase sb = SkillsBase.getFromCache(name);
if (sb != null) { if (sb != null) {
return sb; return sb;
} }
prepareCallable("SELECT * FROM static_skill_skillsbase WHERE name = ?"); prepareCallable("SELECT * FROM static_skill_skillsbase WHERE name = ?");
setString(1, name); setString(1, name);
ArrayList<AbstractGameObject> result = getObjectList(); ArrayList<AbstractGameObject> result = getObjectList();
if (result.size() > 0) { if (result.size() > 0) {
sb = (SkillsBase) result.get(0); sb = (SkillsBase) result.get(0);
SkillsBase.putInCache(sb); SkillsBase.putInCache(sb);
return sb; return sb;
} else { } else {
return null; return null;
} }
} }
public SkillsBase GET_BASE_BY_TOKEN(final int token) { public SkillsBase GET_BASE_BY_TOKEN(final int token) {
SkillsBase sb = SkillsBase.getFromCache(token); SkillsBase sb = SkillsBase.getFromCache(token);
if (sb != null) { if (sb != null) {
return sb; return sb;
} }
prepareCallable("SELECT * FROM static_skill_skillsbase WHERE token = ?"); prepareCallable("SELECT * FROM static_skill_skillsbase WHERE token = ?");
setInt(1, token); setInt(1, token);
ArrayList<AbstractGameObject> result = getObjectList(); ArrayList<AbstractGameObject> result = getObjectList();
if (result.size() > 0) { if (result.size() > 0) {
sb = (SkillsBase) result.get(0); sb = (SkillsBase) result.get(0);
SkillsBase.putInCache(sb); SkillsBase.putInCache(sb);
return sb; return sb;
} else { } else {
return null; return null;
} }
} }
public void LOAD_ALL_MAX_SKILLS_FOR_CONTRACT() { public void LOAD_ALL_MAX_SKILLS_FOR_CONTRACT() {
prepareCallable("SELECT * FROM `static_rune_maxskills`"); prepareCallable("SELECT * FROM `static_rune_maxskills`");
try { try {
ResultSet rs = executeQuery(); ResultSet rs = executeQuery();
//shrines cached in rs for easy cache on creation. //shrines cached in rs for easy cache on creation.
while (rs.next()) { while (rs.next()) {
MaxSkills maxSKills = new MaxSkills(rs); MaxSkills maxSKills = new MaxSkills(rs);
if (MaxSkills.MaxSkillsSet.get(maxSKills.getRuneID()) == null){ if (MaxSkills.MaxSkillsSet.get(maxSKills.getRuneID()) == null) {
ArrayList<MaxSkills> newMaxSkillsList = new ArrayList<>(); ArrayList<MaxSkills> newMaxSkillsList = new ArrayList<>();
newMaxSkillsList.add(maxSKills); newMaxSkillsList.add(maxSKills);
MaxSkills.MaxSkillsSet.put(maxSKills.getRuneID(), newMaxSkillsList); MaxSkills.MaxSkillsSet.put(maxSKills.getRuneID(), newMaxSkillsList);
}else } else
MaxSkills.MaxSkillsSet.get(maxSKills.getRuneID()).add(maxSKills); MaxSkills.MaxSkillsSet.get(maxSKills.getRuneID()).add(maxSKills);
} }
} catch (SQLException e) {
} catch (SQLException e) { Logger.error(e.getErrorCode() + ' ' + e.getMessage(), e);
Logger.error( e.getErrorCode() + ' ' + e.getMessage(), e); } finally {
} finally { closeCallable();
closeCallable(); }
}
}
}
public void LOAD_ALL_RUNE_SKILLS() {
public void LOAD_ALL_RUNE_SKILLS() {
try (Connection connection = DbManager.getConnection();
try (Connection connection = DbManager.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_skill_skillsgranted`")) {
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_skill_skillsgranted`")) {
ResultSet rs = preparedStatement.executeQuery();
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) {
while (rs.next()) {
int runeID = rs.getInt("runeID");
int runeID = rs.getInt("runeID"); int token = rs.getInt("token");
int token = rs.getInt("token"); int amount = rs.getInt("amount");
int amount = rs.getInt("amount");
if (SkillsBase.runeSkillsCache.get(runeID) == null)
if (SkillsBase.runeSkillsCache.get(runeID) == null) SkillsBase.runeSkillsCache.put(runeID, new HashMap<>());
SkillsBase.runeSkillsCache.put(runeID, new HashMap<>());
SkillsBase.runeSkillsCache.get(runeID).put(token, amount);
SkillsBase.runeSkillsCache.get(runeID).put(token, amount); }
}
} catch (SQLException e) {
} catch (SQLException e) { Logger.error(e);
Logger.error(e); }
} }
}
} }

36
src/engine/db/handlers/dbVendorDialogHandler.java

@ -21,30 +21,30 @@ import java.sql.SQLException;
public class dbVendorDialogHandler extends dbHandlerBase { public class dbVendorDialogHandler extends dbHandlerBase {
public dbVendorDialogHandler() { public dbVendorDialogHandler() {
this.localClass = VendorDialog.class; this.localClass = VendorDialog.class;
this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName()); this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
} }
public VendorDialog GET_VENDORDIALOG(final int objectUUID) { public VendorDialog GET_VENDORDIALOG(final int objectUUID) {
VendorDialog vendorDialog = (VendorDialog) DbManager.getFromCache(Enum.GameObjectType.VendorDialog, objectUUID); VendorDialog vendorDialog = (VendorDialog) DbManager.getFromCache(Enum.GameObjectType.VendorDialog, objectUUID);
if (vendorDialog != null) if (vendorDialog != null)
return vendorDialog; return vendorDialog;
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_vendordialog` WHERE `ID`=?")) { PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_vendordialog` WHERE `ID`=?")) {
preparedStatement.setInt(1, objectUUID); preparedStatement.setInt(1, objectUUID);
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
vendorDialog = (VendorDialog) getObjectFromRs(rs); vendorDialog = (VendorDialog) getObjectFromRs(rs);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return vendorDialog; return vendorDialog;
} }
} }

19
src/engine/db/handlers/dbZoneHandler.java

@ -11,6 +11,8 @@ package engine.db.handlers;
import engine.Enum; import engine.Enum;
import engine.gameManager.DbManager; import engine.gameManager.DbManager;
import engine.gameManager.ZoneManager;
import engine.math.Vector2f;
import engine.objects.Zone; import engine.objects.Zone;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
@ -77,7 +79,7 @@ public class dbZoneHandler extends dbHandlerBase {
try (Connection connection = DbManager.getConnection(); 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 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, (long) objectUUID); preparedStatement.setLong(1, objectUUID);
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
zoneList = getObjectsFromRs(rs, 2000); zoneList = getObjectsFromRs(rs, 2000);
@ -89,19 +91,24 @@ public class dbZoneHandler extends dbHandlerBase {
return zoneList; return zoneList;
} }
public ResultSet GET_ZONE_EXTENTS(final int loadNum) { public void LOAD_ZONE_EXTENTS() {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_zone_size` WHERE `loadNum`=?;")) { PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_zone_size`;")) {
preparedStatement.setInt(1, loadNum); ResultSet rs = preparedStatement.executeQuery();
return 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) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
} }
return null;
} }
public boolean DELETE_ZONE(final Zone zone) { public boolean DELETE_ZONE(final Zone zone) {

26
src/engine/gameManager/ZoneManager.java

@ -24,10 +24,7 @@ import org.pmw.tinylog.Logger;
import java.time.Instant; import java.time.Instant;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.util.ArrayList; import java.util.*;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
@ -39,17 +36,18 @@ public enum ZoneManager {
ZONEMANAGER; ZONEMANAGER;
public static Instant hotZoneLastUpdate; public static final Set<Zone> macroZones = Collections.newSetFromMap(new ConcurrentHashMap<>());
/* Instance variables */
private static Zone seaFloor = null;
public static Zone hotZone = null;
public static int hotZoneCycle = 0; // Used with HOTZONE_DURATION from config.
private static final ConcurrentHashMap<Integer, Zone> zonesByID = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD); private static final ConcurrentHashMap<Integer, Zone> zonesByID = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD);
private static final ConcurrentHashMap<Integer, Zone> zonesByUUID = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD); private static final ConcurrentHashMap<Integer, Zone> zonesByUUID = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD);
private static final ConcurrentHashMap<String, Zone> zonesByName = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD); private static final ConcurrentHashMap<String, Zone> zonesByName = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD);
public static final Set<Zone> macroZones = Collections.newSetFromMap(new ConcurrentHashMap<>());
private static final Set<Zone> npcCityZones = Collections.newSetFromMap(new ConcurrentHashMap<>()); private static final Set<Zone> npcCityZones = Collections.newSetFromMap(new ConcurrentHashMap<>());
private static final Set<Zone> playerCityZones = Collections.newSetFromMap(new ConcurrentHashMap<>()); private static final Set<Zone> playerCityZones = Collections.newSetFromMap(new ConcurrentHashMap<>());
public static Instant hotZoneLastUpdate;
public static Zone hotZone = null;
public static int hotZoneCycle = 0; // Used with HOTZONE_DURATION from config.
public static HashMap<Integer, Vector2f> _zone_size_data = new HashMap<>();
/* Instance variables */
private static Zone seaFloor = null;
// Find all zones coordinates fit into, starting with Sea Floor // Find all zones coordinates fit into, starting with Sea Floor
@ -170,14 +168,14 @@ public enum ZoneManager {
return (Bounds.collide(loc, ZoneManager.hotZone.getBounds()) == true); return (Bounds.collide(loc, ZoneManager.hotZone.getBounds()) == true);
} }
public static void setSeaFloor(final Zone value) {
ZoneManager.seaFloor = value;
}
public static Zone getSeaFloor() { public static Zone getSeaFloor() {
return ZoneManager.seaFloor; return ZoneManager.seaFloor;
} }
public static void setSeaFloor(final Zone value) {
ZoneManager.seaFloor = value;
}
public static final void populateWorldZones(final Zone zone) { public static final void populateWorldZones(final Zone zone) {
int loadNum = zone.getLoadNum(); int loadNum = zone.getLoadNum();

261
src/engine/objects/Zone.java

@ -30,19 +30,25 @@ import java.util.concurrent.ConcurrentHashMap;
public class Zone extends AbstractGameObject { public class Zone extends AbstractGameObject {
public final Set<Building> zoneBuildingSet = Collections.newSetFromMap(new ConcurrentHashMap<>());
public final Set<NPC> zoneNPCSet = Collections.newSetFromMap(new ConcurrentHashMap<>());
public final Set<Mob> zoneMobSet = Collections.newSetFromMap(new ConcurrentHashMap<>());
private final int playerCityID; private final int playerCityID;
private final String zoneName; private final String zoneName;
private final float xCoord; private final float xCoord;
private final float zCoord; private final float zCoord;
private final float yCoord; private final float yCoord;
public float absX = 0.0f;
public float absY = 0.0f;
public float absZ = 0.0f;
private final int loadNum; private final int loadNum;
private final byte safeZone; private final byte safeZone;
private final String Icon1; private final String Icon1;
private final String Icon2; private final String Icon2;
private final String Icon3; private final String Icon3;
public float absX = 0.0f;
public float absY = 0.0f;
public float absZ = 0.0f;
public int minLvl;
public int maxLvl;
public boolean hasBeenHotzone = false;
private ArrayList<Zone> nodes = null; private ArrayList<Zone> nodes = null;
private int parentZoneID; private int parentZoneID;
private Zone parent = null; private Zone parent = null;
@ -50,16 +56,9 @@ public class Zone extends AbstractGameObject {
private boolean isNPCCity = false; private boolean isNPCCity = false;
private boolean isPlayerCity = false; private boolean isPlayerCity = false;
private String hash; private String hash;
public int minLvl;
public int maxLvl;
private float worldAltitude = 0; private float worldAltitude = 0;
private float seaLevel = 0; private float seaLevel = 0;
public final Set<Building> zoneBuildingSet = Collections.newSetFromMap(new ConcurrentHashMap<>());
public final Set<NPC> zoneNPCSet = Collections.newSetFromMap(new ConcurrentHashMap<>());
public final Set<Mob> zoneMobSet = Collections.newSetFromMap(new ConcurrentHashMap<>());
public boolean hasBeenHotzone = false;
/** /**
* ResultSet Constructor * ResultSet Constructor
*/ */
@ -87,7 +86,7 @@ public class Zone extends AbstractGameObject {
this.setParent(parentZone); this.setParent(parentZone);
if (this.minLvl == 0 && parentZone != null){ if (this.minLvl == 0 && parentZone != null) {
this.minLvl = parentZone.minLvl; this.minLvl = parentZone.minLvl;
this.maxLvl = parentZone.maxLvl; this.maxLvl = parentZone.maxLvl;
} }
@ -103,6 +102,59 @@ public class Zone extends AbstractGameObject {
} }
public static void serializeForClientMsg(Zone zone, ByteBufferWriter writer) {
if (zone.loadNum == 0 && zone.playerCityID == 0)
Logger.warn("Warning! WorldServerMap with ID " + zone.getObjectUUID() + " has a loadnum of 0 (player city) and no city linked. This will probably crash the client!");
// Player City Terraform values serialized here.
if (zone.playerCityID > 0) {
writer.put((byte) 1); // Player City - True
writer.putFloat(Enum.CityBoundsType.ZONE.extents);
writer.putFloat(Enum.CityBoundsType.ZONE.extents);
} else
writer.put((byte) 0); // Player City - False
writer.putFloat(zone.xCoord);
writer.putFloat(zone.zCoord);
writer.putFloat(zone.yCoord);
writer.putInt(0);
writer.putInt(0);
writer.putInt(zone.loadNum);
if (zone.playerCityID > 0) {
City k = City.getCity(zone.playerCityID);
if (k != null) {
writer.putInt(k.getObjectType().ordinal());
writer.putInt(k.getObjectUUID());
} else
writer.putLong(0x0);
} else {
writer.putInt(zone.getObjectType().ordinal());
writer.putInt(zone.getObjectUUID());
}
writer.putInt(zone.nodes.size());
City city = City.getCity(zone.playerCityID);
if (city != null)
writer.putString(city.getCityName());
else
writer.putString(zone.zoneName);
writer.put(zone.safeZone);
writer.putString(zone.Icon1);
writer.putString(zone.Icon2);
writer.putString(zone.Icon3);
writer.put((byte) 0); // Pad
for (Zone child : zone.nodes) {
Zone.serializeForClientMsg(child, writer);
}
}
/* Method sets a default value for player cities /* Method sets a default value for player cities
* otherwise using values derived from the loadnum * otherwise using values derived from the loadnum
* field in the obj_zone database table. * field in the obj_zone database table.
@ -123,38 +175,18 @@ public class Zone extends AbstractGameObject {
return; return;
} }
// All other zones have bounding boxes loaded from database Vector2f zoneSize = ZoneManager._zone_size_data.get(this.loadNum);
ResultSet rs = DbManager.ZoneQueries.GET_ZONE_EXTENTS(this.loadNum);
boolean loaded = false;
if (rs != null)
try {
if (rs.next()) {
halfExtentX = rs.getFloat("xRadius");
halfExtentY = rs.getFloat("zRadius");
this.bounds.setBounds(new Vector2f(this.absX, this.absZ), new Vector2f(halfExtentX, halfExtentY), 0.0f);
loaded = true;
}
} catch (SQLException e) { // Default to player zone size on error? Maybe log this
Logger.error("SQLException: " + e.getMessage());
}
if (!loaded) {
// Default to Citygrid size on error
if (zoneSize != null)
this.bounds.setBounds(new Vector2f(this.absX, this.absZ), zoneSize, 0.0f);
else
bounds.setBounds(new Vector2f(this.absX, this.absZ), new Vector2f(Enum.CityBoundsType.ZONE.extents, Enum.CityBoundsType.ZONE.extents), 0.0f); bounds.setBounds(new Vector2f(this.absX, this.absZ), new Vector2f(Enum.CityBoundsType.ZONE.extents, Enum.CityBoundsType.ZONE.extents), 0.0f);
}
} }
/*
* Getters
*/
public int getPlayerCityUUID() { public int getPlayerCityUUID() {
if (this.playerCityID == 0)
return 0;
return this.playerCityID; return this.playerCityID;
} }
@ -178,10 +210,6 @@ public class Zone extends AbstractGameObject {
return loadNum; return loadNum;
} }
public int getLoadNumClient() {
return loadNum;
}
public byte getSafeZone() { public byte getSafeZone() {
return safeZone; return safeZone;
} }
@ -190,45 +218,9 @@ public class Zone extends AbstractGameObject {
return Icon1; return Icon1;
} }
public String getIcon2() { public void generateWorldAltitude() {
return Icon2;
}
public String getIcon3() {
return Icon3;
}
public void setParent(final Zone value) {
this.parent = value;
this.parentZoneID = (this.parent != null) ? this.parent.getObjectUUID() : 0;
if (this.parent != null) {
this.absX = this.xCoord + parent.absX;
this.absY = this.yCoord + parent.absY;
this.absZ = this.zCoord + parent.absZ;
if (this.minLvl == 0 || this.maxLvl == 0){
this.minLvl = this.parent.minLvl;
this.maxLvl = this.parent.maxLvl;
}
} else { //only the Sea Floor zone does not have a parent
this.absX = this.xCoord;
this.absY = MBServerStatics.SEA_FLOOR_ALTITUDE;
this.absZ = this.zCoord;
}
// Zone AABB is set here as it's coordinate space is world requiring a parent.
this.setBounds();
if (this.getHeightMap() != null && this.getHeightMap().getSeaLevel() != 0)
this.seaLevel = this.getHeightMap().getSeaLevel();
}
public void generateWorldAltitude(){
if (ZoneManager.getSeaFloor().getObjectUUID() == this.getObjectUUID()){ if (ZoneManager.getSeaFloor().getObjectUUID() == this.getObjectUUID()) {
this.worldAltitude = MBServerStatics.SEA_FLOOR_ALTITUDE; this.worldAltitude = MBServerStatics.SEA_FLOOR_ALTITUDE;
return; return;
} }
@ -240,9 +232,9 @@ public class Zone extends AbstractGameObject {
//seafloor only zone with null parent; //seafloor only zone with null parent;
while(parentZone != ZoneManager.getSeaFloor()){ while (parentZone != ZoneManager.getSeaFloor()) {
if(parentZone.getHeightMap() != null){ if (parentZone.getHeightMap() != null) {
Vector2f zoneLoc = ZoneManager.worldToZoneSpace(currentZone.getLoc(), parentZone); Vector2f zoneLoc = ZoneManager.worldToZoneSpace(currentZone.getLoc(), parentZone);
altitude += parentZone.getHeightMap().getInterpolatedTerrainHeight(zoneLoc); altitude += parentZone.getHeightMap().getInterpolatedTerrainHeight(zoneLoc);
@ -258,14 +250,14 @@ public class Zone extends AbstractGameObject {
if (ZoneManager.getSeaFloor().equals(this)) if (ZoneManager.getSeaFloor().equals(this))
this.seaLevel = 0; this.seaLevel = 0;
else if else if
(this.getHeightMap() != null && this.getHeightMap().getSeaLevel() == 0){ (this.getHeightMap() != null && this.getHeightMap().getSeaLevel() == 0) {
this.seaLevel = this.parent.seaLevel; this.seaLevel = this.parent.seaLevel;
}else if (this.getHeightMap() != null){ } else if (this.getHeightMap() != null) {
this.seaLevel = this.worldAltitude + this.getHeightMap().getSeaLevel(); this.seaLevel = this.worldAltitude + this.getHeightMap().getSeaLevel();
}else { } else {
this.seaLevel = this.parent.seaLevel; this.seaLevel = this.parent.seaLevel;
} }
} }
@ -273,6 +265,34 @@ public class Zone extends AbstractGameObject {
return this.parent; return this.parent;
} }
public void setParent(final Zone value) {
this.parent = value;
this.parentZoneID = (this.parent != null) ? this.parent.getObjectUUID() : 0;
if (this.parent != null) {
this.absX = this.xCoord + parent.absX;
this.absY = this.yCoord + parent.absY;
this.absZ = this.zCoord + parent.absZ;
if (this.minLvl == 0 || this.maxLvl == 0) {
this.minLvl = this.parent.minLvl;
this.maxLvl = this.parent.maxLvl;
}
} else { //only the Sea Floor zone does not have a parent
this.absX = this.xCoord;
this.absY = MBServerStatics.SEA_FLOOR_ALTITUDE;
this.absZ = this.zCoord;
}
// Zone AABB is set here as it's coordinate space is world requiring a parent.
this.setBounds();
if (this.getHeightMap() != null && this.getHeightMap().getSeaLevel() != 0)
this.seaLevel = this.getHeightMap().getSeaLevel();
}
public float getAbsX() { public float getAbsX() {
return this.absX; return this.absX;
} }
@ -302,14 +322,14 @@ public class Zone extends AbstractGameObject {
return this.isNPCCity; return this.isNPCCity;
} }
public boolean isPlayerCity() {
return this.isPlayerCity;
}
public void setNPCCity(boolean value) { public void setNPCCity(boolean value) {
this.isNPCCity = value; this.isNPCCity = value;
} }
public boolean isPlayerCity() {
return this.isPlayerCity;
}
public void setPlayerCity(boolean value) { public void setPlayerCity(boolean value) {
this.isPlayerCity = value; this.isPlayerCity = value;
} }
@ -336,67 +356,12 @@ public class Zone extends AbstractGameObject {
return nodes; return nodes;
} }
public void addNode(Zone child) {
this.nodes.add(child);
}
/* /*
* Serializing * Serializing
*/ */
public void addNode(Zone child) {
public static void serializeForClientMsg(Zone zone,ByteBufferWriter writer) { this.nodes.add(child);
if (zone.loadNum == 0 && zone.playerCityID == 0)
Logger.warn( "Warning! WorldServerMap with ID " + zone.getObjectUUID() + " has a loadnum of 0 (player city) and no city linked. This will probably crash the client!");
// Player City Terraform values serialized here.
if (zone.playerCityID > 0) {
writer.put((byte) 1); // Player City - True
writer.putFloat(Enum.CityBoundsType.ZONE.extents);
writer.putFloat(Enum.CityBoundsType.ZONE.extents);
} else
writer.put((byte) 0); // Player City - False
writer.putFloat(zone.xCoord);
writer.putFloat(zone.zCoord);
writer.putFloat(zone.yCoord);
writer.putInt(0);
writer.putInt(0);
writer.putInt(zone.loadNum);
if (zone.playerCityID > 0) {
City k = City.getCity(zone.playerCityID);
if (k != null) {
writer.putInt(k.getObjectType().ordinal());
writer.putInt(k.getObjectUUID());
}
else
writer.putLong(0x0);
} else {
writer.putInt(zone.getObjectType().ordinal());
writer.putInt(zone.getObjectUUID());
}
writer.putInt(zone.nodes.size());
City city = City.getCity(zone.playerCityID);
if (city != null)
writer.putString(city.getCityName());
else
writer.putString(zone.zoneName);
writer.put(zone.safeZone);
writer.putString(zone.Icon1);
writer.putString(zone.Icon2);
writer.putString(zone.Icon3);
writer.put((byte) 0); // Pad
for (Zone child : zone.nodes) {
Zone.serializeForClientMsg(child,writer);
}
} }
@Override @Override

Loading…
Cancel
Save