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

Implemented room description display (map/template name)

This commit is contained in:
Ivan Savenko
2024-03-11 19:47:35 +02:00
parent 69236b73ca
commit 715e094f5c
10 changed files with 73 additions and 11 deletions

View File

@ -149,7 +149,7 @@ GlobalLobbyRoomCard::GlobalLobbyRoomCard(GlobalLobbyWindow * window, const Globa
backgroundOverlay = std::make_shared<TransparentFilledRectangle>(Rect(0, 0, pos.w, pos.h), ColorRGBA(0, 0, 0, 128), ColorRGBA(64, 64, 64, 64)); backgroundOverlay = std::make_shared<TransparentFilledRectangle>(Rect(0, 0, pos.w, pos.h), ColorRGBA(0, 0, 0, 128), ColorRGBA(64, 64, 64, 64));
labelName = std::make_shared<CLabel>(5, 2, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, roomDescription.hostAccountDisplayName); labelName = std::make_shared<CLabel>(5, 2, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, roomDescription.hostAccountDisplayName);
labelStatus = std::make_shared<CLabel>(5, 20, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::YELLOW, roomDescription.description); labelDescription = std::make_shared<CLabel>(5, 20, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::YELLOW, roomDescription.description);
labelRoomSize = std::make_shared<CLabel>(160, 2, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::YELLOW, roomSizeText.toString()); labelRoomSize = std::make_shared<CLabel>(160, 2, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::YELLOW, roomSizeText.toString());
iconRoomSize = std::make_shared<CPicture>(ImagePath::builtin("lobby/iconPlayer"), Point(145, 5)); iconRoomSize = std::make_shared<CPicture>(ImagePath::builtin("lobby/iconPlayer"), Point(145, 5));

View File

@ -52,7 +52,7 @@ public:
std::shared_ptr<TransparentFilledRectangle> backgroundOverlay; std::shared_ptr<TransparentFilledRectangle> backgroundOverlay;
std::shared_ptr<CLabel> labelName; std::shared_ptr<CLabel> labelName;
std::shared_ptr<CLabel> labelRoomSize; std::shared_ptr<CLabel> labelRoomSize;
std::shared_ptr<CLabel> labelStatus; std::shared_ptr<CLabel> labelDescription;
std::shared_ptr<CButton> buttonJoin; std::shared_ptr<CButton> buttonJoin;
std::shared_ptr<CPicture> iconRoomSize; std::shared_ptr<CPicture> iconRoomSize;
}; };

View File

@ -29,6 +29,7 @@ void LobbyDatabase::createTables()
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
roomID TEXT, roomID TEXT,
hostAccountID TEXT, hostAccountID TEXT,
description TEXT NOT NULL DEFAULT '',
status INTEGER NOT NULL DEFAULT 0, status INTEGER NOT NULL DEFAULT 0,
playerLimit INTEGER NOT NULL, playerLimit INTEGER NOT NULL,
creationTime TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL creationTime TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL
@ -155,6 +156,12 @@ void LobbyDatabase::prepareStatements()
WHERE accountID = ? WHERE accountID = ?
)"; )";
static const std::string updateRoomDescriptionText = R"(
UPDATE gameRooms
SET description = ?
WHERE roomID = ?
)";
// SELECT FROM // SELECT FROM
static const std::string getRecentMessageHistoryText = R"( static const std::string getRecentMessageHistoryText = R"(
@ -194,7 +201,7 @@ void LobbyDatabase::prepareStatements()
)"; )";
static const std::string getActiveGameRoomsText = R"( static const std::string getActiveGameRoomsText = R"(
SELECT roomID, hostAccountID, displayName, status, playerLimit SELECT roomID, hostAccountID, displayName, description, status, playerLimit
FROM gameRooms FROM gameRooms
LEFT JOIN accounts ON hostAccountID = accountID LEFT JOIN accounts ON hostAccountID = accountID
WHERE status = 1 WHERE status = 1
@ -270,6 +277,7 @@ void LobbyDatabase::prepareStatements()
setAccountOnlineStatement = database->prepare(setAccountOnlineText); setAccountOnlineStatement = database->prepare(setAccountOnlineText);
setGameRoomStatusStatement = database->prepare(setGameRoomStatusText); setGameRoomStatusStatement = database->prepare(setGameRoomStatusText);
updateAccountLoginTimeStatement = database->prepare(updateAccountLoginTimeText); updateAccountLoginTimeStatement = database->prepare(updateAccountLoginTimeText);
updateRoomDescriptionStatement = database->prepare(updateRoomDescriptionText);
getRecentMessageHistoryStatement = database->prepare(getRecentMessageHistoryText); getRecentMessageHistoryStatement = database->prepare(getRecentMessageHistoryText);
getIdleGameRoomStatement = database->prepare(getIdleGameRoomText); getIdleGameRoomStatement = database->prepare(getIdleGameRoomText);
@ -392,6 +400,11 @@ void LobbyDatabase::updateAccountLoginTime(const std::string & accountID)
updateAccountLoginTimeStatement->executeOnce(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 LobbyDatabase::getAccountDisplayName(const std::string & accountID)
{ {
std::string result; std::string result;
@ -486,7 +499,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.roomStatus, entry.playersLimit); getActiveGameRoomsStatement->getColumns(entry.roomID, entry.hostAccountID, entry.hostAccountDisplayName, entry.description, entry.roomStatus, entry.playersLimit);
result.push_back(entry); result.push_back(entry);
} }
getActiveGameRoomsStatement->reset(); getActiveGameRoomsStatement->reset();

View File

@ -34,6 +34,7 @@ class LobbyDatabase
SQLiteStatementPtr setAccountOnlineStatement; SQLiteStatementPtr setAccountOnlineStatement;
SQLiteStatementPtr setGameRoomStatusStatement; SQLiteStatementPtr setGameRoomStatusStatement;
SQLiteStatementPtr updateAccountLoginTimeStatement; SQLiteStatementPtr updateAccountLoginTimeStatement;
SQLiteStatementPtr updateRoomDescriptionStatement;
SQLiteStatementPtr getRecentMessageHistoryStatement; SQLiteStatementPtr getRecentMessageHistoryStatement;
SQLiteStatementPtr getIdleGameRoomStatement; 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 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 updateRoomDescription(const std::string & gameRoomID, const std::string & description);
std::vector<LobbyGameRoom> getActiveGameRooms(); std::vector<LobbyGameRoom> getActiveGameRooms();
std::vector<LobbyAccount> getActiveAccounts(); std::vector<LobbyAccount> getActiveAccounts();

View File

@ -20,6 +20,7 @@ struct LobbyGameRoom
std::string roomID; std::string roomID;
std::string hostAccountID; std::string hostAccountID;
std::string hostAccountDisplayName; std::string hostAccountDisplayName;
std::string description;
std::string roomStatus; std::string roomStatus;
uint32_t playersCount; uint32_t playersCount;
uint32_t playersLimit; uint32_t playersLimit;

View File

@ -162,7 +162,7 @@ JsonNode LobbyServer::prepareActiveGameRooms()
jsonEntry["gameRoomID"].String() = gameRoom.roomID; jsonEntry["gameRoomID"].String() = gameRoom.roomID;
jsonEntry["hostAccountID"].String() = gameRoom.hostAccountID; jsonEntry["hostAccountID"].String() = gameRoom.hostAccountID;
jsonEntry["hostAccountDisplayName"].String() = gameRoom.hostAccountDisplayName; jsonEntry["hostAccountDisplayName"].String() = gameRoom.hostAccountDisplayName;
jsonEntry["description"].String() = "TODO: ROOM DESCRIPTION"; jsonEntry["description"].String() = gameRoom.description;
jsonEntry["playersCount"].Integer() = gameRoom.playersCount; jsonEntry["playersCount"].Integer() = gameRoom.playersCount;
jsonEntry["playersLimit"].Integer() = gameRoom.playersLimit; jsonEntry["playersLimit"].Integer() = gameRoom.playersLimit;
reply["gameRooms"].Vector().push_back(jsonEntry); reply["gameRooms"].Vector().push_back(jsonEntry);
@ -329,6 +329,9 @@ void LobbyServer::onPacketReceived(const NetworkConnectionPtr & connection, cons
std::string roomName = activeGameRooms.at(connection); std::string roomName = activeGameRooms.at(connection);
logGlobal->info("%s: Received message of type %s", roomName, messageType); logGlobal->info("%s: Received message of type %s", roomName, messageType);
if(messageType == "changeRoomDescription")
return receiveChangeRoomDescription(connection, json);
if(messageType == "leaveGameRoom") if(messageType == "leaveGameRoom")
return receiveLeaveGameRoom(connection, json); return receiveLeaveGameRoom(connection, json);
@ -573,6 +576,15 @@ void LobbyServer::receiveJoinGameRoom(const NetworkConnectionPtr & connection, c
broadcastActiveGameRooms(); 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) void LobbyServer::receiveLeaveGameRoom(const NetworkConnectionPtr & connection, const JsonNode & json)
{ {
std::string accountID = json["accountID"].String(); std::string accountID = json["accountID"].String();

View File

@ -85,6 +85,7 @@ class LobbyServer final : public INetworkServerListener
void receiveActivateGameRoom(const NetworkConnectionPtr & connection, const JsonNode & json); void receiveActivateGameRoom(const NetworkConnectionPtr & connection, const JsonNode & json);
void receiveJoinGameRoom(const NetworkConnectionPtr & connection, const JsonNode & json); void receiveJoinGameRoom(const NetworkConnectionPtr & connection, const JsonNode & json);
void receiveLeaveGameRoom(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 receiveSendInvite(const NetworkConnectionPtr & connection, const JsonNode & json);
void receiveDeclineInvite(const NetworkConnectionPtr & connection, const JsonNode & json); void receiveDeclineInvite(const NetworkConnectionPtr & connection, const JsonNode & json);

View File

@ -595,6 +595,24 @@ void CVCMIServer::updateStartInfoOnMapChange(std::shared_ptr<CMapInfo> mapInfo,
else else
si->mapGenOptions.reset(); si->mapGenOptions.reset();
} }
if (lobbyProcessor)
{
std::string roomDescription;
if (si->mapGenOptions)
{
if (si->mapGenOptions->getMapTemplate())
roomDescription = si->mapGenOptions->getMapTemplate()->getName();
// else - no template selected.
// TODO: handle this somehow?
}
else
roomDescription = mi->getNameTranslated();
lobbyProcessor->sendChangeRoomDescription(roomDescription);
}
si->mapname = mi->fileURI; si->mapname = mi->fileURI;
} }

View File

@ -47,8 +47,7 @@ void GlobalLobbyProcessor::onDisconnected(const std::shared_ptr<INetworkConnecti
message["type"].String() = "leaveGameRoom"; message["type"].String() = "leaveGameRoom";
message["accountID"].String() = proxy.first; message["accountID"].String() = proxy.first;
assert(JsonUtils::validate(message, "vcmi:lobbyProtocol/" + message["type"].String(), message["type"].String() + " pack")); sendMessage(controlConnection, message);
controlConnection->sendPacket(message.toBytes());
break; break;
} }
} }
@ -127,8 +126,7 @@ void GlobalLobbyProcessor::onConnectionEstablished(const std::shared_ptr<INetwor
toSend["accountCookie"] = settings["lobby"]["accountCookie"]; toSend["accountCookie"] = settings["lobby"]["accountCookie"];
toSend["version"].String() = VCMI_VERSION_STRING; toSend["version"].String() = VCMI_VERSION_STRING;
assert(JsonUtils::validate(toSend, "vcmi:lobbyProtocol/" + toSend["type"].String(), toSend["type"].String() + " pack")); sendMessage(connection, toSend);
connection->sendPacket(toSend.toBytes());
} }
else else
{ {
@ -144,10 +142,24 @@ void GlobalLobbyProcessor::onConnectionEstablished(const std::shared_ptr<INetwor
toSend["guestAccountID"].String() = guestAccountID; toSend["guestAccountID"].String() = guestAccountID;
toSend["accountCookie"] = settings["lobby"]["accountCookie"]; toSend["accountCookie"] = settings["lobby"]["accountCookie"];
assert(JsonUtils::validate(toSend, "vcmi:lobbyProtocol/" + toSend["type"].String(), toSend["type"].String() + " pack")); sendMessage(connection, toSend);
connection->sendPacket(toSend.toBytes());
proxyConnections[guestAccountID] = connection; proxyConnections[guestAccountID] = connection;
owner.onNewConnection(connection); owner.onNewConnection(connection);
} }
} }
void GlobalLobbyProcessor::sendChangeRoomDescription(const std::string & description)
{
JsonNode toSend;
toSend["type"].String() = "changeRoomDescription";
toSend["description"].String() = description;
sendMessage(controlConnection, toSend);
}
void GlobalLobbyProcessor::sendMessage(const NetworkConnectionPtr & targetConnection, const JsonNode & toSend)
{
assert(JsonUtils::validate(toSend, "vcmi:lobbyProtocol/" + toSend["type"].String(), toSend["type"].String() + " pack"));
targetConnection->sendPacket(toSend.toBytes());
}

View File

@ -34,6 +34,9 @@ class GlobalLobbyProcessor : public INetworkClientListener
void receiveAccountJoinsRoom(const JsonNode & json); void receiveAccountJoinsRoom(const JsonNode & json);
void establishNewConnection(); void establishNewConnection();
void sendMessage(const NetworkConnectionPtr & targetConnection, const JsonNode & payload);
public: public:
void sendChangeRoomDescription(const std::string & description);
explicit GlobalLobbyProcessor(CVCMIServer & owner); explicit GlobalLobbyProcessor(CVCMIServer & owner);
}; };