mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-25 14:17:29 -04:00
Remove /serverreport, integrate it into /serverinfo.
This commit is contained in:
parent
a6cf896e1b
commit
9205b4faf5
@ -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) {
|
||||
|
@ -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.");
|
||||
}
|
||||
}
|
||||
}
|
@ -254,7 +254,6 @@
|
||||
<Compile Include="Commands\Information\CmdRules.cs" />
|
||||
<Compile Include="Commands\Information\CmdSearch.cs" />
|
||||
<Compile Include="Commands\Information\CmdSeen.cs" />
|
||||
<Compile Include="Commands\Information\CmdServerReport.cs" />
|
||||
<Compile Include="Commands\Information\CmdStaff.cs" />
|
||||
<Compile Include="Commands\Information\CmdTime.cs" />
|
||||
<Compile Include="Commands\Information\CmdTop.cs" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user