From 9dae5ff8fb737a3db8e94c27439124aa873971bf Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 1 Jun 2016 00:34:07 +1000 Subject: [PATCH] Remove /pcount, integrate it into /sinfo. --- Commands/Information/CmdPCount.cs | 59 --------------------------- Commands/Information/CmdServerInfo.cs | 24 +++++++---- MCGalaxy_.csproj | 1 - Player/Player.cs | 9 +--- Player/PlayerList.cs | 5 +++ 5 files changed, 22 insertions(+), 76 deletions(-) delete mode 100644 Commands/Information/CmdPCount.cs diff --git a/Commands/Information/CmdPCount.cs b/Commands/Information/CmdPCount.cs deleted file mode 100644 index 6753ba83a..000000000 --- a/Commands/Information/CmdPCount.cs +++ /dev/null @@ -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."); - } - } -} diff --git a/Commands/Information/CmdServerInfo.cs b/Commands/Information/CmdServerInfo.cs index dd263d313..5a46054a7 100644 --- a/Commands/Information/CmdServerInfo.cs +++ b/Commands/Information/CmdServerInfo.cs @@ -16,7 +16,9 @@ permissions and limitations under the Licenses. */ using System; +using System.Data; using System.Diagnostics; +using MCGalaxy.SQL; namespace MCGalaxy.Commands { public sealed class CmdServerInfo : Command { @@ -36,25 +38,29 @@ namespace MCGalaxy.Commands { public override void Use(Player p, string message) { if (message != "") { Help(p); return; } - Player.Message(p, "Server's name: &b" + Server.name + "%S"); - Player.Message(p, "&a" + Player.number + " %Splayers online, &8" - + Player.GetBannedCount() + " banned%S players total."); - Player.Message(p, "&a" + LevelInfo.Loaded.Count + " %Slevels currently loaded. " + - "Currency is &3" + Server.moneys + "%S."); + // TODO: use max rowid to be faster + DataTable table = Database.fillData("SELECT COUNT(id) FROM Players"); + int count = int.Parse(table.Rows[0]["COUNT(id)"].ToString()); + table.Dispose(); + + 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; 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)."); - Command.all.Find("devs").Use(p, ""); Player.Message(p, "Player positions are updated every &b" + Server.updateTimer.Interval + " %Smilliseconds."); string owner = Server.server_owner; 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 - Player.Message(p, "Console state: &3" + Server.ZallState); + Player.Message(p, "Console state: &3{0}", Server.ZallState); if (CheckAdditionalPerm(p)) ShowServerStats(p); diff --git a/MCGalaxy_.csproj b/MCGalaxy_.csproj index d4c2e689b..19fead384 100644 --- a/MCGalaxy_.csproj +++ b/MCGalaxy_.csproj @@ -248,7 +248,6 @@ - diff --git a/Player/Player.cs b/Player/Player.cs index b4d36ee0c..7755b3eb2 100644 --- a/Player/Player.cs +++ b/Player/Player.cs @@ -689,13 +689,8 @@ Next: continue; } public static int GetBannedCount() { - try { - return File.ReadAllLines("ranks/banned.txt").Length; - } - catch/* (Exception ex)*/ - { - return 0; - } + Group group = Group.findPerm(LevelPermission.Banned); + return group == null ? 0 : group.playerList.Count; } #endregion diff --git a/Player/PlayerList.cs b/Player/PlayerList.cs index a586022fd..28d09d6b4 100644 --- a/Player/PlayerList.cs +++ b/Player/PlayerList.cs @@ -47,6 +47,11 @@ namespace MCGalaxy { return new List(players); } + public int Count { get { + lock (locker) + return players.Count; + } } + public void Save() { Save(group.fileName, true); } public void Save(string path, bool console) {