Remove /pcount, integrate it into /sinfo.

This commit is contained in:
UnknownShadow200 2016-06-01 00:34:07 +10:00
parent d343804aae
commit 9dae5ff8fb
5 changed files with 22 additions and 76 deletions

View File

@ -1,59 +0,0 @@
/*
Copyright 2010 MCLawl Team - Written by Valek (Modified for use with 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.Data;
using MCGalaxy.SQL;
namespace MCGalaxy.Commands {
public sealed class CmdPCount : Command {
public override string name { get { return "pcount"; } }
public override string shortcut { get { return ""; } }
public override string type { get { return CommandTypes.Information; } }
public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }
public override void Use(Player p, string message) {
int bancount = Group.findPerm(LevelPermission.Banned).playerList.All().Count;
DataTable table = Database.fillData("SELECT COUNT(id) FROM Players");
Player.Message(p, "A total of " + table.Rows[0]["COUNT(id)"] + " unique players have visited this server.");
Player.Message(p, "Of these players, " + bancount + " have been banned.");
table.Dispose();
int count = 0, hiddenCount = 0;
Player[] players = PlayerInfo.Online.Items;
foreach (Player pl in players) {
if (!Entities.CanSee(p, pl)) continue;
count++;
if (pl.hidden) hiddenCount++;
}
string verb = count == 1 ? "is " : "are ";
string qualifier = count == 1 ? " player" : " players";
if (hiddenCount == 0)
Player.Message(p, "There " + verb + count + qualifier + " online.");
else
Player.Message(p, "There " + verb + count + qualifier + " online (" + hiddenCount + " hidden).");
}
public override void Help(Player p) {
Player.Message(p, "/pcount - Displays the number of players online and total.");
}
}
}

View File

@ -16,7 +16,9 @@
permissions and limitations under the Licenses. permissions and limitations under the Licenses.
*/ */
using System; using System;
using System.Data;
using System.Diagnostics; using System.Diagnostics;
using MCGalaxy.SQL;
namespace MCGalaxy.Commands { namespace MCGalaxy.Commands {
public sealed class CmdServerInfo : Command { public sealed class CmdServerInfo : Command {
@ -36,25 +38,29 @@ namespace MCGalaxy.Commands {
public override void Use(Player p, string message) { public override void Use(Player p, string message) {
if (message != "") { Help(p); return; } if (message != "") { Help(p); return; }
Player.Message(p, "Server's name: &b" + Server.name + "%S"); // TODO: use max rowid to be faster
Player.Message(p, "&a" + Player.number + " %Splayers online, &8" DataTable table = Database.fillData("SELECT COUNT(id) FROM Players");
+ Player.GetBannedCount() + " banned%S players total."); int count = int.Parse(table.Rows[0]["COUNT(id)"].ToString());
Player.Message(p, "&a" + LevelInfo.Loaded.Count + " %Slevels currently loaded. " + table.Dispose();
"Currency is &3" + Server.moneys + "%S.");
Player.Message(p, "Server's name: &b{0}%S", Server.name);
Player.Message(p, "&a{0}%S players total. (&a{1}%S online, &8{2} banned%S)",
count, Player.number, Player.GetBannedCount());
Player.Message(p, "&a{0} %Slevels currently loaded. Currency is &3{1}%S.",
LevelInfo.Loaded.Count, Server.moneys);
TimeSpan up = DateTime.UtcNow - Server.StartTime; TimeSpan up = DateTime.UtcNow - Server.StartTime;
Player.Message(p, "Been up for &b" + WhoInfo.Shorten(up, true) + Player.Message(p, "Been up for &b" + WhoInfo.Shorten(up, true) +
"%S, and is running &bMCGalaxy &a" + Server.VersionString + "%S, running &bMCGalaxy &a" + Server.VersionString +
"%S (based on &bMCForge %Sand &bMCLawl%S)."); "%S (based on &bMCForge %Sand &bMCLawl%S).");
Command.all.Find("devs").Use(p, "");
Player.Message(p, "Player positions are updated every &b" Player.Message(p, "Player positions are updated every &b"
+ Server.updateTimer.Interval + " %Smilliseconds."); + Server.updateTimer.Interval + " %Smilliseconds.");
string owner = Server.server_owner; string owner = Server.server_owner;
if (!owner.CaselessEq("Notch")) if (!owner.CaselessEq("Notch"))
Player.Message(p, "Owner is &3" + owner + ". %SConsole state: &3" + Server.ZallState); Player.Message(p, "Owner is &3{0}. %SConsole state: &3{1}", owner, Server.ZallState);
else else
Player.Message(p, "Console state: &3" + Server.ZallState); Player.Message(p, "Console state: &3{0}", Server.ZallState);
if (CheckAdditionalPerm(p)) if (CheckAdditionalPerm(p))
ShowServerStats(p); ShowServerStats(p);

View File

@ -248,7 +248,6 @@
<Compile Include="Commands\Information\CmdOpRules.cs" /> <Compile Include="Commands\Information\CmdOpRules.cs" />
<Compile Include="Commands\Information\CmdOpStats.cs" /> <Compile Include="Commands\Information\CmdOpStats.cs" />
<Compile Include="Commands\Information\CmdPClients.cs" /> <Compile Include="Commands\Information\CmdPClients.cs" />
<Compile Include="Commands\Information\CmdPCount.cs" />
<Compile Include="Commands\Information\CmdPlayers.cs" /> <Compile Include="Commands\Information\CmdPlayers.cs" />
<Compile Include="Commands\Information\CmdRankReqs.cs" /> <Compile Include="Commands\Information\CmdRankReqs.cs" />
<Compile Include="Commands\Information\CmdRules.cs" /> <Compile Include="Commands\Information\CmdRules.cs" />

View File

@ -689,13 +689,8 @@ Next: continue;
} }
public static int GetBannedCount() { public static int GetBannedCount() {
try { Group group = Group.findPerm(LevelPermission.Banned);
return File.ReadAllLines("ranks/banned.txt").Length; return group == null ? 0 : group.playerList.Count;
}
catch/* (Exception ex)*/
{
return 0;
}
} }
#endregion #endregion

View File

@ -47,6 +47,11 @@ namespace MCGalaxy {
return new List<string>(players); return new List<string>(players);
} }
public int Count { get {
lock (locker)
return players.Count;
} }
public void Save() { Save(group.fileName, true); } public void Save() { Save(group.fileName, true); }
public void Save(string path, bool console) { public void Save(string path, bool console) {