From f653376c22c117b7f2d311d4980c855f91f6c1d9 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 05:31:16 -0400 Subject: [PATCH] Handler created for ClientAdminCommandMsg --- src/engine/gameManager/ChatManager.java | 94 +------------ src/engine/net/client/ClientMessagePump.java | 4 - src/engine/net/client/Protocol.java | 2 +- .../ClientAdminCommandMsgHandler.java | 126 ++++++++++++++++++ 4 files changed, 129 insertions(+), 97 deletions(-) create mode 100644 src/engine/net/client/handlers/ClientAdminCommandMsgHandler.java diff --git a/src/engine/gameManager/ChatManager.java b/src/engine/gameManager/ChatManager.java index ca1aa00c..9180c1b9 100644 --- a/src/engine/gameManager/ChatManager.java +++ b/src/engine/gameManager/ChatManager.java @@ -21,8 +21,8 @@ import engine.net.DispatchMessage; import engine.net.MessageDispatcher; import engine.net.client.ClientConnection; import engine.net.client.Protocol; +import engine.net.client.handlers.ClientAdminCommandMsgHandler; import engine.net.client.msg.chat.*; -import engine.net.client.msg.commands.ClientAdminCommandMsg; import engine.objects.*; import engine.server.MBServerStatics; import engine.server.world.WorldServer; @@ -190,7 +190,7 @@ public enum ChatManager { } if (ChatManager.isDevCommand(text) == true) { - ChatManager.processDevCommand(player, text); + ClientAdminCommandMsgHandler.processDevCommand(player, text); return; } @@ -1083,94 +1083,4 @@ public enum ChatManager { return text.equalsIgnoreCase("lua_population()"); } - private static boolean processDevCommand(AbstractWorldObject sender, String text) { - - if (sender.getObjectType().equals(GameObjectType.PlayerCharacter)) { - - PlayerCharacter pcSender = (PlayerCharacter) sender; - - // first remove the DEV_CMD_PREFIX - String[] words = text.split(MBServerStatics.DEV_CMD_PREFIX, 2); - - if (words[1].length() == 0) - return false; - - // next get the command - String[] commands = words[1].split(" ", 2); - String cmd = commands[0].toLowerCase(); - String cmdArgument = ""; - - if (commands.length > 1) - cmdArgument = commands[1].trim(); - - AbstractGameObject target = pcSender.getLastTarget(); - // return DevCmd.processDevCommand(pcSender, cmd, cmdArgument, - // target); - return DevCmdManager.handleDevCmd(pcSender, cmd, - cmdArgument, target); - } - return false; - } - - /** - * Process an Admin Command, which is a preset command sent from the client - */ - public static void HandleClientAdminCmd(ClientAdminCommandMsg data, - ClientConnection cc) { - - PlayerCharacter pcSender = SessionManager.getPlayerCharacter(cc); - - if (pcSender == null) - return; - - Account acct = SessionManager.getAccount(pcSender); - - if (acct == null) - return; - - // require minimal access to continue - // specific accessLevel checks performed by the DevCmdManager - if (acct.status.equals(Enum.AccountStatus.ADMIN) == false) { - Logger.warn(pcSender.getFirstName() + " Attempted to use a client admin command"); - //wtf? ChatManager.chatSystemInfo(pcSender, "CHEATER!!!!!!!!!!!!!"); - return; - } - - // First remove the initial slash - String d = data.getMsgCommand(); - String[] words = d.split("/", 2); - - if (words[1].length() == 0) - return; - - // Next get the command - String[] commands = words[1].split(" ", 2); - String cmd = commands[0].toLowerCase(); - String cmdArgument = ""; - - if (commands.length > 1) - cmdArgument = commands[1].trim(); - - AbstractGameObject target = data.getTarget(); - - // Map to a DevCmd - String devCmd = ""; - - if (cmd.compareTo("goto") == 0) - devCmd = "goto"; - else if (cmd.compareTo("suspend") == 0) - devCmd = "suspend"; - else if (cmd.compareTo("getinfo") == 0) - devCmd = "info"; - else if (devCmd.isEmpty()) { - Logger.info("Unhandled admin command was used: /" - + cmd); - return; - } - - DevCmdManager.handleDevCmd(pcSender, devCmd, cmdArgument, - target); - } - - } diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 84a799df..a8391b11 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -22,7 +22,6 @@ import engine.net.NetMsgHandler; import engine.net.client.handlers.AbstractClientMsgHandler; import engine.net.client.msg.*; import engine.net.client.msg.chat.AbstractChatMsg; -import engine.net.client.msg.commands.ClientAdminCommandMsg; import engine.objects.*; import engine.server.MBServerStatics; import engine.server.world.WorldServer; @@ -379,9 +378,6 @@ public class ClientMessagePump implements NetMsgHandler { break; case OPENVAULT: break; - case CLIENTADMINCOMMAND: - ChatManager.HandleClientAdminCmd((ClientAdminCommandMsg) msg, origin); - break; case COMBATMODE: CombatManager.toggleCombat(((ToggleCombatMsg) msg).toggleCombat(), origin); break; diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index 936c7256..c498933f 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -77,7 +77,7 @@ public enum Protocol { CITYZONE(0x254947F2, CityZoneMsg.class, null), //For Creating City Object Clientside(Terraform)/Rename City. CLAIMASSET(0x948C62CC, ClaimAssetMsg.class, ClaimAssetMsgHandler.class), // ClaimAsset CLAIMGUILDTREE(0xFD1C6442, ClaimGuildTreeMsg.class, ClaimGuildTreeMsgHandler.class), - CLIENTADMINCOMMAND(0x624EAB5F, ClientAdminCommandMsg.class, null), //Admin Command + CLIENTADMINCOMMAND(0x624EAB5F, ClientAdminCommandMsg.class, ClientAdminCommandMsgHandler.class), //Admin Command CLIENTUPDATEVAULT(0x66EDBECD, UpdateVaultMsg.class, null), COMBATMODE(0xFE4BF353, ToggleCombatMsg.class, null), //Toggle Combat mode CONFIRMPROMOTE(0x153BB5F9, ConfirmPromoteMsg.class, null), diff --git a/src/engine/net/client/handlers/ClientAdminCommandMsgHandler.java b/src/engine/net/client/handlers/ClientAdminCommandMsgHandler.java new file mode 100644 index 00000000..1e3500cf --- /dev/null +++ b/src/engine/net/client/handlers/ClientAdminCommandMsgHandler.java @@ -0,0 +1,126 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + +package engine.net.client.handlers; + +import engine.Enum; +import engine.exception.MsgSendException; +import engine.gameManager.DevCmdManager; +import engine.gameManager.SessionManager; +import engine.net.client.ClientConnection; +import engine.net.client.msg.ClientNetMsg; +import engine.net.client.msg.commands.ClientAdminCommandMsg; +import engine.objects.AbstractGameObject; +import engine.objects.AbstractWorldObject; +import engine.objects.Account; +import engine.objects.PlayerCharacter; +import engine.server.MBServerStatics; +import org.pmw.tinylog.Logger; + +public class ClientAdminCommandMsgHandler extends AbstractClientMsgHandler { + + public ClientAdminCommandMsgHandler() { + super(ClientAdminCommandMsg.class); + } + + public static boolean processDevCommand(AbstractWorldObject sender, String text) { + + if (sender.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) { + + PlayerCharacter pcSender = (PlayerCharacter) sender; + + // first remove the DEV_CMD_PREFIX + String[] words = text.split(MBServerStatics.DEV_CMD_PREFIX, 2); + + if (words[1].length() == 0) + return false; + + // next get the command + String[] commands = words[1].split(" ", 2); + String cmd = commands[0].toLowerCase(); + String cmdArgument = ""; + + if (commands.length > 1) + cmdArgument = commands[1].trim(); + + AbstractGameObject target = pcSender.getLastTarget(); + // return DevCmd.processDevCommand(pcSender, cmd, cmdArgument, + // target); + return DevCmdManager.handleDevCmd(pcSender, cmd, + cmdArgument, target); + } + return false; + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter player = origin.getPlayerCharacter(); + + // Member variable declaration + + ClientAdminCommandMsg msg; + + // Member variable assignment + + msg = (ClientAdminCommandMsg) baseMsg; + + if (player == null) + return true; + + Account acct = SessionManager.getAccount(player); + + if (acct == null) + return true; + + // require minimal access to continue + // specific accessLevel checks performed by the DevCmdManager + if (acct.status.equals(Enum.AccountStatus.ADMIN) == false) { + Logger.warn(player.getFirstName() + " Attempted to use a client admin command"); + //wtf? ChatManager.chatSystemInfo(pcSender, "CHEATER!!!!!!!!!!!!!"); + return true; + } + + // First remove the initial slash + String d = msg.getMsgCommand(); + String[] words = d.split("/", 2); + + if (words[1].length() == 0) + return true; + + // Next get the command + String[] commands = words[1].split(" ", 2); + String cmd = commands[0].toLowerCase(); + String cmdArgument = ""; + + if (commands.length > 1) + cmdArgument = commands[1].trim(); + + AbstractGameObject target = msg.getTarget(); + + // Map to a DevCmd + String devCmd = ""; + + if (cmd.compareTo("goto") == 0) + devCmd = "goto"; + else if (cmd.compareTo("suspend") == 0) + devCmd = "suspend"; + else if (cmd.compareTo("getinfo") == 0) + devCmd = "info"; + else if (devCmd.isEmpty()) { + Logger.info("Unhandled admin command was used: /" + + cmd); + return true; + } + + DevCmdManager.handleDevCmd(player, devCmd, cmdArgument, + target); + return true; + } + +} \ No newline at end of file