Browse Source

Reformatted file.

master
MagicBot 2 years ago
parent
commit
f723e35785
  1. 564
      src/engine/gameManager/ZoneManager.java
  2. 96
      src/engine/net/client/Protocol.java
  3. 98
      src/engine/net/client/handlers/CityDataHandler.java
  4. 485
      src/engine/net/client/msg/cityDataMsg.java
  5. 10
      src/engine/workthreads/HourlyJobThread.java

564
src/engine/gameManager/ZoneManager.java

@ -34,409 +34,405 @@ import java.util.concurrent.ThreadLocalRandom; @@ -34,409 +34,405 @@ import java.util.concurrent.ThreadLocalRandom;
*/
public enum ZoneManager {
ZONEMANAGER;
ZONEMANAGER;
/* Instance variables */
private static Zone seaFloor = null;
private static Zone hotzone = null;
private static final ConcurrentHashMap<Integer, Zone> zonesByID = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD);
private static final ConcurrentHashMap<Integer, Zone> zonesByUUID = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD);
private static final ConcurrentHashMap<String, Zone> zonesByName = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD);
private static final Set<Zone> macroZones = Collections.newSetFromMap(new ConcurrentHashMap<>());
private static final Set<Zone> npcCityZones = Collections.newSetFromMap(new ConcurrentHashMap<>());
private static final Set<Zone> playerCityZones = Collections.newSetFromMap(new ConcurrentHashMap<>());
// Find all zones coordinates fit into, starting with Sea Floor
public static ArrayList<Zone> getAllZonesIn(final Vector3fImmutable loc) {
ArrayList<Zone> allIn = new ArrayList<>();
Zone zone;
zone = ZoneManager.findSmallestZone(loc);
if (zone != null) {
allIn.add(zone);
while (zone.getParent() != null) {
zone = zone.getParent();
allIn.add(zone);
}
}
return allIn;
}
/* Instance variables */
private static Zone seaFloor = null;
private static Zone hotzone = null;
private static ConcurrentHashMap<Integer, Zone> zonesByID = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD);
private static ConcurrentHashMap<Integer, Zone> zonesByUUID = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD);
private static ConcurrentHashMap<String, Zone> zonesByName = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD);
private static Set<Zone> macroZones = Collections.newSetFromMap(new ConcurrentHashMap<>());
private static Set<Zone> npcCityZones = Collections.newSetFromMap(new ConcurrentHashMap<>());
private static Set<Zone> playerCityZones = Collections.newSetFromMap(new ConcurrentHashMap<>());
// Find all zones coordinates fit into, starting with Sea Floor
// Find smallest zone coordinates fit into.
public static ArrayList<Zone> getAllZonesIn(final Vector3fImmutable loc) {
public static final Zone findSmallestZone(final Vector3fImmutable loc) {
ArrayList<Zone> allIn = new ArrayList<>();
Zone zone;
Zone zone = ZoneManager.seaFloor;
zone = ZoneManager.findSmallestZone(loc);
if (zone == null)
return null;
if (zone != null) {
allIn.add(zone);
while (zone.getParent() != null) {
zone = zone.getParent();
allIn.add(zone);
}
}
return allIn;
}
boolean childFound = true;
// Find smallest zone coordinates fit into.
while (childFound) {
public static final Zone findSmallestZone(final Vector3fImmutable loc) {
childFound = false;
Zone zone = ZoneManager.seaFloor;
ArrayList<Zone> nodes = zone.getNodes();
if (zone == null)
return null;
// Logger.info("soze", "" + nodes.size());
if (nodes != null)
for (Zone child : nodes) {
boolean childFound = true;
if (Bounds.collide(loc, child.getBounds()) == true) {
zone = child;
childFound = true;
break;
}
}
}
return zone;
}
while (childFound) {
public static void addZone(final int zoneID, final Zone zone) {
childFound = false;
ZoneManager.zonesByID.put(zoneID, zone);
ArrayList<Zone> nodes = zone.getNodes();
if (zone != null)
ZoneManager.zonesByUUID.put(zone.getObjectUUID(), zone);
// Logger.info("soze", "" + nodes.size());
if (nodes != null)
for (Zone child : nodes) {
ZoneManager.zonesByName.put(zone.getName().toLowerCase(), zone);
if (Bounds.collide(loc, child.getBounds()) == true) {
zone = child;
childFound = true;
break;
}
}
}
return zone;
}
}
public static void addZone(final int zoneID, final Zone zone) {
public static Zone getZoneByUUID(final int zoneUUID) {
return ZoneManager.zonesByUUID.get(zoneUUID);
}
ZoneManager.zonesByID.put(zoneID, zone);
public static Zone getZoneByZoneID(final int zoneID) {
if (zone != null)
ZoneManager.zonesByUUID.put(zone.getObjectUUID(), zone);
return ZoneManager.zonesByID.get(zoneID);
}
ZoneManager.zonesByName.put(zone.getName().toLowerCase(), zone);
public static final Collection<Zone> getAllZones() {
return ZoneManager.zonesByUUID.values();
}
}
public static final Zone getHotZone() {
return ZoneManager.hotzone;
}
public static Zone getZoneByUUID(final int zoneUUID) {
return ZoneManager.zonesByUUID.get(zoneUUID);
}
public static final void setHotZone(final Zone zone) {
if (!zone.isMacroZone())
return;
ZoneManager.hotzone = zone;
zone.hasBeenHotzone = true;
zone.becameHotzone = LocalDateTime.now();
}
public static Zone getZoneByZoneID(final int zoneID) {
public static boolean inHotZone(final Vector3fImmutable loc) {
return ZoneManager.zonesByID.get(zoneID);
}
if (ZoneManager.hotzone == null)
return false;
public static final Collection<Zone> getAllZones() {
return ZoneManager.zonesByUUID.values();
}
return (Bounds.collide(loc, ZoneManager.hotzone.getBounds()) == true);
}
public static final Zone getHotZone() {
return ZoneManager.hotzone;
}
public static void setSeaFloor(final Zone value) {
ZoneManager.seaFloor = value;
}
public static final void setHotZone(final Zone zone) {
if (!zone.isMacroZone())
return;
ZoneManager.hotzone = zone;
zone.hasBeenHotzone = true;
zone.becameHotzone = LocalDateTime.now();
}
public static Zone getSeaFloor() {
return ZoneManager.seaFloor;
}
public static boolean inHotZone(final Vector3fImmutable loc) {
public static final void populateWorldZones(final Zone zone) {
if (ZoneManager.hotzone == null)
return false;
int loadNum = zone.getLoadNum();
return (Bounds.collide(loc, ZoneManager.hotzone.getBounds()) == true);
}
// Zones are added to separate
// collections for quick access
// based upon their type.
public static void setSeaFloor(final Zone value) {
ZoneManager.seaFloor = value;
}
if (zone.isMacroZone()) {
addMacroZone(zone);
return;
}
public static Zone getSeaFloor() {
return ZoneManager.seaFloor;
}
public static final void populateWorldZones(final Zone zone) {
if (zone.isPlayerCity()) {
addPlayerCityZone(zone);
return;
}
int loadNum = zone.getLoadNum();
if (zone.isNPCCity())
addNPCCityZone(zone);
// Zones are added to separate
// collections for quick access
// based upon their type.
}
if (zone.isMacroZone()) {
addMacroZone(zone);
return;
}
private static void addMacroZone(final Zone zone) {
ZoneManager.macroZones.add(zone);
}
private static void addNPCCityZone(final Zone zone) {
zone.setNPCCity(true);
ZoneManager.npcCityZones.add(zone);
}
if (zone.isPlayerCity()) {
addPlayerCityZone(zone);
return;
}
public static final void addPlayerCityZone(final Zone zone) {
zone.setPlayerCity(true);
ZoneManager.playerCityZones.add(zone);
}
if (zone.isNPCCity())
addNPCCityZone(zone);
public static final void generateAndSetRandomHotzone() {
}
Zone hotzone;
ArrayList<Integer> zoneArray = new ArrayList<>();
private static void addMacroZone(final Zone zone) {
ZoneManager.macroZones.add(zone);
}
if (ZoneManager.macroZones.isEmpty())
return;
private static void addNPCCityZone(final Zone zone) {
zone.setNPCCity(true);
ZoneManager.npcCityZones.add(zone);
}
for (Zone zone : ZoneManager.macroZones) {
public static final void addPlayerCityZone(final Zone zone) {
zone.setPlayerCity(true);
ZoneManager.playerCityZones.add(zone);
}
if (validHotZone(zone))
zoneArray.add(zone.getObjectUUID());
public static final void generateAndSetRandomHotzone() {
}
Zone hotzone;
ArrayList<Integer> zoneArray = new ArrayList<>();
int entryIndex = ThreadLocalRandom.current().nextInt(zoneArray.size());
if (ZoneManager.macroZones.isEmpty())
return;
hotzone = ZoneManager.getZoneByUUID(zoneArray.get(entryIndex));
for (Zone zone : ZoneManager.macroZones) {
if (validHotZone(zone))
zoneArray.add(zone.getObjectUUID());
if (hotzone == null) {
Logger.error("Hotzone is null");
return;
}
}
int entryIndex = ThreadLocalRandom.current().nextInt(zoneArray.size());
ZoneManager.setHotZone(hotzone);
WorldServer.setLastHZChange(System.currentTimeMillis());
hotzone = ZoneManager.getZoneByUUID(zoneArray.get(entryIndex));
}
public static final boolean validHotZone(Zone zone) {
if (hotzone == null){
Logger.error( "Hotzone is null");
return;
}
if (zone.getSafeZone() == (byte) 1)
return false; // no safe zone hotzones// if (this.hotzone == null)
if (zone.getNodes().isEmpty())
return false;
ZoneManager.setHotZone(hotzone);
WorldServer.setLastHZChange(System.currentTimeMillis());
if (zone.equals(ZoneManager.seaFloor))
return false;
//no duplicate hotzones
if (zone.hasBeenHotzone == true) {
return false;
}
// return false; //first time setting, accept it
// if (this.hotzone.getUUID() == zone.getUUID())
// return true; //no same hotzone
}
if (ZoneManager.hotzone != null)
return ZoneManager.hotzone.getObjectUUID() != zone.getObjectUUID();
public static final boolean validHotZone(Zone zone) {
return true;
}
if (zone.getSafeZone() == (byte) 1)
return false; // no safe zone hotzones// if (this.hotzone == null)
/**
* Gets a MacroZone by name.
*
* @param inputName MacroZone name to search for
* @return Zone of the MacroZone, or Null
*/
public static Zone findMacroZoneByName(String inputName) {
synchronized (ZoneManager.macroZones) {
for (Zone zone : ZoneManager.macroZones) {
String zoneName = zone.getName();
if (zoneName.equalsIgnoreCase(inputName))
return zone;
}
}
return null;
}
if (zone.getNodes().isEmpty())
return false;
// Converts world coordinates to coordinates local to a given zone.
if (zone.equals(ZoneManager.seaFloor))
return false;
//no duplicate hotzones
if(zone.hasBeenHotzone == true){
return false;
}
// return false; //first time setting, accept it
// if (this.hotzone.getUUID() == zone.getUUID())
// return true; //no same hotzone
public static Vector3fImmutable worldToLocal(Vector3fImmutable worldVector,
Zone serverZone) {
if (ZoneManager.hotzone != null)
return ZoneManager.hotzone.getObjectUUID() != zone.getObjectUUID();
Vector3fImmutable localCoords;
return true;
}
localCoords = new Vector3fImmutable(worldVector.x - serverZone.absX,
worldVector.y - serverZone.absY, worldVector.z
- serverZone.absZ);
/**
* Gets a MacroZone by name.
*
* @param inputName
* MacroZone name to search for
* @return Zone of the MacroZone, or Null
*/
return localCoords;
}
public static Zone findMacroZoneByName(String inputName) {
synchronized (ZoneManager.macroZones) {
for (Zone zone : ZoneManager.macroZones) {
String zoneName = zone.getName();
if (zoneName.equalsIgnoreCase(inputName))
return zone;
}
}
return null;
}
public static Vector2f worldToZoneSpace(Vector3fImmutable worldVector,
Zone serverZone) {
// Converts world coordinates to coordinates local to a given zone.
Vector2f localCoords;
Vector2f zoneOrigin;
public static Vector3fImmutable worldToLocal(Vector3fImmutable worldVector,
Zone serverZone) {
// Top left corner of zone is calculated in world space by the center and it's extents.
Vector3fImmutable localCoords;
zoneOrigin = new Vector2f(serverZone.getLoc().x, serverZone.getLoc().z);
zoneOrigin = zoneOrigin.subtract(new Vector2f(serverZone.getBounds().getHalfExtents().x, serverZone.getBounds().getHalfExtents().y));
localCoords = new Vector3fImmutable(worldVector.x - serverZone.absX,
worldVector.y - serverZone.absY, worldVector.z
- serverZone.absZ);
// Local coordinate in world space translated to an offset from the calculated zone origin.
return localCoords;
}
localCoords = new Vector2f(worldVector.x, worldVector.z);
localCoords = localCoords.subtract(zoneOrigin);
public static Vector2f worldToZoneSpace(Vector3fImmutable worldVector,
Zone serverZone) {
localCoords.setY((serverZone.getBounds().getHalfExtents().y * 2) - localCoords.y);
Vector2f localCoords;
Vector2f zoneOrigin;
// Top left corner of zone is calculated in world space by the center and it's extents.
// TODO : Make sure this value does not go outside the zone's bounds.
zoneOrigin = new Vector2f(serverZone.getLoc().x, serverZone.getLoc().z);
zoneOrigin = zoneOrigin.subtract(new Vector2f(serverZone.getBounds().getHalfExtents().x, serverZone.getBounds().getHalfExtents().y));
return localCoords;
}
// Local coordinate in world space translated to an offset from the calculated zone origin.
// Converts local zone coordinates to world coordinates
localCoords = new Vector2f(worldVector.x, worldVector.z);
localCoords = localCoords.subtract(zoneOrigin);
public static Vector3fImmutable localToWorld(Vector3fImmutable worldVector,
Zone serverZone) {
localCoords.setY((serverZone.getBounds().getHalfExtents().y * 2) - localCoords.y);
Vector3fImmutable worldCoords;
worldCoords = new Vector3fImmutable(worldVector.x + serverZone.absX,
worldVector.y + serverZone.absY, worldVector.z
+ serverZone.absZ);
return worldCoords;
}
// TODO : Make sure this value does not go outside the zone's bounds.
/**
* Converts from local (relative to this building) to world.
*
* @param localPos position in local reference (relative to this building)
* @return position relative to world
*/
return localCoords;
}
public static Vector3fImmutable convertLocalToWorld(Building building, Vector3fImmutable localPos) {
// Converts local zone coordinates to world coordinates
// convert from SB rotation value to radians
public static Vector3fImmutable localToWorld(Vector3fImmutable worldVector,
Zone serverZone) {
Vector3fImmutable worldCoords;
if (building.getBounds().getQuaternion() == null)
return building.getLoc();
Vector3fImmutable rotatedLocal = Vector3fImmutable.rotateAroundPoint(Vector3fImmutable.ZERO, localPos, building.getBounds().getQuaternion());
// handle building rotation
// handle building translation
worldCoords = new Vector3fImmutable(worldVector.x + serverZone.absX,
worldVector.y + serverZone.absY, worldVector.z
+ serverZone.absZ);
return building.getLoc().add(rotatedLocal.x, rotatedLocal.y, rotatedLocal.z);
}
return worldCoords;
}
//used for regions, Building bounds not set yet.
public static Vector3f convertLocalToWorld(Building building, Vector3f localPos, Bounds bounds) {
/**
* Converts from local (relative to this building) to world.
*
* @param localPos position in local reference (relative to this building)
* @return position relative to world
*/
// convert from SB rotation value to radians
public static Vector3fImmutable convertLocalToWorld(Building building, Vector3fImmutable localPos) {
// convert from SB rotation value to radians
if (building.getBounds().getQuaternion() == null)
return building.getLoc();
Vector3fImmutable rotatedLocal = Vector3fImmutable.rotateAroundPoint(Vector3fImmutable.ZERO, localPos, building.getBounds().getQuaternion());
// handle building rotation
// handle building translation
Vector3f rotatedLocal = Vector3f.rotateAroundPoint(Vector3f.ZERO, localPos, bounds.getQuaternion());
// handle building rotation
// handle building translation
return building.getLoc().add(rotatedLocal.x, rotatedLocal.y,rotatedLocal.z);
}
//used for regions, Building bounds not set yet.
public static Vector3f convertLocalToWorld(Building building, Vector3f localPos, Bounds bounds) {
return new Vector3f(building.getLoc().add(rotatedLocal.x, rotatedLocal.y, rotatedLocal.z));
}
// convert from SB rotation value to radians
Vector3f rotatedLocal = Vector3f.rotateAroundPoint(Vector3f.ZERO, localPos, bounds.getQuaternion());
// handle building rotation
// handle building translation
public static Vector3fImmutable convertWorldToLocal(Building building, Vector3fImmutable WorldPos) {
Vector3fImmutable convertLoc = Vector3fImmutable.rotateAroundPoint(building.getLoc(), WorldPos, -building.getBounds().getQuaternion().angleY);
return new Vector3f(building.getLoc().add(rotatedLocal.x, rotatedLocal.y,rotatedLocal.z));
}
public static Vector3fImmutable convertWorldToLocal(Building building, Vector3fImmutable WorldPos) {
Vector3fImmutable convertLoc = Vector3fImmutable.rotateAroundPoint(building.getLoc(),WorldPos,-building.getBounds().getQuaternion().angleY);
convertLoc = convertLoc.subtract(building.getLoc());
convertLoc = convertLoc.subtract(building.getLoc());
// convert from SB rotation value to radians
return convertLoc;
// convert from SB rotation value to radians
}
return convertLoc;
public static Vector3fImmutable convertNPCLoc(Building building, Vector3fImmutable npcLoc) {
}
return Vector3fImmutable.rotateAroundPoint(Vector3fImmutable.ZERO, npcLoc, -building.getBounds().getQuaternion().angleY);
public static Vector3fImmutable convertNPCLoc(Building building, Vector3fImmutable npcLoc) {
}
return Vector3fImmutable.rotateAroundPoint(Vector3fImmutable.ZERO, npcLoc, -building.getBounds().getQuaternion().angleY);
// Method returns a city if the given location is within
// a city siege radius.
}
// Method returns a city if the given location is within
// a city siege radius.
public static City getCityAtLocation(Vector3fImmutable worldLoc) {
Zone currentZone;
ArrayList<Zone> zoneList;
City city;
public static City getCityAtLocation(Vector3fImmutable worldLoc) {
currentZone = ZoneManager.findSmallestZone(worldLoc);
Zone currentZone;
ArrayList<Zone> zoneList;
City city;
if (currentZone.isPlayerCity())
return City.getCity(currentZone.getPlayerCityUUID());
currentZone = ZoneManager.findSmallestZone(worldLoc);
// Not currently on a city grid. Test nearby cities
// to see if we are on one of their seige bounds.
if (currentZone.isPlayerCity())
return City.getCity(currentZone.getPlayerCityUUID());
zoneList = currentZone.getNodes();
// Not currently on a city grid. Test nearby cities
// to see if we are on one of their seige bounds.
for (Zone zone : zoneList) {
zoneList = currentZone.getNodes();
if (zone == currentZone)
continue;
for (Zone zone : zoneList) {
if (zone.isPlayerCity() == false)
continue;
if (zone == currentZone)
continue;
city = City.getCity(zone.getPlayerCityUUID());
if (worldLoc.isInsideCircle(city.getLoc(), Enum.CityBoundsType.SIEGE.extents))
return city;
}
return null;
}
if (zone.isPlayerCity() == false)
continue;
/* Method is called when creating a new player city to
* validate that the new zone does not overlap any other
* zone that might currently exist
*/
city = City.getCity(zone.getPlayerCityUUID());
public static boolean validTreePlacementLoc(Zone currentZone, float positionX, float positionZ) {
if (worldLoc.isInsideCircle(city.getLoc(), Enum.CityBoundsType.SIEGE.extents))
return city;
}
// Member Variable declaration
return null;
}
ArrayList<Zone> zoneList;
boolean validLocation = true;
Bounds treeBounds;
/* Method is called when creating a new player city to
* validate that the new zone does not overlap any other
* zone that might currently exist
*/
if (currentZone.isContininent() == false)
return false;
public static boolean validTreePlacementLoc(Zone currentZone, float positionX, float positionZ) {
// Member Variable declaration
treeBounds = Bounds.borrow();
treeBounds.setBounds(new Vector2f(positionX, positionZ), new Vector2f(Enum.CityBoundsType.SIEGE.extents, Enum.CityBoundsType.SIEGE.extents), 0.0f);
ArrayList<Zone> zoneList;
boolean validLocation = true;
Bounds treeBounds;
if (currentZone.isContininent() == false)
return false;
treeBounds = Bounds.borrow();
treeBounds.setBounds(new Vector2f(positionX, positionZ), new Vector2f(Enum.CityBoundsType.SIEGE.extents, Enum.CityBoundsType.SIEGE.extents), 0.0f);
zoneList = currentZone.getNodes();
zoneList = currentZone.getNodes();
for (Zone zone : zoneList) {
for (Zone zone : zoneList) {
if (zone.isContininent())
continue;
if (zone.isContininent())
continue;
if (Bounds.collide(treeBounds, zone.getBounds(), 0.0f))
validLocation = false;
}
if (Bounds.collide(treeBounds, zone.getBounds(), 0.0f))
validLocation = false;
}
treeBounds.release();
return validLocation;
treeBounds.release();
return validLocation;
}
}

96
src/engine/net/client/Protocol.java

@ -26,14 +26,14 @@ public enum Protocol { @@ -26,14 +26,14 @@ public enum Protocol {
ACTIVATECHARTER(0x296C0B22, UseCharterMsg.class, null),// Use Guild Charter
ACTIVATENPC(0xC9AAE81E, ActivateNPCMessage.class, ActivateNPCMsgHandler.class),
ACTIVATEPLEDGE(0x5A694DC0, SwearInMsg.class, SwearInHandler.class), // Swear In
ADDFRIEND(0xCFA1C787,AddFriendMessage.class,null),
ALLIANCECHANGE(0x0E7D0B57, AllianceChangeMsg.class, AllianceChangeMsgHandler.class), // Remove From Allies/Enemies List
ADDFRIEND(0xCFA1C787, AddFriendMessage.class, null),
ALLIANCECHANGE(0x0E7D0B57, AllianceChangeMsg.class, AllianceChangeMsgHandler.class), // Remove From Allies/Enemies List
ALLYENEMYLIST(0xAEA443FD, AllyEnemyListMsg.class, AllyEnemyListMsgHandler.class),
ARCCOMBATMODEATTACKING(0xD8B10579, SetCombatModeMsg.class, null), // Attack From Outside Combat Mode
ARCCOMBATMODEATTACKING(0xD8B10579, SetCombatModeMsg.class, null), // Attack From Outside Combat Mode
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, ArcMineChangeProductionMsgHandler.class),
ARCMINECHANGEPRODUCTION(0x1EAA993F, ArcMineChangeProductionMsg.class, ArcMineChangeProductionMsgHandler.class),
ARCMINETOWERCRESTUPDATE(0x34164D0D, null, null),
ARCMINEWINDOWAVAILABLETIME(0x6C909DE7, ArcMineWindowAvailableTimeMsg.class, ArcMineWindowAvailableTimeHandler.class),
ARCMINEWINDOWCHANGE(0x92B2148A, ArcMineWindowChangeMsg.class, MineWindowChangeHandler.class),
@ -62,7 +62,7 @@ public enum Protocol { @@ -62,7 +62,7 @@ public enum Protocol {
CHANNELMUTE(0xC1BDC53A, ChatFilterMsg.class, ChannelMuteMsgHandler.class), //Chat Channels that are turned on
CHARSELECTSCREEN(0x682C935D, null, null), // Character Selection Screen
CHATCITY(0x9D402901, ChatCityMsg.class, null), // Chat Channel: /City
CHATCSR(0x14EBA1C3, ChatCSRMsg.class, null), //Chat Channel: CSR
CHATCSR(0x14EBA1C3, ChatCSRMsg.class, null), //Chat Channel: CSR
CHATGROUP(0xA895B634, ChatGroupMsg.class, null), // Chat Channel: /group
CHATGUILD(0xA9D92ED4, ChatGuildMsg.class, null), // Chat Channel: /guild
CHATIC(0x00A75F35, ChatICMsg.class, null), // Chat Channel: /IC
@ -78,13 +78,13 @@ public enum Protocol { @@ -78,13 +78,13 @@ public enum Protocol {
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),
CLIENTADMINCOMMAND(0x624EAB5F, ClientAdminCommandMsg.class, null), //Admin Command
CLIENTUPDATEVAULT( 0x66EDBECD, UpdateVaultMsg.class, null),
CLIENTADMINCOMMAND(0x624EAB5F, ClientAdminCommandMsg.class, null), //Admin Command
CLIENTUPDATEVAULT(0x66EDBECD, UpdateVaultMsg.class, null),
COMBATMODE(0xFE4BF353, ToggleCombatMsg.class, null), //Toggle Combat mode
CONFIRMPROMOTE(0x153BB5F9, ConfirmPromoteMsg.class, null),
COSTTOOPENBANK(0x135BE5E8, AckBankWindowOpenedMsg.class, null), // ACK Bank Window Opened
CREATECHAR(0x5D18B5C8, CommitNewCharacterMsg.class, null), // Commit New Character,
CREATEPETITION(0xD489CFED, GuildCreationFinalizeMsg.class, GuildCreationFinalizeHandler.class), //Confirm guild creation
CREATEPETITION(0xD489CFED, GuildCreationFinalizeMsg.class, GuildCreationFinalizeHandler.class), //Confirm guild creation
CUSTOMERPETITION(0x7F9D7D6D, PetitionReceivedMsg.class, null),
DELETEOBJECT(0x57F069D8, DeleteItemMsg.class, null), //Delete Item from Inventory
DESTROYBUILDING(0x3CB6FAD3, DestroyBuildingMsg.class, DestroyBuildingHandler.class), // Destroy Building
@ -95,8 +95,8 @@ public enum Protocol { @@ -95,8 +95,8 @@ public enum Protocol {
EQUIP(0x3CB1AF8C, TransferItemFromInventoryToEquipMsg.class, null), // Transfer Item from Inventory to Equip
EXPERIENCE(0xC57802A7, GrantExperienceMsg.class, null), //TODO rename once identified
FORGETOBJECTS(0xE307A0E1, UnloadObjectsMsg.class, null), // Unload Objects
FRIENDACCEPT(0xCA297870,AcceptFriendMsg.class,FriendAcceptHandler.class),
FRIENDDECLINE(0xF08FC279,DeclineFriendMsg.class,FriendDeclineHandler.class),
FRIENDACCEPT(0xCA297870, AcceptFriendMsg.class, FriendAcceptHandler.class),
FRIENDDECLINE(0xF08FC279, DeclineFriendMsg.class, FriendDeclineHandler.class),
FURNITURE(0xCE7FA503, FurnitureMsg.class, FurnitureHandler.class),
GAMESERVERIPRESPONSE(0x6C95CF87, GameServerIPResponseMsg.class, null), // Game Server IP Response
GLOBALCHANNELMESSAGE(0x2bf03fd2, null, null),
@ -109,7 +109,7 @@ public enum Protocol { @@ -109,7 +109,7 @@ public enum Protocol {
GUILDMEMBERONLINE(0x7B79EB3A, GuildEnterWorldMsg.class, null), // Send Enter World Message to Guild
GUILDRANKCHANGE(0x0DEFB21F, ChangeRankMsg.class, ChangeRankHandler.class), // Change Rank
GUILDTREESTATUS(0x4B95FB85, GuildTreeStatusMsg.class, null),
HIRELINGSERVICE(0xD3D93322,HirelingServiceMsg.class,HirelingServiceMsgHandler.class),
HIRELINGSERVICE(0xD3D93322, HirelingServiceMsg.class, HirelingServiceMsgHandler.class),
IGNORE(0xBD8881EE, IgnoreMsg.class, null), //client sent /ignore command
INITIATETRADEHUDS(0x667D29D8, OpenTradeWindowMsg.class, null), // Open Trade Window
INVITEGROUP(0x004A2012, GroupInviteMsg.class, GroupInviteHandler.class), // Send/Receive/Deny Group Invite
@ -164,11 +164,11 @@ public enum Protocol { @@ -164,11 +164,11 @@ public enum Protocol {
RAISEATTR(0x5EEB65E0, ModifyStatMsg.class, null), // Modify Stat
RANDOM(0xAC5D0135, RandomMsg.class, null), //RequestSend random roll
READYTOENTER(0x490E4FE0, EnterWorldReceivedMsg.class, null), //Client Ack Receive Enter World
REALMDATA(0x2399B775, null, null), //Realm Data - Optional(?)
REALMDATA(0x2399B775, null, null), //Realm Data - Optional(?)
RECOMMENDNATION(0x6D4579E9, RecommendNationMsg.class, RecommendNationMsgHandler.class), // Recommend as Ally/Enemy, error
RECYCLEPOWER(0x24033B67, RecyclePowerMsg.class, null), //Unlock power for reUse
REMOVECHAR(0x5D3F9739, DeleteCharacterMsg.class, null), // Delete Character
REMOVEFRIEND(0xE0D5DB42,RemoveFriendMessage.class,RemoveFriendHandler.class),
REMOVEFRIEND(0xE0D5DB42, RemoveFriendMessage.class, RemoveFriendHandler.class),
REPAIRBUILDING(0xAF8C2560, RepairBuildingMsg.class, RepairBuildingMsgHandler.class),
REPAIROBJECT(0x782219CE, RepairMsg.class, null), //Repair Window Req/Ack, RepairObject item Req/Ack
REQUESTCONTENTS(0xA786B0A2, LootWindowRequestMsg.class, null), // MoveObjectToContainer Window Request
@ -179,7 +179,7 @@ public enum Protocol { @@ -179,7 +179,7 @@ public enum Protocol {
REQUESTTOTRADE(0x4D84259B, TradeRequestMsg.class, null), // Trade Request
REQUESTTRADECANCEL(0xCB0C5735, RejectTradeRequestMsg.class, null), // Reject RequestToTrade
REQUESTTRADEOK(0xFFD29841, AcceptTradeRequestMsg.class, null), // Accept Trade Request
RESETAFTERDEATH(0xFDCBB98F,RespawnMsg.class, null), //Respawn Request/Response
RESETAFTERDEATH(0xFDCBB98F, RespawnMsg.class, null), //Respawn Request/Response
ROTATEMSG(0x57F2088E, RotateObjectMsg.class, null),
SAFEMODE(0x9CF3922A, SafeModeMsg.class, null), //Tell client they're in safe mode
SCALEOBJECT(0xE2B392D9, null, null), // Adjust scale of object
@ -210,7 +210,7 @@ public enum Protocol { @@ -210,7 +210,7 @@ public enum Protocol {
TAXCITY(0xCD41EAA6, TaxCityMsg.class, TaxCityMsgHandler.class),
TAXRESOURCES(0x4AD458AF, TaxResourcesMsg.class, TaxResourcesMsgHandler.class),
TELEPORT(0x23E726EA, TeleportToPointMsg.class, null), // Teleport to point
TERRITORYCHANGE(0x6B388C8C,TerritoryChangeMessage.class, null), //Hey rich, look what I found? :)
TERRITORYCHANGE(0x6B388C8C, TerritoryChangeMessage.class, null), //Hey rich, look what I found? :)
TOGGLESITSTAND(0x624F3C0F, ToggleSitStandMsg.class, null), //Toggle Sit/Stand
TRADEADDGOLD(0x654ACB45, AddGoldToTradeWindowMsg.class, null), // Add Gold to Trade Window
TRADEADDOBJECT(0x55D363E9, AddItemToTradeWindowMsg.class, null), // Add an Item to the Trade Window
@ -227,7 +227,7 @@ public enum Protocol { @@ -227,7 +227,7 @@ public enum Protocol {
TRANSFERITEMFROMVAULTTOINVENTORY(0x0119A64D, TransferItemFromVaultToInventoryMsg.class, null), // Transfer Item from Vault to Inventory
TRANSFERITEMTOBANK(0xD48C46FA, TransferItemFromInventoryToBankMsg.class, null), // Transfer Item from Inventory to Bank
UNEQUIP(0xC6BFB907, TransferItemFromEquipToInventoryMsg.class, null), // Transfer Item from Equip to Inventory
UNKNOWN(0x238C9259, UnknownMsg.class,null),
UNKNOWN(0x238C9259, UnknownMsg.class, null),
UPDATECHARORMOB(0xB6D78961, null, null),
UPDATECLIENTALLIANCES(0xF3FEB5D4, null, GuildUnknownHandler.class), //AlliancesMsg
UPDATECLIENTINVENTORIES(0xE66F533D, UpdateInventoryMsg.class, null), //Update player inventory
@ -247,14 +247,14 @@ public enum Protocol { @@ -247,14 +247,14 @@ public enum Protocol {
WEIGHTINVENTORY(0xF1B6A85C, LootWindowResponseMsg.class, null), // MoveObjectToContainer Window Response
WHOREQUEST(0xF431CCE9, WhoRequestMsg.class, null), // Request /who
WHORESPONSE(0xD7C36568, WhoResponseMsg.class, null), // Response /who
REQUESTBALLLIST(0xE366FF64,RequestBallListMessage.class,RequestBallListHandler.class),
SENDBALLENTRY(0xAC2B5EDC,SendBallEntryMessage.class,SendBallEntryHandler.class),
UNKNOWN1(-263523523, Unknown1Msg.class,null),
DROPGOLD(1461654160,DropGoldMsg.class,null);
REQUESTBALLLIST(0xE366FF64, RequestBallListMessage.class, RequestBallListHandler.class),
SENDBALLENTRY(0xAC2B5EDC, SendBallEntryMessage.class, SendBallEntryHandler.class),
UNKNOWN1(-263523523, Unknown1Msg.class, null),
DROPGOLD(1461654160, DropGoldMsg.class, null);
public int opcode;
private Class message;
private Class handlerClass;
private final Class message;
private final Class handlerClass;
public Constructor constructor;
public AbstractClientMsgHandler handler;
@ -275,7 +275,7 @@ public enum Protocol { @@ -275,7 +275,7 @@ public enum Protocol {
}
}
// Create instance of message handler for incoming protocol messages
// Create instance of message handler for incoming protocol messages
if (this.handlerClass != null) {
try {
@ -286,7 +286,7 @@ public enum Protocol { @@ -286,7 +286,7 @@ public enum Protocol {
}
}
private static HashMap<Integer, Protocol> _protocolMsgByOpcode = new HashMap<>();
private static final HashMap<Integer, Protocol> _protocolMsgByOpcode = new HashMap<>();
public static Protocol getByOpcode(int opcode) {
@ -302,37 +302,37 @@ public enum Protocol { @@ -302,37 +302,37 @@ public enum Protocol {
for (Protocol protocol : Protocol.values()) {
if (_protocolMsgByOpcode.containsKey(protocol.opcode)){
Logger.error("Duplicate opcodes for " + protocol.name() + " and " + _protocolMsgByOpcode.get(protocol.opcode).name());
}
if (_protocolMsgByOpcode.containsKey(protocol.opcode)) {
Logger.error("Duplicate opcodes for " + protocol.name() + " and " + _protocolMsgByOpcode.get(protocol.opcode).name());
}
_protocolMsgByOpcode.put(protocol.opcode, protocol);
}
}
public static int FindNextValidOpcode(ByteBufferReader reader){
int startPos = reader.position();
int bytesLeft = reader.remaining();
public static int FindNextValidOpcode(ByteBufferReader reader) {
int startPos = reader.position();
int bytesLeft = reader.remaining();
if (bytesLeft < 4)
return startPos;
int nextPos = startPos;
for (int i = 1; i< bytesLeft; i++ ){
reader.position(nextPos);
if (reader.remaining() < 4)
return reader.position();
int newOpcode = reader.getInt();
if (bytesLeft < 4)
return startPos;
int nextPos = startPos;
for (int i = 1; i < bytesLeft; i++) {
reader.position(nextPos);
if (reader.remaining() < 4)
return reader.position();
int newOpcode = reader.getInt();
Protocol foundProtocol = Protocol.getByOpcode(newOpcode);
if (foundProtocol.equals(Protocol.NONE)){
nextPos += 1;
continue;
}
Protocol foundProtocol = Protocol.getByOpcode(newOpcode);
if (foundProtocol.equals(Protocol.NONE)) {
nextPos += 1;
continue;
}
//found opcode. return position - 4 to rewind back to start of opcode, so we can handle it.
return reader.position() - 4;
}
//found opcode. return position - 4 to rewind back to start of opcode, so we can handle it.
return reader.position() - 4;
}
return startPos;
}
return startPos;
}
}

98
src/engine/net/client/handlers/CityDataHandler.java

@ -19,77 +19,77 @@ import engine.session.Session; @@ -19,77 +19,77 @@ import engine.session.Session;
/*
* @Author:
* @Summary: Processes application protocol message which displays
* the map interface. (Zones, Cities, Realms, Hotzones)
* the map interface. (Zones, Cities, Realms, Hot-zones)
*/
public class CityDataHandler extends AbstractClientMsgHandler {
public CityDataHandler() {
super(KeepAliveServerClientMsg.class);
}
public CityDataHandler() {
super(KeepAliveServerClientMsg.class);
}
@Override
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
@Override
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
boolean updateMine = false;
boolean updateCity = false;
Session playerSession;
PlayerCharacter playerCharacter;
Zone hotZone;
boolean updateMine = false;
boolean updateCity = false;
Session playerSession;
PlayerCharacter playerCharacter;
Zone hotZone;
playerCharacter = origin.getPlayerCharacter();
playerCharacter = origin.getPlayerCharacter();
if (playerCharacter == null)
return true;
if (playerCharacter == null)
return true;
// Session is needed as param for worldObjectMsg.
// Session is needed as param for worldObjectMsg.
playerSession = SessionManager.getSession(playerCharacter);
playerSession = SessionManager.getSession(playerCharacter);
if (playerSession == null)
return true;
if (playerSession == null)
return true;
// Cache current hotZone
// Cache current hotZone
hotZone = ZoneManager.getHotZone();
hotZone = ZoneManager.getHotZone();
// No reason to serialize cities and mines everytime map is
// opened. Wait until something has changed.
// 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("mineupdate") <= Mine.getLastChange()) {
playerCharacter.setTimeStamp("mineupdate", System.currentTimeMillis());
updateMine = true;
}
if (playerCharacter.getTimeStamp("cityUpdate") <= City.lastCityUpdate){
playerCharacter.setTimeStamp("cityUpdate", System.currentTimeMillis());
updateCity = 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);
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);
Dispatch dispatch = Dispatch.borrow(playerCharacter, cityDataMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
if (playerCharacter.getTimeStamp("hotzoneupdate") <= WorldServer.getLastHZChange()) {
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);
}
}
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
// Serialize the realms for this map
WorldRealmMsg worldRealmMsg = new WorldRealmMsg();
dispatch = Dispatch.borrow(playerCharacter, worldRealmMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
WorldRealmMsg worldRealmMsg = new WorldRealmMsg();
dispatch = Dispatch.borrow(playerCharacter, worldRealmMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
return true;
}
return true;
}
}

485
src/engine/net/client/msg/cityDataMsg.java

@ -29,251 +29,246 @@ import java.util.concurrent.ConcurrentHashMap; @@ -29,251 +29,246 @@ import java.util.concurrent.ConcurrentHashMap;
public class cityDataMsg extends ClientNetMsg {
private Session s;
private boolean forEnterWorld;
private static ByteBuffer cachedEnterWorld;
private static long cachedExpireTime;
public static final long wdComp = 0xFF00FF0000000003L;
private static byte ver = 1;
private boolean updateCities = false;
private boolean updateRunegates = false;
private boolean updateMines = false;
/**
* This is the general purpose constructor.
*
* @param s
* Session
* @param forEnterWorld
* boolean flag
*/
public cityDataMsg(Session s, boolean forEnterWorld) {
super(Protocol.CITYDATA);
this.s = s;
this.forEnterWorld = forEnterWorld;
}
public cityDataMsg(boolean updateCities, boolean updateRunegates, boolean updateMines) {
super(Protocol.CITYDATA);
this.s = null;
this.forEnterWorld = false;
this.updateCities = updateCities;
this.updateRunegates = updateRunegates;
this.updateMines = updateMines;
}
/**
* 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 cityDataMsg(AbstractConnection origin, ByteBufferReader reader)
{
super(Protocol.CITYDATA, origin, reader);
this.forEnterWorld = false;
}
@Override
protected int getPowerOfTwoBufferSize() {
return (18); // 2^14 == 16384
}
/**
* Serializes the subclass specific items to the supplied NetMsgWriter.
*/
@Override
protected void _serialize(ByteBufferWriter writer) {
if (this.forEnterWorld)
serializeForEnterWorld(writer);
else
serializeForMapUpdate(writer);
}
/**
* Specific use serializer
*
* @param writer
*/
private void serializeForMapUpdate(ByteBufferWriter writer) {
//Handle City updates
if (this.updateCities) {
writer.put((byte) 0);
ArrayList<City> cityList = new ArrayList<>();
ConcurrentHashMap<Integer, AbstractGameObject> map = DbManager.getMap(Enum.GameObjectType.City);
if (map != null) {
for (AbstractGameObject ago : map.values())
if (ago.getObjectType().equals(Enum.GameObjectType.City))
cityList.add((City)ago);
writer.putInt(cityList.size());
for (City city: cityList){
City.serializeForClientMsg(city, writer);
}
} else {
Logger.error("missing city map");
writer.putInt(0);
}
} else
writer.put((byte) 1);
//Handle Runegate updates
if (this.updateRunegates) {
writer.put((byte) 0);
writer.putInt(Runegate._runegates.values().size());
for(Runegate runegate : Runegate._runegates.values()) {
runegate._serializeForEnterWorld(writer);
}
} else
writer.put((byte) 1);
//Handle Mine updates
try{
if (this.updateMines) {
ArrayList<Mine> mineList = new ArrayList<>();
for (Mine toAdd: Mine.mineMap.keySet()){
mineList.add(toAdd);
}
writer.putInt(mineList.size());
for (Mine mine: mineList)
Mine.serializeForClientMsg(mine, writer);
} else
writer.putInt(0);
}catch(Exception e){
Logger.error(e);
}
writer.put((byte) 0); // PAD
}
/**
* Specific use serializer
*
* @param writer
*/
private void serializeForEnterWorld(ByteBufferWriter writer) {
if (s == null || s.getPlayerCharacter() == null)
return;
long startT = System.currentTimeMillis();
if (cachedEnterWorld == null) {
// Never before been cached, so init stuff
cachedEnterWorld = Network.byteBufferPool.getBuffer(19);
cachedExpireTime = 0L;
}
//Check to see if its time to renew cache.
if (cachedExpireTime < System.currentTimeMillis()) {
synchronized (cachedEnterWorld) {
cityDataMsg.attemptSerializeForEnterWorld(cachedEnterWorld);
}
cachedExpireTime = startT + 60000;
}
writer.putBB(cachedEnterWorld);
}
private static void attemptSerializeForEnterWorld(ByteBuffer bb) {
bb.clear();
ByteBufferWriter temp = new ByteBufferWriter(bb);
temp.put((byte) 0); // PAD
ArrayList<City> cityList = new ArrayList<>();
ConcurrentHashMap<Integer, AbstractGameObject> map = DbManager.getMap(Enum.GameObjectType.City);
for (AbstractGameObject ago : map.values())
if (ago.getObjectType().equals(Enum.GameObjectType.City))
cityList.add((City)ago);
temp.putInt(cityList.size());
for (City city: cityList)
City.serializeForClientMsg(city, temp);
temp.put((byte) 0); // PAD
// Serialize runegates
temp.putInt(Runegate._runegates.values().size());
for(Runegate runegate : Runegate._runegates.values()) {
runegate._serializeForEnterWorld(temp);
}
ArrayList<Mine> mineList = new ArrayList<>();
for (Mine toAdd : Mine.mineMap.keySet()){
mineList.add(toAdd);
}
temp.putInt(mineList.size());
for (Mine mine: mineList)
Mine.serializeForClientMsg(mine, temp);
temp.put((byte) 0); // PAD
}
/**
* Deserializes the subclass specific items from the supplied NetMsgReader.
*/
@Override
protected void _deserialize(ByteBufferReader reader)
{
// Client only sends 11 bytes.
byte type = reader.get();
if (type == 1){
reader.get();
reader.get();
reader.getInt();
}else{
reader.get();
reader.getInt();
reader.get();
reader.getInt();
}
}
/**
* @return the s
*/
public Session getS() {
return s;
}
/**
* @return the forEnterWorld
*/
public boolean isForEnterWorld() {
return forEnterWorld;
}
public void updateCities(boolean value) {
this.updateCities = value;
}
public void updateRunegates(boolean value) {
this.updateRunegates = value;
}
public void updateMines(boolean value) {
this.updateMines = value;
}
private Session s;
private final boolean forEnterWorld;
private static ByteBuffer cachedEnterWorld;
private static long cachedExpireTime;
public static final long wdComp = 0xFF00FF0000000003L;
private static final byte ver = 1;
private boolean updateCities = false;
private boolean updateRunegates = false;
private boolean updateMines = false;
/**
* This is the general purpose constructor.
*
* @param s Session
* @param forEnterWorld boolean flag
*/
public cityDataMsg(Session s, boolean forEnterWorld) {
super(Protocol.CITYDATA);
this.s = s;
this.forEnterWorld = forEnterWorld;
}
public cityDataMsg(boolean updateCities, boolean updateRunegates, boolean updateMines) {
super(Protocol.CITYDATA);
this.s = null;
this.forEnterWorld = false;
this.updateCities = updateCities;
this.updateRunegates = updateRunegates;
this.updateMines = updateMines;
}
/**
* 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 cityDataMsg(AbstractConnection origin, ByteBufferReader reader) {
super(Protocol.CITYDATA, origin, reader);
this.forEnterWorld = false;
}
@Override
protected int getPowerOfTwoBufferSize() {
return (18); // 2^14 == 16384
}
/**
* Serializes the subclass specific items to the supplied NetMsgWriter.
*/
@Override
protected void _serialize(ByteBufferWriter writer) {
if (this.forEnterWorld)
serializeForEnterWorld(writer);
else
serializeForMapUpdate(writer);
}
/**
* Specific use serializer
*
* @param writer
*/
private void serializeForMapUpdate(ByteBufferWriter writer) {
//Handle City updates
if (this.updateCities) {
writer.put((byte) 0);
ArrayList<City> cityList = new ArrayList<>();
ConcurrentHashMap<Integer, AbstractGameObject> map = DbManager.getMap(Enum.GameObjectType.City);
if (map != null) {
for (AbstractGameObject ago : map.values())
if (ago.getObjectType().equals(Enum.GameObjectType.City))
cityList.add((City) ago);
writer.putInt(cityList.size());
for (City city : cityList) {
City.serializeForClientMsg(city, writer);
}
} else {
Logger.error("missing city map");
writer.putInt(0);
}
} else
writer.put((byte) 1);
//Handle Runegate updates
if (this.updateRunegates) {
writer.put((byte) 0);
writer.putInt(Runegate._runegates.values().size());
for (Runegate runegate : Runegate._runegates.values()) {
runegate._serializeForEnterWorld(writer);
}
} else
writer.put((byte) 1);
//Handle Mine updates
try {
if (this.updateMines) {
ArrayList<Mine> mineList = new ArrayList<>();
for (Mine toAdd : Mine.mineMap.keySet()) {
mineList.add(toAdd);
}
writer.putInt(mineList.size());
for (Mine mine : mineList)
Mine.serializeForClientMsg(mine, writer);
} else
writer.putInt(0);
} catch (Exception e) {
Logger.error(e);
}
writer.put((byte) 0); // PAD
}
/**
* Specific use serializer
*
* @param writer
*/
private void serializeForEnterWorld(ByteBufferWriter writer) {
if (s == null || s.getPlayerCharacter() == null)
return;
long startT = System.currentTimeMillis();
if (cachedEnterWorld == null) {
// Never before been cached, so init stuff
cachedEnterWorld = Network.byteBufferPool.getBuffer(19);
cachedExpireTime = 0L;
}
//Check to see if its time to renew cache.
if (cachedExpireTime < System.currentTimeMillis()) {
synchronized (cachedEnterWorld) {
cityDataMsg.attemptSerializeForEnterWorld(cachedEnterWorld);
}
cachedExpireTime = startT + 60000;
}
writer.putBB(cachedEnterWorld);
}
private static void attemptSerializeForEnterWorld(ByteBuffer bb) {
bb.clear();
ByteBufferWriter temp = new ByteBufferWriter(bb);
temp.put((byte) 0); // PAD
ArrayList<City> cityList = new ArrayList<>();
ConcurrentHashMap<Integer, AbstractGameObject> map = DbManager.getMap(Enum.GameObjectType.City);
for (AbstractGameObject ago : map.values())
if (ago.getObjectType().equals(Enum.GameObjectType.City))
cityList.add((City) ago);
temp.putInt(cityList.size());
for (City city : cityList)
City.serializeForClientMsg(city, temp);
temp.put((byte) 0); // PAD
// Serialize runegates
temp.putInt(Runegate._runegates.values().size());
for (Runegate runegate : Runegate._runegates.values()) {
runegate._serializeForEnterWorld(temp);
}
ArrayList<Mine> mineList = new ArrayList<>();
for (Mine toAdd : Mine.mineMap.keySet()) {
mineList.add(toAdd);
}
temp.putInt(mineList.size());
for (Mine mine : mineList)
Mine.serializeForClientMsg(mine, temp);
temp.put((byte) 0); // PAD
}
/**
* Deserializes the subclass specific items from the supplied NetMsgReader.
*/
@Override
protected void _deserialize(ByteBufferReader reader) {
// Client only sends 11 bytes.
byte type = reader.get();
if (type == 1) {
reader.get();
reader.get();
reader.getInt();
} else {
reader.get();
reader.getInt();
reader.get();
reader.getInt();
}
}
/**
* @return the s
*/
public Session getS() {
return s;
}
/**
* @return the forEnterWorld
*/
public boolean isForEnterWorld() {
return forEnterWorld;
}
public void updateCities(boolean value) {
this.updateCities = value;
}
public void updateRunegates(boolean value) {
this.updateRunegates = value;
}
public void updateMines(boolean value) {
this.updateMines = value;
}
}

10
src/engine/workthreads/HourlyJobThread.java

@ -43,20 +43,20 @@ public class HourlyJobThread implements Runnable { @@ -43,20 +43,20 @@ public class HourlyJobThread implements Runnable {
try {
Zone hotzone = ZoneManager.getHotZone();
if(hotzone == null){
if (hotzone == null) {
//no hotzone? set one.
ZoneManager.generateAndSetRandomHotzone();
}
int hotzoneDuration = Integer.valueOf(ConfigManager.MB_HOTZONE_DURATION.getValue());
if(((LocalDateTime.now().getHour()) - hotzone.becameHotzone.getHour()) >= hotzoneDuration) {
if (((LocalDateTime.now().getHour()) - hotzone.becameHotzone.getHour()) >= hotzoneDuration) {
ZoneManager.generateAndSetRandomHotzone();
hotzone = ZoneManager.getHotZone();
}
if (hotzone == null) {
Logger.error("Null hotzone returned from mapmanager");
} else {
Logger.info("new hotzone: " + hotzone.getName());
WorldServer.setLastHZChange(System.currentTimeMillis());
Logger.info("new hotzone: " + hotzone.getName());
WorldServer.setLastHZChange(System.currentTimeMillis());
}
} catch (Exception e) {
@ -187,7 +187,7 @@ public class HourlyJobThread implements Runnable { @@ -187,7 +187,7 @@ public class HourlyJobThread implements Runnable {
ArrayList<Mine> mines = Mine.getMines();
for (Mine mine : mines) {
if(LocalDateTime.now().getHour() == 1400){
if (LocalDateTime.now().getHour() == 1400) {
mine.wasClaimed = false;
}
try {

Loading…
Cancel
Save