-
Notifications
You must be signed in to change notification settings - Fork 0
/
HanksRT.c
3888 lines (2922 loc) · 80.6 KB
/
HanksRT.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright 2001-2018 John Wiseman G8BPQ
This file is part of LinBPQ/BPQ32.
LinBPQ/BPQ32 is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
LinBPQ/BPQ32 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LinBPQ/BPQ32. If not, see http://www.gnu.org/licenses
*/
#define _CRT_SECURE_NO_DEPRECATE
#define _USE_32BIT_TIME_T
#pragma data_seg("_BPQDATA")
#define LIBCONFIG_STATIC
#include "libconfig.h"
#ifdef LINBPQ
#include "CHeaders.h"
#endif
#include "bpqchat.h"
#ifndef WIN32
iconv_t link_toUTF8 = NULL;
#endif
VOID ChatClearQueue(ChatCIRCUIT * conn);
VOID ChatFlush(ChatCIRCUIT * conn);
VOID APIENTRY SendChatReport(SOCKET ChatReportSocket, char * buff, int txlen);
unsigned short int compute_crc(unsigned char *buf,int len);
extern struct SEM ChatSemaphore;
extern SOCKADDR_IN Chatreportdest;
char OurNode[10];
char OurAlias[10];
#define MaxSockets 64
int MaxChatStreams=0;
ChatCIRCUIT ChatConnections[MaxSockets+1];
ULONG ChatApplMask;
int NumberofChatStreams=0;
char ChatSignoffMsg[100];
char OtherNodesList[1000];
char ChatWelcomeMsg[1000];
char Position[81] = "";
char PopupText[260] = "";
int PopupMode = 0;
char RtKnown[MAX_PATH];
char RtUsr[MAX_PATH] = "STUsers.txt";
char RtUsrTemp[MAX_PATH] = "STUsers.tmp";
int AXIPPort = 0;
ChatCIRCUIT *circuit_hd = NULL; // This is a chain of RT circuits. There may be others
CHATNODE *node_hd = NULL; // Nodes
LINK *link_hd = NULL; // Nodes we link to
TOPIC *topic_hd = NULL;
USER *user_hd = NULL;
KNOWNNODE * known_hd = NULL;
int ChatTmr = 0;
BOOL NeedStatus = FALSE;
char Verstring[80];
static void node_dec(CHATNODE *node);
static KNOWNNODE *knownnode_add(char *call);
VOID SendChatLinkStatus();
char * lookupuser(char * call);
VOID ChatSendWelcomeMsg(int Stream, ChatCIRCUIT * conn, struct UserInfo * user);
static int AutoColours[20] = {0, 4, 9, 11, 13, 16, 17, 42, 45, 50, 61, 64, 66, 72, 81, 84, 85, 86, 87, 89};
#define MaxSockets 64
extern struct SEM OutputSEM;
BOOL NeedINFO = TRUE; // Send INFO Msg after 10 Secs
//#undef free
//#define free(p)
int ChatIsUTF8(unsigned char *ptr, int len)
{
int n;
unsigned char * cpt = ptr;
// This is simpler than the Term version, as it only handles complete lines of text, so cant get split sequences
cpt--;
for (n = 0; n < len; n++)
{
cpt++;
if (*cpt < 128)
continue;
if ((*cpt & 0xF8) == 0xF0)
{ // start of 4-byte sequence
if (((*(cpt + 1) & 0xC0) == 0x80)
&& ((*(cpt + 2) & 0xC0) == 0x80)
&& ((*(cpt + 3) & 0xC0) == 0x80))
{
cpt += 3;
n += 3;
continue;
}
return FALSE;
}
else if ((*cpt & 0xF0) == 0xE0)
{ // start of 3-byte sequence
if (((*(cpt + 1) & 0xC0) == 0x80)
&& ((*(cpt + 2) & 0xC0) == 0x80))
{
cpt += 2;
n += 2;
continue;
}
return FALSE;
}
else if ((*cpt & 0xE0) == 0xC0)
{ // start of 2-byte sequence
if ((*(cpt + 1) & 0xC0) == 0x80)
{
cpt++;
n++;
continue;
}
return FALSE;
}
return FALSE;
}
return TRUE;
}
#ifndef LINBPQ
char * strlop(char * buf, char delim)
{
// Terminate buf at delim, and return rest of string
char * ptr = strchr(buf, delim);
if (ptr == NULL) return NULL;
*(ptr)++=0;
return ptr;
}
VOID * _zalloc_dbg(int len, int type, char * file, int line)
{
// ?? malloc and clear
void * ptr;
ptr=_malloc_dbg(len, type, file, line);
if (ptr == NULL)
CriticalErrorHandler("malloc failed");
memset(ptr, 0, len);
return ptr;
}
VOID * _zalloc(int len)
{
// ?? malloc and clear
void * ptr;
ptr=malloc(len);
if (ptr == NULL)
CriticalErrorHandler("malloc failed");
memset(ptr, 0, len);
return ptr;
}
#endif
#ifdef LINBPQ
static VOID __cdecl nprintf(ChatCIRCUIT * conn, const char * format, ...)
{
// seems to be printf to a socket
char buff[600];
va_list(arglist);
va_start(arglist, format);
vsprintf(buff, format, arglist);
nputs(conn, buff);
}
#endif
static VOID nputc(ChatCIRCUIT * conn, char chr)
{
// Seems to send chr to socket
WriteLogLine(conn, '>',&chr, 1, LOG_CHAT);
ChatQueueMsg(conn, &chr, 1);
}
static VOID nputs(ChatCIRCUIT * conn, char * buf)
{
// Seems to send buf to socket
ChatQueueMsg(conn, buf, strlen(buf));
if (*buf == 0x1b)
buf += 2; // Colour Escape
WriteLogLine(conn, '>',buf, strlen(buf), LOG_CHAT);
}
int ChatQueueMsg(ChatCIRCUIT * conn, char * msg, int len)
{
// Add Message to queue for this connection
// UCHAR * OutputQueue; // Messages to user
// int OutputQueueLength; // Total Malloc'ed size. Also Put Pointer for next Message
// int OutputGetPointer; // Next byte to send. When Getpointer = Quele Length all is sent - free the buffer and start again.
// Create or extend buffer
GetSemaphore(&OutputSEM, 0);
if (conn->OutputQueueLength + len > 9999)
{
Debugprintf("Corrupt Output Queue Len %d", conn->OutputQueueLength);
conn->OutputQueueLength = 0;
conn->OutputGetPointer = 0;
}
memcpy(&conn->OutputQueue[conn->OutputQueueLength], msg, len);
conn->OutputQueueLength += len;
FreeSemaphore(&OutputSEM);
return len;
}
VOID ChatSendWelcomeMsg(int Stream, ChatCIRCUIT * conn, struct UserInfo * user)
{
if (!rtloginu (conn, TRUE))
{
// Already connected - close
ChatFlush(conn);
Sleep(1000);
Disconnect(conn->BPQStream);
}
return;
}
VOID ChatExpandAndSendMessage(ChatCIRCUIT * conn, char * Msg, int LOG)
{
char NewMessage[10000];
char * OldP = Msg;
char * NewP = NewMessage;
char * ptr, * pptr;
int len;
char Dollar[] = "$";
char CR[] = "\r";
int Msgs = 0, Unread = 0;
ptr = strchr(OldP, '$');
while (ptr)
{
len = ptr - OldP; // Chars before $
memcpy(NewP, OldP, len);
NewP += len;
switch (*++ptr)
{
case 'I': // First name of the connected user.
pptr = conn->UserPointer->Name;
break;
case 'U': // Callsign of the connected user.
pptr = conn->UserPointer->Call;
break;
case 'W': // Inserts a carriage return.
pptr = CR;
break;
break;
default:
pptr = Dollar; // Just Copy $
}
len = strlen(pptr);
memcpy(NewP, pptr, len);
NewP += len;
OldP = ++ptr;
ptr = strchr(OldP, '$');
}
strcpy(NewP, OldP);
len = RemoveLF(NewMessage, strlen(NewMessage));
WriteLogLine(conn, '>', NewMessage, len, LOG);
ChatQueueMsg(conn, NewMessage, len);
}
void chat_link_out (LINK *link)
{
int n, p;
ChatCIRCUIT * conn;
char Msg[80];
for (n = NumberofChatStreams-1; n >= 0 ; n--)
{
conn = &ChatConnections[n];
if (conn->Active == FALSE)
{
p = conn->BPQStream;
memset(conn, 0, sizeof(ChatCIRCUIT)); // Clear everything
conn->BPQStream = p;
conn->Active = TRUE;
circuit_new(conn,p_linkini);
conn->u.link = link;
conn->Flags = CHATMODE | CHATLINK;
n=sprintf_s(Msg, sizeof(Msg), "Connecting to Chat Node %s", conn->u.link->alias);
strcpy(conn->Callsign, conn->u.link->alias);
WriteLogLine(conn, '|',Msg, n, LOG_CHAT);
ConnectUsingAppl(conn->BPQStream, ChatApplMask);
// Connected Event will trigger connect to remote system
return;
}
}
return;
}
VOID saywhat(ChatCIRCUIT *circuit)
{
nputs(circuit, "Invalid Command\r");
}
VOID saydone(ChatCIRCUIT *circuit)
{
nputs(circuit, "Ok\r");
}
VOID strnew(char ** new, char *f1)
{
// seems to allocate a new string, and copy the old one to it
// how is this different to strdup??
*new = _strdup(f1);
}
#define sl_ins_hd(link, hd) \
if (hd == NULL)\
hd=link;\
else\
{\
link->next=hd->next;\
hd->next=link;\
}
BOOL matchi(char * p1, char * p2)
{
// Return TRUE is strings match
if (_stricmp(p1, p2))
return FALSE;
else
return TRUE;
}
VOID ProcessChatLine(ChatCIRCUIT * conn, struct UserInfo * user, char* OrigBuffer, int len)
{
ChatCIRCUIT *c;
char * Buffer = OrigBuffer;
WCHAR BufferW[65536];
UCHAR BufferB[65536];
// Convert to UTF8 if not already in UTF-8
if (len == 73 && memcmp(&OrigBuffer[40], " ", 20) == 0)
{
// Chat Signon Message. If Topic is present, switch to it
char * Context;
char * Appl;
char * topic;
Appl = strtok_s(OrigBuffer, " ,\r", &Context);
topic = strtok_s(NULL, " ,\r", &Context);
if (topic == NULL)
return; // Just Chat
// Have a Topic
if (conn->Flags & GETTINGUSER)
{
// Need to log in before switching topic, so Give a dummy name here
conn->Flags &= ~GETTINGUSER;
strcpy(user->Name, "?_name");
ChatSendWelcomeMsg(conn->BPQStream, conn, user);
}
OrigBuffer[40] = 0;
sprintf(&OrigBuffer[40],"/t %s\r", topic);
strcpy(OrigBuffer, &OrigBuffer[40]);
len = strlen(OrigBuffer);
}
else
{
// Normal input
if (conn->Flags & GETTINGUSER)
{
conn->Flags &= ~GETTINGUSER;
memcpy(user->Name, Buffer, len-1);
ChatSendWelcomeMsg(conn->BPQStream, conn, user);
return;
}
}
if (ChatIsUTF8(OrigBuffer, len) == FALSE)
{
// With Windows it is simple - convert using current codepage
// I think the only reliable way is to convert to unicode and back
#ifdef WIN32
int wlen;
wlen = MultiByteToWideChar(CP_ACP, 0, Buffer, len, BufferW, 65536);
len = WideCharToMultiByte(CP_UTF8, 0, BufferW, wlen, BufferB, 63336, NULL, NULL);
Buffer = BufferB;
#else
int left = 65536;
UCHAR * BufferBP = BufferB;
struct user_t * icu = conn->u.user;
if (conn->rtcflags & p_user)
{
if (icu->iconv_toUTF8 == NULL)
{
icu->iconv_toUTF8 = iconv_open("UTF-8", icu->Codepage);
if (icu->iconv_toUTF8 == (iconv_t)-1)
icu->iconv_toUTF8 = iconv_open("UTF-8", "CP1252");
}
iconv(icu->iconv_toUTF8, NULL, NULL, NULL, NULL); // Reset State Machine
iconv(icu->iconv_toUTF8, &Buffer, &len, (char ** __restrict__)&BufferBP, &left);
}
else
{
if (link_toUTF8 == NULL)
link_toUTF8 = iconv_open("UTF-8", "CP1252");
iconv(link_toUTF8, NULL, NULL, NULL, NULL); // Reset State Machine
iconv(link_toUTF8, &Buffer, &len, (char ** __restrict__)&BufferBP, &left);
}
len = 65536 - left;
Buffer = BufferB;
#endif
}
WriteLogLine(conn, '<',Buffer, len, LOG_CHAT);
Buffer[len] = 0;
strlop(Buffer, '\r');
if (conn->rtcflags == p_linkwait)
{
//waiting for *RTL
if (memcmp(Buffer, "*RTL", 4) == 0)
{
// Node - Node Connect
if (rtloginl (conn, conn->Callsign))
{
// Accepted
conn->Flags |= CHATLINK;
return;
}
else
{
// Connection refused
Disconnect(conn->BPQStream);
return;
}
}
if (Buffer[0] == '[' && Buffer[len-2] == ']') // SID
return;
nprintf(conn, "Unexpected Message on Chat Node-Node Link - Disconnecting\r");
ChatFlush(conn);
Sleep(500);
Disconnect(conn->BPQStream);
return;
}
if (conn->Flags & CHATLINK)
{
#ifndef LINBPQ
struct _EXCEPTION_POINTERS exinfo;
__try
{
chkctl(conn, Buffer, len);
}
#define EXCEPTMSG "Process Chat Line"
#include "StdExcept.c"
Debugprintf("CHAT *** Was procesing Chat Node Message %s", Buffer);
Disconnect(conn->BPQStream);
CheckProgramErrors();
}
#else
chkctl(conn, Buffer, len);
#endif
return;
}
if(conn->u.user == NULL)
{
// A node link, but not activated yet, or a chat console which has dosconnected
if (conn->BPQStream != -2)
return;
// Log console user in
if (rtloginu (conn, TRUE))
conn->Flags |= CHATMODE;
return;
}
if ((len <6) && (memcmp(Buffer, "*RTL", 4) == 0))
{
// Other end thinks this is a node-node link
Logprintf(LOG_CHAT, conn, '!', "Station %s trying to start Node Protocol, but not defined as a Node",
conn->Callsign);
knownnode_add(conn->Callsign); // So it won't happen again
Disconnect(conn->BPQStream);
return;
}
if (Buffer[0] == '/')
{
// Process Command
if (_memicmp(&Buffer[1], "Bye", 1) == 0)
{
SendUnbuffered(conn->BPQStream, ChatSignoffMsg, strlen(ChatSignoffMsg));
if (conn->BPQStream < 0)
{
logout(conn);
conn->Flags = 0;
if (conn->BPQStream == -2)
CloseConsole(conn->BPQStream);
}
else
ReturntoNode(conn->BPQStream);
return;
}
if (_memicmp(&Buffer[1], "Quit", 4) == 0)
{
SendUnbuffered(conn->BPQStream, ChatSignoffMsg, strlen(ChatSignoffMsg));
if (conn->BPQStream < 0)
{
logout(conn);
conn->Flags = 0;
if (conn->BPQStream == -2)
CloseConsole(conn->BPQStream);
}
else
{
Sleep(1000);
Disconnect(conn->BPQStream);
}
return;
}
if (_memicmp(&Buffer[1], "Keepalive", 4) == 0)
{
conn->u.user->rtflags ^= u_keepalive;
upduser(conn->u.user);
nprintf(conn, "Keepalive is %s\r", (conn->u.user->rtflags & u_keepalive) ? "Enabled" : "Disabled");
conn->u.user->lastsendtime = time(NULL);
return;
}
if (_memicmp(&Buffer[1], "AUTOCHARSET", 4) == 0)
{
conn->u.user->rtflags ^= u_auto;
upduser(conn->u.user);
nprintf(conn, "Automatic Character set selection is %s\r", (conn->u.user->rtflags & u_auto) ? "Enabled" : "Disabled");
conn->u.user->lastsendtime = time(NULL);
return;
}
if (_memicmp(&Buffer[1], "UTF-8", 3) == 0)
{
conn->u.user->rtflags ^= u_noUTF8;
upduser(conn->u.user);
nprintf(conn, "Character set is %s\r", (conn->u.user->rtflags & u_noUTF8) ? "8 Bit" : "UTF-8");
conn->u.user->lastsendtime = time(NULL);
return;
}
if ((_memicmp(&Buffer[1], "CodePage", 2) == 0) || (_memicmp(&Buffer[1], "CP", 2) == 0))
{
char * Context;
char * CP = strtok_s(&Buffer[1], " ,\r", &Context);
#ifndef WIN32
iconv_t temp = NULL;
#else
int temp = 0;
WCHAR TempW[10];
#endif
CP = strtok_s(NULL, " ,\r", &Context);
if (CP == NULL || CP[0] == 0)
{
#ifndef WIN32
if (conn->u.user->Codepage[0])
nprintf(conn, "Codepage is %s\r", conn->u.user->Codepage);
#else
if (conn->u.user->Codepage)
nprintf(conn, "Codepage is %d\r", conn->u.user->Codepage);
#endif
else
nprintf(conn, "Codepage is not set\r");
return;
}
_strupr(CP);
#ifndef WIN32
// Validate Code Page by trying to open an iconv descriptor
temp = iconv_open("UTF-8", CP);
if (temp == (iconv_t)-1)
{
nprintf(conn, "Invalid Codepage %s\r", CP);
return;
}
iconv_close(conn->u.user->iconv_toUTF8);
iconv_close(conn->u.user->iconv_fromUTF8);
conn->u.user->iconv_toUTF8 = temp;
conn->u.user->iconv_fromUTF8 = iconv_open(CP, "UTF-8");
strcpy(conn->u.user->Codepage, CP);
nprintf(conn, "Codepage set to %s\r", conn->u.user->Codepage);
#else
if (CP[0] == 'C')
CP +=2;
// Validate by trying ot use it
temp = atoi(CP);
if (MultiByteToWideChar(temp, 0, "\r", 2, TempW, 10) == 0)
{
int err = GetLastError();
if (err == ERROR_INVALID_PARAMETER)
{
nprintf(conn, "Invalid Codepage %d\r", temp);
return;
}
}
conn->u.user->Codepage = temp;
nprintf(conn, "Codepage set to %d\r", conn->u.user->Codepage);
#endif
upduser(conn->u.user);
return;
}
if (_memicmp(&Buffer[1], "Shownames", 4) == 0)
{
conn->u.user->rtflags ^= u_shownames;
upduser(conn->u.user);
nprintf(conn, "Shownames is %s\r", (conn->u.user->rtflags & u_shownames) ? "Enabled" : "Disabled");
conn->u.user->lastsendtime = time(NULL);
return;
}
if (_memicmp(&Buffer[1], "Time", 4) == 0)
{
conn->u.user->rtflags ^= u_showtime;
upduser(conn->u.user);
nprintf(conn, "Show Time is %s\r", (conn->u.user->rtflags & u_showtime) ? "Enabled" : "Disabled");
conn->u.user->lastsendtime = time(NULL);
return;
}
if (_memicmp(&Buffer[1], "colours", 4) == 0)
{
int i =0;
while (i < 100)
{
nprintf(conn, "\x1b%c%02d XXXXX\r", i + 10, i);
i++;
if (i == 3)
i++;
}
return;
}
rt_cmd(conn, Buffer);
return;
}
// Send message to all other connected users on same channel
text_tellu(conn->u.user, Buffer, NULL, o_topic); // To local users.
conn->u.user->lastrealmsgtime = conn->u.user->lastmsgtime = time(NULL);
// Send to Linked nodes
for (c = circuit_hd; c; c = c->next)
{
if ((c->rtcflags & p_linked) && c->refcnt && ct_find(c, conn->u.user->topic))
nprintf(c, "%c%c%s %s %s\r", FORMAT, id_data, OurNode, conn->u.user->call, Buffer);
}
}
void upduser(USER *user)
{
FILE *in, *out;
char *c;
char Buffer[2048];
char *buf = Buffer;
in = fopen(RtUsr, "r");
if (!(in))
{
in = fopen(RtUsr, "w");
fclose(in);
in = fopen(RtUsr, "r");
}
out = fopen(RtUsrTemp, "w");
if (!(in) || !(out)) return;
while(fgets(buf, 128, in))
{
c = strchr(buf, ' ');
if (c) *c = '\0';
if (!matchi(buf, user->call))
{
if (c) *c = ' ';
fputs(buf, out);
}
}
#ifdef LINBPQ
fprintf(out, "%s %d %s %s¬%d¬%s\n", user->call, user->rtflags, user->name, user->qth, user->Colour, user->Codepage);
#else
fprintf(out, "%s %d %s %s¬%d¬%d\n", user->call, user->rtflags, user->name, user->qth, user->Colour, user->Codepage);
#endif
fclose(in);
fclose(out);
remove(RtUsr);
rename(RtUsrTemp, RtUsr);
}
char * lookupuser(char * call)
{
FILE *in;
char *flags;
char Buffer[2048];
char *buf = Buffer;
char * name;
in = fopen(RtUsr, "r");
if (in)
{
while(fgets(buf, 128, in))
{
strlop(buf, '\n');
flags = strlop(buf, ' ');
if (!matchi(buf, call)) continue;
if (!flags) break;
fclose(in);
name = strlop(flags, ' ');
strlop(name, ' ');
return _strdup(name);
}
fclose(in);
}
return NULL;
}
void rduser(USER *user)
{
FILE *in;
char *name, *flags, *qth;
char Buffer[2048];
char *buf = Buffer;
char * ptr;
user->name = _strdup("?_name");
user->qth = _strdup("?_qth");
in = fopen(RtUsr, "r");
if (in)
{
while(fgets(buf, 128, in))
{
strlop(buf, '\n');
flags = strlop(buf, ' ');
if (!matchi(buf, user->call)) continue;
if (!flags) break;
name = strlop(flags, ' ');
user->rtflags = atoi(flags);
qth = strlop(name, ' ');
strnew(&user->name, name);
if (!qth) break;
// Colour Code may follow QTH, and Code Page may follow Colour
ptr = strchr(qth, '¬');
if (ptr)
{
*ptr++ = 0;
user->Colour = atoi(ptr);
ptr = strchr(ptr, '¬');
if (ptr)
{
*ptr++ = 0;
#ifndef WIN32
strcpy(user->Codepage, ptr);
#else
user->Codepage = atoi(ptr);
#endif
}
}
strnew(&user->qth, qth);
break;
}
fclose(in);
#ifndef WIN32
// Open an iconv decriptor for each conversion
if (user->Codepage[0])
user->iconv_toUTF8 = iconv_open("UTF-8", user->Codepage);
else
user->iconv_toUTF8 = (iconv_t)-1;
if (user->iconv_toUTF8 == (iconv_t)-1)
user->iconv_toUTF8 = iconv_open("UTF-8", "CP1252");
if (user->Codepage[0])
user->iconv_fromUTF8 = iconv_open(user->Codepage, "UTF-8");
else
user->iconv_fromUTF8 = (iconv_t)-1;
if (user->iconv_fromUTF8 == (iconv_t)-1)
user->iconv_fromUTF8 = iconv_open("CP1252", "UTF-8");
#endif
}
}
void ReportBadJoin(char * ncall, char *ucall)
{
Logprintf(LOG_CHAT, NULL, '!', "User %s Join from Node %s but already connected", ucall, ncall);
}
void ReportBadLeave(char * ncall, char * ucall)
{
Logprintf(LOG_CHAT, NULL, '!', "Node %s reporting Node %s as a leaving user", ncall, ucall);
}
struct DUPINFO DupInfo[MAXDUPS];
static BOOL CheckforDups(ChatCIRCUIT * circuit, char * Call, char * Msg)
{