finished cmd_addban
authorpk910 <philipp@zoelle1.de>
Thu, 8 Sep 2011 23:31:40 +0000 (01:31 +0200)
committerpk910 <philipp@zoelle1.de>
Thu, 8 Sep 2011 23:42:02 +0000 (01:42 +0200)
DBHelper.c
DBHelper.h
bot_NeonServ.c
cmd_neonserv_addban.c

index c8efb6b12092c13715b11aafdf8f36d894d808e2..5e9005d771e669d8bf55487a160943b84bd48322 100644 (file)
@@ -5,7 +5,7 @@
 #include "ChanUser.h"
 #include "mysqlConn.h"
 #include "lang.h"
-
+#include "tools.h"
 
 void _loadUserSettings(struct UserNode *user) {
     check_mysql();
@@ -154,4 +154,16 @@ int isUserProtected(struct ChanNode *chan, struct UserNode *victim, struct UserN
     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;
+}
index 5c0c16d9411cfb2306c8cd7d515428913d05780e..af4cc326f6761da8414ce2a54174b0b41278b54e 100644 (file)
@@ -19,4 +19,6 @@ void _loadChannelSettings(struct ChanNode *chan);
 #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
index 7a0a772cf372a9106f33dc300407921846acec4b..5920dc239655bcd9a407e59495ad9bc07c7bdc33 100644 (file)
@@ -37,6 +37,7 @@ static const struct default_language_entry msgtab[] = {
     {"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."},
index 245190b391607c94c678c84d4ce3d87a174c6740..1e476ef0976a0c7c8d16b78b249711ec2c3eb092 100644 (file)
@@ -68,6 +68,21 @@ static void neonserv_cmd_addban_async1(struct ClientSocket *client, struct Clien
     }
     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();