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

Sub Wait.Loop
 On Local Error Goto Err.Trap25
 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="Wait mode. "+Var$
 Call IO.O
 Wait.Mode=True
 Allow.Break=True
 Auto.Break=False
 Break=False
 Var1!=Timeit!
 Var2=False
 VarZ#=0#
 Do While Security.Guard
    Allow.Break=True
    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)
       If Len(Buffer) Then
          If Instr(Buffer,Chr$(27)) Then
             Buffer=Nul
             Strng="<escape>"
             Call IO.O
             Exit Do
          Endif
          Buffer=Nul
       Endif
       Call Check.Break
       If Auto.Break Then
          Exit Do
       Endif
       Call Check.Carrier
       Call Read.Mess
       Call IO.Timing
       Call Read.Node.Mess("")
    Loop
    If New.Room Then
       Call Enter.New.Room
    Endif
    If Command.Time.Limit>False Then
       If Time.Elapsed(Var1!,Csng(Command.Time.Limit)) Then
          Var2=True
          Exit Do
       Endif
    Endif
    If option1#>0# Then
       VarZ#=VarZ#+1#
       If VarZ#>option1# Then
          Var2=-2
          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
    Call Write.Record(UserFile,User.Index)
    Timeout=Timeit!
    Call IO.Timing
    Last.Command="Wait-Mode"
    Call Update.Mess(4)

    ' update system
    If (New.Mail.Count Mod 4) = 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
 Auto.Mode=False
 Break=False
 Wait.Mode=False
 If Var2=True Then
    Strng="Command time limit!"
    Call IO.O
 Endif
 If Var2=-2 Then
    Strng="Command rounds exceeded!"
    Call IO.O
 Endif
 Exit Sub
Get.Config:
 VarX=0
 Option1#=-1#
 Option1!=-1!
 Option3=-1
 Do
    VarX=VarX+1
    If VarX>Options.Lines Then
       Goto Next.Read
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
    If Ucase$(Var$)="[CMD139]" 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+"CMD139.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
          Option1#=-1#
          Option1!=-1!
          Option3=-1
          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
Parse.Options:
 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$)+.5)
 Case "round.time.delay"
    option1!=Csng(Val(Var3$))
 End Select
 Return
Err.Resume25:
 Exit Sub
Err.Trap25:
 Resume Err.Resume25
End Sub
