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'");
+ 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'", chan->channel_id);
+ 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;
+}
+