 Rem File: Cmd123.bas
 Rem Sub: Switch.Lights
 Rem $Include: 'dndbbs.inc'
 On Error Goto Main.Error
 If Chained<>-2 Then
    Color 15,0
    Print "DNDBBS Command 123 -- Switch.Lights."
    Color 7,0
    End
 Endif
 Call Switch.Lights
Main.Resume:
 Chain DND.Path+"DNDBBS.EXE"
 End
Main.Error:
 Resume Main.Resume

' switch lights on/off in current room.
Sub Switch.Lights
 On Local Error Goto Error.Trap34
 Gosub Get.Config
 If Normal.User Then
    If Option1 Then
       If UserRecord.Level<Option1 Then
          Strng="You can't! Level is too low!"
          Call IO.O
          Exit Sub
       Endif
    Endif
 Endif
 Var=False
 Temp5!=RoomRecord.First
 If Temp5! Then
    Do While Lost.Carrier=False
       Call Read.Record(RoomInvFile,Temp5!)
       If MessWorkRecord6.Room=SFalse Then
          Exit Do
       Endif
       Temp6!=MessWorkRecord6.Next
       Temp7!=MessWorkRecord6.Index
       If Temp7!<SFalse Then
          Temp7!=Abs(Temp7!)
          Call Read.Record(ObjectFile,Temp7!)
          If ObjectRecord.SwitchType=2 Then ' fixed 09/25/2019
             Var=True
             If ObjectRecord.SwitchLight Then
                Var1=Var1+1 ' count lights went out
                ObjectRecord.SwitchLight=False
             Else
                ObjectRecord.SwitchLight=True
                Var2=Var2+1 ' count lights went on
             Endif
             Call Write.Record(ObjectFile,Temp7!)
          Endif
       Endif
       If Temp6!=SFalse Then
          Exit Do
       Endif
       Temp5!=Temp6!
    Loop
 Endif
 If Var=False Then
    Strng="Nothing happens!"
    Call IO.O
    Exit Sub
 Endif
 If Var1 Then
    If Var1=1 Then
       Strng="A light just went out!"
       Strng3=" just switched a light off!"
    Else
       Strng="Some lights just went out!"
       Strng3=" just switched some lights off!"
    Endif
    Call IO.O
    Gosub Switched
 Endif
 If Var2 Then
    If Var2=1 Then
       Strng="A light just went on!"
       Strng3=" just switched a light on!"
    Else
       Strng="Some lights just went on!"
       Strng3=" just switched some lights on!"
    Endif
    Call IO.O
    Gosub Switched
 Endif
 Exit Sub
Switched:
 If Node>False Then
    Out2=UserRecord.CodeName
    Out2=Rtrim$(Out2)
    Out2=Lcase$(Out2)
    Out2=Out2+Strng3
    Call Send.Mess(8,SFalse,Room,Out2)
 Endif
 Return
Get.Config:
 VarX=0
 Option1=0
 Do
    VarX=VarX+1
    If VarX>Options.Lines Then
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
    If Ucase$(Var$)="[CMD123]" 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)))
             Select Case Lcase$(Var2$)
             Case "level.restrict"
                If Int(Val(Var3$))>0 And Int(Val(Var3$))<=32767 Then
                   Option1=Int(Val(Var3$))
                Endif
             End Select
          Endif
       Loop
    Endif
 Loop
 Return
Error.Resume34:
 Exit Sub
Error.Trap34:
 Resume Error.Resume34
End Sub
