Store extended player info, list display names

- Add 1.10.1 and 1.10.2 in supported version list
 - Store both player name and player display names
 - List command will sort players by player name
 - List command will now display by display name
 - Ability to use /list raw to display by real name

Suggestion by Johngreen123
This commit is contained in:
ORelio 2016-08-22 19:09:43 +02:00
parent a4cc36ce05
commit 9a98a9d46f
10 changed files with 156 additions and 85 deletions

View file

@ -8,11 +8,18 @@ namespace MinecraftClient.Commands
public class List : Command public class List : Command
{ {
public override string CMDName { get { return "list"; } } public override string CMDName { get { return "list"; } }
public override string CMDDesc { get { return "list: get the player list."; } } public override string CMDDesc { get { return "list [raw]: get the player list."; } }
public override string Run(McTcpClient handler, string command) public override string Run(McTcpClient handler, string command)
{ {
return "PlayerList: " + String.Join(", ", handler.GetOnlinePlayers()); bool rawNames = getArg(command).ToLower() == "raw";
return "PlayerList: "
+ String.Join(", ",
handler.GetOnlinePlayers()
.OrderBy(player => player.Name)
.Select(player => rawNames
? player.Name
: player.DisplayName));
} }
} }
} }

View file

@ -23,31 +23,10 @@ namespace MinecraftClient
private static readonly List<string> cmd_names = new List<string>(); private static readonly List<string> cmd_names = new List<string>();
private static readonly Dictionary<string, Command> cmds = new Dictionary<string, Command>(); private static readonly Dictionary<string, Command> cmds = new Dictionary<string, Command>();
private readonly Dictionary<Guid, string> onlinePlayers = new Dictionary<Guid, string>(); private readonly Dictionary<Guid, PlayerInfo> onlinePlayers = new Dictionary<Guid, PlayerInfo>();
private readonly List<ChatBot> bots = new List<ChatBot>(); private readonly List<ChatBot> bots = new List<ChatBot>();
private static readonly List<ChatBots.Script> scripts_on_hold = new List<ChatBots.Script>(); private static readonly List<ChatBots.Script> scripts_on_hold = new List<ChatBots.Script>();
public void BotLoad(ChatBot b) {
b.SetHandler(this);
bots.Add(b);
b.Initialize();
if (this.handler != null)
{
b.AfterGameJoined();
}
Settings.SingleCommand = "";
}
public void BotUnLoad(ChatBot b) {
bots.RemoveAll(item => object.ReferenceEquals(item, b));
// ToList is needed to avoid an InvalidOperationException from modfiying the list while it's being iterated upon.
var botRegistrations = registeredBotPluginChannels.Where(entry => entry.Value.Contains(b)).ToList();
foreach (var entry in botRegistrations)
{
UnregisterPluginChannel(entry.Key, b);
}
}
public void BotClear() { bots.Clear(); }
private readonly Dictionary<string, List<ChatBot>> registeredBotPluginChannels = new Dictionary<string, List<ChatBot>>(); private readonly Dictionary<string, List<ChatBot>> registeredBotPluginChannels = new Dictionary<string, List<ChatBot>>();
private readonly List<string> registeredServerPluginChannels = new List<String>(); private readonly List<string> registeredServerPluginChannels = new List<String>();
@ -86,7 +65,6 @@ namespace MinecraftClient
/// <param name="server_ip">The server IP</param> /// <param name="server_ip">The server IP</param>
/// <param name="port">The server port to use</param> /// <param name="port">The server port to use</param>
/// <param name="protocolversion">Minecraft protocol version to use</param> /// <param name="protocolversion">Minecraft protocol version to use</param>
public McTcpClient(string username, string uuid, string sessionID, int protocolversion, ForgeInfo forgeInfo, string server_ip, ushort port) public McTcpClient(string username, string uuid, string sessionID, int protocolversion, ForgeInfo forgeInfo, string server_ip, ushort port)
{ {
StartClient(username, uuid, sessionID, server_ip, port, protocolversion, forgeInfo, false, ""); StartClient(username, uuid, sessionID, server_ip, port, protocolversion, forgeInfo, false, "");
@ -102,7 +80,6 @@ namespace MinecraftClient
/// <param name="port">The server port to use</param> /// <param name="port">The server port to use</param>
/// <param name="protocolversion">Minecraft protocol version to use</param> /// <param name="protocolversion">Minecraft protocol version to use</param>
/// <param name="command">The text or command to send.</param> /// <param name="command">The text or command to send.</param>
public McTcpClient(string username, string uuid, string sessionID, string server_ip, ushort port, int protocolversion, ForgeInfo forgeInfo, string command) public McTcpClient(string username, string uuid, string sessionID, string server_ip, ushort port, int protocolversion, ForgeInfo forgeInfo, string command)
{ {
StartClient(username, uuid, sessionID, server_ip, port, protocolversion, forgeInfo, true, command); StartClient(username, uuid, sessionID, server_ip, port, protocolversion, forgeInfo, true, command);
@ -119,7 +96,6 @@ namespace MinecraftClient
/// <param name="uuid">The player's UUID for online-mode authentication</param> /// <param name="uuid">The player's UUID for online-mode authentication</param>
/// <param name="singlecommand">If set to true, the client will send a single command and then disconnect from the server</param> /// <param name="singlecommand">If set to true, the client will send a single command and then disconnect from the server</param>
/// <param name="command">The text or command to send. Will only be sent if singlecommand is set to true.</param> /// <param name="command">The text or command to send. Will only be sent if singlecommand is set to true.</param>
private void StartClient(string user, string uuid, string sessionID, string server_ip, ushort port, int protocolversion, ForgeInfo forgeInfo, bool singlecommand, string command) private void StartClient(string user, string uuid, string sessionID, string server_ip, ushort port, int protocolversion, ForgeInfo forgeInfo, bool singlecommand, string command)
{ {
bool retry = false; bool retry = false;
@ -209,7 +185,6 @@ namespace MinecraftClient
/// <summary> /// <summary>
/// Allows the user to send chat messages, commands, and to leave the server. /// Allows the user to send chat messages, commands, and to leave the server.
/// </summary> /// </summary>
private void CommandPrompt() private void CommandPrompt()
{ {
try try
@ -267,7 +242,6 @@ namespace MinecraftClient
/// <param name="interactive_mode">Set to true if command was sent by the user using the command prompt</param> /// <param name="interactive_mode">Set to true if command was sent by the user using the command prompt</param>
/// <param name="response_msg">May contain a confirmation or error message after processing the command, or "" otherwise.</param> /// <param name="response_msg">May contain a confirmation or error message after processing the command, or "" otherwise.</param>
/// <returns>TRUE if the command was indeed an internal MCC command</returns> /// <returns>TRUE if the command was indeed an internal MCC command</returns>
public bool PerformInternalCommand(string command, ref string response_msg) public bool PerformInternalCommand(string command, ref string response_msg)
{ {
/* Load commands from the 'Commands' namespace */ /* Load commands from the 'Commands' namespace */
@ -330,7 +304,6 @@ namespace MinecraftClient
/// <summary> /// <summary>
/// Disconnect the client from the server /// Disconnect the client from the server
/// </summary> /// </summary>
public void Disconnect() public void Disconnect()
{ {
foreach (ChatBot bot in bots) foreach (ChatBot bot in bots)
@ -352,10 +325,47 @@ namespace MinecraftClient
client.Close(); client.Close();
} }
/// <summary>
/// Load a new bot
/// </summary>
public void BotLoad(ChatBot b)
{
b.SetHandler(this);
bots.Add(b);
b.Initialize();
if (this.handler != null)
{
b.AfterGameJoined();
}
Settings.SingleCommand = "";
}
/// <summary>
/// Unload a bot
/// </summary>
public void BotUnLoad(ChatBot b)
{
bots.RemoveAll(item => object.ReferenceEquals(item, b));
// ToList is needed to avoid an InvalidOperationException from modfiying the list while it's being iterated upon.
var botRegistrations = registeredBotPluginChannels.Where(entry => entry.Value.Contains(b)).ToList();
foreach (var entry in botRegistrations)
{
UnregisterPluginChannel(entry.Key, b);
}
}
/// <summary>
/// Clear bots
/// </summary>
public void BotClear()
{
bots.Clear();
}
/// <summary> /// <summary>
/// Called when a server was successfully joined /// Called when a server was successfully joined
/// </summary> /// </summary>
public void OnGameJoined() public void OnGameJoined()
{ {
if (!String.IsNullOrWhiteSpace(Settings.BrandInfo)) if (!String.IsNullOrWhiteSpace(Settings.BrandInfo))
@ -370,7 +380,6 @@ namespace MinecraftClient
/// </summary> /// </summary>
/// <param name="location">The new location</param> /// <param name="location">The new location</param>
/// <param name="relative">If true, the location is relative to the current location</param> /// <param name="relative">If true, the location is relative to the current location</param>
public void UpdateLocation(Location location, bool relative) public void UpdateLocation(Location location, bool relative)
{ {
lock (locationLock) lock (locationLock)
@ -390,7 +399,6 @@ namespace MinecraftClient
/// </summary> /// </summary>
/// <param name="location">The new location</param> /// <param name="location">The new location</param>
/// <param name="relative">If true, the location is relative to the current location</param> /// <param name="relative">If true, the location is relative to the current location</param>
public void UpdateLocation(Location location) public void UpdateLocation(Location location)
{ {
UpdateLocation(location, false); UpdateLocation(location, false);
@ -417,7 +425,6 @@ namespace MinecraftClient
/// Received some text from the server /// Received some text from the server
/// </summary> /// </summary>
/// <param name="text">Text received</param> /// <param name="text">Text received</param>
public void OnTextReceived(string text) public void OnTextReceived(string text)
{ {
ConsoleIO.WriteLineFormatted(text, false); ConsoleIO.WriteLineFormatted(text, false);
@ -441,7 +448,6 @@ namespace MinecraftClient
/// <summary> /// <summary>
/// When connection has been lost /// When connection has been lost
/// </summary> /// </summary>
public void OnConnectionLost(ChatBot.DisconnectReason reason, string message) public void OnConnectionLost(ChatBot.DisconnectReason reason, string message)
{ {
bool will_restart = false; bool will_restart = false;
@ -474,7 +480,6 @@ namespace MinecraftClient
/// <summary> /// <summary>
/// Called ~10 times per second by the protocol handler /// Called ~10 times per second by the protocol handler
/// </summary> /// </summary>
public void OnUpdate() public void OnUpdate()
{ {
foreach (var bot in bots.ToArray()) foreach (var bot in bots.ToArray())
@ -516,7 +521,6 @@ namespace MinecraftClient
/// </summary> /// </summary>
/// <param name="text">Text to send to the server</param> /// <param name="text">Text to send to the server</param>
/// <returns>True if the text was sent with no error</returns> /// <returns>True if the text was sent with no error</returns>
public bool SendText(string text) public bool SendText(string text)
{ {
if (text.Length > 100) //Message is too long? if (text.Length > 100) //Message is too long?
@ -547,7 +551,6 @@ namespace MinecraftClient
/// Allow to respawn after death /// Allow to respawn after death
/// </summary> /// </summary>
/// <returns>True if packet successfully sent</returns> /// <returns>True if packet successfully sent</returns>
public bool SendRespawnPacket() public bool SendRespawnPacket()
{ {
return handler.SendRespawnPacket(); return handler.SendRespawnPacket();
@ -557,17 +560,16 @@ namespace MinecraftClient
/// Triggered when a new player joins the game /// Triggered when a new player joins the game
/// </summary> /// </summary>
/// <param name="uuid">UUID of the player</param> /// <param name="uuid">UUID of the player</param>
/// <param name="name">Name of the player</param> /// <param name="info">Info about this player</param>
public void OnPlayerJoin(PlayerInfo info)
public void OnPlayerJoin(Guid uuid, string name)
{ {
//Ignore TabListPlus placeholders //Ignore TabListPlus placeholders
if (name.StartsWith("0000tab#")) if (info.Name.StartsWith("0000tab#"))
return; return;
lock (onlinePlayers) lock (onlinePlayers)
{ {
onlinePlayers[uuid] = name; onlinePlayers[info.UUID] = info;
} }
} }
@ -575,7 +577,6 @@ namespace MinecraftClient
/// Triggered when a player has left the game /// Triggered when a player has left the game
/// </summary> /// </summary>
/// <param name="uuid">UUID of the player</param> /// <param name="uuid">UUID of the player</param>
public void OnPlayerLeave(Guid uuid) public void OnPlayerLeave(Guid uuid)
{ {
lock (onlinePlayers) lock (onlinePlayers)
@ -588,8 +589,7 @@ namespace MinecraftClient
/// Get a set of online player names /// Get a set of online player names
/// </summary> /// </summary>
/// <returns>Online player names</returns> /// <returns>Online player names</returns>
public PlayerInfo[] GetOnlinePlayers()
public string[] GetOnlinePlayers()
{ {
lock (onlinePlayers) lock (onlinePlayers)
{ {
@ -602,7 +602,6 @@ namespace MinecraftClient
/// </summary> /// </summary>
/// <param name="channel">The channel to register.</param> /// <param name="channel">The channel to register.</param>
/// <param name="bot">The bot to register the channel for.</param> /// <param name="bot">The bot to register the channel for.</param>
public void RegisterPluginChannel(string channel, ChatBot bot) public void RegisterPluginChannel(string channel, ChatBot bot)
{ {
if (registeredBotPluginChannels.ContainsKey(channel)) if (registeredBotPluginChannels.ContainsKey(channel))
@ -623,7 +622,6 @@ namespace MinecraftClient
/// </summary> /// </summary>
/// <param name="channel">The channel to unregister.</param> /// <param name="channel">The channel to unregister.</param>
/// <param name="bot">The bot to unregister the channel for.</param> /// <param name="bot">The bot to unregister the channel for.</param>
public void UnregisterPluginChannel(string channel, ChatBot bot) public void UnregisterPluginChannel(string channel, ChatBot bot)
{ {
if (registeredBotPluginChannels.ContainsKey(channel)) if (registeredBotPluginChannels.ContainsKey(channel))
@ -646,7 +644,6 @@ namespace MinecraftClient
/// <param name="data">The payload for the packet.</param> /// <param name="data">The payload for the packet.</param>
/// <param name="sendEvenIfNotRegistered">Whether the packet should be sent even if the server or the client hasn't registered it yet.</param> /// <param name="sendEvenIfNotRegistered">Whether the packet should be sent even if the server or the client hasn't registered it yet.</param>
/// <returns>Whether the packet was sent: true if it was sent, false if there was a connection error or it wasn't registered.</returns> /// <returns>Whether the packet was sent: true if it was sent, false if there was a connection error or it wasn't registered.</returns>
public bool SendPluginChannelMessage(string channel, byte[] data, bool sendEvenIfNotRegistered = false) public bool SendPluginChannelMessage(string channel, byte[] data, bool sendEvenIfNotRegistered = false)
{ {
if (!sendEvenIfNotRegistered) if (!sendEvenIfNotRegistered)
@ -668,7 +665,6 @@ namespace MinecraftClient
/// </summary> /// </summary>
/// <param name="channel">The channel the message was sent on</param> /// <param name="channel">The channel the message was sent on</param>
/// <param name="data">The data from the channel</param> /// <param name="data">The data from the channel</param>
public void OnPluginChannelMessage(string channel, byte[] data) public void OnPluginChannelMessage(string channel, byte[] data)
{ {
if (channel == "REGISTER") if (channel == "REGISTER")

View file

@ -148,6 +148,7 @@
<Compile Include="Protocol\Handlers\Protocol16.cs" /> <Compile Include="Protocol\Handlers\Protocol16.cs" />
<Compile Include="Protocol\IMinecraftCom.cs" /> <Compile Include="Protocol\IMinecraftCom.cs" />
<Compile Include="Protocol\IMinecraftComHandler.cs" /> <Compile Include="Protocol\IMinecraftComHandler.cs" />
<Compile Include="Protocol\PlayerInfo.cs" />
<Compile Include="Protocol\ProtocolHandler.cs" /> <Compile Include="Protocol\ProtocolHandler.cs" />
<Compile Include="Protocol\SessionCache\CacheType.cs" /> <Compile Include="Protocol\SessionCache\CacheType.cs" />
<Compile Include="Protocol\SessionCache\SessionCache.cs" /> <Compile Include="Protocol\SessionCache\SessionCache.cs" />

View file

@ -15,7 +15,6 @@ namespace MinecraftClient
/// Allows to connect to any Minecraft server, send and receive text, automated scripts. /// Allows to connect to any Minecraft server, send and receive text, automated scripts.
/// This source code is released under the CDDL 1.0 License. /// This source code is released under the CDDL 1.0 License.
/// </summary> /// </summary>
static class Program static class Program
{ {
private static McTcpClient Client; private static McTcpClient Client;
@ -23,7 +22,7 @@ namespace MinecraftClient
public const string Version = "1.10.0 DEV"; public const string Version = "1.10.0 DEV";
public const string MCLowestVersion = "1.4.6"; public const string MCLowestVersion = "1.4.6";
public const string MCHighestVersion = "1.10.0"; public const string MCHighestVersion = "1.10.2";
private static Thread offlinePrompt = null; private static Thread offlinePrompt = null;
private static bool useMcVersionOnce = false; private static bool useMcVersionOnce = false;
@ -31,7 +30,6 @@ namespace MinecraftClient
/// <summary> /// <summary>
/// The main entry point of Minecraft Console Client /// The main entry point of Minecraft Console Client
/// </summary> /// </summary>
static void Main(string[] args) static void Main(string[] args)
{ {
Console.WriteLine("Console Client for MC {0} to {1} - v{2} - By ORelio & Contributors", MCLowestVersion, MCHighestVersion, Version); Console.WriteLine("Console Client for MC {0} to {1} - v{2} - By ORelio & Contributors", MCLowestVersion, MCHighestVersion, Version);
@ -129,7 +127,6 @@ namespace MinecraftClient
/// <summary> /// <summary>
/// Start a new Client /// Start a new Client
/// </summary> /// </summary>
private static void InitializeClient() private static void InitializeClient()
{ {
SessionToken session = new SessionToken(); SessionToken session = new SessionToken();
@ -271,7 +268,6 @@ namespace MinecraftClient
/// <summary> /// <summary>
/// Disconnect the current client from the server and restart it /// Disconnect the current client from the server and restart it
/// </summary> /// </summary>
public static void Restart() public static void Restart()
{ {
new Thread(new ThreadStart(delegate new Thread(new ThreadStart(delegate
@ -286,7 +282,6 @@ namespace MinecraftClient
/// <summary> /// <summary>
/// Disconnect the current client from the server and exit the app /// Disconnect the current client from the server and exit the app
/// </summary> /// </summary>
public static void Exit() public static void Exit()
{ {
new Thread(new ThreadStart(delegate new Thread(new ThreadStart(delegate
@ -305,7 +300,6 @@ namespace MinecraftClient
/// <param name="errorMessage">Error message to display and optionally pass to AutoRelog bot</param> /// <param name="errorMessage">Error message to display and optionally pass to AutoRelog bot</param>
/// <param name="versionError">Specify if the error is related to an incompatible or unkown server version</param> /// <param name="versionError">Specify if the error is related to an incompatible or unkown server version</param>
/// <param name="disconnectReason">If set, the error message will be processed by the AutoRelog bot</param> /// <param name="disconnectReason">If set, the error message will be processed by the AutoRelog bot</param>
public static void HandleFailure(string errorMessage = null, bool versionError = false, ChatBots.AutoRelog.DisconnectReason? disconnectReason = null) public static void HandleFailure(string errorMessage = null, bool versionError = false, ChatBots.AutoRelog.DisconnectReason? disconnectReason = null)
{ {
if (!String.IsNullOrEmpty(errorMessage)) if (!String.IsNullOrEmpty(errorMessage))
@ -387,7 +381,6 @@ namespace MinecraftClient
/// <summary> /// <summary>
/// Detect if the user is running Minecraft Console Client through Mono /// Detect if the user is running Minecraft Console Client through Mono
/// </summary> /// </summary>
public static bool isUsingMono public static bool isUsingMono
{ {
get get
@ -402,7 +395,6 @@ namespace MinecraftClient
/// <param name="nameSpace">Namespace to process</param> /// <param name="nameSpace">Namespace to process</param>
/// <param name="assembly">Assembly to use. Default is Assembly.GetExecutingAssembly()</param> /// <param name="assembly">Assembly to use. Default is Assembly.GetExecutingAssembly()</param>
/// <returns></returns> /// <returns></returns>
public static Type[] GetTypesInNamespace(string nameSpace, Assembly assembly = null) public static Type[] GetTypesInNamespace(string nameSpace, Assembly assembly = null)
{ {
if (assembly == null) { assembly = Assembly.GetExecutingAssembly(); } if (assembly == null) { assembly = Assembly.GetExecutingAssembly(); }

View file

@ -160,7 +160,7 @@ namespace MinecraftClient.Protocol.Handlers
case 0xC9: case 0xC9:
string name = readNextString(); bool online = readNextByte() != 0x00; readData(2); string name = readNextString(); bool online = readNextByte() != 0x00; readData(2);
Guid FakeUUID = new Guid(MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(name)).Take(16).ToArray()); Guid FakeUUID = new Guid(MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(name)).Take(16).ToArray());
if (online) { handler.OnPlayerJoin(FakeUUID, name); } else { handler.OnPlayerLeave(FakeUUID); } if (online) { handler.OnPlayerJoin(new PlayerInfo(FakeUUID, name)); } else { handler.OnPlayerLeave(FakeUUID); }
break; break;
case 0xCA: if (protocolversion >= 72) { readData(9); } else readData(3); break; case 0xCA: if (protocolversion >= 72) { readData(9); } else readData(3); break;
case 0xCB: autocomplete_result = readNextString(); autocomplete_received = true; break; case 0xCB: autocomplete_result = readNextString(); autocomplete_received = true; break;

View file

@ -437,9 +437,10 @@ namespace MinecraftClient.Protocol.Handlers
} }
readNextVarInt(packetData); readNextVarInt(packetData);
readNextVarInt(packetData); readNextVarInt(packetData);
string displayName = name;
if (readNextBool(packetData)) if (readNextBool(packetData))
readNextString(packetData); displayName = readNextString(packetData);
handler.OnPlayerJoin(uuid, name); handler.OnPlayerJoin(new PlayerInfo(uuid, name, displayName));
break; break;
case 0x01: //Update gamemode case 0x01: //Update gamemode
case 0x02: //Update latency case 0x02: //Update latency
@ -465,7 +466,7 @@ namespace MinecraftClient.Protocol.Handlers
short ping = readNextShort(packetData); short ping = readNextShort(packetData);
Guid FakeUUID = new Guid(MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(name)).Take(16).ToArray()); Guid FakeUUID = new Guid(MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(name)).Take(16).ToArray());
if (online) if (online)
handler.OnPlayerJoin(FakeUUID, name); handler.OnPlayerJoin(new PlayerInfo(FakeUUID, name));
else handler.OnPlayerLeave(FakeUUID); else handler.OnPlayerLeave(FakeUUID);
} }
break; break;

View file

@ -22,55 +22,48 @@ namespace MinecraftClient.Protocol
string GetUsername(); string GetUsername();
string GetUserUUID(); string GetUserUUID();
string GetSessionID(); string GetSessionID();
string[] GetOnlinePlayers(); PlayerInfo[] GetOnlinePlayers();
Location GetCurrentLocation(); Location GetCurrentLocation();
World GetWorld(); World GetWorld();
/// <summary> /// <summary>
/// Called when a server was successfully joined /// Called when a server was successfully joined
/// </summary> /// </summary>
void OnGameJoined(); void OnGameJoined();
/// <summary> /// <summary>
/// This method is called when the protocol handler receives a chat message /// This method is called when the protocol handler receives a chat message
/// </summary> /// </summary>
void OnTextReceived(string text); void OnTextReceived(string text);
/// <summary> /// <summary>
/// This method is called when a new player joins the game /// This method is called when a new player joins the game
/// </summary> /// </summary>
/// <param name="uuid">UUID of the player</param> /// <param name="uuid">UUID of the player</param>
/// <param name="name">Name of the player</param> /// <param name="info">Info about this player</param>
void OnPlayerJoin(PlayerInfo info);
void OnPlayerJoin(Guid uuid, string name);
/// <summary> /// <summary>
/// This method is called when a player has left the game /// This method is called when a player has left the game
/// </summary> /// </summary>
/// <param name="uuid">UUID of the player</param> /// <param name="uuid">UUID of the player</param>
void OnPlayerLeave(Guid uuid); void OnPlayerLeave(Guid uuid);
/// <summary> /// <summary>
/// Called when the server sets the new location for the player /// Called when the server sets the new location for the player
/// </summary> /// </summary>
/// <param name="location">New location of the player</param> /// <param name="location">New location of the player</param>
void UpdateLocation(Location location); void UpdateLocation(Location location);
/// <summary> /// <summary>
/// This method is called when the connection has been lost /// This method is called when the connection has been lost
/// </summary> /// </summary>
void OnConnectionLost(ChatBot.DisconnectReason reason, string message); void OnConnectionLost(ChatBot.DisconnectReason reason, string message);
/// <summary> /// <summary>
/// Called ~10 times per second (10 ticks per second) /// Called ~10 times per second (10 ticks per second)
/// Useful for updating bots in other parts of the program /// Useful for updating bots in other parts of the program
/// </summary> /// </summary>
void OnUpdate(); void OnUpdate();
/// <summary> /// <summary>
@ -78,7 +71,6 @@ namespace MinecraftClient.Protocol
/// </summary> /// </summary>
/// <param name="channel">The channel to register.</param> /// <param name="channel">The channel to register.</param>
/// <param name="bot">The bot to register the channel for.</param> /// <param name="bot">The bot to register the channel for.</param>
void RegisterPluginChannel(string channel, ChatBot bot); void RegisterPluginChannel(string channel, ChatBot bot);
/// <summary> /// <summary>
@ -86,7 +78,6 @@ namespace MinecraftClient.Protocol
/// </summary> /// </summary>
/// <param name="channel">The channel to unregister.</param> /// <param name="channel">The channel to unregister.</param>
/// <param name="bot">The bot to unregister the channel for.</param> /// <param name="bot">The bot to unregister the channel for.</param>
void UnregisterPluginChannel(string channel, ChatBot bot); void UnregisterPluginChannel(string channel, ChatBot bot);
/// <summary> /// <summary>
@ -97,7 +88,6 @@ namespace MinecraftClient.Protocol
/// <param name="data">The payload for the packet.</param> /// <param name="data">The payload for the packet.</param>
/// <param name="sendEvenIfNotRegistered">Whether the packet should be sent even if the server or the client hasn't registered it yet.</param> /// <param name="sendEvenIfNotRegistered">Whether the packet should be sent even if the server or the client hasn't registered it yet.</param>
/// <returns>Whether the packet was sent: true if it was sent, false if there was a connection error or it wasn't registered.</returns> /// <returns>Whether the packet was sent: true if it was sent, false if there was a connection error or it wasn't registered.</returns>
bool SendPluginChannelMessage(string channel, byte[] data, bool sendEvenIfNotRegistered = false); bool SendPluginChannelMessage(string channel, byte[] data, bool sendEvenIfNotRegistered = false);
/// <summary> /// <summary>
@ -105,7 +95,6 @@ namespace MinecraftClient.Protocol
/// </summary> /// </summary>
/// <param name="channel">The channel the message was sent on</param> /// <param name="channel">The channel the message was sent on</param>
/// <param name="data">The data from the channel</param> /// <param name="data">The data from the channel</param>
void OnPluginChannelMessage(string channel, byte[] data); void OnPluginChannelMessage(string channel, byte[] data);
} }
} }

View file

@ -0,0 +1,86 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MinecraftClient.Protocol
{
/// <summary>
/// Information about a player (player tab list item)
/// </summary>
public struct PlayerInfo : IComparable<PlayerInfo>
{
private Guid _uuid;
private string _name;
private string _displayName;
public Guid UUID { get { return _uuid; } }
public string Name { get { return _name; } }
public string DisplayName { get { return _displayName; } }
/// <summary>
/// Create a new PlayerInfo structure
/// </summary>
/// <param name="uuid">Player Id</param>
/// <param name="name">Player Name</param>
public PlayerInfo(Guid uuid, string name)
{
_uuid = uuid;
_name = name;
_displayName = name;
}
/// <summary>
/// Create a new PlayerInfo structure
/// </summary>
/// <param name="uuid">Player Id</param>
/// <param name="name">Player Name</param>
/// <param name="displayName">Player Display Name</param>
public PlayerInfo(Guid uuid, string name, string displayName)
: this(uuid, name)
{
_displayName = displayName;
}
/// <summary>
/// String representation of the player
/// </summary>
/// <returns>Player display name</returns>
public override string ToString()
{
return DisplayName;
}
/// <summary>
/// Compare a player to another player
/// </summary>
/// <param name="obj">Other player</param>
/// <returns>TRUE if same player Id</returns>
public override bool Equals(object obj)
{
if (obj is PlayerInfo)
return UUID.Equals(((PlayerInfo)obj).UUID);
return base.Equals(obj);
}
/// <summary>
/// Basic hash function for player, from Player Id
/// </summary>
/// <returns>Interger hash</returns>
/// <remarks>Required when overriding Equals()</remarks>
public override int GetHashCode()
{
return UUID.GetHashCode();
}
/// <summary>
/// Allows sorting players by name
/// </summary>
/// <param name="obj">Other player to compare to</param>
/// <returns>Comparition with the player's name</returns>
int IComparable<PlayerInfo>.CompareTo(PlayerInfo obj)
{
return Name.CompareTo(obj.Name);
}
}
}

View file

@ -96,6 +96,7 @@ namespace MinecraftClient.Protocol
return 60; return 60;
case "1.5.2": case "1.5.2":
return 61; return 61;
case "1.6":
case "1.6.0": case "1.6.0":
return 72; return 72;
case "1.6.1": case "1.6.1":
@ -114,6 +115,7 @@ namespace MinecraftClient.Protocol
case "1.7.9": case "1.7.9":
case "1.7.10": case "1.7.10":
return 5; return 5;
case "1.8":
case "1.8.0": case "1.8.0":
case "1.8.1": case "1.8.1":
case "1.8.2": case "1.8.2":
@ -125,6 +127,7 @@ namespace MinecraftClient.Protocol
case "1.8.8": case "1.8.8":
case "1.8.9": case "1.8.9":
return 47; return 47;
case "1.9":
case "1.9.0": case "1.9.0":
return 107; return 107;
case "1.9.1": case "1.9.1":
@ -134,7 +137,10 @@ namespace MinecraftClient.Protocol
case "1.9.3": case "1.9.3":
case "1.9.4": case "1.9.4":
return 110; return 110;
case "1.10":
case "1.10.0": case "1.10.0":
case "1.10.1":
case "1.10.2":
return 210; return 210;
default: default:
return 0; return 0;
@ -234,7 +240,6 @@ namespace MinecraftClient.Protocol
/// <param name="accesstoken">Will contain the cached access token previously returned by Minecraft.net</param> /// <param name="accesstoken">Will contain the cached access token previously returned by Minecraft.net</param>
/// <param name="clienttoken">Will contain the cached client token created on login</param> /// <param name="clienttoken">Will contain the cached client token created on login</param>
/// <returns>Returns the status of the token (Valid, Invalid, etc.)</returns> /// <returns>Returns the status of the token (Valid, Invalid, etc.)</returns>
///
public static LoginResult GetTokenValidation(SessionToken session) public static LoginResult GetTokenValidation(SessionToken session)
{ {
try try
@ -269,7 +274,6 @@ namespace MinecraftClient.Protocol
/// <param name="clienttoken">Will contain the client token generated before sending to Minecraft.net</param> /// <param name="clienttoken">Will contain the client token generated before sending to Minecraft.net</param>
/// <param name="uuid">Will contain the player's PlayerID, needed for multiplayer</param> /// <param name="uuid">Will contain the player's PlayerID, needed for multiplayer</param>
/// <returns>Returns the status of the new token request (Success, Failure, etc.)</returns> /// <returns>Returns the status of the new token request (Success, Failure, etc.)</returns>
///
public static LoginResult GetNewToken(SessionToken currentsession, out SessionToken newsession) public static LoginResult GetNewToken(SessionToken currentsession, out SessionToken newsession)
{ {
newsession = new SessionToken(); newsession = new SessionToken();
@ -319,7 +323,6 @@ namespace MinecraftClient.Protocol
/// <param name="accesstoken">Session ID</param> /// <param name="accesstoken">Session ID</param>
/// <param name="serverhash">Server ID</param> /// <param name="serverhash">Server ID</param>
/// <returns>TRUE if session was successfully checked</returns> /// <returns>TRUE if session was successfully checked</returns>
public static bool SessionCheck(string uuid, string accesstoken, string serverhash) public static bool SessionCheck(string uuid, string accesstoken, string serverhash)
{ {
try try
@ -348,7 +351,6 @@ namespace MinecraftClient.Protocol
/// <param name="cookies">Cookies for making the request</param> /// <param name="cookies">Cookies for making the request</param>
/// <param name="result">Request result</param> /// <param name="result">Request result</param>
/// <returns>HTTP Status code</returns> /// <returns>HTTP Status code</returns>
private static int doHTTPSGet(string host, string endpoint, string cookies, ref string result) private static int doHTTPSGet(string host, string endpoint, string cookies, ref string result)
{ {
List<String> http_request = new List<string>(); List<String> http_request = new List<string>();
@ -372,7 +374,6 @@ namespace MinecraftClient.Protocol
/// <param name="request">Request payload</param> /// <param name="request">Request payload</param>
/// <param name="result">Request result</param> /// <param name="result">Request result</param>
/// <returns>HTTP Status code</returns> /// <returns>HTTP Status code</returns>
private static int doHTTPSPost(string host, string endpoint, string request, ref string result) private static int doHTTPSPost(string host, string endpoint, string request, ref string result)
{ {
List<String> http_request = new List<string>(); List<String> http_request = new List<string>();
@ -395,7 +396,6 @@ namespace MinecraftClient.Protocol
/// <param name="host">Host to connect to</param> /// <param name="host">Host to connect to</param>
/// <param name="result">Request result</param> /// <param name="result">Request result</param>
/// <returns>HTTP Status code</returns> /// <returns>HTTP Status code</returns>
private static int doHTTPSRequest(List<string> headers, string host, ref string result) private static int doHTTPSRequest(List<string> headers, string host, ref string result)
{ {
string postResult = null; string postResult = null;
@ -425,7 +425,6 @@ namespace MinecraftClient.Protocol
/// </summary> /// </summary>
/// <param name="text">Source text</param> /// <param name="text">Source text</param>
/// <returns>Encoded text</returns> /// <returns>Encoded text</returns>
private static string jsonEncode(string text) private static string jsonEncode(string text)
{ {
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();

View file

@ -63,7 +63,7 @@ In scripts and remote control, no slash is needed to perform the command.
- send <text> : send a message or a command to the server - send <text> : send a message or a command to the server
- respawn : Use this to respawn if you are dead (like clicking "respawn" ingame) - respawn : Use this to respawn if you are dead (like clicking "respawn" ingame)
- log <text> : display some text in the console (useful for scripts) - log <text> : display some text in the console (useful for scripts)
- list : list players logged in to the server (uses tab list info sent by server) - list [raw] : list players logged in to the server (raw = force show real names)
- set varname=value : set a value which can be used as %varname% in further commands - set varname=value : set a value which can be used as %varname% in further commands
- wait <time> : wait X ticks (10 ticks = ~1 second. Only for scripts) - wait <time> : wait X ticks (10 ticks = ~1 second. Only for scripts)
- move : used for moving when terrain and movements feature is enabled - move : used for moving when terrain and movements feature is enabled