Fix /whonick returning 'player not online' when multiple people matched the given nickname.

This commit is contained in:
UnknownShadow200 2017-08-11 16:44:41 +10:00
parent f452602912
commit 2697c934cd
7 changed files with 14 additions and 31 deletions

View File

@ -99,7 +99,7 @@ namespace MCGalaxy.Commands.Bots{
Player.Message(p, "Created new bot AI: &b" + ai); Player.Message(p, "Created new bot AI: &b" + ai);
using (StreamWriter w = new StreamWriter("bots/" + ai)) using (StreamWriter w = new StreamWriter("bots/" + ai))
w.WriteLine("#Version 2"); w.WriteLine("#Version 2");
} else if (instructions[0] != "#Version 2") { } else if (!instructions[0].CaselessEq("#Version 2")) {
Player.Message(p, "File found is out-of-date. Overwriting"); Player.Message(p, "File found is out-of-date. Overwriting");
File.Delete("bots/" + ai); File.Delete("bots/" + ai);
using (StreamWriter w = new StreamWriter("bots/" + ai)) using (StreamWriter w = new StreamWriter("bots/" + ai))

View File

@ -28,11 +28,18 @@ namespace MCGalaxy.Commands.Info {
public override void Use(Player p, string message) { public override void Use(Player p, string message) {
if (message.Length == 0) { Help(p); return; } if (message.Length == 0) { Help(p); return; }
Player nick = PlayerInfo.FindNick(p, message); Player nick = FindNick(p, message);
if (nick == null) {
Player.Message(p, "The player is not online."); return; if (nick == null) return;
}
Player.Message(p, "This player's real username is " + nick.name); Player.Message(p, "This player's real username is " + nick.name);
}
static Player FindNick(Player p, string nick) {
nick = Colors.Strip(nick);
Player[] players = PlayerInfo.Online.Items;
int matches = 0;
return Matcher.Find<Player>(p, nick, out matches, players, pl => Entities.CanSee(p, pl),
pl => Colors.Strip(pl.DisplayName), "online player nicks");
} }
public override void Help(Player p) { public override void Help(Player p) {

View File

@ -46,7 +46,7 @@ namespace MCGalaxy.Core {
case ModActionType.Warned: case ModActionType.Warned:
AddNote(action, "W"); break; AddNote(action, "W"); break;
case ModActionType.Ban: case ModActionType.Ban:
string banType = action.Duration.Ticks == 0 ? "B" : "T"; string banType = action.Duration.Ticks != 0 ? "T" : "B";
AddNote(action, banType); break; AddNote(action, banType); break;
} }
} }

View File

@ -378,9 +378,6 @@ namespace MCGalaxy {
[Obsolete("Use PlayerInfo.FindExact(name)")] [Obsolete("Use PlayerInfo.FindExact(name)")]
public static Player FindExact(string name) { return PlayerInfo.FindExact(name); } public static Player FindExact(string name) { return PlayerInfo.FindExact(name); }
[Obsolete("Use PlayerInfo.FindNick(name)")]
public static Player FindNick(string name) { return PlayerInfo.FindNick(null, name); }
unsafe static byte NextFreeId() { unsafe static byte NextFreeId() {
byte* used = stackalloc byte[256]; byte* used = stackalloc byte[256];
for (int i = 0; i < 256; i++) for (int i = 0; i < 256; i++)

View File

@ -25,8 +25,6 @@ namespace MCGalaxy {
/// <summary> Array of all currently online players. </summary> /// <summary> Array of all currently online players. </summary>
/// <remarks> Note this field is highly volatile, you should cache references to the items array. </remarks> /// <remarks> Note this field is highly volatile, you should cache references to the items array. </remarks>
public static VolatileArray<Player> Online = new VolatileArray<Player>(true); public static VolatileArray<Player> Online = new VolatileArray<Player>(true);
[Obsolete("Use PlayerInfo.Online.Items")]
public static List<Player> players;
public static Group GetGroup(string name) { return Group.GroupIn(name); } public static Group GetGroup(string name) { return Group.GroupIn(name); }
@ -89,23 +87,6 @@ namespace MCGalaxy {
} }
return null; return null;
} }
public static Player FindNick(Player p, string nick) {
nick = Colors.Strip(nick);
Player[] players = PlayerInfo.Online.Items;
Player match = null; int matches = 0;
foreach (Player pl in players) {
if (!Entities.CanSee(p, pl)) continue;
string name = Colors.Strip(pl.DisplayName);
if (name.CaselessEq(nick)) return pl;
if (name.CaselessContains(nick)) {
match = pl; matches++;
}
}
return matches == 1 ? match : null;
}
/// <summary> Retrieves from the database the player data for the player /// <summary> Retrieves from the database the player data for the player

View File

@ -36,7 +36,7 @@ namespace MCGalaxy {
public static IRCBot IRC; public static IRCBot IRC;
public static Thread locationChecker; public static Thread locationChecker;
public static DateTime StartTime, StartTimeLocal; public static DateTime StartTime;
public static PlayerExtList AutoloadMaps; public static PlayerExtList AutoloadMaps;
public static PlayerMetaList RankInfo = new PlayerMetaList("text/rankinfo.txt"); public static PlayerMetaList RankInfo = new PlayerMetaList("text/rankinfo.txt");

View File

@ -76,12 +76,10 @@ namespace MCGalaxy {
#pragma warning disable 0618 #pragma warning disable 0618
Player.players = PlayerInfo.Online.list; Player.players = PlayerInfo.Online.list;
PlayerInfo.players = PlayerInfo.Online.list;
Server.levels = LevelInfo.Loaded.list; Server.levels = LevelInfo.Loaded.list;
#pragma warning restore 0618 #pragma warning restore 0618
StartTime = DateTime.UtcNow; StartTime = DateTime.UtcNow;
StartTimeLocal = StartTime.ToLocalTime();
shuttingDown = false; shuttingDown = false;
Logger.Log(LogType.SystemActivity, "Starting Server"); Logger.Log(LogType.SystemActivity, "Starting Server");
ServicePointManager.Expect100Continue = false; ServicePointManager.Expect100Continue = false;