Skip to content

Commit f248134

Browse files
committed
Dropped support for geolocation redirection
I have decided to remove this feature as it is not useful for the purpose it was designed for
1 parent b9824a1 commit f248134

File tree

10 files changed

+27
-185
lines changed

10 files changed

+27
-185
lines changed

lobbybalancer.iml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,6 @@
3939
<orderEntry type="library" name="Maven: me.jaimemartz:faucet-core:1.0" level="project" />
4040
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.4" level="project" />
4141
<orderEntry type="library" name="Maven: org.bstats:bstats-bungeecord:1.1" level="project" />
42-
<orderEntry type="library" name="Maven: com.maxmind.geoip2:geoip2:2.8.0" level="project" />
43-
<orderEntry type="library" name="Maven: com.maxmind.db:maxmind-db:1.2.1" level="project" />
44-
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.2" level="project" />
45-
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.4" level="project" />
46-
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
47-
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.9" level="project" />
48-
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.2" level="project" />
49-
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.0" level="project" />
50-
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.2" level="project" />
5142
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
5243
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
5344
</component>

pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,6 @@
108108
<version>LATEST</version>
109109
<scope>compile</scope>
110110
</dependency>
111-
<dependency>
112-
<groupId>com.maxmind.geoip2</groupId>
113-
<artifactId>geoip2</artifactId>
114-
<version>2.8.0</version>
115-
<scope>compile</scope>
116-
</dependency>
117111
<dependency>
118112
<groupId>junit</groupId>
119113
<artifactId>junit</artifactId>

src/main/java/me/jaimemartz/lobbybalancer/LobbyBalancer.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package me.jaimemartz.lobbybalancer;
22

3-
import com.fasterxml.jackson.databind.ext.Java7Support;
43
import me.jaimemartz.faucet.ConfigFactory;
54
import me.jaimemartz.lobbybalancer.commands.FallbackCommand;
65
import me.jaimemartz.lobbybalancer.commands.MainCommand;
76
import me.jaimemartz.lobbybalancer.commands.ManageCommand;
87
import me.jaimemartz.lobbybalancer.configuration.ConfigEntries;
98
import me.jaimemartz.lobbybalancer.connection.ServerAssignRegistry;
109
import me.jaimemartz.lobbybalancer.listener.*;
11-
import me.jaimemartz.lobbybalancer.manager.GeolocationManager;
1210
import me.jaimemartz.lobbybalancer.manager.PlayerLocker;
1311
import me.jaimemartz.lobbybalancer.ping.PingManager;
1412
import me.jaimemartz.lobbybalancer.section.SectionManager;
@@ -36,7 +34,6 @@ public class LobbyBalancer extends Plugin {
3634
private PingManager pingManager;
3735
private SectionManager sectionManager;
3836
private Command fallbackCommand, mainCommand, manageCommand;
39-
private GeolocationManager geolocationManager;
4037
private Listener connectListener, kickListener, messageListener, reloadListener;
4138

4239
@Override
@@ -90,16 +87,6 @@ private void enable() {
9087
e.printStackTrace();
9188
}
9289

93-
Logger.getLogger(Java7Support.class.getName()).setLevel(Level.SEVERE);
94-
95-
if (ConfigEntries.GEOLOCATION_ENABLED.get()) {
96-
try {
97-
geolocationManager = new GeolocationManager(this);
98-
} catch (Exception e) {
99-
e.printStackTrace();
100-
}
101-
}
102-
10390
sectionManager = new SectionManager(this);
10491

10592
try {
@@ -161,10 +148,6 @@ private void disable() {
161148
reloadListener = null;
162149
}
163150

164-
if (ConfigEntries.GEOLOCATION_ENABLED.get()) {
165-
geolocationManager = null;
166-
}
167-
168151
if (ConfigEntries.SERVER_CHECK_ENABLED.get()) {
169152
pingManager.stop();
170153
pingManager = null;
@@ -210,10 +193,6 @@ public void reloadPlugin() {
210193
getLogger().info(String.format("The plugin has been reloaded, took %sms", ending));
211194
}
212195

213-
public GeolocationManager getGeolocationManager() {
214-
return geolocationManager;
215-
}
216-
217196
public PingManager getPingManager() {
218197
return pingManager;
219198
}

src/main/java/me/jaimemartz/lobbybalancer/configuration/ConfigEntries.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ public class ConfigEntries implements ConfigEntryHolder {
1919
public static final ConfigEntry<Boolean> SERVER_CHECK_PRINT_INFO = new ConfigEntry<>(0, "settings.server-check.print-info", false);
2020
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"));
2121

22-
public static final ConfigEntry<Boolean> GEOLOCATION_ENABLED = new ConfigEntry<>(0, "settings.geolocation.enabled", true);
23-
public static final ConfigEntry<Boolean> GEOLOCATION_PRINT_INFO = new ConfigEntry<>(0, "settings.geolocation.print-info", true);
24-
2522
public static final ConfigEntry<Boolean> RECONNECT_KICK_ENABLED = new ConfigEntry<>(0, "settings.reconnect-kick.enabled", true);
2623
public static final ConfigEntry<Boolean> RECONNECT_KICK_INVERTED = new ConfigEntry<>(0, "settings.reconnect-kick.inverted", false);
2724
public static final ConfigEntry<List<String>> RECONNECT_KICK_REASONS = new ConfigEntry<>(0, "settings.reconnect-kick.reasons", Collections.emptyList());

src/main/java/me/jaimemartz/lobbybalancer/connection/ProviderType.java

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
package me.jaimemartz.lobbybalancer.connection;
22

33
import com.google.common.collect.Iterables;
4-
import com.maxmind.geoip2.exception.GeoIp2Exception;
5-
import com.maxmind.geoip2.model.CountryResponse;
6-
import com.maxmind.geoip2.record.Country;
74
import me.jaimemartz.lobbybalancer.LobbyBalancer;
8-
import me.jaimemartz.lobbybalancer.configuration.ConfigEntries;
95
import me.jaimemartz.lobbybalancer.manager.NetworkManager;
106
import me.jaimemartz.lobbybalancer.ping.PingStatus;
117
import me.jaimemartz.lobbybalancer.section.ServerSection;
128
import net.md_5.bungee.api.config.ServerInfo;
139
import net.md_5.bungee.api.connection.ProxiedPlayer;
14-
import net.md_5.bungee.config.Configuration;
1510

16-
import java.io.IOException;
17-
import java.net.InetAddress;
1811
import java.util.List;
1912
import java.util.concurrent.ThreadLocalRandom;
2013

@@ -25,48 +18,14 @@ public ServerInfo requestTarget(LobbyBalancer plugin, ServerSection section, Lis
2518
return null;
2619
}
2720
},
21+
2822
DIRECT(1, "Returns the only server in the list") {
2923
@Override
3024
public ServerInfo requestTarget(LobbyBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player) {
3125
return Iterables.getOnlyElement(list);
3226
}
3327
},
34-
LOCALIZED(2, "Returns the server that matches a region") {
35-
@Override
36-
public ServerInfo requestTarget(LobbyBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player) {
37-
Configuration rules = plugin.getConfig().getSection("settings.geolocation.rules");
38-
if (ConfigEntries.GEOLOCATION_ENABLED.get() && rules.contains(section.getName())) {
39-
Configuration rule = rules.getSection(section.getName());
40-
InetAddress address = player.getAddress().getAddress();
41-
42-
try {
43-
CountryResponse response = plugin.getGeolocationManager().getReader().country(address);
44-
Country country = response.getCountry();
45-
46-
if (ConfigEntries.GEOLOCATION_PRINT_INFO.get()) {
47-
plugin.getLogger().info(String.format(
48-
"Player Address: \"%s\", Country Code: \"%s\"",
49-
address.toString(), country.getIsoCode()
50-
));
51-
}
52-
53-
for (String name : rule.getKeys()) {
54-
List<String> countries = rule.getStringList(name);
55-
if (countries.contains(country.getIsoCode())) {
56-
ServerInfo server = plugin.getProxy().getServerInfo(name);
57-
if (server != null) {
58-
return server;
59-
}
60-
break;
61-
}
62-
}
63-
} catch (IOException | GeoIp2Exception e) {
64-
e.printStackTrace();
65-
}
66-
}
67-
return list.get(ThreadLocalRandom.current().nextInt(list.size()));
68-
}
69-
},
28+
7029
LOWEST(3, "Returns the server with the least players online") {
7130
@Override
7231
public ServerInfo requestTarget(LobbyBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player) {
@@ -85,12 +44,14 @@ public ServerInfo requestTarget(LobbyBalancer plugin, ServerSection section, Lis
8544
return target;
8645
}
8746
},
47+
8848
RANDOM(4, "Returns a random server") {
8949
@Override
9050
public ServerInfo requestTarget(LobbyBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player) {
9151
return list.get(ThreadLocalRandom.current().nextInt(list.size()));
9252
}
9353
},
54+
9455
PROGRESSIVE(5, "Returns the first server that is not full") {
9556
@Override
9657
public ServerInfo requestTarget(LobbyBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player) {
@@ -104,6 +65,7 @@ public ServerInfo requestTarget(LobbyBalancer plugin, ServerSection section, Lis
10465
return list.get(ThreadLocalRandom.current().nextInt(list.size()));
10566
}
10667
},
68+
10769
FILLER(6, "Returns the server with the most players online that is not full") {
10870
@Override
10971
public ServerInfo requestTarget(LobbyBalancer plugin, ServerSection section, List<ServerInfo> list, ProxiedPlayer player) {

src/main/java/me/jaimemartz/lobbybalancer/manager/GeolocationManager.java

Lines changed: 0 additions & 60 deletions
This file was deleted.

src/main/java/me/jaimemartz/lobbybalancer/ping/PingManager.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,17 @@ public PingManager(LobbyBalancer plugin) {
2929
storage.forEach((k, v) -> v.setOutdated(true));
3030

3131
for (ServerSection section : plugin.getSectionManager().getSections().values()) {
32-
if (stopped)
33-
break;
32+
for (ServerInfo server : section.getServers()) {
33+
if (stopped) {
34+
break;
35+
}
3436

35-
section.getServers().forEach(server -> {
3637
if (getStatus(server).isOutdated()) {
37-
track(plugin, server);
38+
update(plugin, server);
3839
}
39-
});
40+
}
4041
}
42+
4143
}, 0L, ConfigEntries.SERVER_CHECK_INTERVAL.get(), TimeUnit.MILLISECONDS);
4244
}
4345

@@ -49,15 +51,10 @@ public void stop() {
4951
}
5052
}
5153

52-
private void track(LobbyBalancer plugin, ServerInfo server) {
54+
private void update(LobbyBalancer plugin, ServerInfo server) {
5355
tactic.ping(server, (status, throwable) -> {
5456
if (status == null) {
55-
status = new PingStatus("Server Unreachable", 0, 0);
56-
}
57-
58-
if (ConfigEntries.SERVER_CHECK_PRINT_INFO.get()) {
59-
plugin.getLogger().info(String.format("Tracking server %s, status: [Description: \"%s\", Online Players: %s, Maximum Players: %s, Accessible: %s]",
60-
server.getName(), status.getDescription(), status.getOnlinePlayers(), status.getMaximumPlayers(), status.isAccessible()));
57+
status = new PingStatus();
6158
}
6259

6360
status.setOutdated(false);
@@ -69,9 +66,9 @@ public PingStatus getStatus(ServerInfo server) {
6966
PingStatus status = storage.get(server);
7067

7168
if (status == null) {
72-
status = new PingStatus(server.getMotd(), server.getPlayers().size(), Integer.MAX_VALUE);
69+
return new PingStatus(server);
70+
} else {
71+
return status;
7372
}
74-
75-
return status;
7673
}
7774
}

src/main/java/me/jaimemartz/lobbybalancer/ping/PingStatus.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
package me.jaimemartz.lobbybalancer.ping;
22

33
import me.jaimemartz.lobbybalancer.configuration.ConfigEntries;
4+
import net.md_5.bungee.api.config.ServerInfo;
45

56
public final class PingStatus {
67
private final String description;
78
private final int online, maximum;
89
private boolean outdated = true;
910

11+
public PingStatus() {
12+
this("Server Unreachable", 0, 0);
13+
}
14+
15+
public PingStatus(ServerInfo server) {
16+
this(server.getMotd(), server.getPlayers().size(), Integer.MAX_VALUE);
17+
}
18+
1019
public PingStatus(String description, int online, int maximum) {
1120
this.description = description;
1221
this.online = online;
@@ -44,10 +53,6 @@ public boolean isAccessible() {
4453
}
4554
}
4655

47-
if (online >= maximum) {
48-
return false;
49-
}
50-
51-
return true;
56+
return online < maximum;
5257
}
5358
}

src/main/java/me/jaimemartz/lobbybalancer/section/ServerSection.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,6 @@ public void load() {
123123
if (configuration.contains("provider")) {
124124
try {
125125
provider = ProviderType.valueOf(configuration.getString("provider").toUpperCase());
126-
if (provider == ProviderType.LOCALIZED) {
127-
Configuration rules = plugin.getConfig().getSection("settings.geolocation.rules");
128-
if (!rules.contains(name)) {
129-
throw new IllegalStateException(String.format("The section \"%s\" does not have a rule set in the geolocation section", this.name));
130-
}
131-
}
132126
} catch (IllegalArgumentException e) {
133127
e.printStackTrace();
134128
}

src/main/resources/config.yml

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,6 @@ settings:
9191
rules:
9292
'section-from': 'section-to'
9393

94-
# This gets the country of a player and decides to which server the player should go
95-
# Country ISO codes: http://dev.maxmind.com/geoip/legacy/codes/iso3166/
96-
# WARNING: In testing stage
97-
geolocation:
98-
# If disabled the localized provider will choose a random server
99-
enabled: false
100-
101-
# This prints info every time the plugin checks the country of a player (while being used)
102-
print-info: true
103-
104-
# The rules for the localized provider, every section using it has to have a rule
105-
# The country must be the code as specified in the link above
106-
rules:
107-
practice:
108-
'EUPractice': ["Country1", "Country2"]
109-
'USPractice': ["Country3", "Country4"]
110-
11194
# This will reload the plugin every time you execute /greload
11295
auto-reload: true
11396

0 commit comments

Comments
 (0)