TigerEmu/Communication/Messages/Incoming/Catalog/PurchaseFromCatalogEvent.cs

43 lines
1.3 KiB
C#

using Tiger.Communication.Messages.Interfaces;
using Tiger.Communication.Messages.Types;
using Tiger.Game.Catalogue;
using Tiger.Networking.Game.Sessions;
namespace Tiger.Communication.Messages.Incoming.Catalog;
public class PurchaseFromCatalogEvent : IMessageEvent
{
private readonly ICatalogueManager _catalogueManager;
private readonly IGameSessionManager _gameSessionManager;
public PurchaseFromCatalogEvent(ICatalogueManager catalogueManager, IGameSessionManager gameSessionManager)
{
_catalogueManager = catalogueManager;
_gameSessionManager = gameSessionManager;
}
public IncomingHeaders Header => IncomingHeaders.CatalogPurchase;
public async Task HandleAsync(GameSession gameSession, ClientMessage request)
{
if (gameSession.Habbo == null)
{
await _gameSessionManager.CloseAsync("Not logged in", gameSession);
return;
}
var pageId = request.ReadInt32();
var offerId = request.ReadInt32();
var extraData = request.ReadString();
var amount = request.ReadInt32();
if (amount < 0 || !_catalogueManager.Pages.TryGetValue(pageId, out var page))
{
return;
}
if (page.Layout.Equals("vip_buy"))
{
await _catalogueManager.PurchaseClubOffer(offerId, gameSession);
}
}
}