TigerEmu/Networking/Game/Sessions/GameSession.cs

42 lines
1.0 KiB
C#

using System.Net.Sockets;
using Tiger.Communication.Messages.Interfaces;
using Tiger.Communication.Messages.Types;
using Tiger.Game.Habbos;
using Tiger.Security;
namespace Tiger.Networking.Game.Sessions;
public class GameSession
{
public TcpClient Client { get; }
public NetworkStream Stream { get; }
public string SessionId { get; }
public Habbo? Habbo { get; set; }
public Rc4? Rc4 { get; set; }
public GameSession(TcpClient client, string sessionId)
{
Client = client;
SessionId = sessionId;
Stream = Client.GetStream();
}
public async Task SendComposerAsync(IMessageComposer composer)
{
var message = new ServerMessage((short)composer.Header);
composer.Compose(message);
await SendMessageAsync(message);
}
public async Task SendMessageAsync(ServerMessage message)
{
var bytes = message.ToArray();
await Stream.WriteAsync(bytes);
}
public async Task CloseAsync()
{
Stream.Close();
Client.Close();
}
}