From 9205b4faf59f6199323e1c01b24a21dfae085d71 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 28 May 2016 14:42:27 +1000 Subject: [PATCH] Remove /serverreport, integrate it into /serverinfo. --- Commands/Information/CmdServerInfo.cs | 39 ++++++++++++-- Commands/Information/CmdServerReport.cs | 70 ------------------------- MCGalaxy_.csproj | 1 - 3 files changed, 34 insertions(+), 76 deletions(-) delete mode 100644 Commands/Information/CmdServerReport.cs diff --git a/Commands/Information/CmdServerInfo.cs b/Commands/Information/CmdServerInfo.cs index d287a8b32..b632ee737 100644 --- a/Commands/Information/CmdServerInfo.cs +++ b/Commands/Information/CmdServerInfo.cs @@ -16,10 +16,12 @@ permissions and limitations under the Licenses. */ using System; +using System.Diagnostics; + namespace MCGalaxy.Commands { public sealed class CmdServerInfo : Command { - public override string name { get { return "sinfo"; } } - public override string shortcut { get { return ""; } } + public override string name { get { return "serverinfo"; } } + public override string shortcut { get { return "sinfo"; } } public override string type { get { return CommandTypes.Information; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Banned; } } @@ -27,7 +29,10 @@ namespace MCGalaxy.Commands { public override CommandAlias[] Aliases { get { return new[] { new CommandAlias("host"), new CommandAlias("zall") }; } } - + public override CommandPerm[] AdditionalPerms { + get { return new[] { new CommandPerm(LevelPermission.Admin, "+ can see server CPU and memory usage") }; } + } + public override void Use(Player p, string message) { if (message != "") { Help(p); return; } @@ -38,8 +43,8 @@ namespace MCGalaxy.Commands { "Currency is &3" + Server.moneys + "%S."); TimeSpan up = DateTime.UtcNow - Server.StartTime; - Player.Message(p, "Been online for &b" + WhoInfo.Shorten(up, true) + - "%S, and is runing &bMCGalaxy &a" + Server.VersionString + + Player.Message(p, "Been up for &b" + WhoInfo.Shorten(up, true) + + "%S, and is running &bMCGalaxy &a" + Server.VersionString + "%S (based on &bMCForge %Sand &bMCLawl%S)."); Command.all.Find("devs").Use(p, ""); @@ -50,6 +55,30 @@ namespace MCGalaxy.Commands { Player.Message(p, "Owner is &3" + owner + ". %SConsole state: &3" + Server.ZallState); else Player.Message(p, "Console state: &3" + Server.ZallState); + + if (CheckAdditionalPerm(p)) + ShowServerStats(p); + } + + void ShowServerStats(Player p) { + Process proc = Process.GetCurrentProcess(); + if (Server.PCCounter == null) { + Player.Message(p, "Starting performance counters...one second"); + Server.PCCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total"); + Server.PCCounter.BeginInit(); + Server.PCCounter.NextValue(); + + Server.ProcessCounter = new PerformanceCounter("Process", "% Processor Time", proc.ProcessName); + Server.ProcessCounter.BeginInit(); + Server.ProcessCounter.NextValue(); + } + + // Private Bytes because it is what the process has reserved for itself + int threads = proc.Threads.Count; + int mem = (int)Math.Round(proc.PrivateMemorySize64 / 1048576.0); + double cpu = Server.ProcessCounter.NextValue(), all = Server.PCCounter.NextValue(); + Player.Message(p, "&a{0}% %SCPU usage, &a{1}% %Sby all processes", cpu.ToString("F2"), all.ToString("F2")); + Player.Message(p, "&a{0}%S threads, using &a{1}%S megabytes of memory", threads, mem); } public override void Help(Player p) { diff --git a/Commands/Information/CmdServerReport.cs b/Commands/Information/CmdServerReport.cs deleted file mode 100644 index a33378e1b..000000000 --- a/Commands/Information/CmdServerReport.cs +++ /dev/null @@ -1,70 +0,0 @@ -/* - Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy) - - Dual-licensed under the Educational Community License, Version 2.0 and - the GNU General Public License, Version 3 (the "Licenses"); you may - not use this file except in compliance with the Licenses. You may - obtain a copy of the Licenses at - - http://www.opensource.org/licenses/ecl2.php - http://www.gnu.org/licenses/gpl-3.0.html - - Unless required by applicable law or agreed to in writing, - software distributed under the Licenses are distributed on an "AS IS" - BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - or implied. See the Licenses for the specific language governing - permissions and limitations under the Licenses. -*/ -using System; -using System.Diagnostics; -namespace MCGalaxy.Commands -{ - public sealed class CmdServerReport : Command - { - public override string name { get { return "serverreport"; } } - public override string shortcut { get { return "sr"; } } - public override string type { get { return CommandTypes.Information; } } - public override bool museumUsable { get { return true; } } - public override LevelPermission defaultRank { get { return LevelPermission.Admin; } } - public CmdServerReport() { } - - public override void Use(Player p, string message) - { - if (Server.PCCounter == null) - { - Player.Message(p, "Starting PCCounter...one second"); - Server.PCCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total"); - Server.PCCounter.BeginInit(); - Server.PCCounter.NextValue(); - } - if (Server.ProcessCounter == null) - { - Player.Message(p, "Starting ProcessCounter...one second"); - Server.ProcessCounter = new PerformanceCounter("Process", "% Processor Time", Process.GetCurrentProcess().ProcessName); - Server.ProcessCounter.BeginInit(); - Server.ProcessCounter.NextValue(); - } - - TimeSpan tp = Process.GetCurrentProcess().TotalProcessorTime; - TimeSpan up = (DateTime.Now - Process.GetCurrentProcess().StartTime); - - //To get actual CPU% is OS dependant - string ProcessorUsage = "CPU Usage (Processes : All Processes):" + Server.ProcessCounter.NextValue() + " : " + Server.PCCounter.NextValue(); - //Alternative Average? - //string ProcessorUsage = "CPU Usage is Not Implemented: So here is ProcessUsageTime/ProcessTotalTime:"+String.Format("00.00",(((tp.Ticks/up.Ticks))*100))+"%"; - //reports Private Bytes because it is what the process has reserved for itself and is unsharable - string MemoryUsage = "Memory Usage: " + Math.Round((double)Process.GetCurrentProcess().PrivateMemorySize64 / 1048576).ToString() + " Megabytes"; - string Uptime = "Uptime: " + up.Days + " Days " + up.Hours + " Hours " + up.Minutes + " Minutes " + up.Seconds + " Seconds"; - string Threads = "Threads: " + Process.GetCurrentProcess().Threads.Count; - Player.Message(p, Uptime); - Player.Message(p, MemoryUsage); - Player.Message(p, ProcessorUsage); - Player.Message(p, Threads); - - } - public override void Help(Player p) - { - Player.Message(p, "/serverreport - Get server CPU%, RAM usage, and uptime."); - } - } -} diff --git a/MCGalaxy_.csproj b/MCGalaxy_.csproj index 09df95e0e..f49d49543 100644 --- a/MCGalaxy_.csproj +++ b/MCGalaxy_.csproj @@ -254,7 +254,6 @@ -