From 421f04fe6003a3995f0df2ecded0335cc78e70f3 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sat, 4 Apr 2020 12:22:20 +0200 Subject: [PATCH] Fixed some small stuff --- git-teaspeak | 2 +- server/src/client/command_handler/misc.cpp | 47 +++++++++++----------- shared | 2 +- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/git-teaspeak b/git-teaspeak index 15e5431..d4ffb41 160000 --- a/git-teaspeak +++ b/git-teaspeak @@ -1 +1 @@ -Subproject commit 15e54314da1903c0a70845180898e41b75749dbd +Subproject commit d4ffb41adc2fe5145be4ab343039e72f66058d33 diff --git a/server/src/client/command_handler/misc.cpp b/server/src/client/command_handler/misc.cpp index 4a5d189..a4123e2 100644 --- a/server/src/client/command_handler/misc.cpp +++ b/server/src/client/command_handler/misc.cpp @@ -767,7 +767,9 @@ command_result ConnectedClient::handleCommandBanClient(Command &cmd) { CMD_RESET_IDLE; CMD_CHK_AND_INC_FLOOD_POINTS(25); - string uid; + std::string target_unique_id{}; + ClientDbId target_database_id{0}; + string reason = cmd[0].has("banreason") ? cmd["banreason"].string() : ""; auto time = cmd[0].has("time") ? cmd["time"].as() : 0UL; chrono::time_point until = time > 0 ? chrono::system_clock::now() + chrono::seconds(time) : chrono::time_point(); @@ -776,43 +778,40 @@ command_result ConnectedClient::handleCommandBanClient(Command &cmd) { const auto no_hwid = cmd.hasParm("no-hardware-id"); const auto no_ip = cmd.hasParm("no-ip"); - deque> target_clients; + std::deque> target_clients; if (cmd[0].has("uid")) { - target_clients = this->server->findClientsByUid(uid = cmd["uid"].string()); - for(const auto& client : target_clients) - if(client->getType() == ClientType::CLIENT_MUSIC) - return command_result{error::client_invalid_id, "You cant ban a music bot!"}; + target_clients = this->server->findClientsByUid(target_unique_id = cmd["uid"].string()); + } else if(cmd[0].has("cldbid")) { + target_clients = this->server->findClientsByCldbId(target_database_id = cmd["cldbid"].as()); } else { target_clients = {this->server->find_client_by_id(cmd["clid"].as())}; if(!target_clients[0]) { return command_result{error::client_invalid_id, "Could not find target client"}; } - if(target_clients[0]->getType() == ClientType::CLIENT_MUSIC) { + } + + for(const auto& client : target_clients) + if(client->getType() == ClientType::CLIENT_MUSIC) return command_result{error::client_invalid_id, "You cant ban a music bot!"}; - } - uid = target_clients[0]->getUid(); - } - ClientDbId target_dbid = 0; - if (!target_clients.empty()) { - target_dbid = target_clients[0]->getClientDatabaseId(); - } else { - auto info = serverInstance->databaseHelper()->queryDatabaseInfoByUid(this->getServer(), {uid}); - if (!info.empty()) - target_dbid = info[0]->cldbid; - else - return command_result{error::client_unknown}; - } + if(!target_clients.empty()) { + if(target_unique_id.empty()) + target_unique_id = target_clients.back()->getUid(); - if(!permission::v2::permission_granted(this->server->calculate_permission(permission::i_client_needed_ban_power, target_dbid, ClientType::CLIENT_TEAMSPEAK, 0), this->calculate_permission(permission::i_client_ban_power, 0))) + if(!target_database_id) + target_database_id = target_clients.back()->getClientDatabaseId(); + } + if(!permission::v2::permission_granted(this->server->calculate_permission(permission::i_client_needed_ban_power, target_database_id, ClientType::CLIENT_TEAMSPEAK, 0), this->calculate_permission(permission::i_client_ban_power, 0))) return command_result{permission::i_client_ban_power}; - if (permission::v2::permission_granted(1, this->server->calculate_permission(permission::b_client_ignore_bans, target_dbid, ClientType::CLIENT_TEAMSPEAK, 0))) + if (permission::v2::permission_granted(1, this->server->calculate_permission(permission::b_client_ignore_bans, target_database_id, ClientType::CLIENT_TEAMSPEAK, 0))) return command_result{permission::b_client_ignore_bans}; deque ban_ids; - auto _id = serverInstance->banManager()->registerBan(this->getServer()->getServerId(), this->getClientDatabaseId(), reason, uid, "", "", "", until); - ban_ids.push_back(_id); + if(!target_unique_id.empty()) { + auto _id = serverInstance->banManager()->registerBan(this->getServer()->getServerId(), this->getClientDatabaseId(), reason, target_unique_id, "", "", "", until); + ban_ids.push_back(_id); + } auto b_ban_name = permission::v2::permission_granted(1, this->calculate_permission(permission::b_client_ban_name, 0), false); auto b_ban_ip = permission::v2::permission_granted(1, this->calculate_permission(permission::b_client_ban_ip, 0), false); diff --git a/shared b/shared index 9063e17..f86c9b5 160000 --- a/shared +++ b/shared @@ -1 +1 @@ -Subproject commit 9063e17efb1b1d837e771da6c8262b477b39cbb3 +Subproject commit f86c9b522a97ec6b524da3c7aa4bddffa54f7f38