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;
61 static const struct default_language_entry msgtab[] = {
62 {"MODCMD_LESS_PARAM_COUNT", "This command requires more parameters."},
63 {"MODCMD_CHAN_REQUIRED", "You must provide the name of a channel that exists and the bot is on."},
64 {"MODCMD_AUTH_REQUIRED", "You need to be authenticated with AuthServ to use this command."},
65 {"MODCMD_CHAN_SUSPENDED", "This channel is currently suspended."},
66 {"MODCMD_PRIVILEGED", "$b%s$b is a privileged command."}, /* {ARGS: "god"} */
67 {"MODCMD_PUBCMD", "Public commands in $b%s$b are restricted."}, /* {ARGS: "#TestChan"} */
68 {"MODCMD_ACCESS_DENIED", "Access denied."},
72 static int get_binds_index(char first_char) {
73 if(tolower(first_char) >= 'a' && tolower(first_char) <= 'z') {
74 return tolower(first_char) - 'a';
79 struct ClientSocket* get_prefered_bot(int botid) {
80 struct ClientSocket *client, *lowbot = NULL;
81 for(client = getBots(SOCKET_FLAG_READY, NULL); client; client = getBots(SOCKET_FLAG_READY, client)) {
82 if(client->botid == botid) {
83 if((client->flags & SOCKET_FLAG_PREFERRED))
92 static char* get_channel_trigger(int botid, struct ChanNode *chan) {
93 struct trigger_cache *trigger;
94 for(trigger = chan->trigger; trigger; trigger = trigger->next) {
95 if(trigger->botid == botid)
96 return trigger->trigger;
98 struct trigger_callback *cb;
99 for(cb = trigger_callbacks; cb; cb = cb->next) {
100 if(cb->botid == botid)
103 char triggerStr[TRIGGERLEN];
105 cb->func(chan, triggerStr);
107 strcpy(triggerStr, "+");
108 trigger = malloc(sizeof(*trigger));
110 perror("malloc() failed");
113 trigger->botid = botid;
114 trigger->trigger = (triggerStr[0] ? strdup(triggerStr) : NULL);
115 trigger->next = chan->trigger;
116 chan->trigger = trigger;
117 return trigger->trigger;
120 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);
122 static USERAUTH_CALLBACK(command_checked_auth) {
123 struct command_check_user_cache *cache = data;
124 tmp_text_client = cache->textclient;
125 handle_command_async(cache->client, user, cache->chan, cache->sent_chan, cache->cbind, cache->argv, cache->argc);
126 free(cache->message);
127 if(cache->args_buffer)
128 free(cache->args_buffer);
133 static void handle_command(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, char *message) {
134 struct ChanNode *sent_chan = chan;
135 if(message[0] == '#') {
136 char *chanName = message;
137 message = strstr(message, " ");
141 struct ChanNode *chan2 = getChanByName(chanName);
145 message = strdup(message);
146 int bind_index = get_binds_index(message[0]);
147 char *args = strstr(message, " ");
148 char *args_buffer = NULL; //we need this to save a possible pointer to a allocation we need to free
153 struct cmd_binding *cbind;
154 for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
155 if(cbind->botid == client->botid && stricmp(cbind->cmd, message) == 0) {
157 tmp_text_client = get_prefered_bot(client->botid);
158 //parse the arguments...
159 char *arga[MAXNUMPARAMS];
164 //skip leading spaces
168 if (argc >= MAXNUMPARAMS)
170 while (*args != ' ' && *args)
175 if(argc != 0 && argv[0][0] == '#' && !(cbind->func->flags & CMDFLAG_CHAN_PARAM)) {
176 struct ChanNode *chan2 = getChanByName(argv[0]);
183 if(cbind->paramcount) {
184 //userdefined parameters...
185 args_buffer = malloc(MAXLEN * 2 * sizeof(*args_buffer));
187 char *uargs[MAXNUMPARAMS];
192 for(i = 0; i < cbind->paramcount; i++) {
193 b = cbind->parameters[i];
196 if(b[strlen(b)-1] == '-') {
197 allargs = strlen(b)-1;
202 } else if(b[strlen(b)-1] == '+') {
203 allargs = strlen(b)-1;
214 uargs[uargc++] = args_buffer + args_pos;
216 args_pos += sprintf(args_buffer + args_pos, "%s", argv[argi-1]) + 1;
217 } else if(allargs == 1) {
218 args_pos += sprintf(args_buffer + args_pos, "%s", argv[argi-1]) + 1;
219 for(argi++; argi <= argc; argi++) {
220 uargs[uargc++] = args_buffer + args_pos;
221 args_pos += sprintf(args_buffer + args_pos, "%s", argv[argi-1]) + 1;
223 } else if(allargs == 2) {
224 for(;argi <= argc; argi++) {
225 args_pos += sprintf(args_buffer + args_pos, (allargs ? "%s" : " %s"), argv[argi-1]);
230 } else if((cbind->func->flags & CMDFLAG_EMPTY_ARGS)) {
231 uargs[uargc++] = args_buffer + args_pos;
232 args_buffer[args_pos++] = '\0';
234 } else if(!strcmp(b, "c")) {
235 uargs[uargc++] = args_buffer + args_pos;
236 args_pos += sprintf(args_buffer + args_pos, "%s", (chan ? chan->name : "")) + 1;
237 } else if(!strcmp(b, "n")) {
238 uargs[uargc++] = args_buffer + args_pos;
239 args_pos += sprintf(args_buffer + args_pos, "%s", user->nick) + 1;
242 uargs[uargc++] = args_buffer + args_pos;
243 args_pos += sprintf(args_buffer + args_pos, "%s", b) + 1;
249 if(argc < cbind->func->paramcount) {
250 reply(tmp_text_client, user, "MODCMD_LESS_PARAM_COUNT");
253 if((cbind->func->flags & CMDFLAG_REQUIRE_CHAN) && !chan) {
254 reply(tmp_text_client, user, "MODCMD_CHAN_REQUIRED");
257 if((cbind->func->flags & CMDFLAG_CHECK_AUTH) && !(user->flags & USERFLAG_ISAUTHED)) {
259 struct command_check_user_cache *data = malloc(sizeof(*data));
260 char **temp_argv = malloc(argc*sizeof(*temp_argv));
261 if (!data || !temp_argv) {
262 perror("malloc() failed");
265 memcpy(temp_argv, argv, argc*sizeof(*temp_argv));
266 data->argv = temp_argv;
268 data->client = client;
271 data->sent_chan = sent_chan;
272 data->message = message;
273 data->args_buffer = args_buffer;
275 data->textclient = tmp_text_client;
276 get_userauth(user, command_checked_auth, data);
279 handle_command_async(client, user, chan, sent_chan, cbind, argv, argc);
288 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) {
292 int eventflags = (cbind->func->flags & (CMDFLAG_LOG | CMDFLAG_OPLOG));
293 if((cbind->func->flags & CMDFLAG_REQUIRE_AUTH) && !(user->flags & USERFLAG_ISAUTHED)) {
294 reply(tmp_text_client, user, "MODCMD_AUTH_REQUIRED");
297 if(sent_chan && sent_chan != chan) {
298 //check pubcmd of this channel
299 printf_mysql_query("SELECT `channel_pubcmd` FROM `channels` WHERE `channel_name` = '%s'", escape_string(sent_chan->name));
301 if ((row = mysql_fetch_row(res)) != NULL) {
302 uaccess = getChannelAccess(user, sent_chan);
303 if(row[0] && uaccess < atoi(row[0]) && !isGodMode(user)) { //NOTE: HARDCODED DEFAULT: pubcmd = 0
304 reply(tmp_text_client, user, "MODCMD_PUBCMD", sent_chan->name);
309 int global_access = ((cbind->flags & CMDFLAG_OVERRIDE_GLOBAL_ACCESS) ? cbind->global_access : cbind->func->global_access);
310 if(global_access > 0) {
311 int user_global_access = 0;
312 printf_mysql_query("SELECT `user_access` FROM `users` WHERE `user_user` = '%s'", escape_string(user->auth));
314 if ((row = mysql_fetch_row(res)) != NULL) {
315 user_global_access = atoi(row[0]);
317 if(user_global_access < global_access) {
318 if(!user_global_access)
319 reply(tmp_text_client, user, "MODCMD_PRIVILEGED", cbind->cmd);
321 reply(tmp_text_client, user, "MODCMD_ACCESS_DENIED");
325 if((cbind->func->flags & CMDFLAG_REGISTERED_CHAN)) {
326 MYSQL_ROW defaults = NULL;
327 char access_list[256];
329 int access_count = 0;
331 char *str_a, *str_b = cbind->func->channel_access, *str_c;
332 if(cbind->flags & CMDFLAG_OVERRIDE_CHANNEL_ACCESS)
333 str_b = cbind->channel_access;
334 access_list[0] = '\0';
336 str_c = strdup(str_b);
338 while((str_a = str_b)) {
339 str_b = strstr(str_a, ",");
346 access_pos += sprintf(access_list+access_pos, ", `%s`", str_a);
349 if(atoi(str_a) > minaccess)
350 minaccess = atoi(str_a);
355 if(!(chan->flags & CHANFLAG_REQUESTED_CHANINFO) || (sent_chan && sent_chan == chan) || access_count || minaccess) {
356 printf_mysql_query("SELECT `channel_id`, `channel_pubcmd` %s FROM `channels` WHERE `channel_name` = '%s'", access_list, escape_string(chan->name));
358 if ((row = mysql_fetch_row(res)) != NULL) {
359 chan->flags |= CHANFLAG_CHAN_REGISTERED;
360 chan->channel_id = atoi(row[0]);
361 if((sent_chan && sent_chan == chan) || access_count || minaccess) {
362 uaccess = getChannelAccess(user, chan);
363 if(uaccess < minaccess && isGodMode(user)) {
364 eventflags |= CMDFLAG_OPLOG;
365 } else if(uaccess < minaccess) {
367 reply(tmp_text_client, user, "MODCMD_ACCESS_DENIED");
370 if(!row[1] && !defaults) {
371 printf_mysql_query("SELECT `channel_id`, `channel_pubcmd` %s FROM `channels` WHERE `channel_name` = 'defaults'", access_list);
372 defaults = mysql_fetch_row(mysql_use());
374 if(sent_chan && (sent_chan == chan) && uaccess < (row[1] ? atoi(row[1]) : atoi(defaults[1]))) {
375 if(isGodMode(user)) {
376 eventflags |= CMDFLAG_OPLOG;
379 reply(tmp_text_client, user, "MODCMD_PUBCMD", chan->name);
384 for(i = 0; i < access_count; i++) {
385 if(!row[2+i] && !defaults) {
386 printf_mysql_query("SELECT `channel_id`, `channel_pubcmd` %s FROM `channels` WHERE `channel_name` = 'defaults'", access_list);
387 defaults = mysql_fetch_row(mysql_use());
389 if(uaccess < (row[2+i] ? atoi(row[2+i]) : atoi(defaults[2+i]))) {
390 if(isGodMode(user)) {
391 eventflags |= CMDFLAG_OPLOG;
393 reply(tmp_text_client, user, "MODCMD_ACCESS_DENIED");
400 chan->flags |= CHANFLAG_REQUESTED_CHANINFO;
402 if(!(chan->flags & CHANFLAG_CHAN_REGISTERED)) {
403 reply(tmp_text_client, user, "MODCMD_CHAN_REQUIRED");
406 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);
408 if ((row = mysql_fetch_row(res)) == NULL) {
409 reply(tmp_text_client, user, "MODCMD_CHAN_REQUIRED");
411 } else if(!strcmp(row[1], "1")) {
412 reply(tmp_text_client, user, "MODCMD_CHAN_SUSPENDED");
416 if((cbind->func->flags & CMDFLAG_REQUIRE_GOD) && !isGodMode(user)) {
417 reply(tmp_text_client, user, "MODCMD_PRIVILEGED", cbind->cmd);
420 struct Event *event = createEvent(client, user, chan, cbind->func->name, argv, argc, eventflags);
421 cbind->func->func(client, user, chan, argv, argc, event);
424 static void got_chanmsg(struct UserNode *user, struct ChanNode *chan, char *message) {
427 struct ClientSocket *client;
429 for(client = getBots(SOCKET_FLAG_READY, NULL); client; client = getBots(SOCKET_FLAG_READY, client)) {
430 if(isUserOnChan(client->user, chan) && (client->flags & SOCKET_FLAG_PREFERRED) && !FD_ISSET(client->botid, &fds)) {
431 FD_SET(client->botid, &fds);
432 trigger = get_channel_trigger(client->botid, chan);
433 if(trigger && stricmplen(message, trigger, strlen(trigger)) == 0) {
434 handle_command(client, user, chan, message + strlen(trigger));
438 for(client = getBots(SOCKET_FLAG_READY, NULL); client; client = getBots(SOCKET_FLAG_READY, client)) {
439 if(isUserOnChan(client->user, chan) && !FD_ISSET(client->botid, &fds)) {
440 FD_SET(client->botid, &fds);
441 trigger = get_channel_trigger(client->botid, chan);
442 if(trigger && stricmplen(message, trigger, strlen(trigger)) == 0) {
443 handle_command(client, user, chan, message + strlen(trigger));
449 static void got_privmsg(struct UserNode *user, struct UserNode *target, char *message) {
450 struct ClientSocket *client;
451 for(client = getBots(SOCKET_FLAG_READY, NULL); client; client = getBots(SOCKET_FLAG_READY, client)) {
452 if(client->user == target) {
453 handle_command(client, user, NULL, message);
458 int register_command(int botid, char *name, cmd_bind_t *func, int paramcount, char *channel_access, int global_access, unsigned int flags) {
459 struct cmd_function *cmdfunc;
460 for(cmdfunc = cmd_functions; cmdfunc; cmdfunc = cmdfunc->next) {
461 if((cmdfunc->botid == botid || cmdfunc->botid == 0) && strcmp(cmdfunc->name, name) == 0)
464 cmdfunc = malloc(sizeof(*cmdfunc));
466 perror("malloc() failed");
469 cmdfunc->botid = botid;
470 cmdfunc->name = strdup(name);
471 cmdfunc->func = func;
472 cmdfunc->flags = flags;
473 cmdfunc->paramcount = paramcount;
474 cmdfunc->channel_access = channel_access;
475 cmdfunc->global_access = global_access;
476 cmdfunc->next = cmd_functions;
477 cmd_functions = cmdfunc;
481 int set_trigger_callback(int botid, trigger_callback_t *func) {
482 static struct trigger_callback *cb = NULL;
483 for(cb = trigger_callbacks; cb; cb = cb->next) {
484 if(cb->botid == botid)
488 cb = malloc(sizeof(*cb));
490 perror("malloc() failed");
494 cb->next = trigger_callbacks;
495 trigger_callbacks = cb;
501 int changeChannelTrigger(int botid, struct ChanNode *chan, char *new_trigger) {
502 struct trigger_cache *trigger;
503 for(trigger = chan->trigger; trigger; trigger = trigger->next) {
504 if(trigger->botid == botid) {
505 free(trigger->trigger);
506 trigger->trigger = strdup(new_trigger);
513 int bind_cmd_to_function(int botid, char *cmd, struct cmd_function *func) {
514 int bind_index = get_binds_index(cmd[0]);
515 struct cmd_binding *cbind;
516 for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
517 if(cbind->botid == botid && strcmp(cbind->cmd, cmd) == 0)
520 cbind = malloc(sizeof(*cbind));
522 perror("malloc() failed");
525 cbind->botid = botid;
526 cbind->cmd = strdup(cmd);
528 cbind->paramcount = 0;
529 cbind->global_access = 0;
530 cbind->channel_access = NULL;
532 cbind->next = cmd_binds[bind_index];
533 cmd_binds[bind_index] = cbind;
537 int bind_cmd_to_command(int botid, char *cmd, char *func) {
538 struct cmd_function *cmdfunc;
541 if((c = strstr(func, "."))) {
543 struct cmd_bot_alias *botalias;
544 for(botalias = bot_aliases; botalias; botalias = botalias->next) {
545 if(!stricmp(botalias->alias, func)) {
546 fbotid = botalias->botid;
553 for(cmdfunc = cmd_functions; cmdfunc; cmdfunc = cmdfunc->next) {
554 if((cmdfunc->botid == fbotid || cmdfunc->botid == 0) && strcmp(cmdfunc->name, func) == 0)
557 if(!cmdfunc) return 0;
558 int bind_index = get_binds_index(cmd[0]);
559 struct cmd_binding *cbind;
560 for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
561 if(cbind->botid == botid && strcmp(cbind->cmd, cmd) == 0)
564 cbind = malloc(sizeof(*cbind));
566 perror("malloc() failed");
569 cbind->botid = botid;
570 cbind->cmd = strdup(cmd);
571 cbind->func = cmdfunc;
572 cbind->next = cmd_binds[bind_index];
573 cbind->paramcount = 0;
574 cbind->global_access = 0;
575 cbind->channel_access = NULL;
577 cmd_binds[bind_index] = cbind;
581 int unbind_cmd(int botid, char *cmd) {
582 int bind_index = get_binds_index(cmd[0]);
583 struct cmd_binding *cbind, *last = NULL;
584 for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
585 if(cbind->botid == botid && strcmp(cbind->cmd, cmd) == 0) {
587 last->next = cbind->next;
589 cmd_binds[bind_index] = cbind->next;
591 if(cbind->paramcount) {
593 for(i = 0; i < cbind->paramcount; i++)
594 free(cbind->parameters[i]);
604 struct cmd_function *find_cmd_function(int botid, char *name) {
605 struct cmd_function *cmdfunc;
607 if((c = strstr(name, "."))) {
609 struct cmd_bot_alias *botalias;
610 for(botalias = bot_aliases; botalias; botalias = botalias->next) {
611 if(!stricmp(botalias->alias, name)) {
612 botid = botalias->botid;
619 for(cmdfunc = cmd_functions; cmdfunc; cmdfunc = cmdfunc->next) {
620 if((cmdfunc->botid == botid || cmdfunc->botid == 0) && stricmp(cmdfunc->name, name) == 0)
626 struct ClientSocket *getTextBot() {
627 return tmp_text_client;
631 cmd_binds = calloc(27, sizeof(*cmd_binds));
632 bind_chanmsg(got_chanmsg);
633 bind_privmsg(got_privmsg);
634 register_default_language_table(msgtab);
639 for(i = 0; i < 27; i++) {
640 struct cmd_binding *cbind, *next;
641 for(cbind = cmd_binds[i]; cbind; cbind = next) {
644 if(cbind->paramcount) {
646 for(j = 0; j < cbind->paramcount; j++)
647 free(cbind->parameters[j]);
649 if(cbind->channel_access)
650 free(cbind->channel_access);
655 struct cmd_function *cmdfunct, *next;
656 for(cmdfunct = cmd_functions; cmdfunct; cmdfunct = next) {
657 next = cmdfunct->next;
658 free(cmdfunct->name);
661 struct trigger_callback *cb, *next_cb;
662 for(cb = trigger_callbacks; cb; cb = next_cb) {
666 struct cmd_bot_alias *botalias, *next_botalias;
667 for(botalias = bot_aliases; botalias; botalias = next_botalias) {
668 next_botalias = botalias->next;
669 free(botalias->alias);
672 cmd_functions = NULL;
673 trigger_callbacks = NULL;
677 void bind_set_parameters(int botid, char *cmd, char *parameters) {
678 int bind_index = get_binds_index(cmd[0]);
679 struct cmd_binding *cbind;
680 for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
681 if(cbind->botid == botid && strcmp(cbind->cmd, cmd) == 0) {
682 if(cbind->paramcount) {
684 for(i = 0; i < cbind->paramcount; i++)
685 free(cbind->parameters[i]);
686 cbind->paramcount = 0;
688 char *a, *b = parameters;
692 cbind->parameters[cbind->paramcount++] = strdup(b);
700 void bind_set_global_access(int botid, char *cmd, int gaccess) {
701 int bind_index = get_binds_index(cmd[0]);
702 struct cmd_binding *cbind;
703 for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
704 if(cbind->botid == botid && strcmp(cbind->cmd, cmd) == 0) {
706 cbind->global_access = gaccess;
707 cbind->flags |= CMDFLAG_OVERRIDE_GLOBAL_ACCESS;
709 cbind->flags &= ~CMDFLAG_OVERRIDE_GLOBAL_ACCESS;
716 void bind_set_channel_access(int botid, char *cmd, char *chanaccess) {
717 int bind_index = get_binds_index(cmd[0]);
718 struct cmd_binding *cbind;
719 for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
720 if(cbind->botid == botid && strcmp(cbind->cmd, cmd) == 0) {
721 if(cbind->channel_access)
722 free(cbind->channel_access);
724 cbind->channel_access = strdup(chanaccess);
725 cbind->flags |= CMDFLAG_OVERRIDE_CHANNEL_ACCESS;
727 cbind->channel_access = NULL;
728 cbind->flags &= ~CMDFLAG_OVERRIDE_CHANNEL_ACCESS;
735 struct cmd_binding *find_cmd_binding(int botid, char *cmd) {
736 int bind_index = get_binds_index(cmd[0]);
737 struct cmd_binding *cbind;
738 for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
739 if(cbind->botid == botid && strcmp(cbind->cmd, cmd) == 0) {
746 void bind_unbound_required_functions(int botid) {
747 struct cmd_function *cmdfunc;
749 struct cmd_binding *cbind;
750 for(cmdfunc = cmd_functions; cmdfunc; cmdfunc = cmdfunc->next) {
751 if((cmdfunc->flags & CMDFLAG_REQUIRED)) {
753 for(i = 0; i < 27; i++) {
754 for(cbind = cmd_binds[i]; cbind; cbind = cbind->next) {
755 if(cbind->botid == botid && cbind->func == cmdfunc) {
763 if(!found && bind_cmd_to_function(botid, cmdfunc->name, cmdfunc)) {
764 cbind = find_cmd_binding(botid, cmdfunc->name);
765 cbind->flags |= CMDFLAG_TEMPONARY_BIND;
771 void register_bot_alias(int botid, char *alias) {
772 struct cmd_bot_alias *botalias;
773 for(botalias = bot_aliases; botalias; botalias = botalias->next) {
774 if(!stricmp(botalias->alias, alias))
777 botalias = malloc(sizeof(*botalias));
779 perror("malloc() failed");
782 botalias->botid = botid;
783 botalias->alias = strdup(alias);
784 botalias->next = bot_aliases;
785 bot_aliases = botalias;
788 struct cmd_binding *getAllBinds(struct cmd_binding *last) {
793 bind_index = get_binds_index(last->cmd[0]) + 1;
799 if(cmd_binds[bind_index])
800 return cmd_binds[bind_index];
802 } while(bind_index < 27);