add time played support to server query results
This commit is contained in:
parent
9bc12f5f97
commit
c47bceb3f3
@ -63,6 +63,8 @@ ServerClientContext::ServerClientContext(ConnectionId clientId, Maybe<HostAddres
|
||||
m_netGroup.addNetElement(&m_teamNetState);
|
||||
m_netGroup.addNetElement(&m_shipUpgrades);
|
||||
m_netGroup.addNetElement(&m_shipCoordinate);
|
||||
|
||||
m_creationTime = Time::monotonicMilliseconds();
|
||||
}
|
||||
|
||||
ConnectionId ServerClientContext::clientId() const {
|
||||
@ -289,4 +291,8 @@ Json ServerClientContext::storeServerData() {
|
||||
return store;
|
||||
}
|
||||
|
||||
int64_t ServerClientContext::creationTime() const {
|
||||
return m_creationTime;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -85,6 +85,8 @@ public:
|
||||
void loadServerData(Json const& store);
|
||||
Json storeServerData();
|
||||
|
||||
int64_t creationTime() const;
|
||||
|
||||
private:
|
||||
ConnectionId const m_clientId;
|
||||
Maybe<HostAddress> const m_remoteAddress;
|
||||
@ -109,6 +111,7 @@ private:
|
||||
|
||||
NetElementTopGroup m_netGroup;
|
||||
uint64_t m_netVersion = 0;
|
||||
int64_t m_creationTime;
|
||||
|
||||
NetElementData<Maybe<pair<WarpAction, WarpMode>>> m_orbitWarpActionNetState;
|
||||
NetElementData<WorldId> m_playerWorldIdNetState;
|
||||
|
@ -173,6 +173,15 @@ List<ConnectionId> UniverseServer::clientIds() const {
|
||||
return m_clients.keys();
|
||||
}
|
||||
|
||||
List<pair<ConnectionId, int64_t>> UniverseServer::clientIdsAndCreationTime() const {
|
||||
List<pair<ConnectionId, int64_t>> 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();
|
||||
|
@ -55,6 +55,7 @@ public:
|
||||
bool isWorldActive(WorldId const& worldId) const;
|
||||
|
||||
List<ConnectionId> clientIds() const;
|
||||
List<pair<ConnectionId, int64_t>> clientIdsAndCreationTime() const;
|
||||
size_t numberOfClients() const;
|
||||
uint32_t maxClients() const;
|
||||
bool isConnectedClient(ConnectionId clientId) const;
|
||||
|
@ -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;
|
||||
|
@ -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";
|
||||
|
Loading…
x
Reference in New Issue
Block a user