Mercurial > hg > nnchat
annotate main.c @ 698:28fe6a1be852
Adjust to th-libs th_args_help() API change.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 12 Jan 2020 20:28:35 +0200 |
parents | adac0e9f2810 |
children | e9232ce52bf8 |
rev | line source |
---|---|
41 | 1 /* |
2 * NNChat - Custom chat client for NewbieNudes.com chatrooms | |
39 | 3 * Written by Matti 'ccr' Hämäläinen |
668 | 4 * (C) Copyright 2008-2016 Tecnic Software productions (TNSP) |
39 | 5 */ |
0 | 6 #include "th_args.h" |
133 | 7 #include "th_config.h" |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
8 #include "th_network.h" |
662
0c94af18f55e
Two more generic functions were moved to th-libs, so factor out the
Matti Hamalainen <ccr@tnsp.org>
parents:
661
diff
changeset
|
9 #include "th_file.h" |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
10 #include "util.h" |
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
11 #include "ui.h" |
555 | 12 #include <unistd.h> |
13 #include <fcntl.h> | |
661
eb3692d85ac2
Use TH_PLAT_WINDOWS for preprocessor conditionals.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
14 #ifdef TH_PLAT_WINDOWS |
649 | 15 # include <shlwapi.h> |
16 # include <shfolder.h> | |
128
713879a7ca10
Wait for forked processes, to prevent a zombie apocalypse.
Matti Hamalainen <ccr@tnsp.org>
parents:
125
diff
changeset
|
17 #else |
649 | 18 # include <sys/wait.h> |
19 # include <sys/stat.h> | |
20 # include <sys/types.h> | |
68
3ab7751fdad1
MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents:
67
diff
changeset
|
21 #endif |
0 | 22 |
661
eb3692d85ac2
Use TH_PLAT_WINDOWS for preprocessor conditionals.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
23 #ifdef TH_PLAT_WINDOWS |
649 | 24 # define SET_CONFIG_FILE "nnchat.txt" |
25 # define SET_LOG_DIR "NNChat Log Files" | |
139
c39399725f7b
Define some platform-specific constants.
Matti Hamalainen <ccr@tnsp.org>
parents:
137
diff
changeset
|
26 #else |
650
98f5d15d5ec4
Improve and fix XDG support.
Matti Hamalainen <ccr@tnsp.org>
parents:
649
diff
changeset
|
27 # define SET_LOG_DIR "nnlogs" |
98f5d15d5ec4
Improve and fix XDG support.
Matti Hamalainen <ccr@tnsp.org>
parents:
649
diff
changeset
|
28 # if defined(USE_XDG) |
98f5d15d5ec4
Improve and fix XDG support.
Matti Hamalainen <ccr@tnsp.org>
parents:
649
diff
changeset
|
29 # define SET_XDG_CONFIG_DIR "nnchat" |
98f5d15d5ec4
Improve and fix XDG support.
Matti Hamalainen <ccr@tnsp.org>
parents:
649
diff
changeset
|
30 # define SET_CONFIG_FILE "config" |
98f5d15d5ec4
Improve and fix XDG support.
Matti Hamalainen <ccr@tnsp.org>
parents:
649
diff
changeset
|
31 # else |
98f5d15d5ec4
Improve and fix XDG support.
Matti Hamalainen <ccr@tnsp.org>
parents:
649
diff
changeset
|
32 # define SET_CONFIG_FILE ".nnchat" |
98f5d15d5ec4
Improve and fix XDG support.
Matti Hamalainen <ccr@tnsp.org>
parents:
649
diff
changeset
|
33 # endif |
139
c39399725f7b
Define some platform-specific constants.
Matti Hamalainen <ccr@tnsp.org>
parents:
137
diff
changeset
|
34 #endif |
49
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
35 |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
36 #define SET_PROFILE_PREFIX "http://www.newbienudes.com/profile/%s/" |
409
4556174b5be8
Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
408
diff
changeset
|
37 #define SET_NICK_SEPARATOR ':' |
4556174b5be8
Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
408
diff
changeset
|
38 |
636 | 39 #define SET_PROXY_PORT 1080 |
588
573a3ad30938
Bump up the command history size.
Matti Hamalainen <ccr@tnsp.org>
parents:
586
diff
changeset
|
40 #define SET_MAX_HISTORY (64) // Command history length |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
41 #define SET_KEEPALIVE (15*60) // Ping/keepalive period in seconds |
0 | 42 |
652
58a376f86cdf
Make browser a configurable setting (in addition to environment variable),
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
43 enum |
58a376f86cdf
Make browser a configurable setting (in addition to environment variable),
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
44 { |
58a376f86cdf
Make browser a configurable setting (in addition to environment variable),
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
45 BMT_MOZILLA, |
58a376f86cdf
Make browser a configurable setting (in addition to environment variable),
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
46 BMT_NEW_FIREFOX, |
58a376f86cdf
Make browser a configurable setting (in addition to environment variable),
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
47 }; |
58a376f86cdf
Make browser a configurable setting (in addition to environment variable),
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
48 |
49
0bcc38910a77
Simple ringbuffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
49 |
592
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
50 typedef struct |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
51 { |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
52 char *name; |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
53 int port; |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
54 char *desc; |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
55 } nn_room_data_t; |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
56 |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
57 static const nn_room_data_t nn_room_data[] = |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
58 { |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
59 { "main" , 8005, "Main room" }, |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
60 { "pit" , 8003, "Passion Pit" }, |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
61 }; |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
62 |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
63 static const int nn_room_data_n = sizeof(nn_room_data) / sizeof(nn_room_data[0]); |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
64 |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
65 |
0 | 66 /* Options |
67 */ | |
352
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
68 int optPort = 8005, |
636 | 69 optProxyPort = SET_PROXY_PORT, |
623
118276b60667
More work towards using th-libs th_network module.
Matti Hamalainen <ccr@tnsp.org>
parents:
622
diff
changeset
|
70 optProxyType = TH_PROXY_NONE, |
633 | 71 optProxyAuthType = TH_PROXY_AUTH_NONE, |
72 optProxyAddrType = TH_PROXY_ADDR_DOMAIN; | |
690
6fa9c36d0634
Adjust to match th-libs API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
689
diff
changeset
|
73 unsigned int optUserColor = 0x000000; |
652
58a376f86cdf
Make browser a configurable setting (in addition to environment variable),
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
74 int optBrowserRunMethod = BMT_NEW_FIREFOX; |
96
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
75 char *optServer = "chat.newbienudes.com", |
352
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
76 *optProxyServer = NULL, |
602
4bae14092b78
Add parameters (unused for now) for proxy password etc. in case SOCKS 5
Matti Hamalainen <ccr@tnsp.org>
parents:
601
diff
changeset
|
77 *optProxyUserID = NULL, |
4bae14092b78
Add parameters (unused for now) for proxy password etc. in case SOCKS 5
Matti Hamalainen <ccr@tnsp.org>
parents:
601
diff
changeset
|
78 *optProxyPassword = NULL, |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
79 *optUserName = NULL, |
198
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
80 *optUserNameCmd = NULL, |
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
81 *optUserNameEnc = NULL, |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
82 *optPassword = NULL, |
198
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
83 *optPasswordCmd = NULL, |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
84 *optLogPath = NULL, |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
85 *optLogExtension = ".log", |
409
4556174b5be8
Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
408
diff
changeset
|
86 *optSite = "NN", |
4556174b5be8
Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
408
diff
changeset
|
87 *optNickSepStr = NULL; |
4556174b5be8
Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
408
diff
changeset
|
88 char optNickSep; |
552 | 89 BOOL optDaemon = FALSE, |
638
bda973fa2b3b
Add proxy disable/enable setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
636
diff
changeset
|
90 optProxyEnable = FALSE, |
552 | 91 setIgnoreMode = FALSE, |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
92 optDebug = FALSE, |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
93 optLogEnable = FALSE, |
554
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
94 optLogDaily = FALSE, |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
95 optOnlyFriendPrv = FALSE; |
140
2d2ef5bbcc11
Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
96 |
664
87ef546de419
Create configuration directory path if it does not yet exist when saving
Matti Hamalainen <ccr@tnsp.org>
parents:
663
diff
changeset
|
97 char *setHomeDir = NULL, *setConfigDir = NULL, *setProxyURI = NULL; |
657
8b8ef14d7177
Update to match th-libs API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
654
diff
changeset
|
98 th_llist_t *setIgnoreList = NULL, |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
99 *setFriendList = NULL, |
264
4c1c18a388d9
Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents:
258
diff
changeset
|
100 *setIdleMessages = NULL; |
140
2d2ef5bbcc11
Use th-libs linked list code for managing ignore list.
Matti Hamalainen <ccr@tnsp.org>
parents:
139
diff
changeset
|
101 nn_userhash_t *nnUsers = NULL; |
137
fad8c31e41e6
Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
102 char *setConfigFile = NULL, |
fad8c31e41e6
Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
103 *setBrowser = NULL; |
561
1ff9e85a1fcc
Rework the configuration file loading and saving to use the I/O context and new th-config API.
Matti Hamalainen <ccr@tnsp.org>
parents:
560
diff
changeset
|
104 th_cfgitem_t *cfg = NULL; |
89
c2d916b340bf
Change some typedef names; Add struct for user list handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
86
diff
changeset
|
105 |
513 | 106 nn_editbuf_t *editHistBuf[SET_MAX_HISTORY+2]; |
107 int editHistPos = 0, | |
108 editHistMax = 0; | |
273 | 109 |
110 /* Logging mode flags | |
111 */ | |
391 | 112 enum |
113 { | |
553
b464409fa643
Make LOG_* flags enum more readable and extendable by using hexadecimal values.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
114 LOG_FILE = 0x0001, |
b464409fa643
Make LOG_* flags enum more readable and extendable by using hexadecimal values.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
115 LOG_WINDOW = 0x0002, |
b464409fa643
Make LOG_* flags enum more readable and extendable by using hexadecimal values.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
116 LOG_STAMP = 0x0004, |
b464409fa643
Make LOG_* flags enum more readable and extendable by using hexadecimal values.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
117 LOG_FILE2 = 0x0008, |
554
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
118 LOG_RECURSIVE = 0x0010, |
273 | 119 }; |
120 | |
121 | |
0 | 122 /* Arguments |
123 */ | |
670 | 124 static const th_optarg optList[] = |
391 | 125 { |
640
51dd01786d25
Update to work with changed th_args API.
Matti Hamalainen <ccr@tnsp.org>
parents:
639
diff
changeset
|
126 { 0, '?', "help", "Show this help and be so very much verbose that it almost hurts you", OPT_NONE }, |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
127 { 1, 'v', "verbose", "Be more verbose", OPT_NONE }, |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
128 { 2, 'p', "port", "Connect to port", OPT_ARGREQ }, |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
129 { 3, 's', "server", "Server to connect to", OPT_ARGREQ }, |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
130 { 4, 'C', "color", "Initial color in RGB hex 000000", OPT_ARGREQ }, |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
131 { 6, 'D', "daemon", "A pseudo-daemon mode for logging", OPT_NONE }, |
352
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
132 { 7, 'f', "force-site", "Force site (default: NN)", OPT_ARGREQ }, |
162
e59cec397811
Add a debug mode option (commandline) and enable certain features when we are in debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
133 { 8, 'd', "debug", "Enable various debug features", OPT_NONE }, |
391 | 134 |
608
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
135 {10, 'P', "proxy", "Set proxy data, see below for syntax", OPT_ARGREQ }, |
592
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
136 |
697 | 137 {13, 'r', "room", "Connect to room (see list below)", OPT_ARGREQ }, |
0 | 138 }; |
139 | |
640
51dd01786d25
Update to work with changed th_args API.
Matti Hamalainen <ccr@tnsp.org>
parents:
639
diff
changeset
|
140 static const int optListN = sizeof(optList) / sizeof(optList[0]); |
0 | 141 |
142 | |
258 | 143 void argShowHelp(void) |
68
3ab7751fdad1
MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents:
67
diff
changeset
|
144 { |
592
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
145 int i; |
607 | 146 th_print_banner(stdout, th_prog_name, "[options] <username> <password>"); |
391 | 147 |
698
28fe6a1be852
Adjust to th-libs th_args_help() API change.
Matti Hamalainen <ccr@tnsp.org>
parents:
697
diff
changeset
|
148 th_args_help(stdout, optList, optListN, 0, 80 - 2); |
592
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
149 |
608
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
150 printf( |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
151 "\n" |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
152 "Supported proxy types are SOCKS 4/4A and SOCKS 5.\n" |
617 | 153 "(Only user/pass auth and no auth supported, no GSSAPI!)\n" |
608
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
154 "These can be set with the -P option as follows:\n" |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
155 "\n" |
638
bda973fa2b3b
Add proxy disable/enable setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
636
diff
changeset
|
156 " -P disable (to disable proxy use)\n" |
608
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
157 " -P <type>://[<userid>[:passwd]@]<host>[:<port>]\n" |
636 | 158 " -P socks4://localhost:9000\n" |
159 " -P socks5://foobar:pass@localhost\n" | |
608
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
160 "\n" |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
161 "Type can be socks4, socks4a or socks5. Only socks5\n" |
636 | 162 "supports user/pass authentication. Default port is %d.\n" |
608
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
163 "\n" |
636 | 164 "Supported rooms (for option '-r'):\n", |
165 SET_PROXY_PORT); | |
608
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
166 |
592
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
167 for (i = 0; i < nn_room_data_n; i++) |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
168 { |
697 | 169 const nn_room_data_t *rdata = &nn_room_data[i]; |
170 | |
171 printf(" %-8s - %s (port %d)\n", | |
172 rdata->name, | |
173 rdata->desc, | |
174 rdata->port); | |
592
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
175 } |
636 | 176 |
177 printf("\n"); | |
68
3ab7751fdad1
MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents:
67
diff
changeset
|
178 } |
3ab7751fdad1
MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents:
67
diff
changeset
|
179 |
3ab7751fdad1
MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents:
67
diff
changeset
|
180 |
608
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
181 BOOL argSplitStr(const char *src, const char *at, char **res1, char **res2) |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
182 { |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
183 char *pos, *tmp = th_strdup(src); |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
184 |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
185 if (tmp != NULL && (pos = strstr(tmp, at)) != NULL) |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
186 { |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
187 *pos = 0; |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
188 pos += strlen(at); |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
189 *res1 = th_strdup_trim(tmp, TH_TRIM_BOTH); |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
190 *res2 = th_strdup_trim(pos, TH_TRIM_BOTH); |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
191 th_free(tmp); |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
192 return TRUE; |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
193 } |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
194 else |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
195 { |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
196 th_free(tmp); |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
197 return FALSE; |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
198 } |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
199 } |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
200 |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
201 |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
202 BOOL argHandleProxyURI(const char *uri) |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
203 { |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
204 // Attempt to parse the proxy URI |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
205 BOOL ret = FALSE; |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
206 char *proto = NULL, *rest = NULL, *host = NULL, |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
207 *auth = NULL, *port = NULL; |
612
59588bbf8d55
Remove possible trailing slash from proxy URI.
Matti Hamalainen <ccr@tnsp.org>
parents:
609
diff
changeset
|
208 size_t len; |
608
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
209 |
638
bda973fa2b3b
Add proxy disable/enable setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
636
diff
changeset
|
210 optProxyEnable = FALSE; |
bda973fa2b3b
Add proxy disable/enable setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
636
diff
changeset
|
211 |
bda973fa2b3b
Add proxy disable/enable setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
636
diff
changeset
|
212 // Handle disable case |
642 | 213 if (th_strncasecmp(uri, "disab", 5) == 0) |
638
bda973fa2b3b
Add proxy disable/enable setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
636
diff
changeset
|
214 return TRUE; |
bda973fa2b3b
Add proxy disable/enable setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
636
diff
changeset
|
215 |
bda973fa2b3b
Add proxy disable/enable setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
636
diff
changeset
|
216 // Split the URI |
608
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
217 if (!argSplitStr(uri, "://", &proto, &rest)) |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
218 { |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
219 THERR("Malformed proxy URI, should be <type>://[<userid>[:passwd]@]<host>[:<port>]\n"); |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
220 goto out; |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
221 } |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
222 |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
223 // Validate proxy type |
642 | 224 if (th_strcasecmp(proto, "socks4") == 0) |
623
118276b60667
More work towards using th-libs th_network module.
Matti Hamalainen <ccr@tnsp.org>
parents:
622
diff
changeset
|
225 optProxyType = TH_PROXY_SOCKS4; |
608
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
226 else |
642 | 227 if (th_strcasecmp(proto, "socks4a") == 0) |
623
118276b60667
More work towards using th-libs th_network module.
Matti Hamalainen <ccr@tnsp.org>
parents:
622
diff
changeset
|
228 optProxyType = TH_PROXY_SOCKS4A; |
608
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
229 else |
642 | 230 if (th_strcasecmp(proto, "socks5") == 0) |
625
edac1485308d
Socks5 support stuff, not finished yet (as SOCKS5 needs to be implemented in th_network)
Matti Hamalainen <ccr@tnsp.org>
parents:
624
diff
changeset
|
231 optProxyType = TH_PROXY_SOCKS5; |
edac1485308d
Socks5 support stuff, not finished yet (as SOCKS5 needs to be implemented in th_network)
Matti Hamalainen <ccr@tnsp.org>
parents:
624
diff
changeset
|
232 else |
608
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
233 { |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
234 THERR("Invalid proxy type specified: '%s'\n", proto); |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
235 goto out; |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
236 } |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
237 |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
238 // Does the URI contain anything else? |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
239 if (strlen(rest) == 0) |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
240 { |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
241 THERR("Malformed proxy URI, no host specified.\n"); |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
242 goto out; |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
243 } |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
244 |
612
59588bbf8d55
Remove possible trailing slash from proxy URI.
Matti Hamalainen <ccr@tnsp.org>
parents:
609
diff
changeset
|
245 // Remove trailing slash |
59588bbf8d55
Remove possible trailing slash from proxy URI.
Matti Hamalainen <ccr@tnsp.org>
parents:
609
diff
changeset
|
246 len = strlen(rest) - 1; |
59588bbf8d55
Remove possible trailing slash from proxy URI.
Matti Hamalainen <ccr@tnsp.org>
parents:
609
diff
changeset
|
247 if (rest[len] == '/') |
59588bbf8d55
Remove possible trailing slash from proxy URI.
Matti Hamalainen <ccr@tnsp.org>
parents:
609
diff
changeset
|
248 rest[len] = 0; |
59588bbf8d55
Remove possible trailing slash from proxy URI.
Matti Hamalainen <ccr@tnsp.org>
parents:
609
diff
changeset
|
249 |
608
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
250 // Check for auth credentials |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
251 if (argSplitStr(rest, "@", &auth, &host)) |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
252 { |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
253 if (strlen(auth) == 0) |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
254 { |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
255 THERR("Malformed proxy URI, zero length authentication credentials.\n"); |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
256 goto out; |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
257 } |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
258 |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
259 // Should have authentication credentials |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
260 if (!argSplitStr(auth, ":", &optProxyUserID, &optProxyPassword)) |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
261 optProxyUserID = th_strdup(auth); |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
262 } |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
263 else |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
264 host = th_strdup(rest); |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
265 |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
266 // Check if proxy port was specified |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
267 if (argSplitStr(host, ":", &optProxyServer, &port)) |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
268 optProxyPort = atoi(port); |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
269 else |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
270 optProxyServer = th_strdup(host); |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
271 |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
272 // Check what authentication type to use |
623
118276b60667
More work towards using th-libs th_network module.
Matti Hamalainen <ccr@tnsp.org>
parents:
622
diff
changeset
|
273 if (optProxyType == TH_PROXY_SOCKS5 && |
608
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
274 optProxyUserID != NULL && optProxyPassword != NULL) |
623
118276b60667
More work towards using th-libs th_network module.
Matti Hamalainen <ccr@tnsp.org>
parents:
622
diff
changeset
|
275 optProxyAuthType = TH_PROXY_AUTH_USER; |
608
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
276 else |
623
118276b60667
More work towards using th-libs th_network module.
Matti Hamalainen <ccr@tnsp.org>
parents:
622
diff
changeset
|
277 optProxyAuthType = TH_PROXY_AUTH_NONE; |
608
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
278 |
638
bda973fa2b3b
Add proxy disable/enable setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
636
diff
changeset
|
279 optProxyEnable = TRUE; |
608
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
280 ret = TRUE; |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
281 |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
282 out: |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
283 th_free(proto); |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
284 th_free(rest); |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
285 th_free(host); |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
286 th_free(auth); |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
287 th_free(port); |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
288 |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
289 return ret; |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
290 } |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
291 |
629
005d7a0351b6
More API changes in th_network.
Matti Hamalainen <ccr@tnsp.org>
parents:
628
diff
changeset
|
292 |
0 | 293 BOOL argHandleOpt(const int optN, char *optArg, char *currArg) |
294 { | |
391 | 295 switch (optN) |
296 { | |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
297 case 0: |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
298 argShowHelp(); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
299 exit(0); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
300 break; |
0 | 301 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
302 case 1: |
678
75daa6ec65df
Fix to match changes in th-libs API.
Matti Hamalainen <ccr@tnsp.org>
parents:
677
diff
changeset
|
303 th_verbosity++; |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
304 break; |
391 | 305 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
306 case 2: |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
307 optPort = atoi(optArg); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
308 break; |
0 | 309 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
310 case 3: |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
311 optServer = optArg; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
312 break; |
391 | 313 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
314 case 4: |
690
6fa9c36d0634
Adjust to match th-libs API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
689
diff
changeset
|
315 if (!th_get_hex_triplet(optArg, &optUserColor)) |
391 | 316 { |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
317 THERR("Invalid color argument '%s', should be a RGB hex triplet '000000'.\n", |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
318 optArg); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
319 return FALSE; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
320 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
321 THMSG(1, "Using color #%06x\n", optUserColor); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
322 break; |
0 | 323 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
324 case 7: |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
325 optSite = optArg; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
326 break; |
33
e49ea6febfeb
Cleanups. Added option to specify/fake "site" where logging in from.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
327 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
328 case 6: |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
329 optDaemon = TRUE; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
330 THMSG(1, "Running in pseudo-daemon mode.\n"); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
331 break; |
21 | 332 |
162
e59cec397811
Add a debug mode option (commandline) and enable certain features when we are in debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
333 case 8: |
e59cec397811
Add a debug mode option (commandline) and enable certain features when we are in debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
334 optDebug = TRUE; |
e59cec397811
Add a debug mode option (commandline) and enable certain features when we are in debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
335 THMSG(1, "Debug mode enabled.\n"); |
e59cec397811
Add a debug mode option (commandline) and enable certain features when we are in debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
336 break; |
e59cec397811
Add a debug mode option (commandline) and enable certain features when we are in debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
337 |
352
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
338 |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
339 case 10: |
608
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
340 if (!argHandleProxyURI(optArg)) |
a8fa7803284a
Change how proxy is specified on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
607
diff
changeset
|
341 return FALSE; |
352
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
342 break; |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
343 |
592
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
344 case 13: |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
345 { |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
346 int i; |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
347 for (i = 0; i < nn_room_data_n; i++) |
642 | 348 if (!th_strcasecmp(nn_room_data[i].name, optArg)) |
592
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
349 { |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
350 optPort = nn_room_data[i].port; |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
351 return TRUE; |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
352 } |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
353 |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
354 THERR("Unsupported room '%s'.\n", optArg); |
594
463210f14158
Oops, we didn't error out when the room name was non-existent for -r option.
Matti Hamalainen <ccr@tnsp.org>
parents:
593
diff
changeset
|
355 return FALSE; |
592
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
356 } |
27a6b7c2caad
Add -r option for specifying the room by name instead of port.
Matti Hamalainen <ccr@tnsp.org>
parents:
590
diff
changeset
|
357 break; |
352
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
358 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
359 default: |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
360 THERR("Unknown option '%s'.\n", currArg); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
361 return FALSE; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
362 } |
391 | 363 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
364 return TRUE; |
0 | 365 } |
366 | |
367 | |
368 BOOL argHandleFile(char *currArg) | |
369 { | |
198
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
370 if (!optUserNameCmd) |
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
371 optUserNameCmd = currArg; |
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
372 else if (!optPasswordCmd) |
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
373 optPasswordCmd = currArg; |
391 | 374 else |
375 { | |
198
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
376 THERR("Username '%s' already specified on commandline!\n", optUserNameCmd); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
377 return FALSE; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
378 } |
391 | 379 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
380 return TRUE; |
0 | 381 } |
382 | |
460 | 383 |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
384 BOOL nn_conn_send_msg(th_conn_t *conn, const char *user, const char *str) |
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
385 { |
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
386 char *msg; |
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
387 |
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
388 if (str == NULL) |
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
389 return FALSE; |
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
390 |
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
391 msg = th_strdup_printf("<USER>%s</USER><MESSAGE>%s</MESSAGE>", user, str); |
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
392 |
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
393 if (msg != NULL) |
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
394 { |
629
005d7a0351b6
More API changes in th_network.
Matti Hamalainen <ccr@tnsp.org>
parents:
628
diff
changeset
|
395 int ret = th_conn_send_buf(conn, msg, strlen(msg) + 1); |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
396 th_free(msg); |
629
005d7a0351b6
More API changes in th_network.
Matti Hamalainen <ccr@tnsp.org>
parents:
628
diff
changeset
|
397 return ret == THERR_OK; |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
398 } |
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
399 else |
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
400 return FALSE; |
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
401 } |
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
402 |
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
403 |
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
404 BOOL nn_conn_send_msg_v(th_conn_t *conn, const char *user, const char *fmt, ...) |
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
405 { |
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
406 BOOL res; |
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
407 char *tmp; |
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
408 va_list ap; |
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
409 |
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
410 va_start(ap, fmt); |
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
411 tmp = th_strdup_vprintf(fmt, ap); |
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
412 va_end(ap); |
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
413 |
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
414 res = nn_conn_send_msg(conn, user, tmp); |
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
415 th_free(tmp); |
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
416 return res; |
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
417 } |
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
418 |
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
419 |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
420 int printFile(FILE *outFile, const char *fmt) |
0 | 421 { |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
422 const char *s = fmt; |
391 | 423 |
424 while (*s) | |
425 { | |
426 if (*s == '½') | |
427 { | |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
428 s++; |
391 | 429 if (*s == '½') |
430 { | |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
431 fputc((unsigned char) *s, outFile); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
432 s++; |
391 | 433 } |
434 else | |
435 { | |
74 | 436 while (*s && isdigit((int) *s)) s++; |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
437 if (*s != '½') return -1; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
438 s++; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
439 } |
391 | 440 } |
441 else | |
442 { | |
191
4007b9ac7cde
Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
443 if ((unsigned char) *s == 255) |
4007b9ac7cde
Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
444 fputc(' ', outFile); |
4007b9ac7cde
Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
445 else |
4007b9ac7cde
Handle usernames with whitespace by converting whitespaces to chr 255 in
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
446 fputc((unsigned char) *s, outFile); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
447 s++; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
448 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
449 } |
391 | 450 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
451 return 0; |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
452 } |
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
453 |
620 | 454 |
542
d8184a3c241f
Clean up window logging logic a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
455 void printMsgFile(nn_window_t *win, int flags, const char *stamp, const char *msg) |
d8184a3c241f
Clean up window logging logic a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
456 { |
d8184a3c241f
Clean up window logging logic a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
457 if (win != NULL && win->logFile != NULL) |
d8184a3c241f
Clean up window logging logic a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
458 { |
d8184a3c241f
Clean up window logging logic a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
459 if (flags & LOG_STAMP) printFile(win->logFile, stamp); |
d8184a3c241f
Clean up window logging logic a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
460 printFile(win->logFile, msg); |
d8184a3c241f
Clean up window logging logic a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
461 fflush(win->logFile); |
d8184a3c241f
Clean up window logging logic a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
462 } |
d8184a3c241f
Clean up window logging logic a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
463 } |
d8184a3c241f
Clean up window logging logic a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
464 |
554
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
465 |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
466 void printMsgF(nn_window_t *win, int flags, const char *fmt, ...); |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
467 BOOL nn_log_reopen(nn_window_t *win); |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
468 |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
469 |
563
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
470 void printMsgConst(nn_window_t *win, int flags, const char *msg) |
28
512775f6b081
A refactored ncurses-based UI.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
471 { |
563
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
472 char tmpStr[128]; |
554
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
473 nn_window_t *tmpwin = (win != NULL) ? win : nnwin_main_window(); |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
474 |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
475 // Only the main window |
576
414d11df07ce
Gracefully handle error situations when the main UI has not yet been
Matti Hamalainen <ccr@tnsp.org>
parents:
573
diff
changeset
|
476 if (win == NULL && tmpwin != NULL && (flags & LOG_RECURSIVE) == 0) |
554
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
477 { |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
478 time_t currTime = time(NULL); |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
479 struct tm *currTm, *prevTm; |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
480 |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
481 if ((currTm = localtime(&currTime)) != NULL && |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
482 currTm->tm_hour == 0 && |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
483 (prevTm = localtime(&tmpwin->logPrevMsgTime)) != NULL && |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
484 prevTm->tm_hour == 23) |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
485 { |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
486 str_get_timestamp(tmpStr, sizeof(tmpStr), "%d %b %Y"); |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
487 printMsgF(win, LOG_RECURSIVE, "Day changed to %s.\n", tmpStr); |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
488 nn_log_reopen(tmpwin); |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
489 } |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
490 |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
491 tmpwin->logPrevMsgTime = currTime; |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
492 } |
391 | 493 |
520 | 494 if (flags & LOG_STAMP) |
495 { | |
496 str_get_timestamp(tmpStr, sizeof(tmpStr), "½17½[½11½%H:%M:%S½17½]½0½ "); | |
497 } | |
391 | 498 |
542
d8184a3c241f
Clean up window logging logic a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
499 if (flags & LOG_FILE) |
391 | 500 { |
563
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
501 printMsgFile(win != NULL ? win : nnwin_main_window(), flags, tmpStr, msg); |
544
e30fa8592a48
Possibly fix logging after latest changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
542
diff
changeset
|
502 } |
542
d8184a3c241f
Clean up window logging logic a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
541
diff
changeset
|
503 |
544
e30fa8592a48
Possibly fix logging after latest changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
542
diff
changeset
|
504 if (flags & LOG_FILE2) |
e30fa8592a48
Possibly fix logging after latest changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
542
diff
changeset
|
505 { |
563
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
506 printMsgFile(nnwin_main_window(), flags, tmpStr, msg); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
507 } |
391 | 508 |
509 if (!optDaemon && (flags & LOG_WINDOW)) | |
510 { | |
554
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
511 if (flags & LOG_STAMP) nnwin_print(tmpwin, tmpStr); |
563
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
512 nnwin_print(tmpwin, msg); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
513 } |
563
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
514 } |
391 | 515 |
563
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
516 void printMsgV(nn_window_t *win, int flags, const char *fmt, va_list ap) |
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
517 { |
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
518 char *buf = th_strdup_vprintf(fmt, ap); |
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
519 printMsgConst(win, flags, buf); |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
520 th_free(buf); |
0 | 521 } |
522 | |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
523 void printMsg(nn_window_t *win, const char *fmt, ...) |
100
ed4067c10a8a
Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
524 { |
ed4067c10a8a
Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
525 va_list ap; |
391 | 526 |
100
ed4067c10a8a
Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
527 va_start(ap, fmt); |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
528 printMsgV(win, LOG_STAMP | LOG_WINDOW | LOG_FILE, fmt, ap); |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
529 va_end(ap); |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
530 } |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
531 |
322
b9c15c57dc8f
Clean up message functions, add new printMsgQ() helper function for messages that should not
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
532 void printMsgF(nn_window_t *win, int flags, const char *fmt, ...) |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
533 { |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
534 va_list ap; |
391 | 535 |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
536 va_start(ap, fmt); |
322
b9c15c57dc8f
Clean up message functions, add new printMsgQ() helper function for messages that should not
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
537 printMsgV(win, flags | LOG_STAMP, fmt, ap); |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
538 va_end(ap); |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
539 } |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
540 |
322
b9c15c57dc8f
Clean up message functions, add new printMsgQ() helper function for messages that should not
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
541 void printMsgQ(nn_window_t *win, const char *fmt, ...) |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
542 { |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
543 va_list ap; |
391 | 544 |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
545 va_start(ap, fmt); |
322
b9c15c57dc8f
Clean up message functions, add new printMsgQ() helper function for messages that should not
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
546 printMsgV(win, LOG_STAMP | LOG_WINDOW, fmt, ap); |
100
ed4067c10a8a
Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
547 va_end(ap); |
ed4067c10a8a
Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
548 } |
ed4067c10a8a
Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
549 |
0 | 550 |
223
03af28fb1c38
Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
551 char *errorMessages = NULL; |
03af28fb1c38
Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
552 |
563
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
553 void errorMsgConst(const char *msg) |
96
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
554 { |
563
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
555 printMsgConst(NULL, LOG_STAMP | LOG_WINDOW | LOG_FILE, msg); |
391 | 556 |
557 if (errorMessages != NULL) | |
558 { | |
563
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
559 // XXX Yes, this is lazy. |
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
560 char *tmp = th_strdup_printf("%s%s", errorMessages, msg); |
223
03af28fb1c38
Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
561 th_free(errorMessages); |
563
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
562 errorMessages = tmp; |
391 | 563 } |
564 else | |
563
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
565 errorMessages = th_strdup(msg); |
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
566 } |
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
567 |
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
568 |
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
569 void errorMsgV(const char *fmt, va_list ap) |
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
570 { |
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
571 char *msg = th_strdup_vprintf(fmt, ap); |
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
572 errorMsgConst(msg); |
c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
Matti Hamalainen <ccr@tnsp.org>
parents:
561
diff
changeset
|
573 th_free(msg); |
96
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
574 } |
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
575 |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
464
diff
changeset
|
576 |
236
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
577 void errorMsg(const char *fmt, ...) |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
578 { |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
579 va_list ap; |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
580 |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
581 va_start(ap, fmt); |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
582 errorMsgV(fmt, ap); |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
583 va_end(ap); |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
584 } |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
585 |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
464
diff
changeset
|
586 |
513 | 587 void debugMsg(const char *fmt, ...) |
588 { | |
589 if (optDebug) | |
590 { | |
591 va_list ap; | |
592 | |
593 va_start(ap, fmt); | |
544
e30fa8592a48
Possibly fix logging after latest changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
542
diff
changeset
|
594 printMsgV(NULL, LOG_FILE | LOG_WINDOW, fmt, ap); |
513 | 595 va_end(ap); |
596 } | |
597 } | |
598 | |
599 | |
623
118276b60667
More work towards using th-libs th_network module.
Matti Hamalainen <ccr@tnsp.org>
parents:
622
diff
changeset
|
600 void nn_network_errfunc(struct _th_conn_t *conn, int err, const char *msg) |
236
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
601 { |
262
6d48fc4fd421
Shut up some trivial warnings.
Matti Hamalainen <ccr@tnsp.org>
parents:
258
diff
changeset
|
602 (void) conn; |
623
118276b60667
More work towards using th-libs th_network module.
Matti Hamalainen <ccr@tnsp.org>
parents:
622
diff
changeset
|
603 (void) err; |
564
6e5789cbb4d4
Change network layer error/info message passing API to pass direct strings
Matti Hamalainen <ccr@tnsp.org>
parents:
563
diff
changeset
|
604 errorMsg("%s", msg); |
236
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
605 } |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
606 |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
464
diff
changeset
|
607 |
623
118276b60667
More work towards using th-libs th_network module.
Matti Hamalainen <ccr@tnsp.org>
parents:
622
diff
changeset
|
608 void nn_network_msgfunc(struct _th_conn_t *conn, int loglevel, const char *msg) |
236
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
609 { |
262
6d48fc4fd421
Shut up some trivial warnings.
Matti Hamalainen <ccr@tnsp.org>
parents:
258
diff
changeset
|
610 (void) conn; |
623
118276b60667
More work towards using th-libs th_network module.
Matti Hamalainen <ccr@tnsp.org>
parents:
622
diff
changeset
|
611 (void) loglevel; |
564
6e5789cbb4d4
Change network layer error/info message passing API to pass direct strings
Matti Hamalainen <ccr@tnsp.org>
parents:
563
diff
changeset
|
612 printMsgConst(NULL, LOG_STAMP | LOG_WINDOW | LOG_FILE, msg); |
236
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
613 } |
71fa0364c058
Report network errors to the user.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
614 |
225
801ac37321f6
Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
615 |
663
0b81e5fdc7b5
Use the new io context API.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
616 void nn_ioctx_errfunc(th_ioctx *ctx, const int err, const char *msg) |
565
de1af9652fef
Update to conform to changes in th-libs ioctx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
564
diff
changeset
|
617 { |
de1af9652fef
Update to conform to changes in th-libs ioctx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
564
diff
changeset
|
618 (void) err; |
582
8a0c2eb25b35
Adjust certain error message formats slightly.
Matti Hamalainen <ccr@tnsp.org>
parents:
581
diff
changeset
|
619 errorMsg("[%s:%d] %s", |
565
de1af9652fef
Update to conform to changes in th-libs ioctx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
564
diff
changeset
|
620 ctx->filename, ctx->line, msg); |
de1af9652fef
Update to conform to changes in th-libs ioctx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
564
diff
changeset
|
621 } |
de1af9652fef
Update to conform to changes in th-libs ioctx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
564
diff
changeset
|
622 |
de1af9652fef
Update to conform to changes in th-libs ioctx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
564
diff
changeset
|
623 |
663
0b81e5fdc7b5
Use the new io context API.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
624 void nn_ioctx_msgfunc(th_ioctx *ctx, const int level, const char *msg) |
565
de1af9652fef
Update to conform to changes in th-libs ioctx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
564
diff
changeset
|
625 { |
de1af9652fef
Update to conform to changes in th-libs ioctx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
564
diff
changeset
|
626 (void) ctx; |
666
1b18551b25e7
Silence a warning about unused function argument.
Matti Hamalainen <ccr@tnsp.org>
parents:
664
diff
changeset
|
627 (void) level; |
565
de1af9652fef
Update to conform to changes in th-libs ioctx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
564
diff
changeset
|
628 printMsgConst(NULL, LOG_STAMP | LOG_WINDOW | LOG_FILE, msg); |
de1af9652fef
Update to conform to changes in th-libs ioctx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
564
diff
changeset
|
629 } |
de1af9652fef
Update to conform to changes in th-libs ioctx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
564
diff
changeset
|
630 |
de1af9652fef
Update to conform to changes in th-libs ioctx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
564
diff
changeset
|
631 |
657
8b8ef14d7177
Update to match th-libs API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
654
diff
changeset
|
632 BOOL nn_check_name_list(th_llist_t *list, const char *name) |
225
801ac37321f6
Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
633 { |
657
8b8ef14d7177
Update to match th-libs API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
654
diff
changeset
|
634 th_llist_t *node; |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
635 |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
636 for (node = list; node != NULL; node = node->next) |
391 | 637 { |
372
b9f0bdad6285
Use th_strcasecmp() and th_strncasecmp().
Matti Hamalainen <ccr@tnsp.org>
parents:
369
diff
changeset
|
638 if (th_strcasecmp(name, (char *) node->data) == 0) |
225
801ac37321f6
Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
639 return TRUE; |
801ac37321f6
Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
640 } |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
641 |
225
801ac37321f6
Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
642 return FALSE; |
801ac37321f6
Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
643 } |
801ac37321f6
Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
644 |
801ac37321f6
Sanitize ignore handling; Also action messages and PRVs were not being properly ignored, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
645 |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
646 int nnproto_parse_user(th_conn_t *conn) |
0 | 647 { |
229
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
648 BOOL isMine, isIgnored = FALSE; |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
649 char *name, *msg, *t; |
391 | 650 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
651 // Find start of the message |
639
02e1307e2a62
API changes in th_network module.
Matti Hamalainen <ccr@tnsp.org>
parents:
638
diff
changeset
|
652 name = conn->base.ptr; |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
653 t = th_conn_buf_strstr(conn, "</USER>"); |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
654 if (!t) return 1; |
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
655 *t = 0; |
391 | 656 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
657 // Find end of the message |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
658 t = th_conn_buf_strstr(conn, "<MESSAGE>"); |
430
aaadf6cea6be
Better handling of some messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
429
diff
changeset
|
659 if (!t) return 2; |
639
02e1307e2a62
API changes in th_network module.
Matti Hamalainen <ccr@tnsp.org>
parents:
638
diff
changeset
|
660 msg = conn->base.ptr; |
430
aaadf6cea6be
Better handling of some messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
429
diff
changeset
|
661 |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
662 t = th_conn_buf_strstr(conn, "</MESSAGE>"); |
229
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
663 if (!t) return 3; |
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
664 *t = 0; |
391 | 665 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
666 // Decode message string |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
667 msg = nn_decode_str1(msg); |
481 | 668 if (!msg) |
669 { | |
670 errorMsg("Decode/malloc failure @ nnproto_parse_user()\n"); | |
671 return -1; | |
672 } | |
391 | 673 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
674 // Decode username |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
675 name = nn_decode_str1(name); |
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
676 if (!name) |
391 | 677 { |
481 | 678 errorMsg("Decode/malloc failure @ nnproto_parse_user()\n"); |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
679 th_free(msg); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
680 return -2; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
681 } |
229
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
682 |
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
683 /* Check if the username is on our ignore list and |
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
684 * that it is not our OWN username! |
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
685 */ |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
686 isMine = strcmp(name, optUserName) == 0; |
620 | 687 isIgnored = setIgnoreMode && !isMine && nn_check_name_list(setIgnoreList, name); |
108
f323b137ca08
Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents:
107
diff
changeset
|
688 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
689 // Is it a special control message? |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
690 if (*msg == '/') |
391 | 691 { |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
692 // Ignore room join/leave messages |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
693 if (!optDebug && (strstr(msg, "left the room") || strstr(msg, "joined the room from"))) |
229
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
694 goto done; |
108
f323b137ca08
Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents:
107
diff
changeset
|
695 |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
696 t = nn_strip_tags(msg + 1); |
391 | 697 if (!strncmp(t, "BPRV ", 5)) |
698 { | |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
699 char *in_name, *tmp, *in_msg, *h; |
293 | 700 nn_window_t *win; |
701 h = nn_decode_str2(t + 1); | |
391 | 702 |
418 | 703 // Check type of |
704 if ((isMine = strncmp(t, "BPRV from ", 10)) == 0) | |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
705 in_name = nn_decode_str2(t + 10); |
391 | 706 else |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
707 in_name = nn_decode_str2(t + 8); |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
708 |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
709 for (tmp = in_name; *tmp && *tmp != ':'; tmp++); |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
710 if (tmp[0] != 0 && tmp[1] == ' ') |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
711 in_msg = tmp + 2; |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
712 else |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
713 in_msg = ""; |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
714 *tmp = 0; |
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
715 |
620 | 716 if (!optOnlyFriendPrv || !nn_check_name_list(setFriendList, in_name)) |
391 | 717 { |
620 | 718 isIgnored = setIgnoreMode && nn_check_name_list(setIgnoreList, in_name); |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
719 win = nnwin_find(in_name); |
388
f45673fe6b23
Log private messages always in the PRV format.
Matti Hamalainen <ccr@tnsp.org>
parents:
385
diff
changeset
|
720 |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
721 if (win != NULL) |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
722 { |
544
e30fa8592a48
Possibly fix logging after latest changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
542
diff
changeset
|
723 printMsgF(win, isIgnored ? LOG_FILE : (LOG_FILE | LOG_WINDOW), |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
724 "½5½<½%d½%s½5½>½0½ %s\n", |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
725 isMine ? 14 : 15, isMine ? optUserName : in_name, in_msg); |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
726 |
544
e30fa8592a48
Possibly fix logging after latest changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
542
diff
changeset
|
727 printMsgF(NULL, LOG_FILE2, "½11½%s½0½\n", h); |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
728 } |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
729 else |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
730 { |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
731 printMsgF(NULL, isIgnored ? LOG_FILE : (LOG_WINDOW | LOG_FILE), |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
732 "½11½%s½0½\n", h); |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
733 } |
391 | 734 } |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
735 |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
736 th_free(in_name); |
293 | 737 th_free(h); |
391 | 738 } |
739 else | |
740 { | |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
741 // It's an action (/me) |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
742 char *h = nn_decode_str2(t); |
322
b9c15c57dc8f
Clean up message functions, add new printMsgQ() helper function for messages that should not
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
743 printMsgF(NULL, isIgnored ? LOG_FILE : (LOG_WINDOW | LOG_FILE), |
b9c15c57dc8f
Clean up message functions, add new printMsgQ() helper function for messages that should not
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
744 "½9½* %s½0½\n", h); |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
745 th_free(h); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
746 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
747 th_free(t); |
391 | 748 } |
749 else | |
750 { | |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
751 // It's a normal message |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
752 char *h; |
530
f0bca971170b
Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
526
diff
changeset
|
753 int colorNick, colorText; |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
754 t = nn_strip_tags(msg); |
97
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
755 h = nn_decode_str2(t); |
530
f0bca971170b
Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
526
diff
changeset
|
756 if (isMine) |
f0bca971170b
Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
526
diff
changeset
|
757 { |
f0bca971170b
Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
526
diff
changeset
|
758 colorNick = 14; |
f0bca971170b
Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
526
diff
changeset
|
759 colorText = 0; |
f0bca971170b
Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
526
diff
changeset
|
760 } |
f0bca971170b
Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
526
diff
changeset
|
761 else |
f0bca971170b
Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
526
diff
changeset
|
762 { |
620 | 763 if (nn_check_name_list(setFriendList, name)) |
530
f0bca971170b
Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
526
diff
changeset
|
764 { |
535
379e361f1144
Fix various segfault issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
533
diff
changeset
|
765 colorNick = 11; |
379e361f1144
Fix various segfault issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
533
diff
changeset
|
766 colorText = 0; |
530
f0bca971170b
Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
526
diff
changeset
|
767 } |
f0bca971170b
Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
526
diff
changeset
|
768 else |
f0bca971170b
Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
526
diff
changeset
|
769 { |
f0bca971170b
Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
526
diff
changeset
|
770 colorNick = 15; |
f0bca971170b
Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
526
diff
changeset
|
771 colorText = 0; |
f0bca971170b
Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
526
diff
changeset
|
772 } |
f0bca971170b
Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
526
diff
changeset
|
773 } |
f0bca971170b
Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
526
diff
changeset
|
774 |
322
b9c15c57dc8f
Clean up message functions, add new printMsgQ() helper function for messages that should not
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
775 printMsgF(NULL, isIgnored ? LOG_FILE : (LOG_WINDOW | LOG_FILE), |
530
f0bca971170b
Change coloring to use friend list as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
526
diff
changeset
|
776 "½5½<½%d½%s½5½>½%d½ %s½0½\n", colorNick, name, colorText, h); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
777 th_free(h); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
778 th_free(t); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
779 } |
108
f323b137ca08
Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents:
107
diff
changeset
|
780 |
229
08d4355d6fc9
Repair automatic PRV target setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
228
diff
changeset
|
781 done: |
417
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
782 th_free(msg); |
ccee77fe4525
Fix protocol message parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
416
diff
changeset
|
783 th_free(name); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
784 return 0; |
0 | 785 } |
786 | |
787 | |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
788 int nnproto_parse_login(th_conn_t *conn) |
0 | 789 { |
156
0a9fe14882dc
Introduce utility function getTimeStamp() and use it to lessen code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
155
diff
changeset
|
790 char tmpStr[256]; |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
791 str_get_timestamp(tmpStr, sizeof(tmpStr), "%c"); |
391 | 792 |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
793 if (!th_conn_buf_strcmp(conn, "FAILURE>")) |
391 | 794 { |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
795 th_conn_buf_strstr(conn, "</LOGIN_FAILURE>"); |
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
796 th_conn_buf_strstr(conn, "</USER>"); |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
797 printMsg(NULL, "½1½Login failure½0½ - ½3½%s½0½\n", tmpStr); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
798 return -2; |
391 | 799 } |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
800 else if (!th_conn_buf_strcmp(conn, "SUCCESS>")) |
391 | 801 { |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
802 th_conn_buf_strstr(conn, "</LOGIN_SUCCESS>"); |
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
803 th_conn_buf_strstr(conn, "</USER>"); |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
804 printMsg(NULL, "½2½Login success½0½ - ½3½%s½0½\n", tmpStr); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
805 nn_conn_send_msg(conn, optUserNameEnc, "%2FRequestUserList"); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
806 return 0; |
391 | 807 } |
808 else | |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
809 return 1; |
0 | 810 } |
811 | |
812 | |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
813 int nnproto_parse_add_user(th_conn_t *conn) |
0 | 814 { |
639
02e1307e2a62
API changes in th_network module.
Matti Hamalainen <ccr@tnsp.org>
parents:
638
diff
changeset
|
815 char *p, *s, *str = conn->base.ptr; |
297
d34910f1b1e1
Print messages about user leaving or joining the chat in the specific buffer, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
816 nn_window_t *win; |
0 | 817 |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
818 s = th_conn_buf_strstr(conn, "</ADD_USER>"); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
819 if (!s) return 1; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
820 *s = 0; |
391 | 821 |
97
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
822 p = nn_dbldecode_str(str); |
481 | 823 if (!p) |
824 { | |
825 errorMsg("Decode/malloc failure @ nnproto_parse_add_user()\n"); | |
826 return -1; | |
827 } | |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
828 |
422 | 829 win = nnwin_find(p); |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
830 nn_userhash_insert(nnUsers, nn_username_encode(p)); |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
831 |
654
9c2ae1b96674
Change messages for join/part.
Matti Hamalainen <ccr@tnsp.org>
parents:
652
diff
changeset
|
832 printMsg(NULL, "! ½3½%s½0½ ½2½JOINED.½0½\n", p); |
297
d34910f1b1e1
Print messages about user leaving or joining the chat in the specific buffer, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
833 if (win != NULL) |
d34910f1b1e1
Print messages about user leaving or joining the chat in the specific buffer, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
834 printMsg(win, "! ½3½%s½0½ ½2½joined the chat.½0½\n", p); |
d34910f1b1e1
Print messages about user leaving or joining the chat in the specific buffer, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
835 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
836 th_free(p); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
837 return 0; |
0 | 838 } |
839 | |
840 | |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
841 int nnproto_parse_delete_user(th_conn_t *conn) |
0 | 842 { |
639
02e1307e2a62
API changes in th_network module.
Matti Hamalainen <ccr@tnsp.org>
parents:
638
diff
changeset
|
843 char *p, *s, *str = conn->base.ptr; |
297
d34910f1b1e1
Print messages about user leaving or joining the chat in the specific buffer, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
844 nn_window_t *win; |
0 | 845 |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
846 s = th_conn_buf_strstr(conn, "</DELETE_USER>"); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
847 if (!s) return 1; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
848 *s = 0; |
391 | 849 |
97
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
850 p = nn_dbldecode_str(str); |
481 | 851 if (!p) |
852 { | |
853 errorMsg("Decode/malloc failure @ nnproto_parse_delete_user()\n"); | |
854 return -1; | |
855 } | |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
856 |
422 | 857 win = nnwin_find(p); |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
858 nn_userhash_delete(nnUsers, nn_username_encode(p)); |
107
8037a3a7e491
Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
859 |
654
9c2ae1b96674
Change messages for join/part.
Matti Hamalainen <ccr@tnsp.org>
parents:
652
diff
changeset
|
860 printMsg(NULL, "! ½3½%s½0½ ½1½LEFT.½0½\n", p); |
297
d34910f1b1e1
Print messages about user leaving or joining the chat in the specific buffer, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
861 if (win != NULL) |
d34910f1b1e1
Print messages about user leaving or joining the chat in the specific buffer, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
293
diff
changeset
|
862 printMsg(win, "! ½3½%s½0½ ½1½left the chat.½0½\n", p); |
391 | 863 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
864 th_free(p); |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
865 return 0; |
0 | 866 } |
867 | |
868 | |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
869 int nnproto_parse_num_clients(th_conn_t *conn) |
0 | 870 { |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
871 th_conn_buf_strstr(conn, "</NUMCLIENTS>"); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
872 return 0; |
0 | 873 } |
874 | |
875 | |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
876 int nnproto_parse_boot(th_conn_t *conn) |
96
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
877 { |
391 | 878 (void) conn; |
96
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
879 errorMsg("Booted by server.\n"); |
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
880 return -1; |
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
881 } |
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
882 |
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
883 |
391 | 884 typedef struct |
885 { | |
443 | 886 char *name; |
431
a9b20b31cae1
More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
430
diff
changeset
|
887 size_t len; |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
888 int (*handler)(th_conn_t *); |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
889 } nn_protocolcmd_t; |
0 | 890 |
891 | |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
892 static nn_protocolcmd_t protoCmds[] = |
391 | 893 { |
431
a9b20b31cae1
More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
430
diff
changeset
|
894 { "<USER>", 0, nnproto_parse_user }, |
a9b20b31cae1
More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
430
diff
changeset
|
895 { "<LOGIN_", 0, nnproto_parse_login }, |
a9b20b31cae1
More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
430
diff
changeset
|
896 { "<DELETE_USER>", 0, nnproto_parse_delete_user }, |
a9b20b31cae1
More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
430
diff
changeset
|
897 { "<ADD_USER>", 0, nnproto_parse_add_user }, |
a9b20b31cae1
More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
430
diff
changeset
|
898 { "<NUMCLIENTS>", 0, nnproto_parse_num_clients }, |
a9b20b31cae1
More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
430
diff
changeset
|
899 { "<BOOT />", 0, nnproto_parse_boot }, |
0 | 900 }; |
901 | |
108
f323b137ca08
Tab-completion now works with cycling, but bugs with names that have whitespaces.
Matti Hamalainen <ccr@tnsp.org>
parents:
107
diff
changeset
|
902 static const int nprotoCmds = sizeof(protoCmds) / sizeof(protoCmds[0]); |
0 | 903 |
904 | |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
905 int nn_parse_protocol(th_conn_t *conn) |
0 | 906 { |
130
352ec3c300e4
A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
907 static BOOL protoCmdsInit = FALSE; |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
908 int i; |
130
352ec3c300e4
A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
909 |
391 | 910 if (!protoCmdsInit) |
911 { | |
130
352ec3c300e4
A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
912 for (i = 0; i < nprotoCmds; i++) |
443 | 913 protoCmds[i].len = strlen(protoCmds[i].name); |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
914 |
130
352ec3c300e4
A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
915 protoCmdsInit = TRUE; |
352ec3c300e4
A different initialization.
Matti Hamalainen <ccr@tnsp.org>
parents:
129
diff
changeset
|
916 } |
391 | 917 |
918 for (i = 0; i < nprotoCmds; i++) | |
919 { | |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
920 if (!th_conn_buf_strncmp(conn, protoCmds[i].name, protoCmds[i].len)) |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
921 return protoCmds[i].handler(conn); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
922 } |
162
e59cec397811
Add a debug mode option (commandline) and enable certain features when we are in debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
923 |
391 | 924 if (optDebug) |
925 { | |
639
02e1307e2a62
API changes in th_network module.
Matti Hamalainen <ccr@tnsp.org>
parents:
638
diff
changeset
|
926 printMsg(NULL, "Unknown protocmd: \"%s\"\n", conn->base.ptr); |
162
e59cec397811
Add a debug mode option (commandline) and enable certain features when we are in debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
927 return 0; |
391 | 928 } |
929 else | |
162
e59cec397811
Add a debug mode option (commandline) and enable certain features when we are in debug mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
161
diff
changeset
|
930 return 1; |
0 | 931 } |
932 | |
402
563a70e8a303
Oops, these functions were moved/renamed and were left out from a previous commit. :|
Matti Hamalainen <ccr@tnsp.org>
parents:
401
diff
changeset
|
933 |
474
4ddc3d87242e
Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
934 int nn_open_uri(const char *uri) |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
935 { |
661
eb3692d85ac2
Use TH_PLAT_WINDOWS for preprocessor conditionals.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
936 #ifdef TH_PLAT_WINDOWS |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
937 HINSTANCE status; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
938 |
442 | 939 status = ShellExecute(NULL, "open", uri, NULL, NULL, SW_SHOWNA); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
940 if (status <= (HINSTANCE) 32) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
941 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
942 printMsgQ(currWin, "Could not launch default web browser: %d\n", status); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
943 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
944 #else |
474
4ddc3d87242e
Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
945 int status; |
4ddc3d87242e
Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
946 int fds[2]; |
4ddc3d87242e
Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
947 pid_t pid; |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
948 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
949 if (pipe(fds) == -1) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
950 { |
621
29b8ff5b625b
Use th_get_error() and th_error_str().
Matti Hamalainen <ccr@tnsp.org>
parents:
620
diff
changeset
|
951 int ret = th_get_error(); |
29b8ff5b625b
Use th_get_error() and th_error_str().
Matti Hamalainen <ccr@tnsp.org>
parents:
620
diff
changeset
|
952 printMsgQ(currWin, "Could not open process communication pipe! (%d, %s)\n", |
29b8ff5b625b
Use th_get_error() and th_error_str().
Matti Hamalainen <ccr@tnsp.org>
parents:
620
diff
changeset
|
953 ret, th_error_str(ret)); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
954 return 0; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
955 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
956 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
957 if ((pid = fork()) < 0) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
958 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
959 printMsgQ(currWin, "Could not create sub-process!\n"); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
960 } |
652
58a376f86cdf
Make browser a configurable setting (in addition to environment variable),
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
961 else |
58a376f86cdf
Make browser a configurable setting (in addition to environment variable),
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
962 if (pid == 0) |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
963 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
964 dup2(fds[1], STDOUT_FILENO); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
965 dup2(fds[0], STDERR_FILENO); |
652
58a376f86cdf
Make browser a configurable setting (in addition to environment variable),
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
966 switch (optBrowserRunMethod) |
58a376f86cdf
Make browser a configurable setting (in addition to environment variable),
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
967 { |
58a376f86cdf
Make browser a configurable setting (in addition to environment variable),
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
968 case BMT_NEW_FIREFOX: |
58a376f86cdf
Make browser a configurable setting (in addition to environment variable),
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
969 // Newer method, supported by new-ish versions of Firefox |
58a376f86cdf
Make browser a configurable setting (in addition to environment variable),
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
970 execlp(setBrowser, setBrowser, "-new-tab", uri, (void *)NULL); |
58a376f86cdf
Make browser a configurable setting (in addition to environment variable),
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
971 break; |
58a376f86cdf
Make browser a configurable setting (in addition to environment variable),
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
972 |
58a376f86cdf
Make browser a configurable setting (in addition to environment variable),
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
973 default: |
58a376f86cdf
Make browser a configurable setting (in addition to environment variable),
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
974 // Default old method |
58a376f86cdf
Make browser a configurable setting (in addition to environment variable),
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
975 { |
58a376f86cdf
Make browser a configurable setting (in addition to environment variable),
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
976 char *url = th_strdup_printf("openurl(%s,new-tab)", uri); |
58a376f86cdf
Make browser a configurable setting (in addition to environment variable),
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
977 execlp(setBrowser, setBrowser, "-remote", url, (void *)NULL); |
58a376f86cdf
Make browser a configurable setting (in addition to environment variable),
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
978 th_free(url); |
58a376f86cdf
Make browser a configurable setting (in addition to environment variable),
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
979 } |
58a376f86cdf
Make browser a configurable setting (in addition to environment variable),
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
980 } |
58a376f86cdf
Make browser a configurable setting (in addition to environment variable),
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
981 |
621
29b8ff5b625b
Use th_get_error() and th_error_str().
Matti Hamalainen <ccr@tnsp.org>
parents:
620
diff
changeset
|
982 _exit(th_get_error()); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
983 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
984 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
985 wait(&status); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
986 #endif |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
987 |
474
4ddc3d87242e
Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
988 return 0; |
4ddc3d87242e
Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
989 } |
4ddc3d87242e
Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
990 |
516 | 991 |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
992 int nncmd_send_raw(th_conn_t *conn, char *str) |
603
0a30bf8db004
Add new command /raw for sending only once encoded data.
Matti Hamalainen <ccr@tnsp.org>
parents:
602
diff
changeset
|
993 { |
0a30bf8db004
Add new command /raw for sending only once encoded data.
Matti Hamalainen <ccr@tnsp.org>
parents:
602
diff
changeset
|
994 #if 1 |
0a30bf8db004
Add new command /raw for sending only once encoded data.
Matti Hamalainen <ccr@tnsp.org>
parents:
602
diff
changeset
|
995 char *tmp = nn_encode_str1(str); |
0a30bf8db004
Add new command /raw for sending only once encoded data.
Matti Hamalainen <ccr@tnsp.org>
parents:
602
diff
changeset
|
996 if (tmp == NULL) return -2; |
0a30bf8db004
Add new command /raw for sending only once encoded data.
Matti Hamalainen <ccr@tnsp.org>
parents:
602
diff
changeset
|
997 nn_conn_send_msg(conn, optUserNameEnc, tmp); |
0a30bf8db004
Add new command /raw for sending only once encoded data.
Matti Hamalainen <ccr@tnsp.org>
parents:
602
diff
changeset
|
998 th_free(tmp); |
0a30bf8db004
Add new command /raw for sending only once encoded data.
Matti Hamalainen <ccr@tnsp.org>
parents:
602
diff
changeset
|
999 #else |
0a30bf8db004
Add new command /raw for sending only once encoded data.
Matti Hamalainen <ccr@tnsp.org>
parents:
602
diff
changeset
|
1000 nn_conn_send_msg(conn, optUserNameEnc, str); |
0a30bf8db004
Add new command /raw for sending only once encoded data.
Matti Hamalainen <ccr@tnsp.org>
parents:
602
diff
changeset
|
1001 #endif |
0a30bf8db004
Add new command /raw for sending only once encoded data.
Matti Hamalainen <ccr@tnsp.org>
parents:
602
diff
changeset
|
1002 |
0a30bf8db004
Add new command /raw for sending only once encoded data.
Matti Hamalainen <ccr@tnsp.org>
parents:
602
diff
changeset
|
1003 return 0; |
0a30bf8db004
Add new command /raw for sending only once encoded data.
Matti Hamalainen <ccr@tnsp.org>
parents:
602
diff
changeset
|
1004 } |
0a30bf8db004
Add new command /raw for sending only once encoded data.
Matti Hamalainen <ccr@tnsp.org>
parents:
602
diff
changeset
|
1005 |
0a30bf8db004
Add new command /raw for sending only once encoded data.
Matti Hamalainen <ccr@tnsp.org>
parents:
602
diff
changeset
|
1006 |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
1007 int nncmd_open_profile(th_conn_t *conn, char *name) |
474
4ddc3d87242e
Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
1008 { |
4ddc3d87242e
Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
1009 char *enc_name = nn_encode_str1(name); |
4ddc3d87242e
Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
1010 char *uri = th_strdup_printf(SET_PROFILE_PREFIX, name); |
4ddc3d87242e
Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
1011 (void) conn; |
4ddc3d87242e
Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
1012 |
4ddc3d87242e
Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
1013 printMsg(currWin, "Opening profile for: '%s'\n", name); |
4ddc3d87242e
Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
1014 |
4ddc3d87242e
Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
1015 nn_open_uri(uri); |
4ddc3d87242e
Refactor web-browser launching into nn_open_uri().
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
1016 |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1017 th_free(uri); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1018 th_free(enc_name); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1019 return 0; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1020 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1021 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1022 |
657
8b8ef14d7177
Update to match th-libs API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
654
diff
changeset
|
1023 int nncmd_change_list(th_conn_t *conn, const char *listname, th_llist_t **list, const char *name) |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1024 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1025 (void) conn; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1026 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1027 if (name[0]) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1028 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1029 // Add or remove someone to/from ignore |
657
8b8ef14d7177
Update to match th-libs API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
654
diff
changeset
|
1030 th_llist_t *user = th_llist_find_func(*list, name, str_compare); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1031 if (user != NULL) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1032 { |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
1033 printMsgQ(currWin, "Removed user '%s' from %s list.\n", name, listname); |
531 | 1034 th_llist_delete_node(list, user); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1035 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1036 else |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1037 { |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
1038 printMsgQ(currWin, "Added '%s' to %s list.\n", name, listname); |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
1039 th_llist_append(list, th_strdup(name)); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1040 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1041 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1042 else |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1043 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1044 // Just list whomever is in ignore now |
657
8b8ef14d7177
Update to match th-libs API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
654
diff
changeset
|
1045 th_llist_t *user = *list; |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
1046 size_t nuser = th_llist_length(*list); |
696 | 1047 char *result = th_strdup_printf("Users on %s list (%" PRIu_SIZE_T "): ", |
1048 listname, nuser); | |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1049 while (user != NULL) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1050 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1051 if (user->data != NULL) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1052 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1053 th_pstr_printf(&result, "%s'%s'", result, (char *) user->data); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1054 if (--nuser > 0) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1055 th_pstr_printf(&result, "%s, ", result); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1056 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1057 user = user->next; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1058 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1059 printMsgQ(currWin, "%s\n", result); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1060 th_free(result); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1061 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1062 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1063 return 0; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1064 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1065 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1066 |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
1067 int nncmd_ignore(th_conn_t *conn, char *name) |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
1068 { |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
1069 return nncmd_change_list(conn, "ignore", &setIgnoreList, name); |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
1070 } |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
1071 |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
1072 |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
1073 int nncmd_friend(th_conn_t *conn, char *name) |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
1074 { |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
1075 return nncmd_change_list(conn, "friend", &setFriendList, name); |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
1076 } |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
1077 |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
1078 |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
1079 int nncmd_set_color(th_conn_t *conn, char *arg) |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1080 { |
690
6fa9c36d0634
Adjust to match th-libs API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
689
diff
changeset
|
1081 unsigned int val; |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1082 (void) conn; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1083 |
690
6fa9c36d0634
Adjust to match th-libs API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
689
diff
changeset
|
1084 if (!th_get_hex_triplet(arg, &val)) |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1085 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1086 printMsgQ(currWin, "Invalid color value '%s'\n", arg); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1087 return 1; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1088 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1089 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1090 optUserColor = val; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1091 printMsgQ(currWin, "Setting color to #%06x\n", optUserColor); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1092 nn_conn_send_msg_v(conn, optUserNameEnc, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1093 return 0; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1094 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1095 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1096 |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
1097 int nncmd_open_query(th_conn_t *conn, char *name) |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1098 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1099 (void) conn; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1100 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1101 if (name[0]) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1102 { |
446
3396acd40147
Rename and remove some functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1103 nn_user_t *user = nn_userhash_find(nnUsers, nn_username_encode(name)); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1104 if (user != NULL) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1105 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1106 name = nn_username_decode(th_strdup(user->name)); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1107 printMsgQ(currWin, "Opening PRV query for '%s'.\n", name); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1108 if (nnwin_open(name, TRUE)) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1109 printMsgQ(currWin, "In PRV query with '%s'.\n", name); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1110 th_free(name); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1111 return 0; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1112 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1113 else |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1114 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1115 printMsgQ(currWin, "Could not find username '%s'.\n", name); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1116 return 1; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1117 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1118 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1119 else |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1120 { |
472 | 1121 printMsgQ(currWin, |
1122 "Usage: /query username\n" | |
1123 "To close a PRV query, use /close [username]\n" | |
1124 "/close without username will close the current PRV window, if any.\n"); | |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1125 return 1; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1126 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1127 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1128 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1129 |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
1130 int nncmd_close_query(th_conn_t *conn, char *name) |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1131 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1132 (void) conn; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1133 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1134 if (name[0]) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1135 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1136 nn_window_t *win = nnwin_find(name); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1137 if (win != NULL) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1138 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1139 nnwin_close(win); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1140 printMsgQ(currWin, "Closed PRV query to '%s'.\n", name); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1141 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1142 else |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1143 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1144 printMsgQ(currWin, "No PRV query by name '%s'.\n", name); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1145 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1146 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1147 else |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1148 { |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
464
diff
changeset
|
1149 if (currWin != nnwin_main_window()) |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1150 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1151 nnwin_close(currWin); |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
464
diff
changeset
|
1152 currWin = nnwin_main_window(); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1153 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1154 else |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1155 { |
472 | 1156 printMsgQ(currWin, |
1157 "Usage: /close [username]\n" | |
1158 "/close without username will close the current PRV window. if any.\n"); | |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1159 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1160 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1161 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1162 return 0; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1163 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1164 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1165 |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
1166 int nncmd_window_info(th_conn_t *conn, char *arg) |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1167 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1168 (void) conn; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1169 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1170 if (arg[0]) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1171 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1172 int val = atoi(arg); |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
464
diff
changeset
|
1173 nn_window_t *win = nnwin_get(val); |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
464
diff
changeset
|
1174 if (win != NULL) |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
464
diff
changeset
|
1175 currWin = win; |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1176 else |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1177 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1178 printMsgQ(currWin, "Invalid window number '%s'\n", arg); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1179 return 1; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1180 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1181 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1182 else |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1183 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1184 printMsgQ(currWin, "Window : #%d\n", currWin->num); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1185 printMsgQ(currWin, "ID : %s\n", currWin->id); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1186 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1187 return 0; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1188 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1189 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1190 |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
1191 int nncmd_list_all_users(th_conn_t *conn, char *buf) |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1192 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1193 (void) buf; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1194 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1195 // Alias /listallusers |
425 | 1196 return nn_conn_send_msg(conn, optUserNameEnc, "%2Flistallusers"); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1197 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1198 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1199 |
486
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1200 #define NAME_NUM_PER_LINE 3 |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1201 #define NAME_ENTRY_SIZE 64 |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1202 #define NAME_ENTRY_WIDTH 22 |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1203 |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1204 typedef struct |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1205 { |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1206 char buf[(NAME_NUM_PER_LINE * NAME_ENTRY_SIZE) + 16]; |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1207 size_t offs; |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1208 int i, total; |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1209 } nncmd_namedata_t; |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1210 |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1211 |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1212 static int nncmd_names_do(const nn_user_t *user, void *data) |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1213 { |
486
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1214 nncmd_namedata_t *d = data; |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1215 char name[NAME_ENTRY_SIZE]; |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1216 size_t len; |
538
ffacb78d9b9f
Add colorization of usernames on userlist based on friend/ignore status.
Matti Hamalainen <ccr@tnsp.org>
parents:
536
diff
changeset
|
1217 int color; |
486
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1218 |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
1219 if (nn_check_name_list(setFriendList, user->name)) |
538
ffacb78d9b9f
Add colorization of usernames on userlist based on friend/ignore status.
Matti Hamalainen <ccr@tnsp.org>
parents:
536
diff
changeset
|
1220 color = 11; |
ffacb78d9b9f
Add colorization of usernames on userlist based on friend/ignore status.
Matti Hamalainen <ccr@tnsp.org>
parents:
536
diff
changeset
|
1221 else |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
1222 if (nn_check_name_list(setIgnoreList, user->name)) |
538
ffacb78d9b9f
Add colorization of usernames on userlist based on friend/ignore status.
Matti Hamalainen <ccr@tnsp.org>
parents:
536
diff
changeset
|
1223 color = 1; |
ffacb78d9b9f
Add colorization of usernames on userlist based on friend/ignore status.
Matti Hamalainen <ccr@tnsp.org>
parents:
536
diff
changeset
|
1224 else |
ffacb78d9b9f
Add colorization of usernames on userlist based on friend/ignore status.
Matti Hamalainen <ccr@tnsp.org>
parents:
536
diff
changeset
|
1225 color = 3; |
ffacb78d9b9f
Add colorization of usernames on userlist based on friend/ignore status.
Matti Hamalainen <ccr@tnsp.org>
parents:
536
diff
changeset
|
1226 |
ffacb78d9b9f
Add colorization of usernames on userlist based on friend/ignore status.
Matti Hamalainen <ccr@tnsp.org>
parents:
536
diff
changeset
|
1227 snprintf(name, sizeof(name), "[½%d½%-20s½0½] ", color, user->name); |
486
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1228 |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1229 d->total++; |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1230 if (d->i >= NAME_NUM_PER_LINE) |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1231 { |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1232 printMsgQ(currWin, "%s\n", d->buf); |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1233 d->i = 0; |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1234 d->offs = 0; |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1235 } |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1236 |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1237 len = strlen(name); |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1238 memcpy(d->buf + d->offs, name, len + 1); |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1239 d->offs += len; |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1240 d->i++; |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1241 |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1242 return 0; |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1243 } |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1244 |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1245 |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
1246 int nncmd_names(th_conn_t *conn, char *arg) |
486
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1247 { |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1248 nncmd_namedata_t data; |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1249 (void) conn; |
486
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1250 (void) arg; |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1251 |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1252 printMsgQ(currWin, "Users:\n"); |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1253 data.i = data.total = 0; |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1254 data.offs = 0; |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1255 |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1256 nn_userhash_foreach(nnUsers, nncmd_names_do, &data); |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1257 |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1258 if (data.i > 0) |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1259 { |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1260 printMsgQ(currWin, "%s\n", data.buf); |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1261 } |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1262 |
d48327519b17
Implement /who / /names functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
481
diff
changeset
|
1263 printMsgQ(currWin, "%d users total.\n", data.total); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1264 return 0; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1265 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1266 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1267 |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
1268 int nncmd_save_config(th_conn_t *conn, char *buf) |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1269 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1270 (void) conn; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1271 (void) buf; |
663
0b81e5fdc7b5
Use the new io context API.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
1272 th_ioctx *ctx = NULL; |
556
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1273 int cfgfd = -1; |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1274 |
664
87ef546de419
Create configuration directory path if it does not yet exist when saving
Matti Hamalainen <ccr@tnsp.org>
parents:
663
diff
changeset
|
1275 if (!th_mkdir_path(setConfigDir, 0)) |
87ef546de419
Create configuration directory path if it does not yet exist when saving
Matti Hamalainen <ccr@tnsp.org>
parents:
663
diff
changeset
|
1276 { |
87ef546de419
Create configuration directory path if it does not yet exist when saving
Matti Hamalainen <ccr@tnsp.org>
parents:
663
diff
changeset
|
1277 printMsgQ(currWin, "Could not create configuration file directory '%s'.\n", |
87ef546de419
Create configuration directory path if it does not yet exist when saving
Matti Hamalainen <ccr@tnsp.org>
parents:
663
diff
changeset
|
1278 setConfigDir); |
87ef546de419
Create configuration directory path if it does not yet exist when saving
Matti Hamalainen <ccr@tnsp.org>
parents:
663
diff
changeset
|
1279 goto error; |
87ef546de419
Create configuration directory path if it does not yet exist when saving
Matti Hamalainen <ccr@tnsp.org>
parents:
663
diff
changeset
|
1280 } |
87ef546de419
Create configuration directory path if it does not yet exist when saving
Matti Hamalainen <ccr@tnsp.org>
parents:
663
diff
changeset
|
1281 |
663
0b81e5fdc7b5
Use the new io context API.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
1282 if ((ctx = th_io_new(&th_stdio_io_ops, setConfigFile)) == NULL) |
561
1ff9e85a1fcc
Rework the configuration file loading and saving to use the I/O context and new th-config API.
Matti Hamalainen <ccr@tnsp.org>
parents:
560
diff
changeset
|
1283 { |
1ff9e85a1fcc
Rework the configuration file loading and saving to use the I/O context and new th-config API.
Matti Hamalainen <ccr@tnsp.org>
parents:
560
diff
changeset
|
1284 printMsgQ(currWin, "Could not initialize I/O context for configuration file writing!\n"); |
1ff9e85a1fcc
Rework the configuration file loading and saving to use the I/O context and new th-config API.
Matti Hamalainen <ccr@tnsp.org>
parents:
560
diff
changeset
|
1285 goto error; |
1ff9e85a1fcc
Rework the configuration file loading and saving to use the I/O context and new th-config API.
Matti Hamalainen <ccr@tnsp.org>
parents:
560
diff
changeset
|
1286 } |
1ff9e85a1fcc
Rework the configuration file loading and saving to use the I/O context and new th-config API.
Matti Hamalainen <ccr@tnsp.org>
parents:
560
diff
changeset
|
1287 |
663
0b81e5fdc7b5
Use the new io context API.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
1288 th_io_set_handlers(ctx, nn_ioctx_errfunc, nn_ioctx_msgfunc); |
0b81e5fdc7b5
Use the new io context API.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
1289 |
672 | 1290 if ((cfgfd = open(ctx->filename, O_CREAT | O_TRUNC | O_WRONLY, |
663
0b81e5fdc7b5
Use the new io context API.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
1291 #ifdef TH_PLAT_WINDOWS |
672 | 1292 0 |
556
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1293 #else |
672 | 1294 S_IRUSR | S_IWUSR |
1295 #endif | |
1296 )) == -1 || | |
663
0b81e5fdc7b5
Use the new io context API.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
1297 (ctx->data = (void *) fdopen(cfgfd, "w")) == NULL) |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1298 { |
621
29b8ff5b625b
Use th_get_error() and th_error_str().
Matti Hamalainen <ccr@tnsp.org>
parents:
620
diff
changeset
|
1299 int err = th_get_error(); |
556
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1300 printMsgQ(currWin, "Could not create configuration to file '%s', %d: %s\n", |
663
0b81e5fdc7b5
Use the new io context API.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
1301 ctx->filename, err, th_error_str(err)); |
556
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1302 goto error; |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1303 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1304 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1305 printMsgQ(currWin, "Configuration saved in file '%s', res=%d\n", |
663
0b81e5fdc7b5
Use the new io context API.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
1306 ctx->filename, th_cfg_write(ctx, cfg)); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1307 |
556
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1308 error: |
663
0b81e5fdc7b5
Use the new io context API.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
1309 th_io_free(ctx); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1310 return 0; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1311 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1312 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1313 |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
1314 int nncmd_quit(th_conn_t *conn, char *buf) |
573 | 1315 { |
1316 (void) conn; | |
1317 (void) buf; | |
1318 | |
1319 appQuitFlag = TRUE; | |
1320 return 0; | |
1321 } | |
1322 | |
1323 | |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1324 enum |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1325 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1326 CMDARG_NONE, |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1327 CMDARG_STRING, |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1328 CMDARG_OPTIONAL, |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1329 CMDARG_NICK, |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1330 }; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1331 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1332 typedef struct |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1333 { |
443 | 1334 char *name; |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1335 int flags; |
431
a9b20b31cae1
More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
430
diff
changeset
|
1336 size_t len; |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
1337 int (*handler)(th_conn_t *, char *buf); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1338 } nn_usercmd_t; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1339 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1340 |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1341 static nn_usercmd_t userCmdsTable[] = |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1342 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1343 // Server side commands, we just implement completion |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1344 { "/me", CMDARG_STRING, 0, NULL }, |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1345 { "/status", CMDARG_STRING, 0, NULL }, |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1346 { "/list", CMDARG_NONE, 0, nncmd_list_all_users }, |
518 | 1347 { "/prvon", CMDARG_NONE, 0, NULL }, |
1348 { "/prvoff", CMDARG_NONE, 0, NULL }, | |
601
e661d7654e23
Add /mute to 'supported' passthrough commands.
Matti Hamalainen <ccr@tnsp.org>
parents:
599
diff
changeset
|
1349 { "/mute", CMDARG_STRING, 0, NULL }, |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1350 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1351 // List internal username list |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1352 { "/who", CMDARG_NONE, 0, nncmd_names }, |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1353 { "/names", CMDARG_NONE, 0, nncmd_names }, |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1354 |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1355 { "/w", CMDARG_NICK, 0, nncmd_open_profile }, |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1356 { "/profile", CMDARG_NICK, 0, nncmd_open_profile }, |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1357 |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1358 { "/query", CMDARG_NICK, 0, nncmd_open_query }, |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1359 { "/close", CMDARG_OPTIONAL, 0, nncmd_close_query }, |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1360 { "/win", CMDARG_OPTIONAL, 0, nncmd_window_info }, |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1361 |
497 | 1362 { "/ignore", CMDARG_OPTIONAL, 0, nncmd_ignore }, |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
1363 { "/friend", CMDARG_OPTIONAL, 0, nncmd_friend }, |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1364 { "/color", CMDARG_STRING, 0, nncmd_set_color }, |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1365 { "/save", CMDARG_NONE, 0, nncmd_save_config }, |
573 | 1366 |
603
0a30bf8db004
Add new command /raw for sending only once encoded data.
Matti Hamalainen <ccr@tnsp.org>
parents:
602
diff
changeset
|
1367 { "/raw", CMDARG_STRING, 0, nncmd_send_raw }, |
0a30bf8db004
Add new command /raw for sending only once encoded data.
Matti Hamalainen <ccr@tnsp.org>
parents:
602
diff
changeset
|
1368 |
573 | 1369 { "/quit", CMDARG_NONE, 0, nncmd_quit }, |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1370 }; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1371 |
657
8b8ef14d7177
Update to match th-libs API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
654
diff
changeset
|
1372 static th_llist_t *userCmds = NULL; |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1373 |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1374 |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1375 void nn_usercmd_init() |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1376 { |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1377 size_t i; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1378 for (i = 0; i < sizeof(userCmdsTable) / sizeof(userCmdsTable[0]); i++) |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1379 { |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1380 th_llist_append(&userCmds, &userCmdsTable[i]); |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1381 userCmdsTable[i].len = strlen(userCmdsTable[i].name); |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1382 } |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1383 } |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1384 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1385 |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
1386 int nn_handle_command(th_conn_t *conn, char *buf) |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1387 { |
657
8b8ef14d7177
Update to match th-libs API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
654
diff
changeset
|
1388 th_llist_t *curr; |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1389 |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1390 for (curr = userCmds; curr != NULL; curr = curr->next) |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1391 { |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1392 nn_usercmd_t *cmd = curr->data; |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1393 |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1394 if (!th_strncasecmp(buf, cmd->name, cmd->len)) |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1395 { |
457 | 1396 char *nbuf; |
1397 if (buf[cmd->len] != 0 && !th_isspace(buf[cmd->len])) | |
1398 continue; | |
1399 | |
1400 nbuf = str_trim_left(buf + cmd->len); | |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1401 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1402 switch (cmd->flags) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1403 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1404 case CMDARG_NICK: |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1405 case CMDARG_STRING: |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1406 if (!nbuf[0]) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1407 { |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1408 printMsgQ(currWin, "Command %s requires an argument.\n", cmd->name); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1409 return 1; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1410 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1411 break; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1412 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1413 case CMDARG_NONE: |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1414 if (nbuf[0]) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1415 { |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1416 printMsgQ(currWin, "Command %s does not take arguments.\n", cmd->name); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1417 return 1; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1418 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1419 break; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1420 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1421 case CMDARG_OPTIONAL: |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1422 break; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1423 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1424 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1425 // Check if there is a handler function |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1426 if (cmd->handler) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1427 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1428 // Internal commands have a handler |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1429 return cmd->handler(conn, nbuf); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1430 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1431 else |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1432 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1433 // Server-side commands are just pass-through here |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1434 char *tmp = nn_dblencode_str(buf); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1435 BOOL result; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1436 if (tmp == NULL) return -2; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1437 result = nn_conn_send_msg(conn, optUserNameEnc, tmp); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1438 th_free(tmp); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1439 return result ? 0 : -1; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1440 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1441 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1442 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1443 |
444 | 1444 printMsgQ(currWin, "Unknown command: %s\n", buf); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1445 return 1; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1446 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1447 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1448 |
657
8b8ef14d7177
Update to match th-libs API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
654
diff
changeset
|
1449 static nn_usercmd_t *nn_usercmd_match_do(th_llist_t *list, const char *pattern, size_t len) |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1450 { |
657
8b8ef14d7177
Update to match th-libs API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
654
diff
changeset
|
1451 th_llist_t *node; |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1452 for (node = list; node != NULL; node = node->next) |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1453 { |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1454 nn_usercmd_t *cmd = node->data; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1455 if (len <= strlen(cmd->name) && th_strncasecmp(cmd->name, pattern, len) == 0) |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1456 return cmd; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1457 } |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1458 return NULL; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1459 } |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1460 |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1461 |
657
8b8ef14d7177
Update to match th-libs API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
654
diff
changeset
|
1462 nn_usercmd_t *nn_usercmd_match(th_llist_t *list, const char *pattern, const char *current, BOOL again) |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1463 { |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1464 nn_usercmd_t *curr; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1465 size_t len; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1466 |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1467 if (list == NULL || pattern == NULL) return NULL; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1468 |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1469 len = strlen(pattern); |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1470 |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1471 if (current != NULL) |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1472 { |
657
8b8ef14d7177
Update to match th-libs API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
654
diff
changeset
|
1473 th_llist_t *node; |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1474 for (node = list; node != NULL; node = node->next) |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1475 { |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1476 curr = node->data; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1477 if (th_strcasecmp(curr->name, current) == 0) |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1478 { |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1479 if (again) |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1480 return curr; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1481 |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1482 if ((curr = nn_usercmd_match_do(node->next, pattern, len)) != NULL) |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1483 return curr; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1484 } |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1485 } |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1486 } |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1487 |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1488 if ((curr = nn_usercmd_match_do(list, pattern, len)) != NULL) |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1489 return curr; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1490 |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1491 return NULL; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1492 } |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1493 |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1494 |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
1495 int nn_handle_input(th_conn_t *conn, char *buf, size_t bufLen) |
0 | 1496 { |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1497 BOOL result; |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1498 char *tmp; |
391 | 1499 |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1500 // Trim right side |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1501 while (bufLen > 0 && th_isspace(buf[bufLen - 1])) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1502 buf[--bufLen] = 0; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1503 |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1504 if (buf[0] == 0) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1505 return 1; |
258 | 1506 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1507 // Decode completed usernames |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1508 nn_username_decode(buf); |
391 | 1509 |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1510 // Check for commands |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1511 if (buf[0] == '/') |
426 | 1512 return nn_handle_command(conn, buf); |
133 | 1513 |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1514 // If current window is not the main room window, send private |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
464
diff
changeset
|
1515 if (currWin != nnwin_main_window()) |
391 | 1516 { |
1517 if (currWin->id != NULL) | |
1518 { | |
431
a9b20b31cae1
More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
430
diff
changeset
|
1519 char *msg = th_strdup_printf("/prv -to %s -msg %s", currWin->id, buf); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1520 if (msg == NULL) return -3; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1521 tmp = nn_dblencode_str(msg); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1522 if (tmp == NULL) |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1523 { |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1524 th_free(msg); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1525 return -2; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1526 } |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1527 result = nn_conn_send_msg(conn, optUserNameEnc, tmp); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1528 th_free(tmp); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1529 th_free(msg); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1530 return result ? 0 : -1; |
391 | 1531 } |
1532 else | |
1533 { | |
322
b9c15c57dc8f
Clean up message functions, add new printMsgQ() helper function for messages that should not
Matti Hamalainen <ccr@tnsp.org>
parents:
321
diff
changeset
|
1534 printMsgQ(NULL, "No target set, exiting prv mode.\n"); |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1535 return 1; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1536 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1537 } |
291
cc2a1d837e7b
Window / buffer functionality works now. Queries work (with few minor glitches).
Matti Hamalainen <ccr@tnsp.org>
parents:
289
diff
changeset
|
1538 |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1539 // Send double-encoded message |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1540 tmp = nn_dblencode_str(buf); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1541 if (tmp == NULL) return -2; |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1542 result = nn_conn_send_msg(conn, optUserNameEnc, tmp); |
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
1543 th_free(tmp); |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
1544 return result ? 0 : -1; |
0 | 1545 } |
1546 | |
405 | 1547 |
449
7d9fa9f7caf1
Rename tab completion functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
1548 static void nn_tabcomplete_replace(nn_editbuf_t *buf, size_t *pi, const size_t startPos, const size_t endPos, char *c) |
447
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1549 { |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1550 size_t i; |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1551 |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1552 for (i = startPos; i <= endPos; i++) |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1553 nn_editbuf_delete(buf, startPos); |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1554 |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1555 for (i = startPos; *c; i++, c++) |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1556 nn_editbuf_insert(buf, i, *c); |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1557 |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1558 *pi = i; |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1559 } |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1560 |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1561 |
449
7d9fa9f7caf1
Rename tab completion functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
1562 static void nn_tabcomplete_finish(nn_editbuf_t *buf, char **previous, const size_t startPos, const char *name) |
447
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1563 { |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1564 nn_editbuf_setpos(buf, startPos + 1 + strlen(name)); |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1565 th_free(*previous); |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1566 *previous = th_strdup(name); |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1567 } |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1568 |
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1569 |
449
7d9fa9f7caf1
Rename tab completion functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
1570 BOOL nn_tabcomplete_buffer(nn_editbuf_t *buf) |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
1571 { |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1572 static char *previous = NULL, *pattern = NULL; |
451 | 1573 char *str = buf->data; |
429
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1574 BOOL again = FALSE, hasSeparator = FALSE, |
447
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1575 hasSpace, newPattern = FALSE, isCommand; |
431
a9b20b31cae1
More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
430
diff
changeset
|
1576 size_t endPos, startPos = buf->pos; |
107
8037a3a7e491
Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
1577 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1578 // previous word |
391 | 1579 if (startPos >= 2 && str[startPos - 1] == ' ' && str[startPos - 2] != ' ') |
1580 { | |
113
2a53156e7e12
Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
1581 startPos -= 2; |
2a53156e7e12
Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
1582 endPos = startPos; |
2a53156e7e12
Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
1583 while (startPos > 0 && str[startPos - 1] != ' ') startPos--; |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1584 } |
391 | 1585 else |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1586 // middle of a word, new pattern |
404
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1587 if (startPos < buf->len && str[startPos] != ' ') |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1588 { |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1589 endPos = startPos; |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1590 while (startPos > 0 && str[startPos - 1] != ' ') startPos--; |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1591 while (endPos < buf->len - 1 && str[endPos + 1] != ' ') endPos++; |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1592 newPattern = TRUE; |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1593 } |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1594 else |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1595 // previous word, new pattern |
404
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1596 if (startPos >= 1 && str[startPos - 1] != ' ') |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1597 { |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1598 startPos -= 1; |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1599 endPos = startPos; |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1600 while (startPos > 0 && str[startPos - 1] != ' ') startPos--; |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1601 newPattern = TRUE; |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1602 } |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1603 else |
d11a68f214eb
Fix indentation after astyle reindent.
Matti Hamalainen <ccr@tnsp.org>
parents:
403
diff
changeset
|
1604 return FALSE; |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1605 |
429
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1606 // Check if this is a command completion |
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1607 isCommand = (str[0] == '/' && startPos == 0); |
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1608 |
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1609 if (!isCommand && str[endPos] == optNickSep) |
391 | 1610 { |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1611 endPos--; |
391 | 1612 if (startPos > 0) |
113
2a53156e7e12
Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
1613 return FALSE; |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1614 hasSeparator = TRUE; |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1615 } |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1616 |
451 | 1617 hasSpace = (buf->pos > 0 && str[buf->pos - 1] == ' ') || |
447
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1618 (buf->pos <= buf->len && str[buf->pos] == ' '); |
391 | 1619 |
1620 if (newPattern) | |
1621 { | |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1622 // Get pattern, check if it matches previous pattern and set 'again' flag |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1623 char *npattern = nn_editbuf_get_string(buf, startPos, endPos); |
372
b9f0bdad6285
Use th_strcasecmp() and th_strncasecmp().
Matti Hamalainen <ccr@tnsp.org>
parents:
369
diff
changeset
|
1624 if (pattern && npattern && th_strcasecmp(npattern, pattern) == 0) |
116
741e45592522
Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
1625 again = TRUE; |
391 | 1626 |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1627 th_free(pattern); |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1628 pattern = npattern; |
391 | 1629 |
1630 if (!again) | |
1631 { | |
677 | 1632 th_free_r(&previous); |
116
741e45592522
Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
1633 } |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1634 } |
116
741e45592522
Add simple "prediction" into tab-completion based on previously gotten last
Matti Hamalainen <ccr@tnsp.org>
parents:
115
diff
changeset
|
1635 |
429
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1636 if (!pattern) |
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1637 return FALSE; |
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1638 |
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1639 if (isCommand) |
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1640 { |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1641 nn_usercmd_t *cmd = nn_usercmd_match(userCmds, pattern, previous, again); |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1642 if (cmd) |
429
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1643 { |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1644 size_t i; |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1645 nn_tabcomplete_replace(buf, &i, startPos, endPos, cmd->name); |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1646 |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1647 if (!hasSpace) |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1648 nn_editbuf_insert(buf, i++, ' '); |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1649 |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1650 nn_tabcomplete_finish(buf, &previous, startPos, cmd->name); |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1651 return TRUE; |
429
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1652 } |
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1653 } |
2ac24f1e241b
Start working on command completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
427
diff
changeset
|
1654 else |
391 | 1655 { |
446
3396acd40147
Rename and remove some functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1656 nn_user_t *user = nn_userhash_match(nnUsers, pattern, previous, again); |
107
8037a3a7e491
Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
1657 |
391 | 1658 if (user) |
1659 { | |
431
a9b20b31cae1
More code cleanups, this time using clang with excessive warnings enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
430
diff
changeset
|
1660 size_t i; |
449
7d9fa9f7caf1
Rename tab completion functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
1661 nn_tabcomplete_replace(buf, &i, startPos, endPos, user->name); |
107
8037a3a7e491
Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
1662 |
391 | 1663 if (!hasSeparator && startPos == 0) |
1664 { | |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1665 nn_editbuf_insert(buf, i++, optNickSep); |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1666 startPos++; |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1667 } |
447
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1668 else |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1669 if (hasSeparator) |
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1670 startPos++; |
447
2d650408f5de
Modularize tab completion code a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
446
diff
changeset
|
1671 |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1672 if (!hasSpace) |
113
2a53156e7e12
Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
1673 nn_editbuf_insert(buf, i++, ' '); |
189
b0d64dde62af
Fix username tab completion. Should now work like in Irssi, though the
Matti Hamalainen <ccr@tnsp.org>
parents:
188
diff
changeset
|
1674 |
449
7d9fa9f7caf1
Rename tab completion functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
1675 nn_tabcomplete_finish(buf, &previous, startPos, user->name); |
113
2a53156e7e12
Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
1676 return TRUE; |
107
8037a3a7e491
Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
1677 } |
8037a3a7e491
Implement username tab-completion. It's still buggy, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
1678 } |
391 | 1679 |
113
2a53156e7e12
Yay, tab-completion cycling now works (except for usernames with whitespaces, of course ...)
Matti Hamalainen <ccr@tnsp.org>
parents:
112
diff
changeset
|
1680 return FALSE; |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
1681 } |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
1682 |
405 | 1683 |
513 | 1684 BOOL processUserInput(int c, nn_editbuf_t *editBuf, nn_editstate_t *editState) |
1685 { | |
1686 // Chat window switching via Meta/Esc-[1..9] | |
1687 if (c >= 0x5001 && c <= 0x5009) | |
1688 { | |
1689 nn_window_t *win = nnwin_get(c - 0x5000); | |
1690 if (win != NULL) | |
1691 { | |
1692 currWin = win; | |
1693 editState->update = TRUE; | |
1694 } | |
1695 } | |
1696 else | |
1697 switch (c) | |
1698 { | |
1699 case KEY_ENTER: | |
1700 // Call the user input handler | |
1701 if (editBuf->len > 0) | |
1702 { | |
1703 int result; | |
1704 | |
1705 if (editHistMax > 0) | |
1706 { | |
1707 nn_editbuf_free(editHistBuf[SET_MAX_HISTORY+1]); | |
1708 editHistBuf[SET_MAX_HISTORY+1] = NULL; | |
1709 memmove(&editHistBuf[2], &editHistBuf[1], | |
1710 editHistMax * sizeof(editHistBuf[0])); | |
1711 } | |
1712 | |
1713 editHistPos = 0; | |
1714 editHistBuf[1] = nn_editbuf_copy(editBuf); | |
1715 if (editHistMax < SET_MAX_HISTORY) | |
1716 editHistMax++; | |
1717 | |
1718 result = nn_handle_input(editState->conn, editBuf->data, editBuf->len); | |
1719 | |
1720 nn_editbuf_clear(editBuf); | |
1721 | |
1722 if (result < 0) | |
1723 { | |
1724 errorMsg("Fatal error handling user input: %s\n", editBuf->data); | |
1725 editState->isError = TRUE; | |
1726 } | |
1727 else | |
1728 { | |
1729 // Update time value of last sent message for unidle timeouts | |
1730 editState->prevKeepAlive = time(NULL); | |
1731 } | |
1732 } | |
1733 break; | |
1734 | |
1735 case KEY_NPAGE: | |
1736 case KEY_PPAGE: | |
1737 // Page Up / Page Down | |
1738 if (currWin != NULL) | |
1739 { | |
1740 int oldPos = currWin->pos, page = (scrHeight - 4) / 3; | |
1741 | |
1742 currWin->pos += (c == KEY_NPAGE) ? - page : page; | |
1743 | |
1744 if (currWin->pos >= currWin->data->n - page) | |
1745 currWin->pos = currWin->data->n - page; | |
1746 if (currWin->pos < 0) | |
1747 currWin->pos = 0; | |
1748 | |
1749 if (oldPos != currWin->pos) | |
1750 editState->update = TRUE; | |
1751 } | |
1752 break; | |
1753 | |
1754 case KEY_UP: // Backwards in input history | |
1755 if (editHistPos == 0) | |
1756 { | |
1757 nn_editbuf_free(editHistBuf[0]); | |
1758 editHistBuf[0] = nn_editbuf_copy(editBuf); | |
1759 } | |
1760 if (editHistPos < editHistMax) | |
1761 { | |
1762 editHistPos++; | |
681
ceb73b712121
Fix an issue in editBuffer handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
678
diff
changeset
|
1763 nn_editbuf_copy_to(editBuf, editHistBuf[editHistPos]); |
513 | 1764 } |
1765 break; | |
1766 | |
1767 case KEY_DOWN: // Forwards in input history | |
1768 if (editHistPos > 0) | |
1769 { | |
1770 editHistPos--; | |
681
ceb73b712121
Fix an issue in editBuffer handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
678
diff
changeset
|
1771 nn_editbuf_copy_to(editBuf, editHistBuf[editHistPos]); |
513 | 1772 } |
1773 break; | |
1774 | |
1775 case KEY_F(5): // F5 = Ignore mode | |
515 | 1776 setIgnoreMode = !setIgnoreMode; |
513 | 1777 printMsgQ(currWin, "Ignore mode = %s\n", setIgnoreMode ? "ON" : "OFF"); |
1778 break; | |
1779 | |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
1780 case KEY_F(6): // F6 = Ignore mode |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
1781 optOnlyFriendPrv = !optOnlyFriendPrv; |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
1782 printMsgQ(currWin, "Only friends allowed to PRV you = %s\n", optOnlyFriendPrv ? "ON" : "OFF"); |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
1783 break; |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
1784 |
513 | 1785 case KEY_F(9): // F9 = Quit |
1786 printMsg(currWin, "Quitting per user request (%d/0x%x).\n", c, c); | |
571
3ae357fd34bb
Rename quit-related internal variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
1787 appQuitFlag = TRUE; |
513 | 1788 break; |
1789 | |
1790 case 0x09: // Tab = complete username or command | |
1791 nn_tabcomplete_buffer(editBuf); | |
1792 break; | |
1793 | |
1794 default: | |
1795 return FALSE; | |
1796 } | |
1797 | |
1798 return TRUE; | |
1799 } | |
1800 | |
1801 | |
1802 BOOL processUserPrompt(int c, nn_editbuf_t *editBuf, nn_editstate_t *editState) | |
1803 { | |
1804 (void) editBuf; | |
1805 | |
1806 switch (c) | |
1807 { | |
1808 case KEY_ENTER: | |
1809 editState->done = TRUE; | |
1810 break; | |
526
ba5807ebff88
Make it possible to quit when entering username/passwd.
Matti Hamalainen <ccr@tnsp.org>
parents:
521
diff
changeset
|
1811 |
ba5807ebff88
Make it possible to quit when entering username/passwd.
Matti Hamalainen <ccr@tnsp.org>
parents:
521
diff
changeset
|
1812 case KEY_F(9): // F9 = Quit |
ba5807ebff88
Make it possible to quit when entering username/passwd.
Matti Hamalainen <ccr@tnsp.org>
parents:
521
diff
changeset
|
1813 printMsg(currWin, "Quitting per user request (%d/0x%x).\n", c, c); |
571
3ae357fd34bb
Rename quit-related internal variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
1814 appQuitFlag = TRUE; |
526
ba5807ebff88
Make it possible to quit when entering username/passwd.
Matti Hamalainen <ccr@tnsp.org>
parents:
521
diff
changeset
|
1815 break; |
513 | 1816 |
1817 default: | |
1818 return FALSE; | |
1819 } | |
1820 | |
1821 return TRUE; | |
1822 } | |
1823 | |
1824 | |
1825 void updateUserPrompt(nn_editbuf_t *editBuf, nn_editstate_t *editState) | |
1826 { | |
1827 nnwin_update(editState->update, editState->mask, editBuf, optUserName, optUserColor); | |
1828 } | |
1829 | |
1830 | |
535
379e361f1144
Fix various segfault issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
533
diff
changeset
|
1831 void clearEditState(nn_editstate_t *st) |
379e361f1144
Fix various segfault issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
533
diff
changeset
|
1832 { |
379e361f1144
Fix various segfault issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
533
diff
changeset
|
1833 memset(st, 0, sizeof(nn_editstate_t)); |
379e361f1144
Fix various segfault issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
533
diff
changeset
|
1834 st->insertMode = TRUE; |
379e361f1144
Fix various segfault issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
533
diff
changeset
|
1835 st->debugMsg = debugMsg; |
379e361f1144
Fix various segfault issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
533
diff
changeset
|
1836 } |
379e361f1144
Fix various segfault issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
533
diff
changeset
|
1837 |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1838 |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1839 BOOL nn_log_open(nn_window_t *win) |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1840 { |
650
98f5d15d5ec4
Improve and fix XDG support.
Matti Hamalainen <ccr@tnsp.org>
parents:
649
diff
changeset
|
1841 char *path = NULL, *plt; |
661
eb3692d85ac2
Use TH_PLAT_WINDOWS for preprocessor conditionals.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
1842 #ifndef TH_PLAT_WINDOWS |
556
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1843 int logFd = -1; |
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1844 #endif |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1845 |
650
98f5d15d5ec4
Improve and fix XDG support.
Matti Hamalainen <ccr@tnsp.org>
parents:
649
diff
changeset
|
1846 if (!optLogEnable || optLogPath == NULL) |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1847 return FALSE; |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1848 |
693
9ed896f7b531
Use TH_DIR_SEPARATOR_CHR instead of our own define.
Matti Hamalainen <ccr@tnsp.org>
parents:
692
diff
changeset
|
1849 plt = strrchr(optLogPath, TH_DIR_SEPARATOR_CHR); |
650
98f5d15d5ec4
Improve and fix XDG support.
Matti Hamalainen <ccr@tnsp.org>
parents:
649
diff
changeset
|
1850 if (plt == NULL || plt[1] != 0) |
693
9ed896f7b531
Use TH_DIR_SEPARATOR_CHR instead of our own define.
Matti Hamalainen <ccr@tnsp.org>
parents:
692
diff
changeset
|
1851 path = th_strdup_printf("%s%c", optLogPath, TH_DIR_SEPARATOR_CHR); |
650
98f5d15d5ec4
Improve and fix XDG support.
Matti Hamalainen <ccr@tnsp.org>
parents:
649
diff
changeset
|
1852 else |
98f5d15d5ec4
Improve and fix XDG support.
Matti Hamalainen <ccr@tnsp.org>
parents:
649
diff
changeset
|
1853 path = th_strdup(optLogPath); |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1854 |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1855 if (win->id == NULL) |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1856 { |
554
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1857 // Main window log (aka room log) |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1858 if (optLogDaily) |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1859 { |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1860 char stamp[64]; |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1861 str_get_timestamp(stamp, sizeof(stamp), "%Y-%m-%d"); |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1862 win->logFilename = th_strdup_printf("%sroom_%d-%s%s", |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1863 path != NULL ? path : "", optPort, |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1864 stamp, optLogExtension); |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1865 } |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1866 else |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1867 { |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1868 win->logFilename = th_strdup_printf("%sroom_%d%s", |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1869 path != NULL ? path : "", optPort, optLogExtension); |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1870 } |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1871 } |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1872 else |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1873 { |
552 | 1874 // PRV chat log |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1875 size_t pos; |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1876 char *cleaned; |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1877 |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1878 if ((cleaned = th_strdup(win->id)) == NULL) |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1879 return FALSE; |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1880 |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1881 for (pos = 0; cleaned[pos] != 0; pos++) |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1882 { |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1883 if (!isalnum(cleaned[pos])) |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1884 cleaned[pos] = '_'; |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1885 } |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1886 |
551
89fafb218396
Fix situations where the log path is unset.
Matti Hamalainen <ccr@tnsp.org>
parents:
550
diff
changeset
|
1887 win->logFilename = th_strdup_printf("%s%s%s", |
89fafb218396
Fix situations where the log path is unset.
Matti Hamalainen <ccr@tnsp.org>
parents:
550
diff
changeset
|
1888 path != NULL ? path : "", cleaned, optLogExtension); |
89fafb218396
Fix situations where the log path is unset.
Matti Hamalainen <ccr@tnsp.org>
parents:
550
diff
changeset
|
1889 |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1890 th_free(cleaned); |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1891 } |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1892 |
552 | 1893 // Try to open the file for appending |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1894 if (win->logFilename == NULL) |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1895 goto error; |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1896 |
661
eb3692d85ac2
Use TH_PLAT_WINDOWS for preprocessor conditionals.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
1897 #ifdef TH_PLAT_WINDOWS |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1898 if ((win->logFile = fopen(win->logFilename, "a")) == NULL) |
556
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1899 #else |
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1900 if ((logFd = open(win->logFilename, O_CREAT | O_APPEND | O_WRONLY, S_IRUSR | S_IWUSR)) == -1 || |
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1901 (win->logFile = fdopen(logFd, "a")) == NULL) |
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1902 #endif |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1903 { |
621
29b8ff5b625b
Use th_get_error() and th_error_str().
Matti Hamalainen <ccr@tnsp.org>
parents:
620
diff
changeset
|
1904 int err = th_get_error(); |
556
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1905 errorMsg("Could not open logfile '%s' for appending, %d: %s\n", |
621
29b8ff5b625b
Use th_get_error() and th_error_str().
Matti Hamalainen <ccr@tnsp.org>
parents:
620
diff
changeset
|
1906 win->logFilename, err, th_error_str(err)); |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1907 goto error; |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1908 } |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1909 |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1910 printMsg(win, "Logging to '%s'.\n", win->logFilename); |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1911 |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1912 th_free(path); |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1913 return TRUE; |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1914 |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1915 error: |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1916 th_free(path); |
677 | 1917 th_free_r(&win->logFilename); |
556
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1918 if (win->logFile != NULL) |
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1919 fclose(win->logFile); |
661
eb3692d85ac2
Use TH_PLAT_WINDOWS for preprocessor conditionals.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
1920 #ifndef TH_PLAT_WINDOWS |
556
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1921 else |
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1922 if (logFd >= 0) |
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1923 close(logFd); |
9b72d0060b85
Create configuration and log files with reduced permissions (rw for user
Matti Hamalainen <ccr@tnsp.org>
parents:
555
diff
changeset
|
1924 #endif |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1925 return FALSE; |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1926 } |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1927 |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1928 |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1929 void nn_log_close(nn_window_t *win) |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1930 { |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1931 if (win->logFile != NULL) |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1932 fclose(win->logFile); |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1933 win->logFile = NULL; |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1934 |
677 | 1935 th_free_r(&win->logFilename); |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1936 } |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1937 |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
1938 |
554
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1939 BOOL nn_log_reopen(nn_window_t *win) |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1940 { |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1941 nn_log_close(win); |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1942 return nn_log_open(win); |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1943 } |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1944 |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
1945 |
0 | 1946 int main(int argc, char *argv[]) |
1947 { | |
513 | 1948 char *tmpStr; |
623
118276b60667
More work towards using th-libs th_network module.
Matti Hamalainen <ccr@tnsp.org>
parents:
622
diff
changeset
|
1949 int index, updateCount = 0, ret; |
513 | 1950 BOOL argsOK, colorSet = FALSE; |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
1951 th_conn_t *conn = NULL; |
168
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
1952 nn_editbuf_t *editBuf = nn_editbuf_new(NN_TMPBUF_SIZE); |
513 | 1953 nn_editstate_t editState; |
561
1ff9e85a1fcc
Rework the configuration file loading and saving to use the I/O context and new th-config API.
Matti Hamalainen <ccr@tnsp.org>
parents:
560
diff
changeset
|
1954 th_cfgitem_t *tmpcfg; |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
1955 |
513 | 1956 memset(editHistBuf, 0, sizeof(editHistBuf)); |
535
379e361f1144
Fix various segfault issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
533
diff
changeset
|
1957 clearEditState(&editState); |
391 | 1958 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1959 // Initialize |
195
829457be9eea
Build system changes to support (in a big kludgy manner) icon and version information resource generation for Win32 binaries.
Matti Hamalainen <ccr@tnsp.org>
parents:
191
diff
changeset
|
1960 th_init("NNChat", "Newbie Nudes chat client", NN_VERSION, |
668 | 1961 "Written and designed by Anonymous Finnish Guy (C) 2008-2016", |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
1962 "This software is freeware, use and distribute as you wish."); |
678
75daa6ec65df
Fix to match changes in th-libs API.
Matti Hamalainen <ccr@tnsp.org>
parents:
677
diff
changeset
|
1963 |
75daa6ec65df
Fix to match changes in th-libs API.
Matti Hamalainen <ccr@tnsp.org>
parents:
677
diff
changeset
|
1964 th_verbosity = 0; |
133 | 1965 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
1966 // Read configuration file |
148 | 1967 tmpcfg = NULL; |
133 | 1968 th_cfg_add_comment(&tmpcfg, "General settings"); |
1969 th_cfg_add_string(&tmpcfg, "username", &optUserName, NULL); | |
1970 th_cfg_add_string(&tmpcfg, "password", &optPassword, NULL); | |
409
4556174b5be8
Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
408
diff
changeset
|
1971 |
150
db5e7a1f1eb3
Add comment in config file about format of user color setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
149
diff
changeset
|
1972 th_cfg_add_comment(&tmpcfg, "Default color as a hex-triplet"); |
133 | 1973 th_cfg_add_hexvalue(&tmpcfg, "color", &optUserColor, optUserColor); |
391 | 1974 |
149
a4d6707161a7
Add config file option for default setting of ignore mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
1975 th_cfg_add_comment(&tmpcfg, "Default setting of ignore mode"); |
151
303db1141147
Oops, should be th_cfg_add_bool() instead of th_cfg_add_boolean()
Matti Hamalainen <ccr@tnsp.org>
parents:
150
diff
changeset
|
1976 th_cfg_add_bool(&tmpcfg, "ignore", &setIgnoreMode, setIgnoreMode); |
149
a4d6707161a7
Add config file option for default setting of ignore mode.
Matti Hamalainen <ccr@tnsp.org>
parents:
148
diff
changeset
|
1977 th_cfg_add_comment(&tmpcfg, "People to be ignored when ignore mode is enabled"); |
265
b9c650db8a6a
Rename variable nnIgnoreList to setIgnoreList.
Matti Hamalainen <ccr@tnsp.org>
parents:
264
diff
changeset
|
1978 th_cfg_add_string_list(&tmpcfg, "ignore_list", &setIgnoreList); |
264
4c1c18a388d9
Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents:
258
diff
changeset
|
1979 |
519
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
1980 th_cfg_add_comment(&tmpcfg, "Allow only defined friends to private to you"); |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
1981 th_cfg_add_bool(&tmpcfg, "prv_friends", &optOnlyFriendPrv, optOnlyFriendPrv); |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
1982 th_cfg_add_comment(&tmpcfg, "List of your friends"); |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
1983 th_cfg_add_string_list(&tmpcfg, "friend_list", &setFriendList); |
f17d2ab25618
Add option for only allowing private messages from people on a special friend list.
Matti Hamalainen <ccr@tnsp.org>
parents:
518
diff
changeset
|
1984 |
264
4c1c18a388d9
Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents:
258
diff
changeset
|
1985 th_cfg_add_comment(&tmpcfg, "Random messages for idle timeout protection. If none are set, plain '.' is used."); |
4c1c18a388d9
Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents:
258
diff
changeset
|
1986 th_cfg_add_string_list(&tmpcfg, "idle_messages", &setIdleMessages); |
4c1c18a388d9
Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents:
258
diff
changeset
|
1987 |
409
4556174b5be8
Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
408
diff
changeset
|
1988 th_cfg_add_comment(&tmpcfg, "Character used as nickname auto-completion separator (default is ':')"); |
4556174b5be8
Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
408
diff
changeset
|
1989 th_cfg_add_string(&tmpcfg, "nick_separator", &optNickSepStr, NULL); |
4556174b5be8
Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
408
diff
changeset
|
1990 |
133 | 1991 th_cfg_add_section(&cfg, "general", tmpcfg); |
1992 | |
264
4c1c18a388d9
Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents:
258
diff
changeset
|
1993 |
133 | 1994 tmpcfg = NULL; |
1995 th_cfg_add_comment(&tmpcfg, "Chat server hostname or IP address"); | |
1996 th_cfg_add_string(&tmpcfg, "host", &optServer, optServer); | |
593
00f476c65e1b
Remove port descriptions from configuration.
Matti Hamalainen <ccr@tnsp.org>
parents:
592
diff
changeset
|
1997 |
00f476c65e1b
Remove port descriptions from configuration.
Matti Hamalainen <ccr@tnsp.org>
parents:
592
diff
changeset
|
1998 th_cfg_add_comment(&tmpcfg, "Default port to connect"); |
133 | 1999 th_cfg_add_int(&tmpcfg, "port", &optPort, optPort); |
2000 th_cfg_add_section(&cfg, "server", tmpcfg); | |
2001 | |
239
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
2002 tmpcfg = NULL; |
638
bda973fa2b3b
Add proxy disable/enable setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
636
diff
changeset
|
2003 th_cfg_add_comment(&tmpcfg, "Enable proxy"); |
bda973fa2b3b
Add proxy disable/enable setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
636
diff
changeset
|
2004 th_cfg_add_bool(&tmpcfg, "enable", &optProxyEnable, optProxyEnable); |
689
1b15cf9442ff
Typofix in config file comments.
Matti Hamalainen <ccr@tnsp.org>
parents:
687
diff
changeset
|
2005 th_cfg_add_comment(&tmpcfg, "Proxy URI (see commandline help for more information)"); |
609
b10d81ddfc55
Use URI form of proxy configuration in the config file as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
608
diff
changeset
|
2006 th_cfg_add_string(&tmpcfg, "uri", &setProxyURI, NULL); |
353
83ae825bb8c1
Add configuration section for proxy settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
352
diff
changeset
|
2007 th_cfg_add_section(&cfg, "proxy", tmpcfg); |
83ae825bb8c1
Add configuration section for proxy settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
352
diff
changeset
|
2008 |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
2009 |
353
83ae825bb8c1
Add configuration section for proxy settings.
Matti Hamalainen <ccr@tnsp.org>
parents:
352
diff
changeset
|
2010 tmpcfg = NULL; |
652
58a376f86cdf
Make browser a configurable setting (in addition to environment variable),
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
2011 th_cfg_add_comment(&tmpcfg, "Web browser binary/path to execute (UNIX/Linux only)"); |
58a376f86cdf
Make browser a configurable setting (in addition to environment variable),
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
2012 th_cfg_add_string(&tmpcfg, "browser", &setBrowser, NULL); |
58a376f86cdf
Make browser a configurable setting (in addition to environment variable),
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
2013 th_cfg_add_comment(&tmpcfg, "Browser execution method (0 = default/old Mozilla, 1 = new Firefox)"); |
58a376f86cdf
Make browser a configurable setting (in addition to environment variable),
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
2014 th_cfg_add_int(&tmpcfg, "run-method", &optBrowserRunMethod, BMT_MOZILLA); |
58a376f86cdf
Make browser a configurable setting (in addition to environment variable),
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
2015 th_cfg_add_section(&cfg, "web-browser", tmpcfg); |
58a376f86cdf
Make browser a configurable setting (in addition to environment variable),
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
2016 |
58a376f86cdf
Make browser a configurable setting (in addition to environment variable),
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
2017 |
58a376f86cdf
Make browser a configurable setting (in addition to environment variable),
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
2018 tmpcfg = NULL; |
239
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
2019 th_cfg_add_comment(&tmpcfg, "Enable logging"); |
247 | 2020 th_cfg_add_bool(&tmpcfg, "enable", &optLogEnable, optLogEnable); |
554
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
2021 |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
2022 th_cfg_add_comment(&tmpcfg, "Use daily logfiles for room logs"); |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
2023 th_cfg_add_bool(&tmpcfg, "daily", &optLogDaily, optLogDaily); |
13901e9be15b
Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents:
553
diff
changeset
|
2024 |
541
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
2025 th_cfg_add_comment(&tmpcfg, "Log files path"); |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
2026 th_cfg_add_string(&tmpcfg, "path", &optLogPath, optLogPath); |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
2027 |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
2028 th_cfg_add_comment(&tmpcfg, "Log filename extension"); |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
2029 th_cfg_add_string(&tmpcfg, "extension", &optLogExtension, optLogExtension); |
44f67ec5e945
Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents:
538
diff
changeset
|
2030 |
247 | 2031 th_cfg_add_section(&cfg, "logging", tmpcfg); |
239
b7e7ed741a18
Add unfinished code for logfile name parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
2032 |
512 | 2033 // Get home directory path |
154
e8f67e344aaf
Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
2034 { |
691 | 2035 setHomeDir = th_get_home_dir(); |
2036 | |
661
eb3692d85ac2
Use TH_PLAT_WINDOWS for preprocessor conditionals.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
2037 #if defined(TH_PLAT_WINDOWS) |
391 | 2038 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); |
648
a9d25e083f44
Separate home dir and config dir functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
643
diff
changeset
|
2039 setConfigDir = th_strdup(setHomeDir); |
616
1ffacd20b88b
Clean up the #ifdef mess around homedir handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
613
diff
changeset
|
2040 #elif defined(USE_XDG) |
648
a9d25e083f44
Separate home dir and config dir functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
643
diff
changeset
|
2041 const char *xdgConfigDir = getenv("XDG_CONFIG_HOME"); |
546 | 2042 |
2043 // If XDG is enabled, try the environment variable first | |
648
a9d25e083f44
Separate home dir and config dir functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
643
diff
changeset
|
2044 if (xdgConfigDir != NULL && strcmp(xdgConfigDir, "")) |
650
98f5d15d5ec4
Improve and fix XDG support.
Matti Hamalainen <ccr@tnsp.org>
parents:
649
diff
changeset
|
2045 setConfigDir = th_strdup_printf("%s/%s/", xdgConfigDir, SET_XDG_CONFIG_DIR); |
512 | 2046 else |
546 | 2047 // Nope, try the obvious alternative |
650
98f5d15d5ec4
Improve and fix XDG support.
Matti Hamalainen <ccr@tnsp.org>
parents:
649
diff
changeset
|
2048 setConfigDir = th_strdup_printf("%s/.config/%s/", setHomeDir, SET_XDG_CONFIG_DIR); |
512 | 2049 #else |
648
a9d25e083f44
Separate home dir and config dir functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
643
diff
changeset
|
2050 setConfigDir = th_strdup(setHomeDir); |
512 | 2051 #endif |
2052 } | |
391 | 2053 |
648
a9d25e083f44
Separate home dir and config dir functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
643
diff
changeset
|
2054 if (setConfigDir != NULL) |
391 | 2055 { |
663
0b81e5fdc7b5
Use the new io context API.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
2056 th_ioctx *ctx; |
154
e8f67e344aaf
Get correct directory for saving configuration under Windows.
Matti Hamalainen <ccr@tnsp.org>
parents:
153
diff
changeset
|
2057 |
693
9ed896f7b531
Use TH_DIR_SEPARATOR_CHR instead of our own define.
Matti Hamalainen <ccr@tnsp.org>
parents:
692
diff
changeset
|
2058 setConfigFile = th_strdup_printf("%s%c%s", setConfigDir, TH_DIR_SEPARATOR_CHR, SET_CONFIG_FILE); |
687
e6d60eacf24d
Update to new th_io_fopen() API.
Matti Hamalainen <ccr@tnsp.org>
parents:
686
diff
changeset
|
2059 if (th_io_fopen(&ctx, &th_stdio_io_ops, setConfigFile, "r") == THERR_OK) |
391 | 2060 { |
663
0b81e5fdc7b5
Use the new io context API.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
2061 th_io_set_handlers(ctx, nn_ioctx_errfunc, nn_ioctx_msgfunc); |
0b81e5fdc7b5
Use the new io context API.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
2062 |
687
e6d60eacf24d
Update to new th_io_fopen() API.
Matti Hamalainen <ccr@tnsp.org>
parents:
686
diff
changeset
|
2063 THMSG(0, "Reading configuration from '%s'.\n", |
e6d60eacf24d
Update to new th_io_fopen() API.
Matti Hamalainen <ccr@tnsp.org>
parents:
686
diff
changeset
|
2064 setConfigFile); |
663
0b81e5fdc7b5
Use the new io context API.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
2065 |
0b81e5fdc7b5
Use the new io context API.
Matti Hamalainen <ccr@tnsp.org>
parents:
662
diff
changeset
|
2066 th_cfg_read(ctx, cfg); |
692
863542691130
Free io context instead of just closing it.
Matti Hamalainen <ccr@tnsp.org>
parents:
691
diff
changeset
|
2067 th_io_free(ctx); |
315
864e6e52ed69
Fix a filehandle leak when reading in configuration file.
Matti Hamalainen <ccr@tnsp.org>
parents:
314
diff
changeset
|
2068 } |
133 | 2069 } |
196
edd5ce3e5399
Add simplistic username/password requester if none given on commandline or config file.
Matti Hamalainen <ccr@tnsp.org>
parents:
195
diff
changeset
|
2070 |
609
b10d81ddfc55
Use URI form of proxy configuration in the config file as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
608
diff
changeset
|
2071 if (setProxyURI && !argHandleProxyURI(setProxyURI)) |
b10d81ddfc55
Use URI form of proxy configuration in the config file as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
608
diff
changeset
|
2072 goto err_exit; |
b10d81ddfc55
Use URI form of proxy configuration in the config file as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
608
diff
changeset
|
2073 |
546 | 2074 optNickSep = optNickSepStr ? optNickSepStr[0] : SET_NICK_SEPARATOR; |
409
4556174b5be8
Make nickname autocomplete separator configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
408
diff
changeset
|
2075 |
137
fad8c31e41e6
Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
2076 setBrowser = getenv("BROWSER"); |
652
58a376f86cdf
Make browser a configurable setting (in addition to environment variable),
Matti Hamalainen <ccr@tnsp.org>
parents:
650
diff
changeset
|
2077 if (setBrowser == NULL || setBrowser[0] == 0) |
137
fad8c31e41e6
Move browser code around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
2078 setBrowser = "firefox"; |
391 | 2079 |
648
a9d25e083f44
Separate home dir and config dir functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
643
diff
changeset
|
2080 if (optLogPath == NULL && setHomeDir != NULL) |
545
895ede06ff11
Implement default log file directory.
Matti Hamalainen <ccr@tnsp.org>
parents:
544
diff
changeset
|
2081 { |
895ede06ff11
Implement default log file directory.
Matti Hamalainen <ccr@tnsp.org>
parents:
544
diff
changeset
|
2082 optLogPath = th_strdup_printf("%s%c%s%c", |
693
9ed896f7b531
Use TH_DIR_SEPARATOR_CHR instead of our own define.
Matti Hamalainen <ccr@tnsp.org>
parents:
692
diff
changeset
|
2083 setHomeDir, TH_DIR_SEPARATOR_CHR, SET_LOG_DIR, TH_DIR_SEPARATOR_CHR); |
545
895ede06ff11
Implement default log file directory.
Matti Hamalainen <ccr@tnsp.org>
parents:
544
diff
changeset
|
2084 } |
895ede06ff11
Implement default log file directory.
Matti Hamalainen <ccr@tnsp.org>
parents:
544
diff
changeset
|
2085 |
558
e32881ece842
Only try to create log directories if logging is enabled.
Matti Hamalainen <ccr@tnsp.org>
parents:
557
diff
changeset
|
2086 if (optLogEnable) |
550
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
2087 { |
686
256002aa06cc
Changed to conform to new th_stat_path() API.
Matti Hamalainen <ccr@tnsp.org>
parents:
681
diff
changeset
|
2088 th_stat_data sdata; |
256002aa06cc
Changed to conform to new th_stat_path() API.
Matti Hamalainen <ccr@tnsp.org>
parents:
681
diff
changeset
|
2089 if (th_stat_path(optLogPath, &sdata)) |
550
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
2090 { |
686
256002aa06cc
Changed to conform to new th_stat_path() API.
Matti Hamalainen <ccr@tnsp.org>
parents:
681
diff
changeset
|
2091 if ((sdata.flags & TH_IS_DIR) == 0) |
550
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
2092 { |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
2093 THERR("The log file path '%s' is not a directory.\n", |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
2094 optLogPath); |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
2095 goto err_exit; |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
2096 } |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
2097 else |
686
256002aa06cc
Changed to conform to new th_stat_path() API.
Matti Hamalainen <ccr@tnsp.org>
parents:
681
diff
changeset
|
2098 if ((sdata.flags & TH_IS_WRITABLE) == 0) |
550
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
2099 { |
661
eb3692d85ac2
Use TH_PLAT_WINDOWS for preprocessor conditionals.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
2100 #ifdef TH_PLAT_WINDOWS |
662
0c94af18f55e
Two more generic functions were moved to th-libs, so factor out the
Matti Hamalainen <ccr@tnsp.org>
parents:
661
diff
changeset
|
2101 if (!th_mkdir_path(optLogPath, 0)) |
557
02244c553741
Fix Win32 side of log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
556
diff
changeset
|
2102 { |
02244c553741
Fix Win32 side of log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
556
diff
changeset
|
2103 THERR("Could not create log file directory '%s'.\n", |
02244c553741
Fix Win32 side of log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
556
diff
changeset
|
2104 optLogPath); |
02244c553741
Fix Win32 side of log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
556
diff
changeset
|
2105 goto err_exit; |
02244c553741
Fix Win32 side of log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
556
diff
changeset
|
2106 } |
02244c553741
Fix Win32 side of log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
556
diff
changeset
|
2107 #else |
550
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
2108 THERR("The log file path '%s' is not writable.\n", |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
2109 optLogPath); |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
2110 goto err_exit; |
557
02244c553741
Fix Win32 side of log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
556
diff
changeset
|
2111 #endif |
550
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
2112 } |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
2113 } |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
2114 else |
662
0c94af18f55e
Two more generic functions were moved to th-libs, so factor out the
Matti Hamalainen <ccr@tnsp.org>
parents:
661
diff
changeset
|
2115 if (!th_mkdir_path(optLogPath, 0)) |
550
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
2116 { |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
2117 THERR("Could not create log file directory '%s'.\n", |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
2118 optLogPath); |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
2119 goto err_exit; |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
2120 } |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
2121 } |
504a8b9297a3
Fix log directory creation.
Matti Hamalainen <ccr@tnsp.org>
parents:
549
diff
changeset
|
2122 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2123 // Parse command line arguments |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
2124 argsOK = th_args_process(argc, argv, optList, optListN, |
640
51dd01786d25
Update to work with changed th_args API.
Matti Hamalainen <ccr@tnsp.org>
parents:
639
diff
changeset
|
2125 argHandleOpt, argHandleFile, 0); |
26
b84fc46c6035
Improved color hex triplet parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
2126 |
391 | 2127 if (optUserNameCmd != NULL) |
2128 { | |
513 | 2129 THMSG(1, "Username set on commandline.\n"); |
198
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
2130 optUserName = optUserNameCmd; |
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
2131 optPassword = optPasswordCmd; |
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
2132 } |
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
2133 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
2134 if (!argsOK) |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
2135 return -2; |
64
6a3a917303e4
Some random cleanups, bring back WinSock support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
2136 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2137 // Allocate userhash |
391 | 2138 if ((nnUsers = nn_userhash_new()) == NULL) |
2139 { | |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
2140 THERR("Could not allocate userhash. Fatal error.\n"); |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
2141 return -105; |
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
2142 } |
64
6a3a917303e4
Some random cleanups, bring back WinSock support.
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
2143 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2144 // If no idle messages are set, add default |
391 | 2145 if (setIdleMessages == NULL) |
2146 { | |
264
4c1c18a388d9
Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents:
258
diff
changeset
|
2147 th_llist_append(&setIdleMessages, th_strdup(".")); |
4c1c18a388d9
Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents:
258
diff
changeset
|
2148 } |
4c1c18a388d9
Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents:
258
diff
changeset
|
2149 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2150 // Initialize network |
623
118276b60667
More work towards using th-libs th_network module.
Matti Hamalainen <ccr@tnsp.org>
parents:
622
diff
changeset
|
2151 if ((ret = th_network_init()) != THERR_OK) |
391 | 2152 { |
623
118276b60667
More work towards using th-libs th_network module.
Matti Hamalainen <ccr@tnsp.org>
parents:
622
diff
changeset
|
2153 THERR("Could not initialize network subsystem: %s\n", th_error_str(ret)); |
91
acfc4b4bc180
Create network initialization functions in libnnchat and move Win32/WinSock code there.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
2154 goto err_exit; |
391 | 2155 } |
68
3ab7751fdad1
MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents:
67
diff
changeset
|
2156 |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
464
diff
changeset
|
2157 // Initialize curses windowing |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
464
diff
changeset
|
2158 if (!optDaemon && !nnwin_init(SET_DELAY)) |
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
464
diff
changeset
|
2159 goto err_exit; |
391 | 2160 |
549
dd7b58eca06d
Use the helper functions for creating log file directory automatically.
Matti Hamalainen <ccr@tnsp.org>
parents:
548
diff
changeset
|
2161 |
571
3ae357fd34bb
Rename quit-related internal variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
2162 if (appCursesInit) |
501
ca88945d8eda
Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents:
497
diff
changeset
|
2163 { |
536
15e447d6a2a6
Fix to conform to th-libs changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
535
diff
changeset
|
2164 printMsg(NULL, "%s v%s - %s\n", th_prog_name, th_prog_version, th_prog_desc); |
513 | 2165 printMsg(NULL, "%s\n", th_prog_author); |
2166 printMsg(NULL, "%s\n", th_prog_license); | |
2167 | |
2168 nnwin_update(TRUE, FALSE, NULL, optUserName, optUserColor); | |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2169 |
513 | 2170 // Check if we have username and password |
2171 if (optUserName == NULL || optPassword == NULL) | |
2172 { | |
2173 printMsg(NULL, "Please enter your NN login credentials.\n"); | |
2174 printMsg(NULL, "You can avoid doing this every time by issuing '/save' after logging in.\n"); | |
2175 | |
2176 printMsg(NULL, "Enter your NN username ...\n"); | |
2177 optUserName = nnwin_prompt_requester(FALSE, &editState, processUserPrompt, updateUserPrompt); | |
571
3ae357fd34bb
Rename quit-related internal variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
2178 if (appQuitFlag) |
526
ba5807ebff88
Make it possible to quit when entering username/passwd.
Matti Hamalainen <ccr@tnsp.org>
parents:
521
diff
changeset
|
2179 goto err_exit; |
513 | 2180 |
2181 editState.mask = TRUE; | |
2182 printMsg(NULL, "Enter your NN password ...\n"); | |
2183 optPassword = nnwin_prompt_requester(TRUE, &editState, processUserPrompt, updateUserPrompt); | |
2184 editState.mask = FALSE; | |
571
3ae357fd34bb
Rename quit-related internal variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
2185 if (appQuitFlag) |
526
ba5807ebff88
Make it possible to quit when entering username/passwd.
Matti Hamalainen <ccr@tnsp.org>
parents:
521
diff
changeset
|
2186 goto err_exit; |
513 | 2187 } |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2188 } |
391 | 2189 |
2190 if (optUserName == NULL || optPassword == NULL) | |
2191 { | |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2192 errorMsg("Username and/or password not specified.\n"); |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2193 goto err_exit; |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2194 } |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2195 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2196 // Create a connection |
627 | 2197 conn = th_conn_new(nn_network_errfunc, nn_network_msgfunc, -1); |
391 | 2198 if (conn == NULL) |
2199 { | |
354
c01e42fc9adb
More work on SOCKS proxy support, should work now.
Matti Hamalainen <ccr@tnsp.org>
parents:
353
diff
changeset
|
2200 errorMsg("Could not create connection structure.\n"); |
c01e42fc9adb
More work on SOCKS proxy support, should work now.
Matti Hamalainen <ccr@tnsp.org>
parents:
353
diff
changeset
|
2201 goto err_exit; |
c01e42fc9adb
More work on SOCKS proxy support, should work now.
Matti Hamalainen <ccr@tnsp.org>
parents:
353
diff
changeset
|
2202 } |
513 | 2203 |
2204 editState.conn = conn; | |
354
c01e42fc9adb
More work on SOCKS proxy support, should work now.
Matti Hamalainen <ccr@tnsp.org>
parents:
353
diff
changeset
|
2205 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2206 // Are we using a proxy? |
638
bda973fa2b3b
Add proxy disable/enable setting.
Matti Hamalainen <ccr@tnsp.org>
parents:
636
diff
changeset
|
2207 if (optProxyEnable && optProxyType != TH_PROXY_NONE && optProxyServer != NULL) |
391 | 2208 { |
602
4bae14092b78
Add parameters (unused for now) for proxy password etc. in case SOCKS 5
Matti Hamalainen <ccr@tnsp.org>
parents:
601
diff
changeset
|
2209 if (optProxyUserID == NULL) |
4bae14092b78
Add parameters (unused for now) for proxy password etc. in case SOCKS 5
Matti Hamalainen <ccr@tnsp.org>
parents:
601
diff
changeset
|
2210 optProxyUserID = "James Bond"; |
4bae14092b78
Add parameters (unused for now) for proxy password etc. in case SOCKS 5
Matti Hamalainen <ccr@tnsp.org>
parents:
601
diff
changeset
|
2211 |
628 | 2212 if (th_conn_set_proxy(conn, optProxyType, optProxyPort, optProxyServer, optProxyAuthType) != THERR_OK || |
633 | 2213 th_conn_set_proxy_auth_user(conn, optProxyUserID, optProxyPassword) != THERR_OK || |
2214 th_conn_set_proxy_mode(conn, TH_PROXY_CMD_CONNECT) != THERR_OK || | |
635 | 2215 th_conn_set_proxy_addr_type(conn, optProxyAddrType) != THERR_OK) |
391 | 2216 { |
354
c01e42fc9adb
More work on SOCKS proxy support, should work now.
Matti Hamalainen <ccr@tnsp.org>
parents:
353
diff
changeset
|
2217 errorMsg("Error setting proxy information.\n"); |
352
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
2218 goto err_exit; |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
2219 } |
b54c8545dcb0
Overhaul network code a bit, add initial implementation of SOCKS4/4A proxy support -- which may not work yet, it is untested.
Matti Hamalainen <ccr@tnsp.org>
parents:
347
diff
changeset
|
2220 } |
391 | 2221 |
329
c0988ab45afd
#ifdef out the policy probe.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
2222 #ifdef FINAL_BUILD |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2223 /* To emulate the official client, we first make a request for |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2224 * policy file, even though we don't use it for anything... |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2225 */ |
635 | 2226 if (th_conn_open(conn, 843, optServer) != 0) |
391 | 2227 { |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2228 errorMsg("Policy file request connection setup failed!\n"); |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2229 goto err_exit; |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2230 } |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2231 |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2232 tmpStr = "<policy-file-request/>"; |
629
005d7a0351b6
More API changes in th_network.
Matti Hamalainen <ccr@tnsp.org>
parents:
628
diff
changeset
|
2233 if (th_conn_send_buf(conn, tmpStr, strlen(tmpStr) + 1) != THERR_OK) |
391 | 2234 { |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2235 errorMsg("Failed to send policy file request.\n"); |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2236 goto err_exit; |
391 | 2237 } |
2238 else | |
2239 { | |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
2240 int cres = th_conn_pull(conn); |
624 | 2241 if (cres == TH_CONN_DATA_AVAIL) |
391 | 2242 { |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
2243 printMsg(currWin, "Probe got: %s\n", conn->buf); |
391 | 2244 } |
2245 else | |
2246 { | |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
2247 printMsg(currWin, "Could not get policy probe.\n"); |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2248 } |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2249 } |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
2250 th_conn_free(conn); |
329
c0988ab45afd
#ifdef out the policy probe.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
2251 #endif |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2252 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2253 // Okay, now do the proper connection ... |
635 | 2254 if (th_conn_open(conn, optPort, optServer) != 0) |
391 | 2255 { |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2256 errorMsg("Main connection setup failed!\n"); |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2257 goto err_exit; |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2258 } |
391 | 2259 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2260 // Send login command |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2261 optUserNameEnc = nn_dblencode_str(optUserName); |
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2262 tmpStr = nn_dblencode_str(optSite); |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
2263 nn_conn_send_msg_v(conn, optUserNameEnc, "%%2Flogin%%20%%2Dsite%%20%s%%20%%2Dpassword%%20%s", tmpStr, optPassword); |
268
d04ea4395e9e
Move username and password prompting into the Curses interface, also move Curses initialization to earlier phase.
Matti Hamalainen <ccr@tnsp.org>
parents:
267
diff
changeset
|
2264 th_free(tmpStr); |
391 | 2265 |
450
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
2266 // Initialize user commands |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
2267 nn_usercmd_init(); |
a8373a1ce1eb
Implement command tab completion.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
2268 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2269 // Initialize random numbers |
513 | 2270 editState.prevKeepAlive = time(NULL); |
643
d6792ccefe2f
Use ANSI C srand/rand() instead of POSIX srandom/random().
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
2271 srand((int) editState.prevKeepAlive); |
100
ed4067c10a8a
Remove useless buffer usage from error reporting function.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
2272 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2273 // Enter mainloop |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
2274 th_conn_reset(conn); |
571
3ae357fd34bb
Rename quit-related internal variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
2275 while (!editState.isError && !appQuitFlag) |
391 | 2276 { |
445
7e46f2f0ba34
Cleanup packet retrying a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
444
diff
changeset
|
2277 int retries = 3, cres; |
584
6d23385c0643
Prevent spurious screen updates.
Matti Hamalainen <ccr@tnsp.org>
parents:
582
diff
changeset
|
2278 editState.update = FALSE; |
445
7e46f2f0ba34
Cleanup packet retrying a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
444
diff
changeset
|
2279 |
7e46f2f0ba34
Cleanup packet retrying a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
444
diff
changeset
|
2280 packet_retry: |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
2281 cres = th_conn_pull(conn); |
624 | 2282 if (cres == TH_CONN_DATA_AVAIL) |
439
70ea06294f3f
Possibly fix packet handling after the whole mess of refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
437
diff
changeset
|
2283 { |
639
02e1307e2a62
API changes in th_network module.
Matti Hamalainen <ccr@tnsp.org>
parents:
638
diff
changeset
|
2284 while (conn->base.ptr < conn->base.in_ptr && |
02e1307e2a62
API changes in th_network module.
Matti Hamalainen <ccr@tnsp.org>
parents:
638
diff
changeset
|
2285 *(conn->base.in_ptr - 1) == 0 && |
513 | 2286 retries > 0 && !editState.isError) |
391 | 2287 { |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
2288 // th_conn_dump_buffer(stderr, conn); |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
2289 int result = nn_parse_protocol(conn); |
436 | 2290 if (result == 0) |
2291 { | |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
2292 th_conn_buf_skip(conn, 1); |
436 | 2293 } |
2294 else | |
385 | 2295 if (result > 0) |
2296 { | |
445
7e46f2f0ba34
Cleanup packet retrying a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
444
diff
changeset
|
2297 // Retry if possible |
439
70ea06294f3f
Possibly fix packet handling after the whole mess of refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
437
diff
changeset
|
2298 if (--retries > 0) |
445
7e46f2f0ba34
Cleanup packet retrying a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
444
diff
changeset
|
2299 goto packet_retry; |
7e46f2f0ba34
Cleanup packet retrying a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
444
diff
changeset
|
2300 |
7e46f2f0ba34
Cleanup packet retrying a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
444
diff
changeset
|
2301 // Couldn't handle the message for some reason |
639
02e1307e2a62
API changes in th_network module.
Matti Hamalainen <ccr@tnsp.org>
parents:
638
diff
changeset
|
2302 printMsg(currWin, "Could not handle: %s\n", conn->base.ptr); |
02e1307e2a62
API changes in th_network module.
Matti Hamalainen <ccr@tnsp.org>
parents:
638
diff
changeset
|
2303 th_conn_buf_skip(conn, strlen(conn->base.ptr) + 1); |
385 | 2304 } |
436 | 2305 else |
513 | 2306 editState.isError = TRUE; |
403
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
2307 } |
7bec02f382fb
Refactor the connection and protocol handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
402
diff
changeset
|
2308 } |
439
70ea06294f3f
Possibly fix packet handling after the whole mess of refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
437
diff
changeset
|
2309 else |
624 | 2310 if (cres < TH_CONN_ERROR || !th_conn_check(conn)) |
513 | 2311 editState.isError = TRUE; |
168
2e4850ece456
Partially re-factor connection handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
165
diff
changeset
|
2312 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2313 // Handle user input |
586
7c593c9303e8
Add another tiny screen update flush check.
Matti Hamalainen <ccr@tnsp.org>
parents:
584
diff
changeset
|
2314 BOOL flushed = FALSE; |
571
3ae357fd34bb
Rename quit-related internal variables.
Matti Hamalainen <ccr@tnsp.org>
parents:
565
diff
changeset
|
2315 if (appCursesInit) |
391 | 2316 { |
513 | 2317 nnwin_input_process(editBuf, &editState, processUserInput); |
2318 nnwin_update(editState.update, editState.mask, editBuf, optUserName, optUserColor); | |
586
7c593c9303e8
Add another tiny screen update flush check.
Matti Hamalainen <ccr@tnsp.org>
parents:
584
diff
changeset
|
2319 flushed = TRUE; |
513 | 2320 } |
391 | 2321 |
2322 if (++updateCount > 10) | |
2323 { | |
96
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
2324 time_t tmpTime = time(NULL); |
513 | 2325 if (tmpTime - editState.prevKeepAlive > SET_KEEPALIVE) |
391 | 2326 { |
643
d6792ccefe2f
Use ANSI C srand/rand() instead of POSIX srandom/random().
Matti Hamalainen <ccr@tnsp.org>
parents:
642
diff
changeset
|
2327 size_t n = ((size_t) rand()) % th_llist_length(setIdleMessages); |
657
8b8ef14d7177
Update to match th-libs API changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
654
diff
changeset
|
2328 th_llist_t *node = th_llist_get_nth(setIdleMessages, n); |
264
4c1c18a388d9
Add configuration setting and functionality for random "keepalive" messages to avoid idle timeout kicks from chat.
Matti Hamalainen <ccr@tnsp.org>
parents:
258
diff
changeset
|
2329 nn_conn_send_msg(conn, optUserNameEnc, node->data); |
513 | 2330 editState.prevKeepAlive = tmpTime; |
96
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
2331 } |
391 | 2332 |
2333 if (!colorSet) | |
2334 { | |
96
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
2335 colorSet = TRUE; |
424
aeb24b1b5e77
Refactor the /command handling completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
422
diff
changeset
|
2336 nn_conn_send_msg_v(conn, optUserNameEnc, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor); |
96
7c9538e71c89
Add connection keepalive by sending /listallusers every 15 minutes,
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
2337 } |
513 | 2338 |
586
7c593c9303e8
Add another tiny screen update flush check.
Matti Hamalainen <ccr@tnsp.org>
parents:
584
diff
changeset
|
2339 if (appCursesInit && !flushed) |
513 | 2340 { |
2341 nnwin_update(FALSE, editState.mask, editBuf, optUserName, optUserColor); | |
2342 } | |
391 | 2343 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
2344 updateCount = 0; |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
2345 } |
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
2346 } |
391 | 2347 |
419
d015ecbd231d
Use C99 style comments, too.
Matti Hamalainen <ccr@tnsp.org>
parents:
418
diff
changeset
|
2348 // 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
|
2349 err_exit: |
532
cfab338d3c9e
Stop to show errors when exiting even when not running on Win32.
Matti Hamalainen <ccr@tnsp.org>
parents:
531
diff
changeset
|
2350 if (errorMessages || editState.isError) |
521 | 2351 { |
2352 char *tmp; | |
2353 printMsg(NULL, "Press enter to exit.\n"); | |
535
379e361f1144
Fix various segfault issues.
Matti Hamalainen <ccr@tnsp.org>
parents:
533
diff
changeset
|
2354 clearEditState(&editState); |
521 | 2355 tmp = nnwin_prompt_requester(FALSE, &editState, processUserPrompt, updateUserPrompt); |
2356 th_free(tmp); | |
2357 } | |
2358 | |
316
1065115665bd
Plug some more minor memory leaks.
Matti Hamalainen <ccr@tnsp.org>
parents:
315
diff
changeset
|
2359 th_cfg_free(cfg); |
432
966c521e0954
Rename user home directory variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
431
diff
changeset
|
2360 th_free(setHomeDir); |
648
a9d25e083f44
Separate home dir and config dir functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
643
diff
changeset
|
2361 th_free(setConfigDir); |
694
788a58dab07a
th-libs function th_llist_free_func() was renamed to th_llist_free_func_data(). Fix references.
Matti Hamalainen <ccr@tnsp.org>
parents:
693
diff
changeset
|
2362 th_llist_free_func_data(setIdleMessages, th_free); |
103
eaa524e153f9
Initial implementation of functions for implementing tab-completion for user names.
Matti Hamalainen <ccr@tnsp.org>
parents:
100
diff
changeset
|
2363 nn_userhash_free(nnUsers); |
97
218efd2f0641
Rename functions for clarity.
Matti Hamalainen <ccr@tnsp.org>
parents:
96
diff
changeset
|
2364 nn_editbuf_free(editBuf); |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
2365 |
466
796508f828f6
Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
464
diff
changeset
|
2366 for (index = 0; index <= SET_MAX_HISTORY; index++) |
513 | 2367 nn_editbuf_free(editHistBuf[index]); |
288
e7ef3db3b954
Implement "windows" in the chat. Only main window used for now, and even
Matti Hamalainen <ccr@tnsp.org>
parents:
280
diff
changeset
|
2368 |
489
ba48840b8525
Move network initialization/shutdown flag checking to network module.
Matti Hamalainen <ccr@tnsp.org>
parents:
486
diff
changeset
|
2369 nnwin_shutdown(); |
391 | 2370 |
661
eb3692d85ac2
Use TH_PLAT_WINDOWS for preprocessor conditionals.
Matti Hamalainen <ccr@tnsp.org>
parents:
657
diff
changeset
|
2371 #ifndef TH_PLAT_WINDOWS |
223
03af28fb1c38
Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
2372 if (errorMessages) |
03af28fb1c38
Show error messages printed out to stderr only after the program has quit.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
2373 THERR("%s", errorMessages); |
222
a1fefbce0b7a
Add a simple 'press enter to continue' for Windows port, when an error occurs so the user can see it before the application closes.
Matti Hamalainen <ccr@tnsp.org>
parents:
221
diff
changeset
|
2374 #endif |
391 | 2375 |
198
21a37995c3fb
Make configuration username/password overridable on command line.
Matti Hamalainen <ccr@tnsp.org>
parents:
197
diff
changeset
|
2376 th_free(optUserNameEnc); |
622
bb6b07b44800
Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents:
621
diff
changeset
|
2377 th_conn_free(conn); |
623
118276b60667
More work towards using th-libs th_network module.
Matti Hamalainen <ccr@tnsp.org>
parents:
622
diff
changeset
|
2378 th_network_close(); |
68
3ab7751fdad1
MingW compatibility, with one ugly kludge.
Matti Hamalainen <ccr@tnsp.org>
parents:
67
diff
changeset
|
2379 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
2380 THMSG(1, "Connection terminated.\n"); |
391 | 2381 |
70
5228ad7b4f57
Remove tabs from indentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
69
diff
changeset
|
2382 return 0; |
0 | 2383 } |