diff --git a/Commands/Moderation/CmdPossess.cs b/Commands/Moderation/CmdPossess.cs index 37b62d3c9..ffd977ef4 100644 --- a/Commands/Moderation/CmdPossess.cs +++ b/Commands/Moderation/CmdPossess.cs @@ -67,7 +67,7 @@ namespace MCGalaxy.Commands { Player.Message(p, "That player is either following someone or already possessed."); return; } if (p.possess != "") { - Player prev = PlayerInfo.Find(p.possess); + Player prev = PlayerInfo.FindExact(p.possess); if (prev != null) { prev.following = ""; prev.canBuild = true; diff --git a/GUI/Window.cs b/GUI/Window.cs index 6a7cc8b49..d6b411e2f 100644 --- a/GUI/Window.cs +++ b/GUI/Window.cs @@ -74,7 +74,7 @@ namespace MCGalaxy.Gui { UpdateListTimer.Elapsed += delegate { try { - UpdateClientList(PlayerInfo.players); + UpdateClientList(Player.players); UpdateMapList(); } catch { } // needed for slower computers @@ -219,14 +219,14 @@ namespace MCGalaxy.Gui { //dgvPlayers.SuspendLayout(); pc = new PlayerCollection(); - PlayerInfo.players.ForEach(p => pc.Add(p)); + Player.players.ForEach(p => pc.Add(p)); //dgvPlayers.Invalidate(); main_Players.DataSource = pc; // Reselect player if (selected != null) { - foreach (Player t in PlayerInfo.players) + foreach (Player t in Player.players) for (int j = 0; j < main_Players.Rows.Count; j++) if (Equals(main_Players.Rows[j].Cells[0].Value, selected)) main_Players.Rows[j].Selected = true; @@ -536,7 +536,7 @@ namespace MCGalaxy.Gui { } void LoginBt_Click(object sender, EventArgs e) { - if (curPlayer == null || !PlayerInfo.players.Contains(curPlayer)) { + if (curPlayer == null || !Player.players.Contains(curPlayer)) { PlayersTextBox.AppendTextAndScroll("No Player Selected"); return; } CP437Writer.WriteAllText("text/login/" + curPlayer.name + ".txt", pl_txtLogin.Text); @@ -544,7 +544,7 @@ namespace MCGalaxy.Gui { } void LogoutBt_Click(object sender, EventArgs e) { - if (curPlayer == null || !PlayerInfo.players.Contains(curPlayer)) { + if (curPlayer == null || !Player.players.Contains(curPlayer)) { PlayersTextBox.AppendTextAndScroll("No Player Selected"); return; } CP437Writer.WriteAllText("text/logout/" + curPlayer.name + ".txt", pl_txtLogout.Text); @@ -552,7 +552,7 @@ namespace MCGalaxy.Gui { } void TitleBt_Click(object sender, EventArgs e) { - if (curPlayer == null || !PlayerInfo.players.Contains(curPlayer)) { + if (curPlayer == null || !Player.players.Contains(curPlayer)) { PlayersTextBox.AppendTextAndScroll("No Player Selected"); return; } if (pl_txtTitle.Text.Length > 17) { PlayersTextBox.AppendTextAndScroll("Title must be under 17 letters."); return; } @@ -561,7 +561,7 @@ namespace MCGalaxy.Gui { } void ColorBt_Click(object sender, EventArgs e) { - if (curPlayer == null || !PlayerInfo.players.Contains(curPlayer)) { + if (curPlayer == null || !Player.players.Contains(curPlayer)) { PlayersTextBox.AppendTextAndScroll("No Player Selected"); return; } curPlayer.color = Colors.Parse(pl_cmbColor.Text); @@ -569,7 +569,7 @@ namespace MCGalaxy.Gui { } void MapBt_Click(object sender, EventArgs e) { - if (curPlayer == null || !PlayerInfo.players.Contains(curPlayer)) { + if (curPlayer == null || !Player.players.Contains(curPlayer)) { PlayersTextBox.AppendTextAndScroll("No Player Selected"); return; } if (pl_cmbMap.Text.ToLower() == curPlayer.level.name.ToLower()) { @@ -588,7 +588,7 @@ namespace MCGalaxy.Gui { } void UndoBt_Click(object sender, EventArgs e) { - if (curPlayer == null || !PlayerInfo.players.Contains(curPlayer)) { + if (curPlayer == null || !Player.players.Contains(curPlayer)) { PlayersTextBox.AppendTextAndScroll("No Player Selected"); return; } if (pl_txtUndo.Text.Trim() == "") { @@ -604,7 +604,7 @@ namespace MCGalaxy.Gui { } void MessageBt_Click(object sender, EventArgs e) { - if (curPlayer == null || !PlayerInfo.players.Contains(curPlayer)) { + if (curPlayer == null || !Player.players.Contains(curPlayer)) { PlayersTextBox.AppendTextAndScroll("No Player Selected"); return; } Player.SendMessage(curPlayer, " " + pl_txtMessage.Text); @@ -613,7 +613,7 @@ namespace MCGalaxy.Gui { } void ImpersonateORSendCmdBt_Click(object sender, EventArgs e) { - if (curPlayer == null || !PlayerInfo.players.Contains(curPlayer)) { + if (curPlayer == null || !Player.players.Contains(curPlayer)) { PlayersTextBox.AppendTextAndScroll("No Player Selected"); return; } try { @@ -669,7 +669,7 @@ namespace MCGalaxy.Gui { void IPBanBt_Click(object sender, EventArgs e) { DoCmd("banip", "IP-Banned"); } void DoCmd(string cmdName, string action) { - if (curPlayer == null || !PlayerInfo.players.Contains(curPlayer)) { + if (curPlayer == null || !Player.players.Contains(curPlayer)) { PlayersTextBox.AppendTextAndScroll("No Player Selected"); return; } Command.all.Find(cmdName).Use(null, curPlayer.name); @@ -677,7 +677,7 @@ namespace MCGalaxy.Gui { } void DoCmd(string cmdName, string action, string prefix) { - if (curPlayer == null || !PlayerInfo.players.Contains(curPlayer)) { + if (curPlayer == null || !Player.players.Contains(curPlayer)) { PlayersTextBox.AppendTextAndScroll("No Player Selected"); return; } Command.all.Find(cmdName).Use(null, prefix + curPlayer.name); @@ -686,7 +686,7 @@ namespace MCGalaxy.Gui { void DoToggle(string cmdName, Button target, string targetDesc, Predicate getter, string action) { - if (curPlayer == null || !PlayerInfo.players.Contains(curPlayer)) { + if (curPlayer == null || !Player.players.Contains(curPlayer)) { PlayersTextBox.AppendTextAndScroll("No Player Selected"); return; } Command.all.Find(cmdName).Use(null, curPlayer.name); @@ -701,7 +701,7 @@ namespace MCGalaxy.Gui { } void SendRulesTxt_Click(object sender, EventArgs e) { - if (curPlayer == null || !PlayerInfo.players.Contains(curPlayer)) { + if (curPlayer == null || !Player.players.Contains(curPlayer)) { PlayersTextBox.AppendTextAndScroll("No Player Selected"); return; } Command.all.Find("rules").Use(curPlayer, ""); @@ -709,7 +709,7 @@ namespace MCGalaxy.Gui { } void SpawnBt_Click(object sender, EventArgs e) { - if (curPlayer == null || !PlayerInfo.players.Contains(curPlayer)) { + if (curPlayer == null || !Player.players.Contains(curPlayer)) { PlayersTextBox.AppendTextAndScroll("No Player Selected"); return; } Player p = curPlayer; @@ -722,11 +722,9 @@ namespace MCGalaxy.Gui { public void UpdatePlyersListBox() { RunOnUiThread( - delegate - { - + delegate { PlyersListBox.Items.Clear(); - foreach (Player p in PlayerInfo.players) + foreach (Player p in Player.players) { PlyersListBox.Items.Add(p.name); } diff --git a/Player/Player.cs b/Player/Player.cs index d36b6db11..377bdf592 100644 --- a/Player/Player.cs +++ b/Player/Player.cs @@ -362,13 +362,13 @@ catch { }*/ } public bool IsAloneOnCurrentLevel() { - return PlayerInfo.players.All(pl => pl.level != level || pl == this); + return Player.players.All(pl => pl.level != level || pl == this); } #endregion #region == OTHER == - [Obsolete("Use PlayerInfo.players")] + [Obsolete("Use PlayerInfo.Online.Items")] public static List players; [Obsolete("Use PlayerInfo.Find(name)")] diff --git a/Player/PlayerInfo.cs b/Player/PlayerInfo.cs index fd46b362c..a6459ec4a 100644 --- a/Player/PlayerInfo.cs +++ b/Player/PlayerInfo.cs @@ -19,15 +19,13 @@ using System.Data; using MCGalaxy.SQL; namespace MCGalaxy { - - public static class PlayerInfo { - public static List players; - + public static class PlayerInfo { + /// Array of all currently online players. /// Note this field is highly volatile, you should cache references to the items array. public static VolatileArray Online = new VolatileArray(true); - - public static List GetPlayers() { return new List(players); } + [Obsolete("Use PlayerInfo.Online.Items")] + public static List players; public static Group GetGroup(string name) { return Group.findPlayerGroup(name); } @@ -52,7 +50,8 @@ namespace MCGalaxy { int matches = 0; return FindMatches(pl, name, out matches, onlyCanSee); } - public static Player FindMatches(Player pl, string name, out int matches, bool onlyCanSee = true) { + public static Player FindMatches(Player pl, string name, + out int matches, bool onlyCanSee = true) { matches = 0; if (!Player.ValidName(name)) { Player.Message(pl, "\"{0}\" is not a valid player name.", name); return null; @@ -63,6 +62,8 @@ namespace MCGalaxy { p => p.name, "online players"); } + /// Finds the online player whose name caselessly exactly matches the given name. + /// Player instance if an exact match is found, null if not. public static Player FindExact(string name) { Player[] players = PlayerInfo.Online.Items; @@ -90,6 +91,9 @@ namespace MCGalaxy { } + /// Retrieves the player data for the player whose name + /// caselessly exactly matches the given name. + /// PlayerData instance if found, null if not. public static PlayerData FindData(string name) { using (DataTable results = Query(name, "*")) { if (results.Rows.Count == 0) return null; @@ -97,13 +101,19 @@ namespace MCGalaxy { } } + /// Retrieves the actual name for the player whose name + /// caselessly exactly matches the given name. + /// Correctly cased name if found, null if not. public static string FindName(string name) { using (DataTable playerDB = Query(name, "Name")) { if (playerDB.Rows.Count == 0) return null; return playerDB.Rows[0]["Name"].ToString().Trim(); } } - + + /// Retrieves the last IP address for the player whose name + /// caselessly exactly matches the given name. + /// Last IP address if found, null if not. public static string FindIP(string name) { using (DataTable results = Query(name, "IP")) { if (results.Rows.Count == 0) return null; @@ -139,6 +149,8 @@ namespace MCGalaxy { } } + /// Retrieves the names of all players whose last IP address + /// matches the given IP address. public static List FindAccounts(string ip) { DataTable clones = Database.Fill("SELECT Name FROM Players WHERE IP=@0", ip); List alts = new List(); diff --git a/Server/Server.cs b/Server/Server.cs index f995be2fb..7af773c23 100644 --- a/Server/Server.cs +++ b/Server/Server.cs @@ -60,8 +60,8 @@ namespace MCGalaxy { serverConfig = ConfigElement.GetAll(typeof(Server), typeof(ZombieGame)); levelConfig = ConfigElement.GetAll(typeof(Level)); - PlayerInfo.players = PlayerInfo.Online.list; Player.players = PlayerInfo.Online.list; + PlayerInfo.players = PlayerInfo.Online.list; Server.levels = LevelInfo.Loaded.list; PlayerBot.playerbots = PlayerBot.Bots.list; StartTime = DateTime.UtcNow; @@ -164,7 +164,7 @@ namespace MCGalaxy { string api = ""; API API = new API(); API.max_players = (int)Server.players; - API.players = PlayerInfo.players.Select(mc => mc.name).ToArray(); + API.players = Player.players.Select(mc => mc.name).ToArray(); API.chat = Player.Last50Chat.ToArray(); api = JsonConvert.SerializeObject(API, Formatting.Indented); return api; @@ -290,7 +290,7 @@ namespace MCGalaxy { } public void PlayerListUpdate() { - if (Server.s.OnPlayerListChange != null) Server.s.OnPlayerListChange(PlayerInfo.players); + if (Server.s.OnPlayerListChange != null) Server.s.OnPlayerListChange(Player.players); } public void FailBeat() {