mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-26 22:57:00 +02:00
Show number of players in open room
This commit is contained in:
parent
eaca128c99
commit
6d2ca070ea
@ -170,12 +170,18 @@ void LobbyDatabase::prepareStatements()
|
||||
)";
|
||||
|
||||
static const std::string getActiveGameRoomsText = R"(
|
||||
SELECT roomID, hostAccountID, displayName, status, 0, playerLimit
|
||||
SELECT roomID, hostAccountID, displayName, status, playerLimit
|
||||
FROM gameRooms
|
||||
LEFT JOIN accounts ON hostAccountID = accountID
|
||||
WHERE status = 1
|
||||
)";
|
||||
|
||||
static const std::string countAccountsInRoomText = R"(
|
||||
SELECT COUNT(accountID)
|
||||
FROM gameRoomPlayers
|
||||
WHERE roomID = ?
|
||||
)";
|
||||
|
||||
static const std::string getAccountDisplayNameText = R"(
|
||||
SELECT displayName
|
||||
FROM accounts
|
||||
@ -239,6 +245,7 @@ void LobbyDatabase::prepareStatements()
|
||||
getActiveAccountsStatement = database->prepare(getActiveAccountsText);
|
||||
getActiveGameRoomsStatement = database->prepare(getActiveGameRoomsText);
|
||||
getAccountDisplayNameStatement = database->prepare(getAccountDisplayNameText);
|
||||
countAccountsInRoomStatement = database->prepare(countAccountsInRoomText);
|
||||
|
||||
isAccountCookieValidStatement = database->prepare(isAccountCookieValidText);
|
||||
isPlayerInGameRoomStatement = database->prepare(isPlayerInGameRoomText);
|
||||
@ -429,10 +436,18 @@ std::vector<LobbyGameRoom> LobbyDatabase::getActiveGameRooms()
|
||||
while(getActiveGameRoomsStatement->execute())
|
||||
{
|
||||
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);
|
||||
}
|
||||
getActiveGameRoomsStatement->reset();
|
||||
|
||||
for (auto & room : result)
|
||||
{
|
||||
countAccountsInRoomStatement->setBinds(room.roomID);
|
||||
if(countAccountsInRoomStatement->execute())
|
||||
countAccountsInRoomStatement->getColumns(room.playersCount);
|
||||
countAccountsInRoomStatement->reset();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,7 @@ class LobbyDatabase
|
||||
SQLiteStatementPtr getActiveAccountsStatement;
|
||||
SQLiteStatementPtr getAccountGameRoomStatement;
|
||||
SQLiteStatementPtr getAccountDisplayNameStatement;
|
||||
SQLiteStatementPtr countAccountsInRoomStatement;
|
||||
|
||||
SQLiteStatementPtr isAccountCookieValidStatement;
|
||||
SQLiteStatementPtr isGameRoomCookieValidStatement;
|
||||
|
@ -465,6 +465,7 @@ void LobbyServer::receiveOpenGameRoom(const NetworkConnectionPtr & connection, c
|
||||
// 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
|
||||
|
||||
database->insertPlayerIntoGameRoom(accountID, gameRoomID);
|
||||
broadcastActiveGameRooms();
|
||||
sendJoinRoomSuccess(connection, gameRoomID);
|
||||
}
|
||||
@ -493,6 +494,7 @@ void LobbyServer::receiveJoinGameRoom(const NetworkConnectionPtr & connection, c
|
||||
if(database->getGameRoomFreeSlots(gameRoomID) == 0)
|
||||
return;
|
||||
|
||||
database->insertPlayerIntoGameRoom(accountID, gameRoomID);
|
||||
sendAccountJoinsRoom(targetRoom, accountID);
|
||||
//No reply to client - will be sent once match server establishes proxy connection with lobby
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user