home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / top2src.zip / BJ4TOP.ZIP / BJNEW.PAS < prev    next >
Pascal/Delphi Source File  |  1996-05-08  |  62KB  |  1,788 lines

  1. {$M 16384,0,0}
  2. {$V-}
  3. Program Blackjack4TOP;
  4. Uses DOS, Crt, BJSupp;
  5.  
  6. Type
  7.   IDXRec = Record
  8.              RecLen : Word;
  9.              Alias : String[30];
  10.              RealName : String[40];
  11.              Baud : Word;
  12.              Location : String[30];
  13.              Gender : Word;
  14.              Quiet : Byte;
  15.              Task : Word;
  16.              LastTime : LongInt;
  17.              Channel : LongInt;
  18.              Listed : Byte;
  19.              Security : Word;
  20.              Actions : Byte;
  21. {             Buf : Array [1..346] of byte;}
  22.            end;
  23.  
  24.   Str30 = String[30];
  25.   Str255 = String[255];
  26.  
  27.   NodeRec = Record
  28.              RecLen : Word;
  29.              Kind : Integer;
  30.              From : Integer;
  31.              DoneTo : Integer;
  32.              Gender : Integer;
  33.              Alias : Str30;
  34.              Data : Str255;
  35.              Channel : LongInt;
  36.              MinSec : Word;
  37.              MaxSec : Word;
  38.              Data1 : LongInt;
  39.            end;
  40.  
  41.   ConfigRec = Record
  42.                 StartCD : Word;
  43.                 BetCD : Byte;
  44.                 MaxBet : Byte;
  45.                 MinBet : Byte;
  46.                 TimeBetweenGames : Byte;
  47.                 FirstWarn : Byte;
  48.                 SecondWarn : Byte;
  49.                 BootFromBJ : Byte;
  50.               end;
  51.  
  52. Type
  53.   RegisterRec = record
  54.                   TheReg : string;
  55.                   TheName : string;
  56.                 end;
  57. Const
  58.   RegisterData : RegisterRec
  59.                = ( TheReg : '00000000000';
  60.                    TheName : '[UNREGISTERED]');
  61.  
  62.   ProgVerStr = ' v0.92';
  63.  
  64.   fmReadOnly  = $00;
  65.   fmWriteOnly = $01;
  66.   fmReadWrite = $02;
  67.  
  68.   fmDenyAll   = $10;
  69.   fmDenyWrite = $20;
  70.   fmDenyRead  = $30;
  71.   fmDenyNone  = $40;
  72.  
  73.   ConfigData : ConfigRec
  74.                = ( StartCD : 1000;
  75.                    BetCD : 10;
  76.                    MaxBet : 100;
  77.                    MinBet : 10;
  78.                    TimeBetweenGames : 19;
  79.                    FirstWarn : 60;
  80.                    SecondWarn : 90;
  81.                    BootFromBJ : 125
  82.                   );
  83.  
  84.   HelpData : Array[1..14] of String = (
  85.   #13#10'^A^oEnter ^A^n/BJ BET ^A^m<amount> ^A^oto change your bet (cannot be done during a game).',
  86.   '^A^oEnter ^A^n/BJ CD ^A^oor ^A^n/BJ $ ^A^ofor your current number of Cyberdollars.',
  87.   '^A^oEnter ^A^n/BJ DOUBLE x ^A^oto double down hand x.',
  88.   '^A^oEnter ^A^n/BJ HAND ^A^oto view the dealer''s and your own cards.',
  89.   '^A^oEnter ^A^n/BJ HELP ^A^ofor this commands list.',
  90.   '^A^oEnter ^A^n/BJ HIT x ^A^oto ask for a new card for hand x.',
  91.   '^A^oEnter ^A^n/BJ INSURE ^A^oto make an insurance bet against a blackjack.',
  92.   '^A^oEnter ^A^n/BJ OFF ^A^oto be dealt out of blackjack.',
  93.   '^A^oEnter ^A^n/BJ ON ^A^oto join in the next game of blackjack.',
  94.   '^A^oEnter ^A^n/BJ SCAN ^A^oto see who''s playing blackjack.',
  95.   '^A^oEnter ^A^n/BJ SPLIT x ^A^oto split hand x.',
  96.   '^A^oEnter ^A^n/BJ STAY ^A^oto end your turn.',
  97.   '^A^oEnter ^A^n/BJ TURN ^A^oto see who''s turn it is.'#13#10,
  98.   '^A^mIf ^lx^m is left off commands that need it, hand #^l1^m is assumed.'#13#10);
  99.  
  100.   ComList : Array[1..16] of String = ('BJ BET', 'BJ $',
  101.   'BJ CD', 'BJ DOUBLE', 'BJ DOUBLE2', 'BJ HAND', 'BJ HELP', 'BJ HIT',
  102.   'BJ HIT 2', 'BJ INSURE', 'BJ OFF', 'BJ ON', 'BJ SCAN', 'BJ SPLIT',
  103.   'BJ STAY', 'BJ TURN');
  104.  
  105.  
  106. Var
  107.   IPCDir : String;
  108.   Node : Byte;
  109.   NodeStr : String;
  110.   NodeData : NodeRec;
  111.   NodeData2 : NodeRec;
  112.   GamePlaying : Boolean;
  113.   L : Word;
  114.   Sec : Word;
  115.   OldSec : Word;
  116.   SecPassed : Word;
  117.   NodeTurn : Integer;
  118.   NodeStat : Array [1..255] of Byte; { 0 = Not in game }
  119.                                      { 1 = Waiting }
  120.                                      { 2 = In game }
  121.   NodeCD : Array [1..255] of LongInt;
  122.   NodeInsure : Array [1..255] of Boolean;
  123.   NodeHand : Array [1..6, 1..255] of String[24];
  124.   NodeDoneH : Array [1..6, 1..255] of Boolean;
  125.   NodeBet : Array [1..255] of byte;
  126.   NodeDD : Array [1..6, 1..255] of byte;
  127.   NodeNumHands : Array [1..255] of byte;
  128.   UsedCards : String;
  129.   DealerHand : String[40];
  130.  
  131. Procedure InitScr;
  132. Var
  133.   Loop : Word;
  134. begin
  135.   TextAttr := $71;
  136.   ClrScr;
  137.   GotoXY (1,2);
  138.   For loop := 1 to 1920 do Write ('░');
  139.   Textbackground (blue);
  140.   GotoXY (1,1);
  141.   Textbackground (7);
  142.   Textcolor (red);
  143.   Write (' Blackjack for TOP'+ProgVerStr);
  144.   Textcolor (0);
  145.   Write (' Configuration (c) 1994 by David Ong, OmniWare(tm)');
  146.   ClrEol;
  147.   GotoXY (1,25);
  148.   Textcolor (Red);
  149.   Write (' Help: ');
  150.   Textcolor (0);
  151.   Write ('Use cursor keys to select a choice.');
  152.   ClrEol;
  153.   WindowBorder (4,3,60,13,White,7);
  154.   TextAttr := $7F;
  155.   GotoXY (27,3);
  156.   Write ('┤ Config ├');
  157.   GotoXY (6,4);
  158.   Textcolor (0);
  159.   Writeln ('Starting Cyberdollars:');
  160.   GotoXY (6,5);
  161.   Writeln ('Minimum bet:');
  162.   GotoXY (6,6);
  163.   Writeln ('Maximum bet: ');
  164.   GotoXY (6,7);
  165.   Writeln ('Time between games:');
  166.   GotoXY (6,8);
  167. {  For Loop := 1 to 9 do WriteField (Loop);}
  168. end;
  169.  
  170. Procedure ConfigureBJ;
  171. begin
  172.   InitScr;
  173.   Halt;
  174. end;
  175.  
  176. Procedure SaveReg;
  177. Var
  178.   ExeFile    : file;
  179.   HeaderSize : word;
  180.   FileName : String;
  181.  
  182. begin
  183.   FileName := ParamStr (0);
  184.   Writeln ('Writing registration codes to ', FileName);
  185.   Assign (ExeFile, FileName);
  186.   Reset (ExeFile, 1);
  187.   Seek      (ExeFile, 8);
  188.   Blockread (ExeFile, HeaderSize, Sizeof (HeaderSize));
  189.   Seek      (ExeFile, Longint(16) * (seg(RegisterData)
  190.             - PrefixSeg + HeaderSize) + ofs (RegisterData) - 256);
  191.   Blockwrite (ExeFile, RegisterData, sizeof (RegisterData));
  192.   Close      (ExeFile);
  193. end;
  194.  
  195. Procedure Enter_Reg;
  196. begin
  197.   Writeln;
  198.   Writeln ('BJ4TOP Registration--Your registration code and named will be saved to');
  199.   Writeln ('  the ', ParamStr(0), ' file.');
  200.   Writeln;
  201.   Write ('Your Name (Please note it is case sensitive): ');
  202.   Readln (RegisterData.TheName);
  203.   Write ('Registration Number:');
  204.   Readln (RegisterData.TheReg);
  205.   Writeln;
  206. {  UserName := RegisterData.TheName;}
  207. {  RegisterNum := RegisterData.TheReg;}
  208. {  Check_Register;}
  209. {  If Registered then Writeln ('The registration number checks out, thank you
  210. for registering')}
  211. {  else}
  212.   begin
  213.     Writeln ('The registration number doesn''t check out, make sure you''ve entered');
  214.     Writeln ('everything correctly!'+#7);
  215.     Writeln;
  216.     Writeln ('Name and registration number not saved.');
  217.     Halt (1);
  218.   end;
  219.   Writeln;
  220.   If Not FExists (ParamStr (0)) then Writeln ('Error: The file '+ParamStr(0)+' could not be written to.'+#7)
  221.   else SaveReg;
  222. end;
  223.  
  224. Procedure InitProgram;
  225. begin
  226.   Randomize;
  227.   Writeln;
  228.   Writeln ('Blackjack for TOP'+ProgVerStr);
  229.   Writeln ('Original BJ4RAP program Copyright 1995 David Ong, OmniWare(tm)');
  230.   Writeln ('TOP modifications Copyright 1996 Paul Sidorsky, ISMWare, All Rights Reserved.');
  231.   Writeln;
  232.   If ParamCount < 1 then
  233.   begin
  234.     Writeln ('Command line parameter(s) missing!');
  235.     Writeln;
  236.     Writeln ('Usage: BJ4TOP <work path> [<node>]');
  237.     Writeln;
  238.     Writeln ('<work path>  Is the path to TOP''s work directory.');
  239.     Writeln ('<node>       Is optional and if given will force BJ4TOP to use the node even');
  240.     Writeln ('             if it is already taken.');
  241.     Writeln;
  242.     Writeln ('Eg: BJ4TOP d:\top\workdir');
  243.     Writeln ('For further help refer to BJ4TOP.DOC');
  244.     Halt;
  245.   end;
  246. {  RegisterKey := '#####';}
  247. {  UserName := RegisterData.TheName;}
  248. {  RegisterNum := RegisterData.TheReg;}
  249. {  Check_Register;}
  250.   If UpStr(ParamStr (1)) = '/REGISTER' then
  251.   begin
  252.     Enter_Reg;
  253.     Halt;
  254.   end;
  255. { If UpStr(ParamStr(1)) = '/CONFIG' then ConfigureBJ;}
  256.   IPCDir := ParamStr(1);
  257.   If IPCDir[Length(IPCDir)] <> '\' then IPCDir := IPCDir + '\';
  258.   FileMode:=fmReadWrite+FmDenyNone;
  259.   If not FExists (IPCDir + 'NODEIDX.TCH') then
  260.   begin
  261.     Writeln ('Error: The NODEIDX.TCH file was not found in the ', UpStr(IPCDir), ' directory!');
  262.     Writeln ('Make sure TOP uses the same work path and has been previously run or is'#13#10'currently running.');
  263.     Halt;
  264.   end;
  265.   If not FExists (IPCDir + 'NODEIDX2.TCH') then
  266.   begin
  267.     Writeln ('Error: The NODEIDX2.TCH file was not found in the ', UpStr(IPCDir), ' directory!');
  268.     Writeln ('Make sure TOP uses the same work path and has been previously run or is'#13#10'currently running.');
  269.     Halt;
  270.   end;
  271. end;
  272.  
  273. Function UnUsedNode : byte;
  274. Var
  275.   f : file of byte;
  276.   L : byte;
  277.   B : byte;
  278.   Error : Integer;
  279. begin
  280.   If Paramcount < 2 then
  281.   begin
  282.     L := 0;
  283.     Assign (F, IPCDir + 'NODEIDX2.TCH');
  284.     Reset (f);
  285.     Repeat
  286.       Inc (l);
  287.       {$I-}
  288.       Repeat
  289.         Read (f,b);
  290.       Until IOResult = 0;
  291.       {$I+}
  292.     Until b = 0;
  293.     Close (f);
  294.   end
  295.   else
  296.   begin
  297.     Val (ParamStr(2), L, Error);
  298.     If (Error <> 0) or (L = 0) then
  299.     begin
  300.       Writeln ('Invalid forced node passed!');
  301.       Writeln ('Node must be from 1 to 255');
  302.       Halt;
  303.     end;
  304.   end;
  305.   UnUsedNode := L;
  306. end;
  307.  
  308. Procedure TakeNode;
  309. Var
  310.   L : byte;
  311.   B : byte;
  312.   f : File of byte;
  313.   IDXFile : File of IDXRec;
  314.   IDXData : IDXRec;
  315. begin
  316.   L := 0;
  317.   Assign (f, IPCDir + 'MSG'+NodeStr+'.TCH');
  318.   Rewrite (f);
  319.   Close (f);
  320.   Assign (f, IPCDir + 'MIX'+NodeStr+'.TCH');
  321.   Rewrite (f);
  322.   Close (f);
  323.   Assign (F, IPCDir + 'NODEIDX2.TCH');
  324.   Reset (f);
  325.   Seek (f, Node);
  326.   b := 1;
  327.   {$I-}
  328.   Repeat
  329.     Write (f,b);
  330.   Until IOResult = 0;
  331.   {$I+}
  332.   Close (f);
  333.   Assign (IDXFile, IPCDir + 'NODEIDX.TCH');
  334.   Reset (IDXFile);
  335.   Seek (IDXFile, Node);
  336.   FillChar (IDXData, SizeOf(IDXData), #0);
  337.   IDXData.Alias := 'A^pBJ'#8'lackjack Dealer'#0;
  338.   IDXData.Alias[0] := '^';
  339.   IDXData.RealName := 'J'#0;
  340.   IDXData.RealName[0] := 'B';
  341.   IDXData.Baud := 0;
  342. {  If registered then}
  343. {  begin
  344.     IDXData.Location := 'egistered'+#0;
  345.     IDXData.Location[0] := 'R';
  346.   end}
  347.   {else}
  348.   begin
  349.     IDXData.Location := 'NREGISTERED'+#0;
  350.     IDXData.Location[0] := 'U';
  351.   end;
  352.   IDXData.Gender := 0;
  353.   IDXData.LastTime := 0;
  354.   IDXData.Channel := 1;
  355.   IDXData.Listed := 1;
  356.   IDXData.Security := 65535;
  357.   {$I-}
  358.   Repeat
  359.     Write (IDXFile, IDXData);
  360.   Until IOResult = 0;
  361.   {$I+}
  362.   Close (IDXFile);
  363. end;
  364.  
  365. Procedure SendMSG (N : byte; NodeData : NodeRec);
  366. Var
  367.   b : byte;
  368.   f : File of byte;
  369.   NodeFile : File of NodeRec;
  370. begin
  371.   Assign (f, IPCDir + 'MIX' + PaddedNum(N)+'.TCH');
  372.   Reset (f);
  373.   b := 0;
  374.   If not Eof (f) then
  375.   Repeat
  376.     {$I-}
  377.     Repeat
  378.       Read (f,b);
  379.     Until IOResult = 0;
  380.     {$I+}
  381.     If Eof (f) then
  382.     begin
  383.       b := 0;
  384.       Write (f,b);
  385.     end;
  386.   Until B = 0
  387.   else Write (f,b);
  388.   b := 1;
  389.   Seek (f, FilePos(f) - 1);
  390.   {$I-}
  391.   Repeat
  392.     Write (f,b);
  393.   Until IOResult = 0;
  394.   {$I+}
  395.   Assign (NodeFile, IPCDir + 'MSG' + PaddedNum(N)+'.TCH');
  396.   Reset (NodeFile);
  397.   Seek (NodeFile, FilePos(f) - 1);
  398.   {$I-}
  399.   Repeat
  400.     Write (NodeFile, NodeData);
  401.   Until IOResult = 0;
  402.   {$I+}
  403.   Close (NodeFile);
  404.   Close (f);
  405.   Assign (F, IPCDir + 'CHGIDX.TCH');
  406.   Reset (f);
  407.   Seek (f, N);
  408.   b := 1;
  409.   {$I-}
  410.   Repeat
  411.     Write (f,b);
  412.   Until IOResult = 0;
  413.   {$I+}
  414.   Close (f);
  415. end;
  416.  
  417. Procedure BroadCast (T : Byte; Alias : Str30; Data : Str255);
  418. Var
  419.   IDX2 : File of byte;
  420.   b : byte;
  421.   L : Word;
  422.   NodeData : NodeRec;
  423. begin
  424.   FillChar (NodeData, SizeOf(NodeData), #0);
  425.   NodeData.Doneto := -1;
  426.   Alias := Alias + #0;
  427.   Data := Data + #0;
  428.   NodeData.Kind := T;
  429.   NodeData.From := Node;
  430.   NodeData.Alias := Minus1 (Alias);
  431.   NodeData.Alias[0] := Alias[1];
  432.   NodeData.Data := Minus1 (Data);
  433.   NodeData.Data[0] := Data[1];
  434.   NodeData.Channel := 1;
  435.   NodeData.MinSec := 0;
  436.   NodeData.Data1 := 0;
  437.   Assign (IDX2, IPCDir + 'NODEIDX2.TCH');
  438.   {$I-}
  439.   Repeat
  440.     Reset (IDX2);
  441.   Until IOResult = 0;
  442.   {$I+}
  443.   For L := 0 to (FileSize(IDX2) - 1) do
  444.   begin
  445.     {$I-}
  446.     Repeat
  447.       Read (IDX2, b);
  448.     Until IOResult = 0;
  449.     {$I+}
  450.     If (L <> Node) and (b=1) and (NodeStat[L] <> 0) then SendMSG (L, NodeData);
  451.   end;
  452.   Close (IDX2);
  453. end;
  454.  
  455. Procedure BroadCastAll (T : Byte; Alias : Str30; Data : Str255);
  456. Var
  457.   IDX2 : File of byte;
  458.   b : byte;
  459.   L : Word;
  460.   NodeData : NodeRec;
  461. begin
  462.   FillChar (NodeData, SizeOf(NodeData), #0);
  463.   NodeData.Doneto := -1;
  464.   Alias := Alias + #0;
  465.   Data := Data + #0;
  466.   NodeData.Kind := T;
  467.   NodeData.From := Node;
  468.   NodeData.Alias := Minus1 (Alias);
  469.   NodeData.Alias[0] := Alias[1];
  470.   NodeData.Data := Minus1 (Data);
  471.   NodeData.Data[0] := Data[1];
  472.   NodeData.Channel := 1;
  473.   NodeData.MinSec := 0;
  474.   NodeData.Data1 := 0;
  475.   Assign (IDX2, IPCDir + 'NODEIDX2.TCH');
  476.   {$I-}
  477.   Repeat
  478.     Reset (IDX2);
  479.   Until IOResult = 0;
  480.   {$I+}
  481.   For L := 0 to (FileSize(IDX2) - 1) do
  482.   begin
  483.     {$I-}
  484.     Repeat
  485.       Read (IDX2, b);
  486.     Until IOResult = 0;
  487.     {$I+}
  488.     If (L <> Node) and (b=1) then SendMSG (L, NodeData);
  489.   end;
  490.   Close (IDX2);
  491. end;
  492.  
  493. Procedure BroadCastAllBut (T : Byte; Alias : Str30; Data : Str255; NoSend : Byte);
  494. Var
  495.   IDX2 : File of byte;
  496.   b : byte;
  497.   L : Word;
  498.   NodeData : NodeRec;
  499. begin
  500.   FillChar (NodeData, SizeOf(NodeData), #0);
  501.   NodeData.Doneto := -1;
  502.   Alias := Alias + #0;
  503.   Data := Data + #0;
  504.   NodeData.Kind := T;
  505.   NodeData.From := node;
  506.   NodeData.Alias := Minus1 (Alias);
  507.   NodeData.Alias[0] := Alias[1];
  508.   NodeData.Data := Minus1 (Data);
  509.   NodeData.Data[0] := Data[1];
  510.   NodeData.Channel := 1;
  511.   NodeData.MinSec := 0;
  512.   NodeData.Data1 := 0;
  513.   Assign (IDX2, IPCDir + 'NODEIDX2.TCH');
  514.   {$I-}
  515.   Repeat
  516.     Reset (IDX2);
  517.   Until IOResult = 0;
  518.   {$I+}
  519.   For L := 0 to (FileSize(IDX2) - 1) do
  520.   begin
  521.     {$I-}
  522.     Repeat
  523.       Read (IDX2, b);
  524.     Until IOResult = 0;
  525.     {$I+}
  526.     If (L <> Node) and (b=1) and (NoSend <> L) then SendMSG (L, NodeData);
  527.   end;
  528.   Close (IDX2);
  529. end;
  530.  
  531. Procedure GiveMSG (T : Byte; Alias : Str30; Data : Str255; Node : Byte);
  532. Var
  533.   IDX2 : File of byte;
  534.   b : byte;
  535.   L : Word;
  536.   NodeData : NodeRec;
  537. begin
  538.   FillChar (NodeData, SizeOf(NodeData), #0);
  539.   NodeData.Doneto := -1;
  540.   Alias := Alias + #0;
  541.   Data := Data + #0;
  542.   NodeData.Kind := T;
  543.   NodeData.From := node;
  544.   NodeData.Alias := Minus1 (Alias);
  545.   NodeData.Alias[0] := Alias[1];
  546.   NodeData.Data := Minus1 (Data);
  547.   NodeData.Data[0] := Data[1];
  548.   NodeData.Channel := 1;
  549.   NodeData.MinSec := 0;
  550.   NodeData.Data1 := 0;
  551.   SendMSG (Node, NodeData);
  552. end;
  553.  
  554. Procedure BroadCastBut (T : Byte; Alias : Str30; Data : Str255; NoSend : Byte);
  555. Var
  556.   IDX2 : File of byte;
  557.   b : byte;
  558.   L : Word;
  559.   NodeData : NodeRec;
  560. begin
  561.   FillChar (NodeData, SizeOf(NodeData), #0);
  562.   NodeData.Doneto := -1;
  563.   Alias := Alias + #0;
  564.   Data := Data + #0;
  565.   NodeData.Kind := T;
  566.   NodeData.From := node;
  567.   NodeData.Alias := Minus1 (Alias);
  568.   NodeData.Alias[0] := Alias[1];
  569.   NodeData.Data := Minus1 (Data);
  570.   NodeData.Data[0] := Data[1];
  571.   NodeData.Channel := 1;
  572.   NodeData.MinSec := 0;
  573.   NodeData.Data1 := 0;
  574.   Assign (IDX2, IPCDir + 'NODEIDX2.TCH');
  575.   {$I-}
  576.   Repeat
  577.     Reset (IDX2);
  578.   Until IOResult = 0;
  579.   {$I+}
  580.   For L := 0 to (FileSize(IDX2) - 1) do
  581.   begin
  582.     {$I-}
  583.     Repeat
  584.       Read (IDX2, b);
  585.     Until IOResult = 0;
  586.     {$I+}
  587.     If (L <> Node) and (b=1) and (L <> NoSend) and (NodeStat[L] <> 0) then SendMSG (L, NodeData);
  588.   end;
  589.   Close (IDX2);
  590. end;
  591.  
  592. Function NodeUser (I : Integer) : String;
  593. Var
  594.   IDXFile : File of IDXRec;
  595.   IDXData : IDXRec;
  596. begin
  597.   If I > 0 then
  598.   begin
  599.     Assign (IDXFile, IPCDir + 'NODEIDX.TCH');
  600.     Reset (IDXFile);
  601.     Seek (IDXFile, I);
  602.     {$I-}
  603.     Repeat
  604.       Read (IDXFile, IDXData);
  605.     Until IOResult = 0;
  606.     {$I+}
  607.     NodeUser := CStr (IDXData.Alias);
  608.     Close (IDXFile);
  609.   end
  610.   else NodeUser := 'everyone';
  611. end;
  612.  
  613. Function NodeGender (I : Word) : Boolean;
  614. Var
  615.   IDXFile : File of IDXRec;
  616.   IDXData : IDXRec;
  617. begin
  618.   If I > 0 then
  619.   begin
  620.     Assign (IDXFile, IPCDir + 'NODEIDX.TCH');
  621.     Reset (IDXFile);
  622.     Seek (IDXFile, I);
  623.     {$I-}
  624.     Repeat
  625.       Read (IDXFile, IDXData);
  626.     Until IOResult = 0;
  627.     {$I+}
  628.     Close (IDXFile);
  629.     NodeGender := IDXData.Gender = 1;
  630.   end
  631.   else NodeGender := False;
  632. end;
  633.  
  634. Procedure InitTOP;
  635. begin
  636.   Node := UnusedNode;
  637.   Writeln ('Logging onto TOP as node ', Node);
  638.   Str (Node, NodeStr);
  639.   NodeStr := PaddedNum (Node);
  640.   TakeNode;
  641.   BroadCastAll (2, '^A^pBJ'#8'lackjack Dealer', '');
  642.   BroadCastAll (9, '', '^I^i*** Blackjack'+ProgVerStr+' Game Module Active ***');
  643.   BroadCastAll (9, '', '^A^nThis program is registered to: ^A^p'+Registerdata.TheName);
  644. {  If not Registered then}
  645.     BroadCastAll (9, '', '^I^oBe sure to register soon!');
  646.   BroadCastAll (9, '', '^A^nType ^A^p/BJ HELP ^A^nfor the commands.');
  647. end;
  648.  
  649. Procedure DeInit;
  650. Var
  651.   B : byte;
  652.   f : File of byte;
  653. begin
  654.   BroadCastAll (3, '^A^mThe ^A^pBlackjack Dealer','');
  655.   BroadCastAll (9, '', '^I^i*** Blackjack'+ProgVerStr+' Game Module Deactivated ***');
  656.   Assign (F, IPCDir + 'NODEIDX2.TCH');
  657.   Reset (f);
  658.   Seek (f, node);
  659.   b := 0;
  660.   {$I-}
  661.   Repeat
  662.     Write (f,b);
  663.   Until IOResult = 0;
  664.   {$I+}
  665.   Close (f);
  666.   TextAttr := $07;
  667.   Window (1,1,80,25);
  668.   ClrScr;
  669. end;
  670.  
  671. Procedure InitScreen;
  672. begin
  673.   Delay (1000);
  674.   ClrScr;
  675.   TextAttr := $71;  { Grey on blue }
  676.   { Put background in, skipping the bottom line to create a status bar }
  677.   For L := 1 to 1920 do Write ('░');
  678.   TextAttr := $74;
  679.   GotoXY (1,1);   ClrEol;
  680.   GotoXY (8,1);  Writeln ('Blackjack for TOP'+ProgVerStr+' Copyright 1996 Paul Sidorsky All Rights Reserved.');
  681.   WindowBorder (5,3,74,21, White, Blue);
  682.   GotoXY (1,25);
  683.   TextAttr := $70;
  684.   Write (' Press <ESC> to deactivate blackjack');
  685.   ClrEol;
  686. {  If not registered then}
  687.   begin
  688.     GotoXY (67,25);
  689.     Textcolor (Red+Blink);
  690.     Textbackground (LightGray);
  691.     Write ('Unregistered');
  692.   end;
  693. {  else
  694.   begin
  695.     GotoXY (67,25);
  696.     Textcolor (Red);
  697.     Textbackground (LightGray);
  698.     Write ('Registered');
  699.   end;}
  700.   Window (6,4,73,20);
  701.   Textbackground (Blue);
  702.   Textcolor (Yellow);
  703.   Writeln ('Waiting for people to join blackjack.');
  704. end;
  705.  
  706. Procedure InitVars;
  707. Var
  708.   D : integer;
  709. begin
  710.   For L := 1 to 255 do
  711.   begin
  712.     NodeStat[L] := 0;
  713.     NodeCD[L] := ConfigData.StartCD;
  714.     NodeBet[L] := ConfigData.BetCD;
  715.     NodeInsure[L] := False;
  716.     For D := 1 to 6 do
  717.     begin
  718.       NodeHand[D, L] := '';
  719.       NodeDD[D, L] := 1;
  720.       NodeDoneH[D, L] := False;
  721.     end;
  722.     NodeNumHands[L] := 0;
  723.   end;
  724.   UsedCards := '';
  725. end;
  726.  
  727. Function MSGWait : boolean;
  728. Var
  729.   b : byte;
  730.   f : File of byte;
  731. begin
  732.   Assign (f, IPCDir + 'CHGIDX.TCH');
  733.   Reset (f);
  734.   Seek (f, node);
  735.   {$I-}
  736.   Repeat
  737.     Read (f,b);
  738.   Until IOResult = 0;
  739.   {$I+}
  740.   MSGWait := b = 1;
  741.   Close (f);
  742. end;
  743.  
  744. Function DoneAllHands(P : Word) : Boolean;
  745. Var
  746.   H : Word;
  747.   C : Word;
  748. begin
  749.   C := 0;
  750.   For H := 1 to NodeNumHands[P] do
  751.     If NodeDoneH[H, P] then Inc(C);
  752.   If C = NodeNumHands[P] then DoneAllHands := True else DoneAllHands := False;
  753. end;
  754.  
  755. Function OkayToSplit(N : Word; P : Word) : Boolean;
  756. Var
  757.   H : Word;
  758.   C : Word;
  759. begin
  760.   OkayToSplit := False;
  761.   C := 0;
  762.   If NodeNumHands[P] < 6 then
  763.   begin
  764.     For H := 1 to NodeNumHands[P] do
  765.       If Length(NodeHand[H, P]) = 4 then
  766.         Inc(C);
  767.     If C = NodeNumHands[P] then OkayToSplit := True;
  768.   end;
  769. end;
  770.  
  771. Function GetCard : String;
  772. Const
  773.   Cards : Array [1..13] of Char = 'A23456789TJQK';
  774.   Kinds : Array [1..4] of Char = 'HDSC';
  775. Var
  776.   Value, Kind : Byte;
  777.   Card : String[6];
  778. begin
  779.   Repeat
  780.     Value := Random (13)+1;
  781.     Kind := Random (4)+1;
  782.     Card := Cards[Value] + Kinds [Kind];
  783.   Until Pos (Card, UsedCards) = 0;
  784.   UsedCards := UsedCards + Card;
  785.   If Length (UsedCards) = 104 then UsedCards := '';
  786.   GetCard := Card;
  787. end;
  788.  
  789. Function HandValue (Hand : String) : Byte;
  790. Var
  791.   Value : Byte;
  792.   Aces : Byte;
  793. begin
  794.   Value := 0;
  795.   { Count aces }
  796.   Aces := 0;
  797.   For L := 1 to Length (Hand) do if Hand[L] = 'A' then Inc (Aces);
  798.   While Hand[0] > #1 do
  799.   begin
  800.     If Hand[1] = 'A' then Value := Value + 11;
  801.     If Hand[1] in ['T','J','Q','K'] then Value := Value + 10;
  802.     If Hand[1] in ['2'..'9'] then Value := Value + Ord(Hand[1])-48;
  803.     Delete (Hand, 1, 2);
  804.   end;
  805.   While (Value > 21) and (Aces <> 0) do
  806.   begin
  807.     Dec (Value,10);
  808.     Dec (Aces);
  809.   end;
  810.   HandValue := Value;
  811. end;
  812.  
  813. Function ColorHand (Hand : String) : String;
  814. Var
  815.   New : String;
  816. begin
  817.   New := '';
  818.   While Hand[0] > #1 do
  819.   begin
  820.     If Hand[2] in ['D','H'] then New := New + '^H^e'+Hand[1]+Hand[2]+'^A^k '
  821.     else
  822.     If Hand[2] in ['C','S'] then New := New + '^H^a'+Hand[1]+Hand[2]+'^A^k '
  823.     else New := New + '^H^a  ^A^k';
  824.     Delete (Hand, 1, 2);
  825.   end;
  826.   ColorHand := New;
  827. end;
  828.  
  829. Procedure NextPlayer;
  830. Var
  831.   I : Word;
  832.   X : Byte;
  833. begin
  834.   If NodeStat[NodeTurn] <> 0 then
  835.   begin
  836.     X := 0;
  837.     For I := 1 to NodeNumHands[NodeTurn] Do
  838.     begin
  839.       If NodeHand[I, NodeTurn] <> '' then
  840.         If HandValue (NodeHand[I, NodeTurn]) > 21 then Inc(X);
  841.     end;
  842.     if X >= NodeNumHands[NodeTurn] then NodeStat[NodeTurn] := 1;
  843.   end;
  844.   If NodeStat[NodeTurn] = 1 then
  845.   begin
  846.     If NodeInsure[NodeTurn] then
  847.     begin
  848.       Dec (NodeCD[NodeTurn], Round (NodeBet[NodeTurn]/2));
  849.       GiveMSG (9, '', '^A^pYou^I^n lose ^A^nyour insurance bet of ^A^p'+ToStr(Round(NodeBet[NodeTurn]/2))
  850.                +' ^A^nCyberdollars!', NodeTurn);
  851.       If NodeGender (NodeTurn) then
  852.         BroadCastBut (9, '', '^A^p'+NodeUser(NodeTurn)+'^I^n loses ^A^nher insurance bet of ^A^p'
  853.                       +ToStr(Round(NodeBet[NodeTurn]/2))+' ^A^nCyberdollars!', NodeTurn)
  854.       else
  855.         BroadCastBut (9, '', '^A^p'+NodeUser(NodeTurn)+'^I^n loses ^A^nhis insurance bet of ^A^p'
  856.                       +ToStr(Round(NodeBet[NodeTurn]/2))+' ^A^nCyberdollars!', NodeTurn)
  857.     end;
  858.   end;
  859.   I := NodeTurn;
  860.   Repeat
  861.     Inc (I);
  862.   Until (I = 256) or (NodeStat[I] = 2);
  863.   If I = 256 then NodeTurn := -1       { Dealer's turn }
  864.     else NodeTurn := I;
  865.   If NodeTurn > 1 then
  866.   begin
  867.     NodeData2.DoneTo := -1;
  868.     NodeData2.From := node;
  869.     NodeData2.Gender := 0;
  870.     NodeData2.Alias := '';
  871.     NodeData2.Kind := 9;
  872.     NodeData2.Data := 'A^mIt is your turn in ^A^pblackjack^A^m!'#0;
  873.     NodeData2.Data[0] := '^';
  874.     NodeData2.Channel := 1;
  875.     NodeData2.MinSec := 0;
  876.     NodeData2.Data1 := 0;
  877.     SendMSG (NodeTurn, NodeData2);
  878.   end;
  879.   SecPassed := 0;
  880.   If NodeTurn > 1 then Writeln ('It is ', NodeUser(NodeTurn), '''s turn in blackjack.')
  881.   else Writeln ('It is the Dealer''s turn in blackjack.');
  882. end;
  883.  
  884. Procedure DisplayHand (Node : Word);
  885. var
  886.   X : Word;
  887. begin
  888.   GiveMSG (9, '', '^A^nDealer''s cards: '+ColorHand(DealerHand[1]+DealerHand[2])+'^H^a  ^A^n  (^A^p'
  889.            +ToStr(HandValue(DealerHand[1]+DealerHand[2]))+'^A^n)', Node);
  890.   If NodeNumHands[Node] > 1 then
  891.   begin
  892.     For X := 1 to NodeNumHands[Node] do
  893.       If not NodeDoneH[X, Node] then
  894.       GiveMSG (9, '', '^A^nHand #'+ToStr(X)+':      '+ColorHand(NodeHand[X, Node])+' ^A^n(^A^p'
  895.                +ToStr(HandValue(NodeHand[X, Node]))+'^A^n)', Node);
  896.   end
  897.   else
  898.     GiveMSG (9, '', '^A^nYour cards:     '+ColorHand(NodeHand[1, Node])+' ^A^n(^A^p'
  899.              +ToStr(HandValue(NodeHand[1, Node]))+'^A^n)', Node);
  900. end;
  901.  
  902. Procedure RegRemind;
  903. Var
  904.   N : Byte;
  905. begin
  906.   N := Random (4);
  907.   Case N of
  908.     0 : Broadcast (9,'','From ^A^lBlackjack Dealer^A^o, holding up a big placard: ^A^kRemember to register Blackjack!');
  909.     1 : BroadCast (9,'','^I^pThis version of Blackjack for TOP is UNREGISTERED!^A^o');
  910.     2 : BroadCast (9,'','From ^A^lBlackjack Dealer^A^o, in a hypnotic tone: ^A^kRegister blackjack, Register blackjack...');
  911.     3 : BroadCast (9,'','From ^A^lBlackjack Dealer^A^o, over the bar''s PA system: ^A^kBlackjack is UNREGISTERED!');
  912.   end;
  913. end;
  914.  
  915. Procedure Retal (Node : Word);
  916. Var
  917.   N : Byte;
  918.   J : Byte;
  919.   T : LongInt;
  920. begin
  921.   N := Random (30);
  922.   If N > 9 then
  923.   begin
  924.     J := Random (9);
  925.     Case J of
  926.     0 : begin
  927.           GiveMSG (9, '', '^oThe ^A^lBlackjack Dealer ^A^ois booting ^A^lyou ^A^oto the head!',
  928.                       Node);
  929.           BroadCastAllBut (9, '', '^oThe ^A^lBlackjack Dealer ^A^ois booting ^A^l'+NodeUser(Node)+' ^A^oto the head!', Node);
  930.         end;
  931.     1 : begin
  932.           GiveMSG (9, '', '^oThe ^A^lBlackjack Dealer ^A^ois frowning darkly at ^A^lyou^A^o!',
  933.                       Node);
  934.           BroadCastAllBut (9, '', '^oThe ^A^lBlackjack Dealer ^A^ois frowning darkly at ^A^l'+NodeUser(Node)+'^A^o!', Node);
  935.         end;
  936.     2 : begin
  937.           GiveMSG (9, '', '^oThe ^A^lBlackjack Dealer ^A^ojust smacked ^A^lyou ^A^oacross the back of the head!',
  938.                       Node);
  939.           BroadCastAllBut (9, '', '^oThe ^A^lBlackjack Dealer ^A^ojust smacked ^A^l'+NodeUser(Node)
  940.                         +' ^A^oacross the back of the head!', Node);
  941.         end;
  942.     3 : If NodeStat[Node] > 0 then
  943.           BroadCastAll (9, '^oThe Blackjack Dealer',
  944.               '^oFrom ^A^lThe Blackjack Dealer^A^o, grumbling unhappily: ^A^kStop that, '
  945.                         +NodeUser(Node)+', or I''ll kick you out of the game!');
  946.     4 : If NodeStat[Node] > 0 then
  947.           BroadCastAll (9, '^oThe Blackjack Dealer',
  948.               '^oFrom ^A^lThe Blackjack Dealer^A^o, grumbling unhappily: ^A^kStop that, '
  949.                         +NodeUser(Node)+', or I''ll have to fine you!');
  950.     5 : begin
  951.           GiveMSG (9, '', '^oThe ^A^lBlackjack Dealer ^A^ojust elbowed ^A^lyou ^A^oin the face!',
  952.                       Node);
  953.           BroadCastAllBut (9, '', '^oThe ^A^lBlackjack Dealer ^A^ojust elbowed ^A^l'+NodeUser(Node)+' ^A^oin the face!', Node);
  954.         end;
  955.     6 : BroadCastAll (9, '', '^oThe ^A^lBlackjack Dealer ^A^ojust put up ^A^lhis^A^o deflector shields!');
  956.     7 : begin
  957.           GiveMSG (9, '', '^oThe ^A^lBlackjack Dealer ^A^ojust poked ^A^lyou ^A^oin the ribs!',
  958.                       Node);
  959.           BroadCastAllBut (9, '', '^oThe ^A^lBlackjack Dealer ^A^ojust poked ^A^l'+NodeUser(Node)+' ^A^oin the ribs!', Node);
  960.         end;
  961.     8 : begin
  962.           GiveMSG (9, '', '^oThe ^A^lBlackjack Dealer ^A^ojust gave ^A^lyou ^A^oa good, swift, kick in the butt!',
  963.                       Node);
  964.           BroadCastAllBut (9, '', '^oThe ^A^lBlackjack Dealer ^A^ojust gave ^A^l'+NodeUser(Node)
  965.                            +' ^A^oa good, swift, kick in the butt!', Node);
  966.         end;
  967.     end;
  968.   end
  969.   else
  970.   If ((N = 9) or (N = 8) or (N = 15)) and (NodeStat[NodeData.From] > 0) then
  971.   begin
  972.     If NodeStat[nodedata.from] = 2 then
  973.     begin
  974.       For J := 1 to NodeNumHands[J] do
  975.         If HandValue (NodeHand[J, Node]) < 22 then
  976.           Dec (NodeCD[Node], NodeBet[Node]*NodeDD[J, Node]);
  977.       If NodeInsure[Node] then Dec (NodeCD[Node], Round(NodeBet[Node]/2));
  978.     end;
  979.     NodeStat[Node] := 0;
  980.     BroadCastBut (9,'','^A^nThe ^A^pblackjack dealer ^A^njust tossed ^A^p'+(NodeUser(Node))
  981.                   +' ^A^nout of the ^A^pblackjack^A^n game!', Node);
  982.     GiveMSG (9,'','^A^nThe angry ^A^pblackjack dealer ^A^njust tossed ^A^pyou ^A^nout of the ^A^pblackjack^A^n game!',
  983.                   Node);
  984.     Writeln (NodeUser(Node), ' is dealt out of the blackjack game.');
  985.     If (nodedata.from) = NodeTurn then NextPlayer;
  986.   end;
  987.   If (N = 25) and (NodeStat[NodeData.From] > 0) then
  988.   begin
  989.     T := (((random(5) + 4) MOD 3) + 1) * 100;
  990.     Dec(NodeCD[NodeData.From], T);
  991.     BroadCastBut (9,'','^A^nThe ^pblackjack dealer ^njust ^I^pfined^A '+(NodeUser(Node))
  992.                   +' ^l'+ ToStr(T) +'^n CyberDollars!', Node);
  993.     GiveMSG (9,'','^A^nThe ^pblackjack dealer ^njust ^I^pfined^A you'
  994.              +' ^l'+ ToStr(T) +'^n CyberDollars!', Node);
  995.     Writeln(NodeUser(Node), ' has been fined ', T, 'CDs.');
  996.   end;
  997. end;
  998.  
  999. Procedure Process (NodeData : NodeRec);
  1000. Var
  1001.   s : String;
  1002.   I : Word;
  1003.   L : LongInt;
  1004.   Error : Integer;
  1005.   J : Word;
  1006.   H : Word;
  1007. begin
  1008.   NodeData2.DoneTo := -1;
  1009.   NodeData2.From := node;
  1010.   NodeData2.Gender := 0;
  1011.   NodeData2.Alias := '';
  1012.   NodeData2.Kind := 9;
  1013.   NodeData2.Channel := 1;
  1014.   NodeData2.MinSec := 0;
  1015.   NodeData2.Data1 := 0;
  1016.   If NodeData.Kind = 6 then
  1017.   begin
  1018.     s := KillSpaces(UpStr(CStr(NodeData.Data)));
  1019.     If s = 'ON' then
  1020.     begin
  1021.       If NodeStat[NodeData.From+1] = 0 then
  1022.       begin
  1023.         GiveMSG (9, '', '^A^nOk, you will now be playing in the next ^A^pblackjack ^A^ngame!',
  1024.                  NodeData.from);
  1025.         NodeStat[NodeData.from] := 1;
  1026.         BroadCastBut (9,'','^A^p'+CStr(NodeData.Alias)+' ^A^nwill be playing in the next ^A^pblackjack^A^n game!',
  1027.                       NodeData.from);
  1028.         Writeln (CStr(NodeData.Alias), ' joins the blackjack game.');
  1029.       end
  1030.       else
  1031.         GiveMSG (9, '', '^A^nYou are already playing ^A^pblackjack^A^n!', NodeData.from);
  1032.     end;
  1033.     If s = 'OFF' then
  1034.     begin
  1035.       If NodeStat[NodeData.from] = 0 then
  1036.         GiveMSG (9, '', '^A^nYou aren''t playing in ^A^pblackjack^A^n!', NodeData.from)
  1037.       else
  1038.       begin
  1039.         GiveMSG (9, '', '^A^nOk, you are no longer playing ^A^pblackjack^A^n.', NodeData.from);
  1040.         If NodeStat[NodeData.from] = 2 then
  1041.         begin
  1042.           For H := 1 to NodeNumHands[NodeData.from] do
  1043.           Dec (NodeCD[NodeData.from], NodeBet[NodeData.from]*NodeDD[H, NodeData.from]);
  1044.           NextPlayer;
  1045.         end;
  1046.         BroadCastBut (9,'','^A^p'+CStr(NodeData.Alias)+' ^A^nask to be dealt out of the ^A^pblackjack^A^n game!',
  1047.                       NodeData.from);
  1048.         Writeln (CStr(NodeData.Alias), ' is dealt out of the blackjack game.');
  1049.         NodeStat[NodeData.from] := 0;
  1050.       end;
  1051.     end;
  1052.     If (s='INSURE')or(s='INSURANCE')or(s='INSUR')or(s='INS')or(s='INSUER') then
  1053.     begin
  1054.       If (NodeStat[NodeData.from] = 2) then
  1055.       begin
  1056.         If NodeData.from = NodeTurn then
  1057.         begin
  1058.           If NodeInsure[NodeData.from] then
  1059.             GiveMSG (9, '', '^A^nYou''ve already made an insurance bet!', NodeData.from)
  1060.           else
  1061.           begin
  1062.             If (Length (NodeHand[1, NodeData.from]) = 4) and (NodeNumHands[NodeData.from] = 1) then
  1063.             begin
  1064.               GiveMSG (9, '', '^A^nOk, you make an insurance bet.', NodeData.from);
  1065.               BroadcastBut (9, '', '^A^p'+NodeUser(NodeTurn)+' ^A^nmakes an insurance bet.', NodeData.from);
  1066.               NodeInsure[NodeData.from] := True;
  1067.             end
  1068.             else GiveMSG (9, '', '^A^nYou can''t buy insurance now!', NodeData.from);
  1069.           end;
  1070.         end
  1071.         else
  1072.           GiveMSG (9, '', '^A^nIt isn''t your turn!', NodeData.from);
  1073.       end
  1074.       else
  1075.         GiveMSG (9, '', '^A^nYou aren''t playing in the ^A^pblackjack^A^n game.', NodeData.from);
  1076.     end;
  1077.     If (s='STAY')or(s='STA')or(s='STY')or(s='SAY')or(s='TAY')or(s='STYA')or(s='STAYU')or
  1078.        (s='STAND') then
  1079.     begin
  1080.       If (NodeStat[NodeData.from] = 2) then
  1081.       begin
  1082.         If NodeData.from = NodeTurn then
  1083.         begin
  1084.           GiveMSG (9, '', '^A^nOk, you stay.', NodeData.from);
  1085.           BroadcastBut (9, '', '^A^p'+NodeUser(NodeTurn)+' ^A^nstays.', NodeData.from);
  1086.           NextPlayer;
  1087.         end
  1088.         else
  1089.           GiveMSG (9, '', '^A^nIt isn''t your turn!', NodeData.from);
  1090.       end
  1091.       else
  1092.         GiveMSG (9, '', '^A^nYou aren''t playing in the ^A^pblackjack^A^n game.', NodeData.from);
  1093.     end;
  1094.     If (s='HAND')or(s='HAN')or(s='HADN')or(s='AHND') then
  1095.     begin
  1096.       If NodeStat[NodeData.from] = 2 then DisplayHand (NodeData.from)
  1097.       else
  1098.         GiveMSG (9, '', '^A^nYou aren''t playing in the ^A^pblackjack^A^n game.', NodeData.from);
  1099.     end;
  1100.     If (s = 'CD') or (s = '$') then
  1101.       GiveMSG (9, '', '^A^nYou have ^A^p'+ ToStr(NodeCD[NodeData.from])+'^A^n Cyberdollars.', NodeData.from);
  1102.     If Copy(s, 1, 3) = 'HIT' then
  1103.     begin
  1104.       If NodeStat[NodeData.from] = 2 then
  1105.       begin
  1106.         If NodeData.from = NodeTurn then
  1107.         begin
  1108.           If Length(s) = 3 then H := 1 else Val(Copy(s, 4, 1), H, Error);
  1109.           if H > NodeNumHands[NodeData.from] then GiveMsg(9, '', '^A^nYou don''t have '+ToStr(H)+' hands!', NodeData.from)
  1110.           else
  1111.           If NodeDoneH[H, NodeData.from] then GiveMSG (9, '', '^A^nYou can''t play that hand!', NodeData.from)
  1112.           else
  1113.           begin
  1114.             if NodeNumHands[NodeData.from] = 1 then
  1115.             BroadcastBut (9, '', '^A^p'+NodeUser(NodeTurn)+' ^A^nhits.', NodeData.from)
  1116.             else
  1117.             BroadcastBut (9, '', '^A^p'+NodeUser(NodeTurn)+' ^A^nhits hand #'+ToStr(H)+'.', NodeData.from);
  1118.             NodeHand[H, NodeData.from] := NodeHand[H, NodeData.from] + GetCard;
  1119.             DisplayHand (NodeData.from);
  1120.             SecPassed := 0;
  1121.             Writeln (NodeUser(NodeTurn), ' hits.');
  1122.             If HandValue(NodeHand[H, NodeData.from]) > 21 then
  1123.             begin
  1124.               GiveMSG (9, '', '^I^nYou busted!', NodeData.from);
  1125.               BroadCastBut (9, '', '^A^p'+NodeUser(NodeTurn)+' ^A^nbusts!', NodeData.from);
  1126.               BroadCastBut (9, '', '^A^p'+NodeUser(NodeTurn)+'^I^n loses ^A^p'+ToStr(NodeBet[NodeTurn])+' ^A^nCyberdollars!'
  1127.                             , NodeData.from);
  1128.               GiveMSG (9, '', '^A^pYou^I^n lose ^A^p'+ToStr(NodeBet[NodeTurn])+' ^A^nCyberdollars!', NodeData.from);
  1129.               Dec (NodeCD[NodeData.from], NodeBet[NodeData.from]);
  1130.               Writeln (NodeUser(NodeTurn), ' busts.');
  1131.               NodeDoneH[H, NodeData.from] := True;
  1132.               If DoneAllHands(NodeData.from) then NextPlayer;
  1133.             end;
  1134.           end;
  1135.         end
  1136.         else
  1137.           GiveMSG (9, '', '^A^nIt is not your turn!', NodeData.from);
  1138.       end
  1139.       else
  1140.         GiveMSG (9, '',  '^A^nYou aren''t playing in the ^A^pblackjack^A^n game.', NodeData.from);
  1141.     end;
  1142. {    If (s='HIT2')or(s='HTI2')or(s='HI2T')or(s='IHT2') then
  1143.     begin
  1144.       If NodeStat[NodeData.from] = 2 then
  1145.       begin
  1146.         If NodeData.from = NodeTurn then
  1147.         begin
  1148.           If NodeHand2[NodeData.from] = '' then
  1149.             GiveMSG (9, '', '^A^nYou don''t have a second hand!', NodeData.from)
  1150.           else
  1151.           begin
  1152.             If NodeDoneH2[NodeData.from] then GiveMSG (9, '', '^A^nYou can''t play that hand!', NodeData.from)
  1153.             else
  1154.             begin
  1155.               BroadcastBut (9, '', '^A^p'+NodeUser(NodeTurn)+' ^A^nhits second hand.', NodeData.from);
  1156.               NodeHand2[NodeData.from] := NodeHand2[NodeData.from] + GetCard;
  1157.               DisplayHand (NodeData.from);
  1158.               SecPassed := 0;
  1159.               Writeln (NodeUser(NodeTurn), ' hits second hand.');
  1160.               If HandValue(NodeHand2[NodeData.from]) > 21 then
  1161.               begin
  1162.                 GiveMSG (9, '', '^I^nYou busted!', NodeData.from);
  1163.                 BroadCastBut (9, '', '^A^p'+NodeUser(NodeTurn)+' ^A^nbusts!', NodeData.from);
  1164.                 BroadCastBut (9, '', '^A^p'+NodeUser(NodeTurn)+'^I^n loses ^A^p'+ToStr(NodeBet[NodeTurn])+' ^A^nCyberdollars!'
  1165.                               , NodeData.from);
  1166.                 GiveMSG (9, '', '^A^pYou^I^n lose ^A^p'+ToStr(NodeBet[NodeTurn])+' ^A^nCyberdollars!', NodeData.from);
  1167.                 Dec (NodeCD[NodeData.from], NodeBet[NodeData.from]);
  1168.                 Writeln (NodeUser(NodeTurn), ' busts.');
  1169.                 NodeDoneH2[NodeData.from] := True;
  1170.                 If NodeDoneH1[NodeData.from] and NodeDoneH2[NodeData.from] then NextPlayer;
  1171.               end;
  1172.             end;
  1173.           end;
  1174.         end
  1175.         else
  1176.           GiveMSG (9, '', '^A^nIt is not your turn!', NodeData.from);
  1177.       end
  1178.       else
  1179.         GiveMSG (9, '',  '^A^nYou aren''t playing in the ^A^pblackjack^A^n game.', NodeData.from);
  1180.     end;}
  1181.     If (s = 'HELP') or (s = '!') or (s = '?') or (s = 'COMMANDS') then
  1182.     begin
  1183.       For I := 1 to 14 do
  1184.         GiveMSG (9, '', HelpData[I], NodeData.from);
  1185.     end;
  1186.     If Copy(s, 1, 5) = 'SPLIT' then
  1187.     begin
  1188.       If NodeStat[NodeData.from] = 2 then
  1189.         If NodeData.from = NodeTurn then
  1190.         begin
  1191.           If Length(s) = 5 then H := 1 else Val(Copy(s, 6, 1), H, Error);
  1192.           if H > NodeNumHands[NodeData.from] then GiveMsg(9, '', '^A^nYou don''t have '+ToStr(H)+' hands!', NodeData.from)
  1193.           else
  1194.           If OkayToSplit(H, NodeData.from) then
  1195.           begin
  1196.             If HandValue (NodeHand[H, NodeData.from][1]+NodeHand[H, NodeData.from][2])
  1197.                = HandValue (NodeHand[H, NodeData.from][3]+NodeHand[H, NodeData.from][4]) then
  1198.             begin
  1199.               GiveMSG (9, '', '^A^nOk, you split.', NodeData.from);
  1200.               SecPassed := 0;
  1201.               If NodeNumHands[NodeData.from] = 1 then
  1202.               BroadcastBut (9, '', '^A^p'+NodeUser(NodeTurn)+' ^A^nsplits.', NodeData.from)
  1203.               else
  1204.               BroadcastBut (9, '', '^A^p'+NodeUser(NodeTurn)+' ^A^nsplits hand #'+ToStr(H)+'.', NodeData.from);
  1205.               Inc(NodeNumHands[NodeData.from]);
  1206.               NodeHand[NodeNumHands[NodeData.from], NodeData.from] :=
  1207.                 NodeHand[H, NodeData.from][3]+NodeHand[H, NodeData.from][4];
  1208.               Dec (NodeHand[H, NodeData.from][0], 2);
  1209.               NodeHand[H, NodeData.from] := NodeHand[H, NodeData.from] + GetCard;
  1210.               NodeHand[NodeNumHands[NodeData.From], NodeData.from] :=
  1211.                 NodeHand[NodeNumHands[NodeData.From], NodeData.from] + GetCard;
  1212.               DisplayHand (NodeData.from);
  1213.             end
  1214.             else GiveMSG (9, '', '^A^nYou can''t split when card values are different!', NodeData.from)
  1215.           end
  1216.           else GiveMSG (9, '', '^A^nYou can''t split now!', NodeData.from)
  1217.         end
  1218.         else
  1219.           GiveMSG (9, '', '^A^nIt is not your turn!', NodeData.from)
  1220.       else
  1221.         GiveMSG (9, '',  '^A^nYou aren''t playing in the ^A^pblackjack^A^n game.', NodeData.from);
  1222.     end;
  1223.     if Copy(s, 1, 6) = 'DOUBLE' then
  1224.     begin
  1225.       If NodeStat[NodeData.from] = 2 then
  1226.       begin
  1227.         If NodeData.from = NodeTurn then
  1228.         begin
  1229.           If Length(s) = 6 then H := 1 else Val(Copy(s, 7, 1), H, Error);
  1230.           if H > NodeNumHands[NodeData.from] then GiveMsg(9, '', '^A^nYou don''t have '+ToStr(H)+' hands!', NodeData.from)
  1231.           else
  1232.           If NodeDoneH[H, NodeData.from] then GiveMSG (9, '', '^A^nYou can''t play that hand!', NodeData.from)
  1233.           else
  1234.           if Length(NodeHand[H, NodeData.from]) <= 4 then
  1235.           begin
  1236.             if NodeNumHands[NodeData.from] = 1 then
  1237.             BroadcastBut (9, '', '^A^p'+NodeUser(NodeTurn)+' ^A^ndoubles down.', NodeData.from)
  1238.             else
  1239.             BroadcastBut (9, '', '^A^p'+NodeUser(NodeTurn)+' ^A^ndoubles down hand #'+ToStr(H)+'.', NodeData.from);
  1240.             NodeHand[H, NodeData.from] := NodeHand[H, NodeData.from] + GetCard;
  1241.             NodeDD[H, NodeData.from] := 2;
  1242.             GiveMSG (9, '', '^A^nOk, you ^A^pdouble down^A^n!', NodeData.from);
  1243.             DisplayHand (NodeData.from);
  1244.             SecPassed := 0;
  1245.             Writeln (NodeUser(NodeTurn), ' doubles down.');
  1246.             If HandValue(NodeHand[H, NodeData.from]) > 21 then
  1247.             begin
  1248.               GiveMSG (9, '', '^I^nYou busted!', NodeData.from);
  1249.               BroadCastBut (9, '', '^A^p'+NodeUser(NodeTurn)+' ^A^nbusts!', NodeData.from);
  1250.               BroadCastBut (9, '', '^A^p'+NodeUser(NodeTurn)+'^I^n loses ^A^p'+ToStr(NodeBet[NodeTurn]*NodeDD[H, NodeTurn])
  1251.                             +' ^A^nCyberdollars!', NodeData.from);
  1252.               GiveMSG (9, '', '^A^pYou^I^n lose ^A^p'+ToStr(NodeBet[NodeTurn]*NodeDD[H, NodeTurn])+' ^A^nCyberdollars!',
  1253.                        NodeData.from);
  1254.               Dec (NodeCD[NodeData.from], NodeBet[NodeData.from]*NodeDD[H, NodeData.from]);
  1255.               Writeln (NodeUser(NodeTurn), ' busts.');
  1256.             end;
  1257.             NodeDoneH[H, NodeData.from] := True;
  1258.             if DoneAllHands(NodeData.from) then NextPlayer;
  1259.           end
  1260.           else
  1261.             GiveMSG (9, '', '^A^nYou can''t double down after hitting!', NodeData.from);
  1262.         end
  1263.         else
  1264.           GiveMSG (9, '', '^A^nIt is not your turn!', NodeData.from);
  1265.       end
  1266.       else
  1267.         GiveMSG (9, '',  '^A^nYou aren''t playing in the ^A^pblackjack^A^n game.', NodeData.from);
  1268.     end;
  1269. {    If (s = 'DOUBLE2') or (s = 'DOUBLEDOWN2') or (s = 'DD2') then
  1270.     begin
  1271.       If NodeStat[NodeData.from] = 2 then
  1272.       begin
  1273.         If NodeData.from = NodeTurn then
  1274.         begin
  1275.           If NodeHand2[NodeData.from] = '' then
  1276.             GiveMSG (9, '', '^A^nYou don''t have a second hand!', NodeData.from)
  1277.           else
  1278.           begin
  1279.             if Length(NodeHand2[NodeData.from]) <= 4 then
  1280.             begin
  1281.               BroadcastBut (9, '', '^A^p'+NodeUser(NodeTurn)+' ^A^ndoubles down on second hand.', NodeData.from);
  1282.               NodeHand2[NodeData.from] := NodeHand2[NodeData.from] + GetCard;
  1283.               NodeDD2[NodeData.from] := 2;
  1284.               GiveMSG (9, '', '^A^nOk, you ^A^pdouble down^A^n!', NodeData.from);
  1285.               DisplayHand (NodeData.from);
  1286.               SecPassed := 0;
  1287.               Writeln (NodeUser(NodeTurn), ' doubles down on second hand.');
  1288.               If HandValue(NodeHand2[NodeData.from]) > 21 then
  1289.               begin
  1290.                 GiveMSG (9, '', '^I^nYou busted!', NodeData.from);
  1291.                 BroadCastBut (9, '', '^A^p'+NodeUser(NodeTurn)+' ^A^nbusts!', NodeData.from);
  1292.                 BroadCastBut (9, '', '^A^p'+NodeUser(NodeTurn)+'^I^n loses ^A^p'+ToStr(NodeBet[NodeTurn]*NodeDD2[NodeTurn])
  1293.                               +' ^A^nCyberdollars!', NodeData.from);
  1294.                 GiveMSG (9, '', '^A^pYou^I^n lose ^A^p'+ToStr(NodeBet[NodeTurn]*NodeDD2[NodeTurn])+' ^A^nCyberdollars!',
  1295.                          NodeData.from);
  1296.                 Dec (NodeCD[NodeData.from], NodeBet[NodeData.from]*NodeDD2[NodeData.from]);
  1297.                 Writeln (NodeUser(NodeTurn), ' busts.');
  1298.               end;
  1299.               NodeDoneH2[NodeData.from] := True;
  1300.               If NodeDoneH1[NodeData.from] and NodeDoneH2[NodeData.from] then NextPlayer;
  1301.             end
  1302.             else
  1303.             GiveMSG (9, '', '^a^nYou can''t double down after hitting!', NodeData.from);
  1304.           end
  1305.         end
  1306.         else
  1307.           GiveMSG (9, '', '^A^nIt is not your turn!', NodeData.from);
  1308.       end
  1309.       else
  1310.         GiveMSG (9, '',  '^A^nYou aren''t playing in the ^A^pblackjack^A^n game.', NodeData.from);
  1311.     end;}
  1312.     If (s='TURN')or(s='TUR')or(s='TUNR') then
  1313.     begin
  1314.       If GamePlaying then
  1315.       begin
  1316.         If NodeTurn = NodeData.from then
  1317.           GiveMSG (9, '', '^A^nIt is ^A^pyour ^A^nturn in blackjack.',
  1318.                    NodeData.from)
  1319.         else
  1320.           GiveMSG (9, '', '^A^nIt is ^A^p'+NodeUser(NodeTurn)+'^A^n''s turn in blackjack.',
  1321.                    NodeData.from);
  1322.       end
  1323.       else
  1324.         GiveMSG (9, '', '^A^nThere is no blackjack game being played at the moment.', NodeData.from);
  1325.     end;
  1326.     If (s='SCAN')or(s='SCA')or(s='SCNA') then
  1327.     begin
  1328.       GiveMSG (9, '', #13#10'^A^oPlayer                          Playing    Cyberdollars', NodeData.from);
  1329.       GiveMSG (9, '', '^A^o-------------------------------------------------------', NodeData.from);
  1330.       For I := 1 to 255 do
  1331.       begin
  1332.         If NodeStat[I] = 1 then
  1333.           GiveMSG (9, '', '^A^o'+NodeUser(I)+Spaces(34-Length(KillTOPCodes(NodeUser(I)))) +' No         '+ToStr(NodeCD[I]),
  1334.                    NodeData.from);
  1335.         If NodeStat[I] = 2 then
  1336.           GiveMSG (9, '', '^A^o'+NodeUser(I)+Spaces(34-Length(KillTOPCodes(NodeUser(I)))) +'Yes         '+ToStr(NodeCD[I]),
  1337.                    NodeData.from);
  1338.       end;
  1339.       GiveMSG (9, '', #0, NodeData.from);
  1340.     end;
  1341.     If (s='BET')or(s='BTE') then
  1342.       GiveMSG (9, '', '^A^nYour current bet is ^A^p'+ToStr(NodeBet[NodeData.from])+' ^A^nCyberdollars.', NodeData.from)
  1343.     else
  1344.     If (s[1] = 'B') and (s[2] = 'E') and (s[3] = 'T') and (s[0] > #3) then
  1345.     begin
  1346.       If NodeStat[NodeData.from] < 2 then
  1347.       begin
  1348.         Delete (s, 1, 3);
  1349.         Val (s, L, Error);
  1350.         If (Error <> 0) or (L > ConfigData.MaxBet) or (L < ConfigData.MinBet) then
  1351.         begin
  1352.           GiveMSG (9, '', '^A^nBets must be between ^A^p'+ToStr(ConfigData.MinBet)+' ^A^nand ^A^p'+ToStr(ConfigData.MaxBet)+
  1353.                    ' ^A^nCyberdollars.', NodeData.from);
  1354.         end
  1355.         else
  1356.         begin
  1357.           NodeBet[NodeData.from] := L;
  1358.           GiveMSG (9, '', '^A^nOk, your bet will now be ^A^p'+ToStr(L)+' ^A^nCyberdollars.', NodeData.from);
  1359.         end;
  1360.       end
  1361.       else
  1362.         GiveMSG (9, '', '^A^nSorry, you cannot change your bet during a game.', NodeData.from);
  1363.     end;
  1364.   end;
  1365.   If (NodeData.Kind = 3) or (NodeData.Kind = 19) then
  1366.   begin
  1367.     If NodeStat[NodeData.from] = 2 then
  1368.     begin
  1369.       For J := 1 to NodeNumHands[Node] do
  1370.       If (HandValue (NodeHand[J, Node]) < 22) then
  1371.       Dec (NodeCD[NodeData.from], NodeBet[NodeData.from]*NodeDD[J, NodeData.from]);
  1372.       If NodeInsure[Node] then Dec (NodeCD[Node], Round(NodeBet[Node]/2));
  1373.       NodeStat[NodeData.from] := 0;
  1374.       BroadCastBut (9,'','^A^p'+CStr(NodeData.Alias)+' ^A^nis dealt out of the ^A^pblackjack^A^n game!',
  1375.                     NodeData.from);
  1376.       Writeln (CStr(NodeData.Alias), ' is dealt out of the blackjack game.');
  1377.       If (NodeData.from) = NodeTurn then NextPlayer;
  1378.     end;
  1379.     NodeCD[NodeData.from] := ConfigData.StartCD;
  1380.     NodeBet[NodeData.from] := ConfigData.BetCD;
  1381.   end;
  1382.   If (NodeData.Kind = 1) then
  1383.   begin
  1384.     s := UpStr(CStr(NodeData.Data));
  1385.     For J := 1 to 16 do
  1386.       If s = ComList[J] then GiveMSG (6, '^A^pThe blackjack dealer', 'You missed a "^A^k/^A^o" in your blackjack command.'
  1387.                                       , NodeData.from);
  1388.   end;
  1389.   If (NodeData.Kind = 10) and (NodeData.DoneTo = Node) then
  1390.   begin
  1391.     s := CStr(NodeData.Data);
  1392.     If Pos ('just barfed ALL OVER', s) <> 0 then Retal (NodeData.from);
  1393.     If Pos ('just bonked',s) <> 0 then Retal (NodeData.from);
  1394.     If Pos ('is booting',s) <> 0 then Retal (NodeData.from);
  1395.     If Pos ('with a disruptor!',s) <> 0 then Retal (NodeData.from);
  1396.     If Pos ('just tossed a grenade!',s) <> 0 then Retal (NodeData.from);
  1397.     If Pos ('is hitting',s) <> 0 then Retal (NodeData.from);
  1398.     If Pos ('is kicking the life out of',s) <> 0 then Retal (NodeData.from);
  1399.     If Pos ('with a mushroom cloud!',s) <> 0 then Retal (NodeData.from);
  1400.     If Pos ('a phaser and blasted',s) <> 0 then Retal (NodeData.from);
  1401.     If Pos ('is punching',s) <> 0 then Retal (NodeData.from);
  1402.     If Pos ('just shot',s) <> 0 then Retal (NodeData.from);
  1403.     If Pos ('just slapped',s) <> 0 then Retal (NodeData.from);
  1404.     If Pos ('across the back of the head!',s) <> 0 then Retal (NodeData.from);
  1405.     If Pos ('just spit on',s) <> 0 then Retal (NodeData.from);
  1406.     If Pos ('is stripping',s) <> 0 then Retal (NodeData.from);
  1407.     If Pos ('just zapped',s) <> 0 then Retal (NodeData.from);
  1408.     If Pos ('just bashed',s) <> 0 then Retal (NodeData.from);
  1409.     If Pos ('just stapled',s) <> 0 then Retal (NodeData.from);
  1410.     If Pos ('just killed',s) <> 0 then Retal (NodeData.from);
  1411.     If Pos ('just elbowed',s) <> 0 then Retal (NodeData.from);
  1412.     If Pos ('just poked',s) <> 0 then Retal (NodeData.from);
  1413.   end;
  1414. end;
  1415.  
  1416. Procedure GetMSGs;
  1417. Var
  1418.   b : byte;
  1419.   z : byte;
  1420.   f : file of byte;
  1421.   NodeFile : File of NodeRec;
  1422. begin
  1423.   z := 0;
  1424.   Assign (f, IPCDir + 'MIX'+NodeStr+'.TCH');
  1425.   Assign (NodeFile, IPCDir + 'MSG'+NodeStr+'.TCH');
  1426.   Reset (f);
  1427.   Reset (NodeFile);
  1428.   Repeat
  1429.     {$I-}
  1430.     Repeat
  1431.       Read (f,b);
  1432.     Until IOResult = 0;
  1433.     Seek (f, FilePos (f) - 1);
  1434.     Repeat
  1435.       Write (f,z);
  1436.     Until IOResult = 0;
  1437.     Repeat
  1438.       Read (NodeFile, NodeData);
  1439.     Until IOResult = 0;
  1440.     {$I+}
  1441.     If b = 1 then Process (NodeData);
  1442.   Until Eof (f);
  1443.   Close (f);
  1444.   Close (NodeFile);
  1445.   b := 0;
  1446.   Assign (f, IPCDir + 'CHGIDX.TCH');
  1447.   Reset (f);
  1448.   Seek (f, node);
  1449.   {$I-}
  1450.   Repeat
  1451.     Write (f,b);
  1452.   Until IOResult = 0;
  1453.   {$I+}
  1454.   Close (f);
  1455. end;
  1456.  
  1457. Procedure WaitSec;
  1458. begin
  1459.   GetTime (L, L, OldSec, L);
  1460.   Repeat
  1461.     GetTime (L, L, Sec, L);
  1462.   Until Sec <> OldSec;
  1463.   OldSec := Sec;
  1464.   Inc (SecPassed);
  1465. end;
  1466.  
  1467. Procedure StartGame;
  1468. Var
  1469.   SomeoneIn : Boolean;
  1470.   I : Word;
  1471. begin
  1472.   Writeln ('Starting a new blackjack game');
  1473.  { UsedCards := ''; }
  1474.   NodeData2.DoneTo := -1;
  1475.   NodeData2.From := node;
  1476.   NodeData2.Gender := 0;
  1477.   NodeData2.Alias := '';
  1478.   NodeData2.Kind := 9;
  1479.   NodeData2.Channel := 1;
  1480.   NodeData2.MinSec := 0;
  1481.   NodeData2.Data1 := 0;
  1482.   SomeoneIn := False;
  1483.   { Get dealer's hand }
  1484.   DealerHand := GetCard + GetCard;
  1485.   If (Random(5) = 0) {and (not registered)} then RegRemind;
  1486.   For I := 1 to 255 do
  1487.     If NodeStat[I] > 0 then
  1488.     begin
  1489.       SomeoneIn := True;
  1490.       GiveMSG (9, '', #0, I);
  1491.       GiveMSG (9, '', '^A^nA new ^A^pblackjack ^A^ngame has begun!', I);
  1492.       NodeStat[I] := 2;
  1493.     end;
  1494.   { Deal first cards }
  1495.   For I := 1 to 255 do
  1496.     If NodeStat[I] = 2 then
  1497.     begin
  1498.       NodeNumHands[I] := 1;
  1499.       NodeHand[1, I] := GetCard + GetCard;
  1500.       GiveMSG (9, '', '^A^nDealer''s cards: '+ColorHand(DealerHand[1]+DealerHand[2])+'^H^a  ^A^n  (^A^p'
  1501.                +ToStr(HandValue(DealerHand[1]+DealerHand[2]))+'^A^n)', I);
  1502.       GiveMSG (9, '', '^A^nYour cards:     '+ColorHand(NodeHand[1, I])+' ^A^n(^A^p'+ToStr(HandValue(NodeHand[1, I]))+'^A^n)',
  1503.                I);
  1504.       If DealerHand[1] = 'A' then GiveMSG (9, '',
  1505.         '^A^nDealer has possible blackjack, you may want to make an insurance bet.', I);
  1506.     end;
  1507.   If SomeoneIn then
  1508.   begin
  1509.     For I := 255 downto 1 do If NodeStat[I] = 2 then NodeTurn := I;
  1510.     GamePlaying := True;
  1511.     GiveMSG (9, '', '^A^nIt is your turn in ^A^pblackjack^A^n!', NodeTurn);
  1512.     Writeln ('It is ', NodeUser(NodeTurn), '''s turn in blackjack.');
  1513.   end
  1514.   else Writeln ('No players.');
  1515.   SecPassed := 0;
  1516. end;
  1517.  
  1518. Procedure WarnUser;
  1519. begin
  1520.   GiveMSG (9, '', #7'^I^nIt is still your turn in ^I^pblackjack^A^n!', NodeTurn);
  1521.   WaitSec;
  1522. end;
  1523.  
  1524. Procedure DealerPlay;
  1525. Var
  1526.   H : Word;
  1527.   I : Word;
  1528.   DealerValue : Word;
  1529. begin
  1530.   BroadCast (9, '', '');
  1531.   BroadCast (9, '', '^A^nThe ^A^pBlackjack dealer ^A^nnow plays.');
  1532.   WaitSec;
  1533.   BroadCast (9, '', '^A^nDealer''s cards: '+ColorHand(DealerHand)+' ^A^n(^A^p'+ToStr(HandValue(DealerHand))+'^A^n)');
  1534.   WaitSec;
  1535.   While HandValue (DealerHand) < 17 do
  1536.   begin
  1537.     Writeln ('Dealer hits.');
  1538.     BroadCast (9, '', '^A^pDealer ^A^nhits.');
  1539.     DealerHand := DealerHand + GetCard;
  1540.     WaitSec;
  1541.     BroadCast (9, '', '^A^nDealer''s cards: '+ColorHand(DealerHand)+' ^A^n(^A^p'+ToStr(HandValue(DealerHand))+'^A^n)');
  1542.     WaitSec;
  1543.   end;
  1544.   WaitSec;
  1545.   If HandValue (DealerHand) < 22 then BroadCast (9, '', '^A^pDealer ^A^nstays.'#13#10)
  1546.   else BroadCast (9, '', '^A^pDealer ^A^nbusts!'#13#10);
  1547.   BroadCast (9, '', '^A^nThe ^A^pblackjack ^A^ngame is over!');
  1548.  
  1549.   { Pay the winners }
  1550.   DealerValue := HandValue (DealerHand);
  1551.   If DealerValue > 21 then DealerValue := 0;
  1552.   If (DealerValue = 21) and (Length (DealerHand) = 4) then
  1553.   begin
  1554.     { Blackjack for dealer }
  1555.     BroadCast (9, '', '^A^nThe ^A^pdealer ^A^nhas a ^I^pblackjack^A^n!');
  1556.     For I := 1 to 255 do if NodeStat[I] = 2 then
  1557.     begin
  1558.       If NodeInsure[I] then
  1559.       begin
  1560.         Inc (NodeCD[I], Round (NodeBet[I]));
  1561.         GiveMSG (9, '', '^A^pYou^I^n win ^A^nyour insurance bet and get ^A^p'+ToStr(Round(NodeBet[I]))
  1562.                  +' ^A^nCyberdollars!', I);
  1563.         If NodeGender (I) then
  1564.           BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^I^n wins ^A^nher insurance bet and gets ^A^p'
  1565.                         +ToStr(Round(NodeBet[I]))+' ^A^nCyberdollars!', I)
  1566.         else
  1567.           BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^I^n wins ^A^nhis insurance bet and gets ^A^p'
  1568.                         +ToStr(Round(NodeBet[I]))+' ^A^nCyberdollars!', I)
  1569.       end;
  1570.       For H := 1 to NodeNumHands[I] do
  1571.       begin
  1572.       If (HandValue (NodeHand[H, I]) = 21) and (Length(NodeHand[H, I]) = 4) then
  1573.       begin
  1574.         BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^A^n''s hand #'+ToStr(H)+': '+ColorHand(NodeHand[H, I])+
  1575.                    ' ^A^n(^A^p'+ToStr(HandValue(NodeHand[H, I]))+'^A^n)', I);
  1576.         GiveMSG (9, '', '^A^pYour^A^n hand #'+ToStr(H)+':   '+ColorHand(NodeHand[H, I])+
  1577.                    ' ^A^n(^A^p'+ToStr(HandValue(NodeHand[H, I]))+'^A^n)', I);
  1578.         BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^A^n loses nothing.',I);
  1579.         GiveMSG (9, '', '^A^pYou^A^n lose nothing.',I);
  1580.       end
  1581.       else
  1582.       begin
  1583.         If HandValue (NodeHand[H, I]) < 22 then
  1584.         begin
  1585.           BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^A^n''s hand #'+ToStr(H)+': '+ColorHand(NodeHand[H, I])+
  1586.                         ' ^A^n(^A^p'+ToStr(HandValue(NodeHand[H, I]))+'^A^n)', I);
  1587.           GiveMSG (9, '', '^A^pYour^A^n hand #'+ToStr(H)+':   '+ColorHand(NodeHand[H, I])+
  1588.                   ' ^A^n(^A^p'+ToStr(HandValue(NodeHand[H, I]))+'^A^n)', I);
  1589.           BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^I^n loses ^A^p'+ToStr(NodeBet[I]*NodeDD[H, I])+' ^A^nCyberdollars!',I);
  1590.           GiveMSG (9, '', '^A^pYou^I^n lose ^A^p'+ToStr(NodeBet[I]*NodeDD[H, I])+' ^A^nCyberdollars!',I);
  1591.           Dec (NodeCD[I], NodeBet[I]*NodeDD[H, I]);
  1592.         end;
  1593.       end;
  1594. {      If (HandValue (NodeHand2[I]) = 21) and (Length(NodeHand2[I]) = 4) and
  1595.          (NodeHand2[I] <> '') then
  1596.       begin
  1597.         BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^A^n''s second hand: '+ColorHand(NodeHand2[I])+
  1598.                    ' ^A^n(^A^p'+ToStr(HandValue(NodeHand2[I]))+'^A^n)', I);
  1599.         GiveMSG (9, '', '^A^pYour^A^n second hand: '+ColorHand(NodeHand2[I])+
  1600.                    ' ^A^n(^A^p'+ToStr(HandValue(NodeHand2[I]))+'^A^n)', I);
  1601.         BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^A^n loses nothing.',I);
  1602.         GiveMSG (9, '', '^A^pYou^A^n lose nothing.',I);
  1603.       end
  1604.       else
  1605.       begin
  1606.         If (NodeHand2[I] <> '') and (HandValue (NodeHand2[I]) < 22) then
  1607.         begin
  1608.           BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^A^n''s second hand: '+ColorHand(NodeHand2[I])+
  1609.                      ' ^A^n(^A^p'+ToStr(HandValue(NodeHand2[I]))+'^A^n)', I);
  1610.           GiveMSG (9, '', '^A^pYour^A^n second hand: '+ColorHand(NodeHand2[I])+
  1611.                      ' ^A^n(^A^p'+ToStr(HandValue(NodeHand2[I]))+'^A^n)', I);
  1612.           BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^I^n loses ^A^p'+ToStr(NodeBet[I]*NodeDD2[I])+' ^A^nCyberdollars!',I);
  1613.           GiveMSG (9, '', '^A^pYou^I^n lose ^A^p'+ToStr(NodeBet[I]*NodeDD2[I])+' ^A^nCyberdollars!',I);
  1614.           Dec (NodeCD[I], NodeBet[I]*NodeDD2[I]);
  1615.         end;
  1616.       end;}
  1617.       end;
  1618.     end;
  1619.   end
  1620.   else
  1621.   For I := 1 to 255 do if NodeStat[I] = 2 then
  1622.   begin
  1623.     For H := 1 to NodeNumHands[I] do
  1624.     begin
  1625.     If HandValue (NodeHand[H, I]) < 22 then
  1626.     begin
  1627.       BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^A^n''s hand #'+ToStr(H)+': '+ColorHand(NodeHand[H, I])+
  1628.                  ' ^A^n(^A^p'+ToStr(HandValue(NodeHand[H, I]))+'^A^n)', I);
  1629.       GiveMSG (9, '', '^A^pYour^A^n hand #'+ToStr(H)+':   '+ColorHand(NodeHand[H, I])+
  1630.                  ' ^A^n(^A^p'+ToStr(HandValue(NodeHand[H, I]))+'^A^n)', I);
  1631.       If (HandValue (NodeHand[H, I]) = 21) and (Length (NodeHand[H, I]) = 4) then
  1632.       begin
  1633.         { Blackjack }
  1634.         GiveMSG (9, '', '^I^nYou got a ^I^pblackjack^I^n!', I);
  1635.         BroadCastBut (9, '', '^A^p'+NodeUser(I)+' ^A^nhas a ^A^pblackjack^A^n!', I);
  1636.         BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^I^n wins ^A^p'+ToStr(Round(NodeBet[I]*(3/2)))
  1637.                           +' ^A^nCyberdollars!', I);
  1638.         GiveMSG (9, '', '^A^pYou^I^n win ^A^p'+ToStr(Round(NodeBet[I]*(3/2)))+' ^A^nCyberdollars!', I);
  1639.         Inc (NodeCD[I], Round(NodeBet[I]*(3/2)));
  1640.         Writeln (NodeUser(I), ' gets a blackjack.');
  1641.       end
  1642.       else
  1643.       If HandValue (NodeHand[H, I]) > DealerValue then
  1644.       begin
  1645.         BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^I^n wins ^A^p'+ToStr(NodeBet[I]*NodeDD[H, I])+' ^A^nCyberdollars!',I);
  1646.         GiveMSG (9, '', '^A^pYou^I^n win ^A^p'+ToStr(NodeBet[I]*NodeDD[H, I])+' ^A^nCyberdollars!',I);
  1647.         Inc (NodeCD[I], NodeBet[I]*NodeDD[H, I]);
  1648.       end
  1649.       else
  1650.       If HandValue (NodeHand[H, I]) < DealerValue then
  1651.       begin
  1652.         BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^I^n loses ^A^p'+ToStr(NodeBet[I]*NodeDD[H, I])+' ^A^nCyberdollars!',I);
  1653.         GiveMSG (9, '', '^A^pYou^I^n lose ^A^p'+ToStr(NodeBet[I]*NodeDD[H, I])+' ^A^nCyberdollars!',I);
  1654.         Dec (NodeCD[I], NodeBet[I]*NodeDD[H, I]);
  1655.       end
  1656.       else
  1657.       If HandValue (NodeHand[H, I]) = DealerValue then
  1658.       begin
  1659.         BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^A^n loses nothing.',I);
  1660.         GiveMSG (9, '', '^A^pYou^A^n lose nothing.',I);
  1661.       end;
  1662.       If NodeInsure[I] then
  1663.       begin
  1664.         Dec (NodeCD[I], Round (NodeBet[I]/2));
  1665.         GiveMSG (9, '', '^A^pYou^I^n lose ^A^nyour insurance bet of ^A^p'+ToStr(Round(NodeBet[I]/2))
  1666.                  +' ^A^nCyberdollars!', I);
  1667.         If NodeGender (I) then
  1668.           BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^I^n loses ^A^nher insurance bet of ^A^p'
  1669.                         +ToStr(Round(NodeBet[I]/2))+' ^A^nCyberdollars!', I)
  1670.         else
  1671.           BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^I^n loses ^A^nhis insurance bet of ^A^p'
  1672.                         +ToStr(Round(NodeBet[I]/2))+' ^A^nCyberdollars!', I)
  1673.       end;
  1674.     end;
  1675.     end;
  1676. {    If (NodeHand2[I] <> '') and (HandValue (NodeHand2[I]) < 22) then
  1677.     begin
  1678.       BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^A^n''s second hand: '+ColorHand(NodeHand2[I])+
  1679.                  ' ^A^n(^A^p'+ToStr(HandValue(NodeHand2[I]))+'^A^n)', I);
  1680.       GiveMSG (9, '', '^A^pYour^A^n second hand: '+ColorHand(NodeHand2[I])+
  1681.                  ' ^A^n(^A^p'+ToStr(HandValue(NodeHand2[I]))+'^A^n)', I);
  1682.       If (HandValue (NodeHand2[I]) = 21) and (Length (NodeHand2[I]) = 4) then
  1683.       begin}
  1684.         { Blackjack }{
  1685.         GiveMSG (9, '', '^I^nYou got a ^I^pblackjack^I^n!', I);
  1686.         BroadCastBut (9, '', '^A^p'+NodeUser(I)+' ^A^nhas a ^A^pblackjack^A^n!', I);
  1687.         BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^I^n wins ^A^p'+ToStr(Round(NodeBet[I]*(3/2)))
  1688.                           +' ^A^nCyberdollars!', I);
  1689.         GiveMSG (9, '', '^A^pYou^I^n win ^A^p'+ToStr(Round(NodeBet[I]*(3/2)))+' ^A^nCyberdollars!', I);
  1690.         Inc (NodeCD[I], Round(NodeBet[I]*(3/2)));
  1691.         Writeln (NodeUser(I), ' gets a blackjack.');
  1692.       end
  1693.       else
  1694.       If HandValue (NodeHand2[I]) > DealerValue then
  1695.       begin
  1696.         BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^I^n wins ^A^p'+ToStr(NodeBet[I]*NodeDD2[I])+' ^A^nCyberdollars!',I);
  1697.         GiveMSG (9, '', '^A^pYou^I^n win ^A^p'+ToStr(NodeBet[I]*NodeDD2[I])+' ^A^nCyberdollars!',I);
  1698.         Inc (NodeCD[I], NodeBet[I]*NodeDD2[I]);
  1699.       end
  1700.       else
  1701.       If HandValue (NodeHand2[I]) < DealerValue then
  1702.       begin
  1703.         BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^I^n loses ^A^p'+ToStr(NodeBet[I]*NodeDD2[I])+' ^A^nCyberdollars!',I);
  1704.         GiveMSG (9, '', '^A^pYou^I^n lose ^A^p'+ToStr(NodeBet[I]*NodeDD2[I])+' ^A^nCyberdollars!',I);
  1705.         Dec (NodeCD[I], NodeBet[I]*NodeDD2[I]);
  1706.       end
  1707.       else
  1708.       If HandValue (NodeHand2[I]) = DealerValue then
  1709.       begin
  1710.         BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^A^n loses nothing.',I);
  1711.         GiveMSG (9, '', '^A^pYou^A^n lose nothing.',I);
  1712.       end;
  1713.       If NodeInsure[I] then
  1714.       begin
  1715.         Dec (NodeCD[I], Round (NodeBet[I]/2));
  1716.         GiveMSG (9, '', '^A^pYou^I^n lose ^A^nyour insurance bet of ^A^p'+ToStr(Round(NodeBet[I]/2))
  1717.                  +' ^A^nCyberdollars!', I);
  1718.         If NodeGender (I) then
  1719.           BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^I^n loses ^A^nher insurance bet of ^A^p'
  1720.                         +ToStr(Round(NodeBet[I]/2))+' ^A^nCyberdollars!', I)
  1721.         else
  1722.           BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^I^n loses ^A^nhis insurance bet of ^A^p'
  1723.                         +ToStr(Round(NodeBet[I]/2))+' ^A^nCyberdollars!', I)
  1724.       end;
  1725.     end;}
  1726.   end;
  1727.   GamePlaying := False;
  1728.   SecPassed := 0;
  1729.   For I := 1 to 255 do
  1730.   begin
  1731.     If NodeStat[I] = 2 then NodeStat[I] := 1;
  1732.     For H := 1 to 6 do
  1733.     begin
  1734.       NodeHand[H, I] := '';
  1735.       NodeDD[H, I] := 1;
  1736.       NodeDoneH[H, I] := False;
  1737.     end;
  1738.     NodeNumHands[I] := 0;
  1739.     NodeInsure[I] := False;
  1740.   end;
  1741. end;
  1742.  
  1743. Procedure BootUser;
  1744. begin
  1745.   GiveMSG (9, '', #7'^I^nYou have been thrown out of the ^I^pblackjack^I^n game for taking too long!', NodeTurn);
  1746.   BroadCastBut (9, '', '^A^nThe ^A^pBlackjack dealer^A^n has thrown ^A^p'+NodeUser(NodeTurn)
  1747.                 +'^A^n out of the game for taking too long!', NodeTurn);
  1748.   NodeStat[NodeTurn] := 0;
  1749.   Dec (NodeCD[NodeTurn], NodeBet[NodeTurn]);
  1750.   WaitSec;
  1751.   NextPlayer;
  1752. end;
  1753.  
  1754. Procedure RunBJ;
  1755. Var
  1756.   ch : Char;
  1757. begin
  1758.   ch := #0;
  1759.   OldSec := 0;
  1760.   SecPassed := 0;
  1761.   GamePlaying := False;
  1762.   Repeat
  1763.     GetTime (L, L, Sec, L);
  1764.     If Sec <> OldSec then
  1765.     begin
  1766.       OldSec := Sec;
  1767.       Inc (SecPassed);
  1768.     end;
  1769.     If not GamePlaying and (SecPassed > ConfigData.TimeBetweenGames) then StartGame;
  1770.     If GamePlaying and (SecPassed = ConfigData.FirstWarn) then WarnUser;
  1771.     If GamePlaying and (SecPassed = ConfigData.SecondWarn) then WarnUser;
  1772.     If GamePlaying and (SecPassed = ConfigData.BootFromBJ) then BootUser;
  1773.     If MSGWait then GetMSGs;
  1774.     TimeSlice (2);
  1775.     If (NodeTurn = -1) and (GamePlaying) then DealerPlay;
  1776.     If Keypressed then ch := Readkey;
  1777.   Until ch = #27;
  1778. end;
  1779.  
  1780. begin
  1781.   InitProgram;
  1782.   InitTOP;
  1783.   InitScreen;
  1784.   InitVars;
  1785.   RunBJ;
  1786.   DeInit;
  1787. end.
  1788.