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