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.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.public" : "Public",
"vcmi.lobby.room.private" : "Private",
@ -94,7 +94,7 @@
"vcmi.lobby.room.mode" : "Game Mode",
"vcmi.lobby.room.state.public" : "Public",
"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.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;
//const auto & onInviteClicked = [window, accountID=accountDescription.accountID]()
//{
// window->doInviteAccount(accountID);
//};
pos.w = 130;
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));
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);
//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)

View File

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

View File

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

View File

@ -60,6 +60,8 @@ NetworkConnectionPtr LobbyServer::findGameRoom(const std::string & gameRoomID) c
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"));
target->sendPacket(json.toBytes());
}
@ -342,6 +344,9 @@ void LobbyServer::onPacketReceived(const NetworkConnectionPtr & connection, cons
if(messageType == "changeRoomDescription")
return receiveChangeRoomDescription(connection, json);
if(messageType == "gameStarted")
return receiveGameStarted(connection, json);
if(messageType == "leaveGameRoom")
return receiveLeaveGameRoom(connection, json);
@ -597,6 +602,14 @@ void LobbyServer::receiveChangeRoomDescription(const NetworkConnectionPtr & conn
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)
{
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 receiveLeaveGameRoom(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 receiveDeclineInvite(const NetworkConnectionPtr & connection, const JsonNode & json);

View File

@ -257,6 +257,9 @@ bool CVCMIServer::prepareToStartGame()
Load::Progress current(1);
progressTracking.include(current);
if (lobbyProcessor)
lobbyProcessor->sendGameStarted();
auto progressTrackingThread = boost::thread([this, &progressTracking]()
{
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)
{
JsonNode toSend;

View File

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