From 80c11db80b2d098bd2b3b0d26d7d23f93db3c4c9 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 29 Mar 2024 06:14:19 -0400 Subject: [PATCH] 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();