added bot/ircop mark to cmd_nicklist
[NeonServV5.git] / src / modules / global.mod / cmd_global_setbot.c
1 /* cmd_global_setbot.c - NeonServ v5.5
2  * Copyright (C) 2011-2012  Philipp Kreil (pk910)
3  * 
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.
8  * 
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.
13  * 
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/>. 
16  */
17
18 #include "cmd_global.h"
19
20 /*
21 * argv[0]  botid
22 * argv[1]  setting
23 * argv[2]  value
24 */
25
26 static int global_cmd_setbot_active(struct ClientSocket *textclient, struct UserNode *user, MYSQL_ROW bot, char *value);
27 static int global_cmd_setbot_nick(struct ClientSocket *textclient, struct UserNode *user, MYSQL_ROW bot, char *value);
28 static int global_cmd_setbot_ident(struct ClientSocket *textclient, struct UserNode *user, MYSQL_ROW bot, char *value);
29 static int global_cmd_setbot_realname(struct ClientSocket *textclient, struct UserNode *user, MYSQL_ROW bot, char *value);
30 static int global_cmd_setbot_server(struct ClientSocket *textclient, struct UserNode *user, MYSQL_ROW bot, char *value);
31 static int global_cmd_setbot_port(struct ClientSocket *textclient, struct UserNode *user, MYSQL_ROW bot, char *value);
32 static int global_cmd_setbot_bind(struct ClientSocket *textclient, struct UserNode *user, MYSQL_ROW bot, char *value);
33 static int global_cmd_setbot_ssl(struct ClientSocket *textclient, struct UserNode *user, MYSQL_ROW bot, char *value);
34 static int global_cmd_setbot_serverpass(struct ClientSocket *textclient, struct UserNode *user, MYSQL_ROW bot, char *value);
35 static int global_cmd_setbot_class(struct ClientSocket *textclient, struct UserNode *user, MYSQL_ROW bot, char *value);
36 static int global_cmd_setbot_queue(struct ClientSocket *textclient, struct UserNode *user, MYSQL_ROW bot, char *value);
37 static int global_cmd_setbot_prefered(struct ClientSocket *textclient, struct UserNode *user, MYSQL_ROW bot, char *value);
38 static int global_cmd_setbot_secret(struct ClientSocket *textclient, struct UserNode *user, MYSQL_ROW bot, char *value);
39 static int global_cmd_setbot_maxchan(struct ClientSocket *textclient, struct UserNode *user, MYSQL_ROW bot, char *value);
40 static int global_cmd_setbot_priority(struct ClientSocket *textclient, struct UserNode *user, MYSQL_ROW bot, char *value);
41 static int global_cmd_setbot_trigger(struct ClientSocket *textclient, struct UserNode *user, MYSQL_ROW bot, char *value);
42
43 CMD_BIND(global_cmd_setbot) {
44     MYSQL_RES *res;
45     MYSQL_ROW row;
46     int botid = atoi(argv[0]);
47     printf_mysql_query("SELECT `active`, `nick`, `server`, `port`, `pass`, `botclass`, `textbot`, `queue`, `defaulttrigger`, `max_channels`, `register_priority`, `bind`, `ident`, `realname`, `ssl`, `id`, `secret` FROM `bots` WHERE `id` = '%d'", botid);
48     res = mysql_use();
49     if(!(row = mysql_fetch_row(res))) {
50         reply(textclient, user, "NS_SETBOT_UNKNOWN", botid);
51         return;
52     }
53     if(argc > 1) {
54         char *value;
55         if(argc > 2) {
56             value = merge_argv(argv, 2, argc);
57         } else
58             value = NULL;
59         int log_event = 0;
60         if(!stricmp(argv[1], "active")) log_event = global_cmd_setbot_active(textclient, user, row, value);
61         else if(!stricmp(argv[1], "nick")) log_event = global_cmd_setbot_nick(textclient, user, row, value);
62         else if(!stricmp(argv[1], "ident")) log_event = global_cmd_setbot_ident(textclient, user, row, value);
63         else if(!stricmp(argv[1], "realname")) log_event = global_cmd_setbot_realname(textclient, user, row, value);
64         else if(!stricmp(argv[1], "server")) log_event = global_cmd_setbot_server(textclient, user, row, value);
65         else if(!stricmp(argv[1], "port")) log_event = global_cmd_setbot_port(textclient, user, row, value);
66         else if(!stricmp(argv[1], "bind")) log_event = global_cmd_setbot_bind(textclient, user, row, value);
67         else if(!stricmp(argv[1], "ssl")) log_event = global_cmd_setbot_ssl(textclient, user, row, value);
68         else if(!stricmp(argv[1], "serverpass")) log_event = global_cmd_setbot_serverpass(textclient, user, row, value);
69         else if(!stricmp(argv[1], "botclass")) log_event = global_cmd_setbot_class(textclient, user, row, value);
70         else if(!stricmp(argv[1], "queue")) log_event = global_cmd_setbot_queue(textclient, user, row, value);
71         else if(!stricmp(argv[1], "prefered")) log_event = global_cmd_setbot_prefered(textclient, user, row, value);
72         else if(!stricmp(argv[1], "secret")) log_event = global_cmd_setbot_secret(textclient, user, row, value);
73         else if(!stricmp(argv[1], "maxchan")) log_event = global_cmd_setbot_maxchan(textclient, user, row, value);
74         else if(!stricmp(argv[1], "priority")) log_event = global_cmd_setbot_priority(textclient, user, row, value);
75         else if(!stricmp(argv[1], "trigger")) log_event = global_cmd_setbot_trigger(textclient, user, row, value);
76         else {
77             reply(textclient, user, "NS_SETBOT_SETTING", argv[1]);
78         }
79         if(log_event) {
80             if(!stricmp(argv[1], "serverpass") && value) { //censor server password 
81                 char cmd_args[MAXLEN];
82                 sprintf(cmd_args, "%d SERVERPASS ***", botid);
83                 free(event->arguments);
84                 event->arguments = strdup(cmd_args);
85             }
86             logEvent(event);
87         }
88     } else {
89         reply(textclient, user, "NS_SETBOT_HEADER", botid);
90         global_cmd_setbot_active(textclient, user, row, NULL);
91         global_cmd_setbot_nick(textclient, user, row, NULL);
92         global_cmd_setbot_ident(textclient, user, row, NULL);
93         global_cmd_setbot_realname(textclient, user, row, NULL);
94         global_cmd_setbot_server(textclient, user, row, NULL);
95         global_cmd_setbot_port(textclient, user, row, NULL);
96         global_cmd_setbot_bind(textclient, user, row, NULL);
97         global_cmd_setbot_ssl(textclient, user, row, NULL);
98         global_cmd_setbot_serverpass(textclient, user, row, NULL);
99         global_cmd_setbot_class(textclient, user, row, NULL);
100         global_cmd_setbot_queue(textclient, user, row, NULL);
101         global_cmd_setbot_prefered(textclient, user, row, NULL);
102         global_cmd_setbot_secret(textclient, user, row, NULL);
103         global_cmd_setbot_maxchan(textclient, user, row, NULL);
104         global_cmd_setbot_priority(textclient, user, row, NULL);
105         global_cmd_setbot_trigger(textclient, user, row, NULL);
106     }
107 }
108
109 static int global_cmd_setbot_active(struct ClientSocket *textclient, struct UserNode *user, MYSQL_ROW bot, char *value) {
110     int val = ((bot[0] && !strcmp(bot[0], "1")) ? 1 : 0);
111     int ret = 0;
112     if(value) {
113         if(!strcmp(value, "0") || !stricmp(value, "off") || !stricmp(value, get_language_string(user, "NS_SET_OFF"))) {
114             val = 0;
115         } else if(!strcmp(value, "1") || !stricmp(value, "on") || !stricmp(value, get_language_string(user, "NS_SET_ON"))) {
116             val = 1;
117         } else {
118             reply(textclient, user, "NS_SET_INVALID_BOOLEAN", value);
119             return 0;
120         }
121         if(val != ((bot[0] && !strcmp(bot[0], "1")) ? 1 : 0)) {
122             if(val) {
123                 //add the bot
124                 struct ClientSocket *client;
125                 client = create_socket(bot[2], atoi(bot[3]), bot[11], bot[4], bot[1], bot[12], bot[13]);
126                 client->flags |= (strcmp(bot[6], "0") ? SOCKET_FLAG_PREFERRED : 0);
127                 client->flags |= (strcmp(bot[7], "0") ? SOCKET_FLAG_USE_QUEUE : 0);
128                 client->flags |= (strcmp(bot[14], "0") ? SOCKET_FLAG_SSL : 0);
129                 client->botid = atoi(bot[5]);
130                 client->clientid = atoi(bot[15]);
131                 connect_socket(client);
132                 if(client->botid == 0) {
133                     MYSQL_RES *res;
134                     MYSQL_ROW row;
135                     printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access` FROM `bot_binds` WHERE `botclass` = '0' AND `botid` = '%d'", client->clientid);
136                     res = mysql_use();
137                     while ((row = mysql_fetch_row(res)) != NULL) {
138                         if(bind_botwise_cmd_to_command(0, client->clientid, row[0], row[1])) {
139                             if(row[2] && strcmp(row[2], "")) {
140                                 bind_botwise_set_parameters(0, client->clientid, row[0], row[2]);
141                             }
142                             if(row[3]) {
143                                 bind_botwise_set_global_access(0, client->clientid, row[0], atoi(row[3]));
144                             }
145                             if(row[4]) {
146                                 bind_botwise_set_channel_access(0, client->clientid, row[0], row[4]);
147                             }
148                         }
149                     }
150                     bind_botwise_unbound_required_functions(0, client->clientid);
151                 }
152             } else {
153                 //remove the bot
154                 struct ClientSocket *client;
155                 for(client = getBots(0, NULL); client; client = getBots(0, client)) {
156                     if(client->clientid == atoi(bot[15])) {
157                         unbind_botwise_allcmd(0, client->clientid);
158                         close_socket(client);
159                         break;
160                     }
161                 }
162             }
163             printf_mysql_query("UPDATE `bots` SET `active` = '%d' WHERE `id` = '%s'", val, bot[15]);
164             ret = 1;
165         }
166     }
167     reply(textclient, user, "\002ACTIVE     \002 %s", get_language_string(user, (val ? "NS_SET_ON" : "NS_SET_OFF")));
168     return ret;
169 }
170
171 static int global_cmd_setbot_nick(struct ClientSocket *textclient, struct UserNode *user, MYSQL_ROW bot, char *value) {
172     char *val = bot[1];
173     int ret = 0;
174     if(value) {
175         if(!is_valid_nick(value)) {
176             reply(textclient, user, "NS_SETBOT_NICK_INVALID", value);
177             return 0;
178         }
179         //rename the bot
180         struct ClientSocket *client;
181         for(client = getBots(0, NULL); client; client = getBots(0, client)) {
182             if(client->clientid == atoi(bot[15])) {
183                 if(client->nick)
184                     free(client->nick);
185                 client->nick = strdup(value);
186                 if(client->flags & SOCKET_FLAG_READY)
187                     putsock(client, "NICK %s", value);
188                 break;
189             }
190         }
191         printf_mysql_query("UPDATE `bots` SET `nick` = '%s' WHERE `id` = '%s'", escape_string(value), bot[15]);
192         val = value;
193         ret = 1;
194     }
195     reply(textclient, user, "\002NICK       \002 %s", val);
196     return ret;
197 }
198
199 static int global_cmd_setbot_ident(struct ClientSocket *textclient, struct UserNode *user, MYSQL_ROW bot, char *value) {
200     char *val = bot[12];
201     int ret = 0;
202     if(value) {
203         if(strlen(value) > 12)
204             value[12] = '\0';
205         //rename the bot
206         struct ClientSocket *client;
207         for(client = getBots(0, NULL); client; client = getBots(0, client)) {
208             if(client->clientid == atoi(bot[15])) {
209                 if(client->ident)
210                     free(client->ident);
211                 client->ident = strdup(value);
212                 break;
213             }
214         }
215         printf_mysql_query("UPDATE `bots` SET `ident` = '%s' WHERE `id` = '%s'", escape_string(value), bot[15]);
216         val = value;
217         ret = 1;
218     }
219     reply(textclient, user, "\002IDENT      \002 %s", val);
220     return ret;
221 }
222
223 static int global_cmd_setbot_realname(struct ClientSocket *textclient, struct UserNode *user, MYSQL_ROW bot, char *value) {
224     char *val = bot[13];
225     int ret = 0;
226     if(value) {
227         if(strlen(value) > 255)
228             value[255] = '\0';
229         //rename the bot
230         struct ClientSocket *client;
231         for(client = getBots(0, NULL); client; client = getBots(0, client)) {
232             if(client->clientid == atoi(bot[15])) {
233                 if(client->ident)
234                     free(client->ident);
235                 client->ident = strdup(value);
236                 break;
237             }
238         }
239         printf_mysql_query("UPDATE `bots` SET `realname` = '%s' WHERE `id` = '%s'", escape_string(value), bot[15]);
240         val = value;
241         ret = 1;
242     }
243     reply(textclient, user, "\002REALNAME   \002 %s", val);
244     return ret;
245 }
246
247 static int global_cmd_setbot_server(struct ClientSocket *textclient, struct UserNode *user, MYSQL_ROW bot, char *value) {
248     char *val = bot[2];
249     int ret = 0;
250     if(value) {
251         struct ClientSocket *client;
252         for(client = getBots(0, NULL); client; client = getBots(0, client)) {
253             if(client->clientid == atoi(bot[15])) {
254                 if(client->host)
255                     free(client->host);
256                 client->host = strdup(value);
257                 if(client->flags & SOCKET_FLAG_READY)
258                     reply(textclient, user, "NS_SETBOT_NEED_RESTART");
259                 break;
260             }
261         }
262         printf_mysql_query("UPDATE `bots` SET `server` = '%s' WHERE `id` = '%s'", escape_string(value), bot[15]);
263         val = value;
264         ret = 1;
265     }
266     reply(textclient, user, "\002SERVER     \002 %s", val);
267     return ret;
268 }
269
270 static int global_cmd_setbot_port(struct ClientSocket *textclient, struct UserNode *user, MYSQL_ROW bot, char *value) {
271     int val = atoi(bot[3]);
272     int ret = 0;
273     if(value) {
274         val = atoi(value);
275         if(val <= 0 || val > 65534) {
276             reply(textclient, user, "NS_SETBOT_PORT_INVALID", value);
277             return 0;
278         }
279         struct ClientSocket *client;
280         for(client = getBots(0, NULL); client; client = getBots(0, client)) {
281             if(client->clientid == atoi(bot[15])) {
282                 client->port = val;
283                 if(client->flags & SOCKET_FLAG_READY)
284                     reply(textclient, user, "NS_SETBOT_NEED_RESTART");
285                 break;
286             }
287         }
288         printf_mysql_query("UPDATE `bots` SET `port` = '%d' WHERE `id` = '%s'", val, bot[15]);
289         ret = 1;
290     }
291     reply(textclient, user, "\002PORT       \002 %d", val);
292     return ret;
293 }
294
295 static int global_cmd_setbot_bind(struct ClientSocket *textclient, struct UserNode *user, MYSQL_ROW bot, char *value) {
296     char *val = bot[11];
297     int ret = 0;
298     if(value) {
299         if(!strcmp(value, "*")) 
300             value = NULL;
301         struct ClientSocket *client;
302         for(client = getBots(0, NULL); client; client = getBots(0, client)) {
303             if(client->clientid == atoi(bot[15])) {
304                 if(client->bind)
305                     free(client->bind);
306                 client->bind = (value ? strdup(value) : NULL);
307                 if(client->flags & SOCKET_FLAG_READY)
308                     reply(textclient, user, "NS_SETBOT_NEED_RESTART");
309                 break;
310             }
311         }
312         if(value)
313             printf_mysql_query("UPDATE `bots` SET `bind` = '%s' WHERE `id` = '%s'", escape_string(value), bot[15]);
314         else
315             printf_mysql_query("UPDATE `bots` SET `bind` = NULL WHERE `id` = '%s'", bot[15]);
316         val = value;
317         ret = 1;
318     }
319     reply(textclient, user, "\002BIND       \002 %s", val);
320     return ret;
321 }
322
323 static int global_cmd_setbot_ssl(struct ClientSocket *textclient, struct UserNode *user, MYSQL_ROW bot, char *value) {
324     int val = (strcmp(bot[14], "0") ? 1 : 0);
325     int ret = 0;
326     if(value) {
327         if(!strcmp(value, "0") || !stricmp(value, "off") || !stricmp(value, get_language_string(user, "NS_SET_OFF"))) {
328             val = 0;
329         } else if(!strcmp(value, "1") || !stricmp(value, "on") || !stricmp(value, get_language_string(user, "NS_SET_ON"))) {
330             val = 1;
331         } else {
332             reply(textclient, user, "NS_SET_INVALID_BOOLEAN", value);
333             return 0;
334         }
335         struct ClientSocket *client;
336         for(client = getBots(0, NULL); client; client = getBots(0, client)) {
337             if(client->clientid == atoi(bot[15])) {
338                 if(val)
339                     client->flags |= SOCKET_FLAG_SSL;
340                 else
341                     client->flags &= ~SOCKET_FLAG_SSL;
342                 if(client->flags & SOCKET_FLAG_READY)
343                     reply(textclient, user, "NS_SETBOT_NEED_RESTART");
344                 break;
345             }
346         }
347         printf_mysql_query("UPDATE `bots` SET `ssl` = '%d' WHERE `id` = '%s'", val, bot[15]);
348         ret = 1;
349     }
350     reply(textclient, user, "\002SSL        \002 %s", get_language_string(user, (val ? "NS_SET_ON" : "NS_SET_OFF")));
351     return ret;
352 }
353
354 static int global_cmd_setbot_serverpass(struct ClientSocket *textclient, struct UserNode *user, MYSQL_ROW bot, char *value) {
355     char *val = bot[4];
356     int ret = 0;
357     if(value) {
358         if(!strcmp(value, "*")) 
359             value = "";
360         struct ClientSocket *client;
361         for(client = getBots(0, NULL); client; client = getBots(0, client)) {
362             if(client->clientid == atoi(bot[15])) {
363                 if(client->pass)
364                     free(client->pass);
365                 client->pass = (value ? strdup(value) : NULL);
366                 if(client->flags & SOCKET_FLAG_READY)
367                     reply(textclient, user, "NS_SETBOT_NEED_RESTART");
368                 break;
369             }
370         }
371         printf_mysql_query("UPDATE `bots` SET `pass` = '%s' WHERE `id` = '%s'", escape_string(value), bot[15]);
372         val = value;
373         ret = 1;
374     }
375     reply(textclient, user, "\002SERVERPASS \002 %s", val);
376     return ret;
377 }
378
379 static int global_cmd_setbot_class(struct ClientSocket *textclient, struct UserNode *user, MYSQL_ROW bot, char *value) {
380     int val = atoi(bot[5]);
381     int ret = 0;
382     if(value) {
383         if((val = resolve_botalias(value)) == -1) {
384             reply(textclient, user, "NS_SETBOT_INVALID_CLASS", value);
385             return 0;
386         }
387         if(val != atoi(bot[5])) {
388             struct ClientSocket *client;
389             for(client = getBots(0, NULL); client; client = getBots(0, client)) {
390                 if(client->clientid == atoi(bot[15])) {
391                     unbind_botwise_allcmd(0, client->clientid);
392                     client->botid = val;
393                     if(client->botid == 0) {
394                         MYSQL_RES *res;
395                         MYSQL_ROW row;
396                         printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access` FROM `bot_binds` WHERE `botclass` = '0' AND `botid` = '%d'", client->clientid);
397                         res = mysql_use();
398                         while ((row = mysql_fetch_row(res)) != NULL) {
399                             if(bind_botwise_cmd_to_command(client->botid, client->clientid, row[0], row[1])) {
400                                 if(row[2] && strcmp(row[2], "")) {
401                                     bind_botwise_set_parameters(client->botid, client->clientid, row[0], row[2]);
402                                 }
403                                 if(row[3]) {
404                                     bind_botwise_set_global_access(client->botid, client->clientid, row[0], atoi(row[3]));
405                                 }
406                                 if(row[4]) {
407                                     bind_botwise_set_channel_access(client->botid, client->clientid, row[0], row[4]);
408                                 }
409                             }
410                         }
411                         bind_botwise_unbound_required_functions(client->botid, client->clientid);
412                     }
413                     break;
414                 }
415             }
416             printf_mysql_query("UPDATE `bots` SET `botclass` = '%d' WHERE `id` = '%s'", val, bot[15]);
417             ret = 1;
418         }
419     }
420     reply(textclient, user, "\002BOTCLASS   \002 %s", resolve_botid(val));
421     return ret;
422 }
423
424 static int global_cmd_setbot_queue(struct ClientSocket *textclient, struct UserNode *user, MYSQL_ROW bot, char *value) {
425     int val = (strcmp(bot[7], "0") ? 1 : 0);
426     int ret = 0;
427     if(value) {
428         if(!strcmp(value, "0") || !stricmp(value, "off") || !stricmp(value, get_language_string(user, "NS_SET_OFF"))) {
429             val = 0;
430         } else if(!strcmp(value, "1") || !stricmp(value, "on") || !stricmp(value, get_language_string(user, "NS_SET_ON"))) {
431             val = 1;
432         } else {
433             reply(textclient, user, "NS_SET_INVALID_BOOLEAN", value);
434             return 0;
435         }
436         struct ClientSocket *client;
437         for(client = getBots(0, NULL); client; client = getBots(0, client)) {
438             if(client->clientid == atoi(bot[15])) {
439                 if(val)
440                     client->flags |= SOCKET_FLAG_USE_QUEUE;
441                 else
442                     client->flags &= ~SOCKET_FLAG_USE_QUEUE;
443                 break;
444             }
445         }
446         printf_mysql_query("UPDATE `bots` SET `queue` = '%d' WHERE `id` = '%s'", val, bot[15]);
447         ret = 1;
448     }
449     reply(textclient, user, "\002QUEUE      \002 %s", get_language_string(user, (val ? "NS_SET_ON" : "NS_SET_OFF")));
450     return ret;
451 }
452
453 static int global_cmd_setbot_prefered(struct ClientSocket *textclient, struct UserNode *user, MYSQL_ROW bot, char *value) {
454     int val = (strcmp(bot[6], "0") ? 1 : 0);
455     int ret = 0;
456     if(value) {
457         if(!strcmp(value, "0") || !stricmp(value, "off") || !stricmp(value, get_language_string(user, "NS_SET_OFF"))) {
458             val = 0;
459         } else if(!strcmp(value, "1") || !stricmp(value, "on") || !stricmp(value, get_language_string(user, "NS_SET_ON"))) {
460             val = 1;
461         } else {
462             reply(textclient, user, "NS_SET_INVALID_BOOLEAN", value);
463             return 0;
464         }
465         struct ClientSocket *client;
466         for(client = getBots(0, NULL); client; client = getBots(0, client)) {
467             if(client->clientid == atoi(bot[15])) {
468                 if(val)
469                     client->flags |= SOCKET_FLAG_PREFERRED;
470                 else
471                     client->flags &= ~SOCKET_FLAG_PREFERRED;
472                 break;
473             }
474         }
475         printf_mysql_query("UPDATE `bots` SET `textbot` = '%d' WHERE `id` = '%s'", val, bot[15]);
476         ret = 1;
477     }
478     reply(textclient, user, "\002PREFERED   \002 %s", get_language_string(user, (val ? "NS_SET_ON" : "NS_SET_OFF")));
479     return ret;
480 }
481
482 static int global_cmd_setbot_secret(struct ClientSocket *textclient, struct UserNode *user, MYSQL_ROW bot, char *value) {
483     int val = (strcmp(bot[16], "0") ? 1 : 0);
484     int ret = 0;
485     if(value) {
486         if(!strcmp(value, "0") || !stricmp(value, "off") || !stricmp(value, get_language_string(user, "NS_SET_OFF"))) {
487             val = 0;
488         } else if(!strcmp(value, "1") || !stricmp(value, "on") || !stricmp(value, get_language_string(user, "NS_SET_ON"))) {
489             val = 1;
490         } else {
491             reply(textclient, user, "NS_SET_INVALID_BOOLEAN", value);
492             return 0;
493         }
494         struct ClientSocket *client;
495         for(client = getBots(0, NULL); client; client = getBots(0, client)) {
496             if(client->clientid == atoi(bot[15])) {
497                 if(val)
498                     client->flags |= SOCKET_FLAG_SECRET_BOT;
499                 else
500                     client->flags &= ~SOCKET_FLAG_SECRET_BOT;
501                 break;
502             }
503         }
504         printf_mysql_query("UPDATE `bots` SET `secret` = '%d' WHERE `id` = '%s'", val, bot[15]);
505         ret = 1;
506     }
507     reply(textclient, user, "\002SECRET     \002 %s", get_language_string(user, (val ? "NS_SET_ON" : "NS_SET_OFF")));
508     return ret;
509 }
510
511 static int global_cmd_setbot_maxchan(struct ClientSocket *textclient, struct UserNode *user, MYSQL_ROW bot, char *value) {
512     int val = atoi(bot[9]);
513     int ret = 0;
514     if(value) {
515         val = atoi(value);
516         if(val < 0 || val > 99999) {
517             reply(textclient, user, "NS_SETBOT_MAXCHAN_INVALID", value);
518             return 0;
519         }
520         printf_mysql_query("UPDATE `bots` SET `max_channels` = '%d' WHERE `id` = '%s'", val, bot[15]);
521         ret = 1;
522     }
523     reply(textclient, user, "\002MAXCHAN    \002 %d", val);
524     return ret;
525 }
526
527 static int global_cmd_setbot_priority(struct ClientSocket *textclient, struct UserNode *user, MYSQL_ROW bot, char *value) {
528     int val = atoi(bot[10]);
529     int ret = 0;
530     if(value) {
531         val = atoi(value);
532         if(val < 0 || val > 99) {
533             reply(textclient, user, "NS_SETBOT_PRIORITY_INVALID", value);
534             return 0;
535         }
536         printf_mysql_query("UPDATE `bots` SET `register_priority` = '%d' WHERE `id` = '%s'", val, bot[15]);
537         ret = 1;
538     }
539     reply(textclient, user, "\002PRIORITY   \002 %d", val);
540     return ret;
541 }
542
543 static int global_cmd_setbot_trigger(struct ClientSocket *textclient, struct UserNode *user, MYSQL_ROW bot, char *value) {
544     char *val = bot[8];
545     int ret = 0;
546     if(value) {
547         if(!*value || strlen(value) > 10) {
548             reply(textclient, user, "NS_SETBOT_TRIGGER_INVALID", value);
549             return 0;
550         }
551         printf_mysql_query("UPDATE `bots` SET `defaulttrigger` = '%s' WHERE `id` = '%s'", escape_string(value), bot[15]);
552         flush_trigger_cache(atoi(bot[5]), atoi(bot[15]));
553         reply(textclient, user, "NS_SETBOT_TRIGGER_NOTE");
554         val = value;
555         ret = 1;
556     }
557     reply(textclient, user, "\002TRIGGER    \002 %s", val);
558     return ret;
559 }