added IPNode for storing real IP's of users
[NeonServV5.git] / src / tools.c
index c802bbeaf165e4f3762a5b11dd1560db0acb53b9..2cb1065fa8458b33b2235200e3269f79a1e48558 100644 (file)
@@ -19,6 +19,7 @@
 #include "ChanNode.h"
 #include "lang.h"
 #include "ClientSocket.h"
+#include "IPNode.h"
 
 static const struct default_language_entry msgtab[] = {
     {"TIME_MASK_2_ITEMS", "%s and %s"}, /* {ARGS: "2 days", "1 hour"} */
@@ -487,7 +488,7 @@ char* make_banmask(char *input, char* buffer) {
         ident = input;
         *p = '\0';
         host = p+1;
-    } else if((p = strstr(input, "."))) {
+    } else if((p = strstr(input, ".")) || (p = strstr(input, ":"))) {
         host = input;
     } else if(*input == '*' && input[1] != '\0' && !strstr(input+1, "*")) {
         //AUTH MASK
@@ -525,6 +526,26 @@ int isFakeHost(char *host) {
     return (strlen(p2+1) > 4);
 }
 
+int mask_match(char *mask, struct UserNode *user) {
+    char usermask[NICKLEN+USERLEN+HOSTLEN+3];
+    char matchmask[strlen(mask)+3];
+    strcpy(matchmask, mask);
+    char *host = strchr(mask, '@');
+    if(host) {
+        struct IPNode *ip = createIPNode(host);
+        int bits = (ip->flags & IPNODE_IS_IPV6 ? 128 : 32);
+        if((host = strchr(host, '/'))) {
+            bits = atoi(host+1);
+        }
+        if(ip && user->ip&& !ipmatch(user->ip, ip, bits)) {
+            host[1] = '*';
+            host[2] = '\0';
+        }
+    }
+    sprintf(usermask, "%s!%s@%s", user->nick, user->ident, user->host);
+    return match(matchmask, usermask);
+}
+
 static unsigned long crc_table[256];
 
 static void crc32_init() {