Skip to content

Commit

Permalink
fix game cancellation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ctizen committed Oct 19, 2024
1 parent d92e410 commit e374454
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Mimir/src/helpers/SessionState.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ public static function fromJson(\Common\Ruleset $rules, array $playersIds, strin
$instance = new self($rules, $playersIds);

foreach ($ret as $key => $value) {
if ($key === '_isFinished') { // deprecated field, left for compatibility
continue;
}
$instance->$key = $value;
}

Expand Down
2 changes: 1 addition & 1 deletion Mimir/src/models/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function getTablesState($eventId, $omitLastRound = false)
SessionPrimitive::STATUS_FINISHED,
SessionPrimitive::STATUS_INPROGRESS,
SessionPrimitive::STATUS_PREFINISHED
], 0, intval($tablesCount));
], 0, intval($tablesCount), 'end_date');
return $this->_formatTablesState($lastGames, $reggedPlayers, $omitLastRound);
}

Expand Down
2 changes: 1 addition & 1 deletion Mimir/src/primitives/PlayerHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ public function getAvgPlace()

/**
* @param float $startRating
* @param int $penaltyAmount
* @param float $penaltyAmount
* @return float
*/
public function getAvgScore(float $startRating, $penaltyAmount)
Expand Down
8 changes: 7 additions & 1 deletion Mimir/src/primitives/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -1032,14 +1032,20 @@ public function rollback(RoundPrimitive $round): void

/**
* Check if current session is chronologically last for all its players.
* Exclude cancelled games, as they're not counted
* @return bool
* @throws \Exception
*/
public function isLastForPlayers()
{
$last = $this->_ds->table(self::REL_USER)
->join(
self::$_table,
self::$_table . '.id = ' . self::REL_USER . '.session_id ' .
'AND ' . self::$_table . ".status != 'cancelled'"
)
->whereIn('player_id', $this->getPlayersIds())
->orderByDesc('id')
->orderByDesc(self::REL_USER . '.id')
->limit(4)
->findArray();

Expand Down

0 comments on commit e374454

Please sign in to comment.