From f913dc2229eac22d7eaf1b779efedf4dc8d224fa Mon Sep 17 00:00:00 2001 From: Ziggeh Date: Tue, 28 Jul 2015 19:23:23 +0200 Subject: [PATCH] Current amount of online players is now correctly displayed at character creation and population status is calculated relatively to GALAXY-MAX-ONLINE --- .../packets/swg/login/LoginClusterStatus.java | 18 +------- src/services/player/LoginService.java | 41 +++++++++++++++++-- 2 files changed, 39 insertions(+), 20 deletions(-) diff --git a/src/network/packets/swg/login/LoginClusterStatus.java b/src/network/packets/swg/login/LoginClusterStatus.java index 6ac790100..ead39599e 100644 --- a/src/network/packets/swg/login/LoginClusterStatus.java +++ b/src/network/packets/swg/login/LoginClusterStatus.java @@ -37,7 +37,7 @@ import resources.Galaxy; public class LoginClusterStatus extends SWGPacket { - public static final int CRC = 0x3436AEB6; + public static final int CRC = getCrc("LoginClusterStatus"); private Vector galaxies; @@ -100,20 +100,4 @@ public class LoginClusterStatus extends SWGPacket { return galaxies; } - private int getPopulationStatus(int pop) { - if (pop < 300) - return 0; // Very Light - if (pop < 600) - return 1; // Light - if (pop < 900) - return 2; // Medium - if (pop < 1200) - return 3; // Heavy - if (pop < 1500) - return 4; // Very Heavy - if (pop < 3000) - return 5; // Extremely Heavy - return 6; // Full - } - } diff --git a/src/services/player/LoginService.java b/src/services/player/LoginService.java index 7a3843657..96eb63c88 100644 --- a/src/services/player/LoginService.java +++ b/src/services/player/LoginService.java @@ -306,21 +306,29 @@ public class LoginService extends Service { Config c = getConfig(ConfigFile.PRIMARY); ResultSet set = getGalaxies.executeQuery(); List galaxies = new ArrayList(); + int maxPopulation = c.getInt("GALAXY-MAX-ONLINE", 3000); + double consumed; + int population; + try { while (set.next()) { Galaxy g = new Galaxy(); + population = set.getInt("population"); + consumed = ((double) population / maxPopulation) * 100; + g.setId(set.getInt("id")); g.setName(set.getString("name")); g.setAddress(set.getString("address")); - g.setPopulation(set.getInt("population")); + g.setPopulation(population); g.setTimeZone(set.getInt("timezone")); g.setZonePort(set.getInt("zone_port")); g.setPingPort(set.getInt("ping_port")); g.setStatus(set.getInt("status")); g.setMaxCharacters(c.getInt("GALAXY-MAX-CHARACTERS", 2)); - g.setOnlinePlayerLimit(c.getInt("GALAXY-MAX-ONLINE", 3000)); - g.setOnlineFreeTrialLimit(c.getInt("GALAXY-MAX-ONLINE", 3000)); + g.setOnlinePlayerLimit(maxPopulation); + g.setOnlineFreeTrialLimit(maxPopulation); g.setRecommended(true); + g.setPopulationStatus(populationStatus(consumed)); // If locked, restricted, or full if (p.getAccessLevel() == AccessLevel.ADMIN && g.getStatus() != GalaxyStatus.UP) g.setStatus(GalaxyStatus.UP); @@ -366,4 +374,31 @@ public class LoginService extends Service { } } + private int populationStatus(double consumed) { + double veryLight = 10; // 10% + double light = 20; // 20% + double medium = 30; // 30% + double heavy = 40; // 40% + double veryHeavy = 50; // 50% + double extremelyHeavy = 100; // 100% + int popStatus; + + if(consumed < veryLight) + popStatus = 0; + else if(consumed < light) + popStatus = 1; + else if(consumed < medium) + popStatus = 2; + else if(consumed < heavy) + popStatus = 3; + else if(consumed < veryHeavy) + popStatus = 4; + else if(consumed < extremelyHeavy) + popStatus = 5; + else + popStatus = 6; + + return popStatus; + } + }