Some minor changes and fixes
This commit is contained in:
parent
6605a440bd
commit
0cff59328f
@ -36,8 +36,9 @@ void ConnectionStatistics::logOutgoingPacket(const category::value &category, si
|
||||
this->statistics_second_current.connection_bytes_sent[category] += size;
|
||||
this->statistics_second_current.connection_packets_sent[category] += 1;
|
||||
|
||||
if(this->handle)
|
||||
if(this->handle) {
|
||||
this->handle->logOutgoingPacket(category, size);
|
||||
}
|
||||
}
|
||||
|
||||
/* file transfer */
|
||||
|
@ -572,9 +572,13 @@ bool ConnectedClient::notifyClientNeededPermissions() {
|
||||
auto permissions = this->cached_permissions;
|
||||
cache_lock.unlock();
|
||||
|
||||
for(const auto& value : permissions) {
|
||||
cmd[index]["permid"] = value.first;
|
||||
cmd[index++]["permvalue"] = value.second.has_value ? value.second.value : 0;
|
||||
for(const auto& [ key, value ] : permissions) {
|
||||
if(!value.has_value) {
|
||||
continue;
|
||||
}
|
||||
|
||||
cmd[index]["permid"] = key;
|
||||
cmd[index++]["permvalue"] = value.value;
|
||||
}
|
||||
|
||||
if(index == 0) {
|
||||
@ -586,22 +590,6 @@ bool ConnectedClient::notifyClientNeededPermissions() {
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void write_command_result_error(ts::command_builder_bulk bulk, const command_result& result, const std::string& errorCodeKey) {
|
||||
bulk.put_unchecked(errorCodeKey, (uint32_t) result.error_code());
|
||||
bulk.put_unchecked("msg", findError(result.error_code()).message);
|
||||
if(result.is_permission_error())
|
||||
bulk.put_unchecked("failed_permid", (uint32_t) result.permission_id());
|
||||
}
|
||||
|
||||
inline void write_command_result_detailed(ts::command_builder_bulk bulk, const command_result& result, const std::string& errorCodeKey) {
|
||||
auto details = result.details();
|
||||
bulk.put_unchecked(errorCodeKey, (uint32_t) details->error_id);
|
||||
bulk.put_unchecked("msg", findError(details->error_id).message);
|
||||
|
||||
for(const auto& extra : details->extra_properties)
|
||||
bulk.put(extra.first, extra.second);
|
||||
}
|
||||
|
||||
bool ConnectedClient::notifyError(const command_result& result, const std::string& retCode) {
|
||||
ts::command_builder command{"error"};
|
||||
|
||||
|
@ -1,18 +1,13 @@
|
||||
#include <iostream>
|
||||
#include <bitset>
|
||||
#include <algorithm>
|
||||
#include "ConnectedClient.h"
|
||||
#include "voice/VoiceClient.h"
|
||||
#include "../server/VoiceServer.h"
|
||||
#include "../InstanceHandler.h"
|
||||
#include "../server/QueryServer.h"
|
||||
#include "../manager/PermissionNameMapper.h"
|
||||
#include "music/MusicClient.h"
|
||||
#include <log/LogUtils.h>
|
||||
#include <misc/sassert.h>
|
||||
#include <misc/timer.h>
|
||||
#include "./web/WebClient.h"
|
||||
#include "query/command3.h"
|
||||
|
||||
using namespace std::chrono;
|
||||
using namespace std;
|
||||
@ -410,9 +405,10 @@ bool ConnectedClient::notifyClientMoved(const shared_ptr<ConnectedClient> &clien
|
||||
}
|
||||
|
||||
bool ConnectedClient::notifyClientUpdated(const std::shared_ptr<ConnectedClient> &client, const deque<const property::PropertyDescription*> &props, bool lock) {
|
||||
shared_lock channel_lock(this->channel_lock, defer_lock);
|
||||
if(lock)
|
||||
std::shared_lock channel_lock(this->channel_lock, defer_lock);
|
||||
if(lock) {
|
||||
channel_lock.lock();
|
||||
}
|
||||
|
||||
if(!this->isClientVisible(client, false) && client != this)
|
||||
return false;
|
||||
|
@ -550,14 +550,6 @@ void SpeakingClient::processLeave() {
|
||||
server->music_manager_->cleanup_client_bots(this->getClientDatabaseId());
|
||||
//ref_server = nullptr; Removed caused nullptr exceptions
|
||||
}
|
||||
{ //Delete own viewing clients
|
||||
/*
|
||||
* No need, are only weak references!
|
||||
threads::MutexLock l(this->viewLock);
|
||||
this->visibleClients.clear();
|
||||
this->mutedClients.clear();
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
void SpeakingClient::triggerVoiceEnd() {
|
||||
@ -798,22 +790,33 @@ command_result SpeakingClient::handleCommandBroadcastVideoJoin(Command &cmd) {
|
||||
return ts::command_result{error::vs_critical, "failed to count client streams"};
|
||||
}
|
||||
|
||||
if(!permission::v2::permission_granted(camera_streams + screen_streams, this->calculate_permission(permission::i_video_max_streams, this->getChannelId()), false)) {
|
||||
return ts::command_result{permission::i_video_max_streams};
|
||||
auto permission_max_streams = this->calculate_permission(permission::i_video_max_streams, this->getChannelId());
|
||||
if(permission_max_streams.has_value) {
|
||||
if(!permission::v2::permission_granted(camera_streams + screen_streams, permission_max_streams, false)) {
|
||||
return ts::command_result{permission::i_video_max_streams};
|
||||
}
|
||||
}
|
||||
|
||||
switch(broadcast_type) {
|
||||
case rtc::VideoBroadcastType::Camera:
|
||||
if(!permission::v2::permission_granted(camera_streams, this->calculate_permission(permission::i_video_max_camera_streams, this->getChannelId()), false)) {
|
||||
return ts::command_result{permission::i_video_max_camera_streams};
|
||||
case rtc::VideoBroadcastType::Camera: {
|
||||
const auto permission_max_camera_streams = this->calculate_permission(permission::i_video_max_camera_streams, this->getChannelId());
|
||||
if(permission_max_camera_streams.has_value) {
|
||||
if(!permission::v2::permission_granted(camera_streams, permission_max_camera_streams, false)) {
|
||||
return ts::command_result{permission::i_video_max_camera_streams};
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case rtc::VideoBroadcastType::Screen:
|
||||
if(!permission::v2::permission_granted(screen_streams, this->calculate_permission(permission::i_video_max_screen_streams, this->getChannelId()), false)) {
|
||||
return ts::command_result{permission::i_video_max_screen_streams};
|
||||
case rtc::VideoBroadcastType::Screen: {
|
||||
const auto permission_max_screen_streams = this->calculate_permission(permission::i_video_max_camera_streams, this->getChannelId());
|
||||
if(permission_max_screen_streams.has_value) {
|
||||
if(!permission::v2::permission_granted(screen_streams, permission_max_screen_streams, false)) {
|
||||
return ts::command_result{permission::i_video_max_screen_streams};
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
return ts::command_result{error::broadcast_invalid_type};
|
||||
|
@ -148,17 +148,22 @@ command_result ConnectedClient::handleCommandChannelGroupAdd(Command &cmd) {
|
||||
ACTION_REQUIRES_GLOBAL_PERMISSION(permission::b_serverinstance_modify_templates, 1);
|
||||
log_group_type = log::GroupType::TEMPLATE;
|
||||
} else {
|
||||
if (!this->server)
|
||||
if (!this->server) {
|
||||
return command_result{error::parameter_invalid, "you cant create normal groups on the template server!"};
|
||||
}
|
||||
|
||||
log_group_type = log::GroupType::NORMAL;
|
||||
}
|
||||
|
||||
if (cmd["name"].string().empty())
|
||||
if (cmd["name"].string().empty()) {
|
||||
return command_result{error::parameter_invalid, "invalid group name"};
|
||||
}
|
||||
|
||||
for (const auto &gr : group_manager->availableServerGroups(true))
|
||||
if (gr->name() == cmd["name"].string() && gr->target() == GroupTarget::GROUPTARGET_CHANNEL)
|
||||
for (const auto &gr : group_manager->availableServerGroups(true)) {
|
||||
if (gr->name() == cmd["name"].string() && gr->target() == GroupTarget::GROUPTARGET_CHANNEL) {
|
||||
return command_result{error::parameter_invalid, "Group already exists"};
|
||||
}
|
||||
}
|
||||
|
||||
auto group = group_manager->createGroup(GroupTarget::GROUPTARGET_CHANNEL, cmd["type"].as<GroupType>(), cmd["name"].string());
|
||||
serverInstance->action_logger()->group_logger.log_group_create(this->getServerId(), this->ref(), log::GroupTarget::CHANNEL, log_group_type, group->groupId(), group->name(), 0, "");
|
||||
@ -186,8 +191,9 @@ command_result ConnectedClient::handleCommandChannelGroupAdd(Command &cmd) {
|
||||
});
|
||||
}
|
||||
}
|
||||
} else
|
||||
} else {
|
||||
return command_result{error::group_invalid_id};
|
||||
}
|
||||
return command_result{error::ok};
|
||||
}
|
||||
|
||||
|
@ -32,8 +32,9 @@ CryptSetupHandler::CommandHandleResult CryptSetupHandler::handle_command(const s
|
||||
command_handler = &CryptSetupHandler::handleCommandClientInit;
|
||||
}
|
||||
|
||||
if(!command_handler)
|
||||
if(!command_handler) {
|
||||
return CommandHandleResult::PASS_THROUGH;
|
||||
}
|
||||
|
||||
this->last_command_ = std::chrono::system_clock::now();
|
||||
|
||||
@ -51,8 +52,9 @@ CryptSetupHandler::CommandHandleResult CryptSetupHandler::handle_command(const s
|
||||
ts::command_builder notify{"error"};
|
||||
cmd_result.build_error_response(notify, "id");
|
||||
|
||||
if(parser.has_key("return_code"))
|
||||
if(parser.has_key("return_code")) {
|
||||
notify.put_unchecked(0, "return_code", parser.value("return_code"));
|
||||
}
|
||||
|
||||
this->connection->send_command(notify.build(), false, nullptr);
|
||||
|
||||
|
@ -36,7 +36,7 @@ void ServerCommandExecutor::force_insert_command(const pipes::buffer_view &buffe
|
||||
void ServerCommandExecutor::enqueue_command_execution(ReassembledCommand *command) {
|
||||
assert(!command->next_command);
|
||||
|
||||
bool command_handling_scheduled{false};
|
||||
bool command_handling_scheduled;
|
||||
{
|
||||
std::lock_guard pc_lock{this->pending_commands_lock};
|
||||
*this->pending_commands_tail = command;
|
||||
@ -53,8 +53,9 @@ void ServerCommandExecutor::enqueue_command_execution(ReassembledCommand *comman
|
||||
}
|
||||
|
||||
void ServerCommandExecutor::execute_handle_command_packets(const std::chrono::system_clock::time_point& /* scheduled */) {
|
||||
if(!this->client->getServer() || this->client->connectionState() >= ConnectionState::DISCONNECTING)
|
||||
if(!this->client->getServer() || this->client->connectionState() >= ConnectionState::DISCONNECTING) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::unique_ptr<ReassembledCommand, void(*)(ReassembledCommand*)> pending_command{nullptr, ReassembledCommand::free};
|
||||
while(true) {
|
||||
@ -92,6 +93,7 @@ void ServerCommandExecutor::execute_handle_command_packets(const std::chrono::sy
|
||||
}
|
||||
|
||||
auto voice_server = this->client->getVoiceServer();
|
||||
if(voice_server)
|
||||
if(voice_server) {
|
||||
voice_server->schedule_command_handling(client);
|
||||
}
|
||||
}
|
@ -254,7 +254,9 @@ void VoiceClient::finalDisconnect() {
|
||||
}
|
||||
this->flushing_thread.reset();
|
||||
}
|
||||
if(this->voice_server) this->voice_server->unregisterConnection(ownLock);
|
||||
if(this->voice_server) {
|
||||
this->voice_server->unregisterConnection(ownLock);
|
||||
}
|
||||
}
|
||||
|
||||
void VoiceClient::execute_handle_packet(const std::chrono::system_clock::time_point &time) {
|
||||
|
@ -10,7 +10,9 @@ using namespace ts::connection;
|
||||
using namespace ts::protocol;
|
||||
|
||||
void VoiceClientConnection::handlePacketPong(const ts::protocol::ClientPacketParser &packet) {
|
||||
if(packet.payload_length() < 2) return;
|
||||
if(packet.payload_length() < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->ping_handler_.received_pong(be2le16((char*) packet.payload().data_ptr()));
|
||||
}
|
||||
@ -26,7 +28,9 @@ void VoiceClientConnection::handlePacketPing(const protocol::ClientPacketParser&
|
||||
|
||||
void VoiceClientConnection::handlePacketVoice(const protocol::ClientPacketParser& packet) {
|
||||
auto client = this->getCurrentClient();
|
||||
if(!client) return;
|
||||
if(!client) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(client->should_handle_voice_packet(packet.payload_length())) {
|
||||
auto& sink = client->rtc_audio_supplier;
|
||||
@ -65,15 +69,18 @@ void VoiceClientConnection::handlePacketVoiceWhisper(const ts::protocol::ClientP
|
||||
}
|
||||
|
||||
void VoiceClientConnection::handlePacketAck(const protocol::ClientPacketParser& packet) {
|
||||
if(packet.payload_length() < 2) return;
|
||||
if(packet.payload_length() < 2) {
|
||||
return;
|
||||
}
|
||||
uint16_t target_id{be2le16(packet.payload().data_ptr<char>())};
|
||||
|
||||
this->ping_handler_.received_command_acknowledged();
|
||||
this->packet_statistics().received_acknowledge((protocol::PacketType) packet.type(), target_id | (uint32_t) (packet.estimated_generation() << 16U));
|
||||
|
||||
string error{};
|
||||
if(!this->packet_encoder().acknowledge_manager().process_acknowledge(packet.type(), target_id, error))
|
||||
if(!this->packet_encoder().acknowledge_manager().process_acknowledge(packet.type(), target_id, error)) {
|
||||
debugMessage(this->virtual_server_id_, "{} Failed to handle acknowledge: {}", this->log_prefix(), error);
|
||||
}
|
||||
}
|
||||
|
||||
void VoiceClientConnection::handlePacketAckLow(const ts::protocol::ClientPacketParser &packet) {
|
||||
@ -82,7 +89,7 @@ void VoiceClientConnection::handlePacketAckLow(const ts::protocol::ClientPacketP
|
||||
|
||||
void VoiceClientConnection::handlePacketCommand(ReassembledCommand* command) {
|
||||
{
|
||||
using CommandHandleResult = CryptSetupHandler::CommandHandleResult ;
|
||||
using CommandHandleResult = CryptSetupHandler::CommandHandleResult;
|
||||
|
||||
auto result = this->crypt_setup_handler_.handle_command(command->command_view());
|
||||
switch (result) {
|
||||
|
Loading…
Reference in New Issue
Block a user