From c710157030ae319c5038c4a13ed733d9b4498721 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Fri, 19 Jul 2019 19:42:57 +0200 Subject: [PATCH 1/6] fixed SIGILL in server select --- server/src/channel/ClientChannelView.h | 1 - server/src/client/query/QueryClient.h | 2 -- server/src/client/query/QueryClientCommands.cpp | 3 ++- shared | 2 +- 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/server/src/channel/ClientChannelView.h b/server/src/channel/ClientChannelView.h index fdc0f84..ea951bd 100644 --- a/server/src/channel/ClientChannelView.h +++ b/server/src/channel/ClientChannelView.h @@ -32,7 +32,6 @@ namespace ts { ChannelId cached_parent_id = 0; }; - typedef std::shared_lock TreeLock; class ClientChannelView : private TreeView { public: enum ChannelAction { diff --git a/server/src/client/query/QueryClient.h b/server/src/client/query/QueryClient.h index d215232..d430c7c 100644 --- a/server/src/client/query/QueryClient.h +++ b/server/src/client/query/QueryClient.h @@ -38,8 +38,6 @@ namespace ts { bool ignoresFlood() override; inline std::shared_ptr getQueryAccount() { return this->query_account; } - - std::shared_recursive_mutex server_lock; protected: void preInitialize(); void postInitialize(); diff --git a/server/src/client/query/QueryClientCommands.cpp b/server/src/client/query/QueryClientCommands.cpp index cc661b4..14019e4 100644 --- a/server/src/client/query/QueryClientCommands.cpp +++ b/server/src/client/query/QueryClientCommands.cpp @@ -318,7 +318,8 @@ CommandResult QueryClient::handleCommandServerSelect(Command &cmd) { //register at current server { - unique_lock server_lock(this->server_lock); + //unique_lock server_lock(this->server_lock); + /* We dont need to lock the server because only one command can be executed at the time. Everything else should copy the server once and test the copy and use that ref then */ this->server = target; } diff --git a/shared b/shared index 6ee207a..9833dab 160000 --- a/shared +++ b/shared @@ -1 +1 @@ -Subproject commit 6ee207aaadeb9a57a9e1fc4fd19ebeb1be81f1fd +Subproject commit 9833dab6e4f96c045da632c208aa1bc977d45349 From 98929707ae75673e194b62ce18cf3e2b77f61e9f Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Fri, 19 Jul 2019 21:32:31 +0200 Subject: [PATCH 2/6] Fixed --- server/src/client/ConnectedClient.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/server/src/client/ConnectedClient.cpp b/server/src/client/ConnectedClient.cpp index 4685bb4..7b68913 100644 --- a/server/src/client/ConnectedClient.cpp +++ b/server/src/client/ConnectedClient.cpp @@ -948,6 +948,13 @@ permission::v2::PermissionFlaggedValue ConnectedClient::calculate_permission_val return {index->second, index->second != permNotGranted}; } + auto ref_server = this->server; + if(ref_server) { + auto result = this->server->calculatePermissions2(this->getClientDatabaseId(), {permission}, this->getType(), channel_id, false); + if(!result.empty()) /* it should never be empty! */ + return result.back().second; + } + auto value = this->permissionValue(permission::PERMTEST_ORDERED, permission, nullptr); return {value, value != permNotGranted}; } \ No newline at end of file From d3cc5984e575691ec55b0501769bb35944cc00a7 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sun, 21 Jul 2019 10:57:01 +0200 Subject: [PATCH 3/6] fixed first instance setup miracle --- server/src/InstanceHandler.cpp | 2 +- server/src/InstanceHandlerSetup.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/server/src/InstanceHandler.cpp b/server/src/InstanceHandler.cpp index 795154d..103b91b 100644 --- a/server/src/InstanceHandler.cpp +++ b/server/src/InstanceHandler.cpp @@ -111,7 +111,7 @@ InstanceHandler::InstanceHandler(SqlDataManager *sql) : sql(sql) { this->groupManager = std::make_shared(nullptr, this->getSql()); this->groupManager->loadGroupFormDatabase(); - if (this->groupManager->availableServerGroups(false).empty()){ + if (this->groupManager->availableServerGroups(false).empty()) { if(!this->setupDefaultGroups()){ logCritical(LOG_INSTANCE, "Could not setup server instance! Stopping..."); mainThreadActive = false; diff --git a/server/src/InstanceHandlerSetup.cpp b/server/src/InstanceHandlerSetup.cpp index 31cdcc4..ce443ab 100644 --- a/server/src/InstanceHandlerSetup.cpp +++ b/server/src/InstanceHandlerSetup.cpp @@ -141,6 +141,7 @@ bool InstanceHandler::setupDefaultGroups() { } } } + this->save_group_permissions(); this->getSql()->pool->threads()->wait_for(); //Wait for all permissions to flush return true; } From a5e545afebb9af11c0c4552696b23aa901d5e768 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sun, 21 Jul 2019 12:32:29 +0200 Subject: [PATCH 4/6] fixed poke permissions --- server/src/client/ConnectedClientCommandHandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/client/ConnectedClientCommandHandler.cpp b/server/src/client/ConnectedClientCommandHandler.cpp index 7ee1e55..2e5ebaf 100644 --- a/server/src/client/ConnectedClientCommandHandler.cpp +++ b/server/src/client/ConnectedClientCommandHandler.cpp @@ -2222,7 +2222,7 @@ CommandResult ConnectedClient::handleCommandClientPoke(Command &cmd) { auto client = this->server->findClient(cmd["clid"].as()); if (!client) return {findError("client_invalid_id"), "invalid client id"}; if (client->getType() == CLIENT_MUSIC) return {findError("client_invalid_type"), "You cant poke a music bot!"}; - CACHED_PERM_CHECK(permission::i_client_poke_power, client->permissionValue(permission::PERMTEST_ORDERED, permission::i_client_needed_poke_power, client->currentChannel)); + CACHED_PERM_CHECK(permission::i_client_poke_power, client->permissionValue(permission::PERMTEST_ORDERED, permission::i_client_needed_poke_power, client->currentChannel), false); client->notifyClientPoke(_this.lock(), cmd["msg"]); return CommandResult::Success; From c9e257270f38f24e3290470f89640e6aecb57d34 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sun, 21 Jul 2019 14:56:53 +0200 Subject: [PATCH 5/6] Fixed a command packet order issue --- server/src/client/ConnectedClient.cpp | 7 ++++++- server/src/client/ConnectedClient.h | 1 + server/src/client/ConnectedClientCommandHandler.cpp | 8 ++++++-- server/src/client/voice/VoiceClient.h | 1 + shared | 2 +- 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/server/src/client/ConnectedClient.cpp b/server/src/client/ConnectedClient.cpp index 7b68913..81b1913 100644 --- a/server/src/client/ConnectedClient.cpp +++ b/server/src/client/ConnectedClient.cpp @@ -620,7 +620,12 @@ inline void send_channels(ConnectedClient* client, ChannelIT begin, const Channe if(++index > 6) break; } - client->sendCommand(channellist); + if(dynamic_cast(client)) { + auto vc = dynamic_cast(client); + vc->sendCommand0(channellist, false, true); /* we need to process this command directly so it will be processed before the channellistfinished stuff */ + } else { + client->sendCommand(channellist); + } if(begin != end) send_channels(client, begin, end, override_orderid); } diff --git a/server/src/client/ConnectedClient.h b/server/src/client/ConnectedClient.h index 010745f..7d5ad5f 100644 --- a/server/src/client/ConnectedClient.h +++ b/server/src/client/ConnectedClient.h @@ -121,6 +121,7 @@ namespace ts { bool isAddressV6() { return this->remote_address.ss_family == AF_INET6; } const sockaddr_in6* getAddressV6(){ return (sockaddr_in6*) &this->remote_address; } + /* Note: Order is not guaranteed here! */ virtual void sendCommand(const ts::Command& command, bool low = false) = 0; //General manager stuff diff --git a/server/src/client/ConnectedClientCommandHandler.cpp b/server/src/client/ConnectedClientCommandHandler.cpp index 2e5ebaf..ff237c8 100644 --- a/server/src/client/ConnectedClientCommandHandler.cpp +++ b/server/src/client/ConnectedClientCommandHandler.cpp @@ -3313,8 +3313,12 @@ CommandResult ConnectedClient::handleCommandFTGetFileList(Command &cmd) { } if (fileList[0].has("name")) { - this->sendCommand(fileList); - if (this->getExternalType() == CLIENT_TEAMSPEAK) this->sendCommand(fileListFinished); + if(dynamic_cast(this)) { + dynamic_cast(this)->sendCommand0(fileList, false, true); /* We need to process this directly else the order could get shuffeled up! */ + this->sendCommand(fileListFinished); + } else { + this->sendCommand(fileList); + } return CommandResult::Success; } else { return {findError("database_empty_result"), "empty"}; diff --git a/server/src/client/voice/VoiceClient.h b/server/src/client/voice/VoiceClient.h index 8173179..e5283f0 100644 --- a/server/src/client/voice/VoiceClient.h +++ b/server/src/client/voice/VoiceClient.h @@ -55,6 +55,7 @@ namespace ts { bool disconnect(ViewReasonId /* reason type */, const std::string& /* reason */, const std::shared_ptr& /* invoker */, bool /* notify viewer */); virtual void sendCommand(const ts::Command &command, bool low = false) { return this->sendCommand0(command, low); } + /* Note: Order is only guaranteed if progressDirectly is on! */ virtual void sendCommand0(const ts::Command &command, bool low = false, bool progressDirectly = false, std::unique_ptr> listener = nullptr); virtual void sendAcknowledge(uint16_t packetId, bool low = false); diff --git a/shared b/shared index 9833dab..a0cca36 160000 --- a/shared +++ b/shared @@ -1 +1 @@ -Subproject commit 9833dab6e4f96c045da632c208aa1bc977d45349 +Subproject commit a0cca36eca11da410626a340dbe4377067d59c1b From 1ac7c112d497e5f47be5c9ebb952dc556debbcad Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sun, 21 Jul 2019 14:58:16 +0200 Subject: [PATCH 6/6] improved stuff --- server/src/client/ConnectedClient.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server/src/client/ConnectedClient.cpp b/server/src/client/ConnectedClient.cpp index 81b1913..e5a2abe 100644 --- a/server/src/client/ConnectedClient.cpp +++ b/server/src/client/ConnectedClient.cpp @@ -766,7 +766,11 @@ void ConnectedClient::sendServerInit() { command["pv"] = 6; //Protocol version command["acn"] = this->getDisplayName(); command["aclid"] = this->getClientId(); - this->sendCommand(command); + if(dynamic_cast(this)) { + dynamic_cast(this)->sendCommand0(command, false, true); /* process it directly so the order for the channellist entries is ensured. (First serverinit then everything else) */ + } else { + this->sendCommand(command); + } } bool ConnectedClient::handleCommandFull(Command& cmd, bool disconnectOnFail) {