1 /* cmd_global_modcmd.c - NeonServ v5.3
2 * Copyright (C) 2011 Philipp Kreil (pk910)
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "cmd_global.h"
26 static int global_cmd_modcmd_params(struct UserNode *user, struct cmd_binding *cbind, char *value);
27 static int global_cmd_modcmd_caccess(struct UserNode *user, struct cmd_binding *cbind, char *value);
28 static int global_cmd_modcmd_oaccess(struct UserNode *user, struct cmd_binding *cbind, char *value);
30 CMD_BIND(global_cmd_modcmd) {
33 struct cmd_binding *cbind = find_botwise_cmd_binding(client->botid, client->clientid, argv[0]);
35 reply(getTextBot(), user, "NS_UNBIND_NOT_FOUND", argv[0]);
39 printf_mysql_query("SELECT `user_access` FROM `users` WHERE `user_user` = '%s'", escape_string(user->auth));
41 if ((row = mysql_fetch_row(res)) != NULL) {
42 uaccess = atoi(row[0]);
44 int gaccess = ((cbind->flags & CMDFLAG_OVERRIDE_GLOBAL_ACCESS) ? cbind->global_access : cbind->func->global_access);
45 if(gaccess > uaccess) {
46 reply(getTextBot(), user, "NS_MODCMD_OUTRANKED", cbind->cmd, gaccess);
52 value = merge_argv(argv, 2, argc);
56 if(!stricmp(argv[1], "caccess")) log_event = global_cmd_modcmd_caccess(user, cbind, value);
57 else if(!stricmp(argv[1], "oaccess")) log_event = global_cmd_modcmd_oaccess(user, cbind, value);
58 else if(!stricmp(argv[1], "parameters")) log_event = global_cmd_modcmd_params(user, cbind, value);
60 reply(getTextBot(), user, "NS_MODCMD_SETTING", argv[1]);
66 reply(getTextBot(), user, "NS_MODCMD_HEADER", cbind->cmd);
67 global_cmd_modcmd_params(user, cbind, NULL);
68 global_cmd_modcmd_caccess(user, cbind, NULL);
69 global_cmd_modcmd_oaccess(user, cbind, NULL);
73 static int global_cmd_modcmd_params(struct UserNode *user, struct cmd_binding *cbind, char *value) {
74 char parameters[MAXLEN];
76 if(cbind->paramcount) {
78 for(i = 0; i < cbind->paramcount; i++) {
79 parampos += sprintf(parameters + parampos, (i ? " %s" : "%s"), cbind->parameters[i]);
84 if(!strcmp(value, "*"))
86 bind_botwise_set_parameters(cbind->botid, cbind->clientid, cbind->cmd, value);
88 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));
90 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));
91 strcpy(parameters, (value ? value : ""));
94 reply(getTextBot(), user, "\002PARAMETERS \002 %s", parameters);
98 static int global_cmd_modcmd_caccess(struct UserNode *user, struct cmd_binding *cbind, char *value) {
102 if(!strcmp(value, "*"))
104 bind_botwise_set_channel_access(cbind->botid, cbind->clientid, cbind->cmd, value);
105 if(cbind->botid == 0)
106 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));
108 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));
112 if(cbind->flags & CMDFLAG_OVERRIDE_CHANNEL_ACCESS)
113 sprintf(caccess, "%s", cbind->channel_access);
115 sprintf(caccess, "\00314%s\003", (cbind->func->channel_access ? cbind->func->channel_access : "0"));
116 reply(getTextBot(), user, "\002CACCESS \002 %s", caccess);
120 static int global_cmd_modcmd_oaccess(struct UserNode *user, struct cmd_binding *cbind, char *value) {
121 char oaccess[MAXLEN];
124 if(!strcmp(value, "*"))
126 bind_botwise_set_global_access(cbind->botid, cbind->clientid, cbind->cmd, atoi(value));
127 if(cbind->botid == 0)
128 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));
130 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));
134 if(cbind->flags & CMDFLAG_OVERRIDE_GLOBAL_ACCESS)
135 sprintf(oaccess, "%d", cbind->global_access);
137 sprintf(oaccess, "\00314%d\003", (cbind->func->global_access ? cbind->func->global_access : 0));
138 reply(getTextBot(), user, "\002OACCESS \002 %s", oaccess);