Dropped support for geolocation redirection

I have decided to remove this feature as it is not useful for the purpose it was designed for
This commit is contained in:
Jaime Martinez Rincon 2017-04-16 20:45:36 +02:00
parent b9824a1f81
commit f248134192
10 changed files with 28 additions and 186 deletions

View File

@ -39,15 +39,6 @@
<orderEntry type="library" name="Maven: me.jaimemartz:faucet-core:1.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.4" level="project" />
<orderEntry type="library" name="Maven: org.bstats:bstats-bungeecord:1.1" level="project" />
<orderEntry type="library" name="Maven: com.maxmind.geoip2:geoip2:2.8.0" level="project" />
<orderEntry type="library" name="Maven: com.maxmind.db:maxmind-db:1.2.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.4" level="project" />
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.9" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.2" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.0" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
</component>

View File

@ -108,12 +108,6 @@
<version>LATEST</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.maxmind.geoip2</groupId>
<artifactId>geoip2</artifactId>
<version>2.8.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>

View File

@ -1,6 +1,5 @@
package me.jaimemartz.lobbybalancer;
import com.fasterxml.jackson.databind.ext.Java7Support;
import me.jaimemartz.faucet.ConfigFactory;
import me.jaimemartz.lobbybalancer.commands.FallbackCommand;
import me.jaimemartz.lobbybalancer.commands.MainCommand;
@ -8,7 +7,6 @@ import me.jaimemartz.lobbybalancer.commands.ManageCommand;
import me.jaimemartz.lobbybalancer.configuration.ConfigEntries;
import me.jaimemartz.lobbybalancer.connection.ServerAssignRegistry;
import me.jaimemartz.lobbybalancer.listener.*;
import me.jaimemartz.lobbybalancer.manager.GeolocationManager;
import me.jaimemartz.lobbybalancer.manager.PlayerLocker;
import me.jaimemartz.lobbybalancer.ping.PingManager;
import me.jaimemartz.lobbybalancer.section.SectionManager;
@ -36,7 +34,6 @@ public class LobbyBalancer extends Plugin {
private PingManager pingManager;
private SectionManager sectionManager;
private Command fallbackCommand, mainCommand, manageCommand;
private GeolocationManager geolocationManager;
private Listener connectListener, kickListener, messageListener, reloadListener;
@Override
@ -90,16 +87,6 @@ public class LobbyBalancer extends Plugin {
e.printStackTrace();
}
Logger.getLogger(Java7Support.class.getName()).setLevel(Level.SEVERE);
if (ConfigEntries.GEOLOCATION_ENABLED.get()) {
try {
geolocationManager = new GeolocationManager(this);
} catch (Exception e) {
e.printStackTrace();
}
}
sectionManager = new SectionManager(this);
try {
@ -161,10 +148,6 @@ public class LobbyBalancer extends Plugin {
reloadListener = null;
}
if (ConfigEntries.GEOLOCATION_ENABLED.get()) {
geolocationManager = null;
}
if (ConfigEntries.SERVER_CHECK_ENABLED.get()) {
pingManager.stop();
pingManager = null;
@ -210,10 +193,6 @@ public class LobbyBalancer extends Plugin {
getLogger().info(String.format("The plugin has been reloaded, took %sms", ending));
}
public GeolocationManager getGeolocationManager() {
return geolocationManager;
}
public PingManager getPingManager() {
return pingManager;
}

View File

@ -19,9 +19,6 @@ public class ConfigEntries implements ConfigEntryHolder {
public static final ConfigEntry<Boolean> SERVER_CHECK_PRINT_INFO = new ConfigEntry<>(0, "settings.server-check.print-info", false);
public static final ConfigEntry<List<String>> SERVER_CHECK_MARKER_DESCS = new ConfigEntry<>(0, "settings.server-check.marker-descs", Arrays.asList("Server is not accessible", "Gamemode has already started"));
public static final ConfigEntry<Boolean> GEOLOCATION_ENABLED = new ConfigEntry<>(0, "settings.geolocation.enabled", true);
public static final ConfigEntry<Boolean> GEOLOCATION_PRINT_INFO = new ConfigEntry<>(0, "settings.geolocation.print-info", true);
public static final ConfigEntry<Boolean> RECONNECT_KICK_ENABLED = new ConfigEntry<>(0, "settings.reconnect-kick.enabled", true);
public static final ConfigEntry<Boolean> RECONNECT_KICK_INVERTED = new ConfigEntry<>(0, "settings.reconnect-kick.inverted", false);
public static final ConfigEntry<List<String>> RECONNECT_KICK_REASONS = new ConfigEntry<>(0, "settings.reconnect-kick.reasons", Collections.emptyList());

View File

@ -1,20 +1,13 @@
package me.jaimemartz.lobbybalancer.connection;
import com.google.common.collect.Iterables;
import com.maxmind.geoip2.exception.GeoIp2Exception;
import com.maxmind.geoip2.model.CountryResponse;
import com.maxmind.geoip2.record.Country;
import me.jaimemartz.lobbybalancer.LobbyBalancer;
import me.jaimemartz.lobbybalancer.configuration.ConfigEntries;
import me.jaimemartz.lobbybalancer.manager.NetworkManager;
import me.jaimemartz.lobbybalancer.ping.PingStatus;
import me.jaimemartz.lobbybalancer.section.ServerSection;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.config.Configuration;
import java.io.IOException;
import java.net.InetAddress;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
@ -25,48 +18,14 @@ public enum ProviderType {
return null;
}
},
DIRECT(1, "Returns the only server in the list") {
@Override
public ServerInfo requestTarget(LobbyBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player) {
return Iterables.getOnlyElement(list);
}
},
LOCALIZED(2, "Returns the server that matches a region") {
@Override
public ServerInfo requestTarget(LobbyBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player) {
Configuration rules = plugin.getConfig().getSection("settings.geolocation.rules");
if (ConfigEntries.GEOLOCATION_ENABLED.get() && rules.contains(section.getName())) {
Configuration rule = rules.getSection(section.getName());
InetAddress address = player.getAddress().getAddress();
try {
CountryResponse response = plugin.getGeolocationManager().getReader().country(address);
Country country = response.getCountry();
if (ConfigEntries.GEOLOCATION_PRINT_INFO.get()) {
plugin.getLogger().info(String.format(
"Player Address: \"%s\", Country Code: \"%s\"",
address.toString(), country.getIsoCode()
));
}
for (String name : rule.getKeys()) {
List<String> countries = rule.getStringList(name);
if (countries.contains(country.getIsoCode())) {
ServerInfo server = plugin.getProxy().getServerInfo(name);
if (server != null) {
return server;
}
break;
}
}
} catch (IOException | GeoIp2Exception e) {
e.printStackTrace();
}
}
return list.get(ThreadLocalRandom.current().nextInt(list.size()));
}
},
LOWEST(3, "Returns the server with the least players online") {
@Override
public ServerInfo requestTarget(LobbyBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player) {
@ -85,12 +44,14 @@ public enum ProviderType {
return target;
}
},
RANDOM(4, "Returns a random server") {
@Override
public ServerInfo requestTarget(LobbyBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player) {
return list.get(ThreadLocalRandom.current().nextInt(list.size()));
}
},
PROGRESSIVE(5, "Returns the first server that is not full") {
@Override
public ServerInfo requestTarget(LobbyBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player) {
@ -104,6 +65,7 @@ public enum ProviderType {
return list.get(ThreadLocalRandom.current().nextInt(list.size()));
}
},
FILLER(6, "Returns the server with the most players online that is not full") {
@Override
public ServerInfo requestTarget(LobbyBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player) {

View File

@ -1,60 +0,0 @@
package me.jaimemartz.lobbybalancer.manager;
import com.maxmind.db.CHMCache;
import com.maxmind.geoip2.DatabaseReader;
import me.jaimemartz.lobbybalancer.LobbyBalancer;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.util.zip.GZIPInputStream;
public class GeolocationManager {
private final DatabaseReader reader;
public GeolocationManager(LobbyBalancer plugin) throws IOException {
File dir = new File(plugin.getDataFolder(), "database");
if (!dir.exists()) {
dir.mkdir();
}
File packed = new File(dir, "GeoLite2-Country.mmdb.gz");
File database = new File(dir, "GeoLite2-Country.mmdb");
if (!database.exists()) {
plugin.getLogger().info("Downloading database");
URL url = new URL("http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.mmdb.gz");
try (ReadableByteChannel rbc = Channels.newChannel(url.openStream())) {
try (FileOutputStream fos = new FileOutputStream(packed)) {
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
}
}
plugin.getLogger().info("Unpacking database");
byte[] buffer = new byte[1024];
try (GZIPInputStream in = new GZIPInputStream(new FileInputStream(packed))) {
try (FileOutputStream out = new FileOutputStream(database)) {
int len;
while ((len = in.read(buffer)) > 0) {
out.write(buffer, 0, len);
}
}
}
plugin.getLogger().info("Deleting packed archive, success: " + (packed.delete() ? "yes" : "no"));
} else {
plugin.getLogger().info("Database exists, no need to download again");
}
plugin.getLogger().info("Initializing database");
reader = new DatabaseReader.Builder(database).withCache(new CHMCache()).build();
}
public DatabaseReader getReader() {
return reader;
}
}

View File

@ -29,15 +29,17 @@ public class PingManager {
storage.forEach((k, v) -> v.setOutdated(true));
for (ServerSection section : plugin.getSectionManager().getSections().values()) {
if (stopped)
break;
section.getServers().forEach(server -> {
if (getStatus(server).isOutdated()) {
track(plugin, server);
for (ServerInfo server : section.getServers()) {
if (stopped) {
break;
}
});
if (getStatus(server).isOutdated()) {
update(plugin, server);
}
}
}
}, 0L, ConfigEntries.SERVER_CHECK_INTERVAL.get(), TimeUnit.MILLISECONDS);
}
@ -49,15 +51,10 @@ public class PingManager {
}
}
private void track(LobbyBalancer plugin, ServerInfo server) {
private void update(LobbyBalancer plugin, ServerInfo server) {
tactic.ping(server, (status, throwable) -> {
if (status == null) {
status = new PingStatus("Server Unreachable", 0, 0);
}
if (ConfigEntries.SERVER_CHECK_PRINT_INFO.get()) {
plugin.getLogger().info(String.format("Tracking server %s, status: [Description: \"%s\", Online Players: %s, Maximum Players: %s, Accessible: %s]",
server.getName(), status.getDescription(), status.getOnlinePlayers(), status.getMaximumPlayers(), status.isAccessible()));
status = new PingStatus();
}
status.setOutdated(false);
@ -69,9 +66,9 @@ public class PingManager {
PingStatus status = storage.get(server);
if (status == null) {
status = new PingStatus(server.getMotd(), server.getPlayers().size(), Integer.MAX_VALUE);
return new PingStatus(server);
} else {
return status;
}
return status;
}
}

View File

@ -1,12 +1,21 @@
package me.jaimemartz.lobbybalancer.ping;
import me.jaimemartz.lobbybalancer.configuration.ConfigEntries;
import net.md_5.bungee.api.config.ServerInfo;
public final class PingStatus {
private final String description;
private final int online, maximum;
private boolean outdated = true;
public PingStatus() {
this("Server Unreachable", 0, 0);
}
public PingStatus(ServerInfo server) {
this(server.getMotd(), server.getPlayers().size(), Integer.MAX_VALUE);
}
public PingStatus(String description, int online, int maximum) {
this.description = description;
this.online = online;
@ -44,10 +53,6 @@ public final class PingStatus {
}
}
if (online >= maximum) {
return false;
}
return true;
return online < maximum;
}
}

View File

@ -123,12 +123,6 @@ public class ServerSection {
if (configuration.contains("provider")) {
try {
provider = ProviderType.valueOf(configuration.getString("provider").toUpperCase());
if (provider == ProviderType.LOCALIZED) {
Configuration rules = plugin.getConfig().getSection("settings.geolocation.rules");
if (!rules.contains(name)) {
throw new IllegalStateException(String.format("The section \"%s\" does not have a rule set in the geolocation section", this.name));
}
}
} catch (IllegalArgumentException e) {
e.printStackTrace();
}

View File

@ -91,23 +91,6 @@ settings:
rules:
'section-from': 'section-to'
# This gets the country of a player and decides to which server the player should go
# Country ISO codes: http://dev.maxmind.com/geoip/legacy/codes/iso3166/
# WARNING: In testing stage
geolocation:
# If disabled the localized provider will choose a random server
enabled: false
# This prints info every time the plugin checks the country of a player (while being used)
print-info: true
# The rules for the localized provider, every section using it has to have a rule
# The country must be the code as specified in the link above
rules:
practice:
'EUPractice': ["Country1", "Country2"]
'USPractice': ["Country3", "Country4"]
# This will reload the plugin every time you execute /greload
auto-reload: true