diff --git a/Communication/Messages/Incoming/Landingview/GetPromoArticlesMessageEvent.cs b/Communication/Messages/Incoming/Landingview/GetPromoArticlesMessageEvent.cs new file mode 100644 index 0000000..0ad214b --- /dev/null +++ b/Communication/Messages/Incoming/Landingview/GetPromoArticlesMessageEvent.cs @@ -0,0 +1,31 @@ +using Tiger.Communication.Messages.Interfaces; +using Tiger.Communication.Messages.Outgoing.Landingview; +using Tiger.Communication.Messages.Types; +using Tiger.Game.LandingView; +using Tiger.Networking.Game.Sessions; + +namespace Tiger.Communication.Messages.Incoming.Landingview; + +public class GetPromoArticlesMessageEvent : IMessageEvent +{ + private readonly IGameSessionManager _gameSessionManager; + private readonly ILandingViewManager _landingViewManager; + + public GetPromoArticlesMessageEvent(IGameSessionManager gameSessionManager, ILandingViewManager landingViewManager) + { + _gameSessionManager = gameSessionManager; + _landingViewManager = landingViewManager; + } + + public IncomingHeaders Header => IncomingHeaders.GetPromoArticlesEvent; + public async Task HandleAsync(GameSession gameSession, ClientMessage request) + { + if (gameSession.Habbo == null) + { + await _gameSessionManager.CloseAsync("Not logged in", gameSession); + return; + } + + await gameSession.SendComposerAsync(new PromoArticlesComposer(_landingViewManager.PromoArticles)); + } +} \ No newline at end of file diff --git a/Communication/Messages/Outgoing/Landingview/PromoArticlesComposer.cs b/Communication/Messages/Outgoing/Landingview/PromoArticlesComposer.cs new file mode 100644 index 0000000..60e567c --- /dev/null +++ b/Communication/Messages/Outgoing/Landingview/PromoArticlesComposer.cs @@ -0,0 +1,32 @@ +using Tiger.Communication.Messages.Interfaces; +using Tiger.Communication.Messages.Types; +using Tiger.Game.LandingView; + +namespace Tiger.Communication.Messages.Outgoing.Landingview; + +public class PromoArticlesComposer : IMessageComposer +{ + private readonly ICollection _promoArticles; + + public PromoArticlesComposer(ICollection promoArticles) + { + _promoArticles = promoArticles; + } + + public OutgoingHeaders Header => OutgoingHeaders.PromoArticlesMessageComposer; + public void Compose(ServerMessage message) + { + message.AppendInt32(_promoArticles.Count); + + foreach (var promoArticle in _promoArticles) + { + message.AppendInt32(promoArticle.Id); + message.AppendString(promoArticle.Title); + message.AppendString(promoArticle.BodyText); + message.AppendString(promoArticle.ButtonText); + message.AppendInt32((int)promoArticle.LinkType); + message.AppendString(promoArticle.LinkContent); + message.AppendString(promoArticle.ImageUrl); + } + } +} \ No newline at end of file diff --git a/Game/LandingView/ILandingViewManager.cs b/Game/LandingView/ILandingViewManager.cs new file mode 100644 index 0000000..ed2c11e --- /dev/null +++ b/Game/LandingView/ILandingViewManager.cs @@ -0,0 +1,7 @@ +namespace Tiger.Game.LandingView; + +public interface ILandingViewManager +{ + ICollection PromoArticles { get; } + Task LoadPromoArticlesAsync(); +} \ No newline at end of file diff --git a/Game/LandingView/LandingViewManager.cs b/Game/LandingView/LandingViewManager.cs new file mode 100644 index 0000000..59907dd --- /dev/null +++ b/Game/LandingView/LandingViewManager.cs @@ -0,0 +1,25 @@ +using Microsoft.Extensions.Logging; +using Tiger.Storage; + +namespace Tiger.Game.LandingView; + +public class LandingViewManager : ILandingViewManager +{ + private readonly IRepository _promoArticleRepository; + private readonly ILogger _logger; + + public LandingViewManager(IRepository promoArticleRepository, ILogger logger) + { + _promoArticleRepository = promoArticleRepository; + _logger = logger; + } + + public ICollection PromoArticles { get; private set; } = new List(); + + public async Task LoadPromoArticlesAsync() + { + PromoArticles = (await _promoArticleRepository.FindByAsync()).ToList(); + + _logger.LogInformation("Loaded {Count} promo articles", PromoArticles.Count); + } +} \ No newline at end of file diff --git a/Game/LandingView/PromoArticle.cs b/Game/LandingView/PromoArticle.cs new file mode 100644 index 0000000..c54c42d --- /dev/null +++ b/Game/LandingView/PromoArticle.cs @@ -0,0 +1,12 @@ +namespace Tiger.Game.LandingView; + +public class PromoArticle +{ + public virtual int Id { get; set; } + public virtual string Title { get; set; } = null!; + public virtual string BodyText { get; set; } = null!; + public virtual string ButtonText { get; set; } = null!; + public virtual PromoArticleLinkType LinkType { get; set; } + public virtual string LinkContent { get; set; } = null!; + public virtual string ImageUrl { get; set; } = null!; +} \ No newline at end of file diff --git a/Game/LandingView/PromoArticleLinkType.cs b/Game/LandingView/PromoArticleLinkType.cs new file mode 100644 index 0000000..ebbada1 --- /dev/null +++ b/Game/LandingView/PromoArticleLinkType.cs @@ -0,0 +1,8 @@ +namespace Tiger.Game.LandingView; + +public enum PromoArticleLinkType +{ + LinkTypeUrl = 0, + LinkTypeInternal = 1, + LinkTypeNoLink = 2 +} \ No newline at end of file diff --git a/Game/LandingView/PromoArticleMap.cs b/Game/LandingView/PromoArticleMap.cs new file mode 100644 index 0000000..2057b79 --- /dev/null +++ b/Game/LandingView/PromoArticleMap.cs @@ -0,0 +1,18 @@ +using FluentNHibernate.Mapping; + +namespace Tiger.Game.LandingView; + +public class PromoArticleMap : ClassMap +{ + public PromoArticleMap() + { + Table("landing_promo_articles"); + Id(pa => pa.Id).Column("id").GeneratedBy.Identity(); + Map(pa => pa.Title).Column("title").Not.Nullable(); + Map(pa => pa.BodyText).Column("body_text").Not.Nullable(); + Map(pa => pa.ButtonText).Column("button_text").Not.Nullable(); + Map(pa => pa.LinkType).CustomType().Column("link_type").Not.Nullable(); + Map(pa => pa.LinkContent).Column("link_content").Not.Nullable(); + Map(pa => pa.ImageUrl).Column("image_url").Not.Nullable(); + } +} \ No newline at end of file diff --git a/Program.cs b/Program.cs index 8cd5f3d..124cd73 100644 --- a/Program.cs +++ b/Program.cs @@ -6,6 +6,7 @@ using Tiger.Communication.Messages; using Tiger.Game.Catalogue; using Tiger.Game.Figuredata; using Tiger.Game.Habbos; +using Tiger.Game.LandingView; using Tiger.Game.Settings; using Tiger.Networking.Game; using Tiger.Networking.Game.Sessions; @@ -37,6 +38,7 @@ collection.AddScoped(typeof(IRepository<>), typeof(Repository<>)); collection.AddSingleton(); collection.AddSingleton(); collection.AddSingleton(); +collection.AddSingleton(); collection.RegisterMessageEvents(); var provider = collection.BuildServiceProvider(); @@ -44,6 +46,7 @@ var provider = collection.BuildServiceProvider(); await provider.GetRequiredService().ReloadSettingsAsync(); await provider.GetRequiredService().LoadPagesAsync(); provider.GetRequiredService(); +await provider.GetRequiredService().LoadPromoArticlesAsync(); provider.GetRequiredService().Start($"http://{configuration["Network:Game:Ip"]}:{configuration["Network:Game:Port"]}/");