From d7b18dc457e871d75b67d42898cbfc40265eb345 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 08:14:27 -0400 Subject: [PATCH] Handler created for RequestToTrade --- src/engine/gameManager/TradeManager.java | 11 ---- src/engine/net/client/ClientMessagePump.java | 3 - src/engine/net/client/Protocol.java | 2 +- .../handlers/TradeRequestMsgHandler.java | 59 +++++++++++++++++++ src/engine/objects/CharacterItemManager.java | 2 +- 5 files changed, 61 insertions(+), 16 deletions(-) create mode 100644 src/engine/net/client/handlers/TradeRequestMsgHandler.java diff --git a/src/engine/gameManager/TradeManager.java b/src/engine/gameManager/TradeManager.java index 2b6b50e3..c90204c7 100644 --- a/src/engine/gameManager/TradeManager.java +++ b/src/engine/gameManager/TradeManager.java @@ -21,17 +21,6 @@ public enum TradeManager { TRADEMANAGER; - public static void tradeRequest(TradeRequestMsg msg, ClientConnection origin) { - - PlayerCharacter source = origin.getPlayerCharacter(); - - if (source == null) - return; - - source.charItemManager.tradeRequest(msg); - - } - public static void acceptTradeRequest(AcceptTradeRequestMsg msg, ClientConnection origin) { diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 0a094478..27037d10 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -73,9 +73,6 @@ public class ClientMessagePump implements NetMsgHandler { break; case OPENVAULT: break; - case REQUESTTOTRADE: - TradeManager.tradeRequest((TradeRequestMsg) msg, origin); - break; case REQUESTTRADEOK: TradeManager.acceptTradeRequest((AcceptTradeRequestMsg) msg, origin); break; diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index 9dd34cc6..f2343d4e 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -177,7 +177,7 @@ public enum Protocol { REQUESTMELEEATTACK(0x98C71545, AttackCmdMsg.class, AttackCmdMsgHandler.class), // Attack REQUESTMEMBERLIST(0x3235E5EA, GuildControlMsg.class, GuildControlHandler.class), // Part of Promote/Demote, Also Player History REQUESTTOOPENBANK(0xF26E453F, null, null), // RequestToOpenBankMsg - REQUESTTOTRADE(0x4D84259B, TradeRequestMsg.class, null), // Trade Request + REQUESTTOTRADE(0x4D84259B, TradeRequestMsg.class, TradeRequestMsgHandler.class), // Trade Request REQUESTTRADECANCEL(0xCB0C5735, RejectTradeRequestMsg.class, null), // Reject RequestToTrade REQUESTTRADEOK(0xFFD29841, AcceptTradeRequestMsg.class, null), // Accept Trade Request RESETAFTERDEATH(0xFDCBB98F, RespawnMsg.class, RespawnMsgHandler.class), //Respawn Request/Response diff --git a/src/engine/net/client/handlers/TradeRequestMsgHandler.java b/src/engine/net/client/handlers/TradeRequestMsgHandler.java new file mode 100644 index 00000000..37b4c22b --- /dev/null +++ b/src/engine/net/client/handlers/TradeRequestMsgHandler.java @@ -0,0 +1,59 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + +package engine.net.client.handlers; + +import engine.Enum; +import engine.exception.MsgSendException; +import engine.gameManager.ChatManager; +import engine.net.Dispatch; +import engine.net.DispatchMessage; +import engine.net.client.ClientConnection; +import engine.net.client.msg.ClientNetMsg; +import engine.net.client.msg.TradeRequestMsg; +import engine.objects.CharacterItemManager; +import engine.objects.PlayerCharacter; + +public class TradeRequestMsgHandler extends AbstractClientMsgHandler { + + public TradeRequestMsgHandler() { + super(TradeRequestMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + TradeRequestMsg msg = (TradeRequestMsg) baseMsg; + + PlayerCharacter source = origin.getPlayerCharacter(); + PlayerCharacter target = PlayerCharacter.getFromCache(msg.getPlayerID()); + Dispatch dispatch; + + if (!CharacterItemManager.canTrade(source, target)) { + ChatManager.chatSystemError(source, "Can't currently trade with target player"); + return false; + } + + // TODO uncomment this block after we determine when we + // setBankOpen(false) and setVaultOpen(false) + CharacterItemManager cim1 = source.charItemManager; + CharacterItemManager cim2 = target.charItemManager; + + if (cim1 == null) + return false; + + if (cim2 == null) + return false; + + dispatch = Dispatch.borrow(target, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + return true; + + } + +} \ No newline at end of file diff --git a/src/engine/objects/CharacterItemManager.java b/src/engine/objects/CharacterItemManager.java index bf452bbc..af4b5baa 100644 --- a/src/engine/objects/CharacterItemManager.java +++ b/src/engine/objects/CharacterItemManager.java @@ -411,7 +411,7 @@ public class CharacterItemManager { } - public synchronized boolean canTrade(PlayerCharacter playerA, PlayerCharacter playerB) { + public static synchronized boolean canTrade(PlayerCharacter playerA, PlayerCharacter playerB) { if (playerA == null || playerB == null) return false;