 Rem File: Cmd208.bas
 Rem Sub: Reboot.System
 Rem $Include: 'dndbbs.inc'

 On Error Goto Main.Error
 If Chained=0 Then ' local mode
    Call Get.Node
    Call Open.Arrays
    Call Get.Config
    Call Increase.Files
    Call Make.FileNames
    Call Reset.Cursor
    Call Detect.Share
    Call Open.Files
    Call Read.Options
    Call Valid.Node
    Call Save.Screen2(0)
    Color 14,0
    Print "DNDBBS CMD208 - |Reboot"
    Var$=Nul
    If Command$<>Nul Then
       Var$=Command$
    Endif
    Call Alt.Login(Var,Var$)
    If Var=False Then
       If Lost.Carrier=False Then
          Color 14,0
          Print "Codename not found."
       Endif
       Call More.Prompt
       Goto Main.Resume
    Endif
    Call Search.Mess.File(User.Index,Var1)
    If Var1 Then
       Color 14,0
       Print "Codename is in use."
       Call More.Prompt
       Goto Main.Resume
    Endif
    Call Get.User.Stats(Var)
    Timeon=Timeit!
    Time.Left=3600!
 Endif
 Call Reboot.System
Main.Resume:
 If Chained=-2 Then
    Chain DND.Path+"DNDBBS.EXE"
 Endif
 Call Clear.Status.Line
 Call ScreenANSI(1,37,7)
 Color 7, 0
 Cls
 Call Save.Screen2(-1)
' Locate Max.Row,1,1
 If TempX=0 Then TempX=1
 Locate TempX,1,1
 Color 15,0
 Print
 Print "Now exiting |Reboot.."
 Color 7,0
 Call Decrease.Files
 End
Main.Error:
 Resume Main.Resume

Sub Reboot.System
 On Local Error Goto ErrorTrp40
 Gosub Get.Config
 Call Reboot.Status.Line
 If Windows.Detected Then
    Do While Lost.Carrier=False
       Graphics.Off=False
       Strng="Reboot selection:"
       Call IO.O
       Graphics.Off=True
       If Dir$("reboot.exe")<>"" Then
          If Local.Mode Then
             If Option2 Then
                Strng="(A)bort"
                Call IO.O
             Endif
             If Option3 Then
                Strng="(B)abort all"
                Call IO.O
             Endif
          Endif
       Endif
       If Option4 Then
          Strng="(L)ist"
          Call IO.O
       Endif
       If Option5 Then
          Strng="(R)estart"
          Call IO.O
       Endif
       If Option6 Then
          Strng="(S)hutdown"
          Call IO.O
       Endif
       If Dir$("reboot.exe")<>"" Then
          If Local.Mode Then
             If Option7 Then
                Strng="(X)restart all"
                Call IO.O
             Endif
             If Option8 Then
                Strng="(Y)shutdown all"
                Call IO.O
             Endif
          Endif
       Endif
       Graphics.Off=False
       No.Input.Out=""
       Strng="Enter reboot selection(Q to Quit,<enter>=prompts)? "
       Call IO.I
       Var$=Lcase$(Out2)
       Select Case Var$
       Case "a" ' abort
          If Option2 Then
             If Dir$("reboot.exe")<>"" Then
                If Local.Mode Then
                   Call Clear.Status.Line
                   Shell "reboot.exe /ABORT"
                   Exit Sub
                Endif
             Endif
          Endif
       Case "b" ' abortall
          If Option3 Then
             If Dir$("reboot.exe")<>"" Then
                If Local.Mode Then
                   Call Clear.Status.Line
                   Shell "reboot.exe /ABORTALL"
                   Exit Sub
                Endif
             Endif
          Endif
       Case "x" ' restart all
          If Option7 Then
             If Dir$("reboot.exe")<>"" Then
                If Local.Mode Then
                   Call Clear.Status.Line
                   Shell "reboot.exe /ALL"
                   Exit Sub
                Endif
             Endif
          Endif
       Case "y" ' shutdown all
          If Option8 Then
             If Dir$("reboot.exe")<>"" Then
                If Local.Mode Then
                   Call Clear.Status.Line
                   Shell "reboot.exe /ALLX"
                   Exit Sub
                Endif
             Endif
          Endif
       Case "l" ' list
          If Option4 Then
             ' get local computer name
             Call Get.Machine.Name(VarQ$)

             ' make filenames for shell
             Filename$="dndtmp"+NodeX+".bat"
             Filename1$="dndtmp"+NodeX+".txt"
             Filename2$="dndtmp"+NodeX+".lst"
             Close #TempFile1
             Open Filename$ For Output As #TempFile1
             Print #TempFile1,"@echo off"
             Print #TempFile1,"ipconfig | find "+Chr$(34)+"IPv4"+Chr$(34)+" > "+Filename1$
             Print #TempFile1,"net view > "+Filename2$
             Print #TempFile1,"exit"
             Close #TempFile1

             ' perform shell
             Call Close.Files
             Call ScreenANSI(4,37,7)
             Shell Filename$
             Call Open.Shell.Files

             ' get IP address of local computer
             Var=3
             Close #TempFile1
             Open Filename1$ For Input As TempFile1
             If Eof(TempFile1)=0 Then
                Line Input #TempFile1,VarX$
                If Lcase$(Left$(VarX$,22))="program too big to fit" Then
                   VarX$=Nul
                Else
                   Var1=Instr(VarX$,":")
                   If Var1 Then
                      VarX$=Mid$(VarX$,Var1+1)
                      If VarQ$=Nul Then
                         Strng="This computer:"+VarX$
                         Var=Var+1
                         Call IO.O
                      Endif
                   Else
                      VarX$=Nul
                   Endif
                Endif
             Endif

             ' read all netpaths
             Graphics.Off=False
             Strng="The following net paths were found:"
             Call IO.O
             Strng="Server Name            Remark"
             Call IO.O
             Strng=String$(40,"-")
             Call IO.O
             Graphics.Off=True
             Close #TempFile1
             Open Filename2$ For Input As TempFile1
             VarX=0
             Do
                If Lost.Carrier Then
                   Exit Do
                Endif
                If Eof(TempFile1) Then
                   Exit Do
                Endif
                Line Input #TempFile1,Var$
                If Lcase$(Left$(Var$,22))="program too big to fit" Then
                   Strng="Error reading net view. Use Shroom."
                   Call IO.O
                   VarX=-1
                   Exit Do
                Endif
                If Left$(Var$,2) = "\\" Then
                   Strng=Var$
                   Call IO.O
                   VarZ$=Left$(Var$,23)
                   VarZ$=Mid$(VarZ$,3)
                   VarZ$=Rtrim$(VarZ$)
                   If VarZ$=VarQ$ Then
                      If Len(VarX$) Then
                         Strng="   ("+Ltrim$(VarX$)+")"
                         Call IO.O
                         Var=Var+1
                      Endif
                   Endif
                   VarX=-1
                   Var=Var+1
                   If Var>=User.Pagelength-2 Then
                      Var=False
                      If Continuous=False Then
                         Call More.Prompt
                         If No Or Quit Then
                            Exit Do
                         Endif
                      Endif
                   Endif
                Endif
             Loop
             If VarX=0 Then
                Strng="No nets found."
                Call IO.O
             Endif
             If Var Then
                Call More.Prompt
             Endif
          Endif
       Case "r" ' reboot
          If Option5 Then
             VarX=0
             Exit Do
          Endif
       Case "s" ' shutdown
          If Option6 Then
             VarX=-1
             Exit Do
          Endif
       Case "q"
          Exit Sub
       Case ""
          Exit Do
       End Select
    Loop
    Do
       If Lost.Carrier Then
          Exit Sub
       Endif
       Graphics.Off=False
       Strng="Reboot type selection:"
       Call IO.O
       Graphics.Off=True
       If Option13 Then
          Strng="(L)ocal computer"
          Call IO.O
       Endif
       If Option14 Then
          Strng="(R)emote computer"
          Call IO.O
       Endif
       Graphics.Off=False
       No.Input.Out="q"
       Strng="Enter reboot type(Q to Quit)? "
       Call IO.I
       Select Case Ucase$(Out2)
       Case "L"
          If Option13 Then
             VarZ=-1
             Exit Do
          Endif
       Case "R"
          If Option14 Then
             VarZ=-2
             Exit Do
          Endif
       Case "Q"
          Exit Sub
       End Select
    Loop

    ' perform reboot/shutdown remote computer
    If VarZ=-2 Then
       Strng="Enter remote computer name? "
       Call IO.I
       If Lost.Carrier Then
          Exit Sub
       Endif
       If Len(Out2)=0 Then
          Exit Sub
       Endif
       VarZ$=Ucase$(Out2)

       ' check local computer
       Call Get.Machine.Name(VarX$)
       If VarX$=VarZ$ Then
          Strng="Computer is not remote."
          Call IO.O
          Exit Sub
       Endif

       ' shutdown remote computer
       Graphics.Off=True
       No.Input.Out="N"
       If VarX=0 Then
          Strng2="reboot"
       Else
          Strng2="shutdown"
       Endif
       Strng="Are you sure you want to "+Strng2+" remote computer(y/n)? "
       Call IO.I
       If No Then
          Exit Sub
       Endif
       If Lost.Carrier Then
          Exit Sub
       Endif

       ' remote windows reboot/shutdown
       If VarX=0 Then
          ' reboot remote
          Var$="shutdown /r /m \\"+VarZ$+" /t"+Str$(Option1)
          Strng2="Restart"
       Else
          ' shutdown remote
          Var$="shutdown /s /m \\"+VarZ$+" /t"+Str$(Option1)
          Strng2="Shutdown"
       Endif
       If Len(Option2$) Then
          Var$=Var$+" /c "+Chr$(34)+Option2$+Chr$(34)
       Endif
       Call ScreenANSI(1,37,7)
       Color 7,0
       Shell Var$
       Call ScreenANSI(1,37,7)
       Color 7,0
       Call ScreenANSI(2,Max.Row-1,1)
       Locate Max.Row-1,1,1
       Strng=Strng2+" message sent."
       Call IO.O
       Exit Sub
    Endif
 Endif

 ' shutdown local computer
 Graphics.Off=True
 No.Input.Out="N"
 If VarX=0 Then
    Strng2="reboot"
 Else
    Strng2="shutdown"
 Endif
 Strng="Are you sure you want to "+Strng2+" local computer(y/n)? "
 Call IO.I
 If No Then
    Exit Sub
 Endif
 If Lost.Carrier Then
    Exit Sub
 Endif

 REM Starting here logs off user, closes partition,
 REM  attempts to reboot computer, and exits to dos.

 ' record/send reboot message
 If VarX=0 Then
    Strng="Rebooting partition.."
 Else
    Strng="Shutdown partition.."
 Endif
 Call IO.O
 If VarX=0 Then
    OutZ="Reboot Process"
 Else
    OutZ="Shutdown Process"
 Endif
 If Rtrim$(NodeX)=Nul Then
    OutZ=OutZ+" (Node -)."
 Else
    OutZ=OutZ+" (Node "+NodeX+")."
 Endif
 If Node>False Then
    Call Send.Mess(4,SFalse,SFalse,OutZ)
 Endif
 Call Update.DayFile(OutZ,True,False)

 ' clear/store user info
 If User.Index>SFalse Then
    If Chained=-2 Then
       Call Put.User.Record
       Call Clean.Room.Node(Room)
       Call Remove.Vehicle
       Call Update.LastUser
       Call Record.Time(True)
       Call Reset.Keys
    Endif
 Endif

 ' clear local screen
 Call ScreenANSI(1,37,7)
 Color 7,0
 Call ScreenANSI(2,Max.Row,1)
 Locate Max.Row,1,1

 ' clear remote screen
 Graphics.On=True
 Graphics.Off=False
 If Local.Mode=False Then
    Call Modem.ANSI(1,37,7)
 Endif
 Line.Length=1
 No.Echo=True
 Carriage.Return=True
 Strng=Nul
 Call IO.O
 Graphics.On=False

 ' perform DOS reboot/shutdown
 If Windows.Detected=False Then
    Do
       If Lost.Carrier Then
          Gosub Close.Partition
          Exit Do
       Endif
       Graphics.Off=False
       Strng="DOS reboot menu:"
       Call IO.O
       Graphics.Off=True
       If Option9 Then
          Strng="(C)old boot"
          Call IO.O
       Endif
       If Option10 Then
          Strng="(W)arm boot"
          Call IO.O
       Endif
       If Local.Mode=False Then
          If Fossil.Active Then
             If Fossil.Version=1 Then
                If Option11 Then
                   Strng="(F)ossil cold boot"
                   Call IO.O
                Endif
                If Option12 Then
                   Strng="(G)fossil warm boot"
                   Call IO.O
                Endif
             Endif
          Endif
       Endif
       Graphics.Off=False
       No.Input.Out="n"
       Strng="Enter reboot selection(N for none)? "
       Call IO.I
       Select Case Lcase$(Out2)
       Case "n"
          Gosub Close.Partition
          Exit Do
       Case "c"
          ' cold boot
          If Option9 Then
             Gosub Close.Partition
             Def Seg = &h0ffff
             Call Absolute(0)
             Def Seg
             Exit Do
          Endif
       Case "w"
          ' warm boot
          If Option10 Then
             Gosub Close.Partition
             Out &h64,&hF0
             Exit Do
          Endif
       Case "f"
          ' fossil cold boot
          If Option11 Then
             If Local.Mode=False Then
                If Fossil.Active Then
                   If Fossil.Version=1 Then
                      Gosub Close.Partition
                      InregsX.AX=&H1700
                      InregsX.DX=Port
                      Call InterruptX(&H14,InregsX,OutregsX)
                      Exit Do
                   Endif
                Endif
             Endif
          Endif
       Case "g"
          ' fossil warm boot
          If Option12 Then
             If Local.Mode=False Then
                If Fossil.Active Then
                   If Fossil.Version=1 Then
                      Gosub Close.Partition
                      InregsX.AX=&H1701
                      InregsX.DX=Port
                      Call InterruptX(&H14,InregsX,OutregsX)
                      Exit Do
                   Endif
                Endif
             Endif
          Endif
       End Select
    Loop
 Else
    ' perform Windows reboot/shutdown
    Gosub Close.Partition
    If VarX=0 Then
       ' reboot
       Var$="shutdown /r /t"+Str$(Option1)
    Else
       ' shutdown
       Var$="shutdown /s /t"+Str$(Option1)
    Endif
    ' reboot comment
    If Len(Option2$) Then
       Var$=Var$+" /c "+Chr$(34)+Option2$+Chr$(34)
    Endif
    Shell Var$
 Endif

 ' reset partition
 Lost.Carrier=True
 Node.Abort=True
 User.Index=SFalse
 Call Clear.Status.Line
 Graphics.Off=False
 Exit Sub

Close.Partition:
 ' close partition
 Call Clear.Status.Line
 Call Zero.Node(0)
 Call Drop.DTR
 Close
 Call Sleep.Second(2!)
 Return

Get.Config:
 Option1=1
 Option2$="Dndbbs shutdown"
 Option2=True
 Option3=True
 Option4=True
 Option5=True
 Option6=True
 Option7=True
 Option8=True
 Option9=False
 Option10=False
 Option11=True
 Option12=True
 Option13=True
 Option14=True
 VarX2=0
 Do
    VarX2=VarX2+1
    If VarX2>Options.Lines Then
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX2)))
    If Ucase$(Var$)="[REBOOT]" Then
       Do
          VarX2=VarX2+1
          If VarX2>Options.Lines Then
             Return
          Endif
          Var$=Ltrim$(Rtrim$(Options.Array(VarX2)))
          If Ucase$(Var$)="[END]" Then
             Return
          Endif
          Var=Instr(Var$,"=")
          If Var Then
             Var2$=Ltrim$(Rtrim$(Left$(Var$,Var-1)))
             Var3$=Ltrim$(Rtrim$(Mid$(Var$,Var+1)))
             Select Case Lcase$(Var2$)
             Case "restart.time"
                VarY=Int(Val(Var3$))
                If VarY>=0 And VarY<=600 Then
                   Option1=VarY
                Endif
             Case "restart.message"
                If Len(Var3$) Then
                   Option2$=Var3$
                Endif
             Case "allow.abort"
                Select Case Ucase$(Var3$)
                Case "0", "OFF", "FALSE"
                   Option2=False
                Case "-1", "ON", "TRUE"
                   Option2=True
                End Select
             Case "allow.abortall"
                Select Case Ucase$(Var3$)
                Case "0", "OFF", "FALSE"
                   Option3=False
                Case "-1", "ON", "TRUE"
                   Option3=True
                End Select
             Case "allow.listnets"
                Select Case Ucase$(Var3$)
                Case "0", "OFF", "FALSE"
                   Option4=False
                Case "-1", "ON", "TRUE"
                   Option4=True
                End Select
             Case "allow.restart"
                Select Case Ucase$(Var3$)
                Case "0", "OFF", "FALSE"
                   Option5=False
                Case "-1", "ON", "TRUE"
                   Option5=True
                End Select
             Case "allow.shutdown"
                Select Case Ucase$(Var3$)
                Case "0", "OFF", "FALSE"
                   Option6=False
                Case "-1", "ON", "TRUE"
                   Option6=True
                End Select
             Case "allow.restartall"
                Select Case Ucase$(Var3$)
                Case "0", "OFF", "FALSE"
                   Option7=False
                Case "-1", "ON", "TRUE"
                   Option7=True
                End Select
             Case "allow.shutdownall"
                Select Case Ucase$(Var3$)
                Case "0", "OFF", "FALSE"
                   Option8=False
                Case "-1", "ON", "TRUE"
                   Option8=True
                End Select
             Case "allow.dos.coldboot"
                Select Case Ucase$(Var3$)
                Case "0", "OFF", "FALSE"
                   Option9=False
                Case "-1", "ON", "TRUE"
                   Option9=True
                End Select
             Case "allow.dos.warmboot"
                Select Case Ucase$(Var3$)
                Case "0", "OFF", "FALSE"
                   Option10=False
                Case "-1", "ON", "TRUE"
                   Option10=True
                End Select
             Case "allow.dos.fossil.coldboot"
                Select Case Ucase$(Var3$)
                Case "0", "OFF", "FALSE"
                   Option11=False
                Case "-1", "ON", "TRUE"
                   Option11=True
                End Select
             Case "allow.dos.fossil.warmboot"
                Select Case Ucase$(Var3$)
                Case "0", "OFF", "FALSE"
                   Option12=False
                Case "-1", "ON", "TRUE"
                   Option12=True
                End Select
             Case "allow.local.reboot"
                Select Case Ucase$(Var3$)
                Case "0", "OFF", "FALSE"
                   Option13=False
                Case "-1", "ON", "TRUE"
                   Option13=True
                End Select
             Case "allow.remote.reboot"
                Select Case Ucase$(Var3$)
                Case "0", "OFF", "FALSE"
                   Option14=False
                Case "-1", "ON", "TRUE"
                   Option14=True
                End Select
             End Select
          Endif
       Loop
    Endif
 Loop
 Return
ErrorRsm40:
 Exit Sub
ErrorTrp40:
 Resume ErrorRsm40
End Sub

' store default server name
Sub Get.Machine.Name(VarX$)
 On Local Error Goto ErrorTrap19z
 DIM Default.Net AS STRING * 16
 VarX$ = Nul
 Default.Net = Nul
 InregsX.AX = &H5E00
 InregsX.DS = VARSEG(Default.Net)
 InregsX.DX = VARPTR(Default.Net)
 CALL InterruptX(&H21, InregsX, OutregsX)
 ' check error flag.
 IF (OutregsX.Flags AND &H1) = &H0 THEN
    ' read CH
    VarS = (OutregsX.CX AND &HFF00) / 256
    IF VarS > 0 THEN ' valid name.
       VarX$ = Default.Net
       Imbedded = INSTR(VarX$, CHR$(0))
       IF Imbedded THEN
          VarX$ = LEFT$(VarX$, Imbedded - 1)
       END IF
       VarX$ = UCASE$(RTRIM$(VarX$))
       EXIT SUB
    END IF
 END IF
 ' check net path.
 If VarX$ = Nul Then
    Var$ = Environ$("COMPUTERNAME")
    If Len(Var$) Then
       VarX$ = Var$
    Endif
 Endif
ErrorResume19z:
 Exit Sub
ErrorTrap19z:
 Resume ErrorResume19z
End Sub

Sub Update.LastUser
 On Local Error Goto ErrorTrap18
 Strng=UserRecord.CodeName
 Strng=Lcase$(Strng)
 Mid$(Strng,1,1)=Ucase$(Mid$(Strng,1,1))
 Strng=Strng+" "+Time.On+" "+Format$(Now,"hh:mm:ss")
 Time1$=Format$(Now,"hh:mm:ss")
 OnTime#=TimeValue(Time1$)-TimeValue(Time.On)
 If OnTime#<False Then
    OnTime#=OnTime#+TimeValue("12:00:00")*2
 Endif
 Temp$=Format$(OnTime#,"hh:mm:ss")
 Strng=Strng+" "+Temp$
 Var#=Permanent.Killed*UserRecord.Level*10+ _
    Players.Killed*UserRecord.Level*2+ _
    Monsters.Killed*UserRecord.Level
 If Var#=DFalse Then
    Strng=Strng+" Zero"
 Else
    Strng=Strng+Str$(Var#)
 Endif
 Call Update.DayFile(Strng,UnTrue,0)
ErrorResume18:
 Exit Sub
ErrorTrap18:
 Resume ErrorResume18
End Sub

Sub Zero.Node(Var)
 On Local Error Goto ErrorTrap6
 Var2=Var
 If Var2<>-1 Then
    Var2=0
 Endif
 Call Clear.Node(Var2)
 VarX=Node+1
 Call Write.Message.Record(MessWorkFile1,VarX)
 Call Clear.Node7
 Call Write.Message.Record(MessWorkFile7,VarX)
ErrorResume6:
 Exit Sub
ErrorTrap6:
 Resume ErrorResume6
End Sub

Sub Drop.DTR
 On Local Error Goto Error.Trap46a
 ' check door mode
 If BBS.Mode Then
    Exit Sub
 Endif
 ' check local node
 If Port=-1 Then
    Exit Sub
 Endif
 ' check local login
 If Local.Mode Then
    Exit Sub
 Endif
 ' check fossil
 If Fossil.Active=False Then
    Call Get.MCR(VarZ)
    If VarZ>0 Then
       ' drop dtr
       Out VarZ,0
    Endif
    Exit Sub
 Endif
 ' drop dtr using fossil
 If Fossil.Version=1 Then
    Call Extended.Driver2(31,0) ' x00 1Fh
 Else
    Call Extended.Driver2(6,0) ' fossil set dtr
 Endif
Error.Resume46a:
 Exit Sub
Error.Trap46a:
 Resume Error.Resume46a
End Sub

Sub Reset.Keys
 On Local Error Goto ErrorTrp26x
 For Var=1 To 10
    Var2$=Chr$(27)+"[0;"+Mid$(Str$(Var+58),2)
    Var2$=Var2$+";0;"+Mid$(Str$(Var+58),2)+"p"
    If Local.Mode=False Then
       If Remote.ANSI.Color Then
          Call Put.Modem(Var2$)
       Endif
    Else
       If Local.ANSI.Color Then
          Call Put.Screen(Var2$)
       Endif
    Endif
 Next
ErrorRsm26x:
 Exit Sub
ErrorTrp26x:
 Resume ErrorRsm26x
End Sub

' get modem control register port address
Sub Get.MCR(VarZ)
 On Local Error Goto Error.Trap46b
 VarX=Base.Address
 If VarX>0 Then
    ' set mcr address
    VarZ=VarX+4
    Exit Sub
 Endif
 ' default port address
 Select Case Port
 Case 0
    VarY=&H3F8
 Case 1
    VarY=&H2F8
 Case 2
    VarY=&H3E8
 Case 3
    VarY=&H2E8
 Case 4
    VarY=&H3E0
 Case 5
    VarY=&H2E0
 Case 6
    VarY=&H338
 Case 7
    VarY=&H238
 Case Else
    VarZ=0
    Exit Sub
 End Select
 ' set mcr address
 VarZ=VarY+4
Error.Resume46b:
 Exit Sub
Error.Trap46b:
 Resume Error.Resume46b
End Sub

' lower/raise dtr, get x00 status
Sub Extended.Driver2(Var,Var2)
 On Local Error Goto Error.Trap50x
 Select Case Var
 Case 4 ' detect fossil 2
    InregsX.AX=&H0400
 Case 6 ' line dtr io fossil
    InregsX.AX=&H0600+Var2
 Case 28 ' detect fossil 1 (x00)
    InregsX.AX=&H1C00
 Case 31 ' line dtr io x00
    InregsX.AX=&H1F01
    InregsX.BX=Var2
 End Select
 InregsX.DX=Port
 Call InterruptX(&H14,InregsX,OutregsX)
Error.Resume50x:
 Exit Sub
Error.Trap50x:
 Resume Error.Resume50x
End Sub

Sub Clear.Node(Var)
 On Local Error Goto ErrorTrap9
 Call Get.Machine.Name(Var$)
 MessWorkRecord1.MachineName=Var$
 If Var Then
    MessWorkRecord1.PortNumber=Port+1
 Else   
    MessWorkRecord1.PortNumber=False
 Endif
 MessWorkRecord1.ActiveNode=Var
 MessWorkRecord1.Monitor=False
 MessWorkRecord1.Chatting=False
 MessWorkRecord1.RoomNumber=SFalse
 MessWorkRecord1.UserIndex=SFalse
 MessWorkRecord1.UserName=Offline$
 MessWorkRecord1.ClassName=Offline$
 MessWorkRecord1.OfferTime=SFalse
 MessWorkRecord1.GoldFor=DFalse
 MessWorkRecord1.ItemFor=SFalse
 MessWorkRecord1.ForCharges=False
 MessWorkRecord1.GoldOffer=DFalse
 MessWorkRecord1.ItemOffer=SFalse
 MessWorkRecord1.OfferCharges=False
 MessWorkRecord1.ContainerOffer=False
 MessWorkRecord1.ContainerFor=False
 MessWorkRecord1.LastMonster=SFalse
 MessWorkRecord1.LastUser=SFalse
 MessWorkRecord1.SendFlags=String$(MaxNodes+1,"1")
 MessWorkRecord1.ReceiveFlags=String$(MaxNodes+1,"1")
ErrorResume9:
 Exit Sub
ErrorTrap9:
 Resume ErrorResume9
End Sub

Sub Clear.Node7
 On Local Error Goto ErrorTrap10
 MessWorkRecord7.Flags1=False
 MessWorkRecord7.Flags2=False
 MessWorkRecord7.Flags3=False
 MessWorkRecord7.Flags4=False
 MessWorkRecord7.Flags5=False
ErrorResume10:
 Exit Sub
ErrorTrap10:
 Resume ErrorResume10
End Sub

Sub Reboot.Status.Line
 On Local Error Goto Error.Trap60
 Temp$=UserRecord.CodeName
 Temp$=Rtrim$(Temp$)
 Temp$=Lcase$(Temp$)
 Mid$(Temp$,1,1)=Ucase$(Mid$(Temp$,1,1))
 Temp$=Temp$+" > "
 Temp$=Temp$+"reboot menu: "+Fclock$
 Temp$=Left$(Temp$,79)
 Temp$=Temp$+Space$(79-Len(Temp$))
 Call Display.Status.Line(True)
Error.Resume60:
 Exit Sub
Error.Trap60:
 Resume Error.Resume60
End Sub

Sub Clear.Status.Line
 On Local Error Goto Error.Trap58a
 Temp$=Space$(79)
 Call Display.Status.Line(False)
Error.Resume58a:
 Exit Sub
Error.Trap58a:
 Resume Error.Resume58a
End Sub

Sub Alt.Login(Var,Var$)
 On Local Error Goto ErrorTrp25
 If Instr(Var$,"/N:") Then
    Var$=Left$(Var$,Instr(Var$,"/N:")-1)
 Endif
 Out2=Nul
 Var=False
 If Len(Var$) Then
    Var2=Instr(Var$,Chr$(34))
    If Var2 Then
       Var$=Mid$(Var$,Var2+1)
       Var2=Instr(Var$,Chr$(34))
       If Var2 Then
          Out2=Left$(Var$,Var2-1)
          If Out2=Nul Then
             Exit Sub
          Endif
       Else
          Exit Sub
       Endif
    Else
       Exit Sub
    Endif
 Endif
Start.Login:
 If Out2=Nul Then
    Graphics.Off=False
    Strng="Enter codename(?=list,*=search): "
    Call IO.I
 Endif
 Strng=Lcase$(Rtrim$(Out2))
 Out2=Nul
 If Len(Strng)=0 Then
    Exit Sub
 Endif
 If Strng="?" Then
    Temp1=False
    For Temp1!=1! To Lof(UserFile)/UserRecLen
       Call Read.Record(UserFile,Temp1!)
       Out3=UserRecord.CodeName
       Out3=Lcase$(Rtrim$(Out3))
       If Out3<>"<deleted>" Then
          Strng=Out3
          Mid$(Strng,1,1)=Ucase$(Mid$(Strng,1,1))
          Strng=Rtrim$(UserRecord.Prefix1)+Strng
          Call Convert.ANSI(True,VarQ,VarR)
          Carriage.Return=True
          Graphics.On=True
          Call IO.O
          Graphics.On=False
          Strng=Strng+" (level "+Form$(Cdbl(UserRecord.Level))+")"
          If UserRecord.ClassType=AsstDM Then
             Strng=Strng+" [AsstDM]"
          Endif
          If UserRecord.ClassType=DM Then
             Strng=Strng+" [DM]"
          Endif
          If UserRecord.Flags And Special.Char4 Then
             Strng=Strng+" [Sysop]"
          Endif
          Call Search.Mess.File(Temp1!,Var1)
          If Var1 Then
             Strng=Strng+" {online}"
          Endif
          Call IO.O
          Temp1=Temp1+1
          If Temp1>=User.Pagelength-2 Then
             Temp1=False
             Call More.Prompt
             If No Or Quit Then
                Exit For
             Endif
          Endif
       Endif
    Next
    If Temp1 Then
       Call More.Prompt
    Endif
    Out2=Nul
    Goto Start.Login
 Endif
 If Strng="*" Then
    Strng="Enter codename search(?,* allowed): "
    Call IO.I
    Var2$=Lcase$(Out2)
    Temp1=False
    Var2=False
    For Temp1!=1! To Lof(UserFile)/UserRecLen
       Call Read.Record(UserFile,Temp1!)
       Out3=UserRecord.CodeName
       Out3=Lcase$(Rtrim$(Out3))
       If Out3<>"<deleted>" Then
          Out2=Var2$
          Call InstrSUB2(VarX)
          If VarX Then
             Var2=True
             Strng=Out3
             Mid$(Strng,1,1)=Ucase$(Mid$(Strng,1,1))
             Strng=Rtrim$(UserRecord.Prefix1)+Strng
             Call Convert.ANSI(True,VarQ,VarR)
             Carriage.Return=True
             Graphics.On=True
             Call IO.O
             Graphics.On=False
             Strng=Strng+" (level "+Form$(Cdbl(UserRecord.Level))+")"
             If UserRecord.ClassType=AsstDM Then
                Strng=Strng+" [AsstDM]"
             Endif
             If UserRecord.ClassType=DM Then
                Strng=Strng+" [DM]"
             Endif
             If UserRecord.Flags And Special.Char4 Then
                Strng=Strng+" [Sysop]"
             Endif
             Call Search.Mess.File(Temp1!,Var1)
             If Var1 Then
                Strng=Strng+" {online}"
             Endif
             Call IO.O
             Temp1=Temp1+1
             If Temp1>=User.Pagelength-2 Then
                Temp1=False
                Call More.Prompt
                If No Or Quit Then
                   Exit For
                Endif
             Endif
          Endif
       Endif
    Next
    If Var2=False Then
       Strng="Codename not found."
       Call IO.O
    Endif
    If Temp1 Then
       Call More.Prompt
    Endif
    Out2=Nul
    Goto Start.Login
 Endif
 For User.Index=1! To Lof(UserFile)/UserRecLen
    Call Read.Record(UserFile,User.Index)
    Out3=UserRecord.CodeName
    Out3=Lcase$(Rtrim$(Out3))
    If Strng=Out3 Then
       Var=True ' valid name
       Exit Sub
    Endif
 Next
 User.Index=SFalse
 Exit Sub
ErrorRsm25:
 Exit Sub
ErrorTrp25:
 Security.Guard=False
 Resume ErrorRsm25
End Sub

Sub Get.Node
 On Local Error Goto Node.Error
 Var$=Command$
 Var$=Ltrim$(Rtrim$(Var$))
 If Instr(Var$,"/N:") Then
    Var$=Mid$(Var$,Instr(Var$,"/N:")+3)
    Select Case Len(Var$)
    Case 0
       Node=0
       NodeX=Nul
       Exit Sub
    Case 1 ' 0-9,A-Z
       Select Case Var$
       Case "0" To "9"
          Node=Val(Var$)+1
          NodeX=Var$
       Case "A" To "Z"
          Node=Asc(Var$)-54
          NodeX=Var$
       Case Else
          Goto Node.Error
       End Select
    Case 2 ' 10-99
       VarX=Int(Val(Var$))
       If VarX>=10 And VarX<=99 Then
          Node=VarX+27 ' 37-126
          NodeX=Mid$(Str$(VarX),2) ' 10-99
       Else
          Goto Node.Error
       Endif
    Case Else
       Goto Node.Error
    End Select
 Endif
 Exit Sub
Node.Error:
 Color 14,0
 Out2="CMD208 Module - |Reboot"+Chr$(13)+Chr$(10)
 Out3="Error reading node. Node must be <nul>,0-9,A-Z,10-99."
 Call Terminate.Program
End Sub

Sub Valid.Node
 On Local Error Goto ErrorTrap11
 If Node>=False And Node<=MaxNodes Then
    VarX2=Node+1
    Call Read.Message.Record(MessWorkFile1,VarX2)
    If MessWorkRecord1.ActiveNode Then
       If Rtrim$(NodeX)=Nul Then
          Strng="Node -, already active."
       Else
          Strng="Node "+NodeX+", already active."
       Endif
       Goto ErrorTrap11
    Else
       Strng=Rtrim$(MessWorkRecord1.UserName)
       Call Valid.Name(Strng)
       If TempA Then
          If Rtrim$(NodeX)=Nul Then
             Strng="Node -, active codename."
          Else
             Strng="Node "+NodeX+", active codename."
          Endif
          Goto ErrorTrap11
       Endif
    Endif
 Else
    Strng="Node '"+NodeX+"' is not a valid node number."
    Goto ErrorTrap11
 Endif
ErrorResume11:
 Exit Sub
ErrorTrap11:
 Color 14,0
 Out2="CMD208 Module - |Reboot"+Chr$(13)+Chr$(10)
 Out3=Strng
 Call Terminate.Program
End Sub

Sub Open.Arrays
 On Local Error Goto Array.Error
 Call Plex.Function(26)
 If (OutregsX.AX And &HFF)=&HFF Then
    Local.ANSI.Color=True
 Else
    Local.ANSI.Color=False
 Endif
 Local.Avatar.Color=False
 Call Plex.Function(27)
 If (OutregsX.AX And &HFF)=&HFF Then
    If (OutregsX.DX And &HFF)=&H16 Then
       Local.Avatar.Color=True
    Endif
 Endif
 Local.Mode=True
 Lost.Carrier=False
 Call Read.Rows(Max.Row)
 Locate Max.Row,1,1
 Call VideoInt(15,0)
 Video.Page=OutregsX.BX
Redim Alignment.Name1(1 To MaxAlignment) As String*7,_
 Alignment.Name2(1 To MaxAlignment) As String*7,_
 Class.Name(1 To MaxClassNames) As String*15,_
 Direction(1 To MaxDirections) As String*9,_
 High.Class.Name(1 To MaxClassNames) As String*15,_
 InventoryNames(1 To MaxItems) As String*8,_
 Numeral(1 To MaxNumerals) As String*5,_
 Race(1 To MaxRaces) As String*8,_
 Room.Array(1 To MaxRoomArrays) As String*40,_
 Stat(1 To MaxStats) As String*12,_
 Training.Stats(1 To MaxClassNames,1 To MaxTrainStats) As Integer,_
 Weapon.Type.Name(1 To MaxWeapons) As String*9
 Exit Sub
Array.Error:
 Color 14,0
 Out2="CMD208 Module - |Reboot"+Chr$(13)+Chr$(10)
 Out3="Error opening arrays. Free more RAM."
 Call Terminate.Program
End Sub

Sub Get.Config
 On Local Error Goto Config.Error
 DND.Path=Environ$("DNDBBS")
 If DND.Path<>Nul Then
    If Right$(DND.Path,1)<>"\" Then
       DND.Path=DND.Path+"\"
    Endif
 Endif
 FileName=DND.Path+"DND"+NodeX+".CFG"
 Close #TempFile1
 Open FileName For Input Shared As #TempFile1
 Line Input #TempFile1,Var$
 For Temp1=1 To MaxConfigArray1
    Input #TempFile1,Var!
 Next
 For Temp1=1 To MaxConfigArray2
    Input #TempFile1,Var%
    Select Case Temp1
    Case 48
       Allow.High.Class=Var%
    Case 81
       Allow.Remote.Edit=Var%
    Case 86
       User.Echo=Var%
    Case 87
       User.Linefeeds=Var%
    Case 88
       User.Linelength=Var%
    Case 89
       User.Pagelength=Var%
    Case 90
       User.Wordwrap=Var%
    Case 111
       Disable.DM=Var%
    Case 112
       Disable.Nodes=Var%
    Case 113
       Disable.Sysop=Var%
    End Select
 Next
 For Temp1=1 To MaxConfigArray3
    Line Input #TempFile1,Var$
    Select Case Temp1
    Case 1
       Prelog.FileName=Var$
    Case 3
       Welcome.FileName=Var$
    Case 4
       Notice.FileName=Var$
    Case 11
       Data.Path1=Var$
    Case 12
       MonClass.FileName=Var$
    Case 13
       MonTalk.FileName=Var$
    Case 15
       File.Extension1=Var$
    Case 16
       Room.FileName=Var$
    Case 17
       Object.FileName=Var$
    Case 18
       Monster.FileName=Var$
    Case 19
       Treasure.FileName=Var$
    Case 20
       Spell.FileName=Var$
    Case 21
       User.FileName=Var$
    Case 22
       NonPlayer.FileName=Var$
    Case 28
       Logoff.FileName=Var$
    Case 38
       Logoff.Help.FileName=Var$
    Case 51
       Usage.FileName=Var$
    Case 52
       Data.Path2=Var$
    Case 53
       Data.Path3=Var$
    Case 54
       Data.Path4=Var$
    Case 55
       Help.FileName1=Var$
    Case 56
       Help.Filename2=Var$
    Case 57
       Team.FileName=Var$
    Case 58
       Public.FileName=Var$
    Case 59
       Message.Base.FileName=Var$
    Case 60
       Private.FileName=Var$
    Case 61
       Help.FileName3=Var$
    Case 62
       File.Extension2=Var$
    Case 65
       Catalog.FileName=Var$
    Case 68
       MessWork.FileName=Var$
    Case 71
       Action.FileName=Var$
    Case 72
       Day.File.FileName=Var$
    Case 76
       Help.FileName4=Var$
    Case 80
       Container.FileName=Var$
    Case 85
       ANSIPrefixChar=Var$
    Case 86
       UserInv.FileName=Var$
    Case 87
       CtnInv.FileName=Var$
    Case 88
       TeamInv.FileName=Var$
    Case 89
       RoomInv.FileName=Var$
    Case 90
       MonInv.FileName=Var$
    Case 91
       Inline.FileName2=Var$
    Case 92
       Inline.FileName1=Var$
    Case 93
       Room.Desc.FileName=Var$
    End Select
 Next
 For Temp1=1 To 10
    For Temp2=1 To 4
       Input #TempFile1,Training.Stats(Temp1,Temp2)
    Next
 Next
 For Temp1=1 To 20
    Line Input #TempFile1,Room.Array(Temp1)
 Next
 MessWork.FileName=Data.Path3+MessWork.FileName
 For Temp1=1 To 10
    Line Input #TempFile1,High.Class.Name(Temp1)
 Next
 For Temp1=1 To 8
    Line Input #TempFile1,Race(Temp1)
 Next
 For Temp1=1 To 10
    Line Input #TempFile1,Class.Name(Temp1)
 Next
 For Temp1=1 To 7
    Line Input #TempFile1,Stat(Temp1)
 Next
 For Temp1=1 To 12
    Line Input #TempFile1,Direction(Temp1)
 Next
 For Temp1=1 To 10
    Line Input #TempFile1,Numeral(Temp1)
 Next
 For Temp1=1 To 4
    Line Input #TempFile1,Weapon.Type.Name(Temp1)
 Next
 For Temp1=1 To 3
    Line Input #TempFile1,Alignment.Name1(Temp1)
 Next
 For Temp1=1 To 3
    Line Input #TempFile1,Alignment.Name2(Temp1)
 Next
 For Temp1=1 To MaxUserCommands
    Line Input #TempFile1,Var$
    For Temp2=1 To 3
       Line Input #TempFile1,Var$
    Next
    Input #TempFile1,Var%
    For Temp2=1 To 8
       Input #TempFile1,Var%
    Next
    For Temp2=1 To 4
       Input #TempFile1,Var%
    Next
    Input #TempFile1,Var%
    Input #TempFile1,Var%
 Next
 For Temp1=1 To MaxDMcommands
    Line Input #TempFile1,Var$
    Input #TempFile1,Var%
    For Temp2=1 To 3
       Input #TempFile1,Var%
    Next
 Next
 For Temp1=1 To MaxSysopCommands
    Line Input #TempFile1,Var$
    Input #TempFile1,Var%
 Next
 For Temp1=1 To MaxNodeCommands
    Line Input #TempFile1,Var$
    For Temp2=1 To 8
       Input #TempFile1,Var%
    Next
 Next
 For Temp1=1 To MaxLetters
    Input #TempFile1,Var%
 Next
 For Temp1=1 To MaxStrips
    Line Input #TempFile1,Var$
 Next
 For Temp1=1 To 10
    Line Input #TempFile1,Var$
    Input #TempFile1,Var%
    Input #TempFile1,Var%
 Next
 For Temp1=1 To 10
    Line Input #TempFile1,InventoryNames(Temp1)
 Next
 Exit Sub
Config.Error:
 Color 14,0
 Out2="CMD208 Module - |Reboot"+Chr$(13)+Chr$(10)
 Out3="Error reading "+Lcase$(FileName)+" (error:"+Str$(Err)+"). Run Dndcnfg."
 Call Terminate.Program
End Sub

Sub Increase.Files
 On Local Error Goto Increase.Error
 Close
 Call StdinInt(62,0)
 PSP.Segment=OutregsX.BX
 Def Seg=PSP.Segment
 Command.Line=&H80
 Command.Tail=Command.Line+60
 For Var=1 To 54
    Poke Command.Tail+Var-1,&HFF
 Next
 For Var=1 To 4
    File.Handle=Peek(&H18+Var-1)
    Poke Command.Tail+Var-1,File.Handle
 Next
 Poke &H32,54
 Poke &H34,Command.Tail
 Def Seg
 Close
 Exit Sub
Increase.Error:
 Color 14,0
 Out2="Error increasing file handles."+Chr$(13)+Chr$(10)
 Out3="Increase files= in config.sys or config.nt, or run Dndcnfg."
 Call Terminate.Program
End Sub

Sub Make.FileNames
 On Local Error Goto Make.Error
 Out2=Environ$("DNDDAT")
 If Out2<>Nul Then
    If Right$(Out2,1)<>"\" Then
       Out2=Out2+"\"
    Endif
    Data.Path1=Out2
 Endif
 Out2=Environ$("DNDDOC")
 If Out2<>Nul Then
    If Right$(Out2,1)<>"\" Then
       Out2=Out2+"\"
    Endif
    Data.Path2=Out2
 Endif
 Out2=Environ$("DNDTEMP")
 If Out2<>Nul Then
    If Right$(Out2,1)<>"\" Then
       Out2=Out2+"\"
    Endif
    Data.Path3=Out2
 Endif
 Out2=Environ$("DNDMESS")
 If Out2<>Nul Then
    If Right$(Out2,1)<>"\" Then
       Out2=Out2+"\"
    Endif
    Data.Path4=Out2
 Endif
 DOS.Exit="EDTDOS"+Rtrim$(NodeX)+".BAT"
 Day.File.FileName=Data.Path1+Day.File.FileName
 Catalog.FileName=Data.Path2+Catalog.FileName+File.Extension2
 Logoff.FileName=Data.Path1+Logoff.FileName+File.Extension1
 Notice.FileName=Data.Path1+Notice.FileName+File.Extension1
 Prelog.FileName=Data.Path1+Prelog.FileName+File.Extension1
 Welcome.FileName=Data.Path1+Welcome.FileName+File.Extension1
 User.FileName=Data.Path1+User.FileName+File.Extension1
 NonPlayer.FileName=Data.Path1+NonPlayer.FileName+File.Extension1
 Room.FileName=Data.Path1+Room.FileName+File.Extension1
 Object.FileName=Data.Path1+Object.FileName+File.Extension1
 Monster.FileName=Data.Path1+Monster.FileName+File.Extension1
 Treasure.FileName=Data.Path1+Treasure.FileName+File.Extension1
 MonTalk.FileName=Data.Path1+MonTalk.FileName+File.Extension1
 MonClass.FileName=Data.Path1+MonClass.FileName+File.Extension1
 Spell.FileName=Data.Path1+Spell.FileName+File.Extension1
 Action.FileName=Data.Path1+Action.FileName+File.Extension1
 Team.FileName=Data.Path1+Team.FileName+File.Extension1
 Container.FileName=Data.Path1+Container.FileName+File.Extension1
 Message.Base.FileName=Data.Path4+Message.Base.FileName+File.Extension1
 Logon.Help.FileName=Data.Path1+Help.FileName3+File.Extension1
 UserInv.FileName=Data.Path1+UserInv.FileName+File.Extension1
 CtnInv.FileName=Data.Path1+CtnInv.FileName+File.Extension1
 TeamInv.FileName=Data.Path1+TeamInv.FileName+File.Extension1
 RoomInv.FileName=Data.Path1+RoomInv.FileName+File.Extension1
 MonInv.FileName=Data.Path1+MonInv.FileName+File.Extension1
 Room.Desc.FileName=Data.Path1+Room.Desc.FileName+File.Extension1
 Usage.FileName=Data.Path1+Usage.FileName+File.Extension1
 Help.FileName1=Data.Path1+Help.FileName1+File.Extension1
 Help.FileName2=Data.Path1+Help.FileName2+File.Extension1
 Logoff.Help.FileName=Data.Path1+Logoff.Help.FileName+File.Extension1
 Exit Sub
Make.Error:
 Color 14,0
 Out2="CMD208 Module - |Reboot"+Chr$(13)+Chr$(10)
 Out3="Error making "+Lcase$(FileName)+" (error:"+Str$(Err)+"). Increase files= in config.sys or run Dndcnfg."+Chr$(13)+Chr$(10)
 Call Terminate.Program
End Sub

Sub Open.Files
 On Local Error Goto Open.Error
 Close
 ActionRecLen=Len(ActionRecord)
 BufferRecLen=Len(BufferRecord)
 ContainerRecLen=Len(ContainerRecord)
 HelpRecLen1=Len(HelpRecord1)
 HelpRecLen2=Len(HelpRecord2)
 HelpRecLen3=Len(HelpRecord3)
 MessBaseRecLen=Len(MessageBaseRecord)
 MessageRecLen=Len(BufferRecord)
 MonsterRecLen=Len(MonsterRecord)
 NewMessRecLen=Len(NewMessages)
 TableRecLen=Len(TableRecord)
 UserRecLen=Len(UserRecord)
 UserProfileRecLen=Len(UserProfile)
 MonClassRecLen=Len(MonClassRecord)
 MonTalkRecLen=Len(BufferRecord)
 NonPlayerRecLen=Len(MonsterRecord)
 ObjectRecLen=Len(ObjectRecord)
 RoomDescLen=Len(BufferRecord)
 RoomRecLen=Len(RoomRecord)
 SpellRecLen=Len(SpellRecord)
 TeamRecLen=Len(TeamRecord)
 TreasureRecLen=Len(TreasureRecord)
 MessWorkRecLen1=Len(MessWorkRecord1)
 MessWorkRecLen2=Len(MessWorkRecord2)
 MessWorkRecLen3=Len(MessWorkRecord3)
 MessWorkRecLen5=Len(MessWorkRecord5)
 MessWorkRecLen4=Len(MessWorkRecord4)
 MessWorkRecLen6=Len(MessWorkRecord6)
 MessWorkRecLen7=Len(MessWorkRecord7)
 FileName=DND.Path+"ACCOUNTS.SIC"
 Open FileName For Random Shared As #SicFile Len=UserProfileRecLen

 FileName=User.FileName
 Open FileName For Random Shared As #UserFile Len=UserRecLen
 Open FileName For Random Shared As #UserFile2 Len=UserRecLen

 FileName=NonPlayer.FileName
 Open FileName For Random Shared As #NonPlayerFile Len=NonPlayerRecLen
 FileName=Room.FileName
 Open FileName For Random Shared As #RoomFile Len=RoomRecLen
 FileName=Object.FileName
 Open FileName For Random Shared As #ObjectFile Len=ObjectRecLen
 FileName=Monster.FileName
 Open FileName For Random Shared As #MonsterFile Len=MonsterRecLen
 FileName=Treasure.FileName
 Open FileName For Random Shared As #TreasureFile Len=TreasureRecLen
 FileName=MonTalk.FileName
 Open FileName For Random Shared As #MonTalkFile Len=MonTalkRecLen
 FileName=MonClass.FileName
 Open FileName For Random Shared As #MonClassFile Len=MonClassRecLen
 FileName=Spell.FileName
 Open FileName For Random Shared As #SpellFile Len=SpellRecLen
 FileName=Action.FileName
 Open FileName For Random Shared As #ActionFile Len=ActionRecLen
 FileName=Help.FileName1
 Open FileName For Random Shared As #HelpFile1 Len=HelpRecLen1
 FileName=Team.FileName
 Open FileName For Random Shared As #TeamFile Len=TeamRecLen
 FileName=Container.FileName
 Open FileName For Random Shared As #ContainerFile Len=ContainerRecLen
 FileName=Message.Base.FileName
 Open FileName For Random Shared As #MessBaseFile Len=MessBaseRecLen
 FileName=UserInv.FileName
 Open FileName For Random Shared As #UserInvFile Len=MessWorkRecLen6
 FileName=CtnInv.FileName
 Open FileName For Random Shared As #CtnInvFile Len=MessWorkRecLen6
 FileName=TeamInv.FileName
 Open FileName For Random Shared As #TeamInvFile Len=MessWorkRecLen6
 FileName=RoomInv.FileName
 Open FileName For Random Shared As #RoomInvFile Len=MessWorkRecLen6
 FileName=MonInv.FileName
 Open FileName For Random Shared As #MonInvFile Len=MessWorkRecLen6
 FileName=Room.Desc.FileName
 Open FileName For Random Shared As #RoomDescFile Len=RoomDescLen
 FileName=MessWork.FileName+"1"+File.Extension1
 Open FileName For Random Shared As #MessWorkFile1 Len=MessWorkRecLen1
 FileName=MessWork.FileName+"6"+File.Extension1
 Open FileName For Random Shared As #MessWorkFile6 Len=MessWorkRecLen6
 FileName=MessWork.FileName+"7"+File.Extension1
 Open FileName For Random Shared As #MessWorkFile7 Len=MessWorkRecLen7
 Exit Sub
Open.Error:
 Color 14,0
 Out2="CMD208 Module - |Reboot"+Chr$(13)+Chr$(10)
 Out3="Error opening "+Lcase$(FileName)+" (error:"+Str$(Err)+"). Increase files= in config.sys or run Dndcnfg."+Chr$(13)+Chr$(10)
 Call Terminate.Program
End Sub

Sub Read.Options
 On Local Error Goto Error.Trap13
 Redim Options.Array(1 To 165) As String
 Options.Lines=165
 Var=0
 Close #TempFile1
 Filename=DND.Path+"option"+nodex+".cfg"
 If Dir$(Filename)<>Nul Then
    Open Filename For Input As #TempFile1
    Do
       If Eof(TempFile1) Then
          Exit Do
       Endif
       Line Input #TempFile1, Var$
       Var$=Rtrim$(Var$)
       If Left$(Var$,1)=";" Then
          Eat$ = Nul
       Else
          If Len(Var$) Then
             Var=Var+1
             If Var>Options.Lines Then
                Options.Lines=Options.Lines+10
                Redim Preserve Options.Array(1 To Options.Lines) As String
             Endif
             Options.Array(Var)=Var$
          Endif
       Endif
    Loop
 Endif
 Options.Lines=Var
Error.Resume13:
 Exit Sub
Error.Trap13:
 Color 14,0
 Out2="CMD208 Module - |Reboot"+Chr$(13)+Chr$(10)
 Out3="Error"+Str$(Err)+" reading "+FileName+". Edit file and restart."
 Call Terminate.Program
 Resume Error.Resume13
End Sub

Sub Reset.Cursor
 On Local Error Goto ErrMain13
 Call ScreenANSI(1,37,7)
 Locate Max.Row-1,1,1
 Graphics.Off=False
 Line.Length=False
MainExit13:
 Exit Sub
ErrMain13:
 Resume MainExit13
End Sub

Sub Detect.Share
 On Local Error Goto ErrResume149b
 Call Plex.Function(16)
 If (OutregsX.AX And &HFF)=&HFF Then
    Share.Installed=True
 Else
    Share.Installed=False
 Endif
 Windows.Detected = False
 Call Plex.Function(22)
 If OutregsX.BX>0 Then
    Windows.Detected = True
    ' store windows version
    Win.Minor=OutregsX.BX And &HFF
    Win.Major=(OutregsX.BX And &HFF00)/256
 Endif
ErrExit149b:
 Exit Sub
ErrResume149b:
 Resume ErrExit149b
End Sub

Sub Read.Rows(Var)
 On Local Error Goto Error.Trap62x
 Temp1=50
 Locate 50,1,0
 Var=50
 Exit Sub
Next.Trap1:
 Temp1=43
 Locate 43,1,0
 Var=43
 Exit Sub
Next.Trap2:
 Temp1=25
 Locate 25,1,0
 Var=25
 Exit Sub
Next.Trap3:
 Var=12
Error.Resume62x:
 Exit Sub
Error.Trap62x:
 If Temp1=50 Then
    Resume Next.Trap1
 Endif
 If Temp1=43 Then
    Resume Next.Trap2
 Endif
 If Temp1=25 Then
    Resume Next.Trap3
 Endif
 Resume Error.Resume62x
End Sub

Sub Search.Mess.File(Var1!,Var2)
 On Local Error Goto ErrMain41
 Var2=False
 For TempA=False To MaxNodes
    Call Read.Message.Record(MessWorkFile1,TempA+1)
    Var$=MessWorkRecord1.UserName
    Select Case Rtrim$(Lcase$(Var$))
    Case "login", "logoff", "relogin"
       TempB=False
    Case Deleted$, Offline$
       TempB=False
    Case Else
       TempB=True
    End Select
    If TempB Then
       If MessWorkRecord1.UserIndex=Var1! Then
          Var2=True
          Exit For
       Endif
    Endif
 Next
MainExit41:
 Exit Sub
ErrMain41:
 Resume MainExit41
End Sub

Sub Save.Screen2(Var)
 On Local Error Goto Error.Trap62
 If Var=False Then
    VarX3=(Max.Row-1)*80+80
    Redim Temp.ArrayY(VarX3) As Long
    Redim Temp.ArrayZ(VarX3) As Double
    For Var1=1 To Max.Row
       For Var2=1 To 80
          TempZ1=Screen(Var1,Var2)
          TempZ2=Screen(Var1,Var2,1)
          VarX2=(Var1-1)*80+Var2
          Temp.ArrayY(VarX2)=TempZ1
          Temp.ArrayZ(VarX2)=TempZ2
       Next
    Next
 Else
    Cls
    For VarX=Max.Row To 1 Step -1
       For VarY=1 To 80
          VarX2=(VarX-1)*80+VarY
          If Temp.ArrayY(VarX2)<>32 Then
             Goto Next.Line
          Endif
       Next
    Next
Next.Line:
    TempX=VarX
    For Var1=1 To VarX ' Max.Row
       For Var2=1 To 80
          VarX2=(Var1-1)*80+Var2
          VarB=Int(Temp.ArrayZ(VarX2)/16)
          VarF=Temp.ArrayZ(VarX2) Mod 16
          TempZ1=Temp.ArrayY(VarX2)
          Locate Var1,Var2,0
          Color VarF,VarB
          Print Chr$(TempZ1);
       Next
    Next
 Endif
Error.Resume62:
 Exit Sub
Error.Trap62:
 Resume Error.Resume62
End Sub

