From 16c41aba82ad49b8b228a82ec49f132ed2bf8c2d Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Wed, 25 Mar 2015 15:02:14 -0700 Subject: [PATCH] Retrofitted BungeeRotator to updating IP information. --- Plugins/Mineplex.BungeeRotator/.classpath | 6 +-- .../src/mineplex/bungee/BungeeRotator.java | 40 +++++++++++++++---- .../src/mineplex/bungee/IPGeoData.java | 2 +- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/Plugins/Mineplex.BungeeRotator/.classpath b/Plugins/Mineplex.BungeeRotator/.classpath index 7692a6421..e26939c64 100644 --- a/Plugins/Mineplex.BungeeRotator/.classpath +++ b/Plugins/Mineplex.BungeeRotator/.classpath @@ -2,12 +2,12 @@ - - - + + + diff --git a/Plugins/Mineplex.BungeeRotator/src/mineplex/bungee/BungeeRotator.java b/Plugins/Mineplex.BungeeRotator/src/mineplex/bungee/BungeeRotator.java index 795d23fdf..d08510506 100644 --- a/Plugins/Mineplex.BungeeRotator/src/mineplex/bungee/BungeeRotator.java +++ b/Plugins/Mineplex.BungeeRotator/src/mineplex/bungee/BungeeRotator.java @@ -26,11 +26,11 @@ import mineplex.serverdata.data.BungeeServer; import mineplex.serverdata.data.DataRepository; import mineplex.serverdata.redis.RedisDataRepository; import mineplex.serverdata.servers.ServerManager; -import mineplex.serverdata.servers.ServerRepository; public class BungeeRotator { private static DataRepository _repository; + private static PlayerStatsRepository _ipRepository; //private static ServerRepository _repository = null; private static SimpleDateFormat _dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); @@ -39,12 +39,6 @@ public class BungeeRotator public static void main(String args[]) { - /* - IPGeoData recor = new HttpCallBase("http://www.freegeoip.net/json/124.149.22.183").Execute(IPGeoData.class); - - System.out.println(recor.country_name + " " + recor.region_name); - */ - try { Class.forName("com.mysql.jdbc.Driver"); @@ -78,6 +72,8 @@ public class BungeeRotator _repository = new RedisDataRepository(ServerManager.getMasterConnection(), ServerManager.getSlaveConnection(), Region.ALL, BungeeServer.class, "bungeeServers"); + _ipRepository = new PlayerStatsRepository(); + BungeeSorter bungeeSorter = new BungeeSorter(); int maxRecordCount = 10; @@ -96,6 +92,9 @@ public class BungeeRotator for (BungeeServer server : bungeeServers) { + if (server.getPublicAddress().equalsIgnoreCase("127.0.0.1")) + continue; + totalPlayers += server.getPlayerCount(); if (server.getRegion() == Region.US) @@ -119,6 +118,9 @@ public class BungeeRotator for (BungeeServer server : bungeeServers) { + if (server.getPublicAddress().equalsIgnoreCase("127.0.0.1")) + continue; + if (usServers.size() < maxRecordCount && server.getRegion() == Region.US) { if (usServers.size() >= 2 && server.getPlayerCount() > 900) @@ -207,7 +209,28 @@ public class BungeeRotator log("Deleted " + recordsToDelete.size() + " records."); } } - + + List updatedAddresses = new ArrayList(1000); + + for (IpInfo ipInfo : _ipRepository.getIpAddresses()) + { + IPGeoData recor = new HttpCallBase("http://www.freegeoip.net/json/" + ipInfo.ipAddress).Execute(IPGeoData.class); + ipInfo.countryCode = recor.country_code; + ipInfo.countryName = recor.country_name; + ipInfo.regionCode = recor.region_code; + ipInfo.regionName = recor.region_name; + ipInfo.city = recor.city; + ipInfo.zipCode = recor.zip_code; + ipInfo.timeZone = recor.time_zone; + ipInfo.latitude = recor.latitude; + ipInfo.longitude = recor.longitude; + ipInfo.metroCode = recor.metro_code; + + updatedAddresses.add(ipInfo); + } + + _ipRepository.updateIps(updatedAddresses); + try { Thread.sleep(15000); @@ -220,6 +243,7 @@ public class BungeeRotator } catch (Exception ex) { + ex.printStackTrace(); log("Error doing something : " + ex.getMessage()); try diff --git a/Plugins/Mineplex.BungeeRotator/src/mineplex/bungee/IPGeoData.java b/Plugins/Mineplex.BungeeRotator/src/mineplex/bungee/IPGeoData.java index c8265c0a2..9988f681c 100644 --- a/Plugins/Mineplex.BungeeRotator/src/mineplex/bungee/IPGeoData.java +++ b/Plugins/Mineplex.BungeeRotator/src/mineplex/bungee/IPGeoData.java @@ -8,7 +8,7 @@ public class IPGeoData public String region_code; public String region_name; public String city; - public int zip_code; + public String zip_code; public String time_zone; public double latitude; public double longitude;