Some code refactoring

This commit is contained in:
WolverinDEV
2021-04-14 14:57:04 +02:00
parent bf643b4797
commit 6b774d3a80
29 changed files with 610 additions and 468 deletions
+12 -14
View File
@@ -43,7 +43,7 @@ bool SpeakingClient::shouldReceiveVoice(const std::shared_ptr<ConnectedClient> &
if(this->properties()[property::CLIENT_OUTPUT_MUTED].as_or<bool>(false)) return false;
{
shared_lock client_lock(this->channel_lock);
shared_lock client_lock(this->channel_tree_mutex);
for(const auto& entry : this->mutedClients)
if(entry.lock() == sender)
return false;
@@ -55,7 +55,7 @@ bool SpeakingClient::shouldReceiveVoiceWhisper(const std::shared_ptr<ConnectedCl
if(!this->shouldReceiveVoice(sender))
return false;
return permission::v2::permission_granted(this->cpmerission_needed_whisper_power, sender->cpmerission_whisper_power, false);
return permission::v2::permission_granted(this->cpmerission_needed_whisper_power, sender->cpmerission_whisper_power);
}
bool SpeakingClient::should_handle_voice_packet(size_t) {
@@ -396,16 +396,14 @@ command_result SpeakingClient::handleCommandClientInit(Command& cmd) {
}
/* must be triggered while helding an execute lock */
//Note: Client permissions are may not really
void SpeakingClient::processJoin() {
TIMING_START(timings);
auto ref_server = this->server;
assert(ref_server);
this->resetIdleTime();
/* don't process any commands */
std::lock_guard command_lock_{this->command_lock};
auto ref_server = this->server;
assert(ref_server);
if(this->state != ConnectionState::INIT_HIGH) {
logError(this->getServerId(), "{} Invalid processJoin() connection state!", CLIENT_STR_LOG_PREFIX);
@@ -507,10 +505,10 @@ void SpeakingClient::processJoin() {
this->properties()[property::CLIENT_CHANNEL_GROUP_ID] = "0";
this->properties()[property::CLIENT_TALK_POWER] = "0";
unique_lock server_channel_lock(this->server->channel_tree_lock);
unique_lock server_channel_lock(this->server->channel_tree_mutex);
this->server->client_move(this->ref(), channel, nullptr, "", ViewReasonId::VREASON_USER_ACTION, false, server_channel_lock);
if(this->getType() != ClientType::CLIENT_TEAMSPEAK) {
std::lock_guard own_channel_lock{this->channel_lock};
std::lock_guard own_channel_lock{this->channel_tree_mutex};
this->subscribeChannel({this->currentChannel}, false, true); /* su "improve" the TS3 clients join speed we send the channel clients a bit later, when the TS3 client gets his own client variables */
}
}
@@ -571,7 +569,7 @@ void SpeakingClient::processLeave() {
if(server){
logMessage(this->getServerId(), "Voice client {}/{} ({}) from {} left.", this->getClientDatabaseId(), this->getUid(), this->getDisplayName(), this->getLoggingPeerIp() + ":" + to_string(this->getPeerPort()));
{
unique_lock server_channel_lock(this->server->channel_tree_lock);
unique_lock server_channel_lock(this->server->channel_tree_mutex);
server->unregisterClient(ownLock, "disconnected", server_channel_lock); /* already moves client to void if needed */
}
server->music_manager_->cleanup_client_bots(this->getClientDatabaseId());
@@ -822,7 +820,7 @@ command_result SpeakingClient::handleCommandBroadcastVideo(Command &command) {
switch(type) {
case rtc::VideoBroadcastType::Screen:
if(!permission::v2::permission_granted(1, this->calculate_permission(permission::b_video_screen, this->getChannelId()), false)) {
if(!permission::v2::permission_granted(1, this->calculate_permission(permission::b_video_screen, this->getChannelId()))) {
return ts::command_result{permission::b_video_screen};
}
@@ -830,7 +828,7 @@ command_result SpeakingClient::handleCommandBroadcastVideo(Command &command) {
case rtc::VideoBroadcastType::Camera:
if(!permission::v2::permission_granted(1, this->calculate_permission(permission::b_video_camera, this->getChannelId()), false)) {
if(!permission::v2::permission_granted(1, this->calculate_permission(permission::b_video_camera, this->getChannelId()))) {
return ts::command_result{permission::b_video_camera};
}
@@ -934,7 +932,7 @@ command_result SpeakingClient::handleCommandBroadcastVideoJoin(Command &cmd) {
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)) {
if(!permission::v2::permission_granted(camera_streams + screen_streams, permission_max_streams)) {
return ts::command_result{permission::i_video_max_streams};
}
}
@@ -943,7 +941,7 @@ command_result SpeakingClient::handleCommandBroadcastVideoJoin(Command &cmd) {
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)) {
if(!permission::v2::permission_granted(camera_streams, permission_max_camera_streams)) {
return ts::command_result{permission::i_video_max_camera_streams};
}
}
@@ -953,7 +951,7 @@ command_result SpeakingClient::handleCommandBroadcastVideoJoin(Command &cmd) {
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)) {
if(!permission::v2::permission_granted(screen_streams, permission_max_screen_streams)) {
return ts::command_result{permission::i_video_max_screen_streams};
}
}