From 7d0db0dea009dfd5695ac2db5a4378aaecb8ccd8 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sun, 23 Aug 2020 22:23:12 +0200 Subject: [PATCH] Some minor snapshot updates --- file/local_server/LocalFileProvider.cpp | 27 ---------------- git-teaspeak | 2 +- server/src/DatabaseHelper.cpp | 4 +-- server/src/snapshots/deploy.cpp | 42 +++++++++++++++++++++++-- shared | 2 +- 5 files changed, 44 insertions(+), 33 deletions(-) diff --git a/file/local_server/LocalFileProvider.cpp b/file/local_server/LocalFileProvider.cpp index 074a745..12202bc 100644 --- a/file/local_server/LocalFileProvider.cpp +++ b/file/local_server/LocalFileProvider.cpp @@ -57,33 +57,6 @@ bool file::initialize(std::string &error, const std::string& hostnames, uint16_t continue; } } -#if 0 - { - auto query_bindings_string = this->properties()[property::SERVERINSTANCE_QUERY_HOST].as(); - auto query_port = this->properties()[property::SERVERINSTANCE_QUERY_PORT].as(); - auto query_bindings = net::resolve_bindings(query_bindings_string, query_port); - deque> bindings; - - for(auto& binding : query_bindings) { - if(!get<2>(binding).empty()) { - logError(LOG_QUERY, "Failed to resolve binding for {}: {}", get<0>(binding), get<2>(binding)); - continue; - } - auto entry = make_shared(); - memcpy(&entry->address, &get<1>(binding), sizeof(sockaddr_storage)); - - entry->file_descriptor = -1; - entry->event_accept = nullptr; - bindings.push_back(entry); - } - - logMessage(LOG_QUERY, "Starting server on {}:{}", query_bindings_string, query_port); - if(!queryServer->start(bindings, errorMessage)) { - logCritical(LOG_QUERY, "Failed to start query server: {}", errorMessage); - return false; - } - } -#endif return true; } diff --git a/git-teaspeak b/git-teaspeak index d26d083..b83a798 160000 --- a/git-teaspeak +++ b/git-teaspeak @@ -1 +1 @@ -Subproject commit d26d083635929f4df73e94b3feca8287a0608612 +Subproject commit b83a798e5348cbf916b84c1ab684adbadbaf9a71 diff --git a/server/src/DatabaseHelper.cpp b/server/src/DatabaseHelper.cpp index a2c1070..fc43b2e 100644 --- a/server/src/DatabaseHelper.cpp +++ b/server/src/DatabaseHelper.cpp @@ -155,10 +155,10 @@ void DatabaseHelper::deleteClient(const std::shared_ptr& server, state = sql::command(this->sql, "DELETE FROM `assignedGroups` WHERE `serverId` = :sid AND `cldbid` = :id", variable{":sid", serverId}, variable{":id", cldbid}).execute(); if(serverId == 0) { - state = sql::command(this->sql, "DELETE FROM `clients_server` WHERE `server_id` = :sid AND `client_database_id` = :id", variable{":sid", serverId}, variable{":id", cldbid}).execute(); - } else { state = sql::command(this->sql, "DELETE FROM `clients_server` WHERE `client_database_id` = :id", variable{":id", cldbid}).execute(); state = sql::command(this->sql, "DELETE FROM `clients` WHERE `client_database_id` = :id", variable{":id", cldbid}).execute(); + } else { + state = sql::command(this->sql, "DELETE FROM `clients_server` WHERE `server_id` = :sid AND `client_database_id` = :id", variable{":sid", serverId}, variable{":id", cldbid}).execute(); } //TODO delete letters diff --git a/server/src/snapshots/deploy.cpp b/server/src/snapshots/deploy.cpp index 0d71c94..065f579 100644 --- a/server/src/snapshots/deploy.cpp +++ b/server/src/snapshots/deploy.cpp @@ -111,7 +111,7 @@ bool VirtualServerManager::try_deploy_snapshot(std::string &error, ts::ServerId sql::model insert_command{this->handle->getSql(), - "INSERT INTO `clients_server` (`server_id`, `client_unique_id`, `client_database_id`, `client_created`, `original_client_id`) SELECT :serverId, :uniqueId, `client_database_id`, :timestamp, :org_id FROM `clients` WHERE `client_unique_id` = :uniqueId;"}; + "INSERT INTO `clients_server` (`server_id`, `client_unique_id`, `client_database_id`, `client_nickname`, `client_created`, `original_client_id`) SELECT :serverId, :uniqueId, `client_database_id`, :nickname, :timestamp, :org_id FROM `clients` WHERE `client_unique_id` = :uniqueId;"}; insert_command.value(":serverId", target_server_id); @@ -119,7 +119,8 @@ bool VirtualServerManager::try_deploy_snapshot(std::string &error, ts::ServerId auto sqlResult = insert_command.command().values( variable{":uniqueId", client.unique_id}, variable{":timestamp", std::chrono::floor(client.timestamp_created.time_since_epoch()).count()}, - variable{":org_id", client.database_id} + variable{":org_id", client.database_id}, + variable{":nickname", client.nickname} ).execute(); if(!sqlResult) @@ -154,6 +155,43 @@ bool VirtualServerManager::try_deploy_snapshot(std::string &error, ts::ServerId error = "failed to query client database id mappings (" + map_query_result.fmtStr() + ")"; return false; } + + /* the descriptions */ + { + sql::InsertQuery insert_properties_query{"properties", + sql::Column("serverId"), + sql::Column("type"), + sql::Column("id"), + sql::Column("key"), + sql::Column("value") + }; + + + std::string description_property{property::describe(property::CLIENT_DESCRIPTION).name}; + for(const auto& client : snapshot_data.parsed_clients) { + if(client.description.empty()) { + continue; + } + + auto new_id = mappings.client_id.find(client.database_id); + if(new_id == mappings.client_id.end()) { + continue; + } + + insert_properties_query.add_entry( + target_server_id, + property::PROP_TYPE_CLIENT, + new_id->second, + description_property, + client.description + ); + } + + auto presult = insert_properties_query.execute(this->handle->getSql(), true); + if(!presult.has_succeeded()) { + logWarning(logging_server_id, "Failed to insert some client properties into the database ({} failed)", presult.failed_entries.size()); + } + } } /* channels */ diff --git a/shared b/shared index f80f629..4d7fabe 160000 --- a/shared +++ b/shared @@ -1 +1 @@ -Subproject commit f80f629496aa20d7d4c883c4f8554bcf9271816e +Subproject commit 4d7fabe2eae09068e0c3bb47e1b0d5d08df11e45