-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updtate the anti vpn file and add a vpn search with web
- Loading branch information
Showing
4 changed files
with
182 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package util; | ||
|
||
import java.util.ArrayList; | ||
|
||
import arc.Core; | ||
import arc.util.Log; | ||
import arc.util.serialization.Jval; | ||
|
||
|
||
public class AntiVpn { | ||
public static ArrayList<String> vpnServersList = new ArrayList<>(); | ||
public static int timesLeft = 10, timesLimit = timesLeft; | ||
public static boolean isEnabled = false, vpnFileFound = true, fullLoaded = false; | ||
|
||
private boolean foundVpn = false; | ||
|
||
private AntiVpn() { | ||
} | ||
|
||
|
||
public static boolean checkIP(String ip) { | ||
AntiVpn test = new AntiVpn(); | ||
|
||
Core.net.httpGet("https://vpnapi.io/api/" + ip, s -> { | ||
Jval content = Jval.read(s.getResultAsString()); | ||
|
||
if (content.get("security") != null) test.foundVpn = content.get("security").asArray().get(0).asBool(); | ||
timesLeft = timesLimit; | ||
|
||
}, f -> { | ||
Log.err("Anti VPN: An error occurred while finding or processing the player's IP address." | ||
+ "\nError: " + f.getMessage()); | ||
|
||
if (vpnFileFound) { | ||
Log.info("The search will be done by the reference file (less reliable)."); | ||
test.foundVpn = vpnServersList.contains(ip); | ||
timesLeft = timesLimit; | ||
|
||
} else { | ||
Log.err("The reference file was not loaded. The player's IP will therefore not be verified."); | ||
|
||
if (timesLeft++ == timesLimit) { | ||
Log.warn("The unsuccessful search limit has been reached. Anti VPN will be deactivated..."); | ||
isEnabled = false; | ||
|
||
} else Log.warn("If this happens another '@' times, the anti VPN will be disabled!", timesLimit-timesLeft); | ||
} | ||
}); | ||
|
||
return test.foundVpn; | ||
} | ||
|
||
public static void init() { init(false); } | ||
public static void init(boolean loadSettings) { | ||
if (loadSettings && Core.settings.has("AntiVpn")) { | ||
try { | ||
String[] temp = Core.settings.getString("AntiVpn").split(" \\| "); | ||
isEnabled = Boolean.parseBoolean(temp[0]); | ||
timesLimit = Integer.parseInt(temp[1]); | ||
|
||
} catch (Exception e) { saveSettings(); } | ||
} | ||
|
||
if (isEnabled) { | ||
arc.files.Fi file = Core.files.local("config/ip-vpn-list.txt"); | ||
|
||
if (file.exists()) { | ||
try { | ||
Log.info("Loading anti VPN file..."); | ||
|
||
for (Object line : file.readString().lines().toArray()) vpnServersList.add((String) line); | ||
if (vpnServersList.get(0).equals("### Vpn servers list ###")) { | ||
vpnServersList.remove(0); | ||
|
||
fullLoaded = true; | ||
Log.info("File loaded!"); | ||
return; | ||
|
||
} else { | ||
vpnServersList.clear(); | ||
Log.warn("You have an old version of the file, downloading the new file..."); | ||
} | ||
} catch (Exception e) { Log.err("The anti VPN file could not be load! Try to download the file..."); } | ||
|
||
} else { | ||
Log.err("The anti VPN file was not found! Downloading the file from the web..."); | ||
try { file.file().createNewFile(); } | ||
catch (java.io.IOException e) {} | ||
} | ||
|
||
Core.net.httpGet("https://raw.githubusercontent.com/ZetaMap/moreCommands/main/ip-vpn-list.txt", s -> { | ||
file.writeBytes(s.getResult()); | ||
Object[] list = file.readString().lines().toArray(); | ||
for (Object line : list) vpnServersList.add((String) line); | ||
|
||
Log.info("File upload successful!"); | ||
fullLoaded = true; | ||
}, f -> { | ||
Log.err("The anti VPN file could not be downloaded from the web! Searches will therefore only be done by web..."); | ||
vpnFileFound = false; | ||
}); | ||
} | ||
} | ||
|
||
public static void saveSettings() { | ||
Core.settings.put("AntiVpn", isEnabled + " | " + timesLimit); | ||
} | ||
} |
Oops, something went wrong.