diff --git a/source/game/StarServerClientContext.cpp b/source/game/StarServerClientContext.cpp index fcbffbd..cd7c6cd 100644 --- a/source/game/StarServerClientContext.cpp +++ b/source/game/StarServerClientContext.cpp @@ -63,6 +63,8 @@ ServerClientContext::ServerClientContext(ConnectionId clientId, Maybe const m_remoteAddress; @@ -109,6 +111,7 @@ private: NetElementTopGroup m_netGroup; uint64_t m_netVersion = 0; + int64_t m_creationTime; NetElementData>> m_orbitWarpActionNetState; NetElementData m_playerWorldIdNetState; diff --git a/source/game/StarUniverseServer.cpp b/source/game/StarUniverseServer.cpp index 9ce097e..fde8ca6 100644 --- a/source/game/StarUniverseServer.cpp +++ b/source/game/StarUniverseServer.cpp @@ -173,6 +173,15 @@ List UniverseServer::clientIds() const { return m_clients.keys(); } +List> UniverseServer::clientIdsAndCreationTime() const { + List> result; + ReadLocker clientsLocker(m_clientsLock); + result.reserve(m_clients.size()); + for (auto& pair : m_clients) + result.emplaceAppend(pair.first, pair.second->creationTime()); + return result; +} + size_t UniverseServer::numberOfClients() const { ReadLocker clientsLocker(m_clientsLock); return m_clients.size(); diff --git a/source/game/StarUniverseServer.hpp b/source/game/StarUniverseServer.hpp index e7f24fa..a87194f 100644 --- a/source/game/StarUniverseServer.hpp +++ b/source/game/StarUniverseServer.hpp @@ -55,6 +55,7 @@ public: bool isWorldActive(WorldId const& worldId) const; List clientIds() const; + List> clientIdsAndCreationTime() const; size_t numberOfClients() const; uint32_t maxClients() const; bool isConnectedClient(ConnectionId clientId) const; diff --git a/source/server/StarServerQueryThread.cpp b/source/server/StarServerQueryThread.cpp index 2011f42..441fa63 100644 --- a/source/server/StarServerQueryThread.cpp +++ b/source/server/StarServerQueryThread.cpp @@ -107,6 +107,8 @@ bool ServerQueryThread::processPacket(HostAddressWithPort const& address, char c << A2S_TYPE_DEDICATED // dedicated #ifdef STAR_SYSTEM_FAMILY_WINDOWS << A2S_ENV_WINDOWS // os +#elif defined(STAR_SYSTEM_MACOS) + << A2S_ENV_MAC // os #else << A2S_ENV_LINUX // os #endif @@ -153,17 +155,17 @@ void ServerQueryThread::buildPlayerResponse() { return; } - auto clientIds = m_universe->clientIds(); + auto clientIds = m_universe->clientIdsAndCreationTime(); uint8_t cnt = (uint8_t)clientIds.count(); int32_t kills = 0; // Not currently supported - float timeConnected = 60; // Not supported defaults to 1min m_playersResponse.clear(); m_playersResponse << A2S_HEAD_INT << A2S_PLAYER_REPLY << cnt; uint8_t i = 0; - for (auto clientId : clientIds) { - m_playersResponse << i++ << m_universe->clientNick(clientId) << kills << timeConnected; + for (auto& pair : clientIds) { + auto timeConnected = float(now - pair.second) / 1000.f; + m_playersResponse << i++ << m_universe->clientNick(pair.first) << kills << timeConnected; } m_lastPlayersResponse = now; diff --git a/source/server/StarServerQueryThread.hpp b/source/server/StarServerQueryThread.hpp index 54ab93f..d45e1a9 100644 --- a/source/server/StarServerQueryThread.hpp +++ b/source/server/StarServerQueryThread.hpp @@ -42,11 +42,12 @@ private: static const uint8_t A2S_EDF_TAGS = 0x20; static const uint8_t A2S_EDF_STV = 0x40; static const uint8_t A2S_EDF_PORT = 0x80; - static const uint8_t A2S_ENV_WINDOWS = 'W'; - static const uint8_t A2S_ENV_LINUX = 'L'; - static const uint8_t A2S_TYPE_DEDICATED = 'D'; - static const uint8_t A2S_TYPE_LISTEN = 'L'; - static const uint8_t A2S_TYPE_TV = 'P'; + static const uint8_t A2S_ENV_WINDOWS = 'w'; + static const uint8_t A2S_ENV_LINUX = 'l'; + static const uint8_t A2S_ENV_MAC = 'm'; + static const uint8_t A2S_TYPE_DEDICATED = 'd'; + static const uint8_t A2S_TYPE_LISTEN = 'l'; + static const uint8_t A2S_TYPE_TV = 'p'; static const uint8_t A2S_VAC_OFF = 0x00; static const uint8_t A2S_VAC_ON = 0x01; static constexpr const char* A2S_INFO_REQUEST_STRING = "Source Engine Query";