changeset 592:27a6b7c2caad

Add -r option for specifying the room by name instead of port.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 29 Sep 2013 22:08:49 +0300
parents 926426a3e401
children 00f476c65e1b
files main.c
diffstat 1 files changed, 41 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/main.c	Sun Sep 29 22:07:36 2013 +0300
+++ b/main.c	Sun Sep 29 22:08:49 2013 +0300
@@ -39,6 +39,22 @@
 #define SET_KEEPALIVE   (15*60)     // Ping/keepalive period in seconds
 
 
+typedef struct
+{
+    char *name;
+    int port;
+    char *desc;
+} nn_room_data_t;
+
+static const nn_room_data_t nn_room_data[] =
+{
+    { "main" , 8005, "Main room" },
+    { "pit"  , 8003, "Passion Pit" },
+};
+
+static const int nn_room_data_n = sizeof(nn_room_data) / sizeof(nn_room_data[0]);
+
+
 /* Options
  */
 int     optPort = 8005,
@@ -104,6 +120,8 @@
     {10, '4', "socks4",     "SOCKS4 proxy server", OPT_ARGREQ },
     {11, 'A', "socks4a",    "SOCKS4A proxy server", OPT_ARGREQ },
     {12, 'P', "proxy-port", "Proxy port (default: 1080)", OPT_ARGREQ },
+
+    {13, 'r', "room",       "Connect to room (main, pit)", OPT_ARGREQ },
 };
 
 const int optListN = (sizeof(optList) / sizeof(optList[0]));
@@ -111,10 +129,20 @@
 
 void argShowHelp(void)
 {
+    int i;
     th_print_banner(stdout, th_prog_name,
                     "[options] <username> <password>");
 
     th_args_help(stdout, optList, optListN);
+
+    printf("Supported rooms (for option '-r'):\n");
+    for (i = 0; i < nn_room_data_n; i++)
+    {
+        printf("  %s  - %s (port %d)\n",
+            nn_room_data[i].name,
+            nn_room_data[i].desc,
+            nn_room_data[i].port);
+    }
 }
 
 
@@ -178,6 +206,19 @@
         optProxyPort = atoi(optArg);
         break;
 
+    case 13:
+        {
+            int i;
+            for (i = 0; i < nn_room_data_n; i++)
+            if (!strcasecmp(nn_room_data[i].name, optArg))
+            {
+                optPort = nn_room_data[i].port;
+                return TRUE;
+            }
+
+            THERR("Unsupported room '%s'.\n", optArg);
+        }
+        break;
 
     default:
         THERR("Unknown option '%s'.\n", currArg);