Mercurial > hg > nnchat
annotate nnchat.c @ 63:afd90bbb3af6
Colour changes.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 11 Nov 2008 22:06:07 +0200 |
parents | ff5d74f0d428 |
children | 6a3a917303e4 |
rev | line source |
---|---|
41 | 1 /* |
2 * NNChat - Custom chat client for NewbieNudes.com chatrooms | |
39 | 3 * Written by Matti 'ccr' Hämäläinen |
4 * (C) Copyright 2008 Tecnic Software productions (TNSP) | |
5 */ | |
62
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
6 #include "libnnchat.h" |
0 | 7 #include <stdlib.h> |
8 #include "th_args.h" | |
9 #include <string.h> | |
10 #include <errno.h> | |
11 #include <time.h> | |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
12 #include <ncurses.h> |
0 | 13 |
49
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
14 |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
15 #define SET_MAX_BACKBUF (1024) |
30 | 16 #define SET_MAX_HISTORY (16) |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
17 #define SET_DELAY (15) |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
18 #define SET_DELAY_USEC (SET_DELAY * 1000) |
0 | 19 |
49
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
20 |
0 | 21 /* Options |
22 */ | |
27 | 23 int optPort = 8005; |
39 | 24 int optUserColor = 0x006080; |
27 | 25 char *optServer = "www11.servemedata.com", |
26 *optUserName = NULL, | |
27 *optUserName2 = NULL, | |
28 *optPassword = NULL, | |
29 *optLogFilename = NULL, | |
33
e49ea6febfeb
Cleanups. Added option to specify/fake "site" where logging in from.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
30 *setTarget = NULL, |
e49ea6febfeb
Cleanups. Added option to specify/fake "site" where logging in from.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
31 *optSite = "NN"; |
21 | 32 BOOL optDaemon = FALSE; |
0 | 33 FILE *optLogFile = NULL; |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
34 WINDOW *mainWin = NULL, |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
35 *statusWin = NULL, |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
36 *editWin = NULL; |
59 | 37 BOOL setPrvMode = FALSE; |
33
e49ea6febfeb
Cleanups. Added option to specify/fake "site" where logging in from.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
38 |
0 | 39 /* Arguments |
40 */ | |
41 optarg_t optList[] = { | |
27 | 42 { 0, '?', "help", "Show this help", OPT_NONE }, |
43 { 1, 'v', "verbose", "Be more verbose", OPT_NONE }, | |
44 { 2, 'p', "port", "Connect to port", OPT_ARGREQ }, | |
45 { 3, 's', "server", "Server to connect to", OPT_ARGREQ }, | |
46 { 4, 'C', "color", "Initial color in RGB hex 000000", OPT_ARGREQ }, | |
47 { 5, 'l', "logfile", "Log filename", OPT_ARGREQ }, | |
48 { 6, 'D', "daemon", "A pseudo-daemon mode for logging", OPT_NONE }, | |
33
e49ea6febfeb
Cleanups. Added option to specify/fake "site" where logging in from.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
49 { 7, 'S', "site", "Site (default: NN)", OPT_ARGREQ }, |
0 | 50 }; |
51 | |
43
40ba8cdcf03a
Cleanups, added a silly morse code conversion mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
52 const int optListN = (sizeof(optList) / sizeof(optList[0])); |
0 | 53 |
54 | |
55 void argShowHelp() | |
56 { | |
57 th_args_help(stdout, optList, optListN, th_prog_name, | |
58 "[options] <username> <password>"); | |
59 } | |
60 | |
61 | |
26
b84fc46c6035
Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
62 int getColor(char *str) |
b84fc46c6035
Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
63 { |
b84fc46c6035
Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
64 char *p = str; |
b84fc46c6035
Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
65 int len, val = 0; |
b84fc46c6035
Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
66 |
b84fc46c6035
Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
67 for (len = 0; *p && len < 6; p++, len++) { |
b84fc46c6035
Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
68 if (*p >= '0' && *p <= '9') { |
b84fc46c6035
Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
69 val *= 16; val += (*p - '0'); |
b84fc46c6035
Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
70 } else if (*p >= 'A' && *p <= 'F') { |
b84fc46c6035
Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
71 val *= 16; val += (*p - 'A') + 10; |
b84fc46c6035
Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
72 } else if (*p >= 'a' && *p <= 'f') { |
b84fc46c6035
Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
73 val *= 16; val += (*p - 'a') + 10; |
b84fc46c6035
Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
74 } else |
b84fc46c6035
Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
75 return -1; |
b84fc46c6035
Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
76 } |
b84fc46c6035
Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
77 |
b84fc46c6035
Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
78 return (len == 6) ? val : -1; |
b84fc46c6035
Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
79 } |
b84fc46c6035
Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
80 |
0 | 81 BOOL argHandleOpt(const int optN, char *optArg, char *currArg) |
82 { | |
83 switch (optN) { | |
84 case 0: | |
85 argShowHelp(); | |
86 exit(0); | |
87 break; | |
88 | |
89 case 1: | |
90 th_verbosityLevel++; | |
91 break; | |
92 | |
93 case 2: | |
94 optPort = atoi(optArg); | |
95 break; | |
96 | |
97 case 3: | |
98 optServer = optArg; | |
99 break; | |
100 | |
101 case 4: | |
26
b84fc46c6035
Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
102 if ((optUserColor = getColor(optArg)) < 0) { |
0 | 103 THERR("Invalid color argument '%s', should be a RGB hex triplet '000000'.\n", |
104 optArg); | |
105 return FALSE; | |
106 } | |
107 THMSG(1, "Using color #%06x\n", optUserColor); | |
108 break; | |
109 | |
110 case 5: | |
111 optLogFilename = optArg; | |
112 break; | |
113 | |
33
e49ea6febfeb
Cleanups. Added option to specify/fake "site" where logging in from.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
114 case 7: |
e49ea6febfeb
Cleanups. Added option to specify/fake "site" where logging in from.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
115 optSite = optArg; |
e49ea6febfeb
Cleanups. Added option to specify/fake "site" where logging in from.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
116 break; |
e49ea6febfeb
Cleanups. Added option to specify/fake "site" where logging in from.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
117 |
21 | 118 case 6: |
119 optDaemon = TRUE; | |
120 THMSG(1, "Running in pseudo-daemon mode.\n"); | |
121 break; | |
122 | |
0 | 123 default: |
124 THERR("Unknown option '%s'.\n", currArg); | |
125 return FALSE; | |
126 } | |
127 | |
128 return TRUE; | |
129 } | |
130 | |
131 | |
132 BOOL argHandleFile(char *currArg) | |
133 { | |
134 if (!optUserName) | |
135 optUserName = currArg; | |
136 else if (!optPassword) | |
137 optPassword = currArg; | |
138 else { | |
139 THERR("Username '%s' already specified on commandline!\n", optUserName); | |
140 return FALSE; | |
141 } | |
142 | |
143 return TRUE; | |
144 } | |
145 | |
49
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
146 |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
147 typedef struct { |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
148 char **data; |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
149 size_t n, size; |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
150 } ringbuf_t; |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
151 |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
152 |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
153 ringbuf_t * newRingBuf(const size_t size) |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
154 { |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
155 ringbuf_t *res = th_calloc(1, sizeof(ringbuf_t)); |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
156 |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
157 res->data = (char **) th_malloc(size * sizeof(char *)); |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
158 res->size = size; |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
159 res->n = 0; |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
160 |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
161 return res; |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
162 } |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
163 |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
164 |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
165 void freeRingBuf(ringbuf_t *buf) |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
166 { |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
167 size_t i; |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
168 |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
169 for (i = 0; i < buf->n; i++) |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
170 th_free(buf->data[i]); |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
171 |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
172 th_free(buf->data); |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
173 th_free(buf); |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
174 } |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
175 |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
176 |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
177 void addRingBuf(ringbuf_t *buf, const char *str) |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
178 { |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
179 if (buf->n < buf->size) { |
50
d08bf3b6561d
Use strdup; Added function to decode morse code.
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
180 buf->data[buf->n] = strdup(str); |
49
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
181 buf->n++; |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
182 } else { |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
183 th_free(buf->data[0]); |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
184 memmove(&(buf->data[0]), &(buf->data[1]), buf->size - 1); |
50
d08bf3b6561d
Use strdup; Added function to decode morse code.
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
185 buf->data[buf->size - 1] = strdup(str); |
49
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
186 } |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
187 } |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
188 |
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
189 |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
190 typedef struct { |
31
9b429b283786
Add command history functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
191 ssize_t pos, len, size; |
9b429b283786
Add command history functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
192 char *data; |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
193 } editbuf_t; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
194 |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
195 |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
196 int writeBuf(editbuf_t *buf, ssize_t pos, int ch) |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
197 { |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
198 /* Check arguments */ |
31
9b429b283786
Add command history functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
199 if (buf->len+1 >= buf->size) return -3; |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
200 |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
201 if (pos < 0) |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
202 return -1; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
203 else if (pos >= buf->len) { |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
204 buf->data[buf->len++] = ch; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
205 } else { |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
206 buf->data[pos] = ch; |
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 return 0; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
209 } |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
210 |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
211 int insertBuf(editbuf_t *buf, ssize_t pos, int ch) |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
212 { |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
213 /* Check arguments */ |
31
9b429b283786
Add command history functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
214 if (buf->len+1 >= buf->size) return -3; |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
215 |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
216 if (pos < 0) |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
217 return -1; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
218 else if (pos >= buf->len) { |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
219 buf->data[buf->len] = ch; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
220 } else { |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
221 memmove(&(buf->data[pos+1]), &(buf->data[pos]), buf->len - pos + 1); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
222 buf->data[pos] = ch; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
223 } |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
224 buf->len++; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
225 return 0; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
226 } |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
227 |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
228 int deleteBuf(editbuf_t *buf, ssize_t pos) |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
229 { |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
230 /* Check arguments */ |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
231 if (pos < 0) |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
232 return -1; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
233 else if (pos < buf->len) { |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
234 memmove(&(buf->data[pos]), &(buf->data[pos+1]), buf->len - pos); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
235 buf->len--; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
236 return 0; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
237 } else |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
238 return -2; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
239 } |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
240 |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
241 void clearBuf(editbuf_t *buf) |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
242 { |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
243 buf->len = 0; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
244 buf->pos = 0; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
245 } |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
246 |
31
9b429b283786
Add command history functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
247 editbuf_t * newBuf(ssize_t n) |
30 | 248 { |
31
9b429b283786
Add command history functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
249 editbuf_t *res = th_calloc(1, sizeof(editbuf_t)); |
9b429b283786
Add command history functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
250 |
9b429b283786
Add command history functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
251 res->data = (char *) th_malloc(n); |
9b429b283786
Add command history functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
252 res->size = n; |
9b429b283786
Add command history functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
253 |
9b429b283786
Add command history functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
254 return res; |
30 | 255 } |
256 | |
257 void freeBuf(editbuf_t *buf) | |
258 { | |
31
9b429b283786
Add command history functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
259 if (buf) { |
9b429b283786
Add command history functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
260 th_free(buf->data); |
9b429b283786
Add command history functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
261 th_free(buf); |
9b429b283786
Add command history functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
262 } |
30 | 263 } |
264 | |
265 editbuf_t * copyBuf(editbuf_t *src) | |
266 { | |
31
9b429b283786
Add command history functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
267 editbuf_t *res; |
30 | 268 |
31
9b429b283786
Add command history functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
269 assert(src != NULL); |
9b429b283786
Add command history functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
270 |
9b429b283786
Add command history functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
271 if (src == NULL) return NULL; |
30 | 272 |
31
9b429b283786
Add command history functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
273 if ((res = newBuf(src->size)) == NULL) |
9b429b283786
Add command history functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
274 return NULL; |
30 | 275 |
31
9b429b283786
Add command history functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
276 memcpy(res->data, src->data, src->size); |
9b429b283786
Add command history functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
277 res->pos = res->len = src->len; |
9b429b283786
Add command history functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
278 |
9b429b283786
Add command history functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
279 return res; |
30 | 280 } |
281 | |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
282 void setBufPos(editbuf_t *buf, ssize_t pos) |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
283 { |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
284 /* Check arguments */ |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
285 if (pos < 0) |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
286 buf->pos = 0; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
287 else if (pos >= buf->len) |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
288 buf->pos = buf->len; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
289 else |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
290 buf->pos = pos; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
291 } |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
292 |
30 | 293 void updateStatus(BOOL insertMode) |
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 char tmpStr[128] = ""; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
296 time_t timeStamp; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
297 struct tm *tmpTime;; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
298 |
32
67ec4073e38c
Check for NULL pointers (fixes "daemon" mode)
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
299 if (statusWin == NULL) return; |
67ec4073e38c
Check for NULL pointers (fixes "daemon" mode)
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
300 |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
301 timeStamp = time(NULL); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
302 if ((tmpTime = localtime(&timeStamp)) != NULL) { |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
303 strftime(tmpStr, sizeof(tmpStr), "%H:%M:%S", tmpTime); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
304 } |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
305 |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
306 wbkgdset(statusWin, 0x0d00); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
307 werase(statusWin); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
308 |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
309 wattrset(statusWin, A_BOLD); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
310 mvwaddstr(statusWin, 0, 1, tmpStr); |
29
a27ef0e359b9
Make statusline more informative.
Matti Hamalainen <ccr@tnsp.org>
parents:
28
diff
changeset
|
311 |
a27ef0e359b9
Make statusline more informative.
Matti Hamalainen <ccr@tnsp.org>
parents:
28
diff
changeset
|
312 waddstr(statusWin, " | "); |
30 | 313 wattrset(statusWin, A_BOLD | COLOR_PAIR(16)); |
29
a27ef0e359b9
Make statusline more informative.
Matti Hamalainen <ccr@tnsp.org>
parents:
28
diff
changeset
|
314 waddstr(statusWin, optUserName); |
a27ef0e359b9
Make statusline more informative.
Matti Hamalainen <ccr@tnsp.org>
parents:
28
diff
changeset
|
315 wattrset(statusWin, A_BOLD | COLOR_PAIR(13)); |
a27ef0e359b9
Make statusline more informative.
Matti Hamalainen <ccr@tnsp.org>
parents:
28
diff
changeset
|
316 |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
317 waddstr(statusWin, " | "); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
318 wattrset(statusWin, A_BOLD | COLOR_PAIR(11)); |
30 | 319 waddstr(statusWin, insertMode ? "INS" : "DEL"); |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
320 |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
321 wattrset(statusWin, A_BOLD | COLOR_PAIR(13)); |
29
a27ef0e359b9
Make statusline more informative.
Matti Hamalainen <ccr@tnsp.org>
parents:
28
diff
changeset
|
322 waddstr(statusWin, " | Prv: "); |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
323 |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
324 wattrset(statusWin, A_BOLD | COLOR_PAIR(11)); |
29
a27ef0e359b9
Make statusline more informative.
Matti Hamalainen <ccr@tnsp.org>
parents:
28
diff
changeset
|
325 waddstr(statusWin, setTarget != NULL ? setTarget : "-"); |
a27ef0e359b9
Make statusline more informative.
Matti Hamalainen <ccr@tnsp.org>
parents:
28
diff
changeset
|
326 |
a27ef0e359b9
Make statusline more informative.
Matti Hamalainen <ccr@tnsp.org>
parents:
28
diff
changeset
|
327 wattrset(statusWin, A_BOLD | COLOR_PAIR(13)); |
30 | 328 waddstr(statusWin, " | P/C: "); |
29
a27ef0e359b9
Make statusline more informative.
Matti Hamalainen <ccr@tnsp.org>
parents:
28
diff
changeset
|
329 wattrset(statusWin, A_BOLD | COLOR_PAIR(11)); |
30 | 330 snprintf(tmpStr, sizeof(tmpStr), "%d / #%06x", optPort, optUserColor); |
29
a27ef0e359b9
Make statusline more informative.
Matti Hamalainen <ccr@tnsp.org>
parents:
28
diff
changeset
|
331 waddstr(statusWin, tmpStr); |
a27ef0e359b9
Make statusline more informative.
Matti Hamalainen <ccr@tnsp.org>
parents:
28
diff
changeset
|
332 |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
333 wrefresh(statusWin); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
334 } |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
335 |
30 | 336 void printEditBuf(char *str, editbuf_t *buf) |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
337 { |
32
67ec4073e38c
Check for NULL pointers (fixes "daemon" mode)
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
338 if (statusWin == NULL || buf == NULL) return; |
67ec4073e38c
Check for NULL pointers (fixes "daemon" mode)
Matti Hamalainen <ccr@tnsp.org>
parents:
31
diff
changeset
|
339 |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
340 buf->data[buf->len] = 0; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
341 werase(editWin); |
30 | 342 |
343 wattrset(editWin, A_BOLD); | |
344 mvwaddstr(editWin, 0, 0, str); | |
345 waddstr(editWin, "> "); | |
346 wattrset(editWin, A_NORMAL); | |
347 | |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
348 if (buf->pos < buf->len) { |
30 | 349 waddnstr(editWin, buf->data, buf->pos); |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
350 wattrset(editWin, A_REVERSE); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
351 waddch(editWin, buf->data[buf->pos]); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
352 wattrset(editWin, A_NORMAL); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
353 waddnstr(editWin, buf->data + buf->pos + 1, buf->len - buf->pos - 1); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
354 } else { |
30 | 355 waddnstr(editWin, buf->data, buf->len); |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
356 wattrset(editWin, A_REVERSE); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
357 waddch(editWin, ' '); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
358 wattrset(editWin, A_NORMAL); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
359 } |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
360 wrefresh(editWin); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
361 } |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
362 |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
363 int printWin(WINDOW *win, const char *fmt) |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
364 { |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
365 const char *s = fmt; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
366 int col = 0; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
367 |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
368 while (*s) { |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
369 if (*s == '½') { |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
370 int val = 0; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
371 s++; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
372 if (*s == '½') { |
55
5ec3b7d14715
Add typecasts to fix printing of 8-bit characters.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
373 waddch(win, ((unsigned char) *s) | col); |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
374 s++; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
375 } else { |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
376 while (*s && isdigit(*s)) { |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
377 val *= 10; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
378 val += (*s - '0'); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
379 s++; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
380 } |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
381 if (*s != '½') return -1; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
382 s++; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
383 |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
384 if (val < 9) { |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
385 col = A_DIM | COLOR_PAIR(val); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
386 } else if (val < 30) { |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
387 col = A_BOLD | COLOR_PAIR(val - 9); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
388 } |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
389 } |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
390 } else { |
55
5ec3b7d14715
Add typecasts to fix printing of 8-bit characters.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
391 waddch(win, ((unsigned char) *s) | col); |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
392 s++; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
393 } |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
394 } |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
395 return 0; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
396 } |
0 | 397 |
62
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
398 |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
399 int printFile(FILE *outFile, const char *fmt) |
0 | 400 { |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
401 const char *s = fmt; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
402 |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
403 while (*s) { |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
404 if (*s == '½') { |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
405 s++; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
406 if (*s == '½') { |
58 | 407 fputc((unsigned char) *s, outFile); |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
408 s++; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
409 } else { |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
410 while (*s && isdigit(*s)) s++; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
411 if (*s != '½') return -1; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
412 s++; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
413 } |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
414 } else { |
58 | 415 fputc((unsigned char) *s, outFile); |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
416 s++; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
417 } |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
418 } |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
419 |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
420 return 0; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
421 } |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
422 |
62
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
423 |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
424 void printMsg(char *fmt, ...) |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
425 { |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
426 char tmpStr[128] = "", buf[8192]; |
0 | 427 va_list ap; |
428 time_t timeStamp; | |
429 struct tm *tmpTime;; | |
430 | |
431 timeStamp = time(NULL); | |
432 if ((tmpTime = localtime(&timeStamp)) != NULL) { | |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
433 strftime(tmpStr, sizeof(tmpStr), "½17½[½11½%H:%M:%S½17½]½0½ ", tmpTime); |
0 | 434 } |
435 | |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
436 va_start(ap, fmt); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
437 vsnprintf(buf, sizeof(buf), fmt, ap); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
438 va_end(ap); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
439 |
0 | 440 if (optLogFile) { |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
441 printFile(optLogFile, tmpStr); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
442 printFile(optLogFile, buf); |
0 | 443 fflush(optLogFile); |
444 } | |
445 | |
21 | 446 if (!optDaemon) { |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
447 printWin(mainWin, tmpStr); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
448 printWin(mainWin, buf); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
449 wrefresh(mainWin); |
21 | 450 } |
0 | 451 } |
452 | |
453 | |
454 int handleUser(int sock, char *str) | |
455 { | |
456 const char *msg = "</USER><MESSAGE>"; | |
22 | 457 char *p = str, *q, *s, *t, *h; |
0 | 458 |
459 (void) sock; | |
460 | |
461 s = strstr(str, msg); | |
462 if (!s) return 1; | |
463 *s = 0; | |
464 s += strlen(msg); | |
465 | |
466 q = strstr(s, "</MESSAGE>"); | |
467 if (!q) return 3; | |
468 *q = 0; | |
469 | |
470 s = decodeStr1(s); | |
471 if (!s) return -1; | |
472 | |
473 p = decodeStr1(p); | |
474 if (!p) { | |
475 th_free(s); | |
476 return -2; | |
477 } | |
478 | |
479 | |
480 if (*s == '/') { | |
62
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
481 t = stripXMLTags(s + 1); |
40 | 482 if (!strncmp(t, "BPRV", 4)) { |
483 h = decodeStr2(t + 1); | |
484 printMsg("½11½%s½0½\n", h); | |
485 } else { | |
22 | 486 h = decodeStr2(t); |
40 | 487 printMsg("½9½* %s½0½\n", h); |
19 | 488 } |
22 | 489 th_free(h); |
0 | 490 th_free(t); |
491 } else { | |
63 | 492 BOOL isMine = strcmp(p, optUserName) == 0; |
62
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
493 t = stripXMLTags(s); |
22 | 494 h = decodeStr2(t); |
63 | 495 printMsg("½5½<½%d½%s½5½>½%d½ %s½0½\n", |
496 isMine ? 14 : 15, p, isMine ? 16 : 0, h); | |
22 | 497 th_free(h); |
0 | 498 th_free(t); |
499 } | |
500 | |
501 th_free(s); | |
502 th_free(p); | |
503 return 0; | |
504 } | |
505 | |
506 | |
507 int handleLogin(int sock, char *str) | |
508 { | |
19 | 509 char tmpStr[256] = ""; |
510 time_t timeStamp; | |
511 struct tm *tmpTime;; | |
512 | |
513 timeStamp = time(NULL); | |
514 if ((tmpTime = localtime(&timeStamp)) != NULL) { | |
515 strftime(tmpStr, sizeof(tmpStr), "%c", tmpTime); | |
516 } | |
517 | |
0 | 518 if (!strncmp(str, "FAILURE", 7)) { |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
519 printMsg("½1½Login failure½0½ - ½3½%s½0½\n", tmpStr); |
0 | 520 return -2; |
521 } else if (!strncmp(str, "SUCCESS", 7)) { | |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
522 printMsg("½2½Login success½0½ - ½3½%s½0½\n", tmpStr); |
13
86fe5f0d1a85
Cleanups; Added probing connection (requesting some policy crap) to emulate the official client.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
523 sendUserMsg(sock, optUserName2, "%%2FRequestUserList"); |
0 | 524 return 0; |
525 } else | |
526 return 1; | |
527 } | |
528 | |
529 | |
530 int handleAddUser(int sock, char *str) | |
531 { | |
9 | 532 char *p, *s = strstr(str, "</ADD_USER>"); |
0 | 533 |
534 (void) sock; | |
535 | |
536 if (!s) return 1; | |
537 *s = 0; | |
9 | 538 |
539 p = decodeStr1(str); | |
540 if (!p) return -1; | |
541 | |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
542 printMsg("! ½3½%s½0½ ½2½ADDED.½0½\n", p); |
9 | 543 th_free(p); |
0 | 544 return 0; |
545 } | |
546 | |
547 | |
548 int handleDeleteUser(int sock, char *str) | |
549 { | |
9 | 550 char *p, *s = strstr(str, "</DELETE_USER>"); |
0 | 551 |
552 (void) sock; | |
553 | |
554 if (!s) return 1; | |
555 *s = 0; | |
9 | 556 |
557 p = decodeStr1(str); | |
558 if (!p) return -1; | |
559 | |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
560 printMsg("! ½3½%s½0½ ½1½DELETED.½0½\n", p); |
9 | 561 th_free(p); |
0 | 562 return 0; |
563 } | |
564 | |
565 | |
566 int handleFoo(int sock, char *str) | |
567 { | |
568 (void) sock; (void) str; | |
569 | |
570 return 0; | |
571 } | |
572 | |
573 | |
574 typedef struct { | |
575 char *cmd; | |
576 int (*handler)(int, char *); | |
577 } protocmd_t; | |
578 | |
579 | |
580 protocmd_t protoCmds[] = { | |
581 { "<USER>", handleUser }, | |
582 { "<LOGIN_", handleLogin }, | |
583 { "<DELETE_USER>", handleDeleteUser }, | |
584 { "<ADD_USER>", handleAddUser }, | |
585 { "<NUMCLIENTS>", handleFoo }, | |
586 }; | |
587 | |
43
40ba8cdcf03a
Cleanups, added a silly morse code conversion mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
588 const int nprotoCmds = (sizeof(protoCmds) / sizeof(protoCmds[0])); |
0 | 589 |
590 | |
51
cf7789d88350
Fix the input packet handling to properly handle packets with multiple
Matti Hamalainen <ccr@tnsp.org>
parents:
50
diff
changeset
|
591 int handleProtocol(const int sock, char *buf, size_t bufLen) |
0 | 592 { |
593 int i; | |
594 | |
595 for (i = 0; i < nprotoCmds; i++) { | |
596 size_t cmdLen = strlen(protoCmds[i].cmd); | |
597 if (cmdLen < bufLen && !strncmp(buf, protoCmds[i].cmd, cmdLen)) { | |
598 return protoCmds[i].handler(sock, buf + cmdLen); | |
599 } | |
600 } | |
601 | |
602 return 1; | |
603 } | |
604 | |
605 | |
51
cf7789d88350
Fix the input packet handling to properly handle packets with multiple
Matti Hamalainen <ccr@tnsp.org>
parents:
50
diff
changeset
|
606 int handleUserInput(const int sock, char *buf, size_t bufLen) |
0 | 607 { |
25
3b67a9a806a7
Added /color command to change colour.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
608 char *tmpStr, *tmpStr2, tmpBuf[4096]; |
0 | 609 BOOL result; |
610 | |
611 /* Trim right */ | |
612 buf[--bufLen] = 0; | |
613 while (bufLen > 0 && (buf[bufLen] == '\n' || buf[bufLen] == '\r' || th_isspace(buf[bufLen]))) | |
614 buf[bufLen--] = 0; | |
615 | |
616 /* Check command */ | |
617 if (*buf == 0) { | |
618 return 1; | |
25
3b67a9a806a7
Added /color command to change colour.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
619 } else if (!strncmp(buf, "/color ", 7)) { |
30 | 620 int tmpInt; |
621 if ((tmpInt = getColor(buf+7)) < 0) { | |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
622 printMsg("Invalid color value '%s'\n", buf+7); |
25
3b67a9a806a7
Added /color command to change colour.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
623 return 1; |
3b67a9a806a7
Added /color command to change colour.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
624 } |
30 | 625 optUserColor = tmpInt; |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
626 printMsg("Setting color to #%06x\n", optUserColor); |
25
3b67a9a806a7
Added /color command to change colour.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
627 sendUserMsg(sock, optUserName2, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor); |
3b67a9a806a7
Added /color command to change colour.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
628 return 0; |
27 | 629 } else if (!strncmp(buf, "/flood ", 7)) { |
630 int i; | |
631 | |
632 snprintf(tmpBuf, sizeof(tmpBuf), "/prv -to %s -msg . .", | |
633 buf+7); | |
634 | |
635 tmpStr = encodeStr2(tmpBuf); | |
636 if (!tmpStr) return -2; | |
637 tmpStr2 = encodeStr1(tmpStr); | |
638 if (!tmpStr2) { | |
639 th_free(tmpStr); | |
640 return -3; | |
641 } | |
642 | |
643 result = TRUE; | |
644 for (i = 0; i < 50 && result; i++) { | |
645 result = sendUserMsg(sock, optUserName2, "%s", tmpStr2); | |
646 usleep(250); | |
647 } | |
648 | |
649 th_free(tmpStr); | |
650 th_free(tmpStr2); | |
651 return 0; | |
30 | 652 } else if (!strncmp(buf, "/to ", 4)) { |
653 th_free(setTarget); | |
50
d08bf3b6561d
Use strdup; Added function to decode morse code.
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
654 setTarget = strdup(buf + 4); |
30 | 655 printMsg("Set prv target to '%s'\n", setTarget); |
656 return 0; | |
657 } else if (setPrvMode) { | |
658 if (setTarget != NULL) { | |
659 snprintf(tmpBuf, sizeof(tmpBuf), "/prv -to %s -msg %s", setTarget, buf); | |
660 buf = tmpBuf; | |
661 } else { | |
662 printMsg("No target set, exiting prv mode.\n"); | |
663 setPrvMode = FALSE; | |
664 return 1; | |
665 } | |
24
78d260256450
Added two simple commands to simplify private chatting, "/to" and "/msg".
Matti Hamalainen <ccr@tnsp.org>
parents:
23
diff
changeset
|
666 } |
78d260256450
Added two simple commands to simplify private chatting, "/to" and "/msg".
Matti Hamalainen <ccr@tnsp.org>
parents:
23
diff
changeset
|
667 |
43
40ba8cdcf03a
Cleanups, added a silly morse code conversion mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
668 |
40ba8cdcf03a
Cleanups, added a silly morse code conversion mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
669 /* Send double-encoded */ |
40ba8cdcf03a
Cleanups, added a silly morse code conversion mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
670 tmpStr = encodeStr2(buf); |
40ba8cdcf03a
Cleanups, added a silly morse code conversion mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
671 if (!tmpStr) return -2; |
40ba8cdcf03a
Cleanups, added a silly morse code conversion mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
672 tmpStr2 = encodeStr1(tmpStr); |
40ba8cdcf03a
Cleanups, added a silly morse code conversion mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
673 if (!tmpStr2) { |
0 | 674 th_free(tmpStr); |
43
40ba8cdcf03a
Cleanups, added a silly morse code conversion mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
675 return -3; |
0 | 676 } |
43
40ba8cdcf03a
Cleanups, added a silly morse code conversion mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
677 |
40ba8cdcf03a
Cleanups, added a silly morse code conversion mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
678 result = sendUserMsg(sock, optUserName2, "%s", tmpStr2); |
40ba8cdcf03a
Cleanups, added a silly morse code conversion mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
679 th_free(tmpStr); |
40ba8cdcf03a
Cleanups, added a silly morse code conversion mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
680 th_free(tmpStr2); |
40ba8cdcf03a
Cleanups, added a silly morse code conversion mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
681 if (result) |
40ba8cdcf03a
Cleanups, added a silly morse code conversion mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
682 return 0; |
40ba8cdcf03a
Cleanups, added a silly morse code conversion mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
683 else |
40ba8cdcf03a
Cleanups, added a silly morse code conversion mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
684 return -1; |
0 | 685 } |
686 | |
687 | |
46
65b1ac6a1e2e
Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
688 BOOL initializeWindows(void) |
65b1ac6a1e2e
Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
689 { |
65b1ac6a1e2e
Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
690 if (mainWin) delwin(mainWin); |
65b1ac6a1e2e
Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
691 if (statusWin) delwin(statusWin); |
65b1ac6a1e2e
Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
692 if (editWin) delwin(editWin); |
65b1ac6a1e2e
Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
693 |
65b1ac6a1e2e
Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
694 mainWin = newwin(LINES - 4, COLS, 0, 0); |
65b1ac6a1e2e
Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
695 statusWin = newwin(1, COLS, LINES - 4, 0); |
65b1ac6a1e2e
Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
696 editWin = newwin(3, COLS, LINES - 3, 0); |
65b1ac6a1e2e
Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
697 |
65b1ac6a1e2e
Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
698 if (mainWin == NULL || statusWin == NULL || editWin == NULL) { |
65b1ac6a1e2e
Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
699 THERR("Could not create ncurses windows!\n"); |
65b1ac6a1e2e
Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
700 return FALSE; |
65b1ac6a1e2e
Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
701 } |
65b1ac6a1e2e
Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
702 scrollok(mainWin, 1); |
65b1ac6a1e2e
Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
703 |
65b1ac6a1e2e
Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
704 return TRUE; |
65b1ac6a1e2e
Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
705 } |
65b1ac6a1e2e
Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
706 |
65b1ac6a1e2e
Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
707 |
0 | 708 int main(int argc, char *argv[]) |
709 { | |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
710 int tmpSocket, curVis, updateCount = 0; |
0 | 711 struct hostent *tmpHost; |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
712 BOOL argsOK, isError = FALSE, |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
713 exitProg = FALSE, |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
714 colorSet = FALSE, |
30 | 715 cursesInit = FALSE, |
716 insertMode = TRUE; | |
13
86fe5f0d1a85
Cleanups; Added probing connection (requesting some policy crap) to emulate the official client.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
717 struct timeval tv; |
86fe5f0d1a85
Cleanups; Added probing connection (requesting some policy crap) to emulate the official client.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
718 fd_set sockfds; |
86fe5f0d1a85
Cleanups; Added probing connection (requesting some policy crap) to emulate the official client.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
719 char *tmpStr; |
31
9b429b283786
Add command history functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
720 editbuf_t *editBuf = newBuf(SET_BUFSIZE); |
30 | 721 editbuf_t *histBuf[SET_MAX_HISTORY+2]; |
722 int histPos = 0, histMax = 0; | |
723 | |
724 memset(histBuf, 0, sizeof(histBuf)); | |
725 | |
0 | 726 /* Initialize */ |
61 | 727 th_init("NNChat", "Newbie Nudes chat client", "0.6.5", |
6
526ba3b578d7
Changed copyright etc. again.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
728 "Written and designed by Anonymous Finnish Guy (C) 2008", |
526ba3b578d7
Changed copyright etc. again.
Matti Hamalainen <ccr@tnsp.org>
parents:
4
diff
changeset
|
729 "This software is freeware, use and distribute as you wish."); |
0 | 730 th_verbosityLevel = 0; |
731 | |
732 /* Parse arguments */ | |
26
b84fc46c6035
Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
733 argsOK = th_args_process(argc, argv, optList, optListN, |
0 | 734 argHandleOpt, argHandleFile, FALSE); |
26
b84fc46c6035
Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
735 |
0 | 736 /* Check the mode and arguments */ |
737 if (optUserName == NULL || optPassword == NULL) { | |
738 THERR("User/pass not specified, get some --help\n"); | |
739 return -1; | |
740 } | |
741 | |
26
b84fc46c6035
Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
742 if (!argsOK) |
b84fc46c6035
Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
743 return -2; |
b84fc46c6035
Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
744 |
0 | 745 /* Open logfile */ |
746 if (optLogFilename) { | |
747 THMSG(1, "Opening logfile '%s'\n", optLogFilename); | |
748 | |
749 if ((optLogFile = fopen(optLogFilename, "a")) == NULL) { | |
750 THERR("Could not open logfile for appending!\n"); | |
751 return -9; | |
752 } | |
753 } | |
754 | |
755 /* Okay ... */ | |
756 THMSG(1, "Trying to resolve host '%s' ...\n", optServer); | |
757 tmpHost = gethostbyname(optServer); | |
758 if (tmpHost == NULL) { | |
759 THERR("Could not resolve hostname: %s.\n", | |
760 hstrerror(h_errno)); | |
761 return -3; | |
762 } | |
763 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
|
764 |
39 | 765 #if 0 |
62
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
766 /* To emulate the official client, we first make a request for |
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
767 * policy file, even though we don't use it for anything... |
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
768 */ |
13
86fe5f0d1a85
Cleanups; Added probing connection (requesting some policy crap) to emulate the official client.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
769 if ((tmpSocket = openConnection((struct in_addr *) tmpHost->h_addr, optPort)) < 0) { |
62
ff5d74f0d428
Moved some functions to "libnnchat".
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
770 THERR("Policy file request connection setup failed!\n"); |
13
86fe5f0d1a85
Cleanups; Added probing connection (requesting some policy crap) to emulate the official client.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
771 goto err_exit; |
0 | 772 } |
773 | |
13
86fe5f0d1a85
Cleanups; Added probing connection (requesting some policy crap) to emulate the official client.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
774 tmpStr = "<policy-file-request/>"; |
23
40fecbab1dc1
Check for error condition properly.
Matti Hamalainen <ccr@tnsp.org>
parents:
22
diff
changeset
|
775 if (sendToSocket(tmpSocket, tmpStr, strlen(tmpStr) + 1) == FALSE) { |
13
86fe5f0d1a85
Cleanups; Added probing connection (requesting some policy crap) to emulate the official client.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
776 THERR("Failed to send fakeprobe.\n"); |
86fe5f0d1a85
Cleanups; Added probing connection (requesting some policy crap) to emulate the official client.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
777 goto err_exit; |
86fe5f0d1a85
Cleanups; Added probing connection (requesting some policy crap) to emulate the official client.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
778 } else { |
86fe5f0d1a85
Cleanups; Added probing connection (requesting some policy crap) to emulate the official client.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
779 ssize_t gotBuf; |
86fe5f0d1a85
Cleanups; Added probing connection (requesting some policy crap) to emulate the official client.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
780 char tmpBuf[4096]; |
86fe5f0d1a85
Cleanups; Added probing connection (requesting some policy crap) to emulate the official client.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
781 gotBuf = recv(tmpSocket, tmpBuf, sizeof(tmpBuf), 0); |
86fe5f0d1a85
Cleanups; Added probing connection (requesting some policy crap) to emulate the official client.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
782 tmpBuf[gotBuf-1] = 0; |
86fe5f0d1a85
Cleanups; Added probing connection (requesting some policy crap) to emulate the official client.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
783 THMSG(2, "Probe got: %s\n", tmpBuf); |
86fe5f0d1a85
Cleanups; Added probing connection (requesting some policy crap) to emulate the official client.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
784 closeConnection(tmpSocket); |
0 | 785 } |
39 | 786 #endif |
26
b84fc46c6035
Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
787 |
13
86fe5f0d1a85
Cleanups; Added probing connection (requesting some policy crap) to emulate the official client.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
788 /* Okay, now do the proper connection ... */ |
86fe5f0d1a85
Cleanups; Added probing connection (requesting some policy crap) to emulate the official client.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
789 if ((tmpSocket = openConnection((struct in_addr *) tmpHost->h_addr, optPort)) < 0) { |
86fe5f0d1a85
Cleanups; Added probing connection (requesting some policy crap) to emulate the official client.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
790 THERR("Main connection setup failed!\n"); |
86fe5f0d1a85
Cleanups; Added probing connection (requesting some policy crap) to emulate the official client.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
791 goto err_exit; |
86fe5f0d1a85
Cleanups; Added probing connection (requesting some policy crap) to emulate the official client.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
792 } |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
793 |
33
e49ea6febfeb
Cleanups. Added option to specify/fake "site" where logging in from.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
794 THMSG(1, "Connected, logging in as '%s', site '%s'.\n", optUserName, optSite); |
0 | 795 optUserName2 = encodeStr1(optUserName); |
33
e49ea6febfeb
Cleanups. Added option to specify/fake "site" where logging in from.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
796 tmpStr = encodeStr1(optSite); |
e49ea6febfeb
Cleanups. Added option to specify/fake "site" where logging in from.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
797 sendUserMsg(tmpSocket, optUserName2, "%%2Flogin%%20%%2Dsite%%20%s%%20%%2Dpassword%%20%s", tmpStr, optPassword); |
e49ea6febfeb
Cleanups. Added option to specify/fake "site" where logging in from.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
798 th_free(tmpStr); |
0 | 799 |
33
e49ea6febfeb
Cleanups. Added option to specify/fake "site" where logging in from.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
800 /* Initialize NCurses */ |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
801 if (!optDaemon) { |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
802 initscr(); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
803 raw(); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
804 keypad(stdscr, TRUE); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
805 noecho(); |
50
d08bf3b6561d
Use strdup; Added function to decode morse code.
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
806 meta(stdscr, TRUE); |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
807 timeout(SET_DELAY); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
808 curVis = curs_set(0); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
809 if (has_colors()) { |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
810 start_color(); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
811 |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
812 init_pair(1, COLOR_RED, COLOR_BLACK); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
813 init_pair(2, COLOR_GREEN, COLOR_BLACK); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
814 init_pair(3, COLOR_YELLOW, COLOR_BLACK); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
815 init_pair(4, COLOR_BLUE, COLOR_BLACK); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
816 init_pair(5, COLOR_MAGENTA, COLOR_BLACK); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
817 init_pair(6, COLOR_CYAN, COLOR_BLACK); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
818 init_pair(7, COLOR_WHITE, COLOR_BLACK); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
819 init_pair(8, COLOR_BLACK, COLOR_BLACK); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
820 |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
821 init_pair(10, COLOR_BLACK, COLOR_RED); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
822 init_pair(11, COLOR_WHITE, COLOR_RED); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
823 init_pair(12, COLOR_GREEN, COLOR_RED); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
824 init_pair(13, COLOR_YELLOW, COLOR_RED); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
825 init_pair(14, COLOR_BLUE, COLOR_RED); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
826 init_pair(15, COLOR_MAGENTA, COLOR_RED); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
827 init_pair(16, COLOR_CYAN, COLOR_RED); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
828 |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
829 } |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
830 |
46
65b1ac6a1e2e
Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
831 cursesInit = TRUE; |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
832 |
46
65b1ac6a1e2e
Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
833 if (!initializeWindows()) |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
834 goto err_exit; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
835 |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
836 clearBuf(editBuf); |
30 | 837 printEditBuf("", editBuf); |
838 updateStatus(insertMode); | |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
839 } |
30 | 840 |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
841 |
30 | 842 /* Enter mainloop */ |
0 | 843 FD_ZERO(&sockfds); |
844 FD_SET(tmpSocket, &sockfds); | |
845 | |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
846 while (!isError && !exitProg) { |
0 | 847 int result; |
848 fd_set tmpfds; | |
849 | |
850 /* Check for incoming data from the server */ | |
851 tv.tv_sec = 0; | |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
852 tv.tv_usec = SET_DELAY_USEC; |
0 | 853 tmpfds = sockfds; |
854 if ((result = select(tmpSocket+1, &tmpfds, NULL, NULL, &tv)) == -1) { | |
53 | 855 if (errno != EINTR && errno != ERESTART) { |
856 printMsg("Error occured in select(sockfds): %d, %s\n", errno, strerror(errno)); | |
857 isError = TRUE; | |
858 } | |
0 | 859 } else if (FD_ISSET(tmpSocket, &tmpfds)) { |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
860 ssize_t gotBuf; |
30 | 861 char tmpBuf[8192]; |
51
cf7789d88350
Fix the input packet handling to properly handle packets with multiple
Matti Hamalainen <ccr@tnsp.org>
parents:
50
diff
changeset
|
862 char *bufPtr = tmpBuf; |
0 | 863 gotBuf = recv(tmpSocket, tmpBuf, sizeof(tmpBuf), 0); |
864 | |
865 if (gotBuf < 0) { | |
9 | 866 printMsg("Error in recv: %s\n", strerror(errno)); |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
867 isError = TRUE; |
0 | 868 } else if (gotBuf == 0) { |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
869 printMsg("Server closed connection.\n"); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
870 isError = TRUE; |
0 | 871 } else { |
872 /* Handle protocol data */ | |
873 tmpBuf[gotBuf] = 0; | |
51
cf7789d88350
Fix the input packet handling to properly handle packets with multiple
Matti Hamalainen <ccr@tnsp.org>
parents:
50
diff
changeset
|
874 do { |
cf7789d88350
Fix the input packet handling to properly handle packets with multiple
Matti Hamalainen <ccr@tnsp.org>
parents:
50
diff
changeset
|
875 size_t bufLen = strlen(bufPtr) + 1; |
cf7789d88350
Fix the input packet handling to properly handle packets with multiple
Matti Hamalainen <ccr@tnsp.org>
parents:
50
diff
changeset
|
876 result = handleProtocol(tmpSocket, bufPtr, bufLen); |
0 | 877 |
51
cf7789d88350
Fix the input packet handling to properly handle packets with multiple
Matti Hamalainen <ccr@tnsp.org>
parents:
50
diff
changeset
|
878 if (result > 0) { |
cf7789d88350
Fix the input packet handling to properly handle packets with multiple
Matti Hamalainen <ccr@tnsp.org>
parents:
50
diff
changeset
|
879 /* Couldn't handle the message for some reason */ |
cf7789d88350
Fix the input packet handling to properly handle packets with multiple
Matti Hamalainen <ccr@tnsp.org>
parents:
50
diff
changeset
|
880 printMsg("Could not handle: %s\n", tmpBuf); |
cf7789d88350
Fix the input packet handling to properly handle packets with multiple
Matti Hamalainen <ccr@tnsp.org>
parents:
50
diff
changeset
|
881 } else if (result < 0) { |
cf7789d88350
Fix the input packet handling to properly handle packets with multiple
Matti Hamalainen <ccr@tnsp.org>
parents:
50
diff
changeset
|
882 /* Fatal error, quit */ |
cf7789d88350
Fix the input packet handling to properly handle packets with multiple
Matti Hamalainen <ccr@tnsp.org>
parents:
50
diff
changeset
|
883 printMsg("Fatal error with message: %s\n", tmpBuf); |
cf7789d88350
Fix the input packet handling to properly handle packets with multiple
Matti Hamalainen <ccr@tnsp.org>
parents:
50
diff
changeset
|
884 isError = TRUE; |
cf7789d88350
Fix the input packet handling to properly handle packets with multiple
Matti Hamalainen <ccr@tnsp.org>
parents:
50
diff
changeset
|
885 } |
cf7789d88350
Fix the input packet handling to properly handle packets with multiple
Matti Hamalainen <ccr@tnsp.org>
parents:
50
diff
changeset
|
886 |
cf7789d88350
Fix the input packet handling to properly handle packets with multiple
Matti Hamalainen <ccr@tnsp.org>
parents:
50
diff
changeset
|
887 gotBuf -= bufLen; |
cf7789d88350
Fix the input packet handling to properly handle packets with multiple
Matti Hamalainen <ccr@tnsp.org>
parents:
50
diff
changeset
|
888 bufPtr += bufLen; |
cf7789d88350
Fix the input packet handling to properly handle packets with multiple
Matti Hamalainen <ccr@tnsp.org>
parents:
50
diff
changeset
|
889 } while (gotBuf > 0 && !isError); |
30 | 890 updateStatus(insertMode); |
0 | 891 } |
892 } | |
893 | |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
894 /* Handle user input */ |
21 | 895 if (!optDaemon) { |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
896 int c, cnt = 0; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
897 BOOL update = FALSE; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
898 |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
899 /* Handle several buffered keypresses at once */ |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
900 do { |
50
d08bf3b6561d
Use strdup; Added function to decode morse code.
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
901 c = wgetch(stdscr); |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
902 switch (c) { |
46
65b1ac6a1e2e
Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
903 case KEY_RESIZE: |
65b1ac6a1e2e
Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
904 if (!initializeWindows()) { |
65b1ac6a1e2e
Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
905 THERR("Error resizing ncurses windows\n"); |
65b1ac6a1e2e
Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
906 isError = TRUE; |
65b1ac6a1e2e
Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
907 } |
65b1ac6a1e2e
Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
908 break; |
65b1ac6a1e2e
Support for resizing the terminal on fly. Not perfect, but works.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
909 |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
910 case KEY_ENTER: |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
911 case '\n': |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
912 case '\r': |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
913 /* Call the user input handler */ |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
914 if (editBuf->len > 0) { |
30 | 915 |
916 if (histMax > 0) { | |
31
9b429b283786
Add command history functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
917 freeBuf(histBuf[SET_MAX_HISTORY+1]); |
9b429b283786
Add command history functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
918 histBuf[SET_MAX_HISTORY+1] = NULL; |
30 | 919 memmove(&histBuf[2], &histBuf[1], histMax * sizeof(histBuf[0])); |
920 } | |
31
9b429b283786
Add command history functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
921 |
30 | 922 histPos = 0; |
923 histBuf[1] = copyBuf(editBuf); | |
924 if (histMax < SET_MAX_HISTORY) histMax++; | |
925 | |
34
f5d335771b16
Fix a bug with mixed editBuf->pos vs editBuf->len.
Matti Hamalainen <ccr@tnsp.org>
parents:
33
diff
changeset
|
926 insertBuf(editBuf, editBuf->len, 0); |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
927 result = handleUserInput(tmpSocket, editBuf->data, editBuf->len); |
30 | 928 |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
929 clearBuf(editBuf); |
30 | 930 |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
931 if (result < 0) { |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
932 printMsg("Fatal error handling user input: %s\n", editBuf->data); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
933 isError = TRUE; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
934 } |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
935 |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
936 update = TRUE; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
937 } |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
938 break; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
939 |
30 | 940 case 0x09: /* Tab = switch between PRV */ |
941 if (setPrvMode) | |
942 setPrvMode = FALSE; | |
943 else { | |
944 if (setTarget != NULL) | |
945 setPrvMode = TRUE; | |
946 } | |
947 update = TRUE; | |
948 break; | |
949 | |
54 | 950 case KEY_UP: /* Backwards in input history */ |
31
9b429b283786
Add command history functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
951 if (histPos == 0) { |
9b429b283786
Add command history functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
952 freeBuf(histBuf[0]); |
30 | 953 histBuf[0] = copyBuf(editBuf); |
31
9b429b283786
Add command history functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
954 } |
30 | 955 if (histPos < histMax) { |
956 histPos++; | |
957 freeBuf(editBuf); | |
958 editBuf = copyBuf(histBuf[histPos]); | |
959 update = TRUE; | |
960 } | |
961 break; | |
962 | |
54 | 963 case KEY_DOWN: /* Forwards in input history */ |
30 | 964 if (histPos > 0) { |
965 histPos--; | |
966 freeBuf(editBuf); | |
967 editBuf = copyBuf(histBuf[histPos]); | |
968 update = TRUE; | |
969 } | |
970 break; | |
971 | |
54 | 972 case 0x204: /* ctrl+left = Skip words left */ |
45
ceec75116aa7
Improved editing commands ctrl+<left/right>
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
973 while (editBuf->pos > 0 && isspace(editBuf->data[editBuf->pos - 1])) |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
974 editBuf->pos--; |
45
ceec75116aa7
Improved editing commands ctrl+<left/right>
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
975 while (editBuf->pos > 0 && !isspace(editBuf->data[editBuf->pos - 1])) |
ceec75116aa7
Improved editing commands ctrl+<left/right>
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
976 editBuf->pos--; |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
977 update = TRUE; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
978 break; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
979 |
54 | 980 case 0x206: /* ctrl+right = Skip words right */ |
45
ceec75116aa7
Improved editing commands ctrl+<left/right>
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
981 while (editBuf->pos < editBuf->len && isspace(editBuf->data[editBuf->pos])) |
ceec75116aa7
Improved editing commands ctrl+<left/right>
Matti Hamalainen <ccr@tnsp.org>
parents:
43
diff
changeset
|
982 editBuf->pos++; |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
983 while (editBuf->pos < editBuf->len && !isspace(editBuf->data[editBuf->pos])) |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
984 editBuf->pos++; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
985 if (editBuf->pos > editBuf->len) |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
986 editBuf->pos = editBuf->len; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
987 update = TRUE; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
988 break; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
989 |
54 | 990 case 0x111: /* F9 = Quit */ |
33
e49ea6febfeb
Cleanups. Added option to specify/fake "site" where logging in from.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
991 printMsg("Quitting per user request.\n"); |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
992 exitProg = TRUE; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
993 break; |
0 | 994 |
54 | 995 case 0x109: /* F1 = Toggle insert / overwrite mode */ |
43
40ba8cdcf03a
Cleanups, added a silly morse code conversion mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
996 insertMode = !insertMode; |
40ba8cdcf03a
Cleanups, added a silly morse code conversion mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
997 update = TRUE; |
40ba8cdcf03a
Cleanups, added a silly morse code conversion mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
998 break; |
40ba8cdcf03a
Cleanups, added a silly morse code conversion mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
999 |
54 | 1000 case 0x10a: /* F2 = Clear editbuffer */ |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1001 clearBuf(editBuf); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1002 update = TRUE; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1003 break; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1004 |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1005 case KEY_HOME: setBufPos(editBuf, 0); update = TRUE; break; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1006 case KEY_END: setBufPos(editBuf, editBuf->len); update = TRUE; break; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1007 case KEY_LEFT: setBufPos(editBuf, editBuf->pos - 1); update = TRUE; break; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1008 case KEY_RIGHT: setBufPos(editBuf, editBuf->pos + 1); update = TRUE; break; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1009 |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1010 case KEY_BACKSPACE: |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1011 deleteBuf(editBuf, editBuf->pos - 1); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1012 setBufPos(editBuf, editBuf->pos - 1); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1013 update = TRUE; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1014 break; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1015 |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1016 case 0x14a: |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1017 /* Delete */ |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1018 deleteBuf(editBuf, editBuf->pos); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1019 update = TRUE; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1020 break; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1021 |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1022 case 0x0c: |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1023 /* ctrl+l */ |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1024 redrawwin(mainWin); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1025 redrawwin(statusWin); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1026 redrawwin(editWin); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1027 break; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1028 |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1029 case ERR: |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1030 /* Ignore */ |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1031 break; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1032 |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1033 default: |
36 | 1034 if (isprint(c) || c == 0xe4 || c == 0xf6 || c == 0xc4 || c == 0xd6) { |
30 | 1035 if (insertMode) |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1036 insertBuf(editBuf, editBuf->pos, c); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1037 else |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1038 writeBuf(editBuf, editBuf->pos, c); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1039 setBufPos(editBuf, editBuf->pos + 1); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1040 update = TRUE; |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1041 } else { |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1042 printMsg("Unhandled key: %02x\n", c); |
0 | 1043 } |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1044 break; |
0 | 1045 } |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1046 } while (c != ERR && !exitProg && ++cnt < 10); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1047 |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1048 if (update) { |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1049 /* Update edit line */ |
30 | 1050 printEditBuf(setPrvMode ? setTarget : "", editBuf); |
1051 updateStatus(insertMode); | |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1052 } |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1053 } /* !optDaemon */ |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1054 |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1055 if (++updateCount > 10) { |
30 | 1056 updateStatus(insertMode); |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1057 updateCount = 0; |
0 | 1058 } |
1059 | |
13
86fe5f0d1a85
Cleanups; Added probing connection (requesting some policy crap) to emulate the official client.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
1060 if (!colorSet) { |
86fe5f0d1a85
Cleanups; Added probing connection (requesting some policy crap) to emulate the official client.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
1061 colorSet = TRUE; |
30 | 1062 printMsg("%s v%s - %s\n", th_prog_name, th_prog_version, th_prog_fullname); |
1063 printMsg("%s\n", th_prog_author); | |
1064 printMsg("%s\n", th_prog_license); | |
27 | 1065 sendUserMsg(tmpSocket, optUserName2, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor); |
13
86fe5f0d1a85
Cleanups; Added probing connection (requesting some policy crap) to emulate the official client.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
1066 } |
0 | 1067 } |
1068 | |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1069 /* 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
|
1070 err_exit: |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1071 if (cursesInit) { |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1072 if (curVis != ERR) |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1073 curs_set(curVis); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1074 endwin(); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1075 THMSG(1, "NCurses deinitialized.\n"); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1076 } |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1077 |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1078 if (isError) { |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1079 THMSG(1, "Error exit.\n"); |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1080 } |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
1081 |
0 | 1082 th_free(optUserName2); |
10 | 1083 |
13
86fe5f0d1a85
Cleanups; Added probing connection (requesting some policy crap) to emulate the official client.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
1084 closeConnection(tmpSocket); |
86fe5f0d1a85
Cleanups; Added probing connection (requesting some policy crap) to emulate the official client.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
1085 |
86fe5f0d1a85
Cleanups; Added probing connection (requesting some policy crap) to emulate the official client.
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
1086 THMSG(1, "Connection terminated.\n"); |
0 | 1087 |
1088 if (optLogFile) { | |
1089 THMSG(1, "Closing logfile.\n"); | |
1090 fclose(optLogFile); | |
1091 } | |
1092 | |
1093 return 0; | |
1094 } |