forked from RealDeuce/OpenDoors
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathODCore.c
More file actions
1620 lines (1348 loc) · 46.6 KB
/
Copy pathODCore.c
File metadata and controls
1620 lines (1348 loc) · 46.6 KB
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
/* OpenDoors Online Software Programming Toolkit
* (C) Copyright 1991 - 1999 by Brian Pirie.
*
* Oct-2001 door32.sys/socket modifications by Rob Swindell (www.synchro.net)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*
* File: ODCore.c
*
* Description: Implements the core of OpenDoors, including chat mode
* and standard input/output functions that are
* used throughout OpenDoors.
*
* Revisions: Date Ver Who Change
* ---------------------------------------------------------------
* Oct 13, 1994 6.00 BP New file header format.
* Oct 19, 1994 6.00 BP Changed paging hours logic.
* Oct 21, 1994 6.00 BP Further isolated com routines.
* Oct 22, 1994 6.00 BP Name case conversion /w punct.
* Dec 08, 1994 6.00 BP Allow custom chat mode deactivation.
* Dec 09, 1994 6.00 BP Remove global dir entry structure.
* Dec 13, 1994 6.00 BP Remove include of dir.h.
* Dec 31, 1994 6.00 BP Remove #ifndef USEINLINE DOS code.
* Dec 31, 1994 6.00 BP Remove old multitasker definitions.
* Jan 01, 1995 6.00 BP Don't use ODComInbound().
* Jan 01, 1995 6.00 BP _waitdrain() -> ODWaitDrain().
* Jan 01, 1995 6.00 BP Use new millisecond timer functions.
* Jan 01, 1995 6.00 BP Remove od_init() from _remotechar()
* Jan 01, 1995 6.00 BP Split off odkrnl.c from odcore.c
* Aug 19, 1995 6.00 BP 32-bit portability.
* Nov 11, 1995 6.00 BP Moved first_word() to odlist.c
* Nov 11, 1995 6.00 BP Removed register keyword.
* Nov 14, 1995 6.00 BP Added include of odscrn.h.
* Nov 16, 1995 6.00 BP Create odcore.h.
* Nov 17, 1995 6.00 BP Use new input queue mechanism.
* Dec 12, 1995 6.00 BP Added od_set_color().
* Dec 12, 1995 6.00 BP Added entry, exit and kernel macros.
* Dec 13, 1995 6.00 BP Moved chat mode code to ODKrnl.h.
* Dec 19, 1995 6.00 BP Request reason for chat outside hours.
* Dec 23, 1995 6.00 BP Allow space to continue at page pause.
* Dec 24, 1995 6.00 BP Added abtGreyBlock.
* Dec 30, 1995 6.00 BP Added ODCALL for calling convention.
* Jan 03, 1996 6.00 BP Use OD_API_VAR_DEFN for od_control.
* Jan 04, 1996 6.00 BP tODInQueueEvent -> tODInputEvent.
* Jan 23, 1996 6.00 BP No od_set_statusline() under Win32.
* Jan 30, 1996 6.00 BP Replaced od_yield() with od_sleep().
* Jan 30, 1996 6.00 BP Add ODInQueueGetNextEvent() timeout.
* Jan 09, 1996 6.00 BP ODComOutbound() returns actual size.
* Jan 09, 1996 6.00 BP Reduce kernel calls from od_disp...().
* Feb 19, 1996 6.00 BP Changed version number to 6.00.
* Mar 03, 1996 6.10 BP Begin version 6.10.
* Mar 19, 1996 6.10 BP MSVC15 source-level compatibility.
* Mar 21, 1996 6.10 BP Added od_control_get().
* Sep 01, 1996 6.10 BP Update output area on od_set_per...().
* Oct 19, 2001 6.20 RS od_get_key now ignores linefeeds.
* Mar 14, 2002 6.22 RS Fixed od_get_key(bWait=FALSE)
* Aug 10, 2003 6.23 SH *nix support
*/
#define BUILDING_OPENDOORS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <errno.h>
#include "OpenDoor.h"
#include "ODStr.h"
#include "ODGen.h"
#include "ODPlat.h"
#include "ODCom.h"
#include "ODKrnl.h"
#include "ODScrn.h"
#include "ODCore.h"
#include "ODInQue.h"
#ifdef ODPLAT_WIN32
#include "ODFrame.h"
#endif /* ODPLAT_WIN32 */
/* GLOBAL VARIABLES SHARED THROUGHOUT OPENDOORS. */
/* Global declaration of the OpenDoors control structure. */
OD_API_VAR_DEFN tODControl
#ifndef _WIN32 /* warning C4229: anachronism used : modifiers on data are ignored */
OD_GLOBAL_CONV
#endif
od_control;
/* OpenDoors global initialized flag. */
BOOL bODInitialized = FALSE;
/* Global serial port object handle. */
tPortHandle hSerialPort;
/* Global input queue object handle. */
tODInQueueHandle hODInputQueue;
/* Reentrancy control. */
BOOL bIsCallbackActive = FALSE;
BOOL bShellChatActive = FALSE;
/* Global working space. */
char szODWorkString[OD_GLOBAL_WORK_STRING_SIZE];
/* Global instance of the text information structure for general use. */
tODScrnTextInfo ODTextInfo;
/* Logfile function hooks. */
BOOL (*pfLogWrite)(INT) = NULL;
void (*pfLogClose)(INT) = NULL;
/* od_color_config() support for od_printf(). */
char chColorCheck = 0;
char *pchColorEndPos;
/* Status line information. */
BYTE btCurrentStatusLine = STATUS_NONE;
OD_PERSONALITY_CALLBACK *pfCurrentPersonality = NULL;
char szDesiredPersonality[33] = "";
SET_PERSONALITY_FUNC *pfSetPersonality = NULL;
/* Commonly used character sequences. */
char abtBlackBlock[2] = {' ', 0x07};
char abtGreyBlock[2] = {' ', 0x70};
char szBackspaceWithDelete[4] = {8, ' ', 8, 0};
/* Current output area on screen. */
BYTE btOutputTop = 1;
BYTE btOutputBottom = 23;
/* PRIVATE VARIABLES. */
/* Display color varaibles. */
char bAnyColorChangeYet;
/* Static character sequences. */
static char szClearScreen[2] = {12, 0};
/* Lookup table to map colors from PC values to ANSI color values. */
static BYTE abtPCToANSIColorTable[8] = {30, 34, 32, 36, 31, 35, 33, 37};
/* LOCAL HELPER FUNCTIONS. */
static void ODAddANSIParameter(char *szControlSequence, int nParameterValue);
/* ----------------------------------------------------------------------------
* ODWaitDrain()
*
* Waits for up to the specified number of milliseconds for the output serial
* buffer to drain.
*
* Parameters: MaxWait - Specifies the maximum number of milliseconds to wait
* before timing out.
*
* Return: void
*/
void ODWaitDrain(tODMilliSec MaxWait)
{
int nOutboundSize;
tODTimer Timer;
/* If we are operating in local mode, then don't do anything. */
if(od_control.baud == 0) return;
/* Otherwise, start a timer that is set to elapse after the maximum */
/* wait period. */
ODTimerStart(&Timer, MaxWait);
/* Loop until either the outbound buffer is empty, or the */
/* timer has elapsed. */
for(;;)
{
/* Check whether any data is in the outbound serial queue. */
ODComOutbound(hSerialPort, &nOutboundSize);
/* If the queue is empty or the timer has elapsed, then stop */
/* waiting. */
if(nOutboundSize == 0 || ODTimerElapsed(&Timer)) break;
/* Otherwise, give other tasks a chance to run. */
od_sleep(0);
/* Give od_kernel() activities a chance to run. */
CALL_KERNEL_IF_NEEDED();
}
}
/* ----------------------------------------------------------------------------
* od_clr_scr()
*
* Clears the contents of the local and remote screens, if screen clearing is
* enabled.
*
* Parameters: none
*
* Return: void
*/
ODAPIDEF void ODCALL od_clr_scr(void)
{
INT16 nOriginalAttrib;
/* Log function entry if running in trace mode */
TRACE(TRACE_API, "od_clr_scr()");
if(!bODInitialized) od_init();
OD_API_ENTRY();
/* Don't clear screen if disabled. */
if(!od_control.od_always_clear && !(od_control.user_attribute & 2)
&& (od_control.od_extended_info || od_control.od_info_type == CUSTOM))
{
OD_API_EXIT();
return;
}
if(od_control.user_rip)
{
od_disp("!|*", 3, FALSE);
if(!od_control.od_default_rip_win)
{
od_disp("!|w0000270M12", 13, FALSE);
}
}
if(od_control.user_ansi)
{
od_disp("\x1b[2J\x1b[1;1H", 10, FALSE);
}
else {
/* Send ascii 12 to modem, no local echo. */
od_disp(szClearScreen, 1, FALSE);
}
/* Clear local window. */
ODScrnClear();
/* Get color set prior to screen clear. */
nOriginalAttrib = od_control.od_cur_attrib;
/* Current color state is unknown. */
od_control.od_cur_attrib = -1;
/* Set color to original value. This gurantees that local and */
/* remote systems both have the same current color set. */
od_set_attrib(nOriginalAttrib);
OD_API_EXIT();
}
/* ----------------------------------------------------------------------------
* od_input_str()
*
* Allows the user to input a string up to the specified length, using
* characters in the specified range. This string input function is designed
* to be compatible with all terminal types.
*
* Parameters: pszInput - Pointer to string to store input in.
*
* nMaxLength - Maximum number of characters to permit the user
* to input.
*
* chMin - The minimum character value to permit. This must
* be at least ASCII 32.
*
* chMax - The maximum character value to permit.
*
* Return: void
*/
ODAPIDEF void ODCALL od_input_str(char *pszInput,
INT nMaxLength,
unsigned char chMin,
unsigned char chMax)
{
char chKeyPressed;
INT nPosition;
/* Log function entry if running in trace mode. */
TRACE(TRACE_API, "od_input_str()");
/* Initialize OpenDoors if it hasn't already been done. */
if(!bODInitialized) od_init();
OD_API_ENTRY();
/* Start at the beginning of the string. */
nPosition = 0;
/* Check that input parameters are valid. */
if(pszInput == NULL || nMaxLength < 1 || chMin > chMax)
{
od_control.od_error = ERR_PARAMETER;
OD_API_EXIT();
return;
}
for(;;)
{
chKeyPressed = od_get_key(TRUE);
/* If user pressed enter. */
if(chKeyPressed == '\r' || chKeyPressed == '\n')
{
/* Terminate the string. */
pszInput[nPosition] = '\0';
/* Display CR-LF sequence. */
od_disp_str("\n\r");
/* Exit the function. */
OD_API_EXIT();
return;
}
/* If the user pressed backspace. */
else if(chKeyPressed == 8)
{
/* If we are not currently at the beginning of the string. */
if(nPosition > 0)
{
/* Send backspace sequence. */
od_disp_str(szBackspaceWithDelete);
/* Move current position back by one position in the string. */
--nPosition;
}
}
/* If this is a valid character to place in the string and we have */
/* not reached the maximum size of the string yet. */
else if(chKeyPressed >= chMin && chKeyPressed <= chMax
&& nPosition < nMaxLength)
{
/* Display key that was pressed. */
od_putch(chKeyPressed);
/* Add the entered character to the string and increment our */
/* current position in the string. */
pszInput[nPosition++] = chKeyPressed;
}
}
}
/* ----------------------------------------------------------------------------
* od_clear_keybuffer()
*
* Clears any keystrokes from the inbound buffers. Both input from local and
* remote systems is discarded, by clearing both OpenDoors' common input
* event queue, and the serial port inbound buffer. This function is called
* to cause any input by the user prior to the time the function was called
* to be ignored.
*
* Parameters: none
*
* Return: void
*/
ODAPIDEF void ODCALL od_clear_keybuffer(void)
{
/* Log function entry if running in trace mode. */
TRACE(TRACE_API, "od_clear_keybuffer()");
/* Initialize OpenDoors if it hasn't already been done. */
if(!bODInitialized) od_init();
OD_API_ENTRY();
/* Empty any events in the common input event queue. */
ODInQueueEmpty(hODInputQueue);
/* If we are not operating in local mode ... */
if(od_control.baud != 0)
{
/* ... then remove any items in the serial port inbound buffer. */
ODComClearInbound(hSerialPort);
}
/* Call the OpenDoors kernel function. */
CALL_KERNEL_IF_NEEDED();
OD_API_EXIT();
}
/* ----------------------------------------------------------------------------
* od_key_pending()
*
* Returns TRUE if there's a key pending, FALSE otherwise.
*
* Parameters: none
*
* Return: TRUE if character is waiting, FALSE if no character is waiting.
*/
ODAPIDEF BOOL ODCALL od_key_pending(void)
{
/* Initialize OpenDoors if it hasn't already been done. */
if(!bODInitialized) od_init();
/* Log function entry if running in trace mode. */
TRACE(TRACE_API, "od_get_key()");
OD_API_ENTRY();
/* Call the OpenDoors kernel. */
CALL_KERNEL_IF_NEEDED();
if(!ODInQueueWaiting(hODInputQueue))
{
OD_API_EXIT();
return(FALSE);
}
OD_API_EXIT();
return(TRUE);
}
/* ----------------------------------------------------------------------------
* od_get_key()
*
* Inputs a single character, optionally waiting for the next character if no
* character has been received yet. This function returns data received from
* either the local or remote system, in the order in which it was received.
*
* Parameters: bWait - FALSE if od_get_key() should return right away with
* a value of 0 if no characters have been received, or
* TRUE if od_get_key() should wait for the next received
* character.
*
* Return: Character that was received, or 0 if no character is waiting.
*/
ODAPIDEF char ODCALL od_get_key(BOOL bWait)
{
tODInputEvent InputEvent;
/* Initialize OpenDoors if it hasn't already been done. */
if(!bODInitialized) od_init();
/* Log function entry if running in trace mode. */
TRACE(TRACE_API, "od_get_key()");
OD_API_ENTRY();
/* Call the OpenDoors kernel. */
CALL_KERNEL_IF_NEEDED();
do {
/* If we aren't supposed to wait for input, then check whether any */
/* input is waiting in the input queue, and if not return right away */
/* without any data. */
if(!bWait)
{
if(!ODInQueueWaiting(hODInputQueue))
{
OD_API_EXIT();
return(0);
}
}
/* Obtain the next character from the input queue. If we get to this */
/* point and there is no data waiting in the input queue, then the */
/* ODInQueueGetNextEvent() function will block until a character */
/* is available in the input queue. */
ODInQueueGetNextEvent(hODInputQueue, &InputEvent, OD_NO_TIMEOUT);
/* Only keyboard input events are currently supported by od_get_key(). */
ASSERT(InputEvent.EventType == EVENT_CHARACTER);
/* Update OpenDoors control structure member that records whether the */
/* last input came from the local or remote user. */
od_control.od_last_input = InputEvent.bFromRemote ? 0 : 1;
} while(InputEvent.chKeyPress == '\n'); /* Ignore line-feed char */
/* Return the character that was pressed by the user. */
OD_API_EXIT();
return(InputEvent.chKeyPress);
}
/* ----------------------------------------------------------------------------
* od_carrier()
*
* Allows programs to determine the current state of the carrier detect
* signal when OpenDoors' automatic carrier detection has been disabled.
*
* Parameters: none
*
* Return: TRUE if the carrier detct signal is present, FALSE if it
* isn't. When operating in local mode, this function always
* returns FALSE.
*/
ODAPIDEF BOOL ODCALL od_carrier(void)
{
BOOL bIsCarrier;
/* Initialize OpenDoors if it hasn't already been done. */
if(!bODInitialized) od_init();
OD_API_ENTRY();
/* Log function entry if running in trace mode */
TRACE(TRACE_API, "od_carrier()");
/* If we are operating in local mode, then return FALSE. */
if(od_control.baud == 0)
{
od_control.od_error = ERR_NOREMOTE;
OD_API_EXIT();
return(FALSE);
}
/* In remote mode, obtain the current state of the carrier detect signal. */
ODComCarrier(hSerialPort, &bIsCarrier);
/* Return the current state of the carrier detect signal. */
OD_API_EXIT();
return(bIsCarrier);
}
/* ----------------------------------------------------------------------------
* od_repeat()
*
* This function displays the same character the specified number of times on
* the local and remote screens, using any available optimal control sequences
* under the current display mode.
*
* Parameters: chValue - Character to repeat.
*
* btTimes - Number of times to repeat the character.
*
* Return: void
*/
ODAPIDEF void ODCALL od_repeat(char chValue, BYTE btTimes)
{
char *pchCurStringPos;
BYTE btLeft;
char szBuffer[3];
/* Log function entry if running in trace mode. */
TRACE(TRACE_API, "od_repeat()");
/* Ensure that OpenDoors has been initialized. */
if(!bODInitialized) od_init();
OD_API_ENTRY();
/* If the caller asked to repeat the character 0 times, then we can */
/* safely return right away without doing anything. */
if(btTimes == 0)
{
OD_API_EXIT();
return;
}
/* Generate string of repeat characters. */
pchCurStringPos = szODWorkString;
for(btLeft = btTimes; btLeft--;)
{
*pchCurStringPos++ = chValue;
}
*pchCurStringPos = '\0';
/* Display repeated string on local screen. */
ODScrnDisplayString(szODWorkString);
/* If we are operating in AVATAR mode. */
if(od_control.user_avatar)
{
/* Generate the AVATAR control sequence to repeat this character */
/* the specified number of times. */
szBuffer[0] = 25;
szBuffer[1] = chValue;
szBuffer[2] = btTimes;
od_disp(szBuffer, 3, FALSE);
}
/* If AVATAR mode is not available. */
else
{
/* Send the entire repeated string to the remote system. */
od_disp(szODWorkString, btTimes, FALSE);
}
OD_API_EXIT();
}
/* ----------------------------------------------------------------------------
* od_page()
*
* This function is called when the user wished to page the system operator.
*
* Parameters: none
*
* Return: void
*/
ODAPIDEF void ODCALL od_page(void)
{
INT16 nCount;
tODTimer Timer;
time_t nUnixTime;
struct tm *TimeBlock;
INT16 nMinute;
BOOL bFailed = FALSE;
INT16 nOriginalAttrib;
/* Log function entry if running in trace mode. */
TRACE(TRACE_API, "od_page()");
/* Initialize OpenDoors if it hasn't already been done. */
if(!bODInitialized) od_init();
OD_API_ENTRY();
/* Save current display color attribute. */
nOriginalAttrib = od_control.od_cur_attrib;
/* Clear the screen. */
od_clr_scr();
od_set_attrib(od_control.od_chat_color1);
/* Ask reason for chat. */
od_disp_str(od_control.od_chat_reason);
od_set_attrib(od_control.od_chat_color2);
od_putch('[');
/* Use extended ASCII characters if operating in ANSI or AVATAR mode. */
if(od_control.user_ansi || od_control.user_avatar)
{
od_repeat('\xc4',77);
}
else
{
od_repeat('-',77);
}
od_disp_str("]\n\r ");
od_input_str(od_control.user_reasonforchat,77,32,255);
/* If the user did not abort sysop paging by entering a blank reason */
/* for chat. */
if(strlen(od_control.user_reasonforchat) != 0)
{
/* Indicate that the user wants to chat. */
od_control.user_wantchat = TRUE;
#ifdef ODPLAT_WIN32
ODFrameUpdateWantChat();
#endif /* ODPLAT_WIN32 */
/* Determine whether or not sysop paging should be permitted at */
/* the current time. */
nUnixTime = time(NULL);
TimeBlock = localtime(&nUnixTime);
nMinute = (60 * TimeBlock->tm_hour) + TimeBlock->tm_min;
if(od_control.od_pagestartmin < od_control.od_pageendmin)
{
if(nMinute < od_control.od_pagestartmin
|| nMinute >= od_control.od_pageendmin)
{
bFailed = TRUE;
}
}
else if(od_control.od_pagestartmin > od_control.od_pageendmin)
{
if(nMinute < od_control.od_pagestartmin
&& nMinute >= od_control.od_pageendmin)
{
bFailed = TRUE;
}
}
else
{
bFailed = FALSE;
}
/* If paging is set to PAGE_ENABLE, meaning that sysop paging should */
/* be permitted regardless of the time of day, then allow paging. */
if(od_control.od_okaytopage == PAGE_ENABLE)
{
bFailed = FALSE;
}
/* If paging is explicitly disable by PAGE_DISABLE, or the current */
/* time of the day is not normally permitted for paging. */
if(od_control.od_okaytopage == PAGE_DISABLE || bFailed)
{
/* Indicate this to user. */
od_disp_str("\n\r");
od_disp_str(od_control.od_no_sysop);
od_disp_str(od_control.od_press_key);
od_get_answer("\x0d\x0a");
/* Return from this function. */
goto cleanup;
}
/* Update status line right away. */
bForceStatusUpdate = TRUE;
CALL_KERNEL_IF_NEEDED();
/* Write sysop page information to the logfile, if the log file */
/* system is hooked up. */
if(pfLogWrite != NULL)
{
(*pfLogWrite)(8);
}
/* Tell the user that we are now paging the system operator. */
od_set_attrib(od_control.od_chat_color1);
od_disp_str(od_control.od_paging);
#ifdef OD_TEXTMODE
/* Display sysop page status line if it exists and the sysop status */
/* line is currently active. */
if(od_control.od_page_statusline != -1 && btCurrentStatusLine != 8)
{
od_set_statusline(od_control.od_page_statusline);
}
#endif /* OD_TEXTMODE */
/* Increment the total number of times that the user has paged */
/* the sysop. */
++od_control.user_numpages;
/* Sysop hasn't responded yet. */
bChatted=FALSE;
/* Loop for length of sysop page. */
for(nCount = 0; nCount < od_control.od_page_len; ++nCount)
{
/* Start a timer that is set to elapse in exactly one second. */
ODTimerStart(&Timer, 1000);
/* Display another period character. */
od_putch('.');
/* Abort page if system operator answered */
if(bChatted) goto cleanup;
/* Send beep to local and remote systems. */
od_putch('\a');
/* Check whether system operator has answered after playing beep. */
if (bChatted) goto cleanup;
/* Wait for the timer to elapse, calling od_kernel() so that */
/* chat mode will start as soon as the sysop presses the */
/* chat key. */
while(!ODTimerElapsed(&Timer))
{
CALL_KERNEL_IF_NEEDED();
}
}
/* If sysop page time has elapsed without a response from the */
/* sysop, then notify the user. */
od_disp_str(od_control.od_no_response);
od_disp_str(od_control.od_press_key);
od_get_answer("\x0d\x0a");
od_disp_str("\n\r\n\r");
}
cleanup:
/* Restore original display color attribute. */
od_set_attrib(nOriginalAttrib);
OD_API_EXIT();
}
/* ----------------------------------------------------------------------------
* od_disp()
*
* Function to send one or more character to the remote system, optionally
* also echoing the same characters to the local screen.
*
* Parameters: pachBuffer - Pointer to buffer of characters to send.
*
* nSize - Number of characters to send from the buffer.
*
* bLocalEcho - TRUE to also echo the characters to the local
* screen, FALSE to just send the characters to the
* remote system.
*
* Return: void
*/
ODAPIDEF void ODCALL od_disp(const char *pachBuffer, INT nSize, BOOL bLocalEcho)
{
/* Log function entry if running in trace mode. */
TRACE(TRACE_API, "od_disp()");
/* Initialize OpenDoors if it hasn't already been done. */
if(!bODInitialized) od_init();
OD_API_ENTRY();
/* Call the OpenDoors kernel, if needed. */
#ifndef OD_MULTITHREADED
if(ODTimerElapsed(&RunKernelTimer))
{
CALL_KERNEL_IF_NEEDED();
}
#endif /* !OD_MULTITHREADED */
/* If we are operating in remote mode, then send the buffer to the */
/* remote system. */
if(od_control.baud != 0)
{
ODComSendBuffer(hSerialPort, (BYTE *)pachBuffer, nSize);
}
/* If we are also to display the character on the local screen, then */
/* display the buffer on the local screen. */
if(bLocalEcho)
{
ODScrnDisplayBuffer(pachBuffer, nSize);
}
OD_API_EXIT();
}
/* ----------------------------------------------------------------------------
* od_disp_str()
*
* Displays a string on both the local and remote systems.
*
* Parameters: pszToDisplay - Pointer to the string to be displayed.
*
* Return: void
*/
ODAPIDEF void ODCALL od_disp_str(const char *pszToDisplay)
{
/* Log function entry if running in trace mode */
TRACE(TRACE_API, "od_disp_str()");
/* Initialize OpenDoors if it hasn't already been done. */
if(!bODInitialized) od_init();
OD_API_ENTRY();
/* Call the OpenDoors kernel, if needed. */
#ifndef OD_MULTITHREADED
if(ODTimerElapsed(&RunKernelTimer))
{
CALL_KERNEL_IF_NEEDED();
}
#endif /* !OD_MULTITHREADED */
/* Send the string to the remote system, if we are running in remote mode. */
if(od_control.baud != 0)
{
ODComSendBuffer(hSerialPort, (BYTE *)pszToDisplay, strlen(pszToDisplay));
}
/* Display the screen on the local screen. */
ODScrnDisplayString(pszToDisplay);
OD_API_EXIT();
}
/* ----------------------------------------------------------------------------
* od_set_statusline()
*
* Switches to one of the available status lines provided by the current
* personality, or turns off the status line altogether.
*
* Parameters: nSetting - Indicates which status line (if any) should be
* activated.
*
* Return: void
*/
ODAPIDEF void ODCALL od_set_statusline(INT nSetting)
{
#ifdef OD_TEXTMODE
INT nDistance;
BYTE btCount
#endif /* OD_TEXTMODE */
/* Log function entry if running in trace mode. */
TRACE(TRACE_API, "od_set_statusline()");
/* Initialize OpenDoors if it hasn't already been done. */
if(!bODInitialized) od_init();
OD_API_ENTRY()
#ifdef OD_TEXTMODE
/* If status line is disabled, then don't do anything. */
if(!od_control.od_status_on)
{
OD_API_EXIT();
return;
}
/* Ensure that the parameter is within the valid range. */
if(nSetting < 0 || nSetting > 8)
{
nSetting = 0;
}
/* If the specified status line is already active, and status line */
/* update isn't being forced, then return without doing anything. */
if(!od_control.od_update_status_now && nSetting == btCurrentStatusLine)
{
OD_API_EXIT();
return;
}
/* Save the current cursor settings. */
ODStoreTextInfo();
/* Reset screen boundary to allow access to the entire screen. */
ODScrnSetBoundary(1,1,80,25);
/* If status line is being turned off. */
if(btCurrentStatusLine == STATUS_NONE)
{
if((nDistance = (INT)ODTextInfo.cury - ( 1 + (INT)btOutputBottom
- (INT)btOutputTop)) > 0)
{
ODScrnCopyText(1, (BYTE)((INT)btOutputTop + nDistance), 80,
(BYTE)((INT)btOutputBottom + nDistance), (BYTE)btOutputTop, 1);
ODTextInfo.cury = 1 + btOutputBottom - btOutputTop;
}
else if(ODTextInfo.cury < btOutputTop)
{
ODTextInfo.cury = btOutputTop;
ODScrnCopyText(1, (BYTE)(btOutputTop + 24 - btOutputBottom), 80, 25,
btOutputTop, 1);
}
}
od_control.od_current_statusline = btCurrentStatusLine = nSetting;
if(nSetting == 8)
{
ODScrnSetAttribute(0x07);
for(btCount = 1; btCount <= 25; ++btCount)
{
if(btCount < btOutputTop || btCount > btOutputBottom)
{
if(btCount == 25)
{
ODScrnPutText(80, 25, 80, 25, abtBlackBlock);
ODScrnSetCursorPos(1, 25);
ODScrnDisplayString(" ");
}
else
{
ODScrnSetCursorPos(1, 24);
ODScrnDisplayString(" ");
}
}
}
ODScrnSetAttribute(ODTextInfo.attribute);
ODScrnSetCursorPos(ODTextInfo.curx, ODTextInfo.cury);
}
else
{
ODScrnEnableCaret(FALSE);
ODScrnEnableScrolling(FALSE);
(*pfCurrentPersonality)((BYTE)nSetting);
ODScrnEnableCaret(TRUE);
ODScrnEnableScrolling(TRUE);
ODScrnSetBoundary(1, btOutputTop, 80, btOutputBottom);
ODScrnSetAttribute(ODTextInfo.attribute);
ODScrnSetCursorPos(ODTextInfo.curx, ODTextInfo.cury);
}