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

Commit

Permalink
Added custom-proxy-check and request-limit settings.
Browse files Browse the repository at this point in the history
Former-commit-id: 95fccc8
  • Loading branch information
xishift committed Jul 15, 2020
1 parent eb5e02f commit 2c81499
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
21 changes: 18 additions & 3 deletions src/main/java/me/ishift/epicguard/core/check/impl/ProxyCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,43 @@
import java.util.List;

public class ProxyCheck extends Check {
private int requests;

public ProxyCheck(EpicGuard epicGuard) {
super(epicGuard);
}

@Override
public boolean check(String address, String nickname) {
CheckMode mode = CheckMode.valueOf(this.getConfig().proxyCheck);
String url = "http://proxycheck.io/v2/" + address + "?key=" + this.getConfig().proxyCheckKey + "&vpn=1";

switch (mode) {
case NEVER:
return false;
case ALWAYS:
return URLUtils.readString(url).contains("yes");
return this.proxyCheck(address);
case ATTACK:
if (this.getEpicGuard().isAttack()) {
return URLUtils.readString(url).contains("yes");
return this.proxyCheck(address);
}
}
return false;
}

private boolean proxyCheck(String address) {
if (this.requests > this.getConfig().requestLimit) {
return false;
}

String url = "http://proxycheck.io/v2/" + address + "?key=" + this.getConfig().proxyCheckKey + "&vpn=1";
if (!this.getConfig().customProxyCheck.equals("disabled")) {
url = this.getConfig().customProxyCheck.replace("%ip%", address);
}

this.requests++;
return URLUtils.readString(url).contains("yes");
}

@Override
public List<String> getKickMessage() {
return this.getEpicGuard().getMessages().kickMessageProxy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ public class PluginConfiguration {
@CfgComment(" ")
@CfgComment("")

@CfgComment("If you want to use other proxy/vpn checker")
@CfgComment("than default (proxycheck.io), you can set it here.")
@CfgComment("Available placeholders: %ip%")
@CfgStringStyle(CfgStringStyle.StringStyle.ALWAYS_QUOTED)
@CfgName("custom-proxy-check-url")
public String customProxyCheck = "disabled";

@CfgComment("Limit of requests sent by the proxy/vpn checker.")
@CfgComment("Default (1000) is limit for proxycheck.io with free key.")
@CfgComment("request-limit")
public int requestLimit = 1000;

@CfgComment("If log message contains one of these words, it will")
@CfgComment("be hidden. This can save a lot of CPU on big attacks.")
@CfgCollectionStyle(CfgCollectionStyle.CollectionStyle.ALWAYS_NEW_LINE)
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/me/ishift/epicguard/core/user/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ public class Account {
private final List<String> nicknames;

public Account(EpicGuard epicGuard, String address, String nickname) {
this.nicknames = epicGuard.getStorageManager().getData().getStringList("account-limiter." + address);
String ip = address.replace(".", "@");
this.nicknames = epicGuard.getStorageManager().getData().getStringList("account-limiter." + ip);
if (!this.nicknames.contains(nickname)) {
this.nicknames.add(nickname);
}
epicGuard.getStorageManager().getData().set("account-limiter." + address, this.nicknames);
epicGuard.getStorageManager().getData().set("account-limiter." + ip, this.nicknames);
}

public List<String> getNicknames() {
Expand Down

0 comments on commit 2c81499

Please sign in to comment.