From 5b74992beb5f4523485c8a4b6749c7dd6bbf282a Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Tue, 1 Dec 2020 10:07:36 +0100 Subject: [PATCH] Updated the channel edit and create functions --- src/BasicChannel.cpp | 6 ++++-- src/Error.cpp | 2 ++ src/Error.h | 3 +++ src/PropertyDefinition.h | 2 +- src/query/command3.h | 13 +++++++++++++ 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/BasicChannel.cpp b/src/BasicChannel.cpp index 4e870db..1ded848 100644 --- a/src/BasicChannel.cpp +++ b/src/BasicChannel.cpp @@ -192,9 +192,11 @@ std::shared_ptr BasicChannelTree::findChannel(ChannelId channelId, std::shared_ptr BasicChannelTree::findChannel(const std::string &name, const shared_ptr &layer) { - for (auto elm : this->channels()) - if (elm->name() == name && elm->parent() == layer) + for (auto elm : this->channels()) { + if (elm->name() == name && elm->parent() == layer) { return elm; + } + } return nullptr; } diff --git a/src/Error.cpp b/src/Error.cpp index 61c0bd9..aac6d1f 100644 --- a/src/Error.cpp +++ b/src/Error.cpp @@ -64,6 +64,8 @@ const std::vector ts::avariableErrors = { {0x0310, "channel_is_deleted" , "target channel is deleted" }, {0x0311, "channel_name_invalid" , "channel name is invalid" }, {0x0312, "channel_limit_reached" , "the virtualserver channel limit has been reached" }, + define_error_description(channel_family_not_visible, "the channel family isn't visible by default"), + define_error_description(channel_default_require_visible, "the channel family contains the default channel"), {0x0400, "server_invalid_id" , "invalid serverID" }, {0x0401, "server_running" , "server is running" }, diff --git a/src/Error.h b/src/Error.h index 3fd58e5..05919ec 100644 --- a/src/Error.h +++ b/src/Error.h @@ -76,6 +76,9 @@ namespace ts { channel_is_deleted = 0x310, channel_name_invalid = 0x311, channel_limit_reached = 0x312, + + channel_family_not_visible = 0x320, + channel_default_require_visible = 0x321, server_invalid_id = 0x400, server_running = 0x401, diff --git a/src/PropertyDefinition.h b/src/PropertyDefinition.h index 034f995..59931b4 100644 --- a/src/PropertyDefinition.h +++ b/src/PropertyDefinition.h @@ -127,7 +127,7 @@ property_list = std::array{ PropertyDescription{CHANNEL_MAXCLIENTS, "channel_maxclients", "-1", TYPE_SIGNED_NUMBER, FLAG_CHANNEL_VIEW | FLAG_SS | FLAG_USER_EDITABLE}, //Available for all channels that are "in view", always up-to-date PropertyDescription{CHANNEL_MAXFAMILYCLIENTS, "channel_maxfamilyclients", "-1", TYPE_SIGNED_NUMBER, FLAG_CHANNEL_VIEW | FLAG_SS | FLAG_USER_EDITABLE}, //Available for all channels that are "in view", always up-to-date PropertyDescription{CHANNEL_ORDER, "channel_order", "0", TYPE_UNSIGNED_NUMBER, FLAG_CHANNEL_VIEW | FLAG_SS | FLAG_USER_EDITABLE}, //Available for all channels that are "in view", always up-to-date - PropertyDescription{CHANNEL_FLAG_PERMANENT, "channel_flag_permanent", "1", TYPE_BOOL, FLAG_CHANNEL_VIEW | FLAG_SS | FLAG_USER_EDITABLE}, //Available for all channels that are "in view", always up-to-date + PropertyDescription{CHANNEL_FLAG_PERMANENT, "channel_flag_permanent", "0", TYPE_BOOL, FLAG_CHANNEL_VIEW | FLAG_SS | FLAG_USER_EDITABLE}, //Available for all channels that are "in view", always up-to-date PropertyDescription{CHANNEL_FLAG_SEMI_PERMANENT, "channel_flag_semi_permanent", "0", TYPE_BOOL, FLAG_CHANNEL_VIEW | FLAG_SS | FLAG_USER_EDITABLE}, //Available for all channels that are "in view", always up-to-date PropertyDescription{CHANNEL_FLAG_DEFAULT, "channel_flag_default", "0", TYPE_BOOL, FLAG_CHANNEL_VIEW | FLAG_SS | FLAG_USER_EDITABLE}, //Available for all channels that are "in view", always up-to-date PropertyDescription{CHANNEL_FLAG_PASSWORD, "channel_flag_password", "0", TYPE_BOOL, FLAG_CHANNEL_VIEW | FLAG_SS | FLAG_USER_EDITABLE}, //Available for all channels that are "in view", always up-to-date diff --git a/src/query/command3.h b/src/query/command3.h index 1c5cc7f..48cfc49 100644 --- a/src/query/command3.h +++ b/src/query/command3.h @@ -97,6 +97,19 @@ namespace ts { } } + template + inline void expect_value_as(const std::string_view& key) const { + static_assert(converter::supported, "Target type isn't supported!"); + static_assert(!converter::supported || converter::from_string_view, "Target type dosn't support parsing"); + + auto value = this->value(key); + try { + converter::from_string_view(value); + } catch (std::exception& ex) { + throw command_value_cast_failed{this->key_command_character_index(key), std::string{key}, value, typeid(T)}; + } + } + [[nodiscard]] inline size_t command_character_index() const { return this->abs_index; } [[nodiscard]] inline size_t key_command_character_index(const std::string_view& key) const { size_t begin{0};