From 8083f39ba14bdbb022a4435da6852a662980d75d Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 04:46:45 -0400 Subject: [PATCH] Handler created for DeleteItemMsg --- src/engine/net/client/ClientMessagePump.java | 36 ---------- src/engine/net/client/Protocol.java | 2 +- .../client/handlers/DeleteItemMsgHandler.java | 69 +++++++++++++++++++ 3 files changed, 70 insertions(+), 37 deletions(-) create mode 100644 src/engine/net/client/handlers/DeleteItemMsgHandler.java diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 267e11bf..3bbfee14 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -92,39 +92,6 @@ public class ClientMessagePump implements NetMsgHandler { DispatchMessage.dispatchMsgToInterestArea(pc, rwss, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); } - private static void DeleteItem(DeleteItemMsg msg, ClientConnection origin) { - - CharacterItemManager itemManager = origin.getPlayerCharacter().charItemManager; - int uuid = msg.getUUID(); - - - PlayerCharacter sourcePlayer = origin.getPlayerCharacter(); - - if (sourcePlayer == null) - return; - - if (!sourcePlayer.isAlive()) - return; - - Item i = Item.getFromCache(msg.getUUID()); - - if (i == null) - return; - - if (!itemManager.doesCharOwnThisItem(i.getObjectUUID())) - return; - - if (!itemManager.inventoryContains(i)) - return; - - if (i.isCanDestroy()) - if (itemManager.delete(i) == true) { - Dispatch dispatch = Dispatch.borrow(sourcePlayer, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - } - - } - private static void ackBankWindowOpened(AckBankWindowOpenedMsg msg, ClientConnection origin) { // According to the Wiki, the client should not send this message. // Log the instance to investigate, and modify Wiki accordingly. @@ -761,9 +728,6 @@ public class ClientMessagePump implements NetMsgHandler { case IGNORE: ((IgnoreMsg) msg).handleRequest(origin); break; - case DELETEOBJECT: - DeleteItem((DeleteItemMsg) msg, origin); - break; case VIEWRESOURCES: ViewResourcesMessage((ViewResourcesMessage) msg, origin); break; diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index b25245c2..a0a0db6c 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -85,7 +85,7 @@ public enum Protocol { CREATECHAR(0x5D18B5C8, CommitNewCharacterMsg.class, null), // Commit New Character, CREATEPETITION(0xD489CFED, GuildCreationFinalizeMsg.class, GuildCreationFinalizeHandler.class), //Confirm guild creation CUSTOMERPETITION(0x7F9D7D6D, PetitionReceivedMsg.class, PetitionReceivedMsgHandler.class), - DELETEOBJECT(0x57F069D8, DeleteItemMsg.class, null), //Delete Item from Inventory + DELETEOBJECT(0x57F069D8, DeleteItemMsg.class, DeleteItemMsgHandler.class), //Delete Item from Inventory DESTROYBUILDING(0x3CB6FAD3, DestroyBuildingMsg.class, DestroyBuildingHandler.class), // Destroy Building DISBANDGUILD(0x77AABD64, DisbandGuildMsg.class, DisbandGuildHandler.class), //Disband Guild DISMISSGUILD(0x8D2D3D61, DismissGuildMsg.class, DismissGuildHandler.class), diff --git a/src/engine/net/client/handlers/DeleteItemMsgHandler.java b/src/engine/net/client/handlers/DeleteItemMsgHandler.java new file mode 100644 index 00000000..2dfcc210 --- /dev/null +++ b/src/engine/net/client/handlers/DeleteItemMsgHandler.java @@ -0,0 +1,69 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + +package engine.net.client.handlers; + +import engine.Enum.DispatchChannel; +import engine.exception.MsgSendException; +import engine.net.Dispatch; +import engine.net.DispatchMessage; +import engine.net.client.ClientConnection; +import engine.net.client.msg.ClientNetMsg; +import engine.net.client.msg.DeleteItemMsg; +import engine.objects.CharacterItemManager; +import engine.objects.Item; +import engine.objects.PlayerCharacter; + +public class DeleteItemMsgHandler extends AbstractClientMsgHandler { + + public DeleteItemMsgHandler() { + super(DeleteItemMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter player = origin.getPlayerCharacter(); + + // Member variable declaration + + DeleteItemMsg msg; + + // Member variable assignment + + msg = (DeleteItemMsg) baseMsg; + CharacterItemManager itemManager = origin.getPlayerCharacter().charItemManager; + int uuid = msg.getUUID(); + + if (player == null) + return true; + + if (!player.isAlive()) + return true; + + Item item = Item.getFromCache(msg.getUUID()); + + if (item == null) + return true; + + if (!itemManager.doesCharOwnThisItem(item.getObjectUUID())) + return true; + + if (!itemManager.inventoryContains(item)) + return true; + + if (item.isCanDestroy()) + if (itemManager.delete(item) == true) { + Dispatch dispatch = Dispatch.borrow(player, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + } + + return true; + } + +} \ No newline at end of file