From 45171ce498f3a7d6637da6747e7d2c7e7949850d Mon Sep 17 00:00:00 2001 From: pk910 Date: Wed, 17 Aug 2011 05:15:19 +0200 Subject: [PATCH] moved cmds to extra files and loading binds from the database --- bot_NeonServ.c | 29 +++++++++++++---------------- cmd_neonserv_modes.c | 6 ++++++ cmd_neonserv_users.c | 8 ++++++++ modcmd.c | 10 ++++++++++ modcmd.h | 3 +++ 5 files changed, 40 insertions(+), 16 deletions(-) create mode 100644 cmd_neonserv_modes.c create mode 100644 cmd_neonserv_users.c diff --git a/bot_NeonServ.c b/bot_NeonServ.c index 1621d3c..7237bcf 100644 --- a/bot_NeonServ.c +++ b/bot_NeonServ.c @@ -16,19 +16,11 @@ static const struct default_language_entry msgtab[] = { {NULL, NULL} }; -static CMD_BIND(neonserv_cmd_users) { - struct ChanUser *chanuser; - putsock(client, "PRIVMSG %s :[BOT JOIN] Users on this Channel:", chan->name); - for(chanuser = getChannelUsers(chan, NULL); chanuser; chanuser = getChannelUsers(chan, chanuser)) { - putsock(client, "PRIVMSG %s : %s!%s@%s [%s] rights: %d", chan->name, chanuser->user->nick, chanuser->user->ident, chanuser->user->host, ((chanuser->user->flags & USERFLAG_ISAUTHED) ? chanuser->user->auth : "*"), chanuser->flags); - } -} - -static CMD_BIND(neonserv_cmd_modes) { - char modeBuf[MAXLEN]; - getModeString(chan, modeBuf); - putsock(client, "PRIVMSG %s :Modes: %s", chan->name, modeBuf); -} +/* +INCLUDE ALL CMD's HERE +*/ +#include "cmd_neonserv_users.c" +#include "cmd_neonserv_modes.c" static void neonserv_bot_ready(struct ClientSocket *client) { MYSQL_RES *res; @@ -70,7 +62,14 @@ static void start_bots() { printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access` FROM `bot_binds` WHERE `botid` = '%d'", client->clientid); res2 = mysql_use(); while ((row = mysql_fetch_row(res2)) != NULL) { - + if(bind_cmd_to_command(BOTID, row[0], row[1])) { + if(row[2] && strcmp(row[2], "")) { + bind_set_parameters(BOTID, row[0], row[2]); + } + if(atoi(row[3]) > 0) { + bind_set_gaccess(BOTID, row[0], atoi(row[3])); + } + } } } } @@ -84,8 +83,6 @@ void init_NeonServ() { start_bots(); bind_bot_ready(neonserv_bot_ready); set_trigger_callback(BOTID, neonserv_trigger_callback); - bind_cmd_to_command(BOTID, "users", "users"); - bind_cmd_to_command(BOTID, "modes", "modes"); register_default_language_table(msgtab); } diff --git a/cmd_neonserv_modes.c b/cmd_neonserv_modes.c new file mode 100644 index 0000000..b2240aa --- /dev/null +++ b/cmd_neonserv_modes.c @@ -0,0 +1,6 @@ + +static CMD_BIND(neonserv_cmd_modes) { + char modeBuf[MAXLEN]; + getModeString(chan, modeBuf); + putsock(client, "PRIVMSG %s :Modes: %s", chan->name, modeBuf); +} diff --git a/cmd_neonserv_users.c b/cmd_neonserv_users.c new file mode 100644 index 0000000..3011259 --- /dev/null +++ b/cmd_neonserv_users.c @@ -0,0 +1,8 @@ + +static CMD_BIND(neonserv_cmd_users) { + struct ChanUser *chanuser; + putsock(client, "PRIVMSG %s :[BOT JOIN] Users on this Channel:", chan->name); + for(chanuser = getChannelUsers(chan, NULL); chanuser; chanuser = getChannelUsers(chan, chanuser)) { + putsock(client, "PRIVMSG %s : %s!%s@%s [%s] rights: %d", chan->name, chanuser->user->nick, chanuser->user->ident, chanuser->user->host, ((chanuser->user->flags & USERFLAG_ISAUTHED) ? chanuser->user->auth : "*"), chanuser->flags); + } +} diff --git a/modcmd.c b/modcmd.c index 96b0c8b..469de2e 100644 --- a/modcmd.c +++ b/modcmd.c @@ -336,6 +336,7 @@ int bind_cmd_to_function(int botid, char *cmd, struct cmd_function *func) { cbind->cmd = strdup(cmd); cbind->func = func; cbind->parameters = NULL; + cbind->access = 0; cbind->flags = 0; cbind->next = cmd_binds[bind_index]; cmd_binds[bind_index] = cbind; @@ -365,6 +366,7 @@ int bind_cmd_to_command(int botid, char *cmd, char *func) { cbind->func = cmdfunc; cbind->next = cmd_binds[bind_index]; cbind->parameters = NULL; + cbind->access = 0; cbind->flags = 0; cmd_binds[bind_index] = cbind; return 1; @@ -429,3 +431,11 @@ void free_modcmd() { trigger_callbacks = NULL; } +void bind_set_parameters(int botid, char *cmd, char *parameters) { + +} + +void bind_set_gaccess(int botid, char *cmd, int access) { + +} + diff --git a/modcmd.h b/modcmd.h index 30c0fd0..8b18986 100644 --- a/modcmd.h +++ b/modcmd.h @@ -32,6 +32,7 @@ struct cmd_binding { struct cmd_function *func; unsigned int flags; char *parameters; + int access; struct cmd_binding *next; }; @@ -53,5 +54,7 @@ int bind_cmd_to_function(int botid, char *cmd, struct cmd_function *func); int bind_cmd_to_command(int botid, char *cmd, char *func); int unbind_cmd(int botid, char *cmd); struct ClientSocket *getTextBot(); +void bind_set_parameters(int botid, char *cmd, char *parameters); +void bind_set_gaccess(int botid, char *cmd, int access); #endif \ No newline at end of file -- 2.20.1