Retrofitted BungeeRotator to updating IP information.

This commit is contained in:
Jonathan Williams 2015-03-25 15:02:14 -07:00
parent 6c72bc2c36
commit 16c41aba82
3 changed files with 36 additions and 12 deletions

View File

@ -2,12 +2,12 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/httpclient-4.2.jar"/>
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/httpcore-4.2.jar"/>
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/commons-codec-1.6.jar"/>
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/gson-2.2.1.jar"/>
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/javax.mail.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.Core"/>
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.ServerData"/>
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/httpclient-4.2.jar"/>
<classpathentry kind="var" path="REPO_DIR"/>
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/httpcore-4.2.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -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<BungeeServer> _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<BungeeServer>(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<IpInfo> updatedAddresses = new ArrayList<IpInfo>(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

View File

@ -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;