mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-25 06:04:46 -04:00
Part 1 of refactoring /whois
This commit is contained in:
parent
d1ca70d499
commit
62548b6f76
@ -38,6 +38,7 @@ namespace MCGalaxy.Commands.Info {
|
||||
if (message == "") message = p.name;
|
||||
int matches;
|
||||
Player pl = PlayerInfo.FindMatches(p, message, out matches);
|
||||
PlayerData target = null;
|
||||
if (matches > 1) return;
|
||||
|
||||
WhoInfo info;
|
||||
@ -45,12 +46,23 @@ namespace MCGalaxy.Commands.Info {
|
||||
info = FromOnline(pl);
|
||||
} else {
|
||||
if (!Formatter.ValidName(p, message, "player")) return;
|
||||
Player.Message(p, "Searching database for the player..");
|
||||
PlayerData target = PlayerInfo.FindOfflineMatches(p, message);
|
||||
Player.Message(p, "Searching database for the player..");
|
||||
target = PlayerInfo.FindOfflineMatches(p, message);
|
||||
if (target == null) return;
|
||||
info = FromOffline(target, message);
|
||||
}
|
||||
WhoInfo.Output(p, info, CheckExtraPerm(p));
|
||||
|
||||
Player.Message(p, "-------------");
|
||||
if (pl != null) {
|
||||
foreach (OnlineStatPrinter printer in OnlineStat.Stats) {
|
||||
printer(p, pl);
|
||||
}
|
||||
} else {
|
||||
foreach (OfflineStatPrinter printer in OfflineStat.Stats) {
|
||||
printer(p, target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
WhoInfo FromOnline(Player who) {
|
||||
@ -59,17 +71,6 @@ namespace MCGalaxy.Commands.Info {
|
||||
info.FullName = prefix + who.ColoredName;
|
||||
info.Name = who.name;
|
||||
info.Group = who.group;
|
||||
info.Money = who.money; info.Deaths = who.overallDeath;
|
||||
|
||||
info.TotalBlocks = who.overallBlocks; info.TotalDrawn = who.TotalDrawn;
|
||||
info.TotalPlaced = who.TotalPlaced; info.TotalDeleted = who.TotalDeleted;
|
||||
info.LoginBlocks = who.loginBlocks;
|
||||
|
||||
info.TimeSpent = who.time; info.TimeOnline = DateTime.Now - who.timeLogged;
|
||||
info.First = who.firstLogin;
|
||||
info.Logins = who.totalLogins; info.Kicks = who.totalKicked;
|
||||
info.IP = who.ip; info.AfkMessage = who.afkMessage;
|
||||
info.IdleTime = DateTime.UtcNow - who.LastAction;
|
||||
|
||||
info.RoundsTotal = who.Game.TotalRoundsSurvived;
|
||||
info.RoundsMax = who.Game.MaxRoundsSurvived;
|
||||
@ -87,17 +88,6 @@ namespace MCGalaxy.Commands.Info {
|
||||
info.FullName = prefix + color + data.Name.RemoveLastPlus();
|
||||
info.Name = data.Name;
|
||||
info.Group = group;
|
||||
info.Money = data.Money; info.Deaths = data.Deaths;
|
||||
|
||||
info.TotalBlocks = data.TotalModified; info.TotalDrawn = data.TotalDrawn;
|
||||
info.TotalPlaced = data.TotalPlaced; info.TotalDeleted = data.TotalDeleted;
|
||||
info.LoginBlocks = -1;
|
||||
|
||||
info.TimeSpent = data.TotalTime;
|
||||
info.First = data.FirstLogin;
|
||||
info.Last = data.LastLogin;
|
||||
info.Logins = data.Logins; info.Kicks = data.Kicks;
|
||||
info.IP = data.IP;
|
||||
|
||||
if (Server.zombie.Running) {
|
||||
ZombieStats stats = Server.zombie.LoadZombieStats(data.Name);
|
||||
@ -106,6 +96,24 @@ namespace MCGalaxy.Commands.Info {
|
||||
}
|
||||
return info;
|
||||
}
|
||||
|
||||
class WhoInfo {
|
||||
public string FullName, Name;
|
||||
public Group Group;
|
||||
public int RoundsTotal, RoundsMax;
|
||||
public int InfectedTotal, InfectedMax;
|
||||
|
||||
public static void Output(Player p, WhoInfo who, bool canSeeIP) {
|
||||
Player.Message(p, who.FullName + " %S(" + who.Name + ") has:");
|
||||
Player.Message(p, " Rank of " + who.Group.ColoredName);
|
||||
|
||||
if (!Server.zombie.Running) return;
|
||||
Player.Message(p, " Survived &a{0} %Srounds (max &e{1}%S)",
|
||||
who.RoundsTotal, who.RoundsMax);
|
||||
Player.Message(p, " Infected &a{0} %Splayers (max &e{1}%S)",
|
||||
who.InfectedTotal, who.InfectedMax);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
Player.Message(p, "%T/whois [name]");
|
||||
|
@ -1,106 +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 MCGalaxy.Eco;
|
||||
|
||||
namespace MCGalaxy.Commands.Info {
|
||||
class WhoInfo {
|
||||
public string FullName, Name;
|
||||
public Group Group;
|
||||
public int Money, Deaths;
|
||||
public long TotalBlocks, LoginBlocks, TotalDrawn, TotalPlaced, TotalDeleted;
|
||||
public TimeSpan TimeSpent, TimeOnline;
|
||||
public DateTime First, Last;
|
||||
public int Logins, Kicks;
|
||||
public string IP;
|
||||
public int RoundsTotal, RoundsMax;
|
||||
public int InfectedTotal, InfectedMax;
|
||||
public TimeSpan IdleTime;
|
||||
public string AfkMessage;
|
||||
|
||||
public static void Output(Player p, WhoInfo who, bool canSeeIP) {
|
||||
Player.Message(p, who.FullName + " %S(" + who.Name + ") has:");
|
||||
Player.Message(p, " Rank of " + who.Group.ColoredName);
|
||||
|
||||
if (Economy.Enabled)
|
||||
Player.Message(p, " &a{0} &cdeaths%S, &a{2} %S{3}, {1} %Sawards",
|
||||
who.Deaths, Awards.AwardAmount(who.Name), who.Money, Server.moneys);
|
||||
else
|
||||
Player.Message(p, " &a{0} &cdeaths%S, {1} %Sawards",
|
||||
who.Deaths, Awards.AwardAmount(who.Name));
|
||||
|
||||
if (who.LoginBlocks >= 0)
|
||||
Player.Message(p, " Modified &a{0} %Sblocks, &a{1} %Ssince login", who.TotalBlocks, who.LoginBlocks);
|
||||
else
|
||||
Player.Message(p, " Modified &a{0} %Sblocks", who.TotalBlocks);
|
||||
Player.Message(p, " &a{0} %Splaced, &a{1} %Sdeleted, &a{2} %Sdrawn",
|
||||
who.TotalPlaced, who.TotalDeleted, who.TotalDrawn);
|
||||
|
||||
if (who.TimeOnline.Ticks > 0)
|
||||
Player.Message(p, " Spent &a{0} %Son the server, &a{1} %Sthis session",
|
||||
who.TimeSpent.Shorten(), who.TimeOnline.Shorten());
|
||||
else
|
||||
Player.Message(p, " Spent &a{0} %Son the server", who.TimeSpent.Shorten());
|
||||
|
||||
if (who.Last.Ticks > 0)
|
||||
Player.Message(p, " First login &a" + who.First.ToString("yyyy-MM-dd")
|
||||
+ "%S, last login &a" + who.Last.ToString("yyyy-MM-dd"));
|
||||
else
|
||||
Player.Message(p, " First login on &a" + who.First.ToString("yyyy-MM-dd")
|
||||
+ "%S, and is currently &aonline");
|
||||
|
||||
Player.Message(p, " Logged in &a{0} %Stimes, &c{1} %Sof which ended in a kick", who.Logins, who.Kicks);
|
||||
if (who.Group.Permission == LevelPermission.Banned) {
|
||||
string[] data = Ban.GetBanData(who.Name);
|
||||
if (data != null) {
|
||||
Player.Message(p, " Banned for {0} by {1}",
|
||||
data[1], PlayerInfo.GetColoredName(p, data[0]));
|
||||
} else {
|
||||
Player.Message(p, " Is banned");
|
||||
}
|
||||
}
|
||||
|
||||
if (Server.Devs.CaselessContains(who.Name.RemoveLastPlus()))
|
||||
Player.Message(p, " Player is an &9{0} Developer", Server.SoftwareName);
|
||||
if (Server.Mods.CaselessContains(who.Name.RemoveLastPlus()))
|
||||
Player.Message(p, " Player is an &9{0} Moderator", Server.SoftwareName);
|
||||
if (Server.server_owner.CaselessEq(who.Name))
|
||||
Player.Message(p, " Player is the &cServer owner");
|
||||
|
||||
if (canSeeIP) {
|
||||
string ipMsg = who.IP;
|
||||
if (Server.bannedIP.Contains(who.IP)) ipMsg = "&8" + who.IP + ", which is banned";
|
||||
Player.Message(p, " The IP of " + ipMsg);
|
||||
if (Server.useWhitelist && Server.whiteList.Contains(who.Name))
|
||||
Player.Message(p, " Player is &fWhitelisted");
|
||||
}
|
||||
|
||||
if (who.AfkMessage != null) {
|
||||
Player.Message(p, " Idle for {0} (AFK {1}%S)", who.IdleTime.Shorten(), who.AfkMessage);
|
||||
} else if (who.IdleTime.TotalMinutes >= 1) {
|
||||
Player.Message(p, " Idle for {0}", who.IdleTime.Shorten());
|
||||
}
|
||||
|
||||
if (!Server.zombie.Running) return;
|
||||
Player.Message(p, " Survived &a{0} %Srounds (max &e{1}%S)",
|
||||
who.RoundsTotal, who.RoundsMax);
|
||||
Player.Message(p, " Infected &a{0} %Splayers (max &e{1}%S)",
|
||||
who.InfectedTotal, who.InfectedMax);
|
||||
}
|
||||
}
|
||||
}
|
54
MCGalaxy/Database/Stats/OfflineStat.cs
Normal file
54
MCGalaxy/Database/Stats/OfflineStat.cs
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
Copyright 2015 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.osedu.org/licenses/ECL-2.0
|
||||
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.Collections.Generic;
|
||||
|
||||
namespace MCGalaxy.DB {
|
||||
|
||||
public delegate void OfflineStatPrinter(Player p, PlayerData who);
|
||||
|
||||
/// <summary> Prints stats for an offline player in /whois. </summary>
|
||||
public static class OfflineStat {
|
||||
|
||||
/// <summary> List of stats that can be output to /whois. </summary>
|
||||
public static List<OfflineStatPrinter> Stats = new List<OfflineStatPrinter>() {
|
||||
(p, who) => OnlineStat.MiscLine(p, who.Name, who.Deaths, who.Money),
|
||||
BlocksModifiedLine,
|
||||
(p, who) => OnlineStat.BlockStatsLine(p, who.TotalPlaced, who.TotalDeleted, who.TotalDrawn),
|
||||
TimeSpentLine,
|
||||
LoginLine,
|
||||
(p, who) => OnlineStat.LoginsLine(p, who.Logins, who.Kicks),
|
||||
(p, who) => OnlineStat.BanLine(p, who.Name, Group.findPlayerGroup(who.Name)),
|
||||
(p, who) => OnlineStat.SpecialGroupLine(p, who.Name),
|
||||
(p, who) => OnlineStat.IPLine(p, who.Name, who.IP),
|
||||
};
|
||||
|
||||
static void BlocksModifiedLine(Player p, PlayerData who) {
|
||||
Player.Message(p, " Modified &a{0} %Sblocks", who.TotalModified);
|
||||
}
|
||||
|
||||
static void TimeSpentLine(Player p, PlayerData who) {
|
||||
Player.Message(p, " Spent &a{0} %Son the server", who.TotalTime.Shorten());
|
||||
}
|
||||
|
||||
static void LoginLine(Player p, PlayerData who) {
|
||||
Player.Message(p, " First login &a{0}%S, last login &a{1}",
|
||||
who.FirstLogin.ToString("yyyy-MM-dd"), who.LastLogin.ToString("yyyy-MM-dd"));
|
||||
}
|
||||
}
|
||||
}
|
120
MCGalaxy/Database/Stats/OnlineStat.cs
Normal file
120
MCGalaxy/Database/Stats/OnlineStat.cs
Normal file
@ -0,0 +1,120 @@
|
||||
/*
|
||||
Copyright 2015 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.osedu.org/licenses/ECL-2.0
|
||||
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.Collections.Generic;
|
||||
using MCGalaxy.Commands;
|
||||
using MCGalaxy.Eco;
|
||||
|
||||
namespace MCGalaxy.DB {
|
||||
|
||||
public delegate void OnlineStatPrinter(Player p, Player who);
|
||||
|
||||
/// <summary> Prints stats for an online player in /whois. </summary>
|
||||
public static class OnlineStat {
|
||||
|
||||
/// <summary> List of stats that can be output to /whois. </summary>
|
||||
public static List<OnlineStatPrinter> Stats = new List<OnlineStatPrinter>() {
|
||||
(p, who) => MiscLine(p, who.name, who.overallDeath, who.money),
|
||||
BlocksModifiedLine,
|
||||
(p, who) => BlockStatsLine(p, who.TotalPlaced, who.TotalDeleted, who.TotalDrawn),
|
||||
TimeSpentLine,
|
||||
LoginLine,
|
||||
(p, who) => LoginsLine(p, who.totalLogins, who.totalKicked),
|
||||
(p, who) => BanLine(p, who.name, who.group),
|
||||
(p, who) => SpecialGroupLine(p, who.name),
|
||||
(p, who) => IPLine(p, who.name, who.ip),
|
||||
IdleLine,
|
||||
};
|
||||
|
||||
internal static void MiscLine(Player p, string name, int deaths, int money) {
|
||||
if (Economy.Enabled) {
|
||||
Player.Message(p, " &a{0} &cdeaths%S, &a{2} %S{3}, {1} %Sawards",
|
||||
deaths, Awards.AwardAmount(name), money, Server.moneys);
|
||||
} else {
|
||||
Player.Message(p, " &a{0} &cdeaths%S, {1} %Sawards",
|
||||
deaths, Awards.AwardAmount(name));
|
||||
}
|
||||
}
|
||||
|
||||
static void BlocksModifiedLine(Player p, Player who) {
|
||||
Player.Message(p, " Modified &a{0} %Sblocks, &a{1} %Ssince login", who.overallBlocks, who.loginBlocks);
|
||||
}
|
||||
|
||||
internal static void BlockStatsLine(Player p, long placed, long deleted, long drawn) {
|
||||
Player.Message(p, " &a{0} %Splaced, &a{1} %Sdeleted, &a{2} %Sdrawn",
|
||||
placed, deleted, drawn);
|
||||
}
|
||||
|
||||
static void TimeSpentLine(Player p, Player who) {
|
||||
TimeSpan timeOnline = DateTime.Now - who.timeLogged;
|
||||
Player.Message(p, " Spent &a{0} %Son the server, &a{1} %Sthis session",
|
||||
who.time.Shorten(), timeOnline.Shorten());
|
||||
}
|
||||
|
||||
static void LoginLine(Player p, Player who) {
|
||||
Player.Message(p, " First login &a{0}%S, and is currently &aonline",
|
||||
who.firstLogin.ToString("yyyy-MM-dd"));
|
||||
}
|
||||
|
||||
internal static void LoginsLine(Player p, int logins, int kicks) {
|
||||
Player.Message(p, " Logged in &a{0} %Stimes, &c{1} %Sof which ended in a kick", logins, kicks);
|
||||
}
|
||||
|
||||
internal static void BanLine(Player p, string name, Group grp) {
|
||||
if (grp.Permission != LevelPermission.Banned) return;
|
||||
|
||||
string[] data = Ban.GetBanData(name);
|
||||
if (data != null) {
|
||||
Player.Message(p, " Banned for {0} by {1}",
|
||||
data[1], PlayerInfo.GetColoredName(p, data[0]));
|
||||
} else {
|
||||
Player.Message(p, " Is banned");
|
||||
}
|
||||
}
|
||||
|
||||
internal static void SpecialGroupLine(Player p, string name) {
|
||||
if (Server.Devs.CaselessContains(name.RemoveLastPlus()))
|
||||
Player.Message(p, " Player is an &9{0} Developer", Server.SoftwareName);
|
||||
if (Server.Mods.CaselessContains(name.RemoveLastPlus()))
|
||||
Player.Message(p, " Player is an &9{0} Moderator", Server.SoftwareName);
|
||||
if (Server.server_owner.CaselessEq(name))
|
||||
Player.Message(p, " Player is the &cServer owner");
|
||||
}
|
||||
|
||||
internal static void IPLine(Player p, string name, string ip) {
|
||||
LevelPermission seeIPPerm = CommandExtraPerms.MinPerm("whois");
|
||||
if (p != null && p.Rank < seeIPPerm) return;
|
||||
|
||||
string ipMsg = ip;
|
||||
if (Server.bannedIP.Contains(ip)) ipMsg = "&8" + ip + ", which is banned";
|
||||
|
||||
Player.Message(p, " The IP of " + ipMsg);
|
||||
if (Server.useWhitelist && Server.whiteList.Contains(name))
|
||||
Player.Message(p, " Player is &fWhitelisted");
|
||||
}
|
||||
|
||||
static void IdleLine(Player p, Player who) {
|
||||
TimeSpan idleTime = DateTime.UtcNow - who.LastAction;
|
||||
if (who.afkMessage != null) {
|
||||
Player.Message(p, " Idle for {0} (AFK {1}%S)", idleTime.Shorten(), who.afkMessage);
|
||||
} else if (idleTime.TotalMinutes >= 1) {
|
||||
Player.Message(p, " Idle for {0}", idleTime.Shorten());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -17,7 +17,6 @@
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace MCGalaxy.DB {
|
||||
|
||||
|
@ -121,16 +121,6 @@ namespace MCGalaxy {
|
||||
}
|
||||
|
||||
|
||||
internal static ColumnDesc[] createBlock = new ColumnDesc[] {
|
||||
new ColumnDesc("Username", ColumnType.Char, 20),
|
||||
new ColumnDesc("TimePerformed", ColumnType.DateTime),
|
||||
new ColumnDesc("X", ColumnType.UInt16),
|
||||
new ColumnDesc("Y", ColumnType.UInt16),
|
||||
new ColumnDesc("Z", ColumnType.UInt16),
|
||||
new ColumnDesc("Type", ColumnType.UInt8),
|
||||
new ColumnDesc("Deleted", ColumnType.Bool),
|
||||
};
|
||||
|
||||
internal static ColumnDesc[] createPortals = new ColumnDesc[] {
|
||||
new ColumnDesc("EntryX", ColumnType.UInt16),
|
||||
new ColumnDesc("EntryY", ColumnType.UInt16),
|
||||
|
@ -274,7 +274,6 @@
|
||||
<Compile Include="Commands\Information\CmdWhere.cs" />
|
||||
<Compile Include="Commands\Information\CmdWhois.cs" />
|
||||
<Compile Include="Commands\Information\CmdWhoNick.cs" />
|
||||
<Compile Include="Commands\Information\WhoInfo.cs" />
|
||||
<Compile Include="Commands\Maintenance\CmdBlockDB.cs" />
|
||||
<Compile Include="Commands\Maintenance\CmdBlockSpeed.cs" />
|
||||
<Compile Include="Commands\Maintenance\CmdInfoSwap.cs" />
|
||||
@ -412,6 +411,8 @@
|
||||
<Compile Include="Database\Backends\MySQL.cs" />
|
||||
<Compile Include="Database\ParameterisedQuery.cs" />
|
||||
<Compile Include="Database\PlayerData.cs" />
|
||||
<Compile Include="Database\Stats\OfflineStat.cs" />
|
||||
<Compile Include="Database\Stats\OnlineStat.cs" />
|
||||
<Compile Include="Database\Stats\TopStat.cs" />
|
||||
<Compile Include="Database\TableDumper.cs" />
|
||||
<Compile Include="Drawing\Brushes\Brush.cs" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user