Fixed the server group create command

This commit is contained in:
WolverinDEV 2020-09-16 14:27:27 +02:00
parent a8bd42fd3f
commit 0a3585f4f8
3 changed files with 57 additions and 12 deletions

@ -1 +1 @@
Subproject commit b36b1e19aeb8bd5026437d2bb0b4d91c480ed65b
Subproject commit a1530bc0ffa4566d4d601ada07a33fd8ea9f7078

View File

@ -163,12 +163,29 @@ command_result ConnectedClient::handleCommandChannelGroupAdd(Command &cmd) {
auto group = group_manager->createGroup(GroupTarget::GROUPTARGET_CHANNEL, cmd["type"].as<GroupType>(), cmd["name"].string());
serverInstance->action_logger()->group_logger.log_group_create(this->getServerId(), this->ref(), log::GroupTarget::CHANNEL, log_group_type, group->groupId(), group->name(), 0, "");
{
ts::command_builder notify{this->notify_response_command("notifychannelgroupadded")};
notify.put_unchecked(0, "cgid", group->groupId());
this->sendCommand(notify);
}
if (group) {
group->permissions()->set_permission(permission::b_group_is_permanent, {1, 0}, permission::v2::set_value, permission::v2::do_nothing);
if(this->server)
this->server->forEachClient([](shared_ptr<ConnectedClient> cl) {
cl->notifyChannelGroupList();
});
if(this->server) {
if(this->getType() == ClientType::CLIENT_QUERY) {
this->server->forEachClient([&](const std::shared_ptr<ConnectedClient>& cl) {
if(cl == this) {
return;
}
cl->notifyChannelGroupList();
});
} else {
this->server->forEachClient([](const std::shared_ptr<ConnectedClient>& cl) {
cl->notifyChannelGroupList();
});
}
}
} else return command_result{error::group_invalid_id};
return command_result{error::ok};
}

View File

@ -304,9 +304,15 @@ command_result ConnectedClient::handleCommandServerGroupAdd(Command &cmd) {
CMD_CHK_AND_INC_FLOOD_POINTS(5);
ACTION_REQUIRES_GLOBAL_PERMISSION(permission::b_virtualserver_servergroup_create, 1);
if(cmd["name"].string().empty()) return command_result{error::parameter_invalid};
if(cmd["name"].string().empty()) {
return command_result{error::parameter_invalid, "name"};
}
log::GroupType log_group_type;
if(!cmd[0].has("type")) {
cmd["type"] = GroupType::GROUP_TYPE_NORMAL;
}
if(cmd["type"].as<GroupType>() == GroupType::GROUP_TYPE_QUERY) {
ACTION_REQUIRES_GLOBAL_PERMISSION(permission::b_serverinstance_modify_querygroup, 1);
log_group_type = log::GroupType::QUERY;
@ -321,17 +327,39 @@ command_result ConnectedClient::handleCommandServerGroupAdd(Command &cmd) {
}
auto group_manager = this->server ? this->server->getGroupManager() : serverInstance->getGroupManager().get();
for(const auto& gr : group_manager->availableServerGroups(true))
if(gr->name() == cmd["name"].string() && gr->target() == GroupTarget::GROUPTARGET_SERVER) return command_result{error::parameter_invalid, "Group already exists"};
for(const auto& gr : group_manager->availableServerGroups(true)) {
if(gr->name() == cmd["name"].string() && gr->target() == GroupTarget::GROUPTARGET_SERVER) {
return command_result{error::parameter_invalid, "Group already exists"};
}
}
auto group = group_manager->createGroup(GroupTarget::GROUPTARGET_SERVER, cmd["type"].as<GroupType>(), cmd["name"].string());
if(!group)
if(!group) {
return command_result{error::vs_critical};
}
group->permissions()->set_permission(permission::b_group_is_permanent, {1,0}, permission::v2::set_value, permission::v2::do_nothing);
{
ts::command_builder notify{this->notify_response_command("notifyservergroupadded")};
notify.put_unchecked(0, "sgid", group->groupId());
this->sendCommand(notify);
}
if(this->server) {
this->server->forEachClient([](shared_ptr<ConnectedClient> cl) {
cl->notifyServerGroupList();
});
if(this->getType() == ClientType::CLIENT_QUERY) {
this->server->forEachClient([&](const shared_ptr<ConnectedClient>& cl) {
if(cl == this) {
return;
}
cl->notifyServerGroupList();
});
} else {
this->server->forEachClient([&](const shared_ptr<ConnectedClient>& cl) {
cl->notifyServerGroupList();
});
}
}
serverInstance->action_logger()->group_logger.log_group_create(this->getServerId(), this->ref(), log::GroupTarget::SERVER, log_group_type, group->groupId(), group->name(), 0, "");
return command_result{error::ok};