Set matches that never reached gameplay state to 'cancelled' state

This commit is contained in:
Ivan Savenko
2024-03-27 13:10:55 +02:00
parent 862f6f8c7b
commit 89d091a386
3 changed files with 21 additions and 9 deletions
+10 -4
View File
@@ -90,14 +90,20 @@ void LobbyDatabase::clearOldData()
)";
//FIXME: set different status for rooms that never reached in game state
static const std::string removeActiveRooms = R"(
static const std::string removeActiveLobbyRooms = R"(
UPDATE gameRooms
SET status = 4
WHERE status IN (0,1,2)
)";
static const std::string removeActiveGameRooms = R"(
UPDATE gameRooms
SET status = 5
WHERE status <> 5
WHERE status = 3
)";
database->prepare(removeActiveAccounts)->execute();
database->prepare(removeActiveRooms)->execute();
database->prepare(removeActiveLobbyRooms)->execute();
database->prepare(removeActiveGameRooms)->execute();
}
void LobbyDatabase::prepareStatements()
@@ -209,7 +215,7 @@ void LobbyDatabase::prepareStatements()
FROM gameRoomPlayers grp
LEFT JOIN gameRooms gr ON gr.roomID = grp.roomID
LEFT JOIN accounts a ON gr.hostAccountID = a.accountID
WHERE grp.accountID = ? AND status IN (4,5)
WHERE grp.accountID = ? AND status = 5
ORDER BY secondsElapsed ASC
)");
+10 -4
View File
@@ -283,11 +283,17 @@ void LobbyServer::onDisconnected(const NetworkConnectionPtr & connection, const
if(activeGameRooms.count(connection))
{
std::string gameRoomID = activeGameRooms.at(connection);
database->setGameRoomStatus(gameRoomID, LobbyRoomState::CLOSED);
for(const auto & accountConnection : activeAccounts)
if (database->isPlayerInGameRoom(accountConnection.second, gameRoomID))
sendMatchesHistory(accountConnection.first);
if (database->getGameRoomStatus(gameRoomID) == LobbyRoomState::BUSY)
{
database->setGameRoomStatus(gameRoomID, LobbyRoomState::CLOSED);
for(const auto & accountConnection : activeAccounts)
if (database->isPlayerInGameRoom(accountConnection.second, gameRoomID))
sendMatchesHistory(accountConnection.first);
}
else
database->setGameRoomStatus(gameRoomID, LobbyRoomState::CANCELLED);
activeGameRooms.erase(connection);
}