From b98c5f8907143adffab00ec5e05d2746681a715f Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sun, 16 Feb 2020 19:02:06 +0100 Subject: [PATCH] Some issue fixes --- server/src/VirtualServer.cpp | 2 +- server/src/client/ConnectedClient.cpp | 2 +- server/src/client/command_handler/misc.cpp | 13 +++++++------ server/src/client/command_handler/music.cpp | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/server/src/VirtualServer.cpp b/server/src/VirtualServer.cpp index 3238076..41d8175 100644 --- a/server/src/VirtualServer.cpp +++ b/server/src/VirtualServer.cpp @@ -1203,7 +1203,7 @@ void VirtualServer::send_text_message(const std::shared_ptr &chann if(flag_password) continue; /* TODO: Send notification about new message. The client then could request messages via message history */ - if(!client->calculate_and_get_join_state(channel)) + if(auto err_perm{client->calculate_and_get_join_state(channel)}; err_perm) continue; } client->notifyTextMessage(ChatMessageMode::TEXTMODE_CHANNEL, sender, client_id, channel_id, now, message); diff --git a/server/src/client/ConnectedClient.cpp b/server/src/client/ConnectedClient.cpp index 86f3695..ccb5cef 100644 --- a/server/src/client/ConnectedClient.cpp +++ b/server/src/client/ConnectedClient.cpp @@ -987,5 +987,5 @@ permission::PermissionType ConnectedClient::calculate_and_get_join_state(const s if(permission::v2::permission_granted(1, this->calculate_permission(permission::b_client_is_sticky, this->currentChannel ? this->currentChannel->channelId() : 0))) if(!permission::v2::permission_granted(1, this->calculate_permission(permission::b_client_ignore_sticky, channel_id))) RESULT(permission::b_client_is_sticky); - RESULT(permission::unknown); + RESULT(permission::ok); } \ No newline at end of file diff --git a/server/src/client/command_handler/misc.cpp b/server/src/client/command_handler/misc.cpp index 35640c9..2198846 100644 --- a/server/src/client/command_handler/misc.cpp +++ b/server/src/client/command_handler/misc.cpp @@ -541,6 +541,10 @@ command_result ConnectedClient::handleCommandSendTextMessage(Command &cmd) { channel = this->currentChannel; channel_id = this->currentChannel->channelId(); } + + if(!permission::v2::permission_granted(1, this->calculate_permission(permission::b_client_channel_textmessage_send, channel_id), false)) \ + return command_result{permission::b_client_channel_textmessage_send}; + if(channel == this->currentChannel) { channel_tree_read_lock.unlock(); //Method may creates a music bot which modifies the channel tree if(this->handleTextMessage(ChatMessageMode::TEXTMODE_CHANNEL, cmd["msg"], nullptr)) @@ -548,16 +552,13 @@ command_result ConnectedClient::handleCommandSendTextMessage(Command &cmd) { channel_tree_read_lock.lock(); } - if(!permission::v2::permission_granted(1, this->calculate_permission(permission::b_client_channel_textmessage_send, channel_id), false)) \ - return command_result{permission::b_client_channel_textmessage_send}; - bool conversation_private = channel->properties()[property::CHANNEL_FLAG_CONVERSATION_PRIVATE].as(); if(channel != this->currentChannel) { if(conversation_private) return command_result{error::conversation_is_private}; - if(!this->calculate_and_get_join_state(channel)) - return command_result{permission::b_client_channel_textmessage_send}; /* You're not allowed to send messages :) */ + if(auto fail_perm{this->calculate_and_get_join_state(channel)}; fail_perm != permission::ok) + return command_result{fail_perm}; /* You're not allowed to send messages :) */ } this->server->send_text_message(channel, this->ref(), cmd["msg"].string()); @@ -2502,7 +2503,7 @@ command_result ConnectedClient::handleCommandConversationMessageDelete(ts::Comma if (!permission::v2::permission_granted(1, this->calculate_permission(permission::b_channel_conversation_message_delete, 1, channel->channelId()))) return command_result{permission::b_channel_conversation_message_delete}; - if(auto error_perm = this->calculate_and_get_join_state(channel); error_perm != permission::b_client_is_sticky) + if(auto error_perm = this->calculate_and_get_join_state(channel); error_perm && error_perm != permission::b_client_is_sticky) return command_result{error_perm}; } } diff --git a/server/src/client/command_handler/music.cpp b/server/src/client/command_handler/music.cpp index fb42afe..44502cf 100644 --- a/server/src/client/command_handler/music.cpp +++ b/server/src/client/command_handler/music.cpp @@ -119,7 +119,7 @@ command_result ConnectedClient::handleCommandMusicBotCreate(Command& cmd) { if(!channel) { if(cmd[0].has("cid")) return command_result{error::channel_invalid_id}; } else { - if(!this->calculate_and_get_join_state(channel)) + if(this->calculate_and_get_join_state(channel) != permission::ok) channel = nullptr; } if(!channel)