mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-09-06 20:28:06 +02:00
Merge pull request #105 from AuthMe-Team/geoip2
This commit is contained in:
commit
10fedfb66d
@ -253,18 +253,20 @@ public class AuthMePlayerListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
String playerIP = event.getAddress().getHostAddress();
|
||||
if (auth == null && Settings.enableProtection) {
|
||||
String countryCode = GeoLiteAPI.getCountryCode(playerIP);
|
||||
if (!Settings.countriesBlacklist.isEmpty() && Settings.countriesBlacklist.contains(countryCode)) {
|
||||
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
|
||||
event.setKickMessage(m.retrieveSingle(MessageKey.COUNTRY_BANNED_ERROR));
|
||||
return;
|
||||
}
|
||||
if (!Settings.countries.isEmpty() && !Settings.countries.contains(countryCode)) {
|
||||
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
|
||||
event.setKickMessage(m.retrieveSingle(MessageKey.COUNTRY_BANNED_ERROR));
|
||||
return;
|
||||
if (auth == null) {
|
||||
if (!Settings.countriesBlacklist.isEmpty() || !Settings.countries.isEmpty()) {
|
||||
String playerIP = event.getAddress().getHostAddress();
|
||||
String countryCode = GeoLiteAPI.getCountryCode(playerIP);
|
||||
if (Settings.countriesBlacklist.contains(countryCode)) {
|
||||
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
|
||||
event.setKickMessage(m.retrieveSingle(MessageKey.COUNTRY_BANNED_ERROR));
|
||||
return;
|
||||
}
|
||||
if (Settings.enableProtection && !Settings.countries.contains(countryCode)) {
|
||||
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
|
||||
event.setKickMessage(m.retrieveSingle(MessageKey.COUNTRY_BANNED_ERROR));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,14 +32,15 @@ public class AuthMeServerListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
String countryCode = GeoLiteAPI.getCountryCode(event.getAddress().getHostAddress());
|
||||
if (!Settings.countriesBlacklist.isEmpty() && Settings.countriesBlacklist.contains(countryCode)) {
|
||||
event.setMotd(m.retrieveSingle(MessageKey.COUNTRY_BANNED_ERROR));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Settings.countries.isEmpty() && !Settings.countries.contains(countryCode)) {
|
||||
event.setMotd(m.retrieveSingle(MessageKey.COUNTRY_BANNED_ERROR));
|
||||
if (!Settings.countriesBlacklist.isEmpty() || !Settings.countries.isEmpty()){
|
||||
String countryCode = GeoLiteAPI.getCountryCode(event.getAddress().getHostAddress());
|
||||
if( Settings.countriesBlacklist.contains(countryCode)) {
|
||||
event.setMotd(m.retrieveSingle(MessageKey.COUNTRY_BANNED_ERROR));
|
||||
return;
|
||||
}
|
||||
if (!Settings.countries.contains(countryCode)) {
|
||||
event.setMotd(m.retrieveSingle(MessageKey.COUNTRY_BANNED_ERROR));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,16 +84,16 @@ public class GeoLiteAPI {
|
||||
/**
|
||||
* Get the country code of the given IP address.
|
||||
*
|
||||
* @param ip Ip address
|
||||
* @param ip textual IP address to lookup.
|
||||
*
|
||||
* @return String
|
||||
* @return two-character ISO 3166-1 alpha code for the country.
|
||||
*/
|
||||
public static String getCountryCode(String ip) {
|
||||
if (isDataAvailable()) {
|
||||
if (!"127.0.0.1".equals(ip) && isDataAvailable()) {
|
||||
try {
|
||||
return databaseReader.country(InetAddress.getByName(ip)).getCountry().getIsoCode();
|
||||
} catch (Exception e) {
|
||||
ConsoleLogger.logException("Error while getting country code", e);
|
||||
ConsoleLogger.writeStackTrace(e);
|
||||
}
|
||||
}
|
||||
return "--";
|
||||
@ -102,16 +102,16 @@ public class GeoLiteAPI {
|
||||
/**
|
||||
* Get the country name of the given IP address.
|
||||
*
|
||||
* @param ip Ip address
|
||||
* @param ip textual IP address to lookup.
|
||||
*
|
||||
* @return String
|
||||
* @return The name of the country.
|
||||
*/
|
||||
public static String getCountryName(String ip) {
|
||||
if (isDataAvailable()) {
|
||||
if (!"127.0.0.1".equals(ip) && isDataAvailable()) {
|
||||
try {
|
||||
return databaseReader.country(InetAddress.getByName(ip)).getCountry().getName();
|
||||
} catch (Exception e) {
|
||||
ConsoleLogger.logException("Error while getting country name", e);
|
||||
ConsoleLogger.writeStackTrace(e);
|
||||
}
|
||||
}
|
||||
return "N/A";
|
||||
|
Loading…
Reference in New Issue
Block a user