1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Fixed check for number of players in the room

This commit is contained in:
Ivan Savenko 2024-04-23 19:21:30 +03:00
parent e05a05c455
commit 67cf37b85b
2 changed files with 16 additions and 9 deletions

View File

@ -272,13 +272,19 @@ void LobbyDatabase::prepareStatements()
ORDER BY secondsElapsed ASC
)");
countRoomUsedSlotsStatement = database->prepare(R"(
getGameRoomPlayersStatement = database->prepare(R"(
SELECT a.accountID, a.displayName
FROM gameRoomPlayers grp
LEFT JOIN accounts a ON a.accountID = grp.accountID
WHERE roomID = ?
)");
countRoomUsedSlotsStatement = database->prepare(R"(
SELECT COUNT(grp.accountID)
FROM gameRoomPlayers grp
WHERE roomID = ?
)");
countRoomTotalSlotsStatement = database->prepare(R"(
SELECT playerLimit
FROM gameRooms
@ -566,14 +572,14 @@ std::vector<LobbyGameRoom> LobbyDatabase::getActiveGameRooms()
for (auto & room : result)
{
countRoomUsedSlotsStatement->setBinds(room.roomID);
while(countRoomUsedSlotsStatement->execute())
getGameRoomPlayersStatement->setBinds(room.roomID);
while(getGameRoomPlayersStatement->execute())
{
LobbyAccount account;
countRoomUsedSlotsStatement->getColumns(account.accountID, account.displayName);
getGameRoomPlayersStatement->getColumns(account.accountID, account.displayName);
room.participants.push_back(account);
}
countRoomUsedSlotsStatement->reset();
getGameRoomPlayersStatement->reset();
}
return result;
}
@ -593,14 +599,14 @@ std::vector<LobbyGameRoom> LobbyDatabase::getAccountGameHistory(const std::strin
for (auto & room : result)
{
countRoomUsedSlotsStatement->setBinds(room.roomID);
while(countRoomUsedSlotsStatement->execute())
getGameRoomPlayersStatement->setBinds(room.roomID);
while(getGameRoomPlayersStatement->execute())
{
LobbyAccount account;
countRoomUsedSlotsStatement->getColumns(account.accountID, account.displayName);
getGameRoomPlayersStatement->getColumns(account.accountID, account.displayName);
room.participants.push_back(account);
}
countRoomUsedSlotsStatement->reset();
getGameRoomPlayersStatement->reset();
}
return result;
}

View File

@ -47,6 +47,7 @@ class LobbyDatabase
SQLiteStatementPtr getAccountInviteStatusStatement;
SQLiteStatementPtr getAccountGameRoomStatement;
SQLiteStatementPtr getAccountDisplayNameStatement;
SQLiteStatementPtr getGameRoomPlayersStatement;
SQLiteStatementPtr countRoomUsedSlotsStatement;
SQLiteStatementPtr countRoomTotalSlotsStatement;