feat: добавлен глобальный бан

- Добавлен глобальный бан
- Добавлен плагин KoshakAntiVPN
This commit is contained in:
Reider745
2023-12-30 11:16:13 +03:00
parent f88c593642
commit 0f2cc04171
4 changed files with 91 additions and 0 deletions
Binary file not shown.
@@ -1,10 +1,13 @@
package com.reider745;
import cn.nukkit.Server;
import cn.nukkit.plugin.Plugin;
import cn.nukkit.plugin.PluginDescription;
import cn.nukkit.plugin.PluginLoader;
import cn.nukkit.plugin.PluginManager;
import com.google.common.base.Preconditions;
import com.koshakmine.antivpn.KoshakAntiVPN;
import com.reider745.api.CallbackHelper;
import com.reider745.block.CustomBlock;
import com.reider745.commands.CommandsHelper;
@@ -48,6 +51,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.regex.Pattern;
import java.util.stream.Stream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
@@ -295,6 +299,21 @@ public class InnerCoreServer {
}
public void afterload() {
if(getPropertyBoolean("KoshakAntiVPN", true)){
HashMap<String, Object> description = new HashMap<>();
description.put("name", "KoshakAntiVPN");
description.put("version", "SNAPSHOT");
description.put("main", InnerCorePlugin.class.getName());
description.put("api", new ArrayList<String>());
final File dataFolderFile = new File(dataPath);
KoshakAntiVPN koshakAntiVPN = new KoshakAntiVPN();
koshakAntiVPN.init(null, Server.getInstance(), new PluginDescription(description), dataFolderFile, dataFolderFile);
koshakAntiVPN.saveDefaultConfig();
koshakAntiVPN.onLoad();
koshakAntiVPN.setEnabled();
}
Server.getInstance().getLogger().info("Registering Nukkit-MOT containment...");
PluginManager pluginManager = Server.getInstance().getPluginManager();
pluginManager.getPlugins().put(plugin.getDescription().getName(), plugin);
+1
View File
@@ -77,6 +77,7 @@ public class Main {
loader.registerHooksInitializationForClass(AndroidHooks.class);
loader.registerHooksInitializationForClass(SnowfallEverywhere.class);
loader.registerHooksInitializationForClass(BiomesHooks.class);
loader.registerHooksInitializationForClass(GlobalBanList.class);
//bug fix
loader.registerHooksInitializationForClass(EntityItemHooks.class);
@@ -0,0 +1,71 @@
package com.reider745.hooks;
import cn.nukkit.permission.BanList;
import com.reider745.api.ReflectHelper;
import com.reider745.api.hooks.HookClass;
import com.reider745.api.hooks.annotation.Hooks;
import com.reider745.api.hooks.annotation.Inject;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Arrays;
import java.util.Base64;
@Hooks(className = "cn.nukkit.permission.BanList")
public class GlobalBanList implements HookClass {
private static final String[] banList;
static {
JSONArray list = new JSONArray();
try {
final HttpURLConnection connection = (HttpURLConnection) new URL("https://api.github.com/repos/Reider745/libs/contents/global_ban_list.json?ref=main").openConnection();
connection.setRequestMethod("GET");
final int responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
final BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
final StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null)
response.append(inputLine);
in.close();
String result = "";
final String[] content_lines = new JSONObject(response.toString()).getString("content").split("\\n");
for(final String line : content_lines)
result += new String(Base64.getDecoder().decode(line));
list = new JSONArray(result);
}
} catch (Exception ignored) {
ignored.printStackTrace();
}
final String[] banListGit = new String[list.length()];
for(int i = 0;i < banListGit.length;i++)
banListGit[i] = list.getString(i);
banList = banListGit;
}
@Inject
public static boolean isBanned(BanList self, String name){
final String file = ReflectHelper.getField(self, "file");
if(file != null && file.endsWith("banned-ips.json"))
for(final String ip : banList)
if(ip.equals(name))
return true;
if (!self.isEnable() || name == null)
return false;
else
return self.getEntires().containsKey(name.toLowerCase());
}
}