1 /* cmd_neonserv_command.c - NeonServ v5.0
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_neonserv.h"
23 static int neonserv_cmd_command_chanaccess(struct cmd_binding *cbind, struct ChanNode *chan);
24 static int neonserv_cmd_command_operaccess(struct cmd_binding *cbind);
26 CMD_BIND(neonserv_cmd_command) {
30 struct cmd_binding *cbind = find_cmd_binding(client->botid, argv[0]);
32 reply(getTextBot(), user, "NS_UNBIND_NOT_FOUND", argv[0]);
36 char parameters[MAXLEN];
37 if(cbind->paramcount) {
39 for(i = 0; i < cbind->paramcount; i++) {
40 parampos += sprintf(parameters + parampos, (i ? " %s" : "%s"), cbind->parameters[i]);
44 reply(getTextBot(), user, "NS_COMMAND_BINDING", cbind->cmd, cbind->func->name, parameters);
46 reply(getTextBot(), user, "NS_COMMAND_ACCESS", neonserv_cmd_command_chanaccess(cbind, chan), neonserv_cmd_command_operaccess(cbind));
47 printf_mysql_query("SELECT `user_lang` FROM `users` WHERE `user_user` = '%s'", escape_string(user->auth));
50 if ((row = mysql_fetch_row(res)) != NULL)
54 printf_mysql_query("SELECT `text` FROM `help` WHERE `lang` = '%s' AND `ident` = '%s'", escape_string(lang), escape_string(ident));
56 if ((row = mysql_fetch_row(res)) == NULL) {
57 if(stricmp(lang, "en")) {
58 printf_mysql_query("SELECT `text` FROM `help` WHERE `lang` = 'en' AND `ident` = '%s'", escape_string(ident));
61 if ((row = mysql_fetch_row(res)) == NULL) {
62 printf_mysql_query("SELECT `text` FROM `help` WHERE `lang` = '%s' AND `ident` = '%s'", escape_string(lang), escape_string(cbind->func->name));
64 if ((row = mysql_fetch_row(res)) == NULL) {
65 if(stricmp(lang, "en")) {
66 printf_mysql_query("SELECT `text` FROM `help` WHERE `lang` = 'en' AND `ident` = '%s'", escape_string(cbind->func->name));
69 if ((row = mysql_fetch_row(res)) == NULL) {
78 for(i = 0; i < strlen(row[0]); i++) {
82 sendBuf[sendBufPos] = '\0';
83 reply(getTextBot(), user, "%s", sendBuf);
90 sendBuf[sendBufPos++] = '\002';
94 sendBuf[sendBufPos++] = '\003';
98 sendBuf[sendBufPos++] = '\031';
103 sendBufPos += sprintf(sendBuf + sendBufPos, "%s", client->user->nick);
107 sendBuf[sendBufPos++] = '$';
112 sendBuf[sendBufPos++] = row[0][i];
117 sendBuf[sendBufPos] = '\0';
118 reply(getTextBot(), user, "%s", sendBuf);
123 static int neonserv_cmd_command_chanaccess(struct cmd_binding *cbind, struct ChanNode *chan) {
124 char access_list[256];
126 int access_count = 0;
128 char *str_a, *str_b = cbind->func->channel_access, *str_c;
129 if(cbind->flags & CMDFLAG_OVERRIDE_CHANNEL_ACCESS)
130 str_b = cbind->channel_access;
131 access_list[0] = '\0';
133 str_c = strdup(str_b);
135 while((str_a = str_b)) {
136 str_b = strstr(str_a, ",");
143 access_pos += sprintf(access_list+access_pos, (access_pos ? ", `%s`" : "`%s`"), str_a);
146 if(atoi(str_a) > minaccess)
147 minaccess = atoi(str_a);
154 MYSQL_ROW row, defaults = NULL;
155 printf_mysql_query("SELECT %s FROM `channels` WHERE `channel_name` = '%s'", access_list, escape_string(chan->name));
157 if ((row = mysql_fetch_row(res)) != NULL) {
159 for(i = 0; i < access_count; i++) {
160 if(!row[i] && !defaults) {
161 printf_mysql_query("SELECT %s FROM `channels` WHERE `channel_name` = 'defaults'", access_list);
162 defaults = mysql_fetch_row(mysql_use());
164 caccess = (row[i] ? atoi(row[i]) : atoi(defaults[i]));
165 if(caccess > minaccess)
173 static int neonserv_cmd_command_operaccess(struct cmd_binding *cbind) {
174 return ((cbind->flags & CMDFLAG_OVERRIDE_GLOBAL_ACCESS) ? cbind->global_access : cbind->func->global_access);