finished cmd_addban
[NeonServV5.git] / cmd_neonserv_addban.c
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();