/
misc2.cpp
648 lines (530 loc) · 14.2 KB
/
misc2.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
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
// --------------------------------------------------------------------------
// Citadel: Misc2.CPP
//
// Overlayed miscellaneous stuff that is used often; compare with Misc3.CPP.
#include "ctdl.h"
#pragma hdrstop
#include "cwindows.h"
#include "room.h"
#include "tallybuf.h"
#include "libovl.h"
#include "log.h"
#include "hall.h"
#include "cfgfiles.h"
#include "term.h"
#include "domenu.h"
#include "statline.h"
// --------------------------------------------------------------------------
// Contents
//
// offhook() sysop fn to take modem off hook
// greeting() System-entry blurb etc
// EnterBorder() edit a border line.
// digitbaud() Calculates digit baud rate (0-4) from number (300+)
// --------------------------------------------------------------------------
// greeting(): gives system-entry blurb, etc.
void TERMWINDOWMEMBER greeting(void)
{
MRO.Verbose = FALSE;
if (loggedIn)
{
terminate(FALSE);
}
OC.Echo = BOTH;
OC.setio();
setdefaultconfig(FALSE);
pause(10);
cls(SCROLL_SAVE);
doccr();
StatusLine.Update(WC_TWp);
if (modStat)
{
if (cfg.connectwait)
{
CITWINDOW *w = ScreenSaver.IsOn() ? NULL : CitWindowsMsg(NULL, getmsg(84));
pause(cfg.connectwait * 100);
if (w)
{
destroyCitWindow(w, FALSE);
}
}
CommPort->FlushInput();
}
// make sure we want to talk to this baud rate
if (modStat && (CommPort->GetModemSpeed() < cfg.minbaud))
{
dispBlb(B_TOOLOW);
CITWINDOW *w = ScreenSaver.IsOn() ? NULL : CitWindowsMsg(NULL, getmsg(82));
Hangup();
pause(200);
if (w)
{
destroyCitWindow(w, FALSE);
}
}
else
{
OC.User.SetCanControlD(TRUE);
// set terminal
autoansi();
OC.SetOutFlag(OUTOK);
if (modStat || debug)
{
hello();
doCR();
}
OC.SetOutFlag(OUTOK);
mPrintfCR(getmsg(683), cfg.nodeTitle, cfg.nodeRegion, cfg.nodeCountry);
mPrintfCR(getmsg(682), cfg.softverb, *cfg.softverb ? spc : ns, programName, version);
mPrintf(pcts, Author);
#if VERSION != RELEASE
doCR();
#ifndef HARRY
CRCRmPrintfCR(" 2=== 1NOTE02 ===0");
#else
CRCRmPrintfCR(" 2=== NOTE ===0");
#endif
#ifndef NDEBUG
CRmPrintf("This BBS is running pre-release software. Because this is a test version ");
mPrintf("of the software, it has extra code to assure that things are running as ");
mPrintf("they should. This may cause a noticeable slow-down in the operation of ");
mPrintf("the board. Also, because this is pre-release software, it may contain ");
mPrintf("bugs that could cause a loss of data. This is not likely, but it is best ");
mPrintfCR("to be aware of potential problems before they surprise you.");
#else
mPrintf("This BBS is running pre-release software. Because this is pre-release ");
mPrintf("software, it may contain ");
mPrintf("bugs that could cause a loss of data. This is not likely, but it is best ");
mPrintfCR("to be aware of potential problems before they surprise you.");
#endif
#ifndef HARRY
CRmPrintfCR(" 2=== 1NOTE02 ===0");
#else
CRmPrintfCR(" 2=== NOTE ===0");
#endif
#endif
char dtstr[80];
strftime(dtstr, 79, cfg.vdatestamp, 0l);
doCR();
CRmPrintf(pcts, dtstr);
if (!cfg.forcelogin)
{
CRmPrintf(getmsg(677));
CRmPrintf(getmsg(678));
CRmPrintf(getmsg(679));
}
CurrentRoom->Load(LOBBY);
checkdir();
thisRoom = LOBBY;
const ulong messages = Talley->MessagesInRoom(thisRoom);
CRmPrintfCR(getmsg(144), ltoac(messages), (messages == 1) ? cfg.Lmsg_nym : cfg.Lmsgs_nym);
CommPort->FlushInput();
}
}
// --------------------------------------------------------------------------
// EnterBorder(): Edit a border line.
void TERMWINDOWMEMBER EnterBorder(void)
{
if (!LockMenu(MENU_ENTER))
{
return;
}
SetDoWhat(ENTERBORDER);
if (!CurrentUser->IsEnterBorders() && !CurrentUser->IsSysop())
{
CRCRmPrintfCR(getmenumsg(MENU_ENTER, 18));
}
else
{
doCR(2);
if (!cfg.borders)
{
mPrintfCR(getmenumsg(MENU_ENTER, 38));
UnlockMenu(MENU_ENTER);
return;
}
OC.SetOutFlag(OUTOK);
for (int i = 0; i < cfg.maxborders; i++)
{
mPrintf(getmenumsg(MENU_ENTER, 39), i + 1);
if (borders[i * (BORDERSIZE + 1)])
{
mPrintf(pcts, &(borders[i * (BORDERSIZE + 1)]));
termCap(TERM_NORMAL);
}
else
{
mPrintf(getmenumsg(MENU_ENTER, 40));
}
doCR(2);
}
const int ToEdit = (int) getNumber(getmenumsg(MENU_ENTER, 41), 0L, (long) cfg.maxborders, 0L, FALSE, NULL);
if (ToEdit)
{
CRmPrintf(getmenumsg(MENU_ENTER, 39), ToEdit);
if (borders[(ToEdit - 1) * (BORDERSIZE + 1)])
{
mPrintf(pcts, &(borders[(ToEdit - 1) * (BORDERSIZE + 1)]));
termCap(TERM_NORMAL);
}
else
{
mPrintf(getmenumsg(MENU_ENTER, 40));
}
char stuff[BORDERSIZE + 1];
doCR();
getString(getmenumsg(MENU_ENTER, 42), stuff, BORDERSIZE, FALSE, ns);
if (*stuff)
{
CopyString2Buffer(&(borders[(ToEdit - 1) * (BORDERSIZE + 1)]), stuff, BORDERSIZE + 1);
normalizeString(&(borders[(ToEdit - 1) * (BORDERSIZE + 1)]));
writeBordersDat();
}
}
}
UnlockMenu(MENU_ENTER);
}
// --------------------------------------------------------------------------
// digitbaud(): Calculates PortSpeedE baud rate from number
//
// Input:
// bigbaud: The baud to find the PortSpeedE of. This can be in PortSpeedE
// format already, or in 300/600/1200... format.
//
// Return value:
// PortSpeedE format of bigbaud's rate.
//
// Notes:
// If bigbaud could not be understood, this returns PS_ERROR.
PortSpeedE digitbaud(long bigbaud)
{
if (bigbaud < PS_NUM - 1)
{
// This is a little bit of a kludge to keep people from having to
// change data files when 600 baud was introduced. Pretty ugly, huh?
if (bigbaud > 0)
{
bigbaud++;
}
return ((PortSpeedE) bigbaud);
}
else
{
for (PortSpeedE i = (PortSpeedE) 0; i < PS_NUM; i = (PortSpeedE) (i + 1))
{
if (bigbaud == bauds[i])
{
return (i);
}
}
return (PS_ERROR);
}
}
// --------------------------------------------------------------------------
// digitConnectbaud(): Calculates ModemSpeedE baud rate from number
//
// Input:
// bigbaud: The baud to find the ModemSpeedE of. This can be in ModemSpeedE
// format already, or in 300/600/1200... format.
//
// Return value:
// ModemSpeedE format of bigbaud's rate.
//
// Notes:
// If bigbaud could not be understood, this returns MS_ERROR.
ModemSpeedE digitConnectbaud(long bigbaud)
{
if (bigbaud < MS_NUM - 1)
{
// This is a little bit of a kludge to keep people from having to
// change data files when 600 baud was introduced. Pretty ugly, huh?
if (bigbaud > 0)
{
bigbaud++;
}
return ((ModemSpeedE) bigbaud);
}
else
{
for (ModemSpeedE i = (ModemSpeedE) 0; i < MS_NUM; i = (ModemSpeedE) (i + 1))
{
if (bigbaud == connectbauds[i])
{
return (i);
}
}
return (MS_ERROR);
}
}
// --------------------------------------------------------------------------
// offhook(): Take the modem off-hook.
void TERMWINDOWMEMBER offhook(void)
{
CITWINDOW *w = CitWindowsMsg(NULL, getmsg(19));
Initport();
if (w)
{
destroyCitWindow(w, FALSE);
}
CommPort->OutString(cfg.offhookstr);
CommPort->OutString(br);
#ifndef WINCIT
CommPort->Disable();
#endif
}
void TERMWINDOWMEMBER displayOnOff(const char *string, int value)
{
mPrintf(string, value ? getmsg(549) : getmsg(550));
}
void TERMWINDOWMEMBER displayYesNo(const char *string, int value)
{
mPrintf(string, value ? getmsg(521) : getmsg(522));
}
Bool TERMWINDOWMEMBER changeOnOff(const char *str, Bool value)
{
mPrintfCR(str, value ? getmsg(550) : getmsg(549));
return (!value);
}
Bool TERMWINDOWMEMBER changeYesNo(const char *str, Bool value)
{
mPrintfCR(str, value ? getmsg(522) : getmsg(521));
return (!value);
}
void cdecl nullFunc(void)
{
}
void cyclesignature(void)
{
FILE *fBuf;
char line[256];
char *words[256];
Bool found = FALSE;
char path[80];
// there is only one signature line, so get out and use it
if (cfg.sig_current_pos == LONG_MAX)
{
return;
}
sprintf(path, sbs, cfg.homepath, citfiles[C_CONFIG_CIT]);
if ((fBuf = fopen(path, FO_R)) == NULL) // ASCII mode
{
return;
}
fseek(fBuf, cfg.sig_current_pos, SEEK_SET);
Bool HaveStartedOver = FALSE;
for (; !found;)
{
// if end of file cycle back up
if (fgets(line, 254, fBuf) == NULL)
{
if (!HaveStartedOver)
{
fseek(fBuf, cfg.sig_first_pos, SEEK_SET);
HaveStartedOver = TRUE;
}
else
{
found = TRUE; // not found, but this breaks us out of the loop
}
continue;
}
cfg.sig_current_pos = ftell(fBuf);
if (line[0] != '#')
{
continue;
}
if (strnicmp(line, getmsg(137), strlen(getmsg(137))) != SAMESTRING)
{
// okay we've gone past the last signature, cycle back up
if (!HaveStartedOver)
{
fseek(fBuf, cfg.sig_first_pos, SEEK_SET);
HaveStartedOver = TRUE;
}
else
{
found = TRUE; // not found, but this breaks us out of the loop
}
continue;
}
else
{
found = TRUE;
}
parse_it(words, line);
CopyStringToBuffer(cfg.nodeSignature, words[1]);
cfg.sig_current_pos = ftell(fBuf);
}
fclose(fBuf);
}
// --------------------------------------------------------------------------
// theAlgorithm(): Determine's users ability to get to a room.
//
// Input:
// r_slot rm: The room we wonder about
// h_slot hl: pass starting hall (usually thisHall)
// Bool exclude: TRUE means that excluded rooms should be considered
// inaccessible
//
// Return value:
// TRUE: The room can be accessed
// FALSE: The room cannot be accessed
//
// Notes:
// This is a recursive function.
// If this function runs out of memory, it returns FALSE for almost all rooms
Bool TERMWINDOWMEMBER theAlgorithm(r_slot rm, h_slot hl, Bool exclude)
{
assert(rm >= -1);
assert(rm < cfg.maxrooms);
assert(hl >= -1);
assert(hl < cfg.maxhalls);
static BitBag *hallCheck;
Bool lowest = FALSE;
if (!hallCheck)
{
if (rm == thisRoom || (rm == LOBBY && cfg.subhubs == 4))
{
return (TRUE);
}
if ((exclude && CurrentUser->IsRoomExcluded(rm)) || !CurrentUser->CanAccessRoom(rm))
{
return (FALSE);
}
hallCheck = new BitBag(cfg.maxhalls);
lowest = TRUE;
}
if (!hallCheck)
{
OutOfMemory(78);
}
else
{
if (hallCheck->BitTest(hl))
{
return (FALSE);
}
else
{
hallCheck->BitSet(hl, TRUE);
if (roominhall(rm, hl))
{
delete hallCheck;
hallCheck = NULL;
return (TRUE);
}
for (r_slot rmCnt = 0; rmCnt < cfg.maxrooms; rmCnt++)
{
if (CurrentUser->CanAccessRoom(rmCnt) && (!exclude || !CurrentUser->IsRoomExcluded(rmCnt)) &&
roominhall(rmCnt, hl) && iswindow(rmCnt))
{
for (h_slot hlCnt = 0; hlCnt < cfg.maxhalls; hlCnt++)
{
if (HallData[hlCnt].IsInuse() && CurrentUser->CanAccessHall(hlCnt) &&
HallData[hlCnt].IsWindowedIntoHall(rmCnt))
{
if (theAlgorithm(rm, hlCnt, exclude))
{
return (TRUE);
}
}
}
}
}
}
}
if (lowest && hallCheck)
{
delete hallCheck;
hallCheck = NULL;
}
return (FALSE);
}
// --------------------------------------------------------------------------
// theOtherAlgorithm(): Determine user's ability to get to each room on the system
//
// Input:
// Bool *rooms: A porinter to a cfg.maxrooms array of Bools
// h_slot hl: The hall to start in; usually thisHall
// Bool exclude: TRUE means that excluded rooms should be considered
// inaccessible
//
// Output:
// Bool *rooms: Each member of the array is set to FALSE (user cannot
// access the corresponding room) or TRUE (user can access it)
void TERMWINDOWMEMBER theOtherAlgorithm(Bool *rooms, h_slot hl, Bool exclude)
{
assert(hl >= -1);
assert(hl < cfg.maxhalls);
static BitBag *hallCheck;
Bool lowest = FALSE;
if (!hallCheck)
{
hallCheck = new BitBag(cfg.maxhalls);
memset(rooms, 0, sizeof(Bool) * cfg.maxrooms);
lowest = TRUE;
}
if (!hallCheck)
{
OutOfMemory(79);
}
else
{
if (hallCheck->BitTest(hl))
{
return;
}
else
{
hallCheck->BitSet(hl, TRUE);
if (cfg.subhubs != 4)
{
for (r_slot rmCnt = 0; rmCnt < cfg.maxrooms; rmCnt++)
{
if (!rooms[rmCnt] && CurrentUser->CanAccessRoom(rmCnt) && roominhall(rmCnt, hl) &&
(!exclude || !CurrentUser->IsRoomExcluded(rmCnt)))
{
rooms[rmCnt] = TRUE;
if (iswindow(rmCnt))
{
for (h_slot hlCnt = 0; hlCnt < cfg.maxhalls; hlCnt++)
{
if (HallData[hlCnt].IsInuse() && CurrentUser->CanAccessHall(hlCnt) &&
HallData[hlCnt].IsWindowedIntoHall(rmCnt))
{
theOtherAlgorithm(rooms, hlCnt, exclude);
}
}
}
}
}
}
else if (cfg.subhubs == 4)
{
for (r_slot rmCnt = 0; rmCnt < cfg.maxrooms; rmCnt++)
{
if (!rooms[rmCnt] && CurrentUser->CanAccessRoom(rmCnt) && roominhall(rmCnt, hl) &&
(!exclude || !CurrentUser->IsRoomExcluded(rmCnt)))
{
rooms[rmCnt] = TRUE;
if (rmCnt == 0)
{
for (h_slot hlCnt = 0; hlCnt < cfg.maxhalls; hlCnt++)
{
if (HallData[hlCnt].IsInuse() && CurrentUser->CanAccessHall(hlCnt))
{
theOtherAlgorithm(rooms, hlCnt, exclude);
}
}
}
}
}
}
}
}
if (lowest && hallCheck)
{
delete hallCheck;
hallCheck = NULL;
}
}