 Rem File: Cmd144.bas
 Rem Sub: Monitor
 Rem $Include: 'dndbbs.inc'
 On Error Goto Main.Error
 If Chained<>-2 Then
    Color 15,0
    Print "DNDBBS Command 144 -- Monitor."
    Color 7,0
    End
 Endif
 Var1=Hidden.Player
 Call Monitor
 Hidden.Player=Var1
Main.Resume:
 Chain DND.Path+"DNDBBS.EXE"
 End
Main.Error:
 Resume Main.Resume

Sub Monitor
 On Local Error Goto Error.Trap29
 Gosub Get.Config
 If Option1!<=0! Then
    Option1!=1!
 Endif
 If Local.Mode Then
    Var$="Press <ctrl-break>/<ctrl-c> to interrupt."
 Else
    Var$="Press <control-c>/<control-k> to interrupt."
 Endif
 Strng="Monitor mode. "+Var$
 Call IO.O
 Monitor.Mode=True
 Allow.Break=True
 Auto.Break=False
 Break=False
 Var2#=0#
 Do While Lost.Carrier=False
    Allow.Break=True
    If New.Room Then
       Call Enter.New.Room
    Endif
    Hidden.Player=True
    VarQ!=Timeit!
    Do While Lost.Carrier=False
       If Time.Elapsed(VarQ!,Option1!) Then
          Exit Do
       Endif
       Call Keyboard(Var1)
       Call Get.Modem(False)
       Call Check.Break
       Call Check.Carrier
       If Len(Buffer) Then
          If Instr(Buffer,Chr$(27)) Then
             Buffer=Nul
             Strng="<escape>"
             Call IO.O
             Exit Do
          Endif
          Buffer=Nul
       Endif
       If Auto.Break Then
          Exit Do
       Endif
       If Lost.Carrier Then
          Exit Do
       Endif
       If Node.Abort Then
          Exit Do
       Endif
    Loop
    If Option1#>0# Then
       Var2#=Var2#+1#
       If Var2#>Option1# Then
          Var3=-1
          Exit Do
       Endif
    Endif
    If Auto.Break Then
       If Option3 Then
          Strng="*break*"
          Call IO.O
       Endif
       Exit Do
    Endif
    If Lost.Carrier Then
       Exit Do
    Endif
    If Node.Abort Then
       Exit Do
    Endif
    Timeout=Timeit!
    Call IO.Timing
    Call Read.Node.Mess("")
    Last.Command="Monitor-Mode"
    Call Update.Mess(4)

    ' update system
    If (New.Mail.Count Mod Option0) = 0 Then
       Call Main.Loop.Update
    Endif

    ' reset round counter
    New.Mail.Count = New.Mail.Count + 1
    If New.Mail.Count > 64 Then
       New.Mail.Count = 1
    Endif
 Loop
 Allow.Break=False
 Auto.Break=False
 Break=False
 Monitor.Mode=False
 If Var3 Then
    Strng="Command rounds exceeded!"
    Call IO.O
 Endif
 Exit Sub
Get.Config:
 VarX=0
 Gosub Reset.Options
 Do
    VarX=VarX+1
    If VarX>Options.Lines Then
       Goto Next.Read
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
    If Ucase$(Var$)="[CMD144]" Then
       Do
          VarX=VarX+1
          If VarX>Options.Lines Then
             Goto Next.Read
             Return
          Endif
          Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
          If Ucase$(Var$)="[END]" Then
             Goto Next.Read
             Return
          Endif
          Var=Instr(Var$,"=")
          If Var Then
             Var2$=Ltrim$(Rtrim$(Left$(Var$,Var-1)))
             Var3$=Ltrim$(Rtrim$(Mid$(Var$,Var+1)))
             Gosub Parse.Options
          Endif
       Loop
    Endif
 Loop
 Return
Next.Read:
 Close #TempFile1
 Filename$=DND.Path+"CMD144.CFG"
 If Dir$(Filename$)="" Then
    Return
 Endif
 Open Filename$ For Input As #TempFile1
 Do
    If Eof(TempFile1) Then
       Exit Do
    Endif
    Line Input #TempFile1, Var$
    Var$=Ltrim$(Rtrim$(Var$))
    If Left$(Var$,1)<>";" Then
       VarX$=UserRecord.CodeName
       VarX$=Rtrim$(VarX$)
       VarX$=Ucase$(VarX$)
       If Ucase$(Var$)="["+VarX$+"]" Then
          VarZ=0
          Gosub Reset.Options
          Do
             If Eof(TempFile1) Then
                Exit Do
             Endif
             Line Input #TempFile1, Var$
             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)))
                Gosub Parse.Options
             Endif
          Loop
       Endif
    Endif
 Loop
 Return
Reset.Options:
 Option0=4
 Option1!=1!
 Option1#=-1#
 Option3=-1
 Return
Parse.Options:
 VarQ=Int(Val(Var3$)+.5)
 Select Case Lcase$(Var2$)
 Case "break.switch"
    Select Case Ucase$(Var3$)
    Case "0", "FALSE","OFF"
       Option3=0
    End Select
 Case "maximum.rounds.counter"
    Option1#=Cdbl(Val(Var3$))
 Case "round.time.delay"
    Option1!=Csng(Val(Var3$))
 End Select
 Select Case VarQ
 Case 1,2,4,8,16,32,64
    Select Case Lcase$(Var2$)
    Case "main.loop.update"
       option0=VarQ
    End Select
 End Select
 Return
Error.Resume29:
 Exit Sub
Error.Trap29:
 Resume Error.Resume29
End Sub
