From 3e3c5e75c58acf643df33705369918f58f762234 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sun, 12 Feb 2017 00:27:52 +0100 Subject: [PATCH] ttt fix, thx aurora --- .../Modules/Games/Commands/TicTacToe.cs | 61 ++++++++++--------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/src/NadekoBot/Modules/Games/Commands/TicTacToe.cs b/src/NadekoBot/Modules/Games/Commands/TicTacToe.cs index 1a254e28..4879793b 100644 --- a/src/NadekoBot/Modules/Games/Commands/TicTacToe.cs +++ b/src/NadekoBot/Modules/Games/Commands/TicTacToe.cs @@ -105,36 +105,6 @@ namespace NadekoBot.Modules.Games _log.Warn($"User {firstUser} created a TicTacToe game."); _phase = Phase.Starting; moveLock = new SemaphoreSlim(1, 1); - - timeoutTimer = new Timer(async (_) => - { - await moveLock.WaitAsync(); - try - { - if (_phase == Phase.Ended) - return; - - _phase = Phase.Ended; - if (_users[1] != null) - { - _winner = _users[curUserIndex ^= 1]; - var del = previousMessage?.DeleteAsync(); - try - { - await _channel.EmbedAsync(GetEmbed("Time Expired!")).ConfigureAwait(false); - await del.ConfigureAwait(false); - } - catch { } - } - - OnEnded?.Invoke(this); - } - catch { } - finally - { - moveLock.Release(); - } - }, null, 15000, Timeout.Infinite); } public string GetState() @@ -213,8 +183,39 @@ namespace NadekoBot.Modules.Games _phase = Phase.Started; + timeoutTimer = new Timer(async (_) => + { + await moveLock.WaitAsync(); + try + { + if (_phase == Phase.Ended) + return; + + _phase = Phase.Ended; + if (_users[1] != null) + { + _winner = _users[curUserIndex ^= 1]; + var del = previousMessage?.DeleteAsync(); + try + { + await _channel.EmbedAsync(GetEmbed("Time Expired!")).ConfigureAwait(false); + await del.ConfigureAwait(false); + } + catch { } + } + + OnEnded?.Invoke(this); + } + catch { } + finally + { + moveLock.Release(); + } + }, null, 15000, Timeout.Infinite); + NadekoBot.Client.MessageReceived += Client_MessageReceived; + previousMessage = await _channel.EmbedAsync(GetEmbed("Game Started")).ConfigureAwait(false); }