connect_socket(client);
}
- printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access` FROM `bot_binds` WHERE `botclass` = '%d'", BOTID);
+ printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access`, `flags` FROM `bot_binds` WHERE `botclass` = '%d'", BOTID);
res2 = mysql_use();
while ((row = mysql_fetch_row(res2)) != NULL) {
if(bind_cmd_to_command(BOTID, row[0], row[1])) {
if(row[4]) {
bind_set_channel_access(BOTID, row[0], row[4]);
}
+ if(strcmp(row[5], "0"))
+ bind_set_bind_flags(BOTID, row[0], atoi(row[5]));
}
}
bind_unbound_required_functions(BOTID);
connect_socket(client);
}
- printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access` FROM `bot_binds` WHERE `botclass` = '%d'", BOTID);
+ printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access`, `flags` FROM `bot_binds` WHERE `botclass` = '%d'", BOTID);
res2 = mysql_use();
while ((row = mysql_fetch_row(res2)) != NULL) {
if(bind_cmd_to_command(BOTID, row[0], row[1])) {
if(row[4]) {
bind_set_channel_access(BOTID, row[0], row[4]);
}
+ if(strcmp(row[5], "0"))
+ bind_set_bind_flags(BOTID, row[0], atoi(row[5]));
}
}
bind_unbound_required_functions(BOTID);
{"NS_MODCMD_SETTING", "$b%s$b is an unknown modcmd setting."}, /* {ARGS: "strangeSetting"} */
{"NS_MODCMD_HEADER", "$bSettings for command %s:$b"}, /* {ARGS: "access"} */
{"NS_MODCMD_OUTRANKED", "$b%s$b outranks you. (required access: %d)"}, /* {ARGS: "die", 1000} */
+ {"NS_MODCMD_STATIC_FLAG", "This Flag is added statically. It can't be modified manually."},
{NULL, NULL}
};
connect_socket(client);
}
- printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access` FROM `bot_binds` WHERE `botclass` = '%d'", BOTID);
+ printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access`, `flags` FROM `bot_binds` WHERE `botclass` = '%d'", BOTID);
res2 = mysql_use();
while ((row = mysql_fetch_row(res2)) != NULL) {
if(bind_cmd_to_command(BOTID, row[0], row[1])) {
if(row[4]) {
bind_set_channel_access(BOTID, row[0], row[4]);
}
+ if(strcmp(row[5], "0"))
+ bind_set_bind_flags(BOTID, row[0], atoi(row[5]));
}
}
bind_unbound_required_functions(BOTID);
connect_socket(client);
}
- printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access` FROM `bot_binds` WHERE `botclass` = '%d'", BOTID);
+ printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access`, `flags` FROM `bot_binds` WHERE `botclass` = '%d'", BOTID);
res2 = mysql_use();
while ((row = mysql_fetch_row(res2)) != NULL) {
if(bind_cmd_to_command(BOTID, row[0], row[1])) {
if(row[4]) {
bind_set_channel_access(BOTID, row[0], row[4]);
}
+ if(strcmp(row[5], "0"))
+ bind_set_bind_flags(BOTID, row[0], atoi(row[5]));
}
}
bind_unbound_required_functions(BOTID);
client->clientid = atoi(row[7]);
connect_socket(client);
- printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access` FROM `bot_binds` WHERE `botclass` = '0' AND `botid` = '%d'", client->clientid);
+ printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access`, `chan_access`, `flags` FROM `bot_binds` WHERE `botclass` = '0' AND `botid` = '%d'", client->clientid);
res2 = mysql_use();
while ((row = mysql_fetch_row(res2)) != NULL) {
if(bind_botwise_cmd_to_command(0, client->clientid, row[0], row[1])) {
if(row[4]) {
bind_botwise_set_channel_access(0, client->clientid, row[0], row[4]);
}
+ if(strcmp(row[5], "0"))
+ bind_botwise_set_bind_flags(0, client->clientid, row[0], atoi(row[5]));
}
}
bind_botwise_unbound_required_functions(0, client->clientid);
*/
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);
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]);
}
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);
}
}
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;
+ 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);
+ }
+ 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, cbind->clientid, escape_string(cbind->cmd));
+ else
+ printf_mysql_query("UPDATE `bot_binds` SET `flags` = '%u' WHERE `botclass` = '%d' AND `command` = '%s'", cbind->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;
statistics_commands++;
total_triggered++;
cbind->triggered++;
- if((cbind->func->flags & CMDFLAG_FUNCMD)) {
+ if((BIND_FLAGS(cbind) & CMDFLAG_FUNCMD)) {
if(!sent_chan)
break;
chan = sent_chan;
if (argc >= MAXNUMPARAMS)
break;
while ((escape || *args != ' ') && *args) {
- if((cbind->func->flags & CMDFLAG_ESCAPE_ARGS) && *args == '\\') {
+ if((BIND_FLAGS(cbind) & CMDFLAG_ESCAPE_ARGS) && *args == '\\') {
escape = 1;
offset++;
} else if(escape)
}
}
argv = arga;
- if(argc != 0 && argv[0][0] == '#' && !(cbind->func->flags & CMDFLAG_CHAN_PARAM)) {
+ if(argc != 0 && argv[0][0] == '#' && !(BIND_FLAGS(cbind) & CMDFLAG_CHAN_PARAM)) {
struct ChanNode *chan2 = getChanByName(argv[0]);
if(chan2) {
argv += 1;
}
args_pos++;
}
- } else if((cbind->func->flags & CMDFLAG_EMPTY_ARGS)) {
+ } else if((BIND_FLAGS(cbind) & CMDFLAG_EMPTY_ARGS)) {
uargs[uargc++] = args_buffer + args_pos;
args_buffer[args_pos++] = '\0';
} else if(c) {
reply(tmp_text_client, user, "MODCMD_LESS_PARAM_COUNT");
break;
}
- if((cbind->func->flags & CMDFLAG_REQUIRE_CHAN) && !chan) {
+ if((BIND_FLAGS(cbind) & CMDFLAG_REQUIRE_CHAN) && !chan) {
reply(tmp_text_client, user, "MODCMD_CHAN_REQUIRED");
break;
}
- if(((cbind->func->flags & CMDFLAG_CHECK_AUTH) || (chan && chan != sent_chan && !isUserOnChan(user, chan))) && !(user->flags & USERFLAG_ISAUTHED)) {
+ if(((BIND_FLAGS(cbind) & 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_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)) {
+ int eventflags = (BIND_FLAGS(cbind) & (CMDFLAG_LOG | CMDFLAG_OPLOG));
+ if((BIND_FLAGS(cbind) & CMDFLAG_REQUIRE_AUTH) && !(user->flags & USERFLAG_ISAUTHED)) {
reply(tmp_text_client, user, "MODCMD_AUTH_REQUIRED");
return;
}
return;
}
}
- if((cbind->func->flags & CMDFLAG_REGISTERED_CHAN)) {
+ if((BIND_FLAGS(cbind) & CMDFLAG_REGISTERED_CHAN)) {
MYSQL_ROW defaults = NULL;
char access_list[256];
int access_pos = 0;
return;
}
}
- if((cbind->func->flags & CMDFLAG_REQUIRE_GOD) && !isGodMode(user)) {
+ if((BIND_FLAGS(cbind) & CMDFLAG_REQUIRE_GOD) && !isGodMode(user)) {
reply(tmp_text_client, user, "MODCMD_PRIVILEGED", cbind->cmd);
return;
}
}
}
+void bind_botwise_set_bind_flags(int botid, int clientid, char *cmd, unsigned int flags) {
+ 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 && (botid || clientid == cbind->clientid) && strcmp(cbind->cmd, cmd) == 0) {
+ cbind->flags |= flags;
+ return;
+ }
+ }
+}
+
struct cmd_binding *find_botwise_cmd_binding(int botid, int clientid, char *cmd) {
int bind_index = get_binds_index(cmd[0]);
struct cmd_binding *cbind;
struct cmd_binding *next;
};
+#define BIND_FLAGS(BIND) (BIND->flags | BIND->func->flags)
+
struct trigger_cache {
int botid;
int clientid;
#define bind_set_channel_access(BOTID,CMD,CACCESS) bind_botwise_set_channel_access(BOTID, 0, CMD, CACCESS)
void bind_botwise_set_channel_access(int botid, int clientid, char *cmd, char *chanaccess);
+#define bind_set_bind_flags(BOTID,CMD,FLAGS) bind_botwise_set_bind_flags(BOTID, 0, CMD, FLAGS)
+void bind_botwise_set_bind_flags(int botid, int clientid, char *cmd, unsigned int flags);
+
#define find_cmd_binding(BOTID,CMD) find_botwise_cmd_binding(BOTID, 0, CMD)
struct cmd_binding *find_botwise_cmd_binding(int botid, int clientid, char *cmd);