From b3347cfa8e5c6414507c68dae517ab8fbc47fdc5 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Tue, 15 Oct 2019 18:04:34 +0200 Subject: [PATCH] SOme small updates --- git-teaspeak | 2 +- license/LicenseCreatorCLI.cpp | 6 +- server/src/ServerManager.cpp | 41 ++++++++---- .../client/ConnectedClientNotifyHandler.cpp | 65 ++++++++++--------- 4 files changed, 67 insertions(+), 47 deletions(-) diff --git a/git-teaspeak b/git-teaspeak index 942ae83..d2b3e9b 160000 --- a/git-teaspeak +++ b/git-teaspeak @@ -1 +1 @@ -Subproject commit 942ae832e19be25f5f67ddb8b2fe35b8bb0f65de +Subproject commit d2b3e9bcadea5130b8ae906d9a1e656351f59936 diff --git a/license/LicenseCreatorCLI.cpp b/license/LicenseCreatorCLI.cpp index a483f0a..4225e88 100644 --- a/license/LicenseCreatorCLI.cpp +++ b/license/LicenseCreatorCLI.cpp @@ -65,7 +65,7 @@ class CLIParser { #define REQ_CMD(variable, message, ...) \ if(!options.option_exists({__VA_ARGS__}, false)) { \ - cerr << "missing user" << endl; \ + cerr << message << endl; \ return 1; \ } \ auto variable = url_decode(options.get_option({__VA_ARGS__})) \ @@ -84,8 +84,8 @@ int main(int argc, char **argv) { REQ_CMD(email, "missing email", "-m", "--email"); REQ_CMD(license_type, "missing license_type", "-l", "--license-type"); - REQ_CMD(auth_user, "missing authentification user", "-au", "--auth-user"); - REQ_CMD(auth_pass, "missing authentification user", "-ap", "--auth-pass"); + REQ_CMD(auth_user, "missing authentication user", "-au", "--auth-user"); + REQ_CMD(auth_pass, "missing authentication user", "-ap", "--auth-pass"); REQ_CMD(server_host, "missing server host", "-h", "--server-host"); REQ_CMD(server_port, "missing server port", "-p", "--server-port"); diff --git a/server/src/ServerManager.cpp b/server/src/ServerManager.cpp index ea89685..6c74428 100644 --- a/server/src/ServerManager.cpp +++ b/server/src/ServerManager.cpp @@ -83,22 +83,41 @@ bool ServerManager::initialize(bool autostart) { auto beg = system_clock::now(); size_t server_count = 0; - sql::command(this->handle->getSql(), "SELECT `serverId`, `host`, `port` FROM `servers`").query([&](ServerManager* mgr, int length, char** values, char** columns){ + sql::command(this->handle->getSql(), "SELECT `serverId`, `host`, `port` FROM `servers`").query([&](ServerManager* mgr, int length, std::string* values, std::string* columns){ ServerId id = 0; std::string host; uint16_t port = 0; - for(int index = 0; index < length; index++) - if(strcmp(columns[index], "serverId") == 0) - id = static_cast(stoll(values[index])); - else if(strcmp(columns[index], "host") == 0) - host = values[index]; - else if(strcmp(columns[index], "port") == 0) - port = static_cast(stoul(values[index])); + for(int index = 0; index < length; index++) { + try { + if(columns[index] == "serverId") + id = static_cast(stoll(values[index])); + else if(columns[index] == "host") + host = values[index]; + else if(columns[index] == "port") + port = static_cast(stoul(values[index])); + } catch(std::exception& ex) { + logError(LOG_INSTANCE, "Failed to parse virtual server from database. Failed to parse field {} with value {}: {}", columns[index], values[index], ex.what()); + return 0; + } + } + + + if(id == 0) { + logError(LOG_INSTANCE, "Failed to load virtual server from database. Server id is zero!"); + return 0; + } + + if(host.empty()) { + logWarning(id, "The loaded host is empty. Using default one (from the config.yml)"); + host = config::binding::DefaultVoiceHost; + } + + if(port == 0) { + logError(LOG_INSTANCE, "Failed to load virtual server from database. Server port is zero!"); + return 0; + } - assert(id != 0); - assert(port != 0); - assert(!host.empty()); auto server = make_shared(id, this->handle->getSql()); server->self = server; diff --git a/server/src/client/ConnectedClientNotifyHandler.cpp b/server/src/client/ConnectedClientNotifyHandler.cpp index 4f913b6..84157a4 100644 --- a/server/src/client/ConnectedClientNotifyHandler.cpp +++ b/server/src/client/ConnectedClientNotifyHandler.cpp @@ -255,45 +255,46 @@ bool ConnectedClient::notifyConnectionInfo(const shared_ptr &ta Command notify("notifyconnectioninfo"); notify["clid"] = target->getClientId(); + auto not_set = this->getType() == CLIENT_TEAMSPEAK ? 0 : -1; /* we deliver data to the web client as well, because its a bit dump :D */ if(target->getClientId() != this->getClientId()) { auto report = target->connectionStatistics->full_report(); /* default values which normally sets the client */ - notify["connection_bandwidth_received_last_minute_control"] = -1; - notify["connection_bandwidth_received_last_minute_keepalive"] = -1; - notify["connection_bandwidth_received_last_minute_speech"] = -1; - notify["connection_bandwidth_received_last_second_control"] = -1; - notify["connection_bandwidth_received_last_second_keepalive"] = -1; - notify["connection_bandwidth_received_last_second_speech"] = -1; + notify["connection_bandwidth_received_last_minute_control"] = not_set; + notify["connection_bandwidth_received_last_minute_keepalive"] = not_set; + notify["connection_bandwidth_received_last_minute_speech"] = not_set; + notify["connection_bandwidth_received_last_second_control"] = not_set; + notify["connection_bandwidth_received_last_second_keepalive"] = not_set; + notify["connection_bandwidth_received_last_second_speech"] = not_set; - notify["connection_bandwidth_sent_last_minute_control"] = -1; - notify["connection_bandwidth_sent_last_minute_keepalive"] = -1; - notify["connection_bandwidth_sent_last_minute_speech"] = -1; - notify["connection_bandwidth_sent_last_second_control"] = -1; - notify["connection_bandwidth_sent_last_second_keepalive"] = -1; - notify["connection_bandwidth_sent_last_second_speech"] = -1; + notify["connection_bandwidth_sent_last_minute_control"] = not_set; + notify["connection_bandwidth_sent_last_minute_keepalive"] = not_set; + notify["connection_bandwidth_sent_last_minute_speech"] = not_set; + notify["connection_bandwidth_sent_last_second_control"] = not_set; + notify["connection_bandwidth_sent_last_second_keepalive"] = not_set; + notify["connection_bandwidth_sent_last_second_speech"] = not_set; /* its flipped here because the report is out of the clients view */ - notify["connection_bytes_received_control"] = -1; - notify["connection_bytes_received_keepalive"] = -1; - notify["connection_bytes_received_speech"] = -1; - notify["connection_bytes_sent_control"] = -1; - notify["connection_bytes_sent_keepalive"] = -1; - notify["connection_bytes_sent_speech"] = -1; + notify["connection_bytes_received_control"] = not_set; + notify["connection_bytes_received_keepalive"] = not_set; + notify["connection_bytes_received_speech"] = not_set; + notify["connection_bytes_sent_control"] = not_set; + notify["connection_bytes_sent_keepalive"] = not_set; + notify["connection_bytes_sent_speech"] = not_set; /* its flipped here because the report is out of the clients view */ - notify["connection_packets_received_control"] = -1; - notify["connection_packets_received_keepalive"] = -1; - notify["connection_packets_received_speech"] = -1; - notify["connection_packets_sent_control"] = -1; - notify["connection_packets_sent_keepalive"] = -1; - notify["connection_packets_sent_speech"] = -1; + notify["connection_packets_received_control"] = not_set; + notify["connection_packets_received_keepalive"] = not_set; + notify["connection_packets_received_speech"] = not_set; + notify["connection_packets_sent_control"] = not_set; + notify["connection_packets_sent_keepalive"] = not_set; + notify["connection_packets_sent_speech"] = not_set; - notify["connection_server2client_packetloss_control"] = -1; - notify["connection_server2client_packetloss_keepalive"] = -1; - notify["connection_server2client_packetloss_speech"] = -1; - notify["connection_server2client_packetloss_total"] = -1; + notify["connection_server2client_packetloss_control"] = not_set; + notify["connection_server2client_packetloss_keepalive"] = not_set; + notify["connection_server2client_packetloss_speech"] = not_set; + notify["connection_server2client_packetloss_total"] = not_set; notify["connection_ping"] = 0; notify["connection_ping_deviation"] = 0; @@ -344,10 +345,10 @@ bool ConnectedClient::notifyConnectionInfo(const shared_ptr &ta } //Needs to be filled out - notify["connection_client2server_packetloss_speech"] = -1; - notify["connection_client2server_packetloss_keepalive"] = -1; - notify["connection_client2server_packetloss_control"] = -1; - notify["connection_client2server_packetloss_total"] = -1; + notify["connection_client2server_packetloss_speech"] = not_set; + notify["connection_client2server_packetloss_keepalive"] = not_set; + notify["connection_client2server_packetloss_control"] = not_set; + notify["connection_client2server_packetloss_total"] = not_set; notify["connection_connected_time"] = chrono::duration_cast(chrono::system_clock::now() - target->connectTimestamp).count(); notify["connection_idle_time"] = chrono::duration_cast(chrono::system_clock::now() - target->idleTimestamp).count();