From 8083f39ba14bdbb022a4435da6852a662980d75d Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 04:46:45 -0400 Subject: [PATCH 01/45] 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 From 06e41d5b945ead3607847d95eb97f6f06bdfe69d Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 04:52:07 -0400 Subject: [PATCH 02/45] Handler created for LootWindowRequestMsg --- src/engine/net/client/ClientMessagePump.java | 101 ------------- src/engine/net/client/Protocol.java | 2 +- .../handlers/LootWindowRequestMsgHandler.java | 141 ++++++++++++++++++ 3 files changed, 142 insertions(+), 102 deletions(-) create mode 100644 src/engine/net/client/handlers/LootWindowRequestMsgHandler.java diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 3bbfee14..cfdb9013 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -178,104 +178,6 @@ public class ClientMessagePump implements NetMsgHandler { JobScheduler.getInstance().scheduleJob(new RefreshGroupJob(sourcePlayer), MBServerStatics.LOAD_OBJECT_DELAY); } - private static void lootWindowRequest(LootWindowRequestMsg msg, ClientConnection origin) throws MsgSendException { - - PlayerCharacter pc = SessionManager.getPlayerCharacter(origin); - - if (pc == null) - return; - - if (!pc.isAlive()) - return; - - if (msg.getSourceType() != pc.getObjectType().ordinal() || msg.getSourceID() != pc.getObjectUUID()) { - Logger.error("Player " + pc.getObjectUUID() + " looting from character of id " - + msg.getSourceType() + ' ' + msg.getSourceID()); - return; - } - - if (pc.getAltitude() > 0) - return; - if (!pc.isAlive()) { - return; - } - - - LootWindowResponseMsg lwrm = null; - GameObjectType targetType = GameObjectType.values()[msg.getTargetType()]; - AbstractCharacter characterTarget = null; - Corpse corpseTarget = null; - - switch (targetType) { - case PlayerCharacter: - - characterTarget = PlayerCharacter.getFromCache(msg.getTargetID()); - if (characterTarget == null) - return; - if (characterTarget.isAlive()) - return; - if (pc.getLoc().distanceSquared2D(characterTarget.getLoc()) > sqr(MBServerStatics.LOOT_RANGE)) { - ErrorPopupMsg.sendErrorMsg(pc, "You are too far away to loot this corpse."); - - Logger.info(pc.getFirstName() + " tried looting at " + pc.getLoc().distance2D(characterTarget.getLoc()) + " distance."); - return; - } - lwrm = new LootWindowResponseMsg(characterTarget.getObjectType().ordinal(), characterTarget.getObjectUUID(), characterTarget.getInventory(true)); - break; - case NPC: - characterTarget = NPC.getFromCache(msg.getTargetID()); - if (characterTarget == null) - return; - break; - case Mob: - characterTarget = Mob.getFromCache(msg.getTargetID()); - if ((characterTarget == null) || characterTarget.isAlive()) { - return; - } - - if (pc.getLoc().distanceSquared2D(characterTarget.getLoc()) > sqr(MBServerStatics.LOOT_RANGE)) { - ErrorPopupMsg.sendErrorMsg(pc, "You are too far away to loot this corpse."); - - Logger.info(pc.getFirstName() + " tried looting at " + pc.getLoc().distance2D(characterTarget.getLoc()) + " distance."); - - if (!((Mob) characterTarget).isLootSync()) { - - ((Mob) characterTarget).setLootSync(true); - WorldGrid.updateObject(characterTarget, pc); - } - - - return; - } - - lwrm = new LootWindowResponseMsg(characterTarget.getObjectType().ordinal(), characterTarget.getObjectUUID(), characterTarget.getInventory()); - break; - case Corpse: - corpseTarget = Corpse.getCorpse(msg.getTargetID()); - - if ((corpseTarget == null)) { - return; - } - - if (pc.getLoc().distanceSquared(corpseTarget.getLoc()) > sqr(MBServerStatics.LOOT_RANGE)) { - ErrorPopupMsg.sendErrorMsg(pc, "You are too far away to loot this corpse."); - - Logger.info(pc.getFirstName() + " tried looting at " + pc.getLoc().distance2D(characterTarget.getLoc()) + " distance."); - return; - } - lwrm = new LootWindowResponseMsg(corpseTarget.getObjectType().ordinal(), msg.getTargetID(), corpseTarget.getInventory()); - break; - } - - if (lwrm == null) - return; - - DispatchMessage.dispatchMsgToInterestArea(pc, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); - Dispatch dispatch = Dispatch.borrow(pc, lwrm); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); - - } - private static void loot(LootMsg msg, ClientConnection origin) throws MsgSendException { PlayerCharacter player = SessionManager.getPlayerCharacter(origin); @@ -740,9 +642,6 @@ public class ClientMessagePump implements NetMsgHandler { case RESETAFTERDEATH: respawn((RespawnMsg) msg, origin); break; - case REQUESTCONTENTS: - lootWindowRequest((LootWindowRequestMsg) msg, origin); - break; case MOVEOBJECTTOCONTAINER: loot((LootMsg) msg, origin); break; diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index a0a0db6c..609cb3fe 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -172,7 +172,7 @@ public enum Protocol { REMOVEFRIEND(0xE0D5DB42, RemoveFriendMessage.class, RemoveFriendHandler.class), REPAIRBUILDING(0xAF8C2560, RepairBuildingMsg.class, RepairBuildingMsgHandler.class), REPAIROBJECT(0x782219CE, RepairMsg.class, RepairMsgHandler.class), //Repair Window Req/Ack, RepairObject item Req/Ack - REQUESTCONTENTS(0xA786B0A2, LootWindowRequestMsg.class, null), // MoveObjectToContainer Window Request + REQUESTCONTENTS(0xA786B0A2, LootWindowRequestMsg.class, LootWindowRequestMsgHandler.class), // MoveObjectToContainer Window Request REQUESTGUILDLIST(0x85DCC6D7, ReqGuildListMsg.class, RequestGuildListHandler.class), REQUESTMELEEATTACK(0x98C71545, AttackCmdMsg.class, AttackCmdMsgHandler.class), // Attack REQUESTMEMBERLIST(0x3235E5EA, GuildControlMsg.class, GuildControlHandler.class), // Part of Promote/Demote, Also Player History diff --git a/src/engine/net/client/handlers/LootWindowRequestMsgHandler.java b/src/engine/net/client/handlers/LootWindowRequestMsgHandler.java new file mode 100644 index 00000000..fa23c31f --- /dev/null +++ b/src/engine/net/client/handlers/LootWindowRequestMsgHandler.java @@ -0,0 +1,141 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + +package engine.net.client.handlers; + +import engine.Enum; +import engine.Enum.DispatchChannel; +import engine.InterestManagement.WorldGrid; +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.ErrorPopupMsg; +import engine.net.client.msg.LootWindowRequestMsg; +import engine.net.client.msg.LootWindowResponseMsg; +import engine.objects.*; +import engine.server.MBServerStatics; +import org.pmw.tinylog.Logger; + +import static engine.math.FastMath.sqr; + +public class LootWindowRequestMsgHandler extends AbstractClientMsgHandler { + + public LootWindowRequestMsgHandler() { + super(LootWindowRequestMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter player = origin.getPlayerCharacter(); + + // Member variable declaration + + LootWindowRequestMsg msg; + + // Member variable assignment + + msg = (LootWindowRequestMsg) baseMsg; + + if (player == null) + return true; + + if (!player.isAlive()) + return true; + + if (msg.getSourceType() != player.getObjectType().ordinal() || msg.getSourceID() != player.getObjectUUID()) { + Logger.error("Player " + player.getObjectUUID() + " looting from character of id " + + msg.getSourceType() + ' ' + msg.getSourceID()); + return true; + } + + if (player.getAltitude() > 0) + return true; + + if (!player.isAlive()) + return true; + + LootWindowResponseMsg lwrm = null; + Enum.GameObjectType targetType = Enum.GameObjectType.values()[msg.getTargetType()]; + AbstractCharacter characterTarget = null; + Corpse corpseTarget; + + switch (targetType) { + case PlayerCharacter: + + characterTarget = PlayerCharacter.getFromCache(msg.getTargetID()); + + if (characterTarget == null) + return true; + + if (characterTarget.isAlive()) + return true; + + if (player.getLoc().distanceSquared2D(characterTarget.getLoc()) > sqr(MBServerStatics.LOOT_RANGE)) { + ErrorPopupMsg.sendErrorMsg(player, "You are too far away to loot this corpse."); + Logger.info(player.getFirstName() + " tried looting at " + player.getLoc().distance2D(characterTarget.getLoc()) + " distance."); + return true; + } + + lwrm = new LootWindowResponseMsg(characterTarget.getObjectType().ordinal(), characterTarget.getObjectUUID(), characterTarget.getInventory(true)); + break; + case NPC: + characterTarget = NPC.getFromCache(msg.getTargetID()); + + if (characterTarget == null) + return true; + break; + case Mob: + characterTarget = Mob.getFromCache(msg.getTargetID()); + + if ((characterTarget == null) || characterTarget.isAlive()) + return true; + + if (player.getLoc().distanceSquared2D(characterTarget.getLoc()) > sqr(MBServerStatics.LOOT_RANGE)) { + ErrorPopupMsg.sendErrorMsg(player, "You are too far away to loot this corpse."); + + Logger.info(player.getFirstName() + " tried looting at " + player.getLoc().distance2D(characterTarget.getLoc()) + " distance."); + + if (!((Mob) characterTarget).isLootSync()) { + ((Mob) characterTarget).setLootSync(true); + WorldGrid.updateObject(characterTarget, player); + } + + return true; + } + + lwrm = new LootWindowResponseMsg(characterTarget.getObjectType().ordinal(), characterTarget.getObjectUUID(), characterTarget.getInventory()); + break; + case Corpse: + corpseTarget = Corpse.getCorpse(msg.getTargetID()); + + if ((corpseTarget == null)) + return true; + + if (player.getLoc().distanceSquared(corpseTarget.getLoc()) > sqr(MBServerStatics.LOOT_RANGE)) { + ErrorPopupMsg.sendErrorMsg(player, "You are too far away to loot this corpse."); + Logger.info(player.getFirstName() + " tried looting at " + player.getLoc().distance2D(characterTarget.getLoc()) + " distance."); + return true; + } + lwrm = new LootWindowResponseMsg(corpseTarget.getObjectType().ordinal(), msg.getTargetID(), corpseTarget.getInventory()); + break; + } + + if (lwrm == null) + return true; + + DispatchMessage.dispatchMsgToInterestArea(player, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); + Dispatch dispatch = Dispatch.borrow(player, lwrm); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); + + return true; + } + +} \ No newline at end of file From 4bc19235a6fc8884d342a1d1898c9bfd2b8e7b18 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 04:59:27 -0400 Subject: [PATCH 03/45] Handler created for LootMsg --- src/engine/net/client/ClientMessagePump.java | 234 ---------------- src/engine/net/client/Protocol.java | 2 +- .../net/client/handlers/LootMsgHandler.java | 260 ++++++++++++++++++ 3 files changed, 261 insertions(+), 235 deletions(-) create mode 100644 src/engine/net/client/handlers/LootMsgHandler.java diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index cfdb9013..84a799df 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -32,8 +32,6 @@ import org.pmw.tinylog.Logger; import java.sql.SQLException; -import static engine.math.FastMath.sqr; - /** * @author: * @summary: This class is the mainline router for application protocol @@ -178,235 +176,6 @@ public class ClientMessagePump implements NetMsgHandler { JobScheduler.getInstance().scheduleJob(new RefreshGroupJob(sourcePlayer), MBServerStatics.LOAD_OBJECT_DELAY); } - private static void loot(LootMsg msg, ClientConnection origin) throws MsgSendException { - - PlayerCharacter player = SessionManager.getPlayerCharacter(origin); - if (player == null) - return; - - if (!player.isAlive()) - return; - - Item item = msg.getItem(); - - if (item == null) - return; - - if (item.lootLock.tryLock()) { - try { - Item itemRet = null; - // get current owner - int targetType = msg.getTargetType(); - int targetID = msg.getTargetID(); - - if (targetType == GameObjectType.PlayerCharacter.ordinal() || targetType == GameObjectType.Mob.ordinal() || targetType == GameObjectType.Corpse.ordinal()) { - } else { //needed for getting contracts for some reason - targetType = msg.getSourceID2(); - targetID = msg.getUnknown01(); - } - - //can't loot while flying - if (player.getAltitude() > 0) - return; - - AbstractCharacter tar = null; - Corpse corpse = null; - - if (targetType == GameObjectType.PlayerCharacter.ordinal() || targetType == GameObjectType.Mob.ordinal()) { - - if (targetType == GameObjectType.PlayerCharacter.ordinal()) { - tar = PlayerCharacter.getFromCache(targetID); - - if (tar == null) - return; - - if (player.getObjectUUID() != tar.getObjectUUID() && ((PlayerCharacter) tar).isInSafeZone()) - return; - - } else if (targetType == GameObjectType.NPC.ordinal()) - tar = NPC.getFromCache(targetID); - else if (targetType == GameObjectType.Mob.ordinal()) - tar = Mob.getFromCache(targetID); - if (tar == null) - return; - - if (tar.equals(player)) { - ErrorPopupMsg.sendErrorMsg(player, "Cannot loot this item."); - return; - } - - - if (player.getLoc().distanceSquared2D(tar.getLoc()) > sqr(MBServerStatics.LOOT_RANGE)) { - ErrorPopupMsg.sendErrorMsg(player, "You are too far away to loot this corpse."); - - Logger.info(player.getFirstName() + " tried looting at " + player.getLoc().distance2D(tar.getLoc()) + " distance."); - return; - } - - //can't loot from someone who is alive. - if (AbstractWorldObject.IsAbstractCharacter(tar)) { - if (tar.isAlive()) - return; - // Logger.error("WorldServer.loot", "Looting from live player"); - } - - if (!GroupManager.goldSplit(player, item, origin, tar)) { - - if (tar.charItemManager != null) { - - itemRet = tar.charItemManager.lootItemFromMe(item, player, origin); - - //Take equipment off mob - if (tar.getObjectType() == GameObjectType.Mob && itemRet != null) { - Mob mobTarget = (Mob) tar; - - if (item != null && item.getObjectType() == GameObjectType.MobLoot) { - - for (Item equip : mobTarget.charItemManager.equipped.values()) { - - TransferItemFromEquipToInventoryMsg back = new TransferItemFromEquipToInventoryMsg(mobTarget, equip.equipSlot); - DispatchMessage.dispatchMsgToInterestArea(mobTarget, back, DispatchChannel.SECONDARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); - - LootMsg lootMsg = new LootMsg(0, 0, tar.getObjectType().ordinal(), tar.getObjectUUID(), equip); - Dispatch dispatch = Dispatch.borrow(player, lootMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - break; - } - } - } - } - - } - } else if (targetType == GameObjectType.Corpse.ordinal()) { - corpse = Corpse.getCorpse(targetID); - if (corpse == null) - return; - - if (player.getLoc().distanceSquared2D(corpse.getLoc()) > sqr(MBServerStatics.LOOT_RANGE)) { - ErrorPopupMsg.sendErrorMsg(player, "You are too far away to loot this corpse."); - - Logger.info(player.getFirstName() + " tried looting at " + player.getLoc().distance2D(corpse.getLoc()) + " distance."); - return; - } - - - //can't loot other players in safe zone. - if (corpse.getBelongsToType() == GameObjectType.PlayerCharacter.ordinal()) { - - if (player.getObjectUUID() == corpse.getBelongsToID()) - itemRet = corpse.lootItem(item, player); - else if (!GroupManager.goldSplit(player, item, origin, corpse)) { - itemRet = corpse.lootItem(item, player); - - } - - if (itemRet == null) - return; - - - if (item.template.item_type.equals(engine.Enum.ItemType.GOLD)) { - // this is done to prevent the temporary goldItem item - // (from the mob) from appearing in player's inventory. - // It also updates the goldItem quantity display - UpdateGoldMsg updateTargetGold = null; - - - if (corpse != null) - updateTargetGold = new UpdateGoldMsg(corpse); - - updateTargetGold.configure(); - DispatchMessage.dispatchMsgToInterestArea(corpse, updateTargetGold, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); - - UpdateGoldMsg ugm = new UpdateGoldMsg(player); - ugm.configure(); - Dispatch dispatch = Dispatch.borrow(player, ugm); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - - // respond back loot message. Try sending to everyone. - - } else { - - DispatchMessage.dispatchMsgToInterestArea(corpse, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, true); - - - //player.getCharItemManager().updateInventory(); - } - - //TODO send group loot message if player is grouped and visible - Group group = GroupManager.getGroup(player); - - if (group != null && group.getSplitGold() && (item.template.item_type.equals(engine.Enum.ItemType.GOLD) == false)) { - String name = item.getName(); - String text = player.getFirstName() + " has looted " + name + '.'; - ChatManager.chatGroupInfoCanSee(player, text); - } - - return; - } - - - } else - return; - - - if (itemRet == null) { - return; - } - - if (item.template.item_type.equals(engine.Enum.ItemType.GOLD)) { - // this is done to prevent the temporary goldItem item - // (from the mob) from appearing in player's inventory. - // It also updates the goldItem quantity display - UpdateGoldMsg updateTargetGold = null; - - if (tar != null) - updateTargetGold = new UpdateGoldMsg(tar); - else if (corpse != null) - updateTargetGold = new UpdateGoldMsg(corpse); - - updateTargetGold.configure(); - DispatchMessage.dispatchMsgToInterestArea(tar, updateTargetGold, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); - - UpdateGoldMsg ugm = new UpdateGoldMsg(player); - ugm.configure(); - Dispatch dispatch = Dispatch.borrow(player, ugm); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - - // respond back loot message. Try sending to everyone. - - } else { - msg.setSourceType1(0); - msg.setSourceType2(0); - msg.setSourceID1(0); - msg.setSourceID2(0); - Dispatch dispatch = Dispatch.borrow(player, msg); - //DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); - DispatchMessage.dispatchMsgToInterestArea(tar, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, true); - LootMsg newItemMsg = new LootMsg(GameObjectType.PlayerCharacter.ordinal(), player.getObjectUUID(), 0, 0, itemRet); - dispatch = Dispatch.borrow(player, newItemMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); - - //player.getCharItemManager().updateInventory(); - } - - //TODO send group loot message if player is grouped and visible - Group group = GroupManager.getGroup(player); - - if (group != null && group.getSplitGold() && (item.template.item_type.equals(engine.Enum.ItemType.GOLD) == false)) { - String name = item.getName(); - String text = player.getFirstName() + " has looted " + name + '.'; - ChatManager.chatGroupInfoCanSee(player, text); - } - } catch (Exception e) { - Logger.info(e.getMessage()); - } finally { - item.lootLock.unlock(); - } - } - - - } - // called when player types /show private static void show(ShowMsg msg, ClientConnection origin) throws MsgSendException { @@ -642,9 +411,6 @@ public class ClientMessagePump implements NetMsgHandler { case RESETAFTERDEATH: respawn((RespawnMsg) msg, origin); break; - case MOVEOBJECTTOCONTAINER: - loot((LootMsg) msg, origin); - break; case SHOWCOMBATINFO: show((ShowMsg) msg, origin); break; diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index 609cb3fe..936c7256 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -143,7 +143,7 @@ public enum Protocol { MODIFYGUILDSTATE(0x38936FEA, ToggleLfgRecruitingMsg.class, null), //Toggle LFGroup/LFGuild/Recruiting MOTD(0xEC841E8D, MOTDMsg.class, MOTDEditHandler.class), //Send/Rec Guild/Nation/IC MOTD Message MOVECORRECTION(0x47FAD1E3, null, null), //Force move to point? - MOVEOBJECTTOCONTAINER(0xD1639F7C, LootMsg.class, null), //Send/Recv MoveObjectToContainer Msg + MOVEOBJECTTOCONTAINER(0xD1639F7C, LootMsg.class, LootMsgHandler.class), //Send/Recv MoveObjectToContainer Msg MOVETOPOINT(0x49EF7241, MoveToPointMsg.class, MoveToPointHandler.class), // Move to point NAMEVERIFY(0x1B3BF0B1, null, null), // Invalid Name in Character Creation NEWWORLD(0x982E4A77, WorldDataMsg.class, null), // World Data diff --git a/src/engine/net/client/handlers/LootMsgHandler.java b/src/engine/net/client/handlers/LootMsgHandler.java new file mode 100644 index 00000000..b727b1af --- /dev/null +++ b/src/engine/net/client/handlers/LootMsgHandler.java @@ -0,0 +1,260 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + +package engine.net.client.handlers; + +import engine.Enum; +import engine.Enum.DispatchChannel; +import engine.exception.MsgSendException; +import engine.gameManager.ChatManager; +import engine.gameManager.GroupManager; +import engine.net.Dispatch; +import engine.net.DispatchMessage; +import engine.net.client.ClientConnection; +import engine.net.client.msg.*; +import engine.objects.*; +import engine.server.MBServerStatics; +import org.pmw.tinylog.Logger; + +import static engine.math.FastMath.sqr; + +public class LootMsgHandler extends AbstractClientMsgHandler { + + public LootMsgHandler() { + super(LootMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter player = origin.getPlayerCharacter(); + + // Member variable declaration + + LootMsg msg; + + // Member variable assignment + + msg = (LootMsg) baseMsg; + + if (player == null) + return true; + + if (!player.isAlive()) + return true; + + Item item = msg.getItem(); + + if (item == null) + return true; + + if (item.lootLock.tryLock()) { + try { + Item itemRet = null; + // get current owner + int targetType = msg.getTargetType(); + int targetID = msg.getTargetID(); + + if (targetType == Enum.GameObjectType.PlayerCharacter.ordinal() || targetType == Enum.GameObjectType.Mob.ordinal() || targetType == Enum.GameObjectType.Corpse.ordinal()) { + } else { //needed for getting contracts for some reason + targetType = msg.getSourceID2(); + targetID = msg.getUnknown01(); + } + + //can't loot while flying + if (player.getAltitude() > 0) + return true; + + AbstractCharacter tar = null; + Corpse corpse = null; + + if (targetType == Enum.GameObjectType.PlayerCharacter.ordinal() || targetType == Enum.GameObjectType.Mob.ordinal()) { + + if (targetType == Enum.GameObjectType.PlayerCharacter.ordinal()) { + tar = PlayerCharacter.getFromCache(targetID); + + if (tar == null) + return true; + + if (player.getObjectUUID() != tar.getObjectUUID() && ((PlayerCharacter) tar).isInSafeZone()) + return true; + + } else if (targetType == Enum.GameObjectType.NPC.ordinal()) + tar = NPC.getFromCache(targetID); + else if (targetType == Enum.GameObjectType.Mob.ordinal()) + tar = Mob.getFromCache(targetID); + + if (tar == null) + return true; + + if (tar.equals(player)) { + ErrorPopupMsg.sendErrorMsg(player, "Cannot loot this item."); + return true; + } + + if (player.getLoc().distanceSquared2D(tar.getLoc()) > sqr(MBServerStatics.LOOT_RANGE)) { + ErrorPopupMsg.sendErrorMsg(player, "You are too far away to loot this corpse."); + Logger.info(player.getFirstName() + " tried looting at " + player.getLoc().distance2D(tar.getLoc()) + " distance."); + return true; + } + + //can't loot from someone who is alive. + if (AbstractWorldObject.IsAbstractCharacter(tar)) { + if (tar.isAlive()) + return true; + // Logger.error("WorldServer.loot", "Looting from live player"); + } + + if (!GroupManager.goldSplit(player, item, origin, tar)) { + + if (tar.charItemManager != null) { + + itemRet = tar.charItemManager.lootItemFromMe(item, player, origin); + + //Take equipment off mob + if (tar.getObjectType() == Enum.GameObjectType.Mob && itemRet != null) { + Mob mobTarget = (Mob) tar; + + if (item != null && item.getObjectType() == Enum.GameObjectType.MobLoot) { + + for (Item equip : mobTarget.charItemManager.equipped.values()) { + + TransferItemFromEquipToInventoryMsg back = new TransferItemFromEquipToInventoryMsg(mobTarget, equip.equipSlot); + DispatchMessage.dispatchMsgToInterestArea(mobTarget, back, DispatchChannel.SECONDARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); + + LootMsg lootMsg = new LootMsg(0, 0, tar.getObjectType().ordinal(), tar.getObjectUUID(), equip); + Dispatch dispatch = Dispatch.borrow(player, lootMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + break; + } + } + } + } + + } + } else if (targetType == Enum.GameObjectType.Corpse.ordinal()) { + corpse = Corpse.getCorpse(targetID); + + if (corpse == null) + return true; + + if (player.getLoc().distanceSquared2D(corpse.getLoc()) > sqr(MBServerStatics.LOOT_RANGE)) { + ErrorPopupMsg.sendErrorMsg(player, "You are too far away to loot this corpse."); + Logger.info(player.getFirstName() + " tried looting at " + player.getLoc().distance2D(corpse.getLoc()) + " distance."); + return true; + } + + //can't loot other players in safe zone. + if (corpse.getBelongsToType() == Enum.GameObjectType.PlayerCharacter.ordinal()) { + + if (player.getObjectUUID() == corpse.getBelongsToID()) + itemRet = corpse.lootItem(item, player); + else if (!GroupManager.goldSplit(player, item, origin, corpse)) { + itemRet = corpse.lootItem(item, player); + + } + + if (itemRet == null) + return true; + + if (item.template.item_type.equals(engine.Enum.ItemType.GOLD)) { + // this is done to prevent the temporary goldItem item + // (from the mob) from appearing in player's inventory. + // It also updates the goldItem quantity display + UpdateGoldMsg updateTargetGold = null; + + if (corpse != null) + updateTargetGold = new UpdateGoldMsg(corpse); + + updateTargetGold.configure(); + DispatchMessage.dispatchMsgToInterestArea(corpse, updateTargetGold, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); + + UpdateGoldMsg ugm = new UpdateGoldMsg(player); + ugm.configure(); + Dispatch dispatch = Dispatch.borrow(player, ugm); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + + // respond back loot message. Try sending to everyone. + + } else + DispatchMessage.dispatchMsgToInterestArea(corpse, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, true); + + + //TODO send group loot message if player is grouped and visible + Group group = GroupManager.getGroup(player); + + if (group != null && group.getSplitGold() && (item.template.item_type.equals(engine.Enum.ItemType.GOLD) == false)) { + String name = item.getName(); + String text = player.getFirstName() + " has looted " + name + '.'; + ChatManager.chatGroupInfoCanSee(player, text); + } + + return true; + } + + } else + return true; + + if (itemRet == null) + return true; + + if (item.template.item_type.equals(engine.Enum.ItemType.GOLD)) { + // this is done to prevent the temporary goldItem item + // (from the mob) from appearing in player's inventory. + // It also updates the goldItem quantity display + UpdateGoldMsg updateTargetGold = null; + + if (tar != null) + updateTargetGold = new UpdateGoldMsg(tar); + else if (corpse != null) + updateTargetGold = new UpdateGoldMsg(corpse); + + updateTargetGold.configure(); + DispatchMessage.dispatchMsgToInterestArea(tar, updateTargetGold, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); + + UpdateGoldMsg ugm = new UpdateGoldMsg(player); + ugm.configure(); + Dispatch dispatch = Dispatch.borrow(player, ugm); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + + // respond back loot message. Try sending to everyone. + + } else { + msg.setSourceType1(0); + msg.setSourceType2(0); + msg.setSourceID1(0); + msg.setSourceID2(0); + Dispatch dispatch = Dispatch.borrow(player, msg); + //DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); + DispatchMessage.dispatchMsgToInterestArea(tar, msg, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, true); + LootMsg newItemMsg = new LootMsg(Enum.GameObjectType.PlayerCharacter.ordinal(), player.getObjectUUID(), 0, 0, itemRet); + dispatch = Dispatch.borrow(player, newItemMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); + + //player.getCharItemManager().updateInventory(); + } + + //TODO send group loot message if player is grouped and visible + Group group = GroupManager.getGroup(player); + + if (group != null && group.getSplitGold() && (item.template.item_type.equals(engine.Enum.ItemType.GOLD) == false)) { + String name = item.getName(); + String text = player.getFirstName() + " has looted " + name + '.'; + ChatManager.chatGroupInfoCanSee(player, text); + } + } catch (Exception e) { + Logger.info(e.getMessage()); + } finally { + item.lootLock.unlock(); + } + } + + return true; + } + +} \ No newline at end of file From f653376c22c117b7f2d311d4980c855f91f6c1d9 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 05:31:16 -0400 Subject: [PATCH 04/45] Handler created for ClientAdminCommandMsg --- src/engine/gameManager/ChatManager.java | 94 +------------ src/engine/net/client/ClientMessagePump.java | 4 - src/engine/net/client/Protocol.java | 2 +- .../ClientAdminCommandMsgHandler.java | 126 ++++++++++++++++++ 4 files changed, 129 insertions(+), 97 deletions(-) create mode 100644 src/engine/net/client/handlers/ClientAdminCommandMsgHandler.java diff --git a/src/engine/gameManager/ChatManager.java b/src/engine/gameManager/ChatManager.java index ca1aa00c..9180c1b9 100644 --- a/src/engine/gameManager/ChatManager.java +++ b/src/engine/gameManager/ChatManager.java @@ -21,8 +21,8 @@ import engine.net.DispatchMessage; import engine.net.MessageDispatcher; import engine.net.client.ClientConnection; import engine.net.client.Protocol; +import engine.net.client.handlers.ClientAdminCommandMsgHandler; import engine.net.client.msg.chat.*; -import engine.net.client.msg.commands.ClientAdminCommandMsg; import engine.objects.*; import engine.server.MBServerStatics; import engine.server.world.WorldServer; @@ -190,7 +190,7 @@ public enum ChatManager { } if (ChatManager.isDevCommand(text) == true) { - ChatManager.processDevCommand(player, text); + ClientAdminCommandMsgHandler.processDevCommand(player, text); return; } @@ -1083,94 +1083,4 @@ public enum ChatManager { return text.equalsIgnoreCase("lua_population()"); } - private static boolean processDevCommand(AbstractWorldObject sender, String text) { - - if (sender.getObjectType().equals(GameObjectType.PlayerCharacter)) { - - PlayerCharacter pcSender = (PlayerCharacter) sender; - - // first remove the DEV_CMD_PREFIX - String[] words = text.split(MBServerStatics.DEV_CMD_PREFIX, 2); - - if (words[1].length() == 0) - return false; - - // next get the command - String[] commands = words[1].split(" ", 2); - String cmd = commands[0].toLowerCase(); - String cmdArgument = ""; - - if (commands.length > 1) - cmdArgument = commands[1].trim(); - - AbstractGameObject target = pcSender.getLastTarget(); - // return DevCmd.processDevCommand(pcSender, cmd, cmdArgument, - // target); - return DevCmdManager.handleDevCmd(pcSender, cmd, - cmdArgument, target); - } - return false; - } - - /** - * Process an Admin Command, which is a preset command sent from the client - */ - public static void HandleClientAdminCmd(ClientAdminCommandMsg data, - ClientConnection cc) { - - PlayerCharacter pcSender = SessionManager.getPlayerCharacter(cc); - - if (pcSender == null) - return; - - Account acct = SessionManager.getAccount(pcSender); - - if (acct == null) - return; - - // require minimal access to continue - // specific accessLevel checks performed by the DevCmdManager - if (acct.status.equals(Enum.AccountStatus.ADMIN) == false) { - Logger.warn(pcSender.getFirstName() + " Attempted to use a client admin command"); - //wtf? ChatManager.chatSystemInfo(pcSender, "CHEATER!!!!!!!!!!!!!"); - return; - } - - // First remove the initial slash - String d = data.getMsgCommand(); - String[] words = d.split("/", 2); - - if (words[1].length() == 0) - return; - - // Next get the command - String[] commands = words[1].split(" ", 2); - String cmd = commands[0].toLowerCase(); - String cmdArgument = ""; - - if (commands.length > 1) - cmdArgument = commands[1].trim(); - - AbstractGameObject target = data.getTarget(); - - // Map to a DevCmd - String devCmd = ""; - - if (cmd.compareTo("goto") == 0) - devCmd = "goto"; - else if (cmd.compareTo("suspend") == 0) - devCmd = "suspend"; - else if (cmd.compareTo("getinfo") == 0) - devCmd = "info"; - else if (devCmd.isEmpty()) { - Logger.info("Unhandled admin command was used: /" - + cmd); - return; - } - - DevCmdManager.handleDevCmd(pcSender, devCmd, cmdArgument, - target); - } - - } diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 84a799df..a8391b11 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -22,7 +22,6 @@ import engine.net.NetMsgHandler; import engine.net.client.handlers.AbstractClientMsgHandler; import engine.net.client.msg.*; import engine.net.client.msg.chat.AbstractChatMsg; -import engine.net.client.msg.commands.ClientAdminCommandMsg; import engine.objects.*; import engine.server.MBServerStatics; import engine.server.world.WorldServer; @@ -379,9 +378,6 @@ public class ClientMessagePump implements NetMsgHandler { break; case OPENVAULT: break; - case CLIENTADMINCOMMAND: - ChatManager.HandleClientAdminCmd((ClientAdminCommandMsg) msg, origin); - break; case COMBATMODE: CombatManager.toggleCombat(((ToggleCombatMsg) msg).toggleCombat(), origin); break; diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index 936c7256..c498933f 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -77,7 +77,7 @@ public enum Protocol { CITYZONE(0x254947F2, CityZoneMsg.class, null), //For Creating City Object Clientside(Terraform)/Rename City. CLAIMASSET(0x948C62CC, ClaimAssetMsg.class, ClaimAssetMsgHandler.class), // ClaimAsset CLAIMGUILDTREE(0xFD1C6442, ClaimGuildTreeMsg.class, ClaimGuildTreeMsgHandler.class), - CLIENTADMINCOMMAND(0x624EAB5F, ClientAdminCommandMsg.class, null), //Admin Command + CLIENTADMINCOMMAND(0x624EAB5F, ClientAdminCommandMsg.class, ClientAdminCommandMsgHandler.class), //Admin Command CLIENTUPDATEVAULT(0x66EDBECD, UpdateVaultMsg.class, null), COMBATMODE(0xFE4BF353, ToggleCombatMsg.class, null), //Toggle Combat mode CONFIRMPROMOTE(0x153BB5F9, ConfirmPromoteMsg.class, null), diff --git a/src/engine/net/client/handlers/ClientAdminCommandMsgHandler.java b/src/engine/net/client/handlers/ClientAdminCommandMsgHandler.java new file mode 100644 index 00000000..1e3500cf --- /dev/null +++ b/src/engine/net/client/handlers/ClientAdminCommandMsgHandler.java @@ -0,0 +1,126 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + +package engine.net.client.handlers; + +import engine.Enum; +import engine.exception.MsgSendException; +import engine.gameManager.DevCmdManager; +import engine.gameManager.SessionManager; +import engine.net.client.ClientConnection; +import engine.net.client.msg.ClientNetMsg; +import engine.net.client.msg.commands.ClientAdminCommandMsg; +import engine.objects.AbstractGameObject; +import engine.objects.AbstractWorldObject; +import engine.objects.Account; +import engine.objects.PlayerCharacter; +import engine.server.MBServerStatics; +import org.pmw.tinylog.Logger; + +public class ClientAdminCommandMsgHandler extends AbstractClientMsgHandler { + + public ClientAdminCommandMsgHandler() { + super(ClientAdminCommandMsg.class); + } + + public static boolean processDevCommand(AbstractWorldObject sender, String text) { + + if (sender.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) { + + PlayerCharacter pcSender = (PlayerCharacter) sender; + + // first remove the DEV_CMD_PREFIX + String[] words = text.split(MBServerStatics.DEV_CMD_PREFIX, 2); + + if (words[1].length() == 0) + return false; + + // next get the command + String[] commands = words[1].split(" ", 2); + String cmd = commands[0].toLowerCase(); + String cmdArgument = ""; + + if (commands.length > 1) + cmdArgument = commands[1].trim(); + + AbstractGameObject target = pcSender.getLastTarget(); + // return DevCmd.processDevCommand(pcSender, cmd, cmdArgument, + // target); + return DevCmdManager.handleDevCmd(pcSender, cmd, + cmdArgument, target); + } + return false; + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter player = origin.getPlayerCharacter(); + + // Member variable declaration + + ClientAdminCommandMsg msg; + + // Member variable assignment + + msg = (ClientAdminCommandMsg) baseMsg; + + if (player == null) + return true; + + Account acct = SessionManager.getAccount(player); + + if (acct == null) + return true; + + // require minimal access to continue + // specific accessLevel checks performed by the DevCmdManager + if (acct.status.equals(Enum.AccountStatus.ADMIN) == false) { + Logger.warn(player.getFirstName() + " Attempted to use a client admin command"); + //wtf? ChatManager.chatSystemInfo(pcSender, "CHEATER!!!!!!!!!!!!!"); + return true; + } + + // First remove the initial slash + String d = msg.getMsgCommand(); + String[] words = d.split("/", 2); + + if (words[1].length() == 0) + return true; + + // Next get the command + String[] commands = words[1].split(" ", 2); + String cmd = commands[0].toLowerCase(); + String cmdArgument = ""; + + if (commands.length > 1) + cmdArgument = commands[1].trim(); + + AbstractGameObject target = msg.getTarget(); + + // Map to a DevCmd + String devCmd = ""; + + if (cmd.compareTo("goto") == 0) + devCmd = "goto"; + else if (cmd.compareTo("suspend") == 0) + devCmd = "suspend"; + else if (cmd.compareTo("getinfo") == 0) + devCmd = "info"; + else if (devCmd.isEmpty()) { + Logger.info("Unhandled admin command was used: /" + + cmd); + return true; + } + + DevCmdManager.handleDevCmd(player, devCmd, cmdArgument, + target); + return true; + } + +} \ No newline at end of file From a103e7c7cd4e364d32d21fe4f69629efac18b479 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 05:48:19 -0400 Subject: [PATCH 05/45] Handlers created for toggle combat messages --- src/engine/net/client/ClientMessagePump.java | 6 -- src/engine/net/client/Protocol.java | 4 +- .../KeepAliveServerClientHandler.java | 6 +- .../handlers/SetCombatModeMsgHandler.java | 57 +++++++++++++++++++ .../handlers/ToggleCombatMsgHandler.java | 57 +++++++++++++++++++ 5 files changed, 118 insertions(+), 12 deletions(-) create mode 100644 src/engine/net/client/handlers/SetCombatModeMsgHandler.java create mode 100644 src/engine/net/client/handlers/ToggleCombatMsgHandler.java diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index a8391b11..2e1b0a84 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -378,12 +378,6 @@ public class ClientMessagePump implements NetMsgHandler { break; case OPENVAULT: break; - case COMBATMODE: - CombatManager.toggleCombat(((ToggleCombatMsg) msg).toggleCombat(), origin); - break; - case ARCCOMBATMODEATTACKING: - CombatManager.toggleCombat(((SetCombatModeMsg) msg).getToggle(), origin); - break; case MODIFYGUILDSTATE: ToggleLfgRecruitingMsg tlrm = (ToggleLfgRecruitingMsg) msg; toggleLfgRecruiting(tlrm, origin); diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index c498933f..05aefd66 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -28,7 +28,7 @@ public enum Protocol { ADDFRIEND(0xCFA1C787, AddFriendMessage.class, null), ALLIANCECHANGE(0x0E7D0B57, AllianceChangeMsg.class, AllianceChangeMsgHandler.class), // Remove From Allies/Enemies List ALLYENEMYLIST(0xAEA443FD, AllyEnemyListMsg.class, AllyEnemyListMsgHandler.class), - ARCCOMBATMODEATTACKING(0xD8B10579, SetCombatModeMsg.class, null), // Attack From Outside Combat Mode + ARCCOMBATMODEATTACKING(0xD8B10579, SetCombatModeMsg.class, SetCombatModeMsgHandler.class), // Attack From Outside Combat Mode ARCHOTZONECHANGE(0xDCFF196F, null, null), //change hotzone ARCIGNORELISTUPDATE(0x4B1B17C2, IgnoreListMsg.class, null), //req/show ignore list ARCLOGINNOTIFY(0x010FED87, ArcLoginNotifyMsg.class, ArcLoginNotifyMsgHandler.class), //Client Confirms entering world @@ -79,7 +79,7 @@ public enum Protocol { CLAIMGUILDTREE(0xFD1C6442, ClaimGuildTreeMsg.class, ClaimGuildTreeMsgHandler.class), CLIENTADMINCOMMAND(0x624EAB5F, ClientAdminCommandMsg.class, ClientAdminCommandMsgHandler.class), //Admin Command CLIENTUPDATEVAULT(0x66EDBECD, UpdateVaultMsg.class, null), - COMBATMODE(0xFE4BF353, ToggleCombatMsg.class, null), //Toggle Combat mode + COMBATMODE(0xFE4BF353, ToggleCombatMsg.class, ToggleCombatMsgHandler.class), //Toggle Combat mode CONFIRMPROMOTE(0x153BB5F9, ConfirmPromoteMsg.class, null), COSTTOOPENBANK(0x135BE5E8, AckBankWindowOpenedMsg.class, null), // ACK Bank Window Opened CREATECHAR(0x5D18B5C8, CommitNewCharacterMsg.class, null), // Commit New Character, diff --git a/src/engine/net/client/handlers/KeepAliveServerClientHandler.java b/src/engine/net/client/handlers/KeepAliveServerClientHandler.java index cf1ebdea..8a9b2b81 100644 --- a/src/engine/net/client/handlers/KeepAliveServerClientHandler.java +++ b/src/engine/net/client/handlers/KeepAliveServerClientHandler.java @@ -26,8 +26,7 @@ public class KeepAliveServerClientHandler extends AbstractClientMsgHandler { @Override protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - PlayerCharacter pc = origin.getPlayerCharacter(); - + PlayerCharacter playerCharacter = origin.getPlayerCharacter(); // Member variable declaration @@ -37,10 +36,9 @@ public class KeepAliveServerClientHandler extends AbstractClientMsgHandler { msg = (KeepAliveServerClientMsg) baseMsg; - // Send ping to client - Dispatch dispatch = Dispatch.borrow(pc, msg); + Dispatch dispatch = Dispatch.borrow(playerCharacter, msg); DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); return true; diff --git a/src/engine/net/client/handlers/SetCombatModeMsgHandler.java b/src/engine/net/client/handlers/SetCombatModeMsgHandler.java new file mode 100644 index 00000000..193156b9 --- /dev/null +++ b/src/engine/net/client/handlers/SetCombatModeMsgHandler.java @@ -0,0 +1,57 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + +package engine.net.client.handlers; + +import engine.Enum; +import engine.exception.MsgSendException; +import engine.net.DispatchMessage; +import engine.net.client.ClientConnection; +import engine.net.client.msg.ClientNetMsg; +import engine.net.client.msg.SetCombatModeMsg; +import engine.net.client.msg.UpdateStateMsg; +import engine.objects.PlayerCharacter; +import engine.server.MBServerStatics; + +public class SetCombatModeMsgHandler extends AbstractClientMsgHandler { + + public SetCombatModeMsgHandler() { + super(SetCombatModeMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter playerCharacter = origin.getPlayerCharacter(); + + // Member variable declaration + + SetCombatModeMsg msg; + boolean toggle; + + // Member variable assignment + + msg = (SetCombatModeMsg) baseMsg; + + if (playerCharacter == null) + return true; + + toggle = msg.getToggle(); + playerCharacter.setCombat(toggle); + + if (!toggle) // toggle is move it to false so clear combat target + playerCharacter.setCombatTarget(null); //clear last combat target + + UpdateStateMsg rwss = new UpdateStateMsg(); + rwss.setPlayer(playerCharacter); + DispatchMessage.dispatchMsgToInterestArea(playerCharacter, rwss, Enum.DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); + + return true; + } + +} \ No newline at end of file diff --git a/src/engine/net/client/handlers/ToggleCombatMsgHandler.java b/src/engine/net/client/handlers/ToggleCombatMsgHandler.java new file mode 100644 index 00000000..c00c189e --- /dev/null +++ b/src/engine/net/client/handlers/ToggleCombatMsgHandler.java @@ -0,0 +1,57 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + +package engine.net.client.handlers; + +import engine.Enum; +import engine.exception.MsgSendException; +import engine.net.DispatchMessage; +import engine.net.client.ClientConnection; +import engine.net.client.msg.ClientNetMsg; +import engine.net.client.msg.ToggleCombatMsg; +import engine.net.client.msg.UpdateStateMsg; +import engine.objects.PlayerCharacter; +import engine.server.MBServerStatics; + +public class ToggleCombatMsgHandler extends AbstractClientMsgHandler { + + public ToggleCombatMsgHandler() { + super(ToggleCombatMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter playerCharacter = origin.getPlayerCharacter(); + + // Member variable declaration + + ToggleCombatMsg msg; + boolean toggle; + + // Member variable assignment + + msg = (ToggleCombatMsg) baseMsg; + + if (playerCharacter == null) + return true; + + toggle = msg.toggleCombat(); + playerCharacter.setCombat(toggle); + + if (!toggle) // toggle is move it to false so clear combat target + playerCharacter.setCombatTarget(null); //clear last combat target + + UpdateStateMsg rwss = new UpdateStateMsg(); + rwss.setPlayer(playerCharacter); + DispatchMessage.dispatchMsgToInterestArea(playerCharacter, rwss, Enum.DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false); + + return true; + } + +} \ No newline at end of file From e86097d732bf27b5ea3668f7813a1d8aabb3ba6d Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 05:58:38 -0400 Subject: [PATCH 06/45] Handler created for LFGmsg --- src/engine/net/client/ClientMessagePump.java | 20 ------- src/engine/net/client/Protocol.java | 2 +- .../ToggleLfgRecruitingMsgHandler.java | 59 +++++++++++++++++++ 3 files changed, 60 insertions(+), 21 deletions(-) create mode 100644 src/engine/net/client/handlers/ToggleLfgRecruitingMsgHandler.java diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 2e1b0a84..2f672355 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -48,22 +48,6 @@ public class ClientMessagePump implements NetMsgHandler { this.server = server; } - private static void toggleLfgRecruiting(ToggleLfgRecruitingMsg msg, ClientConnection origin) throws MsgSendException { - PlayerCharacter pc = SessionManager.getPlayerCharacter(origin); - if (pc == null) - return; - int num = msg.toggleLfgRecruiting(); - if (num == 1) - pc.toggleLFGroup(); - else if (num == 2) - pc.toggleLFGuild(); - else if (num == 3) - pc.toggleRecruiting(); - UpdateStateMsg rwss = new UpdateStateMsg(); - rwss.setPlayer(pc); - DispatchMessage.dispatchMsgToInterestArea(pc, rwss, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); - } - private static void toggleSitStand(ToggleSitStandMsg msg, ClientConnection origin) throws MsgSendException { PlayerCharacter pc = SessionManager.getPlayerCharacter(origin); if (pc == null) @@ -378,10 +362,6 @@ public class ClientMessagePump implements NetMsgHandler { break; case OPENVAULT: break; - case MODIFYGUILDSTATE: - ToggleLfgRecruitingMsg tlrm = (ToggleLfgRecruitingMsg) msg; - toggleLfgRecruiting(tlrm, origin); - break; case TOGGLESITSTAND: ToggleSitStandMsg tssm = (ToggleSitStandMsg) msg; toggleSitStand(tssm, origin); diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index 05aefd66..274ee5aa 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -140,7 +140,7 @@ public enum Protocol { MANAGENPC(0x43A273FA, null, null), // Open Hireling Management Page MERCHANT(0x3E645EF4, MerchantMsg.class, MerchantMsgHandler.class), // Open Teleport List, Teleport, Open Shrine, Request Boon, open/manage warehouse window MINIONTRAINING(0xD355F528, MinionTrainingMessage.class, MinionTrainingMsgHandler.class), - MODIFYGUILDSTATE(0x38936FEA, ToggleLfgRecruitingMsg.class, null), //Toggle LFGroup/LFGuild/Recruiting + MODIFYGUILDSTATE(0x38936FEA, ToggleLfgRecruitingMsg.class, ToggleLfgRecruitingMsgHandler.class), //Toggle LFGroup/LFGuild/Recruiting MOTD(0xEC841E8D, MOTDMsg.class, MOTDEditHandler.class), //Send/Rec Guild/Nation/IC MOTD Message MOVECORRECTION(0x47FAD1E3, null, null), //Force move to point? MOVEOBJECTTOCONTAINER(0xD1639F7C, LootMsg.class, LootMsgHandler.class), //Send/Recv MoveObjectToContainer Msg diff --git a/src/engine/net/client/handlers/ToggleLfgRecruitingMsgHandler.java b/src/engine/net/client/handlers/ToggleLfgRecruitingMsgHandler.java new file mode 100644 index 00000000..b2a1dc04 --- /dev/null +++ b/src/engine/net/client/handlers/ToggleLfgRecruitingMsgHandler.java @@ -0,0 +1,59 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + +package engine.net.client.handlers; + +import engine.Enum.DispatchChannel; +import engine.exception.MsgSendException; +import engine.net.DispatchMessage; +import engine.net.client.ClientConnection; +import engine.net.client.msg.ClientNetMsg; +import engine.net.client.msg.ToggleLfgRecruitingMsg; +import engine.net.client.msg.UpdateStateMsg; +import engine.objects.PlayerCharacter; +import engine.server.MBServerStatics; + +public class ToggleLfgRecruitingMsgHandler extends AbstractClientMsgHandler { + + public ToggleLfgRecruitingMsgHandler() { + super(ToggleLfgRecruitingMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter playerCharacter = origin.getPlayerCharacter(); + + // Member variable declaration + + ToggleLfgRecruitingMsg msg; + + // Member variable assignment + + msg = (ToggleLfgRecruitingMsg) baseMsg; + + if (playerCharacter == null) + return true; + + int num = msg.toggleLfgRecruiting(); + + if (num == 1) + playerCharacter.toggleLFGroup(); + else if (num == 2) + playerCharacter.toggleLFGuild(); + else if (num == 3) + playerCharacter.toggleRecruiting(); + + UpdateStateMsg rwss = new UpdateStateMsg(); + rwss.setPlayer(playerCharacter); + DispatchMessage.dispatchMsgToInterestArea(playerCharacter, rwss, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); + + return true; + } + +} \ No newline at end of file From 7b9d9d64bbda966b581ebdede6fda6c44506e1fe Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 06:02:29 -0400 Subject: [PATCH 07/45] Handler created for ToggleSitStandMsg --- src/engine/net/client/ClientMessagePump.java | 29 --------- src/engine/net/client/Protocol.java | 2 +- .../handlers/ToggleSitStandMsgHandler.java | 65 +++++++++++++++++++ 3 files changed, 66 insertions(+), 30 deletions(-) create mode 100644 src/engine/net/client/handlers/ToggleSitStandMsgHandler.java diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 2f672355..fdfc2c18 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -48,31 +48,6 @@ public class ClientMessagePump implements NetMsgHandler { this.server = server; } - private static void toggleSitStand(ToggleSitStandMsg msg, ClientConnection origin) throws MsgSendException { - PlayerCharacter pc = SessionManager.getPlayerCharacter(origin); - if (pc == null) - return; - - pc.update(); - - pc.setSit(msg.toggleSitStand()); - - // cancel effects that break on sit - if (pc.isSit()) { - pc.setCombat(false); - pc.cancelOnSit(); - } - - UpdateStateMsg rwss = new UpdateStateMsg(); - if (pc.isSit()) { - pc.setCombat(false); - rwss.setAware(1); - } - rwss.setPlayer(pc); - - DispatchMessage.dispatchMsgToInterestArea(pc, rwss, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); - } - 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. @@ -362,10 +337,6 @@ public class ClientMessagePump implements NetMsgHandler { break; case OPENVAULT: break; - case TOGGLESITSTAND: - ToggleSitStandMsg tssm = (ToggleSitStandMsg) msg; - toggleSitStand(tssm, origin); - break; case IGNORE: ((IgnoreMsg) msg).handleRequest(origin); break; diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index 274ee5aa..6b3f6b94 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -210,7 +210,7 @@ public enum Protocol { TAXRESOURCES(0x4AD458AF, TaxResourcesMsg.class, TaxResourcesMsgHandler.class), TELEPORT(0x23E726EA, TeleportToPointMsg.class, null), // Teleport to point TERRITORYCHANGE(0x6B388C8C, TerritoryChangeMessage.class, null), //Hey rich, look what I found? :) - TOGGLESITSTAND(0x624F3C0F, ToggleSitStandMsg.class, null), //Toggle Sit/Stand + TOGGLESITSTAND(0x624F3C0F, ToggleSitStandMsg.class, ToggleSitStandMsgHandler.class), //Toggle Sit/Stand TRADEADDGOLD(0x654ACB45, AddGoldToTradeWindowMsg.class, null), // Add Gold to Trade Window TRADEADDOBJECT(0x55D363E9, AddItemToTradeWindowMsg.class, null), // Add an Item to the Trade Window TRADECLOSE(0x5008D7FC, CloseTradeWindowMsg.class, null), // Cancel trade/ACK trade complete diff --git a/src/engine/net/client/handlers/ToggleSitStandMsgHandler.java b/src/engine/net/client/handlers/ToggleSitStandMsgHandler.java new file mode 100644 index 00000000..2ec21a0a --- /dev/null +++ b/src/engine/net/client/handlers/ToggleSitStandMsgHandler.java @@ -0,0 +1,65 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + +package engine.net.client.handlers; + +import engine.Enum.DispatchChannel; +import engine.exception.MsgSendException; +import engine.net.DispatchMessage; +import engine.net.client.ClientConnection; +import engine.net.client.msg.ClientNetMsg; +import engine.net.client.msg.ToggleSitStandMsg; +import engine.net.client.msg.UpdateStateMsg; +import engine.objects.PlayerCharacter; +import engine.server.MBServerStatics; + +public class ToggleSitStandMsgHandler extends AbstractClientMsgHandler { + + public ToggleSitStandMsgHandler() { + super(ToggleSitStandMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter playerCharacter = origin.getPlayerCharacter(); + + // Member variable declaration + + ToggleSitStandMsg msg; + + // Member variable assignment + + msg = (ToggleSitStandMsg) baseMsg; + + if (playerCharacter == null) + return true; + + playerCharacter.update(); + + playerCharacter.setSit(msg.toggleSitStand()); + + // cancel effects that break on sit + if (playerCharacter.isSit()) { + playerCharacter.setCombat(false); + playerCharacter.cancelOnSit(); + } + + UpdateStateMsg rwss = new UpdateStateMsg(); + + if (playerCharacter.isSit()) { + playerCharacter.setCombat(false); + rwss.setAware(1); + } + rwss.setPlayer(playerCharacter); + + DispatchMessage.dispatchMsgToInterestArea(playerCharacter, rwss, DispatchChannel.PRIMARY, MBServerStatics.CHARACTER_LOAD_RANGE, true, false); + return true; + } + +} \ No newline at end of file From fbec20638998c7f271d2a58294b5d2640dba8770 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 06:08:04 -0400 Subject: [PATCH 08/45] Handler created for IgnoreMsg --- src/engine/net/client/ClientMessagePump.java | 3 - src/engine/net/client/Protocol.java | 2 +- .../net/client/handlers/IgnoreMsgHandler.java | 112 ++++++++++++++++++ src/engine/net/client/msg/IgnoreMsg.java | 79 +----------- 4 files changed, 114 insertions(+), 82 deletions(-) create mode 100644 src/engine/net/client/handlers/IgnoreMsgHandler.java diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index fdfc2c18..0eede17f 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -337,9 +337,6 @@ public class ClientMessagePump implements NetMsgHandler { break; case OPENVAULT: break; - case IGNORE: - ((IgnoreMsg) msg).handleRequest(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 6b3f6b94..61aaa0f2 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -110,7 +110,7 @@ public enum Protocol { GUILDRANKCHANGE(0x0DEFB21F, ChangeRankMsg.class, ChangeRankHandler.class), // Change Rank GUILDTREESTATUS(0x4B95FB85, GuildTreeStatusMsg.class, GuildTreeStatusMsgHandler.class), HIRELINGSERVICE(0xD3D93322, HirelingServiceMsg.class, HirelingServiceMsgHandler.class), - IGNORE(0xBD8881EE, IgnoreMsg.class, null), //client sent /ignore command + IGNORE(0xBD8881EE, IgnoreMsg.class, IgnoreMsgHandler.class), //client sent /ignore command INITIATETRADEHUDS(0x667D29D8, OpenTradeWindowMsg.class, null), // Open Trade Window INVITEGROUP(0x004A2012, GroupInviteMsg.class, GroupInviteHandler.class), // Send/Receive/Deny Group Invite INVITEGUILDFEALTY(0x0274D612, InviteToSubMsg.class, InviteToSubHandler.class), // Invite Guild to Swear diff --git a/src/engine/net/client/handlers/IgnoreMsgHandler.java b/src/engine/net/client/handlers/IgnoreMsgHandler.java new file mode 100644 index 00000000..34e0ee72 --- /dev/null +++ b/src/engine/net/client/handlers/IgnoreMsgHandler.java @@ -0,0 +1,112 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + +package engine.net.client.handlers; + +import engine.exception.MsgSendException; +import engine.gameManager.ChatManager; +import engine.gameManager.DbManager; +import engine.net.client.ClientConnection; +import engine.net.client.msg.ClientNetMsg; +import engine.net.client.msg.IgnoreMsg; +import engine.objects.Account; +import engine.objects.PlayerCharacter; + +public class IgnoreMsgHandler extends AbstractClientMsgHandler { + + public IgnoreMsgHandler() { + super(IgnoreMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter playerCharacter = origin.getPlayerCharacter(); + + // Member variable declaration + + IgnoreMsg msg; + + // Member variable assignment + + msg = (IgnoreMsg) baseMsg; + + if (msg.nameToIgnore.isEmpty()) { // list ignored players + String[] ignoredPlayers = playerCharacter.getIgnoredPlayerNames(); + String crlf = "\r\n"; + String out = "Ignored players (" + ignoredPlayers.length + "):"; + + for (String name : ignoredPlayers) + out += crlf + name; + + ChatManager.chatSystemInfo(playerCharacter, out); + return true; + } + + //FIX THIS, USE OUR CACHE! + PlayerCharacter pcToIgnore = PlayerCharacter.getByFirstName(msg.nameToIgnore); + + if (playerCharacter == null) + return true; + + + if (pcToIgnore == null || pcToIgnore.getAccount() == null) { + ChatManager.chatSystemError(playerCharacter, "Character name " + msg.nameToIgnore + " does not exist and cannot be ignored."); + return true; + } + if (pcToIgnore.getObjectUUID() == playerCharacter.getObjectUUID()) { + ChatManager.chatSystemError(playerCharacter, "Try as you might, you are unable to ignore yourself!"); + return true; + } + String firstName = pcToIgnore.getFirstName(); + + Account account = playerCharacter.getAccount(); + + if (account == null) + return true; + + if (playerCharacter.isIgnoringPlayer(pcToIgnore)) { + + if (account != null) { + if (!DbManager.PlayerCharacterQueries.SET_IGNORE_LIST(account.getObjectUUID(), pcToIgnore.getObjectUUID(), false, pcToIgnore.getFirstName())) { + ChatManager.chatSystemError(playerCharacter, "Unable to update database ignore list."); + } + } else { + ChatManager.chatSystemError(playerCharacter, "Unable to update database ignore list."); + } + + playerCharacter.removeIgnoredPlayer(pcToIgnore.getAccount()); + ChatManager.chatSystemInfo(playerCharacter, "Character " + firstName + " is no longer ignored."); + } else { + + if (!PlayerCharacter.isIgnorable()) { + ChatManager.chatSystemError(playerCharacter, "This character cannot be ignored."); + return true; + } + + if (PlayerCharacter.isIgnoreListFull()) { + ChatManager.chatSystemError(playerCharacter, "Your ignore list is already full."); + return true; + } + + if (account != null) { + if (!DbManager.PlayerCharacterQueries.SET_IGNORE_LIST(account.getObjectUUID(), pcToIgnore.getObjectUUID(), true, pcToIgnore.getFirstName())) { + ChatManager.chatSystemError(playerCharacter, "Unable to update database ignore list. This ignore will not persist past server down."); + } + } else { + ChatManager.chatSystemError(playerCharacter, "Unable to update database ignore list."); + } + + playerCharacter.addIgnoredPlayer(pcToIgnore.getAccount(), pcToIgnore.getFirstName()); + ChatManager.chatSystemInfo(playerCharacter, "Character " + firstName + " is now being ignored."); + } + + return true; + } + +} \ No newline at end of file diff --git a/src/engine/net/client/msg/IgnoreMsg.java b/src/engine/net/client/msg/IgnoreMsg.java index 644f8b45..6c86cf1b 100644 --- a/src/engine/net/client/msg/IgnoreMsg.java +++ b/src/engine/net/client/msg/IgnoreMsg.java @@ -10,23 +10,17 @@ package engine.net.client.msg; -import engine.gameManager.ChatManager; -import engine.gameManager.DbManager; -import engine.gameManager.SessionManager; import engine.net.AbstractConnection; import engine.net.ByteBufferReader; import engine.net.ByteBufferWriter; -import engine.net.client.ClientConnection; import engine.net.client.Protocol; -import engine.objects.Account; -import engine.objects.PlayerCharacter; public class IgnoreMsg extends ClientNetMsg { private int unknown1; private int unknown2; - private String nameToIgnore; + public String nameToIgnore; /** * This is the general purpose constructor. @@ -65,77 +59,6 @@ public class IgnoreMsg extends ClientNetMsg { nameToIgnore = reader.getUnicodeString(); } - public void handleRequest(ClientConnection origin) { - - PlayerCharacter pcSource = SessionManager.getPlayerCharacter(origin); - - if (nameToIgnore.isEmpty()) { // list ignored players - String[] ignoredPlayers = pcSource.getIgnoredPlayerNames(); - String crlf = "\r\n"; - String out = "Ignored players (" + ignoredPlayers.length + "):"; - for (String name : ignoredPlayers) { - out += crlf + name; - } - ChatManager.chatSystemInfo(pcSource, out); - return; - } - - //FIX THIS, USE OUR CACHE! - PlayerCharacter pcToIgnore = PlayerCharacter.getByFirstName(nameToIgnore); - - if (pcSource == null) { - return; - } - if (pcToIgnore == null || pcToIgnore.getAccount() == null) { - ChatManager.chatSystemError(pcSource, "Character name " + nameToIgnore + " does not exist and cannot be ignored."); - return; - } - if (pcToIgnore.getObjectUUID() == pcSource.getObjectUUID()) { - ChatManager.chatSystemError(pcSource, "Try as you might, you are unable to ignore yourself!"); - return; - } - String fn = pcToIgnore.getFirstName(); - - Account ac = pcSource.getAccount(); - - if (ac == null) - return; - - if (pcSource.isIgnoringPlayer(pcToIgnore)) { - - if (ac != null) { - if (!DbManager.PlayerCharacterQueries.SET_IGNORE_LIST(ac.getObjectUUID(), pcToIgnore.getObjectUUID(), false, pcToIgnore.getFirstName())) { - ChatManager.chatSystemError(pcSource, "Unable to update database ignore list."); - } - } else { - ChatManager.chatSystemError(pcSource, "Unable to update database ignore list."); - } - - pcSource.removeIgnoredPlayer(pcToIgnore.getAccount()); - ChatManager.chatSystemInfo(pcSource, "Character " + fn + " is no longer ignored."); - } else { - if (!PlayerCharacter.isIgnorable()) { - ChatManager.chatSystemError(pcSource, "This character cannot be ignored."); - return; - } - if (PlayerCharacter.isIgnoreListFull()) { - ChatManager.chatSystemError(pcSource, "Your ignore list is already full."); - return; - } - - if (ac != null) { - if (!DbManager.PlayerCharacterQueries.SET_IGNORE_LIST(ac.getObjectUUID(), pcToIgnore.getObjectUUID(), true, pcToIgnore.getFirstName())) { - ChatManager.chatSystemError(pcSource, "Unable to update database ignore list. This ignore will not persist past server down."); - } - } else { - ChatManager.chatSystemError(pcSource, "Unable to update database ignore list."); - } - - pcSource.addIgnoredPlayer(pcToIgnore.getAccount(), pcToIgnore.getFirstName()); - ChatManager.chatSystemInfo(pcSource, "Character " + fn + " is now being ignored."); - } - } - /** * @return the unknown1 */ From 80c11db80b2d098bd2b3b0d26d7d23f93db3c4c9 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 06:14:19 -0400 Subject: [PATCH 09/45] Handler created for ViewResourcesMsg --- src/engine/net/client/ClientMessagePump.java | 40 ++---------- src/engine/net/client/Protocol.java | 2 +- .../client/handlers/MerchantMsgHandler.java | 2 +- .../client/handlers/TaxCityMsgHandler.java | 4 +- .../handlers/ViewResourcesMsgHandler.java | 65 +++++++++++++++++++ ...rcesMessage.java => ViewResourcesMsg.java} | 6 +- src/engine/objects/City.java | 4 +- src/engine/objects/Warehouse.java | 8 +-- 8 files changed, 83 insertions(+), 48 deletions(-) create mode 100644 src/engine/net/client/handlers/ViewResourcesMsgHandler.java rename src/engine/net/client/msg/{ViewResourcesMessage.java => ViewResourcesMsg.java} (96%) diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 0eede17f..be5270aa 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -22,15 +22,16 @@ import engine.net.NetMsgHandler; import engine.net.client.handlers.AbstractClientMsgHandler; import engine.net.client.msg.*; import engine.net.client.msg.chat.AbstractChatMsg; -import engine.objects.*; +import engine.objects.AbstractCharacter; +import engine.objects.Mob; +import engine.objects.NPC; +import engine.objects.PlayerCharacter; import engine.server.MBServerStatics; import engine.server.world.WorldServer; import engine.session.Session; import engine.util.StringUtils; import org.pmw.tinylog.Logger; -import java.sql.SQLException; - /** * @author: * @summary: This class is the mainline router for application protocol @@ -167,34 +168,6 @@ public class ClientMessagePump implements NetMsgHandler { } - private static void ViewResourcesMessage(ViewResourcesMessage msg, ClientConnection origin) throws SQLException { - - PlayerCharacter player = SessionManager.getPlayerCharacter(origin); - - if (player == null) - return; - - Guild guild = player.getGuild(); - City city = guild.getOwnedCity(); - - if (city == null) - return; - - Building warehouse = BuildingManager.getBuilding(city.getWarehouseBuildingID()); - - if (warehouse == null) - return; - - ViewResourcesMessage vrm = new ViewResourcesMessage(player); - vrm.setWarehouseBuilding(warehouse); - vrm.setGuild(player.getGuild()); - vrm.configure(); - - Dispatch dispatch = Dispatch.borrow(player, vrm); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - - } - protected static void petAttack(PetAttackMsg msg, ClientConnection conn) throws MsgSendException { PlayerCharacter pc = SessionManager.getPlayerCharacter(conn); @@ -337,9 +310,6 @@ public class ClientMessagePump implements NetMsgHandler { break; case OPENVAULT: break; - case VIEWRESOURCES: - ViewResourcesMessage((ViewResourcesMessage) msg, origin); - break; case RAISEATTR: modifyStat((ModifyStatMsg) msg, origin); break; @@ -423,7 +393,7 @@ public class ClientMessagePump implements NetMsgHandler { } - } catch (MsgSendException | SQLException e) { + } catch (Exception e) { Logger.error("handler for " + protocolMsg + " failed: " + e); return false; } diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index 61aaa0f2..a7fb326e 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -241,7 +241,7 @@ public enum Protocol { VENDORSELLWINDOW(0x267DAB90, VendorSellWindowMsg.class, VendorSellWindowMsgHandler.class), //open Sell to NPC Window VENDORBUYWINDOW(0x682DAB4D, VendorBuyWindowMsg.class, VendorBuyWindowMsgHandler.class), // Open Buy From NPC Window VERSIONINFO(0x4B7EE463, VersionInfoMsg.class, null), // Version Information - VIEWRESOURCES(0xCEFD0346, ViewResourcesMessage.class, null), + VIEWRESOURCES(0xCEFD0346, ViewResourcesMsg.class, ViewResourcesMsgHandler.class), VISUALUPDATE(0x33402fd2, null, null), WEIGHTINVENTORY(0xF1B6A85C, LootWindowResponseMsg.class, null), // MoveObjectToContainer Window Response WHOREQUEST(0xF431CCE9, WhoRequestMsg.class, WhoRequestMsgHandler.class), // Request /who diff --git a/src/engine/net/client/handlers/MerchantMsgHandler.java b/src/engine/net/client/handlers/MerchantMsgHandler.java index f924598a..ad2a0fd2 100644 --- a/src/engine/net/client/handlers/MerchantMsgHandler.java +++ b/src/engine/net/client/handlers/MerchantMsgHandler.java @@ -428,7 +428,7 @@ public class MerchantMsgHandler extends AbstractClientMsgHandler { DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); break; case 16: - ViewResourcesMessage vrm = new ViewResourcesMessage(player); + ViewResourcesMsg vrm = new ViewResourcesMsg(player); warehouse = npc.getBuilding(); vrm.setGuild(player.getGuild()); vrm.setWarehouseBuilding(warehouse); diff --git a/src/engine/net/client/handlers/TaxCityMsgHandler.java b/src/engine/net/client/handlers/TaxCityMsgHandler.java index de320b1d..0f0265e5 100644 --- a/src/engine/net/client/handlers/TaxCityMsgHandler.java +++ b/src/engine/net/client/handlers/TaxCityMsgHandler.java @@ -10,7 +10,7 @@ import engine.net.client.ClientConnection; import engine.net.client.msg.ClientNetMsg; import engine.net.client.msg.ErrorPopupMsg; import engine.net.client.msg.TaxCityMsg; -import engine.net.client.msg.ViewResourcesMessage; +import engine.net.client.msg.ViewResourcesMsg; import engine.objects.*; /* @@ -109,7 +109,7 @@ public class TaxCityMsgHandler extends AbstractClientMsgHandler { // return true; - ViewResourcesMessage vrm = new ViewResourcesMessage(player); + ViewResourcesMsg vrm = new ViewResourcesMsg(player); vrm.setGuild(building.getGuild()); vrm.setWarehouseBuilding(BuildingManager.getBuildingFromCache(building.getCity().warehouse.building.getObjectUUID())); vrm.configure(); diff --git a/src/engine/net/client/handlers/ViewResourcesMsgHandler.java b/src/engine/net/client/handlers/ViewResourcesMsgHandler.java new file mode 100644 index 00000000..1d758a4a --- /dev/null +++ b/src/engine/net/client/handlers/ViewResourcesMsgHandler.java @@ -0,0 +1,65 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + +package engine.net.client.handlers; + +import engine.Enum.DispatchChannel; +import engine.exception.MsgSendException; +import engine.gameManager.BuildingManager; +import engine.net.Dispatch; +import engine.net.DispatchMessage; +import engine.net.client.ClientConnection; +import engine.net.client.msg.ClientNetMsg; +import engine.net.client.msg.ViewResourcesMsg; +import engine.objects.Building; +import engine.objects.City; +import engine.objects.Guild; +import engine.objects.PlayerCharacter; + +public class ViewResourcesMsgHandler extends AbstractClientMsgHandler { + + public ViewResourcesMsgHandler() { + super(ViewResourcesMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter playerCharacter = origin.getPlayerCharacter(); + + // Member variable declaration + + ViewResourcesMsg msg; + + // Member variable assignment + + msg = (ViewResourcesMsg) baseMsg; + + Guild guild = playerCharacter.getGuild(); + City city = guild.getOwnedCity(); + + if (city == null) + return true; + + Building warehouse = BuildingManager.getBuilding(city.getWarehouseBuildingID()); + + if (warehouse == null) + return true; + + ViewResourcesMsg vrm = new ViewResourcesMsg(playerCharacter); + vrm.setWarehouseBuilding(warehouse); + vrm.setGuild(playerCharacter.getGuild()); + vrm.configure(); + + Dispatch dispatch = Dispatch.borrow(playerCharacter, vrm); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + + return true; + } + +} \ No newline at end of file diff --git a/src/engine/net/client/msg/ViewResourcesMessage.java b/src/engine/net/client/msg/ViewResourcesMsg.java similarity index 96% rename from src/engine/net/client/msg/ViewResourcesMessage.java rename to src/engine/net/client/msg/ViewResourcesMsg.java index c39df54d..6ad85be3 100644 --- a/src/engine/net/client/msg/ViewResourcesMessage.java +++ b/src/engine/net/client/msg/ViewResourcesMsg.java @@ -18,7 +18,7 @@ import engine.net.client.Protocol; import engine.objects.*; -public class ViewResourcesMessage extends ClientNetMsg { +public class ViewResourcesMsg extends ClientNetMsg { //resource hashes //0001240F @@ -55,7 +55,7 @@ public class ViewResourcesMessage extends ClientNetMsg { * This is the general purpose constructor. */ - public ViewResourcesMessage(PlayerCharacter player) { + public ViewResourcesMsg(PlayerCharacter player) { super(Protocol.VIEWRESOURCES); this.guild = null; this.player = player; @@ -64,7 +64,7 @@ public class ViewResourcesMessage extends ClientNetMsg { /** * This constructor is used by NetMsgFactory. It attempts to deserialize the ByteBuffer into a message. If a BufferUnderflow occurs (based on reading past the limit) then this constructor Throws that Exception to the caller. */ - public ViewResourcesMessage(AbstractConnection origin, ByteBufferReader reader) { + public ViewResourcesMsg(AbstractConnection origin, ByteBufferReader reader) { super(Protocol.VIEWRESOURCES, origin, reader); } diff --git a/src/engine/objects/City.java b/src/engine/objects/City.java index a431ee8e..4b55230e 100644 --- a/src/engine/objects/City.java +++ b/src/engine/objects/City.java @@ -25,7 +25,7 @@ import engine.net.Dispatch; import engine.net.DispatchMessage; import engine.net.client.msg.ErrorPopupMsg; import engine.net.client.msg.TaxResourcesMsg; -import engine.net.client.msg.ViewResourcesMessage; +import engine.net.client.msg.ViewResourcesMsg; import engine.powers.EffectsBase; import engine.server.MBServerStatics; import engine.server.world.WorldServer; @@ -1387,7 +1387,7 @@ public class City extends AbstractWorldObject { // Member variable assignment - ViewResourcesMessage vrm = new ViewResourcesMessage(player); + ViewResourcesMsg vrm = new ViewResourcesMsg(player); vrm.setGuild(building.getGuild()); vrm.setWarehouseBuilding(BuildingManager.getBuildingFromCache(building.getCity().warehouse.building.getObjectUUID())); vrm.configure(); diff --git a/src/engine/objects/Warehouse.java b/src/engine/objects/Warehouse.java index 7ed3afcc..0f741752 100644 --- a/src/engine/objects/Warehouse.java +++ b/src/engine/objects/Warehouse.java @@ -118,7 +118,7 @@ public class Warehouse { return; } - ViewResourcesMessage vrm = new ViewResourcesMessage(player); + ViewResourcesMsg vrm = new ViewResourcesMsg(player); vrm.setGuild(player.getGuild()); vrm.setWarehouseBuilding(warehouseBuilding); vrm.configure(); @@ -164,7 +164,7 @@ public class Warehouse { return; } - ViewResourcesMessage vrm = new ViewResourcesMessage(player); + ViewResourcesMsg vrm = new ViewResourcesMsg(player); vrm.setGuild(player.getGuild()); vrm.setWarehouseBuilding(warehouseBuilding); vrm.configure(); @@ -205,7 +205,7 @@ public class Warehouse { worked = DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse); if (worked) { - ViewResourcesMessage vrm = new ViewResourcesMessage(player); + ViewResourcesMsg vrm = new ViewResourcesMsg(player); vrm.setGuild(player.getGuild()); vrm.setWarehouseBuilding(warehouseBuilding); vrm.configure(); @@ -222,7 +222,7 @@ public class Warehouse { worked = DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse); if (worked) { - ViewResourcesMessage vrm = new ViewResourcesMessage(player); + ViewResourcesMsg vrm = new ViewResourcesMsg(player); vrm.setGuild(player.getGuild()); vrm.setWarehouseBuilding(warehouseBuilding); vrm.configure(); From 5a1806d11b06a2629c7fdde740b8df6d0a7c819e Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 06:17:46 -0400 Subject: [PATCH 10/45] Handler created for PetCmdMsg --- src/engine/net/client/ClientMessagePump.java | 50 ----------- src/engine/net/client/Protocol.java | 2 +- .../net/client/handlers/PetCmdMsgHandler.java | 84 +++++++++++++++++++ 3 files changed, 85 insertions(+), 51 deletions(-) create mode 100644 src/engine/net/client/handlers/PetCmdMsgHandler.java diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index be5270aa..894270b6 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -11,7 +11,6 @@ package engine.net.client; import engine.Enum.DispatchChannel; import engine.Enum.GameObjectType; -import engine.InterestManagement.WorldGrid; import engine.exception.MsgSendException; import engine.gameManager.*; import engine.job.JobScheduler; @@ -207,52 +206,6 @@ public class ClientMessagePump implements NetMsgHandler { return; } - protected static void petCmd(PetCmdMsg msg, ClientConnection conn) throws MsgSendException { - - PlayerCharacter pc = SessionManager.getPlayerCharacter(conn); - - if (pc == null) - return; - - Mob pet = pc.getPet(); - - if (pet == null) - return; - - if (!pet.isAlive()) - return; - - //if (pet.state == STATE.Disabled) - // return; - - int type = msg.getType(); - - if (type == 1) { //stop attack - pet.setCombatTarget(null); - pc.setCombat(false); - - } else if (type == 2) { //dismiss - pet.dismiss(); - pc.dismissPet(); - - if (pet.isAlive()) - WorldGrid.updateObject(pet); - } else if (type == 3) //toggle assist - pet.toggleAssist(); - else if (type == 5) { //rest - boolean sit = (!(pet.isSit())); - pet.setSit(sit); - - // cancel effects that break on sit - if (pet.isSit()) - pet.cancelOnSit(); - - UpdateStateMsg rwss = new UpdateStateMsg(); - rwss.setPlayer(pet); - DispatchMessage.sendToAllInRange(pet, rwss); - } - } - //Handle RepairObject Window and RepairObject Requests @Override @@ -373,9 +326,6 @@ public class ClientMessagePump implements NetMsgHandler { case ARCPETATTACK: petAttack((PetAttackMsg) msg, origin); break; - case ARCPETCMD: - petCmd((PetCmdMsg) msg, origin); - break; case CHANNELMUTE: break; case KEEPALIVESERVERCLIENT: diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index a7fb326e..e6031cc5 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -38,7 +38,7 @@ public enum Protocol { ARCMINEWINDOWCHANGE(0x92B2148A, ArcMineWindowChangeMsg.class, MineWindowChangeHandler.class), ARCOWNEDMINESLIST(0x59184455, ArcOwnedMinesListMsg.class, ArcOwnedMinesListHandler.class), ARCPETATTACK(0x18CD61AD, PetAttackMsg.class, null), // Pet Attack - ARCPETCMD(0x4E80E001, PetCmdMsg.class, null), // Stop ArcPetAttack, Toggle Assist, Toggle Rest + ARCPETCMD(0x4E80E001, PetCmdMsg.class, PetCmdMsgHandler.class), // Stop ArcPetAttack, Toggle Assist, Toggle Rest ARCPOWERPROJECTILE(0xA2312D3B, null, null), ARCPROMPTRECALL(0xE3196B6E, PromptRecallMsg.class, PromptRecallMsgHandler.class), //Recall Prompt ARCREQUESTTRADEBUSY(0xD4BAB4DF, InvalidTradeRequestMsg.class, null), // Attempt trade with someone who is already trading diff --git a/src/engine/net/client/handlers/PetCmdMsgHandler.java b/src/engine/net/client/handlers/PetCmdMsgHandler.java new file mode 100644 index 00000000..3dcf8e42 --- /dev/null +++ b/src/engine/net/client/handlers/PetCmdMsgHandler.java @@ -0,0 +1,84 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + +package engine.net.client.handlers; + +import engine.InterestManagement.WorldGrid; +import engine.exception.MsgSendException; +import engine.net.DispatchMessage; +import engine.net.client.ClientConnection; +import engine.net.client.msg.ClientNetMsg; +import engine.net.client.msg.PetCmdMsg; +import engine.net.client.msg.UpdateStateMsg; +import engine.objects.Mob; +import engine.objects.PlayerCharacter; + +public class PetCmdMsgHandler extends AbstractClientMsgHandler { + + public PetCmdMsgHandler() { + super(PetCmdMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter playerCharacter = origin.getPlayerCharacter(); + + // Member variable declaration + + PetCmdMsg msg; + + // Member variable assignment + + msg = (PetCmdMsg) baseMsg; + + if (playerCharacter == null) + return true; + + Mob pet = playerCharacter.getPet(); + + if (pet == null) + return true; + + if (!pet.isAlive()) + return true; + + //if (pet.state == STATE.Disabled) + // return; + + int type = msg.getType(); + + if (type == 1) { //stop attack + pet.setCombatTarget(null); + playerCharacter.setCombat(false); + + } else if (type == 2) { //dismiss + pet.dismiss(); + playerCharacter.dismissPet(); + + if (pet.isAlive()) + WorldGrid.updateObject(pet); + } else if (type == 3) //toggle assist + pet.toggleAssist(); + else if (type == 5) { //rest + boolean sit = (!(pet.isSit())); + pet.setSit(sit); + + // cancel effects that break on sit + if (pet.isSit()) + pet.cancelOnSit(); + + UpdateStateMsg rwss = new UpdateStateMsg(); + rwss.setPlayer(pet); + DispatchMessage.sendToAllInRange(pet, rwss); + } + + return true; + } + +} \ No newline at end of file From a162377685444ba07a5da4a70fd765f8e9b43c5e Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 06:23:29 -0400 Subject: [PATCH 11/45] Handler created for ModifyStatMsg --- src/engine/net/client/ClientMessagePump.java | 31 ---------- src/engine/net/client/Protocol.java | 2 +- .../client/handlers/ModifyStatMsgHandler.java | 60 +++++++++++++++++++ 3 files changed, 61 insertions(+), 32 deletions(-) create mode 100644 src/engine/net/client/handlers/ModifyStatMsgHandler.java diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 894270b6..5afb516d 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -54,34 +54,6 @@ public class ClientMessagePump implements NetMsgHandler { Logger.error(msg.toString()); } - private static void modifyStat(ModifyStatMsg msg, ClientConnection origin) { - - PlayerCharacter pc = SessionManager.getPlayerCharacter(origin); - - if (pc == null) - return; - - int type = msg.getType(); - - switch (type) { - case MBServerStatics.STAT_STR_ID: - pc.addStr(msg.getAmount()); - break; - case MBServerStatics.STAT_DEX_ID: - pc.addDex(msg.getAmount()); - break; - case MBServerStatics.STAT_CON_ID: - pc.addCon(msg.getAmount()); - break; - case MBServerStatics.STAT_INT_ID: - pc.addInt(msg.getAmount()); - break; - case MBServerStatics.STAT_SPI_ID: - pc.addSpi(msg.getAmount()); - break; - } - } - // called when player clicks respawn button private static void respawn(RespawnMsg msg, ClientConnection origin) throws MsgSendException { @@ -263,9 +235,6 @@ public class ClientMessagePump implements NetMsgHandler { break; case OPENVAULT: break; - case RAISEATTR: - modifyStat((ModifyStatMsg) msg, origin); - break; case COSTTOOPENBANK: ackBankWindowOpened((AckBankWindowOpenedMsg) msg, origin); break; diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index e6031cc5..c0a7d50f 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -162,7 +162,7 @@ public enum Protocol { POWERACTIONDD(0xD43052F8, ModifyHealthMsg.class, null), //Modify Health/Mana/Stamina using power POWERACTIONDDDIE(0xC27D446B, null, null), //Modify Health/Mana/Stamina using power and kill target POWERTARGNAME(0x5A807CCE, SendSummonsRequestMsg.class, null), // Send Summons Request - RAISEATTR(0x5EEB65E0, ModifyStatMsg.class, null), // Modify Stat + RAISEATTR(0x5EEB65E0, ModifyStatMsg.class, ModifyStatMsgHandler.class), // Modify Stat RANDOM(0xAC5D0135, RandomMsg.class, RandomMsgHandler.class), //RequestSend random roll READYTOENTER(0x490E4FE0, EnterWorldReceivedMsg.class, null), //Client Ack Receive Enter World REALMDATA(0x2399B775, null, null), //Realm Data - Optional(?) diff --git a/src/engine/net/client/handlers/ModifyStatMsgHandler.java b/src/engine/net/client/handlers/ModifyStatMsgHandler.java new file mode 100644 index 00000000..00e82a79 --- /dev/null +++ b/src/engine/net/client/handlers/ModifyStatMsgHandler.java @@ -0,0 +1,60 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// 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.ModifyStatMsg; +import engine.objects.PlayerCharacter; +import engine.server.MBServerStatics; + +public class ModifyStatMsgHandler extends AbstractClientMsgHandler { + + public ModifyStatMsgHandler() { + super(ModifyStatMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter playerCharacter = origin.getPlayerCharacter(); + + // Member variable declaration + + ModifyStatMsg msg; + + // Member variable assignment + + msg = (ModifyStatMsg) baseMsg; + + int type = msg.getType(); + + switch (type) { + case MBServerStatics.STAT_STR_ID: + playerCharacter.addStr(msg.getAmount()); + break; + case MBServerStatics.STAT_DEX_ID: + playerCharacter.addDex(msg.getAmount()); + break; + case MBServerStatics.STAT_CON_ID: + playerCharacter.addCon(msg.getAmount()); + break; + case MBServerStatics.STAT_INT_ID: + playerCharacter.addInt(msg.getAmount()); + break; + case MBServerStatics.STAT_SPI_ID: + playerCharacter.addSpi(msg.getAmount()); + break; + } + + return true; + } + +} \ No newline at end of file From 35ba4bbeecee859bfb9116017ed3af1284e748fc Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 06:26:59 -0400 Subject: [PATCH 12/45] CosttoOpenBankMsg has no handler --- src/engine/net/client/ClientMessagePump.java | 9 --------- src/engine/net/client/Protocol.java | 2 +- .../net/client/handlers/VendorDialogMsgHandler.java | 4 ++-- ...{AckBankWindowOpenedMsg.java => CostOpenBankMsg.java} | 6 +++--- 4 files changed, 6 insertions(+), 15 deletions(-) rename src/engine/net/client/msg/{AckBankWindowOpenedMsg.java => CostOpenBankMsg.java} (92%) diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 5afb516d..ef042a6a 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -48,12 +48,6 @@ public class ClientMessagePump implements NetMsgHandler { this.server = server; } - 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. - Logger.error(msg.toString()); - } - // called when player clicks respawn button private static void respawn(RespawnMsg msg, ClientConnection origin) throws MsgSendException { @@ -235,9 +229,6 @@ public class ClientMessagePump implements NetMsgHandler { break; case OPENVAULT: break; - case COSTTOOPENBANK: - ackBankWindowOpened((AckBankWindowOpenedMsg) msg, origin); - break; case RESETAFTERDEATH: respawn((RespawnMsg) msg, origin); break; diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index c0a7d50f..d503dd3f 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -81,7 +81,7 @@ public enum Protocol { CLIENTUPDATEVAULT(0x66EDBECD, UpdateVaultMsg.class, null), COMBATMODE(0xFE4BF353, ToggleCombatMsg.class, ToggleCombatMsgHandler.class), //Toggle Combat mode CONFIRMPROMOTE(0x153BB5F9, ConfirmPromoteMsg.class, null), - COSTTOOPENBANK(0x135BE5E8, AckBankWindowOpenedMsg.class, null), // ACK Bank Window Opened + COSTTOOPENBANK(0x135BE5E8, CostOpenBankMsg.class, null), // ACK Bank Window Opened CREATECHAR(0x5D18B5C8, CommitNewCharacterMsg.class, null), // Commit New Character, CREATEPETITION(0xD489CFED, GuildCreationFinalizeMsg.class, GuildCreationFinalizeHandler.class), //Confirm guild creation CUSTOMERPETITION(0x7F9D7D6D, PetitionReceivedMsg.class, PetitionReceivedMsgHandler.class), diff --git a/src/engine/net/client/handlers/VendorDialogMsgHandler.java b/src/engine/net/client/handlers/VendorDialogMsgHandler.java index a4a707c6..3cda342f 100644 --- a/src/engine/net/client/handlers/VendorDialogMsgHandler.java +++ b/src/engine/net/client/handlers/VendorDialogMsgHandler.java @@ -510,9 +510,9 @@ public class VendorDialogMsgHandler extends AbstractClientMsgHandler { // TODO When do we setBankOpen(false)? I don't think the client sends a // "CloseBank" message. - AckBankWindowOpenedMsg ackBankWindowOpenedMsg = new AckBankWindowOpenedMsg(playerCharacter, 0L, 0L); + CostOpenBankMsg costOpenBankMsg = new CostOpenBankMsg(playerCharacter, 0L, 0L); - Dispatch dispatch = Dispatch.borrow(playerCharacter, ackBankWindowOpenedMsg); + Dispatch dispatch = Dispatch.borrow(playerCharacter, costOpenBankMsg); DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); ReqBankInventoryMsg reqBankInventoryMsg = new ReqBankInventoryMsg(playerCharacter, 0L); diff --git a/src/engine/net/client/msg/AckBankWindowOpenedMsg.java b/src/engine/net/client/msg/CostOpenBankMsg.java similarity index 92% rename from src/engine/net/client/msg/AckBankWindowOpenedMsg.java rename to src/engine/net/client/msg/CostOpenBankMsg.java index c3a98d35..e854f7dc 100644 --- a/src/engine/net/client/msg/AckBankWindowOpenedMsg.java +++ b/src/engine/net/client/msg/CostOpenBankMsg.java @@ -22,7 +22,7 @@ import engine.objects.PlayerCharacter; * * @author Burfo */ -public class AckBankWindowOpenedMsg extends ClientNetMsg { +public class CostOpenBankMsg extends ClientNetMsg { private int playerType; private int playerID; @@ -32,7 +32,7 @@ public class AckBankWindowOpenedMsg extends ClientNetMsg { /** * This is the general purpose constructor. */ - public AckBankWindowOpenedMsg(PlayerCharacter pc, long unknown01, long unknown02) { + public CostOpenBankMsg(PlayerCharacter pc, long unknown01, long unknown02) { super(Protocol.COSTTOOPENBANK); this.playerType = pc.getObjectType().ordinal(); this.playerID = pc.getObjectUUID(); @@ -46,7 +46,7 @@ public class AckBankWindowOpenedMsg extends ClientNetMsg { * past the limit) then this constructor Throws that Exception to the * caller. */ - public AckBankWindowOpenedMsg(AbstractConnection origin, ByteBufferReader reader) { + public CostOpenBankMsg(AbstractConnection origin, ByteBufferReader reader) { super(Protocol.COSTTOOPENBANK, origin, reader); } From 1acb74ade1578bed0863944965d3e3ebab266dcb Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 06:30:07 -0400 Subject: [PATCH 13/45] Handler created for RespawnMsg --- src/engine/net/client/ClientMessagePump.java | 58 ----------- src/engine/net/client/Protocol.java | 2 +- .../client/handlers/RespawnMsgHandler.java | 95 +++++++++++++++++++ 3 files changed, 96 insertions(+), 59 deletions(-) create mode 100644 src/engine/net/client/handlers/RespawnMsgHandler.java diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index ef042a6a..865fc9b6 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -13,8 +13,6 @@ import engine.Enum.DispatchChannel; import engine.Enum.GameObjectType; import engine.exception.MsgSendException; import engine.gameManager.*; -import engine.job.JobScheduler; -import engine.jobs.RefreshGroupJob; import engine.net.Dispatch; import engine.net.DispatchMessage; import engine.net.NetMsgHandler; @@ -25,7 +23,6 @@ import engine.objects.AbstractCharacter; import engine.objects.Mob; import engine.objects.NPC; import engine.objects.PlayerCharacter; -import engine.server.MBServerStatics; import engine.server.world.WorldServer; import engine.session.Session; import engine.util.StringUtils; @@ -48,58 +45,6 @@ public class ClientMessagePump implements NetMsgHandler { this.server = server; } - // called when player clicks respawn button - private static void respawn(RespawnMsg msg, ClientConnection origin) throws MsgSendException { - - PlayerCharacter sourcePlayer = SessionManager.getPlayerCharacter(origin); - - if (sourcePlayer == null) - return; - - if (msg.getObjectType() != sourcePlayer.getObjectType().ordinal() || msg.getObjectID() != sourcePlayer.getObjectUUID()) { - Logger.error("Player " + sourcePlayer.getObjectUUID() + " respawning character of id " + msg.getObjectType() + ' ' - + msg.getObjectID()); - return; - } - - if (sourcePlayer.isAlive()) { - Logger.error("Player " + sourcePlayer.getObjectUUID() + " respawning while alive"); - return; - } - // ResetAfterDeath player - sourcePlayer.respawnLock.writeLock().lock(); - try { - sourcePlayer.respawn(true, false, true); - - } catch (Exception e) { - Logger.error(e); - } finally { - sourcePlayer.respawnLock.writeLock().unlock(); - - } - // Echo ResetAfterDeath message back - msg.setPlayerHealth(sourcePlayer.getHealth()); - // TODO calculate any experience loss before this point - msg.setPlayerExp(sourcePlayer.getExp() + sourcePlayer.getOverFlowEXP()); - Dispatch dispatch = Dispatch.borrow(sourcePlayer, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); - - MoveToPointMsg moveMsg = new MoveToPointMsg(); - moveMsg.setPlayer(sourcePlayer); - moveMsg.setStartCoord(sourcePlayer.getLoc()); - moveMsg.setEndCoord(sourcePlayer.getLoc()); - moveMsg.setInBuilding(-1); - moveMsg.setInBuildingFloor(-1); - - dispatch = Dispatch.borrow(sourcePlayer, moveMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); - - MovementManager.sendRWSSMsg(sourcePlayer); - - // refresh the whole group with what just happened - JobScheduler.getInstance().scheduleJob(new RefreshGroupJob(sourcePlayer), MBServerStatics.LOAD_OBJECT_DELAY); - } - // called when player types /show private static void show(ShowMsg msg, ClientConnection origin) throws MsgSendException { @@ -229,9 +174,6 @@ public class ClientMessagePump implements NetMsgHandler { break; case OPENVAULT: break; - case RESETAFTERDEATH: - respawn((RespawnMsg) msg, origin); - break; case SHOWCOMBATINFO: show((ShowMsg) msg, origin); break; diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index d503dd3f..1043093e 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -180,7 +180,7 @@ public enum Protocol { REQUESTTOTRADE(0x4D84259B, TradeRequestMsg.class, null), // Trade Request REQUESTTRADECANCEL(0xCB0C5735, RejectTradeRequestMsg.class, null), // Reject RequestToTrade REQUESTTRADEOK(0xFFD29841, AcceptTradeRequestMsg.class, null), // Accept Trade Request - RESETAFTERDEATH(0xFDCBB98F, RespawnMsg.class, null), //Respawn Request/Response + RESETAFTERDEATH(0xFDCBB98F, RespawnMsg.class, RespawnMsgHandler.class), //Respawn Request/Response ROTATEMSG(0x57F2088E, RotateObjectMsg.class, null), SAFEMODE(0x9CF3922A, SafeModeMsg.class, null), //Tell client they're in safe mode SCALEOBJECT(0xE2B392D9, null, null), // Adjust scale of object diff --git a/src/engine/net/client/handlers/RespawnMsgHandler.java b/src/engine/net/client/handlers/RespawnMsgHandler.java new file mode 100644 index 00000000..6708aab1 --- /dev/null +++ b/src/engine/net/client/handlers/RespawnMsgHandler.java @@ -0,0 +1,95 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + +package engine.net.client.handlers; + +import engine.Enum.DispatchChannel; +import engine.exception.MsgSendException; +import engine.gameManager.MovementManager; +import engine.job.JobScheduler; +import engine.jobs.RefreshGroupJob; +import engine.net.Dispatch; +import engine.net.DispatchMessage; +import engine.net.client.ClientConnection; +import engine.net.client.msg.ClientNetMsg; +import engine.net.client.msg.MoveToPointMsg; +import engine.net.client.msg.RespawnMsg; +import engine.objects.PlayerCharacter; +import engine.server.MBServerStatics; +import org.pmw.tinylog.Logger; + +public class RespawnMsgHandler extends AbstractClientMsgHandler { + + public RespawnMsgHandler() { + super(RespawnMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter playerCharacter = origin.getPlayerCharacter(); + + // Member variable declaration + + RespawnMsg msg; + + // Member variable assignment + + msg = (RespawnMsg) baseMsg; + + if (playerCharacter == null) + return true; + + if (msg.getObjectType() != playerCharacter.getObjectType().ordinal() || msg.getObjectID() != playerCharacter.getObjectUUID()) { + Logger.error("Player " + playerCharacter.getObjectUUID() + " respawning character of id " + msg.getObjectType() + ' ' + + msg.getObjectID()); + return true; + } + + if (playerCharacter.isAlive()) { + Logger.error("Player " + playerCharacter.getObjectUUID() + " respawning while alive"); + return true; + } + + // ResetAfterDeath player + playerCharacter.respawnLock.writeLock().lock(); + try { + playerCharacter.respawn(true, false, true); + + } catch (Exception e) { + Logger.error(e); + } finally { + playerCharacter.respawnLock.writeLock().unlock(); + + } + // Echo ResetAfterDeath message back + msg.setPlayerHealth(playerCharacter.getHealth()); + // TODO calculate any experience loss before this point + msg.setPlayerExp(playerCharacter.getExp() + playerCharacter.getOverFlowEXP()); + Dispatch dispatch = Dispatch.borrow(playerCharacter, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); + + MoveToPointMsg moveMsg = new MoveToPointMsg(); + moveMsg.setPlayer(playerCharacter); + moveMsg.setStartCoord(playerCharacter.getLoc()); + moveMsg.setEndCoord(playerCharacter.getLoc()); + moveMsg.setInBuilding(-1); + moveMsg.setInBuildingFloor(-1); + + dispatch = Dispatch.borrow(playerCharacter, moveMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); + + MovementManager.sendRWSSMsg(playerCharacter); + + // refresh the whole group with what just happened + JobScheduler.getInstance().scheduleJob(new RefreshGroupJob(playerCharacter), MBServerStatics.LOAD_OBJECT_DELAY); + + return true; + } + +} \ No newline at end of file From 41f77364aa0d25076d0048f31409c0f8ad7efcb2 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 06:35:17 -0400 Subject: [PATCH 14/45] Cleanup of handler super calls --- src/engine/net/client/handlers/CityDataHandler.java | 7 +++++-- .../net/client/handlers/PerformActionMsgHandler.java | 3 +-- src/engine/net/client/handlers/UseCharterMsgHandler.java | 3 +-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/engine/net/client/handlers/CityDataHandler.java b/src/engine/net/client/handlers/CityDataHandler.java index 98ca60fb..e35ab28b 100644 --- a/src/engine/net/client/handlers/CityDataHandler.java +++ b/src/engine/net/client/handlers/CityDataHandler.java @@ -8,7 +8,10 @@ import engine.gameManager.ZoneManager; import engine.net.Dispatch; import engine.net.DispatchMessage; import engine.net.client.ClientConnection; -import engine.net.client.msg.*; +import engine.net.client.msg.CityDataMsg; +import engine.net.client.msg.ClientNetMsg; +import engine.net.client.msg.HotzoneChangeMsg; +import engine.net.client.msg.WorldRealmMsg; import engine.objects.City; import engine.objects.PlayerCharacter; import engine.session.Session; @@ -22,7 +25,7 @@ import engine.session.Session; public class CityDataHandler extends AbstractClientMsgHandler { public CityDataHandler() { - super(KeepAliveServerClientMsg.class); + super(CityDataMsg.class); } @Override diff --git a/src/engine/net/client/handlers/PerformActionMsgHandler.java b/src/engine/net/client/handlers/PerformActionMsgHandler.java index a8a4033e..f879960a 100644 --- a/src/engine/net/client/handlers/PerformActionMsgHandler.java +++ b/src/engine/net/client/handlers/PerformActionMsgHandler.java @@ -12,13 +12,12 @@ import engine.exception.MsgSendException; import engine.gameManager.PowersManager; import engine.net.client.ClientConnection; import engine.net.client.msg.ClientNetMsg; -import engine.net.client.msg.KeepAliveServerClientMsg; import engine.net.client.msg.PerformActionMsg; public class PerformActionMsgHandler extends AbstractClientMsgHandler { public PerformActionMsgHandler() { - super(KeepAliveServerClientMsg.class); + super(PerformActionMsg.class); } @Override diff --git a/src/engine/net/client/handlers/UseCharterMsgHandler.java b/src/engine/net/client/handlers/UseCharterMsgHandler.java index f61ea384..f7588a23 100644 --- a/src/engine/net/client/handlers/UseCharterMsgHandler.java +++ b/src/engine/net/client/handlers/UseCharterMsgHandler.java @@ -14,13 +14,12 @@ import engine.net.Dispatch; import engine.net.DispatchMessage; import engine.net.client.ClientConnection; import engine.net.client.msg.ClientNetMsg; -import engine.net.client.msg.KeepAliveServerClientMsg; import engine.net.client.msg.UseCharterMsg; public class UseCharterMsgHandler extends AbstractClientMsgHandler { public UseCharterMsgHandler() { - super(KeepAliveServerClientMsg.class); + super(UseCharterMsg.class); } @Override From 01fd6997a8275b347fcc09a5793ff8db1bb16a7e Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 06:40:06 -0400 Subject: [PATCH 15/45] Handler created for ShowMsg --- src/engine/net/client/ClientMessagePump.java | 41 ----------- src/engine/net/client/Protocol.java | 2 +- .../net/client/handlers/ShowMsgHandler.java | 72 +++++++++++++++++++ 3 files changed, 73 insertions(+), 42 deletions(-) create mode 100644 src/engine/net/client/handlers/ShowMsgHandler.java diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 865fc9b6..9c02f18f 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -9,19 +9,14 @@ package engine.net.client; -import engine.Enum.DispatchChannel; import engine.Enum.GameObjectType; import engine.exception.MsgSendException; import engine.gameManager.*; -import engine.net.Dispatch; -import engine.net.DispatchMessage; import engine.net.NetMsgHandler; import engine.net.client.handlers.AbstractClientMsgHandler; import engine.net.client.msg.*; import engine.net.client.msg.chat.AbstractChatMsg; -import engine.objects.AbstractCharacter; import engine.objects.Mob; -import engine.objects.NPC; import engine.objects.PlayerCharacter; import engine.server.world.WorldServer; import engine.session.Session; @@ -45,39 +40,6 @@ public class ClientMessagePump implements NetMsgHandler { this.server = server; } - // called when player types /show - private static void show(ShowMsg msg, ClientConnection origin) throws MsgSendException { - - PlayerCharacter pc = SessionManager.getPlayerCharacter(origin); - - if (pc == null) - return; - - int targetType = msg.getTargetType(); - AbstractCharacter tar = null; - - if (targetType == GameObjectType.PlayerCharacter.ordinal()) - tar = PlayerCharacter.getFromCache(msg.getTargetID()); - else if (targetType == GameObjectType.NPC.ordinal()) - tar = NPC.getFromCache(msg.getTargetID()); - else if (targetType == GameObjectType.Mob.ordinal()) - tar = Mob.getFromCache(msg.getTargetID()); - - if (tar == null || !tar.isAlive() || !tar.isActive()) - return; - - msg.setUnknown01(pc.getLoc()); - msg.setUnknown02(pc.getLoc()); - msg.setRange01(pc.getRange()); - msg.setUnknown03(tar.getLoc()); - msg.setUnknown04(tar.getLoc()); - msg.setRange01(tar.getRange()); - - Dispatch dispatch = Dispatch.borrow(pc, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - - } - protected static void petAttack(PetAttackMsg msg, ClientConnection conn) throws MsgSendException { PlayerCharacter pc = SessionManager.getPlayerCharacter(conn); @@ -174,9 +136,6 @@ public class ClientMessagePump implements NetMsgHandler { break; case OPENVAULT: break; - case SHOWCOMBATINFO: - show((ShowMsg) msg, origin); - break; case REQUESTTOTRADE: TradeManager.tradeRequest((TradeRequestMsg) msg, origin); break; diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index 1043093e..059dfd4c 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -196,7 +196,7 @@ public enum Protocol { SETOBJVAL(0x08A50FD1, null, null), SETRUNE(0x888E7C64, ApplyRuneMsg.class, null), //Apply Promotion, Stat Rune (maybe disc also) TARGETOBJECT(0x64E10938, TargetObjectMsg.class, TargetObjectMsgHandler.class), // Target an object - SHOWCOMBATINFO(0x9BF1E5EA, ShowMsg.class, null), // Request/Response /show + SHOWCOMBATINFO(0x9BF1E5EA, ShowMsg.class, ShowMsgHandler.class), // Request/Response /show SHOWVAULTINVENTORY(0xD1FB4842, null, null), // Show Vault Inventory SOCIALCHANNEL(0x2BF58FA6, SocialMsg.class, SocialMsgHandler.class), // Socials STANDARDALERT(0xFA0A24BB, ErrorPopupMsg.class, null), //Popup messages diff --git a/src/engine/net/client/handlers/ShowMsgHandler.java b/src/engine/net/client/handlers/ShowMsgHandler.java new file mode 100644 index 00000000..97b221bc --- /dev/null +++ b/src/engine/net/client/handlers/ShowMsgHandler.java @@ -0,0 +1,72 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + +package engine.net.client.handlers; + +import engine.Enum; +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.ShowMsg; +import engine.objects.AbstractCharacter; +import engine.objects.Mob; +import engine.objects.NPC; +import engine.objects.PlayerCharacter; + +public class ShowMsgHandler extends AbstractClientMsgHandler { + + public ShowMsgHandler() { + super(ShowMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter playerCharacter = origin.getPlayerCharacter(); + + // Member variable declaration + + ShowMsg msg; + + // Member variable assignment + + msg = (ShowMsg) baseMsg; + + if (playerCharacter == null) + return true; + + int targetType = msg.getTargetType(); + AbstractCharacter tar = null; + + if (targetType == Enum.GameObjectType.PlayerCharacter.ordinal()) + tar = PlayerCharacter.getFromCache(msg.getTargetID()); + else if (targetType == Enum.GameObjectType.NPC.ordinal()) + tar = NPC.getFromCache(msg.getTargetID()); + else if (targetType == Enum.GameObjectType.Mob.ordinal()) + tar = Mob.getFromCache(msg.getTargetID()); + + if (tar == null || !tar.isAlive() || !tar.isActive()) + return true; + + msg.setUnknown01(playerCharacter.getLoc()); + msg.setUnknown02(playerCharacter.getLoc()); + msg.setRange01(playerCharacter.getRange()); + msg.setUnknown03(tar.getLoc()); + msg.setUnknown04(tar.getLoc()); + msg.setRange01(tar.getRange()); + + Dispatch dispatch = Dispatch.borrow(playerCharacter, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + + return true; + } + +} \ No newline at end of file From 56bc38ab734b60e0daedbd0e4937fd6403d2d008 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 06:45:26 -0400 Subject: [PATCH 16/45] Handler created for PetAttackMsg --- src/engine/net/client/ClientMessagePump.java | 46 ------------ src/engine/net/client/Protocol.java | 2 +- .../client/handlers/PetAttackMsgHandler.java | 75 +++++++++++++++++++ 3 files changed, 76 insertions(+), 47 deletions(-) create mode 100644 src/engine/net/client/handlers/PetAttackMsgHandler.java diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 9c02f18f..081b7851 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -9,15 +9,11 @@ package engine.net.client; -import engine.Enum.GameObjectType; -import engine.exception.MsgSendException; import engine.gameManager.*; import engine.net.NetMsgHandler; import engine.net.client.handlers.AbstractClientMsgHandler; import engine.net.client.msg.*; import engine.net.client.msg.chat.AbstractChatMsg; -import engine.objects.Mob; -import engine.objects.PlayerCharacter; import engine.server.world.WorldServer; import engine.session.Session; import engine.util.StringUtils; @@ -40,45 +36,6 @@ public class ClientMessagePump implements NetMsgHandler { this.server = server; } - protected static void petAttack(PetAttackMsg msg, ClientConnection conn) throws MsgSendException { - - PlayerCharacter pc = SessionManager.getPlayerCharacter(conn); - - if (pc == null) - return; - - Mob pet = pc.getPet(); - - if (pet == null) - return; - - if (!pet.isAlive()) - return; - - if ((pc.inSafeZone()) - && (msg.getTargetType() == GameObjectType.PlayerCharacter.ordinal())) - return; - - //CombatManager.setAttackTarget(msg, conn); - if (msg.getTargetType() == GameObjectType.Building.ordinal()) { - conn.getPlayerCharacter().getPet().setCombatTarget(PlayerCharacter.getPlayerCharacter(msg.getTargetID())); - } - switch (msg.getTargetType()) { - case 53: //player character - conn.getPlayerCharacter().getPet().setCombatTarget(PlayerCharacter.getPlayerCharacter(msg.getTargetID())); - break; - case 37://mob - conn.getPlayerCharacter().getPet().setCombatTarget(Mob.getMob(msg.getTargetID())); - break; - case 8://mob - conn.getPlayerCharacter().getPet().setCombatTarget(BuildingManager.getBuilding(msg.getTargetID())); - break; - } - - if (pet.getCombatTarget() == null) - return; - } - //Handle RepairObject Window and RepairObject Requests @Override @@ -184,9 +141,6 @@ public class ClientMessagePump implements NetMsgHandler { case STUCK: MovementManager.stuck(origin); break; - case ARCPETATTACK: - petAttack((PetAttackMsg) msg, origin); - break; case CHANNELMUTE: break; case KEEPALIVESERVERCLIENT: diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index 059dfd4c..429a8ece 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -37,7 +37,7 @@ public enum Protocol { ARCMINEWINDOWAVAILABLETIME(0x6C909DE7, ArcMineWindowAvailableTimeMsg.class, ArcMineWindowAvailableTimeHandler.class), ARCMINEWINDOWCHANGE(0x92B2148A, ArcMineWindowChangeMsg.class, MineWindowChangeHandler.class), ARCOWNEDMINESLIST(0x59184455, ArcOwnedMinesListMsg.class, ArcOwnedMinesListHandler.class), - ARCPETATTACK(0x18CD61AD, PetAttackMsg.class, null), // Pet Attack + ARCPETATTACK(0x18CD61AD, PetAttackMsg.class, PetAttackMsgHandler.class), // Pet Attack ARCPETCMD(0x4E80E001, PetCmdMsg.class, PetCmdMsgHandler.class), // Stop ArcPetAttack, Toggle Assist, Toggle Rest ARCPOWERPROJECTILE(0xA2312D3B, null, null), ARCPROMPTRECALL(0xE3196B6E, PromptRecallMsg.class, PromptRecallMsgHandler.class), //Recall Prompt diff --git a/src/engine/net/client/handlers/PetAttackMsgHandler.java b/src/engine/net/client/handlers/PetAttackMsgHandler.java new file mode 100644 index 00000000..04253fee --- /dev/null +++ b/src/engine/net/client/handlers/PetAttackMsgHandler.java @@ -0,0 +1,75 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + +package engine.net.client.handlers; + +import engine.Enum; +import engine.exception.MsgSendException; +import engine.gameManager.BuildingManager; +import engine.net.client.ClientConnection; +import engine.net.client.msg.ClientNetMsg; +import engine.net.client.msg.PetAttackMsg; +import engine.objects.Mob; +import engine.objects.PlayerCharacter; + +public class PetAttackMsgHandler extends AbstractClientMsgHandler { + + public PetAttackMsgHandler() { + super(PetAttackMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter playerCharacter = origin.getPlayerCharacter(); + + // Member variable declaration + + PetAttackMsg msg; + + // Member variable assignment + + msg = (PetAttackMsg) baseMsg; + + if (playerCharacter == null) + return true; + + Mob pet = playerCharacter.getPet(); + + if (pet == null) + return true; + + if (!pet.isAlive()) + return true; + + if (pet.getCombatTarget() == null) + return true; + + if ((playerCharacter.inSafeZone()) + && (msg.getTargetType() == Enum.GameObjectType.PlayerCharacter.ordinal())) + return true; + + if (msg.getTargetType() == Enum.GameObjectType.Building.ordinal()) + pet.setCombatTarget(PlayerCharacter.getPlayerCharacter(msg.getTargetID())); + + switch (msg.getTargetType()) { + case 53: //player character + pet.setCombatTarget(PlayerCharacter.getPlayerCharacter(msg.getTargetID())); + break; + case 37://mob + pet.setCombatTarget(Mob.getMob(msg.getTargetID())); + break; + case 8://mob + pet.setCombatTarget(BuildingManager.getBuilding(msg.getTargetID())); + break; + } + + return true; + } + +} \ No newline at end of file From 5a5fd8155c08669614178a1e50668072e3def36b Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 06:52:11 -0400 Subject: [PATCH 17/45] Handler created for StuckMsg --- src/engine/gameManager/MovementManager.java | 26 -------- src/engine/net/client/ClientMessagePump.java | 8 +-- src/engine/net/client/Protocol.java | 2 +- .../net/client/handlers/StuckMsgHandler.java | 61 +++++++++++++++++++ .../{StuckCommandMsg.java => StuckMsg.java} | 6 +- 5 files changed, 69 insertions(+), 34 deletions(-) create mode 100644 src/engine/net/client/handlers/StuckMsgHandler.java rename src/engine/net/client/msg/{StuckCommandMsg.java => StuckMsg.java} (91%) diff --git a/src/engine/gameManager/MovementManager.java b/src/engine/gameManager/MovementManager.java index 644569b7..a5743a77 100644 --- a/src/engine/gameManager/MovementManager.java +++ b/src/engine/gameManager/MovementManager.java @@ -14,9 +14,6 @@ import engine.Enum.ModType; import engine.Enum.SourceType; import engine.InterestManagement.InterestManager; import engine.exception.MsgSendException; -import engine.job.JobContainer; -import engine.job.JobScheduler; -import engine.jobs.StuckJob; import engine.math.Bounds; import engine.math.Vector3f; import engine.math.Vector3fImmutable; @@ -30,7 +27,6 @@ import engine.server.MBServerStatics; import org.pmw.tinylog.Logger; import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; import static engine.math.FastMath.sqr; @@ -474,26 +470,4 @@ public enum MovementManager { ac.teleport(ac.getLoc()); } - public static void stuck(ClientConnection origin) { - - PlayerCharacter sourcePlayer = origin.getPlayerCharacter(); - - if (sourcePlayer == null) - return; - - if (sourcePlayer.getTimers().containsKey("Stuck")) - return; - - StuckJob sj = new StuckJob(sourcePlayer); - JobContainer jc = JobScheduler.getInstance().scheduleJob(sj, 10000); // Convert - ConcurrentHashMap timers = sourcePlayer.getTimers(); - - if (timers != null) { - if (timers.containsKey("Stuck")) { - timers.get("Stuck").cancelJob(); - timers.remove("Stuck"); - } - timers.put("Stuck", jc); - } - } } diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 081b7851..7fca0893 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -9,7 +9,10 @@ package engine.net.client; -import engine.gameManager.*; +import engine.gameManager.ChatManager; +import engine.gameManager.PowersManager; +import engine.gameManager.SessionManager; +import engine.gameManager.TradeManager; import engine.net.NetMsgHandler; import engine.net.client.handlers.AbstractClientMsgHandler; import engine.net.client.msg.*; @@ -138,9 +141,6 @@ public class ClientMessagePump implements NetMsgHandler { case ARCTRACKINGLIST: PowersManager.trackWindow((TrackWindowMsg) msg, origin); break; - case STUCK: - MovementManager.stuck(origin); - break; case CHANNELMUTE: break; case KEEPALIVESERVERCLIENT: diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index 429a8ece..4109a450 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -200,7 +200,7 @@ public enum Protocol { SHOWVAULTINVENTORY(0xD1FB4842, null, null), // Show Vault Inventory SOCIALCHANNEL(0x2BF58FA6, SocialMsg.class, SocialMsgHandler.class), // Socials STANDARDALERT(0xFA0A24BB, ErrorPopupMsg.class, null), //Popup messages - STUCK(0x3D04AF3A, StuckCommandMsg.class, null), // /Stuck Command + STUCK(0x3D04AF3A, StuckMsg.class, StuckMsgHandler.class), // /Stuck Command SWEARINGUILD(0x389B66B1, SwearInGuildMsg.class, SwearInGuildHandler.class), SYNC(0x49ec109f, null, null), //Client/Server loc sync SYSTEMBROADCASTCHANNEL(0x2FAD89D1, ChatSystemMsg.class, null), // Chat Channel: System Message diff --git a/src/engine/net/client/handlers/StuckMsgHandler.java b/src/engine/net/client/handlers/StuckMsgHandler.java new file mode 100644 index 00000000..5558d542 --- /dev/null +++ b/src/engine/net/client/handlers/StuckMsgHandler.java @@ -0,0 +1,61 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + +package engine.net.client.handlers; + +import engine.exception.MsgSendException; +import engine.job.JobContainer; +import engine.job.JobScheduler; +import engine.jobs.StuckJob; +import engine.net.client.ClientConnection; +import engine.net.client.msg.ClientNetMsg; +import engine.net.client.msg.StuckMsg; +import engine.objects.PlayerCharacter; + +import java.util.concurrent.ConcurrentHashMap; + +public class StuckMsgHandler extends AbstractClientMsgHandler { + + public StuckMsgHandler() { + super(StuckMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter playerCharacter = origin.getPlayerCharacter(); + + // Member variable declaration + + StuckMsg msg; + + // Member variable assignment + + msg = (StuckMsg) baseMsg; + + if (playerCharacter == null) + return true; + + if (playerCharacter.getTimers().containsKey("Stuck")) + return true; + + StuckJob sj = new StuckJob(playerCharacter); + JobContainer jc = JobScheduler.getInstance().scheduleJob(sj, 10000); // Convert + ConcurrentHashMap timers = playerCharacter.getTimers(); + + if (timers != null) { + if (timers.containsKey("Stuck")) { + timers.get("Stuck").cancelJob(); + timers.remove("Stuck"); + } + timers.put("Stuck", jc); + } + return true; + } + +} \ No newline at end of file diff --git a/src/engine/net/client/msg/StuckCommandMsg.java b/src/engine/net/client/msg/StuckMsg.java similarity index 91% rename from src/engine/net/client/msg/StuckCommandMsg.java rename to src/engine/net/client/msg/StuckMsg.java index 2058633e..b598cb15 100644 --- a/src/engine/net/client/msg/StuckCommandMsg.java +++ b/src/engine/net/client/msg/StuckMsg.java @@ -16,12 +16,12 @@ import engine.net.ByteBufferWriter; import engine.net.client.Protocol; -public class StuckCommandMsg extends ClientNetMsg { +public class StuckMsg extends ClientNetMsg { /** * This is the general purpose constructor. */ - public StuckCommandMsg() { + public StuckMsg() { super(Protocol.STUCK); } @@ -31,7 +31,7 @@ public class StuckCommandMsg extends ClientNetMsg { * past the limit) then this constructor Throws that Exception to the * caller. */ - public StuckCommandMsg(AbstractConnection origin, ByteBufferReader reader) { + public StuckMsg(AbstractConnection origin, ByteBufferReader reader) { super(Protocol.STUCK, origin, reader); } From 1825035739ead38dac04033cdf484892814a0a2b Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 07:04:46 -0400 Subject: [PATCH 18/45] Handler created for RefineMsg --- src/engine/net/client/ClientMessagePump.java | 3 - src/engine/net/client/Protocol.java | 2 +- .../net/client/handlers/RefineMsgHandler.java | 157 ++++++++++++++++++ src/engine/net/client/msg/RefineMsg.java | 133 +-------------- 4 files changed, 164 insertions(+), 131 deletions(-) create mode 100644 src/engine/net/client/handlers/RefineMsgHandler.java diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 7fca0893..c814fe52 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -129,9 +129,6 @@ public class ClientMessagePump implements NetMsgHandler { case ARCUNTRAINLIST: WorldServer.refinerScreen((RefinerScreenMsg) msg, origin); break; - case ARCUNTRAINABILITY: - RefineMsg.refine((RefineMsg) msg, origin); - break; case POWERTARGNAME: PowersManager.summon((SendSummonsRequestMsg) msg, origin); break; diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index 4109a450..2aa3324d 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -47,7 +47,7 @@ public enum Protocol { ARCSUMMON(0xFD816A0A, RecvSummonsRequestMsg.class, null), // Suspect Recv Summons Request ARCTRACKINGLIST(0xC89CF08B, TrackWindowMsg.class, null), //Request/Send Track window ARCTRACKOBJECT(0x609B6BA2, TrackArrowMsg.class, null), //Send Track Arrow - ARCUNTRAINABILITY(0x548DBF83, RefineMsg.class, null), //Refine + ARCUNTRAINABILITY(0x548DBF83, RefineMsg.class, RefineMsgHandler.class), //Refine ARCUNTRAINLIST(0x38879E90, RefinerScreenMsg.class, null), //Refiner screen ARCVIEWASSETTRANSACTIONS(0xBFA476E4, ArcViewAssetTransactionsMsg.class, ArcViewAssetTransactionsMsgHandler.class), ASSETSUPPORT(0xc481f89D, AssetSupportMsg.class, AssetSupportMsgHandler.class), diff --git a/src/engine/net/client/handlers/RefineMsgHandler.java b/src/engine/net/client/handlers/RefineMsgHandler.java new file mode 100644 index 00000000..b53e90fe --- /dev/null +++ b/src/engine/net/client/handlers/RefineMsgHandler.java @@ -0,0 +1,157 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + +package engine.net.client.handlers; + +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.RefineMsg; +import engine.net.client.msg.RefinerScreenMsg; +import engine.objects.*; +import engine.server.MBServerStatics; + +import java.util.ArrayList; +import java.util.concurrent.ConcurrentHashMap; + +public class RefineMsgHandler extends AbstractClientMsgHandler { + + public RefineMsgHandler() { + super(RefineMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter playerCharacter = origin.getPlayerCharacter(); + + // Member variable declaration + + RefineMsg msg; + + // Member variable assignment + + msg = (RefineMsg) baseMsg; + + NPC npc = NPC.getFromCache(msg.npcID); + + if (npc == null) + return true; + + int type = msg.type; + int token = msg.token; + boolean worked = false; + boolean skillPower = true; + + if (type == 0) { //refine skill + worked = refineSkill(origin, playerCharacter, token, msg); + } else if (type == 1) { //refine power + worked = refinePower(origin, playerCharacter, token, msg); + } else if (type == 2) { //refine stat + worked = refineStat(origin, playerCharacter, token, msg); + skillPower = false; + } + + if (worked) { + + //update player + playerCharacter.applyBonuses(); + playerCharacter.charItemManager.RemoveEquipmentFromLackOfSkill(playerCharacter, true); + + //echo refine message back + + Dispatch dispatch = Dispatch.borrow(playerCharacter, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); + + // if (type == 0 && token == 1488335491){ + // dispatch = Dispatch.borrow(pc, msg); + // DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); + // } + + //resend refine screen + + RefinerScreenMsg refinerScreenMsg = new RefinerScreenMsg(skillPower, npc.getSellPercent(playerCharacter)); //TODO set npc cost + dispatch = Dispatch.borrow(playerCharacter, refinerScreenMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); + playerCharacter.recalculate(); + } + return true; + } + + public static boolean refineSkill(ClientConnection origin, PlayerCharacter pc, int token, RefineMsg msg) { + CharacterSkill skill = null; + ConcurrentHashMap skills = pc.getSkills(); + for (CharacterSkill sk : skills.values()) { + if (sk == null) + continue; + SkillsBase sb = sk.getSkillsBase(); + if (sb == null) + continue; + if (sb.getToken() == token) + skill = sk; + } + //check if player has skill to refine + if (skill == null) + return false; + //check there's a train to refine + if (skill.getNumTrains() < 1) + return false; + + //TODO verify if any skills have this as prereq + + //TODO verify if any powers have this as a prereq + //get all players powers + for (CharacterPower power : pc.getPowers().values()) { + ArrayList reqs = PowerReq.getPowerReqsForRune(power.getPowerID()); + for (PowerReq req : reqs) { + ConcurrentHashMap playerSkills = pc.getSkills(); + CharacterSkill playerSkill = playerSkills.get(token); + int currentSkillLevel = playerSkill.getTotalSkillPercet(); + if (token == req.getToken() && req.getLevel() == currentSkillLevel) { + return false; + } + } + } + + //refine skill + return skill.refine(pc); + } + + public static boolean refinePower(ClientConnection origin, PlayerCharacter pc, int token, RefineMsg msg) { + CharacterPower power = null; + ConcurrentHashMap powers = pc.getPowers(); + if (!powers.containsKey(token)) + return false; + power = powers.get(token); + if (power == null) + return false; + if (power.getTrains() < 1) + return false; + + //TODO verify if any powers have this as a prereq + + return power.refine(pc); + } + + public static boolean refineStat(ClientConnection origin, PlayerCharacter pc, int token, RefineMsg msg) { + if (token == MBServerStatics.STAT_STR_ID) + return pc.refineStr(); + if (token == MBServerStatics.STAT_DEX_ID) + return pc.refineDex(); + if (token == MBServerStatics.STAT_CON_ID) + return pc.refineCon(); + if (token == MBServerStatics.STAT_INT_ID) + return pc.refineInt(msg); + if (token == MBServerStatics.STAT_SPI_ID) + return pc.refineSpi(); + return false; + } + +} \ No newline at end of file diff --git a/src/engine/net/client/msg/RefineMsg.java b/src/engine/net/client/msg/RefineMsg.java index bf1e5791..1e6e6eba 100644 --- a/src/engine/net/client/msg/RefineMsg.java +++ b/src/engine/net/client/msg/RefineMsg.java @@ -10,23 +10,18 @@ package engine.net.client.msg; -import engine.gameManager.SessionManager; -import engine.net.*; -import engine.net.client.ClientConnection; +import engine.net.AbstractConnection; +import engine.net.ByteBufferReader; +import engine.net.ByteBufferWriter; import engine.net.client.Protocol; -import engine.objects.*; -import engine.server.MBServerStatics; - -import java.util.ArrayList; -import java.util.concurrent.ConcurrentHashMap; public class RefineMsg extends ClientNetMsg { private int npcType; - private int npcID; + public int npcID; private int unknown01; - private int type; - private int token; + public int type; + public int token; private int unknown02; /** @@ -56,122 +51,6 @@ public class RefineMsg extends ClientNetMsg { super(Protocol.ARCUNTRAINABILITY, origin, reader); } - public static void refine(RefineMsg msg, ClientConnection origin) { - if (origin == null) - return; - PlayerCharacter pc = SessionManager.getPlayerCharacter(origin); - if (pc == null) - return; - NPC npc = NPC.getFromCache(msg.npcID); - if (npc == null) - return; - int type = msg.type; - int token = msg.token; - boolean worked = false; - boolean skillPower = true; - if (type == 0) { //refine skill - worked = refineSkill(origin, pc, token, msg); - } else if (type == 1) { //refine power - worked = refinePower(origin, pc, token, msg); - } else if (type == 2) { //refine stat - worked = refineStat(origin, pc, token, msg); - skillPower = false; - } - - if (worked) { - - //update player - pc.applyBonuses(); - pc.charItemManager.RemoveEquipmentFromLackOfSkill(pc, true); - - //echo refine message back - - Dispatch dispatch = Dispatch.borrow(pc, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); - - // if (type == 0 && token == 1488335491){ - // dispatch = Dispatch.borrow(pc, msg); - // DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); - // } - - //resend refine screen - - RefinerScreenMsg refinerScreenMsg = new RefinerScreenMsg(skillPower, npc.getSellPercent(pc)); //TODO set npc cost - dispatch = Dispatch.borrow(pc, refinerScreenMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); - pc.recalculate(); - } - } - - private static boolean refineSkill(ClientConnection origin, PlayerCharacter pc, int token, RefineMsg msg) { - CharacterSkill skill = null; - ConcurrentHashMap skills = pc.getSkills(); - for (CharacterSkill sk : skills.values()) { - if (sk == null) - continue; - SkillsBase sb = sk.getSkillsBase(); - if (sb == null) - continue; - if (sb.getToken() == token) - skill = sk; - } - //check if player has skill to refine - if (skill == null) - return false; - //check there's a train to refine - if (skill.getNumTrains() < 1) - return false; - - //TODO verify if any skills have this as prereq - - //TODO verify if any powers have this as a prereq - //get all players powers - for (CharacterPower power : pc.getPowers().values()) { - ArrayList reqs = PowerReq.getPowerReqsForRune(power.getPowerID()); - for (PowerReq req : reqs) { - ConcurrentHashMap playerSkills = pc.getSkills(); - CharacterSkill playerSkill = playerSkills.get(token); - int currentSkillLevel = playerSkill.getTotalSkillPercet(); - if (token == req.getToken() && req.getLevel() == currentSkillLevel) { - return false; - } - } - } - - //refine skill - return skill.refine(pc); - } - - private static boolean refinePower(ClientConnection origin, PlayerCharacter pc, int token, RefineMsg msg) { - CharacterPower power = null; - ConcurrentHashMap powers = pc.getPowers(); - if (!powers.containsKey(token)) - return false; - power = powers.get(token); - if (power == null) - return false; - if (power.getTrains() < 1) - return false; - - //TODO verify if any powers have this as a prereq - - return power.refine(pc); - } - - private static boolean refineStat(ClientConnection origin, PlayerCharacter pc, int token, RefineMsg msg) { - if (token == MBServerStatics.STAT_STR_ID) - return pc.refineStr(); - if (token == MBServerStatics.STAT_DEX_ID) - return pc.refineDex(); - if (token == MBServerStatics.STAT_CON_ID) - return pc.refineCon(); - if (token == MBServerStatics.STAT_INT_ID) - return pc.refineInt(msg); - if (token == MBServerStatics.STAT_SPI_ID) - return pc.refineSpi(); - return false; - } - /** * Serializes the subclass specific items to the supplied NetMsgWriter. */ From bf712accf9fb4c6a170f36f5cbd7bdb470755cc4 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 07:07:25 -0400 Subject: [PATCH 19/45] Handler created for RefineScreenMsg --- src/engine/net/client/ClientMessagePump.java | 3 -- src/engine/net/client/Protocol.java | 2 +- .../handlers/RefinerScreenMsgHandler.java | 51 +++++++++++++++++++ src/engine/server/world/WorldServer.java | 13 ----- 4 files changed, 52 insertions(+), 17 deletions(-) create mode 100644 src/engine/net/client/handlers/RefinerScreenMsgHandler.java diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index c814fe52..bcca3228 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -126,9 +126,6 @@ public class ClientMessagePump implements NetMsgHandler { case TRAINERLIST: WorldServer.trainerInfo((TrainerInfoMsg) msg, origin); break; - case ARCUNTRAINLIST: - WorldServer.refinerScreen((RefinerScreenMsg) msg, origin); - break; case POWERTARGNAME: PowersManager.summon((SendSummonsRequestMsg) msg, origin); break; diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index 2aa3324d..8d7cc663 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -48,7 +48,7 @@ public enum Protocol { ARCTRACKINGLIST(0xC89CF08B, TrackWindowMsg.class, null), //Request/Send Track window ARCTRACKOBJECT(0x609B6BA2, TrackArrowMsg.class, null), //Send Track Arrow ARCUNTRAINABILITY(0x548DBF83, RefineMsg.class, RefineMsgHandler.class), //Refine - ARCUNTRAINLIST(0x38879E90, RefinerScreenMsg.class, null), //Refiner screen + ARCUNTRAINLIST(0x38879E90, RefinerScreenMsg.class, RefinerScreenMsgHandler.class), //Refiner screen ARCVIEWASSETTRANSACTIONS(0xBFA476E4, ArcViewAssetTransactionsMsg.class, ArcViewAssetTransactionsMsgHandler.class), ASSETSUPPORT(0xc481f89D, AssetSupportMsg.class, AssetSupportMsgHandler.class), BANISHMEMBER(0x31AA3368, BanishUnbanishMsg.class, BanishUnbanishHandler.class), // Banish/Unbanish diff --git a/src/engine/net/client/handlers/RefinerScreenMsgHandler.java b/src/engine/net/client/handlers/RefinerScreenMsgHandler.java new file mode 100644 index 00000000..2e905fe9 --- /dev/null +++ b/src/engine/net/client/handlers/RefinerScreenMsgHandler.java @@ -0,0 +1,51 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// 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.RefinerScreenMsg; +import engine.objects.NPC; +import engine.objects.PlayerCharacter; + +public class RefinerScreenMsgHandler extends AbstractClientMsgHandler { + + public RefinerScreenMsgHandler() { + super(RefinerScreenMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter playerCharacter = origin.getPlayerCharacter(); + + // Member variable declaration + + RefinerScreenMsg msg; + + // Member variable assignment + + msg = (RefinerScreenMsg) baseMsg; + + NPC npc = NPC.getFromCache(msg.getNpcID()); + + if (npc != null) + msg.setUnknown02(0); //cost to refine? + + Dispatch dispatch = Dispatch.borrow(origin.getPlayerCharacter(), msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + + return true; + } + +} \ No newline at end of file diff --git a/src/engine/server/world/WorldServer.java b/src/engine/server/world/WorldServer.java index ffd9461d..30af5b70 100644 --- a/src/engine/server/world/WorldServer.java +++ b/src/engine/server/world/WorldServer.java @@ -33,7 +33,6 @@ import engine.net.client.ClientConnection; import engine.net.client.ClientConnectionManager; import engine.net.client.ClientMessagePump; import engine.net.client.Protocol; -import engine.net.client.msg.RefinerScreenMsg; import engine.net.client.msg.TrainerInfoMsg; import engine.net.client.msg.UpdateStateMsg; import engine.net.client.msg.chat.ChatSystemMsg; @@ -143,18 +142,6 @@ public class WorldServer { } - public static void refinerScreen(RefinerScreenMsg msg, ClientConnection origin) - throws MsgSendException { - - NPC npc = NPC.getFromCache(msg.getNpcID()); - - if (npc != null) - msg.setUnknown02(0); //cost to refine? - - Dispatch dispatch = Dispatch.borrow(origin.getPlayerCharacter(), msg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - } - public static String getUptimeString() { String outString = null; From ce403a6bd8783b7628c399cf7ec4733d43213c9b Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 07:11:01 -0400 Subject: [PATCH 20/45] Handler created for TrainerInfoMsg --- src/engine/net/client/ClientMessagePump.java | 3 - src/engine/net/client/Protocol.java | 2 +- .../handlers/TrainerInfoMsgHandler.java | 59 +++++++++++++++++++ src/engine/server/world/WorldServer.java | 22 ------- 4 files changed, 60 insertions(+), 26 deletions(-) create mode 100644 src/engine/net/client/handlers/TrainerInfoMsgHandler.java diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index bcca3228..7721b052 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -123,9 +123,6 @@ public class ClientMessagePump implements NetMsgHandler { case ARCREQUESTTRADEBUSY: TradeManager.invalidTradeRequest((InvalidTradeRequestMsg) msg); break; - case TRAINERLIST: - WorldServer.trainerInfo((TrainerInfoMsg) msg, origin); - break; case POWERTARGNAME: PowersManager.summon((SendSummonsRequestMsg) msg, origin); break; diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index 8d7cc663..f421f539 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -217,7 +217,7 @@ public enum Protocol { TRADECONFIRM(0x6911E65E, CommitToTradeMsg.class, null), // Commit to trade TRADECONFIRMSTATUS(0x9F85DAFC, null, null), // Other player commit/uncommit/add item TRADEUNCONFIRM(0xEBE280E0, UncommitToTradeMsg.class, null), // Uncommit to trade - TRAINERLIST(0x41FABA62, TrainerInfoMsg.class, null), //Req/Send Trainer Info/Pricing + 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 TRANSFERGOLDTOFROMBUILDING(0x1B1AC8C7, TransferGoldToFromBuildingMsg.class, TransferGoldToFromBuildingMsgHandler.class), // Transfer Gold to/From Building, Transfer Error diff --git a/src/engine/net/client/handlers/TrainerInfoMsgHandler.java b/src/engine/net/client/handlers/TrainerInfoMsgHandler.java new file mode 100644 index 00000000..0d205354 --- /dev/null +++ b/src/engine/net/client/handlers/TrainerInfoMsgHandler.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.net.Dispatch; +import engine.net.DispatchMessage; +import engine.net.client.ClientConnection; +import engine.net.client.msg.ClientNetMsg; +import engine.net.client.msg.TrainerInfoMsg; +import engine.objects.NPC; +import engine.objects.PlayerCharacter; + +public class TrainerInfoMsgHandler extends AbstractClientMsgHandler { + + public TrainerInfoMsgHandler() { + super(TrainerInfoMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter playerCharacter = origin.getPlayerCharacter(); + + // Member variable declaration + + TrainerInfoMsg msg; + + // Member variable assignment + + msg = (TrainerInfoMsg) baseMsg; + + NPC npc = NPC.getFromCache(msg.getObjectID()); + float sellPercent = 1; + + if (npc != null) { + + if (origin.getPlayerCharacter() != null) + sellPercent = npc.getSellPercent(origin.getPlayerCharacter()); + else + sellPercent = npc.getSellPercent(); + + msg.setTrainPercent(sellPercent); //TrainMsg.getTrainPercent(npc)); + } + + Dispatch dispatch = Dispatch.borrow(origin.getPlayerCharacter(), msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + + return true; + } + +} \ No newline at end of file diff --git a/src/engine/server/world/WorldServer.java b/src/engine/server/world/WorldServer.java index 30af5b70..d6d1e890 100644 --- a/src/engine/server/world/WorldServer.java +++ b/src/engine/server/world/WorldServer.java @@ -25,7 +25,6 @@ import engine.job.JobScheduler; import engine.jobs.LogoutCharacterJob; import engine.mobileAI.Threads.MobAIThread; import engine.mobileAI.Threads.Respawner; -import engine.net.Dispatch; import engine.net.DispatchMessage; import engine.net.ItemProductionManager; import engine.net.Network; @@ -33,7 +32,6 @@ import engine.net.client.ClientConnection; import engine.net.client.ClientConnectionManager; import engine.net.client.ClientMessagePump; import engine.net.client.Protocol; -import engine.net.client.msg.TrainerInfoMsg; import engine.net.client.msg.UpdateStateMsg; import engine.net.client.msg.chat.ChatSystemMsg; import engine.objects.*; @@ -122,26 +120,6 @@ public class WorldServer { } } - public static void trainerInfo(TrainerInfoMsg msg, ClientConnection origin) { - - NPC npc = NPC.getFromCache(msg.getObjectID()); - float sellPercent = 1; - - if (npc != null) { - - if (origin.getPlayerCharacter() != null) - sellPercent = npc.getSellPercent(origin.getPlayerCharacter()); - else - sellPercent = npc.getSellPercent(); - - msg.setTrainPercent(sellPercent); //TrainMsg.getTrainPercent(npc)); - } - - Dispatch dispatch = Dispatch.borrow(origin.getPlayerCharacter(), msg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - - } - public static String getUptimeString() { String outString = null; From 8997701d8a3577033f698197ad9c44cae1776a8a Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 07:30:24 -0400 Subject: [PATCH 21/45] Handler created for TrackWindowMsg --- src/engine/gameManager/PowersManager.java | 117 ----------- src/engine/net/client/ClientMessagePump.java | 3 - src/engine/net/client/Protocol.java | 2 +- .../handlers/TrackWindowMsgHandler.java | 184 ++++++++++++++++++ 4 files changed, 185 insertions(+), 121 deletions(-) create mode 100644 src/engine/net/client/handlers/TrackWindowMsgHandler.java diff --git a/src/engine/gameManager/PowersManager.java b/src/engine/gameManager/PowersManager.java index 0942cf6c..af4a4b93 100644 --- a/src/engine/gameManager/PowersManager.java +++ b/src/engine/gameManager/PowersManager.java @@ -28,7 +28,6 @@ import engine.net.client.msg.*; import engine.objects.*; import engine.powers.*; import engine.powers.poweractions.AbstractPowerAction; -import engine.powers.poweractions.TrackPowerAction; import engine.server.MBServerStatics; import org.pmw.tinylog.Logger; @@ -1382,122 +1381,6 @@ public enum PowersManager { } } - public static void trackWindow(TrackWindowMsg msg, ClientConnection origin) { - - PlayerCharacter playerCharacter = SessionManager.getPlayerCharacter( - origin); - - if (playerCharacter == null) - return; - - if (MBServerStatics.POWERS_DEBUG) { - ChatManager.chatSayInfo( - playerCharacter, - "Using Power: " + Integer.toHexString(msg.getPowerToken()) - + " (" + msg.getPowerToken() + ')'); - Logger.info("Using Power: " - + Integer.toHexString(msg.getPowerToken()) + " (" - + msg.getPowerToken() + ')'); - } - - // get track power used - PowersBase pb = PowersManager.powersBaseByToken.get(msg.getPowerToken()); - - if (pb == null || !pb.isTrack()) - return; - - //check track threshold timer to prevent spam - long currentTime = System.currentTimeMillis(); - long timestamp = playerCharacter.getTimeStamp("trackWindow"); - long dif = currentTime - timestamp; - if (dif < MBServerStatics.TRACK_WINDOW_THRESHOLD) - return; - playerCharacter.setTimeStamp("trackWindow", currentTime); - - ArrayList ablist = pb.getActions(); - if (ablist == null) - return; - - TrackPowerAction tpa = null; - for (ActionsBase ab : ablist) { - AbstractPowerAction apa = ab.getPowerAction(); - if (apa != null && apa instanceof TrackPowerAction) - tpa = (TrackPowerAction) apa; - } - if (tpa == null) - return; - - // Check powers for normal users - if (playerCharacter.getPowers() == null || !playerCharacter.getPowers().containsKey(msg.getPowerToken())) - if (!playerCharacter.isCSR()) - if (!MBServerStatics.POWERS_DEBUG) { - // ChatManager.chatSayInfo(pc, "You may not cast that spell!"); - // this.logEXPLOIT("usePowerA(): Cheat attempted? '" + msg.getPowerToken() + "' was not associated with " + pc.getName()); - return; - } - - // Get search mask for track - int mask = 0; - if (pb.targetPlayer()) - if (tpa.trackVampire()) // track vampires - mask = MBServerStatics.MASK_PLAYER | MBServerStatics.MASK_UNDEAD; - else - // track all players - mask = MBServerStatics.MASK_PLAYER; - else if (pb.targetCorpse()) // track corpses - mask = MBServerStatics.MASK_CORPSE; - else if (tpa.trackNPC()) // Track NPCs - mask = MBServerStatics.MASK_NPC; - else if (tpa.trackUndead()) // Track Undead - mask = MBServerStatics.MASK_MOB | MBServerStatics.MASK_UNDEAD; - else - // Track All - mask = MBServerStatics.MASK_MOB | MBServerStatics.MASK_NPC; - - // Find characters in range - HashSet allTargets; - allTargets = WorldGrid.getObjectsInRangeContains(playerCharacter.getLoc(), - pb.getRange(), mask); - - //remove anyone who can't be tracked - Iterator it = allTargets.iterator(); - while (it.hasNext()) { - AbstractWorldObject awo = it.next(); - if (awo == null) - continue; - else if (!awo.isAlive()) - it.remove(); - else if (awo.getObjectType().equals(GameObjectType.PlayerCharacter)) { - PlayerBonuses bonus = ((PlayerCharacter) awo).getBonuses(); - if (bonus != null && bonus.getBool(ModType.CannotTrack, SourceType.NONE)) - it.remove(); - } - } - - // get max charcters for window - int maxTargets = 20; - PromotionClass promo = playerCharacter.getPromotionClass(); - if (promo != null) { - int tableID = promo.getObjectUUID(); - if (tableID == 2512 || tableID == 2514 || tableID == 2515) - maxTargets = 40; - } - - // create list of characters - HashSet trackChars = RangeBasedAwo.getTrackList( - allTargets, playerCharacter, maxTargets); - - TrackWindowMsg trackWindowMsg = new TrackWindowMsg(msg); - - // send track window - trackWindowMsg.setSource(playerCharacter); - trackWindowMsg.setCharacters(trackChars); - - Dispatch dispatch = Dispatch.borrow(playerCharacter, trackWindowMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - - } - private static void sendRecyclePower(int token, ClientConnection origin) { RecyclePowerMsg recyclePowerMsg = new RecyclePowerMsg(token); diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 7721b052..db3aae62 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -129,9 +129,6 @@ public class ClientMessagePump implements NetMsgHandler { case ARCSUMMON: PowersManager.recvSummon((RecvSummonsRequestMsg) msg, origin); break; - case ARCTRACKINGLIST: - PowersManager.trackWindow((TrackWindowMsg) msg, origin); - break; case CHANNELMUTE: break; case KEEPALIVESERVERCLIENT: diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index f421f539..c9b47759 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -45,7 +45,7 @@ public enum Protocol { ARCSERVERSTATUS(0x87BA4462, null, null), //Update Server Status ARCSIEGESPIRE(0x36A49BC6, ArcSiegeSpireMsg.class, ArcSiegeSpireMsgHandler.class), // Activate/Deactivate Spires ARCSUMMON(0xFD816A0A, RecvSummonsRequestMsg.class, null), // Suspect Recv Summons Request - ARCTRACKINGLIST(0xC89CF08B, TrackWindowMsg.class, null), //Request/Send Track window + ARCTRACKINGLIST(0xC89CF08B, TrackWindowMsg.class, TrackWindowMsgHandler.class), //Request/Send Track window ARCTRACKOBJECT(0x609B6BA2, TrackArrowMsg.class, null), //Send Track Arrow ARCUNTRAINABILITY(0x548DBF83, RefineMsg.class, RefineMsgHandler.class), //Refine ARCUNTRAINLIST(0x38879E90, RefinerScreenMsg.class, RefinerScreenMsgHandler.class), //Refiner screen diff --git a/src/engine/net/client/handlers/TrackWindowMsgHandler.java b/src/engine/net/client/handlers/TrackWindowMsgHandler.java new file mode 100644 index 00000000..9abc6210 --- /dev/null +++ b/src/engine/net/client/handlers/TrackWindowMsgHandler.java @@ -0,0 +1,184 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + +package engine.net.client.handlers; + +import engine.Enum; +import engine.Enum.DispatchChannel; +import engine.InterestManagement.WorldGrid; +import engine.exception.MsgSendException; +import engine.gameManager.ChatManager; +import engine.gameManager.PowersManager; +import engine.net.Dispatch; +import engine.net.DispatchMessage; +import engine.net.client.ClientConnection; +import engine.net.client.msg.ClientNetMsg; +import engine.net.client.msg.TrackWindowMsg; +import engine.objects.*; +import engine.powers.ActionsBase; +import engine.powers.PowersBase; +import engine.powers.RangeBasedAwo; +import engine.powers.poweractions.AbstractPowerAction; +import engine.powers.poweractions.TrackPowerAction; +import engine.server.MBServerStatics; +import org.pmw.tinylog.Logger; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; + +public class TrackWindowMsgHandler extends AbstractClientMsgHandler { + + public TrackWindowMsgHandler() { + super(TrackWindowMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter playerCharacter = origin.getPlayerCharacter(); + + // Member variable declaration + + TrackWindowMsg msg; + + // Member variable assignment + + msg = (TrackWindowMsg) baseMsg; + + if (playerCharacter == null) + return true; + + if (MBServerStatics.POWERS_DEBUG) { + ChatManager.chatSayInfo( + playerCharacter, + "Using Power: " + Integer.toHexString(msg.getPowerToken()) + + " (" + msg.getPowerToken() + ')'); + Logger.info("Using Power: " + + Integer.toHexString(msg.getPowerToken()) + " (" + + msg.getPowerToken() + ')'); + } + + // get track power used + + PowersBase pb = PowersManager.powersBaseByToken.get(msg.getPowerToken()); + + if (pb == null || !pb.isTrack()) + return true; + + //check track threshold timer to prevent spam + + long currentTime = System.currentTimeMillis(); + long timestamp = playerCharacter.getTimeStamp("trackWindow"); + long dif = currentTime - timestamp; + + if (dif < MBServerStatics.TRACK_WINDOW_THRESHOLD) + return true; + + playerCharacter.setTimeStamp("trackWindow", currentTime); + + ArrayList ablist = pb.getActions(); + + if (ablist == null) + return true; + + TrackPowerAction tpa = null; + + for (ActionsBase ab : ablist) { + AbstractPowerAction apa = ab.getPowerAction(); + if (apa != null && apa instanceof TrackPowerAction) + tpa = (TrackPowerAction) apa; + } + + if (tpa == null) + return true; + + // Check powers for normal users + if (playerCharacter.getPowers() == null || !playerCharacter.getPowers().containsKey(msg.getPowerToken())) + if (!playerCharacter.isCSR()) + if (!MBServerStatics.POWERS_DEBUG) { + // ChatManager.chatSayInfo(pc, "You may not cast that spell!"); + // this.logEXPLOIT("usePowerA(): Cheat attempted? '" + msg.getPowerToken() + "' was not associated with " + pc.getName()); + return true; + } + + // Get search mask for track + + int mask = 0; + + if (pb.targetPlayer()) + if (tpa.trackVampire()) // track vampires + mask = MBServerStatics.MASK_PLAYER | MBServerStatics.MASK_UNDEAD; + else + // track all players + mask = MBServerStatics.MASK_PLAYER; + else if (pb.targetCorpse()) // track corpses + mask = MBServerStatics.MASK_CORPSE; + else if (tpa.trackNPC()) // Track NPCs + mask = MBServerStatics.MASK_NPC; + else if (tpa.trackUndead()) // Track Undead + mask = MBServerStatics.MASK_MOB | MBServerStatics.MASK_UNDEAD; + else + // Track All + mask = MBServerStatics.MASK_MOB | MBServerStatics.MASK_NPC; + + // Find characters in range + + HashSet allTargets; + allTargets = WorldGrid.getObjectsInRangeContains(playerCharacter.getLoc(), + pb.getRange(), mask); + + //remove anyone who can't be tracked + + Iterator it = allTargets.iterator(); + + while (it.hasNext()) { + AbstractWorldObject awo = it.next(); + + if (awo == null) + continue; + + else if (!awo.isAlive()) + it.remove(); + + else if (awo.getObjectType().equals(Enum.GameObjectType.PlayerCharacter)) { + PlayerBonuses bonus = ((PlayerCharacter) awo).getBonuses(); + + if (bonus != null && bonus.getBool(Enum.ModType.CannotTrack, Enum.SourceType.NONE)) + it.remove(); + } + } + + // get max characters for window + + int maxTargets = 20; + PromotionClass promo = playerCharacter.getPromotionClass(); + + if (promo != null) { + int tableID = promo.getObjectUUID(); + if (tableID == 2512 || tableID == 2514 || tableID == 2515) + maxTargets = 40; + } + + // create list of characters + HashSet trackChars = RangeBasedAwo.getTrackList( + allTargets, playerCharacter, maxTargets); + + TrackWindowMsg trackWindowMsg = new TrackWindowMsg(msg); + + // send track window + trackWindowMsg.setSource(playerCharacter); + trackWindowMsg.setCharacters(trackChars); + + Dispatch dispatch = Dispatch.borrow(playerCharacter, trackWindowMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + + return true; + } + +} \ No newline at end of file From f0ac342b1f9afb1cf05cf347ca9571491b01f5fb Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 07:36:33 -0400 Subject: [PATCH 22/45] Handler created for SendSummonsMsg --- src/engine/devcmd/cmds/SummonCmd.java | 4 +- src/engine/gameManager/PowersManager.java | 50 +---------- src/engine/net/client/ClientMessagePump.java | 5 +- src/engine/net/client/Protocol.java | 4 +- .../handlers/SendSummonsMsgHandler.java | 90 +++++++++++++++++++ ...onsRequestMsg.java => RecvSummonsMsg.java} | 6 +- ...onsRequestMsg.java => SendSummonsMsg.java} | 6 +- .../poweractions/SummonPowerAction.java | 4 +- 8 files changed, 105 insertions(+), 64 deletions(-) create mode 100644 src/engine/net/client/handlers/SendSummonsMsgHandler.java rename src/engine/net/client/msg/{RecvSummonsRequestMsg.java => RecvSummonsMsg.java} (92%) rename src/engine/net/client/msg/{SendSummonsRequestMsg.java => SendSummonsMsg.java} (94%) diff --git a/src/engine/devcmd/cmds/SummonCmd.java b/src/engine/devcmd/cmds/SummonCmd.java index 6877db2c..83c840d3 100644 --- a/src/engine/devcmd/cmds/SummonCmd.java +++ b/src/engine/devcmd/cmds/SummonCmd.java @@ -13,7 +13,7 @@ import engine.devcmd.AbstractDevCmd; import engine.gameManager.SessionManager; import engine.gameManager.ZoneManager; import engine.math.Vector3fImmutable; -import engine.net.client.msg.RecvSummonsRequestMsg; +import engine.net.client.msg.RecvSummonsMsg; import engine.objects.AbstractGameObject; import engine.objects.PlayerCharacter; import engine.objects.Zone; @@ -41,7 +41,7 @@ public class SummonCmd extends AbstractDevCmd { String location = "Somewhere"; if (zone != null) location = zone.zoneName; - RecvSummonsRequestMsg rsrm = new RecvSummonsRequestMsg(pc.getObjectType().ordinal(), pc.getObjectUUID(), pc.getFirstName(), + RecvSummonsMsg rsrm = new RecvSummonsMsg(pc.getObjectType().ordinal(), pc.getObjectUUID(), pc.getFirstName(), location, false); toSummon.getClientConnection().sendMsg(rsrm); diff --git a/src/engine/gameManager/PowersManager.java b/src/engine/gameManager/PowersManager.java index af4a4b93..f09ce82e 100644 --- a/src/engine/gameManager/PowersManager.java +++ b/src/engine/gameManager/PowersManager.java @@ -1240,53 +1240,7 @@ public enum PowersManager { return false; } - public static void summon(SendSummonsRequestMsg msg, ClientConnection origin) { - PlayerCharacter pc = SessionManager.getPlayerCharacter( - origin); - if (pc == null) - return; - - PlayerCharacter target = SessionManager - .getPlayerCharacterByLowerCaseName(msg.getTargetName()); - if (target == null || target.equals(pc) || target.isCombat()) { - - if (target == null) // Player not found. Send not found message - ChatManager.chatInfoError(pc, - "Cannot find that player to summon."); - else if (target.isCombat()) - ChatManager.chatInfoError(pc, - "Cannot summon player in combat."); - // else trying to summon self, just fail - - // recycle summon - sendRecyclePower(msg.getPowerToken(), origin); - - // TODO: client already subtracted 200 mana.. need to correct it - // end cast - PerformActionMsg pam = new PerformActionMsg(msg.getPowerToken(), - msg.getTrains(), msg.getSourceType(), msg.getSourceID(), 0, - 0, 0f, 0f, 0f, 1, 0); - sendPowerMsg(pc, 2, pam); - - return; - } - if (ConfigManager.MB_RULESET.getValue() == "LORE") { - if (pc.guild.getGuildType().equals(target.guild.getGuildType()) == false) { - ChatManager.chatInfoError(pc, - "Cannot summon player outside your charter."); - return; - } - } - PerformActionMsg pam = new PerformActionMsg(msg.getPowerToken(), msg - .getTrains(), msg.getSourceType(), msg.getSourceID(), target - .getObjectType().ordinal(), target.getObjectUUID(), 0f, 0f, 0f, 1, 0); - - // Client removes 200 mana on summon use.. so don't send message to self - target.addSummoner(pc.getObjectUUID(), System.currentTimeMillis() + MBServerStatics.FOURTYFIVE_SECONDS); - usePower(pam, origin, false); - } - - public static void recvSummon(RecvSummonsRequestMsg msg, ClientConnection origin) { + public static void recvSummon(RecvSummonsMsg msg, ClientConnection origin) { PlayerCharacter pc = SessionManager.getPlayerCharacter(origin); if (pc == null) return; @@ -1381,7 +1335,7 @@ public enum PowersManager { } } - private static void sendRecyclePower(int token, ClientConnection origin) { + public static void sendRecyclePower(int token, ClientConnection origin) { RecyclePowerMsg recyclePowerMsg = new RecyclePowerMsg(token); Dispatch dispatch = Dispatch.borrow(origin.getPlayerCharacter(), recyclePowerMsg); diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index db3aae62..15cc9df9 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -123,11 +123,8 @@ public class ClientMessagePump implements NetMsgHandler { case ARCREQUESTTRADEBUSY: TradeManager.invalidTradeRequest((InvalidTradeRequestMsg) msg); break; - case POWERTARGNAME: - PowersManager.summon((SendSummonsRequestMsg) msg, origin); - break; case ARCSUMMON: - PowersManager.recvSummon((RecvSummonsRequestMsg) msg, origin); + PowersManager.recvSummon((RecvSummonsMsg) msg, origin); break; case CHANNELMUTE: break; diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index c9b47759..c841a79a 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -44,7 +44,7 @@ public enum Protocol { ARCREQUESTTRADEBUSY(0xD4BAB4DF, InvalidTradeRequestMsg.class, null), // Attempt trade with someone who is already trading ARCSERVERSTATUS(0x87BA4462, null, null), //Update Server Status ARCSIEGESPIRE(0x36A49BC6, ArcSiegeSpireMsg.class, ArcSiegeSpireMsgHandler.class), // Activate/Deactivate Spires - ARCSUMMON(0xFD816A0A, RecvSummonsRequestMsg.class, null), // Suspect Recv Summons Request + ARCSUMMON(0xFD816A0A, RecvSummonsMsg.class, null), // Suspect Recv Summons Request ARCTRACKINGLIST(0xC89CF08B, TrackWindowMsg.class, TrackWindowMsgHandler.class), //Request/Send Track window ARCTRACKOBJECT(0x609B6BA2, TrackArrowMsg.class, null), //Send Track Arrow ARCUNTRAINABILITY(0x548DBF83, RefineMsg.class, RefineMsgHandler.class), //Refine @@ -161,7 +161,7 @@ public enum Protocol { POWERACTION(0xA0B27EEB, ApplyEffectMsg.class, null), // Apply Effect, add to effects icons POWERACTIONDD(0xD43052F8, ModifyHealthMsg.class, null), //Modify Health/Mana/Stamina using power POWERACTIONDDDIE(0xC27D446B, null, null), //Modify Health/Mana/Stamina using power and kill target - POWERTARGNAME(0x5A807CCE, SendSummonsRequestMsg.class, null), // Send Summons Request + POWERTARGNAME(0x5A807CCE, SendSummonsMsg.class, SendSummonsMsgHandler.class), // Send Summons Request RAISEATTR(0x5EEB65E0, ModifyStatMsg.class, ModifyStatMsgHandler.class), // Modify Stat RANDOM(0xAC5D0135, RandomMsg.class, RandomMsgHandler.class), //RequestSend random roll READYTOENTER(0x490E4FE0, EnterWorldReceivedMsg.class, null), //Client Ack Receive Enter World diff --git a/src/engine/net/client/handlers/SendSummonsMsgHandler.java b/src/engine/net/client/handlers/SendSummonsMsgHandler.java new file mode 100644 index 00000000..121a502e --- /dev/null +++ b/src/engine/net/client/handlers/SendSummonsMsgHandler.java @@ -0,0 +1,90 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + +package engine.net.client.handlers; + +import engine.exception.MsgSendException; +import engine.gameManager.ChatManager; +import engine.gameManager.ConfigManager; +import engine.gameManager.SessionManager; +import engine.net.client.ClientConnection; +import engine.net.client.msg.ClientNetMsg; +import engine.net.client.msg.PerformActionMsg; +import engine.net.client.msg.SendSummonsMsg; +import engine.objects.PlayerCharacter; +import engine.server.MBServerStatics; + +import static engine.gameManager.PowersManager.*; + +public class SendSummonsMsgHandler extends AbstractClientMsgHandler { + + public SendSummonsMsgHandler() { + super(SendSummonsMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter playerCharacter = origin.getPlayerCharacter(); + + // Member variable declaration + + SendSummonsMsg msg; + + // Member variable assignment + + msg = (SendSummonsMsg) baseMsg; + + if (playerCharacter == null) + return true; + + PlayerCharacter target = SessionManager + .getPlayerCharacterByLowerCaseName(msg.getTargetName()); + + if (target == null || target.equals(playerCharacter) || target.isCombat()) { + + if (target == null) // Player not found. Send not found message + ChatManager.chatInfoError(playerCharacter, + "Cannot find that player to summon."); + else if (target.isCombat()) + ChatManager.chatInfoError(playerCharacter, + "Cannot summon player in combat."); + + // else trying to summon self, just fail + + // recycle summon + sendRecyclePower(msg.getPowerToken(), origin); + + // TODO: client already subtracted 200 mana.. need to correct it + // end cast + PerformActionMsg pam = new PerformActionMsg(msg.getPowerToken(), + msg.getTrains(), msg.getSourceType(), msg.getSourceID(), 0, + 0, 0f, 0f, 0f, 1, 0); + sendPowerMsg(playerCharacter, 2, pam); + + return true; + } + if (ConfigManager.MB_RULESET.getValue() == "LORE") { + if (playerCharacter.guild.getGuildType().equals(target.guild.getGuildType()) == false) { + ChatManager.chatInfoError(playerCharacter, + "Cannot summon player outside your charter."); + return true; + } + } + PerformActionMsg pam = new PerformActionMsg(msg.getPowerToken(), msg + .getTrains(), msg.getSourceType(), msg.getSourceID(), target + .getObjectType().ordinal(), target.getObjectUUID(), 0f, 0f, 0f, 1, 0); + + // Client removes 200 mana on summon use.. so don't send message to self + target.addSummoner(playerCharacter.getObjectUUID(), System.currentTimeMillis() + MBServerStatics.FOURTYFIVE_SECONDS); + usePower(pam, origin, false); + + return true; + } + +} \ No newline at end of file diff --git a/src/engine/net/client/msg/RecvSummonsRequestMsg.java b/src/engine/net/client/msg/RecvSummonsMsg.java similarity index 92% rename from src/engine/net/client/msg/RecvSummonsRequestMsg.java rename to src/engine/net/client/msg/RecvSummonsMsg.java index 2dd6d5d2..bf37bf96 100644 --- a/src/engine/net/client/msg/RecvSummonsRequestMsg.java +++ b/src/engine/net/client/msg/RecvSummonsMsg.java @@ -15,7 +15,7 @@ import engine.net.ByteBufferReader; import engine.net.ByteBufferWriter; import engine.net.client.Protocol; -public class RecvSummonsRequestMsg extends ClientNetMsg { +public class RecvSummonsMsg extends ClientNetMsg { private int sourceType; private int sourceID; @@ -26,7 +26,7 @@ public class RecvSummonsRequestMsg extends ClientNetMsg { /** * This is the general purpose constructor. */ - public RecvSummonsRequestMsg(int sourceType, int sourceID, String sourceName, String locationName, boolean accepted) { + public RecvSummonsMsg(int sourceType, int sourceID, String sourceName, String locationName, boolean accepted) { super(Protocol.ARCSUMMON); this.sourceType = sourceType; this.sourceID = sourceID; @@ -41,7 +41,7 @@ public class RecvSummonsRequestMsg extends ClientNetMsg { * past the limit) then this constructor Throws that Exception to the * caller. */ - public RecvSummonsRequestMsg(AbstractConnection origin, ByteBufferReader reader) { + public RecvSummonsMsg(AbstractConnection origin, ByteBufferReader reader) { super(Protocol.ARCSUMMON, origin, reader); } diff --git a/src/engine/net/client/msg/SendSummonsRequestMsg.java b/src/engine/net/client/msg/SendSummonsMsg.java similarity index 94% rename from src/engine/net/client/msg/SendSummonsRequestMsg.java rename to src/engine/net/client/msg/SendSummonsMsg.java index a634343e..6b5723b5 100644 --- a/src/engine/net/client/msg/SendSummonsRequestMsg.java +++ b/src/engine/net/client/msg/SendSummonsMsg.java @@ -15,7 +15,7 @@ import engine.net.ByteBufferReader; import engine.net.ByteBufferWriter; import engine.net.client.Protocol; -public class SendSummonsRequestMsg extends ClientNetMsg { +public class SendSummonsMsg extends ClientNetMsg { private int powerToken; private int sourceType; @@ -26,7 +26,7 @@ public class SendSummonsRequestMsg extends ClientNetMsg { /** * This is the general purpose constructor. */ - public SendSummonsRequestMsg() { + public SendSummonsMsg() { super(Protocol.POWERTARGNAME); } @@ -36,7 +36,7 @@ public class SendSummonsRequestMsg extends ClientNetMsg { * past the limit) then this constructor Throws that Exception to the * caller. */ - public SendSummonsRequestMsg(AbstractConnection origin, ByteBufferReader reader) { + public SendSummonsMsg(AbstractConnection origin, ByteBufferReader reader) { super(Protocol.POWERTARGNAME, origin, reader); } diff --git a/src/engine/powers/poweractions/SummonPowerAction.java b/src/engine/powers/poweractions/SummonPowerAction.java index 03fe028e..37c26b0d 100644 --- a/src/engine/powers/poweractions/SummonPowerAction.java +++ b/src/engine/powers/poweractions/SummonPowerAction.java @@ -16,7 +16,7 @@ import engine.math.Vector3fImmutable; import engine.net.Dispatch; import engine.net.DispatchMessage; import engine.net.client.ClientConnection; -import engine.net.client.msg.RecvSummonsRequestMsg; +import engine.net.client.msg.RecvSummonsMsg; import engine.objects.AbstractCharacter; import engine.objects.AbstractWorldObject; import engine.objects.PlayerCharacter; @@ -57,7 +57,7 @@ public class SummonPowerAction extends AbstractPowerAction { if (zone != null) location = zone.zoneName; - RecvSummonsRequestMsg rsrm = new RecvSummonsRequestMsg(source.getObjectType().ordinal(), source.getObjectUUID(), source.getFirstName(), + RecvSummonsMsg rsrm = new RecvSummonsMsg(source.getObjectType().ordinal(), source.getObjectUUID(), source.getFirstName(), location, false); Dispatch dispatch = Dispatch.borrow(target, rsrm); From 093bc5e97e287e3718c4c944bf4db217e759c2ba Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 07:41:40 -0400 Subject: [PATCH 23/45] Handler created for RecvSummonsMsg --- src/engine/gameManager/PowersManager.java | 100 +------------ src/engine/net/client/ClientMessagePump.java | 4 - src/engine/net/client/Protocol.java | 2 +- .../handlers/RecvSummonsMsgHandler.java | 135 ++++++++++++++++++ 4 files changed, 140 insertions(+), 101 deletions(-) create mode 100644 src/engine/net/client/handlers/RecvSummonsMsgHandler.java diff --git a/src/engine/gameManager/PowersManager.java b/src/engine/gameManager/PowersManager.java index f09ce82e..da4d8167 100644 --- a/src/engine/gameManager/PowersManager.java +++ b/src/engine/gameManager/PowersManager.java @@ -18,7 +18,10 @@ import engine.job.AbstractJob; import engine.job.AbstractScheduleJob; import engine.job.JobContainer; import engine.job.JobScheduler; -import engine.jobs.*; +import engine.jobs.AbstractEffectJob; +import engine.jobs.FinishRecycleTimeJob; +import engine.jobs.UseItemJob; +import engine.jobs.UsePowerJob; import engine.math.Vector3fImmutable; import engine.net.ByteBufferWriter; import engine.net.Dispatch; @@ -1240,101 +1243,6 @@ public enum PowersManager { return false; } - public static void recvSummon(RecvSummonsMsg msg, ClientConnection origin) { - PlayerCharacter pc = SessionManager.getPlayerCharacter(origin); - if (pc == null) - return; - - PlayerCharacter source = PlayerCharacter.getFromCache(msg.getSourceID()); - if (source == null) - return; - - long tooLate = pc.getSummoner(source.getObjectUUID()); - if (tooLate < System.currentTimeMillis()) { - ChatManager.chatInfoError(pc, "You waited too long to " + (msg.accepted() ? "accept" : "decline") + " the summons."); - pc.removeSummoner(source.getObjectUUID()); - return; - } - - if (pc.getBonuses() != null && pc.getBonuses().getBool(ModType.BlockedPowerType, SourceType.SUMMON)) { - ErrorPopupMsg.sendErrorMsg(pc, "You have been blocked from receiving summons!"); - ErrorPopupMsg.sendErrorMsg(source, "Target is blocked from receiving summons!"); - pc.removeSummoner(source.getObjectUUID()); - return; - } - pc.removeSummoner(source.getObjectUUID()); - - // Handle Accepting or Denying a summons. - // set timer based on summon type. - boolean wentThrough = false; - if (msg.accepted()) - // summons accepted, let's move the player if within time - if (source.isAlive()) { - - // //make sure summons handled in time - ConcurrentHashMap timers = source.getTimers(); - // if (timers == null || !timers.containsKey("SummonSend")) { - // ChatManager.chatInfoError(pc, "You waited too long to " + (msg.accepted() ? "accept" : "decline") + " the summons."); - // return; - // } - - // // clear last summons accept timer - // timers.get("SummonSend").cancelJob(); - //timers.remove("SummonSend"); - // cancel any other summons waiting - timers = pc.getTimers(); - if (timers != null && timers.containsKey("Summon")) - timers.get("Summon").cancelJob(); - - // get time to wait before summons goes through - BaseClass base = source.baseClass; - PromotionClass promo = source.getPromotionClass(); - int duration; - - - //determine if in combat with another player - - - //comment out this block to disable combat timer - // if (lastAttacked < 60000) { - // if (pc.inSafeZone()) //player in safe zone, no need for combat timer - // combat = false; - // else if (source.inSafeZone()) //summoner in safe zone, apply combat timer - // combat = true; - // else if ((source.getLoc().distance2D(pc.getLoc())) > 6144f) - // combat = true; //more than 1.5x width of zone, not tactical summons - // } - - if (promo != null && promo.getObjectUUID() == 2519) - duration = 10000; // Priest summons, 10 seconds - else if (base != null && base.getObjectUUID() == 2501) - duration = 15000; // Healer Summons, 15 seconds - else - duration = 45000; // Belgosh Summons, 45 seconds - - - // Teleport to summoners location - FinishSummonsJob fsj = new FinishSummonsJob(source, pc); - JobContainer jc = JobScheduler.getInstance().scheduleJob(fsj, - duration); - if (timers != null) - timers.put("Summon", jc); - wentThrough = true; - } - - // Summons failed - if (!wentThrough) - // summons refused. Let's be nice and reset recycle timer - if (source != null) { - - // Send summons refused Message - ErrorPopupMsg.sendErrorPopup(source, 29); - - // recycle summons power - //finishRecycleTime(428523680, source, true); - } - } - public static void sendRecyclePower(int token, ClientConnection origin) { RecyclePowerMsg recyclePowerMsg = new RecyclePowerMsg(token); diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 15cc9df9..093fd17c 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -10,7 +10,6 @@ package engine.net.client; import engine.gameManager.ChatManager; -import engine.gameManager.PowersManager; import engine.gameManager.SessionManager; import engine.gameManager.TradeManager; import engine.net.NetMsgHandler; @@ -123,9 +122,6 @@ public class ClientMessagePump implements NetMsgHandler { case ARCREQUESTTRADEBUSY: TradeManager.invalidTradeRequest((InvalidTradeRequestMsg) msg); break; - case ARCSUMMON: - PowersManager.recvSummon((RecvSummonsMsg) msg, origin); - break; case CHANNELMUTE: break; case KEEPALIVESERVERCLIENT: diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index c841a79a..c291b3ab 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -44,7 +44,7 @@ public enum Protocol { ARCREQUESTTRADEBUSY(0xD4BAB4DF, InvalidTradeRequestMsg.class, null), // Attempt trade with someone who is already trading ARCSERVERSTATUS(0x87BA4462, null, null), //Update Server Status ARCSIEGESPIRE(0x36A49BC6, ArcSiegeSpireMsg.class, ArcSiegeSpireMsgHandler.class), // Activate/Deactivate Spires - ARCSUMMON(0xFD816A0A, RecvSummonsMsg.class, null), // Suspect Recv Summons Request + ARCSUMMON(0xFD816A0A, RecvSummonsMsg.class, RecvSummonsMsgHandler.class), // Suspect Recv Summons Request ARCTRACKINGLIST(0xC89CF08B, TrackWindowMsg.class, TrackWindowMsgHandler.class), //Request/Send Track window ARCTRACKOBJECT(0x609B6BA2, TrackArrowMsg.class, null), //Send Track Arrow ARCUNTRAINABILITY(0x548DBF83, RefineMsg.class, RefineMsgHandler.class), //Refine diff --git a/src/engine/net/client/handlers/RecvSummonsMsgHandler.java b/src/engine/net/client/handlers/RecvSummonsMsgHandler.java new file mode 100644 index 00000000..60be7e9c --- /dev/null +++ b/src/engine/net/client/handlers/RecvSummonsMsgHandler.java @@ -0,0 +1,135 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// 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.job.JobContainer; +import engine.job.JobScheduler; +import engine.jobs.FinishSummonsJob; +import engine.net.client.ClientConnection; +import engine.net.client.msg.ClientNetMsg; +import engine.net.client.msg.ErrorPopupMsg; +import engine.net.client.msg.RecvSummonsMsg; +import engine.objects.BaseClass; +import engine.objects.PlayerCharacter; +import engine.objects.PromotionClass; + +import java.util.concurrent.ConcurrentHashMap; + +public class RecvSummonsMsgHandler extends AbstractClientMsgHandler { + + public RecvSummonsMsgHandler() { + super(RecvSummonsMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter playerCharacter = origin.getPlayerCharacter(); + + // Member variable declaration + + RecvSummonsMsg msg; + + // Member variable assignment + + msg = (RecvSummonsMsg) baseMsg; + + if (playerCharacter == null) + return true; + + PlayerCharacter source = PlayerCharacter.getFromCache(msg.getSourceID()); + + if (source == null) + return true; + + long tooLate = playerCharacter.getSummoner(source.getObjectUUID()); + + if (tooLate < System.currentTimeMillis()) { + ChatManager.chatInfoError(playerCharacter, "You waited too long to " + (msg.accepted() ? "accept" : "decline") + " the summons."); + playerCharacter.removeSummoner(source.getObjectUUID()); + return true; + } + + if (playerCharacter.getBonuses() != null && playerCharacter.getBonuses().getBool(Enum.ModType.BlockedPowerType, Enum.SourceType.SUMMON)) { + ErrorPopupMsg.sendErrorMsg(playerCharacter, "You have been blocked from receiving summons!"); + ErrorPopupMsg.sendErrorMsg(source, "Target is blocked from receiving summons!"); + playerCharacter.removeSummoner(source.getObjectUUID()); + return true; + } + + playerCharacter.removeSummoner(source.getObjectUUID()); + + // Handle Accepting or Denying a summons. + // set timer based on summon type. + + boolean wentThrough = false; + + if (msg.accepted()) // summons accepted, let's move the player if within time + if (source.isAlive()) { + + //make sure summons handled in time + ConcurrentHashMap timers; + timers = playerCharacter.getTimers(); + + if (timers != null && timers.containsKey("Summon")) + timers.get("Summon").cancelJob(); + + // get time to wait before summons goes through + + BaseClass base = source.baseClass; + PromotionClass promo = source.getPromotionClass(); + int duration; + + //determine if in combat with another player + + //comment out this block to disable combat timer + // if (lastAttacked < 60000) { + // if (pc.inSafeZone()) //player in safe zone, no need for combat timer + // combat = false; + // else if (source.inSafeZone()) //summoner in safe zone, apply combat timer + // combat = true; + // else if ((source.getLoc().distance2D(pc.getLoc())) > 6144f) + // combat = true; //more than 1.5x width of zone, not tactical summons + // } + + if (promo != null && promo.getObjectUUID() == 2519) + duration = 10000; // Priest summons, 10 seconds + else if (base != null && base.getObjectUUID() == 2501) + duration = 15000; // Healer Summons, 15 seconds + else + duration = 45000; // Belgosh Summons, 45 seconds + + // Teleport to summoners location + + FinishSummonsJob fsj = new FinishSummonsJob(source, playerCharacter); + JobContainer jc = JobScheduler.getInstance().scheduleJob(fsj, + duration); + + if (timers != null) + timers.put("Summon", jc); + + wentThrough = true; + } + + // Summons failed + if (!wentThrough) // summons refused. Let's be nice and reset recycle timer + { + // Send summons refused Message + ErrorPopupMsg.sendErrorPopup(source, 29); + // recycle summons power + //finishRecycleTime(428523680, source, true); + } + + return true; + } + +} \ No newline at end of file From a37825168b2cfbccce1716d4b293fe71764101f0 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 07:50:57 -0400 Subject: [PATCH 24/45] Handler created for AbstractChatMsg --- src/engine/gameManager/ChatManager.java | 74 +-------------- src/engine/net/client/ClientMessagePump.java | 4 - src/engine/net/client/Protocol.java | 20 ++-- .../handlers/AbstractChatMsgHandler.java | 95 +++++++++++++++++++ 4 files changed, 107 insertions(+), 86 deletions(-) create mode 100644 src/engine/net/client/handlers/AbstractChatMsgHandler.java diff --git a/src/engine/gameManager/ChatManager.java b/src/engine/gameManager/ChatManager.java index 9180c1b9..789ae998 100644 --- a/src/engine/gameManager/ChatManager.java +++ b/src/engine/gameManager/ChatManager.java @@ -20,13 +20,11 @@ import engine.net.Dispatch; import engine.net.DispatchMessage; import engine.net.MessageDispatcher; import engine.net.client.ClientConnection; -import engine.net.client.Protocol; import engine.net.client.handlers.ClientAdminCommandMsgHandler; import engine.net.client.msg.chat.*; import engine.objects.*; import engine.server.MBServerStatics; import engine.server.world.WorldServer; -import engine.session.Session; import org.pmw.tinylog.Logger; import java.util.ArrayList; @@ -42,8 +40,8 @@ public enum ChatManager { // (FLOOD_TIME_THRESHOLD) ms will flag as a flood message // Example, set to 3 & 2000 to flag the 3rd message within 2000 ms. - private static final int FLOOD_QTY_THRESHOLD = 3; - private static final int FLOOD_TIME_THRESHOLD = 2000; + public static final int FLOOD_QTY_THRESHOLD = 3; + public static final int FLOOD_TIME_THRESHOLD = 2000; private static final String FLOOD_USER_ERROR = "You talk too much!"; private static final String SILENCED = "You find yourself mute!"; private static final String UNKNOWN_COMMAND = "No such command."; @@ -51,74 +49,6 @@ public enum ChatManager { /** * This method used when handling a ChatMsg received from the network. */ - public static void handleChatMsg(Session sender, AbstractChatMsg msg) { - - if (msg == null) { - Logger.warn( - "null message: "); - return; - } - - if (sender == null) { - Logger.warn( - "null sender: "); - return; - } - - PlayerCharacter pc = sender.getPlayerCharacter(); - - if (pc == null) { - Logger.warn( - "invalid sender: "); - return; - } - - Protocol protocolMsg = msg.getProtocolMsg(); - - // Flood control, implemented per channel - - boolean isFlood = false; - long curMsgTime = System.currentTimeMillis(); - long checkTime = pc.chatFloodTime(protocolMsg.opcode, curMsgTime, FLOOD_QTY_THRESHOLD - 1); - - if ((checkTime > 0L) && (curMsgTime - checkTime < FLOOD_TIME_THRESHOLD)) - isFlood = true; - - switch (protocolMsg) { - case CHATSAY: - ChatManager.chatSay(pc, msg.getMessage(), isFlood); - return; - case CHATCSR: - ChatManager.chatCSR(msg); - return; - case CHATTELL: - ChatTellMsg ctm = (ChatTellMsg) msg; - ChatManager.chatTell(pc, ctm.getTargetName(), ctm.getMessage(), isFlood); - return; - case CHATSHOUT: - ChatManager.chatShout(pc, msg.getMessage(), isFlood); - return; - case CHATGUILD: - ChatManager.chatGuild(pc, (ChatGuildMsg) msg); - return; - case CHATGROUP: - ChatManager.chatGroup(pc, (ChatGroupMsg) msg); - return; - case CHATIC: - ChatManager.chatIC(pc, (ChatICMsg) msg); - return; - case LEADERCHANNELMESSAGE: - ChatManager.chatGlobal(pc, msg.getMessage(), isFlood); - return; - case GLOBALCHANNELMESSAGE: - case CHATPVP: - case CHATCITY: - case CHATINFO: - case SYSTEMBROADCASTCHANNEL: - default: - } - - } /* * Channels diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 093fd17c..51565443 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -9,13 +9,11 @@ package engine.net.client; -import engine.gameManager.ChatManager; import engine.gameManager.SessionManager; import engine.gameManager.TradeManager; import engine.net.NetMsgHandler; import engine.net.client.handlers.AbstractClientMsgHandler; import engine.net.client.msg.*; -import engine.net.client.msg.chat.AbstractChatMsg; import engine.server.world.WorldServer; import engine.session.Session; import engine.util.StringUtils; @@ -89,8 +87,6 @@ public class ClientMessagePump implements NetMsgHandler { case SYSTEMCHANNEL: case GLOBALCHANNELMESSAGE: case LEADERCHANNELMESSAGE: - ChatManager.handleChatMsg(s, (AbstractChatMsg) msg); - break; case READYTOENTER: break; case OPENVAULT: diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index c291b3ab..95255aba 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -60,16 +60,16 @@ public enum Protocol { CHANGEGUILDLEADER(0xE40BC95D, ChangeGuildLeaderMsg.class, ChangeGuildLeaderHandler.class), CHANNELMUTE(0xC1BDC53A, ChatFilterMsg.class, ChannelMuteMsgHandler.class), //Chat Channels that are turned on CHARSELECTSCREEN(0x682C935D, null, null), // Character Selection Screen - CHATCITY(0x9D402901, ChatCityMsg.class, null), // Chat Channel: /City - CHATCSR(0x14EBA1C3, ChatCSRMsg.class, null), //Chat Channel: CSR - CHATGROUP(0xA895B634, ChatGroupMsg.class, null), // Chat Channel: /group - CHATGUILD(0xA9D92ED4, ChatGuildMsg.class, null), // Chat Channel: /guild - CHATIC(0x00A75F35, ChatICMsg.class, null), // Chat Channel: /IC - CHATINFO(0x9D4B61EB, ChatInfoMsg.class, null), // Chat Channel: /Info - CHATPVP(0x14EBA570, ChatPvPMsg.class, null), // Chat Channel: PVP - CHATSAY(0x14EA0393, ChatSayMsg.class, null), // Chat Channel: /say - CHATSHOUT(0xA8D5B560, ChatShoutMsg.class, null), // Chat Channel: /shout - CHATTELL(0x9D4AC896, ChatTellMsg.class, null), // Chat Channel: /tell + CHATCITY(0x9D402901, ChatCityMsg.class, AbstractChatMsgHandler.class), // Chat Channel: /City + CHATCSR(0x14EBA1C3, ChatCSRMsg.class, AbstractChatMsgHandler.class), //Chat Channel: CSR + CHATGROUP(0xA895B634, ChatGroupMsg.class, AbstractChatMsgHandler.class), // Chat Channel: /group + CHATGUILD(0xA9D92ED4, ChatGuildMsg.class, AbstractChatMsgHandler.class), // Chat Channel: /guild + CHATIC(0x00A75F35, ChatICMsg.class, AbstractChatMsgHandler.class), // Chat Channel: /IC + CHATINFO(0x9D4B61EB, ChatInfoMsg.class, AbstractChatMsgHandler.class), // Chat Channel: /Info + CHATPVP(0x14EBA570, ChatPvPMsg.class, AbstractChatMsgHandler.class), // Chat Channel: PVP + CHATSAY(0x14EA0393, ChatSayMsg.class, AbstractChatMsgHandler.class), // Chat Channel: /say + CHATSHOUT(0xA8D5B560, ChatShoutMsg.class, AbstractChatMsgHandler.class), // Chat Channel: /shout + CHATTELL(0x9D4AC896, ChatTellMsg.class, AbstractChatMsgHandler.class), // Chat Channel: /tell CHECKUNIQUEGUILD(0x689097D7, GuildCreationOptionsMsg.class, GuildCreationOptionsHandler.class), // Set Guild Name/Motto in Use Guild Charter CITYASSET(0x7cae1678, CityAssetMsg.class, null), CITYCHOICE(0x406610BB, CityChoiceMsg.class, CityChoiceMsgHandler.class), diff --git a/src/engine/net/client/handlers/AbstractChatMsgHandler.java b/src/engine/net/client/handlers/AbstractChatMsgHandler.java new file mode 100644 index 00000000..6b6e03d5 --- /dev/null +++ b/src/engine/net/client/handlers/AbstractChatMsgHandler.java @@ -0,0 +1,95 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + +package engine.net.client.handlers; + +import engine.exception.MsgSendException; +import engine.gameManager.ChatManager; +import engine.net.client.ClientConnection; +import engine.net.client.Protocol; +import engine.net.client.msg.ClientNetMsg; +import engine.net.client.msg.chat.*; +import engine.objects.PlayerCharacter; + +import static engine.gameManager.ChatManager.FLOOD_QTY_THRESHOLD; +import static engine.gameManager.ChatManager.FLOOD_TIME_THRESHOLD; + +public class AbstractChatMsgHandler extends AbstractClientMsgHandler { + + public AbstractChatMsgHandler() { + super(AbstractChatMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter playerCharacter = origin.getPlayerCharacter(); + + // Member variable declaration + + AbstractChatMsg msg; + + // Member variable assignment + + msg = (AbstractChatMsg) baseMsg; + + if (msg == null) + return true; + + if (playerCharacter == null) + return true; + + Protocol protocolMsg = msg.getProtocolMsg(); + + // Flood control, implemented per channel + + boolean isFlood = false; + long curMsgTime = System.currentTimeMillis(); + long checkTime = playerCharacter.chatFloodTime(protocolMsg.opcode, curMsgTime, FLOOD_QTY_THRESHOLD - 1); + + if ((checkTime > 0L) && (curMsgTime - checkTime < FLOOD_TIME_THRESHOLD)) + isFlood = true; + + switch (protocolMsg) { + case CHATSAY: + ChatManager.chatSay(playerCharacter, msg.getMessage(), isFlood); + return true; + case CHATCSR: + ChatManager.chatCSR(msg); + return true; + case CHATTELL: + ChatTellMsg ctm = (ChatTellMsg) msg; + ChatManager.chatTell(playerCharacter, ctm.getTargetName(), ctm.getMessage(), isFlood); + return true; + case CHATSHOUT: + ChatManager.chatShout(playerCharacter, msg.getMessage(), isFlood); + return true; + case CHATGUILD: + ChatManager.chatGuild(playerCharacter, (ChatGuildMsg) msg); + return true; + case CHATGROUP: + ChatManager.chatGroup(playerCharacter, (ChatGroupMsg) msg); + return true; + case CHATIC: + ChatManager.chatIC(playerCharacter, (ChatICMsg) msg); + return true; + case LEADERCHANNELMESSAGE: + ChatManager.chatGlobal(playerCharacter, msg.getMessage(), isFlood); + return true; + case GLOBALCHANNELMESSAGE: + case CHATPVP: + case CHATCITY: + case CHATINFO: + case SYSTEMBROADCASTCHANNEL: + default: + } + + return true; + } + +} \ No newline at end of file From 301014f06f613641bbd8337cda309b3204459a38 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 07:54:00 -0400 Subject: [PATCH 25/45] Handler created for AbstractChatMsg --- src/engine/net/client/ClientMessagePump.java | 20 +------------------- src/engine/net/client/Protocol.java | 4 ++-- 2 files changed, 3 insertions(+), 21 deletions(-) diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 51565443..0a094478 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -68,25 +68,7 @@ public class ClientMessagePump implements NetMsgHandler { protocolMsg = msg.getProtocolMsg(); switch (protocolMsg) { - /* - * Chat - */ - - // Simplify by fall through. Route in ChatManager - case CHATSAY: - case CHATSHOUT: - case CHATTELL: - case CHATGUILD: - case CHATGROUP: - case CHATPVP: - case CHATIC: - case CHATCITY: - case CHATINFO: - case SYSTEMBROADCASTCHANNEL: - case CHATCSR: - case SYSTEMCHANNEL: - case GLOBALCHANNELMESSAGE: - case LEADERCHANNELMESSAGE: + case READYTOENTER: break; case OPENVAULT: diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index 95255aba..c94ba080 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -98,7 +98,7 @@ public enum Protocol { FRIENDDECLINE(0xF08FC279, DeclineFriendMsg.class, FriendDeclineHandler.class), FURNITURE(0xCE7FA503, FurnitureMsg.class, FurnitureHandler.class), GAMESERVERIPRESPONSE(0x6C95CF87, GameServerIPResponseMsg.class, null), // Game Server IP Response - GLOBALCHANNELMESSAGE(0x2bf03fd2, null, null), + GLOBALCHANNELMESSAGE(0x2bf03fd2, ChatGlobalMsg.class, AbstractChatMsgHandler.class), GOLDFROMVAULT(0x011D0123, GoldFromVaultMsg.class, GoldFromVaultMsgHandler.class), // Transfer Gold from Vault to Inventory GOLDTOVAULT(0x3ABAEE49, GoldToVaultMsg.class, GoldToVaultMsgHandler.class), // Transfer Gold from Inventory to Vault GROUPDISBAND(0xE2B85AA4, DisbandGroupMsg.class, DisbandGroupHandler.class), //Disband Group @@ -125,7 +125,7 @@ public enum Protocol { JOINGUILD(0xF0C5F2FF, AcceptInviteToGuildMsg.class, AcceptInviteToGuildHandler.class), // Accept guild invite KEEPALIVESERVERCLIENT(0x49EE129C, KeepAliveServerClientMsg.class, KeepAliveServerClientHandler.class), // Keep Alive LEADERBOARD(0x6F0C1386, LeaderboardMessage.class, null), - LEADERCHANNELMESSAGE(0x17b306f9, ChatGlobalMsg.class, null), + LEADERCHANNELMESSAGE(0x17b306f9, ChatGlobalMsg.class, AbstractChatMsgHandler.class), LEAVEGROUP(0xD8037303, LeaveGroupMsg.class, LeaveGroupHandler.class), //Leave Group LEAVEGUILD(0x1801EA32, LeaveGuildMsg.class, LeaveGuildHandler.class), // Leave Guild LEAVEREQUEST(0xC79D775C, LeaveWorldMsg.class, LeaveWorldMsgHandler.class), //Client Request Leave World From b74105137eb0d44d09219ed893d08681d2f1f896 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 07:54:57 -0400 Subject: [PATCH 26/45] Handler created for AbstractChatMsg --- src/engine/net/client/Protocol.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index c94ba080..9dd34cc6 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -125,7 +125,7 @@ public enum Protocol { JOINGUILD(0xF0C5F2FF, AcceptInviteToGuildMsg.class, AcceptInviteToGuildHandler.class), // Accept guild invite KEEPALIVESERVERCLIENT(0x49EE129C, KeepAliveServerClientMsg.class, KeepAliveServerClientHandler.class), // Keep Alive LEADERBOARD(0x6F0C1386, LeaderboardMessage.class, null), - LEADERCHANNELMESSAGE(0x17b306f9, ChatGlobalMsg.class, AbstractChatMsgHandler.class), + LEADERCHANNELMESSAGE(0x17b306f9, ChatLeaderMsg.class, AbstractChatMsgHandler.class), LEAVEGROUP(0xD8037303, LeaveGroupMsg.class, LeaveGroupHandler.class), //Leave Group LEAVEGUILD(0x1801EA32, LeaveGuildMsg.class, LeaveGuildHandler.class), // Leave Guild LEAVEREQUEST(0xC79D775C, LeaveWorldMsg.class, LeaveWorldMsgHandler.class), //Client Request Leave World From 9934e60fa440c24550104b098db939f2ec9b9adb Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 08:02:00 -0400 Subject: [PATCH 27/45] Handler created for AbstractChatMsg --- src/engine/net/client/Protocol.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index 9dd34cc6..c94ba080 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -125,7 +125,7 @@ public enum Protocol { JOINGUILD(0xF0C5F2FF, AcceptInviteToGuildMsg.class, AcceptInviteToGuildHandler.class), // Accept guild invite KEEPALIVESERVERCLIENT(0x49EE129C, KeepAliveServerClientMsg.class, KeepAliveServerClientHandler.class), // Keep Alive LEADERBOARD(0x6F0C1386, LeaderboardMessage.class, null), - LEADERCHANNELMESSAGE(0x17b306f9, ChatLeaderMsg.class, AbstractChatMsgHandler.class), + LEADERCHANNELMESSAGE(0x17b306f9, ChatGlobalMsg.class, AbstractChatMsgHandler.class), LEAVEGROUP(0xD8037303, LeaveGroupMsg.class, LeaveGroupHandler.class), //Leave Group LEAVEGUILD(0x1801EA32, LeaveGuildMsg.class, LeaveGuildHandler.class), // Leave Guild LEAVEREQUEST(0xC79D775C, LeaveWorldMsg.class, LeaveWorldMsgHandler.class), //Client Request Leave World From 4fd1a1a14699f9a0ff34feb2bb04f75654faf84f Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 08:02:56 -0400 Subject: [PATCH 28/45] Handler created for AbstractChatMsg --- src/engine/net/client/handlers/AbstractChatMsgHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/net/client/handlers/AbstractChatMsgHandler.java b/src/engine/net/client/handlers/AbstractChatMsgHandler.java index 6b6e03d5..0b33adf0 100644 --- a/src/engine/net/client/handlers/AbstractChatMsgHandler.java +++ b/src/engine/net/client/handlers/AbstractChatMsgHandler.java @@ -79,9 +79,9 @@ public class AbstractChatMsgHandler extends AbstractClientMsgHandler { ChatManager.chatIC(playerCharacter, (ChatICMsg) msg); return true; case LEADERCHANNELMESSAGE: + case GLOBALCHANNELMESSAGE: ChatManager.chatGlobal(playerCharacter, msg.getMessage(), isFlood); return true; - case GLOBALCHANNELMESSAGE: case CHATPVP: case CHATCITY: case CHATINFO: From 7b909e1044ec74b6d47071af86c77d9baaa99a3d Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 08:03:56 -0400 Subject: [PATCH 29/45] Handler created for AbstractChatMsg --- src/engine/net/client/Protocol.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index c94ba080..9dd34cc6 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -125,7 +125,7 @@ public enum Protocol { JOINGUILD(0xF0C5F2FF, AcceptInviteToGuildMsg.class, AcceptInviteToGuildHandler.class), // Accept guild invite KEEPALIVESERVERCLIENT(0x49EE129C, KeepAliveServerClientMsg.class, KeepAliveServerClientHandler.class), // Keep Alive LEADERBOARD(0x6F0C1386, LeaderboardMessage.class, null), - LEADERCHANNELMESSAGE(0x17b306f9, ChatGlobalMsg.class, AbstractChatMsgHandler.class), + LEADERCHANNELMESSAGE(0x17b306f9, ChatLeaderMsg.class, AbstractChatMsgHandler.class), LEAVEGROUP(0xD8037303, LeaveGroupMsg.class, LeaveGroupHandler.class), //Leave Group LEAVEGUILD(0x1801EA32, LeaveGuildMsg.class, LeaveGuildHandler.class), // Leave Guild LEAVEREQUEST(0xC79D775C, LeaveWorldMsg.class, LeaveWorldMsgHandler.class), //Client Request Leave World From d7b18dc457e871d75b67d42898cbfc40265eb345 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 08:14:27 -0400 Subject: [PATCH 30/45] 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; From d4e38c113be5c17114b62b028860d41c0ddf1066 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 08:23:53 -0400 Subject: [PATCH 31/45] Handler created for AceeptTradeMsg --- src/engine/gameManager/TradeManager.java | 16 --- src/engine/net/client/ClientMessagePump.java | 3 - src/engine/net/client/Protocol.java | 2 +- .../AcceptTradeRequestMsgHandler.java | 129 ++++++++++++++++++ src/engine/objects/CharacterItemManager.java | 91 +----------- 5 files changed, 132 insertions(+), 109 deletions(-) create mode 100644 src/engine/net/client/handlers/AcceptTradeRequestMsgHandler.java diff --git a/src/engine/gameManager/TradeManager.java b/src/engine/gameManager/TradeManager.java index c90204c7..29ba69e3 100644 --- a/src/engine/gameManager/TradeManager.java +++ b/src/engine/gameManager/TradeManager.java @@ -22,22 +22,6 @@ public enum TradeManager { TRADEMANAGER; - public static void acceptTradeRequest(AcceptTradeRequestMsg msg, ClientConnection origin) { - - PlayerCharacter source = origin.getPlayerCharacter(); - - if (source == null) - return; - - try { - source.charItemManager.acceptTradeRequest(msg); - } catch (Exception e) { - Logger.error(e); - // TODO Auto-generated catch block - } - - } - public static void rejectTradeRequest(RejectTradeRequestMsg msg, ClientConnection origin) { // TODO Do nothing? If so, delete this method & case above } diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 27037d10..f8c05296 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 REQUESTTRADEOK: - TradeManager.acceptTradeRequest((AcceptTradeRequestMsg) msg, origin); - break; case REQUESTTRADECANCEL: TradeManager.rejectTradeRequest((RejectTradeRequestMsg) msg, origin); break; diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index f2343d4e..e5ec4fbf 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -179,7 +179,7 @@ public enum Protocol { REQUESTTOOPENBANK(0xF26E453F, null, null), // RequestToOpenBankMsg REQUESTTOTRADE(0x4D84259B, TradeRequestMsg.class, TradeRequestMsgHandler.class), // Trade Request REQUESTTRADECANCEL(0xCB0C5735, RejectTradeRequestMsg.class, null), // Reject RequestToTrade - REQUESTTRADEOK(0xFFD29841, AcceptTradeRequestMsg.class, null), // Accept Trade Request + REQUESTTRADEOK(0xFFD29841, AcceptTradeRequestMsg.class, AcceptTradeRequestMsgHandler.class), // Accept Trade Request RESETAFTERDEATH(0xFDCBB98F, RespawnMsg.class, RespawnMsgHandler.class), //Respawn Request/Response ROTATEMSG(0x57F2088E, RotateObjectMsg.class, null), SAFEMODE(0x9CF3922A, SafeModeMsg.class, null), //Tell client they're in safe mode diff --git a/src/engine/net/client/handlers/AcceptTradeRequestMsgHandler.java b/src/engine/net/client/handlers/AcceptTradeRequestMsgHandler.java new file mode 100644 index 00000000..5cc736b9 --- /dev/null +++ b/src/engine/net/client/handlers/AcceptTradeRequestMsgHandler.java @@ -0,0 +1,129 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// 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.AcceptTradeRequestMsg; +import engine.net.client.msg.ClientNetMsg; +import engine.net.client.msg.OpenTradeWindowMsg; +import engine.net.client.msg.UpdateVaultMsg; +import engine.objects.Account; +import engine.objects.CharacterItemManager; +import engine.objects.PlayerCharacter; +import engine.server.MBServerStatics; + +import static engine.math.FastMath.sqr; +import static engine.objects.CharacterItemManager.canTrade; + +public class AcceptTradeRequestMsgHandler extends AbstractClientMsgHandler { + + public AcceptTradeRequestMsgHandler() { + super(AcceptTradeRequestMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + // Member variable declaration + + AcceptTradeRequestMsg msg; + + // Member variable assignment + + msg = (AcceptTradeRequestMsg) baseMsg; + + PlayerCharacter source = (PlayerCharacter) origin.getPlayerCharacter(); + PlayerCharacter target = PlayerCharacter.getFromCache(msg.getTargetID()); + + Dispatch dispatch; + + if (source == null || !source.isAlive()) + return false; + + if (target == null || !target.isAlive()) + return false; + + if (source.charItemManager.tradingWith != null) + return false; + + if (!canTrade(source, target)) + return false; + + // verify characterTarget is in range + if (source.getLoc().distanceSquared2D(target.getLoc()) > sqr(MBServerStatics.TRADE_RANGE)) + return false; + + // TODO uncomment this block after we determine when we + // setBankOpen(false) and setVaultOpen(false) + /* + * CharacterItemManager cim1 = source.getCharItemManager(); + * CharacterItemManager cim2 = characterTarget.getCharItemManager(); if (cim1 == + * null) return false; if (cim2 == null) return false; if (cim1.isBankOpen()) + * return false; if (cim2.isVaultOpen()) return false; + */ + ClientConnection sourceConn = origin; + ClientConnection targetConn = target.getClientConnection(); + + if (sourceConn == null) + return false; + + if (targetConn == null) + return false; + + CharacterItemManager toTradeWith = target.charItemManager; + + if (toTradeWith == null) + return false; + + Account sourceAccount = source.getAccount(); + Account targetAccount = target.getAccount(); + + UpdateVaultMsg uvmSource = new UpdateVaultMsg(sourceAccount); + UpdateVaultMsg uvmTarget = new UpdateVaultMsg(targetAccount); + + dispatch = Dispatch.borrow(source, uvmSource); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); + + dispatch = Dispatch.borrow(target, uvmTarget); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); + + source.charItemManager.setVaultOpen(false); + toTradeWith.setVaultOpen(false); + source.charItemManager.setBankOpen(false); + toTradeWith.setBankOpen(false); + + OpenTradeWindowMsg otwm = new OpenTradeWindowMsg(msg.getUnknown01(), source, target); + + // Only start trade if both players aren't already trading with + // someone + + if (source.charItemManager.tradingWith != null || toTradeWith.getTradingWith() != null) + return false; + + source.charItemManager.initializeTrade(); + toTradeWith.initializeTrade(); + source.charItemManager.setTradingWith(targetConn); + toTradeWith.setTradingWith(sourceConn); + source.charItemManager.tradeID = msg.getUnknown01(); + toTradeWith.tradeID = msg.getUnknown01(); + + dispatch = Dispatch.borrow(source, otwm); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); + + dispatch = Dispatch.borrow(target, otwm); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); + + return true; + } + +} \ No newline at end of file diff --git a/src/engine/objects/CharacterItemManager.java b/src/engine/objects/CharacterItemManager.java index af4b5baa..fc07e1da 100644 --- a/src/engine/objects/CharacterItemManager.java +++ b/src/engine/objects/CharacterItemManager.java @@ -53,12 +53,12 @@ public class CharacterItemManager { private short inventoryWeight; private short equipWeight; private short vaultWeight; - private ClientConnection tradingWith; + public ClientConnection tradingWith; private byte tradeCommitted; private boolean tradeSuccess; private HashSet trading; private int goldTradingAmount; - private int tradeID = 0; + public int tradeID = 0; public CharacterItemManager(AbstractCharacter ac) { super(); @@ -444,93 +444,6 @@ public class CharacterItemManager { return true; } - public synchronized boolean acceptTradeRequest(AcceptTradeRequestMsg msg) { - - PlayerCharacter source = (PlayerCharacter) this.getOwner(); - PlayerCharacter target = PlayerCharacter.getFromCache(msg.getTargetID()); - - Dispatch dispatch; - - if (source == null || !source.isAlive()) - return false; - - if (target == null || !target.isAlive()) - return false; - - if (this.tradingWith != null) - return false; - - if (!canTrade(source, target)) - return false; - - // verify characterTarget is in range - if (source.getLoc().distanceSquared2D(target.getLoc()) > sqr(MBServerStatics.TRADE_RANGE)) - return false; - - // TODO uncomment this block after we determine when we - // setBankOpen(false) and setVaultOpen(false) - /* - * CharacterItemManager cim1 = source.getCharItemManager(); - * CharacterItemManager cim2 = characterTarget.getCharItemManager(); if (cim1 == - * null) return false; if (cim2 == null) return false; if (cim1.isBankOpen()) - * return false; if (cim2.isVaultOpen()) return false; - */ - ClientConnection sourceConn = source.getClientConnection(); - ClientConnection targetConn = target.getClientConnection(); - - if (sourceConn == null) - return false; - - if (targetConn == null) - return false; - - - CharacterItemManager toTradeWith = target.charItemManager; - - if (toTradeWith == null) - return false; - - Account sourceAccount = source.getAccount(); - Account targetAccount = target.getAccount(); - - UpdateVaultMsg uvmSource = new UpdateVaultMsg(sourceAccount); - UpdateVaultMsg uvmTarget = new UpdateVaultMsg(targetAccount); - - dispatch = Dispatch.borrow(source, uvmSource); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); - - dispatch = Dispatch.borrow(target, uvmTarget); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); - - this.setVaultOpen(false); - toTradeWith.setVaultOpen(false); - this.setBankOpen(false); - toTradeWith.setBankOpen(false); - - OpenTradeWindowMsg otwm = new OpenTradeWindowMsg(msg.getUnknown01(), source, target); - - // Only start trade if both players aren't already trading with - // someone - - if (this.getTradingWith() != null || toTradeWith.getTradingWith() != null) - return false; - - this.initializeTrade(); - toTradeWith.initializeTrade(); - this.setTradingWith(targetConn); - toTradeWith.setTradingWith(sourceConn); - this.tradeID = msg.getUnknown01(); - toTradeWith.tradeID = msg.getUnknown01(); - - dispatch = Dispatch.borrow(source, otwm); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); - - dispatch = Dispatch.borrow(target, otwm); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); - - return true; - } - public synchronized boolean addItemToTradeWindow(AddItemToTradeWindowMsg msg) { PlayerCharacter source = (PlayerCharacter) this.getOwner(); Dispatch dispatch; From a70585448f39c4eb3007414b9ad6eb1fceddf098 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 08:27:48 -0400 Subject: [PATCH 32/45] RejectTradeRequest has no handler --- src/engine/gameManager/TradeManager.java | 5 ----- src/engine/net/client/ClientMessagePump.java | 3 --- 2 files changed, 8 deletions(-) diff --git a/src/engine/gameManager/TradeManager.java b/src/engine/gameManager/TradeManager.java index 29ba69e3..9b19c7a8 100644 --- a/src/engine/gameManager/TradeManager.java +++ b/src/engine/gameManager/TradeManager.java @@ -21,11 +21,6 @@ public enum TradeManager { TRADEMANAGER; - - public static void rejectTradeRequest(RejectTradeRequestMsg msg, ClientConnection origin) { - // TODO Do nothing? If so, delete this method & case above - } - public static void addItemToTradeWindow(AddItemToTradeWindowMsg msg, ClientConnection origin) { diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index f8c05296..50028369 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 REQUESTTRADECANCEL: - TradeManager.rejectTradeRequest((RejectTradeRequestMsg) msg, origin); - break; case TRADEADDOBJECT: TradeManager.addItemToTradeWindow((AddItemToTradeWindowMsg) msg, origin); break; From 3f1385dd33ccf4aa8ee86b967dc6391584a1a008 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 08:34:29 -0400 Subject: [PATCH 33/45] Handler created for AddItemToTradeWindowMsg --- src/engine/gameManager/TradeManager.java | 15 --- src/engine/net/client/ClientMessagePump.java | 3 - src/engine/net/client/Protocol.java | 2 +- .../AddItemToTradeWindowMsgHandler.java | 106 ++++++++++++++++++ src/engine/objects/CharacterItemManager.java | 67 +---------- 5 files changed, 108 insertions(+), 85 deletions(-) create mode 100644 src/engine/net/client/handlers/AddItemToTradeWindowMsgHandler.java diff --git a/src/engine/gameManager/TradeManager.java b/src/engine/gameManager/TradeManager.java index 9b19c7a8..1355aad2 100644 --- a/src/engine/gameManager/TradeManager.java +++ b/src/engine/gameManager/TradeManager.java @@ -21,21 +21,6 @@ public enum TradeManager { TRADEMANAGER; - public static void addItemToTradeWindow(AddItemToTradeWindowMsg msg, ClientConnection origin) { - - - PlayerCharacter source = origin.getPlayerCharacter(); - if (source == null || !source.isAlive()) - return; - try { - source.charItemManager.addItemToTradeWindow(msg); - - } catch (Exception e) { - Logger.error(e); - } - - } - public static void addGoldToTradeWindow(AddGoldToTradeWindowMsg msg, ClientConnection origin) { PlayerCharacter source = origin.getPlayerCharacter(); diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 50028369..06b610a9 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 TRADEADDOBJECT: - TradeManager.addItemToTradeWindow((AddItemToTradeWindowMsg) msg, origin); - break; case TRADEADDGOLD: TradeManager.addGoldToTradeWindow((AddGoldToTradeWindowMsg) msg, origin); break; diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index e5ec4fbf..18dff99a 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -212,7 +212,7 @@ public enum Protocol { TERRITORYCHANGE(0x6B388C8C, TerritoryChangeMessage.class, null), //Hey rich, look what I found? :) TOGGLESITSTAND(0x624F3C0F, ToggleSitStandMsg.class, ToggleSitStandMsgHandler.class), //Toggle Sit/Stand TRADEADDGOLD(0x654ACB45, AddGoldToTradeWindowMsg.class, null), // Add Gold to Trade Window - TRADEADDOBJECT(0x55D363E9, AddItemToTradeWindowMsg.class, null), // Add an Item to the 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 TRADECONFIRM(0x6911E65E, CommitToTradeMsg.class, null), // Commit to trade TRADECONFIRMSTATUS(0x9F85DAFC, null, null), // Other player commit/uncommit/add item diff --git a/src/engine/net/client/handlers/AddItemToTradeWindowMsgHandler.java b/src/engine/net/client/handlers/AddItemToTradeWindowMsgHandler.java new file mode 100644 index 00000000..40d09e5a --- /dev/null +++ b/src/engine/net/client/handlers/AddItemToTradeWindowMsgHandler.java @@ -0,0 +1,106 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// 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.AddItemToTradeWindowMsg; +import engine.net.client.msg.ClientNetMsg; +import engine.net.client.msg.UpdateTradeWindowMsg; +import engine.objects.CharacterItemManager; +import engine.objects.Item; +import engine.objects.PlayerCharacter; + +import static engine.objects.CharacterItemManager.canTrade; + +public class AddItemToTradeWindowMsgHandler extends AbstractClientMsgHandler { + + public AddItemToTradeWindowMsgHandler() { + super(AddItemToTradeWindowMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + // Member variable declaration + + AddItemToTradeWindowMsg msg; + + // Member variable assignment + + msg = (AddItemToTradeWindowMsg) baseMsg; + + PlayerCharacter source = origin.getPlayerCharacter(); + Dispatch dispatch; + + if (source == null || !source.isAlive()) + return false; + + ClientConnection ccOther = source.charItemManager.tradingWith; + + if (ccOther == null) + return false; + + PlayerCharacter other = ccOther.getPlayerCharacter(); + + if (other == null || !other.isAlive()) + return false; + + CharacterItemManager tradingWith = other.charItemManager; + + if (tradingWith == null) + return false; + + if (!canTrade(source, other)) + return false; + + Item item = Item.getFromCache(msg.getItemID()); + + if (item == null) + return false; + + if (!source.charItemManager.doesCharOwnThisItem(item.getObjectUUID())) + return false; + + //can't add item to trade window twice + if (source.charItemManager.tradingContains(item)) + return false; + + //dupe check + if (!item.validForInventory(source.getClientConnection(), source, source.charItemManager)) + return false; + + if (!tradingWith.hasRoomTrade(item.template.item_wt)) { + dispatch = Dispatch.borrow(source, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); + return false; + } + + UpdateTradeWindowMsg utwm = new UpdateTradeWindowMsg(source, other); + + source.charItemManager.setTradeCommitted((byte) 0); + tradingWith.setTradeCommitted((byte) 0); + + source.charItemManager.addItemToTrade(item); + + dispatch = Dispatch.borrow(other, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); + + source.charItemManager.modifyCommitToTrade(); + + dispatch = Dispatch.borrow(other, utwm); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); + + return true; + } + +} \ No newline at end of file diff --git a/src/engine/objects/CharacterItemManager.java b/src/engine/objects/CharacterItemManager.java index fc07e1da..5e4b3bdd 100644 --- a/src/engine/objects/CharacterItemManager.java +++ b/src/engine/objects/CharacterItemManager.java @@ -444,71 +444,6 @@ public class CharacterItemManager { return true; } - public synchronized boolean addItemToTradeWindow(AddItemToTradeWindowMsg msg) { - PlayerCharacter source = (PlayerCharacter) this.getOwner(); - Dispatch dispatch; - - if (source == null || !source.isAlive()) - return false; - - - ClientConnection ccOther = this.getTradingWith(); - - if (ccOther == null) - return false; - - PlayerCharacter other = ccOther.getPlayerCharacter(); - - if (other == null || !other.isAlive()) - return false; - - CharacterItemManager tradingWith = other.charItemManager; - - if (tradingWith == null) - return false; - - if (!canTrade(source, other)) - return false; - - Item i = Item.getFromCache(msg.getItemID()); - - if (i == null) - return false; - - if (!this.doesCharOwnThisItem(i.getObjectUUID())) - return false; - - //can't add item to trade window twice - if (this.tradingContains(i)) - return false; - - //dupe check - if (!i.validForInventory(source.getClientConnection(), source, this)) - return false; - - if (!tradingWith.hasRoomTrade(i.template.item_wt)) { - dispatch = Dispatch.borrow(source, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); - return false; - } - - UpdateTradeWindowMsg utwm = new UpdateTradeWindowMsg(source, other); - - this.setTradeCommitted((byte) 0); - tradingWith.setTradeCommitted((byte) 0); - - this.addItemToTrade(i); - - dispatch = Dispatch.borrow(other, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); - - modifyCommitToTrade(); - - dispatch = Dispatch.borrow(other, utwm); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.PRIMARY); - return true; - } - public synchronized boolean addGoldToTradeWindow(AddGoldToTradeWindowMsg msg) { PlayerCharacter source = (PlayerCharacter) this.getOwner(); @@ -648,7 +583,7 @@ public class CharacterItemManager { return true; } - private synchronized boolean modifyCommitToTrade() { + public synchronized boolean modifyCommitToTrade() { CharacterItemManager man1 = this; if (this.getTradingWith() == null) From 3a2b138deb0e5ccf3634fdc2e2a56f6f80facc0c Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 08:39:49 -0400 Subject: [PATCH 34/45] Handler created for AddGoldToTradeWindowMsg --- src/engine/gameManager/TradeManager.java | 25 +--- src/engine/net/client/ClientMessagePump.java | 3 - src/engine/net/client/Protocol.java | 2 +- .../AddGoldToTradeWindowMsgHandler.java | 109 ++++++++++++++++++ src/engine/objects/CharacterItemManager.java | 68 ----------- 5 files changed, 114 insertions(+), 93 deletions(-) create mode 100644 src/engine/net/client/handlers/AddGoldToTradeWindowMsgHandler.java diff --git a/src/engine/gameManager/TradeManager.java b/src/engine/gameManager/TradeManager.java index 1355aad2..ba5e524d 100644 --- a/src/engine/gameManager/TradeManager.java +++ b/src/engine/gameManager/TradeManager.java @@ -12,7 +12,10 @@ import engine.Enum; import engine.net.Dispatch; import engine.net.DispatchMessage; import engine.net.client.ClientConnection; -import engine.net.client.msg.*; +import engine.net.client.msg.CloseTradeWindowMsg; +import engine.net.client.msg.CommitToTradeMsg; +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; @@ -21,26 +24,6 @@ public enum TradeManager { TRADEMANAGER; - public static void addGoldToTradeWindow(AddGoldToTradeWindowMsg msg, ClientConnection origin) { - - PlayerCharacter source = origin.getPlayerCharacter(); - - if (source == null || !source.isAlive()) - return; - - - CharacterItemManager sourceItemMan = source.charItemManager; - - if (sourceItemMan == null) - return; - - try { - sourceItemMan.addGoldToTradeWindow(msg); - } catch (Exception e) { - Logger.error(e); - } - } - public static void commitToTrade(CommitToTradeMsg msg, ClientConnection origin) { PlayerCharacter source = origin.getPlayerCharacter(); diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 06b610a9..89260301 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 TRADEADDGOLD: - TradeManager.addGoldToTradeWindow((AddGoldToTradeWindowMsg) msg, origin); - break; case TRADECONFIRM: TradeManager.commitToTrade((CommitToTradeMsg) msg, origin); break; diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index 18dff99a..5d7775ec 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -211,7 +211,7 @@ public enum Protocol { TELEPORT(0x23E726EA, TeleportToPointMsg.class, null), // Teleport to point TERRITORYCHANGE(0x6B388C8C, TerritoryChangeMessage.class, null), //Hey rich, look what I found? :) TOGGLESITSTAND(0x624F3C0F, ToggleSitStandMsg.class, ToggleSitStandMsgHandler.class), //Toggle Sit/Stand - TRADEADDGOLD(0x654ACB45, AddGoldToTradeWindowMsg.class, null), // Add Gold to Trade Window + 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 TRADECONFIRM(0x6911E65E, CommitToTradeMsg.class, null), // Commit to trade diff --git a/src/engine/net/client/handlers/AddGoldToTradeWindowMsgHandler.java b/src/engine/net/client/handlers/AddGoldToTradeWindowMsgHandler.java new file mode 100644 index 00000000..414e1bc5 --- /dev/null +++ b/src/engine/net/client/handlers/AddGoldToTradeWindowMsgHandler.java @@ -0,0 +1,109 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// 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.AddGoldToTradeWindowMsg; +import engine.net.client.msg.ClientNetMsg; +import engine.net.client.msg.UpdateGoldMsg; +import engine.net.client.msg.UpdateTradeWindowMsg; +import engine.objects.CharacterItemManager; +import engine.objects.PlayerCharacter; +import engine.server.MBServerStatics; +import org.pmw.tinylog.Logger; + +import static engine.objects.CharacterItemManager.canTrade; + +public class AddGoldToTradeWindowMsgHandler extends AbstractClientMsgHandler { + + public AddGoldToTradeWindowMsgHandler() { + super(AddGoldToTradeWindowMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter source = origin.getPlayerCharacter(); + + // Member variable declaration + + AddGoldToTradeWindowMsg msg; + + // Member variable assignment + + msg = (AddGoldToTradeWindowMsg) baseMsg; + Dispatch dispatch; + + if (source == null || !source.isAlive()) + return false; + + ClientConnection ccOther = source.charItemManager.tradingWith; + + if (ccOther == null) + return false; + + PlayerCharacter other = ccOther.getPlayerCharacter(); + + if (other == null || !other.isAlive()) + return false; + + CharacterItemManager tradingWith = other.charItemManager; + + if (tradingWith == null) + return false; + + UpdateTradeWindowMsg utwm = new UpdateTradeWindowMsg(other, source); + UpdateTradeWindowMsg utwmOther = new UpdateTradeWindowMsg(source, other); + + if (!canTrade(source, other)) + return false; + + source.charItemManager.setTradeCommitted((byte) 0); + tradingWith.setTradeCommitted((byte) 0); + + int amt = msg.getAmount(); + + if (amt <= 0) { + Logger.info(source.getFirstName() + " added negative gold to trade window. Dupe attempt FAILED!"); + return false; + } + + if (amt > MBServerStatics.PLAYER_GOLD_LIMIT) + return false; + + if (source.charItemManager.getGoldInventory().getNumOfItems() - amt < 0) + return false; + + source.charItemManager.addGoldToTrade(amt); + + // BONUS CODE BELOW: Thanks some unknown retard! + // sourceItemMan.updateInventory(sourceItemMan.getInventory(), true); + + UpdateGoldMsg ugm = new UpdateGoldMsg(source); + ugm.configure(); + + source.charItemManager.modifyCommitToTrade(); + + dispatch = Dispatch.borrow(source, utwm); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + + dispatch = Dispatch.borrow(source, ugm); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + + dispatch = Dispatch.borrow(other, utwmOther); + 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 5e4b3bdd..50e98e80 100644 --- a/src/engine/objects/CharacterItemManager.java +++ b/src/engine/objects/CharacterItemManager.java @@ -444,74 +444,6 @@ public class CharacterItemManager { return true; } - public synchronized boolean addGoldToTradeWindow(AddGoldToTradeWindowMsg msg) { - - PlayerCharacter source = (PlayerCharacter) this.getOwner(); - Dispatch dispatch; - - if (source == null || !source.isAlive()) - return false; - - - ClientConnection ccOther = this.getTradingWith(); - - if (ccOther == null) - return false; - - PlayerCharacter other = ccOther.getPlayerCharacter(); - - if (other == null || !other.isAlive()) - return false; - - CharacterItemManager tradingWith = other.charItemManager; - - if (tradingWith == null) - return false; - - UpdateTradeWindowMsg utwm = new UpdateTradeWindowMsg(other, source); - UpdateTradeWindowMsg utwmOther = new UpdateTradeWindowMsg(source, other); - - if (!canTrade(source, other)) - return false; - - this.setTradeCommitted((byte) 0); - tradingWith.setTradeCommitted((byte) 0); - - int amt = msg.getAmount(); - - if (amt <= 0) { - Logger.info(source.getFirstName() + " added negative gold to trade window. Dupe attempt FAILED!"); - return false; - } - - if (amt > MBServerStatics.PLAYER_GOLD_LIMIT) - return false; - - if (this.getGoldInventory().getNumOfItems() - amt < 0) - return false; - - this.addGoldToTrade(amt); - - // BONUS CODE BELOW: Thanks some unknown retard! - // sourceItemMan.updateInventory(sourceItemMan.getInventory(), true); - - UpdateGoldMsg ugm = new UpdateGoldMsg(source); - ugm.configure(); - - modifyCommitToTrade(); - - dispatch = Dispatch.borrow(source, utwm); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - - dispatch = Dispatch.borrow(source, ugm); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - - dispatch = Dispatch.borrow(other, utwmOther); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - return true; - - } - public synchronized boolean uncommitToTrade(UncommitToTradeMsg msg) { PlayerCharacter source = (PlayerCharacter) this.getOwner(); From 2768980f6ee2828bdd078ba575e5da3f3b279cfc Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 08:44:12 -0400 Subject: [PATCH 35/45] Handler created for CommitToTradeMsg --- src/engine/gameManager/TradeManager.java | 22 ------ src/engine/net/client/ClientMessagePump.java | 8 +- src/engine/net/client/Protocol.java | 2 +- .../handlers/CommitToTradeMsgHandler.java | 77 +++++++++++++++++++ src/engine/objects/CharacterItemManager.java | 41 ---------- 5 files changed, 82 insertions(+), 68 deletions(-) create mode 100644 src/engine/net/client/handlers/CommitToTradeMsgHandler.java diff --git a/src/engine/gameManager/TradeManager.java b/src/engine/gameManager/TradeManager.java index ba5e524d..c8846855 100644 --- a/src/engine/gameManager/TradeManager.java +++ b/src/engine/gameManager/TradeManager.java @@ -13,7 +13,6 @@ import engine.net.Dispatch; import engine.net.DispatchMessage; import engine.net.client.ClientConnection; import engine.net.client.msg.CloseTradeWindowMsg; -import engine.net.client.msg.CommitToTradeMsg; import engine.net.client.msg.InvalidTradeRequestMsg; import engine.net.client.msg.UncommitToTradeMsg; import engine.objects.CharacterItemManager; @@ -24,26 +23,6 @@ public enum TradeManager { TRADEMANAGER; - public static void commitToTrade(CommitToTradeMsg msg, ClientConnection origin) { - - PlayerCharacter source = origin.getPlayerCharacter(); - - if (source == null || !source.isAlive()) - return; - - CharacterItemManager sourceItemMan = source.charItemManager; - - if (sourceItemMan == null) - return; - - try { - sourceItemMan.commitToTrade(msg); - } catch (Exception e) { - // TODO Auto-generated catch block - Logger.error(e); - } - } - public static void uncommitToTrade(UncommitToTradeMsg msg, ClientConnection origin) { PlayerCharacter source = origin.getPlayerCharacter(); @@ -65,7 +44,6 @@ public enum TradeManager { } - 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 89260301..194b2c96 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -13,7 +13,10 @@ import engine.gameManager.SessionManager; import engine.gameManager.TradeManager; import engine.net.NetMsgHandler; import engine.net.client.handlers.AbstractClientMsgHandler; -import engine.net.client.msg.*; +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; @@ -73,9 +76,6 @@ public class ClientMessagePump implements NetMsgHandler { break; case OPENVAULT: break; - case TRADECONFIRM: - TradeManager.commitToTrade((CommitToTradeMsg) msg, origin); - break; case TRADEUNCONFIRM: TradeManager.uncommitToTrade((UncommitToTradeMsg) msg, origin); break; diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index 5d7775ec..38b7f3e5 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -214,7 +214,7 @@ public enum Protocol { 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 - TRADECONFIRM(0x6911E65E, CommitToTradeMsg.class, null), // Commit to trade + 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 TRAINERLIST(0x41FABA62, TrainerInfoMsg.class, TrainerInfoMsgHandler.class), //Req/Send Trainer Info/Pricing diff --git a/src/engine/net/client/handlers/CommitToTradeMsgHandler.java b/src/engine/net/client/handlers/CommitToTradeMsgHandler.java new file mode 100644 index 00000000..81e890ae --- /dev/null +++ b/src/engine/net/client/handlers/CommitToTradeMsgHandler.java @@ -0,0 +1,77 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// 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.CloseTradeWindowMsg; +import engine.net.client.msg.CommitToTradeMsg; +import engine.objects.CharacterItemManager; +import engine.objects.PlayerCharacter; + +import static engine.objects.CharacterItemManager.canTrade; + +public class CommitToTradeMsgHandler extends AbstractClientMsgHandler { + + public CommitToTradeMsgHandler() { + super(CommitToTradeMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter source = origin.getPlayerCharacter(); + + // Member variable declaration + + CommitToTradeMsg msg; + + // Member variable assignment + + msg = (CommitToTradeMsg) baseMsg; + + if (source == null || !source.isAlive()) + return false; + + source.charItemManager.setTradeCommitted((byte) 1); + + ClientConnection ccOther = source.charItemManager.tradingWith; + + if (ccOther == null) + return false; + + PlayerCharacter other = ccOther.getPlayerCharacter(); + + if (other == null || !other.isAlive()) + return false; + + CharacterItemManager tradingWith = other.charItemManager; + + if (tradingWith == null) + return false; + + if (!canTrade(source, other)) + return false; + + source.charItemManager.modifyCommitToTrade(); + + if (source.charItemManager.getTradeCommitted() == (byte) 1 && tradingWith.getTradeCommitted() == (byte) 1) { + int tradeID = source.charItemManager.tradeID; + CloseTradeWindowMsg ctwm1 = new CloseTradeWindowMsg(source, tradeID); + CloseTradeWindowMsg ctwm2 = new CloseTradeWindowMsg(other, tradeID); + source.charItemManager.commitTrade(); + source.charItemManager.closeTradeWindow(ctwm1, false); + other.charItemManager.closeTradeWindow(ctwm2, false); + } + + return true; + } + +} \ No newline at end of file diff --git a/src/engine/objects/CharacterItemManager.java b/src/engine/objects/CharacterItemManager.java index 50e98e80..ca2fdda8 100644 --- a/src/engine/objects/CharacterItemManager.java +++ b/src/engine/objects/CharacterItemManager.java @@ -474,47 +474,6 @@ public class CharacterItemManager { return modifyCommitToTrade(); } - public synchronized boolean commitToTrade(CommitToTradeMsg msg) { - - PlayerCharacter source = (PlayerCharacter) this.getOwner(); - - if (source == null || !source.isAlive()) - return false; - - - this.setTradeCommitted((byte) 1); - - ClientConnection ccOther = this.getTradingWith(); - - if (ccOther == null) - return false; - - PlayerCharacter other = ccOther.getPlayerCharacter(); - - if (other == null || !other.isAlive()) - return false; - - CharacterItemManager tradingWith = other.charItemManager; - - if (tradingWith == null) - return false; - - if (!canTrade(source, other)) - return false; - - modifyCommitToTrade(); - - if (this.getTradeCommitted() == (byte) 1 && tradingWith.getTradeCommitted() == (byte) 1) { - int tradeID = this.tradeID; - CloseTradeWindowMsg ctwm1 = new CloseTradeWindowMsg(source, tradeID); - CloseTradeWindowMsg ctwm2 = new CloseTradeWindowMsg(other, tradeID); - this.commitTrade(); - this.closeTradeWindow(ctwm1, false); - other.charItemManager.closeTradeWindow(ctwm2, false); - } - return true; - } - public synchronized boolean modifyCommitToTrade() { CharacterItemManager man1 = this; From 5f16289052d3e7e6a15d75c71db45410efa6be81 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 08:48:43 -0400 Subject: [PATCH 36/45] Handler created for UnCommitToTradeMsg --- src/engine/gameManager/TradeManager.java | 22 ------ src/engine/net/client/ClientMessagePump.java | 4 -- src/engine/net/client/Protocol.java | 2 +- .../handlers/UncommitToTradeMsgHandler.java | 67 +++++++++++++++++++ src/engine/objects/CharacterItemManager.java | 30 --------- 5 files changed, 68 insertions(+), 57 deletions(-) create mode 100644 src/engine/net/client/handlers/UncommitToTradeMsgHandler.java 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; From 8cd613c5975381e1c2f50567e0190e1d0837256d Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 08:55:22 -0400 Subject: [PATCH 37/45] 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 From 019c254ac1eee0b183babb4102308f37bcc591ac Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 08:58:31 -0400 Subject: [PATCH 38/45] Handler created for InvalidTradeRequestMsg --- src/engine/gameManager/TradeManager.java | 13 ----- src/engine/net/client/ClientMessagePump.java | 5 -- src/engine/net/client/Protocol.java | 2 +- .../InvalidTradeRequestMsgHandler.java | 47 +++++++++++++++++++ 4 files changed, 48 insertions(+), 19 deletions(-) create mode 100644 src/engine/net/client/handlers/InvalidTradeRequestMsgHandler.java diff --git a/src/engine/gameManager/TradeManager.java b/src/engine/gameManager/TradeManager.java index dbb13513..95f8dd79 100644 --- a/src/engine/gameManager/TradeManager.java +++ b/src/engine/gameManager/TradeManager.java @@ -8,22 +8,9 @@ package engine.gameManager; -import engine.Enum; -import engine.net.Dispatch; -import engine.net.DispatchMessage; -import engine.net.client.msg.InvalidTradeRequestMsg; -import engine.objects.PlayerCharacter; - public enum TradeManager { TRADEMANAGER; - public static void invalidTradeRequest(InvalidTradeRequestMsg msg) { - PlayerCharacter requester = PlayerCharacter.getFromCache(msg.getRequesterID()); - Dispatch dispatch; - - dispatch = Dispatch.borrow(requester, msg); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - } } \ No newline at end of file diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 445413da..d2be335d 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -10,11 +10,9 @@ package engine.net.client; import engine.gameManager.SessionManager; -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.InvalidTradeRequestMsg; import engine.server.world.WorldServer; import engine.session.Session; import engine.util.StringUtils; @@ -74,9 +72,6 @@ public class ClientMessagePump implements NetMsgHandler { break; case OPENVAULT: break; - case ARCREQUESTTRADEBUSY: - TradeManager.invalidTradeRequest((InvalidTradeRequestMsg) msg); - break; case CHANNELMUTE: break; case KEEPALIVESERVERCLIENT: diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index 7ba3b560..3c68e34f 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -41,7 +41,7 @@ public enum Protocol { ARCPETCMD(0x4E80E001, PetCmdMsg.class, PetCmdMsgHandler.class), // Stop ArcPetAttack, Toggle Assist, Toggle Rest ARCPOWERPROJECTILE(0xA2312D3B, null, null), ARCPROMPTRECALL(0xE3196B6E, PromptRecallMsg.class, PromptRecallMsgHandler.class), //Recall Prompt - ARCREQUESTTRADEBUSY(0xD4BAB4DF, InvalidTradeRequestMsg.class, null), // Attempt trade with someone who is already trading + ARCREQUESTTRADEBUSY(0xD4BAB4DF, InvalidTradeRequestMsg.class, InvalidTradeRequestMsgHandler.class), // Attempt trade with someone who is already trading ARCSERVERSTATUS(0x87BA4462, null, null), //Update Server Status ARCSIEGESPIRE(0x36A49BC6, ArcSiegeSpireMsg.class, ArcSiegeSpireMsgHandler.class), // Activate/Deactivate Spires ARCSUMMON(0xFD816A0A, RecvSummonsMsg.class, RecvSummonsMsgHandler.class), // Suspect Recv Summons Request diff --git a/src/engine/net/client/handlers/InvalidTradeRequestMsgHandler.java b/src/engine/net/client/handlers/InvalidTradeRequestMsgHandler.java new file mode 100644 index 00000000..ea6bcc9d --- /dev/null +++ b/src/engine/net/client/handlers/InvalidTradeRequestMsgHandler.java @@ -0,0 +1,47 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// 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.InvalidTradeRequestMsg; +import engine.objects.PlayerCharacter; + +public class InvalidTradeRequestMsgHandler extends AbstractClientMsgHandler { + + public InvalidTradeRequestMsgHandler() { + super(InvalidTradeRequestMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter playerCharacter = origin.getPlayerCharacter(); + + // Member variable declaration + + InvalidTradeRequestMsg msg; + + // Member variable assignment + + msg = (InvalidTradeRequestMsg) baseMsg; + + Dispatch dispatch; + + dispatch = Dispatch.borrow(playerCharacter, msg); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + + return true; + } + +} \ No newline at end of file From 7526cc808c1222c2d72bdb9b7bb0b88e0d661942 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 08:59:14 -0400 Subject: [PATCH 39/45] TradeManager removed --- src/engine/gameManager/TradeManager.java | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 src/engine/gameManager/TradeManager.java diff --git a/src/engine/gameManager/TradeManager.java b/src/engine/gameManager/TradeManager.java deleted file mode 100644 index 95f8dd79..00000000 --- a/src/engine/gameManager/TradeManager.java +++ /dev/null @@ -1,16 +0,0 @@ -// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . -// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· -// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ -// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ -// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ -// Magicbane Emulator Project © 2013 - 2022 -// www.magicbane.com - -package engine.gameManager; - -public enum TradeManager { - - TRADEMANAGER; - - -} \ No newline at end of file From 25ab3747eb940c577bd0cb18de8c0942c63fa3f9 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 10:07:33 -0400 Subject: [PATCH 40/45] Handler written for protocol class --- src/engine/net/client/Protocol.java | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index 3c68e34f..4c7a727b 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -286,6 +286,33 @@ public enum Protocol { } } + public static boolean handleClientMsg(ClientNetMsg msg) { + + if (msg == null) + return false; + + try { + + Protocol protocol = msg.getProtocolMsg(); + + // Unhandled opcode + + if (protocol == null) + return true; + + AbstractClientMsgHandler msgHandler = protocol.handler; + + if (msgHandler == null) + return true; + + } catch (Exception e) { + Logger.error("handler for " + msg.getProtocolMsg() + " failed: " + e); + return false; + } + + return true; + } + public static Protocol getByOpcode(int opcode) { Protocol protocol = _protocolMsgByOpcode.get(opcode); From 0e431aa72626de0b84b18e8e9ac01221b51cbb53 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 10:08:11 -0400 Subject: [PATCH 41/45] Handler written for protocol class --- src/engine/net/client/Protocol.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index 4c7a727b..1417451e 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -302,6 +302,8 @@ public enum Protocol { AbstractClientMsgHandler msgHandler = protocol.handler; + // Eat this message; no or empty handler + if (msgHandler == null) return true; From cfc36c0c27ea2e67314b1982a6b2579c88075bf9 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 13:23:56 -0400 Subject: [PATCH 42/45] Equipslot stored as string --- src/engine/db/handlers/dbItemHandler.java | 5 ++++- src/engine/objects/Item.java | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/engine/db/handlers/dbItemHandler.java b/src/engine/db/handlers/dbItemHandler.java index e21f87da..117b3602 100644 --- a/src/engine/db/handlers/dbItemHandler.java +++ b/src/engine/db/handlers/dbItemHandler.java @@ -92,7 +92,10 @@ public class dbItemHandler extends dbHandlerBase { break; } - preparedStatement.setByte(7, (byte) toAdd.equipSlot.ordinal()); + if (toAdd.equipSlot.equals(Enum.EquipSlotType.NONE)) + preparedStatement.setString(7, ""); + else + preparedStatement.setString(7, toAdd.equipSlot.name()); String flagString = ""; diff --git a/src/engine/objects/Item.java b/src/engine/objects/Item.java index dbe828d3..8b3c3e12 100644 --- a/src/engine/objects/Item.java +++ b/src/engine/objects/Item.java @@ -147,7 +147,12 @@ public class Item extends AbstractWorldObject { this.canDestroy = true; - this.equipSlot = EquipSlotType.values()[rs.getByte("equipSlot")]; + String equipString = rs.getString("equipSlot"); + + if (equipString.isEmpty()) + this.equipSlot = EquipSlotType.NONE; + else + this.equipSlot = EquipSlotType.valueOf(equipString); this.numberOfItems = rs.getInt("numberOfItems"); From 2f3b9e0fb2859e3f74d00d849940124fe52012d1 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 15:26:44 -0400 Subject: [PATCH 43/45] Uppercase for source type --- src/engine/db/handlers/dbPowerHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/db/handlers/dbPowerHandler.java b/src/engine/db/handlers/dbPowerHandler.java index e9714afe..98908f31 100644 --- a/src/engine/db/handlers/dbPowerHandler.java +++ b/src/engine/db/handlers/dbPowerHandler.java @@ -40,7 +40,7 @@ public class dbPowerHandler extends dbHandlerBase { IDString = rs.getString("IDString"); int token = DbManager.hasher.SBStringHash(IDString); - source = rs.getString("source").replace("-", "").trim(); + source = rs.getString("source").replace("-", "").toUpperCase().trim(); Enum.EffectSourceType effectSourceType = Enum.EffectSourceType.GetEffectSourceType(source); if (EffectsBase.effectSourceTypeMap.containsKey(token) == false) From f682f9a5ae89218f98ea65b7283d74b7608a182c Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 15:28:01 -0400 Subject: [PATCH 44/45] Uppercase for source type --- src/engine/Enum.java | 2 +- src/engine/db/handlers/dbPowerHandler.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/engine/Enum.java b/src/engine/Enum.java index ef9d5177..3d250c38 100644 --- a/src/engine/Enum.java +++ b/src/engine/Enum.java @@ -945,7 +945,7 @@ public class Enum { return EffectSourceType.None; try { - returnMod = EffectSourceType.valueOf(modName.replace(",", "")); + returnMod = EffectSourceType.valueOf(modName.replace(",", "").toUpperCase()); } catch (Exception e) { Logger.error(e); return EffectSourceType.None; diff --git a/src/engine/db/handlers/dbPowerHandler.java b/src/engine/db/handlers/dbPowerHandler.java index 98908f31..e9714afe 100644 --- a/src/engine/db/handlers/dbPowerHandler.java +++ b/src/engine/db/handlers/dbPowerHandler.java @@ -40,7 +40,7 @@ public class dbPowerHandler extends dbHandlerBase { IDString = rs.getString("IDString"); int token = DbManager.hasher.SBStringHash(IDString); - source = rs.getString("source").replace("-", "").toUpperCase().trim(); + source = rs.getString("source").replace("-", "").trim(); Enum.EffectSourceType effectSourceType = Enum.EffectSourceType.GetEffectSourceType(source); if (EffectsBase.effectSourceTypeMap.containsKey(token) == false) From 52d37296a7fc4dbe706f771fc110ad18efe89e65 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 15:31:32 -0400 Subject: [PATCH 45/45] Uppercase for source type --- src/engine/Enum.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/Enum.java b/src/engine/Enum.java index 3d250c38..ef9d5177 100644 --- a/src/engine/Enum.java +++ b/src/engine/Enum.java @@ -945,7 +945,7 @@ public class Enum { return EffectSourceType.None; try { - returnMod = EffectSourceType.valueOf(modName.replace(",", "").toUpperCase()); + returnMod = EffectSourceType.valueOf(modName.replace(",", "")); } catch (Exception e) { Logger.error(e); return EffectSourceType.None;