Fixed a critical issue with in-game chat.

This commit is contained in:
Kei-Luna
2026-04-29 09:01:20 +09:00
parent 720f56c708
commit c61ac08dd3
3 changed files with 31 additions and 4 deletions

View File

@@ -38,9 +38,9 @@ public class PlayerCommandSender(PlayerInstance player) : ICommandSender
Type = ChatType.Friend, Type = ChatType.Friend,
Sender = (uint)ConfigManager.Config.ServerOption.ServerProfile.Uid, Sender = (uint)ConfigManager.Config.ServerOption.ServerProfile.Uid,
Recver = (uint)Player.Uid, Recver = (uint)Player.Uid,
Text = msg, Text = ChatMessageHelper.NormalizeForClient(msg),
Profile = Player.ToServerFriendProto(), Profile = Player.ToServerFriendProto(),
TimeStamp = (uint)Extensions.GetUnixMs() TimeStamp = ChatMessageHelper.BuildClientTimestamp()
}; };
await Player.SendPacket(CmdIds.NtfFriendChat, data); await Player.SendPacket(CmdIds.NtfFriendChat, data);
} }

View File

@@ -0,0 +1,27 @@
using System.Text.RegularExpressions;
namespace MikuSB.GameServer.Game.Player;
public static partial class ChatMessageHelper
{
[GeneratedRegex(@"\s+")]
private static partial Regex MultiWhitespaceRegex();
public static uint BuildClientTimestamp()
{
return (uint)MikuSB.Util.Extensions.Extensions.GetUnixSec();
}
public static string NormalizeForClient(string? text)
{
if (string.IsNullOrWhiteSpace(text))
return string.Empty;
var normalized = text
.Replace("\r\n", " ")
.Replace('\r', ' ')
.Replace('\n', ' ');
return MultiWhitespaceRegex().Replace(normalized, " ").Trim();
}
}

View File

@@ -160,9 +160,9 @@ public class PlayerInstance(PlayerGameData data)
Sender = sendUid, Sender = sendUid,
Recver = recvUid, Recver = recvUid,
Emoji = emojiId ?? 0, Emoji = emojiId ?? 0,
Text = message ?? "", Text = ChatMessageHelper.NormalizeForClient(message),
Profile = Data.ToProfileProto(), Profile = Data.ToProfileProto(),
TimeStamp = (uint)Extensions.GetUnixMs() TimeStamp = ChatMessageHelper.BuildClientTimestamp()
}; };
await SendPacket(CmdIds.NtfFriendChat, data); await SendPacket(CmdIds.NtfFriendChat, data);