From ccd0f7fcfd0781891e1a86699c77ecaecc3c36fe Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sat, 19 Dec 2020 10:52:24 +0100 Subject: [PATCH] Fixed a crash related to the whisper system and some minor updates --- rtclib | 2 +- .../src/client/ConnectedClientNotifyHandler.cpp | 17 +++++++++++------ server/src/client/command_handler/channel.cpp | 3 ++- server/src/client/shared/WhisperHandler.cpp | 4 ++++ server/src/client/shared/WhisperHandler.h | 1 + 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/rtclib b/rtclib index 7f1e138..d5a0852 160000 --- a/rtclib +++ b/rtclib @@ -1 +1 @@ -Subproject commit 7f1e1387fcfffd7e82bd51c3a3e0c7f38dcfdd6e +Subproject commit d5a085254595fddc0520de21a75402b43c39f608 diff --git a/server/src/client/ConnectedClientNotifyHandler.cpp b/server/src/client/ConnectedClientNotifyHandler.cpp index fb57694..115cabf 100644 --- a/server/src/client/ConnectedClientNotifyHandler.cpp +++ b/server/src/client/ConnectedClientNotifyHandler.cpp @@ -676,25 +676,30 @@ bool ConnectedClient::notifyChannelEdited( if(!v_channel) return false; //Not visible? Important do not remove! bool send_description_change{false}; + size_t property_count{0}; Command notify("notifychanneledited"); for(auto prop : properties) { const auto& prop_info = property::describe(prop); - if(prop == property::CHANNEL_ORDER) + if(prop == property::CHANNEL_ORDER) { notify[prop_info.name] = v_channel->previous_channel; - else if(prop == property::CHANNEL_DESCRIPTION) { + property_count++; + } else if(prop == property::CHANNEL_DESCRIPTION) { send_description_change = true; } else { notify[prop_info.name] = channel->properties()[prop].as(); + property_count++; } } - notify["cid"] = channel->channelId(); - notify["reasonid"] = ViewReasonId::VREASON_EDITED; + if(property_count > 0) { + notify["cid"] = channel->channelId(); + notify["reasonid"] = ViewReasonId::VREASON_EDITED; - INVOKER(notify, invoker); - this->sendCommand(notify); + INVOKER(notify, invoker); + this->sendCommand(notify); + } if(send_description_change) { Command notify_dchange{"notifychanneldescriptionchanged"}; diff --git a/server/src/client/command_handler/channel.cpp b/server/src/client/command_handler/channel.cpp index b5c0fa9..e7adc61 100644 --- a/server/src/client/command_handler/channel.cpp +++ b/server/src/client/command_handler/channel.cpp @@ -1436,6 +1436,7 @@ ts::command_result ConnectedClient::execute_channel_edit(ChannelId& channel_id, case property::CHANNEL_CODEC_QUALITY: case property::CHANNEL_CODEC_IS_UNENCRYPTED: case property::CHANNEL_DELETE_DELAY: + case property::CHANNEL_SIDEBAR_MODE: break; case property::CHANNEL_PASSWORD: @@ -1500,7 +1501,7 @@ ts::command_result ConnectedClient::execute_channel_edit(ChannelId& channel_id, break; default: - logCritical(this->getServerId(), "{} Channel property {} reached context validation context but we don't know how to handle it. Please report this bug!", property::describe(key).name); + logCritical(this->getServerId(), "{} Channel property {} reached context validation context but we don't know how to handle it. Please report this bug!", CLIENT_LOG_PREFIX, property::describe(key).name); continue; } diff --git a/server/src/client/shared/WhisperHandler.cpp b/server/src/client/shared/WhisperHandler.cpp index 5240d0d..9868141 100644 --- a/server/src/client/shared/WhisperHandler.cpp +++ b/server/src/client/shared/WhisperHandler.cpp @@ -18,6 +18,8 @@ WhisperHandler::~WhisperHandler() { } bool WhisperHandler::validate_whisper_packet(const protocol::ClientPacketParser &packet, bool& match_last_header, void *&payload_ptr, size_t &payload_length) { + std::lock_guard process_lock{this->whisper_head_mutex}; + size_t head_length; if(packet.flags() & protocol::PacketFlag::NewProtocol) { if(packet.payload_length() < 3 + 10) { @@ -163,6 +165,8 @@ void WhisperHandler::signal_session_reset() { } void WhisperHandler::handle_session_reset() { + std::lock_guard process_lock{this->whisper_head_mutex}; + this->session_state = SessionState::Uninitialized; if(this->whisper_head_ptr) { ::free(this->whisper_head_ptr); diff --git a/server/src/client/shared/WhisperHandler.h b/server/src/client/shared/WhisperHandler.h index b02e317..9069f49 100644 --- a/server/src/client/shared/WhisperHandler.h +++ b/server/src/client/shared/WhisperHandler.h @@ -61,6 +61,7 @@ namespace ts::server::whisper { SessionState session_state{SessionState::Uninitialized}; std::chrono::system_clock::time_point session_timestamp{}; + std::mutex whisper_head_mutex{}; void* whisper_head_ptr{nullptr}; size_t whisper_head_length{0}; size_t whisper_head_capacity{0};