+++ /dev/null
-/* cmd_global_modcmd.c - NeonServ v5.3
- * Copyright (C) 2011-2012 Philipp Kreil (pk910)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "cmd_global.h"
-
-/*
-* argv[0] command
-* argv[1] setting
-* argv[2] value
-*/
-
-static int global_cmd_modcmd_params(struct UserNode *user, struct cmd_binding *cbind, char *value);
-static int global_cmd_modcmd_flags(struct UserNode *user, struct cmd_binding *cbind, char *value);
-static int global_cmd_modcmd_caccess(struct UserNode *user, struct cmd_binding *cbind, char *value);
-static int global_cmd_modcmd_oaccess(struct UserNode *user, struct cmd_binding *cbind, char *value);
-
-CMD_BIND(global_cmd_modcmd) {
- MYSQL_RES *res;
- MYSQL_ROW row;
- struct cmd_binding *cbind = find_botwise_cmd_binding(client->botid, client->clientid, argv[0]);
- if (!cbind) {
- reply(getTextBot(), user, "NS_UNBIND_NOT_FOUND", argv[0]);
- return;
- }
- int uaccess = 0;
- printf_mysql_query("SELECT `user_access` FROM `users` WHERE `user_user` = '%s'", escape_string(user->auth));
- res = mysql_use();
- if ((row = mysql_fetch_row(res)) != NULL) {
- uaccess = atoi(row[0]);
- }
- int gaccess = ((cbind->flags & CMDFLAG_OVERRIDE_GLOBAL_ACCESS) ? cbind->global_access : cbind->func->global_access);
- if(gaccess > uaccess) {
- reply(getTextBot(), user, "NS_MODCMD_OUTRANKED", cbind->cmd, gaccess);
- return;
- }
- if(argc > 1) {
- char *value;
- if(argc > 2) {
- value = merge_argv(argv, 2, argc);
- } else
- value = NULL;
- int log_event = 0;
- if(!stricmp(argv[1], "caccess")) log_event = global_cmd_modcmd_caccess(user, cbind, value);
- else if(!stricmp(argv[1], "oaccess")) log_event = global_cmd_modcmd_oaccess(user, cbind, value);
- else if(!stricmp(argv[1], "parameters")) log_event = global_cmd_modcmd_params(user, cbind, value);
- else if(!stricmp(argv[1], "flags")) log_event = global_cmd_modcmd_flags(user, cbind, value);
- else {
- reply(getTextBot(), user, "NS_MODCMD_SETTING", argv[1]);
- }
- if(log_event) {
- logEvent(event);
- }
- } else {
- reply(getTextBot(), user, "NS_MODCMD_HEADER", cbind->cmd);
- global_cmd_modcmd_params(user, cbind, NULL);
- global_cmd_modcmd_caccess(user, cbind, NULL);
- global_cmd_modcmd_oaccess(user, cbind, NULL);
- global_cmd_modcmd_flags(user, cbind, NULL);
- }
-}
-
-static int global_cmd_modcmd_params(struct UserNode *user, struct cmd_binding *cbind, char *value) {
- char parameters[MAXLEN];
- int ret = 0;
- if(cbind->paramcount) {
- int i, parampos = 0;
- for(i = 0; i < cbind->paramcount; i++) {
- parampos += sprintf(parameters + parampos, (i ? " %s" : "%s"), cbind->parameters[i]);
- }
- } else
- parameters[0] = '\0';
- if(value) {
- if(!strcmp(value, "*"))
- value = NULL;
- bind_botwise_set_parameters(cbind->botid, cbind->clientid, cbind->cmd, value);
- if(cbind->botid == 0)
- printf_mysql_query("UPDATE `bot_binds` SET `parameters` = '%s' WHERE `botclass` = '0' AND `botid` = '%d' AND `command` = '%s'", (value ? escape_string(value) : ""), cbind->clientid, escape_string(cbind->cmd));
- else
- printf_mysql_query("UPDATE `bot_binds` SET `parameters` = '%s' WHERE `botclass` = '%d' AND `command` = '%s'", (value ? escape_string(value) : ""), cbind->botid, escape_string(cbind->cmd));
- strcpy(parameters, (value ? value : ""));
- ret = 1;
- }
- reply(getTextBot(), user, "\002PARAMETERS \002 %s", parameters);
- return ret;
-}
-
-static const struct {
- const char *name;
- unsigned int flag;
-} global_cmd_modcmd_show_flags[] = {
- {"REQUIRE_CHAN", CMDFLAG_REQUIRE_CHAN}, //The command requires a valid channel (at least one bot in it)
- {"REQUIRE_AUTH", CMDFLAG_REQUIRE_AUTH}, //The command requires the user to be authenticated
- {"REQUIRE_GOD", CMDFLAG_REQUIRE_GOD}, //The command requires the user to have security override enabled
- {"REQUIRE_REGISTERED", CMDFLAG_REGISTERED_CHAN}, //The command requires the channel to be registered (database entry)
- {"CHECK_AUTH", CMDFLAG_CHECK_AUTH}, //WHO the user if no auth is known, yet
- {"CHANNEL_ARGS", CMDFLAG_CHAN_PARAM}, //don't interpret channel arguments as channel - just pass them as a string
- {"LOG", CMDFLAG_LOG},
- {"OPLOG", CMDFLAG_OPLOG},
- {"FUNCMD", CMDFLAG_FUNCMD},
- {"ESCAPED_ARGS", CMDFLAG_ESCAPE_ARGS}, //allows arguments to be escaped ("a\ b" = "a b" as one argument)
- {"NO_CROSSCHAN", CMDFLAG_NO_CROSSCHAN},
- {NULL, 0}
-};
-
-static int global_cmd_modcmd_flags(struct UserNode *user, struct cmd_binding *cbind, char *value) {
- char flags[MAXLEN];
- int flagpos = 0;
- int ret = 0;
- unsigned int visible_flags = 0;
- int i = 0;
- while(global_cmd_modcmd_show_flags[i].name) {
- if(cbind->func->flags & global_cmd_modcmd_show_flags[i].flag) {
- flagpos += sprintf(flags + flagpos, (flagpos ? " %s" : "\00314%s"), global_cmd_modcmd_show_flags[i].name);
- }
- visible_flags |= global_cmd_modcmd_show_flags[i].flag;
- i++;
- }
- if(flagpos)
- flags[flagpos++] = '\003';
- if(value) {
- int add = 1;
- unsigned int current_flag = 0;
- if(value[0] == '+') {
- value++;
- } else if(value[0] == '-') {
- add = 0;
- value++;
- }
- if(*value) {
- i = 0;
- while(global_cmd_modcmd_show_flags[i].name) {
- if(!stricmp(global_cmd_modcmd_show_flags[i].name, value)) {
- current_flag = global_cmd_modcmd_show_flags[i].flag;
- break;
- }
- i++;
- }
- }
- if(cbind->func->flags & current_flag) {
- reply(getTextBot(), user, "NS_MODCMD_STATIC_FLAG");
- return 0;
- }
- if(add)
- cbind->flags |= current_flag;
- else
- cbind->flags &= ~current_flag;
- if(cbind->botid == 0)
- printf_mysql_query("UPDATE `bot_binds` SET `flags` = '%u' WHERE `botclass` = '0' AND `botid` = '%d' AND `command` = '%s'", (cbind->flags & visible_flags), cbind->clientid, escape_string(cbind->cmd));
- else
- printf_mysql_query("UPDATE `bot_binds` SET `flags` = '%u' WHERE `botclass` = '%d' AND `command` = '%s'", (cbind->flags & visible_flags), cbind->botid, escape_string(cbind->cmd));
- ret = 1;
- }
- i = 0;
- while(global_cmd_modcmd_show_flags[i].name) {
- if(cbind->flags & global_cmd_modcmd_show_flags[i].flag) {
- flagpos += sprintf(flags + flagpos, (flagpos ? " %s" : "%s"), global_cmd_modcmd_show_flags[i].name);
- }
- i++;
- }
- flags[flagpos] = '\0';
- reply(getTextBot(), user, "\002FLAGS \002 %s", flags);
- return ret;
-}
-
-static int global_cmd_modcmd_caccess(struct UserNode *user, struct cmd_binding *cbind, char *value) {
- char caccess[MAXLEN];
- int ret = 0;
- if(value) {
- if(!strcmp(value, "*"))
- value = NULL;
- bind_botwise_set_channel_access(cbind->botid, cbind->clientid, cbind->cmd, value);
- if(cbind->botid == 0)
- printf_mysql_query("UPDATE `bot_binds` SET `chan_access` = %s%s%s WHERE `botclass` = '0' AND `botid` = '%d' AND `command` = '%s'", (value ? "'" : ""), (value ? escape_string(value) : "NULL"), (value ? "'" : ""), cbind->clientid, escape_string(cbind->cmd));
- else
- printf_mysql_query("UPDATE `bot_binds` SET `chan_access` = %s%s%s WHERE `botclass` = '%d' AND `command` = '%s'", (value ? "'" : ""), (value ? escape_string(value) : "NULL"), (value ? "'" : ""), cbind->botid, escape_string(cbind->cmd));
-
- ret = 1;
- }
- if(cbind->flags & CMDFLAG_OVERRIDE_CHANNEL_ACCESS)
- sprintf(caccess, "%s", cbind->channel_access);
- else
- sprintf(caccess, "\00314%s\003", (cbind->func->channel_access ? cbind->func->channel_access : "0"));
- reply(getTextBot(), user, "\002CACCESS \002 %s", caccess);
- return ret;
-}
-
-static int global_cmd_modcmd_oaccess(struct UserNode *user, struct cmd_binding *cbind, char *value) {
- char oaccess[MAXLEN];
- int ret = 0;
- if(value) {
- if(!strcmp(value, "*"))
- value = NULL;
- bind_botwise_set_global_access(cbind->botid, cbind->clientid, cbind->cmd, atoi(value));
- if(cbind->botid == 0)
- printf_mysql_query("UPDATE `bot_binds` SET `global_access` = %s%s%s WHERE `botclass` = '0' AND `botid` = '%d' AND `command` = '%s'", (value ? "'" : ""), (value ? escape_string(value) : "NULL"), (value ? "'" : ""), cbind->clientid, escape_string(cbind->cmd));
- else
- printf_mysql_query("UPDATE `bot_binds` SET `global_access` = %s%s%s WHERE `botclass` = '%d' AND `command` = '%s'", (value ? "'" : ""), (value ? escape_string(value) : "NULL"), (value ? "'" : ""), cbind->botid, escape_string(cbind->cmd));
-
- ret = 1;
- }
- if(cbind->flags & CMDFLAG_OVERRIDE_GLOBAL_ACCESS)
- sprintf(oaccess, "%d", cbind->global_access);
- else
- sprintf(oaccess, "\00314%d\003", (cbind->func->global_access ? cbind->func->global_access : 0));
- reply(getTextBot(), user, "\002OACCESS \002 %s", oaccess);
- return ret;
-}
-