From 4dce1b0ca39c0fc527eb8a6b95ac4cd1d9990422 Mon Sep 17 00:00:00 2001 From: VladimirKhil Date: Tue, 16 Jan 2024 22:02:34 +0100 Subject: [PATCH] Enhanced integration with SIStatistics server --- .../SI.GameServer.Client/GameServerClient.cs | 3 ++ .../SI.GameServer.Contract/ChatMessage.cs | 3 ++ src/Common/SIEngine.Core/FalseStartHelper.cs | 2 +- src/Common/SIEngine.Core/QuestionEngine.cs | 7 ++-- .../SIEngine.Core/QuestionEngineOptions.cs | 2 +- src/SICore/SICore/BusinessLogic/Localizer.cs | 37 +++++++++---------- src/SICore/SICore/Clients/Game/GameLogic.cs | 8 +++- .../SICore/Clients/Player/PlayerTasks.cs | 29 +++++++-------- src/SICore/SICore/Results/GameResult.cs | 12 +++++- 9 files changed, 61 insertions(+), 42 deletions(-) create mode 100644 src/Common/SI.GameServer.Contract/ChatMessage.cs diff --git a/src/Common/SI.GameServer.Client/GameServerClient.cs b/src/Common/SI.GameServer.Client/GameServerClient.cs index 2337620d..63c3a19e 100644 --- a/src/Common/SI.GameServer.Client/GameServerClient.cs +++ b/src/Common/SI.GameServer.Client/GameServerClient.cs @@ -181,6 +181,9 @@ public Task GetGamesHostInfoAsync(CancellationToken cancellationToken public Task GetNewsAsync(CancellationToken cancellationToken = default) => _connection.InvokeAsync("GetNews", cancellationToken); + public Task GetLatestChatMessagesAsync(CancellationToken cancellationToken = default) => + _connection.InvokeAsync("GetLatestChatMessages", cancellationToken); + public Task GetUsersAsync(CancellationToken cancellationToken = default) => _connection.InvokeAsync("GetUsers", cancellationToken); diff --git a/src/Common/SI.GameServer.Contract/ChatMessage.cs b/src/Common/SI.GameServer.Contract/ChatMessage.cs new file mode 100644 index 00000000..d4a4ce0c --- /dev/null +++ b/src/Common/SI.GameServer.Contract/ChatMessage.cs @@ -0,0 +1,3 @@ +namespace SI.GameServer.Contract; + +public sealed record ChatMessage(string UserName, string Text); diff --git a/src/Common/SIEngine.Core/FalseStartHelper.cs b/src/Common/SIEngine.Core/FalseStartHelper.cs index 4f96726e..a29ad0c9 100644 --- a/src/Common/SIEngine.Core/FalseStartHelper.cs +++ b/src/Common/SIEngine.Core/FalseStartHelper.cs @@ -118,7 +118,7 @@ private static bool ValidateThatStepIsFalseStartable( { var contentItem = content.ContentValue[k]; - if (contentItem.Type != AtomTypes.Text) + if (contentItem.Type != ContentTypes.Text) { return true; } diff --git a/src/Common/SIEngine.Core/QuestionEngine.cs b/src/Common/SIEngine.Core/QuestionEngine.cs index 7fd5d22c..cd2590bf 100644 --- a/src/Common/SIEngine.Core/QuestionEngine.cs +++ b/src/Common/SIEngine.Core/QuestionEngine.cs @@ -4,7 +4,7 @@ namespace SIEngine.Core; /// -/// Performs SI question playing (new engine version). +/// Performs SI question playing. /// public sealed class QuestionEngine { @@ -283,10 +283,9 @@ public bool PlayNext() { ContentValue = new List { - new ContentItem - { + new() { Placement = ContentPlacements.Screen, - Type = AtomTypes.Text, + Type = ContentTypes.Text, Value = rightAnswer } } diff --git a/src/Common/SIEngine.Core/QuestionEngineOptions.cs b/src/Common/SIEngine.Core/QuestionEngineOptions.cs index 8bd1dc11..1a775486 100644 --- a/src/Common/SIEngine.Core/QuestionEngineOptions.cs +++ b/src/Common/SIEngine.Core/QuestionEngineOptions.cs @@ -13,7 +13,7 @@ public sealed class QuestionEngineOptions public FalseStartMode FalseStarts { get; set; } = FalseStartMode.Enabled; /// - /// Show simple right answers. + /// Show simple right answers flag. Complex right answers are always shown. /// public bool ShowSimpleRightAnswers { get; set; } diff --git a/src/SICore/SICore/BusinessLogic/Localizer.cs b/src/SICore/SICore/BusinessLogic/Localizer.cs index aecd7f1f..c743fccd 100644 --- a/src/SICore/SICore/BusinessLogic/Localizer.cs +++ b/src/SICore/SICore/BusinessLogic/Localizer.cs @@ -2,31 +2,30 @@ using System.Globalization; using System.Resources; -namespace SICore.BusinessLogic +namespace SICore.BusinessLogic; + +public sealed class Localizer : ILocalizer { - public sealed class Localizer : ILocalizer - { - private readonly ResourceManager _resourceManager; + private readonly ResourceManager _resourceManager; - private ResourceManager _packagesResourceManager; + private ResourceManager _packagesResourceManager; - public CultureInfo Culture { get; } + public CultureInfo Culture { get; } - public Localizer(string culture) - { - _resourceManager = new ResourceManager("SICore.Properties.Resources", typeof(Resources).Assembly); - Culture = new CultureInfo(culture ?? "en-US"); - } + public Localizer(string culture) + { + _resourceManager = new ResourceManager("SICore.Properties.Resources", typeof(Resources).Assembly); + Culture = new CultureInfo(culture ?? "en-US"); + } - public string this[string key] => _resourceManager.GetString(key, Culture); + public string this[string key] => _resourceManager.GetString(key, Culture); - public string GetPackagesString(string key) - { - _packagesResourceManager ??= new ResourceManager( - "SIPackages.Properties.Resources", - typeof(SIPackages.Properties.Resources).Assembly); + public string GetPackagesString(string key) + { + _packagesResourceManager ??= new ResourceManager( + "SIPackages.Properties.Resources", + typeof(SIPackages.Properties.Resources).Assembly); - return _packagesResourceManager.GetString(key, Culture); - } + return _packagesResourceManager.GetString(key, Culture); } } diff --git a/src/SICore/SICore/Clients/Game/GameLogic.cs b/src/SICore/SICore/Clients/Game/GameLogic.cs index 8358ac22..e3107947 100644 --- a/src/SICore/SICore/Clients/Game/GameLogic.cs +++ b/src/SICore/SICore/Clients/Game/GameLogic.cs @@ -144,9 +144,11 @@ internal void Run() _data.PackageDoc = Engine.Document; _data.GameResultInfo.Name = _data.GameName; + _data.GameResultInfo.Language = _data.Settings.AppSettings.Culture; _data.GameResultInfo.PackageName = Engine.PackageName; _data.GameResultInfo.PackageHash = ""; // Will not use hash for now _data.GameResultInfo.PackageAuthors = Engine.Document.Package.Info.Authors.ToArray(); + _data.GameResultInfo.PackageAuthorsContacts = Engine.Document.Package.ContactUri; if (_data.Settings.IsAutomatic) { @@ -902,7 +904,11 @@ protected override async ValueTask DisposeAsync(bool disposing) => await ClientData.TaskLock.TryLockAsync( () => { - SendReport(); + if (_data.Stage != GameStage.Before) + { + SendReport(); + } + Engine.Dispose(); return base.DisposeAsync(disposing); diff --git a/src/SICore/SICore/Clients/Player/PlayerTasks.cs b/src/SICore/SICore/Clients/Player/PlayerTasks.cs index b9f05096..c36ec9c6 100644 --- a/src/SICore/SICore/Clients/Player/PlayerTasks.cs +++ b/src/SICore/SICore/Clients/Player/PlayerTasks.cs @@ -1,17 +1,16 @@ -namespace SICore.Clients.Player +namespace SICore.Clients.Player; + +internal enum PlayerTasks { - internal enum PlayerTasks - { - Ready, - Answer, - Choose, - Cat, - CatCost, - Stake, - ChooseFinal, - FinalStake, - AnswerRight, - AnswerWrong, - PressButton - } + Ready, + Answer, + Choose, + Cat, + CatCost, + Stake, + ChooseFinal, + FinalStake, + AnswerRight, + AnswerWrong, + PressButton } diff --git a/src/SICore/SICore/Results/GameResult.cs b/src/SICore/SICore/Results/GameResult.cs index f1c4ab90..8230faba 100644 --- a/src/SICore/SICore/Results/GameResult.cs +++ b/src/SICore/SICore/Results/GameResult.cs @@ -10,10 +10,15 @@ public sealed class GameResult /// public string Name { get; set; } = ""; + /// + /// Game language. + /// + public string? Language { get; set; } + /// /// Game start time. /// - public DateTimeOffset StartTime { get; set; } + public DateTimeOffset StartTime { get; set; } = DateTimeOffset.UtcNow; /// /// Game duration. @@ -35,6 +40,11 @@ public sealed class GameResult /// public string[] PackageAuthors { get; set; } = Array.Empty(); + /// + /// Game package authors contacts. + /// + public string? PackageAuthorsContacts { get; set; } + /// /// Players results. ///