# HG changeset patch # User Matti Hamalainen # Date 1380481729 -10800 # Node ID 27a6b7c2caad861cd99f880d187fe51c64e4c420 # Parent 926426a3e401e459dd8b0cd76077c953a58f8173 Add -r option for specifying the room by name instead of port. diff -r 926426a3e401 -r 27a6b7c2caad main.c --- 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] "); 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);