X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=src%2Fcmd_global_modcmd.c;h=cc242f94a66096e55a60e88298c20df01901662d;hb=bb5692b9cbff069abbf9573c81e86c3cd2061ceb;hp=7a3b80bcc7f222f6e94d7d9a921a657af2047b53;hpb=be17e22b842b7b831694422b204777c93fd478bb;p=NeonServV5.git diff --git a/src/cmd_global_modcmd.c b/src/cmd_global_modcmd.c index 7a3b80b..cc242f9 100644 --- a/src/cmd_global_modcmd.c +++ b/src/cmd_global_modcmd.c @@ -1,5 +1,5 @@ /* cmd_global_modcmd.c - NeonServ v5.3 - * Copyright (C) 2011 Philipp Kreil (pk910) + * Copyright (C) 2011-2012 Philipp Kreil (pk910) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,6 +24,7 @@ */ static int global_cmd_modcmd_params(struct UserNode *user, struct cmd_binding *cbind, char *value); +static int global_cmd_modcmd_flags(struct UserNode *user, struct cmd_binding *cbind, char *value); static int global_cmd_modcmd_caccess(struct UserNode *user, struct cmd_binding *cbind, char *value); static int global_cmd_modcmd_oaccess(struct UserNode *user, struct cmd_binding *cbind, char *value); @@ -56,6 +57,7 @@ CMD_BIND(global_cmd_modcmd) { if(!stricmp(argv[1], "caccess")) log_event = global_cmd_modcmd_caccess(user, cbind, value); else if(!stricmp(argv[1], "oaccess")) log_event = global_cmd_modcmd_oaccess(user, cbind, value); else if(!stricmp(argv[1], "parameters")) log_event = global_cmd_modcmd_params(user, cbind, value); + else if(!stricmp(argv[1], "flags")) log_event = global_cmd_modcmd_flags(user, cbind, value); else { reply(getTextBot(), user, "NS_MODCMD_SETTING", argv[1]); } @@ -67,6 +69,7 @@ CMD_BIND(global_cmd_modcmd) { global_cmd_modcmd_params(user, cbind, NULL); global_cmd_modcmd_caccess(user, cbind, NULL); global_cmd_modcmd_oaccess(user, cbind, NULL); + global_cmd_modcmd_flags(user, cbind, NULL); } } @@ -95,6 +98,83 @@ static int global_cmd_modcmd_params(struct UserNode *user, struct cmd_binding *c return ret; } +static const struct { + const char *name; + unsigned int flag; +} global_cmd_modcmd_show_flags[] = { + {"REQUIRE_CHAN", CMDFLAG_REQUIRE_CHAN}, //The command requires a valid channel (at least one bot in it) + {"REQUIRE_AUTH", CMDFLAG_REQUIRE_AUTH}, //The command requires the user to be authenticated + {"REQUIRE_GOD", CMDFLAG_REQUIRE_GOD}, //The command requires the user to have security override enabled + {"REQUIRE_REGISTERED", CMDFLAG_REGISTERED_CHAN}, //The command requires the channel to be registered (database entry) + {"CHECK_AUTH", CMDFLAG_CHECK_AUTH}, //WHO the user if no auth is known, yet + {"CHANNEL_ARGS", CMDFLAG_CHAN_PARAM}, //don't interpret channel arguments as channel - just pass them as a string + {"LOG", CMDFLAG_LOG}, + {"OPLOG", CMDFLAG_OPLOG}, + {"FUNCMD", CMDFLAG_FUNCMD}, + {"ESCAPED_ARGS", CMDFLAG_ESCAPE_ARGS}, //allows arguments to be escaped ("a\ b" = "a b" as one argument) + {NULL, 0} +}; + +static int global_cmd_modcmd_flags(struct UserNode *user, struct cmd_binding *cbind, char *value) { + char flags[MAXLEN]; + int flagpos = 0; + int ret = 0; + unsigned int visible_flags = 0; + int i = 0; + while(global_cmd_modcmd_show_flags[i].name) { + if(cbind->func->flags & global_cmd_modcmd_show_flags[i].flag) { + flagpos += sprintf(flags + flagpos, (flagpos ? " %s" : "\00314%s"), global_cmd_modcmd_show_flags[i].name); + } + visible_flags |= global_cmd_modcmd_show_flags[i].flag; + i++; + } + if(flagpos) + flags[flagpos++] = '\003'; + if(value) { + int add = 1; + unsigned int current_flag = 0; + if(value[0] == '+') { + value++; + } else if(value[0] == '-') { + add = 0; + value++; + } + if(*value) { + i = 0; + while(global_cmd_modcmd_show_flags[i].name) { + if(!stricmp(global_cmd_modcmd_show_flags[i].name, value)) { + current_flag = global_cmd_modcmd_show_flags[i].flag; + break; + } + i++; + } + } + if(cbind->func->flags & current_flag) { + reply(getTextBot(), user, "NS_MODCMD_STATIC_FLAG"); + return 0; + } + if(add) + cbind->flags |= current_flag; + else + cbind->flags &= ~current_flag; + if(cbind->botid == 0) + printf_mysql_query("UPDATE `bot_binds` SET `flags` = '%u' WHERE `botclass` = '0' AND `botid` = '%d' AND `command` = '%s'", (cbind->flags & visible_flags), cbind->clientid, escape_string(cbind->cmd)); + else + printf_mysql_query("UPDATE `bot_binds` SET `flags` = '%u' WHERE `botclass` = '%d' AND `command` = '%s'", (cbind->flags & visible_flags), cbind->botid, escape_string(cbind->cmd)); + ret = 1; + } + i = 0; + while(global_cmd_modcmd_show_flags[i].name) { + if(cbind->flags & global_cmd_modcmd_show_flags[i].flag) { + flagpos += sprintf(flags + flagpos, (flagpos ? " %s" : "%s"), global_cmd_modcmd_show_flags[i].name); + } + i++; + } + flags[flagpos] = '\0'; + reply(getTextBot(), user, "\002FLAGS \002 %s", flags); + return ret; +} + static int global_cmd_modcmd_caccess(struct UserNode *user, struct cmd_binding *cbind, char *value) { char caccess[MAXLEN]; int ret = 0;