 Rem File: Cmd205.bas
 Rem Sub: Time.Online
 Rem $Include: 'dndbbs.inc'
 On Error Goto Main.Error
 If Chained<>-2 Then
    Color 15,0
    Print "DNDBBS Command 205 -- Time.Online."
    Color 7,0
    End
 Endif
 If TempX Then
    Call Time.Online
 Else
    Call Reset.Clock
 Endif
Main.Resume:
 Chain DND.Path+"DNDBBS.EXE"
 End
Main.Error:
 Resume Main.Resume

 ' date/time logged on, time used.
Sub Time.Online
 On Local Error Goto Err.Trp1
 Gosub Get.Config2
 Graphics.Off=True
 Strng="It is now "+Fclock$
 Call IO.O
 ' calculate serialized date
 Trap=-1
 OnDate#=DateValue(Date.On)
 Strng2=Format$(OnDate#,"ddd dd mmm yyyy")
 ' calculate serialized time
 OnTime#=TimeValue(Time.On)
 Strng3=Format$(OnTime#,"hh:mma/p")
Resume1a:
 Trap=0
 If Trap.Err Then
    Strng="You logged on at "+Date.On+", "+Time.On+"."
 Else
    Strng="You logged on at "+Strng2+", "+Strng3+"."
 Endif
 Call IO.O
 Trap=-2
 d1$=format$(now,"mm-dd-yyyy")
 Var#=DateValue(d1$)-OnDate# ' serialized date
Resume2a:
 Trap=0
 If Var#>=2# Then
    Strng="You have been on for"+Str$(Var#)+" days!"
    Call IO.O
 Else
    ' time online
    Var1!=Timeit-Timeon ' elapsed
    If Var1!<0! Then Var1!=Var1!+86400! ' midnight
    Strng="You have been on for"
    Strng2="."
    Gosub Time.Display
 Endif
 ' time remaining
 If UserRecord.TimeLimit<SFalse Then
    Strng="You have unlimited time remaining."
    Call IO.O
 Else
    If Var#<2# Then
       Var2!=Timeit-Timeon ' elapsed
       If Var2!<0! Then Var2!=Var2!+86400! ' midnight
       Var1!=Time.Left-Var2! ' remaining
       If Var1!<0! Then Var1!=0!
       Strng="You have"
       Strng2=" remaining."
       Gosub Time.Display
    Endif
 Endif

 ' usage
 Strng="You have used "+Lcase$(ProgramName$)
 Var#=UserRecord.TimesLogon+1#
 Gosub Time.String
 Strng=Strng+Strng2
 Var#=UserRecord.TimesDied
 Gosub Time.String
 Strng=Strng+" and died"+Strng2+"."
 Call IO.O

 Call More.Prompt
 If No Or Quit Then
    Exit Sub
 Endif
 Strng="Current maximum time limit(minutes):"
 Select Case UserRecord.TimeLimit
 Case SFalse
    Select Case UserRecord.ClassType
    Case Is>=AsstDM
       If Config1(3)>SFalse Then
          Strng=Strng+Str$(Config1(3))
       Endif
    Case Else
       Select Case UserRecord.Level
       Case Is<=1
          If Config1(1)>SFalse Then
             Strng=Strng+Str$(Config1(1))
          Endif
       Case Else
          If Config1(2)>SFalse Then
             Strng=Strng+Str$(Config1(2))
          Endif
       End Select
    End Select
 Case Is>SFalse
    Strng=Strng+Str$(UserRecord.TimeLimit)
 Case Else
    Strng=Strng+" (unlimited)"
 End Select
 Call IO.O
 Strng="Current maximum calls allowed:"
 Var2=UserRecord.MaxCalls
 Select Case Var2
 Case Is<False
    Strng=Strng+" (unlimited)"
 Case False
    Strng=Strng+Str$(Config2(1))
 Case Else
    Strng=Strng+Str$(Var2)
 End Select
 Call IO.O
 Var1=UserRecord.FromHour
 Var2=UserRecord.FromMin
 Var3=UserRecord.ToHour
 Var4=UserRecord.ToMin
 If Var1 Or Var2 Or Var3 Or Var4 Then
    Strng="Current time restriction is from "+_
    Right$("0"+Mid$(Str$(Var1),2),2)+":"+_
    Right$("0"+Mid$(Str$(Var2),2),2)+" to "+_
    Right$("0"+Mid$(Str$(Var3),2),2)+":"+_
    Right$("0"+Mid$(Str$(Var4),2),2)
    Call IO.O
 Endif
 Call More.Prompt
 If No Or Quit Then
    Exit Sub
 Endif
 If option1 Then
    Var2=False
    For VarZ=1 To 6
       Select Case VarZ
       Case 1
          Var1$=Rtrim$(GuestRecord.TownMayorTime)
          VarX$="Town Mayor"
          Gosub Display.Time
       Case 2
          Var1$=Rtrim$(GuestRecord.GovernorTime)
          VarX$="Governor"
          Gosub Display.Time
       Case 3
          Var1$=Rtrim$(GuestRecord.GuildMasterTime)
          VarX$="GuildMaster"
          Gosub Display.Time
       Case 4
          Var1$=Rtrim$(GuestRecord.SysopTime)
          VarX$="Sysop"
          Gosub Display.Time
       Case 5
          Var1$=Rtrim$(GuestRecord.DMTime)
          VarX$="DM"
          Gosub Display.Time
       Case 6
          Var1$=Rtrim$(GuestRecord.AsstDMTime)
          VarX$="Asst. DM"
          Gosub Display.Time
       End Select
    Next
    Strng=Rtrim$(GuestRecord.PageTimes)
    If Strng<>Nul Then
       Strng="Sysop page times: "+Strng
       Call IO.O
       Var2=True
    Endif
    If Var2 Then
       Call More.Prompt
    Endif
    If No Or Quit Then
       Exit Sub
    Endif
 Endif
 If option2 Then
    If Sysop Then
       If Special.Names>False Then
          Continuous=False
          Var2=False
          Strng="Display special users(y/n)? "
          No.Input.Out="N"
          Line.Length=1
          Call IO.I
          If Yes Then
             For VarZ=1 To Special.Names
                Var1$=Rtrim$(SpecialUserTime(VarZ))
                VarX$=Lcase$(Rtrim$(SpecialUserName(VarZ)))
                If Len(VarX$) Then
                   Mid$(VarX$,1,1)=Ucase$(Mid$(VarX$,1,1))
                Endif
                Gosub Display.Time
             Next
          Endif
          If Var2 Then
             Call More.Prompt
          Endif
       Endif
    Endif
 Endif
 Exit Sub

' format a string
Time.String:
 Select Case Var#
 Case 1
    Strng2=" once"
 Case 2 To 10
    Strng2=" "+Rtrim$(Numeral(Var#))+" times"
 Case Else
    If Instr(Str$(Var#),"D") Then
       VarQ$=Str$(Var#)
    Else
       VarQ$=" "+Form$(Var#)
    Endif
    Strng2=VarQ$+" times"
 End Select
 Return

' format a string
Time.Display:
 Hours=Int(Var1!/3600!)
 Var1!=Var1!-Hours*3600!
 Minutes=Int(Var1!/60!)
 Var1!=Var1!-Minutes*60!
 Seconds=Int(Var1!)
 If Hours>=23 Then
    Strng=Strng+" a very long time"+Strng2
    Call IO.O
    Return
 Endif
 If Hours=False Then
    If Minutes=False Then
       If Seconds=False Then
          Strng=Strng+" 0 seconds"+Strng2
          Call IO.O
          Return
       Endif
    Endif
 Endif
 If Hours>False Then
    Strng=Strng+Str$(Hours)+" hour"
    If Hours>1 Then
       Strng=Strng+"s"
    Endif
    Strng=Strng+","
 Endif
 If Minutes>False Then
    Strng=Strng+Str$(Minutes)+" minute"
    If Minutes>1 Then
       Strng=Strng+"s"
    Endif
    Strng=Strng+","
 Else
    If Seconds=False Then
       Strng=Left$(Strng,Len(Strng)-1)
    Endif
 Endif
 If Seconds>False Then
    Strng=Strng+Str$(Seconds)+" second"
    If Seconds>1 Then
       Strng=Strng+"s"
    Endif
 Else
    Strng=Left$(Strng,Len(Strng)-1)
 Endif
 Strng=Strng+Strng2
 Call IO.O
 Return

' display restriction notice
Display.Time:
 If Len(Var1$) Then
    If Var2=False Then
       TempC=1
       Var2=True
       Graphics.Off=False
       Strng="Time restrictions:"
       Call IO.O
    Endif
    Graphics.Off=True
    Strng=VarX$+" time slot restriction is "+Var1$
    Call IO.O
    If Continuous=False Then
       TempC=TempC+1
       If TempC>=User.Pagelength-2 Then
          TempC=False
          Call More.Prompt
          If No Or Quit Then
             Exit Sub
          Endif
       Endif
    Endif
 Endif
 Return
Err.Rsm1:
 Exit Sub

' test for illegal function call when serialized date is beyond 2078.
Err.Trp1:
 If Trap=-1 Then
    Trap.Err=-1
    Resume Resume1a
 Endif
 If Trap=-2 Then
    Var#=0#
    Resume Resume2a
 Endif
 Resume Err.Rsm1

Get.Config2:
 Option1=0
 Option2=0
 VarX=0
 Do
    VarX=VarX+1
    If VarX>Options.Lines Then
       Goto Next.Read
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
    If Ucase$(Var$)="[CMD205]" 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+"CMD205.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=0
          Option2=0
          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 "allow.display.users"
    Select Case Lcase$(Var3$)
    Case "-1", "true", "on"
       Option1=-1
    End Select
 Case "allow.display.special.users"
    Select Case Lcase$(Var3$)
    Case "-1", "true", "on"
       Option2=-1
    End Select
 End Select
 Return
End Sub

Sub Reset.Clock
 On Local Error Goto ErrorTrap40
 Graphics.Off=True
 No.Input.Out="N"
 Strng="Set system clock(y/n)? "
 Call IO.I
 If Yes Then
    Strng="Current date: "+DateS$
    Call IO.O
    Strng="New date(form: mm-dd-yyyy)? "
    Call IO.I
    If No.Input=False Then
       Date$=Out2
    Endif
    Strng3=Format$(Now,"hh:mm:ss")
    Strng="Current time: "+Strng3
    Call IO.O
    Strng="New time(form: hh:mm:ss)? "
    Call IO.I
    If No.Input=False Then
       Time$=Out2
    Endif
 Endif
 Graphics.Off=False
ErrorResume40:
 Exit Sub
ErrorTrap40:
 Strng="Error setting date\time."
 Call IO.O
 Resume ErrorResume40
End Sub
