From 0aad154c157bc4ff93a33a813331872ded55d1a7 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Tue, 27 Apr 2021 15:46:19 +0200 Subject: [PATCH] Some minor updates --- git-teaspeak | 2 +- server/src/InstanceHandler.cpp | 8 ++-- server/src/VirtualServer.cpp | 35 ++++++++-------- server/src/VirtualServer.h | 38 +++++++++++++---- server/src/VirtualServerManager.cpp | 35 +++------------- server/src/VirtualServerManager.h | 12 +----- server/src/client/ConnectedClient.cpp | 42 ++++++++++--------- .../src/client/query/QueryClientCommands.cpp | 18 ++++---- 8 files changed, 94 insertions(+), 96 deletions(-) diff --git a/git-teaspeak b/git-teaspeak index 64a573c..dc0e490 160000 --- a/git-teaspeak +++ b/git-teaspeak @@ -1 +1 @@ -Subproject commit 64a573cbd0f890907d4416c87021092e8cce7367 +Subproject commit dc0e49097c317f9c04fb9bfc0c8f61156c743ba8 diff --git a/server/src/InstanceHandler.cpp b/server/src/InstanceHandler.cpp index a84d6e3..4154bdf 100644 --- a/server/src/InstanceHandler.cpp +++ b/server/src/InstanceHandler.cpp @@ -654,10 +654,10 @@ std::shared_ptr InstanceHandler::gener auto request = std::make_shared(); request->license = config::license; request->metrics.servers_online = this->voiceServerManager->runningServers(); - auto report = this->voiceServerManager->clientReport(); - request->metrics.client_online = report.clients_ts; - request->metrics.web_clients_online = report.clients_web; - request->metrics.bots_online = report.bots; + auto report = this->voiceServerManager->instanceSlotUsageReport(); + request->metrics.client_online = report.clients_teamspeak; + request->metrics.web_clients_online = report.clients_teaweb; + request->metrics.bots_online = report.music_bots; request->metrics.queries_online = report.queries; request->metrics.speech_total = this->properties()[property::SERVERINSTANCE_SPOKEN_TIME_TOTAL].as_or(0); request->metrics.speech_varianz = this->properties()[property::SERVERINSTANCE_SPOKEN_TIME_VARIANZ].as_or(0); diff --git a/server/src/VirtualServer.cpp b/server/src/VirtualServer.cpp index a0ee5af..2395719 100644 --- a/server/src/VirtualServer.cpp +++ b/server/src/VirtualServer.cpp @@ -671,36 +671,37 @@ void VirtualServer::stop(const std::string& reason, bool disconnect_query) { this->serverAdmin->server = nullptr; } -size_t VirtualServer::onlineClients() { - size_t result{0}; - - for(const auto& client : this->getClients()) { - if(client->getType() == CLIENT_TEAMSPEAK || client->getType() == CLIENT_QUERY) { - result++; - } +ServerSlotUsageReport VirtualServer::onlineStats() { + ServerSlotUsageReport response{}; + response.server_count = 1; + response.max_clients = this->properties()[property::VIRTUALSERVER_MAXCLIENTS].as_or(0); + response.reserved_clients = this->properties()[property::VIRTUALSERVER_RESERVED_SLOTS].as_or(0); + { + std::lock_guard shared_lock{this->channel_tree_mutex}; + response.online_channels = this->channelTree->channel_count(); } - - return result; -} - -OnlineClientReport VirtualServer::onlineStats() { - OnlineClientReport response{}; - for(const auto &client : this->getClients()) { switch (client->getType()) { case CLIENT_TEAMSPEAK: + response.clients_teamspeak++; + break; + case CLIENT_TEASPEAK: - response.clients_ts++; + response.clients_teaspeak++; break; + case CLIENT_WEB: - response.clients_web++; + response.clients_teaweb++; break; + case CLIENT_QUERY: response.queries++; break; + case CLIENT_MUSIC: - response.bots++; + response.music_bots++; break; + case CLIENT_INTERNAL: case MAX: default: diff --git a/server/src/VirtualServer.h b/server/src/VirtualServer.h index 7e68f38..62f227d 100644 --- a/server/src/VirtualServer.h +++ b/server/src/VirtualServer.h @@ -105,11 +105,35 @@ namespace ts { } }; - struct OnlineClientReport { - uint16_t clients_ts = 0; - uint16_t clients_web = 0; - uint16_t queries = 0; - uint16_t bots = 0; + struct ServerSlotUsageReport { + size_t server_count{0}; + + size_t max_clients{0}; + size_t reserved_clients{0}; + + size_t clients_teamspeak{0}; + size_t clients_teaspeak{0}; + size_t clients_teaweb{0}; + size_t queries{0}; + size_t music_bots{0}; + + size_t online_channels{0}; + + [[nodiscard]] inline size_t voice_clients() const { + return this->clients_teaspeak + this->clients_teamspeak + this->clients_teaweb; + } + + inline ServerSlotUsageReport& operator+=(const ServerSlotUsageReport& other) { + this->max_clients += other.max_clients; + this->reserved_clients += other.reserved_clients; + this->clients_teamspeak += other.clients_teamspeak; + this->clients_teaspeak += other.clients_teaspeak; + this->clients_teaweb += other.clients_teaweb; + this->queries += other.queries; + this->music_bots += other.music_bots; + this->online_channels += other.online_channels; + return *this; + } }; struct CalculateCache {}; @@ -143,9 +167,7 @@ namespace ts { void preStop(const std::string&); void stop(const std::string& reason, bool /* disconnect query */); - size_t onlineClients(); - OnlineClientReport onlineStats(); - size_t onlineChannels(){ return this->channelTree->channel_count(); } + ServerSlotUsageReport onlineStats(); std::shared_ptr find_client_by_id(ClientId /* client id */); std::deque> findClientsByCldbId(ClientDbId cldbId); std::deque> findClientsByUid(ClientUid uid); diff --git a/server/src/VirtualServerManager.cpp b/server/src/VirtualServerManager.cpp index 4f09307..6e80606 100644 --- a/server/src/VirtualServerManager.cpp +++ b/server/src/VirtualServerManager.cpp @@ -272,30 +272,14 @@ ts::ServerId VirtualServerManager::next_available_server_id(bool& success) { return serverId; } -ServerReport VirtualServerManager::report() { - ServerReport result{}; - for(const auto& sr : this->serverInstances()) { - result.available++; - if(sr->running()) { - result.online++; - result.slots += sr->properties()[property::VIRTUALSERVER_MAXCLIENTS].as_or(0); - result.onlineClients += sr->onlineClients(); - result.onlineChannels += sr->onlineChannels(); +ServerSlotUsageReport VirtualServerManager::instanceSlotUsageReport() { + ServerSlotUsageReport result{}; + for(const auto& server : this->serverInstances()) { + if(!server->running()) { + continue; } - } - return result; -} - -OnlineClientReport VirtualServerManager::clientReport() { - OnlineClientReport result{}; - for(const auto& server : this->serverInstances()) { - if(!server->running()) continue; - auto sr = server->onlineStats(); - result.bots += sr.bots; - result.queries += sr.queries; - result.clients_web += sr.clients_web; - result.clients_ts += sr.clients_ts; + result += server->onlineStats(); } return result; } @@ -307,13 +291,6 @@ size_t VirtualServerManager::runningServers() { return res; } -size_t VirtualServerManager::usedSlots() { - size_t res = 0; - for(const auto& sr : this->serverInstances()) - res += sr->properties()[property::VIRTUALSERVER_MAXCLIENTS].as_or(0); - return res; -} - shared_ptr VirtualServerManager::create_server(std::string hosts, uint16_t port) { bool sid_success = false; diff --git a/server/src/VirtualServerManager.h b/server/src/VirtualServerManager.h index a18f8bb..1dc4281 100644 --- a/server/src/VirtualServerManager.h +++ b/server/src/VirtualServerManager.h @@ -10,14 +10,6 @@ namespace ts::server { class InstanceHandler; - struct ServerReport { - size_t available; - size_t online; - - size_t slots; - size_t onlineClients; - size_t onlineChannels; - }; class VirtualServerManager { public: enum State { @@ -55,10 +47,8 @@ namespace ts::server { return instances; } - ServerReport report(); - OnlineClientReport clientReport(); + ServerSlotUsageReport instanceSlotUsageReport(); size_t runningServers(); - size_t usedSlots(); void executeAutostart(); void shutdownAll(const std::string&); diff --git a/server/src/client/ConnectedClient.cpp b/server/src/client/ConnectedClient.cpp index 0d5de39..34d4834 100644 --- a/server/src/client/ConnectedClient.cpp +++ b/server/src/client/ConnectedClient.cpp @@ -846,26 +846,30 @@ void ConnectedClient::sendServerInit() { command["client_myteamspeak_id"] = this->properties()[property::CLIENT_MYTEAMSPEAK_ID].value(); command["client_integrations"] = this->properties()[property::CLIENT_INTEGRATIONS].value(); - if(ts::config::server::DefaultServerLicense == LicenseType::LICENSE_AUTOMATIC_INSTANCE) { - if(serverInstance->getVoiceServerManager()->usedSlots() <= 32) { - command["lt"] = LicenseType::LICENSE_NONE; - } else if(serverInstance->getVoiceServerManager()->usedSlots() <= 512) { - command["lt"] = LicenseType::LICENSE_NPL; - } else { - command["lt"] = LicenseType::LICENSE_HOSTING; - } - } else if(ts::config::server::DefaultServerLicense == LicenseType::LICENSE_AUTOMATIC_SERVER){ - if(this->server->properties()[property::VIRTUALSERVER_MAXCLIENTS].as_or(0) <= 32) { - command["lt"] = LicenseType::LICENSE_NONE; - } else if(this->server->properties()[property::VIRTUALSERVER_MAXCLIENTS].as_or(0) <= 512) { - command["lt"] = LicenseType::LICENSE_NPL; - } else { - command["lt"] = LicenseType::LICENSE_HOSTING; - } - } else { - command["lt"] = ts::config::server::DefaultServerLicense; + switch(ts::config::server::DefaultServerLicense) { + case LicenseType::LICENSE_AUTOMATIC_INSTANCE: + /* We offered this option but it's nonsense... Just use automatic server. */ + case LicenseType::LICENSE_AUTOMATIC_SERVER: + if(this->server->properties()[property::VIRTUALSERVER_MAXCLIENTS].as_or(0) <= 32) { + command["lt"] = LicenseType::LICENSE_NONE; + } else if(this->server->properties()[property::VIRTUALSERVER_MAXCLIENTS].as_or(0) <= 512) { + command["lt"] = LicenseType::LICENSE_NPL; + } else { + command["lt"] = LicenseType::LICENSE_HOSTING; + } + break; + + case LicenseType::LICENSE_NONE: + case LicenseType::LICENSE_HOSTING: + case LicenseType::LICENSE_OFFLINE: + case LicenseType::LICENSE_NPL: + case LicenseType::LICENSE_UNKNOWN: + case LicenseType::LICENSE_PLACEHOLDER: + default: + command["lt"] = ts::config::server::DefaultServerLicense; + break; } - command["pv"] = 6; //Protocol version + command["pv"] = 6; /* protocol version */ command["acn"] = this->getDisplayName(); command["aclid"] = this->getClientId(); this->sendCommand(command); diff --git a/server/src/client/query/QueryClientCommands.cpp b/server/src/client/query/QueryClientCommands.cpp index f1c3f31..c7c3fa2 100644 --- a/server/src/client/query/QueryClientCommands.cpp +++ b/server/src/client/query/QueryClientCommands.cpp @@ -832,10 +832,14 @@ command_result QueryClient::handleCommandInstanceInfo(Command& cmd) { ACTION_REQUIRES_INSTANCE_PERMISSION(permission::b_serverinstance_info_view, 1); Command res(""); - for(const auto& e : serverInstance->properties()->list_properties(property::FLAG_INSTANCE_VARIABLE, this->getType() == CLIENT_TEAMSPEAK ? property::FLAG_NEW : (uint16_t) 0)) + for(const auto& e : serverInstance->properties()->list_properties(property::FLAG_INSTANCE_VARIABLE, this->getType() == CLIENT_TEAMSPEAK ? property::FLAG_NEW : (uint16_t) 0)) { res[e.type().name] = e.value(); - if(!this->properties()[property::CLIENT_LOGIN_NAME].value().empty()) + } + + if(!this->properties()[property::CLIENT_LOGIN_NAME].value().empty()) { res["serverinstance_teaspeak"] = true; + } + res["serverinstance_serverquery_max_connections_per_ip"] = res["serverinstance_query_max_connections_per_ip"].as(); this->sendCommand(res); @@ -875,11 +879,11 @@ command_result QueryClient::handleCommandHostInfo(Command &) { res["instance_uptime"] = duration_cast(system_clock::now() - serverInstance->getStartTimestamp()).count(); res["host_timestamp_utc"] = duration_cast(system_clock::now().time_since_epoch()).count(); - auto vsReport = serverInstance->getVoiceServerManager()->report(); - res["virtualservers_running_total"] = vsReport.online; - res["virtualservers_total_maxclients"] = vsReport.slots; - res["virtualservers_total_clients_online"] = vsReport.onlineClients; - res["virtualservers_total_channels_online"] = vsReport.onlineChannels; + auto instance_report = serverInstance->getVoiceServerManager()->instanceSlotUsageReport(); + res["virtualservers_running_total"] = instance_report.server_count; + res["virtualservers_total_maxclients"] = instance_report.max_clients; + res["virtualservers_total_clients_online"] = instance_report.voice_clients(); + res["virtualservers_total_channels_online"] = instance_report.online_channels; auto total_stats = serverInstance->getStatistics()->total_stats();