From 47125ed6874f64506f0a7ac1f7d51fa361316979 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Fri, 4 Aug 2017 18:12:26 +0200 Subject: [PATCH] connect4 bugfixes --- src/NadekoBot/Modules/Games/Common/Connect4/Connect4.cs | 8 ++++++++ src/NadekoBot/Modules/Games/Connect4Commands.cs | 4 ++++ src/NadekoBot/Modules/Utility/StreamRoleCommands.cs | 1 - 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/NadekoBot/Modules/Games/Common/Connect4/Connect4.cs b/src/NadekoBot/Modules/Games/Common/Connect4/Connect4.cs index 0b247301..c892d7e0 100644 --- a/src/NadekoBot/Modules/Games/Common/Connect4/Connect4.cs +++ b/src/NadekoBot/Modules/Games/Common/Connect4/Connect4.cs @@ -85,6 +85,8 @@ namespace NadekoBot.Modules.Games.Common.Connect4 public void Initialize() { + if (CurrentPhase != Phase.Joining) + return; var _ = Task.Run(async () => { await Task.Delay(15000).ConfigureAwait(false); @@ -267,6 +269,7 @@ namespace NadekoBot.Modules.Games.Common.Connect4 if (same == 4) { + Console.WriteLine($"Won top left diagonal starting from {row + col * NumberOfRows}"); EndGame(Result.CurrentPlayerWon); break; } @@ -292,6 +295,7 @@ namespace NadekoBot.Modules.Games.Common.Connect4 if (same == 4) { + Console.WriteLine($"Won top right diagonal starting from {row + col * NumberOfRows}"); EndGame(Result.CurrentPlayerWon); break; } @@ -327,6 +331,8 @@ namespace NadekoBot.Modules.Games.Common.Connect4 private void EndGame(Result result) { + if (CurrentPhase == Phase.Ended) + return; var _ = OnGameEnded?.Invoke(this, result); CurrentPhase = Phase.Ended; } @@ -351,6 +357,8 @@ namespace NadekoBot.Modules.Games.Common.Connect4 { OnGameFailedToStart = null; OnGameStateUpdated = null; + OnGameEnded = null; + _playerTimeoutTimer?.Change(Timeout.Infinite, Timeout.Infinite); } } } diff --git a/src/NadekoBot/Modules/Games/Connect4Commands.cs b/src/NadekoBot/Modules/Games/Connect4Commands.cs index 81d03b4f..5a1183c2 100644 --- a/src/NadekoBot/Modules/Games/Connect4Commands.cs +++ b/src/NadekoBot/Modules/Games/Connect4Commands.cs @@ -34,6 +34,10 @@ namespace NadekoBot.Modules.Games Connect4Game game; if ((game = Games.GetOrAdd(Context.Channel.Id, newGame)) != newGame) { + if (game.CurrentPhase != Connect4Game.Phase.Joining) + return; + + newGame.Dispose(); //means game already exists, try to join var joined = await game.Join(Context.User.Id, Context.User.ToString()).ConfigureAwait(false); return; diff --git a/src/NadekoBot/Modules/Utility/StreamRoleCommands.cs b/src/NadekoBot/Modules/Utility/StreamRoleCommands.cs index 7749fbca..e6f38947 100644 --- a/src/NadekoBot/Modules/Utility/StreamRoleCommands.cs +++ b/src/NadekoBot/Modules/Utility/StreamRoleCommands.cs @@ -11,7 +11,6 @@ namespace NadekoBot.Modules.Utility { public partial class Utility { - [NoPublicBot] public class StreamRoleCommands : NadekoSubmodule { [NadekoCommand, Usage, Description, Aliases]