mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
Refactored /whois.
This commit is contained in:
parent
62548b6f76
commit
e1aa99a090
@ -28,7 +28,7 @@ namespace MCGalaxy.Commands.Info {
|
||||
public override bool museumUsable { get { return true; } }
|
||||
public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }
|
||||
public override CommandPerm[] ExtraPerms {
|
||||
get { return new[] { new CommandPerm(LevelPermission.AdvBuilder, "+ can see IPs and if a player is whitelisted") }; }
|
||||
get { return new[] { new CommandPerm(LevelPermission.AdvBuilder, "+ can see player's IP and if on whitelist") }; }
|
||||
}
|
||||
public override CommandAlias[] Aliases {
|
||||
get { return new[] { new CommandAlias("info"), new CommandAlias("i") }; }
|
||||
@ -37,81 +37,22 @@ namespace MCGalaxy.Commands.Info {
|
||||
public override void Use(Player p, string message) {
|
||||
if (message == "") message = p.name;
|
||||
int matches;
|
||||
Player pl = PlayerInfo.FindMatches(p, message, out matches);
|
||||
PlayerData target = null;
|
||||
Player who = PlayerInfo.FindMatches(p, message, out matches);
|
||||
if (matches > 1) return;
|
||||
|
||||
WhoInfo info;
|
||||
if (matches == 1) {
|
||||
info = FromOnline(pl);
|
||||
} else {
|
||||
if (matches == 0) {
|
||||
if (!Formatter.ValidName(p, message, "player")) return;
|
||||
Player.Message(p, "Searching database for the player..");
|
||||
target = PlayerInfo.FindOfflineMatches(p, message);
|
||||
PlayerData 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) {
|
||||
WhoInfo info = new WhoInfo();
|
||||
string prefix = who.title == "" ? "" : who.color + "[" + who.titlecolor + who.title + who.color + "] ";
|
||||
info.FullName = prefix + who.ColoredName;
|
||||
info.Name = who.name;
|
||||
info.Group = who.group;
|
||||
|
||||
info.RoundsTotal = who.Game.TotalRoundsSurvived;
|
||||
info.RoundsMax = who.Game.MaxRoundsSurvived;
|
||||
info.InfectedTotal = who.Game.TotalInfected;
|
||||
info.InfectedMax = who.Game.MaxInfected;
|
||||
return info;
|
||||
}
|
||||
|
||||
WhoInfo FromOffline(PlayerData data, string message) {
|
||||
Group group = Group.findPlayerGroup(data.Name);
|
||||
string color = data.Color == "" ? group.color : data.Color;
|
||||
string prefix = data.Title == "" ? "" : color + "[" + data.TitleColor + data.Title + color + "] ";
|
||||
|
||||
WhoInfo info = new WhoInfo();
|
||||
info.FullName = prefix + color + data.Name.RemoveLastPlus();
|
||||
info.Name = data.Name;
|
||||
info.Group = group;
|
||||
|
||||
if (Server.zombie.Running) {
|
||||
ZombieStats stats = Server.zombie.LoadZombieStats(data.Name);
|
||||
info.RoundsTotal = stats.TotalRounds; info.InfectedTotal = stats.TotalInfected;
|
||||
info.RoundsMax = stats.MaxRounds; info.InfectedMax = stats.MaxInfected;
|
||||
}
|
||||
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);
|
||||
} else {
|
||||
foreach (OnlineStatPrinter printer in OnlineStat.Stats) {
|
||||
printer(p, who);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,17 +27,26 @@ namespace MCGalaxy.DB {
|
||||
|
||||
/// <summary> List of stats that can be output to /whois. </summary>
|
||||
public static List<OfflineStatPrinter> Stats = new List<OfflineStatPrinter>() {
|
||||
OfflineCoreLine,
|
||||
(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.BanLine(p, who.Name),
|
||||
(p, who) => OnlineStat.SpecialGroupLine(p, who.Name),
|
||||
(p, who) => OnlineStat.IPLine(p, who.Name, who.IP),
|
||||
};
|
||||
|
||||
static void OfflineCoreLine(Player p, PlayerData data) {
|
||||
Group group = Group.findPlayerGroup(data.Name);
|
||||
string color = data.Color == "" ? group.color : data.Color;
|
||||
string prefix = data.Title == "" ? "" : color + "[" + data.TitleColor + data.Title + color + "] ";
|
||||
string fullName = prefix + color + data.Name.RemoveLastPlus();
|
||||
OnlineStat.CoreLine(p, fullName, data.Name, group);
|
||||
}
|
||||
|
||||
static void BlocksModifiedLine(Player p, PlayerData who) {
|
||||
Player.Message(p, " Modified &a{0} %Sblocks", who.TotalModified);
|
||||
}
|
||||
|
@ -29,18 +29,30 @@ namespace MCGalaxy.DB {
|
||||
|
||||
/// <summary> List of stats that can be output to /whois. </summary>
|
||||
public static List<OnlineStatPrinter> Stats = new List<OnlineStatPrinter>() {
|
||||
OnlineCoreLine,
|
||||
(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) => BanLine(p, who.name),
|
||||
(p, who) => SpecialGroupLine(p, who.name),
|
||||
(p, who) => IPLine(p, who.name, who.ip),
|
||||
IdleLine,
|
||||
};
|
||||
|
||||
static void OnlineCoreLine(Player p, Player who) {
|
||||
string prefix = who.title == "" ? "" : who.color + "[" + who.titlecolor + who.title + who.color + "] ";
|
||||
string fullName = prefix + who.ColoredName;
|
||||
CoreLine(p, fullName, who.name, who.group);
|
||||
}
|
||||
|
||||
internal static void CoreLine(Player p, string fullName, string name, Group grp) {
|
||||
Player.Message(p, fullName + " %S(" + name + ") has:");
|
||||
Player.Message(p, " Rank of " + grp.ColoredName);
|
||||
}
|
||||
|
||||
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",
|
||||
@ -75,8 +87,8 @@ namespace MCGalaxy.DB {
|
||||
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;
|
||||
internal static void BanLine(Player p, string name) {
|
||||
if (!Group.BannedRank.playerList.Contains(name)) return;
|
||||
|
||||
string[] data = Ban.GetBanData(name);
|
||||
if (data != null) {
|
||||
|
@ -41,7 +41,7 @@ namespace MCGalaxy.Games {
|
||||
RoundsDone = 0;
|
||||
if (!SetStartLevel(level)) return;
|
||||
|
||||
HookTopStats();
|
||||
HookStats();
|
||||
Thread t = new Thread(MainLoop);
|
||||
t.Name = "MCG_ZombieGame";
|
||||
t.Start();
|
||||
@ -209,7 +209,7 @@ namespace MCGalaxy.Games {
|
||||
LastLevelName = "";
|
||||
CurLevelName = "";
|
||||
CurLevel = null;
|
||||
UnhookTopStats();
|
||||
UnhookStats();
|
||||
}
|
||||
|
||||
public BountyData FindBounty(string target) {
|
||||
@ -305,17 +305,24 @@ namespace MCGalaxy.Games {
|
||||
}
|
||||
|
||||
TopStat statMostInfected, statMaxInfected, statMostSurvived, statMaxSurvived;
|
||||
void HookTopStats() {
|
||||
OfflineStatPrinter offlineZSStats;
|
||||
OnlineStatPrinter onlineZSStats;
|
||||
void HookStats() {
|
||||
if (TopStat.Stats.Contains(statMostInfected)) return; // don't duplicate
|
||||
|
||||
statMostInfected = new TopStat("Infected", "ZombieStats", "TotalInfected",
|
||||
() => "Most players infected", TopStat.FormatInteger);
|
||||
statMaxInfected = new TopStat("Survived", "ZombieStats", "TotalRounds",
|
||||
() => "Most rounds survived", TopStat.FormatInteger);
|
||||
() => "Most rounds survived", TopStat.FormatInteger);
|
||||
statMostSurvived = new TopStat("ConsecutiveInfected", "ZombieStats", "MaxInfected",
|
||||
() => "Most consecutive infections", TopStat.FormatInteger);
|
||||
statMaxSurvived = new TopStat("ConsecutiveSurvived", "ZombieStats", "MaxRounds",
|
||||
() => "Most consecutive rounds survived", TopStat.FormatInteger);
|
||||
() => "Most consecutive rounds survived", TopStat.FormatInteger);
|
||||
|
||||
offlineZSStats = PrintOfflineZSStats;
|
||||
onlineZSStats = PrintOnlineZSStats;
|
||||
OfflineStat.Stats.Add(offlineZSStats);
|
||||
OnlineStat.Stats.Add(onlineZSStats);
|
||||
|
||||
TopStat.Stats.Add(statMostInfected);
|
||||
TopStat.Stats.Add(statMostSurvived);
|
||||
@ -323,12 +330,31 @@ namespace MCGalaxy.Games {
|
||||
TopStat.Stats.Add(statMaxSurvived);
|
||||
}
|
||||
|
||||
void UnhookTopStats() {
|
||||
void UnhookStats() {
|
||||
OfflineStat.Stats.Remove(offlineZSStats);
|
||||
OnlineStat.Stats.Remove(onlineZSStats);
|
||||
|
||||
TopStat.Stats.Remove(statMostInfected);
|
||||
TopStat.Stats.Remove(statMostSurvived);
|
||||
TopStat.Stats.Remove(statMaxInfected);
|
||||
TopStat.Stats.Remove(statMaxSurvived);
|
||||
}
|
||||
|
||||
static void PrintOnlineZSStats(Player p, Player who) {
|
||||
PrintZSStats(p, who.Game.TotalRoundsSurvived, who.Game.TotalInfected,
|
||||
who.Game.MaxRoundsSurvived, who.Game.MaxInfected);
|
||||
}
|
||||
|
||||
static void PrintOfflineZSStats(Player p, PlayerData who) {
|
||||
ZombieStats stats = Server.zombie.LoadZombieStats(who.Name);
|
||||
PrintZSStats(p, stats.TotalRounds, stats.TotalInfected,
|
||||
stats.MaxRounds, stats.MaxInfected);
|
||||
}
|
||||
|
||||
static void PrintZSStats(Player p, int rounds, int infected, int roundsMax, int infectedMax) {
|
||||
Player.Message(p, " Survived &a{0} %Srounds (max &e{1}%S)", rounds, roundsMax);
|
||||
Player.Message(p, " Infected &a{0} %Splayers (max &e{1}%S)", infected, infectedMax);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user