diff --git a/license/shared/LicenseRequest.cpp b/license/shared/LicenseRequest.cpp index 198a862..3b303fb 100644 --- a/license/shared/LicenseRequest.cpp +++ b/license/shared/LicenseRequest.cpp @@ -12,7 +12,7 @@ using namespace std::chrono; using namespace ts; using namespace license; -#define DEBUG_LICENSE_CLIENT +//#define DEBUG_LICENSE_CLIENT #define CERR(message) LICENSE_FERR(this, CouldNotConnectException, message) @@ -91,7 +91,7 @@ void LicenceRequest::handleEventWrite(int fd, short event, void* ptrClient) { void LicenceRequest::sendPacket(const protocol::packet& packet) { if(this->state == protocol::UNCONNECTED || this->state == protocol::DISCONNECTING) { if(this->verbose) - logError("Tried to send a packet to an unconnected remote!"); + logError(LOG_GENERAL, "Tried to send a packet to an unconnected remote!"); return; } packet.prepare(); @@ -243,7 +243,7 @@ void LicenceRequest::closeConnection() { #ifdef DEBUG_LICENSE_CLIENT if(this->verbose) { - debugMessage("Running close in a new thread"); + debugMessage(LOG_GENERAL,"Running close in a new thread"); this->closeThread->name("License request close"); } #endif diff --git a/server/main.cpp b/server/main.cpp index 2259080..3654a52 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -301,7 +301,7 @@ int main(int argc, char** argv) { strftime(timeBuffer, 32, "%c", stime); logMessageFmt(true, LOG_GENERAL, strobf(" §aLicense expires: §e").string() + string(timeBuffer)); } - logMessage(string() + strobf(" §aLicense valid : ").string() + (ts::config::license_original->isValid() ? strobf("§ayes").string() : strobf("§cno").string())); + logMessageFmt(true, LOG_GENERAL, string() + strobf(" §aLicense valid : ").string() + (ts::config::license_original->isValid() ? strobf("§ayes").string() : strobf("§cno").string())); logMessageFmt(true, LOG_GENERAL, strobf("[]---------------------------------------------------------[]").string()); } @@ -322,11 +322,11 @@ int main(int argc, char** argv) { else if(ts::config::geo::type == geoloc::PROVIDER_IP2LOCATION) geoloc::provider = new geoloc::IP2LocationProvider(ts::config::geo::mappingFile); else { - logCritical("Invalid geo resolver type!"); + logCritical(LOG_GENERAL,"Invalid geo resolver type!"); } if(geoloc::provider && !geoloc::provider->load(errorMessage)) { - logCritical("Could not setup geoloc! Fallback to default flag!"); - logCritical("Message: " + errorMessage); + logCritical(LOG_GENERAL,"Could not setup geoloc! Fallback to default flag!"); + logCritical(LOG_GENERAL,"Message: {}", errorMessage); geoloc::provider = nullptr; errorMessage = ""; } @@ -335,8 +335,8 @@ int main(int argc, char** argv) { geoloc::provider_vpn = new geoloc::IPCatBlocker(ts::config::geo::vpn_file); if(geoloc::provider_vpn && !geoloc::provider_vpn->load(errorMessage)) { - logCritical("Could not setup vpn detector!"); - logCritical("Message: " + errorMessage); + logCritical(LOG_GENERAL,"Could not setup vpn detector!"); + logCritical(LOG_GENERAL,"Message: {}", errorMessage); geoloc::provider_vpn = nullptr; errorMessage = ""; } @@ -345,7 +345,7 @@ int main(int argc, char** argv) { sql = new ts::server::SqlDataManager(); if(!sql->initialize(errorMessage)) { - logCritical("Could not initialize SQL!"); + logCriticalFmt(true, LOG_GENERAL, "Could not initialize SQL!"); if(errorMessage.find("database is locked") != string::npos) { logCriticalFmt(true, LOG_GENERAL, "----------------------------[ ATTENTION ]----------------------------"); logCriticalFmt(true, LOG_GENERAL, "{:^69}", "You're database is already in use!"); diff --git a/server/src/Configuration.cpp b/server/src/Configuration.cpp index 1d15d1e..c0435da 100644 --- a/server/src/Configuration.cpp +++ b/server/src/Configuration.cpp @@ -267,7 +267,7 @@ void remapValue(YAML::Node& node, const string &oldPath, const string &newPath){ if(old.size() > 1) { auto oldNode = old[old.size() - 1]; oldNode = YAML::Null; - if(old[old.size() - 2].remove(oldNode)) logError("Could not remove old config entry"); + if(old[old.size() - 2].remove(oldNode)) logError(LOG_GENERAL, "Could not remove old config entry"); } } @@ -350,8 +350,8 @@ vector config::parseConfig(const std::string& path) { } { if(config_version != CURRENT_CONFIG_VERSION) { - logMessage("You're using an outdated config."); - logMessage("Updating config"); + logMessage(LOG_GENERAL, "You're using an outdated config."); + logMessage(LOG_GENERAL, "Updating config"); switch (config_version){ case 1: diff --git a/server/src/DatabaseHelper.cpp b/server/src/DatabaseHelper.cpp index 0f001b0..ffcf896 100644 --- a/server/src/DatabaseHelper.cpp +++ b/server/src/DatabaseHelper.cpp @@ -65,7 +65,7 @@ int collectData(deque>* list, int length, char** else if(strcmp(columns[index], "lastName") == 0) entry->lastName = values[index]; else if(strcmp(columns[index], "serverId") == 0); - else logError("Invalid db key for manager data. Key: " + string(columns[index])); + else logError(LOG_GENERAL, "Invalid db key for manager data. Key: {}", columns[index]); list->push_back(entry); return 0; @@ -82,7 +82,7 @@ std::deque> DatabaseHelper::queryDatabaseInf for(auto elm : list) query += " `cldbid` = " + to_string(elm) + " OR"; query = query.substr(0, query.length() - 3) + ")"; - logTrace("[SQL] queryDatabseInfo(...) -> " + query); + logTrace(server ? server->getServerId() : 0, "[SQL] queryDatabseInfo(...) -> {}", query); auto state = sql::command(this->sql, query, variable{":serverId", server ? server->getServerId() : 0}).query(std::function(collectData), &result); auto pf = LOG_SQL_CMD; pf(state); @@ -112,7 +112,7 @@ std::deque> DatabaseHelper::queryDatabaseInf for(const auto &elm : list) query += " `clientUid` = '" + elm + "' OR"; query = query.substr(0, query.length() - 3) + ")"; - logTrace("[SQL] queryDatabseInfoByUid(...) -> " + query); + logTrace(server ? server->getServerId() : 0, "[SQL] queryDatabseInfoByUid(...) -> {}", query); auto state = sql::command(this->sql, query, variable{":serverId", server ? server->getServerId() : 0}).query(function(collectData), &result); auto pf = LOG_SQL_CMD; pf(state); diff --git a/server/src/InstanceHandler.cpp b/server/src/InstanceHandler.cpp index cd57cb9..e37ed8f 100644 --- a/server/src/InstanceHandler.cpp +++ b/server/src/InstanceHandler.cpp @@ -248,7 +248,7 @@ bool InstanceHandler::startInstance() { } this->sslMgr = new ssl::SSLManager(); if(!this->sslMgr->initialize()) { - logCritical("Failed to initialize ssl manager."); + logCritical(LOG_GENERAL, "Failed to initialize ssl manager."); return false; } @@ -363,7 +363,7 @@ FwIDAQAB -----END PUBLIC KEY----- )", error, true); if(!rsa) { //TODO just disable the forum verification - logCritical("Failed to initialize WebClient TeaForum key! (" + error + ")"); + logCritical(LOG_GENERAL, "Failed to initialize WebClient TeaForum key! ({})", error); return false; } this->web_event_loop = make_shared(); diff --git a/server/src/ServerManager.cpp b/server/src/ServerManager.cpp index 6c74428..43c2279 100644 --- a/server/src/ServerManager.cpp +++ b/server/src/ServerManager.cpp @@ -62,10 +62,10 @@ bool ServerManager::initialize(bool autostart) { this->execute_loop->initialize(1); this->state = State::STARTING; - logMessage("Generating server puzzles..."); + logMessage(LOG_INSTANCE, "Generating server puzzles..."); auto start = system_clock::now(); this->puzzles->precomputePuzzles(config::voice::DefaultPuzzlePrecomputeSize); - logMessage("Puzzles generated! Time required: " + to_string(duration_cast(system_clock::now() - start).count()) + "ms"); + logMessage(LOG_INSTANCE, "Puzzles generated! Time required: " + to_string(duration_cast(system_clock::now() - start).count()) + "ms"); size_t serverCount = 0; sql::command(this->handle->getSql(), "SELECT COUNT(`serverId`) FROM `servers`").query([](size_t& ptr, int, char** v, char**) { ptr = stoll(v[0]); return 0; }, serverCount); @@ -139,7 +139,7 @@ bool ServerManager::initialize(bool autostart) { if(!server->start(msg)) logError(server->getServerId(), "Failed to start server.\n Message: " + msg); } catch (const std::exception& ex) { - logError(string() + "Could not start server! Got an active exception. Message " + ex.what()); + logError(server->getServerId(), "Could not start server! Got an active exception. Message {}", ex.what()); } } if(id > 0) @@ -400,9 +400,9 @@ void ServerManager::executeAutostart() { string msg; try { if(!server->start(msg)) - logError(server->getServerId(), "Failed to start server.\n Message: " + msg); + logError(server->getServerId(), "Failed to start server.\n Message:{}", msg); } catch (const std::exception& ex) { - logError(string() + "Could not start server! Got an active exception. Message " + ex.what()); + logError(server->getServerId(), "Could not start server! Got an active exception. Message {}", ex.what()); } } } diff --git a/server/src/ServerManagerSnapshotDeploy.cpp b/server/src/ServerManagerSnapshotDeploy.cpp index 49187a0..aca85ad 100644 --- a/server/src/ServerManagerSnapshotDeploy.cpp +++ b/server/src/ServerManagerSnapshotDeploy.cpp @@ -657,7 +657,7 @@ std::shared_ptr ServerManager::createServerFromSnapshot(shared_ptractive = false; current->shutdownNotify.notify_all(); if(!threads::save_join(current->shutdown_thread)) { - logCritical("Could not terminal shutdown thread!"); + logCritical(LOG_GENERAL, "Could not terminate shutdown thread!"); current->shutdown_thread.detach(); } currentShutdown = nullptr; diff --git a/server/src/SignalHandler.cpp b/server/src/SignalHandler.cpp index 8177eea..ebe7140 100644 --- a/server/src/SignalHandler.cpp +++ b/server/src/SignalHandler.cpp @@ -14,12 +14,12 @@ namespace fs = std::experimental::filesystem; google_breakpad::ExceptionHandler* globalExceptionHandler = nullptr; #define SIG(s, c) \ - if(signal(s, c) != nullptr) logError(lstream << "Cant setup " #s); + if(signal(s, c) != nullptr) logError(LOG_GENERAL, "Cant setup signal handler for " #s); extern bool mainThreadDone; static bool dumpCallback(const google_breakpad::MinidumpDescriptor& descriptor, void* context, bool succeeded) { - logCritical("The server crashed!"); + logCritical(LOG_GENERAL, "The server crashed!"); try { if(!fs::exists(fs::u8path(ts::config::crash_path))) fs::create_directories(fs::u8path(ts::config::crash_path)); @@ -27,9 +27,9 @@ static bool dumpCallback(const google_breakpad::MinidumpDescriptor& descriptor, auto path = fs::u8path(descriptor.path()); path = fs::u8path(ts::config::crash_path + "crash_dump_" + path.filename().string()); fs::rename(fs::u8path(descriptor.path()), path); - logCritical("Wrote crash dump to " + path.relative_path().string()); + logCritical(LOG_GENERAL, "Wrote crash dump to " + path.relative_path().string()); } catch (...) { - logCritical("Failed to write/move crash dump!"); + logCritical(LOG_GENERAL, "Failed to write/move crash dump!"); } if(std::current_exception()) { logCritical(LOG_GENERAL, "Exception reached stack root and cause the server to crash!"); @@ -40,10 +40,10 @@ static bool dumpCallback(const google_breakpad::MinidumpDescriptor& descriptor, logCritical(LOG_GENERAL, " Message: {}", ex.what()); } catch(...) {} } - logCritical("Please report this crash to the TeaSpeak maintainer WolverinDEV"); - logCritical("Official issue and bug tracker url: https://github.com/TeaSpeak/TeaSpeak/issues"); - logCritical("Any reports of crashes are useless if you not provide the above generated crashlog!"); - logCritical("Stopping server"); + logCritical(LOG_GENERAL, "Please report this crash to the TeaSpeak maintainer WolverinDEV"); + logCritical(LOG_GENERAL, "Official issue and bug tracker url: https://github.com/TeaSpeak/TeaSpeak/issues"); + logCritical(LOG_GENERAL, "Any reports of crashes are useless if you not provide the above generated crashlog!"); + logCritical(LOG_GENERAL, "Stopping server"); ts::server::shutdownInstance(ts::config::messages::applicationCrashed); while(!mainThreadDone) threads::self::sleep_for(chrono::seconds(1)); return succeeded; @@ -51,11 +51,11 @@ static bool dumpCallback(const google_breakpad::MinidumpDescriptor& descriptor, std::atomic spawn_failed_count = 0; bool ts::syssignal::setup() { - logMessage("Setting up exception handler"); + logMessage(LOG_GENERAL, "Setting up exception handler"); globalExceptionHandler = new google_breakpad::ExceptionHandler(google_breakpad::MinidumpDescriptor("."), nullptr, dumpCallback, nullptr, true, -1); SIG(SIGTERM, &ts::syssignal::handleStopSignal); - if(isatty(fileno(stdin))) //We cant listen for this siganl if stdin ist a atty + if(isatty(fileno(stdin))) //We cant listen for this signal if stdin ist a atty SIG(SIGINT, &ts::syssignal::handleStopSignal); return true; diff --git a/server/src/TS3ServerClientManager.cpp b/server/src/TS3ServerClientManager.cpp index dae1e40..9e29f85 100644 --- a/server/src/TS3ServerClientManager.cpp +++ b/server/src/TS3ServerClientManager.cpp @@ -183,14 +183,17 @@ bool TSServer::assignDefaultChannel(const shared_ptr& client, b channel = this->channelTree->findChannelByPath(str); if (channel) { if(!channel->permission_granted(permission::i_channel_needed_join_power, client->calculate_permission_value(permission::i_channel_join_power, channel->channelId()), false)) { - logMessage(this->serverId, "[{}] Client tried to connect to a channel which he hasn't permission for. Channel: {} ({})", CLIENT_STR_LOG_PREFIX_(client), channel->channelId(), channel->name()); + logMessage(this->serverId, "{} Client tried to connect to a channel which he hasn't permission for. Channel: {} ({})", CLIENT_STR_LOG_PREFIX_(client), channel->channelId(), channel->name()); channel = nullptr; } else if (!channel->passwordMatch(client->properties()[property::CLIENT_DEFAULT_CHANNEL_PASSWORD], true) && client->permissionValue(permission::PERMTEST_ORDERED, permission::b_channel_join_ignore_password, channel) < 1) { - logMessage(this->serverId, "[{}] Client tried to connect to a channel which is password protected and he hasn't the right password. Channel: {} ({})", CLIENT_STR_LOG_PREFIX_(client), channel->channelId(), channel->name()); + logMessage(this->serverId, "{} Client tried to connect to a channel which is password protected and he hasn't the right password. Channel: {} ({})", CLIENT_STR_LOG_PREFIX_(client), channel->channelId(), channel->name()); channel = nullptr; } } else - logMessage("Client " + client->getDisplayName() + "/" + client->getUid() + " tried to join on a not existing channel. Name: " + client->properties()[property::CLIENT_DEFAULT_CHANNEL].as()); + logMessage(this->serverId, "{} Client {}/{} tried to join on a not existing channel. Name: {}", + CLIENT_STR_LOG_PREFIX_(client), + client->getDisplayName(), client->getUid(), + client->properties()[property::CLIENT_DEFAULT_CHANNEL].as()); } if(!channel) channel = this->channelTree->getDefaultChannel(); if(!channel) return false; diff --git a/server/src/TSServer.cpp b/server/src/TSServer.cpp index d8aa491..5177f47 100644 --- a/server/src/TSServer.cpp +++ b/server/src/TSServer.cpp @@ -493,7 +493,7 @@ void TSServer::stop(const std::string& reason) { } else if(cl->getType() == CLIENT_INTERNAL) { } else { - logError("Got manager with unknown type: " + to_string(cl->getType())); + logError(this->serverId, "Got client with unknown type: " + to_string(cl->getType())); } } this->musicManager->disconnectBots(); diff --git a/server/src/channel/ServerChannel.cpp b/server/src/channel/ServerChannel.cpp index e03a5f6..8282f53 100644 --- a/server/src/channel/ServerChannel.cpp +++ b/server/src/channel/ServerChannel.cpp @@ -218,7 +218,7 @@ inline std::shared_ptr buildChannelTree(ServerId serv if(channel->channelOrder() != 0) { if(channel->channelOrder() == channel->channelId()) { brokenTree = true; - logError("Channel order refers to itself! (Resetting)"); + logError(serverId, "Channel order refers to itself! (Resetting)"); channel->properties()[property::CHANNEL_ORDER] = 0; continue; } @@ -475,7 +475,7 @@ void ServerChannelTree::loadChannelsFromDatabase() { return; } - logMessage(this->getServerId(), lstream << "Got " << this->tmpChannelList.size() << " saved channels" << endl); + logMessage(this->getServerId(), "Loaded {} saved channels. Assembling...", this->tmpChannelList.size()); this->initializeTempParents(); this->buildChannelTreeFromTemp(); this->validateChannelNames(); diff --git a/server/src/client/ConnectedClientCommandHandler.cpp b/server/src/client/ConnectedClientCommandHandler.cpp index 01406ab..767501d 100644 --- a/server/src/client/ConnectedClientCommandHandler.cpp +++ b/server/src/client/ConnectedClientCommandHandler.cpp @@ -1,5 +1,7 @@ #include +#include + #include #include #include @@ -475,7 +477,8 @@ CommandResult ConnectedClient::handleCommandServerEdit(Command &cmd) { serverInstance->getWebList()->enable_report(target_server); else serverInstance->getWebList()->disable_report(target_server); - debugMessage(string() + "Changed weblist state to -> " + (cmd["virtualserver_weblist_enabled"].as() ? "activated" : "disabled")); + debugMessage(target_server->getServerId(), "Changed weblist state to -> {}", + cmd["virtualserver_weblist_enabled"].as() ? "activated" : "disabled"); } } SERVEREDIT_CHK_PROP_CACHED("virtualserver_needed_identity_security_level", permission::b_virtualserver_modify_needed_identity_security_level, int) } @@ -3812,7 +3815,7 @@ CommandResult ConnectedClient::handleCommandFTDeleteFile(Command &cmd) { for (const auto &file : files) { if (!file) continue; if (!serverInstance->getFileServer()->deleteFile(file)) { - logCritical(this->getServerId(), lstream << "Cound not delete file " << file->path << "/" << file->name); + logCritical(this->getServerId(), "Could not delete file {}/{}", file->path, file->name); } } @@ -7370,8 +7373,12 @@ CommandResult ConnectedClient::handleCommandLogView(ts::Command& cmd) { PERM_CHECKR(permission::b_virtualserver_log_view, 1, true); for(const auto& sink : logger::logger(target_server)->sinks()) { - if(dynamic_pointer_cast(sink)) { - log_path = dynamic_pointer_cast(sink)->_file_helper.filename(); + if(dynamic_pointer_cast(sink)) { + log_path = dynamic_pointer_cast(sink)->filename(); + break; + } else if(dynamic_pointer_cast(sink)) { + log_path = dynamic_pointer_cast(sink)->filename(); + break; } } if(log_path.empty()) diff --git a/server/src/client/DataClient.cpp b/server/src/client/DataClient.cpp index 42a3a67..c9c4778 100644 --- a/server/src/client/DataClient.cpp +++ b/server/src/client/DataClient.cpp @@ -220,8 +220,12 @@ bool DataClient::permissionGranted(PermissionTestType test, permission::Permissi auto client = dynamic_cast(this); if(client) serverId = client->getServerId(); - debugMessage(serverId, lstream << "[Permission] Value test result for test type " << test << "."); - debugMessage(serverId, lstream << "[Permission] Permission: " << permission::resolvePermissionData(type)->name << " Required value: " << required << " Gained value: " << value << " Force required: " << force_granted << " Channel: " << (target ? target->name() : "none") << " Result: " << result); + debugMessage(serverId, "[Permission] Value test result for test type {}.", test); + debugMessage(serverId, + "[Permission] Permission: {} Required value: {} Gained value: {} Force required: {} Channel: {} Result: {}", + permission::resolvePermissionData(type)->name, + required, value, force_granted, (target ? target->name() : "none"), result + ); }; #endif return result; @@ -237,8 +241,12 @@ bool DataClient::permissionGrantGranted(PermissionTestType test, permission::Per auto client = dynamic_cast(this); if(client) serverId = client->getServerId(); - debugMessage(serverId, lstream << "[Permission] Grant test result for test type " << test << "."); - debugMessage(serverId, lstream << "[Permission] Permission: " << permission::resolvePermissionData(type)->name << " Required value: " << required << " Gained value: " << value << " Force required: " << force_granted << " Channel: " << (target ? target->name() : "none") << " Result: " << result); + debugMessage(serverId, "[Permission] Grant test result for test type {}.", test); + debugMessage(serverId, + "[Permission] Permission: {} Required value: {} Gained value: {} Force required: {} Channel: {} Result: {}", + permission::resolvePermissionData(type)->name, + required, value, force_granted, (target ? target->name() : "none"), result + ); }; #endif return result; diff --git a/server/src/client/InternalClient.cpp b/server/src/client/InternalClient.cpp index 28bd25f..d3eecb3 100644 --- a/server/src/client/InternalClient.cpp +++ b/server/src/client/InternalClient.cpp @@ -27,7 +27,7 @@ void InternalClient::sendCommand(const ts::Command &command, bool low) { } bool InternalClient::closeConnection(const std::chrono::system_clock::time_point& timeout) { - logError("Internal manager is force to disconnect?"); + logError(this->getServerId(), "Internal client is force to disconnect?"); if(this->server) this->server->unregisterInternalClient(static_pointer_cast(_this.lock())); diff --git a/server/src/client/SpeakingClientHandshake.cpp b/server/src/client/SpeakingClientHandshake.cpp index 812503a..2e645cb 100644 --- a/server/src/client/SpeakingClientHandshake.cpp +++ b/server/src/client/SpeakingClientHandshake.cpp @@ -57,39 +57,51 @@ CommandResult SpeakingClient::handleCommandHandshakeBegin(Command& cmd) { //If ! try { this->handshake.identityData = make_shared(); this->handshake.proof_message = cmd["data"].string(); - Json::Reader reader; - std::istringstream stream(this->handshake.proof_message); - reader.parse(stream, *this->handshake.identityData); - if(!stream) return {findError("web_handshake_invalid"), "invalid json!"}; - if((*this->handshake.identityData)["user_id"].isNull()) return {findError("web_handshake_invalid"), "Missing json data!"}; - if((*this->handshake.identityData)["user_name"].isNull()) return {findError("web_handshake_invalid"), "Missing json data!"}; - if((*this->handshake.identityData)["user_group"].isNull()) return {findError("web_handshake_invalid"), "Missing json data!"}; - if((*this->handshake.identityData)["user_groups"].isNull()) return {findError("web_handshake_invalid"), "Missing json data!"}; - if((*this->handshake.identityData)["data_age"].isNull()) return {findError("web_handshake_invalid"), "Missing json data!"}; + std::string error{}; + Json::CharReaderBuilder rbuilder{}; + const std::unique_ptr reader(rbuilder.newCharReader()); + + auto& json_str = this->handshake.proof_message; + if(!reader->parse(json_str.data(), json_str.data() + json_str.size(), &*this->handshake.identityData, &error)) { + debugMessage(this->getServerId(), "[{}] Failed to parse forum account data: {}", error); + return {findError("web_handshake_invalid"), "invalid json!"}; + } + + auto& json_data = *this->handshake.identityData; + if(json_data["user_id"].isNull()) + return {findError("web_handshake_invalid"), "Missing json data (user_id)!"}; + if(json_data["user_name"].isNull()) + return {findError("web_handshake_invalid"), "Missing json data (user_name)!"}; + if(json_data["user_group"].isNull()) + return {findError("web_handshake_invalid"), "Missing json data (user_group)!"}; + if(json_data["user_groups"].isNull()) + return {findError("web_handshake_invalid"), "Missing json data (user_groups)!"}; + if(json_data["data_age"].isNull()) + return {findError("web_handshake_invalid"), "Missing json data (data_age)!"}; //Type test - (*this->handshake.identityData)["user_id"].asInt64(); + json_data["user_id"].asInt64(); - if((*this->handshake.identityData)["data_age"].asUInt64() < duration_cast((system_clock::now() - hours(72)).time_since_epoch()).count()) + if(json_data["data_age"].asUInt64() < duration_cast((system_clock::now() - hours(72)).time_since_epoch()).count()) return {findError("web_handshake_invalid"), "Provided data is too old!"}; - this->properties()[property::CLIENT_UNIQUE_IDENTIFIER] = base64::encode(digest::sha1("TeaSpeak-Forum#" + (*this->handshake.identityData)["user_id"].asString())); + this->properties()[property::CLIENT_UNIQUE_IDENTIFIER] = base64::encode(digest::sha1("TeaSpeak-Forum#" + json_data["user_id"].asString())); - this->properties()[property::CLIENT_TEAFORO_ID] = (*this->handshake.identityData)["user_id"].asInt64(); - this->properties()[property::CLIENT_TEAFORO_NAME] = (*this->handshake.identityData)["user_name"].asString(); + this->properties()[property::CLIENT_TEAFORO_ID] = json_data["user_id"].asInt64(); + this->properties()[property::CLIENT_TEAFORO_NAME] = json_data["user_name"].asString(); { ///* 0x01 := Banned | 0x02 := Stuff | 0x04 := Premium */ uint64_t flags = 0; - if((*this->handshake.identityData)["is_banned"].isBool() && (*this->handshake.identityData)["is_banned"].asBool()) + if(json_data["is_banned"].isBool() && json_data["is_banned"].asBool()) flags |= 0x01U; - if((*this->handshake.identityData)["is_staff"].isBool() && (*this->handshake.identityData)["is_staff"].asBool()) + if(json_data["is_staff"].isBool() && json_data["is_staff"].asBool()) flags |= 0x02U; - if((*this->handshake.identityData)["is_premium"].isBool() && (*this->handshake.identityData)["is_premium"].asBool()) + if(json_data["is_premium"].isBool() && json_data["is_premium"].asBool()) flags |= 0x04U; this->properties()[property::CLIENT_TEAFORO_FLAGS] = flags; diff --git a/server/src/client/music/MusicClient.cpp b/server/src/client/music/MusicClient.cpp index 8ff7c34..b970cc7 100644 --- a/server/src/client/music/MusicClient.cpp +++ b/server/src/client/music/MusicClient.cpp @@ -96,7 +96,7 @@ MusicClient::~MusicClient() { void MusicClient::sendCommand(const ts::Command &command, bool low) { } bool MusicClient::closeConnection(const std::chrono::system_clock::time_point&) { - logError("Music manager is forced to disconnect!"); + logError(this->getServerId(), "Music manager is forced to disconnect!"); /* if(this->server) diff --git a/server/src/client/query/QueryClient.cpp b/server/src/client/query/QueryClient.cpp index eacd78d..a3043c7 100644 --- a/server/src/client/query/QueryClient.cpp +++ b/server/src/client/query/QueryClient.cpp @@ -124,7 +124,7 @@ void QueryClient::writeMessage(const std::string& message) { if(this->connectionType == ConnectionType::PLAIN) this->writeRawMessage(message); else if(this->connectionType == ConnectionType::SSL_ENCRIPTED) this->ssl_handler.send(pipes::buffer_view{(void*) message.data(), message.length()}); - else logCritical("Invalid query connection type!"); + else logCritical(LOG_GENERAL, "Invalid query connection type to write to!"); } diff --git a/server/src/client/query/QueryClientCommands.cpp b/server/src/client/query/QueryClientCommands.cpp index 1858a34..b96c471 100644 --- a/server/src/client/query/QueryClientCommands.cpp +++ b/server/src/client/query/QueryClientCommands.cpp @@ -135,7 +135,7 @@ CommandResult QueryClient::handleCommandLogin(Command& cmd) { username = cmd[0][0].key(); password = cmd[0][1].key(); } - debugMessage("Attempted query login with " + username + " - " + password); + debugMessage(LOG_QUERY, "Having query login attempt for username {}", username); auto _account = serverInstance->getQueryServer()->find_query_account_by_name(username); auto account = _account ? serverInstance->getQueryServer()->load_password(_account) : nullptr; @@ -374,7 +374,6 @@ CommandResult QueryClient::handleCommandJoin(Command &) { if(this->currentChannel) return {findError("server_already_joined"), "already joined!"}; - debugMessage("Uid -> " + this->properties()[property::CLIENT_UNIQUE_IDENTIFIER].as()); this->server->assignDefaultChannel(this->ref(), true); return CommandResult::Success; } @@ -811,7 +810,7 @@ CommandResult QueryClient::handleCommandServerSnapshotDeploy(Command& cmd) { auto hash = cmd["hash"].string(); if(hash.empty()) return {findError("parameter_invalid"), "Invalid hash (not present)"}; - debugMessage("Hash: '" + hash + "'"); + debugMessage(this->getServerId(), "Serversnapshot calculated hash: {}", hash); bool mapping = cmd.hasParm("mapping"); cmd.disableParm("mapping"); @@ -834,7 +833,7 @@ CommandResult QueryClient::handleCommandServerSnapshotDeploy(Command& cmd) { Command res(""); if(!result){ - logError("Could not apply server snapshot: " + error); + logError(this->getServerId(), "Could not apply server snapshot: {}", error); res["success"] = false; res["sid"] = 0; res["message"] = error; @@ -929,7 +928,7 @@ CommandResult QueryClient::handleCommandServerNotifyRegister(Command &cmd) { CMD_REQ_PARM("event"); CMD_RESET_IDLE; if(!cmd[0].has("specifier") && cmd["event"].as() != "all") { //Lagacy support - logMessage("[Query] Client " + this->getLoggingPeerIp() + ":" + to_string(this->getPeerPort()) + " uses the lagacy notify system, which is deprecated!"); + logMessage(this->getServerId(), "{} Client {}:{} uses the lagacy notify system, which is deprecated!", CLIENT_STR_LOG_PREFIX, this->getLoggingPeerIp(), this->getPeerPort()); string event = cmd["event"]; std::transform(event.begin(), event.end(), event.begin(), ::tolower); #include "XMacroEventTypes.h" @@ -985,7 +984,7 @@ CommandResult QueryClient::handleCommandServerNotifyUnregister(Command &cmd) { CMD_REQ_PARM("event"); CMD_RESET_IDLE; if(!cmd[0].has("specifier")){ - logMessage("[Query] Client " + this->getLoggingPeerIp() + ":" + to_string(this->getPeerPort()) + " uses the lagacy notify system, which is deprecated!"); + logMessage(this->getServerId(), "{} Client {}:{} uses the lagacy notify system, which is deprecated!", CLIENT_STR_LOG_PREFIX, this->getLoggingPeerIp(), this->getPeerPort()); string event = cmd["event"]; std::transform(event.begin(), event.end(), event.begin(), ::tolower); #include "XMacroEventTypes.h" diff --git a/server/src/client/voice/VoiceClient.cpp b/server/src/client/voice/VoiceClient.cpp index 29c2179..698008c 100644 --- a/server/src/client/voice/VoiceClient.cpp +++ b/server/src/client/voice/VoiceClient.cpp @@ -42,7 +42,7 @@ VoiceClient::~VoiceClient() { this->connection = nullptr; if(this->flushing_thread) - logCritical(0, "Deleting a VoiceClient which should still be hold within the flush thread!"); + logCritical(this->getServerId(), "Deleting a VoiceClient which should still be hold within the flush thread!"); memtrack::freed(this); } @@ -50,7 +50,7 @@ VoiceClient::~VoiceClient() { void VoiceClient::sendCommand0(const ts::Command &command, bool low, bool direct, std::unique_ptr> listener) { auto cmd = command.build(); if(cmd.empty()) { - logCritical("Attempted to send an empty command!"); + logCritical(this->getServerId(), "{} Attempted to send an empty command!", CLIENT_STR_LOG_PREFIX); return; } diff --git a/server/src/client/voice/VoiceClientCommandHandler.cpp b/server/src/client/voice/VoiceClientCommandHandler.cpp index 8e39a8c..90949c0 100644 --- a/server/src/client/voice/VoiceClientCommandHandler.cpp +++ b/server/src/client/voice/VoiceClientCommandHandler.cpp @@ -29,13 +29,11 @@ CommandResult VoiceClient::handleCommand(ts::Command &command) { return SpeakingClient::handleCommand(command); } -inline int getSecurityLevel(ecc_key* pubKey, size_t offset) { +inline bool calculate_security_level(int& result, ecc_key* pubKey, size_t offset) { size_t pubLength = 256; char pubBuffer[256]; - if(ecc_export(reinterpret_cast(pubBuffer), &pubLength, PK_PUBLIC, pubKey) != CRYPT_OK){ - logError(lstream << "failed to export pub key" << endl); - return -1; - } + if((result = ecc_export(reinterpret_cast(pubBuffer), &pubLength, PK_PUBLIC, pubKey)) != CRYPT_OK) + return false; std::string hashStr = base64_encode(pubBuffer, pubLength) + to_string(offset); char shaBuffer[SHA_DIGEST_LENGTH]; @@ -53,7 +51,8 @@ inline int getSecurityLevel(ecc_key* pubKey, size_t offset) { else break; } } - return zeroBits; + result = zeroBits; + return true; } CommandResult VoiceClient::handleCommandClientInit(Command &cmd) { @@ -61,7 +60,11 @@ CommandResult VoiceClient::handleCommandClientInit(Command &cmd) { this->connection->acknowledge_handler.reset(); if(this->getType() == ClientType::CLIENT_TEAMSPEAK) { - auto securityLevel = getSecurityLevel(this->crypto.remote_key.get(), cmd["client_key_offset"]); + int securityLevel; + if(!calculate_security_level(securityLevel, this->crypto.remote_key.get(), cmd["client_key_offset"])) { + logError(this->getServerId(), "[{}] Failed to calculate security level. Error code: {}", CLIENT_STR_LOG_PREFIX, securityLevel); + return {ErrorType::VSError}; + } if(securityLevel < 8) return {findError("channel_invalid_security_hash"), "cant calculate security level"}; diff --git a/server/src/lincense/LicenseHelper.cpp b/server/src/lincense/LicenseHelper.cpp index 013156d..24b60ff 100644 --- a/server/src/lincense/LicenseHelper.cpp +++ b/server/src/lincense/LicenseHelper.cpp @@ -65,13 +65,13 @@ void LicenseHelper::tick() { } if(!response->license_valid || !response->properties_valid){ if(!response->license_valid) { - if(config::license->isPremium()) logCritical(strobf("Could not validate license.").c_str()); - else logCritical(strobf("Your server has been shutdown remotely!").c_str()); + if(config::license->isPremium()) logCritical(LOG_INSTANCE, strobf("Could not validate license.").c_str()); + else logCritical(LOG_INSTANCE, strobf("Your server has been shutdown remotely!").c_str()); } else if(!response->properties_valid) { - logCritical(strobf("Property adjustment failed!").c_str()); + logCritical(LOG_INSTANCE, strobf("Property adjustment failed!").c_str()); } else - logCritical(strobf("Your license expired!").c_str()); - logCritical(strobf("Stopping application!").c_str()); + logCritical(LOG_INSTANCE, strobf("Your license expired!").c_str()); + logCritical(LOG_INSTANCE, strobf("Stopping application!").c_str()); ts::server::shutdownInstance(); return; } else { @@ -138,11 +138,11 @@ void LicenseHelper::do_request(bool verbose) { #else auto license_host = gethostbyname(strobf("license.teaspeak.de").c_str()); if(!license_host){ - if(verbose) logError(strobf("Could not valid license! (1)").c_str()); + if(verbose) logError(LOG_INSTANCE, strobf("Could not valid license! (1)").c_str()); return; } if(!license_host->h_addr){ - if(verbose) logError(strobf("Could not valid license! (2)").c_str()); + if(verbose) logError(LOG_INSTANCE, strobf("Could not valid license! (2)").c_str()); return; } server_addr.sin_addr.s_addr = ((in_addr*) license_host->h_addr)->s_addr; @@ -150,9 +150,9 @@ void LicenseHelper::do_request(bool verbose) { int first = server_addr.sin_addr.s_addr >> 24; if(first == 0 || first == 127 || first == 255) { if(config::license->isPremium()) { - logError(strobf("You tried to nullroot 'license.teaspeak.de'!").c_str()); - logCritical(strobf("Could not validate license!").c_str()); - logCritical(strobf("Stopping server!").c_str()); + logError(LOG_INSTANCE, strobf("You tried to nullroot 'license.teaspeak.de'!").c_str()); + logCritical(LOG_INSTANCE, strobf("Could not validate license!").c_str()); + logCritical(LOG_INSTANCE, strobf("Stopping server!").c_str()); ts::server::shutdownInstance(); return; } diff --git a/server/src/manager/BanManager.cpp b/server/src/manager/BanManager.cpp index e4e78c7..be74d10 100644 --- a/server/src/manager/BanManager.cpp +++ b/server/src/manager/BanManager.cpp @@ -18,7 +18,7 @@ bool BanManager::loadBans() { this->current_ban_index.store(0); try { if(config::server::delete_old_bans) { - debugMessage("Deleting old bans"); + debugMessage(LOG_INSTANCE, "Deleting old bans"); LOG_SQL_CMD(sql::command(this->sql, "DELETE FROM `bannedClients` WHERE `until` < :now AND `until` > 0", variable{":now", duration_cast(system_clock::now().time_since_epoch()).count()}).execute()); } LOG_SQL_CMD(sql::command(this->sql, "SELECT `banId` FROM `bannedClients` ORDER BY `banId` DESC LIMIT 1").query([](atomic& counter, int, string* values, string*) { diff --git a/server/src/music/MusicBotManager.cpp b/server/src/music/MusicBotManager.cpp index c23e814..276fa34 100644 --- a/server/src/music/MusicBotManager.cpp +++ b/server/src/music/MusicBotManager.cpp @@ -239,7 +239,7 @@ int MusicBotManager::sqlCreateMusicBot(int length, std::string* values, std::str } handle->groups->enableCache(musicBot->getClientDatabaseId()); - if(musicBot->getClientDatabaseId() != botId) logCritical("Invalid music bot id mapping!"); + if(musicBot->getClientDatabaseId() != botId) logCritical(handle->getServerId(),"Invalid music bot id mapping!"); { auto playlist = this->find_playlist(musicBot->properties()[property::CLIENT_PLAYLIST_ID]); diff --git a/server/src/pinteraction/ApplicationInteraction.cpp b/server/src/pinteraction/ApplicationInteraction.cpp index fb9b321..dc9a4df 100644 --- a/server/src/pinteraction/ApplicationInteraction.cpp +++ b/server/src/pinteraction/ApplicationInteraction.cpp @@ -42,7 +42,7 @@ namespace interaction { DefaultMemoryInfo* info = nullptr; if(shmInfo.shm_nattch == 0){ //Im the first program! - debugMessage("Created new memory struct"); + debugMessage(LOG_GENERAL, "Created new memory struct"); *(DefaultMemoryInfo*) SHARED_MEMORY_PTR = DefaultMemoryInfo{}; info = (DefaultMemoryInfo*) SHARED_MEMORY_PTR; @@ -81,7 +81,7 @@ namespace interaction { auto instanceInfo = ownInfo(); instanceInfo->pid = ::getpid(); pthread_mutex_unlock(&info->memoryLock); - debugMessage("Got application instance id " + to_string(INSTANCE_ID)); + debugMessage(LOG_GENERAL, "Got application instance id {}", INSTANCE_ID); return true; } @@ -95,13 +95,13 @@ namespace interaction { shmid_ds info{}; memset(&info, 0, sizeof(info)); if(shmctl(SHARED_MEMORY_ID, IPC_STAT, &info) < 0){ - logMessage(lstream << "Could not collect info: " << strerror(errno)); + logMessage(LOG_INSTANCE, "Could not collect info: {}", errno); return; } if(info.shm_nattch == 0){ shmctl(SHARED_MEMORY_ID, IPC_RMID, nullptr); - logMessage("Deleting shared memory"); + logMessage(LOG_INSTANCE, "Deleting shared memory"); } } diff --git a/server/src/server/VoiceServer.cpp b/server/src/server/VoiceServer.cpp index 814312e..f99f615 100644 --- a/server/src/server/VoiceServer.cpp +++ b/server/src/server/VoiceServer.cpp @@ -248,7 +248,7 @@ bool VoiceServer::unregisterConnection(std::shared_ptr connection) auto found = std::find(this->activeConnections.begin(), this->activeConnections.end(), connection); if(found != activeConnections.end()) this->activeConnections.erase(found); - else logError("unregisterConnection(...) -> could not find client"); + else logError(LOG_GENERAL, "unregisterConnection(...) -> could not find client"); return true; } diff --git a/server/src/terminal/CommandHandler.cpp b/server/src/terminal/CommandHandler.cpp index ac2aa6a..cdb823b 100644 --- a/server/src/terminal/CommandHandler.cpp +++ b/server/src/terminal/CommandHandler.cpp @@ -40,7 +40,6 @@ namespace terminal { do { size_t next = str.find(' ', index); auto elm = str.substr(index, next - index); - debugMessage("Having message part: " + elm + " - " + to_string(index)); if(index == 0){ cmd.command = elm; @@ -194,7 +193,7 @@ namespace terminal { logError("Invalid mode/serverId"); return false; } - debugMessage("Chat message mode " + to_string(mode)); + debugMessage(LOG_GENERAL,"Chat message mode " + to_string(mode)); std::string message; int index = 3; diff --git a/shared b/shared index 41fb841..b9e2da8 160000 --- a/shared +++ b/shared @@ -1 +1 @@ -Subproject commit 41fb8415cdade6ea36cba2bb0221b7177710d41e +Subproject commit b9e2da8bb48ce74561c69cf5c5e3d252d6251ee9