1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-17 01:32:21 +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 ORDER BY secondsElapsed ASC
)"); )");
countRoomUsedSlotsStatement = database->prepare(R"( getGameRoomPlayersStatement = database->prepare(R"(
SELECT a.accountID, a.displayName SELECT a.accountID, a.displayName
FROM gameRoomPlayers grp FROM gameRoomPlayers grp
LEFT JOIN accounts a ON a.accountID = grp.accountID LEFT JOIN accounts a ON a.accountID = grp.accountID
WHERE roomID = ? WHERE roomID = ?
)"); )");
countRoomUsedSlotsStatement = database->prepare(R"(
SELECT COUNT(grp.accountID)
FROM gameRoomPlayers grp
WHERE roomID = ?
)");
countRoomTotalSlotsStatement = database->prepare(R"( countRoomTotalSlotsStatement = database->prepare(R"(
SELECT playerLimit SELECT playerLimit
FROM gameRooms FROM gameRooms
@ -566,14 +572,14 @@ std::vector<LobbyGameRoom> LobbyDatabase::getActiveGameRooms()
for (auto & room : result) for (auto & room : result)
{ {
countRoomUsedSlotsStatement->setBinds(room.roomID); getGameRoomPlayersStatement->setBinds(room.roomID);
while(countRoomUsedSlotsStatement->execute()) while(getGameRoomPlayersStatement->execute())
{ {
LobbyAccount account; LobbyAccount account;
countRoomUsedSlotsStatement->getColumns(account.accountID, account.displayName); getGameRoomPlayersStatement->getColumns(account.accountID, account.displayName);
room.participants.push_back(account); room.participants.push_back(account);
} }
countRoomUsedSlotsStatement->reset(); getGameRoomPlayersStatement->reset();
} }
return result; return result;
} }
@ -593,14 +599,14 @@ std::vector<LobbyGameRoom> LobbyDatabase::getAccountGameHistory(const std::strin
for (auto & room : result) for (auto & room : result)
{ {
countRoomUsedSlotsStatement->setBinds(room.roomID); getGameRoomPlayersStatement->setBinds(room.roomID);
while(countRoomUsedSlotsStatement->execute()) while(getGameRoomPlayersStatement->execute())
{ {
LobbyAccount account; LobbyAccount account;
countRoomUsedSlotsStatement->getColumns(account.accountID, account.displayName); getGameRoomPlayersStatement->getColumns(account.accountID, account.displayName);
room.participants.push_back(account); room.participants.push_back(account);
} }
countRoomUsedSlotsStatement->reset(); getGameRoomPlayersStatement->reset();
} }
return result; return result;
} }

View File

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