From 87d607335ea9c79537c62f8f85a329b679d176ad Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sun, 26 Jan 2020 16:33:48 +0100 Subject: [PATCH] Adding a virtualserver channel limit --- server/src/client/command_handler/channel.cpp | 5 ++++- server/src/client/command_handler/server.cpp | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/server/src/client/command_handler/channel.cpp b/server/src/client/command_handler/channel.cpp index 275484f..ed29e00 100644 --- a/server/src/client/command_handler/channel.cpp +++ b/server/src/client/command_handler/channel.cpp @@ -590,9 +590,10 @@ command_result ConnectedClient::handleCommandChannelCreate(Command &cmd) { } { - size_t created_tmp = 0, created_semi = 0, created_perm = 0; + size_t created_total = 0, created_tmp = 0, created_semi = 0, created_perm = 0; auto own_cldbid = this->getClientDatabaseId(); for(const auto& channel : target_tree->channels()) { + created_total++; if(channel->properties()[property::CHANNEL_CREATED_BY] == own_cldbid) { if(channel->properties()[property::CHANNEL_FLAG_PERMANENT].as()) created_perm++; @@ -603,6 +604,8 @@ command_result ConnectedClient::handleCommandChannelCreate(Command &cmd) { } } + if(created_total >= this->server->properties()[property::VIRTUALSERVER_MAX_CHANNELS].as()) + return command_result{error::channel_limit_reached}; auto max_channels = this->calculate_permission(permission::i_client_max_channels, 0, false, permission_cache); if(max_channels.has_value) { diff --git a/server/src/client/command_handler/server.cpp b/server/src/client/command_handler/server.cpp index 6f42af6..10b4b33 100644 --- a/server/src/client/command_handler/server.cpp +++ b/server/src/client/command_handler/server.cpp @@ -92,6 +92,10 @@ command_result ConnectedClient::handleCommandServerEdit(Command &cmd) { if (cmd["virtualserver_maxclients"].as() > 1024) return command_result{error::accounting_slot_limit_reached, "Do you really need more that 1024 slots?"}; } SERVEREDIT_CHK_PROP_CACHED("virtualserver_reserved_slots", permission::b_virtualserver_modify_reserved_slots, size_t) } + SERVEREDIT_CHK_PROP_CACHED("virtualserver_max_channels", permission::b_virtualserver_modify_maxchannels, size_t) + if(cmd["virtualserver_max_channels"].as() > 8192) + return command_result{error::channel_protocol_limit_reached}; + } SERVEREDIT_CHK_PROP_CACHED("virtualserver_icon_id", permission::b_virtualserver_modify_icon_id, int64_t) } SERVEREDIT_CHK_PROP_CACHED("virtualserver_channel_temp_delete_delay_default", permission::b_virtualserver_modify_channel_temp_delete_delay_default, ChannelId) } SERVEREDIT_CHK_PROP_CACHED("virtualserver_codec_encryption_mode", permission::b_virtualserver_modify_codec_encryption_mode, int) }