Some minor changes and fixes

This commit is contained in:
WolverinDEV 2020-12-17 12:00:27 +01:00
parent 6605a440bd
commit 0cff59328f
9 changed files with 66 additions and 59 deletions

View File

@ -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_bytes_sent[category] += size;
this->statistics_second_current.connection_packets_sent[category] += 1; this->statistics_second_current.connection_packets_sent[category] += 1;
if(this->handle) if(this->handle) {
this->handle->logOutgoingPacket(category, size); this->handle->logOutgoingPacket(category, size);
}
} }
/* file transfer */ /* file transfer */

View File

@ -572,9 +572,13 @@ bool ConnectedClient::notifyClientNeededPermissions() {
auto permissions = this->cached_permissions; auto permissions = this->cached_permissions;
cache_lock.unlock(); cache_lock.unlock();
for(const auto& value : permissions) { for(const auto& [ key, value ] : permissions) {
cmd[index]["permid"] = value.first; if(!value.has_value) {
cmd[index++]["permvalue"] = value.second.has_value ? value.second.value : 0; continue;
}
cmd[index]["permid"] = key;
cmd[index++]["permvalue"] = value.value;
} }
if(index == 0) { if(index == 0) {
@ -586,22 +590,6 @@ bool ConnectedClient::notifyClientNeededPermissions() {
return true; 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) { bool ConnectedClient::notifyError(const command_result& result, const std::string& retCode) {
ts::command_builder command{"error"}; ts::command_builder command{"error"};

View File

@ -1,18 +1,13 @@
#include <iostream>
#include <bitset> #include <bitset>
#include <algorithm> #include <algorithm>
#include "ConnectedClient.h" #include "ConnectedClient.h"
#include "voice/VoiceClient.h" #include "voice/VoiceClient.h"
#include "../server/VoiceServer.h"
#include "../InstanceHandler.h" #include "../InstanceHandler.h"
#include "../server/QueryServer.h" #include "../server/QueryServer.h"
#include "../manager/PermissionNameMapper.h" #include "../manager/PermissionNameMapper.h"
#include "music/MusicClient.h" #include "music/MusicClient.h"
#include <log/LogUtils.h>
#include <misc/sassert.h> #include <misc/sassert.h>
#include <misc/timer.h>
#include "./web/WebClient.h" #include "./web/WebClient.h"
#include "query/command3.h"
using namespace std::chrono; using namespace std::chrono;
using namespace std; 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) { 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); std::shared_lock channel_lock(this->channel_lock, defer_lock);
if(lock) if(lock) {
channel_lock.lock(); channel_lock.lock();
}
if(!this->isClientVisible(client, false) && client != this) if(!this->isClientVisible(client, false) && client != this)
return false; return false;

View File

@ -550,14 +550,6 @@ void SpeakingClient::processLeave() {
server->music_manager_->cleanup_client_bots(this->getClientDatabaseId()); server->music_manager_->cleanup_client_bots(this->getClientDatabaseId());
//ref_server = nullptr; Removed caused nullptr exceptions //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() { 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"}; 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)) { 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}; return ts::command_result{permission::i_video_max_streams};
} }
}
switch(broadcast_type) { switch(broadcast_type) {
case rtc::VideoBroadcastType::Camera: case rtc::VideoBroadcastType::Camera: {
if(!permission::v2::permission_granted(camera_streams, this->calculate_permission(permission::i_video_max_camera_streams, this->getChannelId()), false)) { 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}; 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};
} }
break; break;
}
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: default:
return ts::command_result{error::broadcast_invalid_type}; return ts::command_result{error::broadcast_invalid_type};

View File

@ -148,17 +148,22 @@ command_result ConnectedClient::handleCommandChannelGroupAdd(Command &cmd) {
ACTION_REQUIRES_GLOBAL_PERMISSION(permission::b_serverinstance_modify_templates, 1); ACTION_REQUIRES_GLOBAL_PERMISSION(permission::b_serverinstance_modify_templates, 1);
log_group_type = log::GroupType::TEMPLATE; log_group_type = log::GroupType::TEMPLATE;
} else { } else {
if (!this->server) if (!this->server) {
return command_result{error::parameter_invalid, "you cant create normal groups on the template server!"}; return command_result{error::parameter_invalid, "you cant create normal groups on the template server!"};
}
log_group_type = log::GroupType::NORMAL; 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"}; return command_result{error::parameter_invalid, "invalid group name"};
}
for (const auto &gr : group_manager->availableServerGroups(true)) for (const auto &gr : group_manager->availableServerGroups(true)) {
if (gr->name() == cmd["name"].string() && gr->target() == GroupTarget::GROUPTARGET_CHANNEL) if (gr->name() == cmd["name"].string() && gr->target() == GroupTarget::GROUPTARGET_CHANNEL) {
return command_result{error::parameter_invalid, "Group already exists"}; return command_result{error::parameter_invalid, "Group already exists"};
}
}
auto group = group_manager->createGroup(GroupTarget::GROUPTARGET_CHANNEL, cmd["type"].as<GroupType>(), cmd["name"].string()); 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, ""); 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::group_invalid_id};
}
return command_result{error::ok}; return command_result{error::ok};
} }

View File

@ -32,8 +32,9 @@ CryptSetupHandler::CommandHandleResult CryptSetupHandler::handle_command(const s
command_handler = &CryptSetupHandler::handleCommandClientInit; command_handler = &CryptSetupHandler::handleCommandClientInit;
} }
if(!command_handler) if(!command_handler) {
return CommandHandleResult::PASS_THROUGH; return CommandHandleResult::PASS_THROUGH;
}
this->last_command_ = std::chrono::system_clock::now(); this->last_command_ = std::chrono::system_clock::now();
@ -51,8 +52,9 @@ CryptSetupHandler::CommandHandleResult CryptSetupHandler::handle_command(const s
ts::command_builder notify{"error"}; ts::command_builder notify{"error"};
cmd_result.build_error_response(notify, "id"); 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")); notify.put_unchecked(0, "return_code", parser.value("return_code"));
}
this->connection->send_command(notify.build(), false, nullptr); this->connection->send_command(notify.build(), false, nullptr);

View File

@ -36,7 +36,7 @@ void ServerCommandExecutor::force_insert_command(const pipes::buffer_view &buffe
void ServerCommandExecutor::enqueue_command_execution(ReassembledCommand *command) { void ServerCommandExecutor::enqueue_command_execution(ReassembledCommand *command) {
assert(!command->next_command); assert(!command->next_command);
bool command_handling_scheduled{false}; bool command_handling_scheduled;
{ {
std::lock_guard pc_lock{this->pending_commands_lock}; std::lock_guard pc_lock{this->pending_commands_lock};
*this->pending_commands_tail = command; *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 */) { 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; return;
}
std::unique_ptr<ReassembledCommand, void(*)(ReassembledCommand*)> pending_command{nullptr, ReassembledCommand::free}; std::unique_ptr<ReassembledCommand, void(*)(ReassembledCommand*)> pending_command{nullptr, ReassembledCommand::free};
while(true) { while(true) {
@ -92,6 +93,7 @@ void ServerCommandExecutor::execute_handle_command_packets(const std::chrono::sy
} }
auto voice_server = this->client->getVoiceServer(); auto voice_server = this->client->getVoiceServer();
if(voice_server) if(voice_server) {
voice_server->schedule_command_handling(client); voice_server->schedule_command_handling(client);
}
} }

View File

@ -254,7 +254,9 @@ void VoiceClient::finalDisconnect() {
} }
this->flushing_thread.reset(); 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) { void VoiceClient::execute_handle_packet(const std::chrono::system_clock::time_point &time) {

View File

@ -10,7 +10,9 @@ using namespace ts::connection;
using namespace ts::protocol; using namespace ts::protocol;
void VoiceClientConnection::handlePacketPong(const ts::protocol::ClientPacketParser &packet) { 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())); 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) { void VoiceClientConnection::handlePacketVoice(const protocol::ClientPacketParser& packet) {
auto client = this->getCurrentClient(); auto client = this->getCurrentClient();
if(!client) return; if(!client) {
return;
}
if(client->should_handle_voice_packet(packet.payload_length())) { if(client->should_handle_voice_packet(packet.payload_length())) {
auto& sink = client->rtc_audio_supplier; auto& sink = client->rtc_audio_supplier;
@ -65,15 +69,18 @@ void VoiceClientConnection::handlePacketVoiceWhisper(const ts::protocol::ClientP
} }
void VoiceClientConnection::handlePacketAck(const protocol::ClientPacketParser& packet) { 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>())}; uint16_t target_id{be2le16(packet.payload().data_ptr<char>())};
this->ping_handler_.received_command_acknowledged(); this->ping_handler_.received_command_acknowledged();
this->packet_statistics().received_acknowledge((protocol::PacketType) packet.type(), target_id | (uint32_t) (packet.estimated_generation() << 16U)); this->packet_statistics().received_acknowledge((protocol::PacketType) packet.type(), target_id | (uint32_t) (packet.estimated_generation() << 16U));
string error{}; 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); debugMessage(this->virtual_server_id_, "{} Failed to handle acknowledge: {}", this->log_prefix(), error);
}
} }
void VoiceClientConnection::handlePacketAckLow(const ts::protocol::ClientPacketParser &packet) { void VoiceClientConnection::handlePacketAckLow(const ts::protocol::ClientPacketParser &packet) {
@ -82,7 +89,7 @@ void VoiceClientConnection::handlePacketAckLow(const ts::protocol::ClientPacketP
void VoiceClientConnection::handlePacketCommand(ReassembledCommand* command) { void VoiceClientConnection::handlePacketCommand(ReassembledCommand* command) {
{ {
using CommandHandleResult = CryptSetupHandler::CommandHandleResult ; using CommandHandleResult = CryptSetupHandler::CommandHandleResult;
auto result = this->crypt_setup_handler_.handle_command(command->command_view()); auto result = this->crypt_setup_handler_.handle_command(command->command_view());
switch (result) { switch (result) {