Implemented room description display (map/template name)

This commit is contained in:
Ivan Savenko
2024-03-27 13:10:55 +02:00
parent 69236b73ca
commit 715e094f5c
10 changed files with 73 additions and 11 deletions
+15 -2
View File
@@ -29,6 +29,7 @@ void LobbyDatabase::createTables()
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
roomID TEXT,
hostAccountID TEXT,
description TEXT NOT NULL DEFAULT '',
status INTEGER NOT NULL DEFAULT 0,
playerLimit INTEGER NOT NULL,
creationTime TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL
@@ -155,6 +156,12 @@ void LobbyDatabase::prepareStatements()
WHERE accountID = ?
)";
static const std::string updateRoomDescriptionText = R"(
UPDATE gameRooms
SET description = ?
WHERE roomID = ?
)";
// SELECT FROM
static const std::string getRecentMessageHistoryText = R"(
@@ -194,7 +201,7 @@ void LobbyDatabase::prepareStatements()
)";
static const std::string getActiveGameRoomsText = R"(
SELECT roomID, hostAccountID, displayName, status, playerLimit
SELECT roomID, hostAccountID, displayName, description, status, playerLimit
FROM gameRooms
LEFT JOIN accounts ON hostAccountID = accountID
WHERE status = 1
@@ -270,6 +277,7 @@ void LobbyDatabase::prepareStatements()
setAccountOnlineStatement = database->prepare(setAccountOnlineText);
setGameRoomStatusStatement = database->prepare(setGameRoomStatusText);
updateAccountLoginTimeStatement = database->prepare(updateAccountLoginTimeText);
updateRoomDescriptionStatement = database->prepare(updateRoomDescriptionText);
getRecentMessageHistoryStatement = database->prepare(getRecentMessageHistoryText);
getIdleGameRoomStatement = database->prepare(getIdleGameRoomText);
@@ -392,6 +400,11 @@ void LobbyDatabase::updateAccountLoginTime(const std::string & accountID)
updateAccountLoginTimeStatement->executeOnce(accountID);
}
void LobbyDatabase::updateRoomDescription(const std::string & gameRoomID, const std::string & description)
{
updateRoomDescriptionStatement->executeOnce(description, gameRoomID);
}
std::string LobbyDatabase::getAccountDisplayName(const std::string & accountID)
{
std::string result;
@@ -486,7 +499,7 @@ std::vector<LobbyGameRoom> LobbyDatabase::getActiveGameRooms()
while(getActiveGameRoomsStatement->execute())
{
LobbyGameRoom entry;
getActiveGameRoomsStatement->getColumns(entry.roomID, entry.hostAccountID, entry.hostAccountDisplayName, entry.roomStatus, entry.playersLimit);
getActiveGameRoomsStatement->getColumns(entry.roomID, entry.hostAccountID, entry.hostAccountDisplayName, entry.description, entry.roomStatus, entry.playersLimit);
result.push_back(entry);
}
getActiveGameRoomsStatement->reset();
+2
View File
@@ -34,6 +34,7 @@ class LobbyDatabase
SQLiteStatementPtr setAccountOnlineStatement;
SQLiteStatementPtr setGameRoomStatusStatement;
SQLiteStatementPtr updateAccountLoginTimeStatement;
SQLiteStatementPtr updateRoomDescriptionStatement;
SQLiteStatementPtr getRecentMessageHistoryStatement;
SQLiteStatementPtr getIdleGameRoomStatement;
@@ -75,6 +76,7 @@ public:
void insertChatMessage(const std::string & sender, const std::string & roomType, const std::string & roomID, const std::string & messageText);
void updateAccountLoginTime(const std::string & accountID);
void updateRoomDescription(const std::string & gameRoomID, const std::string & description);
std::vector<LobbyGameRoom> getActiveGameRooms();
std::vector<LobbyAccount> getActiveAccounts();
+1
View File
@@ -20,6 +20,7 @@ struct LobbyGameRoom
std::string roomID;
std::string hostAccountID;
std::string hostAccountDisplayName;
std::string description;
std::string roomStatus;
uint32_t playersCount;
uint32_t playersLimit;
+13 -1
View File
@@ -162,7 +162,7 @@ JsonNode LobbyServer::prepareActiveGameRooms()
jsonEntry["gameRoomID"].String() = gameRoom.roomID;
jsonEntry["hostAccountID"].String() = gameRoom.hostAccountID;
jsonEntry["hostAccountDisplayName"].String() = gameRoom.hostAccountDisplayName;
jsonEntry["description"].String() = "TODO: ROOM DESCRIPTION";
jsonEntry["description"].String() = gameRoom.description;
jsonEntry["playersCount"].Integer() = gameRoom.playersCount;
jsonEntry["playersLimit"].Integer() = gameRoom.playersLimit;
reply["gameRooms"].Vector().push_back(jsonEntry);
@@ -329,6 +329,9 @@ void LobbyServer::onPacketReceived(const NetworkConnectionPtr & connection, cons
std::string roomName = activeGameRooms.at(connection);
logGlobal->info("%s: Received message of type %s", roomName, messageType);
if(messageType == "changeRoomDescription")
return receiveChangeRoomDescription(connection, json);
if(messageType == "leaveGameRoom")
return receiveLeaveGameRoom(connection, json);
@@ -573,6 +576,15 @@ void LobbyServer::receiveJoinGameRoom(const NetworkConnectionPtr & connection, c
broadcastActiveGameRooms();
}
void LobbyServer::receiveChangeRoomDescription(const NetworkConnectionPtr & connection, const JsonNode & json)
{
std::string gameRoomID = activeGameRooms[connection];
std::string description = json["description"].String();
database->updateRoomDescription(gameRoomID, description);
broadcastActiveGameRooms();
}
void LobbyServer::receiveLeaveGameRoom(const NetworkConnectionPtr & connection, const JsonNode & json)
{
std::string accountID = json["accountID"].String();
+1
View File
@@ -85,6 +85,7 @@ class LobbyServer final : public INetworkServerListener
void receiveActivateGameRoom(const NetworkConnectionPtr & connection, const JsonNode & json);
void receiveJoinGameRoom(const NetworkConnectionPtr & connection, const JsonNode & json);
void receiveLeaveGameRoom(const NetworkConnectionPtr & connection, const JsonNode & json);
void receiveChangeRoomDescription(const NetworkConnectionPtr & connection, const JsonNode & json);
void receiveSendInvite(const NetworkConnectionPtr & connection, const JsonNode & json);
void receiveDeclineInvite(const NetworkConnectionPtr & connection, const JsonNode & json);