annotate nnchat.c @ 409:4556174b5be8

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