From 4db45a9cbf6ece87d8c587d379c9a0584a69c6de Mon Sep 17 00:00:00 2001 From: MagicBot Date: Wed, 22 Feb 2023 08:23:13 -0500 Subject: [PATCH] Handler created for cityDataMsg.java --- src/engine/net/client/ClientMessagePump.java | 59 ------------ src/engine/net/client/Protocol.java | 2 +- .../net/client/handlers/CityDataHandler.java | 95 +++++++++++++++++++ .../handlers/RequestEnterWorldHandler.java | 2 +- .../{WorldObjectMsg.java => cityDataMsg.java} | 10 +- 5 files changed, 102 insertions(+), 66 deletions(-) create mode 100644 src/engine/net/client/handlers/CityDataHandler.java rename src/engine/net/client/msg/{WorldObjectMsg.java => cityDataMsg.java} (95%) diff --git a/src/engine/net/client/ClientMessagePump.java b/src/engine/net/client/ClientMessagePump.java index 5e438484..adbe76ee 100644 --- a/src/engine/net/client/ClientMessagePump.java +++ b/src/engine/net/client/ClientMessagePump.java @@ -97,9 +97,6 @@ public class ClientMessagePump implements NetMsgHandler { case SETSELECTEDOBECT: ClientMessagePump.targetObject((TargetObjectMsg) msg, origin); break; - case CITYDATA: - ClientMessagePump.MapData(s, origin); - break; /* * Chat @@ -351,62 +348,6 @@ public class ClientMessagePump implements NetMsgHandler { } - private static void MapData(Session s, ClientConnection origin) { - - Dispatch dispatch; -try{ - - - if (s == null || origin == null) - return; - - PlayerCharacter pc = s.getPlayerCharacter(); - - if (pc == null) - return; -boolean updateMine = false; -boolean updateCity = false; - -//do not update Cities and mines everytime you open map. only update them to client when something's changed. - long lastRefresh = pc.getTimeStamp("mineupdate"); - if (lastRefresh <= Mine.getLastChange()){ - pc.setTimeStamp("mineupdate", System.currentTimeMillis()); - updateMine = true; - } - long lastCityRefresh = pc.getTimeStamp("cityUpdate"); - if (lastCityRefresh <= City.lastCityUpdate){ - pc.setTimeStamp("cityUpdate", System.currentTimeMillis()); - updateCity = true; - } - - - - WorldObjectMsg wom = new WorldObjectMsg(s, false); - wom.updateMines(true); - wom.updateCities(updateCity); - dispatch = Dispatch.borrow(pc, wom); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - // } - - lastRefresh = pc.getTimeStamp("hotzoneupdate"); - if (lastRefresh <= WorldServer.getLastHZChange()) { - Zone hotzone = ZoneManager.getHotZone(); - if (hotzone != null) { - HotzoneChangeMsg hcm = new HotzoneChangeMsg(hotzone.getObjectType().ordinal(), hotzone.getObjectUUID()); - dispatch = Dispatch.borrow(pc, hcm); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - pc.setTimeStamp("hotzoneupdate", System.currentTimeMillis() - 100); - } - } - - WorldRealmMsg wrm = new WorldRealmMsg(); - dispatch = Dispatch.borrow(pc, wrm); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); -}catch(Exception e){ - e.printStackTrace(); -} - } - private static void WhoRequest(WhoRequestMsg msg, ClientConnection origin) { // Handle /who request diff --git a/src/engine/net/client/Protocol.java b/src/engine/net/client/Protocol.java index 6eee1d13..70f3cf52 100644 --- a/src/engine/net/client/Protocol.java +++ b/src/engine/net/client/Protocol.java @@ -74,7 +74,7 @@ public enum Protocol { 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), - CITYDATA(0xB8A947D4, WorldObjectMsg.class, null), //Realm Data - Optional(?) + CITYDATA(0xB8A947D4, cityDataMsg.class, CityDataHandler.class), 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), diff --git a/src/engine/net/client/handlers/CityDataHandler.java b/src/engine/net/client/handlers/CityDataHandler.java new file mode 100644 index 00000000..cc9423c2 --- /dev/null +++ b/src/engine/net/client/handlers/CityDataHandler.java @@ -0,0 +1,95 @@ +package engine.net.client.handlers; + +import engine.Enum; +import engine.Enum.DispatchChannel; +import engine.exception.MsgSendException; +import engine.gameManager.SessionManager; +import engine.gameManager.ZoneManager; +import engine.net.Dispatch; +import engine.net.DispatchMessage; +import engine.net.client.ClientConnection; +import engine.net.client.msg.*; +import engine.objects.City; +import engine.objects.Mine; +import engine.objects.PlayerCharacter; +import engine.objects.Zone; +import engine.server.world.WorldServer; +import engine.session.Session; + +/* + * @Author: + * @Summary: Processes application protocol message which displays + * the map interface. (Zones, Cities, Realms, Hotzones) + */ + +public class CityDataHandler extends AbstractClientMsgHandler { + + public CityDataHandler() { + super(KeepAliveServerClientMsg.class); + } + + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { + + boolean updateMine = false; + boolean updateCity = false; + Session playerSession; + PlayerCharacter playerCharacter; + Zone hotZone; + + playerCharacter = origin.getPlayerCharacter(); + + if (playerCharacter == null) + return true; + + // Session is needed as param for worldObjectMsg. + + playerSession = SessionManager.getSession(playerCharacter); + + if (playerSession == null) + return true; + + // Cache current hotZone + + hotZone = ZoneManager.getHotZone(); + + // No reason to serialize cities and mines everytime map is + // opened. Wait until something has changed. + + if (playerCharacter.getTimeStamp("mineupdate") <= Mine.getLastChange()){ + playerCharacter.setTimeStamp("mineupdate", System.currentTimeMillis()); + updateMine = true; + } + + if (playerCharacter.getTimeStamp("cityUpdate") <= City.lastCityUpdate){ + playerCharacter.setTimeStamp("cityUpdate", System.currentTimeMillis()); + updateCity = true; + } + + cityDataMsg cityDataMsg = new cityDataMsg(SessionManager.getSession(playerCharacter), false); + cityDataMsg.updateMines(updateMine); + cityDataMsg.updateCities(updateCity); + + Dispatch dispatch = Dispatch.borrow(playerCharacter, cityDataMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + + if (playerCharacter.getTimeStamp("hotzoneupdate") <= WorldServer.getLastHZChange()) { + + if (hotZone != null) { + HotzoneChangeMsg hotzoneChangeMsg = new HotzoneChangeMsg(Enum.GameObjectType.Zone.ordinal(), hotZone.getObjectUUID()); + dispatch = Dispatch.borrow(playerCharacter, hotzoneChangeMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + playerCharacter.setTimeStamp("hotzoneupdate", System.currentTimeMillis() - 100); + } + } + + // Serialize the realms for this map + + WorldRealmMsg worldRealmMsg = new WorldRealmMsg(); + dispatch = Dispatch.borrow(playerCharacter, worldRealmMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + + return true; + } + +} \ No newline at end of file diff --git a/src/engine/net/client/handlers/RequestEnterWorldHandler.java b/src/engine/net/client/handlers/RequestEnterWorldHandler.java index 4724439f..e40ad17a 100644 --- a/src/engine/net/client/handlers/RequestEnterWorldHandler.java +++ b/src/engine/net/client/handlers/RequestEnterWorldHandler.java @@ -99,7 +99,7 @@ public class RequestEnterWorldHandler extends AbstractClientMsgHandler { } // Object Data - WorldObjectMsg wom = new WorldObjectMsg(session, true); + cityDataMsg wom = new cityDataMsg(session, true); dispatch = Dispatch.borrow(player, wom); DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY); diff --git a/src/engine/net/client/msg/WorldObjectMsg.java b/src/engine/net/client/msg/cityDataMsg.java similarity index 95% rename from src/engine/net/client/msg/WorldObjectMsg.java rename to src/engine/net/client/msg/cityDataMsg.java index e77f2767..b1334ab4 100644 --- a/src/engine/net/client/msg/WorldObjectMsg.java +++ b/src/engine/net/client/msg/cityDataMsg.java @@ -27,7 +27,7 @@ import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.concurrent.ConcurrentHashMap; -public class WorldObjectMsg extends ClientNetMsg { +public class cityDataMsg extends ClientNetMsg { private Session s; private boolean forEnterWorld; @@ -49,13 +49,13 @@ public class WorldObjectMsg extends ClientNetMsg { * @param forEnterWorld * boolean flag */ - public WorldObjectMsg(Session s, boolean forEnterWorld) { + public cityDataMsg(Session s, boolean forEnterWorld) { super(Protocol.CITYDATA); this.s = s; this.forEnterWorld = forEnterWorld; } - public WorldObjectMsg(boolean updateCities, boolean updateRunegates, boolean updateMines) { + public cityDataMsg(boolean updateCities, boolean updateRunegates, boolean updateMines) { super(Protocol.CITYDATA); this.s = null; this.forEnterWorld = false; @@ -70,7 +70,7 @@ public class WorldObjectMsg extends ClientNetMsg { * past the limit) then this constructor Throws that Exception to the * caller. */ - public WorldObjectMsg(AbstractConnection origin, ByteBufferReader reader) + public cityDataMsg(AbstractConnection origin, ByteBufferReader reader) { super(Protocol.CITYDATA, origin, reader); this.forEnterWorld = false; @@ -178,7 +178,7 @@ public class WorldObjectMsg extends ClientNetMsg { //Check to see if its time to renew cache. if (cachedExpireTime < System.currentTimeMillis()) { synchronized (cachedEnterWorld) { - WorldObjectMsg.attemptSerializeForEnterWorld(cachedEnterWorld); + cityDataMsg.attemptSerializeForEnterWorld(cachedEnterWorld); } cachedExpireTime = startT + 60000; }