Some updates

This commit is contained in:
WolverinDEV
2020-04-28 18:27:49 +02:00
parent 633fe10821
commit ff88705f09
15 changed files with 120 additions and 79 deletions
@@ -1593,7 +1593,7 @@ command_result ConnectedClient::handleCommandChannelDelPerm(Command &cmd) {
for (int index = 0; index < cmd.bulkCount(); index++) {
PARSE_PERMISSION(cmd);
if(!permission::v2::permission_granted(0, this->calculate_permission(permType, channel_id, true))) {
if(!ignore_granted_values && !permission::v2::permission_granted(0, this->calculate_permission(permType, channel_id, true))) {
if(conOnError) continue;
return command_result{permission::i_permission_modify_power};
}
+33 -33
View File
@@ -62,11 +62,13 @@ command_result ConnectedClient::handleCommandClientKick(Command &cmd) {
CMD_REQ_SERVER;
CMD_CHK_AND_INC_FLOOD_POINTS(25);
command_result_bulk result{};
result.reserve(cmd.bulkCount());
std::vector<ConnectedLockedClient<ConnectedClient>> clients{};
clients.reserve(cmd.bulkCount());
auto type = cmd["reasonid"].as<ViewReasonId>();
auto single_client = cmd.bulkCount() == 1;
auto target_channel = type == ViewReasonId::VREASON_CHANNEL_KICK ? this->server->channelTree->getDefaultChannel() : nullptr;
auto kick_power = type == ViewReasonId::VREASON_CHANNEL_KICK ?
this->calculate_permission(permission::i_client_kick_from_channel_power, target_channel->channelId()) :
@@ -76,31 +78,28 @@ command_result ConnectedClient::handleCommandClientKick(Command &cmd) {
ConnectedLockedClient<ConnectedClient> client{this->server->find_client_by_id(cmd[index]["clid"].as<ClientId>())};
if (!client) {
if(single_client)
return command_result{error::client_invalid_id};
result.emplace_result(error::client_invalid_id);
continue;
}
if (client->getType() == CLIENT_MUSIC) {
if(single_client)
return command_result{error::client_invalid_type};
result.emplace_result(error::client_invalid_type);
continue;
}
if(type == ViewReasonId::VREASON_CHANNEL_KICK) {
if(!permission::v2::permission_granted(client->calculate_permission(permission::i_client_needed_kick_from_channel_power, client->getChannelId()), kick_power)) {
if(single_client)
return command_result{permission::i_client_needed_kick_from_channel_power};
result.emplace_result(permission::i_client_needed_kick_from_channel_power);
continue;
}
} else {
if(!permission::v2::permission_granted(client->calculate_permission(permission::i_client_needed_kick_from_server_power, client->getChannelId()), kick_power)) {
if(single_client)
return command_result{permission::i_client_needed_kick_from_server_power};
result.emplace_result(permission::i_client_needed_kick_from_server_power);
continue;
}
}
clients.emplace_back(std::move(client));
result.emplace_result(error::ok);
}
if (clients.empty())
return command_result{error::database_empty_result};
@@ -114,7 +113,7 @@ command_result ConnectedClient::handleCommandClientKick(Command &cmd) {
}
}
return command_result{error::ok};
return command_result{std::forward<command_result_bulk>(result)};
}
command_result ConnectedClient::handleCommandClientGetIds(Command &cmd) {
@@ -177,37 +176,35 @@ command_result ConnectedClient::handleCommandClientMove(Command &cmd) {
auto permission_error = this->calculate_and_get_join_state(channel);
if(permission_error != permission::unknown) return command_result{permission_error};
command_result_bulk result{};
result.reserve(cmd.bulkCount());
std::vector<ConnectedLockedClient<ConnectedClient>> clients{};
auto is_single_client = cmd.bulkCount() == 1;
for(size_t index{0}; index < cmd.bulkCount(); index++) {
auto target_client_id = cmd[index]["clid"].as<ClientId>();
ConnectedLockedClient target_client{target_client_id == 0 ? this->ref() : this->server->find_client_by_id(target_client_id)};
if(!target_client) {
if(is_single_client)
return command_result{error::client_invalid_id};
result.emplace_result(error::client_invalid_id);
continue;
}
if(!target_client->getChannel()) {
if(target_client.client != this) {
if(is_single_client)
return command_result{error::client_invalid_id};
result.emplace_result(error::client_invalid_id);
continue;
}
}
if(target_client.client != this) {
if(!permission::v2::permission_granted(target_client->calculate_permission(permission::i_client_needed_move_power, 0), this->calculate_permission(permission::i_client_move_power, 0))) {
if(is_single_client)
return command_result{permission::i_client_move_power};
result.emplace_result(permission::i_client_move_power);
continue;
}
}
clients.emplace_back(std::move(target_client));
result.emplace_result(permission::ok);
}
if(clients.empty())
return command_result{error::database_empty_result};
if (!channel->properties()[property::CHANNEL_FLAG_MAXCLIENTS_UNLIMITED].as<bool>() || !channel->properties()[property::CHANNEL_FLAG_MAXFAMILYCLIENTS_UNLIMITED].as<bool>()) {
if(!permission::v2::permission_granted(1, this->calculate_permission(permission::b_channel_join_ignore_maxclients, channel->channelId()))) {
@@ -257,7 +254,7 @@ command_result ConnectedClient::handleCommandClientMove(Command &cmd) {
channels.push_back(oldChannel);
}
for(auto oldChannel : channels) {
for(const auto& oldChannel : channels) {
if(!server_channel_w_lock.owns_lock())
server_channel_w_lock.lock();
if(oldChannel->channelType() == ChannelType::temporary && oldChannel->properties()[property::CHANNEL_DELETE_DELAY].as<int64_t>() == 0)
@@ -266,7 +263,7 @@ command_result ConnectedClient::handleCommandClientMove(Command &cmd) {
if(server_channel_w_lock.owns_lock())
server_channel_w_lock.unlock();
}
return command_result{error::ok};
return command_result{std::forward<command_result_bulk>(result)};
}
command_result ConnectedClient::handleCommandClientPoke(Command &cmd) {
@@ -274,42 +271,45 @@ command_result ConnectedClient::handleCommandClientPoke(Command &cmd) {
CMD_RESET_IDLE;
CMD_CHK_AND_INC_FLOOD_POINTS(25);
command_result_bulk result{};
result.reserve(cmd.bulkCount());
std::vector<ConnectedLockedClient<ConnectedClient>> clients{};
clients.reserve(cmd.bulkCount());
bool is_single_poke = cmd.bulkCount() == 1;
for(size_t index{0}; index < cmd.bulkCount(); index++) {
ConnectedLockedClient client{ this->server->find_client_by_id(cmd["clid"].as<ClientId>())};
ConnectedLockedClient client{ this->server->find_client_by_id(cmd[index]["clid"].as<ClientId>())};
if (!client) {
if(is_single_poke)
return command_result{error::client_invalid_id};
result.emplace_result(error::client_invalid_id);
continue;
}
if (client->getType() == CLIENT_MUSIC) {
if(is_single_poke)
return command_result{error::client_invalid_type};
result.emplace_result(error::client_invalid_type);
continue;
}
auto own_permission = this->calculate_permission(permission::i_client_poke_power, client->getChannelId());
if(!permission::v2::permission_granted(client->calculate_permission(permission::i_client_needed_poke_power, client->getChannelId()), own_permission)) {
if(is_single_poke)
return command_result{permission::i_client_poke_power};
result.emplace_result(permission::i_client_poke_power);
continue;
}
clients.push_back(std::move(client));
result.emplace_result(error::ok);
}
if(clients.empty())
return command_result{error::database_empty_result};
else if(clients.size() > 1) {
/* clients might be empty ;) */
if(clients.size() > 1) {
auto max_clients = this->calculate_permission(permission::i_client_poke_max_clients, 0);
if(!permission::v2::permission_granted(clients.size(), max_clients))
return command_result{permission::i_client_poke_max_clients};
}
for(auto& client : clients)
client->notifyClientPoke(_this.lock(), cmd["msg"]);
return command_result{error::ok};
return command_result{std::forward<command_result_bulk>(result)};
}
@@ -150,6 +150,8 @@ inline bool permission_require_granted_value(ts::permission::PermissionType type
case permission::i_max_playlist_size:
case permission::i_max_playlists:
case permission::i_client_poke_max_clients:
case permission::i_client_ban_max_bantime:
case permission::i_client_max_idletime:
case permission::i_group_sort_id:
+1 -2
View File
@@ -284,7 +284,6 @@ command_result ConnectedClient::handleCommandServerRequestConnectionInfo(Command
first_bulk.put_unchecked(property::CONNECTION_PACKETS_RECEIVED_TOTAL, std::accumulate(total_stats.connection_packets_received.begin(), total_stats.connection_packets_received.end(), 0U));
first_bulk.put_unchecked(property::CONNECTION_BYTES_RECEIVED_TOTAL, std::accumulate(total_stats.connection_bytes_received.begin(), total_stats.connection_bytes_received.end(), 0U));
first_bulk.put_unchecked(property::CONNECTION_BANDWIDTH_SENT_LAST_SECOND_TOTAL, std::accumulate(second_report.connection_bytes_sent.begin(), second_report.connection_bytes_sent.end(), 0U));
first_bulk.put_unchecked(property::CONNECTION_BANDWIDTH_SENT_LAST_MINUTE_TOTAL, std::accumulate(minute_report.connection_bytes_sent.begin(), minute_report.connection_bytes_sent.end(), 0U));
first_bulk.put_unchecked(property::CONNECTION_BANDWIDTH_RECEIVED_LAST_SECOND_TOTAL, std::accumulate(second_report.connection_bytes_received.begin(), second_report.connection_bytes_received.end(), 0U));
@@ -895,7 +894,7 @@ command_result ConnectedClient::handleCommandServerGroupDelPerm(Command &cmd) {
for (int index = 0; index < cmd.bulkCount(); index++) {
PARSE_PERMISSION(cmd);
if(!permission::v2::permission_granted(0, this->calculate_permission(permType, 0, true))) {
if(!ignore_granted_values && !permission::v2::permission_granted(0, this->calculate_permission(permType, 0, true))) {
if(conOnError) continue;
return command_result{permission::i_permission_modify_power};
}