Add a new irc_user_modes() helper function and irc_user_mode_chars[] array.
[srvx.git] / src / proto-common.c
index 3a14c68bdc0670b0371028711c61d30fa8d20273..967cb77f2ed823f0b31f678b7621baf5e32b1d29 100644 (file)
@@ -816,3 +816,20 @@ IsChannelName(const char *name) {
     }
     return 1;
 }
+
+unsigned int
+irc_user_modes(const struct userNode *user, char modes[], size_t length)
+{
+    unsigned int ii, jj;
+
+    for (ii = jj = 0; (jj < length) && (irc_user_mode_chars[ii] != '\0'); ++ii) {
+        if ((user->modes & (1 << ii)) && (irc_user_mode_chars[ii] != ' '))
+            modes[jj++] = irc_user_mode_chars[ii];
+    }
+
+    ii = jj;
+    while (jj < length)
+        modes[jj++] = '\0';
+
+    return ii;
+}