Skip to content

Commit

Permalink
Use fast sqlite path for total number of players in /sinfo.
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Jun 9, 2016
1 parent be59b95 commit 96a947c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 19 deletions.
8 changes: 4 additions & 4 deletions Commands/Information/CmdHelp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ internal static void PrintCommandInfo(Player p, Command cmd) {
CommandPerm[] addPerms = cmd.AdditionalPerms;
if (addPerms == null) return;

Player.Message(p, "%TAdditional permissions:");
Player.Message(p, "%TExtra permissions:");
for (int i = 0; i < addPerms.Length; i++) {
var addition = CommandOtherPerms.Find(cmd, i + 1);
LevelPermission perm = (LevelPermission)addition.Permission;
Player.Message(p, GetColoredRank(perm) + "%S" + addition.Description);
var extra = CommandOtherPerms.Find(cmd, i + 1);
LevelPermission perm = (LevelPermission)extra.Permission;
Player.Message(p, "{0}) {1}%S{2}", i + 1, GetColoredRank(perm), extra.Description);
}
}

Expand Down
25 changes: 19 additions & 6 deletions Commands/Information/CmdServerInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,9 @@ public override CommandPerm[] AdditionalPerms {
public override void Use(Player p, string message) {
if (message != "") { Help(p); return; }

// 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());
GetPlayerCount(), Player.number, Player.GetBannedCount());
Player.Message(p, "&a{0} %Slevels currently loaded. Currency is &3{1}%S.",
LevelInfo.Loaded.Count, Server.moneys);

Expand All @@ -66,6 +61,24 @@ public override void Use(Player p, string message) {
ShowServerStats(p);
}

static int GetPlayerCount() {
// Use fast path if possible TODO: fast path for mysql
int count = 0;
if (!Server.useMySQL) {
DataTable maxTable = Database.fillData("SELECT MAX(_ROWID_) FROM Players LIMIT 1;");
if (maxTable.Rows.Count > 0) {
string row = maxTable.Rows[0]["MAX(_ROWID_)"].ToString();
maxTable.Dispose();
if (int.TryParse(row, out count) && count > 0) return count;
}
}

DataTable table = Database.fillData("SELECT COUNT(id) FROM Players");
count = int.Parse(table.Rows[0]["COUNT(id)"].ToString());
table.Dispose();
return count;
}

void ShowServerStats(Player p) {
Process proc = Process.GetCurrentProcess();
if (Server.PCCounter == null) {
Expand Down
9 changes: 4 additions & 5 deletions Commands/Moderation/CmdCmdSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ public override void Use(Player p, string message) {
} else {
CommandOtherPerms.OtherPerms perms = CommandOtherPerms.Find(cmd, otherPermIndex);
if (perms == null) {
Player.Message(p, "This command has no additional permission with that number."); return;
Player.Message(p, "This command has no extra permission with that number."); return;
}

perms.Permission = (int)grp.Permission;
CommandOtherPerms.Save();
string permName = "additional permission " + otherPermIndex;
string permName = "extra permission " + otherPermIndex;
Player.GlobalMessage("&d" + cmd.name + "%S's " + permName + " was set to " + grp.ColoredName);
Player.Message(p, cmd.name + "'s " + permName + " was set to " + grp.ColoredName);
}
Expand All @@ -89,9 +89,8 @@ public override void Help(Player p) {
Player.Message(p, "%HAllows a specific rank to use [cmd]");
Player.Message(p, "%T/cmdset [cmd] [rank] disallow");
Player.Message(p, "%HPrevents a specific rank from using [cmd]");
Player.Message(p, "%T/cmdset [cmd] [rank] <additional permission number>");
Player.Message(p, "%HSet the lowest rank that has that additional permission for [cmd] " +
"(Most commands do not use these)");
Player.Message(p, "%T/cmdset [cmd] [rank] <extra permission number>");
Player.Message(p, "%HSet the lowest rank that has that extra permission for [cmd]");
Player.Message(p, "To see available ranks, type %T/viewranks");
}
}
Expand Down
2 changes: 1 addition & 1 deletion Commands/World/CmdMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ software distributed under the Licenses are distributed on an "AS IS"
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
namespace MCGalaxy.Commands {
namespace MCGalaxy.Commands.World {
public sealed class CmdMain : Command {

public override string name { get { return "main"; } }
Expand Down
3 changes: 0 additions & 3 deletions Commands/World/CmdMuseum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ permissions and limitations under the Licenses.
*/
using System;
using System.IO;
using System.IO.Compression;
using System.Net;
using System.Threading;
using MCGalaxy.Levels.IO;

namespace MCGalaxy.Commands.World {
Expand Down

0 comments on commit 96a947c

Please sign in to comment.