feat: add world chat UI

This commit is contained in:
ud18010
2026-07-28 11:54:07 +08:00
parent 09c89aadf0
commit 48aed26725
28 changed files with 5308 additions and 99 deletions
+33
View File
@@ -32,6 +32,10 @@ namespace XWorld.Server.Gateway.Tests
Moving = moving
}.Encode());
private static Frame WorldChatFrame(string text)
=> new Frame(Channel.Framework, (ushort)FrameworkOpcode.WorldChatSend,
new WorldChatSendMsg { Text = text }.Encode());
private static List<Frame> Frames(FakeConnection c)
{
var list = new List<Frame>();
@@ -85,6 +89,35 @@ namespace XWorld.Server.Gateway.Tests
Assert.True(decoded.Moving);
}
[Fact]
public void WorldChat_IsBroadcastToAllConnectedPlayers()
{
var loop = NewLoop();
var c1 = new FakeConnection(1);
var c2 = new FakeConnection(2);
loop.Submit(new ConnectCommand { PlayerId = 1, Connection = c1 });
loop.Submit(new ConnectCommand { PlayerId = 2, Connection = c2 });
loop.Submit(new FrameCommand { PlayerId = 1, Frame = LobbyJoinFrame("Alice") });
loop.Submit(new FrameCommand { PlayerId = 2, Frame = LobbyJoinFrame("Bob") });
loop.DrainAndTick(0f);
c1.Sent.Clear();
c2.Sent.Clear();
loop.Submit(new FrameCommand { PlayerId = 1, Frame = WorldChatFrame("hello world") });
loop.DrainAndTick(0f);
Frame selfFrame = Frames(c1).Find(f => f.Channel == Channel.Framework && f.Opcode == (ushort)FrameworkOpcode.WorldChatMessage);
Frame otherFrame = Frames(c2).Find(f => f.Channel == Channel.Framework && f.Opcode == (ushort)FrameworkOpcode.WorldChatMessage);
Assert.NotEqual(default, selfFrame);
Assert.NotEqual(default, otherFrame);
WorldChatMessageMsg message = WorldChatMessageMsg.Decode(otherFrame.Payload);
Assert.Equal(1, message.PlayerId);
Assert.Equal("Alice", message.PlayerName);
Assert.Equal("hello world", message.Text);
Assert.True(message.ServerTimeMs > 0);
}
[Fact]
public void Reconnect_ReroutesRoomOutputToNewConnection()
{