-
Notifications
You must be signed in to change notification settings - Fork 1
/
net1.cpp
562 lines (446 loc) · 11.4 KB
/
net1.cpp
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
// --------------------------------------------------------------------------
// Citadel: Net1.CPP
//
// Net 1.0/1.1 protocol implementation.
#include "ctdl.h"
#pragma hdrstop
#include "room.h"
#include "net.h"
#include "filecmd.h"
#include "cfgfiles.h"
#include "cwindows.h"
#include "filerdwr.h"
#include "miscovl.h"
#include "extmsg.h"
// --------------------------------------------------------------------------
// Contents
//
// Net1Slave() Actual networking slave
// Net1Master() During network master code
// get_first_room() get the first room in the room list
// get_next_room() gets the next room in the list
// Net1Cleanup() Done with other system, save mail and messages
// --------------------------------------------------------------------------
// Net1Slave(): Actual networking slave
//
// Return value:
// TRUE: Worked
// FALSE: Didn't
Bool TERMWINDOWMEMBER Net1Slave(void)
{
char line[100];
label troo;
label fn;
FILE *file;
int i = 0;
const protocols *theProt = GetProtocolByKey(node->GetProtocol(), TRUE);
if (!theProt)
{
doccr();
cPrintf(getnetmsg(177));
doCR();
return (FALSE);
}
cPrintf(getnetmsg(178));
doccr();
sprintf(line, sbs, cfg.transpath, node->GetMailFileName());
// create empty mail file if there is none
if ((file = fopen(line, FO_AB)) != NULL)
{
fclose(file);
}
wxsnd(LocalTempPath, line, theProt, 0);
if (!CommPort->HaveConnection())
{
return (FALSE);
}
cPrintf(getnetmsg(179));
doccr();
sprintf(line, sbs, LocalTempPath, roomreqTmp);
unlink(line);
wxrcv(LocalTempPath, roomreqTmp, theProt);
changedir(LocalTempPath);
if (!CommPort->HaveConnection())
{
return (FALSE);
}
sprintf(line, sbs, LocalTempPath, roomreqTmp);
if ((file = fopen(line, FO_RB)) == NULL)
{
perror(getnetmsg(1));
return (FALSE);
}
doccr();
cPrintf(getnetmsg(2));
doccr();
GetStr(file, troo, LABELSIZE);
while (*troo && !feof(file))
{
KBReady();
r_slot rm;
if ((rm = RoomExists(troo)) != CERROR)
{
if (CurrentUser->CanAccessRoom(rm))
{
sprintf(fn, getnetmsg(126), i);
cPrintf(getnetmsg(166), deansi(troo));
if (!((i+1) % 3))
{
doccr();
}
NewRoom(rm, fn, NULL);
}
else
{
doccr();
cPrintf(getnetmsg(111), deansi(troo));
doccr();
amPrintf(getnetmsg(4), troo, bn);
netError = TRUE;
}
}
else
{
doccr();
cPrintf(getnetmsg(5), deansi(troo));
doccr();
amPrintf(getnetmsg(167), troo, bn);
netError = TRUE;
}
i++;
GetStr(file, troo, LABELSIZE);
}
doccr();
fclose(file);
unlink(line);
cPrintf(getnetmsg(7), cfg.Lmsg_nym);
doccr();
if (!CommPort->HaveConnection())
{
return (FALSE);
}
wxsnd(LocalTempPath, getnetmsg(162), theProt, 0);
ambigUnlink(getnetmsg(162));
return (TRUE);
}
// --------------------------------------------------------------------------
// Net1Master(): Network master code
//
// Return value:
// TRUE: Worked
// FALSE: Didn't
Bool TERMWINDOWMEMBER Net1Master(void)
{
char line[100], line2[100];
label here, there;
FILE *file;
int i, rms;
time_t t;
const protocols *theProt = GetProtocolByKey(node->GetProtocol(), TRUE);
if (!theProt)
{
doccr();
cPrintf(getnetmsg(8));
doccr();
return (FALSE);
}
if (!CommPort->HaveConnection())
{
return (FALSE);
}
cPrintf(getnetmsg(9));
doccr();
wxrcv(LocalTempPath, getnetmsg(164), theProt);
if (!CommPort->HaveConnection())
{
return (FALSE);
}
sprintf(line, getnetmsg(168), LocalTempPath);
if ((file = fopen(line, FO_WB)) == NULL)
{
perror(getnetmsg(1));
return (FALSE);
}
for (i = get_first_room(here, there), rms = 0; i; i = get_next_room(here, there), rms++)
{
PutStr(file, there);
}
PutStr(file, ns);
fclose(file);
cPrintf(getnetmsg(10));
doccr();
wxsnd(LocalTempPath, getnetmsg(169), theProt, 0);
unlink(line);
if (!CommPort->HaveConnection())
{
return (FALSE);
}
CommPort->FlushInput();
cPrintf(getnetmsg(11));
// wait for them to get thier shit together
t = time(NULL);
while (CommPort->HaveConnection() && !CommPort->IsInputReady())
{
KBReady();
if (time(NULL) > (t + (node->GetFetchTimeout() * 60)))
{
CITWINDOW *w = ScreenSaver.IsOn() ? NULL : CitWindowsMsg(NULL, getmsg(685), getmsg(73));
Hangup();
if (w)
{
destroyCitWindow(w, FALSE);
}
}
// instantaneous reaction time isn't critical here
CitIsIdle();
}
doccr();
if (!CommPort->HaveConnection())
{
return (FALSE);
}
cPrintf(getnetmsg(12), cfg.Lmsg_nym);
doccr();
wxrcv(LocalTempPath, ns, theProt);
for (i = 0; i < rms; i++)
{
sprintf(line, getnetmsg(126), i);
sprintf(line2, getnetmsg(127), i);
rename(line, line2);
}
return (TRUE);
}
// --------------------------------------------------------------------------
// Net1Cleanup(): Done with other system; save mail and messages
void TERMWINDOWMEMBER Net1Cleanup(void)
{
int t, i;
label fn, here, there;
char line[100];
CITWINDOW *w = ScreenSaver.IsOn() ? NULL : CitWindowsMsg(NULL, getmsg(82));
Hangup();
if (w)
{
destroyCitWindow(w, FALSE);
}
if (cfg.offhook == 1)
{
offhook();
}
sprintf(line, sbs, cfg.transpath, node->GetMailFileName());
unlink(line);
OC.SetOutFlag(IMPERVIOUS);
doccr();
cPrintf(getnetmsg(22));
doccr();
cPrintf(getnetmsg(23));
doccr();
cPrintf(getnetmsg(24));
doccr();
int Rooms = 0, TotalNew = 0, TotalExpired = 0, TotalDuplicate = 0;
int ThisNew, ThisExpired, ThisDuplicate, ThisError;
for (t = get_first_room(here, there), i = 0; t; t = get_next_room(here, there), i++)
{
sprintf(fn, getnetmsg(127), i);
KBReady();
const r_slot rm = RoomExists(here);
if (rm != CERROR && CurrentUser->CanAccessRoom(rm))
{
cPrintf(getnetmsg(166), deansi(here));
if (ReadMsgFl(rm, fn, NULL, &ThisNew, &ThisExpired, &ThisDuplicate, &ThisError, CurrentUser))
{
if (ThisNew)
{
OC.ansiattr = cfg.cattr;
}
cPrintf(getnetmsg(133), ThisNew);
OC.ansiattr = cfg.attr;
cPrintf(getnetmsg(134));
if (ThisExpired)
{
OC.ansiattr = cfg.cattr;
}
cPrintf(getnetmsg(133), ThisExpired);
OC.ansiattr = cfg.attr;
cPrintf(getnetmsg(134));
if (ThisDuplicate)
{
OC.ansiattr = cfg.cattr;
}
cPrintf(getnetmsg(133), ThisDuplicate);
OC.ansiattr = cfg.attr;
TotalNew += ThisNew;
TotalExpired += ThisExpired;
TotalDuplicate += ThisDuplicate;
Rooms++;
}
else
{
amPrintf(getnetmsg(28), there, bn);
netError = TRUE;
cPrintf(getnetmsg(29));
}
doccr();
}
else
{
cPrintf(getnetmsg(30), deansi(here));
amPrintf(getnetmsg(31), here, bn);
netError = TRUE;
doccr();
}
unlink(fn);
}
cPrintf(getnetmsg(24));
doccr();
cPrintf(getnetmsg(32));
if (Rooms)
{
OC.ansiattr = cfg.cattr;
}
cPrintf(getnetmsg(133), Rooms);
OC.ansiattr = cfg.attr;
cPrintf(getnetmsg(134));
if (TotalNew)
{
OC.ansiattr = cfg.cattr;
}
cPrintf(getnetmsg(133), TotalNew);
OC.ansiattr = cfg.attr;
cPrintf(getnetmsg(134));
if (TotalExpired)
{
OC.ansiattr = cfg.cattr;
}
cPrintf(getnetmsg(133), TotalExpired);
OC.ansiattr = cfg.attr;
cPrintf(getnetmsg(134));
if (TotalDuplicate)
{
OC.ansiattr = cfg.cattr;
}
cPrintf(getnetmsg(133), dup);
OC.ansiattr = cfg.attr;
doccr();
cPrintf(getnetmsg(33));
doccr();
doccr();
cPrintf(getnetmsg(34));
doccr();
ReadMsgFl(MAILROOM, getnetmsg(164), NULL, &ThisNew, &ThisExpired, &ThisDuplicate, &ThisError, NULL);
label New, Routed, Rejected;
CopyStringToBuffer(New, ltoac(i == CERROR ? 0 : i));
CopyStringToBuffer(Routed, ltoac(ThisExpired));
CopyStringToBuffer(Rejected, ltoac(ThisDuplicate));
cPrintf(getnetmsg(35), New, ThisNew == 1 ? cfg.Lmsg_nym : cfg.Lmsgs_nym, Routed, Rejected,
ltoac(ThisNew + ThisExpired + ThisDuplicate));
doccr();
changedir(LocalTempPath);
ambigUnlink(getnetmsg(162));
ambigUnlink(getnetmsg(163));
unlink(getnetmsg(164));
changedir(cfg.homepath);
MS.Expired = TotalExpired;
MS.Duplicate = TotalDuplicate;
MS.Entered = TotalNew + ThisNew;
if (netError)
{
label Buffer;
amPrintf(getnetmsg(36), bn, CurrentUser->GetName(Buffer, sizeof(Buffer)), bn);
SaveAideMess(NULL);
}
readNetCmdTmp(CONSOLE);
// we are no longer calling out...
callout = FALSE;
}
// --------------------------------------------------------------------------
// the folowing two routines are used for scaning through the rooms listed
// in NODES.CIT for the other node.
// --------------------------------------------------------------------------
// get_first_room(): Get the first room in the room list, prepare for reading
// the rest.
//
// Output:
// char *here: Filled with the room name here; must be >= LABELSIZE+1
// char *there: Filled with the room name there; must be >= LABELSIZE+1
//
// Return value:
// TRUE: Rooms found
// FALSE: nothing found
//
// Notes:
// If this returns TRUE, you must keep calling get_next_room until it
// returns FALSE. If this or get_next_room returns FALSE, get_next_room
// must not be called again until this is called and it returns TRUE.
Bool TERMWINDOWMEMBER get_first_room(char *here, char *there)
{
assert(!nodefile);
char path[80];
if (!node->GetRoomOffset())
{
return (FALSE);
}
sprintf(path, sbs, cfg.homepath, citfiles[C_NODES_CIT]);
if ((nodefile = fopen(path, FO_R)) == NULL) // ASCII mode
{
cPrintf(getmsg(15), citfiles[C_NODES_CIT]);
doccr();
return (FALSE);
}
fseek(nodefile, node->GetRoomOffset(), SEEK_SET);
return (get_next_room(here, there));
}
// --------------------------------------------------------------------------
// get_next_room(): Gets the next room in the list
//
// Output:
// char *here: Filled with the room name here; must be >= LABELSIZE+1
// char *there: Filled with the room name there; must be >= LABELSIZE+1
//
// Return value:
// TRUE: next room found
// FALSE: no more rooms found
//
// Notes:
// Before calling this, get_first_room() must be called, and it must return
// TRUE. If get_first_room() returns FALSE, this must not be called. If
// get_first_room() returns TRUE, this must keep getting called until it
// returns FALSE. get_first_room() must not be called until this returns
// FALSE. After this returns FALSE, it must not be called again until
// get_first_room() is called and returns TRUE.
Bool TERMWINDOWMEMBER get_next_room(char *here, char *there)
{
assert(nodefile);
char line[95];
while (fgets(line, 90, nodefile) != NULL)
{
if (line[0] != '#')
{
continue;
}
char *words[256];
const int count = parse_it(words, line);
if (SameString(words[0], getnetmsg(37)))
{
fclose(nodefile);
nodefile = NULL;
return (FALSE);
}
if (SameString(words[0], getnetmsg(38)))
{
CopyString2Buffer(here, words[1], LABELSIZE);
if (count > 2)
{
CopyString2Buffer(there, words[2], LABELSIZE);
}
else
{
strcpy(there, here);
}
return (TRUE);
}
}
fclose(nodefile);
nodefile = NULL;
return (FALSE);
}