From f6a4c343a5d4d156e55b7c13dbf534f77ec7e4b0 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 20 Jun 2021 21:36:58 +0200 Subject: [PATCH 1/7] Add StatCommand Fix LoadEvaluation --- src/de/steamwar/bungeecore/BungeeCore.java | 1 + .../steamwar/bungeecore/LoadEvaluation.java | 4 +- .../bungeecore/commands/StatCommand.java | 48 +++++++++++++++++++ .../steamwar/messages/BungeeCore.properties | 1 + 4 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/de/steamwar/bungeecore/commands/StatCommand.java diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index 2344d56..50cb205 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -121,6 +121,7 @@ public class BungeeCore extends Plugin { new UnIgnoreCommand(); new PollresultCommand(); new ResourcereloadCommand(); + new StatCommand(); if(!EVENT_MODE){ new WebregisterCommand(); diff --git a/src/de/steamwar/bungeecore/LoadEvaluation.java b/src/de/steamwar/bungeecore/LoadEvaluation.java index 0732d75..b1f7a0d 100644 --- a/src/de/steamwar/bungeecore/LoadEvaluation.java +++ b/src/de/steamwar/bungeecore/LoadEvaluation.java @@ -64,12 +64,14 @@ public class LoadEvaluation { public static double getCPULoad() { try { - Process process = new ProcessBuilder("cat <(grep 'cpu ' /proc/stat) <(sleep 1 && grep 'cpu ' /proc/stat) | awk -v RS=\"\" '{printf \"%.2f\\n\", ($13-$2+$15-$4)*100/($13-$2+$15-$4+$16-$5)}'").start(); + Process process = new ProcessBuilder("bash", "-c", "cat <(grep 'cpu ' /proc/stat) <(sleep 1 && grep 'cpu ' /proc/stat) | awk -v RS=\"\" '{printf \"%.2f\\n\", ($13-$2+$15-$4)*100/($13-$2+$15-$4+$16-$5)}'").start(); process.waitFor(); return Double.parseDouble(new BufferedReader(new InputStreamReader(process.getInputStream())).readLine()) / 100.0; } catch (IOException e) { + e.printStackTrace(); return 1D; } catch (InterruptedException e) { + e.printStackTrace(); Thread.currentThread().interrupt(); return 1D; } diff --git a/src/de/steamwar/bungeecore/commands/StatCommand.java b/src/de/steamwar/bungeecore/commands/StatCommand.java new file mode 100644 index 0000000..e87eabd --- /dev/null +++ b/src/de/steamwar/bungeecore/commands/StatCommand.java @@ -0,0 +1,48 @@ +package de.steamwar.bungeecore.commands; + +import de.steamwar.bungeecore.LoadEvaluation; +import de.steamwar.bungeecore.Message; +import net.md_5.bungee.api.CommandSender; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +public class StatCommand extends BasicCommand { + + public StatCommand() { + super("stat", "bungeecore.softreload","stats"); + } + + @Override + public void execute(CommandSender sender, String[] args) { + try { + Process process = new ProcessBuilder("ps", "x").start(); + process.waitFor(); + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); + Map serverCounts = new HashMap<>(); + bufferedReader.lines().forEach(s -> { + if (!s.contains("--port") || s.contains("grep")) { + return; + } + String server = "SW"; + if (s.contains("ssh -L")) { + server = s.substring(s.indexOf("ssh -L") + 6).split(" ")[2]; + } + serverCounts.put(server, serverCounts.computeIfAbsent(server, s1 -> 0) + 1); + }); + serverCounts.forEach((s, integer) -> { + if (s.equals("SW")) { + Message.send("STAT_SERVER", sender, s, LoadEvaluation.getRamPercentage(), LoadEvaluation.getCPULoad(), integer); + } else { + Message.send("STAT_SERVER", sender, s.toUpperCase(), LoadEvaluation.getRemoteRamPercentage(s), LoadEvaluation.getRemoteCPULoad(s), integer); + } + }); + } catch (Exception e) { + throw new SecurityException(e.getMessage(), e); + } + } + +} diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index a92b7c5..025f2e4 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -104,6 +104,7 @@ MOD_YELLOW_PLUR=§7Deaktiviere die Mods\n§e{0}\n§7um weiter auf §eSteam§8War #Various commands ALERT=§f{0} +STAT_SERVER=§7Server §f{0} - §7Ram §f{1} §7CPU §f{2} §7Server Count §f{3} #Ban&Mute-Command BAN_TEAM_BANNED={0} §c{1} wurde von {2} {3} gebannt. §f§lGrund: §f{4} From 4120e989ce87c690903fe0782d01ccc80823cf4d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 20 Jun 2021 21:38:12 +0200 Subject: [PATCH 2/7] Add StatCommand Fix LoadEvaluation --- src/de/steamwar/bungeecore/LoadEvaluation.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/de/steamwar/bungeecore/LoadEvaluation.java b/src/de/steamwar/bungeecore/LoadEvaluation.java index b1f7a0d..59fda6c 100644 --- a/src/de/steamwar/bungeecore/LoadEvaluation.java +++ b/src/de/steamwar/bungeecore/LoadEvaluation.java @@ -68,10 +68,8 @@ public class LoadEvaluation { process.waitFor(); return Double.parseDouble(new BufferedReader(new InputStreamReader(process.getInputStream())).readLine()) / 100.0; } catch (IOException e) { - e.printStackTrace(); return 1D; } catch (InterruptedException e) { - e.printStackTrace(); Thread.currentThread().interrupt(); return 1D; } From 5959f8eb6f7ea1490a56cc271b47cfb0bb02e383 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 20 Jun 2021 21:38:45 +0200 Subject: [PATCH 3/7] Add StatCommand Fix LoadEvaluation --- .../bungeecore/commands/StatCommand.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/StatCommand.java b/src/de/steamwar/bungeecore/commands/StatCommand.java index e87eabd..5422e63 100644 --- a/src/de/steamwar/bungeecore/commands/StatCommand.java +++ b/src/de/steamwar/bungeecore/commands/StatCommand.java @@ -1,3 +1,22 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.LoadEvaluation; @@ -6,14 +25,13 @@ import net.md_5.bungee.api.CommandSender; import java.io.BufferedReader; import java.io.InputStreamReader; -import java.util.Arrays; import java.util.HashMap; import java.util.Map; public class StatCommand extends BasicCommand { public StatCommand() { - super("stat", "bungeecore.softreload","stats"); + super("stat", "bungeecore.softreload", "stats"); } @Override From fa70a46b64e12c22c0e8b42115b81fbe9e80a455 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 26 Jun 2021 08:09:23 +0200 Subject: [PATCH 4/7] Remove useless checks --- src/de/steamwar/bungeecore/commands/StatCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/commands/StatCommand.java b/src/de/steamwar/bungeecore/commands/StatCommand.java index 5422e63..506ecab 100644 --- a/src/de/steamwar/bungeecore/commands/StatCommand.java +++ b/src/de/steamwar/bungeecore/commands/StatCommand.java @@ -42,7 +42,7 @@ public class StatCommand extends BasicCommand { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); Map serverCounts = new HashMap<>(); bufferedReader.lines().forEach(s -> { - if (!s.contains("--port") || s.contains("grep")) { + if (!s.contains("--port")) { return; } String server = "SW"; From c750231b144a1bc7bef675766105cae7b1251e41 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 26 Jun 2021 11:13:01 +0200 Subject: [PATCH 5/7] Add + to Local Chat --- .../bungeecore/listeners/ChatListener.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/de/steamwar/bungeecore/listeners/ChatListener.java b/src/de/steamwar/bungeecore/listeners/ChatListener.java index b41ea78..9fd8061 100644 --- a/src/de/steamwar/bungeecore/listeners/ChatListener.java +++ b/src/de/steamwar/bungeecore/listeners/ChatListener.java @@ -19,10 +19,7 @@ package de.steamwar.bungeecore.listeners; -import de.steamwar.bungeecore.BungeeCore; -import de.steamwar.bungeecore.Message; -import de.steamwar.bungeecore.Servertype; -import de.steamwar.bungeecore.Subserver; +import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.commands.BauCommand; import de.steamwar.bungeecore.commands.TpCommand; import de.steamwar.bungeecore.comms.packets.PingPacket; @@ -51,6 +48,8 @@ public class ChatListener extends BasicListener { sanitize7(e); if(e.getMessage().startsWith("/")) onCommand(e); + else if(e.getMessage().startsWith("+")) + onPlusMessage(e); else onChat(e); } @@ -116,6 +115,21 @@ public class ChatListener extends BasicListener { scheduler.schedule(BungeeCore.get(), () -> Message.sendPrefixless("MSG_FORMAT", sender, "YoyoNow", sender.getDisplayName(), Message.parse("CHAT_YOYONOW_4", sender)), 12, TimeUnit.SECONDS); } + private void onPlusMessage(ChatEvent e) { + ProxiedPlayer p = (ProxiedPlayer) e.getSender(); + Subserver subserver = Subserver.getSubserver(p); + if(/*subserver instanceof Bauserver*/true) { + String[] smolArgs = e.getMessage().split(" "); + String[] args = new String[smolArgs.length + 1]; + smolArgs[0] = smolArgs[0].substring(1); + args[0] = ""; + System.arraycopy(smolArgs, 0, args, 1, smolArgs.length); + localChat(e, args); + } else { + onChat(e); + } + } + private void onChat(ChatEvent e){ if(e.getSender() instanceof ProxiedPlayer){ ProxiedPlayer sender = (ProxiedPlayer) e.getSender(); From 955cb8863a0e57259e490186da07c3fa0aed2993 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 26 Jun 2021 11:14:13 +0200 Subject: [PATCH 6/7] Remove Debug --- src/de/steamwar/bungeecore/listeners/ChatListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/listeners/ChatListener.java b/src/de/steamwar/bungeecore/listeners/ChatListener.java index 9fd8061..aeffc19 100644 --- a/src/de/steamwar/bungeecore/listeners/ChatListener.java +++ b/src/de/steamwar/bungeecore/listeners/ChatListener.java @@ -118,7 +118,7 @@ public class ChatListener extends BasicListener { private void onPlusMessage(ChatEvent e) { ProxiedPlayer p = (ProxiedPlayer) e.getSender(); Subserver subserver = Subserver.getSubserver(p); - if(/*subserver instanceof Bauserver*/true) { + if(subserver instanceof Bauserver) { String[] smolArgs = e.getMessage().split(" "); String[] args = new String[smolArgs.length + 1]; smolArgs[0] = smolArgs[0].substring(1); From 906be50771cd2ef488433d9a17ef596b4b048d3f Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 27 Jun 2021 08:10:15 +0200 Subject: [PATCH 7/7] Compress ChatListener.onPlusMessage --- src/de/steamwar/bungeecore/listeners/ChatListener.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/de/steamwar/bungeecore/listeners/ChatListener.java b/src/de/steamwar/bungeecore/listeners/ChatListener.java index aeffc19..12903c0 100644 --- a/src/de/steamwar/bungeecore/listeners/ChatListener.java +++ b/src/de/steamwar/bungeecore/listeners/ChatListener.java @@ -119,9 +119,8 @@ public class ChatListener extends BasicListener { ProxiedPlayer p = (ProxiedPlayer) e.getSender(); Subserver subserver = Subserver.getSubserver(p); if(subserver instanceof Bauserver) { - String[] smolArgs = e.getMessage().split(" "); + String[] smolArgs = e.getMessage().substring(1).split(" "); String[] args = new String[smolArgs.length + 1]; - smolArgs[0] = smolArgs[0].substring(1); args[0] = ""; System.arraycopy(smolArgs, 0, args, 1, smolArgs.length); localChat(e, args);