From 86942e45c92af652156576115e12408f50ed37bb Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sat, 22 Feb 2020 14:14:44 +0100 Subject: [PATCH] A lot of updates --- server/src/Group.cpp | 2 +- server/src/InstanceHandler.cpp | 8 +++++ server/src/client/ConnectedClient.cpp | 10 ++---- server/src/client/command_handler/helpers.h | 2 ++ .../src/client/query/QueryClientCommands.cpp | 32 +++++++++++++++---- server/src/client/web/VoiceBridge.cpp | 4 ++- server/src/music/MusicBotManager.h | 2 +- 7 files changed, 43 insertions(+), 17 deletions(-) diff --git a/server/src/Group.cpp b/server/src/Group.cpp index f26cdd5..c157cd8 100644 --- a/server/src/Group.cpp +++ b/server/src/Group.cpp @@ -314,7 +314,7 @@ GroupId GroupManager::copyGroup(std::shared_ptr group, GroupType type, st auto groupId = generateGroupId(this->sql); auto print = LOG_SQL_CMD; - auto res = sql::command(this->sql, "INSERT INTO `permissions` (`serverId`, `type`, `id`, `channelId`, `permId`, `value`, `grant`) SELECT :tsid AS `serverId`, `type`, :target AS `id`, 0 AS `channelId`, `permId`, `value`,`grant` FROM `permissions` WHERE `serverId` = :ssid AND `type` = :type AND `id` = :source", + auto res = sql::command(this->sql, "INSERT INTO `permissions` (`serverId`, `type`, `id`, `channelId`, `permId`, `value`, `grant`, `flag_skip`, `flag_negate`) SELECT :tsid AS `serverId`, `type`, :target AS `id`, 0 AS `channelId`, `permId`, `value`,`grant`,`flag_skip`, `flag_negate` FROM `permissions` WHERE `serverId` = :ssid AND `type` = :type AND `id` = :source", variable{":target", groupId}, variable{":ssid", group_server}, variable{":tsid", targetServerId}, variable{":source", group->groupId()}, variable{":type", SQL_PERM_GROUP}).execute(); print(res); diff --git a/server/src/InstanceHandler.cpp b/server/src/InstanceHandler.cpp index 08a78bb..f6ea0eb 100644 --- a/server/src/InstanceHandler.cpp +++ b/server/src/InstanceHandler.cpp @@ -161,6 +161,14 @@ InstanceHandler::InstanceHandler(SqlDataManager *sql) : sql(sql) { this->properties()[property::SERVERINSTANCE_UNIQUE_ID] = ""; /* we def got a new instance */ } + if(this->default_tree->channel_count() == 4) { + auto default_channel = this->default_tree->findChannel("[cspacer04]Default Channel", nullptr); + if(default_channel) { + auto ch = this->default_tree->createChannel(0, default_channel->channelId(), "[cspacer05]Administrator Room"); + ch->permissions()->set_permission(permission::i_channel_needed_view_power, {75, 0}, permission::v2::set_value, permission::v2::do_nothing, false, false); + this->save_channel_permissions(); + } + } if(!this->default_tree->getDefaultChannel()) this->default_tree->setDefaultChannel(this->default_tree->findChannel("[cspacer04]Default Channel", nullptr)); if(!this->default_tree->getDefaultChannel()) this->default_tree->setDefaultChannel(*this->default_tree->channels().begin()); assert(this->default_tree->getDefaultChannel()); diff --git a/server/src/client/ConnectedClient.cpp b/server/src/client/ConnectedClient.cpp index 46f9cae..0ac2e5d 100644 --- a/server/src/client/ConnectedClient.cpp +++ b/server/src/client/ConnectedClient.cpp @@ -560,14 +560,8 @@ bool ConnectedClient::notifyClientNeededPermissions() { cache_lock.unlock(); for(const auto& value : permissions) { - if(value.second.has_value) { - cmd[index]["permid"] = value.first; - cmd[index++]["permvalue"] = value.second.value; - } - } - if(permissions.empty()) { - cmd[0]["permid"] = permission::b_client_force_push_to_talk; - cmd[0]["permvalue"] = false; + cmd[index]["permid"] = value.first; + cmd[index++]["permvalue"] = value.second.has_value ? value.second.value : 0; } this->sendCommand(cmd); diff --git a/server/src/client/command_handler/helpers.h b/server/src/client/command_handler/helpers.h index efc2ad9..1d60bca 100644 --- a/server/src/client/command_handler/helpers.h +++ b/server/src/client/command_handler/helpers.h @@ -130,6 +130,8 @@ inline bool permission_require_granted_value(ts::permission::PermissionType type case permission::i_icon_id: case permission::i_max_icon_filesize: case permission::i_client_max_avatar_filesize: + case permission::i_ft_quota_mb_download_per_client: + case permission::i_ft_quota_mb_upload_per_client: case permission::i_client_max_channels: case permission::i_client_max_permanent_channels: diff --git a/server/src/client/query/QueryClientCommands.cpp b/server/src/client/query/QueryClientCommands.cpp index 7cddaa2..f184190 100644 --- a/server/src/client/query/QueryClientCommands.cpp +++ b/server/src/client/query/QueryClientCommands.cpp @@ -303,8 +303,7 @@ command_result QueryClient::handleCommandServerSelect(Command &cmd) { target = serverInstance->getVoiceServerManager()->findServerById(static_cast(stol(parm))); if(!target && (!cmd[0].has("0") && (!cmd[0].has("sid") || !cmd["sid"] == 0))) return command_result{error::server_invalid_id, "Invalid server id"}; - - + if(target && target->getState() != ServerState::ONLINE) return command_result{error::server_is_not_running}; if(target == this->server) return command_result{error::ok}; if(target) { @@ -375,8 +374,8 @@ command_result QueryClient::handleCommandServerSelect(Command &cmd) { command_result QueryClient::handleCommandJoin(Command &) { CMD_REQ_SERVER; CMD_RESET_IDLE; - if(!this->server->running()) - return command_result{error::server_is_not_running, "server isnt started yet"}; + if(this->server->state != ServerState::ONLINE) + return command_result{error::server_is_not_running}; if(this->currentChannel) return command_result{error::server_already_joined, "already joined!"}; @@ -670,7 +669,18 @@ command_result QueryClient::handleCommandServerStart(Command& cmd) { auto server = serverInstance->getVoiceServerManager()->findServerById(cmd["sid"]); if(!server) return command_result{error::server_invalid_id, "invalid bounded server"}; - if(server->running()) return command_result{error::server_running, "server already running"}; + + switch (server->state) { + case ServerState::BOOTING: + return command_result{error::server_is_booting}; + case ServerState::ONLINE: + return command_result{error::server_running}; + case ServerState::SUSPENDING: + return command_result{error::server_is_shutting_down}; + case ServerState::DELETING: + return command_result{error::server_invalid_id}; + case ServerState::OFFLINE: break; + } if(!permission::v2::permission_granted(1, server->calculate_permission(permission::b_virtualserver_start, this->getClientDatabaseId(), ClientType::CLIENT_QUERY, 0))) ACTION_REQUIRES_INSTANCE_PERMISSION(permission::b_virtualserver_start_any, 1); @@ -688,7 +698,17 @@ command_result QueryClient::handleCommandServerStop(Command& cmd) { auto server = serverInstance->getVoiceServerManager()->findServerById(cmd["sid"]); if(!server) return command_result{error::server_invalid_id, "invalid bounded server"}; - if(!server->running()) return command_result{error::server_is_not_running, "server is not running"}; + switch (server->state) { + case ServerState::BOOTING: + return command_result{error::server_is_booting}; + case ServerState::OFFLINE: + return command_result{error::server_is_not_running}; + case ServerState::SUSPENDING: + return command_result{error::server_is_shutting_down}; + case ServerState::DELETING: + return command_result{error::server_invalid_id}; + case ServerState::ONLINE: break; + } if(!permission::v2::permission_granted(1, server->calculate_permission(permission::b_virtualserver_stop, this->getClientDatabaseId(), ClientType::CLIENT_QUERY, 0))) ACTION_REQUIRES_INSTANCE_PERMISSION(permission::b_virtualserver_stop_any, 1); diff --git a/server/src/client/web/VoiceBridge.cpp b/server/src/client/web/VoiceBridge.cpp index 44bf469..42c4244 100644 --- a/server/src/client/web/VoiceBridge.cpp +++ b/server/src/client/web/VoiceBridge.cpp @@ -61,7 +61,9 @@ VoiceBridge::VoiceBridge(const shared_ptr& owner) : _owner(owner) { this->connection = make_unique(config); } -VoiceBridge::~VoiceBridge() {} +VoiceBridge::~VoiceBridge() { + __asm__("nop"); +} int VoiceBridge::server_id() { auto locked = this->_owner.lock(); diff --git a/server/src/music/MusicBotManager.h b/server/src/music/MusicBotManager.h index 87be6ca..aae69fe 100644 --- a/server/src/music/MusicBotManager.h +++ b/server/src/music/MusicBotManager.h @@ -25,7 +25,7 @@ namespace ts { static void adjustTickPool(); - MusicBotManager(const std::shared_ptr&); + explicit MusicBotManager(const std::shared_ptr&); ~MusicBotManager(); void load_bots();