]> jfr.im git - irc/evilnet/x3.git/blobdiff - src/tools.c
Merge branch 'master' of github.com:evilnet/x3
[irc/evilnet/x3.git] / src / tools.c
index 4c00172e676d9f28b2b4a98d35cdab154a6fbb26..357c1c7c3f6eb35a6c66d4957988947115c932f6 100644 (file)
@@ -367,6 +367,10 @@ irc_strtolower(char *str) {
 
 int
 irccasecmp(const char *stra, const char *strb) {
+    if (!stra)
+      return -1;
+    if (!strb)
+      return 1;
     while (*stra && (tolower(*stra) == tolower(*strb)))
         stra++, strb++;
     return tolower(*stra) - tolower(*strb);
@@ -602,11 +606,15 @@ int is_overmask(char *mask)
 }
 
 int
-user_matches_glob(struct userNode *user, const char *orig_glob, int flags)
+user_matches_glob(struct userNode *user, const char *orig_glob, int flags, int shared)
 {
     char *tmpglob, *glob, *marker;
     char exttype = 0;
-    int extreverse = 0, is_extended = 0;
+    int extreverse = 0, is_extended = 0, match = 0, banned = 0;
+    unsigned int count, n;
+    struct modeNode *mn;
+    struct chanNode *channel;
+    struct banNode *ban;
 
     /* Make a writable copy of the glob */
     glob = alloca(strlen(orig_glob)+1);
@@ -651,8 +659,87 @@ user_matches_glob(struct userNode *user, const char *orig_glob, int flags)
                         return 1;
                 }
                 return match_ircglob(user->hostname, glob);
+            case 'c':
+                if (!strstr(glob, "#"))
+                    return -1;
+
+                if (extreverse) {
+                    for (n=count=0; n<user->channels.used; n++) {
+                        mn = user->channels.list[n];
+                        match = 0;
+
+                        if (*glob == '#') {
+                            if (0 == strcasecmp(glob, mn->channel->name))
+                                match = 1;
+                        } else {
+                            if (0 == strcasecmp(glob+1, mn->channel->name)) {
+                                if ((*glob == '@') && (mn->modes & MODE_CHANOP))
+                                    match = 1;
+                                else if ((*glob == '%') && (mn->modes & MODE_HALFOP))
+                                    match = 1;
+                                else if ((*glob == '+') && (mn->modes & MODE_VOICE))
+                                    match = 1;
+                             }
+                        }
+
+                        if (match == 0)
+                            banned = 1;
+                        else {
+                            banned = 0;
+                            break;
+                        }
+                    }
+                } else {
+                    for (n=count=0; n<user->channels.used; n++) {
+                        mn = user->channels.list[n];
+                        match = 0;
+
+                        if (*glob == '#') {
+                            if (0 == strcasecmp(glob, mn->channel->name))
+                                match = 1;
+                        } else {
+                            if (0 == strcasecmp(glob+1, mn->channel->name)) {
+                                if ((*glob == '@') && (mn->modes & MODE_CHANOP))
+                                    match = 1;
+                                else if ((*glob == '%') && (mn->modes & MODE_HALFOP))
+                                    match = 1;
+                                else if ((*glob == '+') && (mn->modes & MODE_VOICE))
+                                    match = 1;
+                             }
+                        }
+
+                        if (match == 1)
+                            banned = 1;
+                    }
+                }
+
+                if (banned)
+                    return 1;
+                else
+                    return match_ircglob(user->hostname, glob);
+            case 'j':
+                 if (shared == 0) {
+                     if (*glob != '#')
+                         return -1;
+                     if ((channel = GetChannel(glob))) {
+                         for (n = 0; n < channel->banlist.used; n++) {
+                             ban = channel->banlist.list[n];
+                             if (user_matches_glob(user, ban->ban, flags, 1))
+                                 return 1;
+                         }
+                     }
+                 }
+                 return match_ircglob(user->hostname, glob);
+            case 'n': /* this is handled ircd side */
+                return match_ircglob(user->hostname, glob);
+            case 'q': /* this is handled ircd side */
+                return match_ircglob(user->hostname, glob);
+            case 't': /* this is handled ircd side */
+                return match_ircglob(user->hostname, glob);
+            case 'R': /* this is handled ircd side */
+                return match_ircglob(user->hostname, glob);
             default:
-                return 0;
+                return -1;
         }
     }