Compare commits

...

2 Commits

Author SHA1 Message Date
Kei-Luna
3611624073 Update version.txt 2026-04-29 09:01:38 +09:00
Kei-Luna
c61ac08dd3 Fixed a critical issue with in-game chat. 2026-04-29 09:01:20 +09:00
4 changed files with 32 additions and 5 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);

View File

@@ -1 +1 @@
v=1.2 v=1.3