Mercurial > hg > nnchat
annotate nnchat.c @ 317:0089d94201b6
Bump version.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 11 Jun 2011 06:32:11 +0300 |
parents | 1065115665bd |
children | 4acfcca39105 |
rev | line source |
---|---|
41 | 1 /* |
2 * NNChat - Custom chat client for NewbieNudes.com chatrooms | |
39 | 3 * Written by Matti 'ccr' Hämäläinen |
237 | 4 * (C) Copyright 2008-2011 Tecnic Software productions (TNSP) |
39 | 5 */ |
62
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
6 #include "libnnchat.h" |
0 | 7 #include <stdlib.h> |
8 #include "th_args.h" | |
133 | 9 #include "th_config.h" |
0 | 10 #include <string.h> |
11 #include <errno.h> | |
64
6a3a917303e4
Some random cleanups, bring back WinSock support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
12 #ifdef __WIN32 |
68
3ab7751fdad1
MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents:
67
diff
changeset
|
13 /* Undefine because both windows.h and curses.h #define it */ |
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 |
230
b64500bb7fbe
Some yet-unused backbuffer related code.
Matti Hamalainen <ccr@tnsp.org>
parents:
229
diff
changeset
|
35 #define SET_BACKBUF_LEN (512) /* Backbuffer size (in lines) */ |
141 | 36 #define SET_MAX_HISTORY (16) /* Command history length */ |
96
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
37 #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
|
38 #define SET_MAX_WINDOWS (32) |
0 | 39 |
49
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
40 |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
41 typedef struct { |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
42 qringbuf_t *data; /* "Backbuffer" data for this window */ |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
43 int pos; /* Current position in the window, 0 = real time */ |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
44 BOOL dirty; |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
45 |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
46 char *id; /* Chatter ID, NULL = main window */ |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
47 int num; /* Window number */ |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
48 |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
49 char *buf; |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
50 size_t len, bufsize; |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
51 } nn_window_t; |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
52 |
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
|
53 |
0 | 54 /* Options |
55 */ | |
254
269135d58acd
Change default port to 8005 (new main room).
Matti Hamalainen <ccr@tnsp.org>
parents:
252
diff
changeset
|
56 int optPort = 8005; |
207
e0c085426b91
Change default user color to black (#000000).
Matti Hamalainen <ccr@tnsp.org>
parents:
206
diff
changeset
|
57 int optUserColor = 0x000000; |
96
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
58 char *optServer = "chat.newbienudes.com", |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
59 *optUserName = NULL, |
198
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
60 *optUserNameCmd = NULL, |
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
61 *optUserNameEnc = NULL, |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
62 *optPassword = NULL, |
198
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
63 *optPasswordCmd = NULL, |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
64 *optLogFilename = NULL, |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
65 *optSite = "NN"; |
116
741e45592522
Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
66 char optNickSep = ':'; |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
67 BOOL optDaemon = FALSE; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
68 FILE *optLogFile = NULL; |
258 | 69 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
|
70 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
|
71 BOOL optLogEnable = FALSE; |
140
2d2ef5bbcc11
Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
72 |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
73 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
|
74 *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
|
75 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
|
76 *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
|
77 *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
|
78 |
265
b9c650db8a6a
Rename variable nnIgnoreList to setIgnoreList.
Matti Hamalainen <ccr@tnsp.org>
parents:
264
diff
changeset
|
79 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
|
80 *setIdleMessages = NULL; |
140
2d2ef5bbcc11
Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
81 nn_userhash_t *nnUsers = NULL; |
137
fad8c31e41e6
Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
82 char *setConfigFile = NULL, |
fad8c31e41e6
Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
83 *setBrowser = NULL; |
133 | 84 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
|
85 |
273 | 86 |
87 /* Logging mode flags | |
88 */ | |
89 enum { | |
90 LOG_FILE = 1, | |
91 LOG_WINDOW = 2, | |
92 LOG_STAMP = 4 | |
93 }; | |
94 | |
95 | |
0 | 96 /* Arguments |
97 */ | |
98 optarg_t optList[] = { | |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
99 { 0, '?', "help", "Show this help", OPT_NONE }, |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
100 { 1, 'v', "verbose", "Be more verbose", OPT_NONE }, |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
101 { 2, 'p', "port", "Connect to port", OPT_ARGREQ }, |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
102 { 3, 's', "server", "Server to connect to", OPT_ARGREQ }, |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
103 { 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
|
104 { 5, 'l', "logfile", "Log filename", OPT_ARGREQ }, |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
105 { 6, 'D', "daemon", "A pseudo-daemon mode for logging", OPT_NONE }, |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
106 { 7, 'S', "site", "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
|
107 { 8, 'd', "debug", "Enable various debug features", OPT_NONE }, |
0 | 108 }; |
109 | |
43
40ba8cdcf03a
Cleanups, added a silly morse code conversion mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
110 const int optListN = (sizeof(optList) / sizeof(optList[0])); |
0 | 111 |
112 | |
258 | 113 void argShowHelp(void) |
68
3ab7751fdad1
MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents:
67
diff
changeset
|
114 { |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
115 th_args_help(stdout, optList, optListN, th_prog_name, |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
116 "[options] <username> <password>"); |
68
3ab7751fdad1
MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents:
67
diff
changeset
|
117 } |
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 |
0 | 120 BOOL argHandleOpt(const int optN, char *optArg, char *currArg) |
121 { | |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
122 switch (optN) { |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
123 case 0: |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
124 argShowHelp(); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
125 exit(0); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
126 break; |
0 | 127 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
128 case 1: |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
129 th_verbosityLevel++; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
130 break; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
131 |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
132 case 2: |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
133 optPort = atoi(optArg); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
134 break; |
0 | 135 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
136 case 3: |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
137 optServer = optArg; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
138 break; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
139 |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
140 case 4: |
132 | 141 if ((optUserColor = th_get_hex_triplet(optArg)) < 0) { |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
142 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
|
143 optArg); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
144 return FALSE; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
145 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
146 THMSG(1, "Using color #%06x\n", optUserColor); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
147 break; |
0 | 148 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
149 case 5: |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
150 optLogFilename = optArg; |
242
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
151 optLogEnable = TRUE; |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
152 break; |
0 | 153 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
154 case 7: |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
155 optSite = optArg; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
156 break; |
33
e49ea6febfeb
Cleanups. Added option to specify/fake "site" where logging in from.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
157 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
158 case 6: |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
159 optDaemon = TRUE; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
160 THMSG(1, "Running in pseudo-daemon mode.\n"); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
161 break; |
21 | 162 |
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
|
163 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
|
164 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
|
165 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
|
166 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
|
167 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
168 default: |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
169 THERR("Unknown option '%s'.\n", currArg); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
170 return FALSE; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
171 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
172 |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
173 return TRUE; |
0 | 174 } |
175 | |
176 | |
177 BOOL argHandleFile(char *currArg) | |
178 { | |
198
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
179 if (!optUserNameCmd) |
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
180 optUserNameCmd = currArg; |
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
181 else if (!optPasswordCmd) |
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
182 optPasswordCmd = currArg; |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
183 else { |
198
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
184 THERR("Username '%s' already specified on commandline!\n", optUserNameCmd); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
185 return FALSE; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
186 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
187 |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
188 return TRUE; |
0 | 189 } |
190 | |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
191 |
156
0a9fe14882dc
Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
192 BOOL getTimeStamp(char *str, size_t len, const char *fmt) |
0a9fe14882dc
Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
193 { |
0a9fe14882dc
Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
194 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
|
195 struct tm *stamp_tm; |
0a9fe14882dc
Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
196 if ((stamp_tm = localtime(&stamp)) != NULL) { |
0a9fe14882dc
Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
197 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
|
198 return TRUE; |
0a9fe14882dc
Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
199 } else { |
0a9fe14882dc
Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
200 str[0] = 0; |
0a9fe14882dc
Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
201 return FALSE; |
0a9fe14882dc
Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
202 } |
0a9fe14882dc
Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
203 } |
49
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
204 |
226 | 205 |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
206 nn_window_t *nn_window_new(const char *id) |
191
4007b9ac7cde
Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
207 { |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
208 nn_window_t *res = th_calloc(1, sizeof(nn_window_t)); |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
209 |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
210 if (res == NULL) return NULL; |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
211 |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
212 res->data = th_ringbuf_new(SET_BACKBUF_LEN, th_free); |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
213 if (res->data == NULL) { |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
214 th_free(res); |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
215 return NULL; |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
216 } |
309 | 217 |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
218 res->id = th_strdup(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
|
219 |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
220 return res; |
191
4007b9ac7cde
Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
221 } |
4007b9ac7cde
Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
222 |
258 | 223 |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
224 void nn_window_free(nn_window_t *win) |
191
4007b9ac7cde
Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
225 { |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
226 if (win != NULL) { |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
227 th_ringbuf_free(win->data); |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
228 th_free(win->id); |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
229 th_free(win); |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
230 } |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
231 } |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
232 |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
233 |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
234 nn_window_t *nn_find_window(const char *id) |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
235 { |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
236 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
|
237 |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
238 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
|
239 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
|
240 chatWindows[i]->id != NULL && |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
241 strcasecmp(id, chatWindows[i]->id) == 0) |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
242 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
|
243 |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
244 return NULL; |
191
4007b9ac7cde
Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
245 } |
4007b9ac7cde
Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
246 |
258 | 247 |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
248 BOOL openWindow(const char *name, BOOL curwin) |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
249 { |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
250 int i; |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
251 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
|
252 if (name == NULL) |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
253 return FALSE; |
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 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
|
256 return FALSE; |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
257 |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
258 for (i = 1; i < SET_MAX_WINDOWS; i++) |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
259 if (chatWindows[i] == NULL) { |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
260 res->num = i; |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
261 chatWindows[i] = res; |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
262 if (curwin) |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
263 currWin = res; |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
264 return TRUE; |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
265 } |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
266 |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
267 return FALSE; |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
268 } |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
269 |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
270 |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
271 void closeWindow(nn_window_t *win) |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
272 { |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
273 int i; |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
274 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
|
275 |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
276 for (i = 1; i < SET_MAX_WINDOWS; i++) |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
277 if (chatWindows[i] == win) { |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
278 chatWindows[i] = NULL; |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
279 nn_window_free(win); |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
280 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 } |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
283 |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
284 |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
285 void updateStatus(void) |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
286 { |
156
0a9fe14882dc
Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
287 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
|
288 int i; |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
289 |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
290 if (statusWin == NULL) return; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
291 |
156
0a9fe14882dc
Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
292 getTimeStamp(tmpStr, sizeof(tmpStr), "%H:%M:%S"); |
110
8af4072dc31a
Fix Win32/MinGW/PDcurses issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
109
diff
changeset
|
293 |
119
4bc63a535acb
Fix some PDCurses incompatibilities and remove some Win32/PDCurses specific hacks.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
294 wbkgdset(statusWin, COLOR_PAIR(10)); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
295 werase(statusWin); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
296 |
119
4bc63a535acb
Fix some PDCurses incompatibilities and remove some Win32/PDCurses specific hacks.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
297 wattrset(statusWin, A_BOLD | COLOR_PAIR(11)); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
298 mvwaddstr(statusWin, 0, 1, tmpStr); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
299 |
119
4bc63a535acb
Fix some PDCurses incompatibilities and remove some Win32/PDCurses specific hacks.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
300 wattrset(statusWin, A_BOLD | COLOR_PAIR(13)); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
301 waddstr(statusWin, " | "); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
302 wattrset(statusWin, A_BOLD | COLOR_PAIR(16)); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
303 waddstr(statusWin, optUserName); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
304 wattrset(statusWin, A_BOLD | COLOR_PAIR(13)); |
29
a27ef0e359b9
Make statusline more informative.
Matti Hamalainen <ccr@tnsp.org>
parents:
28
diff
changeset
|
305 |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
306 wattrset(statusWin, A_BOLD | COLOR_PAIR(13)); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
307 waddstr(statusWin, " | "); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
308 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
|
309 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
|
310 waddstr(statusWin, tmpStr); |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
311 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
312 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
|
313 waddstr(statusWin, " | WIN: "); |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
314 snprintf(tmpStr, sizeof(tmpStr), "%d: %s", currWin->num + 1, currWin->id ? currWin->id : "MAIN"); |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
315 waddstr(statusWin, tmpStr); |
29
a27ef0e359b9
Make statusline more informative.
Matti Hamalainen <ccr@tnsp.org>
parents:
28
diff
changeset
|
316 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
317 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
|
318 waddstr(statusWin, " | "); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
319 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
|
320 |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
321 for (i = 0; i < SET_MAX_WINDOWS; i++) |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
322 if (chatWindows[i] != NULL && chatWindows[i]->dirty) { |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
323 snprintf(tmpStr, sizeof(tmpStr), "%d ", i + 1); |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
324 waddstr(statusWin, tmpStr); |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
325 } |
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 wrefresh(statusWin); |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
328 } |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
329 |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
330 |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
331 void printEditBuf(nn_editbuf_t *buf) |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
332 { |
191
4007b9ac7cde
Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
333 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
|
334 if (editWin == NULL || buf == NULL) return; |
32
67ec4073e38c
Check for NULL pointers (fixes "daemon" mode)
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
335 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
336 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
|
337 tmp = nn_username_decode(th_strdup(buf->data)); |
191
4007b9ac7cde
Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
338 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
339 werase(editWin); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
340 |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
341 wattrset(editWin, A_NORMAL); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
342 |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
343 if (buf->pos < buf->len) { |
191
4007b9ac7cde
Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
344 waddnstr(editWin, tmp, buf->pos); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
345 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
|
346 waddch(editWin, tmp[buf->pos]); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
347 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
|
348 waddnstr(editWin, tmp + buf->pos + 1, buf->len - buf->pos - 1); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
349 } else { |
191
4007b9ac7cde
Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
350 waddnstr(editWin, tmp, buf->len); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
351 wattrset(editWin, A_REVERSE); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
352 waddch(editWin, ' '); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
353 wattrset(editWin, A_NORMAL); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
354 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
355 wrefresh(editWin); |
191
4007b9ac7cde
Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
356 th_free(tmp); |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
357 } |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
358 |
226 | 359 |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
360 int printWin(WINDOW *win, const char *fmt) |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
361 { |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
362 const char *s = fmt; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
363 int col = 0; |
141 | 364 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
365 while (*s) { |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
366 if (*s == '½') { |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
367 int val = 0; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
368 s++; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
369 if (*s == '½') { |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
370 waddch(win, ((unsigned char) *s) | col); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
371 s++; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
372 } else { |
110
8af4072dc31a
Fix Win32/MinGW/PDcurses issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
109
diff
changeset
|
373 while (*s >= '0' && *s <= '9') { |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
374 val *= 10; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
375 val += (*s - '0'); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
376 s++; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
377 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
378 if (*s != '½') return -1; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
379 s++; |
191
4007b9ac7cde
Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
380 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
381 if (val < 9) { |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
382 col = A_DIM | COLOR_PAIR(val); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
383 } else if (val < 30) { |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
384 col = A_BOLD | COLOR_PAIR(val - 9); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
385 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
386 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
387 } else { |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
388 waddch(win, ((unsigned char) *s) | col); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
389 s++; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
390 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
391 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
392 return 0; |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
393 } |
0 | 394 |
62
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
395 |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
396 void nn_window_print(nn_window_t *win, const char *fmt) |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
397 { |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
398 const char *s = fmt; |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
399 while (*s) { |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
400 if (*s == '\n') { |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
401 th_vputch(&(win->buf), &(win->bufsize), &(win->len), '\n'); |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
402 th_vputch(&(win->buf), &(win->bufsize), &(win->len), 0); |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
403 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
|
404 win->buf = NULL; |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
405 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
|
406 } |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
407 else |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
408 if ((unsigned char) *s == 255) |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
409 th_vputch(&(win->buf), &(win->bufsize), &(win->len), ' '); |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
410 else |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
411 if (*s != '\r') |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
412 th_vputch(&(win->buf), &(win->bufsize), &(win->len), *s); |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
413 s++; |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
414 } |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
415 } |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
416 |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
417 |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
418 void updateMainWin(BOOL force) |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
419 { |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
420 int y, w, h, offs; |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
421 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
|
422 |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
423 if (mainWin == NULL || currWin == NULL) return; |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
424 if (!force && !currWin->dirty) return; |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
425 |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
426 buf = currWin->data; |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
427 getmaxyx(mainWin, h, w); |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
428 werase(mainWin); |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
429 |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
430 offs = buf->size - h - currWin->pos; |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
431 if (offs < 0) |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
432 offs = 0; |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
433 |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
434 for (y = 0; y < h && offs < buf->size; offs++) { |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
435 if (buf->data[offs] != NULL) |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
436 printWin(mainWin, (char *) buf->data[offs]); |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
437 y = getcury(mainWin); |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
438 } |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
439 |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
440 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
|
441 wrefresh(mainWin); |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
442 } |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
443 |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
444 |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
445 int printFile(FILE *outFile, const char *fmt) |
0 | 446 { |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
447 const char *s = fmt; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
448 |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
449 while (*s) { |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
450 if (*s == '½') { |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
451 s++; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
452 if (*s == '½') { |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
453 fputc((unsigned char) *s, outFile); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
454 s++; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
455 } else { |
74 | 456 while (*s && isdigit((int) *s)) s++; |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
457 if (*s != '½') return -1; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
458 s++; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
459 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
460 } else { |
191
4007b9ac7cde
Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
461 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
|
462 fputc(' ', outFile); |
4007b9ac7cde
Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
463 else |
4007b9ac7cde
Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
464 fputc((unsigned char) *s, outFile); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
465 s++; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
466 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
467 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
468 |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
469 return 0; |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
470 } |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
471 |
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 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
|
473 { |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
474 char tmpStr[128], *buf; |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
475 |
156
0a9fe14882dc
Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
476 getTimeStamp(tmpStr, sizeof(tmpStr), "½17½[½11½%H:%M:%S½17½]½0½ "); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
477 |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
478 buf = th_strdup_vprintf(fmt, ap); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
479 |
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
|
480 if (optLogFile && (flags & LOG_FILE)) { |
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
|
481 if (flags & LOG_STAMP) printFile(optLogFile, tmpStr); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
482 printFile(optLogFile, buf); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
483 fflush(optLogFile); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
484 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
485 |
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
|
486 if (!optDaemon && (flags & LOG_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 nn_window_t *tmp = win != NULL ? win : chatWindows[0]; |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
488 if (flags & LOG_STAMP) nn_window_print(tmp, tmpStr); |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
489 nn_window_print(tmp, buf); |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
490 updateMainWin(FALSE); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
491 } |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
492 |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
493 th_free(buf); |
0 | 494 } |
495 | |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
496 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
|
497 { |
ed4067c10a8a
Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
498 va_list ap; |
ed4067c10a8a
Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
499 |
ed4067c10a8a
Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
500 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
|
501 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
|
502 va_end(ap); |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
503 } |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
504 |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
505 void printMsgC(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
|
506 { |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
507 va_list ap; |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
508 |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
509 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
|
510 printMsgV(win, 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
|
511 va_end(ap); |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
512 } |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
513 |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
514 void printMsgQ(nn_window_t *win, BOOL logOnly, 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
|
515 { |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
516 va_list ap; |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
517 |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
518 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
|
519 printMsgV(win, logOnly ? (LOG_STAMP | LOG_FILE) : (LOG_STAMP | LOG_WINDOW | LOG_FILE), fmt, ap); |
100
ed4067c10a8a
Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
520 va_end(ap); |
ed4067c10a8a
Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
521 } |
ed4067c10a8a
Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
522 |
0 | 523 |
223
03af28fb1c38
Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
524 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
|
525 |
236
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
526 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
|
527 { |
223
03af28fb1c38
Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
528 char *tmp; |
236
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
529 va_list ap2; |
96
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
530 |
236
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
531 va_copy(ap2, ap); |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
532 printMsgV(chatWindows[0], LOG_STAMP | LOG_WINDOW | LOG_FILE, fmt, ap); |
96
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
533 |
223
03af28fb1c38
Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
534 tmp = th_strdup_vprintf(fmt, ap2); |
03af28fb1c38
Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
535 |
03af28fb1c38
Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
536 if (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
|
537 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
|
538 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
|
539 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
|
540 errorMessages = tmp2; |
03af28fb1c38
Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
541 } else |
03af28fb1c38
Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
542 errorMessages = tmp; |
96
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
543 } |
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
544 |
236
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
545 void errorMsg(const char *fmt, ...) |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
546 { |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
547 va_list ap; |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
548 |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
549 va_start(ap, fmt); |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
550 errorMsgV(fmt, ap); |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
551 va_end(ap); |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
552 } |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
553 |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
554 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
|
555 { |
262
6d48fc4fd421
Shut up some trivial warnings.
Matti Hamalainen <ccr@tnsp.org>
parents:
258
diff
changeset
|
556 (void) conn; |
236
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
557 errorMsgV(fmt, ap); |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
558 } |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
559 |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
560 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
|
561 { |
262
6d48fc4fd421
Shut up some trivial warnings.
Matti Hamalainen <ccr@tnsp.org>
parents:
258
diff
changeset
|
562 (void) conn; |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
563 printMsgV(chatWindows[0], 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
|
564 } |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
565 |
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
|
566 |
801ac37321f6
Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
567 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
|
568 { |
265
b9c650db8a6a
Rename variable nnIgnoreList to setIgnoreList.
Matti Hamalainen <ccr@tnsp.org>
parents:
264
diff
changeset
|
569 qlist_t *node = setIgnoreList; |
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
|
570 while (node != NULL) { |
801ac37321f6
Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
571 if (strcasecmp(name, (char *) node->data) == 0) |
801ac37321f6
Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
572 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
|
573 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
|
574 } |
801ac37321f6
Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
575 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
|
576 } |
801ac37321f6
Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
577 |
801ac37321f6
Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
578 |
168
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
579 int handleUser(nn_conn_t *conn, const char *str) |
0 | 580 { |
108
f323b137ca08
Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents:
107
diff
changeset
|
581 const char *msg = "</USER><MESSAGE>", *p = str; |
229
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
582 BOOL isMine, isIgnored = FALSE; |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
583 char *s, *t, *userName; |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
584 |
168
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
585 (void) conn; |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
586 |
229
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
587 /* Find start of the message */ |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
588 s = strstr(str, msg); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
589 if (!s) return 1; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
590 *s = 0; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
591 s += strlen(msg); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
592 |
229
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
593 /* Find end of the message */ |
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
594 t = strstr(s, "</MESSAGE>"); |
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
595 if (!t) return 3; |
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
596 *t = 0; |
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
597 |
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
598 /* Decode message string */ |
97
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
599 s = nn_decode_str1(s); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
600 if (!s) return -1; |
229
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
601 |
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
602 /* Decode username */ |
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
|
603 userName = nn_decode_str1(p); |
801ac37321f6
Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
604 if (!userName) { |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
605 th_free(s); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
606 return -2; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
607 } |
229
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
608 |
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
609 /* 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
|
610 * that it is not our OWN username! |
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
611 */ |
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
|
612 isMine = strcmp(userName, optUserName) == 0; |
258 | 613 isIgnored = setIgnoreMode && !isMine && checkIgnoreList(userName); |
108
f323b137ca08
Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents:
107
diff
changeset
|
614 |
229
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
615 /* Is it a special control message? */ |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
616 if (*s == '/') { |
108
f323b137ca08
Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents:
107
diff
changeset
|
617 /* Ignore room join/leave messages */ |
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
|
618 if (!optDebug && (strstr(s, "left the room") || strstr(s, "joined the room from"))) |
229
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
619 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
|
620 |
97
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
621 t = nn_strip_tags(s + 1); |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
622 if (!strncmp(t, "BPRV ", 5)) { |
293 | 623 char *name, *tmp, *msg, *h; |
624 nn_window_t *win; | |
625 h = nn_decode_str2(t + 1); | |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
626 |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
627 if (!strncmp(t, "BPRV from ", 10)) { |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
628 name = nn_decode_str2(t + 10); |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
629 isMine = FALSE; |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
630 } else { |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
631 name = nn_decode_str2(t + 8); |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
632 isMine = TRUE; |
188
6b399b7ce40b
Automatically grab PRV target from incoming PRV if target not already set.
Matti Hamalainen <ccr@tnsp.org>
parents:
187
diff
changeset
|
633 } |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
634 |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
635 for (tmp = name; *tmp && *tmp != ':'; tmp++); |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
636 if (tmp[0] != 0 && tmp[1] == ' ') |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
637 msg = tmp + 2; |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
638 else |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
639 msg = ""; |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
640 *tmp = 0; |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
641 |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
642 isIgnored = setIgnoreMode && checkIgnoreList(name); |
293 | 643 win = nn_find_window(name); |
644 | |
645 if (win != NULL) | |
646 printMsgQ(win, isIgnored, "½5½<½%d½%s½5½>½0½ %s\n", isMine ? 14 : 15, isMine ? optUserName : name, msg); | |
647 else | |
648 printMsgQ(NULL, isIgnored, "½11½%s½0½\n", h); | |
649 | |
314 | 650 th_free(name); |
293 | 651 th_free(h); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
652 } else { |
229
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
653 /* 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
|
654 char *h = nn_decode_str2(t); |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
655 printMsgQ(NULL, isIgnored, "½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
|
656 th_free(h); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
657 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
658 th_free(t); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
659 } else { |
229
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
660 /* 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
|
661 char *h; |
97
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
662 t = nn_strip_tags(s); |
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
663 h = nn_decode_str2(t); |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
664 printMsgQ(NULL, isIgnored, "½5½<½%d½%s½5½>½0½ %s\n", isMine ? 14 : 15, userName, h); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
665 th_free(h); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
666 th_free(t); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
667 } |
108
f323b137ca08
Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents:
107
diff
changeset
|
668 |
229
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
669 done: |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
670 th_free(s); |
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
|
671 th_free(userName); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
672 return 0; |
0 | 673 } |
674 | |
675 | |
168
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
676 int handleLogin(nn_conn_t *conn, const char *str) |
0 | 677 { |
156
0a9fe14882dc
Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
678 char tmpStr[256]; |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
679 |
156
0a9fe14882dc
Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
680 getTimeStamp(tmpStr, sizeof(tmpStr), "%c"); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
681 |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
682 if (!strncmp(str, "FAILURE", 7)) { |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
683 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
|
684 return -2; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
685 } else if (!strncmp(str, "SUCCESS", 7)) { |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
686 printMsg(NULL, "½2½Login success½0½ - ½3½%s½0½\n", tmpStr); |
198
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
687 nn_conn_send_msg(conn, optUserNameEnc, "%%2FRequestUserList"); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
688 return 0; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
689 } else |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
690 return 1; |
0 | 691 } |
692 | |
693 | |
168
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
694 int handleAddUser(nn_conn_t *conn, const char *str) |
0 | 695 { |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
696 char *p, *s = strstr(str, "</ADD_USER>"); |
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
|
697 nn_window_t *win; |
0 | 698 |
168
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
699 (void) conn; |
0 | 700 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
701 if (!s) return 1; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
702 *s = 0; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
703 |
97
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
704 p = nn_dbldecode_str(str); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
705 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
|
706 |
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
|
707 win = nn_find_window(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
|
708 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
|
709 |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
710 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
|
711 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
|
712 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
|
713 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
714 th_free(p); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
715 return 0; |
0 | 716 } |
717 | |
718 | |
168
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
719 int handleDeleteUser(nn_conn_t *conn, const char *str) |
0 | 720 { |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
721 char *p, *s = strstr(str, "</DELETE_USER>"); |
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
|
722 nn_window_t *win; |
0 | 723 |
168
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
724 (void) conn; |
0 | 725 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
726 if (!s) return 1; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
727 *s = 0; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
728 |
97
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
729 p = nn_dbldecode_str(str); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
730 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
|
731 |
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
|
732 win = nn_find_window(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
|
733 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
|
734 |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
735 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
|
736 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
|
737 printMsg(win, "! ½3½%s½0½ ½1½left 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
|
738 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
739 th_free(p); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
740 return 0; |
0 | 741 } |
742 | |
743 | |
168
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
744 int handleFoo(nn_conn_t *conn, const char *str) |
0 | 745 { |
168
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
746 (void) conn; (void) str; |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
747 |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
748 return 0; |
0 | 749 } |
750 | |
751 | |
168
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
752 int handleBoot(nn_conn_t *conn, const char *str) |
96
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
753 { |
168
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
754 (void) conn; (void) str; |
96
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
755 errorMsg("Booted by server.\n"); |
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
756 return -1; |
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
757 } |
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
758 |
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
759 |
0 | 760 typedef struct { |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
761 char *cmd; |
129
4235ff4ced04
"Optimize" protocol handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
128
diff
changeset
|
762 ssize_t len; |
168
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
763 int (*handler)(nn_conn_t *, const char *); |
0 | 764 } protocmd_t; |
765 | |
766 | |
129
4235ff4ced04
"Optimize" protocol handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
128
diff
changeset
|
767 static protocmd_t protoCmds[] = { |
4235ff4ced04
"Optimize" protocol handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
128
diff
changeset
|
768 { "<USER>", -1, handleUser }, |
4235ff4ced04
"Optimize" protocol handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
128
diff
changeset
|
769 { "<LOGIN_", -1, handleLogin }, |
4235ff4ced04
"Optimize" protocol handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
128
diff
changeset
|
770 { "<DELETE_USER>", -1, handleDeleteUser }, |
4235ff4ced04
"Optimize" protocol handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
128
diff
changeset
|
771 { "<ADD_USER>", -1, handleAddUser }, |
4235ff4ced04
"Optimize" protocol handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
128
diff
changeset
|
772 { "<NUMCLIENTS>", -1, handleFoo }, |
4235ff4ced04
"Optimize" protocol handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
128
diff
changeset
|
773 { "<BOOT />", -1, handleBoot }, |
0 | 774 }; |
775 | |
108
f323b137ca08
Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents:
107
diff
changeset
|
776 static const int nprotoCmds = sizeof(protoCmds) / sizeof(protoCmds[0]); |
0 | 777 |
778 | |
168
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
779 int handleProtocol(nn_conn_t *conn, const char *buf, const ssize_t bufLen) |
0 | 780 { |
130
352ec3c300e4
A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
781 static BOOL protoCmdsInit = FALSE; |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
782 int i; |
130
352ec3c300e4
A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
783 |
352ec3c300e4
A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
784 if (!protoCmdsInit) { |
352ec3c300e4
A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
785 for (i = 0; i < nprotoCmds; i++) |
352ec3c300e4
A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
786 protoCmds[i].len = strlen(protoCmds[i].cmd); |
352ec3c300e4
A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
787 protoCmdsInit = TRUE; |
352ec3c300e4
A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
788 } |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
789 |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
790 for (i = 0; i < nprotoCmds; i++) { |
129
4235ff4ced04
"Optimize" protocol handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
128
diff
changeset
|
791 ssize_t cmdLen = protoCmds[i].len; |
4235ff4ced04
"Optimize" protocol handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
128
diff
changeset
|
792 if (cmdLen < bufLen && !strncmp(buf, protoCmds[i].cmd, cmdLen)) |
168
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
793 return protoCmds[i].handler(conn, buf + cmdLen); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
794 } |
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
|
795 |
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
|
796 if (optDebug) { |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
797 printMsg(NULL, "Unknown protocmd: \"%s\"\n", buf); |
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
|
798 return 0; |
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
|
799 } else |
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
|
800 return 1; |
0 | 801 } |
802 | |
125
d03ebefb92a6
Improve internal command handling, use fork() and execlp() instead of system() for opening profiles into external browser's tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
803 char * trimLeft(char *buf) |
d03ebefb92a6
Improve internal command handling, use fork() and execlp() instead of system() for opening profiles into external browser's tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
804 { |
202
4b93442bd411
Silence a warning under Solaris and few other systems by using th_isspace() wrapper instead of isspace().
Matti Hamalainen <ccr@tnsp.org>
parents:
198
diff
changeset
|
805 while (*buf != 0 && th_isspace(*buf)) buf++; |
125
d03ebefb92a6
Improve internal command handling, use fork() and execlp() instead of system() for opening profiles into external browser's tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
806 return buf; |
d03ebefb92a6
Improve internal command handling, use fork() and execlp() instead of system() for opening profiles into external browser's tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
807 } |
0 | 808 |
140
2d2ef5bbcc11
Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
809 int compareUsername(const void *s1, const void *s2) |
2d2ef5bbcc11
Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
810 { |
2d2ef5bbcc11
Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
811 return strcasecmp((char *) s1, (char *) s2); |
2d2ef5bbcc11
Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
812 } |
2d2ef5bbcc11
Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
813 |
168
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
814 int handleUserInput(nn_conn_t *conn, char *buf, size_t bufLen) |
0 | 815 { |
78
745f670068dc
Add functions to simplify code.
Matti Hamalainen <ccr@tnsp.org>
parents:
77
diff
changeset
|
816 char *tmpStr, tmpBuf[4096]; |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
817 BOOL result; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
818 |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
819 /* Trim right */ |
112
c4865ac2386c
Fix right-side trimming of command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
820 bufLen--; |
c4865ac2386c
Fix right-side trimming of command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
111
diff
changeset
|
821 buf[bufLen--] = 0; |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
822 while (bufLen > 0 && (buf[bufLen] == '\n' || buf[bufLen] == '\r' || th_isspace(buf[bufLen]))) |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
823 buf[bufLen--] = 0; |
258 | 824 |
825 /* 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
|
826 nn_username_decode(buf); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
827 |
109
1323a7f88c21
Fix /w -command and add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
828 /* Check for special user commands */ |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
829 if (*buf == 0) { |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
830 return 1; |
258 | 831 } |
832 else if (!strncasecmp(buf, "/color ", 7)) { | |
109
1323a7f88c21
Fix /w -command and add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
833 /* Change color */ |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
834 int tmpInt; |
132 | 835 if ((tmpInt = th_get_hex_triplet(trimLeft(buf + 7))) < 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
|
836 printMsg(currWin, "Invalid color value '%s'\n", buf+7); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
837 return 1; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
838 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
839 optUserColor = tmpInt; |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
840 printMsg(currWin, "Setting color to #%06x\n", optUserColor); |
198
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
841 nn_conn_send_msg(conn, optUserNameEnc, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
842 return 0; |
258 | 843 } |
844 else if (!strncasecmp(buf, "/ignore", 7)) { | |
140
2d2ef5bbcc11
Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
845 char *name = trimLeft(buf + 7); |
2d2ef5bbcc11
Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
846 if (strlen(name) > 0) { |
2d2ef5bbcc11
Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
847 /* Add or remove someone to/from ignore */ |
265
b9c650db8a6a
Rename variable nnIgnoreList to setIgnoreList.
Matti Hamalainen <ccr@tnsp.org>
parents:
264
diff
changeset
|
848 qlist_t *user = th_llist_find_func(setIgnoreList, name, compareUsername); |
140
2d2ef5bbcc11
Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
849 if (user != 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
|
850 printMsg(currWin, "Removed user '%s' from ignore.\n", name); |
265
b9c650db8a6a
Rename variable nnIgnoreList to setIgnoreList.
Matti Hamalainen <ccr@tnsp.org>
parents:
264
diff
changeset
|
851 th_llist_delete_node(&setIgnoreList, user); |
140
2d2ef5bbcc11
Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
852 } else { |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
853 printMsg(currWin, "Now ignoring '%s'.\n", name); |
265
b9c650db8a6a
Rename variable nnIgnoreList to setIgnoreList.
Matti Hamalainen <ccr@tnsp.org>
parents:
264
diff
changeset
|
854 th_llist_append(&setIgnoreList, th_strdup(name)); |
140
2d2ef5bbcc11
Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
855 } |
2d2ef5bbcc11
Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
856 } else { |
2d2ef5bbcc11
Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
857 /* Just list whomever is in ignore now */ |
265
b9c650db8a6a
Rename variable nnIgnoreList to setIgnoreList.
Matti Hamalainen <ccr@tnsp.org>
parents:
264
diff
changeset
|
858 qlist_t *user = setIgnoreList; |
b9c650db8a6a
Rename variable nnIgnoreList to setIgnoreList.
Matti Hamalainen <ccr@tnsp.org>
parents:
264
diff
changeset
|
859 ssize_t nuser = th_llist_length(setIgnoreList); |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
860 char *result = th_strdup_printf("Users ignored (%d): ", nuser); |
140
2d2ef5bbcc11
Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
861 while (user != NULL) { |
2d2ef5bbcc11
Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
862 if (user->data != 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
|
863 th_pstr_printf(&result, "%s'%s'", result, (char *) user->data); |
140
2d2ef5bbcc11
Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
864 if (--nuser > 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
|
865 th_pstr_printf(&result, "%s, ", result); |
140
2d2ef5bbcc11
Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
866 } |
2d2ef5bbcc11
Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
867 user = user->next; |
2d2ef5bbcc11
Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
868 } |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
869 printMsg(currWin, "%s\n", result); |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
870 th_free(result); |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
871 } |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
872 return 0; |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
873 } |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
874 else if (!strncasecmp(buf, "/query", 6)) { |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
875 char *name = trimLeft(buf + 6); |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
876 if (strlen(name) > 0) { |
303
859578ec3275
Fix encoding of usernames in /query and /close.
Matti Hamalainen <ccr@tnsp.org>
parents:
301
diff
changeset
|
877 nn_user_t *user = nn_user_find(nnUsers, nn_username_encode(name)); |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
878 if (user != NULL) { |
303
859578ec3275
Fix encoding of usernames in /query and /close.
Matti Hamalainen <ccr@tnsp.org>
parents:
301
diff
changeset
|
879 name = nn_username_decode(th_strdup(user->name)); |
859578ec3275
Fix encoding of usernames in /query and /close.
Matti Hamalainen <ccr@tnsp.org>
parents:
301
diff
changeset
|
880 printMsg(currWin, "Opening PRV query for '%s'.\n", name); |
859578ec3275
Fix encoding of usernames in /query and /close.
Matti Hamalainen <ccr@tnsp.org>
parents:
301
diff
changeset
|
881 if (openWindow(name, TRUE)) |
859578ec3275
Fix encoding of usernames in /query and /close.
Matti Hamalainen <ccr@tnsp.org>
parents:
301
diff
changeset
|
882 printMsg(currWin, "In PRV query with '%s'.\n", name); |
859578ec3275
Fix encoding of usernames in /query and /close.
Matti Hamalainen <ccr@tnsp.org>
parents:
301
diff
changeset
|
883 th_free(name); |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
884 } |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
885 } else { |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
886 printMsg(currWin, "Usage: /query username\n"); |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
887 printMsg(currWin, "To close a PRV query, use /close [username]\n"); |
303
859578ec3275
Fix encoding of usernames in /query and /close.
Matti Hamalainen <ccr@tnsp.org>
parents:
301
diff
changeset
|
888 printMsg(currWin, "/close without username will close the current PRV window.\n"); |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
889 } |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
890 return 0; |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
891 } |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
892 else if (!strncasecmp(buf, "/close", 6)) { |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
893 char *name = trimLeft(buf + 6); |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
894 if (strlen(name) > 0) { |
303
859578ec3275
Fix encoding of usernames in /query and /close.
Matti Hamalainen <ccr@tnsp.org>
parents:
301
diff
changeset
|
895 nn_window_t *win; |
859578ec3275
Fix encoding of usernames in /query and /close.
Matti Hamalainen <ccr@tnsp.org>
parents:
301
diff
changeset
|
896 win = nn_find_window(name); |
301
388c22d6ab44
Closing PRV buffers should not depend on the user being in the internal userlist. Fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
298
diff
changeset
|
897 if (win != NULL) { |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
898 closeWindow(win); |
303
859578ec3275
Fix encoding of usernames in /query and /close.
Matti Hamalainen <ccr@tnsp.org>
parents:
301
diff
changeset
|
899 printMsg(currWin, "Closed PRV query to '%s'.\n", name); |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
900 } else { |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
901 printMsg(currWin, "No PRV query by name '%s'.\n", name); |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
902 } |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
903 } else { |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
904 if (currWin != chatWindows[0]) { |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
905 closeWindow(currWin); |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
906 currWin = chatWindows[0]; |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
907 } |
140
2d2ef5bbcc11
Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
908 } |
2d2ef5bbcc11
Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
909 return 0; |
258 | 910 } |
911 else if (!strncasecmp(buf, "/save", 5)) { | |
133 | 912 /* Save configuration */ |
143
5babbff7ca26
Rename some variables, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
913 FILE *cfgfile = fopen(setConfigFile, "w"); |
5babbff7ca26
Rename some variables, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
914 if (cfgfile == 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
|
915 printMsg(currWin, "Could not create configuration to file '%s': %s\n", |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
916 setConfigFile, strerror(errno)); |
133 | 917 return 0; |
918 } | |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
919 printMsg(currWin, "Configuration saved in file '%s', res=%d\n", |
133 | 920 setConfigFile, |
143
5babbff7ca26
Rename some variables, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
921 th_cfg_write(cfgfile, setConfigFile, cfg)); |
133 | 922 |
143
5babbff7ca26
Rename some variables, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
142
diff
changeset
|
923 fclose(cfgfile); |
133 | 924 return 0; |
258 | 925 } |
926 else if (!strncasecmp(buf, "/w ", 3)) { | |
109
1323a7f88c21
Fix /w -command and add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
927 /* Open given username's profile via firefox in a new tab */ |
137
fad8c31e41e6
Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
928 char *name = trimLeft(buf + 3); |
114
256cca8cc086
Support $BROWSER environment variable setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
113
diff
changeset
|
929 |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
930 printMsg(currWin, "Opening profile for: '%s'\n", name); |
125
d03ebefb92a6
Improve internal command handling, use fork() and execlp() instead of system() for opening profiles into external browser's tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
931 |
108
f323b137ca08
Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents:
107
diff
changeset
|
932 tmpStr = nn_encode_str1(name); |
197
e0ec2280a778
Implement browser launching on Windows via ShellExecute().
Matti Hamalainen <ccr@tnsp.org>
parents:
196
diff
changeset
|
933 #ifdef __WIN32 |
e0ec2280a778
Implement browser launching on Windows via ShellExecute().
Matti Hamalainen <ccr@tnsp.org>
parents:
196
diff
changeset
|
934 { |
218
0e60593006c9
Change ShellExecute return value's variable type to HINSTANCE as it should be.
Matti Hamalainen <ccr@tnsp.org>
parents:
217
diff
changeset
|
935 HINSTANCE status; |
197
e0ec2280a778
Implement browser launching on Windows via ShellExecute().
Matti Hamalainen <ccr@tnsp.org>
parents:
196
diff
changeset
|
936 snprintf(tmpBuf, sizeof(tmpBuf), "http://www.newbienudes.com/profile/%s/", tmpStr); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
937 th_free(tmpStr); |
197
e0ec2280a778
Implement browser launching on Windows via ShellExecute().
Matti Hamalainen <ccr@tnsp.org>
parents:
196
diff
changeset
|
938 status = ShellExecute(NULL, "open", tmpBuf, NULL, NULL, SW_SHOWNA); |
e0ec2280a778
Implement browser launching on Windows via ShellExecute().
Matti Hamalainen <ccr@tnsp.org>
parents:
196
diff
changeset
|
939 if (status <= 32) |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
940 printMsg(currWin, "Could not launch default web browser: %d\n", status); |
197
e0ec2280a778
Implement browser launching on Windows via ShellExecute().
Matti Hamalainen <ccr@tnsp.org>
parents:
196
diff
changeset
|
941 } |
128
713879a7ca10
Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents:
125
diff
changeset
|
942 #else |
713879a7ca10
Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents:
125
diff
changeset
|
943 { |
713879a7ca10
Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents:
125
diff
changeset
|
944 int status; |
233
6b1c67274f6c
Use a pipe to redirect executed browser's stderr and stdout when opening profiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
945 int fds[2]; |
128
713879a7ca10
Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents:
125
diff
changeset
|
946 pid_t pid; |
197
e0ec2280a778
Implement browser launching on Windows via ShellExecute().
Matti Hamalainen <ccr@tnsp.org>
parents:
196
diff
changeset
|
947 snprintf(tmpBuf, sizeof(tmpBuf), "openurl(http://www.newbienudes.com/profile/%s/,new-tab)", tmpStr); |
e0ec2280a778
Implement browser launching on Windows via ShellExecute().
Matti Hamalainen <ccr@tnsp.org>
parents:
196
diff
changeset
|
948 th_free(tmpStr); |
e0ec2280a778
Implement browser launching on Windows via ShellExecute().
Matti Hamalainen <ccr@tnsp.org>
parents:
196
diff
changeset
|
949 |
233
6b1c67274f6c
Use a pipe to redirect executed browser's stderr and stdout when opening profiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
950 if (pipe(fds) == -1) { |
6b1c67274f6c
Use a pipe to redirect executed browser's stderr and stdout when opening profiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
951 int ret = errno; |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
952 printMsg(currWin, "Could not open process communication pipe! (%d, %s)\n", ret, strerror(ret)); |
233
6b1c67274f6c
Use a pipe to redirect executed browser's stderr and stdout when opening profiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
953 return 0; |
6b1c67274f6c
Use a pipe to redirect executed browser's stderr and stdout when opening profiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
954 } |
6b1c67274f6c
Use a pipe to redirect executed browser's stderr and stdout when opening profiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
955 |
125
d03ebefb92a6
Improve internal command handling, use fork() and execlp() instead of system() for opening profiles into external browser's tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
956 if ((pid = fork()) < 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
|
957 printMsg(currWin, "Could not create sub-process!\n"); |
125
d03ebefb92a6
Improve internal command handling, use fork() and execlp() instead of system() for opening profiles into external browser's tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
958 } else if (pid == 0) { |
233
6b1c67274f6c
Use a pipe to redirect executed browser's stderr and stdout when opening profiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
959 dup2(fds[1], STDOUT_FILENO); |
6b1c67274f6c
Use a pipe to redirect executed browser's stderr and stdout when opening profiles.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
960 dup2(fds[0], STDERR_FILENO); |
216
3ccfe8902fd5
Use (void *) typecast for execlp() sentinel to avoid a warning under OpenBSD.
Matti Hamalainen <ccr@tnsp.org>
parents:
211
diff
changeset
|
961 execlp(setBrowser, setBrowser, "-remote", tmpBuf, (void *)NULL); |
128
713879a7ca10
Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents:
125
diff
changeset
|
962 _exit(errno); |
125
d03ebefb92a6
Improve internal command handling, use fork() and execlp() instead of system() for opening profiles into external browser's tabs.
Matti Hamalainen <ccr@tnsp.org>
parents:
123
diff
changeset
|
963 } |
128
713879a7ca10
Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents:
125
diff
changeset
|
964 |
713879a7ca10
Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents:
125
diff
changeset
|
965 wait(&status); |
713879a7ca10
Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents:
125
diff
changeset
|
966 } |
713879a7ca10
Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents:
125
diff
changeset
|
967 #endif |
109
1323a7f88c21
Fix /w -command and add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
968 return 0; |
258 | 969 } |
970 else if (!strncasecmp(buf, "/who", 4)) { | |
109
1323a7f88c21
Fix /w -command and add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
108
diff
changeset
|
971 /* Alias /who to /listallusers */ |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
972 snprintf(tmpBuf, sizeof(tmpBuf), "/listallusers"); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
973 buf = tmpBuf; |
258 | 974 } |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
975 else if (currWin != chatWindows[0]) { |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
976 if (currWin->id != NULL) { |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
977 snprintf(tmpBuf, sizeof(tmpBuf), "/prv -to %s -msg %s", currWin->id, buf); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
978 buf = tmpBuf; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
979 } else { |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
980 printMsg(NULL, "No target set, exiting prv mode.\n"); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
981 return 1; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
982 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
983 } |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
984 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
985 /* Send double-encoded */ |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
986 tmpStr = nn_dblencode_str(nn_username_decode(buf)); |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
987 if (tmpStr == 0) return -2; |
198
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
988 result = nn_conn_send_msg(conn, optUserNameEnc, "%s", tmpStr); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
989 th_free(tmpStr); |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
990 |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
991 return result ? 0 : -1; |
0 | 992 } |
993 | |
155
0720ca51673e
Plug some minor "memory leaks" related to curses.
Matti Hamalainen <ccr@tnsp.org>
parents:
154
diff
changeset
|
994 void closeWindows(void) |
0720ca51673e
Plug some minor "memory leaks" related to curses.
Matti Hamalainen <ccr@tnsp.org>
parents:
154
diff
changeset
|
995 { |
0720ca51673e
Plug some minor "memory leaks" related to curses.
Matti Hamalainen <ccr@tnsp.org>
parents:
154
diff
changeset
|
996 if (mainWin) delwin(mainWin); |
0720ca51673e
Plug some minor "memory leaks" related to curses.
Matti Hamalainen <ccr@tnsp.org>
parents:
154
diff
changeset
|
997 if (statusWin) delwin(statusWin); |
0720ca51673e
Plug some minor "memory leaks" related to curses.
Matti Hamalainen <ccr@tnsp.org>
parents:
154
diff
changeset
|
998 if (editWin) delwin(editWin); |
0720ca51673e
Plug some minor "memory leaks" related to curses.
Matti Hamalainen <ccr@tnsp.org>
parents:
154
diff
changeset
|
999 } |
0 | 1000 |
46
65b1ac6a1e2e
Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
1001 BOOL initializeWindows(void) |
65b1ac6a1e2e
Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
1002 { |
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
|
1003 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
|
1004 |
9e7f52878725
Use getmaxyx() instead of LINES and COLS globals as recommended by curses programming guidelines.
Matti Hamalainen <ccr@tnsp.org>
parents:
117
diff
changeset
|
1005 getmaxyx(stdscr, h, w); |
9e7f52878725
Use getmaxyx() instead of LINES and COLS globals as recommended by curses programming guidelines.
Matti Hamalainen <ccr@tnsp.org>
parents:
117
diff
changeset
|
1006 |
155
0720ca51673e
Plug some minor "memory leaks" related to curses.
Matti Hamalainen <ccr@tnsp.org>
parents:
154
diff
changeset
|
1007 closeWindows(); |
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
|
1008 |
209
e1bfd5227a24
Use curses subwin(stdscr, ...) instead of newwin().
Matti Hamalainen <ccr@tnsp.org>
parents:
208
diff
changeset
|
1009 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
|
1010 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
|
1011 editWin = subwin(stdscr, 3, w, h - 3, 0); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1012 |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1013 if (mainWin == NULL || statusWin == NULL || editWin == 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
|
1014 THERR("Could not create curses chatWindows!\n"); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1015 return FALSE; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1016 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1017 scrollok(mainWin, 1); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1018 |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1019 return TRUE; |
46
65b1ac6a1e2e
Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
1020 } |
65b1ac6a1e2e
Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
1021 |
179
8c493b5671bd
Add separate updateWindows() function.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
1022 void updateWindows(void) |
8c493b5671bd
Add separate updateWindows() function.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
1023 { |
8c493b5671bd
Add separate updateWindows() function.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
1024 if (mainWin) redrawwin(mainWin); |
8c493b5671bd
Add separate updateWindows() function.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
1025 if (statusWin) redrawwin(statusWin); |
8c493b5671bd
Add separate updateWindows() function.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
1026 if (editWin) redrawwin(editWin); |
8c493b5671bd
Add separate updateWindows() function.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
1027 } |
113
2a53156e7e12
Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
1028 |
2a53156e7e12
Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
1029 BOOL performTabCompletion(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
|
1030 { |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1031 static char *previous = NULL, *pattern = NULL; |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1032 BOOL again = FALSE, hasSeparator = FALSE, newPattern = FALSE, hasSpace = FALSE; |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1033 char *str = buf->data; |
113
2a53156e7e12
Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
1034 int mode = 0; |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1035 ssize_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
|
1036 |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1037 /* previous word */ |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1038 if (startPos >= 2 && str[startPos - 1] == ' ' && str[startPos - 2] != ' ') { |
113
2a53156e7e12
Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
1039 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
|
1040 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
|
1041 while (startPos > 0 && str[startPos - 1] != ' ') startPos--; |
2a53156e7e12
Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
1042 mode = 1; |
107
8037a3a7e491
Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
1043 } else |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1044 /* middle of a word, new pattern */ |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1045 if (startPos < buf->len && str[startPos] != ' ') { |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1046 endPos = startPos; |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1047 while (startPos > 0 && str[startPos - 1] != ' ') startPos--; |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1048 while (endPos < buf->len - 1 && str[endPos + 1] != ' ') endPos++; |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1049 newPattern = TRUE; |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1050 mode = 2; |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1051 } else |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1052 /* previous word, new pattern */ |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1053 if (startPos >= 1 && str[startPos - 1] != ' ') { |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1054 startPos -= 1; |
113
2a53156e7e12
Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
1055 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
|
1056 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
|
1057 newPattern = TRUE; |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1058 mode = 3; |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1059 } else { |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1060 if (optDebug) |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1061 printMsg(currWin, "no mode\n"); |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1062 return FALSE; |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1063 } |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1064 |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1065 if (str[endPos] == optNickSep) { |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1066 endPos--; |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1067 if (startPos > 0) { |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1068 if (optDebug) |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1069 printMsg(currWin, "str[endPos] == optNickSep && startPos > 0 (%d)\n", startPos); |
113
2a53156e7e12
Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
1070 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
|
1071 } |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1072 hasSeparator = TRUE; |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1073 } |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1074 |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1075 if (buf->pos > 0 && str[buf->pos - 1] == ' ') |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1076 hasSpace = TRUE; |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1077 if (buf->pos <= buf->len && str[buf->pos] == ' ') |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1078 hasSpace = TRUE; |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1079 |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1080 if (newPattern) { |
116
741e45592522
Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
1081 /* 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
|
1082 char *npattern = nn_editbuf_get_string(buf, startPos, endPos); |
165
f2f0b6f9281b
Dont set 'again' flag in tab completion function if the new and old pattern do not match exactly (apart from case).
Matti Hamalainen <ccr@tnsp.org>
parents:
163
diff
changeset
|
1083 if (pattern && npattern && 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
|
1084 again = TRUE; |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1085 |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1086 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
|
1087 pattern = npattern; |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1088 |
116
741e45592522
Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
1089 if (!again) { |
741e45592522
Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
1090 th_free(previous); |
741e45592522
Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
1091 previous = NULL; |
741e45592522
Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
1092 } |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1093 } |
116
741e45592522
Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
1094 |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1095 if (optDebug) { |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1096 printMsg(currWin, "sPos=%d, ePos=%d <-> bPos=%d, bufLen=%d : pat='%s' (again=%s, hassep=%s, hasspc=%s, newpat=%s, mode=%d)\n", |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1097 startPos, endPos, buf->pos, buf->len, pattern, |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1098 again ? "yes" : "no", |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1099 hasSeparator ? "yes" : "no", |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1100 hasSpace ? "yes" : "no", |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1101 newPattern ? "yes" : "no", mode); |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1102 } |
107
8037a3a7e491
Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
1103 |
113
2a53156e7e12
Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
1104 if (pattern) { |
116
741e45592522
Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
1105 nn_user_t *user = nn_user_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
|
1106 |
108
f323b137ca08
Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents:
107
diff
changeset
|
1107 if (user) { |
107
8037a3a7e491
Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
1108 int i; |
108
f323b137ca08
Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents:
107
diff
changeset
|
1109 char *c = user->name; |
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
|
1110 if (optDebug) |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1111 printMsg(currWin, "match='%s' / prev='%s'\n", user->name, previous); |
107
8037a3a7e491
Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
1112 |
113
2a53156e7e12
Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
1113 for (i = startPos; i <= endPos; i++) |
2a53156e7e12
Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
1114 nn_editbuf_delete(buf, startPos); |
107
8037a3a7e491
Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
1115 |
113
2a53156e7e12
Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
1116 for (i = startPos; *c; i++, c++) |
107
8037a3a7e491
Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
1117 nn_editbuf_insert(buf, i, *c); |
8037a3a7e491
Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
1118 |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1119 if (!hasSeparator && startPos == 0) { |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1120 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
|
1121 startPos++; |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1122 } |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1123 if (hasSeparator) |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1124 startPos++; |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1125 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
|
1126 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
|
1127 |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1128 nn_editbuf_setpos(buf, startPos + 1 + strlen(user->name)); |
107
8037a3a7e491
Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
1129 |
108
f323b137ca08
Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents:
107
diff
changeset
|
1130 th_free(previous); |
f323b137ca08
Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents:
107
diff
changeset
|
1131 previous = th_strdup(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
|
1132 |
2a53156e7e12
Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
1133 return TRUE; |
107
8037a3a7e491
Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
1134 } |
8037a3a7e491
Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
1135 } |
113
2a53156e7e12
Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
1136 |
2a53156e7e12
Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
1137 return FALSE; |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
1138 } |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
1139 |
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
|
1140 #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
|
1141 #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
|
1142 |
239
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1143 char *logParseFilename(const char *fmt, int id) |
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1144 { |
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
|
1145 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
|
1146 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
|
1147 char tmpBuf[32]; |
239
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1148 const char *s = fmt; |
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1149 |
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1150 while (*s) { |
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1151 if (*s == '%') { |
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1152 s++; |
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1153 switch (*s) { |
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1154 case 'i': |
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1155 snprintf(tmpBuf, sizeof(tmpBuf), "%05d", id); |
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1156 VPUTS(tmpBuf); |
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1157 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
|
1158 |
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
|
1159 case 'd': |
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
|
1160 snprintf(tmpBuf, sizeof(tmpBuf), "%d", id); |
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
|
1161 VPUTS(tmpBuf); |
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
|
1162 break; |
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
|
1163 |
239
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1164 case '%': |
242
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1165 VPUTCH('%'); |
239
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1166 break; |
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1167 } |
242
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1168 s++; |
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1169 } else { |
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1170 VPUTCH(*s); |
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1171 s++; |
239
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1172 } |
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1173 } |
242
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1174 |
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1175 VPUTCH(0); |
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1176 return bufData; |
239
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1177 } |
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1178 |
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1179 |
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1180 BOOL logFileOpen(void) |
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1181 { |
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1182 char *filename; |
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1183 |
242
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1184 if (optLogFilename == NULL || !optLogEnable) |
239
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1185 return FALSE; |
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1186 |
242
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1187 filename = logParseFilename(optLogFilename, optPort); |
239
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1188 |
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1189 if ((optLogFile = fopen(filename, "a")) == NULL) { |
242
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1190 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
|
1191 th_free(filename); |
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1192 return FALSE; |
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1193 } |
242
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1194 |
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1195 th_free(filename); |
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1196 |
239
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1197 return TRUE; |
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1198 } |
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1199 |
242
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1200 void logFileClose(void) |
239
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1201 { |
242
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1202 if (optLogFile) { |
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1203 fclose(optLogFile); |
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1204 optLogFile = NULL; |
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1205 } |
239
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1206 } |
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1207 |
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
|
1208 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
|
1209 { |
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
|
1210 char tmpBuf[512], *ptr; |
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
|
1211 ssize_t pos; |
275
66b90d71548b
Improve interactive prompts, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
1212 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
|
1213 |
275
66b90d71548b
Improve interactive prompts, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
1214 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
|
1215 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
|
1216 wgetnstr(win, tmpBuf, sizeof(tmpBuf) - 1); |
275
66b90d71548b
Improve interactive prompts, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
1217 noecho(); |
66b90d71548b
Improve interactive prompts, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
1218 if (curVis != ERR) |
66b90d71548b
Improve interactive prompts, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
1219 curs_set(curVis); |
197
e0ec2280a778
Implement browser launching on Windows via ShellExecute().
Matti Hamalainen <ccr@tnsp.org>
parents:
196
diff
changeset
|
1220 |
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
|
1221 for (pos = strlen(tmpBuf) - 1; pos > 0 && (tmpBuf[pos] == '\n' || tmpBuf[pos] == '\r' || th_isspace(tmpBuf[pos])); pos--) |
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
|
1222 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
|
1223 |
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
|
1224 ptr = trimLeft(tmpBuf); |
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
|
1225 |
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
|
1226 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
|
1227 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
|
1228 else |
edd5ce3e5399
Add simplistic username/password requester if none given on commandline or config file.
Matti Hamalainen <ccr@tnsp.org>
parents:
195
diff
changeset
|
1229 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
|
1230 } |
168
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
1231 |
0 | 1232 int main(int argc, char *argv[]) |
1233 { | |
168
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
1234 nn_conn_t *conn = NULL; |
275
66b90d71548b
Improve interactive prompts, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
1235 struct hostent *tmpHost; |
168
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
1236 int curVis = ERR, updateCount = 0; |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1237 BOOL argsOK, isError = FALSE, |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1238 exitProg = FALSE, |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1239 colorSet = FALSE, |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1240 cursesInit = FALSE, |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1241 networkInit = FALSE, |
275
66b90d71548b
Improve interactive prompts, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
1242 insertMode = TRUE, |
66b90d71548b
Improve interactive prompts, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
1243 firstUpdate = TRUE; |
96
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
1244 time_t prevTime; |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1245 char *tmpStr; |
168
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
1246 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
|
1247 nn_editbuf_t *histBuf[SET_MAX_HISTORY+2]; |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1248 int histPos = 0, histMax = 0; |
275
66b90d71548b
Improve interactive prompts, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
1249 |
154
e8f67e344aaf
Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
1250 cfgitem_t *tmpcfg; |
e8f67e344aaf
Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
1251 char *homeDir = 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
|
1252 |
313
7c96f52e9a3b
memset() history buffer variable unconditionally to avoid derefencing uninitialized memory.
Matti Hamalainen <ccr@tnsp.org>
parents:
309
diff
changeset
|
1253 memset(histBuf, 0, sizeof(histBuf)); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1254 |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1255 /* 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
|
1256 th_init("NNChat", "Newbie Nudes chat client", NN_VERSION, |
237 | 1257 "Written and designed by Anonymous Finnish Guy (C) 2008-2011", |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1258 "This software is freeware, use and distribute as you wish."); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1259 th_verbosityLevel = 0; |
133 | 1260 |
275
66b90d71548b
Improve interactive prompts, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
1261 /* Read configuration file */ |
148 | 1262 tmpcfg = NULL; |
133 | 1263 th_cfg_add_comment(&tmpcfg, "General settings"); |
1264 th_cfg_add_string(&tmpcfg, "username", &optUserName, NULL); | |
1265 th_cfg_add_string(&tmpcfg, "password", &optPassword, NULL); | |
150
db5e7a1f1eb3
Add comment in config file about format of user color setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
149
diff
changeset
|
1266 th_cfg_add_comment(&tmpcfg, "Default color as a hex-triplet"); |
133 | 1267 th_cfg_add_hexvalue(&tmpcfg, "color", &optUserColor, optUserColor); |
149
a4d6707161a7
Add config file option for default setting of ignore mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
1268 |
a4d6707161a7
Add config file option for default setting of ignore mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
1269 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
|
1270 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
|
1271 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
|
1272 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
|
1273 |
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
|
1274 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
|
1275 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
|
1276 |
133 | 1277 th_cfg_add_section(&cfg, "general", tmpcfg); |
1278 | |
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
|
1279 |
133 | 1280 tmpcfg = NULL; |
1281 th_cfg_add_comment(&tmpcfg, "Chat server hostname or IP address"); | |
1282 th_cfg_add_string(&tmpcfg, "host", &optServer, optServer); | |
1283 th_cfg_add_comment(&tmpcfg, "Default port to connect to (8002 = public room, 8003 = passion pit, 8005 = members only)"); | |
1284 th_cfg_add_int(&tmpcfg, "port", &optPort, optPort); | |
1285 th_cfg_add_section(&cfg, "server", tmpcfg); | |
1286 | |
239
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1287 tmpcfg = NULL; |
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
1288 th_cfg_add_comment(&tmpcfg, "Enable logging"); |
247 | 1289 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
|
1290 th_cfg_add_comment(&tmpcfg, "Log filename format"); |
247 | 1291 th_cfg_add_string(&tmpcfg, "filename", &optLogFilename, optLogFilename); |
1292 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
|
1293 |
154
e8f67e344aaf
Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
1294 #ifdef __WIN32 |
e8f67e344aaf
Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
1295 { |
e8f67e344aaf
Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
1296 char tmpPath[MAX_PATH]; |
e8f67e344aaf
Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
1297 if (SHGetFolderPath(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, tmpPath) == S_OK) |
e8f67e344aaf
Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
1298 homeDir = th_strdup(tmpPath); |
197
e0ec2280a778
Implement browser launching on Windows via ShellExecute().
Matti Hamalainen <ccr@tnsp.org>
parents:
196
diff
changeset
|
1299 |
e0ec2280a778
Implement browser launching on Windows via ShellExecute().
Matti Hamalainen <ccr@tnsp.org>
parents:
196
diff
changeset
|
1300 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
|
1301 } |
e8f67e344aaf
Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
1302 #else |
172
ffba05eb578c
Make a copy of getenv("HOME") result instead of using it directly.
Matti Hamalainen <ccr@tnsp.org>
parents:
171
diff
changeset
|
1303 homeDir = th_strdup(getenv("HOME")); |
154
e8f67e344aaf
Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
1304 #endif |
e8f67e344aaf
Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
1305 |
e8f67e344aaf
Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
1306 if (homeDir != NULL) { |
e8f67e344aaf
Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
1307 FILE *cfgfile; |
e8f67e344aaf
Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
1308 setConfigFile = th_strdup_printf("%s" SET_DIR_SEPARATOR "%s", homeDir, SET_CONFIG_FILE); |
e8f67e344aaf
Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
1309 |
e8f67e344aaf
Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
1310 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
|
1311 |
315
864e6e52ed69
Fix a filehandle leak when reading in configuration file.
Matti Hamalainen <ccr@tnsp.org>
parents:
314
diff
changeset
|
1312 if ((cfgfile = fopen(setConfigFile, "r")) != NULL) { |
154
e8f67e344aaf
Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
1313 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
|
1314 fclose(cfgfile); |
864e6e52ed69
Fix a filehandle leak when reading in configuration file.
Matti Hamalainen <ccr@tnsp.org>
parents:
314
diff
changeset
|
1315 } |
133 | 1316 } |
196
edd5ce3e5399
Add simplistic username/password requester if none given on commandline or config file.
Matti Hamalainen <ccr@tnsp.org>
parents:
195
diff
changeset
|
1317 |
137
fad8c31e41e6
Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
1318 setBrowser = getenv("BROWSER"); |
fad8c31e41e6
Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
1319 if (setBrowser == NULL) |
fad8c31e41e6
Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
1320 setBrowser = "firefox"; |
fad8c31e41e6
Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
1321 |
153 | 1322 /* Parse command line arguments */ |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1323 argsOK = th_args_process(argc, argv, optList, optListN, |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1324 argHandleOpt, argHandleFile, FALSE); |
26
b84fc46c6035
Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
1325 |
198
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
1326 if (optUserNameCmd != NULL) { |
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
1327 optUserName = optUserNameCmd; |
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
1328 optPassword = optPasswordCmd; |
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
1329 } |
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
1330 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1331 if (!argsOK) |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1332 return -2; |
64
6a3a917303e4
Some random cleanups, bring back WinSock support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
1333 |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
1334 /* Allocate userhash */ |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
1335 if ((nnUsers = nn_userhash_new()) == NULL) { |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
1336 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
|
1337 return -105; |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
1338 } |
64
6a3a917303e4
Some random cleanups, bring back WinSock support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
1339 |
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
|
1340 /* If no idle messages are set, add default */ |
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
|
1341 if (setIdleMessages == NULL) { |
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
|
1342 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
|
1343 } |
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
|
1344 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1345 /* Open logfile */ |
242
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1346 logFileOpen(); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1347 |
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
|
1348 /* Initialize network */ |
97
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
1349 if (!nn_network_init()) { |
91
acfc4b4bc180
Create network initialization functions in libnnchat and move Win32/WinSock code there.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
1350 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
|
1351 goto err_exit; |
acfc4b4bc180
Create network initialization functions in libnnchat and move Win32/WinSock code there.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
1352 } else |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1353 networkInit = TRUE; |
68
3ab7751fdad1
MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents:
67
diff
changeset
|
1354 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1355 /* Initialize NCurses */ |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1356 if (!optDaemon) { |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1357 if (LINES < 0 || LINES > 1000) LINES = 24; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1358 if (COLS < 0 || COLS > 1000) COLS = 80; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1359 initscr(); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1360 raw(); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1361 keypad(stdscr, TRUE); |
275
66b90d71548b
Improve interactive prompts, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
1362 noecho(); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1363 meta(stdscr, TRUE); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1364 timeout(SET_DELAY); |
275
66b90d71548b
Improve interactive prompts, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
1365 curVis = curs_set(0); |
110
8af4072dc31a
Fix Win32/MinGW/PDcurses issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
109
diff
changeset
|
1366 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1367 if (has_colors()) { |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1368 start_color(); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1369 |
185 | 1370 init_pair( 1, COLOR_RED, COLOR_BLACK); |
1371 init_pair( 2, COLOR_GREEN, COLOR_BLACK); | |
1372 init_pair( 3, COLOR_YELLOW, COLOR_BLACK); | |
1373 init_pair( 4, COLOR_BLUE, COLOR_BLACK); | |
1374 init_pair( 5, COLOR_MAGENTA, COLOR_BLACK); | |
1375 init_pair( 6, COLOR_CYAN, COLOR_BLACK); | |
1376 init_pair( 7, COLOR_WHITE, COLOR_BLACK); | |
1377 init_pair( 8, COLOR_BLACK, COLOR_BLACK); | |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1378 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1379 init_pair(10, COLOR_BLACK, COLOR_RED); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1380 init_pair(11, COLOR_WHITE, COLOR_RED); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1381 init_pair(12, COLOR_GREEN, COLOR_RED); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1382 init_pair(13, COLOR_YELLOW, COLOR_RED); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1383 init_pair(14, COLOR_BLUE, COLOR_RED); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1384 init_pair(15, COLOR_MAGENTA, COLOR_RED); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1385 init_pair(16, COLOR_CYAN, COLOR_RED); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1386 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1387 |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1388 cursesInit = TRUE; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1389 |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1390 if (!initializeWindows()) |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1391 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
|
1392 |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1393 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
|
1394 chatWindows[0] = nn_window_new(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
|
1395 currWin = chatWindows[0]; |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
1396 updateStatus(); |
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
|
1397 } |
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
|
1398 |
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
|
1399 /* Check if we have username and password */ |
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
|
1400 if (cursesInit && (optUserName == NULL || optPassword == 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
|
1401 printWin(editWin, "You can avoid this prompt by issuing '/save' after logging in.\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
|
1402 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
|
1403 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
|
1404 } |
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
|
1405 |
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
|
1406 if (optUserName == NULL || optPassword == 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
|
1407 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
|
1408 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
|
1409 } |
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
|
1410 |
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
|
1411 /* 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
|
1412 printMsg(currWin, "Trying to resolve host '%s' ...\n", optServer); |
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
|
1413 tmpHost = gethostbyname(optServer); |
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
|
1414 if (tmpHost == 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
|
1415 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
|
1416 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
|
1417 } |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1418 printMsg(currWin, "True hostname: %s\n", tmpHost->h_name); |
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
|
1419 |
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
|
1420 /* 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
|
1421 * 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
|
1422 */ |
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
|
1423 conn = nn_conn_open((struct in_addr *) tmpHost->h_addr, 843); |
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
|
1424 if (!nn_conn_check(conn)) { |
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
|
1425 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
|
1426 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
|
1427 } |
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
|
1428 |
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
|
1429 tmpStr = "<policy-file-request/>"; |
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
|
1430 if (nn_conn_send_buf(conn, tmpStr, strlen(tmpStr) + 1) == 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
|
1431 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
|
1432 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
|
1433 } else { |
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
|
1434 int cres = nn_conn_pull(conn); |
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
|
1435 if (cres == 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
|
1436 printMsg(currWin, "Probe got: %s\n", conn->buf); |
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
|
1437 } else { |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1438 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
|
1439 } |
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
|
1440 } |
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
|
1441 nn_conn_close(conn); |
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
|
1442 |
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
|
1443 /* Okay, now do the proper connection ... */ |
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
|
1444 conn = nn_conn_open((struct in_addr *) tmpHost->h_addr, optPort); |
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
|
1445 if (!nn_conn_check(conn)) { |
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
|
1446 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
|
1447 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
|
1448 } |
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
|
1449 |
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
|
1450 conn->errfunc = errorFunc; |
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
|
1451 conn->msgfunc = messageFunc; |
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
|
1452 |
275
66b90d71548b
Improve interactive prompts, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
1453 /* 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
|
1454 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
|
1455 tmpStr = nn_dblencode_str(optSite); |
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
|
1456 nn_conn_send_msg(conn, optUserNameEnc, "%%2Flogin%%20%%2Dsite%%20%s%%20%%2Dpassword%%20%s", tmpStr, optPassword); |
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
|
1457 th_free(tmpStr); |
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
|
1458 |
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
|
1459 /* Initialize random numbers */ |
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
|
1460 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
|
1461 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
|
1462 |
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
|
1463 if (cursesInit) { |
275
66b90d71548b
Improve interactive prompts, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
1464 /* Initialize rest of interactive UI code */ |
97
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
1465 nn_editbuf_clear(editBuf); |
275
66b90d71548b
Improve interactive prompts, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
1466 |
66b90d71548b
Improve interactive prompts, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
1467 /* First update of screen */ |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
1468 printEditBuf(editBuf); |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
1469 updateStatus(); |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1470 |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1471 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
|
1472 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
|
1473 printMsg(NULL, "%s\n", th_prog_license); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1474 } |
100
ed4067c10a8a
Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
1475 |
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
|
1476 /* Enter mainloop */ |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1477 while (!isError && !exitProg) { |
168
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
1478 int cres = nn_conn_pull(conn); |
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
1479 if (cres == 0) { |
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
1480 do { |
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
1481 size_t bufLen = strlen(conn->ptr) + 1; |
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
1482 int result = handleProtocol(conn, conn->ptr, bufLen); |
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
1483 |
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
1484 if (result > 0) { |
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
1485 /* Couldn't handle the message for some reason */ |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1486 printMsg(currWin, "Could not handle: %s\n", conn->ptr); |
168
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
1487 } else if (result < 0) { |
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
1488 /* Fatal error, quit */ |
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
1489 errorMsg("Fatal error with message: %s\n", conn->ptr); |
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
1490 isError = TRUE; |
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
1491 } |
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
1492 |
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
1493 conn->got -= bufLen; |
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
1494 conn->ptr += bufLen; |
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
1495 } while (conn->got > 0 && !isError); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1496 } |
168
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
1497 if (!nn_conn_check(conn)) |
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
1498 isError = TRUE; |
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
1499 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1500 /* Handle user input */ |
275
66b90d71548b
Improve interactive prompts, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
1501 if (cursesInit) { |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1502 int c, cnt = 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
|
1503 BOOL update = FALSE, updateMain = TRUE; |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1504 |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1505 /* Handle several buffered keypresses at once */ |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1506 do { |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1507 c = wgetch(stdscr); |
77
e8c9d7d13866
Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
1508 if (c == 0x1b) { |
e8c9d7d13866
Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
1509 c = wgetch(stdscr); |
e8c9d7d13866
Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
1510 if (c == 'O') { |
e8c9d7d13866
Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
1511 c = wgetch(stdscr); |
e8c9d7d13866
Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
1512 switch (c) { |
e8c9d7d13866
Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
1513 case 'd': c = 0x204; break; |
e8c9d7d13866
Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
1514 case 'c': c = 0x206; break; |
e8c9d7d13866
Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
1515 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
|
1516 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
|
1517 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
|
1518 break; |
e8c9d7d13866
Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
1519 } |
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
|
1520 } else |
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
|
1521 if (c == '[') { |
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
|
1522 c = wgetch(stdscr); |
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
|
1523 switch (c) { |
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
|
1524 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
|
1525 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
|
1526 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
|
1527 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
|
1528 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
|
1529 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
|
1530 break; |
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
|
1531 |
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
|
1532 case 0x32: c = KEY_IC; break; |
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
|
1533 case 0x33: c = KEY_DC; break; |
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
|
1534 |
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
|
1535 case 0x35: c = KEY_PPAGE; break; |
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
|
1536 case 0x36: c = KEY_NPAGE; break; |
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
|
1537 |
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
|
1538 case 0x37: c = KEY_HOME; break; |
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
|
1539 case 0x38: c = KEY_END; break; |
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
|
1540 |
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
|
1541 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
|
1542 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
|
1543 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
|
1544 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
|
1545 break; |
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
|
1546 } |
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
|
1547 /* Get the trailing ~ */ |
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
|
1548 if (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
|
1549 wgetch(stdscr); |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
1550 } |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
1551 if (c >= 0x31 && c <= 0x39) { |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
1552 /* Chat window switching via Meta/Esc-[1..9] */ |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
1553 int win = c - 0x31; |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
1554 if (win < SET_MAX_WINDOWS && chatWindows[win] != NULL) { |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
1555 currWin = chatWindows[win]; |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
1556 update = updateMain = TRUE; |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
1557 } |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
1558 c = ERR; |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
1559 } |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
1560 else { |
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
|
1561 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
|
1562 printMsg(currWin, "Unhandled ESC key sequence 0x%02x\n", c); |
77
e8c9d7d13866
Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
1563 continue; |
e8c9d7d13866
Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
1564 } |
e8c9d7d13866
Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
1565 } |
e8c9d7d13866
Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents:
75
diff
changeset
|
1566 |
119
4bc63a535acb
Fix some PDCurses incompatibilities and remove some Win32/PDCurses specific hacks.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
1567 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1568 switch (c) { |
74 | 1569 #ifdef KEY_RESIZE |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1570 case KEY_RESIZE: |
119
4bc63a535acb
Fix some PDCurses incompatibilities and remove some Win32/PDCurses specific hacks.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
1571 resize_term(0, 0); |
4bc63a535acb
Fix some PDCurses incompatibilities and remove some Win32/PDCurses specific hacks.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
1572 erase(); |
134
f367fc14021a
Use resize_term() and erase() on resize event also with ncurses and not only with PDcurses.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
1573 #ifdef PDCURSES |
119
4bc63a535acb
Fix some PDCurses incompatibilities and remove some Win32/PDCurses specific hacks.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
1574 timeout(SET_DELAY); |
4bc63a535acb
Fix some PDCurses incompatibilities and remove some Win32/PDCurses specific hacks.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
1575 #endif |
4bc63a535acb
Fix some PDCurses incompatibilities and remove some Win32/PDCurses specific hacks.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
1576 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1577 if (!initializeWindows()) { |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1578 errorMsg("Error resizing curses chatWindows\n"); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1579 isError = TRUE; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1580 } |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1581 |
119
4bc63a535acb
Fix some PDCurses incompatibilities and remove some Win32/PDCurses specific hacks.
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
1582 update = 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
|
1583 updateMain = TRUE; |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1584 break; |
74 | 1585 #endif |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1586 |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1587 case KEY_ENTER: |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1588 case '\n': |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1589 case '\r': |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1590 /* Call the user input handler */ |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1591 if (editBuf->len > 0) { |
168
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
1592 int result; |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1593 |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1594 if (histMax > 0) { |
97
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
1595 nn_editbuf_free(histBuf[SET_MAX_HISTORY+1]); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1596 histBuf[SET_MAX_HISTORY+1] = NULL; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1597 memmove(&histBuf[2], &histBuf[1], histMax * sizeof(histBuf[0])); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1598 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1599 |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1600 histPos = 0; |
97
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
1601 histBuf[1] = nn_editbuf_copy(editBuf); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1602 if (histMax < SET_MAX_HISTORY) histMax++; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1603 |
97
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
1604 nn_editbuf_insert(editBuf, editBuf->len, 0); |
168
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
1605 result = handleUserInput(conn, editBuf->data, editBuf->len); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1606 |
97
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
1607 nn_editbuf_clear(editBuf); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1608 |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1609 if (result < 0) { |
96
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
1610 errorMsg("Fatal error handling user input: %s\n", editBuf->data); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1611 isError = TRUE; |
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
|
1612 } else { |
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
|
1613 /* Update time value of last sent message for unidle timeouts */ |
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
|
1614 prevTime = time(NULL); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1615 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1616 |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1617 update = TRUE; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1618 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1619 break; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1620 |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1621 case KEY_UP: /* Backwards in input history */ |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1622 if (histPos == 0) { |
97
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
1623 nn_editbuf_free(histBuf[0]); |
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
1624 histBuf[0] = nn_editbuf_copy(editBuf); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1625 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1626 if (histPos < histMax) { |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1627 histPos++; |
97
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
1628 nn_editbuf_free(editBuf); |
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
1629 editBuf = nn_editbuf_copy(histBuf[histPos]); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1630 update = TRUE; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1631 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1632 break; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1633 |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1634 case KEY_DOWN: /* Forwards in input history */ |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1635 if (histPos > 0) { |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1636 histPos--; |
97
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
1637 nn_editbuf_free(editBuf); |
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
1638 editBuf = nn_editbuf_copy(histBuf[histPos]); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1639 update = TRUE; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1640 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1641 break; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1642 |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
1643 case 0x204: /* ctrl+left arrow = Skip words left */ |
232
3140ea43d4a3
Handle certain terminals differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
230
diff
changeset
|
1644 case 0x20b: |
74 | 1645 while (editBuf->pos > 0 && isspace((int) editBuf->data[editBuf->pos - 1])) |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1646 editBuf->pos--; |
74 | 1647 while (editBuf->pos > 0 && !isspace((int) editBuf->data[editBuf->pos - 1])) |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1648 editBuf->pos--; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1649 update = TRUE; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1650 break; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1651 |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
1652 case 0x206: /* ctrl+right arrow = Skip words right */ |
232
3140ea43d4a3
Handle certain terminals differently.
Matti Hamalainen <ccr@tnsp.org>
parents:
230
diff
changeset
|
1653 case 0x210: |
74 | 1654 while (editBuf->pos < editBuf->len && isspace((int) editBuf->data[editBuf->pos])) |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1655 editBuf->pos++; |
74 | 1656 while (editBuf->pos < editBuf->len && !isspace((int) editBuf->data[editBuf->pos])) |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1657 editBuf->pos++; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1658 update = TRUE; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1659 break; |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
1660 |
280 | 1661 case KEY_HOME: nn_editbuf_setpos(editBuf, 0); update = TRUE; break; |
1662 case KEY_END: nn_editbuf_setpos(editBuf, editBuf->len); update = TRUE; break; | |
1663 case KEY_LEFT: nn_editbuf_setpos(editBuf, editBuf->pos - 1); update = TRUE; break; | |
97
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
1664 case KEY_RIGHT: nn_editbuf_setpos(editBuf, editBuf->pos + 1); update = TRUE; break; |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1665 |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1666 case KEY_BACKSPACE: |
73
c56e766acce1
Support keycode 0x08 as backspace for Win32 compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
1667 case 0x08: |
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
|
1668 case 0x7f: |
97
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
1669 nn_editbuf_delete(editBuf, editBuf->pos - 1); |
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
1670 nn_editbuf_setpos(editBuf, editBuf->pos - 1); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1671 update = TRUE; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1672 break; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1673 |
122 | 1674 case KEY_DC: /* Delete character */ |
97
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
1675 nn_editbuf_delete(editBuf, editBuf->pos); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1676 update = TRUE; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1677 break; |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
1678 |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
1679 |
175 | 1680 case KEY_IC: /* Ins = Toggle insert / overwrite mode */ |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
1681 insertMode = !insertMode; |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
1682 update = TRUE; |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
1683 break; |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1684 |
208
6c5d136b6e6a
Use curses KEY_F(n) macros for defining function keys instead of hardcoded values.
Matti Hamalainen <ccr@tnsp.org>
parents:
207
diff
changeset
|
1685 case KEY_F(2): /* F2 = Clear editbuffer */ |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
1686 nn_editbuf_clear(editBuf); |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
1687 update = TRUE; |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
1688 break; |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
1689 |
208
6c5d136b6e6a
Use curses KEY_F(n) macros for defining function keys instead of hardcoded values.
Matti Hamalainen <ccr@tnsp.org>
parents:
207
diff
changeset
|
1690 case KEY_F(5): /* F5 = Ignore mode */ |
149
a4d6707161a7
Add config file option for default setting of ignore mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
1691 setIgnoreMode = !setIgnoreMode; |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1692 printMsg(currWin, "Ignore mode = %s\n", setIgnoreMode ? "ON" : "OFF"); |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
1693 break; |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
1694 |
203
e7538539de7f
Make ^C equivalent of quit (F9).
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
1695 case 0x03: /* ^C = quit */ |
208
6c5d136b6e6a
Use curses KEY_F(n) macros for defining function keys instead of hardcoded values.
Matti Hamalainen <ccr@tnsp.org>
parents:
207
diff
changeset
|
1696 case KEY_F(9): /* F9 = Quit */ |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1697 printMsg(currWin, "Quitting per user request.\n"); |
175 | 1698 exitProg = TRUE; |
1699 break; | |
1700 | |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
1701 case 0x09: /* Tab = complete username */ |
107
8037a3a7e491
Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
1702 performTabCompletion(editBuf); |
8037a3a7e491
Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
1703 update = TRUE; |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
1704 break; |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
1705 |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
1706 case 0x0c: /* Ctrl + L */ |
179
8c493b5671bd
Add separate updateWindows() function.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
1707 updateWindows(); |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1708 update = TRUE; |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1709 updateMain = TRUE; |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1710 break; |
122 | 1711 |
1712 case KEY_NPAGE: | |
1713 case KEY_PPAGE: | |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1714 if (currWin != NULL) |
230
b64500bb7fbe
Some yet-unused backbuffer related code.
Matti Hamalainen <ccr@tnsp.org>
parents:
229
diff
changeset
|
1715 { |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1716 int numLines, numCols, oldPos = currWin->pos; |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1717 getmaxyx(mainWin, numLines, numCols); |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1718 numLines = (numLines / 2) + 1; |
230
b64500bb7fbe
Some yet-unused backbuffer related code.
Matti Hamalainen <ccr@tnsp.org>
parents:
229
diff
changeset
|
1719 |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1720 if (c == KEY_PPAGE) |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1721 currWin->pos = (currWin->pos > numLines) ? currWin->pos - numLines : 0; |
230
b64500bb7fbe
Some yet-unused backbuffer related code.
Matti Hamalainen <ccr@tnsp.org>
parents:
229
diff
changeset
|
1722 else |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1723 currWin->pos = (currWin->pos < currWin->data->n - numLines) ? currWin->pos + numLines : currWin->data->n - numLines; |
230
b64500bb7fbe
Some yet-unused backbuffer related code.
Matti Hamalainen <ccr@tnsp.org>
parents:
229
diff
changeset
|
1724 |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1725 if (oldPos != currWin->pos) |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1726 updateMain = TRUE; |
230
b64500bb7fbe
Some yet-unused backbuffer related code.
Matti Hamalainen <ccr@tnsp.org>
parents:
229
diff
changeset
|
1727 } |
122 | 1728 break; |
1729 | |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1730 case ERR: |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1731 /* Ignore */ |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1732 break; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1733 |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1734 default: |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1735 if (isprint(c) || c == 0xe4 || c == 0xf6 || c == 0xc4 || c == 0xd6) { |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1736 if (insertMode) |
97
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
1737 nn_editbuf_insert(editBuf, editBuf->pos, c); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1738 else |
97
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
1739 nn_editbuf_write(editBuf, editBuf->pos, c); |
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
1740 nn_editbuf_setpos(editBuf, editBuf->pos + 1); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1741 update = TRUE; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1742 } else { |
298
0119bcc15f15
Another unhandled key warning disabled when debug mode not enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
297
diff
changeset
|
1743 if (optDebug) |
0119bcc15f15
Another unhandled key warning disabled when debug mode not enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
297
diff
changeset
|
1744 printMsg(currWin, "Unhandled key: 0x%02x\n", c); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1745 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1746 break; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1747 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1748 } while (c != ERR && !exitProg && ++cnt < 10); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1749 |
221 | 1750 if (update || firstUpdate) { |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1751 /* Update edit line */ |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
1752 printEditBuf(editBuf); |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
1753 updateStatus(); |
221 | 1754 firstUpdate = FALSE; /* a nasty hack ... */ |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1755 } |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1756 |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1757 updateMainWin(updateMain); |
275
66b90d71548b
Improve interactive prompts, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
1758 } /* cursesInit */ |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1759 |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1760 if (++updateCount > 10) { |
96
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
1761 time_t tmpTime = time(NULL); |
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
1762 if (tmpTime - prevTime > SET_KEEPALIVE) { |
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
|
1763 int n = random() % th_llist_length(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
|
1764 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
|
1765 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
|
1766 prevTime = tmpTime; |
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
1767 } |
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
1768 |
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
1769 if (!colorSet) { |
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
1770 colorSet = TRUE; |
198
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
1771 nn_conn_send_msg(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
|
1772 } |
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
1773 |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
1774 updateStatus(); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1775 updateCount = 0; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1776 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1777 |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1778 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1779 |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1780 /* 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
|
1781 err_exit: |
316
1065115665bd
Plug some more minor memory leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
315
diff
changeset
|
1782 th_cfg_free(cfg); |
308 | 1783 th_free(homeDir); |
316
1065115665bd
Plug some more minor memory leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
315
diff
changeset
|
1784 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
|
1785 nn_userhash_free(nnUsers); |
97
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
1786 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
|
1787 |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1788 { |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1789 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
|
1790 for (i = 0; i <= SET_MAX_HISTORY; i++) |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1791 nn_editbuf_free(histBuf[i]); |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1792 |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1793 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
|
1794 nn_window_free(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
|
1795 } |
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1796 |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
1797 #ifdef __WIN32 |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1798 if (errorMessages) { |
275
66b90d71548b
Improve interactive prompts, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
1799 char *tmp; |
66b90d71548b
Improve interactive prompts, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
1800 wclear(editWin); |
66b90d71548b
Improve interactive prompts, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
273
diff
changeset
|
1801 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
|
1802 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
|
1803 } |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
1804 #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
|
1805 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1806 if (cursesInit) { |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1807 if (curVis != ERR) |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1808 curs_set(curVis); |
155
0720ca51673e
Plug some minor "memory leaks" related to curses.
Matti Hamalainen <ccr@tnsp.org>
parents:
154
diff
changeset
|
1809 closeWindows(); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1810 endwin(); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1811 THMSG(1, "NCurses deinitialized.\n"); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1812 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1813 |
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
|
1814 #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
|
1815 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
|
1816 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
|
1817 #endif |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1818 |
198
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
1819 th_free(optUserNameEnc); |
10 | 1820 |
168
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
1821 nn_conn_close(conn); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1822 |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1823 if (networkInit) |
97
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
1824 nn_network_close(); |
68
3ab7751fdad1
MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents:
67
diff
changeset
|
1825 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1826 THMSG(1, "Connection terminated.\n"); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1827 |
242
cb86d7543be2
Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents:
240
diff
changeset
|
1828 logFileClose(); |
133 | 1829 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1830 return 0; |
0 | 1831 } |