瀏覽代碼

Fixed check for number of players in the room

Ivan Savenko 1 年之前
父節點
當前提交
67cf37b85b
共有 2 個文件被更改,包括 16 次插入9 次删除
  1. 15 9
      lobby/LobbyDatabase.cpp
  2. 1 0
      lobby/LobbyDatabase.h

+ 15 - 9
lobby/LobbyDatabase.cpp

@@ -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;
 }

+ 1 - 0
lobby/LobbyDatabase.h

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