Fixed the server

This commit is contained in:
WolverinDEV 2019-11-08 20:08:22 +01:00
parent b778421593
commit 971a84105b
7 changed files with 30 additions and 19 deletions

View File

@ -86,13 +86,13 @@ target_link_libraries(TeaLicenseClient
${LIBRARY_TOM_CRYPT} ${LIBRARY_TOM_CRYPT}
stdc++fs.a stdc++fs.a
${LIBRARY_PATH_TERMINAL} ${LIBRARY_PATH_TERMINAL}
${LIBRARY_PATH_ED255}
${LIBRARY_PATH_BORINGSSL_SSL} ${LIBRARY_PATH_BORINGSSL_SSL}
${LIBRARY_PATH_BORINGSSL_CRYPTO} ${LIBRARY_PATH_BORINGSSL_CRYPTO}
${LIBRARY_PATH_BREAKPAD} ${LIBRARY_PATH_BREAKPAD}
${TOM_LIBRARIES} ${TOM_LIBRARIES}
${LIBRARY_PATH_JDBC} ${LIBRARY_PATH_JDBC}
${LIBRARY_PATH_ED255}
TeaSpeak #Static TeaSpeak #Static
jsoncpp.a jsoncpp.a
) )
@ -136,6 +136,7 @@ if(NOT DISABLE_QT)
${LIBRARY_TOM_MATH} ${LIBRARY_TOM_MATH}
${LIBRARY_TOM_CRYPT} ${LIBRARY_TOM_CRYPT}
${LIBRARY_PATH_ED255}
stdc++fs stdc++fs
jsoncpp.a jsoncpp.a
${LIBRARY_PATH_DATA_PIPES} ${LIBRARY_PATH_DATA_PIPES}

View File

@ -43,7 +43,7 @@ int main(int ac, char** av){
auto license = license::readLocalLicence(data, error); auto license = license::readLocalLicence(data, error);
cout << "Key: " << base64::encode(license->key()) << endl; cout << "Key: " << base64::encode(license->key()) << endl;
cout << "Key: " << string_to_hex(license->key()) << endl; cout << "Key: " << string_to_hex(license->key()) << endl;
return false; //return false;
connection = new ServerConnection(); connection = new ServerConnection();
if(!connection->connect("mcgalaxy.de", 27786).waitAndGet(false)) { if(!connection->connect("mcgalaxy.de", 27786).waitAndGet(false)) {

View File

@ -7,6 +7,7 @@
#include <shared/License.h> #include <shared/License.h>
#include <memory> #include <memory>
#include <misc/std_unique_ptr.h> #include <misc/std_unique_ptr.h>
#include <ThreadPool/ThreadHelper.h>
#include "ServerConnection.h" #include "ServerConnection.h"
using namespace std; using namespace std;
@ -57,11 +58,11 @@ threads::Future<bool> 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); 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); 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); event_base_dispatch(this->network.event_base);
if(this->verbose) if(this->verbose)
cout << "ev ended!" << endl; cout << "ev ended!" << endl;
}); }};
this->network.state = ConnectionState::CONNECTED; this->network.state = ConnectionState::CONNECTED;
this->protocol.state = protocol::HANDSCAKE; this->protocol.state = protocol::HANDSCAKE;
this->protocol.ping_thread = thread([&]{ this->protocol.ping_thread = thread([&]{
@ -104,7 +105,7 @@ void ServerConnection::closeConnection() {
if(this->network.state == ConnectionState::UNCONNECTED) return; if(this->network.state == ConnectionState::UNCONNECTED) return;
this->network.state = ConnectionState::DISCONNECTING; 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(); }); this->network.flush_thread = new threads::Thread(THREAD_SAVE_OPERATIONS, [&](){ this->closeConnection(); });
return; return;
} }
@ -126,11 +127,7 @@ void ServerConnection::closeConnection() {
cerr << "could not stop event loop!" << endl; cerr << "could not stop event loop!" << endl;
} }
} }
if(this->network.event_base_dispatch) { threads::save_join(this->network.event_base_dispatch);
this->network.event_base_dispatch->join();
delete this->network.event_base_dispatch;
this->network.event_base_dispatch = nullptr;
}
if(this->network.event_base) { if(this->network.event_base) {
event_base_free(this->network.event_base); event_base_free(this->network.event_base);
this->network.event_base = nullptr; this->network.event_base = nullptr;

View File

@ -4,6 +4,8 @@
#include <event.h> #include <event.h>
#include <ThreadPool/Future.h> #include <ThreadPool/Future.h>
#include <deque> #include <deque>
#include <thread>
#include <ThreadPool/Thread.h>
#include "shared/License.h" #include "shared/License.h"
#define FLSUCCESS(listener, object) \ #define FLSUCCESS(listener, object) \
@ -65,7 +67,7 @@ namespace license {
event* event_read = nullptr; event* event_read = nullptr;
event* event_write = nullptr; event* event_write = nullptr;
struct event_base* event_base = nullptr; struct event_base* event_base = nullptr;
threads::Thread* event_base_dispatch = nullptr; std::thread event_base_dispatch;
threads::Thread* flush_thread = nullptr; threads::Thread* flush_thread = nullptr;
@ -73,6 +75,9 @@ namespace license {
std::deque<std::string> queue_write; std::deque<std::string> queue_write;
std::unique_ptr<protocol::packet> current_packet; std::unique_ptr<protocol::packet> current_packet;
std::string overhead;
} network; } network;

View File

@ -27,8 +27,7 @@ void ServerConnection::handleMessage(const std::string& message) {
packet->data += message; packet->data += message;
} else { } else {
packet->data += message.substr(0, left); packet->data += message.substr(0, left);
if(this->verbose) this->network.overhead = message.substr(left);
cerr << "Dropping overhead! FIXME!" << endl;
} }
} else { } else {
if(message.length() < sizeof(protocol::packet::header)) { 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)); memcpy(packet.get(), message.data(), sizeof(protocol::packet::header));
packet->data = message.substr(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()) if(!this->protocol.crypt_key.empty())
xorBuffer((char*) packet->data.data(), packet->data.length(), this->protocol.crypt_key.data(), this->protocol.crypt_key.length()); 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; cout << "Invalid packet type: " << packet->header.packetId << endl;
} }
packet.reset(); 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) { void ServerConnection::handlePacketDisconnect(const std::string& message) {

View File

@ -158,7 +158,7 @@ void Overview::btn_refresh_clicked() {
this->ui.licenses->removeRow(0); this->ui.licenses->removeRow(0);
this->entries.clear(); this->entries.clear();
auto fut = connection->list(0, 0); auto fut = connection->list(0, 100);
fut.waitAndGetLater([&, fut](std::map<std::string, std::shared_ptr<license::LicenseInfo>> response) { fut.waitAndGetLater([&, fut](std::map<std::string, std::shared_ptr<license::LicenseInfo>> response) {
if(!fut.succeeded()) { if(!fut.succeeded()) {
runOnThread(this->thread(), [&, fut](){ runOnThread(this->thread(), [&, fut](){

View File

@ -44,10 +44,13 @@ void TSServer::executeServerTick() {
auto delay = system_clock::now() - lastTick; auto delay = system_clock::now() - lastTick;
auto delay_ms = duration_cast<milliseconds>(delay).count(); auto delay_ms = duration_cast<milliseconds>(delay).count();
if(delay_ms > 510) { if(delay_ms > 510) {
if(delay_ms < 750) if(delay_ms < 750) {
logWarning(this->getServerId(), "Found varianzes within the server tick! (Supposed: 500ms Hold: {}ms)", delay_ms); logWarning(this->getServerId(),
else "Found varianzes within the server tick! (Supposed: 500ms Hold: {}ms)", delay_ms);
logError(this->getServerId(), "Found varianzes within the server tick! This long delay could be an issue. (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(); lastTick = system_clock::now();