TigerEmu/Networking/Game/Sessions/GameSession.cs

42 lines
1.0 KiB
C#
Raw Normal View History

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