Browse Source

Handler created for RequestToTrade

combat-2
MagicBot 8 months ago
parent
commit
d7b18dc457
  1. 11
      src/engine/gameManager/TradeManager.java
  2. 3
      src/engine/net/client/ClientMessagePump.java
  3. 2
      src/engine/net/client/Protocol.java
  4. 59
      src/engine/net/client/handlers/TradeRequestMsgHandler.java
  5. 2
      src/engine/objects/CharacterItemManager.java

11
src/engine/gameManager/TradeManager.java

@ -21,17 +21,6 @@ public enum TradeManager {
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) { public static void acceptTradeRequest(AcceptTradeRequestMsg msg, ClientConnection origin) {

3
src/engine/net/client/ClientMessagePump.java

@ -73,9 +73,6 @@ public class ClientMessagePump implements NetMsgHandler {
break; break;
case OPENVAULT: case OPENVAULT:
break; break;
case REQUESTTOTRADE:
TradeManager.tradeRequest((TradeRequestMsg) msg, origin);
break;
case REQUESTTRADEOK: case REQUESTTRADEOK:
TradeManager.acceptTradeRequest((AcceptTradeRequestMsg) msg, origin); TradeManager.acceptTradeRequest((AcceptTradeRequestMsg) msg, origin);
break; break;

2
src/engine/net/client/Protocol.java

@ -177,7 +177,7 @@ public enum Protocol {
REQUESTMELEEATTACK(0x98C71545, AttackCmdMsg.class, AttackCmdMsgHandler.class), // Attack REQUESTMELEEATTACK(0x98C71545, AttackCmdMsg.class, AttackCmdMsgHandler.class), // Attack
REQUESTMEMBERLIST(0x3235E5EA, GuildControlMsg.class, GuildControlHandler.class), // Part of Promote/Demote, Also Player History REQUESTMEMBERLIST(0x3235E5EA, GuildControlMsg.class, GuildControlHandler.class), // Part of Promote/Demote, Also Player History
REQUESTTOOPENBANK(0xF26E453F, null, null), // RequestToOpenBankMsg 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 REQUESTTRADECANCEL(0xCB0C5735, RejectTradeRequestMsg.class, null), // Reject RequestToTrade
REQUESTTRADEOK(0xFFD29841, AcceptTradeRequestMsg.class, null), // Accept Trade Request REQUESTTRADEOK(0xFFD29841, AcceptTradeRequestMsg.class, null), // Accept Trade Request
RESETAFTERDEATH(0xFDCBB98F, RespawnMsg.class, RespawnMsgHandler.class), //Respawn Request/Response RESETAFTERDEATH(0xFDCBB98F, RespawnMsg.class, RespawnMsgHandler.class), //Respawn Request/Response

59
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;
}
}

2
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) if (playerA == null || playerB == null)
return false; return false;

Loading…
Cancel
Save