Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
Fixed country database not working when check is disabled.
Browse files Browse the repository at this point in the history
  • Loading branch information
PolskiStevek committed Mar 13, 2020
1 parent b9a0999 commit 00687ac
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
10 changes: 5 additions & 5 deletions src/main/java/me/ishift/epicguard/api/GeoAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import com.maxmind.db.CHMCache;
import com.maxmind.geoip2.DatabaseReader;
import com.maxmind.geoip2.exception.GeoIp2Exception;
import me.ishift.epicguard.common.Config;
import me.ishift.epicguard.common.types.GeoMode;

import java.io.File;
import java.io.IOException;
Expand All @@ -34,8 +32,10 @@ public class GeoAPI {
/**
* Creating new GeoAPI instance.
* @param basePath Base path where every files will be downloaded.
* @param country Should country database be enabled/downloaded?
* @param city Should city database be enabled/downloaded?
*/
public GeoAPI(String basePath) {
public GeoAPI(String basePath, boolean country, boolean city) {
try {
EpicGuardAPI.getLogger().info("This product includes GeoLite2 data created by MaxMind, available from www.maxmind.com");
EpicGuardAPI.getLogger().info("By using this software, you agree to GeoLite2 EULA (https://www.maxmind.com/en/geolite2/eula)");
Expand All @@ -44,7 +44,7 @@ public GeoAPI(String basePath) {
final File cityFile = new File(basePath + "/GeoLite2-City.mmdb");
final File timestampFile = new File(basePath + "/last_db_download.txt");

if (Config.countryMode != GeoMode.DISABLED) {
if (country) {
if (!countryFile.exists() || isOutdated(timestampFile)) {
final Downloader downloader = new Downloader("https://github.com/PolskiStevek/EpicGuard/raw/master/files/GeoLite2-Country.mmdb", countryFile);
downloader.download();
Expand All @@ -55,7 +55,7 @@ public GeoAPI(String basePath) {
countryReader = new DatabaseReader.Builder(countryFile).withCache(new CHMCache()).build();
}

if (Config.geoCity) {
if (city) {
if (!cityFile.exists() || isOutdated(timestampFile)) {
final Downloader downloader = new Downloader("https://github.com/PolskiStevek/EpicGuard/raw/master/files/GeoLite2-City.mmdb", cityFile);
downloader.download();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/ishift/epicguard/bukkit/GuardBukkit.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void onEnable() {
metrics.addCustomChart(new Metrics.SingleLineChart("stoppedBots", StorageManager::getBlockedBots));
metrics.addCustomChart(new Metrics.SingleLineChart("checkedConnections", StorageManager::getCheckedConnections));

EpicGuardAPI.setGeoApi(new GeoAPI(this.getDataFolder() + "/data"));
EpicGuardAPI.setGeoApi(new GeoAPI(this.getDataFolder() + "/data", Config.countryEnabled, Config.cityEnabled));
}

@Override
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/me/ishift/epicguard/common/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public class Config {

public static List<String> countryList;
public static GeoMode countryMode;
public static boolean geoCity;
public static boolean cityEnabled;
public static boolean countryEnabled;

public static List<String> blockedNames;
public static boolean updater;
Expand Down Expand Up @@ -101,7 +102,9 @@ public static void loadBukkit() {

serverListCheck = config.getOrSetDefault("antibot.server-list-check", true);
rejoinCheck = config.getOrSetDefault("antibot.rejoin-check", true);
geoCity = config.getOrSetDefault("countries.enable-cities", false);

cityEnabled = config.getOrSetDefault("download-databases.city", true);
countryEnabled = config.getOrSetDefault("download-databases.country", true);

final String countryModeString = config.getString("countries.mode");
countryMode = GeoMode.valueOf(countryModeString);
Expand Down
9 changes: 5 additions & 4 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ countries:
list:
- GB
- DE
- PL
enable-cities: false
download-databases:
city: true
country: true

###############################
## AntiBot ##
Expand Down Expand Up @@ -72,9 +73,9 @@ updater: true

speed:
# How many connections per second should be made to activate additional checks.
connection: 7
connection: 5
# How many pings per second should be made to activate additional checks.
ping-speed: 10
ping-speed: 7

# Block tab-complete packet using ProtocolLib.
# Useful when using a multi-version server, because 1.13+ players
Expand Down
5 changes: 2 additions & 3 deletions src/main/resources/config_bungee.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ countries:
list:
- GB
- DE
- PL

###############################
## AntiBot ##
Expand Down Expand Up @@ -65,9 +64,9 @@ console-filter:

speed:
# How many connections per second should be made to activate additional checks.
connection: 7
connection: 5
# How many pings per second should be made to activate additional checks.
ping-speed: 10
ping-speed: 7

###############################
## Firewall ##
Expand Down

0 comments on commit 00687ac

Please sign in to comment.