changeset 519:f17d2ab25618

Add option for only allowing private messages from people on a special friend list.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 05 Jun 2012 23:20:52 +0300
parents 8132548e1a07
children ab56ed0d0c25
files main.c
diffstat 1 files changed, 59 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/main.c	Tue Jun 05 22:33:21 2012 +0300
+++ b/main.c	Tue Jun 05 23:20:52 2012 +0300
@@ -50,11 +50,13 @@
 char    optNickSep;
 BOOL    optDaemon = FALSE;
 FILE    *optLogFile = NULL;
-BOOL    setIgnoreMode = FALSE;
-BOOL    optDebug = FALSE;
-BOOL    optLogEnable = FALSE;
+BOOL    setIgnoreMode = FALSE,
+        optDebug = FALSE,
+        optLogEnable = FALSE,
+        optOnlyFriendPrv = FALSE;
 
 qlist_t *setIgnoreList = NULL,
+        *setFriendList = NULL,
         *setIdleMessages = NULL;
 nn_userhash_t *nnUsers = NULL;
 char    *setConfigFile = NULL,
@@ -341,15 +343,16 @@
 }
 
 
-BOOL checkIgnoreList(const char *name)
+BOOL checkNameList(qlist_t *list, const char *name)
 {
-    qlist_t *node = setIgnoreList;
-    while (node != NULL)
+    qlist_t *node;
+    
+    for (node = list; node != NULL; node = node->next)
     {
         if (th_strcasecmp(name, (char *) node->data) == 0)
             return TRUE;
-        node = node->next;
     }
+
     return FALSE;
 }
 
@@ -395,7 +398,7 @@
      * that it is not our OWN username!
      */
     isMine = strcmp(name, optUserName) == 0;
-    isIgnored = setIgnoreMode && !isMine && checkIgnoreList(name);
+    isIgnored = setIgnoreMode && !isMine && checkNameList(setIgnoreList, name);
 
     // Is it a special control message?
     if (*msg == '/')
@@ -424,22 +427,26 @@
                 in_msg = "";
             *tmp = 0;
 
-            isIgnored = setIgnoreMode && checkIgnoreList(in_name);
-            win = nnwin_find(in_name);
-
-            if (win != NULL)
+            if (!optOnlyFriendPrv || !checkNameList(setFriendList, in_name))
             {
-                printMsgF(win, isIgnored ? 0 : LOG_WINDOW,
-                    "½5½<½%d½%s½5½>½0½ %s\n",
-                    isMine ? 14 : 15, isMine ? optUserName : in_name, in_msg);
+                isIgnored = setIgnoreMode && checkNameList(setIgnoreList, in_name);
+                win = nnwin_find(in_name);
 
-                printMsgF(NULL, LOG_FILE, "½11½%s½0½\n", h);
+                if (win != NULL)
+                {
+                    printMsgF(win, isIgnored ? 0 : LOG_WINDOW,
+                        "½5½<½%d½%s½5½>½0½ %s\n",
+                        isMine ? 14 : 15, isMine ? optUserName : in_name, in_msg);
+
+                    printMsgF(NULL, LOG_FILE, "½11½%s½0½\n", h);
+                }
+                else
+                {
+                    printMsgF(NULL, isIgnored ? LOG_FILE : (LOG_WINDOW | LOG_FILE),
+                        "½11½%s½0½\n", h);
+                }
             }
-            else
-            {
-                printMsgF(NULL, isIgnored ? LOG_FILE : (LOG_WINDOW | LOG_FILE),
-                    "½11½%s½0½\n", h);
-            }
+            
             th_free(in_name);
             th_free(h);
         }
@@ -677,31 +684,31 @@
 }
 
 
-int nncmd_ignore(nn_conn_t *conn, char *name)
+int nncmd_change_list(nn_conn_t *conn, const char *listname, qlist_t **list, const char *name)
 {
     (void) conn;
 
     if (name[0])
     {
         // Add or remove someone to/from ignore
-        qlist_t *user = th_llist_find_func(setIgnoreList, name, str_compare);
+        qlist_t *user = th_llist_find_func(*list, name, str_compare);
         if (user != NULL)
         {
-            printMsgQ(currWin, "Removed user '%s' from ignore.\n", name);
+            printMsgQ(currWin, "Removed user '%s' from %s list.\n", name, listname);
             th_llist_delete_node(&setIgnoreList, user);
         }
         else
         {
-            printMsgQ(currWin, "Now ignoring '%s'.\n", name);
-            th_llist_append(&setIgnoreList, th_strdup(name));
+            printMsgQ(currWin, "Added '%s' to %s list.\n", name, listname);
+            th_llist_append(list, th_strdup(name));
         }
     }
     else
     {
         // Just list whomever is in ignore now
-        qlist_t *user = setIgnoreList;
-        size_t nuser = th_llist_length(setIgnoreList);
-        char *result = th_strdup_printf("Users ignored (%d): ", nuser);
+        qlist_t *user = *list;
+        size_t nuser = th_llist_length(*list);
+        char *result = th_strdup_printf("Users on %s list (%d): ", listname, nuser);
         while (user != NULL)
         {
             if (user->data != NULL)
@@ -720,6 +727,18 @@
 }
 
 
+int nncmd_ignore(nn_conn_t *conn, char *name)
+{
+    return nncmd_change_list(conn, "ignore", &setIgnoreList, name);
+}
+
+
+int nncmd_friend(nn_conn_t *conn, char *name)
+{
+    return nncmd_change_list(conn, "friend", &setFriendList, name);
+}
+
+
 int nncmd_set_color(nn_conn_t *conn, char *arg)
 {
     int val;
@@ -960,6 +979,7 @@
     { "/win",      CMDARG_OPTIONAL, 0, nncmd_window_info },
 
     { "/ignore",   CMDARG_OPTIONAL, 0, nncmd_ignore },
+    { "/friend",   CMDARG_OPTIONAL, 0, nncmd_friend },
     { "/color",    CMDARG_STRING,   0, nncmd_set_color },
     { "/save",     CMDARG_NONE,     0, nncmd_save_config },
 };
@@ -1407,6 +1427,11 @@
         printMsgQ(currWin, "Ignore mode = %s\n", setIgnoreMode ? "ON" : "OFF");
         break;
 
+    case KEY_F(6): // F6 = Ignore mode
+        optOnlyFriendPrv = !optOnlyFriendPrv;
+        printMsgQ(currWin, "Only friends allowed to PRV you = %s\n", optOnlyFriendPrv ? "ON" : "OFF");
+        break;
+
     case 0x03: // ^C = quit
     case KEY_F(9): // F9 = Quit
         printMsg(currWin, "Quitting per user request (%d/0x%x).\n", c, c);
@@ -1485,6 +1510,11 @@
     th_cfg_add_comment(&tmpcfg, "People to be ignored when ignore mode is enabled");
     th_cfg_add_string_list(&tmpcfg, "ignore_list", &setIgnoreList);
 
+    th_cfg_add_comment(&tmpcfg, "Allow only defined friends to private to you");
+    th_cfg_add_bool(&tmpcfg, "prv_friends", &optOnlyFriendPrv, optOnlyFriendPrv);
+    th_cfg_add_comment(&tmpcfg, "List of your friends");
+    th_cfg_add_string_list(&tmpcfg, "friend_list", &setFriendList);
+
     th_cfg_add_comment(&tmpcfg, "Random messages for idle timeout protection. If none are set, plain '.' is used.");
     th_cfg_add_string_list(&tmpcfg, "idle_messages", &setIdleMessages);