Initial commit: Client Doc docs Server Tools
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
using System.Collections.Generic;
|
||||
using XWorld.Framework;
|
||||
using XWorld.Framework.Protocol;
|
||||
using XWorld.Server.Host;
|
||||
|
||||
namespace XWorld.Server.Gateway
|
||||
{
|
||||
// 房间广播 → 解析各玩家当前连接(重连后自动指向新连接)→ 包成 Game 通道帧入对应出站队列
|
||||
public sealed class RoomOutputSink : IRoomOutput
|
||||
{
|
||||
private readonly string _roomId; // 保留作诊断/日志标识
|
||||
private readonly IReadOnlyList<int> _players;
|
||||
private readonly SessionManager _sessions;
|
||||
|
||||
public RoomOutputSink(string roomId, IReadOnlyList<int> players, SessionManager sessions)
|
||||
{
|
||||
_roomId = roomId; _players = players; _sessions = sessions;
|
||||
}
|
||||
|
||||
public void Broadcast(NetMessage message)
|
||||
{
|
||||
byte[] frame = FrameCodec.Encode(new Frame(Channel.Game, message.Opcode, message.Payload));
|
||||
foreach (var pid in _players)
|
||||
_sessions.GetConnection(pid)?.Send(frame);
|
||||
}
|
||||
|
||||
public void SendTo(int playerId, NetMessage message)
|
||||
{
|
||||
var conn = _sessions.GetConnection(playerId);
|
||||
if (conn != null)
|
||||
conn.Send(FrameCodec.Encode(new Frame(Channel.Game, message.Opcode, message.Payload)));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user