Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
GLDYM authored Nov 25, 2023
2 parents f07b1e9 + f50bfbb commit a08bfca
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 6 deletions.
16 changes: 12 additions & 4 deletions MinecraftClient/ChatBots/WebSocketBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,21 @@ public class Configs

[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;
Expand All @@ -307,9 +315,6 @@ public WebSocketBot()

_ip = Config.Ip;
_port = Config.Port;
_password = Config.Password;
_authenticatedSessions = new();
_waitingEvents = new();
}

public override void Initialize()
Expand Down Expand Up @@ -420,6 +425,9 @@ private bool ProcessWebsocketCommand(string sessionId, string password, string m
_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));
Expand Down
10 changes: 10 additions & 0 deletions MinecraftClient/McClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3438,6 +3438,16 @@ public void OnUpdateScore(string entityname, int action, string objectivename, i
{
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
Expand Down
6 changes: 6 additions & 0 deletions MinecraftClient/Protocol/Handlers/Protocol18.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2375,6 +2375,12 @@ internal bool HandlePacket(int packetID, Queue<byte> packetData)
break;*/

case PacketTypesIn.PlayerListHeaderAndFooter:
var header = dataTypes.ReadNextString(packetData);
var footer = dataTypes.ReadNextString(packetData);
handler.OnTabListHeaderAndFooter(header, footer);
break;

default:
return false; //Ignored packet
}
Expand Down
7 changes: 7 additions & 0 deletions MinecraftClient/Protocol/IMinecraftComHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,13 @@ public interface IMinecraftComHandler
/// <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>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions MinecraftClient/Scripting/ChatBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,13 @@ public virtual void OnScoreboardObjective(string objectivename, byte mode, strin
/// <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>
Expand Down

0 comments on commit a08bfca

Please sign in to comment.