diff --git a/src/engine/gameManager/TradeManager.java b/src/engine/gameManager/TradeManager.java index c8846855..80e529c4 100644 --- a/src/engine/gameManager/TradeManager.java +++ b/src/engine/gameManager/TradeManager.java @@ -14,7 +14,6 @@ import engine.net.DispatchMessage; import engine.net.client.ClientConnection; import engine.net.client.msg.CloseTradeWindowMsg; import engine.net.client.msg.InvalidTradeRequestMsg; -import engine.net.client.msg.UncommitToTradeMsg; import engine.objects.CharacterItemManager; import engine.objects.PlayerCharacter; import org.pmw.tinylog.Logger; @@ -23,27 +22,6 @@ public enum TradeManager { TRADEMANAGER; - public static void uncommitToTrade(UncommitToTradeMsg msg, ClientConnection origin) { - - PlayerCharacter source = origin.getPlayerCharacter(); - - if (source == null || !source.isAlive()) - return; - - CharacterItemManager sourceItemMan = source.charItemManager; - - if (sourceItemMan == null) - return; - - try { - sourceItemMan.uncommitToTrade(msg); - } catch (Exception e) { - // TODO Auto-generated catch block - Logger.error(e); - } - - } - public static void closeTradeWindow(CloseTradeWindowMsg msg, ClientConnection origin) { PlayerCharacter source = origin.getPlayerCharacter(); diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 194b2c96..2520e0b9 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -16,7 +16,6 @@ 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.net.client.msg.UncommitToTradeMsg; import engine.server.world.WorldServer; import engine.session.Session; import engine.util.StringUtils; @@ -76,9 +75,6 @@ public class ClientMessagePump implements NetMsgHandler { break; case OPENVAULT: break; - case TRADEUNCONFIRM: - TradeManager.uncommitToTrade((UncommitToTradeMsg) msg, origin); - break; case TRADECLOSE: TradeManager.closeTradeWindow((CloseTradeWindowMsg) msg, origin); break; diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index 38b7f3e5..ce8982ca 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -216,7 +216,7 @@ public enum Protocol { TRADECLOSE(0x5008D7FC, CloseTradeWindowMsg.class, null), // 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, null), // Uncommit to trade + TRADEUNCONFIRM(0xEBE280E0, UncommitToTradeMsg.class, UncommitToTradeMsgHandler.class), // Uncommit to trade TRAINERLIST(0x41FABA62, TrainerInfoMsg.class, TrainerInfoMsgHandler.class), //Req/Send Trainer Info/Pricing TRAINSKILL(0xB0BF68CD, TrainMsg.class, TrainMsgHandler.class), //Train skills/powers TRANSFERASSET(0x3EA1C4C9, TransferAssetMsg.class, TransferAssetMsgHandler.class), // Transfer Building diff --git a/src/engine/net/client/handlers/UncommitToTradeMsgHandler.java b/src/engine/net/client/handlers/UncommitToTradeMsgHandler.java new file mode 100644 index 00000000..f9de8846 --- /dev/null +++ b/src/engine/net/client/handlers/UncommitToTradeMsgHandler.java @@ -0,0 +1,67 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + +package engine.net.client.handlers; + +import engine.exception.MsgSendException; +import engine.net.client.ClientConnection; +import engine.net.client.msg.ClientNetMsg; +import engine.net.client.msg.UncommitToTradeMsg; +import engine.objects.CharacterItemManager; +import engine.objects.PlayerCharacter; + +import static engine.objects.CharacterItemManager.canTrade; + +public class UncommitToTradeMsgHandler extends AbstractClientMsgHandler { + + public UncommitToTradeMsgHandler() { + super(UncommitToTradeMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter source = origin.getPlayerCharacter(); + + // Member variable declaration + + UncommitToTradeMsg msg; + + // Member variable assignment + + msg = (UncommitToTradeMsg) baseMsg; + + if (source == null || !source.isAlive()) + return true; + + CharacterItemManager sourceItemMan = source.charItemManager; + + if (sourceItemMan == null) + return true; + + sourceItemMan.setTradeCommitted((byte) 0); + + ClientConnection ccOther = sourceItemMan.getTradingWith(); + + if (ccOther == null) + return true; + + PlayerCharacter other = ccOther.getPlayerCharacter(); + + if (other == null) + return true; + + if (!canTrade(source, other)) + return true; + + source.charItemManager.modifyCommitToTrade(); + + return true; + } + +} \ No newline at end of file diff --git a/src/engine/objects/CharacterItemManager.java b/src/engine/objects/CharacterItemManager.java index ca2fdda8..d7053830 100644 --- a/src/engine/objects/CharacterItemManager.java +++ b/src/engine/objects/CharacterItemManager.java @@ -444,36 +444,6 @@ public class CharacterItemManager { return true; } - public synchronized boolean uncommitToTrade(UncommitToTradeMsg msg) { - - PlayerCharacter source = (PlayerCharacter) this.getOwner(); - - if (source == null || !source.isAlive()) - return false; - - CharacterItemManager sourceItemMan = source.charItemManager; - - if (sourceItemMan == null) - return false; - - sourceItemMan.setTradeCommitted((byte) 0); - - ClientConnection ccOther = sourceItemMan.getTradingWith(); - - if (ccOther == null) - return false; - - PlayerCharacter other = ccOther.getPlayerCharacter(); - - if (other == null) - return false; - - if (!canTrade(source, other)) - return false; - - return modifyCommitToTrade(); - } - public synchronized boolean modifyCommitToTrade() { CharacterItemManager man1 = this;