From a69100f6893e85061daf805f2eeef0d4dd235e94 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sun, 26 Jan 2020 16:15:36 +0100 Subject: [PATCH] Improved some stuff --- server/src/client/ConnectedClient.cpp | 2 +- .../client/ConnectedClientNotifyHandler.cpp | 12 +-- .../src/client/query/QueryClientCommands.cpp | 90 +++++++++---------- shared | 2 +- 4 files changed, 52 insertions(+), 54 deletions(-) diff --git a/server/src/client/ConnectedClient.cpp b/server/src/client/ConnectedClient.cpp index 28df428..719e7f0 100644 --- a/server/src/client/ConnectedClient.cpp +++ b/server/src/client/ConnectedClient.cpp @@ -167,7 +167,7 @@ void ConnectedClient::updateChannelClientProperties(bool lock_channel_tree, bool notifyList.emplace_back(property::CLIENT_IS_PRIORITY_SPEAKER); } - block_flood = !!permission_ignore_antiflood.has_value || permission_ignore_antiflood.value <= 0; + block_flood = !permission::v2::permission_granted(1, permission_ignore_antiflood); if(server_ref) server_ref->notifyClientPropertyUpdates(_this.lock(), notifyList, notify_self); this->updateTalkRights(permission_talk_power.has_value ? permission_talk_power.value : 0); diff --git a/server/src/client/ConnectedClientNotifyHandler.cpp b/server/src/client/ConnectedClientNotifyHandler.cpp index 8c34a1c..ef152d4 100644 --- a/server/src/client/ConnectedClientNotifyHandler.cpp +++ b/server/src/client/ConnectedClientNotifyHandler.cpp @@ -36,16 +36,16 @@ do { \ } \ } while(0) -#define INVOKER_NEW(command, invoker) \ +#define INVOKER_NEW(command, invoker) \ do { \ if(invoker) { \ command.put_unchecked(0, "invokerid", invoker->getClientId()); \ - command.put_unchecked(0, "invokername", invoker->getDisplayName()); \ - command.put_unchecked(0, "invokeruid", invoker->getUid()); \ + command.put_unchecked(0, "invokername", invoker->getDisplayName()); \ + command.put_unchecked(0, "invokeruid", invoker->getUid()); \ } else { \ - command.put_unchecked(0, "invokerid", "0"); \ - command.put_unchecked(0, "invokername", "undefined"); \ - command.put_unchecked(0, "invokeruid", "undefined"); \ + command.put_unchecked(0, "invokerid", "0"); \ + command.put_unchecked(0, "invokername", "undefined"); \ + command.put_unchecked(0, "invokeruid", "undefined"); \ } \ } while(0) diff --git a/server/src/client/query/QueryClientCommands.cpp b/server/src/client/query/QueryClientCommands.cpp index f3778fd..0eebd0b 100644 --- a/server/src/client/query/QueryClientCommands.cpp +++ b/server/src/client/query/QueryClientCommands.cpp @@ -483,60 +483,57 @@ command_result QueryClient::handleCommandChannelList(Command& cmd) { CMD_RESET_IDLE; ACTION_REQUIRES_GLOBAL_PERMISSION(permission::b_virtualserver_channel_list, 1); - Command result(""); - int index = 0; shared_lock channel_lock(this->server ? this->server->channel_tree_lock : serverInstance->getChannelTreeLock()); auto entries = this->server ? this->channels->channels() : serverInstance->getChannelTree()->channels(); channel_lock.unlock(); + command_builder result{"", 1024, entries.size()}; for(const auto& channel : entries){ if(!channel) continue; - - auto& bulk = result[index]; - bulk["cid"] = channel->channelId(); - bulk["pid"] = channel->properties()[property::CHANNEL_PID].as(); - bulk["channel_name"] = channel->name(); - bulk["channel_order"] = channel->channelOrder(); - bulk["total_clients"] = this->server ? this->server->getClientsByChannel(channel).size() : 0; - /* bulk["channel_needed_subscribe_power"] = channel->permissions()->getPermissionValue(permission::i_channel_needed_subscribe_power, channel, 0); */ + result.put_unchecked(index, "cid", channel->channelId()); + result.put_unchecked(index, "pid", channel->properties()[property::CHANNEL_PID].as()); + result.put_unchecked(index, "channel_name", channel->name()); + result.put_unchecked(index, "channel_order", channel->channelOrder()); + result.put_unchecked(index, "total_clients", this->server ? this->server->getClientsByChannel(channel).size() : 0); + /* result.put_unchecked(index, "channel_needed_subscribe_power", channel->permissions()->getPermissionValue(permission::i_channel_needed_subscribe_power, channel, 0)); */ if(cmd.hasParm("flags")){ - bulk["channel_flag_default"] = channel->properties()[property::CHANNEL_FLAG_DEFAULT].as(); - bulk["channel_flag_password"] = channel->properties()[property::CHANNEL_FLAG_PASSWORD].as(); - bulk["channel_flag_permanent"] = channel->properties()[property::CHANNEL_FLAG_PERMANENT].as(); - bulk["channel_flag_semi_permanent"] = channel->properties()[property::CHANNEL_FLAG_SEMI_PERMANENT].as(); + result.put_unchecked(index, "channel_flag_default", channel->properties()[property::CHANNEL_FLAG_DEFAULT].as()); + result.put_unchecked(index, "channel_flag_password", channel->properties()[property::CHANNEL_FLAG_PASSWORD].as()); + result.put_unchecked(index, "channel_flag_permanent", channel->properties()[property::CHANNEL_FLAG_PERMANENT].as()); + result.put_unchecked(index, "channel_flag_semi_permanent", channel->properties()[property::CHANNEL_FLAG_SEMI_PERMANENT].as()); } if(cmd.hasParm("voice")){ - bulk["channel_codec"] = channel->properties()[property::CHANNEL_CODEC].as(); - bulk["channel_codec_quality"] = channel->properties()[property::CHANNEL_CODEC_QUALITY].as(); - bulk["channel_needed_talk_power"] = channel->properties()[property::CHANNEL_NEEDED_TALK_POWER].as(); + result.put_unchecked(index, "channel_codec", channel->properties()[property::CHANNEL_CODEC].as()); + result.put_unchecked(index, "channel_codec_quality", channel->properties()[property::CHANNEL_CODEC_QUALITY].as()); + result.put_unchecked(index, "channel_needed_talk_power", channel->properties()[property::CHANNEL_NEEDED_TALK_POWER].as()); } if(cmd.hasParm("icon")){ - bulk["channel_icon_id"] = channel->properties()[property::CHANNEL_ICON_ID].as(); + result.put_unchecked(index, "channel_icon_id", channel->properties()[property::CHANNEL_ICON_ID].as()); } if(cmd.hasParm("limits")){ - bulk["total_clients_family"] = this->server ? this->server->getClientsByChannelRoot(channel, false).size() : 0; - bulk["total_clients"] = this->server ? this->server->getClientsByChannel(channel).size() : 0; + result.put_unchecked(index, "total_clients_family", this->server ? this->server->getClientsByChannelRoot(channel, false).size() : 0); + result.put_unchecked(index, "total_clients", this->server ? this->server->getClientsByChannel(channel).size() : 0); - bulk["channel_maxclients"] = channel->properties()[property::CHANNEL_MAXCLIENTS].as(); - bulk["channel_maxfamilyclients"] = channel->properties()[property::CHANNEL_MAXFAMILYCLIENTS].as(); + result.put_unchecked(index, "channel_maxclients", channel->properties()[property::CHANNEL_MAXCLIENTS].as()); + result.put_unchecked(index, "channel_maxfamilyclients", channel->properties()[property::CHANNEL_MAXFAMILYCLIENTS].as()); { auto needed_power = channel->permissions()->permission_value_flagged(permission::i_channel_subscribe_power); - bulk["channel_needed_subscribe_power"] = needed_power.has_value ? needed_power.value : 0; + result.put_unchecked(index, "channel_needed_subscribe_power", needed_power.has_value ? needed_power.value : 0); } } if(cmd.hasParm("topic")) { - bulk["channel_topic"] = channel->properties()[property::CHANNEL_TOPIC].as(); + result.put_unchecked(index, "channel_topic", channel->properties()[property::CHANNEL_TOPIC].as()); } if(cmd.hasParm("times")){ - bulk["seconds_empty"] = channel->emptySince(); + result.put_unchecked(index, "seconds_empty", channel->emptySince()); } index++; } - this->sendCommand(result); + this->sendCommand(result, false); return command_result{error::ok}; } @@ -544,33 +541,34 @@ command_result QueryClient::handleCommandServerList(Command& cmd) { CMD_RESET_IDLE; ACTION_REQUIRES_INSTANCE_PERMISSION(permission::b_serverinstance_virtualserver_list, 1); - Command res(""); + auto servers = serverInstance->getVoiceServerManager()->serverInstances(); + command_builder result{"", 256, servers.size()}; - int index = 0; - for(const auto& server : serverInstance->getVoiceServerManager()->serverInstances()){ - res[index]["virtualserver_id"] = server->getServerId(); - res[index]["virtualserver_host"] = server->properties()[property::VIRTUALSERVER_HOST].as(); - res[index]["virtualserver_port"] = server->properties()[property::VIRTUALSERVER_PORT].as(); - res[index]["virtualserver_web_host"] = server->properties()[property::VIRTUALSERVER_WEB_HOST].as(); - res[index]["virtualserver_web_port"] = server->properties()[property::VIRTUALSERVER_WEB_PORT].as(); - res[index]["virtualserver_status"] = ServerState::string(server->state); - res[index]["virtualserver_clientsonline"] = server->properties()[property::VIRTUALSERVER_CLIENTS_ONLINE].as(); - res[index]["virtualserver_queryclientsonline"] = server->properties()[property::VIRTUALSERVER_QUERYCLIENTS_ONLINE].as(); - res[index]["virtualserver_maxclients"] = server->properties()[property::VIRTUALSERVER_MAXCLIENTS].as(); + size_t index = 0; + for(const auto& server : serverInstance->getVoiceServerManager()->serverInstances()) { + result.put_unchecked(index, "virtualserver_id", server->getServerId()); + result.put_unchecked(index, "virtualserver_host", server->properties()[property::VIRTUALSERVER_HOST].as()); + result.put_unchecked(index, "virtualserver_port", server->properties()[property::VIRTUALSERVER_PORT].as()); + result.put_unchecked(index, "virtualserver_web_host", server->properties()[property::VIRTUALSERVER_WEB_HOST].as()); + result.put_unchecked(index, "virtualserver_web_port", server->properties()[property::VIRTUALSERVER_WEB_PORT].as()); + result.put_unchecked(index, "virtualserver_status", ServerState::string(server->state)); + result.put_unchecked(index, "virtualserver_clientsonline", server->properties()[property::VIRTUALSERVER_CLIENTS_ONLINE].as()); + result.put_unchecked(index, "virtualserver_queryclientsonline", server->properties()[property::VIRTUALSERVER_QUERYCLIENTS_ONLINE].as()); + result.put_unchecked(index, "virtualserver_maxclients", server->properties()[property::VIRTUALSERVER_MAXCLIENTS].as()); if(server->startTimestamp.time_since_epoch().count() > 0 && server->state == ServerState::ONLINE) - res[index]["virtualserver_uptime"] = duration_cast(system_clock::now() - server->startTimestamp).count(); + result.put_unchecked(index, "virtualserver_uptime", duration_cast(system_clock::now() - server->startTimestamp).count()); else - res[index]["virtualserver_uptime"] = 0; - res[index]["virtualserver_name"] = server->properties()[property::VIRTUALSERVER_NAME].as(); - res[index]["virtualserver_autostart"] = server->properties()[property::VIRTUALSERVER_AUTOSTART].as(); - res[index]["virtualserver_machine_id"] = server->properties()[property::VIRTUALSERVER_MACHINE_ID].as(); + result.put_unchecked(index, "virtualserver_uptime", 0); + result.put_unchecked(index, "virtualserver_name", server->properties()[property::VIRTUALSERVER_NAME].as()); + result.put_unchecked(index, "virtualserver_autostart", server->properties()[property::VIRTUALSERVER_AUTOSTART].as()); + result.put_unchecked(index, "virtualserver_machine_id", server->properties()[property::VIRTUALSERVER_MACHINE_ID].as()); if(cmd.hasParm("uid")) - res[index]["virtualserver_unique_identifier"] = server->properties()[property::VIRTUALSERVER_UNIQUE_IDENTIFIER].as(); - else res[index]["virtualserver_unique_identifier"] = ""; + result.put_unchecked(index, "virtualserver_unique_identifier", server->properties()[property::VIRTUALSERVER_UNIQUE_IDENTIFIER].as()); + else result.put_unchecked(index, "virtualserver_unique_identifier", ""); index++; } - this->sendCommand(res); + this->sendCommand(result, false); return command_result{error::ok}; } diff --git a/shared b/shared index 23a9385..00e8aca 160000 --- a/shared +++ b/shared @@ -1 +1 @@ -Subproject commit 23a9385afebbbdb2cba88c5ea5f84daf4c85acc4 +Subproject commit 00e8aca68ea5257d2fef20912428577171b640e2