{"MODCMD_PRIVILEGED", "$b%s$b is a privileged command."}, /* {ARGS: "god"} */
{"MODCMD_PUBCMD", "Public commands in $b%s$b are restricted."}, /* {ARGS: "#TestChan"} */
{"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."},
{NULL, NULL}
};
free(cache);
}
+static CMD_BIND(modcmd_linker) {
+ //fake command for subcommands
+ //just empty
+}
+
static void handle_command(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, char *message) {
struct ChanNode *sent_chan = chan;
if(message[0] == '#') {
struct cmd_binding *cbind;
for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
if(cbind->botid == client->botid && stricmp(cbind->cmd, message) == 0) {
+ if(cbind->func->func == modcmd_linker) {
+ //links subcommands
+ char command[MAXLEN];
+ struct cmd_binding *parent_bind = cbind;
+ if(args) {
+ char *subcmd = args;
+ args = strstr(args, " ");
+ if(args) {
+ *args = '\0';
+ args++;
+ }
+ sprintf(command, "%s %s", parent_bind->cmd, subcmd);
+ for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
+ if(cbind->botid == client->botid && stricmp(cbind->cmd, command) == 0)
+ break;
+ }
+ if(!cbind)
+ break;
+ } else {
+ //list all sub commands
+ int commandlen = sprintf(command, "%s ", parent_bind->cmd);
+ char subcommands[MAXLEN];
+ int subcompos = 0;
+ for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
+ if(cbind->botid == client->botid && stricmplen(cbind->cmd, command, commandlen) == 0) {
+ subcompos += sprintf(subcommands + subcompos, (subcompos ? ", %s" : "%s"), cbind->cmd + commandlen);
+ }
+ }
+ reply(tmp_text_client, user, "MODCMD_SUBCOMMANDS", parent_bind->cmd, subcommands);
+ break;
+ }
+ }
if(statistics_enabled)
statistics_commands++;
total_triggered++;
- cbind->func->triggered++;
+ cbind->triggered++;
if((cbind->func->flags & CMDFLAG_FUNCMD)) {
if(!sent_chan)
break;
char *arga[MAXNUMPARAMS];
char **argv;
int argc = 0;
+ int escape = 0;
+ int offset = 0;
if(args) {
while(*args) {
//skip leading spaces
arga[argc++] = args;
if (argc >= MAXNUMPARAMS)
break;
- while (*args != ' ' && *args)
+ while ((escape || *args != ' ') && *args) {
+ if((cbind->func->flags & CMDFLAG_ESCAPE_ARGS) && *args == '\\') {
+ escape = 1;
+ offset++;
+ } else if(escape)
+ escape = 0;
+ if(!escape && offset) {
+ args[0 - offset] = args[0];
+ }
args++;
+
+ }
+ if(offset) {
+ args[0-offset] = '\0';
+ offset = 0;
+ }
}
}
argv = arga;
reply(tmp_text_client, user, "MODCMD_CHAN_REQUIRED");
break;
}
- if((cbind->func->flags & CMDFLAG_CHECK_AUTH) && !(user->flags & USERFLAG_ISAUTHED)) {
+ if(((cbind->func->flags & CMDFLAG_CHECK_AUTH) || (chan && chan != sent_chan && !isUserOnChan(user, chan))) && !(user->flags & USERFLAG_ISAUTHED)) {
//check auth...
struct command_check_user_cache *data = malloc(sizeof(*data));
char **temp_argv = malloc(argc*sizeof(*temp_argv));
MYSQL_RES *res;
MYSQL_ROW row;
int uaccess;
+ char requested_uaccess = 0;
int eventflags = (cbind->func->flags & (CMDFLAG_LOG | CMDFLAG_OPLOG));
if((cbind->func->flags & CMDFLAG_REQUIRE_AUTH) && !(user->flags & USERFLAG_ISAUTHED)) {
reply(tmp_text_client, user, "MODCMD_AUTH_REQUIRED");
return;
}
+ if(chan && sent_chan != chan && !isUserOnChan(user, chan)) {
+ char user_in_chan = 0;
+ if((user->flags & USERFLAG_ISAUTHED)) {
+ //maybe there's another user authed to user->auth on the channel...
+ struct ChanUser *cchanuser;
+ for(cchanuser = getChannelUsers(chan, NULL); cchanuser; cchanuser = getChannelUsers(chan, cchanuser)) {
+ if((cchanuser->user->flags & USERFLAG_ISAUTHED) && !stricmp(user->auth, cchanuser->user->auth)) {
+ user_in_chan = 1;
+ break;
+ }
+ }
+ }
+ if(!user_in_chan) {
+ //check if we are allowed to execute commands in this channel
+ requested_uaccess = 1;
+ uaccess = getChannelAccess(user, chan);
+ if(!uaccess) {
+ reply(tmp_text_client, user, "MODCMD_CROSSCHAN", chan->name);
+ return;
+ }
+ }
+ }
if(sent_chan && sent_chan != chan) {
//check pubcmd of this channel
printf_mysql_query("SELECT `channel_pubcmd` FROM `channels` WHERE `channel_name` = '%s'", escape_string(sent_chan->name));
res = mysql_use();
if ((row = mysql_fetch_row(res)) != NULL) {
- uaccess = getChannelAccess(user, sent_chan);
- if(row[0] && uaccess < atoi(row[0]) && !isGodMode(user)) { //NOTE: HARDCODED DEFAULT: pubcmd = 0
+ int saccess = getChannelAccess(user, sent_chan);
+ if(row[0] && saccess < atoi(row[0]) && !isGodMode(user)) { //NOTE: HARDCODED DEFAULT: pubcmd = 0
reply(tmp_text_client, user, "MODCMD_PUBCMD", sent_chan->name);
return;
}
chan->flags |= CHANFLAG_CHAN_REGISTERED;
chan->channel_id = atoi(row[0]);
if((sent_chan && sent_chan == chan) || access_count || minaccess) {
- uaccess = getChannelAccess(user, chan);
+ if(!requested_uaccess) uaccess = getChannelAccess(user, chan);
if(uaccess < minaccess && isGodMode(user)) {
eventflags |= CMDFLAG_OPLOG;
} else if(uaccess < minaccess) {
reply(tmp_text_client, user, "MODCMD_PRIVILEGED", cbind->cmd);
return;
}
- struct Event *event = createEvent(client, user, chan, cbind->func->name, argv, argc, eventflags);
+ struct Event *event = createEvent(client, user, chan, cbind, argv, argc, eventflags);
cbind->func->func(client, user, chan, argv, argc, event);
}
cmdfunc->paramcount = paramcount;
cmdfunc->channel_access = channel_access;
cmdfunc->global_access = global_access;
- cmdfunc->triggered = 0;
cmdfunc->next = cmd_functions;
cmd_functions = cmdfunc;
return 1;
cbind->global_access = 0;
cbind->channel_access = NULL;
cbind->flags = 0;
+ cbind->triggered = 0;
cbind->next = cmd_binds[bind_index];
cmd_binds[bind_index] = cbind;
return 1;
cbind->global_access = 0;
cbind->channel_access = NULL;
cbind->flags = 0;
+ cbind->triggered = 0;
cmd_binds[bind_index] = cbind;
return 1;
}
bind_chanmsg(got_chanmsg);
bind_privmsg(got_privmsg);
register_default_language_table(msgtab);
+ register_command(0, "linker", modcmd_linker, 0, 0, 0, 0); //fake command for subcommands
}
void free_modcmd() {