mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-28 08:48:48 +02:00
Show match creation date in history
This commit is contained in:
parent
b50d9de912
commit
489dd781c2
@ -45,6 +45,15 @@ static std::string getCurrentTimeFormatted(int timeOffsetSeconds = 0)
|
||||
return TextOperations::getFormattedTimeLocal(std::chrono::system_clock::to_time_t(timeNowChrono));
|
||||
}
|
||||
|
||||
static std::string getCurrentDateTimeFormatted(int timeOffsetSeconds = 0)
|
||||
{
|
||||
// FIXME: better/unified way to format date
|
||||
auto timeNowChrono = std::chrono::system_clock::now();
|
||||
timeNowChrono += std::chrono::seconds(timeOffsetSeconds);
|
||||
|
||||
return TextOperations::getFormattedDateTimeLocal(std::chrono::system_clock::to_time_t(timeNowChrono));
|
||||
}
|
||||
|
||||
void GlobalLobbyClient::onPacketReceived(const std::shared_ptr<INetworkConnection> &, const std::vector<std::byte> & message)
|
||||
{
|
||||
boost::mutex::scoped_lock interfaceLock(GH.interfaceMutex);
|
||||
@ -214,6 +223,9 @@ void GlobalLobbyClient::receiveActiveGameRooms(const JsonNode & json)
|
||||
room.hostAccountDisplayName = jsonEntry["hostAccountDisplayName"].String();
|
||||
room.description = jsonEntry["description"].String();
|
||||
room.statusID = jsonEntry["status"].String();
|
||||
int ageSeconds = jsonEntry["ageSeconds"].Integer();
|
||||
room.startDateFormatted = getCurrentDateTimeFormatted(-ageSeconds);
|
||||
|
||||
for (auto const & jsonParticipant : jsonEntry["participants"].Vector())
|
||||
{
|
||||
GlobalLobbyAccount account;
|
||||
@ -244,6 +256,9 @@ void GlobalLobbyClient::receiveMatchesHistory(const JsonNode & json)
|
||||
room.hostAccountDisplayName = jsonEntry["hostAccountDisplayName"].String();
|
||||
room.description = jsonEntry["description"].String();
|
||||
room.statusID = jsonEntry["status"].String();
|
||||
int ageSeconds = jsonEntry["ageSeconds"].Integer();
|
||||
room.startDateFormatted = getCurrentDateTimeFormatted(-ageSeconds);
|
||||
|
||||
for (auto const & jsonParticipant : jsonEntry["participants"].Vector())
|
||||
{
|
||||
GlobalLobbyAccount account;
|
||||
|
@ -20,7 +20,7 @@
|
||||
{
|
||||
"type" : "object",
|
||||
"additionalProperties" : false,
|
||||
"required" : [ "gameRoomID", "hostAccountID", "hostAccountDisplayName", "description", "participants", "playerLimit", "status" ],
|
||||
"required" : [ "gameRoomID", "hostAccountID", "hostAccountDisplayName", "description", "participants", "playerLimit", "status", "ageSeconds" ],
|
||||
"properties" : {
|
||||
"gameRoomID" :
|
||||
{
|
||||
@ -77,6 +77,11 @@
|
||||
"minimum" : 1,
|
||||
"maximum" : 8,
|
||||
"description" : "Maximum number of players that can join this room, including host"
|
||||
},
|
||||
"ageSeconds" :
|
||||
{
|
||||
"type" : "number",
|
||||
"description" : "Age of this room in seconds. For example, 10 means that this room was created 10 seconds ago"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -203,11 +203,12 @@ void LobbyDatabase::prepareStatements()
|
||||
)";
|
||||
|
||||
static const std::string getAccountGameHistoryText = R"(
|
||||
SELECT gr.roomID, hostAccountID, displayName, description, status, playerLimit
|
||||
SELECT gr.roomID, hostAccountID, displayName, description, status, playerLimit, strftime('%s',CURRENT_TIMESTAMP)- strftime('%s',gr.creationTime) AS secondsElapsed
|
||||
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)
|
||||
ORDER BY secondsElapsed ASC
|
||||
)";
|
||||
|
||||
static const std::string getAccountGameRoomText = R"(
|
||||
@ -225,10 +226,11 @@ void LobbyDatabase::prepareStatements()
|
||||
)";
|
||||
|
||||
static const std::string getActiveGameRoomsText = R"(
|
||||
SELECT roomID, hostAccountID, displayName, description, status, playerLimit
|
||||
FROM gameRooms
|
||||
LEFT JOIN accounts ON hostAccountID = accountID
|
||||
SELECT roomID, hostAccountID, displayName, description, status, playerLimit, strftime('%s',CURRENT_TIMESTAMP)- strftime('%s',gr.creationTime) AS secondsElapsed
|
||||
FROM gameRooms gr
|
||||
LEFT JOIN accounts a ON gr.hostAccountID = a.accountID
|
||||
WHERE status IN (1, 2, 3)
|
||||
ORDER BY secondsElapsed ASC
|
||||
)";
|
||||
|
||||
static const std::string countRoomUsedSlotsText = R"(
|
||||
@ -548,7 +550,7 @@ std::vector<LobbyGameRoom> LobbyDatabase::getActiveGameRooms()
|
||||
while(getActiveGameRoomsStatement->execute())
|
||||
{
|
||||
LobbyGameRoom entry;
|
||||
getActiveGameRoomsStatement->getColumns(entry.roomID, entry.hostAccountID, entry.hostAccountDisplayName, entry.description, entry.roomState, entry.playerLimit);
|
||||
getActiveGameRoomsStatement->getColumns(entry.roomID, entry.hostAccountID, entry.hostAccountDisplayName, entry.description, entry.roomState, entry.playerLimit, entry.age);
|
||||
result.push_back(entry);
|
||||
}
|
||||
getActiveGameRoomsStatement->reset();
|
||||
@ -575,7 +577,7 @@ std::vector<LobbyGameRoom> LobbyDatabase::getAccountGameHistory(const std::strin
|
||||
while(getAccountGameHistoryStatement->execute())
|
||||
{
|
||||
LobbyGameRoom entry;
|
||||
getAccountGameHistoryStatement->getColumns(entry.roomID, entry.hostAccountID, entry.hostAccountDisplayName, entry.description, entry.roomState, entry.playerLimit);
|
||||
getAccountGameHistoryStatement->getColumns(entry.roomID, entry.hostAccountID, entry.hostAccountDisplayName, entry.description, entry.roomState, entry.playerLimit, entry.age);
|
||||
result.push_back(entry);
|
||||
}
|
||||
getAccountGameHistoryStatement->reset();
|
||||
|
@ -47,6 +47,7 @@ struct LobbyGameRoom
|
||||
std::vector<LobbyAccount> participants;
|
||||
LobbyRoomState roomState;
|
||||
uint32_t playerLimit;
|
||||
std::chrono::seconds age;
|
||||
};
|
||||
|
||||
struct LobbyChatMessage
|
||||
|
@ -193,6 +193,7 @@ static JsonNode loadLobbyGameRoomToJson(const LobbyGameRoom & gameRoom)
|
||||
jsonEntry["description"].String() = gameRoom.description;
|
||||
jsonEntry["status"].String() = LOBBY_ROOM_STATE_NAMES[vstd::to_underlying(gameRoom.roomState)];
|
||||
jsonEntry["playerLimit"].Integer() = gameRoom.playerLimit;
|
||||
jsonEntry["ageSeconds"].Integer() = gameRoom.age.count();
|
||||
|
||||
for (auto const & account : gameRoom.participants)
|
||||
jsonEntry["participants"].Vector().push_back(loadLobbyAccountToJson(account));
|
||||
|
Loading…
Reference in New Issue
Block a user