added cmd_kick, cmd_kickban & all the functions depending on
[NeonServV5.git] / tools.c
diff --git a/tools.c b/tools.c
index 274187229bc3584fde6e50e925841a475907ebd0..938bf790247cc9ffa215d5dba234c2d0d524d083 100644 (file)
--- a/tools.c
+++ b/tools.c
@@ -370,6 +370,46 @@ void freeModeBuffer(struct ModeBuffer *modeBuf) {
     free(modeBuf);
 }
 
+int is_ircmask(const char *text) {
+    while (*text && (isalnum((char)*text) || strchr("-_[]|\\`^{}?*", *text)))
+        text++;
+    if (*text++ != '!')
+        return 0;
+    while (*text && *text != '@' && !isspace((char)*text))
+        text++;
+    if (*text++ != '@')
+        return 0;
+    while (*text && !isspace((char)*text))
+        text++;
+    return !*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) {
+        sprintf(buffer, "*!*@%s", userhost);
+        return buffer;
+    }
+    
+    //check if the hostname has more than 4 connections (trusted host)
+    if(countUsersWithHost(userhost) > 4) {
+        sprintf(buffer, "*!%s@%s", user->ident, userhost);
+        return buffer;
+    } else {
+        sprintf(buffer, "*!*@%s", userhost);
+        return buffer;
+    }
+}
+
 void init_tools() {
     register_default_language_table(msgtab);
 }