Added catalogue features pages + add some extra checks in catalogue index + pages
							parent
							
								
									e20079bc2c
								
							
						
					
					
						commit
						f56198e9cb
					
				|  | @ -25,10 +25,13 @@ public class GetCatalogIndexEvent : IMessageEvent | ||||||
|             await _gameSessionManager.CloseAsync("Not logged in", gameSession); |             await _gameSessionManager.CloseAsync("Not logged in", gameSession); | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|          |  | ||||||
|         var categories = _catalogueManager.Pages.Values.Where(p => p.Parent is null); |  | ||||||
| 
 | 
 | ||||||
|         await gameSession.SendComposerAsync(new CatalogPagesListComposer(categories, |         var mode = request.ReadString() ?? "normal"; | ||||||
|             request.ReadString() ?? "normal")); |          | ||||||
|  |         var categories = | ||||||
|  |             _catalogueManager.Pages.Values.Where( | ||||||
|  |                 p => p.Parent is null && p.Modes.Contains(mode) && p.MinRank <= gameSession.Habbo.Rank); | ||||||
|  | 
 | ||||||
|  |         await gameSession.SendComposerAsync(new CatalogPagesListComposer(categories, mode)); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | @ -30,11 +30,16 @@ public class GetCatalogPageEvent : IMessageEvent | ||||||
|         var offerId = request.ReadInt32() ?? 0; |         var offerId = request.ReadInt32() ?? 0; | ||||||
|         var mode = request.ReadString() ?? "normal"; |         var mode = request.ReadString() ?? "normal"; | ||||||
| 
 | 
 | ||||||
|         if (!_catalogueManager.Pages.TryGetValue(pageId, out var page)) |         if (!_catalogueManager.Pages.TryGetValue(pageId, out var page) || !page.Enabled || | ||||||
|  |             page.MinRank > gameSession.Habbo.Rank || !page.Modes.Contains(mode)) | ||||||
|         { |         { | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         await gameSession.SendComposerAsync(new CatalogPageMessageComposer(page, offerId, mode)); |         var featuredPages = page.Layout.Equals("frontpage4") | ||||||
|  |             ? _catalogueManager.FeaturedPages.Values | ||||||
|  |             : new List<CatalogueFeaturedPage>(); | ||||||
|  | 
 | ||||||
|  |         await gameSession.SendComposerAsync(new CatalogPageMessageComposer(page, offerId, mode, featuredPages)); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | @ -9,12 +9,15 @@ public class CatalogPageMessageComposer : IMessageComposer | ||||||
|     private readonly CataloguePage _page; |     private readonly CataloguePage _page; | ||||||
|     private readonly int _offerId; |     private readonly int _offerId; | ||||||
|     private readonly string _mode; |     private readonly string _mode; | ||||||
|  |     private readonly ICollection<CatalogueFeaturedPage> _featuredPages; | ||||||
| 
 | 
 | ||||||
|     public CatalogPageMessageComposer(CataloguePage page, int offerId, string mode) |     public CatalogPageMessageComposer(CataloguePage page, int offerId, string mode, | ||||||
|  |         ICollection<CatalogueFeaturedPage> featuredPages) | ||||||
|     { |     { | ||||||
|         _page = page; |         _page = page; | ||||||
|         _offerId = offerId; |         _offerId = offerId; | ||||||
|         _mode = mode; |         _mode = mode; | ||||||
|  |         _featuredPages = featuredPages; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public OutgoingHeaders Header => OutgoingHeaders.CatalogPage; |     public OutgoingHeaders Header => OutgoingHeaders.CatalogPage; | ||||||
|  | @ -40,5 +43,26 @@ public class CatalogPageMessageComposer : IMessageComposer | ||||||
|         message.AppendInt32(0); |         message.AppendInt32(0); | ||||||
|         message.AppendInt32(_offerId); |         message.AppendInt32(_offerId); | ||||||
|         message.AppendBoolean(_page.SeasonalCurrency); |         message.AppendBoolean(_page.SeasonalCurrency); | ||||||
|  |         message.AppendInt32(_featuredPages.Count); | ||||||
|  | 
 | ||||||
|  |         foreach (var featuredPage in _featuredPages) | ||||||
|  |         { | ||||||
|  |             message.AppendInt32(featuredPage.SlotId); | ||||||
|  |             message.AppendString(featuredPage.Caption); | ||||||
|  |             message.AppendString(featuredPage.Image); | ||||||
|  |             message.AppendInt32((int)featuredPage.Type); | ||||||
|  |             switch (featuredPage.Type) | ||||||
|  |             { | ||||||
|  |                 default: | ||||||
|  |                 case CatalogueFeaturedPageType.PageName: | ||||||
|  |                 case CatalogueFeaturedPageType.ProductName: | ||||||
|  |                     message.AppendString(featuredPage.Data); | ||||||
|  |                     break; | ||||||
|  |                 case CatalogueFeaturedPageType.PageId: | ||||||
|  |                     message.AppendInt32(int.TryParse(featuredPage.Data, out var pageId) ? pageId : -1); | ||||||
|  |                     break; | ||||||
|  |             } | ||||||
|  |             message.AppendInt32((int)(DateTime.Now - featuredPage.Expire).TotalSeconds); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | @ -21,7 +21,7 @@ public class CatalogPagesListComposer : IMessageComposer | ||||||
|         message.AppendBoolean(true); |         message.AppendBoolean(true); | ||||||
|         message.AppendInt32(0); |         message.AppendInt32(0); | ||||||
|         message.AppendInt32(-1); |         message.AppendInt32(-1); | ||||||
|         message.AppendString(string.Empty); |         message.AppendString("root"); | ||||||
|         message.AppendString(string.Empty); |         message.AppendString(string.Empty); | ||||||
|         message.AppendInt32(0); |         message.AppendInt32(0); | ||||||
|         message.AppendInt32(_pages.Count()); |         message.AppendInt32(_pages.Count()); | ||||||
|  |  | ||||||
|  | @ -0,0 +1,11 @@ | ||||||
|  | namespace Tiger.Game.Catalogue; | ||||||
|  | 
 | ||||||
|  | public class CatalogueFeaturedPage | ||||||
|  | { | ||||||
|  |     public virtual int SlotId { get; set; } | ||||||
|  |     public virtual string Image { get; set; } = null!; | ||||||
|  |     public virtual string Caption { get; set; } = null!; | ||||||
|  |     public virtual CatalogueFeaturedPageType Type { get; set; } | ||||||
|  |     public virtual DateTime Expire { get; set; } | ||||||
|  |     public virtual string Data { get; set; } = null!; | ||||||
|  | } | ||||||
|  | @ -0,0 +1,17 @@ | ||||||
|  | using FluentNHibernate.Mapping; | ||||||
|  | 
 | ||||||
|  | namespace Tiger.Game.Catalogue; | ||||||
|  | 
 | ||||||
|  | public class CatalogueFeaturedPageMap : ClassMap<CatalogueFeaturedPage> | ||||||
|  | { | ||||||
|  |     public CatalogueFeaturedPageMap() | ||||||
|  |     { | ||||||
|  |         Table("catalogue_featured_pages"); | ||||||
|  |         Id(fp => fp.SlotId).Column("slot_id").GeneratedBy.Identity(); | ||||||
|  |         Map(fp => fp.Image).Column("image").Not.Nullable(); | ||||||
|  |         Map(fp => fp.Caption).Column("caption").Not.Nullable(); | ||||||
|  |         Map(fp => fp.Type).CustomType<int>().Column("type").Not.Nullable(); | ||||||
|  |         Map(fp => fp.Expire).Column("expire").Not.Nullable(); | ||||||
|  |         Map(fp => fp.Data).Column("data").Not.Nullable(); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | @ -0,0 +1,8 @@ | ||||||
|  | namespace Tiger.Game.Catalogue; | ||||||
|  | 
 | ||||||
|  | public enum CatalogueFeaturedPageType | ||||||
|  | { | ||||||
|  |     PageName, | ||||||
|  |     PageId, | ||||||
|  |     ProductName | ||||||
|  | } | ||||||
|  | @ -7,14 +7,19 @@ public class CatalogueManager : ICatalogueManager | ||||||
| { | { | ||||||
|     private readonly IRepository<CataloguePage> _pagesRepository; |     private readonly IRepository<CataloguePage> _pagesRepository; | ||||||
|     private readonly ILogger<ICatalogueManager> _logger; |     private readonly ILogger<ICatalogueManager> _logger; | ||||||
|  |     private readonly IRepository<CatalogueFeaturedPage> _featuredPagesRepository; | ||||||
|      |      | ||||||
|     public IDictionary<int, CataloguePage> Pages { get; private set; } |     public IDictionary<int, CataloguePage> Pages { get; private set; } | ||||||
|  |     public IDictionary<int, CatalogueFeaturedPage> FeaturedPages { get; private set; } | ||||||
| 
 | 
 | ||||||
|     public CatalogueManager(IRepository<CataloguePage> pagesRepository, ILogger<ICatalogueManager> logger) |     public CatalogueManager(IRepository<CataloguePage> pagesRepository, ILogger<ICatalogueManager> logger, | ||||||
|  |         IRepository<CatalogueFeaturedPage> featuredPagesRepository) | ||||||
|     { |     { | ||||||
|         _pagesRepository = pagesRepository; |         _pagesRepository = pagesRepository; | ||||||
|         _logger = logger; |         _logger = logger; | ||||||
|  |         _featuredPagesRepository = featuredPagesRepository; | ||||||
|         Pages = new Dictionary<int, CataloguePage>(); |         Pages = new Dictionary<int, CataloguePage>(); | ||||||
|  |         FeaturedPages = new Dictionary<int, CatalogueFeaturedPage>(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public async Task LoadPagesAsync() |     public async Task LoadPagesAsync() | ||||||
|  | @ -23,4 +28,12 @@ public class CatalogueManager : ICatalogueManager | ||||||
|          |          | ||||||
|         _logger.LogInformation("Loaded {Count} catalogue pages", Pages.Count); |         _logger.LogInformation("Loaded {Count} catalogue pages", Pages.Count); | ||||||
|     } |     } | ||||||
|  |      | ||||||
|  |     public async Task LoadFeaturedPagesAsync() | ||||||
|  |     { | ||||||
|  |         FeaturedPages =(await _featuredPagesRepository.FindByAsync()) | ||||||
|  |             .ToDictionary(p => p.SlotId, p => p); | ||||||
|  |          | ||||||
|  |         _logger.LogInformation("Loaded {Count} catalogue featured pages", FeaturedPages.Count); | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | @ -3,5 +3,7 @@ namespace Tiger.Game.Catalogue; | ||||||
| public interface ICatalogueManager | public interface ICatalogueManager | ||||||
| { | { | ||||||
|     public IDictionary<int, CataloguePage> Pages { get; } |     public IDictionary<int, CataloguePage> Pages { get; } | ||||||
|  |     public IDictionary<int, CatalogueFeaturedPage> FeaturedPages { get; } | ||||||
|     Task LoadPagesAsync(); |     Task LoadPagesAsync(); | ||||||
|  |     Task LoadFeaturedPagesAsync(); | ||||||
| } | } | ||||||
|  | @ -47,6 +47,7 @@ var provider = collection.BuildServiceProvider(); | ||||||
| 
 | 
 | ||||||
| await provider.GetRequiredService<ISettingManager>().ReloadSettingsAsync(); | await provider.GetRequiredService<ISettingManager>().ReloadSettingsAsync(); | ||||||
| await provider.GetRequiredService<ICatalogueManager>().LoadPagesAsync(); | await provider.GetRequiredService<ICatalogueManager>().LoadPagesAsync(); | ||||||
|  | await provider.GetRequiredService<ICatalogueManager>().LoadFeaturedPagesAsync(); | ||||||
| provider.GetRequiredService<IFigureDataManager>(); | provider.GetRequiredService<IFigureDataManager>(); | ||||||
| await provider.GetRequiredService<ILandingViewManager>().LoadPromoArticlesAsync(); | await provider.GetRequiredService<ILandingViewManager>().LoadPromoArticlesAsync(); | ||||||
| await provider.GetRequiredService<IAchievementManager>().LoadAchievementsAsync(); | await provider.GetRequiredService<IAchievementManager>().LoadAchievementsAsync(); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue