Merge branch 'master' into master

This commit is contained in:
Polaris_Light 2023-11-25 17:23:06 +08:00 committed by GitHub
commit a08bfca4e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 54 additions and 6 deletions

View file

@ -287,13 +287,21 @@ public class WebSocketBot : ChatBot
[TomlInlineComment("$ChatBot.WebSocketBot.DebugMode$")]
public bool DebugMode = false;
[TomlInlineComment("$ChatBot.WebSocketBot.AllowIpAlias$")]
public bool AllowIpAlias = false;
}
public WebSocketBot()
{
_password = Config.Password;
_authenticatedSessions = new();
_waitingEvents = new();
var match = Regex.Match(Config.Ip!, @"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}");
if (!match.Success)
// If AllowIpAlias is set to true in the config, then always ignore this check
if (!match.Success & !Config.AllowIpAlias!)
{
LogToConsole(Translations.bot_WebSocketBot_failed_to_start_ip);
return;
@ -307,9 +315,6 @@ public class WebSocketBot : ChatBot
_ip = Config.Ip;
_port = Config.Port;
_password = Config.Password;
_authenticatedSessions = new();
_waitingEvents = new();
}
public override void Initialize()
@ -420,6 +425,9 @@ public class WebSocketBot : ChatBot
_authenticatedSessions.Add(newId);
}
// Update the responder to the new session id
responder = new WsCommandResponder(this, newId, cmd.Command, cmd.RequestId);
responder.SendSuccessResponse(
responder.Quote("The session ID was successfully changed to: '" + newId + "'"), true);
LogToConsole(string.Format(Translations.bot_WebSocketBot_session_id_changed, sessionId, newId));

View file

@ -3439,6 +3439,16 @@ namespace MinecraftClient
DispatchBotEvent(bot => bot.OnUpdateScore(entityname, action, objectivename, value));
}
/// <summary>
/// Called when the client received the Tab Header and Footer
/// </summary>
/// <param name="header">Header</param>
/// <param name="footer">Footer</param>
public void OnTabListHeaderAndFooter(string header, string footer)
{
DispatchBotEvent(bot => bot.OnTabListHeaderAndFooter(header, footer));
}
/// <summary>
/// Called when the health of an entity changed
/// </summary>

View file

@ -2375,6 +2375,12 @@ namespace MinecraftClient.Protocol.Handlers
break;*/
case PacketTypesIn.PlayerListHeaderAndFooter:
var header = dataTypes.ReadNextString(packetData);
var footer = dataTypes.ReadNextString(packetData);
handler.OnTabListHeaderAndFooter(header, footer);
break;
default:
return false; //Ignored packet
}

View file

@ -447,6 +447,13 @@ namespace MinecraftClient.Protocol
/// <param name="value">he score to be displayed next to the entry. Only sent when Action does not equal 1.</param>
void OnUpdateScore(string entityname, int action, string objectivename, int value);
/// <summary>
/// Called when the client received the Tab Header and Footer
/// </summary>
/// <param name="header">Header</param>
/// <param name="footer">Footer</param>
void OnTabListHeaderAndFooter(string header, string footer);
/// <summary>
/// Called when tradeList is received from server
/// </summary>

View file

@ -799,7 +799,8 @@ namespace MinecraftClient {
///NOTE: This is an experimental feature, the bot can be slow at times, you need to walk with a normal speed and to sometimes stop for it to be able to keep up with you
///It&apos;s similar to making animals follow you when you&apos;re holding food in your hand.
///This is due to a slow pathfinding algorithm, we&apos;re working on getting a better one
///You can tweak the update limit and find what works best for you. (NOTE: Do not but a very low one, because you might achieve the opposite, /// [rest of string was truncated]&quot;;.
///You can tweak the update limit and find what works best for you. (NOTE: Do not but a very low one, because you might achieve the opposite,
/// [rest of string was truncated]&quot;;.
/// </summary>
internal static string ChatBot_FollowPlayer {
get {

View file

@ -2451,6 +2451,15 @@ namespace MinecraftClient {
}
}
/// <summary>
/// Looks up a localized string similar to .
/// </summary>
internal static string ChatBot_WebSocketBot_AllowIpAlias {
get {
return ResourceManager.GetString("ChatBot.WebSocketBot.AllowIpAlias", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to .
/// </summary>

View file

@ -347,6 +347,13 @@ namespace MinecraftClient.Scripting
/// <param name="value">The score to be displayed next to the entry. Only sent when Action does not equal 1.</param>
public virtual void OnUpdateScore(string entityname, int action, string objectivename, int value) { }
/// <summary>
/// Called when the client received the Tab Header and Footer
/// </summary>
/// <param name="header">Header</param>
/// <param name="footer">Footer</param>
public virtual void OnTabListHeaderAndFooter(string header, string footer) { }
/// <summary>
/// Called when an inventory/container was updated by server
/// </summary>