Files
Server/src/engine/net/client/handlers/CityDataHandler.java
T

82 lines
2.9 KiB
Java
Raw Normal View History

2023-02-22 08:23:13 -05:00
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.PlayerCharacter;
import engine.session.Session;
/*
* @Author:
* @Summary: Processes application protocol message which displays
2023-02-22 08:34:10 -05:00
* the map interface. (Zones, Cities, Realms, Hot-zones)
2023-02-22 08:23:13 -05:00
*/
public class CityDataHandler extends AbstractClientMsgHandler {
2023-02-22 08:34:10 -05:00
public CityDataHandler() {
super(KeepAliveServerClientMsg.class);
}
2023-02-22 08:23:13 -05:00
2023-02-22 08:34:10 -05:00
@Override
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
2023-02-22 08:23:13 -05:00
2023-02-24 01:26:39 -05:00
boolean updateCities = false;
2023-02-22 08:34:10 -05:00
Session playerSession;
PlayerCharacter playerCharacter;
2023-02-22 08:38:18 -05:00
Dispatch dispatch;
2023-02-22 08:23:13 -05:00
2023-02-22 08:34:10 -05:00
playerCharacter = origin.getPlayerCharacter();
2023-02-22 08:23:13 -05:00
2023-02-22 08:34:10 -05:00
if (playerCharacter == null)
return true;
2023-02-22 08:23:13 -05:00
2023-02-22 08:34:10 -05:00
// Session is needed as param for worldObjectMsg.
2023-02-22 08:23:13 -05:00
2023-02-22 08:34:10 -05:00
playerSession = SessionManager.getSession(playerCharacter);
2023-02-22 08:23:13 -05:00
2023-02-22 08:34:10 -05:00
if (playerSession == null)
return true;
2023-02-22 08:23:13 -05:00
2023-02-23 17:37:14 -05:00
// No reason to serialize cities everytime map is
2023-02-22 08:34:10 -05:00
// opened. Wait until something has changed.
2023-02-23 17:37:14 -05:00
// This does not work for mines.
2023-02-22 08:23:13 -05:00
2023-02-22 08:34:10 -05:00
if (playerCharacter.getTimeStamp("cityUpdate") <= City.lastCityUpdate) {
playerCharacter.setTimeStamp("cityUpdate", System.currentTimeMillis());
2023-02-24 01:26:39 -05:00
updateCities = true;
2023-02-22 08:34:10 -05:00
}
2023-02-22 08:23:13 -05:00
2023-02-24 08:45:03 -05:00
CityDataMsg cityDataMsg = new CityDataMsg(SessionManager.getSession(playerCharacter), false);
2023-02-23 17:37:14 -05:00
cityDataMsg.updateMines(true);
2023-02-24 01:26:39 -05:00
cityDataMsg.updateCities(updateCities);
2023-02-22 08:23:13 -05:00
2023-02-22 08:38:18 -05:00
dispatch = Dispatch.borrow(playerCharacter, cityDataMsg);
2023-02-22 08:34:10 -05:00
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
2023-02-22 08:23:13 -05:00
2023-02-22 08:38:18 -05:00
// If the hotZone has changed then update the client's map accordingly.
2023-02-22 08:23:13 -05:00
2024-06-16 09:29:18 -05:00
if (playerCharacter.getTimestamps().containsKey("hotzoneupdate") && playerCharacter.getTimeStamp("hotzoneupdate") <= ZoneManager.hotZoneLastUpdate.toEpochMilli() && ZoneManager.hotZone != null) {
2023-07-15 09:23:48 -04:00
HotzoneChangeMsg hotzoneChangeMsg = new HotzoneChangeMsg(Enum.GameObjectType.Zone.ordinal(), ZoneManager.hotZone.getObjectUUID());
dispatch = Dispatch.borrow(playerCharacter, hotzoneChangeMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
playerCharacter.setTimeStamp("hotzoneupdate", System.currentTimeMillis() - 100);
2023-02-22 08:34:10 -05:00
}
2023-02-22 08:23:13 -05:00
2023-02-22 08:34:10 -05:00
// Serialize the realms for this map
2023-02-22 08:23:13 -05:00
2023-02-22 08:34:10 -05:00
WorldRealmMsg worldRealmMsg = new WorldRealmMsg();
dispatch = Dispatch.borrow(playerCharacter, worldRealmMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
2023-02-22 08:23:13 -05:00
2023-02-22 08:34:10 -05:00
return true;
}
2023-02-22 08:23:13 -05:00
}