Upload via Git Manager GUI - StatusAPI.java

This commit is contained in:
2026-04-02 06:25:28 +00:00
parent e89c75df5d
commit 9409302954

View File

@@ -5,6 +5,10 @@ import net.md_5.bungee.api.config.ListenerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Plugin;
import net.viper.status.module.ModuleManager;
import net.viper.status.modules.antibot.AntiBotModule;
import net.viper.status.modules.network.NetworkInfoModule;
import net.viper.status.modules.AutoMessage.AutoMessageModule;
import net.viper.status.modules.customcommands.CustomCommandModule;
import net.viper.status.stats.PlayerStats;
import net.viper.status.stats.StatsModule;
import net.viper.status.modules.verify.VerifyModule;
@@ -71,6 +75,10 @@ public class StatusAPI extends Plugin implements Runnable {
moduleManager.registerModule(new BroadcastModule());
moduleManager.registerModule(new CommandBlockerModule());
moduleManager.registerModule(new ChatModule());
moduleManager.registerModule(new AntiBotModule());
moduleManager.registerModule(new NetworkInfoModule());
moduleManager.registerModule(new AutoMessageModule());
moduleManager.registerModule(new CustomCommandModule());
try {
Class<?> forumBridge = Class.forName("net.viper.status.modules.forum.ForumBridgeModule");
@@ -149,6 +157,10 @@ public class StatusAPI extends Plugin implements Runnable {
}
}
public ModuleManager getModuleManager() {
return moduleManager;
}
// --- Update Logik ---
private void checkAndMaybeUpdate() {
try {
@@ -289,6 +301,66 @@ public class StatusAPI extends Plugin implements Runnable {
return;
}
// --- POST /broadcast/cancel ---
if ("POST".equalsIgnoreCase(method) && path.equalsIgnoreCase("/network/attack")) {
int contentLength = 0;
if (headers.containsKey("content-length")) {
try { contentLength = Integer.parseInt(headers.get("content-length")); } catch (NumberFormatException ignored) {}
}
char[] bodyChars = new char[Math.max(0, contentLength)];
if (contentLength > 0) {
int read = 0;
while (read < contentLength) {
int r = in.read(bodyChars, read, contentLength - read);
if (r == -1) break;
read += r;
}
}
String body = new String(bodyChars);
String apiKeyHeader = headers.getOrDefault("x-api-key", headers.getOrDefault("x-apikey", ""));
NetworkInfoModule mod = (NetworkInfoModule) moduleManager.getModule("NetworkInfoModule");
if (mod == null || !mod.isEnabled() || !mod.isAttackNotificationsEnabled()) {
sendHttpResponse(out, "{\"success\":false,\"error\":\"network_module_disabled\"}", 403);
return;
}
if (!mod.isAttackApiKeyValid(apiKeyHeader)) {
sendHttpResponse(out, "{\"success\":false,\"error\":\"bad_api_key\"}", 403);
return;
}
String eventType = extractJsonString(body, "event");
if (eventType == null || eventType.trim().isEmpty()) eventType = "detected";
String source = extractJsonString(body, "source");
Integer cps = null;
Integer blockedIps = null;
Long blockedConnections = null;
String cpsStr = extractJsonString(body, "connectionsPerSecond");
if (cpsStr == null || cpsStr.isEmpty()) cpsStr = extractJsonString(body, "cps");
try { if (cpsStr != null && !cpsStr.isEmpty()) cps = Integer.valueOf(cpsStr.trim()); } catch (Exception ignored) {}
String blockedIpsStr = extractJsonString(body, "ipAddressesBlocked");
if (blockedIpsStr == null || blockedIpsStr.isEmpty()) blockedIpsStr = extractJsonString(body, "blockedIps");
try { if (blockedIpsStr != null && !blockedIpsStr.isEmpty()) blockedIps = Integer.valueOf(blockedIpsStr.trim()); } catch (Exception ignored) {}
String blockedConnectionsStr = extractJsonString(body, "connectionsBlocked");
if (blockedConnectionsStr == null || blockedConnectionsStr.isEmpty()) blockedConnectionsStr = extractJsonString(body, "blockedConnections");
try { if (blockedConnectionsStr != null && !blockedConnectionsStr.isEmpty()) blockedConnections = Long.valueOf(blockedConnectionsStr.trim()); } catch (Exception ignored) {}
boolean sent = mod.sendAttackNotification(eventType, cps, blockedIps, blockedConnections, source);
if (sent) {
sendHttpResponse(out, "{\"success\":true}", 200);
} else {
sendHttpResponse(out, "{\"success\":false,\"error\":\"webhook_disabled_or_missing\"}", 400);
}
return;
}
// --- POST /broadcast/cancel ---
if ("POST".equalsIgnoreCase(method) && (path.equalsIgnoreCase("/broadcast/cancel") || path.equalsIgnoreCase("/cancel"))) {
int contentLength = 0;
@@ -493,6 +565,16 @@ public class StatusAPI extends Plugin implements Runnable {
}
data.put("players", playersList);
NetworkInfoModule networkInfoModule = (NetworkInfoModule) moduleManager.getModule("NetworkInfoModule");
if (networkInfoModule != null && networkInfoModule.isEnabled()) {
data.put("network", networkInfoModule.buildSnapshot());
}
AntiBotModule antiBotModule = (AntiBotModule) moduleManager.getModule("AntiBotModule");
if (antiBotModule != null && antiBotModule.isEnabled()) {
data.put("antibot", antiBotModule.buildSnapshot());
}
String json = buildJsonString(data);
byte[] jsonBytes = json.getBytes("UTF-8");
StringBuilder response = new StringBuilder();