Possibly fixed #375 trivia bug

This commit is contained in:
Kwoth
2022-08-06 17:28:31 +02:00
parent 8c51cf8537
commit 71d6eeb9dd

View File

@@ -57,11 +57,14 @@ public sealed class TriviaGame
// loop until game is stopped // loop until game is stopped
// each iteration is one round // each iteration is one round
var firstRun = true; var firstRun = true;
try
{
while (!_isStopped) while (!_isStopped)
{ {
if (errorCount >= 5) if (errorCount >= 5)
{ {
Log.Warning("Trivia errored 5 times and will quit"); Log.Warning("Trivia errored 5 times and will quit");
await OnEnded(this);
break; break;
} }
@@ -77,7 +80,7 @@ public sealed class TriviaGame
var maybeQuestion = await _questionPool.GetQuestionAsync(); var maybeQuestion = await _questionPool.GetQuestionAsync();
if(!(maybeQuestion is TriviaQuestion question)) if (!(maybeQuestion is TriviaQuestion question))
{ {
// if question is null (ran out of question, or other bugg ) - stop // if question is null (ran out of question, or other bugg ) - stop
break; break;
@@ -87,7 +90,8 @@ public sealed class TriviaGame
try try
{ {
// clear out all of the past guesses // clear out all of the past guesses
while (_inputs.Reader.TryRead(out _)) ; while (_inputs.Reader.TryRead(out _))
;
await OnQuestion(this, question); await OnQuestion(this, question);
} }
@@ -169,11 +173,17 @@ public sealed class TriviaGame
} }
} }
} }
}
catch
{
}
finally
{
// make sure game is set as ended // make sure game is set as ended
_isStopped = true; _isStopped = true;
_ = OnEnded(this);
await OnEnded(this); }
} }
public IReadOnlyList<(ulong User, int points)> GetLeaderboard() public IReadOnlyList<(ulong User, int points)> GetLeaderboard()