X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=modcmd.c;h=5476d5e00a9798fff30610f4f01c2f5f70a4465c;hb=795115bf680185ae01043bd1222b78bfed8c1d87;hp=c3868ea7e8fb138fb17c50404d2caa2c29ee4569;hpb=a10a047c4b8414ecc8d20ee8e48854e3e9e4c5f7;p=NeonServV5.git diff --git a/modcmd.c b/modcmd.c index c3868ea..5476d5e 100644 --- a/modcmd.c +++ b/modcmd.c @@ -36,10 +36,11 @@ static struct ClientSocket *tmp_text_client; static const struct default_language_entry msgtab[] = { {"MODCMD_LESS_PARAM_COUNT", "This command requires more parameters."}, - {"MODCMD_CHAN_REQUIRED", "You must provide the name of a channel that exists."}, + {"MODCMD_CHAN_REQUIRED", "You must provide the name of a channel that exists and the bot is on."}, {"MODCMD_AUTH_REQUIRED", "You need to be authenticated with AuthServ to use this command."}, - {"MODCMD_PRIVILEGED", "\002%s\002 is a privileged command."}, - {"MODCMD_PUBCMD", "Public commands in \002%s\002 are restricted."}, + {"MODCMD_CHAN_SUSPENDED", "This channel is currently suspended."}, + {"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."}, {NULL, NULL} }; @@ -149,41 +150,47 @@ static void handle_command(struct ClientSocket *client, struct UserNode *user, s } if(cbind->parameters) { //userdefined parameters... - char *uarga[MAXNUMPARAMS]; - char params[strlen(cbind->parameters)+1]; - strcpy(params, cbind->parameters); - int uargpos = 0, argi, allargs = 0; - char *ppos = params; - char *prev_ppos = params; - while((ppos = strstr(ppos, " "))) { - *ppos = '\0'; - if(prev_ppos[0] == '%') { - prev_ppos++; - if(prev_ppos[strlen(prev_ppos)-1] == '-') { + char *uargs[MAXNUMPARAMS]; + int uargc = 0; + char *a,*b = cbind->parameters; + int allargs, argi; + do { + a = strstr(b, " "); + if(a) *a = '\0'; + if(b[0] == '%') { + b++; + if(b[strlen(b)-1] == '-') { allargs = 1; - prev_ppos[strlen(prev_ppos)-1] = '\0'; - } else + b[strlen(b)-1] = '\0'; + argi = atoi(b); + b[strlen(b)-1] = '-'; + } else { allargs = 0; - argi = atoi(prev_ppos); + argi = atoi(b); + } if(argi > 0) { - if(argi <= argc) continue; - uarga[uargpos++] = argv[argi-1]; - if(allargs) { - for(;argi < argc; argi++) - uarga[uargpos++] = argv[argi-1]; + if(argi <= argc) { + uargs[uargc++] = argv[argi-1]; + if(allargs) { + for(argi++; argi <= argc; argi++) + uargs[uargc++] = argv[argi-1]; + } } - } else if(!strcmp(prev_ppos, "c")) - uarga[uargpos++] = (chan ? chan->name : NULL); - else if(!strcmp(prev_ppos, "n")) - uarga[uargpos++] = user->nick; + } else if(!strcmp(b, "c")) { + uargs[uargc++] = (chan ? chan->name : NULL); + } else if(!strcmp(b, "n")) { + uargs[uargc++] = user->nick; + } } else { - uarga[uargpos++] = prev_ppos; + uargs[uargc++] = b; } - ppos++; - prev_ppos = ppos; - } - argv = uarga; - argc = uargpos; + if(a) { + *a = ' '; + b = a+1; + } + } while(a); + argv = uargs; + argc = uargc; } if(argc < cbind->func->paramcount) { reply(tmp_text_client, user, "MODCMD_LESS_PARAM_COUNT"); @@ -339,11 +346,14 @@ static void handle_command_async(struct ClientSocket *client, struct UserNode *u reply(tmp_text_client, user, "MODCMD_CHAN_REQUIRED"); return; } - printf_mysql_query("SELECT `botid` FROM `bot_channels` LEFT JOIN `bots` ON `bot_channels`.`botid` = `bots`.`id` WHERE `chanid` = '%d' AND `botclass` = '%d'", chan->channel_id, client->botid); + 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); res = mysql_use(); if ((row = mysql_fetch_row(res)) == NULL) { reply(tmp_text_client, user, "MODCMD_CHAN_REQUIRED"); return; + } else if(!strcmp(row[1], "1")) { + reply(tmp_text_client, user, "MODCMD_CHAN_SUSPENDED"); + return; } } if((cbind->func->flags & CMDFLAG_REQUIRE_GOD) && !isGodMode(user)) { @@ -388,7 +398,7 @@ static void got_privmsg(struct UserNode *user, struct UserNode *target, char *me } } -int register_command(int botid, char *name, cmd_bind_t *func, int paramcount, unsigned int flags, char *channel_access, int global_access) { +int register_command(int botid, char *name, cmd_bind_t *func, int paramcount, char *channel_access, int global_access, unsigned int flags) { struct cmd_function *cmdfunc; for(cmdfunc = cmd_functions; cmdfunc; cmdfunc = cmdfunc->next) { if(cmdfunc->botid == botid && strcmp(cmdfunc->name, name) == 0) @@ -517,6 +527,15 @@ int unbind_cmd(int botid, char *cmd) { return 0; } +struct cmd_function *find_cmd_function(int botid, char *name) { + struct cmd_function *cmdfunc; + for(cmdfunc = cmd_functions; cmdfunc; cmdfunc = cmdfunc->next) { + if(cmdfunc->botid == botid && stricmp(cmdfunc->name, name) == 0) + break; + } + return cmdfunc; +} + struct ClientSocket *getTextBot() { return tmp_text_client; } @@ -605,3 +624,15 @@ void bind_set_channel_access(int botid, char *cmd, char *chanaccess) { } } } + +struct cmd_binding *find_cmd_binding(int botid, char *cmd) { + int bind_index = get_binds_index(cmd[0]); + struct cmd_binding *cbind; + for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) { + if(cbind->botid == botid && strcmp(cbind->cmd, cmd) == 0) { + return cbind; + } + } + return NULL; +} +