45 lines
1.6 KiB
C#
45 lines
1.6 KiB
C#
using Tiger.Communication.Messages.Interfaces;
|
|
using Tiger.Communication.Messages.Outgoing.Catalog;
|
|
using Tiger.Communication.Messages.Types;
|
|
using Tiger.Game.Catalogue;
|
|
using Tiger.Networking.Game.Sessions;
|
|
|
|
namespace Tiger.Communication.Messages.Incoming.Catalog;
|
|
|
|
public class GetCatalogPageEvent : IMessageEvent
|
|
{
|
|
private readonly ICatalogueManager _catalogueManager;
|
|
private readonly IGameSessionManager _gameSessionManager;
|
|
|
|
public GetCatalogPageEvent(ICatalogueManager catalogueManager, IGameSessionManager gameSessionManager)
|
|
{
|
|
_catalogueManager = catalogueManager;
|
|
_gameSessionManager = gameSessionManager;
|
|
}
|
|
|
|
public IncomingHeaders Header => IncomingHeaders.GetCatalogPage;
|
|
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 mode = request.ReadString();
|
|
|
|
if (!_catalogueManager.Pages.TryGetValue(pageId, out var page) || !page.Enabled ||
|
|
page.MinRank > gameSession.Habbo.Rank || !page.Modes.Contains(mode.ToLower()))
|
|
{
|
|
return;
|
|
}
|
|
|
|
var featuredPages = page.Layout.Equals("frontpage4")
|
|
? _catalogueManager.FeaturedPages.Values
|
|
: new List<CatalogueFeaturedPage>();
|
|
|
|
await gameSession.SendComposerAsync(new CatalogPageMessageComposer(page, offerId, mode, featuredPages));
|
|
}
|
|
} |