From 8cd613c5975381e1c2f50567e0190e1d0837256d Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 08:55:22 -0400 Subject: [PATCH] Handler created for CloseTradeWindow --- src/engine/gameManager/TradeManager.java | 24 ------- src/engine/net/client/ClientMessagePump.java | 4 -- src/engine/net/client/Protocol.java | 2 +- .../handlers/CloseTradeWindowMsgHandler.java | 69 +++++++++++++++++++ 4 files changed, 70 insertions(+), 29 deletions(-) create mode 100644 src/engine/net/client/handlers/CloseTradeWindowMsgHandler.java diff --git a/src/engine/gameManager/TradeManager.java b/src/engine/gameManager/TradeManager.java index 80e529c4..dbb13513 100644 --- a/src/engine/gameManager/TradeManager.java +++ b/src/engine/gameManager/TradeManager.java @@ -11,37 +11,13 @@ package engine.gameManager; import engine.Enum; import engine.net.Dispatch; import engine.net.DispatchMessage; -import engine.net.client.ClientConnection; -import engine.net.client.msg.CloseTradeWindowMsg; import engine.net.client.msg.InvalidTradeRequestMsg; -import engine.objects.CharacterItemManager; import engine.objects.PlayerCharacter; -import org.pmw.tinylog.Logger; public enum TradeManager { TRADEMANAGER; - public static void closeTradeWindow(CloseTradeWindowMsg msg, ClientConnection origin) { - - PlayerCharacter source = origin.getPlayerCharacter(); - - if (source == null) - return; - - CharacterItemManager sourceItemMan = source.charItemManager; - - if (sourceItemMan == null) - return; - - try { - sourceItemMan.closeTradeWindow(msg, true); - } catch (Exception e) { - // TODO Auto-generated catch block - Logger.error(e); - } - } - public static void invalidTradeRequest(InvalidTradeRequestMsg msg) { PlayerCharacter requester = PlayerCharacter.getFromCache(msg.getRequesterID()); Dispatch dispatch; diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 2520e0b9..445413da 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -14,7 +14,6 @@ import engine.gameManager.TradeManager; import engine.net.NetMsgHandler; import engine.net.client.handlers.AbstractClientMsgHandler; import engine.net.client.msg.ClientNetMsg; -import engine.net.client.msg.CloseTradeWindowMsg; import engine.net.client.msg.InvalidTradeRequestMsg; import engine.server.world.WorldServer; import engine.session.Session; @@ -75,9 +74,6 @@ public class ClientMessagePump implements NetMsgHandler { break; case OPENVAULT: break; - case TRADECLOSE: - TradeManager.closeTradeWindow((CloseTradeWindowMsg) msg, origin); - break; case ARCREQUESTTRADEBUSY: TradeManager.invalidTradeRequest((InvalidTradeRequestMsg) msg); break; diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index ce8982ca..7ba3b560 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -213,7 +213,7 @@ public enum Protocol { TOGGLESITSTAND(0x624F3C0F, ToggleSitStandMsg.class, ToggleSitStandMsgHandler.class), //Toggle Sit/Stand TRADEADDGOLD(0x654ACB45, AddGoldToTradeWindowMsg.class, AddGoldToTradeWindowMsgHandler.class), // Add Gold to Trade Window TRADEADDOBJECT(0x55D363E9, AddItemToTradeWindowMsg.class, AddItemToTradeWindowMsgHandler.class), // Add an Item to the Trade Window - TRADECLOSE(0x5008D7FC, CloseTradeWindowMsg.class, null), // Cancel trade/ACK trade complete + TRADECLOSE(0x5008D7FC, CloseTradeWindowMsg.class, CloseTradeWindowMsgHandler.class), // Cancel trade/ACK trade complete TRADECONFIRM(0x6911E65E, CommitToTradeMsg.class, CommitToTradeMsgHandler.class), // Commit to trade TRADECONFIRMSTATUS(0x9F85DAFC, null, null), // Other player commit/uncommit/add item TRADEUNCONFIRM(0xEBE280E0, UncommitToTradeMsg.class, UncommitToTradeMsgHandler.class), // Uncommit to trade diff --git a/src/engine/net/client/handlers/CloseTradeWindowMsgHandler.java b/src/engine/net/client/handlers/CloseTradeWindowMsgHandler.java new file mode 100644 index 00000000..7f3f34d2 --- /dev/null +++ b/src/engine/net/client/handlers/CloseTradeWindowMsgHandler.java @@ -0,0 +1,69 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + +package engine.net.client.handlers; + +import engine.Enum; +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.CloseTradeWindowMsg; +import engine.objects.CharacterItemManager; +import engine.objects.PlayerCharacter; + +public class CloseTradeWindowMsgHandler extends AbstractClientMsgHandler { + + public CloseTradeWindowMsgHandler() { + super(CloseTradeWindowMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter source = origin.getPlayerCharacter(); + + // Member variable declaration + + CloseTradeWindowMsg msg; + + // Member variable assignment + + msg = (CloseTradeWindowMsg) baseMsg; + + Dispatch dispatch; + + if (source == null) + return false; + + CharacterItemManager sourceItemMan = source.charItemManager; + + if (sourceItemMan == null) + return false; + + int tradeID = source.charItemManager.tradeID; + CloseTradeWindowMsg closeMsg = new CloseTradeWindowMsg(source, tradeID); + + dispatch = Dispatch.borrow(source, closeMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + + ClientConnection cc2 = sourceItemMan.getTradingWith(); + + if (cc2 == null || cc2.getPlayerCharacter() == null) { + sourceItemMan.endTrade(); + return true; + } + + sourceItemMan.endTrade(); + cc2.getPlayerCharacter().charItemManager.closeTradeWindow(msg, false); + + return true; + } + +} \ No newline at end of file