Mercurial > hg > nnchat
annotate main.c @ 455:f3362ed90676
Added tag dev-0_9_15 for changeset 423a54af68d4
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 26 May 2012 05:16:27 +0300 |
parents | 733396469e5d |
children | bb65460c7aa2 |
rev | line source |
---|---|
41 | 1 /* |
2 * NNChat - Custom chat client for NewbieNudes.com chatrooms | |
39 | 3 * Written by Matti 'ccr' Hämäläinen |
421 | 4 * (C) Copyright 2008-2012 Tecnic Software productions (TNSP) |
39 | 5 */ |
413 | 6 #include "util.h" |
7 #include "network.h" | |
0 | 8 #include "th_args.h" |
133 | 9 #include "th_config.h" |
415 | 10 #include <errno.h> |
11 #include <time.h> | |
64
6a3a917303e4
Some random cleanups, bring back WinSock support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
12 #ifdef __WIN32 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
13 // Undefine because both windows.h and curses.h #define it |
68
3ab7751fdad1
MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents:
67
diff
changeset
|
14 #undef MOUSE_MOVED |
154
e8f67e344aaf
Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
15 #include <shlwapi.h> |
128
713879a7ca10
Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents:
125
diff
changeset
|
16 #else |
713879a7ca10
Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents:
125
diff
changeset
|
17 #include <sys/wait.h> |
68
3ab7751fdad1
MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents:
67
diff
changeset
|
18 #endif |
217
7ba4e371e9a6
Add Makefile for OpenBSD, and specific #ifdef'd includes for the platform.
Matti Hamalainen <ccr@tnsp.org>
parents:
216
diff
changeset
|
19 #ifdef HAVE_NCURSES_H |
7ba4e371e9a6
Add Makefile for OpenBSD, and specific #ifdef'd includes for the platform.
Matti Hamalainen <ccr@tnsp.org>
parents:
216
diff
changeset
|
20 #include <ncurses.h> |
7ba4e371e9a6
Add Makefile for OpenBSD, and specific #ifdef'd includes for the platform.
Matti Hamalainen <ccr@tnsp.org>
parents:
216
diff
changeset
|
21 #else |
64
6a3a917303e4
Some random cleanups, bring back WinSock support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
22 #include <curses.h> |
217
7ba4e371e9a6
Add Makefile for OpenBSD, and specific #ifdef'd includes for the platform.
Matti Hamalainen <ccr@tnsp.org>
parents:
216
diff
changeset
|
23 #endif |
0 | 24 |
139
c39399725f7b
Define some platform-specific constants.
Matti Hamalainen <ccr@tnsp.org>
parents:
137
diff
changeset
|
25 #ifdef __WIN32 |
160
d3c78f2ef77b
Rename configuration file for Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
156
diff
changeset
|
26 #define SET_CONFIG_FILE "nnchat.txt" |
139
c39399725f7b
Define some platform-specific constants.
Matti Hamalainen <ccr@tnsp.org>
parents:
137
diff
changeset
|
27 #define SET_DIR_SEPARATOR "\\" |
210
4554f9abc686
Change timeout() value for PDCurses/Windows to 0 to improve responsivity.
Matti Hamalainen <ccr@tnsp.org>
parents:
209
diff
changeset
|
28 #define SET_DELAY (0) |
139
c39399725f7b
Define some platform-specific constants.
Matti Hamalainen <ccr@tnsp.org>
parents:
137
diff
changeset
|
29 #else |
c39399725f7b
Define some platform-specific constants.
Matti Hamalainen <ccr@tnsp.org>
parents:
137
diff
changeset
|
30 #define SET_CONFIG_FILE ".nnchat" |
c39399725f7b
Define some platform-specific constants.
Matti Hamalainen <ccr@tnsp.org>
parents:
137
diff
changeset
|
31 #define SET_DIR_SEPARATOR "/" |
228
744c277b57cf
Change timeout delay to lower value.
Matti Hamalainen <ccr@tnsp.org>
parents:
226
diff
changeset
|
32 #define SET_DELAY (5) |
139
c39399725f7b
Define some platform-specific constants.
Matti Hamalainen <ccr@tnsp.org>
parents:
137
diff
changeset
|
33 #endif |
49
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
34 |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
35 #define SET_PROFILE_PREFIX "http://www.newbienudes.com/profile/%s/" |
409
4556174b5be8
Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
408
diff
changeset
|
36 #define SET_NICK_SEPARATOR ':' |
4556174b5be8
Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
408
diff
changeset
|
37 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
38 #define SET_MAX_HISTORY (16) // Command history length |
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
39 #define SET_KEEPALIVE (15*60) // Ping/keepalive period in seconds |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
40 #define SET_MAX_WINDOWS (32) |
0 | 41 |
49
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
42 |
0 | 43 /* Options |
44 */ | |
352
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
45 int optPort = 8005, |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
46 optProxyPort = 1080, |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
47 optProxyType = NN_PROXY_NONE; |
207
e0c085426b91
Change default user color to black (#000000).
Matti Hamalainen <ccr@tnsp.org>
parents:
206
diff
changeset
|
48 int optUserColor = 0x000000; |
96
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
49 char *optServer = "chat.newbienudes.com", |
352
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
50 *optProxyServer = NULL, |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
51 *optUserName = NULL, |
198
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
52 *optUserNameCmd = NULL, |
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
53 *optUserNameEnc = NULL, |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
54 *optPassword = NULL, |
198
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
55 *optPasswordCmd = NULL, |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
56 *optLogFilename = NULL, |
409
4556174b5be8
Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
408
diff
changeset
|
57 *optSite = "NN", |
4556174b5be8
Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
408
diff
changeset
|
58 *optNickSepStr = NULL; |
4556174b5be8
Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
408
diff
changeset
|
59 char optNickSep; |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
60 BOOL optDaemon = FALSE; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
61 FILE *optLogFile = NULL; |
258 | 62 BOOL setIgnoreMode = FALSE; |
162
e59cec397811
Add a debug mode option (commandline) and enable certain features when we are in debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
63 BOOL optDebug = FALSE; |
242
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
64 BOOL optLogEnable = FALSE; |
140
2d2ef5bbcc11
Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
65 |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
66 nn_window_t *chatWindows[SET_MAX_WINDOWS], |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
67 *currWin = NULL; |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
68 WINDOW *mainWin = NULL, |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
69 *statusWin = NULL, |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
70 *editWin = NULL; |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
71 |
265
b9c650db8a6a
Rename variable nnIgnoreList to setIgnoreList.
Matti Hamalainen <ccr@tnsp.org>
parents:
264
diff
changeset
|
72 qlist_t *setIgnoreList = NULL, |
264
4c1c18a388d9
Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents:
258
diff
changeset
|
73 *setIdleMessages = NULL; |
140
2d2ef5bbcc11
Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
74 nn_userhash_t *nnUsers = NULL; |
137
fad8c31e41e6
Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
75 char *setConfigFile = NULL, |
fad8c31e41e6
Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
76 *setBrowser = NULL; |
133 | 77 cfgitem_t *cfg = NULL; |
89
c2d916b340bf
Change some typedef names; Add struct for user list handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
78 |
273 | 79 |
80 /* Logging mode flags | |
81 */ | |
391 | 82 enum |
83 { | |
273 | 84 LOG_FILE = 1, |
85 LOG_WINDOW = 2, | |
86 LOG_STAMP = 4 | |
87 }; | |
88 | |
89 | |
0 | 90 /* Arguments |
91 */ | |
391 | 92 optarg_t optList[] = |
93 { | |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
94 { 0, '?', "help", "Show this help", OPT_NONE }, |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
95 { 1, 'v', "verbose", "Be more verbose", OPT_NONE }, |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
96 { 2, 'p', "port", "Connect to port", OPT_ARGREQ }, |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
97 { 3, 's', "server", "Server to connect to", OPT_ARGREQ }, |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
98 { 4, 'C', "color", "Initial color in RGB hex 000000", OPT_ARGREQ }, |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
99 { 5, 'l', "logfile", "Log filename", OPT_ARGREQ }, |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
100 { 6, 'D', "daemon", "A pseudo-daemon mode for logging", OPT_NONE }, |
352
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
101 { 7, 'f', "force-site", "Force site (default: NN)", OPT_ARGREQ }, |
162
e59cec397811
Add a debug mode option (commandline) and enable certain features when we are in debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
102 { 8, 'd', "debug", "Enable various debug features", OPT_NONE }, |
391 | 103 |
352
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
104 {10, '4', "socks4", "SOCKS4 proxy server", OPT_ARGREQ }, |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
105 {11, 'A', "socks4a", "SOCKS4A proxy server", OPT_ARGREQ }, |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
106 {12, 'P', "proxy-port", "Proxy port (default: 1080)", OPT_ARGREQ }, |
0 | 107 }; |
108 | |
43
40ba8cdcf03a
Cleanups, added a silly morse code conversion mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
109 const int optListN = (sizeof(optList) / sizeof(optList[0])); |
0 | 110 |
111 | |
258 | 112 void argShowHelp(void) |
68
3ab7751fdad1
MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents:
67
diff
changeset
|
113 { |
381
7c28f38cb6dd
Update to use new th-libs from the subrepo.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
114 th_print_banner(stdout, th_prog_name, |
391 | 115 "[options] <username> <password>"); |
116 | |
381
7c28f38cb6dd
Update to use new th-libs from the subrepo.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
117 th_args_help(stdout, optList, optListN); |
68
3ab7751fdad1
MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents:
67
diff
changeset
|
118 } |
3ab7751fdad1
MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents:
67
diff
changeset
|
119 |
3ab7751fdad1
MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents:
67
diff
changeset
|
120 |
0 | 121 BOOL argHandleOpt(const int optN, char *optArg, char *currArg) |
122 { | |
391 | 123 switch (optN) |
124 { | |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
125 case 0: |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
126 argShowHelp(); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
127 exit(0); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
128 break; |
0 | 129 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
130 case 1: |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
131 th_verbosityLevel++; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
132 break; |
391 | 133 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
134 case 2: |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
135 optPort = atoi(optArg); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
136 break; |
0 | 137 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
138 case 3: |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
139 optServer = optArg; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
140 break; |
391 | 141 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
142 case 4: |
391 | 143 if ((optUserColor = th_get_hex_triplet(optArg)) < 0) |
144 { | |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
145 THERR("Invalid color argument '%s', should be a RGB hex triplet '000000'.\n", |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
146 optArg); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
147 return FALSE; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
148 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
149 THMSG(1, "Using color #%06x\n", optUserColor); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
150 break; |
0 | 151 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
152 case 5: |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
153 optLogFilename = optArg; |
242
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
154 optLogEnable = TRUE; |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
155 break; |
0 | 156 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
157 case 7: |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
158 optSite = optArg; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
159 break; |
33
e49ea6febfeb
Cleanups. Added option to specify/fake "site" where logging in from.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
160 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
161 case 6: |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
162 optDaemon = TRUE; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
163 THMSG(1, "Running in pseudo-daemon mode.\n"); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
164 break; |
21 | 165 |
162
e59cec397811
Add a debug mode option (commandline) and enable certain features when we are in debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
166 case 8: |
e59cec397811
Add a debug mode option (commandline) and enable certain features when we are in debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
167 optDebug = TRUE; |
e59cec397811
Add a debug mode option (commandline) and enable certain features when we are in debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
168 THMSG(1, "Debug mode enabled.\n"); |
e59cec397811
Add a debug mode option (commandline) and enable certain features when we are in debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
169 break; |
e59cec397811
Add a debug mode option (commandline) and enable certain features when we are in debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
170 |
352
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
171 |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
172 case 10: |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
173 optProxyServer = optArg; |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
174 optProxyType = NN_PROXY_SOCKS4; |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
175 break; |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
176 |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
177 case 11: |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
178 optProxyServer = optArg; |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
179 optProxyType = NN_PROXY_SOCKS4A; |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
180 break; |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
181 |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
182 case 12: |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
183 optPort = atoi(optArg); |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
184 break; |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
185 |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
186 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
187 default: |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
188 THERR("Unknown option '%s'.\n", currArg); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
189 return FALSE; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
190 } |
391 | 191 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
192 return TRUE; |
0 | 193 } |
194 | |
195 | |
196 BOOL argHandleFile(char *currArg) | |
197 { | |
198
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
198 if (!optUserNameCmd) |
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
199 optUserNameCmd = currArg; |
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
200 else if (!optPasswordCmd) |
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
201 optPasswordCmd = currArg; |
391 | 202 else |
203 { | |
198
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
204 THERR("Username '%s' already specified on commandline!\n", optUserNameCmd); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
205 return FALSE; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
206 } |
391 | 207 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
208 return TRUE; |
0 | 209 } |
210 | |
397 | 211 BOOL str_get_timestamp(char *str, size_t len, const char *fmt) |
156
0a9fe14882dc
Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
212 { |
0a9fe14882dc
Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
213 time_t stamp = time(NULL); |
0a9fe14882dc
Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
214 struct tm *stamp_tm; |
391 | 215 if ((stamp_tm = localtime(&stamp)) != NULL) |
216 { | |
156
0a9fe14882dc
Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
217 strftime(str, len, fmt, stamp_tm); |
0a9fe14882dc
Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
218 return TRUE; |
391 | 219 } |
220 else | |
221 { | |
156
0a9fe14882dc
Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
222 str[0] = 0; |
0a9fe14882dc
Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
223 return FALSE; |
0a9fe14882dc
Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
224 } |
0a9fe14882dc
Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
225 } |
49
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
226 |
226 | 227 |
398 | 228 char * str_trim_left(char *buf) |
229 { | |
230 while (*buf != 0 && th_isspace(*buf)) buf++; | |
231 return buf; | |
232 } | |
233 | |
234 int compareUsername(const void *s1, const void *s2) | |
235 { | |
236 return th_strcasecmp((char *) s1, (char *) s2); | |
237 } | |
238 | |
422 | 239 nn_window_t *nnwin_find(const char *id) |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
240 { |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
241 int i; |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
242 |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
243 for (i = 0; i < SET_MAX_WINDOWS; i++) |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
244 if (chatWindows[i] != NULL && |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
245 chatWindows[i]->id != NULL && |
372
b9f0bdad6285
Use th_strcasecmp() and th_strncasecmp().
Matti Hamalainen <ccr@tnsp.org>
parents:
369
diff
changeset
|
246 th_strcasecmp(id, chatWindows[i]->id) == 0) |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
247 return chatWindows[i]; |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
248 |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
249 return NULL; |
191
4007b9ac7cde
Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
250 } |
4007b9ac7cde
Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
251 |
258 | 252 |
422 | 253 BOOL nnwin_open(const char *name, BOOL curwin) |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
254 { |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
255 int i; |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
256 nn_window_t *res; |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
257 if (name == NULL) |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
258 return FALSE; |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
259 |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
260 if ((res = nn_window_new(name)) == NULL) |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
261 return FALSE; |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
262 |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
263 for (i = 1; i < SET_MAX_WINDOWS; i++) |
391 | 264 if (chatWindows[i] == NULL) |
265 { | |
266 res->num = i; | |
267 chatWindows[i] = res; | |
268 if (curwin) | |
269 currWin = res; | |
270 return TRUE; | |
271 } | |
272 | |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
273 return FALSE; |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
274 } |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
275 |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
276 |
422 | 277 void nnwin_close(nn_window_t *win) |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
278 { |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
279 int i; |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
280 if (win == NULL) return; |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
281 |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
282 for (i = 1; i < SET_MAX_WINDOWS; i++) |
391 | 283 if (chatWindows[i] == win) |
284 { | |
285 chatWindows[i] = NULL; | |
286 nn_window_free(win); | |
287 return; | |
288 } | |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
289 } |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
290 |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
291 |
422 | 292 void nnwin_update_statusline(void) |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
293 { |
156
0a9fe14882dc
Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
294 char tmpStr[128]; |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
295 int i; |
391 | 296 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
297 if (statusWin == NULL) return; |
391 | 298 |
397 | 299 str_get_timestamp(tmpStr, sizeof(tmpStr), "%H:%M:%S"); |
110
8af4072dc31a
Fix Win32/MinGW/PDcurses issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
109
diff
changeset
|
300 |
119
4bc63a535acb
Fix some PDCurses incompatibilities and remove some Win32/PDCurses specific hacks.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
301 wbkgdset(statusWin, COLOR_PAIR(10)); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
302 werase(statusWin); |
391 | 303 |
119
4bc63a535acb
Fix some PDCurses incompatibilities and remove some Win32/PDCurses specific hacks.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
304 wattrset(statusWin, A_BOLD | COLOR_PAIR(11)); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
305 mvwaddstr(statusWin, 0, 1, tmpStr); |
391 | 306 |
119
4bc63a535acb
Fix some PDCurses incompatibilities and remove some Win32/PDCurses specific hacks.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
307 wattrset(statusWin, A_BOLD | COLOR_PAIR(13)); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
308 waddstr(statusWin, " | "); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
309 wattrset(statusWin, A_BOLD | COLOR_PAIR(16)); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
310 waddstr(statusWin, optUserName); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
311 wattrset(statusWin, A_BOLD | COLOR_PAIR(13)); |
29
a27ef0e359b9
Make statusline more informative.
Matti Hamalainen <ccr@tnsp.org>
parents:
28
diff
changeset
|
312 |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
313 wattrset(statusWin, A_BOLD | COLOR_PAIR(13)); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
314 waddstr(statusWin, " | "); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
315 wattrset(statusWin, A_BOLD | COLOR_PAIR(11)); |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
316 snprintf(tmpStr, sizeof(tmpStr), "#%06x", optUserColor); |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
317 waddstr(statusWin, tmpStr); |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
318 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
319 wattrset(statusWin, A_BOLD | COLOR_PAIR(13)); |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
320 waddstr(statusWin, " | WIN: "); |
322
b9c15c57dc8f
Clean up message functions, add new printMsgQ() helper function for messages that should not
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
321 snprintf(tmpStr, sizeof(tmpStr), "%d: %s / %d", |
b9c15c57dc8f
Clean up message functions, add new printMsgQ() helper function for messages that should not
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
322 currWin->num + 1, |
b9c15c57dc8f
Clean up message functions, add new printMsgQ() helper function for messages that should not
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
323 currWin->id != NULL ? currWin->id : "MAIN", |
b9c15c57dc8f
Clean up message functions, add new printMsgQ() helper function for messages that should not
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
324 currWin->pos); |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
325 waddstr(statusWin, tmpStr); |
29
a27ef0e359b9
Make statusline more informative.
Matti Hamalainen <ccr@tnsp.org>
parents:
28
diff
changeset
|
326 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
327 wattrset(statusWin, A_BOLD | COLOR_PAIR(13)); |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
328 waddstr(statusWin, " | "); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
329 wattrset(statusWin, A_BOLD | COLOR_PAIR(11)); |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
330 |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
331 for (i = 0; i < SET_MAX_WINDOWS; i++) |
391 | 332 if (chatWindows[i] != NULL && chatWindows[i]->dirty) |
333 { | |
334 snprintf(tmpStr, sizeof(tmpStr), "%d ", i + 1); | |
335 waddstr(statusWin, tmpStr); | |
336 } | |
29
a27ef0e359b9
Make statusline more informative.
Matti Hamalainen <ccr@tnsp.org>
parents:
28
diff
changeset
|
337 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
338 wrefresh(statusWin); |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
339 } |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
340 |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
341 |
422 | 342 void nnwin_update_editbuf(nn_editbuf_t *buf) |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
343 { |
191
4007b9ac7cde
Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
344 char *tmp; |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
345 if (editWin == NULL || buf == NULL) return; |
32
67ec4073e38c
Check for NULL pointers (fixes "daemon" mode)
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
346 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
347 buf->data[buf->len] = 0; |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
348 tmp = nn_username_decode(th_strdup(buf->data)); |
391 | 349 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
350 werase(editWin); |
391 | 351 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
352 wattrset(editWin, A_NORMAL); |
391 | 353 |
354 if (buf->pos < buf->len) | |
355 { | |
191
4007b9ac7cde
Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
356 waddnstr(editWin, tmp, buf->pos); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
357 wattrset(editWin, A_REVERSE); |
191
4007b9ac7cde
Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
358 waddch(editWin, tmp[buf->pos]); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
359 wattrset(editWin, A_NORMAL); |
191
4007b9ac7cde
Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
360 waddnstr(editWin, tmp + buf->pos + 1, buf->len - buf->pos - 1); |
391 | 361 } |
362 else | |
363 { | |
191
4007b9ac7cde
Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
364 waddnstr(editWin, tmp, buf->len); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
365 wattrset(editWin, A_REVERSE); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
366 waddch(editWin, ' '); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
367 wattrset(editWin, A_NORMAL); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
368 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
369 wrefresh(editWin); |
191
4007b9ac7cde
Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
370 th_free(tmp); |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
371 } |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
372 |
226 | 373 |
422 | 374 int nnwin_print(WINDOW *win, const char *fmt) |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
375 { |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
376 const char *s = fmt; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
377 int col = 0; |
141 | 378 |
391 | 379 while (*s) |
380 { | |
381 if (*s == '½') | |
382 { | |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
383 s++; |
391 | 384 if (*s == '½') |
385 { | |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
386 waddch(win, ((unsigned char) *s) | col); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
387 s++; |
391 | 388 } |
389 else | |
390 { | |
328
a8bda904846c
More work towards a working backbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
391 memcpy(&col, s, sizeof(int)); |
a8bda904846c
More work towards a working backbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
392 s += sizeof(int); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
393 } |
391 | 394 } |
395 else | |
396 { | |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
397 waddch(win, ((unsigned char) *s) | col); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
398 s++; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
399 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
400 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
401 return 0; |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
402 } |
0 | 403 |
62
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
404 |
328
a8bda904846c
More work towards a working backbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
405 #define QPUTCH(ch) th_vputch(&(win->buf), &(win->bufsize), &(win->len), ch) |
a8bda904846c
More work towards a working backbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
406 |
422 | 407 int nnwin_print_buf(nn_window_t *win, const char *fmt) |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
408 { |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
409 const char *s = fmt; |
328
a8bda904846c
More work towards a working backbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
410 int col = 0; |
391 | 411 while (*s) |
412 { | |
413 if (*s == '½') | |
414 { | |
328
a8bda904846c
More work towards a working backbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
415 s++; |
391 | 416 if (*s == '½') |
417 { | |
328
a8bda904846c
More work towards a working backbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
418 QPUTCH(*s); |
a8bda904846c
More work towards a working backbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
419 QPUTCH(*s); |
a8bda904846c
More work towards a working backbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
420 win->chlen++; |
391 | 421 } |
422 else | |
423 { | |
328
a8bda904846c
More work towards a working backbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
424 int val = 0; |
391 | 425 while (*s >= '0' && *s <= '9') |
426 { | |
328
a8bda904846c
More work towards a working backbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
427 val *= 10; |
a8bda904846c
More work towards a working backbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
428 val += (*s - '0'); |
a8bda904846c
More work towards a working backbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
429 s++; |
a8bda904846c
More work towards a working backbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
430 } |
a8bda904846c
More work towards a working backbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
431 if (*s != '½') return -1; |
a8bda904846c
More work towards a working backbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
432 |
a8bda904846c
More work towards a working backbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
433 if (val < 9) |
a8bda904846c
More work towards a working backbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
434 col = A_DIM | COLOR_PAIR(val); |
a8bda904846c
More work towards a working backbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
435 else if (val < 30) |
a8bda904846c
More work towards a working backbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
436 col = A_BOLD | COLOR_PAIR(val - 9); |
a8bda904846c
More work towards a working backbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
437 |
a8bda904846c
More work towards a working backbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
438 QPUTCH('½'); |
a8bda904846c
More work towards a working backbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
439 |
a8bda904846c
More work towards a working backbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
440 if (!th_growbuf(&(win->buf), &(win->bufsize), &(win->len), sizeof(int))) |
a8bda904846c
More work towards a working backbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
441 return -2; |
391 | 442 |
328
a8bda904846c
More work towards a working backbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
443 memcpy(win->buf + win->len, &col, sizeof(int)); |
a8bda904846c
More work towards a working backbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
444 win->len += sizeof(int); |
a8bda904846c
More work towards a working backbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
445 } |
391 | 446 } |
447 else if (*s == '\n') | |
448 { | |
328
a8bda904846c
More work towards a working backbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
449 QPUTCH('\n'); |
a8bda904846c
More work towards a working backbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
450 QPUTCH(0); |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
451 th_ringbuf_add(win->data, win->buf); |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
452 win->buf = NULL; |
328
a8bda904846c
More work towards a working backbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
453 win->chlen = 0; |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
454 win->dirty = TRUE; |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
455 } |
391 | 456 else if (*s != '\r') |
457 { | |
328
a8bda904846c
More work towards a working backbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
458 QPUTCH((unsigned char) *s == 255 ? ' ' : *s); |
a8bda904846c
More work towards a working backbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
459 win->chlen++; |
a8bda904846c
More work towards a working backbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
460 } |
a8bda904846c
More work towards a working backbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
461 |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
462 s++; |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
463 } |
328
a8bda904846c
More work towards a working backbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
464 |
a8bda904846c
More work towards a working backbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
465 return 0; |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
466 } |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
467 |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
468 |
422 | 469 BOOL nnwin_update_main(BOOL force) |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
470 { |
376
1617d0a0c58e
Use getmaxy() instead of getmaxyx().
Matti Hamalainen <ccr@tnsp.org>
parents:
372
diff
changeset
|
471 int h, offs; |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
472 qringbuf_t *buf; |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
473 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
474 // Check pointers |
335
1f4def71b836
Back to simplistic backbuffer implementation due to laziness.
Matti Hamalainen <ccr@tnsp.org>
parents:
334
diff
changeset
|
475 if (mainWin == NULL || currWin == NULL) |
1f4def71b836
Back to simplistic backbuffer implementation due to laziness.
Matti Hamalainen <ccr@tnsp.org>
parents:
334
diff
changeset
|
476 return FALSE; |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
477 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
478 // Check if update is forced or if the window is dirty |
335
1f4def71b836
Back to simplistic backbuffer implementation due to laziness.
Matti Hamalainen <ccr@tnsp.org>
parents:
334
diff
changeset
|
479 if (!force && !currWin->dirty) |
1f4def71b836
Back to simplistic backbuffer implementation due to laziness.
Matti Hamalainen <ccr@tnsp.org>
parents:
334
diff
changeset
|
480 return FALSE; |
1f4def71b836
Back to simplistic backbuffer implementation due to laziness.
Matti Hamalainen <ccr@tnsp.org>
parents:
334
diff
changeset
|
481 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
482 // Compute how many lines from backbuffer fit on the screen |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
483 buf = currWin->data; |
376
1617d0a0c58e
Use getmaxy() instead of getmaxyx().
Matti Hamalainen <ccr@tnsp.org>
parents:
372
diff
changeset
|
484 h = getmaxy(mainWin); |
335
1f4def71b836
Back to simplistic backbuffer implementation due to laziness.
Matti Hamalainen <ccr@tnsp.org>
parents:
334
diff
changeset
|
485 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
486 // Clear and redraw window |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
487 werase(mainWin); |
335
1f4def71b836
Back to simplistic backbuffer implementation due to laziness.
Matti Hamalainen <ccr@tnsp.org>
parents:
334
diff
changeset
|
488 scrollok(mainWin, 1); |
391 | 489 for (offs = buf->size - h - currWin->pos; offs >= 0 && offs < buf->size - currWin->pos && offs < buf->size; offs++) |
490 { | |
335
1f4def71b836
Back to simplistic backbuffer implementation due to laziness.
Matti Hamalainen <ccr@tnsp.org>
parents:
334
diff
changeset
|
491 if (buf->data[offs] != NULL) |
422 | 492 nnwin_print(mainWin, buf->data[offs]); |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
493 } |
391 | 494 |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
495 currWin->dirty = FALSE; |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
496 wrefresh(mainWin); |
391 | 497 return TRUE; |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
498 } |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
499 |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
500 |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
501 int printFile(FILE *outFile, const char *fmt) |
0 | 502 { |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
503 const char *s = fmt; |
391 | 504 |
505 while (*s) | |
506 { | |
507 if (*s == '½') | |
508 { | |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
509 s++; |
391 | 510 if (*s == '½') |
511 { | |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
512 fputc((unsigned char) *s, outFile); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
513 s++; |
391 | 514 } |
515 else | |
516 { | |
74 | 517 while (*s && isdigit((int) *s)) s++; |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
518 if (*s != '½') return -1; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
519 s++; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
520 } |
391 | 521 } |
522 else | |
523 { | |
191
4007b9ac7cde
Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
524 if ((unsigned char) *s == 255) |
4007b9ac7cde
Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
525 fputc(' ', outFile); |
4007b9ac7cde
Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
526 else |
4007b9ac7cde
Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
527 fputc((unsigned char) *s, outFile); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
528 s++; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
529 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
530 } |
391 | 531 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
532 return 0; |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
533 } |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
534 |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
535 void printMsgV(nn_window_t *win, int flags, const char *fmt, va_list ap) |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
536 { |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
537 char tmpStr[128], *buf; |
391 | 538 |
397 | 539 str_get_timestamp(tmpStr, sizeof(tmpStr), "½17½[½11½%H:%M:%S½17½]½0½ "); |
391 | 540 |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
541 buf = th_strdup_vprintf(fmt, ap); |
391 | 542 |
543 if (optLogFile && (flags & LOG_FILE)) | |
544 { | |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
545 if (flags & LOG_STAMP) printFile(optLogFile, tmpStr); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
546 printFile(optLogFile, buf); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
547 fflush(optLogFile); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
548 } |
391 | 549 |
550 if (!optDaemon && (flags & LOG_WINDOW)) | |
551 { | |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
552 nn_window_t *tmp = win != NULL ? win : chatWindows[0]; |
422 | 553 if (flags & LOG_STAMP) nnwin_print_buf(tmp, tmpStr); |
554 nnwin_print_buf(tmp, buf); | |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
555 } |
391 | 556 |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
557 th_free(buf); |
0 | 558 } |
559 | |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
560 void printMsg(nn_window_t *win, const char *fmt, ...) |
100
ed4067c10a8a
Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
561 { |
ed4067c10a8a
Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
562 va_list ap; |
391 | 563 |
100
ed4067c10a8a
Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
564 va_start(ap, fmt); |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
565 printMsgV(win, LOG_STAMP | LOG_WINDOW | LOG_FILE, fmt, ap); |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
566 va_end(ap); |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
567 } |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
568 |
322
b9c15c57dc8f
Clean up message functions, add new printMsgQ() helper function for messages that should not
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
569 void printMsgF(nn_window_t *win, int flags, const char *fmt, ...) |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
570 { |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
571 va_list ap; |
391 | 572 |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
573 va_start(ap, fmt); |
322
b9c15c57dc8f
Clean up message functions, add new printMsgQ() helper function for messages that should not
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
574 printMsgV(win, flags | LOG_STAMP, fmt, ap); |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
575 va_end(ap); |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
576 } |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
577 |
322
b9c15c57dc8f
Clean up message functions, add new printMsgQ() helper function for messages that should not
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
578 void printMsgQ(nn_window_t *win, const char *fmt, ...) |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
579 { |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
580 va_list ap; |
391 | 581 |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
582 va_start(ap, fmt); |
322
b9c15c57dc8f
Clean up message functions, add new printMsgQ() helper function for messages that should not
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
583 printMsgV(win, LOG_STAMP | LOG_WINDOW, fmt, ap); |
100
ed4067c10a8a
Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
584 va_end(ap); |
ed4067c10a8a
Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
585 } |
ed4067c10a8a
Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
586 |
0 | 587 |
223
03af28fb1c38
Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
588 char *errorMessages = NULL; |
03af28fb1c38
Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
589 |
236
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
590 void errorMsgV(const char *fmt, va_list ap) |
96
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
591 { |
385 | 592 char *tmp = th_strdup_vprintf(fmt, ap); |
96
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
593 |
359 | 594 printMsg(NULL, "%s", tmp); |
391 | 595 |
596 if (errorMessages != NULL) | |
597 { | |
223
03af28fb1c38
Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
598 char *tmp2 = th_strdup_printf("%s%s", errorMessages, tmp); |
03af28fb1c38
Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
599 th_free(errorMessages); |
03af28fb1c38
Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
600 th_free(tmp); |
03af28fb1c38
Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
601 errorMessages = tmp2; |
391 | 602 } |
603 else | |
223
03af28fb1c38
Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
604 errorMessages = tmp; |
96
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
605 } |
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
606 |
236
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
607 void errorMsg(const char *fmt, ...) |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
608 { |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
609 va_list ap; |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
610 |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
611 va_start(ap, fmt); |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
612 errorMsgV(fmt, ap); |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
613 va_end(ap); |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
614 } |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
615 |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
616 void errorFunc(struct _nn_conn_t *conn, const char *fmt, va_list ap) |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
617 { |
262
6d48fc4fd421
Shut up some trivial warnings.
Matti Hamalainen <ccr@tnsp.org>
parents:
258
diff
changeset
|
618 (void) conn; |
236
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
619 errorMsgV(fmt, ap); |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
620 } |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
621 |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
622 void messageFunc(struct _nn_conn_t *conn, const char *fmt, va_list ap) |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
623 { |
262
6d48fc4fd421
Shut up some trivial warnings.
Matti Hamalainen <ccr@tnsp.org>
parents:
258
diff
changeset
|
624 (void) conn; |
354
c01e42fc9adb
More work on SOCKS proxy support, should work now.
Matti Hamalainen <ccr@tnsp.org>
parents:
353
diff
changeset
|
625 printMsgV(NULL, LOG_STAMP | LOG_WINDOW | LOG_FILE, fmt, ap); |
236
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
626 } |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
627 |
225
801ac37321f6
Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
628 |
801ac37321f6
Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
629 BOOL checkIgnoreList(const char *name) |
801ac37321f6
Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
630 { |
265
b9c650db8a6a
Rename variable nnIgnoreList to setIgnoreList.
Matti Hamalainen <ccr@tnsp.org>
parents:
264
diff
changeset
|
631 qlist_t *node = setIgnoreList; |
391 | 632 while (node != NULL) |
633 { | |
372
b9f0bdad6285
Use th_strcasecmp() and th_strncasecmp().
Matti Hamalainen <ccr@tnsp.org>
parents:
369
diff
changeset
|
634 if (th_strcasecmp(name, (char *) node->data) == 0) |
225
801ac37321f6
Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
635 return TRUE; |
801ac37321f6
Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
636 node = node->next; |
801ac37321f6
Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
637 } |
801ac37321f6
Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
638 return FALSE; |
801ac37321f6
Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
639 } |
801ac37321f6
Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
640 |
801ac37321f6
Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
641 |
416 | 642 int nnproto_parse_user(nn_conn_t *conn) |
0 | 643 { |
229
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
644 BOOL isMine, isIgnored = FALSE; |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
645 char *name, *msg, *t; |
391 | 646 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
647 // Find start of the message |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
648 name = conn->ptr; |
430
aaadf6cea6be
Better handling of some messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
429
diff
changeset
|
649 t = nn_conn_buf_strstr(conn, "</USER>"); |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
650 if (!t) return 1; |
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
651 *t = 0; |
391 | 652 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
653 // Find end of the message |
430
aaadf6cea6be
Better handling of some messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
429
diff
changeset
|
654 t = nn_conn_buf_strstr(conn, "<MESSAGE>"); |
aaadf6cea6be
Better handling of some messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
429
diff
changeset
|
655 if (!t) return 2; |
aaadf6cea6be
Better handling of some messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
429
diff
changeset
|
656 msg = conn->ptr; |
aaadf6cea6be
Better handling of some messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
429
diff
changeset
|
657 |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
658 t = nn_conn_buf_strstr(conn, "</MESSAGE>"); |
229
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
659 if (!t) return 3; |
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
660 *t = 0; |
391 | 661 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
662 // Decode message string |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
663 msg = nn_decode_str1(msg); |
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
664 if (!msg) return -1; |
391 | 665 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
666 // Decode username |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
667 name = nn_decode_str1(name); |
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
668 if (!name) |
391 | 669 { |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
670 th_free(msg); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
671 return -2; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
672 } |
229
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
673 |
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
674 /* Check if the username is on our ignore list and |
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
675 * that it is not our OWN username! |
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
676 */ |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
677 isMine = strcmp(name, optUserName) == 0; |
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
678 isIgnored = setIgnoreMode && !isMine && checkIgnoreList(name); |
108
f323b137ca08
Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents:
107
diff
changeset
|
679 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
680 // Is it a special control message? |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
681 if (*msg == '/') |
391 | 682 { |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
683 // Ignore room join/leave messages |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
684 if (!optDebug && (strstr(msg, "left the room") || strstr(msg, "joined the room from"))) |
229
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
685 goto done; |
108
f323b137ca08
Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents:
107
diff
changeset
|
686 |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
687 t = nn_strip_tags(msg + 1); |
391 | 688 if (!strncmp(t, "BPRV ", 5)) |
689 { | |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
690 char *in_name, *tmp, *in_msg, *h; |
293 | 691 nn_window_t *win; |
692 h = nn_decode_str2(t + 1); | |
391 | 693 |
418 | 694 // Check type of |
695 if ((isMine = strncmp(t, "BPRV from ", 10)) == 0) | |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
696 in_name = nn_decode_str2(t + 10); |
391 | 697 else |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
698 in_name = nn_decode_str2(t + 8); |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
699 |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
700 for (tmp = in_name; *tmp && *tmp != ':'; tmp++); |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
701 if (tmp[0] != 0 && tmp[1] == ' ') |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
702 in_msg = tmp + 2; |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
703 else |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
704 in_msg = ""; |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
705 *tmp = 0; |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
706 |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
707 isIgnored = setIgnoreMode && checkIgnoreList(in_name); |
422 | 708 win = nnwin_find(in_name); |
391 | 709 |
710 if (win != NULL) | |
711 { | |
388
f45673fe6b23
Log private messages always in the PRV format.
Matti Hamalainen <ccr@tnsp.org>
parents:
385
diff
changeset
|
712 printMsgF(win, isIgnored ? 0 : LOG_WINDOW, |
322
b9c15c57dc8f
Clean up message functions, add new printMsgQ() helper function for messages that should not
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
713 "½5½<½%d½%s½5½>½0½ %s\n", |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
714 isMine ? 14 : 15, isMine ? optUserName : in_name, in_msg); |
388
f45673fe6b23
Log private messages always in the PRV format.
Matti Hamalainen <ccr@tnsp.org>
parents:
385
diff
changeset
|
715 |
f45673fe6b23
Log private messages always in the PRV format.
Matti Hamalainen <ccr@tnsp.org>
parents:
385
diff
changeset
|
716 printMsgF(NULL, LOG_FILE, "½11½%s½0½\n", h); |
391 | 717 } |
718 else | |
719 { | |
322
b9c15c57dc8f
Clean up message functions, add new printMsgQ() helper function for messages that should not
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
720 printMsgF(NULL, isIgnored ? LOG_FILE : (LOG_WINDOW | LOG_FILE), |
b9c15c57dc8f
Clean up message functions, add new printMsgQ() helper function for messages that should not
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
721 "½11½%s½0½\n", h); |
b9c15c57dc8f
Clean up message functions, add new printMsgQ() helper function for messages that should not
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
722 } |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
723 th_free(in_name); |
293 | 724 th_free(h); |
391 | 725 } |
726 else | |
727 { | |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
728 // It's an action (/me) |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
729 char *h = nn_decode_str2(t); |
322
b9c15c57dc8f
Clean up message functions, add new printMsgQ() helper function for messages that should not
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
730 printMsgF(NULL, isIgnored ? LOG_FILE : (LOG_WINDOW | LOG_FILE), |
b9c15c57dc8f
Clean up message functions, add new printMsgQ() helper function for messages that should not
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
731 "½9½* %s½0½\n", h); |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
732 th_free(h); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
733 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
734 th_free(t); |
391 | 735 } |
736 else | |
737 { | |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
738 // It's a normal message |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
739 char *h; |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
740 t = nn_strip_tags(msg); |
97
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
741 h = nn_decode_str2(t); |
322
b9c15c57dc8f
Clean up message functions, add new printMsgQ() helper function for messages that should not
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
742 printMsgF(NULL, isIgnored ? LOG_FILE : (LOG_WINDOW | LOG_FILE), |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
743 "½5½<½%d½%s½5½>½0½ %s\n", isMine ? 14 : 15, name, h); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
744 th_free(h); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
745 th_free(t); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
746 } |
108
f323b137ca08
Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents:
107
diff
changeset
|
747 |
229
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
748 done: |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
749 th_free(msg); |
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
750 th_free(name); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
751 return 0; |
0 | 752 } |
753 | |
754 | |
416 | 755 int nnproto_parse_login(nn_conn_t *conn) |
0 | 756 { |
156
0a9fe14882dc
Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
757 char tmpStr[256]; |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
758 str_get_timestamp(tmpStr, sizeof(tmpStr), "%c"); |
391 | 759 |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
760 if (!nn_conn_buf_strcmp(conn, "FAILURE>")) |
391 | 761 { |
430
aaadf6cea6be
Better handling of some messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
429
diff
changeset
|
762 nn_conn_buf_strstr(conn, "</LOGIN_FAILURE>"); |
437
8e9690a3f973
Fix parsing of LOGIN_{SUCCESS,FAILURE} packets.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
763 nn_conn_buf_strstr(conn, "</USER>"); |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
764 printMsg(NULL, "½1½Login failure½0½ - ½3½%s½0½\n", tmpStr); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
765 return -2; |
391 | 766 } |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
767 else if (!nn_conn_buf_strcmp(conn, "SUCCESS>")) |
391 | 768 { |
430
aaadf6cea6be
Better handling of some messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
429
diff
changeset
|
769 nn_conn_buf_strstr(conn, "</LOGIN_SUCCESS>"); |
437
8e9690a3f973
Fix parsing of LOGIN_{SUCCESS,FAILURE} packets.
Matti Hamalainen <ccr@tnsp.org>
parents:
436
diff
changeset
|
770 nn_conn_buf_strstr(conn, "</USER>"); |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
771 printMsg(NULL, "½2½Login success½0½ - ½3½%s½0½\n", tmpStr); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
772 nn_conn_send_msg(conn, optUserNameEnc, "%2FRequestUserList"); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
773 return 0; |
391 | 774 } |
775 else | |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
776 return 1; |
0 | 777 } |
778 | |
779 | |
416 | 780 int nnproto_parse_add_user(nn_conn_t *conn) |
0 | 781 { |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
782 char *p, *s, *str = conn->ptr; |
297
d34910f1b1e1
Print messages about user leaving or joining the chat in the specific buffer, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
783 nn_window_t *win; |
0 | 784 |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
785 s = nn_conn_buf_strstr(conn, "</ADD_USER>"); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
786 if (!s) return 1; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
787 *s = 0; |
391 | 788 |
97
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
789 p = nn_dbldecode_str(str); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
790 if (!p) return -1; |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
791 |
422 | 792 win = nnwin_find(p); |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
793 nn_userhash_insert(nnUsers, nn_username_encode(p)); |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
794 |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
795 printMsg(NULL, "! ½3½%s½0½ ½2½ADDED.½0½\n", p); |
297
d34910f1b1e1
Print messages about user leaving or joining the chat in the specific buffer, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
796 if (win != NULL) |
d34910f1b1e1
Print messages about user leaving or joining the chat in the specific buffer, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
797 printMsg(win, "! ½3½%s½0½ ½2½joined the chat.½0½\n", p); |
d34910f1b1e1
Print messages about user leaving or joining the chat in the specific buffer, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
798 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
799 th_free(p); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
800 return 0; |
0 | 801 } |
802 | |
803 | |
416 | 804 int nnproto_parse_delete_user(nn_conn_t *conn) |
0 | 805 { |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
806 char *p, *s, *str = conn->ptr; |
297
d34910f1b1e1
Print messages about user leaving or joining the chat in the specific buffer, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
807 nn_window_t *win; |
0 | 808 |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
809 s = nn_conn_buf_strstr(conn, "</DELETE_USER>"); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
810 if (!s) return 1; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
811 *s = 0; |
391 | 812 |
97
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
813 p = nn_dbldecode_str(str); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
814 if (!p) return -1; |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
815 |
422 | 816 win = nnwin_find(p); |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
817 nn_userhash_delete(nnUsers, nn_username_encode(p)); |
107
8037a3a7e491
Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
818 |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
819 printMsg(NULL, "! ½3½%s½0½ ½1½DELETED.½0½\n", p); |
297
d34910f1b1e1
Print messages about user leaving or joining the chat in the specific buffer, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
820 if (win != NULL) |
d34910f1b1e1
Print messages about user leaving or joining the chat in the specific buffer, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
821 printMsg(win, "! ½3½%s½0½ ½1½left the chat.½0½\n", p); |
391 | 822 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
823 th_free(p); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
824 return 0; |
0 | 825 } |
826 | |
827 | |
416 | 828 int nnproto_parse_num_clients(nn_conn_t *conn) |
0 | 829 { |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
830 nn_conn_buf_strstr(conn, "</NUMCLIENTS>"); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
831 return 0; |
0 | 832 } |
833 | |
834 | |
416 | 835 int nnproto_parse_boot(nn_conn_t *conn) |
96
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
836 { |
391 | 837 (void) conn; |
96
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
838 errorMsg("Booted by server.\n"); |
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
839 return -1; |
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
840 } |
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
841 |
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
842 |
391 | 843 typedef struct |
844 { | |
443 | 845 char *name; |
431
a9b20b31cae1
More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
430
diff
changeset
|
846 size_t len; |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
847 int (*handler)(nn_conn_t *); |
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
848 } nn_protocolcmd_t; |
0 | 849 |
850 | |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
851 static nn_protocolcmd_t protoCmds[] = |
391 | 852 { |
431
a9b20b31cae1
More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
430
diff
changeset
|
853 { "<USER>", 0, nnproto_parse_user }, |
a9b20b31cae1
More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
430
diff
changeset
|
854 { "<LOGIN_", 0, nnproto_parse_login }, |
a9b20b31cae1
More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
430
diff
changeset
|
855 { "<DELETE_USER>", 0, nnproto_parse_delete_user }, |
a9b20b31cae1
More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
430
diff
changeset
|
856 { "<ADD_USER>", 0, nnproto_parse_add_user }, |
a9b20b31cae1
More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
430
diff
changeset
|
857 { "<NUMCLIENTS>", 0, nnproto_parse_num_clients }, |
a9b20b31cae1
More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
430
diff
changeset
|
858 { "<BOOT />", 0, nnproto_parse_boot }, |
0 | 859 }; |
860 | |
108
f323b137ca08
Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents:
107
diff
changeset
|
861 static const int nprotoCmds = sizeof(protoCmds) / sizeof(protoCmds[0]); |
0 | 862 |
863 | |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
864 int nn_parse_protocol(nn_conn_t *conn) |
0 | 865 { |
130
352ec3c300e4
A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
866 static BOOL protoCmdsInit = FALSE; |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
867 int i; |
130
352ec3c300e4
A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
868 |
391 | 869 if (!protoCmdsInit) |
870 { | |
130
352ec3c300e4
A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
871 for (i = 0; i < nprotoCmds; i++) |
443 | 872 protoCmds[i].len = strlen(protoCmds[i].name); |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
873 |
130
352ec3c300e4
A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
874 protoCmdsInit = TRUE; |
352ec3c300e4
A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
875 } |
391 | 876 |
877 for (i = 0; i < nprotoCmds; i++) | |
878 { | |
443 | 879 if (!nn_conn_buf_strncmp(conn, protoCmds[i].name, protoCmds[i].len)) |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
880 return protoCmds[i].handler(conn); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
881 } |
162
e59cec397811
Add a debug mode option (commandline) and enable certain features when we are in debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
882 |
391 | 883 if (optDebug) |
884 { | |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
885 printMsg(NULL, "Unknown protocmd: \"%s\"\n", conn->ptr); |
162
e59cec397811
Add a debug mode option (commandline) and enable certain features when we are in debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
886 return 0; |
391 | 887 } |
888 else | |
162
e59cec397811
Add a debug mode option (commandline) and enable certain features when we are in debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
889 return 1; |
0 | 890 } |
891 | |
402
563a70e8a303
Oops, these functions were moved/renamed and were left out from a previous commit. :|
Matti Hamalainen <ccr@tnsp.org>
parents:
401
diff
changeset
|
892 |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
893 int nncmd_open_profile(nn_conn_t *conn, char *name) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
894 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
895 char *uri, *enc_name = nn_encode_str1(name); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
896 #ifdef __WIN32 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
897 HINSTANCE status; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
898 #else |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
899 int status; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
900 int fds[2]; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
901 pid_t pid; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
902 #endif |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
903 (void) conn; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
904 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
905 printMsg(currWin, "Opening profile for: '%s'\n", name); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
906 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
907 #ifdef __WIN32 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
908 uri = th_strdup_printf(SET_PROFILE_PREFIX, enc_name); |
442 | 909 status = ShellExecute(NULL, "open", uri, NULL, NULL, SW_SHOWNA); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
910 if (status <= (HINSTANCE) 32) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
911 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
912 printMsgQ(currWin, "Could not launch default web browser: %d\n", status); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
913 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
914 #else |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
915 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
916 uri = th_strdup_printf("openurl(" SET_PROFILE_PREFIX ",new-tab)", enc_name); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
917 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
918 if (pipe(fds) == -1) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
919 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
920 int ret = errno; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
921 printMsgQ(currWin, "Could not open process communication pipe! (%d, %s)\n", ret, strerror(ret)); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
922 return 0; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
923 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
924 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
925 if ((pid = fork()) < 0) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
926 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
927 printMsgQ(currWin, "Could not create sub-process!\n"); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
928 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
929 else if (pid == 0) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
930 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
931 dup2(fds[1], STDOUT_FILENO); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
932 dup2(fds[0], STDERR_FILENO); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
933 execlp(setBrowser, setBrowser, "-remote", uri, (void *)NULL); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
934 _exit(errno); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
935 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
936 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
937 wait(&status); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
938 #endif |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
939 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
940 th_free(uri); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
941 th_free(enc_name); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
942 return 0; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
943 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
944 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
945 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
946 int nncmd_ignore(nn_conn_t *conn, char *name) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
947 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
948 (void) conn; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
949 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
950 if (name[0]) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
951 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
952 // Add or remove someone to/from ignore |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
953 qlist_t *user = th_llist_find_func(setIgnoreList, name, compareUsername); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
954 if (user != NULL) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
955 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
956 printMsgQ(currWin, "Removed user '%s' from ignore.\n", name); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
957 th_llist_delete_node(&setIgnoreList, user); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
958 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
959 else |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
960 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
961 printMsgQ(currWin, "Now ignoring '%s'.\n", name); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
962 th_llist_append(&setIgnoreList, th_strdup(name)); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
963 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
964 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
965 else |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
966 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
967 // Just list whomever is in ignore now |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
968 qlist_t *user = setIgnoreList; |
431
a9b20b31cae1
More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
430
diff
changeset
|
969 size_t nuser = th_llist_length(setIgnoreList); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
970 char *result = th_strdup_printf("Users ignored (%d): ", nuser); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
971 while (user != NULL) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
972 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
973 if (user->data != NULL) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
974 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
975 th_pstr_printf(&result, "%s'%s'", result, (char *) user->data); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
976 if (--nuser > 0) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
977 th_pstr_printf(&result, "%s, ", result); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
978 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
979 user = user->next; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
980 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
981 printMsgQ(currWin, "%s\n", result); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
982 th_free(result); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
983 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
984 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
985 return 0; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
986 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
987 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
988 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
989 int nncmd_set_color(nn_conn_t *conn, char *arg) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
990 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
991 int val; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
992 (void) conn; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
993 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
994 if ((val = th_get_hex_triplet(arg)) < 0) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
995 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
996 printMsgQ(currWin, "Invalid color value '%s'\n", arg); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
997 return 1; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
998 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
999 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1000 optUserColor = val; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1001 printMsgQ(currWin, "Setting color to #%06x\n", optUserColor); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1002 nn_conn_send_msg_v(conn, optUserNameEnc, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1003 return 0; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1004 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1005 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1006 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1007 int nncmd_open_query(nn_conn_t *conn, char *name) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1008 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1009 (void) conn; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1010 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1011 if (name[0]) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1012 { |
446
3396acd40147
Rename and remove some functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1013 nn_user_t *user = nn_userhash_find(nnUsers, nn_username_encode(name)); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1014 if (user != NULL) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1015 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1016 name = nn_username_decode(th_strdup(user->name)); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1017 printMsgQ(currWin, "Opening PRV query for '%s'.\n", name); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1018 if (nnwin_open(name, TRUE)) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1019 printMsgQ(currWin, "In PRV query with '%s'.\n", name); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1020 th_free(name); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1021 return 0; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1022 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1023 else |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1024 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1025 printMsgQ(currWin, "Could not find username '%s'.\n", name); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1026 return 1; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1027 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1028 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1029 else |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1030 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1031 printMsgQ(currWin, "Usage: /query username\n"); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1032 printMsgQ(currWin, "To close a PRV query, use /close [username]\n"); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1033 printMsgQ(currWin, "/close without username will close the current PRV window, if any.\n"); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1034 return 1; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1035 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1036 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1037 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1038 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1039 int nncmd_close_query(nn_conn_t *conn, char *name) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1040 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1041 (void) conn; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1042 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1043 if (name[0]) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1044 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1045 nn_window_t *win = nnwin_find(name); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1046 if (win != NULL) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1047 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1048 nnwin_close(win); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1049 printMsgQ(currWin, "Closed PRV query to '%s'.\n", name); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1050 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1051 else |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1052 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1053 printMsgQ(currWin, "No PRV query by name '%s'.\n", name); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1054 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1055 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1056 else |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1057 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1058 if (currWin != chatWindows[0]) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1059 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1060 nnwin_close(currWin); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1061 currWin = chatWindows[0]; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1062 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1063 else |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1064 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1065 printMsgQ(currWin, "Usage: /close [username]\n"); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1066 printMsgQ(currWin, "/close without username will close the current PRV window. if any.\n"); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1067 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1068 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1069 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1070 return 0; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1071 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1072 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1073 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1074 int nncmd_window_info(nn_conn_t *conn, char *arg) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1075 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1076 (void) conn; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1077 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1078 if (arg[0]) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1079 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1080 int val = atoi(arg); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1081 if (val >= 1 && val < SET_MAX_WINDOWS) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1082 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1083 if (chatWindows[val - 1] != NULL) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1084 currWin = chatWindows[val - 1]; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1085 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1086 else |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1087 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1088 printMsgQ(currWin, "Invalid window number '%s'\n", arg); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1089 return 1; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1090 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1091 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1092 else |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1093 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1094 printMsgQ(currWin, "Window : #%d\n", currWin->num); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1095 printMsgQ(currWin, "ID : %s\n", currWin->id); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1096 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1097 return 0; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1098 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1099 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1100 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1101 int nncmd_list_all_users(nn_conn_t *conn, char *buf) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1102 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1103 (void) buf; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1104 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1105 // Alias /listallusers |
425 | 1106 return nn_conn_send_msg(conn, optUserNameEnc, "%2Flistallusers"); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1107 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1108 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1109 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1110 int nncmd_names(nn_conn_t *conn, char *buf) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1111 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1112 (void) conn; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1113 (void) buf; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1114 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1115 printMsgQ(currWin, "Not implemented yet.\n"); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1116 return 0; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1117 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1118 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1119 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1120 int nncmd_save_config(nn_conn_t *conn, char *buf) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1121 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1122 (void) conn; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1123 (void) buf; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1124 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1125 FILE *cfgfile = fopen(setConfigFile, "w"); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1126 if (cfgfile == NULL) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1127 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1128 printMsgQ(currWin, "Could not create configuration to file '%s': %s\n", |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1129 setConfigFile, strerror(errno)); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1130 return 0; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1131 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1132 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1133 printMsgQ(currWin, "Configuration saved in file '%s', res=%d\n", |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1134 setConfigFile, |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1135 th_cfg_write(cfgfile, setConfigFile, cfg)); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1136 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1137 fclose(cfgfile); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1138 return 0; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1139 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1140 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1141 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1142 enum |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1143 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1144 CMDARG_NONE, |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1145 CMDARG_STRING, |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1146 CMDARG_OPTIONAL, |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1147 CMDARG_NICK, |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1148 }; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1149 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1150 typedef struct |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1151 { |
443 | 1152 char *name; |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1153 int flags; |
431
a9b20b31cae1
More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
430
diff
changeset
|
1154 size_t len; |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1155 int (*handler)(nn_conn_t *, char *buf); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1156 } nn_usercmd_t; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1157 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1158 |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1159 static nn_usercmd_t userCmdsTable[] = |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1160 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1161 // Server side commands, we just implement completion |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1162 { "/me", CMDARG_STRING, 0, NULL }, |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1163 { "/status", CMDARG_STRING, 0, NULL }, |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1164 { "/list", CMDARG_NONE, 0, nncmd_list_all_users }, |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1165 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1166 // List internal username list |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1167 { "/who", CMDARG_NONE, 0, nncmd_names }, |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1168 { "/names", CMDARG_NONE, 0, nncmd_names }, |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1169 |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1170 { "/w", CMDARG_NICK, 0, nncmd_open_profile }, |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1171 { "/profile", CMDARG_NICK, 0, nncmd_open_profile }, |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1172 |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1173 { "/query", CMDARG_NICK, 0, nncmd_open_query }, |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1174 { "/close", CMDARG_OPTIONAL, 0, nncmd_close_query }, |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1175 { "/win", CMDARG_OPTIONAL, 0, nncmd_window_info }, |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1176 |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1177 { "/ignore", CMDARG_NICK, 0, nncmd_ignore }, |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1178 { "/color", CMDARG_STRING, 0, nncmd_set_color }, |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1179 { "/save", CMDARG_NONE, 0, nncmd_save_config }, |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1180 }; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1181 |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1182 static qlist_t *userCmds = NULL; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1183 |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1184 |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1185 void nn_usercmd_init() |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1186 { |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1187 size_t i; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1188 for (i = 0; i < sizeof(userCmdsTable) / sizeof(userCmdsTable[0]); i++) |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1189 { |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1190 th_llist_append(&userCmds, &userCmdsTable[i]); |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1191 userCmdsTable[i].len = strlen(userCmdsTable[i].name); |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1192 } |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1193 } |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1194 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1195 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1196 int nn_handle_command(nn_conn_t *conn, char *buf) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1197 { |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1198 qlist_t *curr; |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1199 |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1200 for (curr = userCmds; curr != NULL; curr = curr->next) |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1201 { |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1202 nn_usercmd_t *cmd = curr->data; |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1203 |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1204 if (!th_strncasecmp(buf, cmd->name, cmd->len)) |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1205 { |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1206 char *nbuf = str_trim_left(buf + cmd->len); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1207 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1208 switch (cmd->flags) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1209 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1210 case CMDARG_NICK: |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1211 case CMDARG_STRING: |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1212 if (!nbuf[0]) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1213 { |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1214 printMsgQ(currWin, "Command %s requires an argument.\n", cmd->name); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1215 return 1; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1216 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1217 break; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1218 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1219 case CMDARG_NONE: |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1220 if (nbuf[0]) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1221 { |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1222 printMsgQ(currWin, "Command %s does not take arguments.\n", cmd->name); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1223 return 1; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1224 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1225 break; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1226 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1227 case CMDARG_OPTIONAL: |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1228 break; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1229 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1230 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1231 // Check if there is a handler function |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1232 if (cmd->handler) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1233 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1234 // Internal commands have a handler |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1235 return cmd->handler(conn, nbuf); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1236 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1237 else |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1238 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1239 // Server-side commands are just pass-through here |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1240 char *tmp = nn_dblencode_str(buf); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1241 BOOL result; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1242 if (tmp == NULL) return -2; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1243 result = nn_conn_send_msg(conn, optUserNameEnc, tmp); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1244 th_free(tmp); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1245 return result ? 0 : -1; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1246 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1247 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1248 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1249 |
444 | 1250 printMsgQ(currWin, "Unknown command: %s\n", buf); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1251 return 1; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1252 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1253 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1254 |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1255 static nn_usercmd_t *nn_usercmd_match_do(qlist_t *list, const char *pattern, size_t len) |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1256 { |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1257 qlist_t *node; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1258 for (node = list; node != NULL; node = node->next) |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1259 { |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1260 nn_usercmd_t *cmd = node->data; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1261 if (len <= strlen(cmd->name) && th_strncasecmp(cmd->name, pattern, len) == 0) |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1262 return cmd; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1263 } |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1264 return NULL; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1265 } |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1266 |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1267 |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1268 nn_usercmd_t *nn_usercmd_match(qlist_t *list, const char *pattern, const char *current, BOOL again) |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1269 { |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1270 nn_usercmd_t *curr; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1271 size_t len; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1272 |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1273 if (list == NULL || pattern == NULL) return NULL; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1274 |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1275 len = strlen(pattern); |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1276 |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1277 if (current != NULL) |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1278 { |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1279 qlist_t *node; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1280 for (node = list; node != NULL; node = node->next) |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1281 { |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1282 curr = node->data; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1283 if (th_strcasecmp(curr->name, current) == 0) |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1284 { |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1285 if (again) |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1286 return curr; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1287 |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1288 if ((curr = nn_usercmd_match_do(node->next, pattern, len)) != NULL) |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1289 return curr; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1290 } |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1291 } |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1292 } |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1293 |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1294 if ((curr = nn_usercmd_match_do(list, pattern, len)) != NULL) |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1295 return curr; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1296 |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1297 return NULL; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1298 } |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1299 |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1300 |
410
7ea78f4a4d23
Rename input handling main function.
Matti Hamalainen <ccr@tnsp.org>
parents:
409
diff
changeset
|
1301 int nn_handle_input(nn_conn_t *conn, char *buf, size_t bufLen) |
0 | 1302 { |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1303 BOOL result; |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1304 char *tmp; |
391 | 1305 |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1306 // Trim right side |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1307 if (bufLen > 0) buf[--bufLen] = 0; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1308 while (bufLen > 0 && th_isspace(buf[bufLen - 1])) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1309 buf[--bufLen] = 0; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1310 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1311 if (buf[0] == 0) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1312 return 1; |
258 | 1313 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1314 // Decode completed usernames |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1315 nn_username_decode(buf); |
391 | 1316 |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1317 // Check for commands |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1318 if (buf[0] == '/') |
426 | 1319 return nn_handle_command(conn, buf); |
133 | 1320 |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1321 // If current window is not the main room window, send private |
391 | 1322 if (currWin != chatWindows[0]) |
1323 { | |
1324 if (currWin->id != NULL) | |
1325 { | |
431
a9b20b31cae1
More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
430
diff
changeset
|
1326 char *msg = th_strdup_printf("/prv -to %s -msg %s", currWin->id, buf); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1327 if (msg == NULL) return -3; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1328 tmp = nn_dblencode_str(msg); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1329 if (tmp == NULL) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1330 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1331 th_free(msg); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1332 return -2; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1333 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1334 result = nn_conn_send_msg(conn, optUserNameEnc, tmp); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1335 th_free(tmp); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1336 th_free(msg); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1337 return result ? 0 : -1; |
391 | 1338 } |
1339 else | |
1340 { | |
322
b9c15c57dc8f
Clean up message functions, add new printMsgQ() helper function for messages that should not
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
1341 printMsgQ(NULL, "No target set, exiting prv mode.\n"); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1342 return 1; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1343 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1344 } |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
1345 |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1346 // Send double-encoded message |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1347 tmp = nn_dblencode_str(buf); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1348 if (tmp == NULL) return -2; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1349 result = nn_conn_send_msg(conn, optUserNameEnc, tmp); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1350 th_free(tmp); |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
1351 return result ? 0 : -1; |
0 | 1352 } |
1353 | |
405 | 1354 |
422 | 1355 void nnwin_close_windows(void) |
155
0720ca51673e
Plug some minor "memory leaks" related to curses.
Matti Hamalainen <ccr@tnsp.org>
parents:
154
diff
changeset
|
1356 { |
0720ca51673e
Plug some minor "memory leaks" related to curses.
Matti Hamalainen <ccr@tnsp.org>
parents:
154
diff
changeset
|
1357 if (mainWin) delwin(mainWin); |
0720ca51673e
Plug some minor "memory leaks" related to curses.
Matti Hamalainen <ccr@tnsp.org>
parents:
154
diff
changeset
|
1358 if (statusWin) delwin(statusWin); |
0720ca51673e
Plug some minor "memory leaks" related to curses.
Matti Hamalainen <ccr@tnsp.org>
parents:
154
diff
changeset
|
1359 if (editWin) delwin(editWin); |
0720ca51673e
Plug some minor "memory leaks" related to curses.
Matti Hamalainen <ccr@tnsp.org>
parents:
154
diff
changeset
|
1360 } |
0 | 1361 |
405 | 1362 |
422 | 1363 BOOL nnwin_initialize_windows(void) |
46
65b1ac6a1e2e
Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
1364 { |
118
9e7f52878725
Use getmaxyx() instead of LINES and COLS globals as recommended by curses programming guidelines.
Matti Hamalainen <ccr@tnsp.org>
parents:
117
diff
changeset
|
1365 int w, h; |
9e7f52878725
Use getmaxyx() instead of LINES and COLS globals as recommended by curses programming guidelines.
Matti Hamalainen <ccr@tnsp.org>
parents:
117
diff
changeset
|
1366 |
9e7f52878725
Use getmaxyx() instead of LINES and COLS globals as recommended by curses programming guidelines.
Matti Hamalainen <ccr@tnsp.org>
parents:
117
diff
changeset
|
1367 getmaxyx(stdscr, h, w); |
391 | 1368 |
422 | 1369 nnwin_close_windows(); |
118
9e7f52878725
Use getmaxyx() instead of LINES and COLS globals as recommended by curses programming guidelines.
Matti Hamalainen <ccr@tnsp.org>
parents:
117
diff
changeset
|
1370 |
209
e1bfd5227a24
Use curses subwin(stdscr, ...) instead of newwin().
Matti Hamalainen <ccr@tnsp.org>
parents:
208
diff
changeset
|
1371 mainWin = subwin(stdscr, h - 4, w, 0, 0); |
e1bfd5227a24
Use curses subwin(stdscr, ...) instead of newwin().
Matti Hamalainen <ccr@tnsp.org>
parents:
208
diff
changeset
|
1372 statusWin = subwin(stdscr, 1, w, h - 4, 0); |
e1bfd5227a24
Use curses subwin(stdscr, ...) instead of newwin().
Matti Hamalainen <ccr@tnsp.org>
parents:
208
diff
changeset
|
1373 editWin = subwin(stdscr, 3, w, h - 3, 0); |
391 | 1374 |
318
4acfcca39105
Don't THERR() in initializeWindows(), just return FALSE.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
1375 if (mainWin == NULL || statusWin == NULL || editWin == NULL) |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1376 return FALSE; |
318
4acfcca39105
Don't THERR() in initializeWindows(), just return FALSE.
Matti Hamalainen <ccr@tnsp.org>
parents:
316
diff
changeset
|
1377 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1378 return TRUE; |
46
65b1ac6a1e2e
Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
1379 } |
65b1ac6a1e2e
Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
1380 |
405 | 1381 |
422 | 1382 void nnwin_update_all(void) |
179
8c493b5671bd
Add separate updateWindows() function.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
1383 { |
8c493b5671bd
Add separate updateWindows() function.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
1384 if (mainWin) redrawwin(mainWin); |
8c493b5671bd
Add separate updateWindows() function.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
1385 if (statusWin) redrawwin(statusWin); |
8c493b5671bd
Add separate updateWindows() function.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
1386 if (editWin) redrawwin(editWin); |
8c493b5671bd
Add separate updateWindows() function.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
1387 } |
113
2a53156e7e12
Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
1388 |
405 | 1389 |
449
7d9fa9f7caf1
Rename tab completion functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
1390 static void nn_tabcomplete_replace(nn_editbuf_t *buf, size_t *pi, const size_t startPos, const size_t endPos, char *c) |
447
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1391 { |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1392 size_t i; |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1393 |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1394 for (i = startPos; i <= endPos; i++) |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1395 nn_editbuf_delete(buf, startPos); |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1396 |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1397 for (i = startPos; *c; i++, c++) |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1398 nn_editbuf_insert(buf, i, *c); |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1399 |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1400 *pi = i; |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1401 } |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1402 |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1403 |
449
7d9fa9f7caf1
Rename tab completion functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
1404 static void nn_tabcomplete_finish(nn_editbuf_t *buf, char **previous, const size_t startPos, const char *name) |
447
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1405 { |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1406 nn_editbuf_setpos(buf, startPos + 1 + strlen(name)); |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1407 th_free(*previous); |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1408 *previous = th_strdup(name); |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1409 } |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1410 |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1411 |
449
7d9fa9f7caf1
Rename tab completion functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
1412 BOOL nn_tabcomplete_buffer(nn_editbuf_t *buf) |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
1413 { |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1414 static char *previous = NULL, *pattern = NULL; |
451 | 1415 char *str = buf->data; |
429
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1416 BOOL again = FALSE, hasSeparator = FALSE, |
447
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1417 hasSpace, newPattern = FALSE, isCommand; |
431
a9b20b31cae1
More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
430
diff
changeset
|
1418 size_t endPos, startPos = buf->pos; |
107
8037a3a7e491
Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
1419 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1420 // previous word |
391 | 1421 if (startPos >= 2 && str[startPos - 1] == ' ' && str[startPos - 2] != ' ') |
1422 { | |
113
2a53156e7e12
Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
1423 startPos -= 2; |
2a53156e7e12
Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
1424 endPos = startPos; |
2a53156e7e12
Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
1425 while (startPos > 0 && str[startPos - 1] != ' ') startPos--; |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1426 } |
391 | 1427 else |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1428 // middle of a word, new pattern |
404
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1429 if (startPos < buf->len && str[startPos] != ' ') |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1430 { |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1431 endPos = startPos; |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1432 while (startPos > 0 && str[startPos - 1] != ' ') startPos--; |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1433 while (endPos < buf->len - 1 && str[endPos + 1] != ' ') endPos++; |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1434 newPattern = TRUE; |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1435 } |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1436 else |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1437 // previous word, new pattern |
404
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1438 if (startPos >= 1 && str[startPos - 1] != ' ') |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1439 { |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1440 startPos -= 1; |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1441 endPos = startPos; |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1442 while (startPos > 0 && str[startPos - 1] != ' ') startPos--; |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1443 newPattern = TRUE; |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1444 } |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1445 else |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1446 return FALSE; |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1447 |
429
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1448 // Check if this is a command completion |
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1449 isCommand = (str[0] == '/' && startPos == 0); |
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1450 |
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1451 if (!isCommand && str[endPos] == optNickSep) |
391 | 1452 { |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1453 endPos--; |
391 | 1454 if (startPos > 0) |
113
2a53156e7e12
Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
1455 return FALSE; |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1456 hasSeparator = TRUE; |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1457 } |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1458 |
451 | 1459 hasSpace = (buf->pos > 0 && str[buf->pos - 1] == ' ') || |
447
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1460 (buf->pos <= buf->len && str[buf->pos] == ' '); |
391 | 1461 |
1462 if (newPattern) | |
1463 { | |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1464 // Get pattern, check if it matches previous pattern and set 'again' flag |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1465 char *npattern = nn_editbuf_get_string(buf, startPos, endPos); |
372
b9f0bdad6285
Use th_strcasecmp() and th_strncasecmp().
Matti Hamalainen <ccr@tnsp.org>
parents:
369
diff
changeset
|
1466 if (pattern && npattern && th_strcasecmp(npattern, pattern) == 0) |
116
741e45592522
Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
1467 again = TRUE; |
391 | 1468 |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1469 th_free(pattern); |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1470 pattern = npattern; |
391 | 1471 |
1472 if (!again) | |
1473 { | |
116
741e45592522
Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
1474 th_free(previous); |
741e45592522
Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
1475 previous = NULL; |
741e45592522
Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
1476 } |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1477 } |
116
741e45592522
Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
1478 |
429
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1479 if (!pattern) |
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1480 return FALSE; |
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1481 |
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1482 if (isCommand) |
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1483 { |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1484 nn_usercmd_t *cmd = nn_usercmd_match(userCmds, pattern, previous, again); |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1485 if (cmd) |
429
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1486 { |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1487 size_t i; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1488 nn_tabcomplete_replace(buf, &i, startPos, endPos, cmd->name); |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1489 |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1490 if (!hasSpace) |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1491 nn_editbuf_insert(buf, i++, ' '); |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1492 |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1493 nn_tabcomplete_finish(buf, &previous, startPos, cmd->name); |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1494 return TRUE; |
429
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1495 } |
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1496 } |
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1497 else |
391 | 1498 { |
446
3396acd40147
Rename and remove some functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1499 nn_user_t *user = nn_userhash_match(nnUsers, pattern, previous, again); |
107
8037a3a7e491
Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
1500 |
391 | 1501 if (user) |
1502 { | |
431
a9b20b31cae1
More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
430
diff
changeset
|
1503 size_t i; |
449
7d9fa9f7caf1
Rename tab completion functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
1504 nn_tabcomplete_replace(buf, &i, startPos, endPos, user->name); |
107
8037a3a7e491
Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
1505 |
391 | 1506 if (!hasSeparator && startPos == 0) |
1507 { | |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1508 nn_editbuf_insert(buf, i++, optNickSep); |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1509 startPos++; |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1510 } |
447
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1511 else |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1512 if (hasSeparator) |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1513 startPos++; |
447
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1514 |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1515 if (!hasSpace) |
113
2a53156e7e12
Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
1516 nn_editbuf_insert(buf, i++, ' '); |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1517 |
449
7d9fa9f7caf1
Rename tab completion functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
1518 nn_tabcomplete_finish(buf, &previous, startPos, user->name); |
113
2a53156e7e12
Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
1519 return TRUE; |
107
8037a3a7e491
Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
1520 } |
8037a3a7e491
Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
1521 } |
391 | 1522 |
113
2a53156e7e12
Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
1523 return FALSE; |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
1524 } |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
1525 |
405 | 1526 |
252
dcf78e2c458c
Improve log filename format parsing; Add special casing for handling of function keys for certain terminal types.
Matti Hamalainen <ccr@tnsp.org>
parents:
247
diff
changeset
|
1527 #define VPUTCH(CH) th_vputch(&bufData, &bufSize, &bufLen, CH) |
242
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1528 #define VPUTS(STR) th_vputs(&bufData, &bufSize, &bufLen, STR) |
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1529 |
239
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1530 char *logParseFilename(const char *fmt, int id) |
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1531 { |
252
dcf78e2c458c
Improve log filename format parsing; Add special casing for handling of function keys for certain terminal types.
Matti Hamalainen <ccr@tnsp.org>
parents:
247
diff
changeset
|
1532 size_t bufSize = strlen(fmt) + TH_BUFGROW, bufLen = 0; |
dcf78e2c458c
Improve log filename format parsing; Add special casing for handling of function keys for certain terminal types.
Matti Hamalainen <ccr@tnsp.org>
parents:
247
diff
changeset
|
1533 char *bufData = th_malloc(bufSize); |
dcf78e2c458c
Improve log filename format parsing; Add special casing for handling of function keys for certain terminal types.
Matti Hamalainen <ccr@tnsp.org>
parents:
247
diff
changeset
|
1534 char tmpBuf[32]; |
239
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1535 const char *s = fmt; |
391 | 1536 |
1537 while (*s) | |
1538 { | |
1539 if (*s == '%') | |
1540 { | |
239
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1541 s++; |
391 | 1542 switch (*s) |
1543 { | |
1544 case 'i': | |
1545 snprintf(tmpBuf, sizeof(tmpBuf), "%05d", id); | |
1546 VPUTS(tmpBuf); | |
1547 break; | |
252
dcf78e2c458c
Improve log filename format parsing; Add special casing for handling of function keys for certain terminal types.
Matti Hamalainen <ccr@tnsp.org>
parents:
247
diff
changeset
|
1548 |
391 | 1549 case 'd': |
1550 snprintf(tmpBuf, sizeof(tmpBuf), "%d", id); | |
1551 VPUTS(tmpBuf); | |
1552 break; | |
252
dcf78e2c458c
Improve log filename format parsing; Add special casing for handling of function keys for certain terminal types.
Matti Hamalainen <ccr@tnsp.org>
parents:
247
diff
changeset
|
1553 |
391 | 1554 case '%': |
1555 VPUTCH('%'); | |
1556 break; | |
239
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1557 } |
242
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1558 s++; |
391 | 1559 } |
1560 else | |
1561 { | |
242
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1562 VPUTCH(*s); |
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1563 s++; |
239
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1564 } |
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1565 } |
391 | 1566 |
242
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1567 VPUTCH(0); |
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1568 return bufData; |
239
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1569 } |
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1570 |
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1571 |
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1572 BOOL logFileOpen(void) |
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1573 { |
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1574 char *filename; |
391 | 1575 |
242
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1576 if (optLogFilename == NULL || !optLogEnable) |
239
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1577 return FALSE; |
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1578 |
242
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1579 filename = logParseFilename(optLogFilename, optPort); |
239
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1580 |
391 | 1581 if ((optLogFile = fopen(filename, "a")) == NULL) |
1582 { | |
242
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1583 errorMsg("Could not open logfile '%s' for appending!\n", filename); |
239
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1584 th_free(filename); |
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1585 return FALSE; |
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1586 } |
391 | 1587 |
242
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1588 th_free(filename); |
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1589 |
239
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1590 return TRUE; |
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1591 } |
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1592 |
405 | 1593 |
242
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1594 void logFileClose(void) |
239
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1595 { |
391 | 1596 if (optLogFile) |
1597 { | |
242
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1598 fclose(optLogFile); |
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1599 optLogFile = NULL; |
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1600 } |
239
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1601 } |
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1602 |
405 | 1603 |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1604 char *promptRequester(WINDOW *win, const char *info, BOOL allowEmpty) |
196
edd5ce3e5399
Add simplistic username/password requester if none given on commandline or config file.
Matti Hamalainen <ccr@tnsp.org>
parents:
195
diff
changeset
|
1605 { |
211
c40329e95445
Trim both left and right side of username+password prompt input. Also allow empty passwords, to be able to use guest accounts.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
1606 char tmpBuf[512], *ptr; |
431
a9b20b31cae1
More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
430
diff
changeset
|
1607 size_t pos; |
275
66b90d71548b
Improve interactive prompts, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
1608 int curVis = curs_set(1); |
196
edd5ce3e5399
Add simplistic username/password requester if none given on commandline or config file.
Matti Hamalainen <ccr@tnsp.org>
parents:
195
diff
changeset
|
1609 |
275
66b90d71548b
Improve interactive prompts, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
1610 echo(); |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1611 waddstr(win, info); |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1612 wgetnstr(win, tmpBuf, sizeof(tmpBuf) - 1); |
275
66b90d71548b
Improve interactive prompts, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
1613 noecho(); |
66b90d71548b
Improve interactive prompts, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
1614 if (curVis != ERR) |
66b90d71548b
Improve interactive prompts, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
1615 curs_set(curVis); |
391 | 1616 |
401
3f20ac9a9e1d
Using th_isspace() should be enough to detect \r and \n.
Matti Hamalainen <ccr@tnsp.org>
parents:
400
diff
changeset
|
1617 for (pos = strlen(tmpBuf) - 1; pos > 0 && th_isspace(tmpBuf[pos]); pos--) |
211
c40329e95445
Trim both left and right side of username+password prompt input. Also allow empty passwords, to be able to use guest accounts.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
1618 tmpBuf[pos] = 0; |
196
edd5ce3e5399
Add simplistic username/password requester if none given on commandline or config file.
Matti Hamalainen <ccr@tnsp.org>
parents:
195
diff
changeset
|
1619 |
398 | 1620 ptr = str_trim_left(tmpBuf); |
211
c40329e95445
Trim both left and right side of username+password prompt input. Also allow empty passwords, to be able to use guest accounts.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
1621 |
c40329e95445
Trim both left and right side of username+password prompt input. Also allow empty passwords, to be able to use guest accounts.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
1622 if (allowEmpty || strlen(ptr) > 0) |
c40329e95445
Trim both left and right side of username+password prompt input. Also allow empty passwords, to be able to use guest accounts.
Matti Hamalainen <ccr@tnsp.org>
parents:
210
diff
changeset
|
1623 return th_strdup(ptr); |
196
edd5ce3e5399
Add simplistic username/password requester if none given on commandline or config file.
Matti Hamalainen <ccr@tnsp.org>
parents:
195
diff
changeset
|
1624 else |
edd5ce3e5399
Add simplistic username/password requester if none given on commandline or config file.
Matti Hamalainen <ccr@tnsp.org>
parents:
195
diff
changeset
|
1625 return NULL; |
edd5ce3e5399
Add simplistic username/password requester if none given on commandline or config file.
Matti Hamalainen <ccr@tnsp.org>
parents:
195
diff
changeset
|
1626 } |
168
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
1627 |
405 | 1628 |
322
b9c15c57dc8f
Clean up message functions, add new printMsgQ() helper function for messages that should not
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
1629 void printHelp(void) |
b9c15c57dc8f
Clean up message functions, add new printMsgQ() helper function for messages that should not
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
1630 { |
340 | 1631 printMsgQ(currWin, "\n" |
400 | 1632 "NNChat Help\n" |
1633 "===========\n" | |
1634 "\n" | |
1635 "F1 This help.\n" | |
1636 "F2 \n" | |
1637 ); | |
322
b9c15c57dc8f
Clean up message functions, add new printMsgQ() helper function for messages that should not
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
1638 } |
b9c15c57dc8f
Clean up message functions, add new printMsgQ() helper function for messages that should not
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
1639 |
405 | 1640 |
0 | 1641 int main(int argc, char *argv[]) |
1642 { | |
168
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
1643 nn_conn_t *conn = NULL; |
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
1644 int curVis = ERR, updateCount = 0; |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1645 BOOL argsOK, isError = FALSE, |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1646 exitProg = FALSE, |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1647 colorSet = FALSE, |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1648 cursesInit = FALSE, |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1649 networkInit = FALSE, |
275
66b90d71548b
Improve interactive prompts, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
1650 insertMode = TRUE, |
66b90d71548b
Improve interactive prompts, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
1651 firstUpdate = TRUE; |
96
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
1652 time_t prevTime; |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1653 char *tmpStr; |
168
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
1654 nn_editbuf_t *editBuf = nn_editbuf_new(NN_TMPBUF_SIZE); |
89
c2d916b340bf
Change some typedef names; Add struct for user list handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
1655 nn_editbuf_t *histBuf[SET_MAX_HISTORY+2]; |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1656 int histPos = 0, histMax = 0; |
275
66b90d71548b
Improve interactive prompts, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
1657 |
154
e8f67e344aaf
Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
1658 cfgitem_t *tmpcfg; |
432
966c521e0954
Rename user home directory variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
431
diff
changeset
|
1659 char *setHomeDir = NULL; |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1660 |
313
7c96f52e9a3b
memset() history buffer variable unconditionally to avoid derefencing uninitialized memory.
Matti Hamalainen <ccr@tnsp.org>
parents:
309
diff
changeset
|
1661 memset(histBuf, 0, sizeof(histBuf)); |
391 | 1662 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1663 // Initialize |
195
829457be9eea
Build system changes to support (in a big kludgy manner) icon and version information resource generation for Win32 binaries.
Matti Hamalainen <ccr@tnsp.org>
parents:
191
diff
changeset
|
1664 th_init("NNChat", "Newbie Nudes chat client", NN_VERSION, |
399 | 1665 "Written and designed by Anonymous Finnish Guy (C) 2008-2012", |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1666 "This software is freeware, use and distribute as you wish."); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1667 th_verbosityLevel = 0; |
133 | 1668 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1669 // Read configuration file |
148 | 1670 tmpcfg = NULL; |
133 | 1671 th_cfg_add_comment(&tmpcfg, "General settings"); |
1672 th_cfg_add_string(&tmpcfg, "username", &optUserName, NULL); | |
1673 th_cfg_add_string(&tmpcfg, "password", &optPassword, NULL); | |
409
4556174b5be8
Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
408
diff
changeset
|
1674 |
150
db5e7a1f1eb3
Add comment in config file about format of user color setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
149
diff
changeset
|
1675 th_cfg_add_comment(&tmpcfg, "Default color as a hex-triplet"); |
133 | 1676 th_cfg_add_hexvalue(&tmpcfg, "color", &optUserColor, optUserColor); |
391 | 1677 |
149
a4d6707161a7
Add config file option for default setting of ignore mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
1678 th_cfg_add_comment(&tmpcfg, "Default setting of ignore mode"); |
151
303db1141147
Oops, should be th_cfg_add_bool() instead of th_cfg_add_boolean()
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
1679 th_cfg_add_bool(&tmpcfg, "ignore", &setIgnoreMode, setIgnoreMode); |
149
a4d6707161a7
Add config file option for default setting of ignore mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
1680 th_cfg_add_comment(&tmpcfg, "People to be ignored when ignore mode is enabled"); |
265
b9c650db8a6a
Rename variable nnIgnoreList to setIgnoreList.
Matti Hamalainen <ccr@tnsp.org>
parents:
264
diff
changeset
|
1681 th_cfg_add_string_list(&tmpcfg, "ignore_list", &setIgnoreList); |
264
4c1c18a388d9
Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents:
258
diff
changeset
|
1682 |
4c1c18a388d9
Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents:
258
diff
changeset
|
1683 th_cfg_add_comment(&tmpcfg, "Random messages for idle timeout protection. If none are set, plain '.' is used."); |
4c1c18a388d9
Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents:
258
diff
changeset
|
1684 th_cfg_add_string_list(&tmpcfg, "idle_messages", &setIdleMessages); |
4c1c18a388d9
Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents:
258
diff
changeset
|
1685 |
409
4556174b5be8
Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
408
diff
changeset
|
1686 th_cfg_add_comment(&tmpcfg, "Character used as nickname auto-completion separator (default is ':')"); |
4556174b5be8
Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
408
diff
changeset
|
1687 th_cfg_add_string(&tmpcfg, "nick_separator", &optNickSepStr, NULL); |
4556174b5be8
Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
408
diff
changeset
|
1688 |
133 | 1689 th_cfg_add_section(&cfg, "general", tmpcfg); |
1690 | |
264
4c1c18a388d9
Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents:
258
diff
changeset
|
1691 |
133 | 1692 tmpcfg = NULL; |
1693 th_cfg_add_comment(&tmpcfg, "Chat server hostname or IP address"); | |
1694 th_cfg_add_string(&tmpcfg, "host", &optServer, optServer); | |
321
384d508d1df3
Update configuration file comment about room ports.
Matti Hamalainen <ccr@tnsp.org>
parents:
320
diff
changeset
|
1695 th_cfg_add_comment(&tmpcfg, "Default port to connect to (8005 = main room, 8003 = passion pit)"); |
133 | 1696 th_cfg_add_int(&tmpcfg, "port", &optPort, optPort); |
1697 th_cfg_add_section(&cfg, "server", tmpcfg); | |
1698 | |
239
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1699 tmpcfg = NULL; |
369
461a6befb7c3
Oops, the proxy type was accidentally called "port" in the configuration file, as was the actual port setting. Fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
360
diff
changeset
|
1700 th_cfg_add_comment(&tmpcfg, "Proxy server type (0 = none, 1 = SOCKS 4, 2 = SOCKS 4a)"); |
461a6befb7c3
Oops, the proxy type was accidentally called "port" in the configuration file, as was the actual port setting. Fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
360
diff
changeset
|
1701 th_cfg_add_int(&tmpcfg, "type", &optProxyType, optProxyType); |
353
83ae825bb8c1
Add configuration section for proxy settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
352
diff
changeset
|
1702 th_cfg_add_comment(&tmpcfg, "Proxy server host name"); |
83ae825bb8c1
Add configuration section for proxy settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
352
diff
changeset
|
1703 th_cfg_add_string(&tmpcfg, "host", &optProxyServer, optProxyServer); |
83ae825bb8c1
Add configuration section for proxy settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
352
diff
changeset
|
1704 th_cfg_add_comment(&tmpcfg, "Proxy port, 1080 is the standard SOCKS port"); |
83ae825bb8c1
Add configuration section for proxy settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
352
diff
changeset
|
1705 th_cfg_add_int(&tmpcfg, "port", &optProxyPort, optProxyPort); |
83ae825bb8c1
Add configuration section for proxy settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
352
diff
changeset
|
1706 th_cfg_add_section(&cfg, "proxy", tmpcfg); |
83ae825bb8c1
Add configuration section for proxy settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
352
diff
changeset
|
1707 |
83ae825bb8c1
Add configuration section for proxy settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
352
diff
changeset
|
1708 tmpcfg = NULL; |
239
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1709 th_cfg_add_comment(&tmpcfg, "Enable logging"); |
247 | 1710 th_cfg_add_bool(&tmpcfg, "enable", &optLogEnable, optLogEnable); |
242
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1711 th_cfg_add_comment(&tmpcfg, "Log filename format"); |
247 | 1712 th_cfg_add_string(&tmpcfg, "filename", &optLogFilename, optLogFilename); |
1713 th_cfg_add_section(&cfg, "logging", tmpcfg); | |
239
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1714 |
154
e8f67e344aaf
Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
1715 #ifdef __WIN32 |
e8f67e344aaf
Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
1716 { |
391 | 1717 char tmpPath[MAX_PATH]; |
1718 if (SHGetFolderPath(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, tmpPath) == S_OK) | |
432
966c521e0954
Rename user home directory variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
431
diff
changeset
|
1719 setHomeDir = th_strdup(tmpPath); |
197
e0ec2280a778
Implement browser launching on Windows via ShellExecute().
Matti Hamalainen <ccr@tnsp.org>
parents:
196
diff
changeset
|
1720 |
391 | 1721 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); |
154
e8f67e344aaf
Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
1722 } |
e8f67e344aaf
Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
1723 #else |
432
966c521e0954
Rename user home directory variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
431
diff
changeset
|
1724 setHomeDir = th_strdup(getenv("HOME")); |
154
e8f67e344aaf
Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
1725 #endif |
391 | 1726 |
432
966c521e0954
Rename user home directory variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
431
diff
changeset
|
1727 if (setHomeDir != NULL) |
391 | 1728 { |
154
e8f67e344aaf
Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
1729 FILE *cfgfile; |
432
966c521e0954
Rename user home directory variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
431
diff
changeset
|
1730 setConfigFile = th_strdup_printf("%s" SET_DIR_SEPARATOR "%s", setHomeDir, SET_CONFIG_FILE); |
154
e8f67e344aaf
Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
1731 |
e8f67e344aaf
Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
1732 THMSG(0, "Reading configuration from '%s'.\n", setConfigFile); |
e8f67e344aaf
Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
1733 |
391 | 1734 if ((cfgfile = fopen(setConfigFile, "r")) != NULL) |
1735 { | |
154
e8f67e344aaf
Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
1736 th_cfg_read(cfgfile, setConfigFile, cfg); |
315
864e6e52ed69
Fix a filehandle leak when reading in configuration file.
Matti Hamalainen <ccr@tnsp.org>
parents:
314
diff
changeset
|
1737 fclose(cfgfile); |
864e6e52ed69
Fix a filehandle leak when reading in configuration file.
Matti Hamalainen <ccr@tnsp.org>
parents:
314
diff
changeset
|
1738 } |
133 | 1739 } |
196
edd5ce3e5399
Add simplistic username/password requester if none given on commandline or config file.
Matti Hamalainen <ccr@tnsp.org>
parents:
195
diff
changeset
|
1740 |
409
4556174b5be8
Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
408
diff
changeset
|
1741 if (optNickSepStr) |
4556174b5be8
Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
408
diff
changeset
|
1742 optNickSep = optNickSepStr[0]; |
4556174b5be8
Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
408
diff
changeset
|
1743 else |
4556174b5be8
Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
408
diff
changeset
|
1744 optNickSep = SET_NICK_SEPARATOR; |
4556174b5be8
Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
408
diff
changeset
|
1745 |
4556174b5be8
Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
408
diff
changeset
|
1746 |
137
fad8c31e41e6
Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
1747 setBrowser = getenv("BROWSER"); |
fad8c31e41e6
Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
1748 if (setBrowser == NULL) |
fad8c31e41e6
Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
1749 setBrowser = "firefox"; |
391 | 1750 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1751 // Parse command line arguments |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1752 argsOK = th_args_process(argc, argv, optList, optListN, |
391 | 1753 argHandleOpt, argHandleFile, FALSE); |
26
b84fc46c6035
Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
1754 |
391 | 1755 if (optUserNameCmd != NULL) |
1756 { | |
198
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
1757 optUserName = optUserNameCmd; |
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
1758 optPassword = optPasswordCmd; |
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
1759 } |
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
1760 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1761 if (!argsOK) |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1762 return -2; |
64
6a3a917303e4
Some random cleanups, bring back WinSock support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
1763 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1764 // Allocate userhash |
391 | 1765 if ((nnUsers = nn_userhash_new()) == NULL) |
1766 { | |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
1767 THERR("Could not allocate userhash. Fatal error.\n"); |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
1768 return -105; |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
1769 } |
64
6a3a917303e4
Some random cleanups, bring back WinSock support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
1770 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1771 // If no idle messages are set, add default |
391 | 1772 if (setIdleMessages == NULL) |
1773 { | |
264
4c1c18a388d9
Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents:
258
diff
changeset
|
1774 th_llist_append(&setIdleMessages, th_strdup(".")); |
4c1c18a388d9
Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents:
258
diff
changeset
|
1775 } |
4c1c18a388d9
Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents:
258
diff
changeset
|
1776 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1777 // Open logfile |
242
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1778 logFileOpen(); |
391 | 1779 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1780 // Initialize network |
391 | 1781 if (!nn_network_init()) |
1782 { | |
91
acfc4b4bc180
Create network initialization functions in libnnchat and move Win32/WinSock code there.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
1783 THERR("Could not initialize network subsystem.\n"); |
acfc4b4bc180
Create network initialization functions in libnnchat and move Win32/WinSock code there.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
1784 goto err_exit; |
391 | 1785 } |
1786 else | |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1787 networkInit = TRUE; |
68
3ab7751fdad1
MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents:
67
diff
changeset
|
1788 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1789 // Initialize NCurses |
391 | 1790 if (!optDaemon) |
1791 { | |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1792 if (LINES < 0 || LINES > 1000) LINES = 24; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1793 if (COLS < 0 || COLS > 1000) COLS = 80; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1794 initscr(); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1795 raw(); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1796 keypad(stdscr, TRUE); |
275
66b90d71548b
Improve interactive prompts, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
1797 noecho(); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1798 meta(stdscr, TRUE); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1799 timeout(SET_DELAY); |
275
66b90d71548b
Improve interactive prompts, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
1800 curVis = curs_set(0); |
110
8af4072dc31a
Fix Win32/MinGW/PDcurses issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
109
diff
changeset
|
1801 |
391 | 1802 if (has_colors()) |
1803 { | |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1804 start_color(); |
391 | 1805 |
185 | 1806 init_pair( 1, COLOR_RED, COLOR_BLACK); |
1807 init_pair( 2, COLOR_GREEN, COLOR_BLACK); | |
1808 init_pair( 3, COLOR_YELLOW, COLOR_BLACK); | |
1809 init_pair( 4, COLOR_BLUE, COLOR_BLACK); | |
1810 init_pair( 5, COLOR_MAGENTA, COLOR_BLACK); | |
1811 init_pair( 6, COLOR_CYAN, COLOR_BLACK); | |
1812 init_pair( 7, COLOR_WHITE, COLOR_BLACK); | |
1813 init_pair( 8, COLOR_BLACK, COLOR_BLACK); | |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1814 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1815 init_pair(10, COLOR_BLACK, COLOR_RED); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1816 init_pair(11, COLOR_WHITE, COLOR_RED); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1817 init_pair(12, COLOR_GREEN, COLOR_RED); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1818 init_pair(13, COLOR_YELLOW, COLOR_RED); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1819 init_pair(14, COLOR_BLUE, COLOR_RED); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1820 init_pair(15, COLOR_MAGENTA, COLOR_RED); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1821 init_pair(16, COLOR_CYAN, COLOR_RED); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1822 } |
391 | 1823 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1824 cursesInit = TRUE; |
391 | 1825 |
422 | 1826 if (!nnwin_initialize_windows()) |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1827 goto err_exit; |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1828 |
346
102fb74fc794
Set window title when running under PDCurses.
Matti Hamalainen <ccr@tnsp.org>
parents:
342
diff
changeset
|
1829 #ifdef PDCURSES |
102fb74fc794
Set window title when running under PDCurses.
Matti Hamalainen <ccr@tnsp.org>
parents:
342
diff
changeset
|
1830 PDC_set_title("NNChat v" NN_VERSION); |
102fb74fc794
Set window title when running under PDCurses.
Matti Hamalainen <ccr@tnsp.org>
parents:
342
diff
changeset
|
1831 #endif |
102fb74fc794
Set window title when running under PDCurses.
Matti Hamalainen <ccr@tnsp.org>
parents:
342
diff
changeset
|
1832 |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1833 memset(chatWindows, 0, sizeof(chatWindows)); |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
1834 chatWindows[0] = nn_window_new(NULL); |
391 | 1835 currWin = chatWindows[0]; |
422 | 1836 nnwin_update_statusline(); |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1837 } |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1838 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1839 // Check if we have username and password |
391 | 1840 if (cursesInit && (optUserName == NULL || optPassword == NULL)) |
1841 { | |
422 | 1842 nnwin_print(editWin, "You can avoid this prompt by issuing '/save' after logging in.\n"); |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1843 optUserName = promptRequester(editWin, "NN username: ", FALSE); |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1844 optPassword = promptRequester(editWin, "NN password: ", TRUE); |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1845 } |
391 | 1846 |
1847 if (optUserName == NULL || optPassword == NULL) | |
1848 { | |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1849 errorMsg("Username and/or password not specified.\n"); |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1850 goto err_exit; |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1851 } |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1852 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1853 // Create a connection |
354
c01e42fc9adb
More work on SOCKS proxy support, should work now.
Matti Hamalainen <ccr@tnsp.org>
parents:
353
diff
changeset
|
1854 conn = nn_conn_new(errorFunc, messageFunc); |
391 | 1855 if (conn == NULL) |
1856 { | |
354
c01e42fc9adb
More work on SOCKS proxy support, should work now.
Matti Hamalainen <ccr@tnsp.org>
parents:
353
diff
changeset
|
1857 errorMsg("Could not create connection structure.\n"); |
c01e42fc9adb
More work on SOCKS proxy support, should work now.
Matti Hamalainen <ccr@tnsp.org>
parents:
353
diff
changeset
|
1858 goto err_exit; |
c01e42fc9adb
More work on SOCKS proxy support, should work now.
Matti Hamalainen <ccr@tnsp.org>
parents:
353
diff
changeset
|
1859 } |
c01e42fc9adb
More work on SOCKS proxy support, should work now.
Matti Hamalainen <ccr@tnsp.org>
parents:
353
diff
changeset
|
1860 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1861 // Are we using a proxy? |
391 | 1862 if (optProxyType != NN_PROXY_NONE && optProxyServer != NULL) |
1863 { | |
1864 if (nn_conn_set_proxy(conn, optProxyType, optProxyPort, optProxyServer) != 0) | |
1865 { | |
354
c01e42fc9adb
More work on SOCKS proxy support, should work now.
Matti Hamalainen <ccr@tnsp.org>
parents:
353
diff
changeset
|
1866 errorMsg("Error setting proxy information.\n"); |
352
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
1867 goto err_exit; |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
1868 } |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
1869 } |
391 | 1870 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1871 // Okay ... |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1872 printMsg(currWin, "Trying to resolve host '%s' ...\n", optServer); |
354
c01e42fc9adb
More work on SOCKS proxy support, should work now.
Matti Hamalainen <ccr@tnsp.org>
parents:
353
diff
changeset
|
1873 conn->host = th_strdup(optServer); |
c01e42fc9adb
More work on SOCKS proxy support, should work now.
Matti Hamalainen <ccr@tnsp.org>
parents:
353
diff
changeset
|
1874 conn->hst = nn_resolve_host(conn, optServer); |
391 | 1875 if (conn->hst == NULL) |
1876 { | |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1877 errorMsg("Could not resolve hostname: %s.\n", strerror(h_errno)); |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1878 goto err_exit; |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1879 } |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1880 |
329
c0988ab45afd
#ifdef out the policy probe.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
1881 #ifdef FINAL_BUILD |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1882 /* To emulate the official client, we first make a request for |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1883 * policy file, even though we don't use it for anything... |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1884 */ |
391 | 1885 if (nn_conn_open(conn, 843, NULL) != 0) |
1886 { | |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1887 errorMsg("Policy file request connection setup failed!\n"); |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1888 goto err_exit; |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1889 } |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1890 |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1891 tmpStr = "<policy-file-request/>"; |
391 | 1892 if (nn_conn_send_buf(conn, tmpStr, strlen(tmpStr) + 1) == FALSE) |
1893 { | |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1894 errorMsg("Failed to send policy file request.\n"); |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1895 goto err_exit; |
391 | 1896 } |
1897 else | |
1898 { | |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1899 int cres = nn_conn_pull(conn); |
391 | 1900 if (cres == 0) |
1901 { | |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1902 printMsg(currWin, "Probe got: %s\n", conn->buf); |
391 | 1903 } |
1904 else | |
1905 { | |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1906 printMsg(currWin, "Could not get policy probe.\n"); |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1907 } |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1908 } |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1909 nn_conn_close(conn); |
329
c0988ab45afd
#ifdef out the policy probe.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
1910 #endif |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1911 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1912 // Okay, now do the proper connection ... |
391 | 1913 if (nn_conn_open(conn, optPort, NULL) != 0) |
1914 { | |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1915 errorMsg("Main connection setup failed!\n"); |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1916 goto err_exit; |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1917 } |
391 | 1918 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1919 // Send login command |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1920 optUserNameEnc = nn_dblencode_str(optUserName); |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1921 tmpStr = nn_dblencode_str(optSite); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1922 nn_conn_send_msg_v(conn, optUserNameEnc, "%%2Flogin%%20%%2Dsite%%20%s%%20%%2Dpassword%%20%s", tmpStr, optPassword); |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1923 th_free(tmpStr); |
391 | 1924 |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1925 // Initialize user commands |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1926 nn_usercmd_init(); |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1927 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1928 // Initialize random numbers |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1929 prevTime = time(NULL); |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1930 srandom((int) prevTime); |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
1931 |
391 | 1932 if (cursesInit) |
1933 { | |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1934 // Initialize rest of interactive UI code |
97
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
1935 nn_editbuf_clear(editBuf); |
275
66b90d71548b
Improve interactive prompts, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
1936 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1937 // First update of screen |
422 | 1938 nnwin_update_editbuf(editBuf); |
1939 nnwin_update_statusline(); | |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1940 |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1941 printMsg(NULL, "%s v%s - %s\n", th_prog_name, th_prog_version, th_prog_fullname); |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1942 printMsg(NULL, "%s\n", th_prog_author); |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1943 printMsg(NULL, "%s\n", th_prog_license); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1944 } |
100
ed4067c10a8a
Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
1945 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1946 // Enter mainloop |
360
b465a17ffa47
Finally fix handling of long packets.
Matti Hamalainen <ccr@tnsp.org>
parents:
359
diff
changeset
|
1947 nn_conn_reset(conn); |
391 | 1948 while (!isError && !exitProg) |
1949 { | |
445
7e46f2f0ba34
Cleanup packet retrying a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
444
diff
changeset
|
1950 int retries = 3, cres; |
7e46f2f0ba34
Cleanup packet retrying a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
444
diff
changeset
|
1951 |
7e46f2f0ba34
Cleanup packet retrying a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
444
diff
changeset
|
1952 packet_retry: |
7e46f2f0ba34
Cleanup packet retrying a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
444
diff
changeset
|
1953 cres = nn_conn_pull(conn); |
439
70ea06294f3f
Possibly fix packet handling after the whole mess of refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
437
diff
changeset
|
1954 if (cres == 0) |
70ea06294f3f
Possibly fix packet handling after the whole mess of refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
437
diff
changeset
|
1955 { |
70ea06294f3f
Possibly fix packet handling after the whole mess of refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
437
diff
changeset
|
1956 while (conn->ptr < conn->in_ptr && |
70ea06294f3f
Possibly fix packet handling after the whole mess of refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
437
diff
changeset
|
1957 *(conn->in_ptr - 1) == 0 && |
445
7e46f2f0ba34
Cleanup packet retrying a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
444
diff
changeset
|
1958 retries > 0 && !isError) |
391 | 1959 { |
439
70ea06294f3f
Possibly fix packet handling after the whole mess of refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
437
diff
changeset
|
1960 // nn_conn_dump_buffer(stderr, conn); |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
1961 int result = nn_parse_protocol(conn); |
436 | 1962 if (result == 0) |
1963 { | |
1964 nn_conn_buf_skip(conn, 1); | |
1965 } | |
1966 else | |
385 | 1967 if (result > 0) |
1968 { | |
445
7e46f2f0ba34
Cleanup packet retrying a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
444
diff
changeset
|
1969 // Retry if possible |
439
70ea06294f3f
Possibly fix packet handling after the whole mess of refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
437
diff
changeset
|
1970 if (--retries > 0) |
445
7e46f2f0ba34
Cleanup packet retrying a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
444
diff
changeset
|
1971 goto packet_retry; |
7e46f2f0ba34
Cleanup packet retrying a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
444
diff
changeset
|
1972 |
7e46f2f0ba34
Cleanup packet retrying a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
444
diff
changeset
|
1973 // Couldn't handle the message for some reason |
7e46f2f0ba34
Cleanup packet retrying a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
444
diff
changeset
|
1974 printMsg(currWin, "Could not handle: %s\n", conn->ptr); |
7e46f2f0ba34
Cleanup packet retrying a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
444
diff
changeset
|
1975 nn_conn_buf_skip(conn, strlen(conn->ptr) + 1); |
385 | 1976 } |
436 | 1977 else |
385 | 1978 { |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1979 // Fatal error, quit |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
1980 errorMsg("Fatal error with message: %s\n", conn->ptr); |
168
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
1981 isError = TRUE; |
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
1982 } |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
1983 } |
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
1984 } |
439
70ea06294f3f
Possibly fix packet handling after the whole mess of refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
437
diff
changeset
|
1985 else |
70ea06294f3f
Possibly fix packet handling after the whole mess of refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
437
diff
changeset
|
1986 if (cres < 0 || !nn_conn_check(conn)) |
168
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
1987 isError = TRUE; |
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
1988 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1989 // Handle user input |
391 | 1990 if (cursesInit) |
1991 { | |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1992 int c, cnt = 0; |
319
b9127815c9aa
Oops, updateMain was set to TRUE by default, causing excessive window refreshing. Fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
318
diff
changeset
|
1993 BOOL update = FALSE, updateMain = FALSE; |
391 | 1994 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1995 // Handle several buffered keypresses at once |
391 | 1996 do |
1997 { | |
77
e8c9d7d13866
Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
1998 c = wgetch(stdscr); |
411 | 1999 |
2000 /* Handle various problematic cases where terminal | |
2001 * keycodes do not get properly translated by curses | |
2002 */ | |
391 | 2003 if (c == 0x1b) |
2004 { | |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2005 // ^[O |
77
e8c9d7d13866
Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
2006 c = wgetch(stdscr); |
391 | 2007 if (c == 'O') |
2008 { | |
2009 c = wgetch(stdscr); | |
2010 switch (c) | |
2011 { | |
2012 case 'd': | |
2013 c = 0x204; | |
2014 break; | |
2015 case 'c': | |
2016 c = 0x206; | |
2017 break; | |
77
e8c9d7d13866
Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
2018 default: |
297
d34910f1b1e1
Print messages about user leaving or joining the chat in the specific buffer, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
2019 if (optDebug) |
d34910f1b1e1
Print messages about user leaving or joining the chat in the specific buffer, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
2020 printMsg(currWin, "Unhandled ESC-O key sequence 0x%02x\n", c); |
77
e8c9d7d13866
Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
2021 break; |
391 | 2022 } |
77
e8c9d7d13866
Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
2023 } |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2024 // ^[[ |
391 | 2025 else if (c == '[') |
2026 { | |
2027 c = wgetch(stdscr); | |
2028 switch (c) | |
2029 { | |
252
dcf78e2c458c
Improve log filename format parsing; Add special casing for handling of function keys for certain terminal types.
Matti Hamalainen <ccr@tnsp.org>
parents:
247
diff
changeset
|
2030 case 0x31: |
dcf78e2c458c
Improve log filename format parsing; Add special casing for handling of function keys for certain terminal types.
Matti Hamalainen <ccr@tnsp.org>
parents:
247
diff
changeset
|
2031 c = wgetch(stdscr); |
dcf78e2c458c
Improve log filename format parsing; Add special casing for handling of function keys for certain terminal types.
Matti Hamalainen <ccr@tnsp.org>
parents:
247
diff
changeset
|
2032 if (c >= 0x31 && c <= 0x39) |
dcf78e2c458c
Improve log filename format parsing; Add special casing for handling of function keys for certain terminal types.
Matti Hamalainen <ccr@tnsp.org>
parents:
247
diff
changeset
|
2033 c = KEY_F(c - 0x30); |
dcf78e2c458c
Improve log filename format parsing; Add special casing for handling of function keys for certain terminal types.
Matti Hamalainen <ccr@tnsp.org>
parents:
247
diff
changeset
|
2034 else |
dcf78e2c458c
Improve log filename format parsing; Add special casing for handling of function keys for certain terminal types.
Matti Hamalainen <ccr@tnsp.org>
parents:
247
diff
changeset
|
2035 c = ERR; |
dcf78e2c458c
Improve log filename format parsing; Add special casing for handling of function keys for certain terminal types.
Matti Hamalainen <ccr@tnsp.org>
parents:
247
diff
changeset
|
2036 break; |
391 | 2037 |
2038 case 0x32: | |
2039 c = KEY_IC; | |
2040 break; | |
2041 case 0x33: | |
2042 c = KEY_DC; | |
2043 break; | |
206
af32c038cf1e
Add some hardcoded translations for certain terminal keycodes that NCurses 4.x on Solaris didn't handle .. urgh.
Matti Hamalainen <ccr@tnsp.org>
parents:
203
diff
changeset
|
2044 |
391 | 2045 case 0x35: |
2046 c = KEY_PPAGE; | |
2047 break; | |
2048 case 0x36: | |
2049 c = KEY_NPAGE; | |
2050 break; | |
206
af32c038cf1e
Add some hardcoded translations for certain terminal keycodes that NCurses 4.x on Solaris didn't handle .. urgh.
Matti Hamalainen <ccr@tnsp.org>
parents:
203
diff
changeset
|
2051 |
391 | 2052 case 0x37: |
2053 c = KEY_HOME; | |
2054 break; | |
2055 case 0x38: | |
2056 c = KEY_END; | |
2057 break; | |
2058 | |
206
af32c038cf1e
Add some hardcoded translations for certain terminal keycodes that NCurses 4.x on Solaris didn't handle .. urgh.
Matti Hamalainen <ccr@tnsp.org>
parents:
203
diff
changeset
|
2059 default: |
297
d34910f1b1e1
Print messages about user leaving or joining the chat in the specific buffer, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
2060 if (optDebug) |
d34910f1b1e1
Print messages about user leaving or joining the chat in the specific buffer, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
2061 printMsg(currWin, "Unhandled ESC-[*~ key sequence 0x%02x\n", c); |
206
af32c038cf1e
Add some hardcoded translations for certain terminal keycodes that NCurses 4.x on Solaris didn't handle .. urgh.
Matti Hamalainen <ccr@tnsp.org>
parents:
203
diff
changeset
|
2062 c = ERR; |
af32c038cf1e
Add some hardcoded translations for certain terminal keycodes that NCurses 4.x on Solaris didn't handle .. urgh.
Matti Hamalainen <ccr@tnsp.org>
parents:
203
diff
changeset
|
2063 break; |
391 | 2064 } |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2065 // Get the trailing ~ |
391 | 2066 if (c != ERR) |
2067 wgetch(stdscr); | |
206
af32c038cf1e
Add some hardcoded translations for certain terminal keycodes that NCurses 4.x on Solaris didn't handle .. urgh.
Matti Hamalainen <ccr@tnsp.org>
parents:
203
diff
changeset
|
2068 } |
391 | 2069 if (c >= 0x31 && c <= 0x39) |
2070 { | |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2071 // Chat window switching via Meta/Esc-[1..9] |
391 | 2072 int win = c - 0x31; |
2073 if (win < SET_MAX_WINDOWS && chatWindows[win] != NULL) | |
2074 { | |
2075 currWin = chatWindows[win]; | |
2076 update = updateMain = TRUE; | |
2077 } | |
2078 c = ERR; | |
2079 } | |
2080 else | |
2081 { | |
2082 if (optDebug) | |
2083 printMsg(currWin, "Unhandled ESC key sequence 0x%02x\n", c); | |
2084 } | |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
2085 } |
391 | 2086 #if defined(__WIN32) && defined(PDCURSES) |
2087 else if (c >= 0x198 && c <= 0x1a0) | |
2088 { | |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2089 // Chat window switching via Meta/Esc-[1..9] |
391 | 2090 int win = c - 0x198; |
2091 if (win < SET_MAX_WINDOWS && chatWindows[win] != NULL) | |
2092 { | |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
2093 currWin = chatWindows[win]; |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
2094 update = updateMain = TRUE; |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
2095 } |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
2096 c = ERR; |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
2097 } |
391 | 2098 #endif |
2099 | |
2100 switch (c) | |
2101 { | |
2102 #ifdef KEY_RESIZE | |
2103 case KEY_RESIZE: | |
2104 resize_term(0, 0); | |
2105 erase(); | |
2106 timeout(SET_DELAY); | |
2107 | |
422 | 2108 if (!nnwin_initialize_windows()) |
391 | 2109 { |
2110 errorMsg("Error resizing curses chatWindows\n"); | |
2111 isError = TRUE; | |
2112 } | |
332
f55f8309aa66
Support alt-[1..9] under Windows/PDCurses/SDL port for buffer switching.
Matti Hamalainen <ccr@tnsp.org>
parents:
331
diff
changeset
|
2113 update = updateMain = TRUE; |
391 | 2114 break; |
341
ece94ae2a051
Handling of certain Curses keycodes only works as intended under
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
2115 #endif |
119
4bc63a535acb
Fix some PDCurses incompatibilities and remove some Win32/PDCurses specific hacks.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
2116 |
391 | 2117 case KEY_ENTER: |
2118 case '\n': | |
2119 case '\r': | |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2120 // Call the user input handler |
391 | 2121 if (editBuf->len > 0) |
2122 { | |
2123 int result; | |
2124 | |
2125 if (histMax > 0) | |
2126 { | |
2127 nn_editbuf_free(histBuf[SET_MAX_HISTORY+1]); | |
2128 histBuf[SET_MAX_HISTORY+1] = NULL; | |
2129 memmove(&histBuf[2], &histBuf[1], histMax * sizeof(histBuf[0])); | |
2130 } | |
320 | 2131 |
391 | 2132 histPos = 0; |
2133 histBuf[1] = nn_editbuf_copy(editBuf); | |
2134 if (histMax < SET_MAX_HISTORY) histMax++; | |
2135 | |
2136 nn_editbuf_insert(editBuf, editBuf->len, 0); | |
410
7ea78f4a4d23
Rename input handling main function.
Matti Hamalainen <ccr@tnsp.org>
parents:
409
diff
changeset
|
2137 result = nn_handle_input(conn, editBuf->data, editBuf->len); |
391 | 2138 |
2139 nn_editbuf_clear(editBuf); | |
2140 | |
2141 if (result < 0) | |
2142 { | |
2143 errorMsg("Fatal error handling user input: %s\n", editBuf->data); | |
2144 isError = TRUE; | |
2145 } | |
2146 else | |
2147 { | |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2148 // Update time value of last sent message for unidle timeouts |
391 | 2149 prevTime = time(NULL); |
2150 } | |
2151 | |
2152 updateMain = update = TRUE; | |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
2153 } |
391 | 2154 break; |
2155 | |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2156 case KEY_UP: // Backwards in input history |
391 | 2157 if (histPos == 0) |
2158 { | |
2159 nn_editbuf_free(histBuf[0]); | |
2160 histBuf[0] = nn_editbuf_copy(editBuf); | |
2161 } | |
2162 if (histPos < histMax) | |
385 | 2163 { |
391 | 2164 histPos++; |
2165 nn_editbuf_free(editBuf); | |
2166 editBuf = nn_editbuf_copy(histBuf[histPos]); | |
2167 update = TRUE; | |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
2168 } |
391 | 2169 break; |
2170 | |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2171 case KEY_DOWN: // Forwards in input history |
391 | 2172 if (histPos > 0) |
2173 { | |
2174 histPos--; | |
2175 nn_editbuf_free(editBuf); | |
2176 editBuf = nn_editbuf_copy(histBuf[histPos]); | |
2177 update = TRUE; | |
2178 } | |
2179 break; | |
2180 | |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2181 case 0x204: // ctrl+left arrow = Skip words left |
391 | 2182 case 0x20b: |
2183 while (editBuf->pos > 0 && isspace((int) editBuf->data[editBuf->pos - 1])) | |
2184 editBuf->pos--; | |
2185 while (editBuf->pos > 0 && !isspace((int) editBuf->data[editBuf->pos - 1])) | |
2186 editBuf->pos--; | |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
2187 update = TRUE; |
391 | 2188 break; |
2189 | |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2190 case 0x206: // ctrl+right arrow = Skip words right |
391 | 2191 case 0x210: |
2192 while (editBuf->pos < editBuf->len && isspace((int) editBuf->data[editBuf->pos])) | |
2193 editBuf->pos++; | |
2194 while (editBuf->pos < editBuf->len && !isspace((int) editBuf->data[editBuf->pos])) | |
2195 editBuf->pos++; | |
2196 update = TRUE; | |
2197 break; | |
2198 | |
2199 case KEY_HOME: | |
2200 nn_editbuf_setpos(editBuf, 0); | |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
2201 update = TRUE; |
391 | 2202 break; |
2203 case KEY_END: | |
2204 nn_editbuf_setpos(editBuf, editBuf->len); | |
2205 update = TRUE; | |
2206 break; | |
2207 case KEY_LEFT: | |
2208 nn_editbuf_setpos(editBuf, editBuf->pos - 1); | |
2209 update = TRUE; | |
2210 break; | |
2211 case KEY_RIGHT: | |
2212 nn_editbuf_setpos(editBuf, editBuf->pos + 1); | |
2213 update = TRUE; | |
2214 break; | |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
2215 |
391 | 2216 case KEY_BACKSPACE: |
2217 case 0x08: | |
2218 case 0x7f: | |
2219 nn_editbuf_delete(editBuf, editBuf->pos - 1); | |
2220 nn_editbuf_setpos(editBuf, editBuf->pos - 1); | |
2221 update = TRUE; | |
2222 break; | |
2223 | |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2224 case KEY_DC: // Delete character |
391 | 2225 nn_editbuf_delete(editBuf, editBuf->pos); |
2226 update = TRUE; | |
2227 break; | |
2228 | |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
2229 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2230 case KEY_IC: // Ins = Toggle insert / overwrite mode |
391 | 2231 insertMode = !insertMode; |
2232 update = TRUE; | |
2233 break; | |
2234 | |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2235 case KEY_F(1): // F1 = Print help |
391 | 2236 printHelp(); |
2237 updateMain = TRUE; | |
2238 break; | |
322
b9c15c57dc8f
Clean up message functions, add new printMsgQ() helper function for messages that should not
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
2239 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2240 case KEY_F(2): // F2 = Clear editbuffer |
391 | 2241 nn_editbuf_clear(editBuf); |
2242 update = TRUE; | |
2243 break; | |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
2244 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2245 case KEY_F(5): // F5 = Ignore mode |
391 | 2246 setIgnoreMode = !setIgnoreMode; |
2247 printMsgQ(currWin, "Ignore mode = %s\n", setIgnoreMode ? "ON" : "OFF"); | |
2248 break; | |
334
3c7676b2b367
#if'd out code for F8 = toggle debug mode key.
Matti Hamalainen <ccr@tnsp.org>
parents:
333
diff
changeset
|
2249 |
3c7676b2b367
#if'd out code for F8 = toggle debug mode key.
Matti Hamalainen <ccr@tnsp.org>
parents:
333
diff
changeset
|
2250 #if 0 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2251 case KEY_F(8): // F8 = Debug |
391 | 2252 optDebug = !optDebug; |
2253 update = TRUE; | |
2254 break; | |
334
3c7676b2b367
#if'd out code for F8 = toggle debug mode key.
Matti Hamalainen <ccr@tnsp.org>
parents:
333
diff
changeset
|
2255 #endif |
391 | 2256 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2257 case 0x03: // ^C = quit |
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2258 case KEY_F(9): // F9 = Quit |
391 | 2259 printMsg(currWin, "Quitting per user request (%d/0x%x).\n", c, c); |
2260 exitProg = TRUE; | |
2261 break; | |
2262 | |
449
7d9fa9f7caf1
Rename tab completion functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
2263 case 0x09: // Tab = complete username or command |
7d9fa9f7caf1
Rename tab completion functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
2264 nn_tabcomplete_buffer(editBuf); |
391 | 2265 update = TRUE; |
2266 break; | |
122 | 2267 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2268 case 0x0c: // Ctrl + L |
422 | 2269 nnwin_update_all(); |
391 | 2270 update = updateMain = TRUE; |
2271 break; | |
230
b64500bb7fbe
Some yet-unused backbuffer related code.
Matti Hamalainen <ccr@tnsp.org>
parents:
229
diff
changeset
|
2272 |
391 | 2273 case KEY_NPAGE: |
2274 case KEY_PPAGE: | |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2275 // Page Up / Page Down |
391 | 2276 if (currWin != NULL) |
2277 { | |
2278 int oldPos = currWin->pos; | |
2279 | |
2280 currWin->pos += (c == KEY_NPAGE) ? -10 : +10; | |
331
26097c5b9b71
Change how backbuffer offset is handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
330
diff
changeset
|
2281 |
391 | 2282 if (currWin->pos < 0) |
2283 currWin->pos = 0; | |
2284 else if (currWin->pos >= currWin->data->n - 10) | |
2285 currWin->pos = currWin->data->n - 10; | |
230
b64500bb7fbe
Some yet-unused backbuffer related code.
Matti Hamalainen <ccr@tnsp.org>
parents:
229
diff
changeset
|
2286 |
391 | 2287 if (oldPos != currWin->pos) |
2288 updateMain = TRUE; | |
2289 } | |
2290 break; | |
2291 | |
2292 case ERR: | |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2293 // Ignore |
391 | 2294 break; |
122 | 2295 |
391 | 2296 default: |
2297 if (isprint(c) || c == 0xe4 || c == 0xf6 || c == 0xc4 || c == 0xd6) | |
2298 { | |
2299 if (insertMode) | |
2300 nn_editbuf_insert(editBuf, editBuf->pos, c); | |
2301 else | |
2302 nn_editbuf_write(editBuf, editBuf->pos, c); | |
2303 nn_editbuf_setpos(editBuf, editBuf->pos + 1); | |
2304 update = TRUE; | |
2305 } | |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
2306 else |
391 | 2307 { |
2308 if (optDebug) | |
2309 printMsg(currWin, "Unhandled key: 0x%02x\n", c); | |
2310 } | |
2311 break; | |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
2312 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
2313 } |
391 | 2314 while (c != ERR && !exitProg && ++cnt < 10); |
2315 | |
422 | 2316 nnwin_update_main(updateMain); |
389
19cb995994c9
Change screen update strategy a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
388
diff
changeset
|
2317 |
391 | 2318 if (update || firstUpdate) |
2319 { | |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2320 // Update edit line |
422 | 2321 nnwin_update_statusline(); |
2322 nnwin_update_editbuf(editBuf); | |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2323 firstUpdate = FALSE; // a nasty hack ... |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
2324 } |
391 | 2325 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2326 } // cursesInit |
391 | 2327 |
2328 if (++updateCount > 10) | |
2329 { | |
96
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
2330 time_t tmpTime = time(NULL); |
391 | 2331 if (tmpTime - prevTime > SET_KEEPALIVE) |
2332 { | |
435
708a15fdf791
Fix a type / conversion related warning.
Matti Hamalainen <ccr@tnsp.org>
parents:
432
diff
changeset
|
2333 size_t n = ((size_t) random()) % th_llist_length(setIdleMessages); |
264
4c1c18a388d9
Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents:
258
diff
changeset
|
2334 qlist_t *node = th_llist_get_nth(setIdleMessages, n); |
4c1c18a388d9
Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents:
258
diff
changeset
|
2335 nn_conn_send_msg(conn, optUserNameEnc, node->data); |
96
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
2336 prevTime = tmpTime; |
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
2337 } |
391 | 2338 |
2339 if (!colorSet) | |
2340 { | |
96
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
2341 colorSet = TRUE; |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
2342 nn_conn_send_msg_v(conn, optUserNameEnc, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor); |
96
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
2343 } |
391 | 2344 |
422 | 2345 nnwin_update_statusline(); |
2346 nnwin_update_editbuf(editBuf); | |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
2347 updateCount = 0; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
2348 } |
391 | 2349 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
2350 } |
391 | 2351 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2352 // Shutdown |
13
86fe5f0d1a85
Cleanups; Added probing connection (requesting some policy crap) to emulate the official client.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
2353 err_exit: |
316
1065115665bd
Plug some more minor memory leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
315
diff
changeset
|
2354 th_cfg_free(cfg); |
432
966c521e0954
Rename user home directory variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
431
diff
changeset
|
2355 th_free(setHomeDir); |
316
1065115665bd
Plug some more minor memory leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
315
diff
changeset
|
2356 th_llist_free_func(setIdleMessages, th_free); |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
2357 nn_userhash_free(nnUsers); |
97
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
2358 nn_editbuf_free(editBuf); |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
2359 |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
2360 { |
391 | 2361 int i; |
2362 for (i = 0; i <= SET_MAX_HISTORY; i++) | |
2363 nn_editbuf_free(histBuf[i]); | |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
2364 |
391 | 2365 for (i = 0; i < SET_MAX_WINDOWS; i++) |
2366 nn_window_free(chatWindows[i]); | |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
2367 } |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
2368 |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
2369 #ifdef __WIN32 |
391 | 2370 if (errorMessages) |
2371 { | |
275
66b90d71548b
Improve interactive prompts, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
2372 char *tmp; |
66b90d71548b
Improve interactive prompts, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
2373 wclear(editWin); |
66b90d71548b
Improve interactive prompts, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
2374 tmp = promptRequester(editWin, "Press enter to quit.\n", FALSE); |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2375 th_free(tmp); |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2376 } |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
2377 #endif |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2378 |
391 | 2379 if (cursesInit) |
2380 { | |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
2381 if (curVis != ERR) |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
2382 curs_set(curVis); |
422 | 2383 nnwin_close_windows(); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
2384 endwin(); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
2385 THMSG(1, "NCurses deinitialized.\n"); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
2386 } |
391 | 2387 |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2388 #ifndef __WIN32 |
223
03af28fb1c38
Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
2389 if (errorMessages) |
03af28fb1c38
Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
2390 THERR("%s", errorMessages); |
222
a1fefbce0b7a
Add a simple 'press enter to continue' for Windows port, when an error occurs so the user can see it before the application closes.
Matti Hamalainen <ccr@tnsp.org>
parents:
221
diff
changeset
|
2391 #endif |
391 | 2392 |
198
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
2393 th_free(optUserNameEnc); |
10 | 2394 |
168
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
2395 nn_conn_close(conn); |
391 | 2396 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
2397 if (networkInit) |
97
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
2398 nn_network_close(); |
68
3ab7751fdad1
MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents:
67
diff
changeset
|
2399 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
2400 THMSG(1, "Connection terminated.\n"); |
391 | 2401 |
242
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
2402 logFileClose(); |
133 | 2403 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
2404 return 0; |
0 | 2405 } |