2023-09-23 11:11:07 +00:00
|
|
|
using System.Net.WebSockets;
|
|
|
|
using Tiger.Communication.Messages.Interfaces;
|
|
|
|
using Tiger.Communication.Messages.Types;
|
|
|
|
using Tiger.Game.Habbos;
|
|
|
|
|
|
|
|
namespace Tiger.Networking.Game.Sessions;
|
|
|
|
|
|
|
|
public class GameSession
|
|
|
|
{
|
|
|
|
public WebSocket WebSocket { get; }
|
|
|
|
public string SessionId { get; }
|
|
|
|
public Habbo? Habbo { get; set; }
|
|
|
|
|
|
|
|
public GameSession(WebSocket webSocket, string sessionId)
|
|
|
|
{
|
|
|
|
WebSocket = webSocket;
|
|
|
|
SessionId = sessionId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task SendComposerAsync(IMessageComposer composer)
|
|
|
|
{
|
|
|
|
var message = new ServerMessage((short)composer.Header);
|
|
|
|
composer.Compose(message);
|
|
|
|
var bytes = message.ToArray();
|
|
|
|
await WebSocket.SendAsync(new ArraySegment<byte>(bytes), WebSocketMessageType.Binary, true,
|
|
|
|
CancellationToken.None);
|
|
|
|
}
|
2023-10-21 06:34:12 +00:00
|
|
|
|
|
|
|
public async Task SendMessageAsync(ServerMessage message)
|
|
|
|
{
|
|
|
|
var bytes = message.ToArray();
|
|
|
|
await WebSocket.SendAsync(new ArraySegment<byte>(bytes), WebSocketMessageType.Binary, true,
|
|
|
|
CancellationToken.None);
|
|
|
|
}
|
2023-09-23 11:11:07 +00:00
|
|
|
}
|