1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-21 17:17:06 +02:00

Send list of active invites as part of room description

This commit is contained in:
Ivan Savenko 2024-05-13 11:43:28 +00:00
parent e12db20314
commit a4ea74fbbc
7 changed files with 58 additions and 0 deletions

View File

@ -220,6 +220,15 @@ void GlobalLobbyClient::receiveActiveGameRooms(const JsonNode & json)
account.displayName = jsonParticipant["displayName"].String();
room.participants.push_back(account);
}
for(const auto & jsonParticipant : jsonEntry["invited"].Vector())
{
GlobalLobbyAccount account;
account.accountID = jsonParticipant["accountID"].String();
account.displayName = jsonParticipant["displayName"].String();
room.invited.push_back(account);
}
room.playerLimit = jsonEntry["playerLimit"].Integer();
activeRooms.push_back(room);

View File

@ -29,6 +29,7 @@ struct GlobalLobbyRoom
std::string startDateFormatted;
ModCompatibilityInfo modList;
std::vector<GlobalLobbyAccount> participants;
std::vector<GlobalLobbyAccount> invited;
int playerLimit;
};

View File

@ -65,6 +65,29 @@
}
}
},
"invited" :
{
"type" : "array",
"description" : "List of accounts that were invited to this room",
"items" :
{
"type" : "object",
"additionalProperties" : false,
"required" : [ "accountID", "displayName" ],
"properties" : {
"accountID" :
{
"type" : "string",
"description" : "Unique ID of an account"
},
"displayName" :
{
"type" : "string",
"description" : "Display name of an account"
}
}
}
},
"mods" :
{
"type" : "array",

View File

@ -272,6 +272,13 @@ void LobbyDatabase::prepareStatements()
ORDER BY secondsElapsed ASC
)");
getGameRoomInvitesStatement = database->prepare(R"(
SELECT a.accountID, a.displayName
FROM gameRoomInvites gri
LEFT JOIN accounts a ON a.accountID = gri.accountID
WHERE roomID = ?
)");
getGameRoomPlayersStatement = database->prepare(R"(
SELECT a.accountID, a.displayName
FROM gameRoomPlayers grp
@ -581,6 +588,19 @@ std::vector<LobbyGameRoom> LobbyDatabase::getActiveGameRooms()
}
getGameRoomPlayersStatement->reset();
}
for (auto & room : result)
{
getGameRoomInvitesStatement->setBinds(room.roomID);
while(getGameRoomInvitesStatement->execute())
{
LobbyAccount account;
getGameRoomInvitesStatement->getColumns(account.accountID, account.displayName);
room.invited.push_back(account);
}
getGameRoomInvitesStatement->reset();
}
return result;
}

View File

@ -48,6 +48,7 @@ class LobbyDatabase
SQLiteStatementPtr getAccountGameRoomStatement;
SQLiteStatementPtr getAccountDisplayNameStatement;
SQLiteStatementPtr getGameRoomPlayersStatement;
SQLiteStatementPtr getGameRoomInvitesStatement;
SQLiteStatementPtr countRoomUsedSlotsStatement;
SQLiteStatementPtr countRoomTotalSlotsStatement;

View File

@ -47,6 +47,7 @@ struct LobbyGameRoom
std::string version;
std::string modsJson;
std::vector<LobbyAccount> participants;
std::vector<LobbyAccount> invited;
LobbyRoomState roomState;
uint32_t playerLimit;
std::chrono::seconds age;

View File

@ -218,6 +218,9 @@ static JsonNode loadLobbyGameRoomToJson(const LobbyGameRoom & gameRoom)
for(const auto & account : gameRoom.participants)
jsonEntry["participants"].Vector().push_back(loadLobbyAccountToJson(account));
for(const auto & account : gameRoom.invited)
jsonEntry["invited"].Vector().push_back(loadLobbyAccountToJson(account));
return jsonEntry;
}