-/* modcmd.c - NeonServ v5.3
+/* modcmd.c - NeonServ v5.4
* Copyright (C) 2011-2012 Philipp Kreil (pk910)
*
* This program is free software: you can redistribute it and/or modify
struct trigger_callback {
int botid;
+ int module_id;
trigger_callback_t *func;
struct trigger_callback *next;
static USERAUTH_CALLBACK(command_checked_auth) {
struct command_check_user_cache *cache = data;
tmp_text_client = cache->textclient;
- handle_command_async(cache->client, user, cache->chan, cache->sent_chan, cache->cbind, cache->argv, cache->argc);
+ if(user)
+ handle_command_async(cache->client, user, cache->chan, cache->sent_chan, cache->cbind, cache->argv, cache->argc);
free(cache->message);
if(cache->args_buffer)
free(cache->args_buffer);
data->args_buffer = args_buffer;
data->cbind = cbind;
data->textclient = tmp_text_client;
- get_userauth(user, command_checked_auth, data);
+ get_userauth(user, 0, command_checked_auth, data);
return;
} else
handle_command_async(client, user, chan, sent_chan, cbind, argv, argc);
}
}
-int register_command(int botid, char *name, cmd_bind_t *func, int paramcount, char *channel_access, int global_access, unsigned int flags) {
+int register_command(int botid, char *name, int module_id, 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 || cmdfunc->botid == 0) && strcmp(cmdfunc->name, name) == 0)
}
cmdfunc->botid = botid;
cmdfunc->name = strdup(name);
+ cmdfunc->module_id = module_id;
cmdfunc->func = func;
cmdfunc->flags = flags;
cmdfunc->paramcount = paramcount;
return 1;
}
-int set_trigger_callback(int botid, trigger_callback_t *func) {
+int set_trigger_callback(int botid, int module_id, trigger_callback_t *func) {
static struct trigger_callback *cb = NULL;
for(cb = trigger_callbacks; cb; cb = cb->next) {
if(cb->botid == botid)
cb->next = trigger_callbacks;
trigger_callbacks = cb;
}
+ cb->module_id = module_id;
cb->func = func;
return 1;
}
return 0;
}
-int unbind_botwise_allcmd(int clientid) {
+int unbind_botwise_allcmd(int botid, 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((botid == 0 && clientid == cbind->clientid) || (botid && botid == cbind->botid)) {
if(last)
last->next = cbind->next;
else
void init_modcmd() {
cmd_binds = calloc(27, sizeof(*cmd_binds));
- bind_chanmsg(got_chanmsg);
- bind_privmsg(got_privmsg);
+ bind_chanmsg(got_chanmsg, 0);
+ bind_privmsg(got_privmsg, 0);
register_default_language_table(msgtab);
- register_command(0, "linker", modcmd_linker, 0, 0, 0, 0); //fake command for subcommands
+ register_command(0, "linker", 0, modcmd_linker, 0, 0, 0, 0); //fake command for subcommands
}
void free_modcmd() {
} while(bind_index < 27);
return NULL;
}
+
+void unregister_module_commands(int module_id) {
+ struct cmd_function *cmdfunct, *nextfunct, *prevfunct = NULL;
+ int i;
+ for(cmdfunct = cmd_functions; cmdfunct; cmdfunct = nextfunct) {
+ nextfunct = cmdfunct->next;
+ if(cmdfunct->module_id == module_id) {
+ 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(cmdfunct == cbind->func) {
+ 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;
+ }
+ }
+ if(prevfunct)
+ prevfunct->next = nextfunct;
+ else
+ cmd_functions = nextfunct;
+ free(cmdfunct->name);
+ free(cmdfunct);
+ } else
+ prevfunct = cmdfunct;
+ }
+ struct trigger_callback *cb, *prevcb = NULL, *nextcb;
+ for(cb = trigger_callbacks; cb; cb = nextcb) {
+ nextcb = cb->next;
+ if(cb->module_id == module_id) {
+ if(prevcb)
+ prevcb->next = nextcb;
+ else
+ trigger_callbacks = nextcb;
+ free(cb);
+ } else
+ prevcb = cb;
+ }
+}