Skip to content
This repository has been archived by the owner on Dec 13, 2020. It is now read-only.

Commit

Permalink
Remove player before checking for 0 players
Browse files Browse the repository at this point in the history
This ensures we don't have sessions with 1 player left in the DB
polluting the stats.
  • Loading branch information
L-P committed Jun 1, 2020
1 parent 1c34640 commit 3e5f24c
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions internal/back/back_matchmaking.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,6 @@ func getSessionPlayersSortedByRating(tx *sqlx.Tx, session MatchSession) ([]Playe
func (b *Back) ensureSessionIsValidForMatchMaking(tx *sqlx.Tx, session MatchSession) (MatchSession, bool, error) {
players := session.GetPlayerIDs()

// No players / closed session
if len(players) < 2 || session.Status != MatchSessionStatusPreparing {
log.Printf("debug: not enough players or closed session %s", session.ID)
return MatchSession{}, false, nil
}

// Ditch the one player we can't match with anyone.
// The last player to join gets removed per community request.
// (They did not like the idea of joining early and be kicked randomly 45
Expand All @@ -317,16 +311,23 @@ func (b *Back) ensureSessionIsValidForMatchMaking(tx *sqlx.Tx, session MatchSess
session.RemovePlayerID(toRemove)
player, err := getPlayerByID(tx, util.UUIDAsBlob(toRemove))
if err != nil {
log.Printf("info: removed odd player %s (%s) from session %s", player.ID, player.Name, session.ID.UUID())
return MatchSession{}, false, fmt.Errorf("unable to fetch odd player: %w", err)
}
log.Printf("info: removed odd player %s (%s) from session %s", player.ID, player.Name, session.ID.UUID())

b.sendOddKickNotification(player)
}

if err := session.update(tx); err != nil {
return MatchSession{}, false, err
}

// No players / closed session
if len(players) < 2 || session.Status != MatchSessionStatusPreparing {
log.Printf("debug: not enough players or closed session %s", session.ID)
return MatchSession{}, false, nil
}

return session, true, nil
}

Expand Down

0 comments on commit 3e5f24c

Please sign in to comment.