-/* modcmd.c - NeonServ v5.2
+/* modcmd.c - NeonServ v5.3
* Copyright (C) 2011 Philipp Kreil (pk910)
*
* This program is free software: you can redistribute it and/or modify
{"MODCMD_ACCESS_DENIED", "Access denied."},
{"MODCMD_SUBCOMMANDS", "Subcommands of %s: %s"}, /* {ARGS: "bot", "ADD, DEL, EDIT"} */
{"MODCMD_CROSSCHAN", "You must be in %s (or on its userlist) to use this command."},
+ {"MODCMD_UNKNOWN", "$b%s$b is an unknown command."}, /* {ARGS: "bla"} */
{NULL, NULL}
};
args++;
}
struct cmd_binding *cbind;
+ int found_cmd = 0;
for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
if(cbind->botid == client->botid && (cbind->botid || cbind->clientid == client->clientid) && stricmp(cbind->cmd, message) == 0) {
+ found_cmd = 1;
+ //get a text bot
+ tmp_text_client = get_botwise_prefered_bot(client->botid, (client->botid == 0 ? client->clientid : 0));
if(cbind->func->func == modcmd_linker) {
//links subcommands
char command[MAXLEN];
subcompos += sprintf(subcommands + subcompos, (subcompos ? ", %s" : "%s"), cbind->cmd + commandlen);
}
}
- reply(tmp_text_client, user, "MODCMD_SUBCOMMANDS", parent_bind->cmd, subcommands);
+ reply(tmp_text_client, user, "MODCMD_SUBCOMMANDS", parent_bind->cmd, (subcompos ? subcommands : "\1dnone\1d"));
break;
}
}
break;
chan = sent_chan;
}
- //get a text bot
- tmp_text_client = get_botwise_prefered_bot(client->botid, (client->botid == 0 ? client->clientid : 0));
//parse the arguments...
char *arga[MAXNUMPARAMS];
char **argv;
int args_pos = 0;
char *uargs[MAXNUMPARAMS];
int uargc = 0;
- char *b;
+ char *b, *c;
int i;
int allargs, argi;
for(i = 0; i < cbind->paramcount; i++) {
b = cbind->parameters[i];
if(b[0] == '%') {
b++;
+ c = b;
+ while(*c && *c != ' ') {
+ if(*c == '|') break;
+ c++;
+ }
+ if(!*c || *c == ' ') c = NULL;
+ else {
+ *c = '\0';
+ c++;
+ }
if(b[strlen(b)-1] == '-') {
allargs = strlen(b)-1;
b[allargs] = '\0';
} else if((cbind->func->flags & CMDFLAG_EMPTY_ARGS)) {
uargs[uargc++] = args_buffer + args_pos;
args_buffer[args_pos++] = '\0';
+ } else if(c) {
+ uargs[uargc++] = args_buffer + args_pos;
+ args_pos += sprintf(args_buffer + args_pos, "%s", c) + 1;
}
} else if(!strcmp(b, "c")) {
uargs[uargc++] = args_buffer + args_pos;
uargs[uargc++] = args_buffer + args_pos;
args_pos += sprintf(args_buffer + args_pos, "%s", user->nick) + 1;
}
+ if(c) c[-1] = '|'; //reset \0 to |
} else {
uargs[uargc++] = args_buffer + args_pos;
args_pos += sprintf(args_buffer + args_pos, "%s", b) + 1;
break;
}
}
+ if(!found_cmd && !sent_chan)
+ reply(get_botwise_prefered_bot(client->botid, (client->botid == 0 ? client->clientid : 0)), user, "MODCMD_UNKNOWN", message);
free(message);
if(args_buffer)
free(args_buffer);
struct ClientSocket *client;
FD_ZERO(&fds);
FD_ZERO(&fds2);
+ got_chanmsg_loop1:
for(client = getBots(SOCKET_FLAG_READY, NULL); client; client = getBots(SOCKET_FLAG_READY, client)) {
if(isUserOnChan(client->user, chan) && (client->flags & SOCKET_FLAG_PREFERRED) && ((client->botid == 0 && !FD_ISSET(client->clientid, &fds)) || (client->botid && !FD_ISSET(client->botid, &fds2)))) {
FD_SET(client->clientid, &fds);
trigger = get_channel_trigger(client->botid, client->clientid, chan);
if(trigger && stricmplen(message, trigger, strlen(trigger)) == 0) {
handle_command(client, user, chan, message + strlen(trigger));
+ goto got_chanmsg_loop1; //Thats really really bad, i know... But we can't count on the "getBots" list anymore after executing a command
}
}
}
+ got_chanmsg_loop2:
for(client = getBots(SOCKET_FLAG_READY, NULL); client; client = getBots(SOCKET_FLAG_READY, client)) {
if(isUserOnChan(client->user, chan) && ((client->botid == 0 && !FD_ISSET(client->clientid, &fds)) || (client->botid && !FD_ISSET(client->botid, &fds2)))) {
- FD_SET(client->botid, &fds);
+ FD_SET(client->clientid, &fds);
FD_SET(client->botid, &fds2);
trigger = get_channel_trigger(client->botid, client->clientid, chan);
if(trigger && stricmplen(message, trigger, strlen(trigger)) == 0) {
handle_command(client, user, chan, message + strlen(trigger));
+ goto got_chanmsg_loop2; //Thats really really bad, i know... But we can't count on the "getBots" list anymore after executing a command
}
}
}
for(i = 0; i < cbind->paramcount; i++)
free(cbind->parameters[i]);
}
+ if(cbind->channel_access)
+ free(cbind->channel_access);
free(cbind);
return 1;
} else
return 0;
}
+int unbind_botwise_allcmd(int clientid) {
+ int i;
+ for(i = 0; i < 27; i++) {
+ struct cmd_binding *cbind, *next, *last = NULL;
+ for(cbind = cmd_binds[i]; cbind; cbind = next) {
+ next = cbind->next;
+ if(clientid == cbind->clientid) {
+ if(last)
+ last->next = cbind->next;
+ else
+ cmd_binds[i] = cbind->next;
+ free(cbind->cmd);
+ if(cbind->paramcount) {
+ int j;
+ for(j = 0; j < cbind->paramcount; j++)
+ free(cbind->parameters[j]);
+ }
+ if(cbind->channel_access)
+ free(cbind->channel_access);
+ free(cbind);
+ } else
+ last = cbind;
+ }
+ }
+ return 1;
+}
+
struct cmd_function *find_cmd_function(int botid, char *name) {
struct cmd_function *cmdfunc;
char *c;