diff --git a/MinecraftClient/Commands/List.cs b/MinecraftClient/Commands/List.cs index f660e039..da9368e0 100644 --- a/MinecraftClient/Commands/List.cs +++ b/MinecraftClient/Commands/List.cs @@ -8,18 +8,11 @@ namespace MinecraftClient.Commands public class List : Command { public override string CMDName { get { return "list"; } } - public override string CMDDesc { get { return "list [raw]: get the player list."; } } + public override string CMDDesc { get { return "list: get the player list."; } } public override string Run(McTcpClient handler, string command) { - bool rawNames = getArg(command).ToLower() == "raw"; - return "PlayerList: " - + String.Join(", ", - handler.GetOnlinePlayers() - .OrderBy(player => player.Name) - .Select(player => rawNames - ? player.Name - : player.DisplayName)); + return "PlayerList: " + String.Join(", ", handler.GetOnlinePlayers()); } } } diff --git a/MinecraftClient/McTcpClient.cs b/MinecraftClient/McTcpClient.cs index ec56755f..3a3e28b8 100644 --- a/MinecraftClient/McTcpClient.cs +++ b/MinecraftClient/McTcpClient.cs @@ -23,7 +23,7 @@ namespace MinecraftClient private static readonly List cmd_names = new List(); private static readonly Dictionary cmds = new Dictionary(); - private readonly Dictionary onlinePlayers = new Dictionary(); + private readonly Dictionary onlinePlayers = new Dictionary(); private readonly List bots = new List(); private static readonly List scripts_on_hold = new List(); @@ -569,16 +569,16 @@ namespace MinecraftClient /// Triggered when a new player joins the game /// /// UUID of the player - /// Info about this player - public void OnPlayerJoin(PlayerInfo info) + /// Name of the player + public void OnPlayerJoin(Guid uuid, string name) { //Ignore placeholders eg 0000tab# from TabListPlus - if (!ChatBot.IsValidName(info.Name)) + if (!ChatBot.IsValidName(name)) return; lock (onlinePlayers) { - onlinePlayers[info.UUID] = info; + onlinePlayers[uuid] = name; } } @@ -598,7 +598,7 @@ namespace MinecraftClient /// Get a set of online player names /// /// Online player names - public PlayerInfo[] GetOnlinePlayers() + public string[] GetOnlinePlayers() { lock (onlinePlayers) { @@ -606,21 +606,6 @@ namespace MinecraftClient } } - /// - /// Get an online player by UUID - /// - /// Player UUID - /// The player, or NULL if not found - public PlayerInfo GetPlayer(Guid uuid) - { - lock (onlinePlayers) - { - if (onlinePlayers.ContainsKey(uuid)) - return onlinePlayers[uuid]; - return null; - } - } - /// /// Registers the given plugin channel for the given bot. /// diff --git a/MinecraftClient/MinecraftClient.csproj b/MinecraftClient/MinecraftClient.csproj index d3934de4..35a9ff85 100644 --- a/MinecraftClient/MinecraftClient.csproj +++ b/MinecraftClient/MinecraftClient.csproj @@ -148,7 +148,6 @@ - diff --git a/MinecraftClient/Protocol/Handlers/Protocol16.cs b/MinecraftClient/Protocol/Handlers/Protocol16.cs index a31b7c38..aa9a7e23 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol16.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol16.cs @@ -160,7 +160,7 @@ namespace MinecraftClient.Protocol.Handlers case 0xC9: string name = readNextString(); bool online = readNextByte() != 0x00; readData(2); Guid FakeUUID = new Guid(MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(name)).Take(16).ToArray()); - if (online) { handler.OnPlayerJoin(new PlayerInfo(FakeUUID, name)); } else { handler.OnPlayerLeave(FakeUUID); } + if (online) { handler.OnPlayerJoin(FakeUUID, name); } else { handler.OnPlayerLeave(FakeUUID); } break; case 0xCA: if (protocolversion >= 72) { readData(9); } else readData(3); break; case 0xCB: autocomplete_result = readNextString(); autocomplete_received = true; break; diff --git a/MinecraftClient/Protocol/Handlers/Protocol18.cs b/MinecraftClient/Protocol/Handlers/Protocol18.cs index 24459d8e..dc411b30 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol18.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol18.cs @@ -437,27 +437,17 @@ namespace MinecraftClient.Protocol.Handlers } readNextVarInt(packetData); readNextVarInt(packetData); - string displayName = name; if (readNextBool(packetData)) - displayName = readNextString(packetData); - handler.OnPlayerJoin(new PlayerInfo(uuid, name, displayName)); + readNextString(packetData); + handler.OnPlayerJoin(uuid, name); break; case 0x01: //Update gamemode case 0x02: //Update latency readNextVarInt(packetData); break; case 0x03: //Update display name - bool hasDisplayName = readNextBool(packetData); - string newDisplayName = null; - if (hasDisplayName) - newDisplayName = readNextString(packetData); - PlayerInfo player = handler.GetPlayer(uuid); - if (player != null) - { - if (hasDisplayName) - player.DisplayName = newDisplayName; - else player.DisplayName = player.Name; - } + if (readNextBool(packetData)) + readNextString(packetData); break; case 0x04: //Player Leave handler.OnPlayerLeave(uuid); @@ -475,7 +465,7 @@ namespace MinecraftClient.Protocol.Handlers short ping = readNextShort(packetData); Guid FakeUUID = new Guid(MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(name)).Take(16).ToArray()); if (online) - handler.OnPlayerJoin(new PlayerInfo(FakeUUID, name)); + handler.OnPlayerJoin(FakeUUID, name); else handler.OnPlayerLeave(FakeUUID); } break; diff --git a/MinecraftClient/Protocol/IMinecraftComHandler.cs b/MinecraftClient/Protocol/IMinecraftComHandler.cs index 882c2d3f..4f5e3df5 100644 --- a/MinecraftClient/Protocol/IMinecraftComHandler.cs +++ b/MinecraftClient/Protocol/IMinecraftComHandler.cs @@ -22,8 +22,7 @@ namespace MinecraftClient.Protocol string GetUsername(); string GetUserUUID(); string GetSessionID(); - PlayerInfo[] GetOnlinePlayers(); - PlayerInfo GetPlayer(Guid uuid); + string[] GetOnlinePlayers(); Location GetCurrentLocation(); World GetWorld(); @@ -41,8 +40,8 @@ namespace MinecraftClient.Protocol /// This method is called when a new player joins the game /// /// UUID of the player - /// Info about this player - void OnPlayerJoin(PlayerInfo info); + /// Name of the player + void OnPlayerJoin(Guid uuid, string name); /// /// This method is called when a player has left the game diff --git a/MinecraftClient/Protocol/PlayerInfo.cs b/MinecraftClient/Protocol/PlayerInfo.cs deleted file mode 100644 index eae0727d..00000000 --- a/MinecraftClient/Protocol/PlayerInfo.cs +++ /dev/null @@ -1,85 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace MinecraftClient.Protocol -{ - /// - /// Information about a player (player tab list item) - /// - public class PlayerInfo : IComparable - { - private Guid _uuid; - private string _name; - - public Guid UUID { get { return _uuid; } } - public string Name { get { return _name; } } - public string DisplayName { get; set; } - - /// - /// Create a new PlayerInfo structure - /// - /// Player Id - /// Player Name - public PlayerInfo(Guid uuid, string name) - { - _uuid = uuid; - _name = name; - DisplayName = name; - } - - /// - /// Create a new PlayerInfo structure - /// - /// Player Id - /// Player Name - /// Player Display Name - public PlayerInfo(Guid uuid, string name, string displayName) - : this(uuid, name) - { - DisplayName = displayName; - } - - /// - /// String representation of the player - /// - /// Player display name - public override string ToString() - { - return DisplayName; - } - - /// - /// Compare a player to another player - /// - /// Other player - /// TRUE if same player Id - public override bool Equals(object obj) - { - if (obj is PlayerInfo) - return UUID.Equals(((PlayerInfo)obj).UUID); - return base.Equals(obj); - } - - /// - /// Basic hash function for player, from Player Id - /// - /// Interger hash - /// Required when overriding Equals() - public override int GetHashCode() - { - return UUID.GetHashCode(); - } - - /// - /// Allows sorting players by name - /// - /// Other player to compare to - /// Comparition with the player's name - int IComparable.CompareTo(PlayerInfo obj) - { - return Name.CompareTo(obj.Name); - } - } -} diff --git a/MinecraftClient/Protocol/ProtocolHandler.cs b/MinecraftClient/Protocol/ProtocolHandler.cs index 67f74d2f..55e5b002 100644 --- a/MinecraftClient/Protocol/ProtocolHandler.cs +++ b/MinecraftClient/Protocol/ProtocolHandler.cs @@ -24,7 +24,6 @@ namespace MinecraftClient.Protocol /// Server Port to ping /// Will contain protocol version, if ping successful /// TRUE if ping was successful - public static bool GetServerInfo(string serverIP, ushort serverPort, ref int protocolversion, ref ForgeInfo forgeInfo) { bool success = false; @@ -65,7 +64,6 @@ namespace MinecraftClient.Protocol /// Protocol version to handle /// Handler with the appropriate callbacks /// - public static IMinecraftCom getProtocolHandler(TcpClient Client, int ProtocolVersion, ForgeInfo forgeInfo, IMinecraftComHandler Handler) { int[] supportedVersions_Protocol16 = { 51, 60, 61, 72, 73, 74, 78 }; @@ -82,7 +80,6 @@ namespace MinecraftClient.Protocol /// /// The Minecraft version number /// The protocol version number or 0 if could not determine protocol version: error, unknown, not supported - public static int MCVer2ProtocolVersion(string MCVersion) { if (MCVersion.Contains('.')) @@ -170,7 +167,6 @@ namespace MinecraftClient.Protocol /// Will contain the client token generated before sending to Minecraft.net /// Will contain the player's PlayerID, needed for multiplayer /// Returns the status of the login (Success, Failure, etc.) - public static LoginResult GetLogin(string user, string pass, out SessionToken session) { session = new SessionToken() { ClientID = Guid.NewGuid().ToString().Replace("-", "") }; diff --git a/MinecraftClient/config/README.txt b/MinecraftClient/config/README.txt index 14f7a131..f2c7035d 100644 --- a/MinecraftClient/config/README.txt +++ b/MinecraftClient/config/README.txt @@ -63,7 +63,7 @@ In scripts and remote control, no slash is needed to perform the command. - send : send a message or a command to the server - respawn : Use this to respawn if you are dead (like clicking "respawn" ingame) - log : display some text in the console (useful for scripts) - - list [raw] : list players logged in to the server (raw = force show real names) + - list : list players logged in to the server (uses tab list info sent by server) - set varname=value : set a value which can be used as %varname% in further commands - wait