From b90b8ca42249626509c3f8d4b1765f3faae4abd0 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sat, 21 Jan 2023 10:11:28 -0500 Subject: [PATCH] Protocol handler created for ArcMineChangeProductionMsg. --- src/engine/net/client/Protocol.java | 2 +- .../ArcMineChangeProductionMsgHandler.java | 69 +++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 src/engine/net/client/handlers/ArcMineChangeProductionMsgHandler.java diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index 121acdcc..6eee1d13 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -33,7 +33,7 @@ public enum Protocol { 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 - ARCMINECHANGEPRODUCTION(0x1EAA993F, ArcMineChangeProductionMsg.class, null), + ARCMINECHANGEPRODUCTION(0x1EAA993F, ArcMineChangeProductionMsg.class, ArcMineChangeProductionMsgHandler.class), ARCMINETOWERCRESTUPDATE(0x34164D0D, null, null), ARCMINEWINDOWAVAILABLETIME(0x6C909DE7, ArcMineWindowAvailableTimeMsg.class, ArcMineWindowAvailableTimeHandler.class), ARCMINEWINDOWCHANGE(0x92B2148A, ArcMineWindowChangeMsg.class, MineWindowChangeHandler.class), diff --git a/src/engine/net/client/handlers/ArcMineChangeProductionMsgHandler.java b/src/engine/net/client/handlers/ArcMineChangeProductionMsgHandler.java new file mode 100644 index 00000000..c2198b7e --- /dev/null +++ b/src/engine/net/client/handlers/ArcMineChangeProductionMsgHandler.java @@ -0,0 +1,69 @@ +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.ArcMineChangeProductionMsg; +import engine.net.client.msg.ClientNetMsg; +import engine.net.client.msg.KeepAliveServerClientMsg; +import engine.objects.GuildStatusController; +import engine.objects.Mine; +import engine.objects.PlayerCharacter; +import engine.objects.Resource; + +/* + * @Author: + * @Summary: Processes application protocol message which keeps + * client's tcp connection open. + */ + +public class ArcMineChangeProductionMsgHandler extends AbstractClientMsgHandler { + + public ArcMineChangeProductionMsgHandler() { + super(ArcMineChangeProductionMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + PlayerCharacter playerCharacter = origin.getPlayerCharacter(); + ArcMineChangeProductionMsg changeProductionMsg = (ArcMineChangeProductionMsg) baseMsg; + + if (playerCharacter == null) + return true; + + //TODO verify this against the warehouse? + + if (GuildStatusController.isInnerCouncil(playerCharacter.getGuildStatus()) == false) // is this only GL? + return true; + + Mine mine = Mine.getMine(changeProductionMsg.getMineID()); + + if (mine == null) + return true; + + //make sure mine belongs to guild + + if (mine.getOwningGuild().isEmptyGuild() || + mine.getOwningGuild().getObjectUUID() != playerCharacter.getGuild().getObjectUUID()) + return true; + + //make sure valid resource + + Resource resource = Resource.resourceByHash.get(changeProductionMsg.getResourceHash()); + + if (resource == null) + return true; + + //update resource + + mine.changeProductionType(resource); + Mine.setLastChange(System.currentTimeMillis()); + Dispatch dispatch = Dispatch.borrow(playerCharacter, changeProductionMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + return true; + } + +} \ No newline at end of file