#include "ChanUser.h"
#include "mysqlConn.h"
#include "lang.h"
-
+#include "tools.h"
void _loadUserSettings(struct UserNode *user) {
check_mysql();
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;
+}
#define loadChannelSettings(CHAN) if(!(CHAN->flags & CHANFLAG_REQUESTED_CHANINFO)) _loadChannelSettings(CHAN)
int isUserProtected(struct ChanNode *chan, struct UserNode *victim, struct UserNode *issuer);
+char *getBanAffectingMask(struct ChanNode *chan, char *mask); //returns bans that match a given mask eg. *!*@ab* if you pass *!*@abcdefg.*
+
#endif
\ No newline at end of file
{"NS_USER_PROTECTED", "Sorry, \002%s\002 is protected."},
{"NS_SERVICE_IMMUNE", "\002%s\002 may not be kicked, killed, banned, or deopped."},
{"NS_TABLE_NONE", " None"},
+ {"NS_BAN_ALREADY_ADDED", "\002%s\002 is already banned in %s."},
{"NS_INVALID_ACCESS_RANGE", "Invalid access range; minimum (%d) must be lower than maximum (%d)."},
{"NS_CLVL_DONE", "%s now has access \002%d\002 in %s."},
{"NS_A_LACKS_ACCESS_BUT_GOD_NICK", "%s lacks access to %s but has \002security override\002 enabled."},
}
MYSQL_RES *res;
MYSQL_ROW row;
+ //check if the provided mask is already banned by another ban
+ char *ban = getBanAffectingMask(chan, mask);
+ if(ban != NULL) {
+ reply(textclient, user, "NS_BAN_ALREADY_ADDED", ban, chan->name);
+ return;
+ }
+ //check if the provided mask affects any existing bans
+ printf_mysql_query("SELECT `ban_mask`, `ban_id` FROM `bans` WHERE `ban_channel` = '%d'", chan->channel_id);
+ res = mysql_use();
+ while ((row = mysql_fetch_row(res)) != NULL) {
+ if(!match(mask, row[0])) {
+ //remove the ban
+ printf_mysql_query("DELETE FROM `bans` WHERE `ban_id` = '%s'", row[1]);
+ }
+ }
printf_mysql_query("SELECT `user_id` FROM `users` WHERE `user_user` = '%s'", escape_string(user->auth));
int userid;
res = mysql_use();