From 971a84105b275ac8d93357cb129b88501c2ad8d8 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Fri, 8 Nov 2019 20:08:22 +0100 Subject: [PATCH] Fixed the server --- license/CMakeLists.txt | 3 ++- license/LicenseManager.cpp | 2 +- license/manager/ServerConnection.cpp | 13 +++++-------- license/manager/ServerConnection.h | 7 ++++++- license/manager/ServerConnectionHandler.cpp | 11 ++++++++--- license/manager/ui/Overview.cpp | 2 +- server/src/TS3ServerHeartbeat.cpp | 11 +++++++---- 7 files changed, 30 insertions(+), 19 deletions(-) diff --git a/license/CMakeLists.txt b/license/CMakeLists.txt index c2145fd..88bdba2 100644 --- a/license/CMakeLists.txt +++ b/license/CMakeLists.txt @@ -86,13 +86,13 @@ target_link_libraries(TeaLicenseClient ${LIBRARY_TOM_CRYPT} stdc++fs.a ${LIBRARY_PATH_TERMINAL} - ${LIBRARY_PATH_ED255} ${LIBRARY_PATH_BORINGSSL_SSL} ${LIBRARY_PATH_BORINGSSL_CRYPTO} ${LIBRARY_PATH_BREAKPAD} ${TOM_LIBRARIES} ${LIBRARY_PATH_JDBC} + ${LIBRARY_PATH_ED255} TeaSpeak #Static jsoncpp.a ) @@ -136,6 +136,7 @@ if(NOT DISABLE_QT) ${LIBRARY_TOM_MATH} ${LIBRARY_TOM_CRYPT} + ${LIBRARY_PATH_ED255} stdc++fs jsoncpp.a ${LIBRARY_PATH_DATA_PIPES} diff --git a/license/LicenseManager.cpp b/license/LicenseManager.cpp index a80e44d..6912036 100644 --- a/license/LicenseManager.cpp +++ b/license/LicenseManager.cpp @@ -43,7 +43,7 @@ int main(int ac, char** av){ auto license = license::readLocalLicence(data, error); cout << "Key: " << base64::encode(license->key()) << endl; cout << "Key: " << string_to_hex(license->key()) << endl; - return false; + //return false; connection = new ServerConnection(); if(!connection->connect("mcgalaxy.de", 27786).waitAndGet(false)) { diff --git a/license/manager/ServerConnection.cpp b/license/manager/ServerConnection.cpp index 3429e10..6cfdd3a 100644 --- a/license/manager/ServerConnection.cpp +++ b/license/manager/ServerConnection.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include "ServerConnection.h" using namespace std; @@ -57,11 +58,11 @@ threads::Future ServerConnection::connect(const std::string &host, uint16_ this->network.event_write = event_new(this->network.event_base, this->network.file_descriptor, EV_WRITE, ServerConnection::handleEventWrite, this); event_add(this->network.event_read, nullptr); - this->network.event_base_dispatch = new threads::Thread(THREAD_SAVE_OPERATIONS, [&](){ + this->network.event_base_dispatch = std::thread{[&]{ event_base_dispatch(this->network.event_base); if(this->verbose) cout << "ev ended!" << endl; - }); + }}; this->network.state = ConnectionState::CONNECTED; this->protocol.state = protocol::HANDSCAKE; this->protocol.ping_thread = thread([&]{ @@ -104,7 +105,7 @@ void ServerConnection::closeConnection() { if(this->network.state == ConnectionState::UNCONNECTED) return; this->network.state = ConnectionState::DISCONNECTING; - if(this->network.event_base_dispatch && *this->network.event_base_dispatch == threads::self::id()) { + if(this->network.event_base_dispatch.get_id() == this_thread::get_id()) { this->network.flush_thread = new threads::Thread(THREAD_SAVE_OPERATIONS, [&](){ this->closeConnection(); }); return; } @@ -126,11 +127,7 @@ void ServerConnection::closeConnection() { cerr << "could not stop event loop!" << endl; } } - if(this->network.event_base_dispatch) { - this->network.event_base_dispatch->join(); - delete this->network.event_base_dispatch; - this->network.event_base_dispatch = nullptr; - } + threads::save_join(this->network.event_base_dispatch); if(this->network.event_base) { event_base_free(this->network.event_base); this->network.event_base = nullptr; diff --git a/license/manager/ServerConnection.h b/license/manager/ServerConnection.h index 4d0699a..35e8e95 100644 --- a/license/manager/ServerConnection.h +++ b/license/manager/ServerConnection.h @@ -4,6 +4,8 @@ #include #include #include +#include +#include #include "shared/License.h" #define FLSUCCESS(listener, object) \ @@ -65,7 +67,7 @@ namespace license { event* event_read = nullptr; event* event_write = nullptr; struct event_base* event_base = nullptr; - threads::Thread* event_base_dispatch = nullptr; + std::thread event_base_dispatch; threads::Thread* flush_thread = nullptr; @@ -73,6 +75,9 @@ namespace license { std::deque queue_write; std::unique_ptr current_packet; + + + std::string overhead; } network; diff --git a/license/manager/ServerConnectionHandler.cpp b/license/manager/ServerConnectionHandler.cpp index 7103a59..faffd0f 100644 --- a/license/manager/ServerConnectionHandler.cpp +++ b/license/manager/ServerConnectionHandler.cpp @@ -27,8 +27,7 @@ void ServerConnection::handleMessage(const std::string& message) { packet->data += message; } else { packet->data += message.substr(0, left); - if(this->verbose) - cerr << "Dropping overhead! FIXME!" << endl; + this->network.overhead = message.substr(left); } } else { if(message.length() < sizeof(protocol::packet::header)) { @@ -41,7 +40,8 @@ void ServerConnection::handleMessage(const std::string& message) { memcpy(packet.get(), message.data(), sizeof(protocol::packet::header)); packet->data = message.substr(sizeof(protocol::packet::header)); } - if(packet->data.length() < packet->header.length) return; + if(packet->data.length() < packet->header.length) + return; if(!this->protocol.crypt_key.empty()) xorBuffer((char*) packet->data.data(), packet->data.length(), this->protocol.crypt_key.data(), this->protocol.crypt_key.length()); @@ -70,6 +70,11 @@ void ServerConnection::handleMessage(const std::string& message) { cout << "Invalid packet type: " << packet->header.packetId << endl; } packet.reset(); + if(!this->network.overhead.empty()) { + auto oh = this->network.overhead; + this->network.overhead = ""; + this->handleMessage(oh); + } } void ServerConnection::handlePacketDisconnect(const std::string& message) { diff --git a/license/manager/ui/Overview.cpp b/license/manager/ui/Overview.cpp index dd84d80..550e1eb 100644 --- a/license/manager/ui/Overview.cpp +++ b/license/manager/ui/Overview.cpp @@ -158,7 +158,7 @@ void Overview::btn_refresh_clicked() { this->ui.licenses->removeRow(0); this->entries.clear(); - auto fut = connection->list(0, 0); + auto fut = connection->list(0, 100); fut.waitAndGetLater([&, fut](std::map> response) { if(!fut.succeeded()) { runOnThread(this->thread(), [&, fut](){ diff --git a/server/src/TS3ServerHeartbeat.cpp b/server/src/TS3ServerHeartbeat.cpp index 5a99d5f..1c83503 100644 --- a/server/src/TS3ServerHeartbeat.cpp +++ b/server/src/TS3ServerHeartbeat.cpp @@ -44,10 +44,13 @@ void TSServer::executeServerTick() { auto delay = system_clock::now() - lastTick; auto delay_ms = duration_cast(delay).count(); if(delay_ms > 510) { - if(delay_ms < 750) - logWarning(this->getServerId(), "Found varianzes within the server tick! (Supposed: 500ms Hold: {}ms)", delay_ms); - else - logError(this->getServerId(), "Found varianzes within the server tick! This long delay could be an issue. (Supposed: 500ms Hold: {}ms)", delay_ms); + if(delay_ms < 750) { + logWarning(this->getServerId(), + "Found varianzes within the server tick! (Supposed: 500ms Hold: {}ms)", delay_ms); + } else { + logError(this->getServerId(), + "Found varianzes within the server tick! This long delay could be an issue. (Supposed: 500ms Hold: {}ms)", delay_ms); + } } } lastTick = system_clock::now();