Skip to content

Commit

Permalink
fix(server): fix chat message cleanup regex
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielMcAssey committed Jan 14, 2025
1 parent 584d911 commit aa7dd14
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion GLOKON.Baiters.Core/BaitersServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public void SendSystemMessage(string message, string color = MessageColour.Defau
{
SendPacket(new("message")
{
// Need to format it like this, if not username wont appear
// Need to format it like this, if not username wont appear and color wont either
["message"] = string.Format("%u: {0}", message),
["color"] = color,
["local"] = false,
Expand Down
9 changes: 5 additions & 4 deletions GLOKON.Baiters.Core/Packets/Handlers/MessageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

namespace GLOKON.Baiters.Core.Packets.Handlers
{
internal class MessageHandler(BaitersServer server) : IPacketHandler
internal partial class MessageHandler(BaitersServer server) : IPacketHandler
{
private readonly Regex _messageCleanUpRegex = new(Regex.Escape("%u:"));

public void Handle(ulong sender, Packet data)
{
string playerName = "UNKNOWN";
Expand All @@ -22,13 +20,16 @@ public void Handle(ulong sender, Packet data)
SentAt = DateTime.Now,
SenderId = sender,
SenderName = playerName,
Message = _messageCleanUpRegex.Replace((string)data["message"], string.Empty, 1).Trim(),
Message = MessageCleanUpRegex().Replace((string)data["message"], string.Empty, 1).Trim(),
Colour = (string)data["color"],
IsLocal = (bool)data["local"],
Position = (Vector3)data["position"],
Zone = (string)data["zone"],
ZoneOwner = (long)data["zone_owner"],
});
}

[GeneratedRegex("%u:?")]
private static partial Regex MessageCleanUpRegex();
}
}

0 comments on commit aa7dd14

Please sign in to comment.