2023-10-06 16:12:35 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-10-14 16:21:53 +00:00
|
|
|
public IncomingHeaders Header => IncomingHeaders.GetCatalogPage;
|
2023-10-06 16:12:35 +00:00
|
|
|
public async Task HandleAsync(GameSession gameSession, ClientMessage request)
|
|
|
|
{
|
|
|
|
if (gameSession.Habbo == null)
|
|
|
|
{
|
|
|
|
await _gameSessionManager.CloseAsync("Not logged in", gameSession);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var pageId = request.ReadInt32() ?? -1;
|
|
|
|
var offerId = request.ReadInt32() ?? 0;
|
|
|
|
var mode = request.ReadString() ?? "normal";
|
|
|
|
|
2023-10-14 17:35:03 +00:00
|
|
|
if (!_catalogueManager.Pages.TryGetValue(pageId, out var page) || !page.Enabled ||
|
|
|
|
page.MinRank > gameSession.Habbo.Rank || !page.Modes.Contains(mode))
|
2023-10-06 16:12:35 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-10-14 17:35:03 +00:00
|
|
|
var featuredPages = page.Layout.Equals("frontpage4")
|
|
|
|
? _catalogueManager.FeaturedPages.Values
|
|
|
|
: new List<CatalogueFeaturedPage>();
|
|
|
|
|
|
|
|
await gameSession.SendComposerAsync(new CatalogPageMessageComposer(page, offerId, mode, featuredPages));
|
2023-10-06 16:12:35 +00:00
|
|
|
}
|
|
|
|
}
|