annotate main.c @ 530:f0bca971170b

Change coloring to use friend list as well.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 06 Jun 2012 16:20:53 +0300
parents ba5807ebff88
children 5d1a832d6e61
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
421
4b7cd24dc943 Update copyright.
Matti Hamalainen <ccr@tnsp.org>
parents: 419
diff changeset
4 * (C) Copyright 2008-2012 Tecnic Software productions (TNSP)
39
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
5 */
413
14b685cdbd2c Rename files.
Matti Hamalainen <ccr@tnsp.org>
parents: 412
diff changeset
6 #include "util.h"
14b685cdbd2c Rename files.
Matti Hamalainen <ccr@tnsp.org>
parents: 412
diff changeset
7 #include "network.h"
466
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents: 464
diff changeset
8 #include "ui.h"
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 #include "th_args.h"
133
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
10 #include "th_config.h"
468
607bd4491e79 Fix win32 build.
Matti Hamalainen <ccr@tnsp.org>
parents: 466
diff changeset
11 #include <time.h>
415
8263cb88556a Some #include cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 413
diff changeset
12 #include <errno.h>
64
6a3a917303e4 Some random cleanups, bring back WinSock support.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
13 #ifdef __WIN32
154
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
14 #include <shlwapi.h>
128
713879a7ca10 Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
15 #else
713879a7ca10 Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
16 #include <sys/wait.h>
68
3ab7751fdad1 MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
17 #endif
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18
139
c39399725f7b Define some platform-specific constants.
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
19 #ifdef __WIN32
160
d3c78f2ef77b Rename configuration file for Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 156
diff changeset
20 #define SET_CONFIG_FILE "nnchat.txt"
139
c39399725f7b Define some platform-specific constants.
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
21 #define SET_DIR_SEPARATOR "\\"
c39399725f7b Define some platform-specific constants.
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
22 #else
c39399725f7b Define some platform-specific constants.
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
23 #define SET_CONFIG_FILE ".nnchat"
c39399725f7b Define some platform-specific constants.
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
24 #define SET_DIR_SEPARATOR "/"
c39399725f7b Define some platform-specific constants.
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
25 #endif
49
0bcc38910a77 Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
26
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
27 #define SET_PROFILE_PREFIX "http://www.newbienudes.com/profile/%s/"
409
4556174b5be8 Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 408
diff changeset
28 #define SET_NICK_SEPARATOR ':'
4556174b5be8 Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 408
diff changeset
29
419
d015ecbd231d Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents: 418
diff changeset
30 #define SET_MAX_HISTORY (16) // Command history length
d015ecbd231d Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents: 418
diff changeset
31 #define SET_KEEPALIVE (15*60) // Ping/keepalive period in seconds
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32
49
0bcc38910a77 Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
33
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 /* Options
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 */
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
36 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
37 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
38 optProxyType = NN_PROXY_NONE;
207
e0c085426b91 Change default user color to black (#000000).
Matti Hamalainen <ccr@tnsp.org>
parents: 206
diff changeset
39 int optUserColor = 0x000000;
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
40 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
41 *optProxyServer = NULL,
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
42 *optUserName = NULL,
198
21a37995c3fb Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents: 197
diff changeset
43 *optUserNameCmd = NULL,
21a37995c3fb Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents: 197
diff changeset
44 *optUserNameEnc = NULL,
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
45 *optPassword = NULL,
198
21a37995c3fb Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents: 197
diff changeset
46 *optPasswordCmd = NULL,
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
47 *optLogFilename = NULL,
409
4556174b5be8 Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 408
diff changeset
48 *optSite = "NN",
4556174b5be8 Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 408
diff changeset
49 *optNickSepStr = NULL;
4556174b5be8 Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 408
diff changeset
50 char optNickSep;
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
51 BOOL optDaemon = FALSE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
52 FILE *optLogFile = NULL;
519
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
53 BOOL setIgnoreMode = FALSE,
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
54 optDebug = FALSE,
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
55 optLogEnable = FALSE,
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
56 optOnlyFriendPrv = FALSE;
140
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
57
265
b9c650db8a6a Rename variable nnIgnoreList to setIgnoreList.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
58 qlist_t *setIgnoreList = NULL,
519
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
59 *setFriendList = 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
60 *setIdleMessages = NULL;
140
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
61 nn_userhash_t *nnUsers = NULL;
137
fad8c31e41e6 Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
62 char *setConfigFile = NULL,
fad8c31e41e6 Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
63 *setBrowser = NULL;
133
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
64 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
65
513
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
66 nn_editbuf_t *editHistBuf[SET_MAX_HISTORY+2];
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
67 int editHistPos = 0,
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
68 editHistMax = 0;
273
4d106ad65f26 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 268
diff changeset
69
4d106ad65f26 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 268
diff changeset
70 /* Logging mode flags
4d106ad65f26 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 268
diff changeset
71 */
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
72 enum
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
73 {
273
4d106ad65f26 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 268
diff changeset
74 LOG_FILE = 1,
4d106ad65f26 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 268
diff changeset
75 LOG_WINDOW = 2,
4d106ad65f26 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 268
diff changeset
76 LOG_STAMP = 4
4d106ad65f26 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 268
diff changeset
77 };
4d106ad65f26 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 268
diff changeset
78
4d106ad65f26 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 268
diff changeset
79
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 /* Arguments
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 */
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
82 optarg_t optList[] =
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
83 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
84 { 0, '?', "help", "Show this help", OPT_NONE },
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
85 { 1, 'v', "verbose", "Be more verbose", OPT_NONE },
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
86 { 2, 'p', "port", "Connect to port", OPT_ARGREQ },
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
87 { 3, 's', "server", "Server to connect to", OPT_ARGREQ },
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
88 { 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
89 { 5, 'l', "logfile", "Log filename", OPT_ARGREQ },
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
90 { 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
91 { 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
92 { 8, 'd', "debug", "Enable various debug features", OPT_NONE },
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
93
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
94 {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
95 {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
96 {12, 'P', "proxy-port", "Proxy port (default: 1080)", OPT_ARGREQ },
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 };
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98
43
40ba8cdcf03a Cleanups, added a silly morse code conversion mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
99 const int optListN = (sizeof(optList) / sizeof(optList[0]));
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101
258
8a0f7446318e General cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 254
diff changeset
102 void argShowHelp(void)
68
3ab7751fdad1 MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
103 {
381
7c28f38cb6dd Update to use new th-libs from the subrepo.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
104 th_print_banner(stdout, th_prog_name,
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
105 "[options] <username> <password>");
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
106
381
7c28f38cb6dd Update to use new th-libs from the subrepo.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
107 th_args_help(stdout, optList, optListN);
68
3ab7751fdad1 MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
108 }
3ab7751fdad1 MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
109
3ab7751fdad1 MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
110
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 BOOL argHandleOpt(const int optN, char *optArg, char *currArg)
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 {
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
113 switch (optN)
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
114 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
115 case 0:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
116 argShowHelp();
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
117 exit(0);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
118 break;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
120 case 1:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
121 th_verbosityLevel++;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
122 break;
391
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 2:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
125 optPort = atoi(optArg);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
126 break;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
128 case 3:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
129 optServer = optArg;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
130 break;
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
131
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
132 case 4:
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
133 if ((optUserColor = th_get_hex_triplet(optArg)) < 0)
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
134 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
135 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
136 optArg);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
137 return FALSE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
138 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
139 THMSG(1, "Using color #%06x\n", optUserColor);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
140 break;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
142 case 5:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
143 optLogFilename = optArg;
242
cb86d7543be2 Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
144 optLogEnable = TRUE;
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
145 break;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
147 case 7:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
148 optSite = optArg;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
149 break;
33
e49ea6febfeb Cleanups. Added option to specify/fake "site" where logging in from.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
150
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
151 case 6:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
152 optDaemon = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
153 THMSG(1, "Running in pseudo-daemon mode.\n");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
154 break;
21
29098addfa65 Added a "daemon" mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
155
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
156 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
157 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
158 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
159 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
160
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
161
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
162 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
163 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
164 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
165 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
166
b54c8545dcb0 Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents: 347
diff changeset
167 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
168 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
169 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
170 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
171
b54c8545dcb0 Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents: 347
diff changeset
172 case 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
173 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
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
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
177 default:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
178 THERR("Unknown option '%s'.\n", currArg);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
179 return FALSE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
180 }
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
181
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
182 return TRUE;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 BOOL argHandleFile(char *currArg)
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
187 {
198
21a37995c3fb Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents: 197
diff changeset
188 if (!optUserNameCmd)
21a37995c3fb Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents: 197
diff changeset
189 optUserNameCmd = currArg;
21a37995c3fb Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents: 197
diff changeset
190 else if (!optPasswordCmd)
21a37995c3fb Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents: 197
diff changeset
191 optPasswordCmd = currArg;
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
192 else
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
193 {
198
21a37995c3fb Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents: 197
diff changeset
194 THERR("Username '%s' already specified on commandline!\n", optUserNameCmd);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
195 return FALSE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
196 }
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
197
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
198 return TRUE;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200
460
c956af023014 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 459
diff changeset
201
28
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
202 int printFile(FILE *outFile, const char *fmt)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
204 const char *s = fmt;
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
205
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
206 while (*s)
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
207 {
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
208 if (*s == '½')
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
209 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
210 s++;
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
211 if (*s == '½')
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
212 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
213 fputc((unsigned char) *s, outFile);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
214 s++;
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
215 }
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
216 else
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
217 {
74
98004129202a Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
218 while (*s && isdigit((int) *s)) s++;
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
219 if (*s != '½') return -1;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
220 s++;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
221 }
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
222 }
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
223 else
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
224 {
191
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
225 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
226 fputc(' ', outFile);
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
227 else
4007b9ac7cde Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents: 190
diff changeset
228 fputc((unsigned char) *s, outFile);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
229 s++;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
230 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
231 }
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
232
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
233 return 0;
28
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
234 }
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
235
288
e7ef3db3b954 Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
236 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
237 {
288
e7ef3db3b954 Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
238 char tmpStr[128], *buf;
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
239
520
ab56ed0d0c25 Slight optimization.
Matti Hamalainen <ccr@tnsp.org>
parents: 519
diff changeset
240 if (flags & LOG_STAMP)
ab56ed0d0c25 Slight optimization.
Matti Hamalainen <ccr@tnsp.org>
parents: 519
diff changeset
241 {
ab56ed0d0c25 Slight optimization.
Matti Hamalainen <ccr@tnsp.org>
parents: 519
diff changeset
242 str_get_timestamp(tmpStr, sizeof(tmpStr), "½17½[½11½%H:%M:%S½17½]½0½ ");
ab56ed0d0c25 Slight optimization.
Matti Hamalainen <ccr@tnsp.org>
parents: 519
diff changeset
243 }
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
244
288
e7ef3db3b954 Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
245 buf = th_strdup_vprintf(fmt, ap);
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
246
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
247 if (optLogFile && (flags & LOG_FILE))
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
248 {
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
249 if (flags & LOG_STAMP) printFile(optLogFile, tmpStr);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
250 printFile(optLogFile, buf);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
251 fflush(optLogFile);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
252 }
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
253
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
254 if (!optDaemon && (flags & LOG_WINDOW))
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
255 {
466
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents: 464
diff changeset
256 nn_window_t *tmp = (win != NULL) ? win : nnwin_main_window();
501
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 497
diff changeset
257 if (flags & LOG_STAMP) nnwin_print(tmp, tmpStr);
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 497
diff changeset
258 nnwin_print(tmp, buf);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
259 }
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
260
288
e7ef3db3b954 Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
261 th_free(buf);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
262 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
263
288
e7ef3db3b954 Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
264 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
265 {
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
266 va_list ap;
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
267
100
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
268 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
269 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
270 va_end(ap);
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
271 }
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
272
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
273 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
274 {
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
275 va_list ap;
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
276
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
277 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
278 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
279 va_end(ap);
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
280 }
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
281
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
282 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
283 {
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
284 va_list ap;
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
285
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
286 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
287 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
288 va_end(ap);
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
289 }
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
290
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
291
223
03af28fb1c38 Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents: 222
diff changeset
292 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
293
236
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
294 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
295 {
385
bbd5edbf1143 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 381
diff changeset
296 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
297
359
8f3c102db611 Fix SOCKS handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 354
diff changeset
298 printMsg(NULL, "%s", tmp);
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
299
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
300 if (errorMessages != NULL)
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
301 {
223
03af28fb1c38 Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents: 222
diff changeset
302 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
303 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
304 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
305 errorMessages = tmp2;
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
306 }
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
307 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
308 errorMessages = tmp;
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
309 }
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
310
466
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents: 464
diff changeset
311
236
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
312 void errorMsg(const char *fmt, ...)
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
313 {
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
314 va_list ap;
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
315
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
316 va_start(ap, fmt);
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
317 errorMsgV(fmt, ap);
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
318 va_end(ap);
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
319 }
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
320
466
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents: 464
diff changeset
321
513
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
322 void debugMsg(const char *fmt, ...)
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
323 {
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
324 if (optDebug)
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
325 {
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
326 va_list ap;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
327
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
328 va_start(ap, fmt);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
329 printMsgV(NULL, LOG_FILE|LOG_WINDOW, fmt, ap);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
330 va_end(ap);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
331 }
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
332 }
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
333
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
334
236
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
335 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
336 {
262
6d48fc4fd421 Shut up some trivial warnings.
Matti Hamalainen <ccr@tnsp.org>
parents: 258
diff changeset
337 (void) conn;
236
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
338 errorMsgV(fmt, ap);
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
339 }
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
340
466
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents: 464
diff changeset
341
236
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
342 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
343 {
262
6d48fc4fd421 Shut up some trivial warnings.
Matti Hamalainen <ccr@tnsp.org>
parents: 258
diff changeset
344 (void) conn;
354
c01e42fc9adb More work on SOCKS proxy support, should work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 353
diff changeset
345 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
346 }
71fa0364c058 Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
347
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
348
519
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
349 BOOL checkNameList(qlist_t *list, const char *name)
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
350 {
519
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
351 qlist_t *node;
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
352
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
353 for (node = list; node != NULL; node = node->next)
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
354 {
372
b9f0bdad6285 Use th_strcasecmp() and th_strncasecmp().
Matti Hamalainen <ccr@tnsp.org>
parents: 369
diff changeset
355 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
356 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
357 }
519
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
358
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
359 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
360 }
801ac37321f6 Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
361
801ac37321f6 Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 223
diff changeset
362
416
8bb69e749d97 Rename some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 415
diff changeset
363 int nnproto_parse_user(nn_conn_t *conn)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
364 {
229
08d4355d6fc9 Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
365 BOOL isMine, isIgnored = FALSE;
417
ccee77fe4525 Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 416
diff changeset
366 char *name, *msg, *t;
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
367
419
d015ecbd231d Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents: 418
diff changeset
368 // Find start of the message
417
ccee77fe4525 Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 416
diff changeset
369 name = conn->ptr;
430
aaadf6cea6be Better handling of some messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 429
diff changeset
370 t = nn_conn_buf_strstr(conn, "</USER>");
417
ccee77fe4525 Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 416
diff changeset
371 if (!t) return 1;
ccee77fe4525 Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 416
diff changeset
372 *t = 0;
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
373
419
d015ecbd231d Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents: 418
diff changeset
374 // Find end of the message
430
aaadf6cea6be Better handling of some messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 429
diff changeset
375 t = nn_conn_buf_strstr(conn, "<MESSAGE>");
aaadf6cea6be Better handling of some messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 429
diff changeset
376 if (!t) return 2;
aaadf6cea6be Better handling of some messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 429
diff changeset
377 msg = conn->ptr;
aaadf6cea6be Better handling of some messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 429
diff changeset
378
417
ccee77fe4525 Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 416
diff changeset
379 t = nn_conn_buf_strstr(conn, "</MESSAGE>");
229
08d4355d6fc9 Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
380 if (!t) return 3;
08d4355d6fc9 Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
381 *t = 0;
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
382
419
d015ecbd231d Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents: 418
diff changeset
383 // Decode message string
417
ccee77fe4525 Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 416
diff changeset
384 msg = nn_decode_str1(msg);
481
73a648387d10 Improve error reporting.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
385 if (!msg)
73a648387d10 Improve error reporting.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
386 {
73a648387d10 Improve error reporting.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
387 errorMsg("Decode/malloc failure @ nnproto_parse_user()\n");
73a648387d10 Improve error reporting.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
388 return -1;
73a648387d10 Improve error reporting.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
389 }
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
390
419
d015ecbd231d Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents: 418
diff changeset
391 // Decode username
417
ccee77fe4525 Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 416
diff changeset
392 name = nn_decode_str1(name);
ccee77fe4525 Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 416
diff changeset
393 if (!name)
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
394 {
481
73a648387d10 Improve error reporting.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
395 errorMsg("Decode/malloc failure @ nnproto_parse_user()\n");
417
ccee77fe4525 Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 416
diff changeset
396 th_free(msg);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
397 return -2;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
398 }
229
08d4355d6fc9 Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
399
08d4355d6fc9 Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
400 /* 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
401 * that it is not our OWN username!
08d4355d6fc9 Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
402 */
417
ccee77fe4525 Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 416
diff changeset
403 isMine = strcmp(name, optUserName) == 0;
519
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
404 isIgnored = setIgnoreMode && !isMine && checkNameList(setIgnoreList, name);
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
405
419
d015ecbd231d Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents: 418
diff changeset
406 // Is it a special control message?
417
ccee77fe4525 Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 416
diff changeset
407 if (*msg == '/')
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
408 {
419
d015ecbd231d Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents: 418
diff changeset
409 // Ignore room join/leave messages
417
ccee77fe4525 Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 416
diff changeset
410 if (!optDebug && (strstr(msg, "left the room") || strstr(msg, "joined the room from")))
229
08d4355d6fc9 Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
411 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
412
417
ccee77fe4525 Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 416
diff changeset
413 t = nn_strip_tags(msg + 1);
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
414 if (!strncmp(t, "BPRV ", 5))
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
415 {
417
ccee77fe4525 Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 416
diff changeset
416 char *in_name, *tmp, *in_msg, *h;
293
ff39ebf05b40 Fix unwindowed PRVs.
Matti Hamalainen <ccr@tnsp.org>
parents: 291
diff changeset
417 nn_window_t *win;
ff39ebf05b40 Fix unwindowed PRVs.
Matti Hamalainen <ccr@tnsp.org>
parents: 291
diff changeset
418 h = nn_decode_str2(t + 1);
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
419
418
8ca09a6cca09 Minor cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
420 // Check type of
8ca09a6cca09 Minor cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
421 if ((isMine = strncmp(t, "BPRV from ", 10)) == 0)
417
ccee77fe4525 Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 416
diff changeset
422 in_name = nn_decode_str2(t + 10);
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
423 else
417
ccee77fe4525 Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 416
diff changeset
424 in_name = nn_decode_str2(t + 8);
291
cc2a1d837e7b Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
425
417
ccee77fe4525 Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 416
diff changeset
426 for (tmp = in_name; *tmp && *tmp != ':'; tmp++);
291
cc2a1d837e7b Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
427 if (tmp[0] != 0 && tmp[1] == ' ')
417
ccee77fe4525 Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 416
diff changeset
428 in_msg = tmp + 2;
291
cc2a1d837e7b Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
429 else
417
ccee77fe4525 Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 416
diff changeset
430 in_msg = "";
291
cc2a1d837e7b Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
431 *tmp = 0;
cc2a1d837e7b Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
432
519
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
433 if (!optOnlyFriendPrv || !checkNameList(setFriendList, in_name))
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
434 {
519
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
435 isIgnored = setIgnoreMode && checkNameList(setIgnoreList, in_name);
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
436 win = nnwin_find(in_name);
388
f45673fe6b23 Log private messages always in the PRV format.
Matti Hamalainen <ccr@tnsp.org>
parents: 385
diff changeset
437
519
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
438 if (win != NULL)
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
439 {
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
440 printMsgF(win, isIgnored ? 0 : LOG_WINDOW,
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
441 "½5½<½%d½%s½5½>½0½ %s\n",
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
442 isMine ? 14 : 15, isMine ? optUserName : in_name, in_msg);
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
443
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
444 printMsgF(NULL, LOG_FILE, "½11½%s½0½\n", h);
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
445 }
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
446 else
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
447 {
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
448 printMsgF(NULL, isIgnored ? LOG_FILE : (LOG_WINDOW | LOG_FILE),
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
449 "½11½%s½0½\n", h);
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
450 }
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
451 }
519
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
452
417
ccee77fe4525 Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 416
diff changeset
453 th_free(in_name);
293
ff39ebf05b40 Fix unwindowed PRVs.
Matti Hamalainen <ccr@tnsp.org>
parents: 291
diff changeset
454 th_free(h);
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
455 }
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
456 else
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
457 {
419
d015ecbd231d Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents: 418
diff changeset
458 // 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
459 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
460 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
461 "½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
462 th_free(h);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
463 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
464 th_free(t);
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
465 }
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
466 else
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
467 {
419
d015ecbd231d Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents: 418
diff changeset
468 // 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
469 char *h;
530
f0bca971170b Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 526
diff changeset
470 int colorNick, colorText;
417
ccee77fe4525 Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 416
diff changeset
471 t = nn_strip_tags(msg);
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
472 h = nn_decode_str2(t);
530
f0bca971170b Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 526
diff changeset
473 if (isMine)
f0bca971170b Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 526
diff changeset
474 {
f0bca971170b Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 526
diff changeset
475 colorNick = 14;
f0bca971170b Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 526
diff changeset
476 colorText = 0;
f0bca971170b Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 526
diff changeset
477 }
f0bca971170b Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 526
diff changeset
478 else
f0bca971170b Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 526
diff changeset
479 {
f0bca971170b Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 526
diff changeset
480 if (checkNameList(setFriendList, name))
f0bca971170b Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 526
diff changeset
481 {
f0bca971170b Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 526
diff changeset
482 colorNick = 5;
f0bca971170b Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 526
diff changeset
483 colorText = 1;
f0bca971170b Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 526
diff changeset
484 }
f0bca971170b Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 526
diff changeset
485 else
f0bca971170b Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 526
diff changeset
486 {
f0bca971170b Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 526
diff changeset
487 colorNick = 15;
f0bca971170b Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 526
diff changeset
488 colorText = 0;
f0bca971170b Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 526
diff changeset
489 }
f0bca971170b Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 526
diff changeset
490 }
f0bca971170b Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 526
diff changeset
491
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
492 printMsgF(NULL, isIgnored ? LOG_FILE : (LOG_WINDOW | LOG_FILE),
530
f0bca971170b Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 526
diff changeset
493 "½5½<½%d½%s½5½>½%d½ %s½0½\n", colorNick, name, colorText, h);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
494 th_free(h);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
495 th_free(t);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
496 }
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
497
229
08d4355d6fc9 Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
498 done:
417
ccee77fe4525 Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 416
diff changeset
499 th_free(msg);
ccee77fe4525 Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 416
diff changeset
500 th_free(name);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
501 return 0;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
502 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
503
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
504
416
8bb69e749d97 Rename some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 415
diff changeset
505 int nnproto_parse_login(nn_conn_t *conn)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
506 {
156
0a9fe14882dc Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 155
diff changeset
507 char tmpStr[256];
403
7bec02f382fb Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
508 str_get_timestamp(tmpStr, sizeof(tmpStr), "%c");
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
509
403
7bec02f382fb Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
510 if (!nn_conn_buf_strcmp(conn, "FAILURE>"))
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
511 {
430
aaadf6cea6be Better handling of some messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 429
diff changeset
512 nn_conn_buf_strstr(conn, "</LOGIN_FAILURE>");
437
8e9690a3f973 Fix parsing of LOGIN_{SUCCESS,FAILURE} packets.
Matti Hamalainen <ccr@tnsp.org>
parents: 436
diff changeset
513 nn_conn_buf_strstr(conn, "</USER>");
288
e7ef3db3b954 Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
514 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
515 return -2;
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
516 }
403
7bec02f382fb Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
517 else if (!nn_conn_buf_strcmp(conn, "SUCCESS>"))
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
518 {
430
aaadf6cea6be Better handling of some messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 429
diff changeset
519 nn_conn_buf_strstr(conn, "</LOGIN_SUCCESS>");
437
8e9690a3f973 Fix parsing of LOGIN_{SUCCESS,FAILURE} packets.
Matti Hamalainen <ccr@tnsp.org>
parents: 436
diff changeset
520 nn_conn_buf_strstr(conn, "</USER>");
288
e7ef3db3b954 Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
521 printMsg(NULL, "½2½Login success½0½ - ½3½%s½0½\n", tmpStr);
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
522 nn_conn_send_msg(conn, optUserNameEnc, "%2FRequestUserList");
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
523 return 0;
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
524 }
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
525 else
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
526 return 1;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
527 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
528
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
529
416
8bb69e749d97 Rename some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 415
diff changeset
530 int nnproto_parse_add_user(nn_conn_t *conn)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
531 {
403
7bec02f382fb Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
532 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
533 nn_window_t *win;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
534
403
7bec02f382fb Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
535 s = nn_conn_buf_strstr(conn, "</ADD_USER>");
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
536 if (!s) return 1;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
537 *s = 0;
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
538
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
539 p = nn_dbldecode_str(str);
481
73a648387d10 Improve error reporting.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
540 if (!p)
73a648387d10 Improve error reporting.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
541 {
73a648387d10 Improve error reporting.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
542 errorMsg("Decode/malloc failure @ nnproto_parse_add_user()\n");
73a648387d10 Improve error reporting.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
543 return -1;
73a648387d10 Improve error reporting.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
544 }
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
545
422
8eb2839a565c Rename various functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 421
diff changeset
546 win = nnwin_find(p);
288
e7ef3db3b954 Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
547 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
548
288
e7ef3db3b954 Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
549 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
550 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
551 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
552
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
553 th_free(p);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
554 return 0;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
555 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
556
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
557
416
8bb69e749d97 Rename some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 415
diff changeset
558 int nnproto_parse_delete_user(nn_conn_t *conn)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
559 {
403
7bec02f382fb Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
560 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
561 nn_window_t *win;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
562
403
7bec02f382fb Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
563 s = nn_conn_buf_strstr(conn, "</DELETE_USER>");
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
564 if (!s) return 1;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
565 *s = 0;
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
566
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
567 p = nn_dbldecode_str(str);
481
73a648387d10 Improve error reporting.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
568 if (!p)
73a648387d10 Improve error reporting.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
569 {
73a648387d10 Improve error reporting.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
570 errorMsg("Decode/malloc failure @ nnproto_parse_delete_user()\n");
73a648387d10 Improve error reporting.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
571 return -1;
73a648387d10 Improve error reporting.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
572 }
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
573
422
8eb2839a565c Rename various functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 421
diff changeset
574 win = nnwin_find(p);
288
e7ef3db3b954 Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
575 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
576
288
e7ef3db3b954 Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
577 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
578 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
579 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
580
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
581 th_free(p);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
582 return 0;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
583 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
584
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
585
416
8bb69e749d97 Rename some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 415
diff changeset
586 int nnproto_parse_num_clients(nn_conn_t *conn)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
587 {
403
7bec02f382fb Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
588 nn_conn_buf_strstr(conn, "</NUMCLIENTS>");
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
589 return 0;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
590 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
591
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
592
416
8bb69e749d97 Rename some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 415
diff changeset
593 int nnproto_parse_boot(nn_conn_t *conn)
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
594 {
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
595 (void) conn;
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
596 errorMsg("Booted by server.\n");
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
597 return -1;
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
598 }
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
599
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
600
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
601 typedef struct
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
602 {
443
96cb82ebb93b Rename a structure member.
Matti Hamalainen <ccr@tnsp.org>
parents: 442
diff changeset
603 char *name;
431
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents: 430
diff changeset
604 size_t len;
403
7bec02f382fb Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
605 int (*handler)(nn_conn_t *);
7bec02f382fb Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
606 } nn_protocolcmd_t;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
607
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
608
403
7bec02f382fb Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
609 static nn_protocolcmd_t protoCmds[] =
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
610 {
431
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents: 430
diff changeset
611 { "<USER>", 0, nnproto_parse_user },
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents: 430
diff changeset
612 { "<LOGIN_", 0, nnproto_parse_login },
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents: 430
diff changeset
613 { "<DELETE_USER>", 0, nnproto_parse_delete_user },
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents: 430
diff changeset
614 { "<ADD_USER>", 0, nnproto_parse_add_user },
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents: 430
diff changeset
615 { "<NUMCLIENTS>", 0, nnproto_parse_num_clients },
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents: 430
diff changeset
616 { "<BOOT />", 0, nnproto_parse_boot },
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
617 };
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
618
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
619 static const int nprotoCmds = sizeof(protoCmds) / sizeof(protoCmds[0]);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
620
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
621
403
7bec02f382fb Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
622 int nn_parse_protocol(nn_conn_t *conn)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
623 {
130
352ec3c300e4 A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
624 static BOOL protoCmdsInit = FALSE;
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
625 int i;
130
352ec3c300e4 A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
626
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
627 if (!protoCmdsInit)
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
628 {
130
352ec3c300e4 A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
629 for (i = 0; i < nprotoCmds; i++)
443
96cb82ebb93b Rename a structure member.
Matti Hamalainen <ccr@tnsp.org>
parents: 442
diff changeset
630 protoCmds[i].len = strlen(protoCmds[i].name);
403
7bec02f382fb Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
631
130
352ec3c300e4 A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
632 protoCmdsInit = TRUE;
352ec3c300e4 A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
633 }
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
634
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
635 for (i = 0; i < nprotoCmds; i++)
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
636 {
443
96cb82ebb93b Rename a structure member.
Matti Hamalainen <ccr@tnsp.org>
parents: 442
diff changeset
637 if (!nn_conn_buf_strncmp(conn, protoCmds[i].name, protoCmds[i].len))
403
7bec02f382fb Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
638 return protoCmds[i].handler(conn);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
639 }
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
640
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
641 if (optDebug)
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
642 {
403
7bec02f382fb Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
643 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
644 return 0;
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
645 }
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
646 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
647 return 1;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
648 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
649
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
650
474
4ddc3d87242e Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
651 int nn_open_uri(const char *uri)
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
652 {
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
653 #ifdef __WIN32
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
654 HINSTANCE status;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
655
442
ecbd9773c74b Minor win32 build fix.
Matti Hamalainen <ccr@tnsp.org>
parents: 439
diff changeset
656 status = ShellExecute(NULL, "open", uri, NULL, NULL, SW_SHOWNA);
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
657 if (status <= (HINSTANCE) 32)
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
658 {
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
659 printMsgQ(currWin, "Could not launch default web browser: %d\n", status);
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
660 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
661 #else
474
4ddc3d87242e Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
662 int status;
4ddc3d87242e Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
663 int fds[2];
4ddc3d87242e Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
664 pid_t pid;
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
665
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
666 if (pipe(fds) == -1)
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
667 {
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
668 int ret = errno;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
669 printMsgQ(currWin, "Could not open process communication pipe! (%d, %s)\n", ret, strerror(ret));
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
670 return 0;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
671 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
672
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
673 if ((pid = fork()) < 0)
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
674 {
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
675 printMsgQ(currWin, "Could not create sub-process!\n");
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
676 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
677 else if (pid == 0)
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
678 {
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
679 dup2(fds[1], STDOUT_FILENO);
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
680 dup2(fds[0], STDERR_FILENO);
474
4ddc3d87242e Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
681 char *url = th_strdup_printf("openurl(%s,new-tab)", uri);
478
4dca76db9e1f Fix opening of browser windows on UNIX.
Matti Hamalainen <ccr@tnsp.org>
parents: 474
diff changeset
682 execlp(setBrowser, setBrowser, "-remote", url, (void *)NULL);
474
4ddc3d87242e Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
683 th_free(url);
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
684 _exit(errno);
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
685 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
686
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
687 wait(&status);
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
688 #endif
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
689
474
4ddc3d87242e Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
690 return 0;
4ddc3d87242e Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
691 }
4ddc3d87242e Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
692
516
08bbd850e2dc Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 515
diff changeset
693
474
4ddc3d87242e Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
694 int nncmd_open_profile(nn_conn_t *conn, char *name)
4ddc3d87242e Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
695 {
4ddc3d87242e Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
696 char *enc_name = nn_encode_str1(name);
4ddc3d87242e Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
697 char *uri = th_strdup_printf(SET_PROFILE_PREFIX, name);
4ddc3d87242e Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
698 (void) conn;
4ddc3d87242e Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
699
4ddc3d87242e Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
700 printMsg(currWin, "Opening profile for: '%s'\n", name);
4ddc3d87242e Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
701
4ddc3d87242e Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
702 nn_open_uri(uri);
4ddc3d87242e Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
703
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
704 th_free(uri);
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
705 th_free(enc_name);
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
706 return 0;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
707 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
708
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
709
519
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
710 int nncmd_change_list(nn_conn_t *conn, const char *listname, qlist_t **list, const char *name)
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
711 {
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
712 (void) conn;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
713
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
714 if (name[0])
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
715 {
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
716 // Add or remove someone to/from ignore
519
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
717 qlist_t *user = th_llist_find_func(*list, name, str_compare);
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
718 if (user != NULL)
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
719 {
519
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
720 printMsgQ(currWin, "Removed user '%s' from %s list.\n", name, listname);
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
721 th_llist_delete_node(&setIgnoreList, user);
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
722 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
723 else
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
724 {
519
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
725 printMsgQ(currWin, "Added '%s' to %s list.\n", name, listname);
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
726 th_llist_append(list, th_strdup(name));
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
727 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
728 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
729 else
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
730 {
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
731 // Just list whomever is in ignore now
519
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
732 qlist_t *user = *list;
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
733 size_t nuser = th_llist_length(*list);
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
734 char *result = th_strdup_printf("Users on %s list (%d): ", listname, nuser);
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
735 while (user != NULL)
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
736 {
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
737 if (user->data != NULL)
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
738 {
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
739 th_pstr_printf(&result, "%s'%s'", result, (char *) user->data);
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
740 if (--nuser > 0)
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
741 th_pstr_printf(&result, "%s, ", result);
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
742 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
743 user = user->next;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
744 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
745 printMsgQ(currWin, "%s\n", result);
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
746 th_free(result);
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
747 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
748
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
749 return 0;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
750 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
751
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
752
519
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
753 int nncmd_ignore(nn_conn_t *conn, char *name)
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
754 {
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
755 return nncmd_change_list(conn, "ignore", &setIgnoreList, name);
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
756 }
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
757
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
758
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
759 int nncmd_friend(nn_conn_t *conn, char *name)
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
760 {
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
761 return nncmd_change_list(conn, "friend", &setFriendList, name);
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
762 }
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
763
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
764
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
765 int nncmd_set_color(nn_conn_t *conn, char *arg)
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
766 {
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
767 int val;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
768 (void) conn;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
769
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
770 if ((val = th_get_hex_triplet(arg)) < 0)
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
771 {
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
772 printMsgQ(currWin, "Invalid color value '%s'\n", arg);
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
773 return 1;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
774 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
775
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
776 optUserColor = val;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
777 printMsgQ(currWin, "Setting color to #%06x\n", optUserColor);
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
778 nn_conn_send_msg_v(conn, optUserNameEnc, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor);
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
779 return 0;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
780 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
781
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
782
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
783 int nncmd_open_query(nn_conn_t *conn, char *name)
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
784 {
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
785 (void) conn;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
786
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
787 if (name[0])
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
788 {
446
3396acd40147 Rename and remove some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 445
diff changeset
789 nn_user_t *user = nn_userhash_find(nnUsers, nn_username_encode(name));
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
790 if (user != NULL)
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
791 {
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
792 name = nn_username_decode(th_strdup(user->name));
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
793 printMsgQ(currWin, "Opening PRV query for '%s'.\n", name);
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
794 if (nnwin_open(name, TRUE))
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
795 printMsgQ(currWin, "In PRV query with '%s'.\n", name);
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
796 th_free(name);
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
797 return 0;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
798 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
799 else
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
800 {
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
801 printMsgQ(currWin, "Could not find username '%s'.\n", name);
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
802 return 1;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
803 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
804 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
805 else
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
806 {
472
53179f875131 Combine some prints.
Matti Hamalainen <ccr@tnsp.org>
parents: 468
diff changeset
807 printMsgQ(currWin,
53179f875131 Combine some prints.
Matti Hamalainen <ccr@tnsp.org>
parents: 468
diff changeset
808 "Usage: /query username\n"
53179f875131 Combine some prints.
Matti Hamalainen <ccr@tnsp.org>
parents: 468
diff changeset
809 "To close a PRV query, use /close [username]\n"
53179f875131 Combine some prints.
Matti Hamalainen <ccr@tnsp.org>
parents: 468
diff changeset
810 "/close without username will close the current PRV window, if any.\n");
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
811 return 1;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
812 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
813 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
814
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
815
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
816 int nncmd_close_query(nn_conn_t *conn, char *name)
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
817 {
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
818 (void) conn;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
819
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
820 if (name[0])
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
821 {
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
822 nn_window_t *win = nnwin_find(name);
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
823 if (win != NULL)
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
824 {
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
825 nnwin_close(win);
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
826 printMsgQ(currWin, "Closed PRV query to '%s'.\n", name);
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
827 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
828 else
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
829 {
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
830 printMsgQ(currWin, "No PRV query by name '%s'.\n", name);
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
831 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
832 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
833 else
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
834 {
466
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents: 464
diff changeset
835 if (currWin != nnwin_main_window())
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
836 {
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
837 nnwin_close(currWin);
466
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents: 464
diff changeset
838 currWin = nnwin_main_window();
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
839 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
840 else
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
841 {
472
53179f875131 Combine some prints.
Matti Hamalainen <ccr@tnsp.org>
parents: 468
diff changeset
842 printMsgQ(currWin,
53179f875131 Combine some prints.
Matti Hamalainen <ccr@tnsp.org>
parents: 468
diff changeset
843 "Usage: /close [username]\n"
53179f875131 Combine some prints.
Matti Hamalainen <ccr@tnsp.org>
parents: 468
diff changeset
844 "/close without username will close the current PRV window. if any.\n");
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
845 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
846 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
847
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
848 return 0;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
849 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
850
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
851
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
852 int nncmd_window_info(nn_conn_t *conn, char *arg)
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
853 {
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
854 (void) conn;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
855
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
856 if (arg[0])
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
857 {
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
858 int val = atoi(arg);
466
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents: 464
diff changeset
859 nn_window_t *win = nnwin_get(val);
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents: 464
diff changeset
860 if (win != NULL)
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents: 464
diff changeset
861 currWin = win;
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
862 else
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
863 {
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
864 printMsgQ(currWin, "Invalid window number '%s'\n", arg);
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
865 return 1;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
866 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
867 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
868 else
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
869 {
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
870 printMsgQ(currWin, "Window : #%d\n", currWin->num);
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
871 printMsgQ(currWin, "ID : %s\n", currWin->id);
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
872 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
873 return 0;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
874 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
875
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
876
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
877 int nncmd_list_all_users(nn_conn_t *conn, char *buf)
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
878 {
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
879 (void) buf;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
880
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
881 // Alias /listallusers
425
143fd51048a9 Fix /list command.
Matti Hamalainen <ccr@tnsp.org>
parents: 424
diff changeset
882 return nn_conn_send_msg(conn, optUserNameEnc, "%2Flistallusers");
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
883 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
884
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
885
486
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
886 #define NAME_NUM_PER_LINE 3
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
887 #define NAME_ENTRY_SIZE 64
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
888 #define NAME_ENTRY_WIDTH 22
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
889
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
890 typedef struct
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
891 {
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
892 char buf[(NAME_NUM_PER_LINE * NAME_ENTRY_SIZE) + 16];
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
893 size_t offs;
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
894 int i, total;
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
895 } nncmd_namedata_t;
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
896
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
897
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
898 static int nncmd_names_do(const nn_user_t *user, void *data)
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
899 {
486
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
900 nncmd_namedata_t *d = data;
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
901 char name[NAME_ENTRY_SIZE];
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
902 size_t len;
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
903
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
904 snprintf(name, sizeof(name), "[½3½%-20s½0½] ", user->name);
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
905
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
906 d->total++;
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
907 if (d->i >= NAME_NUM_PER_LINE)
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
908 {
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
909 printMsgQ(currWin, "%s\n", d->buf);
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
910 d->i = 0;
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
911 d->offs = 0;
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
912 }
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
913
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
914 len = strlen(name);
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
915 memcpy(d->buf + d->offs, name, len + 1);
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
916 d->offs += len;
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
917 d->i++;
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
918
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
919 return 0;
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
920 }
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
921
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
922
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
923 int nncmd_names(nn_conn_t *conn, char *arg)
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
924 {
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
925 nncmd_namedata_t data;
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
926 (void) conn;
486
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
927 (void) arg;
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
928
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
929 printMsgQ(currWin, "Users:\n");
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
930 data.i = data.total = 0;
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
931 data.offs = 0;
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
932
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
933 nn_userhash_foreach(nnUsers, nncmd_names_do, &data);
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
934
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
935 if (data.i > 0)
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
936 {
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
937 printMsgQ(currWin, "%s\n", data.buf);
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
938 }
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
939
d48327519b17 Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
940 printMsgQ(currWin, "%d users total.\n", data.total);
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
941 return 0;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
942 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
943
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
944
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
945 int nncmd_save_config(nn_conn_t *conn, char *buf)
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
946 {
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
947 (void) conn;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
948 (void) buf;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
949
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
950 FILE *cfgfile = fopen(setConfigFile, "w");
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
951 if (cfgfile == NULL)
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
952 {
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
953 printMsgQ(currWin, "Could not create configuration to file '%s': %s\n",
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
954 setConfigFile, strerror(errno));
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
955 return 0;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
956 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
957
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
958 printMsgQ(currWin, "Configuration saved in file '%s', res=%d\n",
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
959 setConfigFile,
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
960 th_cfg_write(cfgfile, setConfigFile, cfg));
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
961
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
962 fclose(cfgfile);
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
963 return 0;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
964 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
965
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
966
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
967 enum
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
968 {
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
969 CMDARG_NONE,
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
970 CMDARG_STRING,
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
971 CMDARG_OPTIONAL,
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
972 CMDARG_NICK,
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
973 };
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
974
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
975 typedef struct
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
976 {
443
96cb82ebb93b Rename a structure member.
Matti Hamalainen <ccr@tnsp.org>
parents: 442
diff changeset
977 char *name;
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
978 int flags;
431
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents: 430
diff changeset
979 size_t len;
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
980 int (*handler)(nn_conn_t *, char *buf);
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
981 } nn_usercmd_t;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
982
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
983
450
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
984 static nn_usercmd_t userCmdsTable[] =
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
985 {
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
986 // Server side commands, we just implement completion
450
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
987 { "/me", CMDARG_STRING, 0, NULL },
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
988 { "/status", CMDARG_STRING, 0, NULL },
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
989 { "/list", CMDARG_NONE, 0, nncmd_list_all_users },
518
8132548e1a07 Add /prvon and /prvoff
Matti Hamalainen <ccr@tnsp.org>
parents: 516
diff changeset
990 { "/prvon", CMDARG_NONE, 0, NULL },
8132548e1a07 Add /prvon and /prvoff
Matti Hamalainen <ccr@tnsp.org>
parents: 516
diff changeset
991 { "/prvoff", CMDARG_NONE, 0, NULL },
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
992
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
993 // List internal username list
450
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
994 { "/who", CMDARG_NONE, 0, nncmd_names },
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
995 { "/names", CMDARG_NONE, 0, nncmd_names },
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
996
450
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
997 { "/w", CMDARG_NICK, 0, nncmd_open_profile },
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
998 { "/profile", CMDARG_NICK, 0, nncmd_open_profile },
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
999
450
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1000 { "/query", CMDARG_NICK, 0, nncmd_open_query },
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1001 { "/close", CMDARG_OPTIONAL, 0, nncmd_close_query },
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1002 { "/win", CMDARG_OPTIONAL, 0, nncmd_window_info },
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1003
497
cbbf502e4a70 Fix /ignore command.
Matti Hamalainen <ccr@tnsp.org>
parents: 494
diff changeset
1004 { "/ignore", CMDARG_OPTIONAL, 0, nncmd_ignore },
519
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
1005 { "/friend", CMDARG_OPTIONAL, 0, nncmd_friend },
450
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1006 { "/color", CMDARG_STRING, 0, nncmd_set_color },
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1007 { "/save", CMDARG_NONE, 0, nncmd_save_config },
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1008 };
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1009
450
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1010 static qlist_t *userCmds = NULL;
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1011
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1012
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1013 void nn_usercmd_init()
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1014 {
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1015 size_t i;
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1016 for (i = 0; i < sizeof(userCmdsTable) / sizeof(userCmdsTable[0]); i++)
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1017 {
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1018 th_llist_append(&userCmds, &userCmdsTable[i]);
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1019 userCmdsTable[i].len = strlen(userCmdsTable[i].name);
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1020 }
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1021 }
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1022
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1023
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1024 int nn_handle_command(nn_conn_t *conn, char *buf)
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1025 {
450
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1026 qlist_t *curr;
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1027
450
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1028 for (curr = userCmds; curr != NULL; curr = curr->next)
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1029 {
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1030 nn_usercmd_t *cmd = curr->data;
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1031
450
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1032 if (!th_strncasecmp(buf, cmd->name, cmd->len))
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1033 {
457
69ce77696c5d Fix command precedence.
Matti Hamalainen <ccr@tnsp.org>
parents: 456
diff changeset
1034 char *nbuf;
69ce77696c5d Fix command precedence.
Matti Hamalainen <ccr@tnsp.org>
parents: 456
diff changeset
1035 if (buf[cmd->len] != 0 && !th_isspace(buf[cmd->len]))
69ce77696c5d Fix command precedence.
Matti Hamalainen <ccr@tnsp.org>
parents: 456
diff changeset
1036 continue;
69ce77696c5d Fix command precedence.
Matti Hamalainen <ccr@tnsp.org>
parents: 456
diff changeset
1037
69ce77696c5d Fix command precedence.
Matti Hamalainen <ccr@tnsp.org>
parents: 456
diff changeset
1038 nbuf = str_trim_left(buf + cmd->len);
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1039
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1040 switch (cmd->flags)
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1041 {
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1042 case CMDARG_NICK:
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1043 case CMDARG_STRING:
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1044 if (!nbuf[0])
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1045 {
450
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1046 printMsgQ(currWin, "Command %s requires an argument.\n", cmd->name);
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1047 return 1;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1048 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1049 break;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1050
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1051 case CMDARG_NONE:
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1052 if (nbuf[0])
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1053 {
450
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1054 printMsgQ(currWin, "Command %s does not take arguments.\n", cmd->name);
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1055 return 1;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1056 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1057 break;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1058
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1059 case CMDARG_OPTIONAL:
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1060 break;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1061 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1062
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1063 // Check if there is a handler function
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1064 if (cmd->handler)
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1065 {
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1066 // Internal commands have a handler
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1067 return cmd->handler(conn, nbuf);
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1068 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1069 else
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1070 {
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1071 // Server-side commands are just pass-through here
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1072 char *tmp = nn_dblencode_str(buf);
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1073 BOOL result;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1074 if (tmp == NULL) return -2;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1075 result = nn_conn_send_msg(conn, optUserNameEnc, tmp);
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1076 th_free(tmp);
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1077 return result ? 0 : -1;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1078 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1079 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1080 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1081
444
29a341fa80a1 Fix cosmetic output issue.
Matti Hamalainen <ccr@tnsp.org>
parents: 443
diff changeset
1082 printMsgQ(currWin, "Unknown command: %s\n", buf);
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1083 return 1;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1084 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1085
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1086
450
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1087 static nn_usercmd_t *nn_usercmd_match_do(qlist_t *list, const char *pattern, size_t len)
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1088 {
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1089 qlist_t *node;
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1090 for (node = list; node != NULL; node = node->next)
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1091 {
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1092 nn_usercmd_t *cmd = node->data;
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1093 if (len <= strlen(cmd->name) && th_strncasecmp(cmd->name, pattern, len) == 0)
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1094 return cmd;
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1095 }
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1096 return NULL;
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1097 }
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1098
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1099
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1100 nn_usercmd_t *nn_usercmd_match(qlist_t *list, const char *pattern, const char *current, BOOL again)
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1101 {
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1102 nn_usercmd_t *curr;
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1103 size_t len;
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1104
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1105 if (list == NULL || pattern == NULL) return NULL;
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1106
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1107 len = strlen(pattern);
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1108
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1109 if (current != NULL)
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1110 {
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1111 qlist_t *node;
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1112 for (node = list; node != NULL; node = node->next)
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1113 {
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1114 curr = node->data;
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1115 if (th_strcasecmp(curr->name, current) == 0)
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1116 {
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1117 if (again)
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1118 return curr;
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1119
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1120 if ((curr = nn_usercmd_match_do(node->next, pattern, len)) != NULL)
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1121 return curr;
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1122 }
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1123 }
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1124 }
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1125
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1126 if ((curr = nn_usercmd_match_do(list, pattern, len)) != NULL)
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1127 return curr;
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1128
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1129 return NULL;
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1130 }
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1131
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1132
410
7ea78f4a4d23 Rename input handling main function.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
1133 int nn_handle_input(nn_conn_t *conn, char *buf, size_t bufLen)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1134 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1135 BOOL result;
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1136 char *tmp;
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1137
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1138 // Trim right side
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1139 while (bufLen > 0 && th_isspace(buf[bufLen - 1]))
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1140 buf[--bufLen] = 0;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1141
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1142 if (buf[0] == 0)
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1143 return 1;
258
8a0f7446318e General cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 254
diff changeset
1144
419
d015ecbd231d Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents: 418
diff changeset
1145 // 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
1146 nn_username_decode(buf);
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1147
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1148 // Check for commands
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1149 if (buf[0] == '/')
426
c2e4d7b4e0ae Fix server-side commands.
Matti Hamalainen <ccr@tnsp.org>
parents: 425
diff changeset
1150 return nn_handle_command(conn, buf);
133
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
1151
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1152 // If current window is not the main room window, send private
466
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents: 464
diff changeset
1153 if (currWin != nnwin_main_window())
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1154 {
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1155 if (currWin->id != NULL)
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1156 {
431
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents: 430
diff changeset
1157 char *msg = th_strdup_printf("/prv -to %s -msg %s", currWin->id, buf);
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1158 if (msg == NULL) return -3;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1159 tmp = nn_dblencode_str(msg);
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1160 if (tmp == NULL)
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1161 {
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1162 th_free(msg);
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1163 return -2;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1164 }
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1165 result = nn_conn_send_msg(conn, optUserNameEnc, tmp);
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1166 th_free(tmp);
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1167 th_free(msg);
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1168 return result ? 0 : -1;
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1169 }
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1170 else
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1171 {
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
1172 printMsgQ(NULL, "No target set, exiting prv mode.\n");
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1173 return 1;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1174 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1175 }
291
cc2a1d837e7b Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents: 289
diff changeset
1176
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1177 // Send double-encoded message
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1178 tmp = nn_dblencode_str(buf);
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1179 if (tmp == NULL) return -2;
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1180 result = nn_conn_send_msg(conn, optUserNameEnc, tmp);
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1181 th_free(tmp);
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1182 return result ? 0 : -1;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1183 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1184
405
b4ed5d574edc Add some empty lines.
Matti Hamalainen <ccr@tnsp.org>
parents: 404
diff changeset
1185
449
7d9fa9f7caf1 Rename tab completion functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
1186 static void nn_tabcomplete_replace(nn_editbuf_t *buf, size_t *pi, const size_t startPos, const size_t endPos, char *c)
447
2d650408f5de Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
1187 {
2d650408f5de Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
1188 size_t i;
2d650408f5de Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
1189
2d650408f5de Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
1190 for (i = startPos; i <= endPos; i++)
2d650408f5de Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
1191 nn_editbuf_delete(buf, startPos);
2d650408f5de Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
1192
2d650408f5de Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
1193 for (i = startPos; *c; i++, c++)
2d650408f5de Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
1194 nn_editbuf_insert(buf, i, *c);
2d650408f5de Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
1195
2d650408f5de Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
1196 *pi = i;
2d650408f5de Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
1197 }
2d650408f5de Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
1198
2d650408f5de Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
1199
449
7d9fa9f7caf1 Rename tab completion functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
1200 static void nn_tabcomplete_finish(nn_editbuf_t *buf, char **previous, const size_t startPos, const char *name)
447
2d650408f5de Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
1201 {
2d650408f5de Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
1202 nn_editbuf_setpos(buf, startPos + 1 + strlen(name));
2d650408f5de Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
1203 th_free(*previous);
2d650408f5de Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
1204 *previous = th_strdup(name);
2d650408f5de Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
1205 }
2d650408f5de Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
1206
2d650408f5de Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
1207
449
7d9fa9f7caf1 Rename tab completion functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
1208 BOOL nn_tabcomplete_buffer(nn_editbuf_t *buf)
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1209 {
189
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
1210 static char *previous = NULL, *pattern = NULL;
451
733396469e5d Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 450
diff changeset
1211 char *str = buf->data;
429
2ac24f1e241b Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 427
diff changeset
1212 BOOL again = FALSE, hasSeparator = FALSE,
447
2d650408f5de Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
1213 hasSpace, newPattern = FALSE, isCommand;
431
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents: 430
diff changeset
1214 size_t endPos, startPos = buf->pos;
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
1215
419
d015ecbd231d Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents: 418
diff changeset
1216 // previous word
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1217 if (startPos >= 2 && str[startPos - 1] == ' ' && str[startPos - 2] != ' ')
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1218 {
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 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
1220 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
1221 while (startPos > 0 && str[startPos - 1] != ' ') startPos--;
189
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
1222 }
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1223 else
419
d015ecbd231d Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents: 418
diff changeset
1224 // middle of a word, new pattern
404
d11a68f214eb Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
1225 if (startPos < buf->len && str[startPos] != ' ')
d11a68f214eb Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
1226 {
d11a68f214eb Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
1227 endPos = startPos;
d11a68f214eb Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
1228 while (startPos > 0 && str[startPos - 1] != ' ') startPos--;
d11a68f214eb Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
1229 while (endPos < buf->len - 1 && str[endPos + 1] != ' ') endPos++;
d11a68f214eb Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
1230 newPattern = TRUE;
d11a68f214eb Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
1231 }
d11a68f214eb Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
1232 else
419
d015ecbd231d Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents: 418
diff changeset
1233 // previous word, new pattern
404
d11a68f214eb Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
1234 if (startPos >= 1 && str[startPos - 1] != ' ')
d11a68f214eb Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
1235 {
d11a68f214eb Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
1236 startPos -= 1;
d11a68f214eb Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
1237 endPos = startPos;
d11a68f214eb Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
1238 while (startPos > 0 && str[startPos - 1] != ' ') startPos--;
d11a68f214eb Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
1239 newPattern = TRUE;
d11a68f214eb Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
1240 }
d11a68f214eb Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
1241 else
d11a68f214eb Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
1242 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
1243
429
2ac24f1e241b Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 427
diff changeset
1244 // Check if this is a command completion
2ac24f1e241b Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 427
diff changeset
1245 isCommand = (str[0] == '/' && startPos == 0);
2ac24f1e241b Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 427
diff changeset
1246
2ac24f1e241b Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 427
diff changeset
1247 if (!isCommand && str[endPos] == optNickSep)
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1248 {
189
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
1249 endPos--;
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1250 if (startPos > 0)
113
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
1251 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
1252 hasSeparator = TRUE;
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
1253 }
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
1254
451
733396469e5d Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 450
diff changeset
1255 hasSpace = (buf->pos > 0 && str[buf->pos - 1] == ' ') ||
447
2d650408f5de Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
1256 (buf->pos <= buf->len && str[buf->pos] == ' ');
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1257
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1258 if (newPattern)
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1259 {
419
d015ecbd231d Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents: 418
diff changeset
1260 // 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
1261 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
1262 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
1263 again = TRUE;
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1264
189
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
1265 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
1266 pattern = npattern;
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1267
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1268 if (!again)
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1269 {
116
741e45592522 Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
1270 th_free(previous);
741e45592522 Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
1271 previous = NULL;
741e45592522 Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
1272 }
189
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
1273 }
116
741e45592522 Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
1274
429
2ac24f1e241b Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 427
diff changeset
1275 if (!pattern)
2ac24f1e241b Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 427
diff changeset
1276 return FALSE;
2ac24f1e241b Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 427
diff changeset
1277
2ac24f1e241b Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 427
diff changeset
1278 if (isCommand)
2ac24f1e241b Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 427
diff changeset
1279 {
450
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1280 nn_usercmd_t *cmd = nn_usercmd_match(userCmds, pattern, previous, again);
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1281 if (cmd)
429
2ac24f1e241b Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 427
diff changeset
1282 {
450
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1283 size_t i;
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1284 nn_tabcomplete_replace(buf, &i, startPos, endPos, cmd->name);
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1285
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1286 if (!hasSpace)
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1287 nn_editbuf_insert(buf, i++, ' ');
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1288
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1289 nn_tabcomplete_finish(buf, &previous, startPos, cmd->name);
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1290 return TRUE;
429
2ac24f1e241b Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 427
diff changeset
1291 }
2ac24f1e241b Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 427
diff changeset
1292 }
2ac24f1e241b Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 427
diff changeset
1293 else
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1294 {
446
3396acd40147 Rename and remove some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 445
diff changeset
1295 nn_user_t *user = nn_userhash_match(nnUsers, pattern, previous, again);
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
1296
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1297 if (user)
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1298 {
431
a9b20b31cae1 More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents: 430
diff changeset
1299 size_t i;
449
7d9fa9f7caf1 Rename tab completion functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
1300 nn_tabcomplete_replace(buf, &i, startPos, endPos, user->name);
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
1301
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1302 if (!hasSeparator && startPos == 0)
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1303 {
189
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
1304 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
1305 startPos++;
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
1306 }
447
2d650408f5de Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
1307 else
189
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
1308 if (hasSeparator)
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
1309 startPos++;
447
2d650408f5de Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
1310
189
b0d64dde62af Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents: 188
diff changeset
1311 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
1312 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
1313
449
7d9fa9f7caf1 Rename tab completion functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 448
diff changeset
1314 nn_tabcomplete_finish(buf, &previous, startPos, user->name);
113
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
1315 return TRUE;
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
1316 }
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
1317 }
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1318
113
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
1319 return FALSE;
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1320 }
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1321
405
b4ed5d574edc Add some empty lines.
Matti Hamalainen <ccr@tnsp.org>
parents: 404
diff changeset
1322
511
291e3caa91a0 Move logParseFilename() to nn_log_parse_filename() under util.c and rename logFileOpen() and logFileClose().
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
1323 BOOL nn_log_file_open(void)
239
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
1324 {
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
1325 char *filename;
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
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 if (optLogFilename == NULL || !optLogEnable)
239
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
1328 return FALSE;
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
1329
511
291e3caa91a0 Move logParseFilename() to nn_log_parse_filename() under util.c and rename logFileOpen() and logFileClose().
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
1330 filename = nn_log_parse_filename(optLogFilename, optPort);
239
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
1331
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1332 if ((optLogFile = fopen(filename, "a")) == NULL)
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1333 {
242
cb86d7543be2 Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
1334 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
1335 th_free(filename);
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
1336 return FALSE;
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
1337 }
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1338
242
cb86d7543be2 Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
1339 th_free(filename);
cb86d7543be2 Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
1340
239
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
1341 return TRUE;
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
405
b4ed5d574edc Add some empty lines.
Matti Hamalainen <ccr@tnsp.org>
parents: 404
diff changeset
1344
511
291e3caa91a0 Move logParseFilename() to nn_log_parse_filename() under util.c and rename logFileOpen() and logFileClose().
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
1345 void nn_log_file_close(void)
239
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
1346 {
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1347 if (optLogFile)
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1348 {
242
cb86d7543be2 Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
1349 fclose(optLogFile);
cb86d7543be2 Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
1350 optLogFile = NULL;
cb86d7543be2 Add functionality for generating logfile names based on port etc. and
Matti Hamalainen <ccr@tnsp.org>
parents: 240
diff changeset
1351 }
239
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
1352 }
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
1353
405
b4ed5d574edc Add some empty lines.
Matti Hamalainen <ccr@tnsp.org>
parents: 404
diff changeset
1354
513
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1355 BOOL processUserInput(int c, nn_editbuf_t *editBuf, nn_editstate_t *editState)
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1356 {
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1357 // Chat window switching via Meta/Esc-[1..9]
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1358 if (c >= 0x5001 && c <= 0x5009)
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1359 {
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1360 nn_window_t *win = nnwin_get(c - 0x5000);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1361 if (win != NULL)
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1362 {
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1363 currWin = win;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1364 editState->update = TRUE;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1365 }
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1366 }
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1367 else
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1368 switch (c)
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1369 {
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1370 case KEY_ENTER:
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1371 // Call the user input handler
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1372 if (editBuf->len > 0)
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1373 {
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1374 int result;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1375
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1376 if (editHistMax > 0)
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1377 {
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1378 nn_editbuf_free(editHistBuf[SET_MAX_HISTORY+1]);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1379 editHistBuf[SET_MAX_HISTORY+1] = NULL;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1380 memmove(&editHistBuf[2], &editHistBuf[1],
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1381 editHistMax * sizeof(editHistBuf[0]));
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1382 }
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1383
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1384 editHistPos = 0;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1385 editHistBuf[1] = nn_editbuf_copy(editBuf);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1386 if (editHistMax < SET_MAX_HISTORY)
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1387 editHistMax++;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1388
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1389 result = nn_handle_input(editState->conn, editBuf->data, editBuf->len);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1390
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1391 nn_editbuf_clear(editBuf);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1392
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1393 if (result < 0)
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1394 {
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1395 errorMsg("Fatal error handling user input: %s\n", editBuf->data);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1396 editState->isError = TRUE;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1397 }
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1398 else
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1399 {
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1400 // Update time value of last sent message for unidle timeouts
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1401 editState->prevKeepAlive = time(NULL);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1402 }
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1403 }
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1404 break;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1405
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1406 case KEY_NPAGE:
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1407 case KEY_PPAGE:
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1408 // Page Up / Page Down
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1409 if (currWin != NULL)
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1410 {
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1411 int oldPos = currWin->pos, page = (scrHeight - 4) / 3;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1412
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1413 currWin->pos += (c == KEY_NPAGE) ? - page : page;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1414
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1415 if (currWin->pos >= currWin->data->n - page)
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1416 currWin->pos = currWin->data->n - page;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1417 if (currWin->pos < 0)
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1418 currWin->pos = 0;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1419
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1420 if (oldPos != currWin->pos)
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1421 editState->update = TRUE;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1422 }
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1423 break;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1424
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1425 case KEY_UP: // Backwards in input history
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1426 if (editHistPos == 0)
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1427 {
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1428 nn_editbuf_free(editHistBuf[0]);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1429 editHistBuf[0] = nn_editbuf_copy(editBuf);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1430 }
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1431 if (editHistPos < editHistMax)
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1432 {
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1433 editHistPos++;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1434 nn_editbuf_free(editBuf);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1435 editBuf = nn_editbuf_copy(editHistBuf[editHistPos]);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1436 }
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1437 break;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1438
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1439 case KEY_DOWN: // Forwards in input history
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1440 if (editHistPos > 0)
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1441 {
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1442 editHistPos--;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1443 nn_editbuf_free(editBuf);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1444 editBuf = nn_editbuf_copy(editHistBuf[editHistPos]);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1445 }
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1446 break;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1447
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1448 case KEY_F(5): // F5 = Ignore mode
515
151edcb79ce4 Fix ignore mode toggling.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
1449 setIgnoreMode = !setIgnoreMode;
513
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1450 printMsgQ(currWin, "Ignore mode = %s\n", setIgnoreMode ? "ON" : "OFF");
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1451 break;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1452
519
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
1453 case KEY_F(6): // F6 = Ignore mode
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
1454 optOnlyFriendPrv = !optOnlyFriendPrv;
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
1455 printMsgQ(currWin, "Only friends allowed to PRV you = %s\n", optOnlyFriendPrv ? "ON" : "OFF");
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
1456 break;
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
1457
513
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1458 case 0x03: // ^C = quit
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1459 case KEY_F(9): // F9 = Quit
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1460 printMsg(currWin, "Quitting per user request (%d/0x%x).\n", c, c);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1461 editState->exitProg = TRUE;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1462 break;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1463
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1464 case 0x09: // Tab = complete username or command
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1465 nn_tabcomplete_buffer(editBuf);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1466 break;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1467
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1468 default:
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1469 return FALSE;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1470 }
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1471
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1472 return TRUE;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1473 }
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1474
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1475
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1476 BOOL processUserPrompt(int c, nn_editbuf_t *editBuf, nn_editstate_t *editState)
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1477 {
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1478 (void) editBuf;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1479
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1480 switch (c)
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1481 {
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1482 case KEY_ENTER:
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1483 editState->done = TRUE;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1484 break;
526
ba5807ebff88 Make it possible to quit when entering username/passwd.
Matti Hamalainen <ccr@tnsp.org>
parents: 521
diff changeset
1485
ba5807ebff88 Make it possible to quit when entering username/passwd.
Matti Hamalainen <ccr@tnsp.org>
parents: 521
diff changeset
1486 case 0x03: // ^C = quit
ba5807ebff88 Make it possible to quit when entering username/passwd.
Matti Hamalainen <ccr@tnsp.org>
parents: 521
diff changeset
1487 case KEY_F(9): // F9 = Quit
ba5807ebff88 Make it possible to quit when entering username/passwd.
Matti Hamalainen <ccr@tnsp.org>
parents: 521
diff changeset
1488 printMsg(currWin, "Quitting per user request (%d/0x%x).\n", c, c);
ba5807ebff88 Make it possible to quit when entering username/passwd.
Matti Hamalainen <ccr@tnsp.org>
parents: 521
diff changeset
1489 editState->exitProg = TRUE;
ba5807ebff88 Make it possible to quit when entering username/passwd.
Matti Hamalainen <ccr@tnsp.org>
parents: 521
diff changeset
1490 break;
513
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1491
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1492 default:
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1493 return FALSE;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1494 }
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1495
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1496 return TRUE;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1497 }
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1498
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1499
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1500 void updateUserPrompt(nn_editbuf_t *editBuf, nn_editstate_t *editState)
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1501 {
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1502 nnwin_update(editState->update, editState->mask, editBuf, optUserName, optUserColor);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1503 }
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1504
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1505
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1506 int main(int argc, char *argv[])
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1507 {
513
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1508 char *tmpStr;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1509 int index, updateCount = 0;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1510 BOOL argsOK, colorSet = FALSE;
168
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1511 nn_conn_t *conn = NULL;
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1512 nn_editbuf_t *editBuf = nn_editbuf_new(NN_TMPBUF_SIZE);
513
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1513 nn_editstate_t editState;
154
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
1514 cfgitem_t *tmpcfg;
432
966c521e0954 Rename user home directory variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 431
diff changeset
1515 char *setHomeDir = NULL;
288
e7ef3db3b954 Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
1516
513
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1517 memset(editHistBuf, 0, sizeof(editHistBuf));
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1518 memset(&editState, 0, sizeof(editState));
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1519 editState.insertMode = TRUE;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1520 editState.debugMsg = debugMsg;
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1521
419
d015ecbd231d Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents: 418
diff changeset
1522 // 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
1523 th_init("NNChat", "Newbie Nudes chat client", NN_VERSION,
399
06a1c1db5bbb Update copyright.
Matti Hamalainen <ccr@tnsp.org>
parents: 398
diff changeset
1524 "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
1525 "This software is freeware, use and distribute as you wish.");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1526 th_verbosityLevel = 0;
133
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
1527
419
d015ecbd231d Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents: 418
diff changeset
1528 // Read configuration file
148
9da39d090ef1 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 147
diff changeset
1529 tmpcfg = NULL;
133
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
1530 th_cfg_add_comment(&tmpcfg, "General settings");
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
1531 th_cfg_add_string(&tmpcfg, "username", &optUserName, NULL);
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
1532 th_cfg_add_string(&tmpcfg, "password", &optPassword, NULL);
409
4556174b5be8 Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 408
diff changeset
1533
150
db5e7a1f1eb3 Add comment in config file about format of user color setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 149
diff changeset
1534 th_cfg_add_comment(&tmpcfg, "Default color as a hex-triplet");
133
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
1535 th_cfg_add_hexvalue(&tmpcfg, "color", &optUserColor, optUserColor);
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1536
149
a4d6707161a7 Add config file option for default setting of ignore mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
1537 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
1538 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
1539 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
1540 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
1541
519
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
1542 th_cfg_add_comment(&tmpcfg, "Allow only defined friends to private to you");
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
1543 th_cfg_add_bool(&tmpcfg, "prv_friends", &optOnlyFriendPrv, optOnlyFriendPrv);
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
1544 th_cfg_add_comment(&tmpcfg, "List of your friends");
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
1545 th_cfg_add_string_list(&tmpcfg, "friend_list", &setFriendList);
f17d2ab25618 Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
1546
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
1547 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
1548 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
1549
409
4556174b5be8 Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 408
diff changeset
1550 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
1551 th_cfg_add_string(&tmpcfg, "nick_separator", &optNickSepStr, NULL);
4556174b5be8 Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 408
diff changeset
1552
133
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
1553 th_cfg_add_section(&cfg, "general", tmpcfg);
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
1554
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
1555
133
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
1556 tmpcfg = NULL;
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
1557 th_cfg_add_comment(&tmpcfg, "Chat server hostname or IP address");
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
1558 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
1559 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
1560 th_cfg_add_int(&tmpcfg, "port", &optPort, optPort);
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
1561 th_cfg_add_section(&cfg, "server", tmpcfg);
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
1562
239
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
1563 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
1564 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
1565 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
1566 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
1567 th_cfg_add_string(&tmpcfg, "host", &optProxyServer, optProxyServer);
83ae825bb8c1 Add configuration section for proxy settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 352
diff changeset
1568 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
1569 th_cfg_add_int(&tmpcfg, "port", &optProxyPort, optProxyPort);
83ae825bb8c1 Add configuration section for proxy settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 352
diff changeset
1570 th_cfg_add_section(&cfg, "proxy", tmpcfg);
83ae825bb8c1 Add configuration section for proxy settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 352
diff changeset
1571
83ae825bb8c1 Add configuration section for proxy settings.
Matti Hamalainen <ccr@tnsp.org>
parents: 352
diff changeset
1572 tmpcfg = NULL;
239
b7e7ed741a18 Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 233
diff changeset
1573 th_cfg_add_comment(&tmpcfg, "Enable logging");
247
fce4e2e31d69 Add the config section ...
Matti Hamalainen <ccr@tnsp.org>
parents: 242
diff changeset
1574 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
1575 th_cfg_add_comment(&tmpcfg, "Log filename format");
247
fce4e2e31d69 Add the config section ...
Matti Hamalainen <ccr@tnsp.org>
parents: 242
diff changeset
1576 th_cfg_add_string(&tmpcfg, "filename", &optLogFilename, optLogFilename);
fce4e2e31d69 Add the config section ...
Matti Hamalainen <ccr@tnsp.org>
parents: 242
diff changeset
1577 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
1578
512
93c8ba1ef55f Support XDG specification.
Matti Hamalainen <ccr@tnsp.org>
parents: 511
diff changeset
1579 // Get home directory path
154
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
1580 #ifdef __WIN32
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
1581 {
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1582 char tmpPath[MAX_PATH];
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1583 if (SHGetFolderPath(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, tmpPath) == S_OK)
432
966c521e0954 Rename user home directory variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 431
diff changeset
1584 setHomeDir = th_strdup(tmpPath);
197
e0ec2280a778 Implement browser launching on Windows via ShellExecute().
Matti Hamalainen <ccr@tnsp.org>
parents: 196
diff changeset
1585
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1586 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
1587 }
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
1588 #else
512
93c8ba1ef55f Support XDG specification.
Matti Hamalainen <ccr@tnsp.org>
parents: 511
diff changeset
1589 {
93c8ba1ef55f Support XDG specification.
Matti Hamalainen <ccr@tnsp.org>
parents: 511
diff changeset
1590 char *xdgConfigDir = getenv("XDG_CONFIG_HOME"),
93c8ba1ef55f Support XDG specification.
Matti Hamalainen <ccr@tnsp.org>
parents: 511
diff changeset
1591 *userHomeDir = getenv("HOME");
93c8ba1ef55f Support XDG specification.
Matti Hamalainen <ccr@tnsp.org>
parents: 511
diff changeset
1592 #ifdef USE_XDG
93c8ba1ef55f Support XDG specification.
Matti Hamalainen <ccr@tnsp.org>
parents: 511
diff changeset
1593 if (xdgConfigDir != NULL)
93c8ba1ef55f Support XDG specification.
Matti Hamalainen <ccr@tnsp.org>
parents: 511
diff changeset
1594 setHomeDir = th_strdup(xdgConfigDir);
93c8ba1ef55f Support XDG specification.
Matti Hamalainen <ccr@tnsp.org>
parents: 511
diff changeset
1595 else
93c8ba1ef55f Support XDG specification.
Matti Hamalainen <ccr@tnsp.org>
parents: 511
diff changeset
1596 setHomeDir = th_strdup_printf("%s/.config", userHomeDir);
93c8ba1ef55f Support XDG specification.
Matti Hamalainen <ccr@tnsp.org>
parents: 511
diff changeset
1597 #else
93c8ba1ef55f Support XDG specification.
Matti Hamalainen <ccr@tnsp.org>
parents: 511
diff changeset
1598 setHomeDir = th_strdup(userHomeDir);
93c8ba1ef55f Support XDG specification.
Matti Hamalainen <ccr@tnsp.org>
parents: 511
diff changeset
1599 #endif
93c8ba1ef55f Support XDG specification.
Matti Hamalainen <ccr@tnsp.org>
parents: 511
diff changeset
1600 }
154
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
1601 #endif
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1602
432
966c521e0954 Rename user home directory variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 431
diff changeset
1603 if (setHomeDir != NULL)
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1604 {
154
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
1605 FILE *cfgfile;
432
966c521e0954 Rename user home directory variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 431
diff changeset
1606 setConfigFile = th_strdup_printf("%s" SET_DIR_SEPARATOR "%s", setHomeDir, SET_CONFIG_FILE);
154
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
1607
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
1608 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
1609
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1610 if ((cfgfile = fopen(setConfigFile, "r")) != NULL)
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1611 {
154
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
1612 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
1613 fclose(cfgfile);
864e6e52ed69 Fix a filehandle leak when reading in configuration file.
Matti Hamalainen <ccr@tnsp.org>
parents: 314
diff changeset
1614 }
133
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
1615 }
196
edd5ce3e5399 Add simplistic username/password requester if none given on commandline or config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 195
diff changeset
1616
409
4556174b5be8 Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 408
diff changeset
1617 if (optNickSepStr)
4556174b5be8 Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 408
diff changeset
1618 optNickSep = optNickSepStr[0];
4556174b5be8 Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 408
diff changeset
1619 else
4556174b5be8 Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 408
diff changeset
1620 optNickSep = SET_NICK_SEPARATOR;
4556174b5be8 Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 408
diff changeset
1621
4556174b5be8 Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 408
diff changeset
1622
137
fad8c31e41e6 Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
1623 setBrowser = getenv("BROWSER");
fad8c31e41e6 Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
1624 if (setBrowser == NULL)
fad8c31e41e6 Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
1625 setBrowser = "firefox";
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1626
419
d015ecbd231d Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents: 418
diff changeset
1627 // Parse command line arguments
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1628 argsOK = th_args_process(argc, argv, optList, optListN,
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1629 argHandleOpt, argHandleFile, FALSE);
26
b84fc46c6035 Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
1630
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1631 if (optUserNameCmd != NULL)
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1632 {
513
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1633 THMSG(1, "Username set on commandline.\n");
198
21a37995c3fb Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents: 197
diff changeset
1634 optUserName = optUserNameCmd;
21a37995c3fb Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents: 197
diff changeset
1635 optPassword = optPasswordCmd;
21a37995c3fb Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents: 197
diff changeset
1636 }
21a37995c3fb Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents: 197
diff changeset
1637
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1638 if (!argsOK)
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1639 return -2;
64
6a3a917303e4 Some random cleanups, bring back WinSock support.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
1640
419
d015ecbd231d Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents: 418
diff changeset
1641 // Allocate userhash
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1642 if ((nnUsers = nn_userhash_new()) == NULL)
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1643 {
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1644 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
1645 return -105;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1646 }
64
6a3a917303e4 Some random cleanups, bring back WinSock support.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
1647
419
d015ecbd231d Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents: 418
diff changeset
1648 // If no idle messages are set, add default
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1649 if (setIdleMessages == NULL)
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1650 {
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
1651 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
1652 }
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
1653
419
d015ecbd231d Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents: 418
diff changeset
1654 // Open logfile
511
291e3caa91a0 Move logParseFilename() to nn_log_parse_filename() under util.c and rename logFileOpen() and logFileClose().
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
1655 nn_log_file_open();
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1656
419
d015ecbd231d Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents: 418
diff changeset
1657 // Initialize network
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1658 if (!nn_network_init())
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1659 {
91
acfc4b4bc180 Create network initialization functions in libnnchat and move Win32/WinSock code there.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
1660 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
1661 goto err_exit;
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1662 }
68
3ab7751fdad1 MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
1663
466
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents: 464
diff changeset
1664 // Initialize curses windowing
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents: 464
diff changeset
1665 if (!optDaemon && !nnwin_init(SET_DELAY))
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents: 464
diff changeset
1666 goto err_exit;
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1667
466
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents: 464
diff changeset
1668 if (cursesInit)
501
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 497
diff changeset
1669 {
513
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1670 printMsg(NULL, "%s v%s - %s\n", th_prog_name, th_prog_version, th_prog_fullname);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1671 printMsg(NULL, "%s\n", th_prog_author);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1672 printMsg(NULL, "%s\n", th_prog_license);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1673
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1674 nnwin_update(TRUE, FALSE, NULL, optUserName, optUserColor);
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
1675
513
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1676 // Check if we have username and password
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1677 if (optUserName == NULL || optPassword == NULL)
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1678 {
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1679 printMsg(NULL, "Please enter your NN login credentials.\n");
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1680 printMsg(NULL, "You can avoid doing this every time by issuing '/save' after logging in.\n");
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1681
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1682 printMsg(NULL, "Enter your NN username ...\n");
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1683 optUserName = nnwin_prompt_requester(FALSE, &editState, processUserPrompt, updateUserPrompt);
526
ba5807ebff88 Make it possible to quit when entering username/passwd.
Matti Hamalainen <ccr@tnsp.org>
parents: 521
diff changeset
1684 if (editState.exitProg)
ba5807ebff88 Make it possible to quit when entering username/passwd.
Matti Hamalainen <ccr@tnsp.org>
parents: 521
diff changeset
1685 goto err_exit;
513
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1686
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1687 editState.mask = TRUE;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1688 printMsg(NULL, "Enter your NN password ...\n");
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1689 optPassword = nnwin_prompt_requester(TRUE, &editState, processUserPrompt, updateUserPrompt);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1690 editState.mask = FALSE;
526
ba5807ebff88 Make it possible to quit when entering username/passwd.
Matti Hamalainen <ccr@tnsp.org>
parents: 521
diff changeset
1691 if (editState.exitProg)
ba5807ebff88 Make it possible to quit when entering username/passwd.
Matti Hamalainen <ccr@tnsp.org>
parents: 521
diff changeset
1692 goto err_exit;
513
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
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 }
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1695
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1696 if (optUserName == NULL || optPassword == NULL)
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1697 {
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
1698 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
1699 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
1700 }
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
1701
419
d015ecbd231d Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents: 418
diff changeset
1702 // Create a connection
354
c01e42fc9adb More work on SOCKS proxy support, should work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 353
diff changeset
1703 conn = nn_conn_new(errorFunc, messageFunc);
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1704 if (conn == NULL)
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1705 {
354
c01e42fc9adb More work on SOCKS proxy support, should work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 353
diff changeset
1706 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
1707 goto err_exit;
c01e42fc9adb More work on SOCKS proxy support, should work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 353
diff changeset
1708 }
513
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1709
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1710 editState.conn = conn;
354
c01e42fc9adb More work on SOCKS proxy support, should work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 353
diff changeset
1711
419
d015ecbd231d Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents: 418
diff changeset
1712 // Are we using a proxy?
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1713 if (optProxyType != NN_PROXY_NONE && optProxyServer != NULL)
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1714 {
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1715 if (nn_conn_set_proxy(conn, optProxyType, optProxyPort, optProxyServer) != 0)
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1716 {
354
c01e42fc9adb More work on SOCKS proxy support, should work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 353
diff changeset
1717 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
1718 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
1719 }
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
1720 }
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1721
456
bb65460c7aa2 Clean up some initialization messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 451
diff changeset
1722 // Okay, try to resolve the hostname
354
c01e42fc9adb More work on SOCKS proxy support, should work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 353
diff changeset
1723 conn->host = th_strdup(optServer);
c01e42fc9adb More work on SOCKS proxy support, should work now.
Matti Hamalainen <ccr@tnsp.org>
parents: 353
diff changeset
1724 conn->hst = nn_resolve_host(conn, optServer);
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1725 if (conn->hst == NULL)
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
1726 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
1727
329
c0988ab45afd #ifdef out the policy probe.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
1728 #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
1729 /* 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
1730 * 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
1731 */
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1732 if (nn_conn_open(conn, 843, NULL) != 0)
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1733 {
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
1734 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
1735 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
1736 }
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
1737
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
1738 tmpStr = "<policy-file-request/>";
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1739 if (nn_conn_send_buf(conn, tmpStr, strlen(tmpStr) + 1) == FALSE)
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1740 {
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
1741 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
1742 goto err_exit;
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1743 }
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1744 else
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1745 {
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
1746 int cres = nn_conn_pull(conn);
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1747 if (cres == 0)
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1748 {
288
e7ef3db3b954 Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
1749 printMsg(currWin, "Probe got: %s\n", conn->buf);
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1750 }
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1751 else
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1752 {
288
e7ef3db3b954 Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
1753 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
1754 }
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
1755 }
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
1756 nn_conn_close(conn);
329
c0988ab45afd #ifdef out the policy probe.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
1757 #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
1758
419
d015ecbd231d Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents: 418
diff changeset
1759 // Okay, now do the proper connection ...
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1760 if (nn_conn_open(conn, optPort, NULL) != 0)
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1761 {
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
1762 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
1763 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
1764 }
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1765
419
d015ecbd231d Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents: 418
diff changeset
1766 // 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
1767 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
1768 tmpStr = nn_dblencode_str(optSite);
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1769 nn_conn_send_msg_v(conn, optUserNameEnc, "%%2Flogin%%20%%2Dsite%%20%s%%20%%2Dpassword%%20%s", tmpStr, optPassword);
268
d04ea4395e9e Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents: 267
diff changeset
1770 th_free(tmpStr);
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1771
450
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1772 // Initialize user commands
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1773 nn_usercmd_init();
a8373a1ce1eb Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents: 449
diff changeset
1774
419
d015ecbd231d Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents: 418
diff changeset
1775 // Initialize random numbers
513
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1776 editState.prevKeepAlive = time(NULL);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1777 srandom((int) editState.prevKeepAlive);
100
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
1778
419
d015ecbd231d Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents: 418
diff changeset
1779 // Enter mainloop
360
b465a17ffa47 Finally fix handling of long packets.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
1780 nn_conn_reset(conn);
513
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1781 while (!editState.isError && !editState.exitProg)
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1782 {
445
7e46f2f0ba34 Cleanup packet retrying a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 444
diff changeset
1783 int retries = 3, cres;
7e46f2f0ba34 Cleanup packet retrying a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 444
diff changeset
1784
7e46f2f0ba34 Cleanup packet retrying a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 444
diff changeset
1785 packet_retry:
7e46f2f0ba34 Cleanup packet retrying a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 444
diff changeset
1786 cres = nn_conn_pull(conn);
439
70ea06294f3f Possibly fix packet handling after the whole mess of refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 437
diff changeset
1787 if (cres == 0)
70ea06294f3f Possibly fix packet handling after the whole mess of refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 437
diff changeset
1788 {
70ea06294f3f Possibly fix packet handling after the whole mess of refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 437
diff changeset
1789 while (conn->ptr < conn->in_ptr &&
70ea06294f3f Possibly fix packet handling after the whole mess of refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 437
diff changeset
1790 *(conn->in_ptr - 1) == 0 &&
513
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1791 retries > 0 && !editState.isError)
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1792 {
439
70ea06294f3f Possibly fix packet handling after the whole mess of refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 437
diff changeset
1793 // nn_conn_dump_buffer(stderr, conn);
403
7bec02f382fb Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
1794 int result = nn_parse_protocol(conn);
436
Matti Hamalainen <ccr@tnsp.org>
parents: 435
diff changeset
1795 if (result == 0)
Matti Hamalainen <ccr@tnsp.org>
parents: 435
diff changeset
1796 {
Matti Hamalainen <ccr@tnsp.org>
parents: 435
diff changeset
1797 nn_conn_buf_skip(conn, 1);
Matti Hamalainen <ccr@tnsp.org>
parents: 435
diff changeset
1798 }
Matti Hamalainen <ccr@tnsp.org>
parents: 435
diff changeset
1799 else
385
bbd5edbf1143 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 381
diff changeset
1800 if (result > 0)
bbd5edbf1143 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 381
diff changeset
1801 {
445
7e46f2f0ba34 Cleanup packet retrying a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 444
diff changeset
1802 // Retry if possible
439
70ea06294f3f Possibly fix packet handling after the whole mess of refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 437
diff changeset
1803 if (--retries > 0)
445
7e46f2f0ba34 Cleanup packet retrying a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 444
diff changeset
1804 goto packet_retry;
7e46f2f0ba34 Cleanup packet retrying a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 444
diff changeset
1805
7e46f2f0ba34 Cleanup packet retrying a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 444
diff changeset
1806 // Couldn't handle the message for some reason
7e46f2f0ba34 Cleanup packet retrying a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 444
diff changeset
1807 printMsg(currWin, "Could not handle: %s\n", conn->ptr);
7e46f2f0ba34 Cleanup packet retrying a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 444
diff changeset
1808 nn_conn_buf_skip(conn, strlen(conn->ptr) + 1);
385
bbd5edbf1143 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 381
diff changeset
1809 }
436
Matti Hamalainen <ccr@tnsp.org>
parents: 435
diff changeset
1810 else
513
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1811 editState.isError = TRUE;
403
7bec02f382fb Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
1812 }
7bec02f382fb Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 402
diff changeset
1813 }
439
70ea06294f3f Possibly fix packet handling after the whole mess of refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 437
diff changeset
1814 else
70ea06294f3f Possibly fix packet handling after the whole mess of refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 437
diff changeset
1815 if (cres < 0 || !nn_conn_check(conn))
513
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1816 editState.isError = TRUE;
168
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1817
419
d015ecbd231d Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents: 418
diff changeset
1818 // Handle user input
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1819 if (cursesInit)
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1820 {
513
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1821 nnwin_input_process(editBuf, &editState, processUserInput);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1822 nnwin_update(editState.update, editState.mask, editBuf, optUserName, optUserColor);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1823 }
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1824
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1825 if (++updateCount > 10)
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1826 {
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1827 time_t tmpTime = time(NULL);
513
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1828 if (tmpTime - editState.prevKeepAlive > SET_KEEPALIVE)
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1829 {
435
708a15fdf791 Fix a type / conversion related warning.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1830 size_t n = ((size_t) random()) % th_llist_length(setIdleMessages);
264
4c1c18a388d9 Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents: 258
diff changeset
1831 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
1832 nn_conn_send_msg(conn, optUserNameEnc, node->data);
513
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1833 editState.prevKeepAlive = tmpTime;
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1834 }
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1835
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1836 if (!colorSet)
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1837 {
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1838 colorSet = TRUE;
424
aeb24b1b5e77 Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1839 nn_conn_send_msg_v(conn, optUserNameEnc, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor);
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1840 }
513
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1841
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1842 if (cursesInit)
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1843 {
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1844 nnwin_update(FALSE, editState.mask, editBuf, optUserName, optUserColor);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1845 }
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1846
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1847 updateCount = 0;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1848 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1849 }
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1850
419
d015ecbd231d Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents: 418
diff changeset
1851 // 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
1852 err_exit:
521
a9a81db93c74 Fix win32 build again.
Matti Hamalainen <ccr@tnsp.org>
parents: 520
diff changeset
1853 #ifdef __WIN32
a9a81db93c74 Fix win32 build again.
Matti Hamalainen <ccr@tnsp.org>
parents: 520
diff changeset
1854 if (errorMessages)
a9a81db93c74 Fix win32 build again.
Matti Hamalainen <ccr@tnsp.org>
parents: 520
diff changeset
1855 {
a9a81db93c74 Fix win32 build again.
Matti Hamalainen <ccr@tnsp.org>
parents: 520
diff changeset
1856 char *tmp;
a9a81db93c74 Fix win32 build again.
Matti Hamalainen <ccr@tnsp.org>
parents: 520
diff changeset
1857 printMsg(NULL, "Press enter to exit.\n");
a9a81db93c74 Fix win32 build again.
Matti Hamalainen <ccr@tnsp.org>
parents: 520
diff changeset
1858 memset(&editState, 0, sizeof(editState));
a9a81db93c74 Fix win32 build again.
Matti Hamalainen <ccr@tnsp.org>
parents: 520
diff changeset
1859 tmp = nnwin_prompt_requester(FALSE, &editState, processUserPrompt, updateUserPrompt);
a9a81db93c74 Fix win32 build again.
Matti Hamalainen <ccr@tnsp.org>
parents: 520
diff changeset
1860 th_free(tmp);
a9a81db93c74 Fix win32 build again.
Matti Hamalainen <ccr@tnsp.org>
parents: 520
diff changeset
1861 }
a9a81db93c74 Fix win32 build again.
Matti Hamalainen <ccr@tnsp.org>
parents: 520
diff changeset
1862 #endif
a9a81db93c74 Fix win32 build again.
Matti Hamalainen <ccr@tnsp.org>
parents: 520
diff changeset
1863
316
1065115665bd Plug some more minor memory leaks.
Matti Hamalainen <ccr@tnsp.org>
parents: 315
diff changeset
1864 th_cfg_free(cfg);
432
966c521e0954 Rename user home directory variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 431
diff changeset
1865 th_free(setHomeDir);
316
1065115665bd Plug some more minor memory leaks.
Matti Hamalainen <ccr@tnsp.org>
parents: 315
diff changeset
1866 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
1867 nn_userhash_free(nnUsers);
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1868 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
1869
466
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents: 464
diff changeset
1870 for (index = 0; index <= SET_MAX_HISTORY; index++)
513
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
1871 nn_editbuf_free(editHistBuf[index]);
288
e7ef3db3b954 Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
1872
489
ba48840b8525 Move network initialization/shutdown flag checking to network module.
Matti Hamalainen <ccr@tnsp.org>
parents: 486
diff changeset
1873 nnwin_shutdown();
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1874
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
1875 #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
1876 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
1877 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
1878 #endif
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1879
198
21a37995c3fb Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents: 197
diff changeset
1880 th_free(optUserNameEnc);
168
2e4850ece456 Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 165
diff changeset
1881 nn_conn_close(conn);
489
ba48840b8525 Move network initialization/shutdown flag checking to network module.
Matti Hamalainen <ccr@tnsp.org>
parents: 486
diff changeset
1882 nn_network_close();
68
3ab7751fdad1 MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
1883
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1884 THMSG(1, "Connection terminated.\n");
391
a2b7ac328e62 Code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 389
diff changeset
1885
511
291e3caa91a0 Move logParseFilename() to nn_log_parse_filename() under util.c and rename logFileOpen() and logFileClose().
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
1886 nn_log_file_close();
133
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
1887
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1888 return 0;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1889 }