--- /dev/null
+/* cmd_global_modcmd.c - NeonServ v5.3
+ * Copyright (C) 2011 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_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 {
+ 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);
+ }
+}
+
+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 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;
+}
+