annotate nnchat.c @ 108:f323b137ca08

Tab-completion now works with cycling, but bugs with names that have whitespaces.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 23 Oct 2010 02:01:00 +0300
parents 8037a3a7e491
children 1323a7f88c21
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"
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 #include <string.h>
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 #include <errno.h>
64
6a3a917303e4 Some random cleanups, bring back WinSock support.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
11 #ifdef __WIN32
68
3ab7751fdad1 MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
12 #define usleep(t) Sleep((t) / 1000)
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
3ab7751fdad1 MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
15 #endif
64
6a3a917303e4 Some random cleanups, bring back WinSock support.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
16 #include <curses.h>
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17
49
0bcc38910a77 Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
18
0bcc38910a77 Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
19 #define SET_MAX_BACKBUF (1024)
30
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
20 #define SET_MAX_HISTORY (16)
28
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
21 #define SET_DELAY (15)
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
22 #define SET_DELAY_USEC (SET_DELAY * 1000)
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
23 #define SET_KEEPALIVE (15*60) /* Ping/keepalive period in seconds */
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
25 char *ignoreList[] = {
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
26 "purr_rr",
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
27 "moisha",
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
28 "leth",
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
29 "shaz:)",
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
30 "rayen",
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
31 "iam2qute4you_92",
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
32 NULL
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
33 };
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
34
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
35 nn_userhash_t *nnUsers = NULL;
49
0bcc38910a77 Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
36
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 /* Options
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 */
104
06e6ac51e3f2 Change default port to 8003.
Matti Hamalainen <ccr@tnsp.org>
parents: 103
diff changeset
39 int optPort = 8003;
39
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
40 int optUserColor = 0x006080;
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
41 char *optServer = "chat.newbienudes.com",
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
42 *optUserName = NULL,
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
43 *optUserName2 = NULL,
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
44 *optPassword = NULL,
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
45 *optLogFilename = NULL,
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
46 *setTarget = NULL,
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
47 *optSite = "NN";
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;
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
54 BOOL ignoreMode = FALSE;
33
e49ea6febfeb Cleanups. Added option to specify/fake "site" where logging in from.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
55
89
c2d916b340bf Change some typedef names; Add struct for user list handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
56
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 /* Arguments
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 */
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 optarg_t optList[] = {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
60 { 0, '?', "help", "Show this help", OPT_NONE },
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
61 { 1, 'v', "verbose", "Be more verbose", OPT_NONE },
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
62 { 2, 'p', "port", "Connect to port", OPT_ARGREQ },
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
63 { 3, 's', "server", "Server to connect to", OPT_ARGREQ },
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
64 { 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
65 { 5, 'l', "logfile", "Log filename", OPT_ARGREQ },
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
66 { 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
67 { 7, 'S', "site", "Site (default: NN)", OPT_ARGREQ },
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 };
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69
43
40ba8cdcf03a Cleanups, added a silly morse code conversion mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
70 const int optListN = (sizeof(optList) / sizeof(optList[0]));
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72
26
b84fc46c6035 Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
73 int getColor(char *str)
b84fc46c6035 Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
74 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
75 char *p = str;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
76 int len, val = 0;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
77
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
78 for (len = 0; *p && len < 6; p++, len++) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
79 if (*p >= '0' && *p <= '9') {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
80 val *= 16; val += (*p - '0');
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
81 } else if (*p >= 'A' && *p <= 'F') {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
82 val *= 16; val += (*p - 'A') + 10;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
83 } else if (*p >= 'a' && *p <= 'f') {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
84 val *= 16; val += (*p - 'a') + 10;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
85 } else
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
86 return -1;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
87 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
88
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
89 return (len == 6) ? val : -1;
26
b84fc46c6035 Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
90 }
b84fc46c6035 Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
91
68
3ab7751fdad1 MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
92
3ab7751fdad1 MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
93 void argShowHelp()
3ab7751fdad1 MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
94 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
95 th_args_help(stdout, optList, optListN, th_prog_name,
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
96 "[options] <username> <password>");
68
3ab7751fdad1 MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
97 }
3ab7751fdad1 MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
98
3ab7751fdad1 MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
99
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 BOOL argHandleOpt(const int optN, char *optArg, char *currArg)
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
102 switch (optN) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
103 case 0:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
104 argShowHelp();
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
105 exit(0);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
106 break;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
108 case 1:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
109 th_verbosityLevel++;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
110 break;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
111
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
112 case 2:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
113 optPort = atoi(optArg);
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 3:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
117 optServer = optArg;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
118 break;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
119
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
120 case 4:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
121 if ((optUserColor = getColor(optArg)) < 0) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
122 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
123 optArg);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
124 return FALSE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
125 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
126 THMSG(1, "Using color #%06x\n", optUserColor);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
127 break;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
129 case 5:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
130 optLogFilename = optArg;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
131 break;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
133 case 7:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
134 optSite = optArg;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
135 break;
33
e49ea6febfeb Cleanups. Added option to specify/fake "site" where logging in from.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
136
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
137 case 6:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
138 optDaemon = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
139 THMSG(1, "Running in pseudo-daemon mode.\n");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
140 break;
21
29098addfa65 Added a "daemon" mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 19
diff changeset
141
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
142 default:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
143 THERR("Unknown option '%s'.\n", currArg);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
144 return FALSE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
145 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
146
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
147 return TRUE;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 BOOL argHandleFile(char *currArg)
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
153 if (!optUserName)
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
154 optUserName = currArg;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
155 else if (!optPassword)
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
156 optPassword = currArg;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
157 else {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
158 THERR("Username '%s' already specified on commandline!\n", optUserName);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
159 return FALSE;
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
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
162 return TRUE;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164
49
0bcc38910a77 Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
165
30
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
166 void updateStatus(BOOL insertMode)
28
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
167 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
168 char tmpStr[128] = "";
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
169 time_t timeStamp;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
170 struct tm *tmpTime;;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
171
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
172 if (statusWin == NULL) return;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
173
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
174 timeStamp = time(NULL);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
175 if ((tmpTime = localtime(&timeStamp)) != NULL) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
176 strftime(tmpStr, sizeof(tmpStr), "%H:%M:%S", tmpTime);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
177 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
178
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
179 wbkgdset(statusWin, 0x0d00);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
180 werase(statusWin);
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);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
183 mvwaddstr(statusWin, 0, 1, tmpStr);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
184
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
185 waddstr(statusWin, " | ");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
186 wattrset(statusWin, A_BOLD | COLOR_PAIR(16));
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
187 waddstr(statusWin, optUserName);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
188 wattrset(statusWin, A_BOLD | COLOR_PAIR(13));
29
a27ef0e359b9 Make statusline more informative.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
189
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
190 waddstr(statusWin, " | ");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
191 wattrset(statusWin, A_BOLD | COLOR_PAIR(11));
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
192 waddstr(statusWin, insertMode ? "INS" : "DEL");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
193
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
194 wattrset(statusWin, A_BOLD | COLOR_PAIR(13));
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
195 waddstr(statusWin, " | Prv: ");
28
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
196
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
197 wattrset(statusWin, A_BOLD | COLOR_PAIR(11));
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
198 waddstr(statusWin, setTarget != NULL ? setTarget : "-");
29
a27ef0e359b9 Make statusline more informative.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
199
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
200 wattrset(statusWin, A_BOLD | COLOR_PAIR(13));
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
201 waddstr(statusWin, " | P/C: ");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
202 wattrset(statusWin, A_BOLD | COLOR_PAIR(11));
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
203 snprintf(tmpStr, sizeof(tmpStr), "%d / #%06x", optPort, optUserColor);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
204 waddstr(statusWin, tmpStr);
29
a27ef0e359b9 Make statusline more informative.
Matti Hamalainen <ccr@tnsp.org>
parents: 28
diff changeset
205
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
206 wrefresh(statusWin);
28
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
207 }
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
208
89
c2d916b340bf Change some typedef names; Add struct for user list handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
209 void printEditBuf(char *str, nn_editbuf_t *buf)
28
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
210 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
211 if (statusWin == NULL || buf == NULL) return;
32
67ec4073e38c Check for NULL pointers (fixes "daemon" mode)
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
212
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
213 buf->data[buf->len] = 0;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
214 werase(editWin);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
215
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
216 wattrset(editWin, A_BOLD);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
217 mvwaddstr(editWin, 0, 0, str);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
218 waddstr(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 if (buf->pos < buf->len) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
222 waddnstr(editWin, buf->data, buf->pos);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
223 wattrset(editWin, A_REVERSE);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
224 waddch(editWin, buf->data[buf->pos]);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
225 wattrset(editWin, A_NORMAL);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
226 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
227 } else {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
228 waddnstr(editWin, buf->data, buf->len);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
229 wattrset(editWin, A_REVERSE);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
230 waddch(editWin, ' ');
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
231 wattrset(editWin, A_NORMAL);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
232 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
233 wrefresh(editWin);
28
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
234 }
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
235
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
236 int printWin(WINDOW *win, const char *fmt)
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
237 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
238 const char *s = fmt;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
239 int col = 0;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
240
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
241 while (*s) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
242 if (*s == '½') {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
243 int val = 0;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
244 s++;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
245 if (*s == '½') {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
246 waddch(win, ((unsigned char) *s) | col);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
247 s++;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
248 } else {
74
98004129202a Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
249 while (*s && isdigit((int) *s)) {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
250 val *= 10;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
251 val += (*s - '0');
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
252 s++;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
253 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
254 if (*s != '½') return -1;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
255 s++;
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 if (val < 9) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
258 col = A_DIM | COLOR_PAIR(val);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
259 } else if (val < 30) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
260 col = A_BOLD | COLOR_PAIR(val - 9);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
261 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
262 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
263 } else {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
264 waddch(win, ((unsigned char) *s) | col);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
265 s++;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
266 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
267 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
268 return 0;
28
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
269 }
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
270
62
ff5d74f0d428 Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
271
28
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
272 int printFile(FILE *outFile, const char *fmt)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
273 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
274 const char *s = fmt;
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 while (*s) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
277 if (*s == '½') {
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 if (*s == '½') {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
280 fputc((unsigned char) *s, outFile);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
281 s++;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
282 } else {
74
98004129202a Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
283 while (*s && isdigit((int) *s)) s++;
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
284 if (*s != '½') return -1;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
285 s++;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
286 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
287 } else {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
288 fputc((unsigned char) *s, outFile);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
289 s++;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
290 }
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
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
293 return 0;
28
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
294 }
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
295
62
ff5d74f0d428 Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
296
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
297 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
298 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
299 char tmpStr[128] = "", buf[8192];
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
300 time_t timeStamp;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
301 struct tm *tmpTime;;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
302
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
303 timeStamp = time(NULL);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
304 if ((tmpTime = localtime(&timeStamp)) != NULL) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
305 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
306 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
307
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
308 vsnprintf(buf, sizeof(buf), fmt, ap);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
309
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
310 if (optLogFile) {
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
311 if (addStamp) printFile(optLogFile, tmpStr);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
312 printFile(optLogFile, buf);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
313 fflush(optLogFile);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
314 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
315
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
316 if (!optDaemon && !logOnly) {
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
317 if (addStamp) printWin(mainWin, tmpStr);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
318 printWin(mainWin, buf);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
319 wrefresh(mainWin);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
320 }
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
321 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
322
100
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
323 void printMsg(const char *fmt, ...)
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
324 {
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
325 va_list ap;
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
326
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
327 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
328 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
329 va_end(ap);
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
330 }
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 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
333 {
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
334 va_list ap;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
335
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
336 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
337 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
338 va_end(ap);
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
339 }
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
340
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
341 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
342 {
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
343 va_list ap;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
344
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
345 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
346 printMsgV(TRUE, logOnly, fmt, ap);
100
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
347 va_end(ap);
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
348 }
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
349
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
350
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
351 void errorMsg(char *fmt, ...)
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
352 {
100
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
353 va_list ap1, ap2;
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
354
100
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
355 va_start(ap1, fmt);
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
356 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
357 printMsgV(TRUE, FALSE, fmt, ap1);
100
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
358 va_end(ap1);
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
359
100
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
360 THERR_V(fmt, ap2);
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
361 va_end(ap2);
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
362 }
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
363
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
364
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
365 int handleUser(int sock, const char *str)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
366 {
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
367 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
368 char *q, *s, *t, *h, *p2;
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
369
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
370 (void) sock;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
371
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
372 s = strstr(str, msg);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
373 if (!s) return 1;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
374 *s = 0;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
375 s += strlen(msg);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
376
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
377 q = strstr(s, "</MESSAGE>");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
378 if (!q) return 3;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
379 *q = 0;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
380
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
381 s = nn_decode_str1(s);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
382 if (!s) return -1;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
383
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
384 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
385 if (!p2) {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
386 th_free(s);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
387 return -2;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
388 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
389
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
390
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
391 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
392 /* 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
393 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
394 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
395
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
396 t = nn_strip_tags(s + 1);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
397 if (!strncmp(t, "BPRV", 4)) {
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
398 h = nn_decode_str2(t + 1);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
399 printMsg("½11½%s½0½\n", h);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
400 } else {
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
401 h = nn_decode_str2(t);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
402 printMsg("½9½* %s½0½\n", h);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
403 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
404 th_free(h);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
405 th_free(t);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
406 } 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
407 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
408 BOOL logOnly = FALSE;
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
409 t = nn_strip_tags(s);
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
410 h = nn_decode_str2(t);
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
411 if (ignoreMode) {
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
412 char **user = ignoreList;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
413 while (*user != NULL) {
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 if (strcasecmp(p2, *user) == 0) {
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
415 logOnly = TRUE;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
416 break;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
417 }
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
418 user++;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
419 }
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
420 }
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
421 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
422 th_free(h);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
423 th_free(t);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
424 }
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
425
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
426 error:
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
427 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
428 th_free(p2);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
429 return 0;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
430 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
431
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
432
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
433 int handleLogin(int sock, const char *str)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
434 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
435 char tmpStr[256] = "";
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
436 time_t timeStamp;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
437 struct tm *tmpTime;;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
438
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
439 timeStamp = time(NULL);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
440 if ((tmpTime = localtime(&timeStamp)) != NULL) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
441 strftime(tmpStr, sizeof(tmpStr), "%c", tmpTime);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
442 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
443
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
444 if (!strncmp(str, "FAILURE", 7)) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
445 printMsg("½1½Login failure½0½ - ½3½%s½0½\n", tmpStr);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
446 return -2;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
447 } else if (!strncmp(str, "SUCCESS", 7)) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
448 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
449 nn_send_msg(sock, optUserName2, "%%2FRequestUserList");
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
450 return 0;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
451 } else
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
452 return 1;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
453 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
454
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
455
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
456 int handleAddUser(int sock, const char *str)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
457 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
458 char *p, *s = strstr(str, "</ADD_USER>");
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
459
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
460 (void) sock;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
461
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
462 if (!s) return 1;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
463 *s = 0;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
464
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
465 p = nn_dbldecode_str(str);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
466 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
467
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
468 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
469
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
470 printMsg("! ½3½%s½0½ ½2½ADDED.½0½\n", p);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
471 th_free(p);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
472 return 0;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
473 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
474
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
475
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
476 int handleDeleteUser(int sock, const char *str)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
477 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
478 char *p, *s = strstr(str, "</DELETE_USER>");
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
479
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
480 (void) sock;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
481
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
482 if (!s) return 1;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
483 *s = 0;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
484
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
485 p = nn_dbldecode_str(str);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
486 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
487
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
488 nn_userhash_delete(nnUsers, p);
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
489
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
490 printMsg("! ½3½%s½0½ ½1½DELETED.½0½\n", p);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
491 th_free(p);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
492 return 0;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
493 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
494
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
495
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
496 int handleFoo(int sock, const char *str)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
497 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
498 (void) sock; (void) str;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
499
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
500 return 0;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
501 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
502
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
503
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 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
505 {
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
506 (void) sock; (void) str;
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
507 errorMsg("Booted by server.\n");
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
508 return -1;
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
509 }
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
510
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
511
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
512 typedef struct {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
513 char *cmd;
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
514 int (*handler)(int, const char *);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
515 } protocmd_t;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
516
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
517
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
518 static const protocmd_t protoCmds[] = {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
519 { "<USER>", handleUser },
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
520 { "<LOGIN_", handleLogin },
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
521 { "<DELETE_USER>", handleDeleteUser },
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
522 { "<ADD_USER>", handleAddUser },
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
523 { "<NUMCLIENTS>", handleFoo },
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
524 { "<BOOT />", handleBoot },
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
525 };
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
526
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
527 static const int nprotoCmds = sizeof(protoCmds) / sizeof(protoCmds[0]);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
528
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
529
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
530 int handleProtocol(const int sock, const char *buf, const size_t bufLen)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
531 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
532 int i;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
533
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
534 for (i = 0; i < nprotoCmds; i++) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
535 size_t cmdLen = strlen(protoCmds[i].cmd);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
536 if (cmdLen < bufLen && !strncmp(buf, protoCmds[i].cmd, cmdLen)) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
537 return protoCmds[i].handler(sock, buf + cmdLen);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
538 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
539 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
540
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
541 return 1;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
542 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
543
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
544
51
cf7789d88350 Fix the input packet handling to properly handle packets with multiple
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
545 int handleUserInput(const int sock, char *buf, size_t bufLen)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
546 {
78
745f670068dc Add functions to simplify code.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
547 char *tmpStr, tmpBuf[4096];
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
548 BOOL result;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
549
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
550 /* Trim right */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
551 buf[--bufLen] = 0;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
552 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
553 buf[bufLen--] = 0;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
554
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
555 /* Check command */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
556 if (*buf == 0) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
557 return 1;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
558 } else if (!strncmp(buf, "/color ", 7)) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
559 int tmpInt;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
560 if ((tmpInt = getColor(buf+7)) < 0) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
561 printMsg("Invalid color value '%s'\n", buf+7);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
562 return 1;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
563 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
564 optUserColor = tmpInt;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
565 printMsg("Setting color to #%06x\n", optUserColor);
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
566 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
567 return 0;
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
568 } else if (!strncmp(buf, "/w ", 3)) {
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
569 char *name = buf + 3;
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
570 pid_t pud;
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
571 tmpStr = nn_encode_str1(name);
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
572 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
573 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
574
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
575 printMsg("Opening profile for: %s\n", name);
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
576 printMsg("%s\n", tmpBuf);
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
577 /*
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
578 if ((pud = fork()) < 0) return 0;
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
579 if (getpid() == pud) {
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
580 execlp("firefox", "-remote", tmpBuf, (char *) NULL);
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
581 exit(0);
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
582 } else
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
583 */
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
584 return 0;
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
585 } else if (!strncmp(buf, "/to ", 4)) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
586 th_free(setTarget);
79
e36df57c5b0f Use th_strdup() again.
Matti Hamalainen <ccr@tnsp.org>
parents: 78
diff changeset
587 setTarget = th_strdup(buf + 4);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
588 printMsg("Set prv target to '%s'\n", setTarget);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
589 return 0;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
590 } else if (!strncmp(buf, "/who", 4)) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
591 snprintf(tmpBuf, sizeof(tmpBuf), "/listallusers");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
592 buf = tmpBuf;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
593 } else if (setPrvMode) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
594 if (setTarget != NULL) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
595 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
596 buf = tmpBuf;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
597 } else {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
598 printMsg("No target set, exiting prv mode.\n");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
599 setPrvMode = FALSE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
600 return 1;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
601 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
602 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
603
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
604
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
605 /* Send double-encoded */
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
606 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
607 if (tmpStr == 0) return -2;
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
608 result = nn_send_msg(sock, optUserName2, "%s", tmpStr);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
609 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
610
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
611 return result ? 0 : -1;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
612 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
613
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
614
46
65b1ac6a1e2e Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
615 BOOL initializeWindows(void)
65b1ac6a1e2e Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
616 {
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
617 if (mainWin) delwin(mainWin);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
618 if (statusWin) delwin(statusWin);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
619 if (editWin) delwin(editWin);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
620
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
621 mainWin = newwin(LINES - 4, COLS, 0, 0);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
622 statusWin = newwin(1, COLS, LINES - 4, 0);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
623 editWin = newwin(3, COLS, LINES - 3, 0);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
624
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
625 if (mainWin == NULL || statusWin == NULL || editWin == NULL) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
626 THERR("Could not create ncurses windows!\n");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
627 return FALSE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
628 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
629 scrollok(mainWin, 1);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
630
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
631 return TRUE;
46
65b1ac6a1e2e Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
632 }
65b1ac6a1e2e Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
633
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
634 void 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
635 {
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
636 static char *previous = NULL;
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
637 static char *matsi = NULL;
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
638 char *b = buf->data;
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
639 ssize_t pos2 = 0, pos1 = buf->pos;
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
640
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
641 if (pos1 > 0) pos1--;
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
642
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
643 if (pos1 > 0 && b[pos1 - 1] == ':') {
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
644 pos1 -= 2;
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
645 pos2 = pos1;
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
646 while (pos1 > 0 && b[pos1 - 1] != ' ') pos1--;
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
647 } else
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
648 if (b[pos1] != ' ' && b[pos1] != ':') {
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
649 pos2 = pos1;
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
650 while (pos1 > 0 && b[pos1 - 1] != ' ') pos1--;
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
651 while (pos2 < buf->len && b[pos2] != ' ') pos2++;
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
652 while (pos2 > 0 && b[pos2] == ' ') pos2--;
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
653 th_free(matsi);
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
654 matsi = nn_editbuf_get_string(buf, pos1, pos2);
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
655 th_free(previous); previous = NULL;
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
656 }
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
657
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
658 if (matsi) {
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
659 nn_user_t *user = nn_user_match(nnUsers, matsi, previous);
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
660 // printMsg("pattern '%s'\n", matsi);
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
661
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
662 if (user) {
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
663 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
664 char *c = user->name;
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
665 // printMsg("match '%s'\n", user->name);
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
666
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
667 for (i = pos1; i <= pos2; i++)
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
668 nn_editbuf_delete(buf, pos1);
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
669
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
670 for (i = pos1; *c; i++, c++)
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
671 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
672
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
673 if (previous == NULL) {
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
674 nn_editbuf_insert(buf, i+1, ':');
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
675 nn_editbuf_insert(buf, i+2, ' ');
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
676 }
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
677 nn_editbuf_setpos(buf, pos1 + 2 + strlen(user->name));
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
678
108
f323b137ca08 Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents: 107
diff changeset
679 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
680 previous = th_strdup(user->name);
107
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
681 }
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
682 }
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
683 }
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
684
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
685 int main(int argc, char *argv[])
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
686 {
85
1534b2c08c74 Initialize some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
687 int tmpSocket = -1, curVis = ERR, updateCount = 0;
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
688 struct hostent *tmpHost;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
689 BOOL argsOK, isError = FALSE,
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
690 exitProg = FALSE,
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
691 colorSet = FALSE,
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
692 cursesInit = FALSE,
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
693 networkInit = FALSE,
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
694 insertMode = TRUE;
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
695 time_t prevTime;
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
696 struct timeval socktv;
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
697 fd_set sockfds;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
698 char *tmpStr;
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
699 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
700 nn_editbuf_t *histBuf[SET_MAX_HISTORY+2];
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
701 int histPos = 0, histMax = 0;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
702
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
703 memset(histBuf, 0, sizeof(histBuf));
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
704
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
705 /* Initialize */
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
706 th_init("NNChat", "Newbie Nudes chat client", "0.7.9",
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
707 "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
708 "This software is freeware, use and distribute as you wish.");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
709 th_verbosityLevel = 0;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
710
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
711 /* Parse arguments */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
712 argsOK = th_args_process(argc, argv, optList, optListN,
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
713 argHandleOpt, argHandleFile, FALSE);
26
b84fc46c6035 Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
714
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
715 /* Check the mode and arguments */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
716 if (optUserName == NULL || optPassword == NULL) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
717 THERR("User/pass not specified, get some --help\n");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
718 return -1;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
719 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
720
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
721 if (!argsOK)
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
722 return -2;
64
6a3a917303e4 Some random cleanups, bring back WinSock support.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
723
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
724 /* Allocate userhash */
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
725 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
726 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
727 return -105;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
728 }
64
6a3a917303e4 Some random cleanups, bring back WinSock support.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
729
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
730 /* Open logfile */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
731 if (optLogFilename) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
732 THMSG(1, "Opening logfile '%s'\n", optLogFilename);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
733
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
734 if ((optLogFile = fopen(optLogFilename, "a")) == NULL) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
735 THERR("Could not open logfile for appending!\n");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
736 return -9;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
737 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
738 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
739
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
740 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
741 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
742 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
743 } else
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
744 networkInit = TRUE;
68
3ab7751fdad1 MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
745
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
746 /* Okay ... */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
747 THMSG(1, "Trying to resolve host '%s' ...\n", optServer);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
748 tmpHost = gethostbyname(optServer);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
749 if (tmpHost == NULL) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
750 THERR("Could not resolve hostname: %s.\n",
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
751 hstrerror(h_errno));
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
752 goto err_exit;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
753 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
754 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
755
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
756 #if 1
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
757 /* 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
758 * 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
759 */
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
760 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
761 THERR("Policy file request connection setup failed!\n");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
762 goto err_exit;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
763 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
764
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
765 tmpStr = "<policy-file-request/>";
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
766 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
767 THERR("Failed to send policy file request.\n");
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
768 goto err_exit;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
769 } else {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
770 ssize_t gotBuf;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
771 char tmpBuf[SET_BUFSIZE];
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
772 gotBuf = recv(tmpSocket, tmpBuf, sizeof(tmpBuf), 0);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
773 tmpBuf[gotBuf-1] = 0;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
774 THMSG(2, "Probe got: %s\n", tmpBuf);
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
775 nn_close_connection(tmpSocket);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
776 }
39
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
777 #endif
26
b84fc46c6035 Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
778
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
779 /* Okay, now do the proper connection ... */
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
780 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
781 THERR("Main connection setup failed!\n");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
782 goto err_exit;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
783 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
784
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
785 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
786 optUserName2 = nn_dblencode_str(optUserName);
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
787 tmpStr = nn_dblencode_str(optSite);
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
788 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
789 th_free(tmpStr);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
790
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
791 /* Initialize NCurses */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
792 if (!optDaemon) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
793 if (LINES < 0 || LINES > 1000) LINES = 24;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
794 if (COLS < 0 || COLS > 1000) COLS = 80;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
795 LINES=24;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
796 initscr();
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
797 raw();
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
798 keypad(stdscr, TRUE);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
799 noecho();
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
800 meta(stdscr, TRUE);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
801 timeout(SET_DELAY);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
802 curVis = curs_set(0);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
803 if (has_colors()) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
804 start_color();
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
805
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
806 init_pair(1, COLOR_RED, COLOR_BLACK);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
807 init_pair(2, COLOR_GREEN, COLOR_BLACK);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
808 init_pair(3, COLOR_YELLOW, COLOR_BLACK);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
809 init_pair(4, COLOR_BLUE, COLOR_BLACK);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
810 init_pair(5, COLOR_MAGENTA, COLOR_BLACK);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
811 init_pair(6, COLOR_CYAN, COLOR_BLACK);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
812 init_pair(7, COLOR_WHITE, COLOR_BLACK);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
813 init_pair(8, COLOR_BLACK, COLOR_BLACK);
28
512775f6b081 A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
814
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
815 init_pair(10, COLOR_BLACK, COLOR_RED);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
816 init_pair(11, COLOR_WHITE, COLOR_RED);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
817 init_pair(12, COLOR_GREEN, COLOR_RED);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
818 init_pair(13, COLOR_YELLOW, COLOR_RED);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
819 init_pair(14, COLOR_BLUE, COLOR_RED);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
820 init_pair(15, COLOR_MAGENTA, COLOR_RED);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
821 init_pair(16, COLOR_CYAN, COLOR_RED);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
822
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
823 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
824
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
825 cursesInit = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
826
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
827 if (!initializeWindows())
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
828 goto err_exit;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
829
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
830 nn_editbuf_clear(editBuf);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
831 printEditBuf("", editBuf);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
832 updateStatus(insertMode);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
833 }
100
ed4067c10a8a Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents: 98
diff changeset
834
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
835 /* Enter mainloop */
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
836 prevTime = time(NULL);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
837 FD_ZERO(&sockfds);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
838 FD_SET(tmpSocket, &sockfds);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
839
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
840 while (!isError && !exitProg) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
841 int result;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
842 fd_set tmpfds;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
843
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
844 /* 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
845 socktv.tv_sec = 0;
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
846 socktv.tv_usec = SET_DELAY_USEC;
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
847 tmpfds = sockfds;
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
848 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
849 int res = nn_get_socket_errno();
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
850 if (res != EINTR) {
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
851 errorMsg("Error occured in select(sockfds): %d, %s\n",
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
852 res, nn_get_socket_errstr(res));
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
853 isError = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
854 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
855 } else if (FD_ISSET(tmpSocket, &tmpfds)) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
856 ssize_t gotBuf;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
857 char tmpBuf[8192];
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
858 char *bufPtr = tmpBuf;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
859 gotBuf = recv(tmpSocket, tmpBuf, sizeof(tmpBuf), 0);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
860
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
861 if (gotBuf < 0) {
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
862 int res = nn_get_socket_errno();
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
863 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
864 isError = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
865 } else if (gotBuf == 0) {
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
866 errorMsg("Server closed connection.\n");
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
867 isError = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
868 } else {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
869 /* Handle protocol data */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
870 tmpBuf[gotBuf] = 0;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
871 do {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
872 size_t bufLen = strlen(bufPtr) + 1;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
873 result = handleProtocol(tmpSocket, bufPtr, bufLen);
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 if (result > 0) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
876 /* Couldn't handle the message for some reason */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
877 printMsg("Could not handle: %s\n", tmpBuf);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
878 } else if (result < 0) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
879 /* Fatal error, quit */
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
880 errorMsg("Fatal error with message: %s\n", tmpBuf);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
881 isError = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
882 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
883
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
884 gotBuf -= bufLen;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
885 bufPtr += bufLen;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
886 } while (gotBuf > 0 && !isError);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
887 updateStatus(insertMode);
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 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
890
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
891 /* Handle user input */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
892 if (!optDaemon) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
893 int c, cnt = 0;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
894 BOOL update = FALSE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
895
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
896 /* Handle several buffered keypresses at once */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
897 do {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
898 c = wgetch(stdscr);
77
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
899
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
900 if (c == 0x1b) {
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
901 c = wgetch(stdscr);
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
902 if (c == 'O') {
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
903 c = wgetch(stdscr);
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
904 switch (c) {
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
905 case 'd': c = 0x204; break;
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
906 case 'c': c = 0x206; break;
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
907 default:
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
908 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
909 break;
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
910 }
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
911 } else {
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
912 printMsg("Unhandled ESC key sequence 0x%02x\n", c);
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
913 continue;
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
914 }
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
915 }
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
916
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
917 switch (c) {
74
98004129202a Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
918 #ifdef KEY_RESIZE
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
919 case KEY_RESIZE:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
920 if (!initializeWindows()) {
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
921 errorMsg("Error resizing ncurses windows\n");
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
922 isError = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
923 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
924 break;
74
98004129202a Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
925 #endif
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
926
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
927 case KEY_ENTER:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
928 case '\n':
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
929 case '\r':
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
930 /* Call the user input handler */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
931 if (editBuf->len > 0) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
932
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
933 if (histMax > 0) {
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
934 nn_editbuf_free(histBuf[SET_MAX_HISTORY+1]);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
935 histBuf[SET_MAX_HISTORY+1] = NULL;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
936 memmove(&histBuf[2], &histBuf[1], histMax * sizeof(histBuf[0]));
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
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
939 histPos = 0;
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
940 histBuf[1] = nn_editbuf_copy(editBuf);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
941 if (histMax < SET_MAX_HISTORY) histMax++;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
942
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
943 nn_editbuf_insert(editBuf, editBuf->len, 0);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
944 result = handleUserInput(tmpSocket, editBuf->data, editBuf->len);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
945
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
946 nn_editbuf_clear(editBuf);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
947
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
948 if (result < 0) {
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
949 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
950 isError = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
951 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
952
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
953 update = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
954 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
955 break;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
956
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
957 case KEY_UP: /* Backwards in input history */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
958 if (histPos == 0) {
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
959 nn_editbuf_free(histBuf[0]);
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
960 histBuf[0] = nn_editbuf_copy(editBuf);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
961 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
962 if (histPos < histMax) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
963 histPos++;
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
964 nn_editbuf_free(editBuf);
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
965 editBuf = nn_editbuf_copy(histBuf[histPos]);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
966 update = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
967 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
968 break;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
969
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
970 case KEY_DOWN: /* Forwards in input history */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
971 if (histPos > 0) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
972 histPos--;
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
973 nn_editbuf_free(editBuf);
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
974 editBuf = nn_editbuf_copy(histBuf[histPos]);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
975 update = TRUE;
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 break;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
978
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
979 case 0x204: /* ctrl+left arrow = Skip words left */
74
98004129202a Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
980 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
981 editBuf->pos--;
74
98004129202a Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
982 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
983 editBuf->pos--;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
984 update = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
985 break;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
986
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
987 case 0x206: /* ctrl+right arrow = Skip words right */
74
98004129202a Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
988 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
989 editBuf->pos++;
74
98004129202a Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
990 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
991 editBuf->pos++;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
992 if (editBuf->pos > editBuf->len)
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
993 editBuf->pos = editBuf->len;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
994 update = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
995 break;
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
996
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
997 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
998 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
999 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
1000 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
1001
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1002 case KEY_BACKSPACE:
73
c56e766acce1 Support keycode 0x08 as backspace for Win32 compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
1003 case 0x08:
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1004 nn_editbuf_delete(editBuf, editBuf->pos - 1);
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1005 nn_editbuf_setpos(editBuf, editBuf->pos - 1);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1006 update = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1007 break;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1008
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1009 case 0x14a: /* Delete */
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1010 nn_editbuf_delete(editBuf, editBuf->pos);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1011 update = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1012 break;
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1013
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1014
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1015 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
1016 insertMode = !insertMode;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1017 update = TRUE;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1018 break;
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1019
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1020 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
1021 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
1022 update = TRUE;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1023 break;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1024
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1025 case 0x10c: /* F3 = Ignore mode */
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1026 ignoreMode = !ignoreMode;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1027 printMsg("Ignore mode = %s\n", ignoreMode ? "ON" : "OFF");
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1028 break;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1029
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1030 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
1031 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
1032 exitProg = TRUE;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1033 break;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1034
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1035 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
1036 if (setPrvMode)
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1037 setPrvMode = FALSE;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1038 else {
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1039 if (setTarget != NULL)
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1040 setPrvMode = TRUE;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1041 }
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1042 update = TRUE;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1043 break;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1044
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1045 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
1046 performTabCompletion(editBuf);
8037a3a7e491 Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
1047 update = TRUE;
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1048 break;
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1049
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1050 case 0x0c: /* Ctrl + L */
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1051 redrawwin(mainWin);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1052 redrawwin(statusWin);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1053 redrawwin(editWin);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1054 break;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1055
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1056 case ERR:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1057 /* Ignore */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1058 break;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1059
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1060 default:
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1061 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
1062 if (insertMode)
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1063 nn_editbuf_insert(editBuf, editBuf->pos, c);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1064 else
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1065 nn_editbuf_write(editBuf, editBuf->pos, c);
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1066 nn_editbuf_setpos(editBuf, editBuf->pos + 1);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1067 update = TRUE;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1068 } else {
77
e8c9d7d13866 Handle certain key sequences better.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
1069 printMsg("Unhandled key: 0x%02x\n", c);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1070 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1071 break;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1072 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1073 } while (c != ERR && !exitProg && ++cnt < 10);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1074
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1075 if (update) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1076 /* Update edit line */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1077 printEditBuf(setPrvMode ? setTarget : "", editBuf);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1078 updateStatus(insertMode);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1079 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1080 } /* !optDaemon */
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1081
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1082 if (++updateCount > 10) {
96
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1083 time_t tmpTime = time(NULL);
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1084 if (tmpTime - prevTime > SET_KEEPALIVE) {
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1085 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
1086 prevTime = tmpTime;
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1087 }
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1088
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1089 if (!colorSet) {
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1090 colorSet = TRUE;
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1091 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
1092 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
1093 printMsg("%s\n", th_prog_license);
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1094 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
1095 }
7c9538e71c89 Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
1096
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1097 updateStatus(insertMode);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1098 updateCount = 0;
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1099 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1100
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1101 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1102
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1103 /* 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
1104 err_exit:
103
eaa524e153f9 Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
1105 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
1106
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1107 nn_editbuf_free(editBuf);
75
abbdd101b267 Free some memory.
Matti Hamalainen <ccr@tnsp.org>
parents: 74
diff changeset
1108 for (histPos = 0; histPos <= SET_MAX_HISTORY; histPos++)
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1109 nn_editbuf_free(histBuf[histPos]);
75
abbdd101b267 Free some memory.
Matti Hamalainen <ccr@tnsp.org>
parents: 74
diff changeset
1110
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1111 if (cursesInit) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1112 if (curVis != ERR)
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1113 curs_set(curVis);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1114 endwin();
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1115 THMSG(1, "NCurses deinitialized.\n");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1116 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1117
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1118 if (isError) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1119 THMSG(1, "Error exit.\n");
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
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1122 th_free(optUserName2);
10
53e127854dca WinSock support fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
1123
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1124 nn_close_connection(tmpSocket);
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1125
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1126 if (networkInit)
97
218efd2f0641 Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
1127 nn_network_close();
68
3ab7751fdad1 MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
1128
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1129 THMSG(1, "Connection terminated.\n");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1130
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1131 if (optLogFile) {
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1132 THMSG(1, "Closing logfile.\n");
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1133 fclose(optLogFile);
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1134 }
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1135
75
abbdd101b267 Free some memory.
Matti Hamalainen <ccr@tnsp.org>
parents: 74
diff changeset
1136
70
5228ad7b4f57 Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
1137 return 0;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1138 }