1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Set room status to "In Game" once gameplay starts

This commit is contained in:
Ivan Savenko 2024-03-12 20:53:39 +02:00
parent 7c9aa9d953
commit 5d188024db
9 changed files with 33 additions and 16 deletions

View File

@ -79,7 +79,7 @@
"vcmi.lobby.login.create" : "New Account", "vcmi.lobby.login.create" : "New Account",
"vcmi.lobby.login.login" : "Login", "vcmi.lobby.login.login" : "Login",
"vcmi.lobby.room.create" : "Create Room", "vcmi.lobby.room.create" : "Create New Room",
"vcmi.lobby.room.players.limit" : "Players Limit", "vcmi.lobby.room.players.limit" : "Players Limit",
"vcmi.lobby.room.public" : "Public", "vcmi.lobby.room.public" : "Public",
"vcmi.lobby.room.private" : "Private", "vcmi.lobby.room.private" : "Private",
@ -94,7 +94,7 @@
"vcmi.lobby.room.mode" : "Game Mode", "vcmi.lobby.room.mode" : "Game Mode",
"vcmi.lobby.room.state.public" : "Public", "vcmi.lobby.room.state.public" : "Public",
"vcmi.lobby.room.state.private" : "Private", "vcmi.lobby.room.state.private" : "Private",
"vcmi.lobby.room.state.busy" : "Busy", // Alternative translations: in game / playing "vcmi.lobby.room.state.busy" : "In Game",
"vcmi.client.errors.invalidMap" : "{Invalid map or campaign}\n\nFailed to start game! Selected map or campaign might be invalid or corrupted. Reason:\n%s", "vcmi.client.errors.invalidMap" : "{Invalid map or campaign}\n\nFailed to start game! Selected map or campaign might be invalid or corrupted. Reason:\n%s",
"vcmi.client.errors.missingCampaigns" : "{Missing data files}\n\nCampaigns data files were not found! You may be using incomplete or corrupted Heroes 3 data files. Please reinstall game data.", "vcmi.client.errors.missingCampaigns" : "{Missing data files}\n\nCampaigns data files were not found! You may be using incomplete or corrupted Heroes 3 data files. Please reinstall game data.",

View File

@ -115,20 +115,12 @@ GlobalLobbyAccountCard::GlobalLobbyAccountCard(GlobalLobbyWindow * window, const
{ {
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE; OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
//const auto & onInviteClicked = [window, accountID=accountDescription.accountID]()
//{
// window->doInviteAccount(accountID);
//};
pos.w = 130; pos.w = 130;
pos.h = 40; pos.h = 40;
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, accountDescription.displayName); labelName = std::make_shared<CLabel>(5, 2, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::WHITE, accountDescription.displayName);
labelStatus = std::make_shared<CLabel>(5, 20, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::YELLOW, accountDescription.status); labelStatus = std::make_shared<CLabel>(5, 20, FONT_SMALL, ETextAlignment::TOPLEFT, Colors::YELLOW, accountDescription.status);
//if (CSH->inLobbyRoom())
// buttonInvite = std::make_shared<CButton>(Point(95, 8), AnimationPath::builtin("settingsWindow/button32"), CButton::tooltip(), onInviteClicked);
} }
GlobalLobbyRoomCard::GlobalLobbyRoomCard(GlobalLobbyWindow * window, const GlobalLobbyRoom & roomDescription) GlobalLobbyRoomCard::GlobalLobbyRoomCard(GlobalLobbyWindow * window, const GlobalLobbyRoom & roomDescription)

View File

@ -166,7 +166,7 @@
"font": "medium", "font": "medium",
"alignment": "center", "alignment": "center",
"color": "yellow", "color": "yellow",
"text": "Back" "text": "core.help.561.hover" // Back
} }
] ]
}, },
@ -200,7 +200,7 @@
"font": "medium", "font": "medium",
"alignment": "center", "alignment": "center",
"color": "yellow", "color": "yellow",
"text": "Create New Room" "text": "vcmi.lobby.room.create"
} }
] ]
}, },

View File

@ -196,7 +196,7 @@ void LobbyDatabase::prepareStatements()
SELECT grp.roomID SELECT grp.roomID
FROM gameRoomPlayers grp FROM gameRoomPlayers grp
LEFT JOIN gameRooms gr ON gr.roomID = grp.roomID LEFT JOIN gameRooms gr ON gr.roomID = grp.roomID
WHERE accountID = ? AND status IN (1, 2) WHERE accountID = ? AND status IN (1, 2, 3)
LIMIT 1 LIMIT 1
)"; )";
@ -210,7 +210,7 @@ void LobbyDatabase::prepareStatements()
SELECT roomID, hostAccountID, displayName, description, 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 IN (1, 2) WHERE status IN (1, 2, 3)
)"; )";
static const std::string countRoomUsedSlotsText = R"( static const std::string countRoomUsedSlotsText = R"(
@ -248,14 +248,14 @@ void LobbyDatabase::prepareStatements()
SELECT COUNT(accountID) SELECT COUNT(accountID)
FROM gameRoomPlayers grp FROM gameRoomPlayers grp
LEFT JOIN gameRooms gr ON gr.roomID = grp.roomID LEFT JOIN gameRooms gr ON gr.roomID = grp.roomID
WHERE accountID = ? AND grp.roomID = ? AND status IN (1, 2) WHERE accountID = ? AND grp.roomID = ? AND status IN (1, 2, 3)
)"; )";
static const std::string isPlayerInAnyGameRoomText = R"( static const std::string isPlayerInAnyGameRoomText = R"(
SELECT COUNT(accountID) SELECT COUNT(accountID)
FROM gameRoomPlayers grp FROM gameRoomPlayers grp
LEFT JOIN gameRooms gr ON gr.roomID = grp.roomID LEFT JOIN gameRooms gr ON gr.roomID = grp.roomID
WHERE accountID = ? AND status IN (1, 2) WHERE accountID = ? AND status IN (1, 2, 3)
)"; )";
static const std::string isAccountIDExistsText = R"( static const std::string isAccountIDExistsText = R"(

View File

@ -60,6 +60,8 @@ NetworkConnectionPtr LobbyServer::findGameRoom(const std::string & gameRoomID) c
void LobbyServer::sendMessage(const NetworkConnectionPtr & target, const JsonNode & json) void LobbyServer::sendMessage(const NetworkConnectionPtr & target, const JsonNode & json)
{ {
logGlobal->info("Sending message of type %s", json["type"].String());
assert(JsonUtils::validate(json, "vcmi:lobbyProtocol/" + json["type"].String(), json["type"].String() + " pack")); assert(JsonUtils::validate(json, "vcmi:lobbyProtocol/" + json["type"].String(), json["type"].String() + " pack"));
target->sendPacket(json.toBytes()); target->sendPacket(json.toBytes());
} }
@ -342,6 +344,9 @@ void LobbyServer::onPacketReceived(const NetworkConnectionPtr & connection, cons
if(messageType == "changeRoomDescription") if(messageType == "changeRoomDescription")
return receiveChangeRoomDescription(connection, json); return receiveChangeRoomDescription(connection, json);
if(messageType == "gameStarted")
return receiveGameStarted(connection, json);
if(messageType == "leaveGameRoom") if(messageType == "leaveGameRoom")
return receiveLeaveGameRoom(connection, json); return receiveLeaveGameRoom(connection, json);
@ -597,6 +602,14 @@ void LobbyServer::receiveChangeRoomDescription(const NetworkConnectionPtr & conn
broadcastActiveGameRooms(); broadcastActiveGameRooms();
} }
void LobbyServer::receiveGameStarted(const NetworkConnectionPtr & connection, const JsonNode & json)
{
std::string gameRoomID = activeGameRooms[connection];
database->setGameRoomStatus(gameRoomID, LobbyRoomState::BUSY);
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

@ -86,6 +86,7 @@ class LobbyServer final : public INetworkServerListener
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 receiveChangeRoomDescription(const NetworkConnectionPtr & connection, const JsonNode & json);
void receiveGameStarted(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

@ -257,6 +257,9 @@ bool CVCMIServer::prepareToStartGame()
Load::Progress current(1); Load::Progress current(1);
progressTracking.include(current); progressTracking.include(current);
if (lobbyProcessor)
lobbyProcessor->sendGameStarted();
auto progressTrackingThread = boost::thread([this, &progressTracking]() auto progressTrackingThread = boost::thread([this, &progressTracking]()
{ {
auto currentProgress = std::numeric_limits<Load::Type>::max(); auto currentProgress = std::numeric_limits<Load::Type>::max();

View File

@ -149,6 +149,13 @@ void GlobalLobbyProcessor::onConnectionEstablished(const std::shared_ptr<INetwor
} }
} }
void GlobalLobbyProcessor::sendGameStarted()
{
JsonNode toSend;
toSend["type"].String() = "gameStarted";
sendMessage(controlConnection, toSend);
}
void GlobalLobbyProcessor::sendChangeRoomDescription(const std::string & description) void GlobalLobbyProcessor::sendChangeRoomDescription(const std::string & description)
{ {
JsonNode toSend; JsonNode toSend;

View File

@ -37,6 +37,7 @@ class GlobalLobbyProcessor : public INetworkClientListener
void sendMessage(const NetworkConnectionPtr & targetConnection, const JsonNode & payload); void sendMessage(const NetworkConnectionPtr & targetConnection, const JsonNode & payload);
public: public:
void sendChangeRoomDescription(const std::string & description); void sendChangeRoomDescription(const std::string & description);
void sendGameStarted();
explicit GlobalLobbyProcessor(CVCMIServer & owner); explicit GlobalLobbyProcessor(CVCMIServer & owner);
}; };