From: pk910 Date: Wed, 17 Aug 2011 02:43:15 +0000 (+0200) Subject: added first messages to modcmd.c X-Git-Tag: v5.3~540 X-Git-Url: http://git.pk910.de/?p=NeonServV5.git;a=commitdiff_plain;h=273602718406b39abb74ae934b98e50dc8dc97a2 added first messages to modcmd.c --- diff --git a/UserNode.c b/UserNode.c index 5db84d6..0606940 100644 --- a/UserNode.c +++ b/UserNode.c @@ -270,14 +270,21 @@ void load_user_settings(struct UserNode *user) { check_mysql(); MYSQL_RES *res; MYSQL_ROW row; - printf_mysql_query("SELECT `user_lang`, `user_reply_privmsg` FROM `users` WHERE `user_user` = '%s'", escape_string(user->auth)); + printf_mysql_query("SELECT `user_lang`, `user_reply_privmsg`, `user_god` FROM `users` WHERE `user_user` = '%s'", escape_string(user->auth)); res = mysql_use(); if ((row = mysql_fetch_row(res)) != NULL) { user->language = get_language_by_tag(row[0]); if(user->language == NULL) user->language = get_default_language(); if(strcmp(row[1], "0")) user->flags |= USERFLAG_REPLY_PRIVMSG; + if(strcmp(row[2], "0")) + user->flags |= USERFLAG_GOD_MODE; } else user->language = get_default_language(); user->flags |= USERFLAG_LOADED_SETTINGS; } + +int isGodMode(struct UserNode *user) { + load_user_settings(); + return (user->flags & USERFLAG_GOD_MODE); +} diff --git a/UserNode.h b/UserNode.h index 3402c7d..9a0c538 100644 --- a/UserNode.h +++ b/UserNode.h @@ -10,6 +10,7 @@ #define USERFLAG_FREETMPUSER 0x0020 #define USERFLAG_LOADED_SETTINGS 0x0040 #define USERFLAG_REPLY_PRIVMSG 0x0080 +#define USERFLAG_GOD_MODE 0x0100 struct ChanUser; struct language; @@ -42,5 +43,6 @@ void delUser(struct UserNode* user, int freeUser); void clearTempUsers(); void load_user_settings(struct UserNode* user); +int isGodMode(struct UserNode *user); #endif diff --git a/modcmd.c b/modcmd.c index 0ef04e6..96b0c8b 100644 --- a/modcmd.c +++ b/modcmd.c @@ -1,6 +1,7 @@ #include "modcmd.h" #include "IRCEvents.h" +#include "IRCParser.h" #include "ClientSocket.h" #include "UserNode.h" #include "ChanNode.h" @@ -16,7 +17,7 @@ struct trigger_callback { }; struct command_check_user_cache { - struct ClientSocket *client; + struct ClientSocket *client, *textclient; struct UserNode *user; struct ChanNode *chan; char **argv; @@ -28,8 +29,14 @@ struct command_check_user_cache { static struct cmd_binding **cmd_binds; static struct cmd_function *cmd_functions = NULL; static struct trigger_callback *trigger_callbacks = NULL; +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_AUTH_REQUIRED", "You need to be authenticated with AuthServ to use this command."}, + {"MODCMD_PRIVILEGED", "§b%s§b is a privileged command."}, + {NULL, NULL} }; @@ -81,8 +88,13 @@ static char* get_channel_trigger(int botid, struct ChanNode *chan) { static USERAUTH_CALLBACK(command_checked_auth) { struct command_check_user_cache *cache = data; int execute_cmd = 1; + tmp_text_client = cache->textclient; if((cache->cbind->func->flags & CMDFLAG_REQUIRE_AUTH) && !(user->flags & USERFLAG_ISAUTHED)) { - //AUTH_REQUIRED + reply(tmp_text_client, user, "MODCMD_AUTH_REQUIRED"); + execute_cmd = 0; + } + else if((cache->cbind->func->flags & CMDFLAG_REQUIRE_GOD) && !isGodMode(user)) { + reply(tmp_text_client, user, "MODCMD_PRIVILEGED", cache->cbind->cmd); execute_cmd = 0; } if(execute_cmd) { @@ -113,6 +125,8 @@ static void handle_command(struct ClientSocket *client, struct UserNode *user, s struct cmd_binding *cbind; for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) { if(cbind->botid == client->botid && strcmp(cbind->cmd, message) == 0) { + //get a text bot + tmp_text_client = get_prefered_bot(client->botid); //parse the arguments... char *arga[MAXNUMPARAMS]; char **argv; @@ -177,13 +191,13 @@ static void handle_command(struct ClientSocket *client, struct UserNode *user, s argc = uargpos; } if(argc < cbind->func->paramcount) { - //LESS_PARAM_COUNT + reply(tmp_text_client, user, "MODCMD_LESS_PARAM_COUNT"); break; } if((cbind->func->flags & CMDFLAG_REQUIRE_CHAN) && !chan) { - //CHAN_REQUIRED + reply(tmp_text_client, user, "MODCMD_CHAN_REQUIRED"); break; - } + } if((cbind->func->flags & CMDFLAG_CHECK_AUTH) && !(user->flags & USERFLAG_ISAUTHED)) { //check auth... struct command_check_user_cache *data = malloc(sizeof(*data)); @@ -200,11 +214,16 @@ static void handle_command(struct ClientSocket *client, struct UserNode *user, s data->chan = chan; data->message = message; data->cbind = cbind; + data->textclient = tmp_text_client; get_userauth(user, command_checked_auth, data); return; } if((cbind->func->flags & CMDFLAG_REQUIRE_AUTH) && !(user->flags & USERFLAG_ISAUTHED)) { - //AUTH_REQUIRED + reply(tmp_text_client, user, "MODCMD_AUTH_REQUIRED"); + break; + } + if((cbind->func->flags & CMDFLAG_REQUIRE_GOD) && !isGodMode(user)) { + reply(tmp_text_client, user, "MODCMD_PRIVILEGED", cbind->cmd); break; } cbind->func->func(client, user, chan, argv, argc); @@ -371,6 +390,10 @@ int unbind_cmd(int botid, char *cmd) { return 0; } +struct ClientSocket *getTextBot() { + return tmp_text_client; +} + void init_modcmd() { cmd_binds = calloc(27, sizeof(*cmd_binds)); bind_chanmsg(got_chanmsg); diff --git a/modcmd.h b/modcmd.h index 5c76a6a..30c0fd0 100644 --- a/modcmd.h +++ b/modcmd.h @@ -52,5 +52,6 @@ int changeChannelTrigger(int botid, struct ChanNode *chan, char *new_trigger); 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(); #endif \ No newline at end of file