annotate nnchat.c @ 154:e8f67e344aaf

Get correct directory for saving configuration under Windows.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 03 Nov 2010 00:03:20 +0200
parents f1684884fd56
children 0720ca51673e
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
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
4 * (C) Copyright 2008-2010 Tecnic Software productions (TNSP)
39
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
5 */
62
ff5d74f0d428 Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
6 #include "libnnchat.h"
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 #include <stdlib.h>
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #include "th_args.h"
133
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
9 #include "th_config.h"
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 #include <string.h>
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 #include <errno.h>
64
6a3a917303e4 Some random cleanups, bring back WinSock support.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
12 #ifdef __WIN32
68
3ab7751fdad1 MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
13 /* Undefine because both windows.h and curses.h #define it */
3ab7751fdad1 MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
14 #undef MOUSE_MOVED
154
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
15 #include <shlwapi.h>
128
713879a7ca10 Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
16 #else
713879a7ca10 Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
17 #include <sys/wait.h>
68
3ab7751fdad1 MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
18 #endif
64
6a3a917303e4 Some random cleanups, bring back WinSock support.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
19 #include <curses.h>
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20
139
c39399725f7b Define some platform-specific constants.
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
21 #ifdef __WIN32
c39399725f7b Define some platform-specific constants.
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
22 #define SET_CONFIG_FILE "nnchat-config.txt"
c39399725f7b Define some platform-specific constants.
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
23 #define SET_DIR_SEPARATOR "\\"
c39399725f7b Define some platform-specific constants.
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
24 #else
c39399725f7b Define some platform-specific constants.
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
25 #define SET_CONFIG_FILE ".nnchat"
c39399725f7b Define some platform-specific constants.
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
26 #define SET_DIR_SEPARATOR "/"
c39399725f7b Define some platform-specific constants.
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
27 #endif
49
0bcc38910a77 Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
28
141
cce05daf6f01 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
29 #define SET_MIN_BACKBUF (1024) /* Backbuffer size (in lines) */
cce05daf6f01 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
30 #define SET_MAX_HISTORY (16) /* Command history length */
28
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
31 #define SET_DELAY (15)
120
804c7db454b4 Adjust delay.
Matti Hamalainen <ccr@tnsp.org>
parents: 119
diff changeset
32 #define SET_DELAY_USEC (SET_DELAY * 250)
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
33 #define SET_KEEPALIVE (15*60) /* Ping/keepalive period in seconds */
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34
49
0bcc38910a77 Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
35
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 /* Options
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 */
104
06e6ac51e3f2 Change default port to 8003.
Matti Hamalainen <ccr@tnsp.org>
parents: 103
diff changeset
38 int optPort = 8003;
39
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
39 int optUserColor = 0x006080;
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",
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
41 *optUserName = NULL,
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
42 *optUserName2 = NULL,
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
43 *optPassword = NULL,
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
44 *optLogFilename = NULL,
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
45 *setTarget = NULL,
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
46 *optSite = "NN";
116
741e45592522 Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
47 char optNickSep = ':';
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
48 BOOL optDaemon = FALSE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
49 FILE *optLogFile = NULL;
28
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
50 WINDOW *mainWin = NULL,
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
51 *statusWin = NULL,
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
52 *editWin = NULL;
59
d57a8acf92bf Remove morse code mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 58
diff changeset
53 BOOL setPrvMode = FALSE;
149
a4d6707161a7 Add config file option for default setting of ignore mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
54 BOOL setIgnoreMode = FALSE;
33
e49ea6febfeb Cleanups. Added option to specify/fake "site" where logging in from.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
55
140
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
56
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
57 qlist_t *nnIgnoreList = NULL;
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
58 nn_userhash_t *nnUsers = NULL;
137
fad8c31e41e6 Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
59 char *setConfigFile = NULL,
fad8c31e41e6 Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
60 *setBrowser = NULL;
133
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
61 cfgitem_t *cfg = NULL;
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
62
89
c2d916b340bf Change some typedef names; Add struct for user list handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
63
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 /* Arguments
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 */
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 optarg_t optList[] = {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
67 { 0, '?', "help", "Show this help", OPT_NONE },
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
68 { 1, 'v', "verbose", "Be more verbose", OPT_NONE },
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
69 { 2, 'p', "port", "Connect to port", OPT_ARGREQ },
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
70 { 3, 's', "server", "Server to connect to", OPT_ARGREQ },
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
71 { 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
72 { 5, 'l', "logfile", "Log filename", OPT_ARGREQ },
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
73 { 6, 'D', "daemon", "A pseudo-daemon mode for logging", OPT_NONE },
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
74 { 7, 'S', "site", "Site (default: NN)", OPT_ARGREQ },
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 };
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76
43
40ba8cdcf03a Cleanups, added a silly morse code conversion mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
77 const int optListN = (sizeof(optList) / sizeof(optList[0]));
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79
68
3ab7751fdad1 MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
80 void argShowHelp()
3ab7751fdad1 MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
81 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
82 th_args_help(stdout, optList, optListN, th_prog_name,
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
83 "[options] <username> <password>");
68
3ab7751fdad1 MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
84 }
3ab7751fdad1 MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
85
3ab7751fdad1 MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
86
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 BOOL argHandleOpt(const int optN, char *optArg, char *currArg)
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
89 switch (optN) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
90 case 0:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
91 argShowHelp();
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
92 exit(0);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
93 break;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
95 case 1:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
96 th_verbosityLevel++;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
97 break;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
98
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
99 case 2:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
100 optPort = atoi(optArg);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
101 break;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
103 case 3:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
104 optServer = optArg;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
105 break;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
106
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
107 case 4:
132
10daf4660cae Use th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents: 130
diff changeset
108 if ((optUserColor = th_get_hex_triplet(optArg)) < 0) {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
109 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
110 optArg);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
111 return FALSE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
112 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
113 THMSG(1, "Using color #%06x\n", optUserColor);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
114 break;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
116 case 5:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
117 optLogFilename = optArg;
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 7:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
121 optSite = optArg;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
122 break;
33
e49ea6febfeb Cleanups. Added option to specify/fake "site" where logging in from.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
123
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
124 case 6:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
125 optDaemon = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
126 THMSG(1, "Running in pseudo-daemon mode.\n");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
127 break;
21
29098addfa65 Added a "daemon" mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
128
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
129 default:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
130 THERR("Unknown option '%s'.\n", currArg);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
131 return FALSE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
132 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
133
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
134 return TRUE;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 BOOL argHandleFile(char *currArg)
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
140 if (!optUserName)
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
141 optUserName = currArg;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
142 else if (!optPassword)
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
143 optPassword = currArg;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
144 else {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
145 THERR("Username '%s' already specified on commandline!\n", optUserName);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
146 return FALSE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
147 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
148
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
149 return TRUE;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151
49
0bcc38910a77 Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
152
30
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
153 void updateStatus(BOOL insertMode)
28
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
154 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
155 char tmpStr[128] = "";
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
156 time_t timeStamp;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
157 struct tm *tmpTime;;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
158
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
159 if (statusWin == NULL) return;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
160
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
161 timeStamp = time(NULL);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
162 if ((tmpTime = localtime(&timeStamp)) != NULL) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
163 strftime(tmpStr, sizeof(tmpStr), "%H:%M:%S", tmpTime);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
164 }
110
8af4072dc31a Fix Win32/MinGW/PDcurses issues.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
165
119
4bc63a535acb Fix some PDCurses incompatibilities and remove some Win32/PDCurses specific hacks.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
166 wbkgdset(statusWin, COLOR_PAIR(10));
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
167 werase(statusWin);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
168
119
4bc63a535acb Fix some PDCurses incompatibilities and remove some Win32/PDCurses specific hacks.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
169 wattrset(statusWin, A_BOLD | COLOR_PAIR(11));
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
170 mvwaddstr(statusWin, 0, 1, tmpStr);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
171
119
4bc63a535acb Fix some PDCurses incompatibilities and remove some Win32/PDCurses specific hacks.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
172 wattrset(statusWin, A_BOLD | COLOR_PAIR(13));
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
173 waddstr(statusWin, " | ");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
174 wattrset(statusWin, A_BOLD | COLOR_PAIR(16));
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
175 waddstr(statusWin, optUserName);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
176 wattrset(statusWin, A_BOLD | COLOR_PAIR(13));
29
a27ef0e359b9 Make statusline more informative.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
177
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
178 waddstr(statusWin, " | ");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
179 wattrset(statusWin, A_BOLD | COLOR_PAIR(11));
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
180 waddstr(statusWin, insertMode ? "INS" : "DEL");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
181
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
182 wattrset(statusWin, A_BOLD | COLOR_PAIR(13));
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
183 waddstr(statusWin, " | Prv: ");
28
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
184
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
185 wattrset(statusWin, A_BOLD | COLOR_PAIR(11));
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
186 waddstr(statusWin, setTarget != NULL ? setTarget : "-");
29
a27ef0e359b9 Make statusline more informative.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
187
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
188 wattrset(statusWin, A_BOLD | COLOR_PAIR(13));
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
189 waddstr(statusWin, " | P/C: ");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
190 wattrset(statusWin, A_BOLD | COLOR_PAIR(11));
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
191 snprintf(tmpStr, sizeof(tmpStr), "%d / #%06x", optPort, optUserColor);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
192 waddstr(statusWin, tmpStr);
29
a27ef0e359b9 Make statusline more informative.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
193
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
194 wrefresh(statusWin);
28
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
195 }
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
196
89
c2d916b340bf Change some typedef names; Add struct for user list handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
197 void printEditBuf(char *str, nn_editbuf_t *buf)
28
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
198 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
199 if (statusWin == NULL || buf == NULL) return;
32
67ec4073e38c Check for NULL pointers (fixes "daemon" mode)
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
200
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
201 buf->data[buf->len] = 0;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
202 werase(editWin);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
203
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
204 wattrset(editWin, A_BOLD);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
205 mvwaddstr(editWin, 0, 0, str);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
206 waddstr(editWin, "> ");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
207 wattrset(editWin, A_NORMAL);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
208
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
209 if (buf->pos < buf->len) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
210 waddnstr(editWin, buf->data, buf->pos);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
211 wattrset(editWin, A_REVERSE);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
212 waddch(editWin, buf->data[buf->pos]);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
213 wattrset(editWin, A_NORMAL);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
214 waddnstr(editWin, buf->data + buf->pos + 1, buf->len - buf->pos - 1);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
215 } else {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
216 waddnstr(editWin, buf->data, buf->len);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
217 wattrset(editWin, A_REVERSE);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
218 waddch(editWin, ' ');
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
219 wattrset(editWin, A_NORMAL);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
220 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
221 wrefresh(editWin);
28
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
222 }
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
223
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
224 int printWin(WINDOW *win, const char *fmt)
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
225 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
226 const char *s = fmt;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
227 int col = 0;
141
cce05daf6f01 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
228
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
229 while (*s) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
230 if (*s == '½') {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
231 int val = 0;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
232 s++;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
233 if (*s == '½') {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
234 waddch(win, ((unsigned char) *s) | col);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
235 s++;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
236 } else {
110
8af4072dc31a Fix Win32/MinGW/PDcurses issues.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
237 while (*s >= '0' && *s <= '9') {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
238 val *= 10;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
239 val += (*s - '0');
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
240 s++;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
241 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
242 if (*s != '½') return -1;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
243 s++;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
244
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
245 if (val < 9) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
246 col = A_DIM | COLOR_PAIR(val);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
247 } else if (val < 30) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
248 col = A_BOLD | COLOR_PAIR(val - 9);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
249 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
250 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
251 } else {
110
8af4072dc31a Fix Win32/MinGW/PDcurses issues.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
252 if (*s != '\r')
121
dad765129133 Remove #ifdef __WIN32 around non-win32 specific code.
Matti Hamalainen <ccr@tnsp.org>
parents: 120
diff changeset
253 waddch(win, ((unsigned char) *s) | col);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
254 s++;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
255 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
256 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
257 return 0;
28
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
258 }
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
259
62
ff5d74f0d428 Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
260
28
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
261 int printFile(FILE *outFile, const char *fmt)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
262 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
263 const char *s = fmt;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
264
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
265 while (*s) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
266 if (*s == '½') {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
267 s++;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
268 if (*s == '½') {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
269 fputc((unsigned char) *s, outFile);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
270 s++;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
271 } else {
74
98004129202a Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
272 while (*s && isdigit((int) *s)) s++;
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
273 if (*s != '½') return -1;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
274 s++;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
275 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
276 } else {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
277 fputc((unsigned char) *s, outFile);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
278 s++;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
279 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
280 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
281
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
282 return 0;
28
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
283 }
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
284
62
ff5d74f0d428 Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents: 61
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 void printMsgV(BOOL addStamp, BOOL logOnly, const char *fmt, va_list ap)
28
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
287 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
288 char tmpStr[128] = "", buf[8192];
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
289 time_t timeStamp;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
290 struct tm *tmpTime;;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
291
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
292 timeStamp = time(NULL);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
293 if ((tmpTime = localtime(&timeStamp)) != NULL) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
294 strftime(tmpStr, sizeof(tmpStr), "½17½[½11½%H:%M:%S½17½]½0½ ", tmpTime);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
295 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
296
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
297 vsnprintf(buf, sizeof(buf), fmt, ap);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
298
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
299 if (optLogFile) {
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
300 if (addStamp) printFile(optLogFile, tmpStr);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
301 printFile(optLogFile, buf);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
302 fflush(optLogFile);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
303 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
304
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
305 if (!optDaemon && !logOnly) {
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
306 if (addStamp) printWin(mainWin, tmpStr);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
307 printWin(mainWin, buf);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
308 wrefresh(mainWin);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
309 }
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
310 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
311
100
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
312 void printMsg(const char *fmt, ...)
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
313 {
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
314 va_list ap;
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
315
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
316 va_start(ap, fmt);
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
317 printMsgV(TRUE, FALSE, fmt, ap);
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
318 va_end(ap);
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
319 }
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
320
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
321 void printMsgC(const char *fmt, ...)
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
322 {
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
323 va_list ap;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
324
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
325 va_start(ap, fmt);
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
326 printMsgV(FALSE, FALSE, fmt, ap);
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
327 va_end(ap);
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
328 }
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
329
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
330 void printMsgQ(BOOL logOnly, const char *fmt, ...)
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
331 {
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
332 va_list ap;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
333
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
334 va_start(ap, fmt);
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
335 printMsgV(TRUE, logOnly, fmt, ap);
100
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
336 va_end(ap);
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
337 }
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
338
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
339
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
340 void errorMsg(char *fmt, ...)
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
341 {
100
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
342 va_list ap1, ap2;
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
343
100
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
344 va_start(ap1, fmt);
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
345 va_copy(ap2, ap1);
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
346 printMsgV(TRUE, FALSE, fmt, ap1);
100
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
347 va_end(ap1);
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
348
100
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
349 THERR_V(fmt, ap2);
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
350 va_end(ap2);
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
351 }
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
352
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
353
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
354 int handleUser(int sock, const char *str)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
355 {
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
356 const char *msg = "</USER><MESSAGE>", *p = str;
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
357 char *q, *s, *t, *h, *p2;
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
358
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
359 (void) sock;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
360
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
361 s = strstr(str, msg);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
362 if (!s) return 1;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
363 *s = 0;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
364 s += strlen(msg);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
365
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
366 q = strstr(s, "</MESSAGE>");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
367 if (!q) return 3;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
368 *q = 0;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
369
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
370 s = nn_decode_str1(s);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
371 if (!s) return -1;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
372
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
373 p2 = nn_decode_str1(p);
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
374 if (!p2) {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
375 th_free(s);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
376 return -2;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
377 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
378
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
379
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
380 if (*s == '/') {
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
381 /* Ignore room join/leave messages */
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
382 if (strstr(s, "left the room") || strstr(s, "joined the room from"))
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
383 goto error;
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
384
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
385 t = nn_strip_tags(s + 1);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
386 if (!strncmp(t, "BPRV", 4)) {
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
387 h = nn_decode_str2(t + 1);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
388 printMsg("½11½%s½0½\n", h);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
389 } else {
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
390 h = nn_decode_str2(t);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
391 printMsg("½9½* %s½0½\n", h);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
392 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
393 th_free(h);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
394 th_free(t);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
395 } else {
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
396 BOOL isMine = strcmp(p2, optUserName) == 0;
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
397 BOOL logOnly = FALSE;
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
398 t = nn_strip_tags(s);
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
399 h = nn_decode_str2(t);
149
a4d6707161a7 Add config file option for default setting of ignore mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
400 if (setIgnoreMode) {
140
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
401 qlist_t *node = nnIgnoreList;
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
402 while (node != NULL) {
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
403 if (strcasecmp(p2, (char *) node->data) == 0) {
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
404 logOnly = TRUE;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
405 break;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
406 }
140
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
407 node = node->next;
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
408 }
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
409 }
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
410 printMsgQ(logOnly, "½5½<½%d½%s½5½>½0½ %s\n", isMine ? 14 : 15, p2, h);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
411 th_free(h);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
412 th_free(t);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
413 }
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
414
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
415 error:
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
416 th_free(s);
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
417 th_free(p2);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
418 return 0;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
419 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
420
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
421
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
422 int handleLogin(int sock, const char *str)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
423 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
424 char tmpStr[256] = "";
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
425 time_t timeStamp;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
426 struct tm *tmpTime;;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
427
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
428 timeStamp = time(NULL);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
429 if ((tmpTime = localtime(&timeStamp)) != NULL) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
430 strftime(tmpStr, sizeof(tmpStr), "%c", tmpTime);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
431 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
432
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
433 if (!strncmp(str, "FAILURE", 7)) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
434 printMsg("½1½Login failure½0½ - ½3½%s½0½\n", tmpStr);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
435 return -2;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
436 } else if (!strncmp(str, "SUCCESS", 7)) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
437 printMsg("½2½Login success½0½ - ½3½%s½0½\n", tmpStr);
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
438 nn_send_msg(sock, optUserName2, "%%2FRequestUserList");
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
439 return 0;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
440 } else
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
441 return 1;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
442 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
443
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
444
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
445 int handleAddUser(int sock, const char *str)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
446 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
447 char *p, *s = strstr(str, "</ADD_USER>");
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
448
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
449 (void) sock;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
450
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
451 if (!s) return 1;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
452 *s = 0;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
453
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
454 p = nn_dbldecode_str(str);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
455 if (!p) return -1;
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
456
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
457 nn_userhash_insert(nnUsers, p);
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
458
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
459 printMsg("! ½3½%s½0½ ½2½ADDED.½0½\n", p);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
460 th_free(p);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
461 return 0;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
462 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
463
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
464
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
465 int handleDeleteUser(int sock, const char *str)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
466 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
467 char *p, *s = strstr(str, "</DELETE_USER>");
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
468
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
469 (void) sock;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
470
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
471 if (!s) return 1;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
472 *s = 0;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
473
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
474 p = nn_dbldecode_str(str);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
475 if (!p) return -1;
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
476
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
477 nn_userhash_delete(nnUsers, p);
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
478
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
479 printMsg("! ½3½%s½0½ ½1½DELETED.½0½\n", p);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
480 th_free(p);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
481 return 0;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
482 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
483
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
484
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
485 int handleFoo(int sock, const char *str)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
486 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
487 (void) sock; (void) str;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
488
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
489 return 0;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
490 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
491
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
492
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
493 int handleBoot(int sock, const char *str)
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
494 {
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
495 (void) sock; (void) str;
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
496 errorMsg("Booted by server.\n");
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
497 return -1;
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
498 }
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
499
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
500
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
501 typedef struct {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
502 char *cmd;
129
4235ff4ced04 "Optimize" protocol handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 128
diff changeset
503 ssize_t len;
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
504 int (*handler)(int, const char *);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
505 } protocmd_t;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
506
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
507
129
4235ff4ced04 "Optimize" protocol handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 128
diff changeset
508 static protocmd_t protoCmds[] = {
4235ff4ced04 "Optimize" protocol handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 128
diff changeset
509 { "<USER>", -1, handleUser },
4235ff4ced04 "Optimize" protocol handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 128
diff changeset
510 { "<LOGIN_", -1, handleLogin },
4235ff4ced04 "Optimize" protocol handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 128
diff changeset
511 { "<DELETE_USER>", -1, handleDeleteUser },
4235ff4ced04 "Optimize" protocol handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 128
diff changeset
512 { "<ADD_USER>", -1, handleAddUser },
4235ff4ced04 "Optimize" protocol handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 128
diff changeset
513 { "<NUMCLIENTS>", -1, handleFoo },
4235ff4ced04 "Optimize" protocol handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 128
diff changeset
514 { "<BOOT />", -1, handleBoot },
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
515 };
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
516
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
517 static const int nprotoCmds = sizeof(protoCmds) / sizeof(protoCmds[0]);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
518
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
519
129
4235ff4ced04 "Optimize" protocol handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 128
diff changeset
520 int handleProtocol(const int sock, const char *buf, const ssize_t bufLen)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
521 {
130
352ec3c300e4 A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
522 static BOOL protoCmdsInit = FALSE;
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
523 int i;
130
352ec3c300e4 A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
524
352ec3c300e4 A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
525 if (!protoCmdsInit) {
352ec3c300e4 A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
526 for (i = 0; i < nprotoCmds; i++)
352ec3c300e4 A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
527 protoCmds[i].len = strlen(protoCmds[i].cmd);
352ec3c300e4 A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
528 protoCmdsInit = TRUE;
352ec3c300e4 A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
529 }
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
530
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
531 for (i = 0; i < nprotoCmds; i++) {
129
4235ff4ced04 "Optimize" protocol handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 128
diff changeset
532 ssize_t cmdLen = protoCmds[i].len;
4235ff4ced04 "Optimize" protocol handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 128
diff changeset
533 if (cmdLen < bufLen && !strncmp(buf, protoCmds[i].cmd, cmdLen))
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
534 return protoCmds[i].handler(sock, buf + cmdLen);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
535 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
536
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
537 return 1;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
538 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
539
125
d03ebefb92a6 Improve internal command handling, use fork() and execlp() instead of system() for opening profiles into external browser's tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
540 char * trimLeft(char *buf)
d03ebefb92a6 Improve internal command handling, use fork() and execlp() instead of system() for opening profiles into external browser's tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
541 {
d03ebefb92a6 Improve internal command handling, use fork() and execlp() instead of system() for opening profiles into external browser's tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
542 while (*buf != 0 && isspace(*buf)) buf++;
d03ebefb92a6 Improve internal command handling, use fork() and execlp() instead of system() for opening profiles into external browser's tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
543 return buf;
d03ebefb92a6 Improve internal command handling, use fork() and execlp() instead of system() for opening profiles into external browser's tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
544 }
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
545
140
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
546 int compareUsername(const void *s1, const void *s2)
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
547 {
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
548 return strcasecmp((char *) s1, (char *) s2);
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
549 }
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
550
51
cf7789d88350 Fix the input packet handling to properly handle packets with multiple
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
551 int handleUserInput(const int sock, char *buf, size_t bufLen)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
552 {
78
745f670068dc Add functions to simplify code.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
553 char *tmpStr, tmpBuf[4096];
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
554 BOOL result;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
555
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
556 /* Trim right */
112
c4865ac2386c Fix right-side trimming of command line.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
557 bufLen--;
c4865ac2386c Fix right-side trimming of command line.
Matti Hamalainen <ccr@tnsp.org>
parents: 111
diff changeset
558 buf[bufLen--] = 0;
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
559 while (bufLen > 0 && (buf[bufLen] == '\n' || buf[bufLen] == '\r' || th_isspace(buf[bufLen])))
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
560 buf[bufLen--] = 0;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
561
109
1323a7f88c21 Fix /w -command and add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
562 /* Check for special user commands */
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
563 if (*buf == 0) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
564 return 1;
111
9db08807018f Make local commands case-insensitive.
Matti Hamalainen <ccr@tnsp.org>
parents: 110
diff changeset
565 } else if (!strncasecmp(buf, "/color ", 7)) {
109
1323a7f88c21 Fix /w -command and add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
566 /* Change color */
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
567 int tmpInt;
132
10daf4660cae Use th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents: 130
diff changeset
568 if ((tmpInt = th_get_hex_triplet(trimLeft(buf + 7))) < 0) {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
569 printMsg("Invalid color value '%s'\n", buf+7);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
570 return 1;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
571 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
572 optUserColor = tmpInt;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
573 printMsg("Setting color to #%06x\n", optUserColor);
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
574 nn_send_msg(sock, optUserName2, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
575 return 0;
140
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
576 } else if (!strncasecmp(buf, "/ignore", 7)) {
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
577 char *name = trimLeft(buf + 7);
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
578 if (strlen(name) > 0) {
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
579 /* Add or remove someone to/from ignore */
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
580 qlist_t *user = th_llist_find_func(nnIgnoreList, name, compareUsername);
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
581 if (user != NULL) {
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
582 printMsg("Removed user '%s' from ignore.\n", name);
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
583 th_llist_delete_node(&nnIgnoreList, user);
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
584 } else {
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
585 printMsg("Now ignoring '%s'.\n", name);
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
586 th_llist_append(&nnIgnoreList, th_strdup(name));
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
587 }
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
588 } else {
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
589 /* Just list whomever is in ignore now */
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
590 qlist_t *user = nnIgnoreList;
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
591 ssize_t nuser = th_llist_length(nnIgnoreList);
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
592 printMsg("Users ignored (%d): ", nuser);
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
593 while (user != NULL) {
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
594 if (user->data != NULL) {
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
595 printMsgC("'%s'", (char *) user->data);
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
596 if (--nuser > 0)
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
597 printMsgC(", ");
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
598 }
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
599 user = user->next;
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
600 }
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
601 printMsgC("\n");
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
602 }
2d2ef5bbcc11 Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents: 139
diff changeset
603 return 0;
133
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
604 } else if (!strncasecmp(buf, "/save", 5)) {
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
605 /* Save configuration */
143
5babbff7ca26 Rename some variables, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
606 FILE *cfgfile = fopen(setConfigFile, "w");
5babbff7ca26 Rename some variables, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
607 if (cfgfile == NULL) {
5babbff7ca26 Rename some variables, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
608 printMsg("Could not create configuration to file '%s': %s\n", setConfigFile,
5babbff7ca26 Rename some variables, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
609 strerror(errno));
133
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
610 return 0;
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
611 }
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
612 printMsg("Configuration saved in file '%s', res=%d\n",
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
613 setConfigFile,
143
5babbff7ca26 Rename some variables, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
614 th_cfg_write(cfgfile, setConfigFile, cfg));
133
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
615
143
5babbff7ca26 Rename some variables, cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 142
diff changeset
616 fclose(cfgfile);
133
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
617 return 0;
111
9db08807018f Make local commands case-insensitive.
Matti Hamalainen <ccr@tnsp.org>
parents: 110
diff changeset
618 } else if (!strncasecmp(buf, "/w ", 3)) {
109
1323a7f88c21 Fix /w -command and add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
619 /* Open given username's profile via firefox in a new tab */
137
fad8c31e41e6 Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
620 char *name = trimLeft(buf + 3);
114
256cca8cc086 Support $BROWSER environment variable setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 113
diff changeset
621
125
d03ebefb92a6 Improve internal command handling, use fork() and execlp() instead of system() for opening profiles into external browser's tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
622 printMsg("Opening profile for: '%s'\n", name);
d03ebefb92a6 Improve internal command handling, use fork() and execlp() instead of system() for opening profiles into external browser's tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
623
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
624 tmpStr = nn_encode_str1(name);
125
d03ebefb92a6 Improve internal command handling, use fork() and execlp() instead of system() for opening profiles into external browser's tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
625 snprintf(tmpBuf, sizeof(tmpBuf), "openurl(http://www.newbienudes.com/profile/%s/,new-tab)", tmpStr);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
626 th_free(tmpStr);
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
627
128
713879a7ca10 Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
628 #ifdef __WIN32
713879a7ca10 Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
629
713879a7ca10 Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
630 #else
713879a7ca10 Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
631 {
713879a7ca10 Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
632 int status;
713879a7ca10 Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
633 pid_t pid;
125
d03ebefb92a6 Improve internal command handling, use fork() and execlp() instead of system() for opening profiles into external browser's tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
634 if ((pid = fork()) < 0) {
d03ebefb92a6 Improve internal command handling, use fork() and execlp() instead of system() for opening profiles into external browser's tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
635 printMsg("Could not create sub-process!\n");
d03ebefb92a6 Improve internal command handling, use fork() and execlp() instead of system() for opening profiles into external browser's tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
636 } else if (pid == 0) {
137
fad8c31e41e6 Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
637 execlp(setBrowser, setBrowser, "-remote", tmpBuf, NULL);
128
713879a7ca10 Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
638 _exit(errno);
125
d03ebefb92a6 Improve internal command handling, use fork() and execlp() instead of system() for opening profiles into external browser's tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
639 }
128
713879a7ca10 Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
640
713879a7ca10 Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
641 wait(&status);
713879a7ca10 Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
642 }
713879a7ca10 Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents: 125
diff changeset
643 #endif
109
1323a7f88c21 Fix /w -command and add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
644 return 0;
111
9db08807018f Make local commands case-insensitive.
Matti Hamalainen <ccr@tnsp.org>
parents: 110
diff changeset
645 } else if (!strncasecmp(buf, "/to ", 4)) {
109
1323a7f88c21 Fix /w -command and add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
646 /* Set private messaging target */
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
647 th_free(setTarget);
125
d03ebefb92a6 Improve internal command handling, use fork() and execlp() instead of system() for opening profiles into external browser's tabs.
Matti Hamalainen <ccr@tnsp.org>
parents: 123
diff changeset
648 setTarget = th_strdup(trimLeft(buf + 4));
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
649 printMsg("Set prv target to '%s'\n", setTarget);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
650 return 0;
111
9db08807018f Make local commands case-insensitive.
Matti Hamalainen <ccr@tnsp.org>
parents: 110
diff changeset
651 } else if (!strncasecmp(buf, "/who", 4)) {
109
1323a7f88c21 Fix /w -command and add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
652 /* Alias /who to /listallusers */
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
653 snprintf(tmpBuf, sizeof(tmpBuf), "/listallusers");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
654 buf = tmpBuf;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
655 } else if (setPrvMode) {
109
1323a7f88c21 Fix /w -command and add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
656 /* Private chat mode, send as PRV */
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
657 if (setTarget != NULL) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
658 snprintf(tmpBuf, sizeof(tmpBuf), "/prv -to %s -msg %s", setTarget, buf);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
659 buf = tmpBuf;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
660 } else {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
661 printMsg("No target set, exiting prv mode.\n");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
662 setPrvMode = FALSE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
663 return 1;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
664 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
665 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
666
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
667 /* Send double-encoded */
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
668 tmpStr = nn_dblencode_str(buf);
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
669 if (tmpStr == 0) return -2;
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
670 result = nn_send_msg(sock, optUserName2, "%s", tmpStr);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
671 th_free(tmpStr);
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
672
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
673 return result ? 0 : -1;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
674 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
675
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
676
46
65b1ac6a1e2e Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
677 BOOL initializeWindows(void)
65b1ac6a1e2e Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
678 {
118
9e7f52878725 Use getmaxyx() instead of LINES and COLS globals as recommended by curses programming guidelines.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
679 int w, h;
9e7f52878725 Use getmaxyx() instead of LINES and COLS globals as recommended by curses programming guidelines.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
680
9e7f52878725 Use getmaxyx() instead of LINES and COLS globals as recommended by curses programming guidelines.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
681 getmaxyx(stdscr, h, w);
9e7f52878725 Use getmaxyx() instead of LINES and COLS globals as recommended by curses programming guidelines.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
682
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
683 if (mainWin) delwin(mainWin);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
684 if (statusWin) delwin(statusWin);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
685 if (editWin) delwin(editWin);
118
9e7f52878725 Use getmaxyx() instead of LINES and COLS globals as recommended by curses programming guidelines.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
686
9e7f52878725 Use getmaxyx() instead of LINES and COLS globals as recommended by curses programming guidelines.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
687 mainWin = newwin(h - 4, w, 0, 0);
9e7f52878725 Use getmaxyx() instead of LINES and COLS globals as recommended by curses programming guidelines.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
688 statusWin = newwin(1, w, h - 4, 0);
9e7f52878725 Use getmaxyx() instead of LINES and COLS globals as recommended by curses programming guidelines.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
689 editWin = newwin(3, w, h - 3, 0);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
690
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
691 if (mainWin == NULL || statusWin == NULL || editWin == NULL) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
692 THERR("Could not create ncurses windows!\n");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
693 return FALSE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
694 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
695 scrollok(mainWin, 1);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
696
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
697 return TRUE;
46
65b1ac6a1e2e Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
698 }
65b1ac6a1e2e Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
699
113
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
700 /*
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
701 Different tab completion scenarios:
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
702
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
703 Line start
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
704 "foo<tab>" ->
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
705 * store "foo" as pattern
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
706 * find match: "Foobar"
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
707 * replace "foo" with match
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
708
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
709 "Foobar: <tab>" ->
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
710 * ": " -> cycle to next match
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
711 * "Foorulez"
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
712 * replace "Foobar: " with "Foorulez: "
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
713
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
714 Same when completing in middle of line, but " " instead of ": ".
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
715 */
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
716 BOOL performTabCompletion(nn_editbuf_t *buf)
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
717 {
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
718 static char *previous = NULL;
113
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
719 static char *pattern = NULL;
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
720 int mode = 0;
116
741e45592522 Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
721 BOOL again = FALSE;
113
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
722 char *str = buf->data;
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
723 ssize_t endPos = 0, startPos = buf->pos;
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
724
113
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
725 if (startPos > 1 && str[startPos - 1] == ' ') {
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
726 startPos -= 2;
116
741e45592522 Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
727 if (str[startPos] == optNickSep)
113
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
728 startPos--;
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
729 if (startPos <= 0 || str[startPos] == ' ')
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
730 return FALSE;
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
731 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
732 while (startPos > 0 && str[startPos - 1] != ' ') startPos--;
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
733 mode = 1;
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
734 } else
113
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
735 if (str[startPos - 1] != ' ' && (startPos == buf->len || str[startPos] == ' ')) {
116
741e45592522 Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
736 char *npattern;
741e45592522 Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
737
113
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
738 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
739 while (startPos > 0 && str[startPos - 1] != ' ') startPos--;
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
740 while (endPos < buf->len && str[endPos] != ' ') endPos++;
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
741 while (endPos > 0 && str[endPos] == ' ') endPos--;
116
741e45592522 Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
742 if (str[endPos] == optNickSep)
113
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
743 return FALSE;
116
741e45592522 Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
744
741e45592522 Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
745 /* Get pattern, check if it matches previous pattern and set 'again' flag */
741e45592522 Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
746 npattern = nn_editbuf_get_string(buf, startPos, endPos);
741e45592522 Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
747 if (pattern && npattern && strncasecmp(npattern, pattern, strlen(pattern)) == 0)
741e45592522 Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
748 again = TRUE;
741e45592522 Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
749 th_free(pattern); pattern = npattern;
741e45592522 Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
750 if (!again) {
741e45592522 Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
751 th_free(previous);
741e45592522 Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
752 previous = NULL;
741e45592522 Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
753 }
113
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
754 mode = 2;
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
755 }
116
741e45592522 Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
756
741e45592522 Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
757 // printMsg("%d, %d <-> %d : '%s' (%d, %d)\n", startPos, endPos, buf->len, pattern, mode, again);
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
758
113
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
759 if (pattern) {
116
741e45592522 Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
760 nn_user_t *user = nn_user_match(nnUsers, pattern, previous, again);
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
761
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
762 if (user) {
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
763 int i;
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
764 char *c = user->name;
116
741e45592522 Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
765 // printMsg("match '%s' / prev '%s'\n", user->name, previous);
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
766
113
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
767 for (i = startPos; i <= endPos; i++)
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
768 nn_editbuf_delete(buf, startPos);
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
769
113
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
770 for (i = startPos; *c; i++, c++)
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
771 nn_editbuf_insert(buf, i, *c);
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
772
116
741e45592522 Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
773 if (previous == NULL || again) {
113
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
774 if (startPos == 0) {
116
741e45592522 Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
775 nn_editbuf_insert(buf, i++, optNickSep);
113
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
776 startPos++;
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
777 }
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
778 nn_editbuf_insert(buf, i++, ' ');
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
779 }
113
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
780 nn_editbuf_setpos(buf, startPos + 2 + strlen(user->name));
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
781
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
782 th_free(previous);
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
783 previous = th_strdup(user->name);
113
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
784
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
785 return TRUE;
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
786 }
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
787 }
113
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
788
2a53156e7e12 Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 112
diff changeset
789 return FALSE;
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
790 }
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
791
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
792 int main(int argc, char *argv[])
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
793 {
85
1534b2c08c74 Initialize some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
794 int tmpSocket = -1, curVis = ERR, updateCount = 0;
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
795 struct hostent *tmpHost;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
796 BOOL argsOK, isError = FALSE,
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
797 exitProg = FALSE,
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
798 colorSet = FALSE,
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
799 cursesInit = FALSE,
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
800 networkInit = FALSE,
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
801 insertMode = TRUE;
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
802 time_t prevTime;
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
803 struct timeval socktv;
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
804 fd_set sockfds;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
805 char *tmpStr;
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
806 nn_editbuf_t *editBuf = nn_editbuf_new(SET_BUFSIZE);
89
c2d916b340bf Change some typedef names; Add struct for user list handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
807 nn_editbuf_t *histBuf[SET_MAX_HISTORY+2];
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
808 int histPos = 0, histMax = 0;
154
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
809
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
810 cfgitem_t *tmpcfg;
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
811 char *homeDir = NULL;
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
812
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
813 memset(histBuf, 0, sizeof(histBuf));
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
814
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
815 /* Initialize */
145
d2e3a95c74df Bump version to 0.8.1.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
816 th_init("NNChat", "Newbie Nudes chat client", "0.8.1",
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
817 "Written and designed by Anonymous Finnish Guy (C) 2008-2010",
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
818 "This software is freeware, use and distribute as you wish.");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
819 th_verbosityLevel = 0;
133
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
820
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
821 /* Read config */
148
9da39d090ef1 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 147
diff changeset
822 tmpcfg = NULL;
133
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
823 th_cfg_add_comment(&tmpcfg, "General settings");
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
824 th_cfg_add_string(&tmpcfg, "username", &optUserName, NULL);
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
825 th_cfg_add_string(&tmpcfg, "password", &optPassword, NULL);
150
db5e7a1f1eb3 Add comment in config file about format of user color setting.
Matti Hamalainen <ccr@tnsp.org>
parents: 149
diff changeset
826 th_cfg_add_comment(&tmpcfg, "Default color as a hex-triplet");
133
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
827 th_cfg_add_hexvalue(&tmpcfg, "color", &optUserColor, optUserColor);
149
a4d6707161a7 Add config file option for default setting of ignore mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
828
a4d6707161a7 Add config file option for default setting of ignore mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
829 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
830 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
831 th_cfg_add_comment(&tmpcfg, "People to be ignored when ignore mode is enabled");
a4d6707161a7 Add config file option for default setting of ignore mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
832 th_cfg_add_string_list(&tmpcfg, "ignore_list", &nnIgnoreList);
133
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
833 th_cfg_add_section(&cfg, "general", tmpcfg);
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
834
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
835 tmpcfg = NULL;
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
836 th_cfg_add_comment(&tmpcfg, "Chat server hostname or IP address");
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
837 th_cfg_add_string(&tmpcfg, "host", &optServer, optServer);
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
838 th_cfg_add_comment(&tmpcfg, "Default port to connect to (8002 = public room, 8003 = passion pit, 8005 = members only)");
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
839 th_cfg_add_int(&tmpcfg, "port", &optPort, optPort);
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
840 th_cfg_add_section(&cfg, "server", tmpcfg);
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
841
154
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
842 #ifdef __WIN32
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
843 {
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
844 char tmpPath[MAX_PATH];
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
845 if (SHGetFolderPath(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, tmpPath) == S_OK)
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
846 homeDir = th_strdup(tmpPath);
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
847 }
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
848 #else
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
849 homeDir = getenv("HOME");
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
850 #endif
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
851
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
852 if (homeDir != NULL) {
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
853 FILE *cfgfile;
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
854 setConfigFile = th_strdup_printf("%s" SET_DIR_SEPARATOR "%s", homeDir, SET_CONFIG_FILE);
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
855
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
856 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
857
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
858 if ((cfgfile = fopen(setConfigFile, "r")) != NULL)
e8f67e344aaf Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
859 th_cfg_read(cfgfile, setConfigFile, cfg);
133
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
860 }
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
861
137
fad8c31e41e6 Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
862 setBrowser = getenv("BROWSER");
fad8c31e41e6 Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
863 if (setBrowser == NULL)
fad8c31e41e6 Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
864 setBrowser = "firefox";
fad8c31e41e6 Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
865
153
f1684884fd56 Comment cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 151
diff changeset
866 /* Parse command line arguments */
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
867 argsOK = th_args_process(argc, argv, optList, optListN,
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
868 argHandleOpt, argHandleFile, FALSE);
26
b84fc46c6035 Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
869
153
f1684884fd56 Comment cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 151
diff changeset
870 /* Check if we have username and password */
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
871 if (optUserName == NULL || optPassword == NULL) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
872 THERR("User/pass not specified, get some --help\n");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
873 return -1;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
874 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
875
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
876 if (!argsOK)
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
877 return -2;
64
6a3a917303e4 Some random cleanups, bring back WinSock support.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
878
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
879 /* Allocate userhash */
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
880 if ((nnUsers = nn_userhash_new()) == NULL) {
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
881 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
882 return -105;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
883 }
64
6a3a917303e4 Some random cleanups, bring back WinSock support.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
884
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
885 /* Open logfile */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
886 if (optLogFilename) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
887 THMSG(1, "Opening logfile '%s'\n", optLogFilename);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
888
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
889 if ((optLogFile = fopen(optLogFilename, "a")) == NULL) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
890 THERR("Could not open logfile for appending!\n");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
891 return -9;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
892 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
893 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
894
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
895 if (!nn_network_init()) {
91
acfc4b4bc180 Create network initialization functions in libnnchat and move Win32/WinSock code there.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
896 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
897 goto err_exit;
acfc4b4bc180 Create network initialization functions in libnnchat and move Win32/WinSock code there.
Matti Hamalainen <ccr@tnsp.org>
parents: 90
diff changeset
898 } else
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
899 networkInit = TRUE;
68
3ab7751fdad1 MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
900
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
901 /* Okay ... */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
902 THMSG(1, "Trying to resolve host '%s' ...\n", optServer);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
903 tmpHost = gethostbyname(optServer);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
904 if (tmpHost == NULL) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
905 THERR("Could not resolve hostname: %s.\n",
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
906 hstrerror(h_errno));
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
907 goto err_exit;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
908 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
909 THMSG(2, "True hostname: %s\n", tmpHost->h_name);
26
b84fc46c6035 Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
910
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
911 /* To emulate the official client, we first make a request for
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
912 * policy file, even though we don't use it for anything...
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
913 */
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
914 if ((tmpSocket = nn_open_connection((struct in_addr *) tmpHost->h_addr, 843)) < 0) {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
915 THERR("Policy file request connection setup failed!\n");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
916 goto err_exit;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
917 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
918
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
919 tmpStr = "<policy-file-request/>";
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
920 if (nn_send_to_socket(tmpSocket, tmpStr, strlen(tmpStr) + 1) == FALSE) {
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
921 THERR("Failed to send policy file request.\n");
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
922 goto err_exit;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
923 } else {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
924 ssize_t gotBuf;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
925 char tmpBuf[SET_BUFSIZE];
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
926 gotBuf = recv(tmpSocket, tmpBuf, sizeof(tmpBuf), 0);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
927 tmpBuf[gotBuf-1] = 0;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
928 THMSG(2, "Probe got: %s\n", tmpBuf);
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
929 nn_close_connection(tmpSocket);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
930 }
26
b84fc46c6035 Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
931
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
932 /* Okay, now do the proper connection ... */
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
933 if ((tmpSocket = nn_open_connection((struct in_addr *) tmpHost->h_addr, optPort)) < 0) {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
934 THERR("Main connection setup failed!\n");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
935 goto err_exit;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
936 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
937
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
938 THMSG(1, "Connected, logging in as '%s', site '%s'.\n", optUserName, optSite);
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
939 optUserName2 = nn_dblencode_str(optUserName);
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
940 tmpStr = nn_dblencode_str(optSite);
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
941 nn_send_msg(tmpSocket, optUserName2, "%%2Flogin%%20%%2Dsite%%20%s%%20%%2Dpassword%%20%s", tmpStr, optPassword);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
942 th_free(tmpStr);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
943
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
944 /* Initialize NCurses */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
945 if (!optDaemon) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
946 if (LINES < 0 || LINES > 1000) LINES = 24;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
947 if (COLS < 0 || COLS > 1000) COLS = 80;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
948 initscr();
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
949 raw();
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
950 keypad(stdscr, TRUE);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
951 noecho();
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
952 meta(stdscr, TRUE);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
953 timeout(SET_DELAY);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
954 curVis = curs_set(0);
110
8af4072dc31a Fix Win32/MinGW/PDcurses issues.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
955
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
956 if (has_colors()) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
957 start_color();
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
958
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
959 init_pair(1, COLOR_RED, COLOR_BLACK);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
960 init_pair(2, COLOR_GREEN, COLOR_BLACK);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
961 init_pair(3, COLOR_YELLOW, COLOR_BLACK);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
962 init_pair(4, COLOR_BLUE, COLOR_BLACK);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
963 init_pair(5, COLOR_MAGENTA, COLOR_BLACK);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
964 init_pair(6, COLOR_CYAN, COLOR_BLACK);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
965 init_pair(7, COLOR_WHITE, COLOR_BLACK);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
966 init_pair(8, COLOR_BLACK, COLOR_BLACK);
28
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
967
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
968 init_pair(10, COLOR_BLACK, COLOR_RED);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
969 init_pair(11, COLOR_WHITE, COLOR_RED);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
970 init_pair(12, COLOR_GREEN, COLOR_RED);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
971 init_pair(13, COLOR_YELLOW, COLOR_RED);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
972 init_pair(14, COLOR_BLUE, COLOR_RED);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
973 init_pair(15, COLOR_MAGENTA, COLOR_RED);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
974 init_pair(16, COLOR_CYAN, COLOR_RED);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
975 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
976
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
977 cursesInit = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
978
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
979 if (!initializeWindows())
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
980 goto err_exit;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
981
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
982 nn_editbuf_clear(editBuf);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
983 printEditBuf("", editBuf);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
984 updateStatus(insertMode);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
985 }
100
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
986
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
987 /* Enter mainloop */
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
988 prevTime = time(NULL);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
989 FD_ZERO(&sockfds);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
990 FD_SET(tmpSocket, &sockfds);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
991
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
992 while (!isError && !exitProg) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
993 int result;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
994 fd_set tmpfds;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
995
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
996 /* Check for incoming data from the server */
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
997 socktv.tv_sec = 0;
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
998 socktv.tv_usec = SET_DELAY_USEC;
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
999 tmpfds = sockfds;
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1000 if ((result = select(tmpSocket+1, &tmpfds, NULL, NULL, &socktv)) == -1) {
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1001 int res = nn_get_socket_errno();
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1002 if (res != EINTR) {
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1003 errorMsg("Error occured in select(sockfds): %d, %s\n",
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1004 res, nn_get_socket_errstr(res));
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1005 isError = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1006 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1007 } else if (FD_ISSET(tmpSocket, &tmpfds)) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1008 ssize_t gotBuf;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1009 char tmpBuf[8192];
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1010 char *bufPtr = tmpBuf;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1011 gotBuf = recv(tmpSocket, tmpBuf, sizeof(tmpBuf), 0);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1012
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1013 if (gotBuf < 0) {
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1014 int res = nn_get_socket_errno();
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1015 errorMsg("Error in recv: %d, %s\n", res, nn_get_socket_errstr(res));
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1016 isError = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1017 } else if (gotBuf == 0) {
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1018 errorMsg("Server closed connection.\n");
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1019 isError = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1020 } else {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1021 /* Handle protocol data */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1022 tmpBuf[gotBuf] = 0;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1023 do {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1024 size_t bufLen = strlen(bufPtr) + 1;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1025 result = handleProtocol(tmpSocket, bufPtr, bufLen);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1026
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1027 if (result > 0) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1028 /* Couldn't handle the message for some reason */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1029 printMsg("Could not handle: %s\n", tmpBuf);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1030 } else if (result < 0) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1031 /* Fatal error, quit */
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1032 errorMsg("Fatal error with message: %s\n", tmpBuf);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1033 isError = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1034 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1035
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1036 gotBuf -= bufLen;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1037 bufPtr += bufLen;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1038 } while (gotBuf > 0 && !isError);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1039 updateStatus(insertMode);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1040 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1041 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1042
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1043 /* Handle user input */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1044 if (!optDaemon) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1045 int c, cnt = 0;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1046 BOOL update = FALSE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1047
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1048 /* Handle several buffered keypresses at once */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1049 do {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1050 c = wgetch(stdscr);
77
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
1051 if (c == 0x1b) {
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
1052 c = wgetch(stdscr);
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
1053 if (c == 'O') {
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
1054 c = wgetch(stdscr);
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
1055 switch (c) {
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
1056 case 'd': c = 0x204; break;
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
1057 case 'c': c = 0x206; break;
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
1058 default:
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
1059 printMsg("Unhandled ESC-O key sequence 0x%02x\n", c);
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
1060 break;
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
1061 }
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
1062 } else {
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
1063 printMsg("Unhandled ESC key sequence 0x%02x\n", c);
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
1064 continue;
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
1065 }
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
1066 }
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
1067
119
4bc63a535acb Fix some PDCurses incompatibilities and remove some Win32/PDCurses specific hacks.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
1068
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1069 switch (c) {
74
98004129202a Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
1070 #ifdef KEY_RESIZE
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1071 case KEY_RESIZE:
119
4bc63a535acb Fix some PDCurses incompatibilities and remove some Win32/PDCurses specific hacks.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
1072 resize_term(0, 0);
4bc63a535acb Fix some PDCurses incompatibilities and remove some Win32/PDCurses specific hacks.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
1073 erase();
134
f367fc14021a Use resize_term() and erase() on resize event also with ncurses and not only with PDcurses.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
1074 #ifdef PDCURSES
119
4bc63a535acb Fix some PDCurses incompatibilities and remove some Win32/PDCurses specific hacks.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
1075 timeout(SET_DELAY);
4bc63a535acb Fix some PDCurses incompatibilities and remove some Win32/PDCurses specific hacks.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
1076 #endif
4bc63a535acb Fix some PDCurses incompatibilities and remove some Win32/PDCurses specific hacks.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
1077
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1078 if (!initializeWindows()) {
119
4bc63a535acb Fix some PDCurses incompatibilities and remove some Win32/PDCurses specific hacks.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
1079 errorMsg("Error resizing curses windows\n");
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1080 isError = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1081 }
119
4bc63a535acb Fix some PDCurses incompatibilities and remove some Win32/PDCurses specific hacks.
Matti Hamalainen <ccr@tnsp.org>
parents: 118
diff changeset
1082 update = TRUE;
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1083 break;
74
98004129202a Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
1084 #endif
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1085
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1086 case KEY_ENTER:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1087 case '\n':
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1088 case '\r':
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1089 /* Call the user input handler */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1090 if (editBuf->len > 0) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1091
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1092 if (histMax > 0) {
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1093 nn_editbuf_free(histBuf[SET_MAX_HISTORY+1]);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1094 histBuf[SET_MAX_HISTORY+1] = NULL;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1095 memmove(&histBuf[2], &histBuf[1], histMax * sizeof(histBuf[0]));
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1096 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1097
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1098 histPos = 0;
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1099 histBuf[1] = nn_editbuf_copy(editBuf);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1100 if (histMax < SET_MAX_HISTORY) histMax++;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1101
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1102 nn_editbuf_insert(editBuf, editBuf->len, 0);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1103 result = handleUserInput(tmpSocket, editBuf->data, editBuf->len);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1104
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1105 nn_editbuf_clear(editBuf);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1106
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1107 if (result < 0) {
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1108 errorMsg("Fatal error handling user input: %s\n", editBuf->data);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1109 isError = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1110 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1111
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1112 update = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1113 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1114 break;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1115
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1116 case KEY_UP: /* Backwards in input history */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1117 if (histPos == 0) {
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1118 nn_editbuf_free(histBuf[0]);
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1119 histBuf[0] = nn_editbuf_copy(editBuf);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1120 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1121 if (histPos < histMax) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1122 histPos++;
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1123 nn_editbuf_free(editBuf);
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1124 editBuf = nn_editbuf_copy(histBuf[histPos]);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1125 update = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1126 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1127 break;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1128
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1129 case KEY_DOWN: /* Forwards in input history */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1130 if (histPos > 0) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1131 histPos--;
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1132 nn_editbuf_free(editBuf);
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1133 editBuf = nn_editbuf_copy(histBuf[histPos]);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1134 update = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1135 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1136 break;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1137
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1138 case 0x204: /* ctrl+left arrow = Skip words left */
74
98004129202a Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
1139 while (editBuf->pos > 0 && isspace((int) editBuf->data[editBuf->pos - 1]))
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1140 editBuf->pos--;
74
98004129202a Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
1141 while (editBuf->pos > 0 && !isspace((int) editBuf->data[editBuf->pos - 1]))
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1142 editBuf->pos--;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1143 update = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1144 break;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1145
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1146 case 0x206: /* ctrl+right arrow = Skip words right */
74
98004129202a Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
1147 while (editBuf->pos < editBuf->len && isspace((int) editBuf->data[editBuf->pos]))
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1148 editBuf->pos++;
74
98004129202a Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
1149 while (editBuf->pos < editBuf->len && !isspace((int) editBuf->data[editBuf->pos]))
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1150 editBuf->pos++;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1151 if (editBuf->pos > editBuf->len)
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1152 editBuf->pos = editBuf->len;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1153 update = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1154 break;
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1155
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1156 case KEY_HOME: nn_editbuf_setpos(editBuf, 0); update = TRUE; break;
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1157 case KEY_END: nn_editbuf_setpos(editBuf, editBuf->len); update = TRUE; break;
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1158 case KEY_LEFT: nn_editbuf_setpos(editBuf, editBuf->pos - 1); update = TRUE; break;
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1159 case KEY_RIGHT: nn_editbuf_setpos(editBuf, editBuf->pos + 1); update = TRUE; break;
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1160
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1161 case KEY_BACKSPACE:
73
c56e766acce1 Support keycode 0x08 as backspace for Win32 compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
1162 case 0x08:
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1163 nn_editbuf_delete(editBuf, editBuf->pos - 1);
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1164 nn_editbuf_setpos(editBuf, editBuf->pos - 1);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1165 update = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1166 break;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1167
122
e564dd9df07c Change some key defines.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
1168 case KEY_DC: /* Delete character */
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1169 nn_editbuf_delete(editBuf, editBuf->pos);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1170 update = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1171 break;
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1172
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1173
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1174 case 0x109: /* F1 = Toggle insert / overwrite mode */
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1175 insertMode = !insertMode;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1176 update = TRUE;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1177 break;
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1178
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1179 case 0x10a: /* F2 = Clear editbuffer */
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1180 nn_editbuf_clear(editBuf);
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1181 update = TRUE;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1182 break;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1183
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1184 case 0x10c: /* F3 = Ignore mode */
149
a4d6707161a7 Add config file option for default setting of ignore mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
1185 setIgnoreMode = !setIgnoreMode;
a4d6707161a7 Add config file option for default setting of ignore mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
1186 printMsg("Ignore mode = %s\n", setIgnoreMode ? "ON" : "OFF");
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1187 break;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1188
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1189 case 0x111: /* F9 = Quit */
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1190 printMsg("Quitting per user request.\n");
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1191 exitProg = TRUE;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1192 break;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1193
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1194 case 0x110: /* F8 = switch between PRV */
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1195 if (setPrvMode)
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1196 setPrvMode = FALSE;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1197 else {
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1198 if (setTarget != NULL)
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1199 setPrvMode = TRUE;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1200 }
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1201 update = TRUE;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1202 break;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1203
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1204 case 0x09: /* Tab = complete username */
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
1205 performTabCompletion(editBuf);
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
1206 update = TRUE;
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1207 break;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1208
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1209 case 0x0c: /* Ctrl + L */
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1210 redrawwin(mainWin);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1211 redrawwin(statusWin);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1212 redrawwin(editWin);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1213 break;
122
e564dd9df07c Change some key defines.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
1214
e564dd9df07c Change some key defines.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
1215 case KEY_NPAGE:
e564dd9df07c Change some key defines.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
1216 case KEY_PPAGE:
e564dd9df07c Change some key defines.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
1217 break;
e564dd9df07c Change some key defines.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
1218
e564dd9df07c Change some key defines.
Matti Hamalainen <ccr@tnsp.org>
parents: 121
diff changeset
1219
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1220 case ERR:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1221 /* Ignore */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1222 break;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1223
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1224 default:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1225 if (isprint(c) || c == 0xe4 || c == 0xf6 || c == 0xc4 || c == 0xd6) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1226 if (insertMode)
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1227 nn_editbuf_insert(editBuf, editBuf->pos, c);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1228 else
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1229 nn_editbuf_write(editBuf, editBuf->pos, c);
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1230 nn_editbuf_setpos(editBuf, editBuf->pos + 1);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1231 update = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1232 } else {
77
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
1233 printMsg("Unhandled key: 0x%02x\n", c);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1234 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1235 break;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1236 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1237 } while (c != ERR && !exitProg && ++cnt < 10);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1238
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1239 if (update) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1240 /* Update edit line */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1241 printEditBuf(setPrvMode ? setTarget : "", editBuf);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1242 updateStatus(insertMode);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1243 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1244 } /* !optDaemon */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1245
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1246 if (++updateCount > 10) {
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1247 time_t tmpTime = time(NULL);
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1248 if (tmpTime - prevTime > SET_KEEPALIVE) {
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1249 nn_send_msg(tmpSocket, optUserName2, "/listallusers");
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1250 prevTime = tmpTime;
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1251 }
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1252
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1253 if (!colorSet) {
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1254 colorSet = TRUE;
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1255 printMsg("%s v%s - %s\n", th_prog_name, th_prog_version, th_prog_fullname);
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1256 printMsg("%s\n", th_prog_author);
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1257 printMsg("%s\n", th_prog_license);
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1258 nn_send_msg(tmpSocket, optUserName2, "%%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
1259 }
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1260
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1261 updateStatus(insertMode);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1262 updateCount = 0;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1263 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1264
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1265 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1266
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1267 /* 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
1268 err_exit:
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1269 nn_userhash_free(nnUsers);
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1270
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1271 nn_editbuf_free(editBuf);
75
abbdd101b267 Free some memory.
Matti Hamalainen <ccr@tnsp.org>
parents: 74
diff changeset
1272 for (histPos = 0; histPos <= SET_MAX_HISTORY; histPos++)
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1273 nn_editbuf_free(histBuf[histPos]);
75
abbdd101b267 Free some memory.
Matti Hamalainen <ccr@tnsp.org>
parents: 74
diff changeset
1274
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1275 if (cursesInit) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1276 if (curVis != ERR)
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1277 curs_set(curVis);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1278 endwin();
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1279 THMSG(1, "NCurses deinitialized.\n");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1280 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1281
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1282 if (isError) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1283 THMSG(1, "Error exit.\n");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1284 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1285
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1286 th_free(optUserName2);
10
53e127854dca WinSock support fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
1287
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1288 nn_close_connection(tmpSocket);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1289
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1290 if (networkInit)
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1291 nn_network_close();
68
3ab7751fdad1 MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
1292
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1293 THMSG(1, "Connection terminated.\n");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1294
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1295 if (optLogFile) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1296 THMSG(1, "Closing logfile.\n");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1297 fclose(optLogFile);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1298 }
133
ffe8bbd429fa Config file.
Matti Hamalainen <ccr@tnsp.org>
parents: 132
diff changeset
1299
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1300 return 0;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1301 }