From ad86a6616d759512bf4904a385336bce71e3cf8b Mon Sep 17 00:00:00 2001 From: Fooxboy Date: Sat, 4 Nov 2023 22:47:50 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BA=D0=BE=D1=82=20=D0=B2=20=D0=BC=D0=B5=D1=88=D0=BA?= =?UTF-8?q?=D0=B5=20=D0=B8=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=84=D0=B8=D0=BD=D0=B0=D0=BB=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BackgroundTasks/PackageCleaner.cs | 32 +++++++++++++ MyOwnGame.Backend/Domain/Session.cs | 5 ++ MyOwnGame.Backend/Helpers/SessionEvents.cs | 10 ++++ MyOwnGame.Backend/Hubs/SessionHub.cs | 13 ++++++ MyOwnGame.Backend/Models/SessionState.cs | 2 + MyOwnGame.Backend/Program.cs | 1 + .../Services/SessionCallbackService.cs | 8 +++- MyOwnGame.Backend/Services/SessionService.cs | 46 ++++++++++++++++++- 8 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 MyOwnGame.Backend/BackgroundTasks/PackageCleaner.cs diff --git a/MyOwnGame.Backend/BackgroundTasks/PackageCleaner.cs b/MyOwnGame.Backend/BackgroundTasks/PackageCleaner.cs new file mode 100644 index 0000000..b29cf98 --- /dev/null +++ b/MyOwnGame.Backend/BackgroundTasks/PackageCleaner.cs @@ -0,0 +1,32 @@ +namespace MyOwnGame.Backend.BackgroundTasks; + +public class PackageCleaner : IBackgroundTask +{ + private readonly IConfiguration _configuration; + private readonly ILogger _logger; + + public PackageCleaner(IConfiguration configuration, ILogger logger) + { + _configuration = configuration; + _logger = logger; + } + + public int Timeout => 54000; + + public Task Invoke() + { + _logger.LogWarning("Начало удаления пакетов"); + + var pathToPackages = _configuration.GetValue("packagesPath"); + + var packageFiles = Directory.GetFiles(pathToPackages); + + foreach (var packageFile in packageFiles) + { + _logger.LogWarning($"Удален пакет '{Path.GetFileName(packageFile)}'"); + File.Delete(packageFile); + } + + return Task.CompletedTask; + } +} \ No newline at end of file diff --git a/MyOwnGame.Backend/Domain/Session.cs b/MyOwnGame.Backend/Domain/Session.cs index 6f40985..cac7e0a 100644 --- a/MyOwnGame.Backend/Domain/Session.cs +++ b/MyOwnGame.Backend/Domain/Session.cs @@ -161,6 +161,11 @@ public void ChangeStateToTable() ResetRespondingPlayer(); } + public void ChangeStateToForwardQuestion() + { + State = SessionState.ForwardQuestion; + } + public void AddReadyToAnswerPlayer(Player player, DateTime time) { _playersReadyToAnswer.Add((player, time)); diff --git a/MyOwnGame.Backend/Helpers/SessionEvents.cs b/MyOwnGame.Backend/Helpers/SessionEvents.cs index cccc3aa..59fc533 100644 --- a/MyOwnGame.Backend/Helpers/SessionEvents.cs +++ b/MyOwnGame.Backend/Helpers/SessionEvents.cs @@ -114,4 +114,14 @@ public enum SessionEvents /// Пользователь устанавливает цену вопроса /// PlayerInstallingQuestionPrice, + + /// + /// Нужно передать вопрос + /// + NeedForwardQuestion, + + /// + /// Пользователь выбирает кому передать вопрос + /// + PlayerChoosesQuestionPlayer } \ No newline at end of file diff --git a/MyOwnGame.Backend/Hubs/SessionHub.cs b/MyOwnGame.Backend/Hubs/SessionHub.cs index 24514d3..75013cc 100644 --- a/MyOwnGame.Backend/Hubs/SessionHub.cs +++ b/MyOwnGame.Backend/Hubs/SessionHub.cs @@ -304,6 +304,19 @@ public async Task SetQuestionPrice(int price) } } + public async Task ForwardQuestion() + { + try + { + + } + catch (Exception ex) + { + _logger.LogError(ex, ex.Message); + throw new HubException(ex.Message, ex); + } + } + public override async Task OnDisconnectedAsync(Exception? exception) { try diff --git a/MyOwnGame.Backend/Models/SessionState.cs b/MyOwnGame.Backend/Models/SessionState.cs index 92058a8..726f8d0 100644 --- a/MyOwnGame.Backend/Models/SessionState.cs +++ b/MyOwnGame.Backend/Models/SessionState.cs @@ -12,5 +12,7 @@ public enum SessionState Table, + ForwardQuestion, + Pause } \ No newline at end of file diff --git a/MyOwnGame.Backend/Program.cs b/MyOwnGame.Backend/Program.cs index 77d37cd..534f75b 100644 --- a/MyOwnGame.Backend/Program.cs +++ b/MyOwnGame.Backend/Program.cs @@ -71,6 +71,7 @@ public static void Main(string[] args) //Регистрация фоновых задач builder.Services.AddSingleton(); + builder.Services.AddSingleton(); builder.Services.AddSingleton(); diff --git a/MyOwnGame.Backend/Services/SessionCallbackService.cs b/MyOwnGame.Backend/Services/SessionCallbackService.cs index 11e5580..2807597 100644 --- a/MyOwnGame.Backend/Services/SessionCallbackService.cs +++ b/MyOwnGame.Backend/Services/SessionCallbackService.cs @@ -165,10 +165,16 @@ await _hubContext.Clients.Client(player.ConnectionId).SendAsync(SessionEvents.Ne await _hubContext.Clients.Group(player.SessionId.ToString()).SendAsync(SessionEvents.PlayerInstallingQuestionPrice.ToString(), PlayerDto.Create(player)); } - + public async Task QuestionPriceInstalled(long sessionId, Player player, int? score) { await _hubContext.Clients.Group(sessionId.ToString()) .SendAsync(SessionEvents.QuestionPriceInstalled.ToString(), PlayerDto.Create(player), score); } + + public async Task NeedForwardQuestion(string connectionId, long sessionId) + { + await _hubContext.Clients.Client(connectionId).SendAsync(SessionEvents.NeedForwardQuestion.ToString()); + await _hubContext.Clients.Group(sessionId.ToString()).SendAsync(SessionEvents.PlayerChoosesQuestionPlayer.ToString()); + } } \ No newline at end of file diff --git a/MyOwnGame.Backend/Services/SessionService.cs b/MyOwnGame.Backend/Services/SessionService.cs index 686d1d9..ef82307 100644 --- a/MyOwnGame.Backend/Services/SessionService.cs +++ b/MyOwnGame.Backend/Services/SessionService.cs @@ -378,6 +378,21 @@ public async Task GetQuestionInfo(int themeNumber, int priceNumber, string conne return; } + + //Если это кот в мешке, кидаем инфу что надо передать + if (questionInfo.QuestionPackInfo.Type == QuestionPackType.Cat || questionInfo.QuestionPackInfo.Type == QuestionPackType.SuperCat) + { + await _callbackService.QuestionSelectedAdmin(adminConnectionId, questionInfo.Answer); + + await _callbackService.QuestionSelected(currentPlayer.SessionId, new List(), + questionInfo.QuestionPackInfo, -1, themeNumber, priceNumber); + + await _callbackService.NeedForwardQuestion(currentPlayer.ConnectionId, currentPlayer.SessionId); + + session.ChangeStateToForwardQuestion(); + + return; + } } //simple @@ -679,7 +694,7 @@ public async Task RemoveFinalTheme(int position, string connectionId) indexPlayer = 0; } - var nextPlayer = session.Players[indexPlayer]; + var nextPlayer = onlinePlayers[indexPlayer]; session.SetSelectQuestionPlayer(nextPlayer); @@ -803,6 +818,35 @@ await _callbackService.QuestionSelected(questionPlayer.SessionId, questionInfo.Q await _callbackService.NeedSetQuestionPrice(nextPlayer.SessionId, nextPlayer, 0, nextPlayer.Score, 1); } + public async Task ForwardQuestion(string connectionId, int playerId) + { + var player = GetPlayer(connectionId); + + if (player is null) + { + throw new Exception("Бляяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяяя"); + } + + var session = _sessionsManager.GetSessionById(player.SessionId); + + if (session is null) + { + throw new Exception("Сессия не найдена(((("); + } + + var forwardPlayer = GetPlayer(player.SessionId, playerId); + + if (forwardPlayer is null) + { + throw new Exception("Не найден игрок, которому передают вопрос"); + } + + + session.ChangeStateToAnswer(); + + await _callbackService.PlayerAnswer(forwardPlayer.SessionId, player); + } + private (Player Player, QuestionInfo QuestionInfo, Session Session) ValidateAnswerData(string connectionId) { var sessionInfo = _sessionsManager.GetSessionInfoByConnection(connectionId);