 Rem File: Cmd037.bas
 Rem Sub: Read.DayFile
 Rem $Include: 'dndbbs.inc'
 On Error Goto Main.Error
 If Chained=0 Then ' local mode
    Call Get.Node
    Call Open.Arrays
    Call Get.Config
    Call Increase.Files
    Call Make.FileNames
    Call Reset.Cursor
    Call Detect.Share
    Call Open.Files
    Call Read.Options
    Call Valid.Node
    Call Save.Screen2(0)
    Color 14,0
    Print "DNDBBS CMD037 - Read.Dayfile."
    Var$=Nul
    If Command$<>Nul Then
       Var$=Command$
    Endif
    Call Alt.Login(Var,Var$)
    If Var=False Then
       If Lost.Carrier=False Then
          Color 14,0
          Print "Codename not found."
       Endif
       Call More.Prompt
       Goto Main.Resume
    Endif
    Call Search.Mess.File(User.Index,Var1)
    If Var1 Then
       Color 14,0
       Print "Codename is in use."
       Call More.Prompt
       Goto Main.Resume
    Endif
    Call Get.User.Stats(Var)
    Timeon=Timeit!
    Time.Left=3600!
 Endif
 Call Read.DayFile
Main.Resume:
 If Chained=-2 Then
    Chain DND.Path+"DNDBBS.EXE"
 Endif
 Call Clear.Status.Line
 Call ScreenANSI(1,37,7)
 Color 7, 0
 Cls
 Call Save.Screen2(-1)
' Locate Max.Row,1,1
 If TempX=0 Then TempX=1
 Locate TempX,1,1
 Color 15,0
 Print
 Print "Now exiting Read.Dayfile.."
 Color 7,0
 Call Decrease.Files
 End
Main.Error:
 Resume Main.Resume

Function ValidDate(Var$)
 On Local Error Goto DateError
 Var$=Rtrim$(Var$)
 If Len(Var$)=10 Then ' mm-dd-yyyy
    For Var=1 To 10
       V$=Mid$(Var$,Var,1)
       Select Case Var
       Case 1, 2, 4, 5, 7, 8, 9, 10
          If V$>="0" And V$<="9" Then
             Eat$ = Nul
          Else
             Goto DateResume
          Endif
       Case Else
          If V$ <> "-" Then
             Goto DateResume
          Endif
       End Select
    Next
 Endif
 Temp#=DateValue(Var$)
 If Temp# Then
    TempC$=Var$
    ValidDate=True
    Exit Function
 Endif
DateResume:
 ValidDate=False
 Exit Function
DateError:
 Resume DateResume
End Function

Sub Read.DayFile
 On Local Error Goto ErrorTrap25
 Gosub Get.Config
Do While Lost.Carrier=False
 If Chained=False Then
    Do While Lost.Carrier=False
       Graphics.Off=False
       Strng="Select read option:"
       Call IO.O
       Graphics.Off=True
       Strng="(1)Dayfile"
       Call IO.O
       Strng="(2)Daylog"
       Call Io.O
       Strng="(3)Lastuser"
       Call IO.O
       Graphics.Off=False
       No.Input.Out="Q"
       Strng="Enter option(1-3,Q to Quit)? "
       Call IO.I
       If Ucase$(Out2)="Q" Then
          Exit Sub
       Endif
       TempX=Int(Val(Out2))
       If TempX>=1 And TempX<=3 Then
          TempX=TempX-2
          Exit Do
       Endif
    Loop
 Endif
 Var=TempX
 VarZ=False
 Var3$=Nul
 If Option1 Then
    No.Input.Out="N"
    Strng="Read old backup files(y/n)? "
    Call IO.I
    VarZ=Yes
    If VarZ Then
       Do While Lost.Carrier=False
          If Len(Option1$) Then
             No.Input.Out=Option1$
          Else
             No.Input.Out="01-01-1980"
          Endif
          Strng="Enter date to start search from(form: MM-DD-YYYY)? "
          Call IO.I
          VarZ$=Out2
          TempA=ValidDate(VarZ$)
          If TempA=False Then
             Strng="Invalid date. Set from 01-01-1980 to 12-31-2078"
             Call IO.O
          Else
             Temp#=DateValue(VarZ$)
             Exit Do
          Endif
       Loop
       If Option2 Then
          No.Input.Out="N"
          Strng="Search for substring(y/n)? "
          No=False:Yes=False:Quit=False
          Call IO.I
          If Yes Then
             Strng="Enter substring(? and * allowed): "
             Call IO.I
             If Len(Out2) Then
                Var3$=Ucase$(Out2)
             Endif
          Endif
       Endif
    Endif
 Endif
 If Var=False Then ' dndlog
    Var3=2
    Do While Lost.Carrier=False
       No.Input.Out="M"
       Strng="Daylog list (S)hort, (M)edium, (L)ong, (Q)uit? "
       Call IO.I
       Select Case Ucase$(Out2)
       Case "L"
          Var3=1
          Exit Do
       Case "M"
          Var3=2
          Exit Do
       Case "S"
          Var3=3
          Exit Do
       Case "Q"
          Exit Sub
       End Select
    Loop
 Endif
 If VarZ Then ' backup files
    Select Case Var
    Case True
       FileName=Data.Path1+"dndday.bak"
    Case False
       FileName=Data.Path1+"dndlog.bak"
    Case UnTrue
       FileName=Data.Path1+"lastuser.bak"
    End Select
 Else ' dayfiles
    Select Case Var
    Case True
       FileName=Day.File.FileName
    Case False
       FileName=Day.Log.FileName
    Case UnTrue
       FileName=LastUser.FileName
    End Select
 Endif
 Allow.Break=True
 Break=False
 Continuous=False
 If Len(FileName)=0 Then
    Strng="Filename not found."
    Call IO.O
    Exit Sub
 Endif
 If Dir$(FileName)="" Then
    Strng="Filename: "+FileName+" not found."
    Call IO.O
    Exit Sub
 Endif
 If Local.Mode And Debug.Mode Then
    Strng="Filename: "+FileName
    Call IO.O
 Endif
 Gosub Display.Header
 If VarZ Then
    Graphics.Off=True
    Close #DayFile1
    Open FileName For Input As #DayFile1
    Do While Not Eof(DayFile1)
       If Lost.Carrier Then
          Exit Do
       Endif
       Line Input #DayFile1,Strng
       Strng=Rtrim$(Strng)
       Temp2#=0#
       If Len(Strng) Then
          Strng2=Left$(Strng,10) ' 01-01-1980
          If Val(Right$(Strng2,4))>=2079 Then
             Temp2#=Temp#
          Else
             Temp2#=DateValue(Strng2)
          Endif
       Endif
       If Temp2#>=Temp# Then
          Select Case Var
          Case 0
             Var$=Mid$(Strng,21)
             Var4=False
             Select Case Var3
             Case 1
                If Left$(Var$,1)="*" Then
                   Var4=-1
                Endif
             Case 2
                If Left$(Var$,2)="**" Then
                   Var4=-1
                Endif
             Case 3
                If Left$(Var$,3)="***" Then
                   Var4=-1
                Endif
             End Select
             If Var4 Then
                If Len(Var3$) Then
                   Out2=Var3$
                   Out3=Strng
                   Call InstrSUB2(VarX)
                   If VarX Then
                      Temp5=Temp5+1
                      Call IO.O
                   Endif
                Else
                   Temp5=Temp5+1
                   Call IO.O
                Endif
             Endif
          Case Else
             If Len(Var3$) Then
                Out2=Var3$
                Out3=Strng
                Call InstrSUB2(VarX)
                If VarX Then
                   Temp5=Temp5+1
                   Call IO.O
                Endif
             Else
                Temp5=Temp5+1
                Call IO.O
             Endif
          End Select
          If Break Then
             Break=False
             Exit Sub
          Endif
          If Temp5>=User.Pagelength-2 Then
             If Continuous=False Then
                No=False:Yes=False:Quit=False
                Call More.Prompt
                Temp5=False
                If Break Then
                   Break=False
                   Exit Sub
                Endif
                If No Or Quit Then
                   Exit Do
                Endif
                Gosub Display.Header
             Endif
          Endif
       Endif
    Loop
 Else
    Graphics.Off=True
    Close #DayFile1
    Open FileName For Random Shared As #DayFile1 Len=DayFileRecLen
    For Temp!=1! To Lof(DayFile1)/DayFileRecLen
       Call Read.Record(DayFile1,Temp!)
       Strng=Rtrim$(BufferRecord.Buffer)
       Strng=Rtrim$(Strng)
       Select Case Var
       Case 0
          Strng2=Mid$(Strng,21)
          Var4=0
          Select Case Var3
          Case 1
             If Left$(Strng2,1)="*" Then
                Var4=-1
             Endif
          Case 2
             If Left$(Strng2,2)="**" Then
                Var4=-1
             Endif
          Case 3
             If Left$(Strng2,3)="***" Then
                Var4=-1
             Endif
          End Select
          If Var4 Then
             Temp5=Temp5+1
             Call IO.O
          Endif
       Case Else
          Temp5=Temp5+1
          Call IO.O
       End Select
       If Break Then
          Break=False
          Exit Sub
       Endif
       If Temp5>=User.Pagelength-2 Then
          If Continuous=False Then
             No=False:Yes=False:Quit=False
             Call More.Prompt
             Temp5=False
             If Break Then
                Break=False
                Exit Sub
             Endif
             If No Or Quit Then
                Exit For
             Endif
             Gosub Display.Header
          Endif
       Endif
    Next
 Endif
 If Break Then
    Break=False
    Exit Sub
 Endif
 Allow.Break=False
 Break=False
 Graphics.Off=False
 If Temp5 Then
    Call More.Prompt
 Endif
 If Chained=-2 Then
    Exit Sub
 Endif
Loop
Exit Sub

Display.Header:
 Select Case Var
 Case True
    Strng="Dayfile"
 Case False
    Strng="Daylog"
 Case UnTrue
    Strng="Lastuser"
 End Select
 Strng=Strng+" list."
 Var$="Press <ctrl-break>/<ctrl-c> to interrupt."
 If Local.Mode=False Then
    Var$="Press <control-c>/<control-k> to interrupt."
 Endif
 Strng=Strng+" "+Var$
 Call IO.O
 Graphics.Off=False
 Var$="DNDBBS v"+Version$+" r"+Release$+" "
 Select Case Var
 Case True
    Var2$="Day File List"
 Case False
    Var2$="Day Log List"
 Case UnTrue
    Var2$="Last User List"
 End Select
 Strng=Var$+Var2$+" "
 If VarZ Then
    Strng=Strng+"from "+VarZ$+"."
 Else
    Strng=Strng+"for "+Left$(Fclock$,15)+"."
 Endif
 Call IO.O
 Graphics.Off=True
 Temp5=2
 If Var=UnTrue Then
    Strng="Date       Username                       Timeon   Timeoff  Total    Score"
    Call IO.O
    Call Display.Line(74)
    Temp5=4
 Endif
 Return
Get.Config:
 Option1=-1
 Option2=-1
 Option1$="01-01-1980"
 Do
    VarX=VarX+1
    If VarX>Options.Lines Then
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
    If Ucase$(Var$)="[CMD037]" 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 "allow.read.oldfiles"
                Select Case Lcase$(Var3$)
                Case "0", "false", "off"
                   Option1=0
                End Select
             Case "allow.search.substring"
                Select Case Lcase$(Var3$)
                Case "0", "false", "off"
                   Option2=0
                End Select
             Case "default.start.date"
                TempA=ValidDate(Var3$)
                If TempA Then
                   Option1$=Var3$
                Endif
             End Select
          Endif
       Loop
    Endif
 Loop
 Return
ErrorResume25:
 Exit Sub
ErrorTrap25:
' Strng="Error:"+Str$(Err)
' Call IO.O
 Resume ErrorResume25
End Sub

Sub Alt.Login(Var,Var$)
 On Local Error Goto ErrorTrp25
 If Instr(Var$,"/N:") Then
    Var$=Left$(Var$,Instr(Var$,"/N:")-1)
 Endif
 Out2=Nul
 Var=False
 If Len(Var$) Then
    Var2=Instr(Var$,Chr$(34))
    If Var2 Then
       Var$=Mid$(Var$,Var2+1)
       Var2=Instr(Var$,Chr$(34))
       If Var2 Then
          Out2=Left$(Var$,Var2-1)
          If Out2=Nul Then
             Exit Sub
          Endif
       Else
          Exit Sub
       Endif
    Else
       Exit Sub
    Endif
 Endif
Start.Login:
 If Out2=Nul Then
    Graphics.Off=False
    Strng="Enter codename(?=list,*=search): "
    Call IO.I
 Endif
 Strng=Lcase$(Rtrim$(Out2))
 Out2=Nul
 If Len(Strng)=0 Then
    Exit Sub
 Endif
 If Strng="?" Then
    Temp1=False
    For Temp1!=1! To Lof(UserFile)/UserRecLen
       Call Read.Record(UserFile,Temp1!)
       Out3=UserRecord.CodeName
       Out3=Lcase$(Rtrim$(Out3))
       If Out3<>"<deleted>" Then
          Strng=Out3
          Mid$(Strng,1,1)=Ucase$(Mid$(Strng,1,1))
          Strng=Rtrim$(UserRecord.Prefix1)+Strng
          Call Convert.ANSI(True,VarQ,VarR)
          Carriage.Return=True
          Graphics.On=True
          Call IO.O
          Graphics.On=False
          Strng=Strng+" (level "+Form$(Cdbl(UserRecord.Level))+")"
          If UserRecord.ClassType=AsstDM Then
             Strng=Strng+" [AsstDM]"
          Endif
          If UserRecord.ClassType=DM Then
             Strng=Strng+" [DM]"
          Endif
          If UserRecord.Flags And Special.Char4 Then
             Strng=Strng+" [Sysop]"
          Endif
          Call Search.Mess.File(Temp1!,Var1)
          If Var1 Then
             Strng=Strng+" {online}"
          Endif
          Call IO.O
          Temp1=Temp1+1
          If Temp1>=User.Pagelength-2 Then
             Temp1=False
             Call More.Prompt
             If No Or Quit Then
                Exit For
             Endif
          Endif
       Endif
    Next
    If Temp1 Then
       Call More.Prompt
    Endif
    Out2=Nul
    Goto Start.Login
 Endif
 If Strng="*" Then
    Strng="Enter codename search(?,* allowed): "
    Call IO.I
    Var2$=Lcase$(Out2)
    Temp1=False
    Var2=False
    For Temp1!=1! To Lof(UserFile)/UserRecLen
       Call Read.Record(UserFile,Temp1!)
       Out3=UserRecord.CodeName
       Out3=Lcase$(Rtrim$(Out3))
       If Out3<>"<deleted>" Then
          Out2=Var2$
          Call InstrSUB2(VarX)
          If VarX Then
             Var2=True
             Strng=Out3
             Mid$(Strng,1,1)=Ucase$(Mid$(Strng,1,1))
             Strng=Rtrim$(UserRecord.Prefix1)+Strng
             Call Convert.ANSI(True,VarQ,VarR)
             Carriage.Return=True
             Graphics.On=True
             Call IO.O
             Graphics.On=False
             Strng=Strng+" (level "+Form$(Cdbl(UserRecord.Level))+")"
             If UserRecord.ClassType=AsstDM Then
                Strng=Strng+" [AsstDM]"
             Endif
             If UserRecord.ClassType=DM Then
                Strng=Strng+" [DM]"
             Endif
             If UserRecord.Flags And Special.Char4 Then
                Strng=Strng+" [Sysop]"
             Endif
             Call Search.Mess.File(Temp1!,Var1)
             If Var1 Then
                Strng=Strng+" {online}"
             Endif
             Call IO.O
             Temp1=Temp1+1
             If Temp1>=User.Pagelength-2 Then
                Temp1=False
                Call More.Prompt
                If No Or Quit Then
                   Exit For
                Endif
             Endif
          Endif
       Endif
    Next
    If Var2=False Then
       Strng="Codename not found."
       Call IO.O
    Endif
    If Temp1 Then
       Call More.Prompt
    Endif
    Out2=Nul
    Goto Start.Login
 Endif
 For User.Index=1! To Lof(UserFile)/UserRecLen
    Call Read.Record(UserFile,User.Index)
    Out3=UserRecord.CodeName
    Out3=Lcase$(Rtrim$(Out3))
    If Strng=Out3 Then
       Var=True ' valid name
       Exit Sub
    Endif
 Next
 User.Index=SFalse
 Exit Sub
ErrorRsm25:
 Exit Sub
ErrorTrp25:
 Security.Guard=False
 Resume ErrorRsm25
End Sub

Sub Get.Node
 On Local Error Goto Node.Error
 Var$=Command$
 Var$=Ltrim$(Rtrim$(Var$))
 If Instr(Var$,"/N:") Then
    Var$=Mid$(Var$,Instr(Var$,"/N:")+3)
    Select Case Len(Var$)
    Case 0
       Node=0
       NodeX=Nul
       Exit Sub
    Case 1 ' 0-9,A-Z
       Select Case Var$
       Case "0" To "9"
          Node=Val(Var$)+1
          NodeX=Var$
       Case "A" To "Z"
          Node=Asc(Var$)-54
          NodeX=Var$
       Case Else
          Goto Node.Error
       End Select
    Case 2 ' 10-99
       VarX=Int(Val(Var$))
       If VarX>=10 And VarX<=99 Then
          Node=VarX+27 ' 37-126
          NodeX=Mid$(Str$(VarX),2) ' 10-99
       Else
          Goto Node.Error
       Endif
    Case Else
       Goto Node.Error
    End Select
 Endif
 Exit Sub
Node.Error:
 Color 14,0
 Out2="CMD037 Module - Read.Dayfile"+Chr$(13)+Chr$(10)
 Out3="Error reading node. Node must be <nul>,0-9,A-Z,10-99."
 Call Terminate.Program
End Sub

Sub Valid.Node
 On Local Error Goto ErrorTrap11
 If Node>=False And Node<=MaxNodes Then
    VarX2=Node+1
    Call Read.Message.Record(MessWorkFile1,VarX2)
    If MessWorkRecord1.ActiveNode Then
       If Rtrim$(NodeX)=Nul Then
          Strng="Node -, already active."
       Else
          Strng="Node "+NodeX+", already active."
       Endif
       Goto ErrorTrap11
    Else
       Strng=Rtrim$(MessWorkRecord1.UserName)
       Call Valid.Name(Strng)
       If TempA Then
          If Rtrim$(NodeX)=Nul Then
             Strng="Node -, active codename."
          Else
             Strng="Node "+NodeX+", active codename."
          Endif
          Goto ErrorTrap11
       Endif
    Endif
 Else
    Strng="Node '"+NodeX+"' is not a valid node number."
    Goto ErrorTrap11
 Endif
ErrorResume11:
 Exit Sub
ErrorTrap11:
 Color 14,0
 Out2="CMD037 Module - Read.Dayfile"+Chr$(13)+Chr$(10)
 Out3=Strng
 Call Terminate.Program
End Sub

Sub Open.Arrays
 On Local Error Goto Array.Error
 Call Plex.Function(26)
 If (OutregsX.AX And &HFF)=&HFF Then
    Local.ANSI.Color=True
 Else
    Local.ANSI.Color=False
 Endif
 Local.Avatar.Color=False
 Call Plex.Function(27)
 If (OutregsX.AX And &HFF)=&HFF Then
    If (OutregsX.DX And &HFF)=&H16 Then
       Local.Avatar.Color=True
    Endif
 Endif
 Local.Mode=True
 Lost.Carrier=False
 Call Read.Rows(Max.Row)
 Locate Max.Row,1,1
 Call VideoInt(15,0)
 Video.Page=OutregsX.BX
Redim Alignment.Name1(1 To MaxAlignment) As String*7,_
 Alignment.Name2(1 To MaxAlignment) As String*7,_
 Class.Name(1 To MaxClassNames) As String*15,_
 Direction(1 To MaxDirections) As String*9,_
 High.Class.Name(1 To MaxClassNames) As String*15,_
 InventoryNames(1 To MaxItems) As String*8,_
 Numeral(1 To MaxNumerals) As String*5,_
 Race(1 To MaxRaces) As String*8,_
 Room.Array(1 To MaxRoomArrays) As String*40,_
 Stat(1 To MaxStats) As String*12,_
 Training.Stats(1 To MaxClassNames,1 To MaxTrainStats) As Integer,_
 Weapon.Type.Name(1 To MaxWeapons) As String*9
 Exit Sub
Array.Error:
 Color 14,0
 Out2="CMD037 Module - Read.Dayfile"+Chr$(13)+Chr$(10)
 Out3="Error opening arrays. Free more RAM."
 Call Terminate.Program
End Sub

Sub Get.Config
 On Local Error Goto Config.Error
 DND.Path=Environ$("DNDBBS")
 If DND.Path<>Nul Then
    If Right$(DND.Path,1)<>"\" Then
       DND.Path=DND.Path+"\"
    Endif
 Endif
 FileName=DND.Path+"DND"+NodeX+".CFG"
 Close #TempFile1
 Open FileName For Input Shared As #TempFile1
 Line Input #TempFile1,Var$
 For Temp1=1 To MaxConfigArray1
    Input #TempFile1,Var!
 Next
 For Temp1=1 To MaxConfigArray2
    Input #TempFile1,Var%
    Select Case Temp1
    Case 48
       Allow.High.Class=Var%
    Case 81
       Allow.Remote.Edit=Var%
    Case 86
       User.Echo=Var%
    Case 87
       User.Linefeeds=Var%
    Case 88
       User.Linelength=Var%
    Case 89
       User.Pagelength=Var%
    Case 90
       User.Wordwrap=Var%
    Case 111
       Disable.DM=Var%
    Case 112
       Disable.Nodes=Var%
    Case 113
       Disable.Sysop=Var%
    End Select
 Next
 For Temp1=1 To MaxConfigArray3
    Line Input #TempFile1,Var$
    Select Case Temp1
    Case 1
       Prelog.FileName=Var$
    Case 3
       Welcome.FileName=Var$
    Case 4
       Notice.FileName=Var$
    Case 11
       Data.Path1=Var$
    Case 12
       MonClass.FileName=Var$
    Case 13
       MonTalk.FileName=Var$
    Case 15
       File.Extension1=Var$
    Case 16
       Room.FileName=Var$
    Case 17
       Object.FileName=Var$
    Case 18
       Monster.FileName=Var$
    Case 19
       Treasure.FileName=Var$
    Case 20
       Spell.FileName=Var$
    Case 21
       User.FileName=Var$
    Case 22
       NonPlayer.FileName=Var$
    Case 28
       Logoff.FileName=Var$
    Case 38
       Logoff.Help.FileName=Var$
    Case 49
       LastUser.FileName=Var$
    Case 51
       Usage.FileName=Var$
    Case 52
       Data.Path2=Var$
    Case 53
       Data.Path3=Var$
    Case 54
       Data.Path4=Var$
    Case 55
       Help.FileName1=Var$
    Case 56
       Help.Filename2=Var$
    Case 57
       Team.FileName=Var$
    Case 58
       Public.FileName=Var$
    Case 59
       Message.Base.FileName=Var$
    Case 60
       Private.FileName=Var$
    Case 61
       Help.FileName3=Var$
    Case 62
       File.Extension2=Var$
    Case 65
       Catalog.FileName=Var$
    Case 67
       Day.Log.FileName=Var$
    Case 68
       MessWork.FileName=Var$
    Case 71
       Action.FileName=Var$
    Case 72
       Day.File.FileName=Var$
    Case 76
       Help.FileName4=Var$
    Case 80
       Container.FileName=Var$
    Case 85
       ANSIPrefixChar=Var$
    Case 86
       UserInv.FileName=Var$
    Case 87
       CtnInv.FileName=Var$
    Case 88
       TeamInv.FileName=Var$
    Case 89
       RoomInv.FileName=Var$
    Case 90
       MonInv.FileName=Var$
    Case 91
       Inline.FileName2=Var$
    Case 92
       Inline.FileName1=Var$
    Case 93
       Room.Desc.FileName=Var$
    End Select
 Next
 For Temp1=1 To 10
    For Temp2=1 To 4
       Input #TempFile1,Training.Stats(Temp1,Temp2)
    Next
 Next
 For Temp1=1 To 20
    Line Input #TempFile1,Room.Array(Temp1)
 Next
 MessWork.FileName=Data.Path3+MessWork.FileName
 For Temp1=1 To 10
    Line Input #TempFile1,High.Class.Name(Temp1)
 Next
 For Temp1=1 To 8
    Line Input #TempFile1,Race(Temp1)
 Next
 For Temp1=1 To 10
    Line Input #TempFile1,Class.Name(Temp1)
 Next
 For Temp1=1 To 7
    Line Input #TempFile1,Stat(Temp1)
 Next
 For Temp1=1 To 12
    Line Input #TempFile1,Direction(Temp1)
 Next
 For Temp1=1 To 10
    Line Input #TempFile1,Numeral(Temp1)
 Next
 For Temp1=1 To 4
    Line Input #TempFile1,Weapon.Type.Name(Temp1)
 Next
 For Temp1=1 To 3
    Line Input #TempFile1,Alignment.Name1(Temp1)
 Next
 For Temp1=1 To 3
    Line Input #TempFile1,Alignment.Name2(Temp1)
 Next
 For Temp1=1 To MaxUserCommands
    Line Input #TempFile1,Var$
    For Temp2=1 To 3
       Line Input #TempFile1,Var$
    Next
    Input #TempFile1,Var%
    For Temp2=1 To 8
       Input #TempFile1,Var%
    Next
    For Temp2=1 To 4
       Input #TempFile1,Var%
    Next
    Input #TempFile1,Var%
    Input #TempFile1,Var%
 Next
 For Temp1=1 To MaxDMcommands
    Line Input #TempFile1,Var$
    Input #TempFile1,Var%
    For Temp2=1 To 3
       Input #TempFile1,Var%
    Next
 Next
 For Temp1=1 To MaxSysopCommands
    Line Input #TempFile1,Var$
    Input #TempFile1,Var%
 Next
 For Temp1=1 To MaxNodeCommands
    Line Input #TempFile1,Var$
    For Temp2=1 To 8
       Input #TempFile1,Var%
    Next
 Next
 For Temp1=1 To MaxLetters
    Input #TempFile1,Var%
 Next
 For Temp1=1 To MaxStrips
    Line Input #TempFile1,Var$
 Next
 For Temp1=1 To 10
    Line Input #TempFile1,Var$
    Input #TempFile1,Var%
    Input #TempFile1,Var%
 Next
 For Temp1=1 To 10
    Line Input #TempFile1,InventoryNames(Temp1)
 Next
 Exit Sub
Config.Error:
 Color 14,0
 Out2="CMD037 Module - Read.Dayfile"+Chr$(13)+Chr$(10)
 Out3="Error reading "+Lcase$(FileName)+" (error:"+Str$(Err)+"). Run Dndcnfg."
 Call Terminate.Program
End Sub

Sub Increase.Files
 On Local Error Goto Increase.Error
 Close
 Call StdinInt(62,0)
 PSP.Segment=OutregsX.BX
 Def Seg=PSP.Segment
 Command.Line=&H80
 Command.Tail=Command.Line+60
 For Var=1 To 54
    Poke Command.Tail+Var-1,&HFF
 Next
 For Var=1 To 4
    File.Handle=Peek(&H18+Var-1)
    Poke Command.Tail+Var-1,File.Handle
 Next
 Poke &H32,54
 Poke &H34,Command.Tail
 Def Seg
 Close
 Exit Sub
Increase.Error:
 Color 14,0
 Out2="Error increasing file handles."+Chr$(13)+Chr$(10)
 Out3="Increase files= in config.sys or config.nt, or run Dndcnfg."
 Call Terminate.Program
End Sub

Sub Make.FileNames
 On Local Error Goto Make.Error
 Out2=Environ$("DNDDAT")
 If Out2<>Nul Then
    If Right$(Out2,1)<>"\" Then
       Out2=Out2+"\"
    Endif
    Data.Path1=Out2
 Endif
 Out2=Environ$("DNDDOC")
 If Out2<>Nul Then
    If Right$(Out2,1)<>"\" Then
       Out2=Out2+"\"
    Endif
    Data.Path2=Out2
 Endif
 Out2=Environ$("DNDTEMP")
 If Out2<>Nul Then
    If Right$(Out2,1)<>"\" Then
       Out2=Out2+"\"
    Endif
    Data.Path3=Out2
 Endif
 Out2=Environ$("DNDMESS")
 If Out2<>Nul Then
    If Right$(Out2,1)<>"\" Then
       Out2=Out2+"\"
    Endif
    Data.Path4=Out2
 Endif
 DOS.Exit="EDTDOS"+Rtrim$(NodeX)+".BAT"
 Day.Log.FileName=Data.Path1+Day.Log.FileName
 Day.File.FileName=Data.Path1+Day.File.FileName
 LastUser.FileName=Data.Path1+LastUser.FileName+File.Extension1
 Catalog.FileName=Data.Path2+Catalog.FileName+File.Extension2
 Logoff.FileName=Data.Path1+Logoff.FileName+File.Extension1
 Notice.FileName=Data.Path1+Notice.FileName+File.Extension1
 Prelog.FileName=Data.Path1+Prelog.FileName+File.Extension1
 Welcome.FileName=Data.Path1+Welcome.FileName+File.Extension1
 User.FileName=Data.Path1+User.FileName+File.Extension1
 NonPlayer.FileName=Data.Path1+NonPlayer.FileName+File.Extension1
 Room.FileName=Data.Path1+Room.FileName+File.Extension1
 Object.FileName=Data.Path1+Object.FileName+File.Extension1
 Monster.FileName=Data.Path1+Monster.FileName+File.Extension1
 Treasure.FileName=Data.Path1+Treasure.FileName+File.Extension1
 MonTalk.FileName=Data.Path1+MonTalk.FileName+File.Extension1
 MonClass.FileName=Data.Path1+MonClass.FileName+File.Extension1
 Spell.FileName=Data.Path1+Spell.FileName+File.Extension1
 Action.FileName=Data.Path1+Action.FileName+File.Extension1
 Team.FileName=Data.Path1+Team.FileName+File.Extension1
 Container.FileName=Data.Path1+Container.FileName+File.Extension1
 Message.Base.FileName=Data.Path4+Message.Base.FileName+File.Extension1
 Logon.Help.FileName=Data.Path1+Help.FileName3+File.Extension1
 UserInv.FileName=Data.Path1+UserInv.FileName+File.Extension1
 CtnInv.FileName=Data.Path1+CtnInv.FileName+File.Extension1
 TeamInv.FileName=Data.Path1+TeamInv.FileName+File.Extension1
 RoomInv.FileName=Data.Path1+RoomInv.FileName+File.Extension1
 MonInv.FileName=Data.Path1+MonInv.FileName+File.Extension1
 Room.Desc.FileName=Data.Path1+Room.Desc.FileName+File.Extension1
 Usage.FileName=Data.Path1+Usage.FileName+File.Extension1
 Help.FileName1=Data.Path1+Help.FileName1+File.Extension1
 Help.FileName2=Data.Path1+Help.FileName2+File.Extension1
 Logoff.Help.FileName=Data.Path1+Logoff.Help.FileName+File.Extension1
 DayFileRecLen=Len(BufferRecord)
 Exit Sub
Make.Error:
 Color 14,0
 Out2="CMD037 Module - Read.Dayfile"+Chr$(13)+Chr$(10)
 Out3="Error making "+Lcase$(FileName)+" (error:"+Str$(Err)+"). Increase files= in config.sys or run Dndcnfg."+Chr$(13)+Chr$(10)
 Call Terminate.Program
End Sub

Sub Open.Files
 On Local Error Goto Open.Error
 Close
 ActionRecLen=Len(ActionRecord)
 BufferRecLen=Len(BufferRecord)
 ContainerRecLen=Len(ContainerRecord)
 HelpRecLen1=Len(HelpRecord1)
 HelpRecLen2=Len(HelpRecord2)
 HelpRecLen3=Len(HelpRecord3)
 MessBaseRecLen=Len(MessageBaseRecord)
 MessageRecLen=Len(BufferRecord)
 MonsterRecLen=Len(MonsterRecord)
 NewMessRecLen=Len(NewMessages)
 TableRecLen=Len(TableRecord)
 UserRecLen=Len(UserRecord)
 UserProfileRecLen=Len(UserProfile)
 MonClassRecLen=Len(MonClassRecord)
 MonTalkRecLen=Len(BufferRecord)
 NonPlayerRecLen=Len(MonsterRecord)
 ObjectRecLen=Len(ObjectRecord)
 RoomDescLen=Len(BufferRecord)
 RoomRecLen=Len(RoomRecord)
 SpellRecLen=Len(SpellRecord)
 TeamRecLen=Len(TeamRecord)
 TreasureRecLen=Len(TreasureRecord)
 MessWorkRecLen1=Len(MessWorkRecord1)
 MessWorkRecLen2=Len(MessWorkRecord2)
 MessWorkRecLen3=Len(MessWorkRecord3)
 MessWorkRecLen5=Len(MessWorkRecord5)
 MessWorkRecLen4=Len(MessWorkRecord4)
 MessWorkRecLen6=Len(MessWorkRecord6)
 MessWorkRecLen7=Len(MessWorkRecord7)
 FileName=DND.Path+"ACCOUNTS.SIC"
 Open FileName For Random Shared As #SicFile Len=UserProfileRecLen

 FileName=User.FileName
 Open FileName For Random Shared As #UserFile Len=UserRecLen
 Open FileName For Random Shared As #UserFile2 Len=UserRecLen

 FileName=NonPlayer.FileName
 Open FileName For Random Shared As #NonPlayerFile Len=NonPlayerRecLen
 FileName=Room.FileName
 Open FileName For Random Shared As #RoomFile Len=RoomRecLen
 FileName=Object.FileName
 Open FileName For Random Shared As #ObjectFile Len=ObjectRecLen
 FileName=Monster.FileName
 Open FileName For Random Shared As #MonsterFile Len=MonsterRecLen
 FileName=Treasure.FileName
 Open FileName For Random Shared As #TreasureFile Len=TreasureRecLen
 FileName=MonTalk.FileName
 Open FileName For Random Shared As #MonTalkFile Len=MonTalkRecLen
 FileName=MonClass.FileName
 Open FileName For Random Shared As #MonClassFile Len=MonClassRecLen
 FileName=Spell.FileName
 Open FileName For Random Shared As #SpellFile Len=SpellRecLen
 FileName=Action.FileName
 Open FileName For Random Shared As #ActionFile Len=ActionRecLen
 FileName=Help.FileName1
 Open FileName For Random Shared As #HelpFile1 Len=HelpRecLen1
 FileName=Team.FileName
 Open FileName For Random Shared As #TeamFile Len=TeamRecLen
 FileName=Container.FileName
 Open FileName For Random Shared As #ContainerFile Len=ContainerRecLen
 FileName=Message.Base.FileName
 Open FileName For Random Shared As #MessBaseFile Len=MessBaseRecLen
 FileName=UserInv.FileName
 Open FileName For Random Shared As #UserInvFile Len=MessWorkRecLen6
 FileName=CtnInv.FileName
 Open FileName For Random Shared As #CtnInvFile Len=MessWorkRecLen6
 FileName=TeamInv.FileName
 Open FileName For Random Shared As #TeamInvFile Len=MessWorkRecLen6
 FileName=RoomInv.FileName
 Open FileName For Random Shared As #RoomInvFile Len=MessWorkRecLen6
 FileName=MonInv.FileName
 Open FileName For Random Shared As #MonInvFile Len=MessWorkRecLen6
 FileName=Room.Desc.FileName
 Open FileName For Random Shared As #RoomDescFile Len=RoomDescLen
 FileName=MessWork.FileName+"1"+File.Extension1
 Open FileName For Random Shared As #MessWorkFile1 Len=MessWorkRecLen1
 FileName=MessWork.FileName+"6"+File.Extension1
 Open FileName For Random Shared As #MessWorkFile6 Len=MessWorkRecLen6
 FileName=MessWork.FileName+"7"+File.Extension1
 Open FileName For Random Shared As #MessWorkFile7 Len=MessWorkRecLen7
 Exit Sub
Open.Error:
 Color 14,0
 Out2="CMD037 Module - Read.Dayfile"+Chr$(13)+Chr$(10)
 Out3="Error opening "+Lcase$(FileName)+" (error:"+Str$(Err)+"). Increase files= in config.sys or run Dndcnfg."+Chr$(13)+Chr$(10)
 Call Terminate.Program
End Sub

Sub Read.Options
 On Local Error Goto Error.Trap13
 Redim Options.Array(1 To 165) As String
 Options.Lines=165
 Var=0
 Close #TempFile1
 Filename2$=DND.Path+"option"+nodex+".cfg"
 If Dir$(Filename2$)<>Nul Then
    Open Filename2$ For Input As #TempFile1
    Do
       If Eof(TempFile1) Then
          Exit Do
       Endif
       Line Input #TempFile1, Var$
       Var$=Rtrim$(Var$)
       If Left$(Var$,1)=";" Then
          Eat$ = Nul
       Else
          If Len(Var$) Then
             Var=Var+1
             If Var>Options.Lines Then
                Options.Lines=Options.Lines+10
                Redim Preserve Options.Array(1 To Options.Lines) As String
             Endif
             Options.Array(Var)=Var$
          Endif
       Endif
    Loop
 Endif
 Options.Lines=Var
Error.Resume13:
 Exit Sub
Error.Trap13:
 Color 14,0
 Out2="CMD037 Module - Read.Dayfile"+Chr$(13)+Chr$(10)
 Out3="Error"+Str$(Err)+" reading "+FileName2$+". Edit file and restart."
 Call Terminate.Program
 Resume Error.Resume13
End Sub

Sub Reset.Cursor
 On Local Error Goto ErrMain13
 Call ScreenANSI(1,37,7)
 Locate Max.Row-1,1,1
 Graphics.Off=False
 Line.Length=False
MainExit13:
 Exit Sub
ErrMain13:
 Resume MainExit13
End Sub

Sub Detect.Share
 On Local Error Goto ErrResume149b
 Call Plex.Function(16)
 If (OutregsX.AX And &HFF)=&HFF Then
    Share.Installed=True
 Else
    Share.Installed=False
 Endif
 Windows.Detected = False
 Call Plex.Function(22)
 If OutregsX.BX>0 Then
    Windows.Detected = True
    ' store windows version
    Win.Minor=OutregsX.BX And &HFF
    Win.Major=(OutregsX.BX And &HFF00)/256
 Endif
ErrExit149b:
 Exit Sub
ErrResume149b:
 Resume ErrExit149b
End Sub

Sub Read.Rows(Var)
 On Local Error Goto Error.Trap62x
 Temp1=50
 Locate 50,1,0
 Var=50
 Exit Sub
Next.Trap1:
 Temp1=43
 Locate 43,1,0
 Var=43
 Exit Sub
Next.Trap2:
 Temp1=25
 Locate 25,1,0
 Var=25
 Exit Sub
Next.Trap3:
 Var=12
Error.Resume62x:
 Exit Sub
Error.Trap62x:
 If Temp1=50 Then
    Resume Next.Trap1
 Endif
 If Temp1=43 Then
    Resume Next.Trap2
 Endif
 If Temp1=25 Then
    Resume Next.Trap3
 Endif
 Resume Error.Resume62x
End Sub

Sub Search.Mess.File(Var1!,Var2)
 On Local Error Goto ErrMain41
 Var2=False
 For TempA=False To MaxNodes
    Call Read.Message.Record(MessWorkFile1,TempA+1)
    Var$=MessWorkRecord1.UserName
    Select Case Rtrim$(Lcase$(Var$))
    Case "login", "logoff", "relogin"
       TempB=False
    Case Deleted$, Offline$
       TempB=False
    Case Else
       TempB=True
    End Select
    If TempB Then
       If MessWorkRecord1.UserIndex=Var1! Then
          Var2=True
          Exit For
       Endif
    Endif
 Next
MainExit41:
 Exit Sub
ErrMain41:
 Resume MainExit41
End Sub

Sub Clear.Status.Line
 On Local Error Goto Error.Trap58a
 Temp$=Space$(79)
 Call Display.Status.Line(False)
Error.Resume58a:
 Exit Sub
Error.Trap58a:
 Resume Error.Resume58a
End Sub

Sub Save.Screen2(Var)
 On Local Error Goto Error.Trap62
 If Var=False Then
    VarX3=(Max.Row-1)*80+80
    Redim Temp.ArrayY(VarX3) As Long
    Redim Temp.ArrayZ(VarX3) As Double
    For Var1=1 To Max.Row
       For Var2=1 To 80
          TempZ1=Screen(Var1,Var2)
          TempZ2=Screen(Var1,Var2,1)
          VarX2=(Var1-1)*80+Var2
          Temp.ArrayY(VarX2)=TempZ1
          Temp.ArrayZ(VarX2)=TempZ2
       Next
    Next
 Else
    Cls
    For VarX=Max.Row To 1 Step -1
       For VarY=1 To 80
          VarX2=(VarX-1)*80+VarY
          If Temp.ArrayY(VarX2)<>32 Then
             Goto Next.Line
          Endif
       Next
    Next
Next.Line:
    TempX=VarX
    For Var1=1 To VarX ' Max.Row
       For Var2=1 To 80
          VarX2=(Var1-1)*80+Var2
          VarB=Int(Temp.ArrayZ(VarX2)/16)
          VarF=Temp.ArrayZ(VarX2) Mod 16
          TempZ1=Temp.ArrayY(VarX2)
          Locate Var1,Var2,0
          Color VarF,VarB
          Print Chr$(TempZ1);
       Next
    Next
 Endif
Error.Resume62:
 Exit Sub
Error.Trap62:
 Resume Error.Resume62
End Sub

