X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=DBHelper.c;h=181fff607b542c6262721a4fe973414594ec5d8c;hb=795115bf680185ae01043bd1222b78bfed8c1d87;hp=f0897d25f03e4a657b534374f58b194e67ad46e6;hpb=ff1ae24742182cbaa38d444b54f32e7154c6b544;p=NeonServV5.git diff --git a/DBHelper.c b/DBHelper.c index f0897d2..181fff6 100644 --- a/DBHelper.c +++ b/DBHelper.c @@ -5,10 +5,9 @@ #include "ChanUser.h" #include "mysqlConn.h" #include "lang.h" - +#include "tools.h" void _loadUserSettings(struct UserNode *user) { - check_mysql(); MYSQL_RES *res; MYSQL_ROW row; printf_mysql_query("SELECT `user_lang`, `user_reply_privmsg`, `user_god` FROM `users` WHERE `user_user` = '%s'", escape_string(user->auth)); @@ -36,7 +35,6 @@ int getChannelAccess(struct UserNode *user, struct ChanNode *chan, int override) if(!(chan->flags & CHANFLAG_CHAN_REGISTERED)) return 0; MYSQL_RES *res; MYSQL_ROW row; - check_mysql(); int caccess = 0; printf_mysql_query("SELECT `user_id`, `user_access`, `user_god` FROM `users` WHERE `user_user` = '%s'", escape_string(user->auth)); res = mysql_use(); @@ -68,12 +66,13 @@ char *getChanDefault(char *channel_setting) { int checkChannelAccess(struct UserNode *user, struct ChanNode *chan, char *channel_setting, int allow_override, int allow_501) { loadChannelSettings(chan); if(!(chan->flags & CHANFLAG_CHAN_REGISTERED)) return 0; + if((user->flags & USERFLAG_ISIRCOP)) return 1; MYSQL_RES *res; MYSQL_ROW row; printf_mysql_query("SELECT `%s` FROM `channels` WHERE `channel_id` = '%d'", channel_setting, chan->channel_id); res = mysql_use(); if ((row = mysql_fetch_row(res)) == NULL) return 0; - int require_access = (row[0] ? atoi(row[0]) : getChanDefault(channel_setting)); + int require_access = atoi((row[0] ? row[0] : getChanDefault(channel_setting))); if(require_access == 0) return 1; if(!(user->flags & USERFLAG_ISAUTHED)) return 0; int caccess = 0; @@ -94,7 +93,6 @@ int checkChannelAccess(struct UserNode *user, struct ChanNode *chan, char *chann } void _loadChannelSettings(struct ChanNode *chan) { - check_mysql(); MYSQL_RES *res; MYSQL_ROW row; printf_mysql_query("SELECT `channel_id` FROM `channels` WHERE `channel_name` = '%s'", escape_string(chan->name)); @@ -106,4 +104,63 @@ void _loadChannelSettings(struct ChanNode *chan) { chan->flags |= CHANFLAG_REQUESTED_CHANINFO; } +//TODO: fix performance: we should cache the user access +int isUserProtected(struct ChanNode *chan, struct UserNode *victim, struct UserNode *issuer) { + /* Don't protect if someone is attacking himself, or if the aggressor is an IRC Operator. */ + if(victim == issuer || (issuer->flags & USERFLAG_ISIRCOP)) return 0; + + /* Don't protect if no one is to be protected. */ + MYSQL_RES *res; + MYSQL_ROW row; + char protection; + loadChannelSettings(chan); + if(!(chan->flags & CHANFLAG_CHAN_REGISTERED)) return 0; + printf_mysql_query("SELECT `channel_protect` FROM `channels` WHERE `channel_id` = '%d'", chan->channel_id); + res = mysql_use(); + if(!(row = mysql_fetch_row(res))) return 0; + if(row[0]) { + protection = (char) atoi(row[0]); + } else { + printf_mysql_query("SELECT `channel_protect` FROM `channels` WHERE `channel_name` = 'defaults'"); + res = mysql_use(); + row = mysql_fetch_row(res); + protection = (char) atoi(row[0]); + } + if(protection == 3) return 0; + + /* Don't protect if the victim isn't added to the channel, unless we are to protect non-users also. */ + int victim_access = getChannelAccess(victim, chan, 0); + if (!victim_access && protection != 0) return 0; + + /* Protect if the aggressor isn't a user because at this point, the aggressor can only be less than or equal to the victim. */ + int issuer_access = getChannelAccess(issuer, chan, 0); + if (!issuer_access) return 1; + + /* If the aggressor was a user, then the victim can't be helped. */ + if(!victim_access) return 0; + + switch(protection) { + case 0: + case 1: + if(victim_access >= issuer_access) return 1; + break; + case 2: + if(victim_access > issuer_access) return 1; + break; + } + return 0; +} +char *getBanAffectingMask(struct ChanNode *chan, char *mask) { + loadChannelSettings(chan); + if(!(chan->flags & CHANFLAG_CHAN_REGISTERED)) return 0; + MYSQL_RES *res; + MYSQL_ROW row; + printf_mysql_query("SELECT `ban_mask` FROM `bans` WHERE `ban_channel` = '%d'", chan->channel_id); + res = mysql_use(); + while ((row = mysql_fetch_row(res)) != NULL) { + if(!match(row[0], mask)) + return row[0]; + } + return NULL; +}