mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-03 06:57:39 +01:00
fix geoip country returning "." if the user is joining from localhost (#2494) @latiku
Implements a check to see if the user's address is `localhost` or `127.0.0.1`, and if so return that the country is unknown. **Edit by @md678685: fixes #2471.**
This commit is contained in:
parent
0aa11b58b9
commit
b4baa28f01
@ -141,6 +141,7 @@ gcmax=\u00a76Maximum memory\:\u00a7c {0} MB.
|
|||||||
gctotal=\u00a76Allocated memory\:\u00a7c {0} MB.
|
gctotal=\u00a76Allocated memory\:\u00a7c {0} MB.
|
||||||
gcWorld=\u00a76{0} "\u00a7c{1}\u00a76"\: \u00a7c{2}\u00a76 chunks, \u00a7c{3}\u00a76 entities, \u00a7c{4}\u00a76 tiles.
|
gcWorld=\u00a76{0} "\u00a7c{1}\u00a76"\: \u00a7c{2}\u00a76 chunks, \u00a7c{3}\u00a76 entities, \u00a7c{4}\u00a76 tiles.
|
||||||
geoipJoinFormat=\u00a76Player \u00a7c{0} \u00a76comes from \u00a7c{1}\u00a76.
|
geoipJoinFormat=\u00a76Player \u00a7c{0} \u00a76comes from \u00a7c{1}\u00a76.
|
||||||
|
geoipCantFind=\u00a76Player \u00a7c{0} \u00a76comes from \u00a7an unknown country\u00a76.
|
||||||
geoIpUrlEmpty=GeoIP download url is empty.
|
geoIpUrlEmpty=GeoIP download url is empty.
|
||||||
geoIpUrlInvalid=GeoIP download url is invalid.
|
geoIpUrlInvalid=GeoIP download url is invalid.
|
||||||
givenSkull=\u00a76You have been given the skull of \u00a7c{0}\u00a76.
|
givenSkull=\u00a76You have been given the skull of \u00a7c{0}\u00a76.
|
||||||
|
@ -15,10 +15,7 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.InetAddress;
|
import java.net.*;
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@ -58,6 +55,8 @@ public class EssentialsGeoIPPlayerListener implements Listener, IConf {
|
|||||||
}
|
}
|
||||||
InetAddress address = player.getAddress().getAddress();
|
InetAddress address = player.getAddress().getAddress();
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (config.getBoolean("database.show-cities", false)) {
|
if (config.getBoolean("database.show-cities", false)) {
|
||||||
CityResponse response = mmreader.city(address);
|
CityResponse response = mmreader.city(address);
|
||||||
@ -82,6 +81,16 @@ public class EssentialsGeoIPPlayerListener implements Listener, IConf {
|
|||||||
sb.append(response.getCountry().getName());
|
sb.append(response.getCountry().getName());
|
||||||
}
|
}
|
||||||
} catch (AddressNotFoundException ex) {
|
} catch (AddressNotFoundException ex) {
|
||||||
|
|
||||||
|
if (checkIfLocal(address)) {
|
||||||
|
for (Player online : player.getServer().getOnlinePlayers()) {
|
||||||
|
User user = ess.getUser(online);
|
||||||
|
if (user.isAuthorized("essentials.geoip.show")) {
|
||||||
|
user.sendMessage(tl("geoipCantFind", u.getDisplayName()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
// GeoIP2 API forced this when address not found in their DB. jar will not complied without this.
|
// GeoIP2 API forced this when address not found in their DB. jar will not complied without this.
|
||||||
// TODO: Maybe, we can set a new custom msg about addr-not-found in messages.properties.
|
// TODO: Maybe, we can set a new custom msg about addr-not-found in messages.properties.
|
||||||
logger.log(Level.INFO, tl("cantReadGeoIpDB") + " " + ex.getLocalizedMessage());
|
logger.log(Level.INFO, tl("cantReadGeoIpDB") + " " + ex.getLocalizedMessage());
|
||||||
@ -205,4 +214,17 @@ public class EssentialsGeoIPPlayerListener implements Listener, IConf {
|
|||||||
logger.log(Level.SEVERE, tl("connectionFailed"), ex);
|
logger.log(Level.SEVERE, tl("connectionFailed"), ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
private boolean checkIfLocal(InetAddress address) {
|
||||||
|
if (address.isAnyLocalAddress() || address.isLoopbackAddress()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Double checks if address is defined on any interface
|
||||||
|
try {
|
||||||
|
return NetworkInterface.getByInetAddress(address) != null;
|
||||||
|
} catch (SocketException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user