Fixed the server
This commit is contained in:
parent
b778421593
commit
971a84105b
@ -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}
|
||||
|
@ -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)) {
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <shared/License.h>
|
||||
#include <memory>
|
||||
#include <misc/std_unique_ptr.h>
|
||||
#include <ThreadPool/ThreadHelper.h>
|
||||
#include "ServerConnection.h"
|
||||
|
||||
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);
|
||||
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;
|
||||
|
@ -4,6 +4,8 @@
|
||||
#include <event.h>
|
||||
#include <ThreadPool/Future.h>
|
||||
#include <deque>
|
||||
#include <thread>
|
||||
#include <ThreadPool/Thread.h>
|
||||
#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<std::string> queue_write;
|
||||
|
||||
std::unique_ptr<protocol::packet> current_packet;
|
||||
|
||||
|
||||
std::string overhead;
|
||||
} network;
|
||||
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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<std::string, std::shared_ptr<license::LicenseInfo>> response) {
|
||||
if(!fut.succeeded()) {
|
||||
runOnThread(this->thread(), [&, fut](){
|
||||
|
@ -44,10 +44,13 @@ void TSServer::executeServerTick() {
|
||||
auto delay = system_clock::now() - lastTick;
|
||||
auto delay_ms = duration_cast<milliseconds>(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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user