/
Door.cs
1766 lines (1604 loc) · 65.3 KB
/
Door.cs
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
/*
RMLib: Nonvisual support classes used by multiple R&M Software programs
Copyright (C) Rick Parrish, R&M Software
This file is part of RMLib.
RMLib 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 3 of the License, or
any later version.
RMLib 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 RMLib. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.IO;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Text.RegularExpressions;
using System.Net.Sockets;
using System.Linq;
// TODO Need to handle telnet/rlogin negotiation
namespace RandM.RMLib
{
/// <summary>
/// Please note that the Door class is not thread safe. If:
/// 1) Anybody ever uses this class, and
/// 2) A use-case for a thread safe Door class is presented
/// then I'll be happy to consider adding the required locking to make it thread safe.
/// </summary>
public static class Door
{
/// <summary>
/// Contains information that was read from the dropfile (if a dropfile was read)
/// Not all dropfiles containt he same information, so only a subset of this data is guaranteed to exist
/// </summary>
public static TDropInfo DropInfo = new TDropInfo();
/// <summary>
/// Contains information about the last key that was read by the doorkit
/// </summary>
public static TLastKey LastKey = new TLastKey();
/// <summary>
/// The prompt that gets displayed when the More() method is called
/// </summary>
public static TMOREPrompt MOREPrompt = new TMOREPrompt();
/// <summary>
/// Contains information about the current session
/// </summary>
public static TSession Session = new TSession();
private static TcpConnection _Connection = null;
#region Standard R&M Door functions
/// <summary>
/// Instantiates and initializes the doorkit with default values
/// </summary>
static Door()
{
LocalEcho = false;
PipeWrite = true;
SethWrite = false;
StripLF = true;
StripNull = true;
OnHangUp = DefaultOnHangUp;
OnHangUp = DefaultOnHangUp;
OnLocalLogin = DefaultOnLocalLogin;
OnStatusBar = DefaultOnStatusBar;
OnTimeOut = DefaultOnTimeOut;
OnTimeUp = DefaultOnTimeUp;
OnUsage = DefaultOnUsage;
try
{
// Try to make the output look like it does on Windows
Console.OutputEncoding = Encoding.GetEncoding("Windows-1252");
}
catch (Exception)
{
// Ignore, the user will just be stuck with whatever the default is
}
}
/// <summary>
/// Checks for a carrier. Always returns true for local sessions
/// </summary>
/// <returns>True if local or carrier exists, false if no carrier exists</returns>
public static bool Carrier
{
get { return (Local || _Connection.Connected); }
}
/// <summary>
/// Clears the local and remote input buffers
/// </summary>
public static void ClearBuffers()
{
while (Crt.KeyPressed())
Crt.ReadKey();
if (!Local)
{
_Connection.ReadString();
}
}
/// <summary>
/// Closes the socket connection, which will disconnect the remote user
/// </summary>
public static void Disconnect()
{
if (!Local)
{
_Connection.ShutdownOnClose = true;
_Connection.Close();
_Connection = null;
}
DropInfo.SocketHandle = -1;
}
/// <summary>
/// Clears all text to the end of the line
/// </summary>
public static void ClrEol()
{
Write(Ansi.ClrEol());
}
/// <summary>
/// Clears all text on the screen
/// </summary>
public static void ClrScr()
{
Write(Ansi.ClrScr());
}
/// <summary>
/// Moves the cursor down the screen
/// </summary>
/// <param name="count">The number of lines to move the cursor down</param>
public static void CursorDown(int count)
{
Write(Ansi.CursorDown(count));
}
/// <summary>
/// Moves the cursor to the left on the screen
/// </summary>
/// <param name="count">The number of columns to move the cursor left</param>
public static void CursorLeft(int count)
{
Write(Ansi.CursorLeft(count));
}
/// <summary>
/// Restores the previously saved cursor position
/// </summary>
/// <seealso cref="CursorSave"/>
public static void CursorRestore()
{
Write(Ansi.CursorRestore());
}
/// <summary>
/// Moves the cursor to the right on the screen
/// </summary>
/// <param name="count">The number of columns to move the cursor right</param>
public static void CursorRight(int count)
{
Write(Ansi.CursorRight(count));
}
/// <summary>
/// Saves the current cursor position
/// </summary>
/// <seealso cref="CursorRestore"/>
public static void CursorSave()
{
Write(Ansi.CursorSave());
}
/// <summary>
/// Moves the cursor up the screen
/// </summary>
/// <param name="count">The number of rows to move the cursor up</param>
public static void CursorUp(int count)
{
Write(Ansi.CursorUp(count));
}
/// <summary>
/// Displays a file (ANSI, ASCII, Text) on screen, optionally pausing every x lines
/// </summary>
/// <param name="fileName">The file to display</param>
/// <param name="linesBeforePause">The number of lines to display before pausing. 0 causes no pauses</param>
public static void DisplayFile(string fileName, int linesBeforePause)
{
if (File.Exists(fileName))
{
string[] Lines = FileUtils.FileReadAllLines(fileName, RMEncoding.Ansi);
for (int i = 0; i < Lines.Length; i++)
{
Write(Lines[i]);
if (i != Lines.Length - 1)
{
WriteLn();
}
if ((linesBeforePause > 0) && ((i + 1) % linesBeforePause == 0))
{
More();
}
}
}
}
private static void DoEvents()
{
TimeSpan Dif = DateTime.Now.Subtract(Session.EventsTime);
if ((Session.Events) && (Dif.TotalMilliseconds > 1000))
{
//Check For Hangup
if ((!Carrier) && (OnHangUp != null))
{
OnHangUp(null, EventArgs.Empty);
}
// Check For Time Up
if ((SecondsLeft < 1) && (OnTimeUp != null))
{
OnTimeUp(null, EventArgs.Empty);
}
// Check For Idle Timeout
if ((Session.DoIdleCheck) && (SecondsIdle > Session.MaxIdle) && (OnTimeOut != null))
{
OnTimeOut(null, EventArgs.Empty);
}
// Check For Time Up Warning
// TODO Fix this so it's not dependent on a per-second check
if ((SecondsLeft % 60 == 1) && (SecondsLeft / 60 <= 5) && (OnTimeUpWarning != null))
{
OnTimeUpWarning(null, EventArgs.Empty);
}
// Check For Idle Timeout Warning
// TODO Fix this so it's not dependent on a per-second check
if ((Session.DoIdleCheck) && ((Session.MaxIdle - SecondsIdle) % 60 == 1) && ((Session.MaxIdle - SecondsIdle) / 60 <= 5) && (OnTimeOutWarning != null))
{
OnTimeOutWarning(null, EventArgs.Empty);
}
// Update Status Bar
if (OnStatusBar != null)
{
OnStatusBar(null, EventArgs.Empty);
}
Session.EventsTime = DateTime.Now;
}
}
/// <summary>
/// Draws a box on the screen with a customizable position, colour, and border
/// </summary>
/// <param name="left">Column for the left side of the box</param>
/// <param name="top">Row for the top of the box</param>
/// <param name="right">Column for the right side of the box</param>
/// <param name="bottom">Row for the bottom of the box</param>
/// <param name="foregroundColour">Foreground colour for the </param>
/// <param name="backgroundColour"></param>
/// <param name="borderStyle"></param>
public static void DrawBox(int left, int top, int right, int bottom, int foregroundColour, int backgroundColour, CrtPanel.BorderStyle borderStyle)
{
// Characters for the box
char TopLeft = '\0';
char TopRight = '\0';
char BottomLeft = '\0';
char BottomRight = '\0';
char TopBottom = '\0';
char LeftRight = '\0';
// Determine which character set to use
switch (borderStyle)
{
case CrtPanel.BorderStyle.Single:
TopLeft = (char)218;
TopRight = (char)191;
BottomLeft = (char)192;
BottomRight = (char)217;
TopBottom = (char)196;
LeftRight = (char)179;
break;
case CrtPanel.BorderStyle.Double:
TopLeft = (char)201;
TopRight = (char)187;
BottomLeft = (char)200;
BottomRight = (char)188;
TopBottom = (char)205;
LeftRight = (char)186;
break;
case CrtPanel.BorderStyle.DoubleH:
case CrtPanel.BorderStyle.SingleV:
TopLeft = (char)213;
TopRight = (char)184;
BottomLeft = (char)212;
BottomRight = (char)190;
TopBottom = (char)205;
LeftRight = (char)179;
break;
case CrtPanel.BorderStyle.DoubleV:
case CrtPanel.BorderStyle.SingleH:
TopLeft = (char)214;
TopRight = (char)183;
BottomLeft = (char)211;
BottomRight = (char)189;
TopBottom = (char)196;
LeftRight = (char)186;
break;
}
// Save current text colour and cursor position
int SavedAttr = Crt.TextAttr;
Write(Ansi.CursorSave());
// Apply new text colour
TextColor(foregroundColour);
TextBackground(backgroundColour);
// Draw top row
GotoXY(left, top);
Write(TopLeft.ToString());
Write(new string(TopBottom, right - left - 1));
Write(TopRight.ToString());
// Draw middle rows
for (int Line = top + 1; Line < bottom; Line++)
{
GotoXY(left, Line);
Write(LeftRight.ToString());
Write(new string(' ', right - left - 1));
Write(LeftRight.ToString());
}
// Draw bottom row
GotoXY(left, bottom);
Write(BottomLeft.ToString());
Write(new string(TopBottom, right - left - 1));
Write(BottomRight.ToString());
// Restore original text colour and cursor position
Write(Ansi.CursorRestore());
TextAttr(SavedAttr);
}
/// <summary>
/// Move the cursor to the given x coordinate on the current line
/// </summary>
/// <param name="column">The 1-based x coordinate to move to</param>
public static void GotoX(int column)
{
Write(Ansi.GotoX(column));
}
/// <summary>
/// Move the cursor to the given x,y coordinate
/// </summary>
/// <param name="column">The 1-based x coordinate</param>
/// <param name="row">The 1-based y coordinate</param>
public static void GotoXY(int column, int row)
{
Write(Ansi.GotoXY(column, row));
}
/// <summary>
/// Move the cursor to the given y coordinate on the current column
/// </summary>
/// <param name="row">The 1-based y coordinate to move to</param>
public static void GotoY(int row)
{
Write(Ansi.GotoY(row));
}
/// <summary>
/// Checks whether a key has been pressed on either the local or remote side
/// </summary>
/// <returns>True if a keypress is waiting, false if no keypress is available</returns>
public static bool KeyPressed()
{
if (Local)
{
return Crt.KeyPressed();
}
else
{
DoEvents();
return (Crt.KeyPressed() || _Connection.CanRead());
}
}
/// <summary>
/// Checks whether the door is running in local mode
/// </summary>
public static bool Local
{
get
{
return ((DropInfo.ComType == 0) || (DropInfo.SocketHandle == -1));
}
}
/// <summary>
/// Determines whether local echo is enabled
/// </summary>
public static bool LocalEcho { get; set; }
/// <summary>
/// Displays a MORE prompt and waits for a keypress. Erased the prompt after a key is pressed
/// </summary>
public static void More()
{
string Line = "";
int LineLength = 0;
switch (DropInfo.Emulation)
{
case DoorEmulationType.ASCII:
Line = MOREPrompt.ASCII;
LineLength = MOREPrompt.ASCII.Length;
break;
case DoorEmulationType.ANSI:
Line = MOREPrompt.ANSI;
LineLength = MOREPrompt.ANSILength;
break;
}
int OldAttr = Crt.TextAttr;
Write(Line);
ReadKey();
CursorLeft(LineLength);
Write("|00" + new string(' ', LineLength));
CursorLeft(LineLength);
TextAttr(OldAttr);
}
/// <summary>
/// Initializes the socket (when not in local mode)
/// </summary>
/// <returns>True if the socket was opened, false if it was not</returns>
public static bool Open()
{
if (Local)
{
return true;
}
else
{
switch (DropInfo.ComType)
{
case 0: return true; // Local
case 1: return false; // Serial
case 2: _Connection = new TelnetConnection(); break;
case 3: _Connection = new RLoginConnection(); break;
case 4: _Connection = new WebSocketConnection(false); break;
}
_Connection.Open(DropInfo.SocketHandle);
_Connection.ShutdownOnClose = false;
return _Connection.Connected;
}
}
/// <summary>
/// Transforms pipe sequences to ansi sequences in the input string
/// </summary>
/// <param name="AText">The string with pipe sequences</param>
/// <returns>A string with ansi sequences in place of pipe sequences</returns>
private static string PipeToAnsi(string AText)
{
if (AText.Contains("|"))
{
// Replace the colour codes
for (int i = 0; i < 255; i++)
{
string Code = "|" + i.ToString("X2");
if (AText.Contains(Code))
{
AText = AText.Replace(Code, Ansi.TextAttr(i));
if (!AText.Contains("|")) break;
}
}
}
return AText;
}
/// <summary>
/// Determines whether pipe sequences should automatically be transformed to ansi sequences
/// </summary>
public static bool PipeWrite { get; set; }
/// <summary>
/// Reads a byte from either the local or remote side with no translation
/// </summary>
/// <returns>A byte if one was available, or null if no key was waiting</returns>
public static byte? ReadByte()
{
byte? B = null;
LastKey.Location = DoorKeyLocation.None;
do
{
while (!KeyPressed())
{
Thread.Sleep(1); // TODO Should not be here
}
if (Crt.KeyPressed())
{
B = (byte)Crt.ReadKey();
LastKey.Location = DoorKeyLocation.Local;
}
else if (!Local && _Connection.CanRead())
{
B = (byte)_Connection.ReadChar(0);
LastKey.Location = DoorKeyLocation.Remote;
}
} while (LastKey.Location == DoorKeyLocation.None);
if (B != null)
{
LastKey.Ch = (char)B;
LastKey.Time = DateTime.Now;
}
return B;
}
/// <summary>
/// Reads a key from either the local or remote side
/// </summary>
/// <returns>A key if one was available, or null if no key was waiting</returns>
public static char? ReadKey()
{
char? Ch = null;
LastKey.Location = DoorKeyLocation.None;
do
{
while (!KeyPressed())
{
Thread.Sleep(1); // TODO Should not be here
}
if (Crt.KeyPressed())
{
Ch = Crt.ReadKey();
if (Ch == '\0')
{
Ch = Crt.ReadKey();
switch (Ch)
{
case 'H':
Ch = ExtendedKeys.UpArrow;
LastKey.Location = DoorKeyLocation.Local;
break;
case 'K':
Ch = ExtendedKeys.LeftArrow;
LastKey.Location = DoorKeyLocation.Local;
break;
case 'M':
Ch = ExtendedKeys.RightArrow;
LastKey.Location = DoorKeyLocation.Local;
break;
case 'P':
Ch = ExtendedKeys.DownArrow;
LastKey.Location = DoorKeyLocation.Local;
break;
default:
// Non-arrow special key, pass to door to see if they want to do something
// with it (ie maybe there's a shortcut for hang-up). Either way, this special
// key doesn't get added to the input buffer
if ((!Local) && (OnSysOpKey != null))
{
OnSysOpKey(null, new CharEventArgs((char)Ch));
}
break;
}
}
else
{
LastKey.Location = DoorKeyLocation.Local;
}
}
else if (!Local && _Connection.CanRead())
{
Ch = _Connection.ReadChar(0);
if (Ch == '\x1B')
{
// ESC, check if we have more data
if (!_Connection.CanRead())
{
// No data waiting, so wait 1/10th of a second to see if more data comes
Thread.Sleep(100);
}
// Check if we have data to follow the ESC
if (_Connection.CanRead())
{
// We have more data, see if it's a [
char SecondChar = (char)_Connection.PeekChar();
if (SecondChar == '[')
{
// Consume the [ since it's most likely part of an escape sequence (if someone actually hit ESC and [ on their own, tough luck)
_Connection.ReadChar(0);
// Now we have ESC[, see if we have more data
if (!_Connection.CanRead())
{
// No data waiting, so wait 1/10th of a second to see if more data comes
Thread.Sleep(100);
}
// Check if we have data to follow the ESC[
if (_Connection.CanRead())
{
// We have more data, see if it's a sequence we handle
// TODO Not all sequences are ESC[ followed by a single byte, ie F1
char ThirdChar = (char)_Connection.ReadChar(0);
switch (ThirdChar)
{
case 'A':
Ch = Door.ExtendedKeys.UpArrow;
LastKey.Location = DoorKeyLocation.Remote;
break;
case 'B':
Ch = Door.ExtendedKeys.DownArrow;
LastKey.Location = DoorKeyLocation.Remote;
break;
case 'C':
Ch = Door.ExtendedKeys.RightArrow;
LastKey.Location = DoorKeyLocation.Remote;
break;
case 'D':
Ch = Door.ExtendedKeys.LeftArrow;
LastKey.Location = DoorKeyLocation.Remote;
break;
}
}
}
else
{
// ESC not followed by [
LastKey.Location = DoorKeyLocation.Remote;
}
}
else
{
// ESC not followed by anything
LastKey.Location = DoorKeyLocation.Remote;
}
}
else
{
// Not an ESC
LastKey.Location = DoorKeyLocation.Remote;
}
}
} while (LastKey.Location == DoorKeyLocation.None);
if (Ch != null)
{
LastKey.Ch = (char)Ch;
LastKey.Time = DateTime.Now;
if (LocalEcho)
{
if (Ch == '\x08') // Backspace
{
Write("\x08 \x08");
}
else if (Ch == '\r') // Enter
{
Write("\r\n");
}
else if ((Ch >= 32) && (Ch <= 126))
{
Write(Ch.ToString());
}
}
}
return Ch;
}
/// <summary>
/// A shortcut for TextBox()
/// </summary>
/// <returns>The line of text input by the user</returns>
public static string ReadLn()
{
return TextBox("", CharacterMask.All, '\0', 50, 50, 7);
}
/// <summary>
/// The number of seconds the user has been idle for
/// </summary>
public static int SecondsIdle
{
get
{
return (int)DateTime.Now.Subtract(LastKey.Time).TotalSeconds;
}
}
/// <summary>
/// The number of seconds the user has left this call
/// </summary>
public static int SecondsLeft
{
get
{
return (DropInfo.MaxTime - SecondsOn);
}
}
/// <summary>
/// The number of seconds the user has been in the door
/// </summary>
public static int SecondsOn
{
get
{
return (int)DateTime.Now.Subtract(Session.TimeOn).TotalSeconds;
}
}
/// <summary>
/// Determines whether "seth" (aka LORD) sequences should be parsed
/// </summary>
public static bool SethWrite { get; set; }
/// <summary>
/// Closes the connection in a way that ensures the caller's connection doesn't get dropped
/// Very important to close this before your door quits!
/// </summary>
public static void Shutdown()
{
if (_Connection != null)
{
_Connection.Close();
_Connection = null;
}
}
/// <summary>
/// Parses the command-line and gets the doorkit ready for use
/// </summary>
public static void Startup()
{
string DropFile = "";
bool Local = false;
int Node = 0;
int Socket = -1;
foreach (string Arg in Environment.GetCommandLineArgs().Skip(1)) // Skip 1 because first is path/filename of door's EXE
{
if ((Arg.Length >= 2) && ((Arg[0] == '/') || (Arg[0] == '-')))
{
char Key = Arg.ToUpper()[1];
string Value = Arg.Substring(2);
switch (Key)
{
case 'C':
if (!int.TryParse(Value, out DropInfo.ComType)) DropInfo.ComType = 0;
break;
case 'D':
DropFile = Value;
break;
case 'H':
if (!int.TryParse(Value, out Socket)) Socket = -1;
break;
case 'L':
Local = true;
break;
case 'N':
if (!int.TryParse(Value, out Node)) Node = 0;
break;
default:
if (OnCLP != null)
{
EventHandler<CommandLineParameterEventArgs> Handler = OnCLP;
if (Handler != null) Handler(null, new CommandLineParameterEventArgs(Key, Value));
}
break;
}
}
}
if (Local)
{
DropInfo.Node = Node;
if (OnLocalLogin != null)
{
OnLocalLogin(null, EventArgs.Empty);
ClrScr();
}
}
else if ((Socket > 0) && (Node > 0))
{
if (DropInfo.ComType == 0) DropInfo.ComType = 2;
DropInfo.SocketHandle = Socket;
DropInfo.Node = Node;
}
else if (!string.IsNullOrEmpty(DropFile))
{
if (File.Exists(DropFile))
{
// 'DropFile' contains a full filename, so confirm it is a DOOR32.SYS file
if (DropFile.ToUpper().Contains("DOOR32.SYS"))
{
ReadDoor32(DropFile);
}
else
{
// TODOZ Maybe support other drop file formats for Linux, and assume local mode when they're used (ie DOOR.SYS, DORINFO.DEF)
ClrScr();
WriteLn();
WriteLn(" Drop File '" + Path.GetFileName(DropFile) + "' Not Supported");
WriteLn();
Thread.Sleep(2500);
throw new Exception("Drop File '" + Path.GetFileName(DropFile) + "' Not Supported");
}
}
else if (Directory.Exists(DropFile))
{
// 'DropFile' only contains a path, so try both door32.sys and DOOR32.SYS (for Linux, which is case sensitive)
if (!ReadDoor32(StringUtils.PathCombine(DropFile, "door32.sys")) && !ReadDoor32(StringUtils.PathCombine(DropFile, "DOOR32.SYS")))
{
ClrScr();
WriteLn();
WriteLn(" DOOR32.SYS not found in '" + DropFile + "'");
WriteLn();
Thread.Sleep(2500);
throw new Exception("DOOR32.SYS not found in '" + DropFile + "'");
}
}
else
{
ClrScr();
WriteLn();
WriteLn(" Drop File '" + DropFile + "' Not Found");
WriteLn();
Thread.Sleep(2500);
throw new Exception("Drop File '" + DropFile + "' Not Found");
}
}
else
{
OnUsage?.Invoke(null, EventArgs.Empty);
}
if (!Local)
{
if (!Open())
{
ClrScr();
WriteLn();
WriteLn(" No Carrier Detected");
WriteLn();
Thread.Sleep(2500);
throw new Exception("No Carrier Detected"); //Environment.Exit(0);
}
}
Crt.Window(1, 1, 80, 24);
ClrScr();
}
/// <summary>
/// Determines whether the LF in CR+LF pairs is stripped out
/// </summary>
public static bool StripLF
{
get
{
if (Local)
{
return true;
}
else
{
return _Connection.StripLF;
}
}
set
{
if (!Local)
{
_Connection.StripLF = value;
}
}
}
/// <summary>
/// Determines whether the NULL in CR+NULL pairs is stripped out
/// </summary>
public static bool StripNull
{
get
{
if (Local)
{
return true;
}
else
{
return _Connection.StripNull;
}
}
set
{
if (!Local)
{
_Connection.StripNull = value;
}
}
}
/// <summary>
/// Strips "seth" (AKA LORD) sequences from an input string
/// </summary>
/// <param name="text">The text containing seth sequences</param>
/// <returns>The text with seth sequences removed</returns>
public static string StripSeth(string text)
{
if (text.Contains("`"))
{
text = Regex.Replace(text, "`1", "", RegexOptions.IgnoreCase);
text = Regex.Replace(text, "`2", "", RegexOptions.IgnoreCase);
text = Regex.Replace(text, "`3", "", RegexOptions.IgnoreCase);
text = Regex.Replace(text, "`4", "", RegexOptions.IgnoreCase);
text = Regex.Replace(text, "`5", "", RegexOptions.IgnoreCase);
text = Regex.Replace(text, "`6", "", RegexOptions.IgnoreCase);
text = Regex.Replace(text, "`7", "", RegexOptions.IgnoreCase);
text = Regex.Replace(text, "`8", "", RegexOptions.IgnoreCase);
text = Regex.Replace(text, "`9", "", RegexOptions.IgnoreCase);
text = Regex.Replace(text, "`0", "", RegexOptions.IgnoreCase);
text = Regex.Replace(text, "`[!]", "", RegexOptions.IgnoreCase);
text = Regex.Replace(text, "`[@]", "", RegexOptions.IgnoreCase);
text = Regex.Replace(text, "`[#]", "", RegexOptions.IgnoreCase);
text = Regex.Replace(text, "`[$]", "", RegexOptions.IgnoreCase);
text = Regex.Replace(text, "`[%]", "", RegexOptions.IgnoreCase);
text = Regex.Replace(text, "`[*]", "", RegexOptions.IgnoreCase);
text = Regex.Replace(text, "`b", "", RegexOptions.IgnoreCase);
text = Regex.Replace(text, "`c", "", RegexOptions.IgnoreCase);
text = Regex.Replace(text, "`d", "", RegexOptions.IgnoreCase);
text = Regex.Replace(text, "`k", "", RegexOptions.IgnoreCase);
text = Regex.Replace(text, "`l", "", RegexOptions.IgnoreCase);
text = Regex.Replace(text, "`w", "", RegexOptions.IgnoreCase);
text = Regex.Replace(text, "`x", "", RegexOptions.IgnoreCase);
text = Regex.Replace(text, "`[\\\\]", "", RegexOptions.IgnoreCase);
text = Regex.Replace(text, "`[|]", "", RegexOptions.IgnoreCase);
text = Regex.Replace(text, "`[.]", "", RegexOptions.IgnoreCase);
text = Regex.Replace(text, "`r0", "", RegexOptions.IgnoreCase);
text = Regex.Replace(text, "`r1", "", RegexOptions.IgnoreCase);
text = Regex.Replace(text, "`r2", "", RegexOptions.IgnoreCase);
text = Regex.Replace(text, "`r3", "", RegexOptions.IgnoreCase);
text = Regex.Replace(text, "`r4", "", RegexOptions.IgnoreCase);
text = Regex.Replace(text, "`r5", "", RegexOptions.IgnoreCase);
text = Regex.Replace(text, "`r6", "", RegexOptions.IgnoreCase);
text = Regex.Replace(text, "`r7", "", RegexOptions.IgnoreCase);
}
return text;
}
/// <summary>
/// A very basic sysop chat feature
/// </summary>
public static void SysopChat()
{
char? Ch = null;
DoorKeyLocation OurLastKeyLocation = DoorKeyLocation.None;
do
{