 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 Security.Guard
    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
       If Local.Mode Then
          Call Release.Time(1)
       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
    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

    If Local.Mode Then
       Call Release.Time(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
 Option0=4
 Option1!=1!
 Option1#=-1#
 Option3=-1
 Do
    VarX=VarX+1
    If VarX>Options.Lines Then
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
    If Ucase$(Var$)="[CMD144]" Then
       Do
          VarX=VarX+1
          If VarX>Options.Lines Then
             Return
          Endif
          Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
          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)))
             VarQ=Int(Val(Var3$))
             Select Case Lcase$(Var2$)
             Case "break.switch"
                Select Case Ucase$(Var3$)
                Case "0", "FALSE","OFF"
                   Option3=0
                End Select
             Case "maximum.rounds.counter"
                Option1#=Int(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
          Endif
       Loop
    Endif
 Loop
 Return
Error.Resume29:
 Exit Sub
Error.Trap29:
 Resume Error.Resume29
End Sub
