1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-17 00:07:41 +02:00

Store and show correct player room limit in UI

This commit is contained in:
Ivan Savenko
2024-03-11 20:03:33 +02:00
parent 715e094f5c
commit 3023db6f0f
11 changed files with 41 additions and 24 deletions

View File

@ -58,11 +58,12 @@ void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyClientConnected(LobbyClientCon
// announce opened game room // announce opened game room
// TODO: find better approach? // TODO: find better approach?
int roomType = settings["lobby"]["roomType"].Integer(); int roomType = settings["lobby"]["roomType"].Integer();
int roomPlayerLimit = settings["lobby"]["roomPlayerLimit"].Integer();
if (roomType != 0) if (roomType != 0)
handler.getGlobalLobby().sendOpenPrivateRoom(); handler.getGlobalLobby().sendOpenRoom("private", roomPlayerLimit);
else else
handler.getGlobalLobby().sendOpenPublicRoom(); handler.getGlobalLobby().sendOpenRoom("public", roomPlayerLimit);
} }
while (!GH.windows().findWindows<GlobalLobbyWindow>().empty()) while (!GH.windows().findWindows<GlobalLobbyWindow>().empty())

View File

@ -184,7 +184,7 @@ void GlobalLobbyClient::receiveActiveGameRooms(const JsonNode & json)
room.hostAccountDisplayName = jsonEntry["hostAccountDisplayName"].String(); room.hostAccountDisplayName = jsonEntry["hostAccountDisplayName"].String();
room.description = jsonEntry["description"].String(); room.description = jsonEntry["description"].String();
room.playersCount = jsonEntry["playersCount"].Integer(); room.playersCount = jsonEntry["playersCount"].Integer();
room.playersLimit = jsonEntry["playersLimit"].Integer(); room.playerLimit = jsonEntry["playerLimit"].Integer();
activeRooms.push_back(room); activeRooms.push_back(room);
} }
@ -284,21 +284,13 @@ void GlobalLobbyClient::sendMessage(const JsonNode & data)
networkConnection->sendPacket(data.toBytes()); networkConnection->sendPacket(data.toBytes());
} }
void GlobalLobbyClient::sendOpenPublicRoom() void GlobalLobbyClient::sendOpenRoom(const std::string & mode, int playerLimit)
{ {
JsonNode toSend; JsonNode toSend;
toSend["type"].String() = "activateGameRoom"; toSend["type"].String() = "activateGameRoom";
toSend["hostAccountID"] = settings["lobby"]["accountID"]; toSend["hostAccountID"] = settings["lobby"]["accountID"];
toSend["roomType"].String() = "public"; toSend["roomType"].String() = mode;
sendMessage(toSend); toSend["playerLimit"].Integer() = playerLimit;
}
void GlobalLobbyClient::sendOpenPrivateRoom()
{
JsonNode toSend;
toSend["type"].String() = "activateGameRoom";
toSend["hostAccountID"] = settings["lobby"]["accountID"];
toSend["roomType"].String() = "private";
sendMessage(toSend); sendMessage(toSend);
} }

View File

@ -60,8 +60,7 @@ public:
void sendMessage(const JsonNode & data); void sendMessage(const JsonNode & data);
void sendClientRegister(const std::string & accountName); void sendClientRegister(const std::string & accountName);
void sendClientLogin(); void sendClientLogin();
void sendOpenPublicRoom(); void sendOpenRoom(const std::string & mode, int playerLimit);
void sendOpenPrivateRoom();
void sendProxyConnectionLogin(const NetworkConnectionPtr & netConnection); void sendProxyConnectionLogin(const NetworkConnectionPtr & netConnection);

View File

@ -23,5 +23,5 @@ struct GlobalLobbyRoom
std::string hostAccountDisplayName; std::string hostAccountDisplayName;
std::string description; std::string description;
int playersCount; int playersCount;
int playersLimit; int playerLimit;
}; };

View File

@ -142,7 +142,7 @@ GlobalLobbyRoomCard::GlobalLobbyRoomCard(GlobalLobbyWindow * window, const Globa
auto roomSizeText = MetaString::createFromRawString("%d/%d"); auto roomSizeText = MetaString::createFromRawString("%d/%d");
roomSizeText.replaceNumber(roomDescription.playersCount); roomSizeText.replaceNumber(roomDescription.playersCount);
roomSizeText.replaceNumber(roomDescription.playersLimit); roomSizeText.replaceNumber(roomDescription.playerLimit);
pos.w = 230; pos.w = 230;
pos.h = 40; pos.h = 40;

View File

@ -22,6 +22,13 @@
"type" : "string", "type" : "string",
"enum" : [ "public", "private" ], "enum" : [ "public", "private" ],
"description" : "Room type to use for activation" "description" : "Room type to use for activation"
} },
"playerLimit" :
{
"type" : "number",
"minimum" : 1,
"maximum" : 8,
"description" : "Maximum number of players that can enter this room"
},
} }
} }

View File

@ -20,7 +20,7 @@
{ {
"type" : "object", "type" : "object",
"additionalProperties" : false, "additionalProperties" : false,
"required" : [ "gameRoomID", "hostAccountID", "hostAccountDisplayName", "description", "playersCount", "playersLimit" ], "required" : [ "gameRoomID", "hostAccountID", "hostAccountDisplayName", "description", "playersCount", "playerLimit" ],
"properties" : { "properties" : {
"gameRoomID" : "gameRoomID" :
{ {
@ -47,9 +47,11 @@
"type" : "number", "type" : "number",
"description" : "Current number of players in this room, including host" "description" : "Current number of players in this room, including host"
}, },
"playersLimit" : "playerLimit" :
{ {
"type" : "number", "type" : "number",
"minimum" : 1,
"maximum" : 8,
"description" : "Maximum number of players that can join this room, including host" "description" : "Maximum number of players that can join this room, including host"
} }
} }

View File

@ -162,6 +162,12 @@ void LobbyDatabase::prepareStatements()
WHERE roomID = ? WHERE roomID = ?
)"; )";
static const std::string updateRoomPlayerLimitText = R"(
UPDATE gameRooms
SET playerLimit = ?
WHERE roomID = ?
)";
// SELECT FROM // SELECT FROM
static const std::string getRecentMessageHistoryText = R"( static const std::string getRecentMessageHistoryText = R"(
@ -278,6 +284,7 @@ void LobbyDatabase::prepareStatements()
setGameRoomStatusStatement = database->prepare(setGameRoomStatusText); setGameRoomStatusStatement = database->prepare(setGameRoomStatusText);
updateAccountLoginTimeStatement = database->prepare(updateAccountLoginTimeText); updateAccountLoginTimeStatement = database->prepare(updateAccountLoginTimeText);
updateRoomDescriptionStatement = database->prepare(updateRoomDescriptionText); updateRoomDescriptionStatement = database->prepare(updateRoomDescriptionText);
updateRoomPlayerLimitStatement = database->prepare(updateRoomPlayerLimitText);
getRecentMessageHistoryStatement = database->prepare(getRecentMessageHistoryText); getRecentMessageHistoryStatement = database->prepare(getRecentMessageHistoryText);
getIdleGameRoomStatement = database->prepare(getIdleGameRoomText); getIdleGameRoomStatement = database->prepare(getIdleGameRoomText);
@ -400,6 +407,11 @@ void LobbyDatabase::updateAccountLoginTime(const std::string & accountID)
updateAccountLoginTimeStatement->executeOnce(accountID); updateAccountLoginTimeStatement->executeOnce(accountID);
} }
void LobbyDatabase::updateRoomPlayerLimit(const std::string & gameRoomID, int playerLimit)
{
updateRoomPlayerLimitStatement->executeOnce(playerLimit, gameRoomID);
}
void LobbyDatabase::updateRoomDescription(const std::string & gameRoomID, const std::string & description) void LobbyDatabase::updateRoomDescription(const std::string & gameRoomID, const std::string & description)
{ {
updateRoomDescriptionStatement->executeOnce(description, gameRoomID); updateRoomDescriptionStatement->executeOnce(description, gameRoomID);
@ -499,7 +511,7 @@ std::vector<LobbyGameRoom> LobbyDatabase::getActiveGameRooms()
while(getActiveGameRoomsStatement->execute()) while(getActiveGameRoomsStatement->execute())
{ {
LobbyGameRoom entry; LobbyGameRoom entry;
getActiveGameRoomsStatement->getColumns(entry.roomID, entry.hostAccountID, entry.hostAccountDisplayName, entry.description, entry.roomStatus, entry.playersLimit); getActiveGameRoomsStatement->getColumns(entry.roomID, entry.hostAccountID, entry.hostAccountDisplayName, entry.description, entry.roomStatus, entry.playerLimit);
result.push_back(entry); result.push_back(entry);
} }
getActiveGameRoomsStatement->reset(); getActiveGameRoomsStatement->reset();

View File

@ -35,6 +35,7 @@ class LobbyDatabase
SQLiteStatementPtr setGameRoomStatusStatement; SQLiteStatementPtr setGameRoomStatusStatement;
SQLiteStatementPtr updateAccountLoginTimeStatement; SQLiteStatementPtr updateAccountLoginTimeStatement;
SQLiteStatementPtr updateRoomDescriptionStatement; SQLiteStatementPtr updateRoomDescriptionStatement;
SQLiteStatementPtr updateRoomPlayerLimitStatement;
SQLiteStatementPtr getRecentMessageHistoryStatement; SQLiteStatementPtr getRecentMessageHistoryStatement;
SQLiteStatementPtr getIdleGameRoomStatement; SQLiteStatementPtr getIdleGameRoomStatement;
@ -76,6 +77,7 @@ public:
void insertChatMessage(const std::string & sender, const std::string & roomType, const std::string & roomID, const std::string & messageText); 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 updateAccountLoginTime(const std::string & accountID);
void updateRoomPlayerLimit(const std::string & gameRoomID, int playerLimit);
void updateRoomDescription(const std::string & gameRoomID, const std::string & description); void updateRoomDescription(const std::string & gameRoomID, const std::string & description);
std::vector<LobbyGameRoom> getActiveGameRooms(); std::vector<LobbyGameRoom> getActiveGameRooms();

View File

@ -23,7 +23,7 @@ struct LobbyGameRoom
std::string description; std::string description;
std::string roomStatus; std::string roomStatus;
uint32_t playersCount; uint32_t playersCount;
uint32_t playersLimit; uint32_t playerLimit;
}; };
struct LobbyChatMessage struct LobbyChatMessage

View File

@ -164,7 +164,7 @@ JsonNode LobbyServer::prepareActiveGameRooms()
jsonEntry["hostAccountDisplayName"].String() = gameRoom.hostAccountDisplayName; jsonEntry["hostAccountDisplayName"].String() = gameRoom.hostAccountDisplayName;
jsonEntry["description"].String() = gameRoom.description; jsonEntry["description"].String() = gameRoom.description;
jsonEntry["playersCount"].Integer() = gameRoom.playersCount; jsonEntry["playersCount"].Integer() = gameRoom.playersCount;
jsonEntry["playersLimit"].Integer() = gameRoom.playersLimit; jsonEntry["playerLimit"].Integer() = gameRoom.playerLimit;
reply["gameRooms"].Vector().push_back(jsonEntry); reply["gameRooms"].Vector().push_back(jsonEntry);
} }
@ -520,6 +520,7 @@ void LobbyServer::receiveActivateGameRoom(const NetworkConnectionPtr & connectio
{ {
std::string hostAccountID = json["hostAccountID"].String(); std::string hostAccountID = json["hostAccountID"].String();
std::string accountID = activeAccounts[connection]; std::string accountID = activeAccounts[connection];
int playerLimit = json["playerLimit"].Integer();
if(database->isPlayerInGameRoom(accountID)) if(database->isPlayerInGameRoom(accountID))
return sendOperationFailed(connection, "Player already in the room!"); return sendOperationFailed(connection, "Player already in the room!");
@ -537,6 +538,7 @@ void LobbyServer::receiveActivateGameRoom(const NetworkConnectionPtr & connectio
if(roomType == "private") if(roomType == "private")
database->setGameRoomStatus(gameRoomID, LobbyRoomState::PRIVATE); database->setGameRoomStatus(gameRoomID, LobbyRoomState::PRIVATE);
database->updateRoomPlayerLimit(gameRoomID, playerLimit);
database->insertPlayerIntoGameRoom(accountID, gameRoomID); database->insertPlayerIntoGameRoom(accountID, gameRoomID);
broadcastActiveGameRooms(); broadcastActiveGameRooms();
sendJoinRoomSuccess(connection, gameRoomID, false); sendJoinRoomSuccess(connection, gameRoomID, false);