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 int statistics_commands = 0;
62 static const struct default_language_entry msgtab[] = {
63 {"MODCMD_LESS_PARAM_COUNT", "This command requires more parameters."},
64 {"MODCMD_CHAN_REQUIRED", "You must provide the name of a channel that exists and the bot is on."},
65 {"MODCMD_AUTH_REQUIRED", "You need to be authenticated with AuthServ to use this command."},
66 {"MODCMD_CHAN_SUSPENDED", "This channel is currently suspended."},
67 {"MODCMD_PRIVILEGED", "$b%s$b is a privileged command."}, /* {ARGS: "god"} */
68 {"MODCMD_PUBCMD", "Public commands in $b%s$b are restricted."}, /* {ARGS: "#TestChan"} */
69 {"MODCMD_ACCESS_DENIED", "Access denied."},
73 static int get_binds_index(char first_char) {
74 if(tolower(first_char) >= 'a' && tolower(first_char) <= 'z') {
75 return tolower(first_char) - 'a';
80 struct ClientSocket* get_prefered_bot(int botid) {
81 struct ClientSocket *client, *lowbot = NULL;
82 for(client = getBots(SOCKET_FLAG_READY, NULL); client; client = getBots(SOCKET_FLAG_READY, client)) {
83 if(client->botid == botid) {
84 if((client->flags & SOCKET_FLAG_PREFERRED))
93 static char* get_channel_trigger(int botid, struct ChanNode *chan) {
94 struct trigger_cache *trigger;
95 for(trigger = chan->trigger; trigger; trigger = trigger->next) {
96 if(trigger->botid == botid)
97 return trigger->trigger;
99 struct trigger_callback *cb;
100 for(cb = trigger_callbacks; cb; cb = cb->next) {
101 if(cb->botid == botid)
104 char triggerStr[TRIGGERLEN];
106 cb->func(chan, triggerStr);
108 strcpy(triggerStr, "+");
109 trigger = malloc(sizeof(*trigger));
111 perror("malloc() failed");
114 trigger->botid = botid;
115 trigger->trigger = (triggerStr[0] ? strdup(triggerStr) : NULL);
116 trigger->next = chan->trigger;
117 chan->trigger = trigger;
118 return trigger->trigger;
121 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);
123 static USERAUTH_CALLBACK(command_checked_auth) {
124 struct command_check_user_cache *cache = data;
125 tmp_text_client = cache->textclient;
126 handle_command_async(cache->client, user, cache->chan, cache->sent_chan, cache->cbind, cache->argv, cache->argc);
127 free(cache->message);
128 if(cache->args_buffer)
129 free(cache->args_buffer);
134 static void handle_command(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, char *message) {
135 struct ChanNode *sent_chan = chan;
136 if(message[0] == '#') {
137 char *chanName = message;
138 message = strstr(message, " ");
142 struct ChanNode *chan2 = getChanByName(chanName);
146 message = strdup(message);
147 int bind_index = get_binds_index(message[0]);
148 char *args = strstr(message, " ");
149 char *args_buffer = NULL; //we need this to save a possible pointer to a allocation we need to free
154 struct cmd_binding *cbind;
155 for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
156 if(cbind->botid == client->botid && stricmp(cbind->cmd, message) == 0) {
157 if(statistics_enabled)
158 statistics_commands++;
159 if((cbind->func->flags & CMDFLAG_FUNCMD)) {
165 tmp_text_client = get_prefered_bot(client->botid);
166 //parse the arguments...
167 char *arga[MAXNUMPARAMS];
172 //skip leading spaces
176 if (argc >= MAXNUMPARAMS)
178 while (*args != ' ' && *args)
183 if(argc != 0 && argv[0][0] == '#' && !(cbind->func->flags & CMDFLAG_CHAN_PARAM)) {
184 struct ChanNode *chan2 = getChanByName(argv[0]);
191 if(cbind->paramcount) {
192 //userdefined parameters...
193 args_buffer = malloc(MAXLEN * 2 * sizeof(*args_buffer));
195 char *uargs[MAXNUMPARAMS];
200 for(i = 0; i < cbind->paramcount; i++) {
201 b = cbind->parameters[i];
204 if(b[strlen(b)-1] == '-') {
205 allargs = strlen(b)-1;
210 } else if(b[strlen(b)-1] == '+') {
211 allargs = strlen(b)-1;
222 uargs[uargc++] = args_buffer + args_pos;
224 args_pos += sprintf(args_buffer + args_pos, "%s", argv[argi-1]) + 1;
225 } else if(allargs == 1) {
226 args_pos += sprintf(args_buffer + args_pos, "%s", argv[argi-1]) + 1;
227 for(argi++; argi <= argc; argi++) {
228 uargs[uargc++] = args_buffer + args_pos;
229 args_pos += sprintf(args_buffer + args_pos, "%s", argv[argi-1]) + 1;
231 } else if(allargs == 2) {
232 for(;argi <= argc; argi++) {
233 args_pos += sprintf(args_buffer + args_pos, (allargs ? "%s" : " %s"), argv[argi-1]);
238 } else if((cbind->func->flags & CMDFLAG_EMPTY_ARGS)) {
239 uargs[uargc++] = args_buffer + args_pos;
240 args_buffer[args_pos++] = '\0';
242 } else if(!strcmp(b, "c")) {
243 uargs[uargc++] = args_buffer + args_pos;
244 args_pos += sprintf(args_buffer + args_pos, "%s", (chan ? chan->name : "")) + 1;
245 } else if(!strcmp(b, "n")) {
246 uargs[uargc++] = args_buffer + args_pos;
247 args_pos += sprintf(args_buffer + args_pos, "%s", user->nick) + 1;
250 uargs[uargc++] = args_buffer + args_pos;
251 args_pos += sprintf(args_buffer + args_pos, "%s", b) + 1;
257 if(argc < cbind->func->paramcount) {
258 reply(tmp_text_client, user, "MODCMD_LESS_PARAM_COUNT");
261 if((cbind->func->flags & CMDFLAG_REQUIRE_CHAN) && !chan) {
262 reply(tmp_text_client, user, "MODCMD_CHAN_REQUIRED");
265 if((cbind->func->flags & CMDFLAG_CHECK_AUTH) && !(user->flags & USERFLAG_ISAUTHED)) {
267 struct command_check_user_cache *data = malloc(sizeof(*data));
268 char **temp_argv = malloc(argc*sizeof(*temp_argv));
269 if (!data || !temp_argv) {
270 perror("malloc() failed");
273 memcpy(temp_argv, argv, argc*sizeof(*temp_argv));
274 data->argv = temp_argv;
276 data->client = client;
279 data->sent_chan = sent_chan;
280 data->message = message;
281 data->args_buffer = args_buffer;
283 data->textclient = tmp_text_client;
284 get_userauth(user, command_checked_auth, data);
287 handle_command_async(client, user, chan, sent_chan, cbind, argv, argc);
296 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) {
300 int eventflags = (cbind->func->flags & (CMDFLAG_LOG | CMDFLAG_OPLOG));
301 if((cbind->func->flags & CMDFLAG_REQUIRE_AUTH) && !(user->flags & USERFLAG_ISAUTHED)) {
302 reply(tmp_text_client, user, "MODCMD_AUTH_REQUIRED");
305 if(sent_chan && sent_chan != chan) {
306 //check pubcmd of this channel
307 printf_mysql_query("SELECT `channel_pubcmd` FROM `channels` WHERE `channel_name` = '%s'", escape_string(sent_chan->name));
309 if ((row = mysql_fetch_row(res)) != NULL) {
310 uaccess = getChannelAccess(user, sent_chan);
311 if(row[0] && uaccess < atoi(row[0]) && !isGodMode(user)) { //NOTE: HARDCODED DEFAULT: pubcmd = 0
312 reply(tmp_text_client, user, "MODCMD_PUBCMD", sent_chan->name);
317 int global_access = ((cbind->flags & CMDFLAG_OVERRIDE_GLOBAL_ACCESS) ? cbind->global_access : cbind->func->global_access);
318 if(global_access > 0) {
319 int user_global_access = 0;
320 printf_mysql_query("SELECT `user_access` FROM `users` WHERE `user_user` = '%s'", escape_string(user->auth));
322 if ((row = mysql_fetch_row(res)) != NULL) {
323 user_global_access = atoi(row[0]);
325 if(user_global_access < global_access) {
326 if(!user_global_access)
327 reply(tmp_text_client, user, "MODCMD_PRIVILEGED", cbind->cmd);
329 reply(tmp_text_client, user, "MODCMD_ACCESS_DENIED");
333 if((cbind->func->flags & CMDFLAG_REGISTERED_CHAN)) {
334 MYSQL_ROW defaults = NULL;
335 char access_list[256];
337 int access_count = 0;
339 char *str_a, *str_b = cbind->func->channel_access, *str_c;
340 if(cbind->flags & CMDFLAG_OVERRIDE_CHANNEL_ACCESS)
341 str_b = cbind->channel_access;
342 access_list[0] = '\0';
344 str_c = strdup(str_b);
346 while((str_a = str_b)) {
347 str_b = strstr(str_a, ",");
354 access_pos += sprintf(access_list+access_pos, ", `%s`", str_a);
357 if(atoi(str_a) > minaccess)
358 minaccess = atoi(str_a);
363 if(!(chan->flags & CHANFLAG_REQUESTED_CHANINFO) || (sent_chan && sent_chan == chan) || access_count || minaccess) {
364 printf_mysql_query("SELECT `channel_id`, `channel_pubcmd` %s FROM `channels` WHERE `channel_name` = '%s'", access_list, escape_string(chan->name));
366 if ((row = mysql_fetch_row(res)) != NULL) {
367 chan->flags |= CHANFLAG_CHAN_REGISTERED;
368 chan->channel_id = atoi(row[0]);
369 if((sent_chan && sent_chan == chan) || access_count || minaccess) {
370 uaccess = getChannelAccess(user, chan);
371 if(uaccess < minaccess && isGodMode(user)) {
372 eventflags |= CMDFLAG_OPLOG;
373 } else if(uaccess < minaccess) {
375 reply(tmp_text_client, user, "MODCMD_ACCESS_DENIED");
378 if(!row[1] && !defaults) {
379 printf_mysql_query("SELECT `channel_id`, `channel_pubcmd` %s FROM `channels` WHERE `channel_name` = 'defaults'", access_list);
380 defaults = mysql_fetch_row(mysql_use());
382 if(sent_chan && (sent_chan == chan) && uaccess < (row[1] ? atoi(row[1]) : atoi(defaults[1]))) {
383 if(isGodMode(user)) {
384 eventflags |= CMDFLAG_OPLOG;
387 reply(tmp_text_client, user, "MODCMD_PUBCMD", chan->name);
392 for(i = 0; i < access_count; i++) {
393 if(!row[2+i] && !defaults) {
394 printf_mysql_query("SELECT `channel_id`, `channel_pubcmd` %s FROM `channels` WHERE `channel_name` = 'defaults'", access_list);
395 defaults = mysql_fetch_row(mysql_use());
397 if(uaccess < (row[2+i] ? atoi(row[2+i]) : atoi(defaults[2+i]))) {
398 if(isGodMode(user)) {
399 eventflags |= CMDFLAG_OPLOG;
401 reply(tmp_text_client, user, "MODCMD_ACCESS_DENIED");
408 chan->flags |= CHANFLAG_REQUESTED_CHANINFO;
410 if(!(chan->flags & CHANFLAG_CHAN_REGISTERED)) {
411 reply(tmp_text_client, user, "MODCMD_CHAN_REQUIRED");
414 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);
416 if ((row = mysql_fetch_row(res)) == NULL) {
417 reply(tmp_text_client, user, "MODCMD_CHAN_REQUIRED");
419 } else if(!strcmp(row[1], "1")) {
420 reply(tmp_text_client, user, "MODCMD_CHAN_SUSPENDED");
424 if((cbind->func->flags & CMDFLAG_REQUIRE_GOD) && !isGodMode(user)) {
425 reply(tmp_text_client, user, "MODCMD_PRIVILEGED", cbind->cmd);
428 struct Event *event = createEvent(client, user, chan, cbind->func->name, argv, argc, eventflags);
429 cbind->func->func(client, user, chan, argv, argc, event);
432 static void got_chanmsg(struct UserNode *user, struct ChanNode *chan, char *message) {
435 struct ClientSocket *client;
437 for(client = getBots(SOCKET_FLAG_READY, NULL); client; client = getBots(SOCKET_FLAG_READY, client)) {
438 if(isUserOnChan(client->user, chan) && (client->flags & SOCKET_FLAG_PREFERRED) && !FD_ISSET(client->botid, &fds)) {
439 FD_SET(client->botid, &fds);
440 trigger = get_channel_trigger(client->botid, chan);
441 if(trigger && stricmplen(message, trigger, strlen(trigger)) == 0) {
442 handle_command(client, user, chan, message + strlen(trigger));
446 for(client = getBots(SOCKET_FLAG_READY, NULL); client; client = getBots(SOCKET_FLAG_READY, client)) {
447 if(isUserOnChan(client->user, chan) && !FD_ISSET(client->botid, &fds)) {
448 FD_SET(client->botid, &fds);
449 trigger = get_channel_trigger(client->botid, chan);
450 if(trigger && stricmplen(message, trigger, strlen(trigger)) == 0) {
451 handle_command(client, user, chan, message + strlen(trigger));
457 static void got_privmsg(struct UserNode *user, struct UserNode *target, char *message) {
458 struct ClientSocket *client;
459 for(client = getBots(SOCKET_FLAG_READY, NULL); client; client = getBots(SOCKET_FLAG_READY, client)) {
460 if(client->user == target) {
461 handle_command(client, user, NULL, message);
466 int register_command(int botid, char *name, cmd_bind_t *func, int paramcount, char *channel_access, int global_access, unsigned int flags) {
467 struct cmd_function *cmdfunc;
468 for(cmdfunc = cmd_functions; cmdfunc; cmdfunc = cmdfunc->next) {
469 if((cmdfunc->botid == botid || cmdfunc->botid == 0) && strcmp(cmdfunc->name, name) == 0)
472 cmdfunc = malloc(sizeof(*cmdfunc));
474 perror("malloc() failed");
477 cmdfunc->botid = botid;
478 cmdfunc->name = strdup(name);
479 cmdfunc->func = func;
480 cmdfunc->flags = flags;
481 cmdfunc->paramcount = paramcount;
482 cmdfunc->channel_access = channel_access;
483 cmdfunc->global_access = global_access;
484 cmdfunc->next = cmd_functions;
485 cmd_functions = cmdfunc;
489 int set_trigger_callback(int botid, trigger_callback_t *func) {
490 static struct trigger_callback *cb = NULL;
491 for(cb = trigger_callbacks; cb; cb = cb->next) {
492 if(cb->botid == botid)
496 cb = malloc(sizeof(*cb));
498 perror("malloc() failed");
502 cb->next = trigger_callbacks;
503 trigger_callbacks = cb;
509 int changeChannelTrigger(int botid, struct ChanNode *chan, char *new_trigger) {
510 struct trigger_cache *trigger;
511 for(trigger = chan->trigger; trigger; trigger = trigger->next) {
512 if(trigger->botid == botid) {
513 free(trigger->trigger);
514 trigger->trigger = strdup(new_trigger);
521 int bind_cmd_to_function(int botid, char *cmd, struct cmd_function *func) {
522 int bind_index = get_binds_index(cmd[0]);
523 struct cmd_binding *cbind;
524 for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
525 if(cbind->botid == botid && strcmp(cbind->cmd, cmd) == 0)
528 cbind = malloc(sizeof(*cbind));
530 perror("malloc() failed");
533 cbind->botid = botid;
534 cbind->cmd = strdup(cmd);
536 cbind->paramcount = 0;
537 cbind->global_access = 0;
538 cbind->channel_access = NULL;
540 cbind->next = cmd_binds[bind_index];
541 cmd_binds[bind_index] = cbind;
545 int bind_cmd_to_command(int botid, char *cmd, char *func) {
546 struct cmd_function *cmdfunc;
549 if((c = strstr(func, "."))) {
551 struct cmd_bot_alias *botalias;
552 for(botalias = bot_aliases; botalias; botalias = botalias->next) {
553 if(!stricmp(botalias->alias, func)) {
554 fbotid = botalias->botid;
561 for(cmdfunc = cmd_functions; cmdfunc; cmdfunc = cmdfunc->next) {
562 if((cmdfunc->botid == fbotid || cmdfunc->botid == 0) && strcmp(cmdfunc->name, func) == 0)
565 if(!cmdfunc) return 0;
566 int bind_index = get_binds_index(cmd[0]);
567 struct cmd_binding *cbind;
568 for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
569 if(cbind->botid == botid && strcmp(cbind->cmd, cmd) == 0)
572 cbind = malloc(sizeof(*cbind));
574 perror("malloc() failed");
577 cbind->botid = botid;
578 cbind->cmd = strdup(cmd);
579 cbind->func = cmdfunc;
580 cbind->next = cmd_binds[bind_index];
581 cbind->paramcount = 0;
582 cbind->global_access = 0;
583 cbind->channel_access = NULL;
585 cmd_binds[bind_index] = cbind;
589 int unbind_cmd(int botid, char *cmd) {
590 int bind_index = get_binds_index(cmd[0]);
591 struct cmd_binding *cbind, *last = NULL;
592 for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
593 if(cbind->botid == botid && strcmp(cbind->cmd, cmd) == 0) {
595 last->next = cbind->next;
597 cmd_binds[bind_index] = cbind->next;
599 if(cbind->paramcount) {
601 for(i = 0; i < cbind->paramcount; i++)
602 free(cbind->parameters[i]);
612 struct cmd_function *find_cmd_function(int botid, char *name) {
613 struct cmd_function *cmdfunc;
615 if((c = strstr(name, "."))) {
617 struct cmd_bot_alias *botalias;
618 for(botalias = bot_aliases; botalias; botalias = botalias->next) {
619 if(!stricmp(botalias->alias, name)) {
620 botid = botalias->botid;
627 for(cmdfunc = cmd_functions; cmdfunc; cmdfunc = cmdfunc->next) {
628 if((cmdfunc->botid == botid || cmdfunc->botid == 0) && stricmp(cmdfunc->name, name) == 0)
634 struct ClientSocket *getTextBot() {
635 return tmp_text_client;
639 cmd_binds = calloc(27, sizeof(*cmd_binds));
640 bind_chanmsg(got_chanmsg);
641 bind_privmsg(got_privmsg);
642 register_default_language_table(msgtab);
647 for(i = 0; i < 27; i++) {
648 struct cmd_binding *cbind, *next;
649 for(cbind = cmd_binds[i]; cbind; cbind = next) {
652 if(cbind->paramcount) {
654 for(j = 0; j < cbind->paramcount; j++)
655 free(cbind->parameters[j]);
657 if(cbind->channel_access)
658 free(cbind->channel_access);
663 struct cmd_function *cmdfunct, *next;
664 for(cmdfunct = cmd_functions; cmdfunct; cmdfunct = next) {
665 next = cmdfunct->next;
666 free(cmdfunct->name);
669 struct trigger_callback *cb, *next_cb;
670 for(cb = trigger_callbacks; cb; cb = next_cb) {
674 struct cmd_bot_alias *botalias, *next_botalias;
675 for(botalias = bot_aliases; botalias; botalias = next_botalias) {
676 next_botalias = botalias->next;
677 free(botalias->alias);
680 cmd_functions = NULL;
681 trigger_callbacks = NULL;
685 void bind_set_parameters(int botid, char *cmd, char *parameters) {
686 int bind_index = get_binds_index(cmd[0]);
687 struct cmd_binding *cbind;
688 for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
689 if(cbind->botid == botid && strcmp(cbind->cmd, cmd) == 0) {
690 if(cbind->paramcount) {
692 for(i = 0; i < cbind->paramcount; i++)
693 free(cbind->parameters[i]);
694 cbind->paramcount = 0;
696 char *a, *b = parameters;
700 cbind->parameters[cbind->paramcount++] = strdup(b);
708 void bind_set_global_access(int botid, char *cmd, int gaccess) {
709 int bind_index = get_binds_index(cmd[0]);
710 struct cmd_binding *cbind;
711 for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
712 if(cbind->botid == botid && strcmp(cbind->cmd, cmd) == 0) {
714 cbind->global_access = gaccess;
715 cbind->flags |= CMDFLAG_OVERRIDE_GLOBAL_ACCESS;
717 cbind->flags &= ~CMDFLAG_OVERRIDE_GLOBAL_ACCESS;
724 void bind_set_channel_access(int botid, char *cmd, char *chanaccess) {
725 int bind_index = get_binds_index(cmd[0]);
726 struct cmd_binding *cbind;
727 for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
728 if(cbind->botid == botid && strcmp(cbind->cmd, cmd) == 0) {
729 if(cbind->channel_access)
730 free(cbind->channel_access);
732 cbind->channel_access = strdup(chanaccess);
733 cbind->flags |= CMDFLAG_OVERRIDE_CHANNEL_ACCESS;
735 cbind->channel_access = NULL;
736 cbind->flags &= ~CMDFLAG_OVERRIDE_CHANNEL_ACCESS;
743 struct cmd_binding *find_cmd_binding(int botid, char *cmd) {
744 int bind_index = get_binds_index(cmd[0]);
745 struct cmd_binding *cbind;
746 for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
747 if(cbind->botid == botid && strcmp(cbind->cmd, cmd) == 0) {
754 void bind_unbound_required_functions(int botid) {
755 struct cmd_function *cmdfunc;
757 struct cmd_binding *cbind;
758 for(cmdfunc = cmd_functions; cmdfunc; cmdfunc = cmdfunc->next) {
759 if((cmdfunc->flags & CMDFLAG_REQUIRED)) {
761 for(i = 0; i < 27; i++) {
762 for(cbind = cmd_binds[i]; cbind; cbind = cbind->next) {
763 if(cbind->botid == botid && cbind->func == cmdfunc) {
771 if(!found && bind_cmd_to_function(botid, cmdfunc->name, cmdfunc)) {
772 cbind = find_cmd_binding(botid, cmdfunc->name);
773 cbind->flags |= CMDFLAG_TEMPONARY_BIND;
779 void register_command_alias(int botid, char *alias) {
780 struct cmd_bot_alias *botalias;
781 for(botalias = bot_aliases; botalias; botalias = botalias->next) {
782 if(!stricmp(botalias->alias, alias))
785 botalias = malloc(sizeof(*botalias));
787 perror("malloc() failed");
790 botalias->botid = botid;
791 botalias->alias = strdup(alias);
792 botalias->next = bot_aliases;
793 bot_aliases = botalias;
796 struct cmd_binding *getAllBinds(struct cmd_binding *last) {
801 bind_index = get_binds_index(last->cmd[0]) + 1;
807 if(cmd_binds[bind_index])
808 return cmd_binds[bind_index];
810 } while(bind_index < 27);