1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-04-25 12:14:46 +02:00

Show number of players in open room

This commit is contained in:
Ivan Savenko 2024-01-27 23:41:36 +02:00
parent eaca128c99
commit 6d2ca070ea
3 changed files with 20 additions and 2 deletions

View File

@ -170,12 +170,18 @@ void LobbyDatabase::prepareStatements()
)"; )";
static const std::string getActiveGameRoomsText = R"( static const std::string getActiveGameRoomsText = R"(
SELECT roomID, hostAccountID, displayName, status, 0, playerLimit SELECT roomID, hostAccountID, displayName, status, playerLimit
FROM gameRooms FROM gameRooms
LEFT JOIN accounts ON hostAccountID = accountID LEFT JOIN accounts ON hostAccountID = accountID
WHERE status = 1 WHERE status = 1
)"; )";
static const std::string countAccountsInRoomText = R"(
SELECT COUNT(accountID)
FROM gameRoomPlayers
WHERE roomID = ?
)";
static const std::string getAccountDisplayNameText = R"( static const std::string getAccountDisplayNameText = R"(
SELECT displayName SELECT displayName
FROM accounts FROM accounts
@ -239,6 +245,7 @@ void LobbyDatabase::prepareStatements()
getActiveAccountsStatement = database->prepare(getActiveAccountsText); getActiveAccountsStatement = database->prepare(getActiveAccountsText);
getActiveGameRoomsStatement = database->prepare(getActiveGameRoomsText); getActiveGameRoomsStatement = database->prepare(getActiveGameRoomsText);
getAccountDisplayNameStatement = database->prepare(getAccountDisplayNameText); getAccountDisplayNameStatement = database->prepare(getAccountDisplayNameText);
countAccountsInRoomStatement = database->prepare(countAccountsInRoomText);
isAccountCookieValidStatement = database->prepare(isAccountCookieValidText); isAccountCookieValidStatement = database->prepare(isAccountCookieValidText);
isPlayerInGameRoomStatement = database->prepare(isPlayerInGameRoomText); isPlayerInGameRoomStatement = database->prepare(isPlayerInGameRoomText);
@ -429,10 +436,18 @@ std::vector<LobbyGameRoom> LobbyDatabase::getActiveGameRooms()
while(getActiveGameRoomsStatement->execute()) while(getActiveGameRoomsStatement->execute())
{ {
LobbyGameRoom entry; LobbyGameRoom entry;
getActiveGameRoomsStatement->getColumns(entry.roomID, entry.hostAccountID, entry.hostAccountDisplayName, entry.roomStatus, entry.playersCount, entry.playersLimit); getActiveGameRoomsStatement->getColumns(entry.roomID, entry.hostAccountID, entry.hostAccountDisplayName, entry.roomStatus, entry.playersLimit);
result.push_back(entry); result.push_back(entry);
} }
getActiveGameRoomsStatement->reset(); getActiveGameRoomsStatement->reset();
for (auto & room : result)
{
countAccountsInRoomStatement->setBinds(room.roomID);
if(countAccountsInRoomStatement->execute())
countAccountsInRoomStatement->getColumns(room.playersCount);
countAccountsInRoomStatement->reset();
}
return result; return result;
} }

View File

@ -41,6 +41,7 @@ class LobbyDatabase
SQLiteStatementPtr getActiveAccountsStatement; SQLiteStatementPtr getActiveAccountsStatement;
SQLiteStatementPtr getAccountGameRoomStatement; SQLiteStatementPtr getAccountGameRoomStatement;
SQLiteStatementPtr getAccountDisplayNameStatement; SQLiteStatementPtr getAccountDisplayNameStatement;
SQLiteStatementPtr countAccountsInRoomStatement;
SQLiteStatementPtr isAccountCookieValidStatement; SQLiteStatementPtr isAccountCookieValidStatement;
SQLiteStatementPtr isGameRoomCookieValidStatement; SQLiteStatementPtr isGameRoomCookieValidStatement;

View File

@ -465,6 +465,7 @@ void LobbyServer::receiveOpenGameRoom(const NetworkConnectionPtr & connection, c
// TODO: additional flags / initial settings, e.g. allowCheats // TODO: additional flags / initial settings, e.g. allowCheats
// TODO: connection mode: direct or proxy. For now direct is assumed. Proxy might be needed later, for hosted servers // TODO: connection mode: direct or proxy. For now direct is assumed. Proxy might be needed later, for hosted servers
database->insertPlayerIntoGameRoom(accountID, gameRoomID);
broadcastActiveGameRooms(); broadcastActiveGameRooms();
sendJoinRoomSuccess(connection, gameRoomID); sendJoinRoomSuccess(connection, gameRoomID);
} }
@ -493,6 +494,7 @@ void LobbyServer::receiveJoinGameRoom(const NetworkConnectionPtr & connection, c
if(database->getGameRoomFreeSlots(gameRoomID) == 0) if(database->getGameRoomFreeSlots(gameRoomID) == 0)
return; return;
database->insertPlayerIntoGameRoom(accountID, gameRoomID);
sendAccountJoinsRoom(targetRoom, accountID); sendAccountJoinsRoom(targetRoom, accountID);
//No reply to client - will be sent once match server establishes proxy connection with lobby //No reply to client - will be sent once match server establishes proxy connection with lobby