added cmd_ban and all functions depending on
[NeonServV5.git] / tools.c
diff --git a/tools.c b/tools.c
index 938bf790247cc9ffa215d5dba234c2d0d524d083..93fbd323e2c42d56e6c4455711e6628a6034f326 100644 (file)
--- a/tools.c
+++ b/tools.c
@@ -386,16 +386,8 @@ int is_ircmask(const char *text) {
 
 char* generate_banmask(struct UserNode *user, char *buffer) {
     char *userhost = user->host;
-    char *p1, *p2 = userhost;
     
-    //find the last dot to identify if the hostmask is a hidden host
-    while((p1 = strstr(userhost, "."))) {
-        p2 = p1;
-    }
-    //TLD database: http://www.iana.org/domains/root/db/
-    //the longest TLD i found was 6 chars long (ignoring the stange exotic ones :D)
-    //but we even ignore '.museum' and '.travel' so we can say that the TLD of our mask needs to be less than 4 chars to be a real domain
-    if(strlen(p2+1) > 4) {
+    if(isFakeHost(user->host)) {
         sprintf(buffer, "*!*@%s", userhost);
         return buffer;
     }
@@ -410,6 +402,57 @@ char* generate_banmask(struct UserNode *user, char *buffer) {
     }
 }
 
+char* make_banmask(char *input, char* buffer) {
+    char *nick = NULL, *ident = NULL, *host = NULL;
+    char tmp[HOSTLEN];
+    char *p;
+    if((p = strstr(input, "!"))) {
+        nick = input;
+        *p = '\0';
+        ident = p+1;
+        if((p = strstr(ident, "@"))) {
+            *p = '\0';
+            host = p+1;
+        }
+    } else if((p = strstr(input, "@"))) {
+        ident = input;
+        *p = '\0';
+        host = p+1;
+    } else if((p = strstr(input, "."))) {
+        host = input;
+    } else if(*input == '*' && !strstr(input+1, "*")) {
+        //AUTH MASK
+        p = getAuthFakehost(input+1);
+        if(p)
+            host = p;
+        else {
+            sprintf(tmp, "%s.*", input+1);
+            host = tmp;
+        }
+    } else {
+        struct UserNode *user = searchUserByNick(input);
+        if(user)
+            return generate_banmask(user, buffer);
+        else
+            nick = input;
+    }
+    sprintf(buffer, "%s!%s@%s", (nick ? nick : "*"), (ident ? ident : "*"), (host ? host : "*"));
+    return buffer;
+}
+
+int isFakeHost(char *host) {
+    char *p1, *p2 = host;
+    
+    //find the last dot to identify if the hostmask is a fake host
+    while((p1 = strstr(p2, "."))) {
+        p2 = p1 + 1;
+    }
+    //TLD database: http://www.iana.org/domains/root/db/
+    //the longest TLD i found was 6 chars long (ignoring the stange exotic ones :D)
+    //but we even ignore '.museum' and '.travel' so we can say that the TLD of our mask needs to be less than 4 chars to be a real domain
+    return (strlen(p2+1) > 4);
+}
+
 void init_tools() {
     register_default_language_table(msgtab);
 }