forked from MagicBane/Server
Handler created for cityDataMsg.java
This commit is contained in:
@@ -97,9 +97,6 @@ public class ClientMessagePump implements NetMsgHandler {
|
|||||||
case SETSELECTEDOBECT:
|
case SETSELECTEDOBECT:
|
||||||
ClientMessagePump.targetObject((TargetObjectMsg) msg, origin);
|
ClientMessagePump.targetObject((TargetObjectMsg) msg, origin);
|
||||||
break;
|
break;
|
||||||
case CITYDATA:
|
|
||||||
ClientMessagePump.MapData(s, origin);
|
|
||||||
break;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Chat
|
* 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) {
|
private static void WhoRequest(WhoRequestMsg msg, ClientConnection origin) {
|
||||||
|
|
||||||
// Handle /who request
|
// Handle /who request
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ public enum Protocol {
|
|||||||
CHECKUNIQUEGUILD(0x689097D7, GuildCreationOptionsMsg.class, GuildCreationOptionsHandler.class), // Set Guild Name/Motto in Use Guild Charter
|
CHECKUNIQUEGUILD(0x689097D7, GuildCreationOptionsMsg.class, GuildCreationOptionsHandler.class), // Set Guild Name/Motto in Use Guild Charter
|
||||||
CITYASSET(0x7cae1678, CityAssetMsg.class, null),
|
CITYASSET(0x7cae1678, CityAssetMsg.class, null),
|
||||||
CITYCHOICE(0x406610BB, CityChoiceMsg.class, CityChoiceMsgHandler.class),
|
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.
|
CITYZONE(0x254947F2, CityZoneMsg.class, null), //For Creating City Object Clientside(Terraform)/Rename City.
|
||||||
CLAIMASSET(0x948C62CC, ClaimAssetMsg.class, ClaimAssetMsgHandler.class), // ClaimAsset
|
CLAIMASSET(0x948C62CC, ClaimAssetMsg.class, ClaimAssetMsgHandler.class), // ClaimAsset
|
||||||
CLAIMGUILDTREE(0xFD1C6442, ClaimGuildTreeMsg.class, ClaimGuildTreeMsgHandler.class),
|
CLAIMGUILDTREE(0xFD1C6442, ClaimGuildTreeMsg.class, ClaimGuildTreeMsgHandler.class),
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -99,7 +99,7 @@ public class RequestEnterWorldHandler extends AbstractClientMsgHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Object Data
|
// Object Data
|
||||||
WorldObjectMsg wom = new WorldObjectMsg(session, true);
|
cityDataMsg wom = new cityDataMsg(session, true);
|
||||||
dispatch = Dispatch.borrow(player, wom);
|
dispatch = Dispatch.borrow(player, wom);
|
||||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY);
|
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.PRIMARY);
|
||||||
|
|
||||||
|
|||||||
+5
-5
@@ -27,7 +27,7 @@ import java.nio.ByteBuffer;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public class WorldObjectMsg extends ClientNetMsg {
|
public class cityDataMsg extends ClientNetMsg {
|
||||||
|
|
||||||
private Session s;
|
private Session s;
|
||||||
private boolean forEnterWorld;
|
private boolean forEnterWorld;
|
||||||
@@ -49,13 +49,13 @@ public class WorldObjectMsg extends ClientNetMsg {
|
|||||||
* @param forEnterWorld
|
* @param forEnterWorld
|
||||||
* boolean flag
|
* boolean flag
|
||||||
*/
|
*/
|
||||||
public WorldObjectMsg(Session s, boolean forEnterWorld) {
|
public cityDataMsg(Session s, boolean forEnterWorld) {
|
||||||
super(Protocol.CITYDATA);
|
super(Protocol.CITYDATA);
|
||||||
this.s = s;
|
this.s = s;
|
||||||
this.forEnterWorld = forEnterWorld;
|
this.forEnterWorld = forEnterWorld;
|
||||||
}
|
}
|
||||||
|
|
||||||
public WorldObjectMsg(boolean updateCities, boolean updateRunegates, boolean updateMines) {
|
public cityDataMsg(boolean updateCities, boolean updateRunegates, boolean updateMines) {
|
||||||
super(Protocol.CITYDATA);
|
super(Protocol.CITYDATA);
|
||||||
this.s = null;
|
this.s = null;
|
||||||
this.forEnterWorld = false;
|
this.forEnterWorld = false;
|
||||||
@@ -70,7 +70,7 @@ public class WorldObjectMsg extends ClientNetMsg {
|
|||||||
* past the limit) then this constructor Throws that Exception to the
|
* past the limit) then this constructor Throws that Exception to the
|
||||||
* caller.
|
* caller.
|
||||||
*/
|
*/
|
||||||
public WorldObjectMsg(AbstractConnection origin, ByteBufferReader reader)
|
public cityDataMsg(AbstractConnection origin, ByteBufferReader reader)
|
||||||
{
|
{
|
||||||
super(Protocol.CITYDATA, origin, reader);
|
super(Protocol.CITYDATA, origin, reader);
|
||||||
this.forEnterWorld = false;
|
this.forEnterWorld = false;
|
||||||
@@ -178,7 +178,7 @@ public class WorldObjectMsg extends ClientNetMsg {
|
|||||||
//Check to see if its time to renew cache.
|
//Check to see if its time to renew cache.
|
||||||
if (cachedExpireTime < System.currentTimeMillis()) {
|
if (cachedExpireTime < System.currentTimeMillis()) {
|
||||||
synchronized (cachedEnterWorld) {
|
synchronized (cachedEnterWorld) {
|
||||||
WorldObjectMsg.attemptSerializeForEnterWorld(cachedEnterWorld);
|
cityDataMsg.attemptSerializeForEnterWorld(cachedEnterWorld);
|
||||||
}
|
}
|
||||||
cachedExpireTime = startT + 60000;
|
cachedExpireTime = startT + 60000;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user