comparison main.c @ 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 2a6b512ee5a1
children 00f476c65e1b
comparison
equal deleted inserted replaced
591:926426a3e401 592:27a6b7c2caad
35 #define SET_PROFILE_PREFIX "http://www.newbienudes.com/profile/%s/" 35 #define SET_PROFILE_PREFIX "http://www.newbienudes.com/profile/%s/"
36 #define SET_NICK_SEPARATOR ':' 36 #define SET_NICK_SEPARATOR ':'
37 37
38 #define SET_MAX_HISTORY (64) // Command history length 38 #define SET_MAX_HISTORY (64) // Command history length
39 #define SET_KEEPALIVE (15*60) // Ping/keepalive period in seconds 39 #define SET_KEEPALIVE (15*60) // Ping/keepalive period in seconds
40
41
42 typedef struct
43 {
44 char *name;
45 int port;
46 char *desc;
47 } nn_room_data_t;
48
49 static const nn_room_data_t nn_room_data[] =
50 {
51 { "main" , 8005, "Main room" },
52 { "pit" , 8003, "Passion Pit" },
53 };
54
55 static const int nn_room_data_n = sizeof(nn_room_data) / sizeof(nn_room_data[0]);
40 56
41 57
42 /* Options 58 /* Options
43 */ 59 */
44 int optPort = 8005, 60 int optPort = 8005,
102 { 8, 'd', "debug", "Enable various debug features", OPT_NONE }, 118 { 8, 'd', "debug", "Enable various debug features", OPT_NONE },
103 119
104 {10, '4', "socks4", "SOCKS4 proxy server", OPT_ARGREQ }, 120 {10, '4', "socks4", "SOCKS4 proxy server", OPT_ARGREQ },
105 {11, 'A', "socks4a", "SOCKS4A proxy server", OPT_ARGREQ }, 121 {11, 'A', "socks4a", "SOCKS4A proxy server", OPT_ARGREQ },
106 {12, 'P', "proxy-port", "Proxy port (default: 1080)", OPT_ARGREQ }, 122 {12, 'P', "proxy-port", "Proxy port (default: 1080)", OPT_ARGREQ },
123
124 {13, 'r', "room", "Connect to room (main, pit)", OPT_ARGREQ },
107 }; 125 };
108 126
109 const int optListN = (sizeof(optList) / sizeof(optList[0])); 127 const int optListN = (sizeof(optList) / sizeof(optList[0]));
110 128
111 129
112 void argShowHelp(void) 130 void argShowHelp(void)
113 { 131 {
132 int i;
114 th_print_banner(stdout, th_prog_name, 133 th_print_banner(stdout, th_prog_name,
115 "[options] <username> <password>"); 134 "[options] <username> <password>");
116 135
117 th_args_help(stdout, optList, optListN); 136 th_args_help(stdout, optList, optListN);
137
138 printf("Supported rooms (for option '-r'):\n");
139 for (i = 0; i < nn_room_data_n; i++)
140 {
141 printf(" %s - %s (port %d)\n",
142 nn_room_data[i].name,
143 nn_room_data[i].desc,
144 nn_room_data[i].port);
145 }
118 } 146 }
119 147
120 148
121 BOOL argHandleOpt(const int optN, char *optArg, char *currArg) 149 BOOL argHandleOpt(const int optN, char *optArg, char *currArg)
122 { 150 {
176 204
177 case 12: 205 case 12:
178 optProxyPort = atoi(optArg); 206 optProxyPort = atoi(optArg);
179 break; 207 break;
180 208
209 case 13:
210 {
211 int i;
212 for (i = 0; i < nn_room_data_n; i++)
213 if (!strcasecmp(nn_room_data[i].name, optArg))
214 {
215 optPort = nn_room_data[i].port;
216 return TRUE;
217 }
218
219 THERR("Unsupported room '%s'.\n", optArg);
220 }
221 break;
181 222
182 default: 223 default:
183 THERR("Unknown option '%s'.\n", currArg); 224 THERR("Unknown option '%s'.\n", currArg);
184 return FALSE; 225 return FALSE;
185 } 226 }