Fixed some bugs related to the new server setup
This commit is contained in:
parent
ceb77a2c85
commit
41f5b30f56
@ -1 +1 @@
|
|||||||
Subproject commit 8c2608f90739a42cd727c8c8eab3d60bbb6dca53
|
Subproject commit 4dfe9fbf023777cbc6dbb278cd1e161fe464edb4
|
@ -118,7 +118,7 @@ bool InstanceHandler::setupDefaultGroups() {
|
|||||||
groups.push_back(group);
|
groups.push_back(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
debugMessage(LOG_INSTANCE, "Read " + to_string(groups.size()) + " default groups");
|
debugMessage(LOG_INSTANCE, "Read {} default groups", groups.size());
|
||||||
for(const auto& info : groups) {
|
for(const auto& info : groups) {
|
||||||
debugMessage(LOG_INSTANCE, "Creating default group {} with type {}", info->name, to_string(info->target));
|
debugMessage(LOG_INSTANCE, "Creating default group {} with type {}", info->name, to_string(info->target));
|
||||||
//Query groups
|
//Query groups
|
||||||
@ -131,8 +131,8 @@ bool InstanceHandler::setupDefaultGroups() {
|
|||||||
create_result = serverInstance->group_manager()->channel_groups()->create_group(groups::GroupType::GROUP_TYPE_TEMPLATE, info->name, c_group);
|
create_result = serverInstance->group_manager()->channel_groups()->create_group(groups::GroupType::GROUP_TYPE_TEMPLATE, info->name, c_group);
|
||||||
created_group = c_group;
|
created_group = c_group;
|
||||||
} else {
|
} else {
|
||||||
std::shared_ptr<groups::ChannelGroup> s_group{};
|
std::shared_ptr<groups::ServerGroup> s_group{};
|
||||||
create_result = serverInstance->group_manager()->channel_groups()->create_group(info->target == 0 ? groups::GroupType::GROUP_TYPE_QUERY : groups::GroupType::GROUP_TYPE_TEMPLATE, info->name, s_group);
|
create_result = serverInstance->group_manager()->server_groups()->create_group(info->target == 0 ? groups::GroupType::GROUP_TYPE_QUERY : groups::GroupType::GROUP_TYPE_TEMPLATE, info->name, s_group);
|
||||||
created_group = s_group;
|
created_group = s_group;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,8 +62,8 @@ ClientPermissionCalculator::ClientPermissionCalculator(
|
|||||||
if(server) {
|
if(server) {
|
||||||
this->virtual_server_id = server->getServerId();
|
this->virtual_server_id = server->getServerId();
|
||||||
this->group_manager_ = server->group_manager();
|
this->group_manager_ = server->group_manager();
|
||||||
|
this->default_server_group = [server]{ return server->default_server_group(); };
|
||||||
this->default_channel_group = [server]{ return server->default_channel_group(); };
|
this->default_channel_group = [server]{ return server->default_channel_group(); };
|
||||||
|
|
||||||
std::shared_ptr<BasicChannel> channel{};
|
std::shared_ptr<BasicChannel> channel{};
|
||||||
try {
|
try {
|
||||||
std::shared_lock channel_lock{server->get_channel_tree_lock()};
|
std::shared_lock channel_lock{server->get_channel_tree_lock()};
|
||||||
@ -94,6 +94,7 @@ void ClientPermissionCalculator::initialize_client(DataClient* client) {
|
|||||||
auto server = client->getServer();
|
auto server = client->getServer();
|
||||||
if(server) {
|
if(server) {
|
||||||
this->group_manager_ = server->group_manager();
|
this->group_manager_ = server->group_manager();
|
||||||
|
this->default_server_group = [server]{ return server->default_server_group(); };
|
||||||
this->default_channel_group = [server]{ return server->default_channel_group(); };
|
this->default_channel_group = [server]{ return server->default_channel_group(); };
|
||||||
} else {
|
} else {
|
||||||
this->group_manager_ = serverInstance->group_manager();
|
this->group_manager_ = serverInstance->group_manager();
|
||||||
@ -340,6 +341,12 @@ const std::vector<std::shared_ptr<groups::ServerGroup>>& ClientPermissionCalcula
|
|||||||
this->assigned_server_groups_->push_back(group);
|
this->assigned_server_groups_->push_back(group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(this->assigned_server_groups_->empty() && this->default_server_group) {
|
||||||
|
auto default_group = this->default_server_group();
|
||||||
|
if(default_group) {
|
||||||
|
this->assigned_server_groups_->push_back(default_group);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return *this->assigned_server_groups_;
|
return *this->assigned_server_groups_;
|
||||||
}
|
}
|
||||||
|
@ -65,6 +65,7 @@ namespace ts::server {
|
|||||||
std::shared_ptr<groups::GroupManager> group_manager_{};
|
std::shared_ptr<groups::GroupManager> group_manager_{};
|
||||||
std::shared_ptr<permission::v2::PermissionManager> channel_permissions{};
|
std::shared_ptr<permission::v2::PermissionManager> channel_permissions{};
|
||||||
std::function<std::shared_ptr<groups::ChannelGroup>()> default_channel_group{[]{ return nullptr; }};
|
std::function<std::shared_ptr<groups::ChannelGroup>()> default_channel_group{[]{ return nullptr; }};
|
||||||
|
std::function<std::shared_ptr<groups::ServerGroup>()> default_server_group{[]{ return nullptr; }};
|
||||||
|
|
||||||
/* fields which will be set when calculating permissions */
|
/* fields which will be set when calculating permissions */
|
||||||
std::shared_ptr<permission::v2::PermissionManager> client_permissions{};
|
std::shared_ptr<permission::v2::PermissionManager> client_permissions{};
|
||||||
|
@ -1028,15 +1028,15 @@ bool VirtualServer::resetPermissions(std::string& new_permission_token) {
|
|||||||
|
|
||||||
this->ensureValidDefaultGroups();
|
this->ensureValidDefaultGroups();
|
||||||
|
|
||||||
|
this->task_notify_channel_group_list.enqueue();
|
||||||
|
this->task_notify_server_group_list.enqueue();
|
||||||
|
|
||||||
for(const auto& client : this->getClients()) {
|
for(const auto& client : this->getClients()) {
|
||||||
client->task_update_displayed_groups.enqueue();
|
client->task_update_displayed_groups.enqueue();
|
||||||
client->task_update_needed_permissions.enqueue();
|
client->task_update_needed_permissions.enqueue();
|
||||||
client->task_update_channel_client_properties.enqueue();
|
client->task_update_channel_client_properties.enqueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
this->task_notify_channel_group_list.enqueue();
|
|
||||||
this->task_notify_server_group_list.enqueue();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1169,11 +1169,33 @@ void VirtualServer::update_channel_from_permissions(const std::shared_ptr<BasicC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<groups::ChannelGroup> VirtualServer::default_channel_group() {
|
std::shared_ptr<groups::ServerGroup> VirtualServer::default_server_group() {
|
||||||
auto group_id = this->properties()[property::VIRTUALSERVER_DEFAULT_CHANNEL_GROUP].as_or<GroupId>(0);
|
auto group_id = this->properties()[property::VIRTUALSERVER_DEFAULT_SERVER_GROUP].as_or<GroupId>(0);
|
||||||
auto group = this->group_manager()->channel_groups()->find_group(groups::GroupCalculateMode::GLOBAL, group_id);
|
auto group = this->group_manager()->server_groups()->find_group(groups::GroupCalculateMode::GLOBAL, group_id);
|
||||||
if(!group) {
|
if(!group) {
|
||||||
auto groups = this->group_manager()->channel_groups()->available_groups(groups::GroupCalculateMode::GLOBAL);
|
auto groups = this->group_manager()->server_groups()->available_groups(groups::GroupCalculateMode::GLOBAL);
|
||||||
|
if(groups.empty()) {
|
||||||
|
logCritical(this->serverId, "Having no available server groups.");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TODO: Log warning? */
|
||||||
|
group = groups.back();
|
||||||
|
}
|
||||||
|
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<groups::ChannelGroup> VirtualServer::default_channel_group() {
|
||||||
|
auto group_id = this->properties()[property::VIRTUALSERVER_DEFAULT_CHANNEL_GROUP].as_or<GroupId>(0);
|
||||||
|
auto group = this->group_manager()->channel_groups()->find_group(groups::GroupCalculateMode::GLOBAL, group_id);
|
||||||
|
if(!group) {
|
||||||
|
auto groups = this->group_manager()->channel_groups()->available_groups(groups::GroupCalculateMode::GLOBAL);
|
||||||
|
if(groups.empty()) {
|
||||||
|
logCritical(this->serverId, "Having no available channel groups.");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
/* TODO: Log warning? */
|
/* TODO: Log warning? */
|
||||||
group = groups.back();
|
group = groups.back();
|
||||||
}
|
}
|
||||||
|
@ -72,6 +72,7 @@ namespace ts {
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace groups {
|
namespace groups {
|
||||||
|
class ServerGroup;
|
||||||
class ChannelGroup;
|
class ChannelGroup;
|
||||||
class GroupManager;
|
class GroupManager;
|
||||||
}
|
}
|
||||||
@ -182,6 +183,7 @@ namespace ts {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] inline auto group_manager() { return this->groups_manager_; }
|
[[nodiscard]] inline auto group_manager() { return this->groups_manager_; }
|
||||||
|
[[nodiscard]] std::shared_ptr<groups::ServerGroup> default_server_group();
|
||||||
[[nodiscard]] std::shared_ptr<groups::ChannelGroup> default_channel_group();
|
[[nodiscard]] std::shared_ptr<groups::ChannelGroup> default_channel_group();
|
||||||
|
|
||||||
bool notifyServerEdited(std::shared_ptr<ConnectedClient>, std::deque<std::string> keys);
|
bool notifyServerEdited(std::shared_ptr<ConnectedClient>, std::deque<std::string> keys);
|
||||||
|
@ -1047,6 +1047,10 @@ void ConnectedClient::update_displayed_client_groups(bool& server_groups_changed
|
|||||||
|
|
||||||
if(!server_group_assignments.empty()) {
|
if(!server_group_assignments.empty()) {
|
||||||
server_group_assignments = server_group_assignments.substr(1);
|
server_group_assignments = server_group_assignments.substr(1);
|
||||||
|
} else if(auto default_group{ref_server->default_server_group()}; default_group) {
|
||||||
|
server_group_assignments = std::to_string(default_group->group_id());
|
||||||
|
} else {
|
||||||
|
server_group_assignments = "0";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_lock view_lock{this->channel_lock};
|
std::unique_lock view_lock{this->channel_lock};
|
||||||
|
@ -91,28 +91,28 @@ command_result ConnectedClient::handleCommandServerEdit(Command &cmd) {
|
|||||||
SERVEREDIT_CHK_PROP_CACHED("virtualserver_default_server_group", permission::b_virtualserver_modify_default_servergroup, GroupId)
|
SERVEREDIT_CHK_PROP_CACHED("virtualserver_default_server_group", permission::b_virtualserver_modify_default_servergroup, GroupId)
|
||||||
if(target_server) {
|
if(target_server) {
|
||||||
auto target_group = group_manager->server_groups()->find_group(groups::GroupCalculateMode::GLOBAL, cmd["virtualserver_default_server_group"].as<GroupId>());
|
auto target_group = group_manager->server_groups()->find_group(groups::GroupCalculateMode::GLOBAL, cmd["virtualserver_default_server_group"].as<GroupId>());
|
||||||
if (target_group) {
|
if (!target_group) {
|
||||||
return command_result{error::group_invalid_id};
|
return command_result{error::group_invalid_id};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} SERVEREDIT_CHK_PROP_CACHED("virtualserver_default_channel_group", permission::b_virtualserver_modify_default_channelgroup, GroupId)
|
} SERVEREDIT_CHK_PROP_CACHED("virtualserver_default_channel_group", permission::b_virtualserver_modify_default_channelgroup, GroupId)
|
||||||
if(target_server) {
|
if(target_server) {
|
||||||
auto target_group = group_manager->channel_groups()->find_group(groups::GroupCalculateMode::GLOBAL, cmd["virtualserver_default_channel_group"].as<GroupId>());
|
auto target_group = group_manager->channel_groups()->find_group(groups::GroupCalculateMode::GLOBAL, cmd["virtualserver_default_channel_group"].as<GroupId>());
|
||||||
if (target_group) {
|
if (!target_group) {
|
||||||
return command_result{error::group_invalid_id};
|
return command_result{error::group_invalid_id};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} SERVEREDIT_CHK_PROP_CACHED("virtualserver_default_channel_admin_group", permission::b_virtualserver_modify_default_channeladmingroup, GroupId)
|
} SERVEREDIT_CHK_PROP_CACHED("virtualserver_default_channel_admin_group", permission::b_virtualserver_modify_default_channeladmingroup, GroupId)
|
||||||
if(target_server) {
|
if(target_server) {
|
||||||
auto target_group = group_manager->channel_groups()->find_group(groups::GroupCalculateMode::GLOBAL, cmd["virtualserver_default_channel_admin_group"].as<GroupId>());
|
auto target_group = group_manager->channel_groups()->find_group(groups::GroupCalculateMode::GLOBAL, cmd["virtualserver_default_channel_admin_group"].as<GroupId>());
|
||||||
if (target_group) {
|
if (!target_group) {
|
||||||
return command_result{error::group_invalid_id};
|
return command_result{error::group_invalid_id};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} SERVEREDIT_CHK_PROP_CACHED("virtualserver_default_music_group", permission::b_virtualserver_modify_default_musicgroup, GroupId)
|
} SERVEREDIT_CHK_PROP_CACHED("virtualserver_default_music_group", permission::b_virtualserver_modify_default_musicgroup, GroupId)
|
||||||
if(target_server) {
|
if(target_server) {
|
||||||
auto target_group = group_manager->server_groups()->find_group(groups::GroupCalculateMode::GLOBAL, cmd["virtualserver_default_server_group"].as<GroupId>());
|
auto target_group = group_manager->server_groups()->find_group(groups::GroupCalculateMode::GLOBAL, cmd["virtualserver_default_server_group"].as<GroupId>());
|
||||||
if (target_group) {
|
if (!target_group) {
|
||||||
return command_result{error::group_invalid_id};
|
return command_result{error::group_invalid_id};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -366,10 +366,14 @@ command_result ConnectedClient::handleCommandServerGroupClientList(Command &cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(index == 0) {
|
if(index == 0) {
|
||||||
return ts::command_result{error::database_empty_result};
|
if(this->getType() != ClientType::CLIENT_TEAMSPEAK) {
|
||||||
|
/* TS3 clients don't want a error here. They're fine with just not receiving a notify */
|
||||||
|
return ts::command_result{error::database_empty_result};
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this->sendCommand(notify);
|
||||||
}
|
}
|
||||||
|
|
||||||
this->sendCommand(notify);
|
|
||||||
return command_result{error::ok};
|
return command_result{error::ok};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -734,6 +734,11 @@ void GroupAssignmentManager::handle_channel_group_deleted(GroupId group_id) {
|
|||||||
void GroupAssignmentManager::reset_all() {
|
void GroupAssignmentManager::reset_all() {
|
||||||
auto sql = sql::command{this->sql_manager(), "DELETE FROM `assignedGroups` WHERE `serverId` = :sid", variable{":sid", this->server_id()}};
|
auto sql = sql::command{this->sql_manager(), "DELETE FROM `assignedGroups` WHERE `serverId` = :sid", variable{":sid", this->server_id()}};
|
||||||
sql.executeLater().waitAndGetLater(LOG_SQL_CMD, {-1, "failed to delete all assignments"});
|
sql.executeLater().waitAndGetLater(LOG_SQL_CMD, {-1, "failed to delete all assignments"});
|
||||||
|
|
||||||
|
{
|
||||||
|
std::lock_guard cache_lock{*this->client_cache_lock};
|
||||||
|
this->client_cache.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<TemporaryAssignmentsLock> GroupAssignmentManager::create_tmp_assignment_lock(ClientDbId cldbid) {
|
std::shared_ptr<TemporaryAssignmentsLock> GroupAssignmentManager::create_tmp_assignment_lock(ClientDbId cldbid) {
|
||||||
|
@ -122,12 +122,12 @@ void AbstractGroupManager::reset_groups(std::map<GroupId, GroupId> &mapping) {
|
|||||||
|
|
||||||
/* Delete all old groups */
|
/* Delete all old groups */
|
||||||
{
|
{
|
||||||
LOG_SQL_CMD(sql::command(this->sql_manager(), "DELETE FROM `permissions` WHERE `serverId` = :serverId AND `type` = :type AND `id` IN (SELECT `groupId` FROM `groups` WHERE `serverId` = :serverId AND AND `target` = :target)",
|
LOG_SQL_CMD(sql::command(this->sql_manager(), "DELETE FROM `permissions` WHERE `serverId` = :serverId AND `type` = :type AND `id` IN (SELECT `groupId` FROM `groups` WHERE `serverId` = :serverId AND `target` = :target)",
|
||||||
variable{":serverId", this->server_id()},
|
variable{":serverId", this->server_id()},
|
||||||
variable{":type", ts::permission::SQL_PERM_GROUP},
|
variable{":type", ts::permission::SQL_PERM_GROUP},
|
||||||
variable{":target", (uint8_t) this->database_target_}).execute());
|
variable{":target", (uint8_t) this->database_target_}).execute());
|
||||||
|
|
||||||
LOG_SQL_CMD(sql::command(this->sql_manager(), "DELETE FROM `assignedGroups` WHERE `serverId` = :serverId AND `groupId` IN (SELECT `groupId` FROM `groups` WHERE `serverId` = :serverId AND AND `target` = :target)",
|
LOG_SQL_CMD(sql::command(this->sql_manager(), "DELETE FROM `assignedGroups` WHERE `serverId` = :serverId AND `groupId` IN (SELECT `groupId` FROM `groups` WHERE `serverId` = :AND AND `target` = :target)",
|
||||||
variable{":serverId", this->server_id()},
|
variable{":serverId", this->server_id()},
|
||||||
variable{":target", (uint8_t) this->database_target_}).execute());
|
variable{":target", (uint8_t) this->database_target_}).execute());
|
||||||
|
|
||||||
@ -137,7 +137,8 @@ void AbstractGroupManager::reset_groups(std::map<GroupId, GroupId> &mapping) {
|
|||||||
).execute());
|
).execute());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(auto error = this->load_data(true); error != GroupLoadResult::SUCCESS) {
|
/* we expect to not have any groups */
|
||||||
|
if(auto error = this->load_data(true); error != GroupLoadResult::NO_GROUPS) {
|
||||||
logCritical(this->server_id(), "Failed to load groups after group unload ({}). There might be no groups loaded now!", (int) error);
|
logCritical(this->server_id(), "Failed to load groups after group unload ({}). There might be no groups loaded now!", (int) error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user