ttt fix, thx aurora

This commit is contained in:
Kwoth 2017-02-12 00:27:52 +01:00
parent c32546d633
commit 3e3c5e75c5

View File

@ -105,36 +105,6 @@ namespace NadekoBot.Modules.Games
_log.Warn($"User {firstUser} created a TicTacToe game."); _log.Warn($"User {firstUser} created a TicTacToe game.");
_phase = Phase.Starting; _phase = Phase.Starting;
moveLock = new SemaphoreSlim(1, 1); 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() public string GetState()
@ -213,8 +183,39 @@ namespace NadekoBot.Modules.Games
_phase = Phase.Started; _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; NadekoBot.Client.MessageReceived += Client_MessageReceived;
previousMessage = await _channel.EmbedAsync(GetEmbed("Game Started")).ConfigureAwait(false); previousMessage = await _channel.EmbedAsync(GetEmbed("Game Started")).ConfigureAwait(false);
} }