5 static int neonserv_cmd_command_chanaccess(struct cmd_binding *cbind, struct ChanNode *chan);
6 static int neonserv_cmd_command_operaccess(struct cmd_binding *cbind);
8 static CMD_BIND(neonserv_cmd_command) {
12 struct cmd_binding *cbind = find_cmd_binding(client->botid, argv[0]);
14 reply(getTextBot(), user, "NS_UNBIND_NOT_FOUND", argv[0]);
18 reply(getTextBot(), user, "NS_COMMAND_BINDING", cbind->cmd, cbind->func->name, (cbind->parameters ? cbind->parameters : ""));
20 reply(getTextBot(), user, "NS_COMMAND_ACCESS", neonserv_cmd_command_chanaccess(cbind, chan), neonserv_cmd_command_operaccess(cbind));
21 printf_mysql_query("SELECT `user_lang` FROM `users` WHERE `user_user` = '%s'", escape_string(user->auth));
24 if ((row = mysql_fetch_row(res)) != NULL)
28 printf_mysql_query("SELECT `text` FROM `help` WHERE `lang` = '%s' AND `ident` = '%s'", escape_string(lang), escape_string(ident));
30 if ((row = mysql_fetch_row(res)) == NULL) {
31 if(stricmp(lang, "en")) {
32 printf_mysql_query("SELECT `text` FROM `help` WHERE `lang` = 'en' AND `ident` = '%s'", escape_string(ident));
35 if ((row = mysql_fetch_row(res)) == NULL) {
36 printf_mysql_query("SELECT `text` FROM `help` WHERE `lang` = '%s' AND `ident` = '%s'", escape_string(lang), escape_string(cbind->func->name));
38 if ((row = mysql_fetch_row(res)) == NULL) {
39 if(stricmp(lang, "en")) {
40 printf_mysql_query("SELECT `text` FROM `help` WHERE `lang` = 'en' AND `ident` = '%s'", escape_string(cbind->func->name));
43 if ((row = mysql_fetch_row(res)) == NULL) {
52 for(i = 0; i < strlen(row[0]); i++) {
56 sendBuf[sendBufPos] = '\0';
57 reply(getTextBot(), user, "%s", sendBuf);
64 sendBuf[sendBufPos++] = '\002';
68 sendBuf[sendBufPos++] = '\003';
72 sendBuf[sendBufPos++] = '\031';
77 sendBufPos += sprintf(sendBuf + sendBufPos, "%s", client->user->nick);
81 sendBuf[sendBufPos++] = '$';
86 sendBuf[sendBufPos++] = row[0][i];
91 sendBuf[sendBufPos] = '\0';
92 reply(getTextBot(), user, "%s", sendBuf);
97 static int neonserv_cmd_command_chanaccess(struct cmd_binding *cbind, struct ChanNode *chan) {
98 char access_list[256];
100 int access_count = 0;
102 char *str_a, *str_b = cbind->func->channel_access, *str_c;
103 if(cbind->flags & CMDFLAG_OVERRIDE_CHANNEL_ACCESS)
104 str_b = cbind->channel_access;
105 access_list[0] = '\0';
107 str_c = strdup(str_b);
109 while((str_a = str_b)) {
110 str_b = strstr(str_a, ",");
117 access_pos += sprintf(access_list+access_pos, (access_pos ? ", `%s`" : "`%s`"), str_a);
120 if(atoi(str_a) > minaccess)
121 minaccess = atoi(str_a);
128 MYSQL_ROW row, defaults = NULL;
129 printf_mysql_query("SELECT %s FROM `channels` WHERE `channel_name` = '%s'", access_list, escape_string(chan->name));
131 if ((row = mysql_fetch_row(res)) != NULL) {
133 for(i = 0; i < access_count; i++) {
134 if(!row[i] && !defaults) {
135 printf_mysql_query("SELECT %s FROM `channels` WHERE `channel_name` = 'defaults'", access_list);
136 defaults = mysql_fetch_row(mysql_use());
138 caccess = (row[i] ? atoi(row[i]) : atoi(defaults[i]));
139 if(caccess > minaccess)
147 static int neonserv_cmd_command_operaccess(struct cmd_binding *cbind) {
148 return ((cbind->flags & CMDFLAG_OVERRIDE_GLOBAL_ACCESS) ? cbind->global_access : cbind->func->global_access);