Browse Source

Refactor to remove abstraction

master
MagicBot 2 years ago
parent
commit
8cb0e66bff
  1. 203
      src/engine/db/handlers/dbGuildHandler.java
  2. 105
      src/engine/devcmd/cmds/GuildListCmd.java
  3. 1
      src/engine/gameManager/DevCmdManager.java

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

@ -17,8 +17,7 @@ import engine.server.MBServerStatics;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.sql.ResultSet; import java.sql.*;
import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
public class dbGuildHandler extends dbHandlerBase { public class dbGuildHandler extends dbHandlerBase {
@ -29,96 +28,129 @@ public class dbGuildHandler extends dbHandlerBase {
} }
public int BANISH_FROM_GUILD_OFFLINE(final int target, boolean sourceIsGuildLeader) { public int BANISH_FROM_GUILD_OFFLINE(final int target, boolean sourceIsGuildLeader) {
if (!sourceIsGuildLeader) //one IC cannot banish another IC
prepareCallable("UPDATE `obj_character` SET `guildUID`=NULL, `guild_isInnerCouncil`=0, `guild_isTaxCollector`=0," String queryString;
+ " `guild_isRecruiter`=0, `guild_isFullMember`=0, `guild_title`=0 WHERE `UID`=? && `guild_isInnerCouncil`=0"); int rowCount;
// Only a Guild Leader can remove inner council
if (sourceIsGuildLeader)
queryString = "UPDATE `obj_character` SET `guildUID`=NULL, `guild_isInnerCouncil`=0, `guild_isTaxCollector`=0,"
+ " `guild_isRecruiter`=0, `guild_isFullMember`=0, `guild_title`=0 WHERE `UID`=?";
else else
prepareCallable("UPDATE `obj_character` SET `guildUID`=NULL, `guild_isInnerCouncil`=0, `guild_isTaxCollector`=0," queryString = "UPDATE `obj_character` SET `guildUID`=NULL, `guild_isInnerCouncil`=0, `guild_isTaxCollector`=0,"
+ " `guild_isRecruiter`=0, `guild_isFullMember`=0, `guild_title`=0 WHERE `UID`=?"); + " `guild_isRecruiter`=0, `guild_isFullMember`=0, `guild_title`=0 WHERE `UID`=? && `guild_isInnerCouncil`=0";
setLong(1, (long) target);
return executeUpdate();
}
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(queryString)) {
preparedStatement.setLong(1, target);
rowCount = preparedStatement.executeUpdate();
} catch (SQLException e) {
Logger.error(e);
return 0;
}
return rowCount;
}
public boolean ADD_TO_BANISHED_FROM_GUILDLIST(int target, long characterID) { public boolean ADD_TO_BANISHED_FROM_GUILDLIST(int target, long characterID) {
prepareCallable("INSERT INTO `dyn_guild_banishlist` (`GuildID`, `CharacterID`) VALUES (?,?)");
setLong(1, (long) target); try (Connection connection = DbManager.getConnection();
setLong(2, characterID); PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_guild_banishlist` (`GuildID`, `CharacterID`) VALUES (?,?)")) {
return (executeUpdate() > 0);
preparedStatement.setLong(1, (long) target);
preparedStatement.setLong(2, characterID);
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
return false;
}
} }
public boolean REMOVE_FROM_BANISH_LIST(int target, long characterID) { public boolean REMOVE_FROM_BANISH_LIST(int target, long characterID) {
prepareCallable("DELETE FROM `dyn_guild_banishlist` (`GuildID`, `CharacterID`) VALUES (?,?)");
setLong(1, (long) target);
setLong(2, characterID);
return (executeUpdate() > 0);
}
public boolean ADD_TO_GUILDHISTORY(int target, PlayerCharacter pc, DateTime historyDate, GuildHistoryType historyType) { try (Connection connection = DbManager.getConnection();
prepareCallable("INSERT INTO `dyn_character_guildhistory` (`GuildID`, `CharacterID`, `historyDate`, `historyType`) VALUES (?,?,?,?)"); PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_guild_banishlist` (`GuildID`, `CharacterID`) VALUES (?,?)")) {
setLong(1, (long) target);
setLong(2, pc.getObjectUUID());
if (historyDate == null) preparedStatement.setLong(1, (long) target);
setNULL(3, java.sql.Types.DATE); preparedStatement.setLong(2, characterID);
else
setTimeStamp(3, historyDate.getMillis());
setString(4,historyType.name());
return (executeUpdate() > 0);
}
//TODO Need to get this working. return (preparedStatement.executeUpdate() > 0);
public ArrayList<Guild> GET_GUILD_HISTORY_OF_PLAYER(final int id) {
prepareCallable("SELECT g.* FROM `obj_guild` g, `dyn_character_guildhistory` l WHERE g.`UID` = l.`GuildID` && l.`CharacterID` = ?"); } catch (SQLException e) {
setLong(1, (long) id); Logger.error(e);
return getObjectList(); return false;
}
} }
public String GET_GUILD_LIST(int guildType) { public boolean ADD_TO_GUILDHISTORY(int target, PlayerCharacter playerCharacter, DateTime historyDate, GuildHistoryType historyType) {
String newLine = System.getProperty("line.separator"); try (Connection connection = DbManager.getConnection();
String outputStr = null; PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_character_guildhistory` (`GuildID`, `CharacterID`, `historyDate`, `historyType`) VALUES (?,?,?,?)")) {
ResultSet resultSet;
// Setup and execute stored procedure preparedStatement.setLong(1, target);
preparedStatement.setLong(2, playerCharacter.getObjectUUID());
prepareCallable("CALL `guild_GETLIST`(?)"); if (historyDate == null)
setInt(1, guildType); preparedStatement.setNull(3, java.sql.Types.DATE);
resultSet = executeQuery(); else
preparedStatement.setTimestamp(3, new Timestamp(historyDate.getMillis()));
// Build formatted string with data from query preparedStatement.setString(4, historyType.name());
outputStr += newLine; return (preparedStatement.executeUpdate() > 0);
outputStr += String.format("%-10s %-30s %-10s %-10s", "UUID", "Name", "GL UUID", "TOL_UUID");
outputStr += newLine;
try { } catch (SQLException e) {
Logger.error(e);
return false;
}
while (resultSet.next()) { }
outputStr += String.format("%-10d %-30s %-10d %-10d", resultSet.getInt(1), //TODO Need to get this working.
resultSet.getString(2), resultSet.getInt(3), resultSet.getInt(4)); public ArrayList<Guild> GET_GUILD_HISTORY_OF_PLAYER(final int id) {
outputStr += newLine;
} ArrayList<Guild> guildList = null;
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT g.* FROM `obj_guild` g, `dyn_character_guildhistory` l WHERE g.`UID` = l.`GuildID` && l.`CharacterID` = ?")) {
preparedStatement.setLong(1, id);
// Exception handling ResultSet rs = preparedStatement.executeQuery();
guildList = getObjectsFromRs(rs, 20);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error( e.getMessage()); Logger.error(e);
} finally {
closeCallable();
} }
return outputStr; return guildList;
} }
public ArrayList<Guild> GET_GUILD_ALLIES(final int id) { public ArrayList<Guild> GET_GUILD_ALLIES(final int id) {
prepareCallable("SELECT g.* FROM `obj_guild` g, `dyn_guild_allianceenemylist` l "
+ "WHERE l.isAlliance = 1 && l.OtherGuildID = g.UID && l.GuildID=?"); ArrayList<Guild> guildList = null;
setLong(1, (long) id);
return getObjectList(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT g.* FROM `obj_guild` g, `dyn_guild_allianceenemylist` l "
+ "WHERE l.isAlliance = 1 && l.OtherGuildID = g.UID && l.GuildID=?")) {
preparedStatement.setLong(1, id);
ResultSet rs = preparedStatement.executeQuery();
guildList = getObjectsFromRs(rs, 20);
} catch (SQLException e) {
Logger.error(e);
}
return guildList;
} }
@ -136,16 +168,49 @@ public class dbGuildHandler extends dbHandlerBase {
} }
public ArrayList<Guild> GET_GUILD_ENEMIES(final int id) { public ArrayList<Guild> GET_GUILD_ENEMIES(final int id) {
prepareCallable("SELECT g.* FROM `obj_guild` g, `dyn_guild_allianceenemylist` l "
+ "WHERE l.isAlliance = 0 && l.OtherGuildID = g.UID && l.GuildID=?"); ArrayList<Guild> guildList = null;
setLong(1, (long) id);
return getObjectList(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT g.* FROM `obj_guild` g, `dyn_guild_allianceenemylist` l "
+ "WHERE l.isAlliance = 0 && l.OtherGuildID = g.UID && l.GuildID=?")) {
preparedStatement.setLong(1, id);
ResultSet rs = preparedStatement.executeQuery();
guildList = getObjectsFromRs(rs, 20);
} catch (SQLException e) {
Logger.error(e);
}
return guildList;
} }
public ArrayList<PlayerCharacter> GET_GUILD_KOS_CHARACTER(final int id) { public ArrayList<PlayerCharacter> GET_GUILD_KOS_CHARACTER(final int id) {
prepareCallable("SELECT c.* FROM `obj_character` c, `dyn_guild_characterkoslist` l WHERE c.`char_isActive` = 1 && l.`KOSCharacterID` = c.`UID` && l.`GuildID`=?");
setLong(1, (long) id); ArrayList<PlayerCharacter> kosList = null;
return getObjectList();
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT c.* FROM `obj_character` c, `dyn_guild_characterkoslist` l WHERE c.`char_isActive` = 1 && l.`KOSCharacterID` = c.`UID` && l.`GuildID`=?")) {
preparedStatement.setLong(1, id);
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) {
int playerUUID = rs.getInt(1);
PlayerCharacter kosPlayer = PlayerCharacter.getPlayerCharacter(playerUUID);
if (kosPlayer != null)
kosList.add(kosPlayer);
}
} catch (SQLException e) {
Logger.error(e);
}
return kosList;
} }
public ArrayList<Guild> GET_GUILD_KOS_GUILD(final int id) { public ArrayList<Guild> GET_GUILD_KOS_GUILD(final int id) {

105
src/engine/devcmd/cmds/GuildListCmd.java

@ -1,105 +0,0 @@
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.devcmd.cmds;
import engine.devcmd.AbstractDevCmd;
import engine.gameManager.DbManager;
import engine.objects.AbstractGameObject;
import engine.objects.PlayerCharacter;
/**
* @author
* Summary: Lists UID, Name and GL UID of either
* Player or NPC sovereign guilds
*/
public class GuildListCmd extends AbstractDevCmd {
// Instance variables
private int _guildType; // 0 = Player : 1 = NPC sovereign guilds
private String outputStr = null;
public GuildListCmd() {
super("guildlist");
}
// AbstractDevCmd Overridden methods
@Override
protected void _doCmd(PlayerCharacter pc, String[] args,
AbstractGameObject target) {
if(validateUserInput(args) == false) {
this.sendUsage(pc);
return;
}
parseUserInput(args);
// Execute stored procedure
outputStr = DbManager.GuildQueries.GET_GUILD_LIST(_guildType);
// Send results to user
throwbackInfo(pc, outputStr);
}
@Override
protected String _getHelpString() {
return "Lists guild info for sovereign guilds";
}
@Override
protected String _getUsageString() {
return "/guildlist npc|player";
}
// Class methods
private static boolean validateUserInput(String[] userInput) {
int stringIndex;
String commandSet = "npcplayer";
// incorrect number of arguments test
if (userInput.length != 1)
return false;
// Test of game object type argument
stringIndex = commandSet.indexOf(userInput[0].toLowerCase());
return stringIndex != -1;
}
private void parseUserInput(String[] userInput) {
// Build mask from user input
switch (userInput[0].toLowerCase()) {
case "npc":
_guildType = 1;
break;
case "player":
_guildType = 0;
break;
default:
break;
}
}
}

1
src/engine/gameManager/DevCmdManager.java

@ -112,7 +112,6 @@ public enum DevCmdManager {
DevCmdManager.registerDevCmd(new DecachePlayerCmd()); DevCmdManager.registerDevCmd(new DecachePlayerCmd());
DevCmdManager.registerDevCmd(new AuditMobsCmd()); DevCmdManager.registerDevCmd(new AuditMobsCmd());
DevCmdManager.registerDevCmd(new ChangeNameCmd()); DevCmdManager.registerDevCmd(new ChangeNameCmd());
DevCmdManager.registerDevCmd(new GuildListCmd());
DevCmdManager.registerDevCmd(new SetGuildCmd()); DevCmdManager.registerDevCmd(new SetGuildCmd());
DevCmdManager.registerDevCmd(new SetOwnerCmd()); DevCmdManager.registerDevCmd(new SetOwnerCmd());
DevCmdManager.registerDevCmd(new NetDebugCmd()); DevCmdManager.registerDevCmd(new NetDebugCmd());

Loading…
Cancel
Save