mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
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:
parent
a4cc36ce05
commit
9a98a9d46f
10 changed files with 156 additions and 85 deletions
|
|
@ -23,31 +23,10 @@ namespace MinecraftClient
|
|||
|
||||
private static readonly List<string> cmd_names = new List<string>();
|
||||
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 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 List<string> registeredServerPluginChannels = new List<String>();
|
||||
|
|
@ -86,7 +65,6 @@ namespace MinecraftClient
|
|||
/// <param name="server_ip">The server IP</param>
|
||||
/// <param name="port">The server port 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)
|
||||
{
|
||||
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="protocolversion">Minecraft protocol version to use</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)
|
||||
{
|
||||
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="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>
|
||||
|
||||
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;
|
||||
|
|
@ -209,7 +185,6 @@ namespace MinecraftClient
|
|||
/// <summary>
|
||||
/// Allows the user to send chat messages, commands, and to leave the server.
|
||||
/// </summary>
|
||||
|
||||
private void CommandPrompt()
|
||||
{
|
||||
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="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>
|
||||
|
||||
public bool PerformInternalCommand(string command, ref string response_msg)
|
||||
{
|
||||
/* Load commands from the 'Commands' namespace */
|
||||
|
|
@ -330,7 +304,6 @@ namespace MinecraftClient
|
|||
/// <summary>
|
||||
/// Disconnect the client from the server
|
||||
/// </summary>
|
||||
|
||||
public void Disconnect()
|
||||
{
|
||||
foreach (ChatBot bot in bots)
|
||||
|
|
@ -352,10 +325,47 @@ namespace MinecraftClient
|
|||
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>
|
||||
/// Called when a server was successfully joined
|
||||
/// </summary>
|
||||
|
||||
public void OnGameJoined()
|
||||
{
|
||||
if (!String.IsNullOrWhiteSpace(Settings.BrandInfo))
|
||||
|
|
@ -370,7 +380,6 @@ namespace MinecraftClient
|
|||
/// </summary>
|
||||
/// <param name="location">The new location</param>
|
||||
/// <param name="relative">If true, the location is relative to the current location</param>
|
||||
|
||||
public void UpdateLocation(Location location, bool relative)
|
||||
{
|
||||
lock (locationLock)
|
||||
|
|
@ -390,7 +399,6 @@ namespace MinecraftClient
|
|||
/// </summary>
|
||||
/// <param name="location">The new location</param>
|
||||
/// <param name="relative">If true, the location is relative to the current location</param>
|
||||
|
||||
public void UpdateLocation(Location location)
|
||||
{
|
||||
UpdateLocation(location, false);
|
||||
|
|
@ -417,7 +425,6 @@ namespace MinecraftClient
|
|||
/// Received some text from the server
|
||||
/// </summary>
|
||||
/// <param name="text">Text received</param>
|
||||
|
||||
public void OnTextReceived(string text)
|
||||
{
|
||||
ConsoleIO.WriteLineFormatted(text, false);
|
||||
|
|
@ -441,7 +448,6 @@ namespace MinecraftClient
|
|||
/// <summary>
|
||||
/// When connection has been lost
|
||||
/// </summary>
|
||||
|
||||
public void OnConnectionLost(ChatBot.DisconnectReason reason, string message)
|
||||
{
|
||||
bool will_restart = false;
|
||||
|
|
@ -474,7 +480,6 @@ namespace MinecraftClient
|
|||
/// <summary>
|
||||
/// Called ~10 times per second by the protocol handler
|
||||
/// </summary>
|
||||
|
||||
public void OnUpdate()
|
||||
{
|
||||
foreach (var bot in bots.ToArray())
|
||||
|
|
@ -516,7 +521,6 @@ namespace MinecraftClient
|
|||
/// </summary>
|
||||
/// <param name="text">Text to send to the server</param>
|
||||
/// <returns>True if the text was sent with no error</returns>
|
||||
|
||||
public bool SendText(string text)
|
||||
{
|
||||
if (text.Length > 100) //Message is too long?
|
||||
|
|
@ -547,7 +551,6 @@ namespace MinecraftClient
|
|||
/// Allow to respawn after death
|
||||
/// </summary>
|
||||
/// <returns>True if packet successfully sent</returns>
|
||||
|
||||
public bool SendRespawnPacket()
|
||||
{
|
||||
return handler.SendRespawnPacket();
|
||||
|
|
@ -557,17 +560,16 @@ namespace MinecraftClient
|
|||
/// Triggered when a new player joins the game
|
||||
/// </summary>
|
||||
/// <param name="uuid">UUID of the player</param>
|
||||
/// <param name="name">Name of the player</param>
|
||||
|
||||
public void OnPlayerJoin(Guid uuid, string name)
|
||||
/// <param name="info">Info about this player</param>
|
||||
public void OnPlayerJoin(PlayerInfo info)
|
||||
{
|
||||
//Ignore TabListPlus placeholders
|
||||
if (name.StartsWith("0000tab#"))
|
||||
if (info.Name.StartsWith("0000tab#"))
|
||||
return;
|
||||
|
||||
lock (onlinePlayers)
|
||||
{
|
||||
onlinePlayers[uuid] = name;
|
||||
onlinePlayers[info.UUID] = info;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -575,7 +577,6 @@ namespace MinecraftClient
|
|||
/// Triggered when a player has left the game
|
||||
/// </summary>
|
||||
/// <param name="uuid">UUID of the player</param>
|
||||
|
||||
public void OnPlayerLeave(Guid uuid)
|
||||
{
|
||||
lock (onlinePlayers)
|
||||
|
|
@ -588,8 +589,7 @@ namespace MinecraftClient
|
|||
/// Get a set of online player names
|
||||
/// </summary>
|
||||
/// <returns>Online player names</returns>
|
||||
|
||||
public string[] GetOnlinePlayers()
|
||||
public PlayerInfo[] GetOnlinePlayers()
|
||||
{
|
||||
lock (onlinePlayers)
|
||||
{
|
||||
|
|
@ -602,7 +602,6 @@ namespace MinecraftClient
|
|||
/// </summary>
|
||||
/// <param name="channel">The channel to register.</param>
|
||||
/// <param name="bot">The bot to register the channel for.</param>
|
||||
|
||||
public void RegisterPluginChannel(string channel, ChatBot bot)
|
||||
{
|
||||
if (registeredBotPluginChannels.ContainsKey(channel))
|
||||
|
|
@ -623,7 +622,6 @@ namespace MinecraftClient
|
|||
/// </summary>
|
||||
/// <param name="channel">The channel to unregister.</param>
|
||||
/// <param name="bot">The bot to unregister the channel for.</param>
|
||||
|
||||
public void UnregisterPluginChannel(string channel, ChatBot bot)
|
||||
{
|
||||
if (registeredBotPluginChannels.ContainsKey(channel))
|
||||
|
|
@ -646,7 +644,6 @@ namespace MinecraftClient
|
|||
/// <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>
|
||||
/// <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)
|
||||
{
|
||||
if (!sendEvenIfNotRegistered)
|
||||
|
|
@ -668,7 +665,6 @@ namespace MinecraftClient
|
|||
/// </summary>
|
||||
/// <param name="channel">The channel the message was sent on</param>
|
||||
/// <param name="data">The data from the channel</param>
|
||||
|
||||
public void OnPluginChannelMessage(string channel, byte[] data)
|
||||
{
|
||||
if (channel == "REGISTER")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue