1 /* modcmd.c - NeonServ v5.2
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/>.
19 #include "IRCEvents.h"
20 #include "IRCParser.h"
21 #include "ClientSocket.h"
25 #include "WHOHandler.h"
27 #include "mysqlConn.h"
29 #include "EventLogger.h"
31 struct trigger_callback {
33 trigger_callback_t *func;
35 struct trigger_callback *next;
38 struct cmd_bot_alias {
42 struct cmd_bot_alias *next;
45 struct command_check_user_cache {
46 struct ClientSocket *client, *textclient;
47 struct UserNode *user;
48 struct ChanNode *chan, *sent_chan;
51 char *message, *args_buffer;
52 struct cmd_binding *cbind;
55 static struct cmd_binding **cmd_binds;
56 static struct cmd_function *cmd_functions = NULL;
57 static struct trigger_callback *trigger_callbacks = NULL;
58 static struct cmd_bot_alias *bot_aliases = NULL;
59 static struct ClientSocket *tmp_text_client;
60 static int total_triggered = 0;
61 int statistics_commands = 0;
63 static const struct default_language_entry msgtab[] = {
64 {"MODCMD_LESS_PARAM_COUNT", "This command requires more parameters."},
65 {"MODCMD_CHAN_REQUIRED", "You must provide the name of a channel that exists and the bot is on."},
66 {"MODCMD_AUTH_REQUIRED", "You need to be authenticated with AuthServ to use this command."},
67 {"MODCMD_CHAN_SUSPENDED", "This channel is currently suspended."},
68 {"MODCMD_PRIVILEGED", "$b%s$b is a privileged command."}, /* {ARGS: "god"} */
69 {"MODCMD_PUBCMD", "Public commands in $b%s$b are restricted."}, /* {ARGS: "#TestChan"} */
70 {"MODCMD_ACCESS_DENIED", "Access denied."},
74 static int get_binds_index(char first_char) {
75 if(tolower(first_char) >= 'a' && tolower(first_char) <= 'z') {
76 return tolower(first_char) - 'a';
81 struct ClientSocket* get_prefered_bot(int botid) {
82 struct ClientSocket *client, *lowbot = NULL;
83 for(client = getBots(SOCKET_FLAG_READY, NULL); client; client = getBots(SOCKET_FLAG_READY, client)) {
84 if(client->botid == botid) {
85 if((client->flags & SOCKET_FLAG_PREFERRED))
94 static char* get_channel_trigger(int botid, struct ChanNode *chan) {
95 struct trigger_cache *trigger;
96 for(trigger = chan->trigger; trigger; trigger = trigger->next) {
97 if(trigger->botid == botid)
98 return trigger->trigger;
100 struct trigger_callback *cb;
101 for(cb = trigger_callbacks; cb; cb = cb->next) {
102 if(cb->botid == botid)
105 char triggerStr[TRIGGERLEN];
107 cb->func(chan, triggerStr);
109 strcpy(triggerStr, "+");
110 trigger = malloc(sizeof(*trigger));
112 perror("malloc() failed");
115 trigger->botid = botid;
116 trigger->trigger = (triggerStr[0] ? strdup(triggerStr) : NULL);
117 trigger->next = chan->trigger;
118 chan->trigger = trigger;
119 return trigger->trigger;
122 static void handle_command_async(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, struct ChanNode *sent_chan, struct cmd_binding *cbind, char **argv, int argc);
124 static USERAUTH_CALLBACK(command_checked_auth) {
125 struct command_check_user_cache *cache = data;
126 tmp_text_client = cache->textclient;
127 handle_command_async(cache->client, user, cache->chan, cache->sent_chan, cache->cbind, cache->argv, cache->argc);
128 free(cache->message);
129 if(cache->args_buffer)
130 free(cache->args_buffer);
135 static void handle_command(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, char *message) {
136 struct ChanNode *sent_chan = chan;
137 if(message[0] == '#') {
138 char *chanName = message;
139 message = strstr(message, " ");
143 struct ChanNode *chan2 = getChanByName(chanName);
147 message = strdup(message);
148 int bind_index = get_binds_index(message[0]);
149 char *args = strstr(message, " ");
150 char *args_buffer = NULL; //we need this to save a possible pointer to a allocation we need to free
155 struct cmd_binding *cbind;
156 for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
157 if(cbind->botid == client->botid && stricmp(cbind->cmd, message) == 0) {
158 if(statistics_enabled)
159 statistics_commands++;
161 cbind->func->triggered++;
162 if((cbind->func->flags & CMDFLAG_FUNCMD)) {
168 tmp_text_client = get_prefered_bot(client->botid);
169 //parse the arguments...
170 char *arga[MAXNUMPARAMS];
175 //skip leading spaces
179 if (argc >= MAXNUMPARAMS)
181 while (*args != ' ' && *args)
186 if(argc != 0 && argv[0][0] == '#' && !(cbind->func->flags & CMDFLAG_CHAN_PARAM)) {
187 struct ChanNode *chan2 = getChanByName(argv[0]);
194 if(cbind->paramcount) {
195 //userdefined parameters...
196 args_buffer = malloc(MAXLEN * 2 * sizeof(*args_buffer));
198 char *uargs[MAXNUMPARAMS];
203 for(i = 0; i < cbind->paramcount; i++) {
204 b = cbind->parameters[i];
207 if(b[strlen(b)-1] == '-') {
208 allargs = strlen(b)-1;
213 } else if(b[strlen(b)-1] == '+') {
214 allargs = strlen(b)-1;
225 uargs[uargc++] = args_buffer + args_pos;
227 args_pos += sprintf(args_buffer + args_pos, "%s", argv[argi-1]) + 1;
228 } else if(allargs == 1) {
229 args_pos += sprintf(args_buffer + args_pos, "%s", argv[argi-1]) + 1;
230 for(argi++; argi <= argc; argi++) {
231 uargs[uargc++] = args_buffer + args_pos;
232 args_pos += sprintf(args_buffer + args_pos, "%s", argv[argi-1]) + 1;
234 } else if(allargs == 2) {
235 for(;argi <= argc; argi++) {
236 args_pos += sprintf(args_buffer + args_pos, (allargs ? "%s" : " %s"), argv[argi-1]);
241 } else if((cbind->func->flags & CMDFLAG_EMPTY_ARGS)) {
242 uargs[uargc++] = args_buffer + args_pos;
243 args_buffer[args_pos++] = '\0';
245 } else if(!strcmp(b, "c")) {
246 uargs[uargc++] = args_buffer + args_pos;
247 args_pos += sprintf(args_buffer + args_pos, "%s", (chan ? chan->name : "")) + 1;
248 } else if(!strcmp(b, "n")) {
249 uargs[uargc++] = args_buffer + args_pos;
250 args_pos += sprintf(args_buffer + args_pos, "%s", user->nick) + 1;
253 uargs[uargc++] = args_buffer + args_pos;
254 args_pos += sprintf(args_buffer + args_pos, "%s", b) + 1;
260 if(argc < cbind->func->paramcount) {
261 reply(tmp_text_client, user, "MODCMD_LESS_PARAM_COUNT");
264 if((cbind->func->flags & CMDFLAG_REQUIRE_CHAN) && !chan) {
265 reply(tmp_text_client, user, "MODCMD_CHAN_REQUIRED");
268 if((cbind->func->flags & CMDFLAG_CHECK_AUTH) && !(user->flags & USERFLAG_ISAUTHED)) {
270 struct command_check_user_cache *data = malloc(sizeof(*data));
271 char **temp_argv = malloc(argc*sizeof(*temp_argv));
272 if (!data || !temp_argv) {
273 perror("malloc() failed");
276 memcpy(temp_argv, argv, argc*sizeof(*temp_argv));
277 data->argv = temp_argv;
279 data->client = client;
282 data->sent_chan = sent_chan;
283 data->message = message;
284 data->args_buffer = args_buffer;
286 data->textclient = tmp_text_client;
287 get_userauth(user, command_checked_auth, data);
290 handle_command_async(client, user, chan, sent_chan, cbind, argv, argc);
299 static void handle_command_async(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, struct ChanNode *sent_chan, struct cmd_binding *cbind, char **argv, int argc) {
303 int eventflags = (cbind->func->flags & (CMDFLAG_LOG | CMDFLAG_OPLOG));
304 if((cbind->func->flags & CMDFLAG_REQUIRE_AUTH) && !(user->flags & USERFLAG_ISAUTHED)) {
305 reply(tmp_text_client, user, "MODCMD_AUTH_REQUIRED");
308 if(sent_chan && sent_chan != chan) {
309 //check pubcmd of this channel
310 printf_mysql_query("SELECT `channel_pubcmd` FROM `channels` WHERE `channel_name` = '%s'", escape_string(sent_chan->name));
312 if ((row = mysql_fetch_row(res)) != NULL) {
313 uaccess = getChannelAccess(user, sent_chan);
314 if(row[0] && uaccess < atoi(row[0]) && !isGodMode(user)) { //NOTE: HARDCODED DEFAULT: pubcmd = 0
315 reply(tmp_text_client, user, "MODCMD_PUBCMD", sent_chan->name);
320 int global_access = ((cbind->flags & CMDFLAG_OVERRIDE_GLOBAL_ACCESS) ? cbind->global_access : cbind->func->global_access);
321 if(global_access > 0) {
322 int user_global_access = 0;
323 printf_mysql_query("SELECT `user_access` FROM `users` WHERE `user_user` = '%s'", escape_string(user->auth));
325 if ((row = mysql_fetch_row(res)) != NULL) {
326 user_global_access = atoi(row[0]);
328 if(user_global_access < global_access) {
329 if(!user_global_access)
330 reply(tmp_text_client, user, "MODCMD_PRIVILEGED", cbind->cmd);
332 reply(tmp_text_client, user, "MODCMD_ACCESS_DENIED");
336 if((cbind->func->flags & CMDFLAG_REGISTERED_CHAN)) {
337 MYSQL_ROW defaults = NULL;
338 char access_list[256];
340 int access_count = 0;
342 char *str_a, *str_b = cbind->func->channel_access, *str_c;
343 if(cbind->flags & CMDFLAG_OVERRIDE_CHANNEL_ACCESS)
344 str_b = cbind->channel_access;
345 access_list[0] = '\0';
347 str_c = strdup(str_b);
349 while((str_a = str_b)) {
350 str_b = strstr(str_a, ",");
357 access_pos += sprintf(access_list+access_pos, ", `%s`", str_a);
360 if(atoi(str_a) > minaccess)
361 minaccess = atoi(str_a);
366 if(!(chan->flags & CHANFLAG_REQUESTED_CHANINFO) || (sent_chan && sent_chan == chan) || access_count || minaccess) {
367 printf_mysql_query("SELECT `channel_id`, `channel_pubcmd` %s FROM `channels` WHERE `channel_name` = '%s'", access_list, escape_string(chan->name));
369 if ((row = mysql_fetch_row(res)) != NULL) {
370 chan->flags |= CHANFLAG_CHAN_REGISTERED;
371 chan->channel_id = atoi(row[0]);
372 if((sent_chan && sent_chan == chan) || access_count || minaccess) {
373 uaccess = getChannelAccess(user, chan);
374 if(uaccess < minaccess && isGodMode(user)) {
375 eventflags |= CMDFLAG_OPLOG;
376 } else if(uaccess < minaccess) {
378 reply(tmp_text_client, user, "MODCMD_ACCESS_DENIED");
381 if(!row[1] && !defaults) {
382 printf_mysql_query("SELECT `channel_id`, `channel_pubcmd` %s FROM `channels` WHERE `channel_name` = 'defaults'", access_list);
383 defaults = mysql_fetch_row(mysql_use());
385 if(sent_chan && (sent_chan == chan) && uaccess < (row[1] ? atoi(row[1]) : atoi(defaults[1]))) {
386 if(isGodMode(user)) {
387 eventflags |= CMDFLAG_OPLOG;
390 reply(tmp_text_client, user, "MODCMD_PUBCMD", chan->name);
395 for(i = 0; i < access_count; i++) {
396 if(!row[2+i] && !defaults) {
397 printf_mysql_query("SELECT `channel_id`, `channel_pubcmd` %s FROM `channels` WHERE `channel_name` = 'defaults'", access_list);
398 defaults = mysql_fetch_row(mysql_use());
400 if(uaccess < (row[2+i] ? atoi(row[2+i]) : atoi(defaults[2+i]))) {
401 if(isGodMode(user)) {
402 eventflags |= CMDFLAG_OPLOG;
404 reply(tmp_text_client, user, "MODCMD_ACCESS_DENIED");
411 chan->flags |= CHANFLAG_REQUESTED_CHANINFO;
413 if(!(chan->flags & CHANFLAG_CHAN_REGISTERED)) {
414 reply(tmp_text_client, user, "MODCMD_CHAN_REQUIRED");
417 printf_mysql_query("SELECT `botid`, `suspended` FROM `bot_channels` LEFT JOIN `bots` ON `bot_channels`.`botid` = `bots`.`id` WHERE `chanid` = '%d' AND `botclass` = '%d'", chan->channel_id, client->botid);
419 if ((row = mysql_fetch_row(res)) == NULL) {
420 reply(tmp_text_client, user, "MODCMD_CHAN_REQUIRED");
422 } else if(!strcmp(row[1], "1")) {
423 reply(tmp_text_client, user, "MODCMD_CHAN_SUSPENDED");
427 if((cbind->func->flags & CMDFLAG_REQUIRE_GOD) && !isGodMode(user)) {
428 reply(tmp_text_client, user, "MODCMD_PRIVILEGED", cbind->cmd);
431 struct Event *event = createEvent(client, user, chan, cbind->func->name, argv, argc, eventflags);
432 cbind->func->func(client, user, chan, argv, argc, event);
435 static void got_chanmsg(struct UserNode *user, struct ChanNode *chan, char *message) {
438 struct ClientSocket *client;
440 for(client = getBots(SOCKET_FLAG_READY, NULL); client; client = getBots(SOCKET_FLAG_READY, client)) {
441 if(isUserOnChan(client->user, chan) && (client->flags & SOCKET_FLAG_PREFERRED) && !FD_ISSET(client->botid, &fds)) {
442 FD_SET(client->botid, &fds);
443 trigger = get_channel_trigger(client->botid, chan);
444 if(trigger && stricmplen(message, trigger, strlen(trigger)) == 0) {
445 handle_command(client, user, chan, message + strlen(trigger));
449 for(client = getBots(SOCKET_FLAG_READY, NULL); client; client = getBots(SOCKET_FLAG_READY, client)) {
450 if(isUserOnChan(client->user, chan) && !FD_ISSET(client->botid, &fds)) {
451 FD_SET(client->botid, &fds);
452 trigger = get_channel_trigger(client->botid, chan);
453 if(trigger && stricmplen(message, trigger, strlen(trigger)) == 0) {
454 handle_command(client, user, chan, message + strlen(trigger));
460 static void got_privmsg(struct UserNode *user, struct UserNode *target, char *message) {
461 struct ClientSocket *client;
462 for(client = getBots(SOCKET_FLAG_READY, NULL); client; client = getBots(SOCKET_FLAG_READY, client)) {
463 if(client->user == target) {
464 handle_command(client, user, NULL, message);
469 int register_command(int botid, char *name, cmd_bind_t *func, int paramcount, char *channel_access, int global_access, unsigned int flags) {
470 struct cmd_function *cmdfunc;
471 for(cmdfunc = cmd_functions; cmdfunc; cmdfunc = cmdfunc->next) {
472 if((cmdfunc->botid == botid || cmdfunc->botid == 0) && strcmp(cmdfunc->name, name) == 0)
475 cmdfunc = malloc(sizeof(*cmdfunc));
477 perror("malloc() failed");
480 cmdfunc->botid = botid;
481 cmdfunc->name = strdup(name);
482 cmdfunc->func = func;
483 cmdfunc->flags = flags;
484 cmdfunc->paramcount = paramcount;
485 cmdfunc->channel_access = channel_access;
486 cmdfunc->global_access = global_access;
487 cmdfunc->triggered = 0;
488 cmdfunc->next = cmd_functions;
489 cmd_functions = cmdfunc;
493 int set_trigger_callback(int botid, trigger_callback_t *func) {
494 static struct trigger_callback *cb = NULL;
495 for(cb = trigger_callbacks; cb; cb = cb->next) {
496 if(cb->botid == botid)
500 cb = malloc(sizeof(*cb));
502 perror("malloc() failed");
506 cb->next = trigger_callbacks;
507 trigger_callbacks = cb;
513 int changeChannelTrigger(int botid, struct ChanNode *chan, char *new_trigger) {
514 struct trigger_cache *trigger;
515 for(trigger = chan->trigger; trigger; trigger = trigger->next) {
516 if(trigger->botid == botid) {
517 free(trigger->trigger);
518 trigger->trigger = strdup(new_trigger);
525 int bind_cmd_to_function(int botid, char *cmd, struct cmd_function *func) {
526 int bind_index = get_binds_index(cmd[0]);
527 struct cmd_binding *cbind;
528 for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
529 if(cbind->botid == botid && strcmp(cbind->cmd, cmd) == 0)
532 cbind = malloc(sizeof(*cbind));
534 perror("malloc() failed");
537 cbind->botid = botid;
538 cbind->cmd = strdup(cmd);
540 cbind->paramcount = 0;
541 cbind->global_access = 0;
542 cbind->channel_access = NULL;
544 cbind->next = cmd_binds[bind_index];
545 cmd_binds[bind_index] = cbind;
549 int bind_cmd_to_command(int botid, char *cmd, char *func) {
550 struct cmd_function *cmdfunc;
553 if((c = strstr(func, "."))) {
555 struct cmd_bot_alias *botalias;
556 for(botalias = bot_aliases; botalias; botalias = botalias->next) {
557 if(!stricmp(botalias->alias, func)) {
558 fbotid = botalias->botid;
565 for(cmdfunc = cmd_functions; cmdfunc; cmdfunc = cmdfunc->next) {
566 if((cmdfunc->botid == fbotid || cmdfunc->botid == 0) && strcmp(cmdfunc->name, func) == 0)
569 if(!cmdfunc) return 0;
570 int bind_index = get_binds_index(cmd[0]);
571 struct cmd_binding *cbind;
572 for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
573 if(cbind->botid == botid && strcmp(cbind->cmd, cmd) == 0)
576 cbind = malloc(sizeof(*cbind));
578 perror("malloc() failed");
581 cbind->botid = botid;
582 cbind->cmd = strdup(cmd);
583 cbind->func = cmdfunc;
584 cbind->next = cmd_binds[bind_index];
585 cbind->paramcount = 0;
586 cbind->global_access = 0;
587 cbind->channel_access = NULL;
589 cmd_binds[bind_index] = cbind;
593 int unbind_cmd(int botid, char *cmd) {
594 int bind_index = get_binds_index(cmd[0]);
595 struct cmd_binding *cbind, *last = NULL;
596 for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
597 if(cbind->botid == botid && strcmp(cbind->cmd, cmd) == 0) {
599 last->next = cbind->next;
601 cmd_binds[bind_index] = cbind->next;
603 if(cbind->paramcount) {
605 for(i = 0; i < cbind->paramcount; i++)
606 free(cbind->parameters[i]);
616 struct cmd_function *find_cmd_function(int botid, char *name) {
617 struct cmd_function *cmdfunc;
619 if((c = strstr(name, "."))) {
621 struct cmd_bot_alias *botalias;
622 for(botalias = bot_aliases; botalias; botalias = botalias->next) {
623 if(!stricmp(botalias->alias, name)) {
624 botid = botalias->botid;
631 for(cmdfunc = cmd_functions; cmdfunc; cmdfunc = cmdfunc->next) {
632 if((cmdfunc->botid == botid || cmdfunc->botid == 0) && stricmp(cmdfunc->name, name) == 0)
638 struct ClientSocket *getTextBot() {
639 return tmp_text_client;
643 cmd_binds = calloc(27, sizeof(*cmd_binds));
644 bind_chanmsg(got_chanmsg);
645 bind_privmsg(got_privmsg);
646 register_default_language_table(msgtab);
651 for(i = 0; i < 27; i++) {
652 struct cmd_binding *cbind, *next;
653 for(cbind = cmd_binds[i]; cbind; cbind = next) {
656 if(cbind->paramcount) {
658 for(j = 0; j < cbind->paramcount; j++)
659 free(cbind->parameters[j]);
661 if(cbind->channel_access)
662 free(cbind->channel_access);
667 struct cmd_function *cmdfunct, *next;
668 for(cmdfunct = cmd_functions; cmdfunct; cmdfunct = next) {
669 next = cmdfunct->next;
670 free(cmdfunct->name);
673 struct trigger_callback *cb, *next_cb;
674 for(cb = trigger_callbacks; cb; cb = next_cb) {
678 struct cmd_bot_alias *botalias, *next_botalias;
679 for(botalias = bot_aliases; botalias; botalias = next_botalias) {
680 next_botalias = botalias->next;
681 free(botalias->alias);
684 cmd_functions = NULL;
685 trigger_callbacks = NULL;
689 void bind_set_parameters(int botid, char *cmd, char *parameters) {
690 int bind_index = get_binds_index(cmd[0]);
691 struct cmd_binding *cbind;
692 for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
693 if(cbind->botid == botid && strcmp(cbind->cmd, cmd) == 0) {
694 if(cbind->paramcount) {
696 for(i = 0; i < cbind->paramcount; i++)
697 free(cbind->parameters[i]);
698 cbind->paramcount = 0;
700 char *a, *b = parameters;
704 cbind->parameters[cbind->paramcount++] = strdup(b);
712 void bind_set_global_access(int botid, char *cmd, int gaccess) {
713 int bind_index = get_binds_index(cmd[0]);
714 struct cmd_binding *cbind;
715 for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
716 if(cbind->botid == botid && strcmp(cbind->cmd, cmd) == 0) {
718 cbind->global_access = gaccess;
719 cbind->flags |= CMDFLAG_OVERRIDE_GLOBAL_ACCESS;
721 cbind->flags &= ~CMDFLAG_OVERRIDE_GLOBAL_ACCESS;
728 void bind_set_channel_access(int botid, char *cmd, char *chanaccess) {
729 int bind_index = get_binds_index(cmd[0]);
730 struct cmd_binding *cbind;
731 for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
732 if(cbind->botid == botid && strcmp(cbind->cmd, cmd) == 0) {
733 if(cbind->channel_access)
734 free(cbind->channel_access);
736 cbind->channel_access = strdup(chanaccess);
737 cbind->flags |= CMDFLAG_OVERRIDE_CHANNEL_ACCESS;
739 cbind->channel_access = NULL;
740 cbind->flags &= ~CMDFLAG_OVERRIDE_CHANNEL_ACCESS;
747 struct cmd_binding *find_cmd_binding(int botid, char *cmd) {
748 int bind_index = get_binds_index(cmd[0]);
749 struct cmd_binding *cbind;
750 for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
751 if(cbind->botid == botid && strcmp(cbind->cmd, cmd) == 0) {
758 void bind_unbound_required_functions(int botid) {
759 struct cmd_function *cmdfunc;
761 struct cmd_binding *cbind;
762 for(cmdfunc = cmd_functions; cmdfunc; cmdfunc = cmdfunc->next) {
763 if((cmdfunc->flags & CMDFLAG_REQUIRED)) {
765 for(i = 0; i < 27; i++) {
766 for(cbind = cmd_binds[i]; cbind; cbind = cbind->next) {
767 if(cbind->botid == botid && cbind->func == cmdfunc) {
775 if(!found && bind_cmd_to_function(botid, cmdfunc->name, cmdfunc)) {
776 cbind = find_cmd_binding(botid, cmdfunc->name);
777 cbind->flags |= CMDFLAG_TEMPONARY_BIND;
783 void register_command_alias(int botid, char *alias) {
784 struct cmd_bot_alias *botalias;
785 for(botalias = bot_aliases; botalias; botalias = botalias->next) {
786 if(!stricmp(botalias->alias, alias))
789 botalias = malloc(sizeof(*botalias));
791 perror("malloc() failed");
794 botalias->botid = botid;
795 botalias->alias = strdup(alias);
796 botalias->next = bot_aliases;
797 bot_aliases = botalias;
800 struct cmd_binding *getAllBinds(struct cmd_binding *last) {
805 bind_index = get_binds_index(last->cmd[0]) + 1;
811 if(cmd_binds[bind_index])
812 return cmd_binds[bind_index];
814 } while(bind_index < 27);