changeset 140:2d2ef5bbcc11

Use th-libs linked list code for managing ignore list.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 02 Nov 2010 21:48:24 +0200
parents c39399725f7b
children cce05daf6f01
files nnchat.c
diffstat 1 files changed, 40 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/nnchat.c	Tue Nov 02 21:47:07 2010 +0200
+++ b/nnchat.c	Tue Nov 02 21:48:24 2010 +0200
@@ -31,17 +31,6 @@
 #define SET_DELAY_USEC  (SET_DELAY * 250)
 #define SET_KEEPALIVE   (15*60)     /* Ping/keepalive period in seconds */
 
-char *ignoreList[] = {
-    "purr_rr",
-    "moisha",
-    "leth",
-    "shaz:)",
-    "rayen",
-    "iam2qute4you_92",
-    NULL
-};
-
-nn_userhash_t *nnUsers = NULL;
 
 /* Options
  */
@@ -63,6 +52,9 @@
 BOOL    setPrvMode = FALSE;
 BOOL	ignoreMode = FALSE;
 
+
+qlist_t *nnIgnoreList = NULL;
+nn_userhash_t *nnUsers = NULL;
 char    *setConfigFile = NULL,
         *setBrowser = NULL;
 cfgitem_t *cfg = NULL;
@@ -405,13 +397,13 @@
         t = nn_strip_tags(s);
         h = nn_decode_str2(t);
         if (ignoreMode) {
-            char **user = ignoreList;
-            while (*user != NULL) {
-                if (strcasecmp(p2, *user) == 0) {
+            qlist_t *node = nnIgnoreList;
+            while (node != NULL) {
+                if (strcasecmp(p2, (char *) node->data) == 0) {
                     logOnly = TRUE;
                     break;
                 }
-                user++;
+                node = node->next;
             }
         }
         printMsgQ(logOnly, "½5½<½%d½%s½5½>½0½ %s\n", isMine ? 14 : 15, p2, h);
@@ -550,6 +542,11 @@
     return buf;
 }
 
+int compareUsername(const void *s1, const void *s2)
+{
+    return strcasecmp((char *) s1, (char *) s2);
+}
+
 int handleUserInput(const int sock, char *buf, size_t bufLen)
 {
     char *tmpStr, tmpBuf[4096];
@@ -575,6 +572,34 @@
         printMsg("Setting color to #%06x\n", optUserColor);
         nn_send_msg(sock, optUserName2, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor);
         return 0;
+    } else if (!strncasecmp(buf, "/ignore", 7)) {
+        char *name = trimLeft(buf + 7);
+        if (strlen(name) > 0) {
+            /* Add or remove someone to/from ignore */
+            qlist_t *user = th_llist_find_func(nnIgnoreList, name, compareUsername);
+            if (user != NULL) {
+                printMsg("Removed user '%s' from ignore.\n", name);
+                th_llist_delete_node(&nnIgnoreList, user);
+            } else {
+                printMsg("Now ignoring '%s'.\n", name);
+                th_llist_append(&nnIgnoreList, th_strdup(name));
+            }
+        } else {
+            /* Just list whomever is in ignore now */
+            qlist_t *user = nnIgnoreList;
+            ssize_t nuser = th_llist_length(nnIgnoreList);
+            printMsg("Users ignored (%d): ", nuser);
+            while (user != NULL) {
+                if (user->data != NULL) {
+                    printMsgC("'%s'", (char *) user->data);
+                    if (--nuser > 0)
+                        printMsgC(", ");
+                }
+                user = user->next;
+            }
+            printMsgC("\n");
+        }
+        return 0;
     } else if (!strncasecmp(buf, "/save", 5)) {
         /* Save configuration */
         FILE *f = fopen(setConfigFile, "w");