 Rem File: EditcmdA for Dndbbs Version v5.0a Release r2.0
 Rem $Include: 'edit.inc'

 On Error Goto ErrMain0
 If Chained2=False Then
    Call Open.Arrays
    Call Get.Config
    Call Increase.Files
    Call Make.FileNames
    Call Open.Files
    Call Reset.Cursor
    Call Detect.Share
    Call Save.Screen2(0)
    Call Passwrd9(Var,"a")
    If Var=False Then
       Call Terminate.Program
       End
    Endif
 Endif
 Call Edit.User
MainExit0:
 End
ErrMain0:
 Resume MainExit0
 End

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 Edit.User
 On Local Error Goto ErrResume1
 Call Edit.Status.Line
 If Lof(UserFile2)=SFalse Then
    Call Add.User
 Endif
 Do While Lost.Carrier=False
    If TempC=False Then
       Graphics.Off=False
       Strng="User Edit utility v"+Left$(Version$,4)+" menu:"
       Call IO.O
       Graphics.Off=True
       Strng=RT$(496,"[A]")+"dd"
       Call IO.O
       Strng=RT$(497,"[C]")+"hange"
       Call IO.O
       Strng=RT$(498,"[D]")+"elete"
       Call IO.O
       Strng=RT$(579,"[F]")+"ind"
       Call IO.O
       Strng=RT$(499,"[L]")+"ist"
       Call IO.O
       Strng=RT$(500,"[P]")+"ack"
       Call IO.O
       Strng=RT$(501,"[R]")+"epair"
       Call IO.O
       Strng=RT$(502,"[S]")+"ort"
       Call IO.O
       Strng=RT$(503,"[U]")+"pdate"
       Call IO.O
       Strng=RT$(701,"[V]")+"ehicles"
       Call IO.O
       If Local.Mode Then
          Strng=RT$(593,"[X]")+"Sysnews"
          Call IO.O
          Strng=RT$(594,"[Y]")+"Print"
          Call IO.O
       Endif
       Graphics.Off=False
    Endif
    Strng="User edit option(q to quit)? "
    Line.Length=TempD
    No.Input.Out="Q"
    Call IO.I
    Select Case Ucase$(Out2)
    Case "A"
       If RT$(496,"[A]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Add.User
          Temp5!=Lof(UserFile2)/UserRecLen
          Call Modify.User
       Endif
    Case "C"
       If RT$(497,"[C]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Find.User(0)
          If Temp5! Then
             Call Modify.User
          Endif
       Endif
    Case "D"
       If RT$(498,"[D]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Remove.User
       Endif
    Case "F"
       If RT$(579,"[F]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Search.Users
       Endif
    Case "L"
       If RT$(499,"[L]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call List.User
       Endif
    Case "P"
       If RT$(500,"[P]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Pack.Users
       Endif
    Case "R"
       If RT$(501,"[R]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Repair.Users(True)
       Endif
    Case "S"
       If RT$(502,"[S]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Sort.Users
       Endif
    Case "U"
       If RT$(503,"[U]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Update.Users
       Endif
    Case "V"
       If RT$(701,"[V]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Edit.Vehicles
       Endif
    Case "X"
       If Local.Mode Then
          If RT$(593,"[X]")="[*]" Then
             Strng="Command restricted.."
             Call IO.O
          Else
             Call Edit.Sysnews
          Endif
       Endif
    Case "Y"
       If Local.Mode Then
          If RT$(594,"[Y]")="[*]" Then
             Strng="Command restricted.."
             Call IO.O
          Else
             Call Print.Users
          Endif
       Endif
    Case "Q"
       Exit Do
    End Select
 Loop
 Close
 Call Clear.Status.Line
 If Chained2 Then
    Chain DND.Path+"EDIT.EXE"
 Endif
 Call Terminate.Program
ErrExit1:
 Exit Sub
ErrResume1:
 Resume ErrExit1
End Sub

Sub Add.User
 On Local Error Goto ErrResume2
 Temp5!=Lof(UserFile2)/UserRecLen+1!
 Call Delete.User
 Call Write.Record(UserFile2,Temp5!)
 Call Clear.Team(Temp5!)
 Call Clear.UserInv(Temp5!)
 Call Clear.Containers(Temp5!)
 UserRecord.ObjectsCreated(10)=UserRecord.ObjectsCreated(10)+1#
 If User.Index Then
    Call Write.Record(UserFile,User.Index)
 Endif
ErrExit2:
 Exit Sub
ErrResume2:
 Resume ErrExit2
End Sub

Sub Add.List.Node3(VarZ!)
 On Local Error Goto ErrorTrp27b
 If UserRecord2.First=SFalse Then
    UserRecord2.First=VarZ!
    UserRecord2.Last=VarZ!
    Call Write.Record(UserFile2,Temp5!)
    MessWorkRecord6.Prev=SFalse
    MessWorkRecord6.Next=SFalse
    Call Write.Record(UserInvFile,VarZ!)
    Exit Sub
 Endif
 MessWorkRecord6.Prev=UserRecord2.Last
 MessWorkRecord6.Next=SFalse
 Call Write.Record(UserInvFile,VarZ!)
 Call Read.Record(UserInvFile,UserRecord2.Last)
 MessWorkRecord6.Next=VarZ!
 Call Write.Record(UserInvFile,UserRecord2.Last)
 Call Read.Record(UserInvFile,VarZ!)
 UserRecord2.Last=VarZ!
 Call Write.Record(UserFile2,Temp5!)
ErrorRsm27b:
 Exit Sub
ErrorTrp27b:
 Resume ErrorRsm27b
End Sub

Sub Delete.List.Node3(VarZ!)
 On Local Error Goto ErrorTrp32a
 If UserRecord2.First=VarZ! Then
    Call Read.Record(UserInvFile,VarZ!)
    UserRecord2.First=MessWorkRecord6.Next
    Call Write.Record(UserFile2,Temp5!)
    If UserRecord2.First>SFalse Then
       Call Read.Record(UserInvFile,UserRecord2.First)
       MessWorkRecord6.Prev=SFalse
       Call Write.Record(UserInvFile,UserRecord2.First)
    Endif
 Else
    If UserRecord2.Last=VarZ! Then
       Call Read.Record(UserInvFile,VarZ!)
       UserRecord2.Last=MessWorkRecord6.Prev
       Call Write.Record(UserFile2,Temp5!)
       If UserRecord2.Last>SFalse Then
          Call Read.Record(UserInvFile,UserRecord2.Last)
          MessWorkRecord6.Next=SFalse
          Call Write.Record(UserInvFile,UserRecord2.Last)
       Endif
    Else
       Call Read.Record(UserInvFile,VarZ!)
       Previous.Node!=MessWorkRecord6.Prev
       Next.Node!=MessWorkRecord6.Next
       Call Read.Record(UserInvFile,Previous.Node!)
       MessWorkRecord6.Next=Next.Node!
       Call Write.Record(UserInvFile,Previous.Node!)
       Call Read.Record(UserInvFile,Next.Node!)
       MessWorkRecord6.Prev=Previous.Node!
       Call Write.Record(UserInvFile,Next.Node!)
    Endif
 Endif
ErrorRsm32a:
 Exit Sub
ErrorTrp32a:
 Resume ErrorRsm32a
End Sub

Sub Modify.User
 On Local Error Goto ErrResume4
 Call Read.Record(UserFile2,Temp5!)
 Do While Lost.Carrier=False
    Call Write.Record(UserFile2,Temp5!)
    Allow.Break=True
    Break=False
    For VarQ=1 To 21
       Call Display.User(True,VarQ)
       If Break Then
	  Exit For
       Endif
    Next
    Allow.Break=False
    Call Search.Mess.File(Temp5!,VarX)
    VarY=TempA
    Strng="User change option(q to quit)? "
    Graphics.Off=False
    Line.Length=TempD
    No.Input.Out="Q"
    Call IO.I
    Select Case Ucase$(Out2)
    Case "A"
       If RT$(505,"[A]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          If Local.Mode=False And Allow.Remote.Edit=False Then
             Strng="Remote DMs cannot edit codename."
             Call IO.O
          Else
             Line.Length=30
             Strng="Codename? "
             Call IO.I
             If Out2<>Nul Then
                Out2=Ucase$(Out2)
                Call Valid(Out2,30)
                If Out2=Nul Then
                   Strng="Illegal characters in codename."
                   Call IO.O
                Else
                   UserRecord2.CodeName=Out2
                   If VarX Then
                      Call Read.Message.Record(MessWorkFile7,VarY+1)
                      MessWorkRecord7.CodeName=Out2
                      MessWorkRecord7.Flags1=MessWorkRecord7.Flags1 Or 2^1
                      Call Write.Message.Record(MessWorkFile7,VarY+1)
                   Endif
                Endif
             Endif
          Endif
       Endif
    Case "B"
       If RT$(506,"[B]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          If Local.Mode=False And Allow.Remote.Edit=False Then
             Strng="Remote DMs cannot edit password."
             Call IO.O
          Else
             Strng="Change password(y/n)? "
             Call IO.I
             If Yes Then
                Hidden=True
                Line.Length=20
                Strng="Enter password? "
                Call IO.I
                Strng2=Out2
                Hidden=False
                If Len(Out2)<3 Then
                   Strng="Password must be at least 3 chars."
                   Call IO.O
                Endif
                If Len(Out2)>=3 Then
                   Out3=Ucase$(Out2)
                   Hidden=True
                   Line.Length=20
                   Strng="Enter password again? "
                   Call IO.I
                   Hidden=False
                   If Len(Out3)<3 Then
                      Strng="Password must be at least 3 chars."
                      Call IO.O
                   Endif
                   If Len(Out2)>=3 Then
                      Out2=Ucase$(Out2)
                      If Out2<>Out3 Then
                         Strng="Passwords don't match!"
                         Call IO.O
                      Else
                         Call Cryptograph(Out2)
                         UserRecord2.PassWord=Out2
                         Call Crypto(Out3)
                         UserRecord2.PassWord3=Out3
                         Strng="Password changed."
                         Call IO.O
                         If VarX Then
                            Call Read.Message.Record(MessWorkFile7,VarY+1)
                            MessWorkRecord7.PassWord=Out3
                            MessWorkRecord7.Flags1=MessWorkRecord7.Flags1 Or 2^2
                            Call Write.Message.Record(MessWorkFile7,VarY+1)
                         Endif
                      Endif
                   Endif
                Endif
             Endif
             Strng="Change password question(y/n)? "
             Call IO.I
             If Yes Then
                Strng="Enter question:"
                Call IO.I
                Out2=Out2+Space$(80-Len(Out2))
                Call Crypto(Out2)
                UserRecord2.Question=Out2
                Strng="Enter answer:"
                Call IO.I
                Out2=Out2+Space$(20-Len(Out2))
                Call Crypto(Out2)
                UserRecord2.Answer=Out2
             Endif
          Endif
       Endif
    Case "C"
       If RT$(507,"[C]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Strng="Level(0-32767)? "
          No.Input.Out="1"
          Call IO.I
          Temp#=Cdbl(Int(Val(Out2)))
          If Temp#>MaxInt Then
             Temp#=MaxInt
          Endif
          Temp3=Cint(Temp#)
          If Temp3>=0 Then
             UserRecord2.Level=Temp3
             If VarX Then
                Call Read.Message.Record(MessWorkFile7,VarY+1)
                MessWorkRecord7.Level=Temp3
                MessWorkRecord7.Flags1=MessWorkRecord7.Flags1 Or 2^3
                Call Write.Message.Record(MessWorkFile7,VarY+1)
             Endif
             Select Case Temp3
             Case IS>32000
                Strng="User is a Ghod and has Dungeon Master access."
                Call IO.O
             Case IS>9999
                Strng="User has Dungeon Master access."
                Call IO.O
             Case IS>999
                Strng="User has Assistant Dungeon Master access."
                Call IO.O
             End Select
          Endif
          Call New.Stats(True)
          Do While Lost.Carrier=False
             Graphics.Off=True
             If TempC=False Then
                For Temp3=1 To MaxRaces
                   Strng=RT$(522+Temp3,"["+Chr$(64+Temp3)+"]")
                   Strng=Strng+Rtrim$(Race(Temp3))
                   Call IO.O
                Next
             Endif
             Graphics.Off=False
             Strng="Race option(a-h/q to quit)? "
             Line.Length=TempD
             No.Input.Out="Q"
             Call IO.I
             Var$=Ucase$(Out2)
             Select Case Var$
             Case "A" To "H"
                Temp3=Asc(Var$)-64
                If RT$(522+Temp3,"[?]")="[*]" Then
                   Strng="Command restricted.."
                   Call IO.O
                Else
                   UserRecord2.Race=Temp3
                   If VarX Then
                      Call Read.Message.Record(MessWorkFile7,VarY+1)
                      MessWorkRecord7.Race=Temp3
                      MessWorkRecord7.Flags3=MessWorkRecord7.Flags3 Or 2^8
                      Call Write.Message.Record(MessWorkFile7,VarY+1)
                   Endif
                   Call New.Stats(True)
                Endif
             Case "Q"
                Exit Do
             End Select
          Loop
       Endif
    Case "D"
       If RT$(508,"[D]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Do While Lost.Carrier=False
             Graphics.Off=True
             If TempC=False Then
                For Temp3=1 To MaxClasses
                   Strng=RT$(530+Temp3,"["+Chr$(64+Temp3)+"]")
                   Strng=Strng+Rtrim$(Class.Name(Temp3))
                   Call IO.O
                Next
                Strng="Class option(a-h/q to quit)? "
                If Local.Mode Or Sysop Then
                   Strng=RT$(595,"[I]")+Rtrim$(Class.Name(9))
                   Call IO.O
                   Strng=RT$(596,"[J]")+Rtrim$(Class.Name(10))
                   Call IO.O
                   Strng="Class option(a-j/q to quit)? "
                Endif
                Graphics.Off=False
             Endif
             Line.Length=TempD
             No.Input.Out="Q"
             Call IO.I
             Var$=Ucase$(Out2)
             Select Case Var$
             Case "A" To "H"
                Temp3=Asc(Var$)-64
                If RT$(530+Temp3,"[?]")="[*]" Then
                   Strng="Command restricted.."
                   Call IO.O
                Else
                   UserRecord2.ClassType=Temp3
                   If VarX Then
                      Call Read.Message.Record(MessWorkFile7,VarY+1)
                      MessWorkRecord7.ClassType=Temp3
                      MessWorkRecord7.Flags1=MessWorkRecord7.Flags1 Or 2^4
                      Call Write.Message.Record(MessWorkFile7,VarY+1)
                   Endif
                   Var$=Rtrim$(Class.Name(Temp3))
                   Strng="Change classname to "+Quote$+Var$+Quote$+"(y/n)? "
                   Call IO.I
                   If Yes Then
                      UserRecord2.ClassName=Var$
                      If VarX Then
                         Call Read.Message.Record(MessWorkFile7,VarY+1)
                         MessWorkRecord7.Classname=Var$
                         MessWorkRecord7.Flags1=MessWorkRecord7.Flags1 Or 2^10
                         Call Write.Message.Record(MessWorkFile7,VarY+1)
                      Endif
                   Endif
                   Call New.Stats(True)
                Endif
             Case "I", "J"
                If Local.Mode Or Sysop Then
                   Temp3=Asc(Var$)-64
                   If RT$(586+Temp3,"[?]")="[*]" Then
                      Strng="Command restricted.."
                      Call IO.O
                   Else
                      UserRecord2.ClassType=Temp3
                      If VarX Then
                         Call Read.Message.Record(MessWorkFile7,VarY+1)
                         MessWorkRecord7.ClassType=Temp3
                         MessWorkRecord7.Flags1=MessWorkRecord7.Flags1 Or 2^4
                         Call Write.Message.Record(MessWorkFile7,VarY+1)
                      Endif
                      Var$=Rtrim$(Class.Name(Temp3))
                      Strng="Change classname to "+Quote$+Var$+Quote$+"(y/n)? "
                      Call IO.I
                      If Yes Then
                         UserRecord2.ClassName=Var$
                         If VarX Then
                            Call Read.Message.Record(MessWorkFile7,VarY+1)
                            MessWorkRecord7.Classname=Var$
                            MessWorkRecord7.Flags1=MessWorkRecord7.Flags1 Or 2^10
                            Call Write.Message.Record(MessWorkFile7,VarY+1)
                         Endif
                      Endif
                      Call New.Stats(True)
                   Endif
                Endif
             Case "Q"
                Exit Do
             End Select
          Loop
       Endif
    Case "E"
       If RT$(509,"[E]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Do While Lost.Carrier=False
             Graphics.Off=True
             If TempC=False Then
                For Temp3=1 To MaxWeapons
                   Strng=RT$(538+Temp3,"["+Chr$(64+Temp3)+"]")
                   Strng=Strng+Rtrim$(Weapon.Type.Name(Temp3))
                   Call IO.O
                Next
                Graphics.Off=False
             Endif
             Strng="Weapon proficiency(a-d/q to quit)? "
             Line.Length=TempD
             No.Input.Out="Q"
             Call IO.I
             Var$=Ucase$(Out2)
             Select Case Var$
             Case "A" To "D"
                Temp3=Asc(Var$)-64
                If RT$(538+Temp3,"[?]")="[*]" Then
                   Strng="Command restricted.."
                   Call IO.O
                Else
                   UserRecord2.Proficiency=Temp3
                   If VarX Then
                      Call Read.Message.Record(MessWorkFile7,VarY+1)
                      MessWorkRecord7.Proficiency=Temp3
                      MessWorkRecord7.Flags1=MessWorkRecord7.Flags1 Or 2^5
                      Call Write.Message.Record(MessWorkFile7,VarY+1)
                   Endif
                Endif
             Case "Q"
                Exit Do
             End Select
          Loop
       Endif
    Case "F"
       If RT$(510,"[F]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Strng="Blunt weapon proficiency%(1-100)? "
          No.Input.Out="10"
          Call IO.I
          Temp3=Int(Val(Out2))
          UserRecord2.Weapons(1)=Temp3
          If VarX Then
             Call Read.Message.Record(MessWorkFile7,VarY+1)
             MessWorkRecord7.Weapon1=Temp3
             MessWorkRecord7.Flags1=MessWorkRecord7.Flags1 Or 2^6
             Call Write.Message.Record(MessWorkFile7,VarY+1)
          Endif
       Endif
    Case "G"
       If RT$(511,"[G]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Strng="Pole weapon proficiency%(1-100)? "
          No.Input.Out="10"
          Call IO.I
          Temp3=Int(Val(Out2))
          UserRecord2.Weapons(2)=Temp3
          If VarX Then
             Call Read.Message.Record(MessWorkFile7,VarY+1)
             MessWorkRecord7.Weapon2=Temp3
             MessWorkRecord7.Flags1=MessWorkRecord7.Flags1 Or 2^7
             Call Write.Message.Record(MessWorkFile7,VarY+1)
          Endif
       Endif
    Case "H"
       If RT$(512,"[H]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Strng="Sharp weapon proficiency%(1-100)? "
          No.Input.Out="10"
          Call IO.I
          Temp3=Int(Val(Out2))
          UserRecord2.Weapons(3)=Temp3
          If VarX Then
             Call Read.Message.Record(MessWorkFile7,VarY+1)
             MessWorkRecord7.Weapon3=Temp3
             MessWorkRecord7.Flags1=MessWorkRecord7.Flags1 Or 2^8
             Call Write.Message.Record(MessWorkFile7,VarY+1)
          Endif
       Endif
    Case "I"
       If RT$(513,"[I]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Strng="Thrusting weapon proficiency%(1-100)? "
          No.Input.Out="10"
          Call IO.I
          Temp3=Int(Val(Out2))
          UserRecord2.Weapons(4)=Temp3
          If VarX Then
             Call Read.Message.Record(MessWorkFile7,VarY+1)
             MessWorkRecord7.Weapon4=Temp3
             MessWorkRecord7.Flags1=MessWorkRecord7.Flags1 Or 2^9
             Call Write.Message.Record(MessWorkFile7,VarY+1)
          Endif
       Endif
    Case "J"
       If RT$(514,"[J]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Strng="Classname? "
          No.Input.Out=Rtrim$(UserRecord2.ClassName)
          Call IO.I
          Call Valid(Out2,20)
          If Out2=Nul Then
             Strng="Illegal characters in classname."
             Call IO.O
          Else
             UserRecord2.ClassName=Out2
             If VarX Then
                Call Read.Message.Record(MessWorkFile7,VarY+1)
                MessWorkRecord7.Classname=Out2
                MessWorkRecord7.Flags1=MessWorkRecord7.Flags1 Or 2^10
                Call Write.Message.Record(MessWorkFile7,VarY+1)
             Endif
          Endif
       Endif
    Case "K"
       If RT$(515,"[K]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Edit.User.Stats(VarX,VarY)
       Endif
    Case "L"
       If RT$(516,"[L]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Strng="Experience? "
          No.Input.Out="128"
          Call IO.I
          Temp3#=Int(Val(Out2))
          If Temp3#>1d308 Then
             Strng="Overflow"
             Call IO.O
          Else
             UserRecord2.Experience=Temp3#
             If VarX Then
                Call Read.Message.Record(MessWorkFile7,VarY+1)
                MessWorkRecord7.Experience=Temp3#
                MessWorkRecord7.Flags2=MessWorkRecord7.Flags2 Or 2^8
                Call Write.Message.Record(MessWorkFile7,VarY+1)
             Endif
          Endif
       Endif
    Case "M"
       If RT$(517,"[M]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Strng="Gold? "
          Call IO.I
          Temp3#=Int(Val(Out2))
          If Temp3#>1d308 Then
             Strng="Overflow"
             Call IO.O
          Else
             UserRecord2.Gold=Temp3#
             If VarX Then
                Call Read.Message.Record(MessWorkFile7,VarY+1)
                MessWorkRecord7.Gold=Temp3#
                MessWorkRecord7.Flags2=MessWorkRecord7.Flags2 Or 2^9
                Call Write.Message.Record(MessWorkFile7,VarY+1)
             Endif
          Endif
       Endif
    Case "N"
       If RT$(518,"[N]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Strng="Room number? "
          Call IO.I
          Var3!=Int(Val(Out2))
          UserRecord2.Room=Var3!
          If VarX Then
             Call Read.Message.Record(MessWorkFile7,VarY+1)
             MessWorkRecord7.Room=Var3!
             MessWorkRecord7.Flags2=MessWorkRecord7.Flags2 Or 2^10
             Call Write.Message.Record(MessWorkFile7,VarY+1)
          Endif
       Endif
    Case "O"
       If RT$(519,"[O]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Do While Lost.Carrier=False
             If TempC=False Then
                Graphics.Off=False
                Strng="Time edit menu:"
                If Debug.Mode Then
                   Strng=Strng+" Last date online: "+UserRecord2.Dateon
                Endif
                Call IO.O
                Graphics.Off=True
                Strng="(1)Reset time used"
                Call IO.O
                Strng="(2)Reset calls made"
                Call IO.O
                Strng="(3)Current maximum time limit(minutes): "
                Select Case UserRecord2.TimeLimit
                Case -1!
                   Strng=Strng+"Unlimited"
                Case 0!
                   Strng=Strng+"Default"
                Case Else
                   Strng=Strng+Form$(Cdbl(UserRecord2.TimeLimit))
                End Select
                Call IO.O
                Strng="(4)Current maximum calls allowed: "
                Select Case UserRecord2.MaxCalls
                Case -1
                   Strng=Strng+"Unlimited"
                Case 0
                   Strng=Strng+"Default"
                Case Else
                   Strng=Strng+Form$(Cdbl(UserRecord2.MaxCalls))
                End Select
                Call IO.O
                Strng="(5)Current time restriction: (none)"
                Var1=UserRecord2.FromHour ' 00-23
                Var2=UserRecord2.FromMin ' 00-59
                Var3=UserRecord2.ToHour ' 00-23
                Var4=UserRecord2.ToMin ' 00-59
                If Var1 Or Var2 Or Var3 Or Var4 Then
                   Strng="(5)Current time restriction: ("
                   Strng=Strng+Right$("0"+Mid$(Str$(Var1),2),2)+":"
                   Strng=Strng+Right$("0"+Mid$(Str$(Var2),2),2)+"-"
                   Strng=Strng+Right$("0"+Mid$(Str$(Var3),2),2)+":"
                   Strng=Strng+Right$("0"+Mid$(Str$(Var4),2),2)+")"
                Endif
                Call IO.O
                Strng="(6)Change user system news last read"
                Call IO.O
             Endif
             Graphics.Off=False
             No.Input.Out="Q"
             Line.Length=TempD
             Strng="Enter time edit selection(1-6, q to quit)? "
             Call IO.I
             Graphics.Off=True
             Select Case Lcase$(Out2)
             Case "q"
                Exit Do
             Case "1"
                If UserRecord2.TimeLimit>=SFalse Then
                   Var$=Str$(UserRecord2.TimeUsed/60!)
                   Var=Instr(Var$,".")
                   If Var Then
                      Var$=Left$(Var$,Var+1)
                   Else
                      Var$=Var$+".0"
                   Endif
                   Strng="Current time used(minutes):"+Var$
                   Call IO.O
                Endif
                If UserRecord2.TimeUsed>0! Then
                   Strng="Reset time used(y/n)? "
                   Call IO.I
                   If Yes Then
                      UserRecord2.TimeUsed=0!
                   Endif
                Endif
             Case "2"
                Strng="Current number of calls made today:"+Str$(Int(UserRecord2.NumCalls))
                Call IO.O
                If UserRecord2.NumCalls Then
                   Strng="Reset calls made(y/n)? "
                   Call IO.I
                   If Yes Then
                      UserRecord2.NumCalls=0
                   Endif
                Endif
             Case "3"
                Strng="Max time limit per day in minutes(-1=unlimited,0=default,1 to 32767)? "
                Call IO.I
                If Len(Out2) Then
                   Temp3!=Int(Val(Out2))
                   Select Case Temp3!
                   Case -1!, 0!, 1! to 32767!
                      UserRecord2.TimeLimit=Temp3!
                      If VarX Then
                         Call Read.Message.Record(MessWorkFile7,VarY+1)
                         MessWorkRecord7.TimeLimit=Temp3!
                         MessWorkRecord7.Flags2=MessWorkRecord7.Flags3 Or 2^1
                         Call Write.Message.Record(MessWorkFile7,VarY+1)
                      Endif
                   Case Else
                      Strng="Time limit out of range."
                      Call IO.O
                   End Select
                Endif
             Case "4"
                Strng="Max calls per day(-1=unlimited,0=default,1 to 32767)? "
                Call IO.I
                If Len(Out2) Then
                   Temp3=Val(Out2)
                   Select Case Temp3
                   Case -1, 0, 1 to 32767
                      UserRecord2.MaxCalls=Temp3
                      If VarX Then
                         Call Read.Message.Record(MessWorkFile7,VarY+1)
                         MessWorkRecord7.MaxCalls=Temp3
                         MessWorkRecord7.Flags2=MessWorkRecord7.Flags3 Or 2^2
                         Call Write.Message.Record(MessWorkFile7,VarY+1)
                      Endif
                   Case Else
                      Strng="Call limit out of range."
                      Call IO.O
                   End Select
                Endif
             Case "5"
                Graphics.Off=False
                Strng="Edit timeon restriction(y/n)? "
                No.Input.Out="N"
                Call IO.I
                If Yes Then
                   VarQ1=0:VarQ2=0:VarQ3=0:VarQ4=0
                   Graphics.Off=True
                   Strng="Timeon restriction(from hour: form HH)? "
                   No.Input.Out="00"
                   Call IO.I
                   If Len(Out2) Then
                      Temp3=Int(Val(Out2))
                      If Temp3>=0 And Temp3<=23 Then
                         VarQ1=Temp3
                      Endif
                   Endif
                   Strng="Timeon restriction(from minute: form MM)? "
                   No.Input.Out="00"
                   Call IO.I
                   If Len(Out2) Then
                      Temp3=Int(Val(Out2))
                      If Temp3>=0 And Temp3<=59 Then
                         VarQ2=Temp3
                      Endif
                   Endif
                   Strng="Timeon restriction(to hour: form HH)? "
                   No.Input.Out="00"
                   Call IO.I
                   If Len(Out2) Then
                      Temp3=Int(Val(Out2))
                      If Temp3>=0 And Temp3<=23 Then
                         VarQ3=Temp3
                      Endif
                   Endif
                   Strng="Timeon restriction(to minute: form MM)? "
                   No.Input.Out="00"
                   Call IO.I
                   If Len(Out2) Then
                      Temp3=Int(Val(Out2))
                      If Temp3>=0 And Temp3<=59 Then
                         VarQ4=Temp3
                      Endif
                   Endif
                   UserRecord2.FromHour=VarQ1
                   UserRecord2.FromMin=VarQ2
                   UserRecord2.ToHour=VarQ3
                   UserRecord2.ToMin=VarQ4
                   If VarQ1=0 And VarQ2=0 And VarQ3=0 And VarQ4=0 Then
                      Strng="Current time restriction reset."
                      Call IO.O
                   Endif
                   If VarX Then
                      Call Read.Message.Record(MessWorkFile7,VarY+1)
                      MessWorkRecord7.FromHour=VarQ1
                      MessWorkRecord7.FromMin=VarQ2
                      MessWorkRecord7.ToHour=VarQ3
                      MessWorkRecord7.ToMin=VarQ4
                      MessWorkRecord7.Flags3=MessWorkRecord7.Flags3 Or 2^3
                      MessWorkRecord7.Flags3=MessWorkRecord7.Flags3 Or 2^4
                      MessWorkRecord7.Flags3=MessWorkRecord7.Flags3 Or 2^5
                      MessWorkRecord7.Flags3=MessWorkRecord7.Flags3 Or 2^6
                      Call Write.Message.Record(MessWorkFile7,VarY+1)
                   Endif
                Endif
             Case "6"
                Graphics.Off=False
                Strng="Change user system news last read(y/n)? "
                No.Input.Out="N"
                Call IO.I
                If Yes Then
                   Strng="Enter last read date(form: MM-DD-YYYY)? "
                   No.Input.Out="01-01-1980"
                   Call IO.I
                   Strng="Invalid date."
                   If Len(Out2)=10 Then
                      TempQ=ValidDate(Out2)
                      If TempQ Then
                         UserRecord2.SysNews=Out2
                         Strng="Date changed."
                      Endif
                   Endif
                   Call IO.O
                   Call More.Prompt
                Endif
             End Select
          Loop
       Endif
    Case "P"
       If RT$(520,"[P]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Edit.User.Inv(VarX,VarY)
       Endif
    Case "R"
       If RT$(521,"[R]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Do While Lost.Carrier=False
             Graphics.Off=True
             Temp=False
             Strng="Special characters: "
             If UserRecord2.Flags And Special.Char1 Then
                Strng=Strng+"Town Mayor, "
                Temp=True
             Endif
             If UserRecord2.Flags And Special.Char2 Then
                Strng=Strng+"Governor, "
                Temp=True
             Endif
             If UserRecord2.Flags And Special.Char3 Then
                Strng=Strng+"Guild Master, "
                Temp=True
             Endif
             If UserRecord2.Flags And Special.Char4 Then
                Strng=Strng+"Sysop, "
                Temp=True
             Endif
             If Temp Then
                Strng=Left$(Strng,Len(Strng)-2)+"."
             Else
                Strng=Strng+"none."
             Endif
             Call IO.O
             If TempC=False Then
                Strng=RT$(546,"[A]")+"Town Mayor"
                Call IO.O
                Strng=RT$(547,"[B]")+"Governor"
                Call IO.O
                Strng=RT$(548,"[C]")+"Guild Master"
                Call IO.O
                Strng=RT$(549,"[D]")+"Sysop"
                Call IO.O
                Strng=RT$(550,"[E]")+"None"
                Call IO.O
                Graphics.Off=False
             Endif
             Strng="Special class option(a-e/q to quit)? "
             Line.Length=TempD
             No.Input.Out="Q"
             Call IO.I
             Select Case Ucase$(Out2)
             Case "A"
                If RT$(546,"[A]")="[*]" Then
                   Strng="Command restricted.."
                   Call IO.O
                Else
                   If (UserRecord2.Flags And Special.Char1)=Special.Char1 Then
                      UserRecord2.Flags=UserRecord2.Flags And Not Special.Char1
                      Strng="User is not Town Mayor."
                   Else
                      UserRecord2.Flags=UserRecord2.Flags Or Special.Char1
                      Strng="User is now Town Mayor."
                   Endif
                   If VarX Then
                      Call Read.Message.Record(MessWorkFile7,VarY+1)
                      MessWorkRecord7.SpecialFlags=UserRecord2.Flags
                      MessWorkRecord7.Flags3=MessWorkRecord7.Flags3 Or 2^7
                      Call Write.Message.Record(MessWorkFile7,VarY+1)
                   Endif
                   Call IO.O
                Endif
             Case "B"
                If RT$(547,"[B]")="[*]" Then
                   Strng="Command restricted.."
                   Call IO.O
                Else
                   If (UserRecord2.Flags And Special.Char2)=Special.Char2 Then
                      UserRecord2.Flags=UserRecord2.Flags And Not Special.Char2
                      Strng="User is not Governor."
                   Else
                      UserRecord2.Flags=UserRecord2.Flags Or Special.Char2
                      Strng="User is now Governor."
                   Endif
                   If VarX Then
                      Call Read.Message.Record(MessWorkFile7,VarY+1)
                      MessWorkRecord7.SpecialFlags=UserRecord2.Flags
                      MessWorkRecord7.Flags3=MessWorkRecord7.Flags3 Or 2^7
                      Call Write.Message.Record(MessWorkFile7,VarY+1)
                   Endif
                   Call IO.O
                Endif
             Case "C"
                If RT$(548,"[C]")="[*]" Then
                   Strng="Command restricted.."
                   Call IO.O
                Else
                   If (UserRecord2.Flags And Special.Char3)=Special.Char3 Then
                      UserRecord2.Flags=UserRecord2.Flags And Not Special.Char3
                      Strng="User is not Guild Master."
                   Else
                      UserRecord2.Flags=UserRecord2.Flags Or Special.Char3
                      Strng="User is now Guild Master."
                   Endif
                   If VarX Then
                      Call Read.Message.Record(MessWorkFile7,VarY+1)
                      MessWorkRecord7.SpecialFlags=UserRecord2.Flags
                      MessWorkRecord7.Flags3=MessWorkRecord7.Flags3 Or 2^7
                      Call Write.Message.Record(MessWorkFile7,VarY+1)
                   Endif
                   Call IO.O
                Endif
             Case "D"
                If RT$(549,"[D]")="[*]" Then
                   Strng="Command restricted.."
                   Call IO.O
                Else
                   If Local.Mode=False Then
                      Strng="Remote DMs cannot make Sysops."
                   Else
                      If (UserRecord2.Flags And Special.Char4)=Special.Char4 Then
                         UserRecord2.Flags=UserRecord2.Flags And Not Special.Char4
                         Strng="User is not Sysop."
                      Else
                         UserRecord2.Flags=UserRecord2.Flags Or Special.Char4
                         Strng="User is now Sysop."
                      Endif
                      If VarX Then
                         Call Read.Message.Record(MessWorkFile7,VarY+1)
                         MessWorkRecord7.SpecialFlags=UserRecord2.Flags
                         MessWorkRecord7.Flags3=MessWorkRecord7.Flags3 Or 2^7
                         Call Write.Message.Record(MessWorkFile7,VarY+1)
                      Endif
                   Endif
                   Call IO.O
                Endif
             Case "E"
                If RT$(550,"[E]")="[*]" Then
                   Strng="Command restricted.."
                   Call IO.O
                Else
                   UserRecord2.Flags=UserRecord2.Flags And Not Special.Char1
                   UserRecord2.Flags=UserRecord2.Flags And Not Special.Char2
                   UserRecord2.Flags=UserRecord2.Flags And Not Special.Char3
                   If Local.Mode Then
                      UserRecord2.Flags=UserRecord2.Flags And Not Special.Char4
                   Endif
                   If VarX Then
                      Call Read.Message.Record(MessWorkFile7,VarY+1)
                      MessWorkRecord7.SpecialFlags=UserRecord2.Flags
                      MessWorkRecord7.Flags3=MessWorkRecord7.Flags3 Or 2^7
                      Call Write.Message.Record(MessWorkFile7,VarY+1)
                   Endif
                   Strng="User is cleared of special character class."
                   Call IO.O
                Endif
             Case "Q"
                Exit Do
             End Select
          Loop
       Endif
    Case "S"
       If RT$(522,"[S]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Graphics.Off=True
          If ANSIPrefixChar=Nul Then
             Strng="ANSI prefix codes not enabled."
             Call IO.O
             Call More.Prompt
          Else
             Do While Lost.Carrier=False
                Strng="Codename ANSI prefix code(8 characters,? for help):"
                Call IO.O
                Strng="? "
                No.Input.Out=Nul
                Call IO.I
                Out2=Ucase$(Out2)
                If Out2="?" Then
                   Call Display.ANSI.Prefixes
                Else
                   Call Check.ANSI.Prefix(V%)
                   If V% Then
                      UserRecord2.Prefix1=Out2
                      If VarX Then
                         Call Read.Message.Record(MessWorkFile7,VarY+1)
                         MessWorkRecord7.Prefix1=Out2
                         MessWorkRecord7.Flags5=MessWorkRecord7.Flags5 Or 2^6
                         Call Write.Message.Record(MessWorkFile7,VarY+1)
                      Endif
                      Exit Do
                   Endif
                   Strng="Invalid ANSI code."
                   Call IO.O
                   Call More.Prompt
                Endif
             Loop
             Do While Lost.Carrier=False
                Strng="Classname ANSI prefix code(8 characters,? for help):"
                Call IO.O
                Strng="? "
                No.Input.Out=Nul
                Call IO.I
                Out2=Ucase$(Out2)
                If Out2="?" Then
                   Call Display.ANSI.Prefixes
                Else
                   Call Check.ANSI.Prefix(V%)
                   If V% Then
                      UserRecord2.Prefix2=Out2
                      If VarX Then
                         Call Read.Message.Record(MessWorkFile7,VarY+1)
                         MessWorkRecord7.Prefix2=Out2
                         MessWorkRecord7.Flags5=MessWorkRecord7.Flags5 Or 2^7
                         Call Write.Message.Record(MessWorkFile7,VarY+1)
                      Endif
                      Exit Do
                   Endif
                   Strng="Invalid ANSI code."
                   Call IO.O
                   Call More.Prompt
                Endif
             Loop
          Endif
       Endif
    Case "T" ' edit objects created
       If RT$(697,"[T]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Do While Lost.Carrier=False
             Graphics.Off=False
             Strng="Objects Created: "
             Var2#=0#
             For Var1=1 To 10
                Var2#=Var2#+UserRecord2.ObjectsCreated(Var1)
             Next
             Strng=Strng+Form$(Var2#)
             Call IO.O
             Graphics.Off=True
             For Var1=1 To 10
                Select Case Var1
                Case 1
                   Strng="[1]Actions"
                Case 2
                   Strng="[2]Monclass"
                Case 3
                   Strng="[3]Monster"
                Case 4
                   Strng="[4]Nonplayer"
                Case 5
                   Strng="[5]Object"
                Case 6
                   Strng="[6]Player"
                Case 7
                   Strng="[7]Room"
                Case 8
                   Strng="[8]Spell"
                Case 9
                   Strng="[9]Treasure"
                Case 10
                   Strng="[10]User"
                End Select
                Var2#=UserRecord2.ObjectsCreated(Var1)
                If Var2#=0# Then
                   Strng=Strng+": 0"
                Else
                   Strng=Strng+": "+Form$(Var2#)
                Endif
                Call IO.O
             Next
             If Local.Mode=False Then
                Call More.Prompt
                Exit Do
             Endif
             Graphics.Off=False
             No.Input.Out="Q"
             Strng="Objects created(1-10,Q to Quit)? "
             Call IO.I
             Out2=Ucase$(Out2)
             If Out2="Q" Then
                Exit Do
             Endif
             Var=Int(Val(Out2))
             If Var>=1 And Var<=10 Then
                Strng="Value? "
                Call IO.I
                Var2#=Int(Val(Out2))
                If Var2#>=0# Then
                   UserRecord2.ObjectsCreated(Var)=Var2#
                   If VarX Then
                      Call Read.Message.Record(MessWorkFile7,VarY+1)
                      For VarQ=1 To 10
                         MessWorkRecord7.ObjCreated(VarQ)=UserRecord2.ObjectsCreated(VarQ)
                      Next
                      MessWorkRecord7.Flags5=MessWorkRecord7.Flags5 Or 2^8
                      Call Write.Message.Record(MessWorkFile7,VarY+1)
                   Endif
                Endif
             Endif
          Loop
       Endif
    Case "W" ' wishes left
       If RT$(698,"[W]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Strng="Wishes left(-1=unlimited,0-32767)? "
          Call IO.I
          Var2=Int(Val(Out2))
          Select Case Var2
          Case -1,0 to 32767
             UserRecord2.WishsLeft=Var2
             If VarX Then
                Call Read.Message.Record(MessWorkFile7,VarY+1)
                MessWorkRecord7.Wishesleft=Var2
                MessWorkRecord7.Flags5=MessWorkRecord7.Flags5 Or 2^4
                Call Write.Message.Record(MessWorkFile7,VarY+1)
             Endif
          End Select
       Endif
    Case "Z" ' node list edit
       If Local.Mode Or Sysop Then
          If RT$(659,"[Z]")="[*]" Then
             Strng="Command restricted.."
             Call IO.O
          Else
             Call Edit.User.Nodelist(VarX,VarY)
          Endif
       Endif
    Case "!" ' command list edit
       If Local.Mode Or Sysop Then
          If RT$(663,"[!]")="[*]" Then
             Strng="Command restricted.."
             Call IO.O
          Else
             Call Edit.User.Commands(VarX,VarY)
          Endif
       Endif
    Case "Q"
       Exit Do
    End Select
 Loop
 Call Write.Record(UserFile2,Temp5!)
 Out2=Lcase$(Rtrim$(UserRecord2.CodeName))
 If Len(Out2) Then
    Mid$(Out2,1,1)=Ucase$(Mid$(Out2,1,1))
 Else
    Out2="<none>"
 Endif
 Strng="Offline"
 If VarX Then
    Strng="Online"
 Endif
 Strng=Strng+" user "+Quote$+Out2+Quote$+" modified."
 Call IO.O
ErrExit4:
 Exit Sub
ErrResume4:
 If Err=5 Then Print "Syntax error."
 If Err=6 Then Print "Overflow."
 Resume ErrExit4
End Sub

Sub Delete.User.Container(VarZ!)
 On Local Error Goto ErrorTrp32d
 If UserRecord2.First2=VarZ! Then
    Call Read.Record(ContainerFile,VarZ!)
    UserRecord2.First2=ContainerRecord.Next
    Call Write.Record(UserFile2,Temp5!)
    If UserRecord2.First2>SFalse Then
       Call Read.Record(ContainerFile,UserRecord2.First2)
       ContainerRecord.Prev=SFalse
       Call Write.Record(ContainerFile,UserRecord2.First2)
    Endif
 Else
    If UserRecord2.Last2=VarZ! Then
       Call Read.Record(ContainerFile,VarZ!)
       UserRecord2.Last2=ContainerRecord.Prev
       Call Write.Record(UserFile2,Temp5!)
       If UserRecord2.Last2>SFalse Then
          Call Read.Record(ContainerFile,UserRecord2.Last2)
          ContainerRecord.Next=SFalse
          Call Write.Record(ContainerFile,UserRecord2.Last2)
       Endif
    Else
       Call Read.Record(ContainerFile,VarZ!)
       Previous.Node!=ContainerRecord.Prev
       Next.Node!=ContainerRecord.Next
       Call Read.Record(ContainerFile,Previous.Node!)
       ContainerRecord.Next=Next.Node!
       Call Write.Record(ContainerFile,Previous.Node!)
       Call Read.Record(ContainerFile,Next.Node!)
       ContainerRecord.Prev=Previous.Node!
       Call Write.Record(ContainerFile,Next.Node!)
    Endif
 Endif
ErrorRsm32d:
 Exit Sub
ErrorTrp32d:
 Resume ErrorRsm32d
End Sub

Sub Remove.User
 On Local Error Goto ErrResume5
 Call Find.User(0)
 If Temp5!=SFalse Then
    Exit Sub
 Endif
 Call Read.Record(UserFile2,Temp5!)
 Out3=Lcase$(Rtrim$(UserRecord2.CodeName))
 If Left$(Out3,9)=Deleted$ Then
    Strng="User already deleted."
    Call IO.O
    Exit Sub
 Endif
 Strng="Delete "+Quote$+Out3+Quote$+". Are you sure(y/n/q)? "
 Line.Length=TempD
 No.Input.Out="N"
 Call IO.I
 If No Or Quit Then
    Exit Sub
 Endif
 Call Delete.User
 Call Write.Record(UserFile2,Temp5!)
 Call Clear.LogFile(Temp5!)
 Call Clear.ScrollFile(Temp5!)
 Call Clear.Team(Temp5!)
 Call Clear.UserInv(Temp5!)
 Call Clear.Containers(Temp5!)
 Strng="User deleted."
 Call IO.O
 No.Input.Out="N"
 Strng="Permanently delete user(y/n)? "
 Call IO.I
 If Yes Then
    FileName=DND.Path+"delete.log"
    Close #TempFile1
    Open FileName For Append Shared As #TempFile1
    Strng="Reason for deletion: "
    Call IO.I
    If Len(Out2)=0 Then
       Out2="Locked out."
    Endif
    Print #TempFile1,Out3
    Print #TempFile1,Fclock$
    Print #TempFile1,Out2
    Close #TempFile1
 Endif
ErrExit5:
 Exit Sub
ErrResume5:
 Resume ErrExit5
End Sub

Sub Delete.User
 On Local Error Goto ErrResume6
 Strng=Deleted$
 Var3$=Strng
 Call Cryptograph(Var3$)
 UserRecord2.PassWord=Var3$
 Var3$=Strng
 Call Crypto(Var3$)
 UserRecord2.Password3=Var3$
 UserRecord2.Password2=Nul
 UserRecord2.Question=Nul
 UserRecord2.ClassName=Deleted$
 UserRecord2.ClassType=1
 UserRecord2.CodeName=Deleted$
 For Var=1 To MaxStats
    UserRecord2.Stats(Var)=12
 Next
 UserRecord2.Beauty=12
 UserRecord2.Glamour=12
 For Temp6=1 To MaxWeapons
    UserRecord2.Weapons(Temp6)=False
 Next
 UserRecord2.Room=SFalse
 UserRecord2.Level=False
 UserRecord2.Experience=DFalse
 UserRecord2.Gold=DFalse
 UserRecord2.Borrow=False
 UserRecord2.NumCalls=False
 UserRecord2.Fatigue=False
 UserRecord2.FatigueMax=False
 UserRecord2.Vitality=False
 UserRecord2.VitalityMax=False
 UserRecord2.Magic=False
 UserRecord2.MagicMax=False
 UserRecord2.Psionic=False
 UserRecord2.PsionicMax=False
 UserRecord2.Poison=False
 UserRecord2.Invisible=False
 UserRecord2.Race=1
 UserRecord2.Proficiency=1
 UserRecord2.Bank=False
 UserRecord2.PlayersKilled=False
 UserRecord2.MonstersKilled=False
 UserRecord2.Brief=False
 UserRecord2.DateOn=DateS$
 UserRecord2.Align1=False
 UserRecord2.Align2=False
 UserRecord2.Flags=False
 UserRecord2.Flags2=False
 UserRecord2.MaxCalls=False
 UserRecord2.FromHour=False
 UserRecord2.FromMin=False
 UserRecord2.ToHour=False
 UserRecord2.ToMin=False
 UserRecord2.SortInv=False
 For Var=1 To MaxItems
    UserRecord2.Weapon(Var).Index=SFalse
    UserRecord2.Weapon(Var).Charges=False
    UserRecord2.Weapon(Var).Plus=False
 Next
 UserRecord2.TimeLimit=SFalse
 UserRecord2.TimeUsed=SFalse
 UserRecord2.TimesLogon=0#
 UserRecord2.TimesDied=0#
 UserRecord2.Encumbrance=10
 UserRecord2.Prefix1=Nul
 UserRecord2.Prefix2=Nul
 UserRecord2.Prefix3=Nul
 For Var=1 To MaxShortcutKeys
    UserRecord2.ShortcutKey1(Var)=Nul
    UserRecord2.ShortcutKey2(Var)=Nul
 Next
 For Var=1 To 10
    UserRecord2.FunctionKeys(Var)=Nul
 Next
 UserRecord2.ActionLineString = ""
 UserRecord2.StatusLineString = ""
 UserRecord2.StatusVar=0
 UserRecord2.NodeList=String$(127,"1")
 UserRecord2.NodeList2=0!
 UserRecord2.EditList=0!
 UserRecord2.First=SFalse
 UserRecord2.Last=SFalse
 UserRecord2.First2=SFalse
 UserRecord2.Last2=SFalse
 UserRecord2.Buffer22=0!
 UserRecord2.Buffer23=0!
 UserRecord2.Buffer24=0#
 UserRecord2.Buffer25=0#
ErrExit6:
 Exit Sub
ErrResume6:
 Resume ErrExit6
End Sub

Sub Clear.LogFile(VarX!)
 On Local Error Goto ErrorTrap33
 Close #LogFile
 Open Log.FileName For Random Shared As #LogFile Len=LogRecLen
 For Var5!=1! To Lof(LogFile)/LogRecLen
    Call Read.Record(LogFile,Var5!)
    If LogRecord.User=VarX! Then
       LogRecord.User=SFalse
       Call Write.Record(LogFile,Var5!)
    Endif
 Next
ErrorResume33:
 Exit Sub
ErrorTrap33:
 Resume ErrorResume33
End Sub

Sub Swap.LogFile(VarX!,VarY!)
 On Local Error Goto ErrorTrap33d
 Close #LogFile
 Open Log.FileName For Random Shared As #LogFile Len=LogRecLen
 For Var5!=1! To Lof(LogFile)/LogRecLen
    Call Read.Record(LogFile,Var5!)
    If LogRecord.User=VarX! Then
       LogRecord.User=VarY!
       Call Write.Record(LogFile,Var5!)
    Else
       If LogRecord.User=VarY! Then
          LogRecord.User=VarX!
          Call Write.Record(LogFile,Var5!)
       Endif
    Endif
 Next
ErrorResume33d:
 Exit Sub
ErrorTrap33d:
 Resume ErrorResume33d
End Sub

Sub Update.LogFile(VarX!,VarY!)
 On Local Error Goto ErrorTrap33e
 Close #LogFile
 Open Log.FileName For Random Shared As #LogFile Len=LogRecLen
 For Var5!=1! To Lof(LogFile)/LogRecLen
    Call Read.Record(LogFile,Var5!)
    If LogRecord.User=VarX! Then
       LogRecord.User=VarY!
       Call Write.Record(LogFile,Var5!)
    Endif
 Next
ErrorResume33e:
 Exit Sub
ErrorTrap33e:
 Resume ErrorResume33e
End Sub

Sub Clear.ScrollFile(VarX!)
 On Local Error Goto ErrorTrap33b
 Close #LogFile
 FileName=DND.Path+"writing.log"
 Open FileName For Random Shared As #LogFile Len=LogRecLen
 For Var5!=1! To Lof(LogFile)/LogRecLen
    Call Read.Record(LogFile,Var5!)
    If LogRecord.User=VarX! Then
       LogRecord.User=SFalse
       Call Write.Record(LogFile,Var5!)
    Endif
 Next
ErrorResume33b:
 Exit Sub
ErrorTrap33b:
 Resume ErrorResume33b
End Sub

Sub Swap.ScrollFile(VarX!,VarY!)
 On Local Error Goto ErrorTrap33c
 Close #LogFile
 FileName=DND.Path+"writing.log"
 Open FileName For Random Shared As #LogFile Len=LogRecLen
 For Var5!=1! To Lof(LogFile)/LogRecLen
    Call Read.Record(LogFile,Var5!)
    If LogRecord.User=VarX! Then
       LogRecord.User=VarY!
       Call Write.Record(LogFile,Var5!)
    Else
       If LogRecord.User=VarY! Then
          LogRecord.User=VarX!
          Call Write.Record(LogFile,Var5!)
       Endif
    Endif
 Next
ErrorResume33c:
 Exit Sub
ErrorTrap33c:
 Resume ErrorResume33c
End Sub

Sub Update.ScrollFile(VarX!,VarY!)
 On Local Error Goto ErrorTrap33f
 Close #LogFile
 FileName=DND.Path+"writing.log"
 Open FileName For Random Shared As #LogFile Len=LogRecLen
 For Var5!=1! To Lof(LogFile)/LogRecLen
    Call Read.Record(LogFile,Var5!)
    If LogRecord.User=VarX! Then
       LogRecord.User=VarY!
       Call Write.Record(LogFile,Var5!)
    Endif
 Next
ErrorResume33f:
 Exit Sub
ErrorTrap33f:
 Resume ErrorResume33f
End Sub

Sub Clear.UserInv(VarX!)
 On Local Error Goto ErrResume6a
 For Var5!=1! To Lof(UserInvFile)/MessWorkRecLen6
    Call Read.Record(UserInvFile,Var5!)
    If MessWorkRecord6.User=VarX! Then
       MessWorkRecord6.User=SFalse
       MessWorkRecord6.Room=SFalse
       MessWorkRecord6.Index=SFalse
       MessWorkRecord6.Charges=False
       MessWorkRecord6.Plus=False
       MessWorkRecord6.Prev=SFalse
       MessWorkRecord6.Next=SFalse
       Call Write.Record(UserInvFile,Var5!)
    Endif
 Next
ErrExit6a:
 Exit Sub
ErrResume6a:
 Resume ErrExit6a
End Sub

Sub List.User
 On Local Error Goto ErrResume7
 Do While Lost.Carrier=False
    Graphics.Off=True
    If TempC=False Then
       Strng=RT$(551,"[D]")+"ayfile"
       Call IO.O
       Strng=RT$(552,"[L]")+"ist"
       Call IO.O
       Strng=RT$(553,"[T]")+"op ten"
       Call IO.O
       Strng=RT$(554,"[U]")+"sers"
       Call IO.O
       Graphics.Off=False
    Endif
    Strng="User list option(d/t/l/u/q to quit)? "
    Line.Length=TempD
    No.Input.Out="Q"
    Call IO.I
    Select Case Ucase$(Out2)
    Case "D"
       If RT$(551,"[D]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Read.Dayfile
       Endif
    Case "L"
       If RT$(552,"[L]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Show.Users
       Endif
    Case "T"
       If RT$(553,"[T]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Top.Ten
          If Break=False Then
             Call Top.Ten.Teams
          Endif
       Endif
    Case "U"
       If RT$(554,"[U]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call User.Report
       Endif
    Case "Q"
       Exit Sub
    End Select
 Loop
ErrExit7:
 Exit Sub
ErrResume7:
 Resume ErrExit7
End Sub

Sub Show.Users
 On Local Error Goto ErrResume9
 Temp3!=Lof(UserFile2)/UserRecLen
 Call Get.Record.Range(Temp!,Temp2!,Temp3!)
 Allow.Break=True
 Break=False
 Continuous=False
 For Temp5!=Temp! To Temp2!
    Call Read.Record(UserFile2,Temp5!)
    For VarQ=1 To 18
       Call Display.User(False,VarQ)
       If Break Then
	  Exit For
       Endif
    Next
    If Break Then
       Exit For
    Endif
    If Continuous=False Then
       Call More.Prompt
       If No Or Quit Then
	  Exit For
       Endif
    Endif
 Next
 Allow.Break=False
 Break=False
ErrExit9:
 Exit Sub
ErrResume9:
 Resume ErrExit9
End Sub

Sub User.Report
 On Local Error Goto ErrResume10
 Graphics.Off=True
 Strng="DNDBBS V"+Version$+" User List For "+Fclock$+"."
 Call IO.O
 Strng=Nul
 Call IO.O
 Strng="Number   User Name                      Class Name           Race     Level DM"
 Call IO.O
 Strng=String$(78,"-")
 Call IO.O
 Temp5=4
 Allow.Break=True
 Break=False
 Continuous=False
 For Temp3!=1! To Lof(UserFile2)/UserRecLen
    Call Read.Record(UserFile2,Temp3!)
    Strng=UserRecord2.CodeName
    If Left$(Strng,9)<>Deleted$ Then
       Strng=Mid$(Str$(Temp3!),2)
       Strng=Strng+Space$(9-Len(Strng))
       Carriage.Return=True
       Call IO.O
       Strng=UserRecord2.CodeName
       Strng=Lcase$(Strng)
       Mid$(Strng,1,1)=Ucase$(Mid$(Strng,1,1))
       Strng=Rtrim$(Strng)
       VarQ=31-Len(Strng)
       Strng=Rtrim$(UserRecord2.Prefix1)+Strng
       Call Convert.ANSI(True,VarQ,VarR)
       Carriage.Return=True
       Graphics.On=True
       Call IO.O
       Graphics.On=False
       Carriage.Return=True
       Strng=Space$(VarQ)
       Call IO.O
       Carriage.Return=True
       Strng=UserRecord2.ClassName
       Strng=Rtrim$(Strng)
       VarQ=20-Len(Strng)
       Strng=Rtrim$(UserRecord2.Prefix2)+Strng
       Call Convert.ANSI(True,VarQ,VarR)
       Carriage.Return=True
       Graphics.On=True
       Call IO.O
       Graphics.On=False
       Carriage.Return=True
       Strng=Space$(VarQ)
       Call IO.O
       Strng=" "
       If UserRecord2.Race<1 Then
          UserRecord2.Race=1
       Endif
       Out2=Race(UserRecord2.Race)
       Out2=Rtrim$(Out2)
       Out2=Out2+Space$(8-Len(Out2))
       Strng=Strng+Out2
       If UserRecord2.Level<=False Then
          Out2=" "+Dead$
       Else
          If UserRecord2.Level>32000 Then
             Out2=" Ghod"
          Else
             Out2=Str$(UserRecord2.Level)
          Endif
       Endif
       If Len(Out2)<=7 Then
          Out2=Out2+Space$(7-Len(Out2))
       Endif
       If UserRecord2.ClassType>=AsstDM Then
          Out2=Out2+"*"
       Endif
       If UserRecord2.Flags And Locked.User Then
          Out2=Out2+Mask$
       Endif
       Out3=Strng+Out2
       Call Search.Mess.File(Temp3!,VarX)
       If VarX Then
          Out3=Out3+"!"
       Endif
       Strng=Out3
       Call IO.O
       If Break Then
	  Exit For
       Endif
       Temp5=Temp5+1
       If Temp5>=User.Pagelength-2 Then
	  Temp5=False
	  If Continuous=False Then
	     Call More.Prompt
             If No Or Quit Then
		Exit For
	     Endif
	  Endif
       Endif
    Endif
 Next
 If Temp5 Then
    Call More.Prompt
 Endif
 Allow.Break=False
 Break=False
ErrExit10:
 Exit Sub
ErrResume10:
 Resume ErrExit10
End Sub

Sub Pack.Users
 On Local Error Goto ErrResume11
 Call Search.Mess2(Var2)
 If Var2 Then
    Strng="Can't pack while node/user online."
    Call IO.O
    Exit Sub
 Endif
 Strng="Pack dead/deleted users(y/n)? "
 Line.Length=TempD
 No.Input.Out="Y"
 Call IO.I
 TempX=Yes
 TempZ=False
 Strng="Delete users before date(y/n)? "
 Line.Length=TempD
 No.Input.Out="N"
 Call IO.I
 If Yes Then
    TempZ=True
    Strng="Enter date(form: MM-DD-YYYY)? "
    No.Input.Out="01-01-1980"
    Call IO.I
    TempQ=ValidDate(Out2)
    If TempQ Then
       Temp#=Int(DateValue(Out2))
    Endif
 Endif
 If TempX Or TempZ Then
    Graphics.Off=True
    Carriage.Return=True
    Strng="Making backup of user file"
    Call IO.O
    FileName=Left$(User.Filename,Instr(User.Filename,"."))+"bak"
    Close #TempFile1
    If Dir$(FileName)<>Nul Then
       Kill FileName
    Endif
    Open FileName For Random Shared As #TempFile1 Len=UserRecLen
    VarD=False
    VarE=False
    VarF!=Timeit!
    For Temp3!=1! To Lof(UserFile2)/UserRecLen
       Call Read.Record(UserFile2,Temp3!)
       Call Write.TempFile(4,Temp3!)
       Call Dot.Display(VarD,VarE,VarF!)
    Next
    Call IO.O
    Graphics.Off=True
    FileName=User.Filename
    Close #UserFile
    Close #UserFile2
    If Dir$(FileName)<>Nul Then
       Kill FileName
    Endif
    Open FileName For Random Shared As #UserFile Len=UserRecLen
    Open FileName For Random Shared As #UserFile2 Len=UserRecLen
    Graphics.Off=True
    Carriage.Return=True
    Strng="Packing user file"
    Call IO.O
    VarD=False
    VarE=False
    VarF!=Timeit!
    Temp1!=SFalse
    For Temp3!=1! To Lof(TempFile1)/UserRecLen
       Call Read.TempFile(4,Temp3!)
       Call New.Stats(False)
       Out3=UserRecord2.CodeName
       Out3=Ucase$(Rtrim$(Out3))
       Temp=False
       If TempX Then
          If Out3=Ucase$(Deleted$) Then
	     Temp=True
	  Endif
          If UserRecord2.Level=False Then
	     Temp=True
	  Endif
       Endif
       If TempZ Then
          Out2=UserRecord2.DateOn
          TempQ=ValidDate(Out2)
          If TempQ Then
             If Int(DateValue(Out2))<Temp# Then
                Temp=True
             Endif
	  Endif
       Endif
       Call Dot.Display(VarD,VarE,VarF!)
       If Temp Then
          Call Clear.LogFile(Temp3!)
          Call Clear.ScrollFile(Temp3!)
          Call Clear.Team(Temp3!)
          Call Clear.UserInv(Temp3!)
          Call Clear.Containers(Temp3!)
       Else
          Temp1!=Temp1!+1!
          Call Write.Record(UserFile2,Temp1!)
          Call Update.Team(Temp3!,Temp1!)
          Call Update.UserInv(Temp3!,Temp1!)
          Call Update.Containers(Temp3!,Temp1!)
          Call Update.LogFile(Temp3!,Temp1!)
          Call Update.ScrollFile(Temp3!,Temp1!)
       Endif
    Next
    Call IO.O
    Graphics.Off=False
    Strng="User file packed."
    Call IO.O
    Close #TempFile1
 Endif
 Strng="Pack user inventory file(y/n)? "
 Line.Length=TempD
 No.Input.Out="Y"
 Call IO.I
 If No Then
    Exit Sub
 Endif
 Call Repair.Users(False)
 Carriage.Return=True
 Graphics.Off=True
 Strng="Making backup of user inventory file"
 Call IO.O
 Close #TempFile1
 FileName=Data.Path1+"USERINV.BAK"
 If Dir$(FileName)<>Nul Then
    Kill FileName
 Endif
 VarD=False
 VarE=False
 VarF!=Timeit!
 Open FileName For Random Shared As #TempFile1 Len=MessWorkRecLen6
 For Temp5!=1! To Lof(UserInvFile)/MessWorkRecLen6
    Call Read.Record(UserInvFile,Temp5!)
    Call Write.TempFile(7,Temp5!)
    Call Dot.Display(VarD,VarE,VarF!)
 Next
 Call IO.O
 Carriage.Return=True
 Strng="Packing user inventory file"
 Call IO.O
 Close #UserInvFile
 FileName=UserInv.FileName
 If Dir$(FileName)<>Nul Then
    Kill FileName
 Endif
 Open FileName For Random Shared As #UserInvFile Len=MessWorkRecLen6
 VarD=False
 VarE=False
 VarF!=Timeit!
 For Temp5!=1! To Lof(UserFile2)/UserRecLen
    Call Read.Record(UserFile2,Temp5!)
    Temp4!=UserRecord2.First
    If Temp4! Then
       UserRecord2.First=SFalse
       UserRecord2.Last=SFalse
       Call Write.Record(UserFile2,Temp5!)
       Do
          Call Read.TempFile(7,Temp4!)
          Temp6!=MessWorkRecord6.Next
          Temp7!=Lof(UserInvFile)/MessWorkRecLen6+1!
          Call Add.List.Node3(Temp7!)
          Call Dot.Display(VarD,VarE,VarF!)
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp4!=Temp6!
       Loop
    Endif
 Next
 Call IO.O
 Graphics.Off=False
 Strng="User inventory file packed."
 Call IO.O
 Close #TempFile1
 Call More.Prompt
ErrExit11:
 Exit Sub
ErrResume11:
 Resume ErrExit11
End Sub

Sub Repair.Users(VarK)
 On Local Error Goto ErrResume11a
 Call Search.Mess2(Var2)
 If Var2 Then
    Strng="Can't repair while node/user online."
    Call IO.O
    Exit Sub
 Endif
 If VarK Then
    Strng="Repair user inventory file(y/n)? "
    Line.Length=TempD
    No.Input.Out="Y"
    Call IO.I
    If No Then
       Exit Sub
    Endif
 Endif
 Carriage.Return=True
 Graphics.Off=True
 Strng="Making backup of user inventory file"
 Call IO.O
 Close #TempFile1
 FileName=Data.Path1+"USERINV2.BAK"
 If Dir$(FileName)<>Nul Then
    Kill FileName
 Endif
 VarD=False
 VarE=False
 VarF!=Timeit!
 Open FileName For Random Shared As #TempFile1 Len=MessWorkRecLen6
 For Temp5!=1! To Lof(UserInvFile)/MessWorkRecLen6
    Call Read.Record(UserInvFile,Temp5!)
    Call Write.TempFile(7,Temp5!)
    Call Dot.Display(VarD,VarE,VarF!)
 Next
 Call IO.O
 Carriage.Return=True
 Graphics.Off=True
 Strng="Repairing user inventory file"
 Call IO.O
 VarD=False
 VarE=False
 VarF!=Timeit!
 Temp5!=SFalse
 VarZ1!=SFalse
 For Temp1!=1! To Lof(UserFile2)/UserRecLen
    Call Dot.Display(VarD,VarE,VarF!)
    Call Read.Record(UserFile2,Temp1!)
    Temp2!=UserRecord2.First
    Temp3!=UserRecord2.Last
    If Temp2!>SFalse And Temp3!>SFalse Then
       If Temp2!=Temp3! Then
          Call Read.Record(UserInvFile,Temp2!)
          If MessWorkRecord6.Prev<>SFalse Or MessWorkRecord6.Next<>SFalse Then
             VarZ1!=VarZ1!+1!
             MessWorkRecord6.Prev=SFalse
             MessWorkRecord6.Next=SFalse
             Call Write.Record(UserInvFile,Temp2!)
          Endif
       Else
          Call Read.Record(UserInvFile,Temp2!)
          If MessWorkRecord6.Prev<>SFalse Then
             VarZ1!=VarZ1!+1!
             MessWorkRecord6.Prev=SFalse
             Call Write.Record(UserInvFile,Temp2!)
          Endif
          Call Read.Record(UserInvFile,Temp3!)
          If MessWorkRecord6.Next<>SFalse Then
             VarZ1!=VarZ1!+1!
             MessWorkRecord6.Next=SFalse
             Call Write.Record(UserInvFile,Temp3!)
          Endif
       Endif
    Endif
 Next
 VarZ2!=SFalse

 ' open table file.
 Close #TempFile1
 FileName=GetFilename$("TABLE","BK3")
 Open FileName For Random Shared As #TempFile1 Len=4
 Field #TempFile1,4 As S$
 ' truncate re-entrant loops.
 For Temp1!=1! To Lof(UserFile2)/UserRecLen
    VarY1!=0!
    Call Dot.Display(VarD,VarE,VarF!)
    Call Read.Record(UserFile2,Temp1!)
    Temp2!=UserRecord2.First
    If Temp2! Then
       Do
          Call Read.Record(UserInvFile,Temp2!)
          ' increase count.
          VarY1!=VarY1!+1!
          ' write Temp2! to table.
          Lset S$=Mks$(Temp2!)
          Put #TempFile1,VarY1!
          ' check next node.
          Temp6!=MessWorkRecord6.Next
          If Temp6!>SFalse Then
             Call Read.Record(UserInvFile,Temp6!)
             ' check Temp6! against table.
             For Temp7!=1! To VarY1!
                Get #TempFile1,Temp7!
                Temp8!=Cvs(S$)
                If Temp6!=Temp8! Then
                   Gosub Truncate1
                   Exit Do
                Endif
             Next
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp2!=Temp6!
       Loop
    Endif
 Next

 ' truncate re-entrant loops.
 For Temp1!=1! To Lof(UserFile2)/UserRecLen
    VarY1!=0!
    Call Dot.Display(VarD,VarE,VarF!)
    Call Read.Record(UserFile2,Temp1!)
    Temp2!=UserRecord2.Last
    If Temp2! Then
       Do
          Call Read.Record(UserInvFile,Temp2!)
          ' increase count.
          VarY1!=VarY1!+1!
          ' write Temp2! to table.
          Lset S$=Mks$(Temp2!)
          Put #TempFile1,VarY1!
          ' check prev node.
          Temp6!=MessWorkRecord6.Prev
          If Temp6!>SFalse Then
             Call Read.Record(UserInvFile,Temp6!)
             ' check Temp6! against table.
             For Temp7!=1! To VarY1!
                Get #TempFile1,Temp7!
                Temp8!=Cvs(S$)
                If Temp6!=Temp8! Then
                   Gosub Truncate2
                   Exit Do
                Endif
             Next
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp2!=Temp6!
       Loop
    Endif
 Next
 Close #TempFile1
 Kill Filename

 ' truncate next loops.
 For Temp1!=1! To Lof(UserFile2)/UserRecLen
    Call Dot.Display(VarD,VarE,VarF!)
    Call Read.Record(UserFile2,Temp1!)
    Temp2!=UserRecord2.First
    If Temp2! Then
       Do
          Call Read.Record(UserInvFile,Temp2!)
          Temp6!=MessWorkRecord6.Next
          If Temp6!>SFalse Then
             Call Read.Record(UserInvFile,Temp6!)
             If Temp2!<>MessWorkRecord6.Prev Then
                Gosub Truncate1
                Exit Do
             Endif
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp2!=Temp6!
       Loop
    Endif
 Next

 ' truncate prev loops.
 For Temp1!=1! To Lof(UserFile2)/UserRecLen
    Call Dot.Display(VarD,VarE,VarF!)
    Call Read.Record(UserFile2,Temp1!)
    Temp2!=UserRecord2.Last
    If Temp2! Then
       Do
          Call Read.Record(UserInvFile,Temp2!)
          Temp6!=MessWorkRecord6.Prev
          If Temp6!>SFalse Then
             Call Read.Record(UserInvFile,Temp6!)
             If Temp2!<>MessWorkRecord6.Next Then
                Gosub Truncate2
                Exit Do
             Endif
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp2!=Temp6!
       Loop
    Endif
 Next

 ' repair mismatched inventory pointers.
 VarZ3!=SFalse
 For Temp1!=1! To Lof(UserFile2)/UserRecLen
    Call Dot.Display(VarD,VarE,VarF!)
    Call Read.Record(UserFile2,Temp1!)
    Temp2!=UserRecord2.First
    If Temp2! Then
       Do
          Call Read.Record(UserInvFile,Temp2!)
          Temp6!=MessWorkRecord6.Next
          Temp3!=MessWorkRecord6.User
          If Temp3!<>Temp1! Then
             VarZ3!=VarZ3!+1!
             MessWorkRecord6.User=Temp1!
             Call Write.Record(UserInvFile,Temp2!)
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp2!=Temp6!
       Loop
    Endif
 Next
 Call IO.O
 Graphics.Off=False
 Strng="User inventory file repaired."
 Call IO.O
 Strng="Reset"+Str$(VarZ1!)+" nodes."
 Call IO.O
 Strng="Deleted"+Str$(VarZ2!)+" nodes."
 Call IO.O
 Strng="Repaired"+Str$(VarZ3!)+" nodes."
 Call IO.O
 Call More.Prompt
 Exit Sub
Truncate1:
 VarZ2!=VarZ2!+1!
 Call Read.Record(UserInvFile,Temp2!)
 MessWorkRecord6.Next=SFalse
 Call Write.Record(UserInvFile,Temp2!)
 UserRecord2.Last=Temp2!
 Call Write.Record(UserFile2,Temp1!)
 Return
Truncate2:
 VarZ2!=VarZ2!+1!
 Call Read.Record(UserInvFile,Temp2!)
 MessWorkRecord6.Prev=SFalse
 Call Write.Record(UserInvFile,Temp2!)
 UserRecord2.First=Temp2!
 Call Write.Record(UserFile2,Temp1!)
 Return
ErrExit11a:
 Exit Sub
ErrResume11a:
 Resume ErrExit11a
End Sub

Sub Sort.Users
 On Local Error Goto ErrResume11b
 Call Search.Mess2(Var2)
 If Var2 Then
    Strng="Can't sort while node/user online."
    Call IO.O
    Exit Sub
 Endif
 Strng="Sort userfile(y/n)? "
 Line.Length=TempD
 No.Input.Out="Y"
 Call IO.I
 If Yes Then
    Do While Lost.Carrier=False
       If TempC=False Then
          Graphics.Off=False
          Strng="Sort order menu:"
          Call IO.O
          Graphics.Off=True
          Strng=" (1)codename"
          Call IO.O
          Strng=" (2)classname"
          Call IO.O
          Strng=" (3)level"
          Call IO.O
          Strng=" (4)race"
          Call IO.O
          Strng=" (5)exit"
          Call IO.O
       Endif
       Graphics.Off=False
       No.Input.Out="5"
       Line.Length=TempD
       Strng="Enter sort option(1-4/5=quit)? "
       Call IO.I
       SortX=Int(Val(Out2))
       If SortX>=1 And SortX<=4 Then
          Exit Do
       Endif
       If SortX=5 Then Exit Sub
    Loop
    Do While Lost.Carrier=False
       If TempC=False Then
          Graphics.Off=False
          Strng="Sort type menu:"
          Call IO.O
          Graphics.Off=True
          Strng=" (1)ascending"
          Call IO.O
          Strng=" (2)descending"
          Call IO.O
          Strng=" (3)exit"
          Call IO.O
       Endif
       Graphics.Off=False
       No.Input.Out="3"
       Line.Length=TempD
       Strng="Enter sort option(1-2/3=quit)? "
       Call IO.I
       SortZ=Int(Val(Out2))
       If SortZ>=1 And SortZ<=2 Then
          Exit Do
       Endif
       If SortZ=3 Then Exit Sub
    Loop
    If SortX>False And SortZ>False Then
       Graphics.Off=True
       Carriage.Return=True
       Strng="Making backup of user file"
       Call IO.O
       FileName=Left$(User.Filename,Instr(User.Filename,"."))+"bak"
       Close #TempFile1
       If Dir$(FileName)<>Nul Then
          Kill FileName
       Endif
       Open FileName For Random Shared As #TempFile1 Len=UserRecLen
       VarD=False
       VarE=False
       VarF!=Timeit!
       For Temp3!=1! To Lof(UserFile2)/UserRecLen
          Call Read.Record(UserFile2,Temp3!)
          Call Write.TempFile(4,Temp3!)
          Call Dot.Display(VarD,VarE,VarF!)
       Next
       Call IO.O
       Graphics.Off=True
       Carriage.Return=True
       Strng="Sorting user file"
       Call IO.O
       VarD=False
       VarE=False
       VarF!=Timeit!
       ' bubble sort fixed 04-29-2019 v5.0a r2.0a;
       For Temp3!=1! To Lof(UserFile)/UserRecLen
          For Temp4!=Temp3!+1! To Lof(UserFile)/UserRecLen
             Call Dot.Display(VarD,VarE,VarF!)
             Call Read.Record(UserFile,Temp4!)
             UserRecord2=UserRecord
             Call Read.Record(UserFile,Temp3!)
             Select Case SortX
             Case 1
                Select Case SortZ
                Case 1
                   If UserRecord2.CodeName<UserRecord.CodeName Then
                      Gosub Swap.Users
                   Endif
                Case 2
                   If UserRecord2.CodeName>UserRecord.CodeName Then
                      Gosub Swap.Users
                   Endif
                End Select
             Case 2
                Select Case SortZ
                Case 1
                   If UserRecord2.ClassName<UserRecord.ClassName Then
                      Gosub Swap.Users
                   Endif
                Case 2
                   If UserRecord2.ClassName>UserRecord.ClassName Then
                      Gosub Swap.Users
                   Endif
                End Select
             Case 3
                Select Case SortZ
                Case 1
                   If UserRecord2.Level<UserRecord.Level Then
                      Gosub Swap.Users
                   Endif
                Case 2
                   If UserRecord2.Level>UserRecord.Level Then
                      Gosub Swap.Users
                   Endif
                End Select
             Case 4
                Select Case SortZ
                Case 1
                   If UserRecord2.Race<UserRecord.Race Then
                      Gosub Swap.Users
                   Endif
                Case 2
                   If UserRecord2.Race>UserRecord.Race Then
                      Gosub Swap.Users
                   Endif
                End Select
             End Select
          Next
       Next
       Call IO.O
    Endif
    Strng="User file sorted."
    Call IO.O
    Call More.Prompt
 Endif
 Exit Sub
Swap.Users:
 ' swap userrecord in temp3! with userrecord2 in temp4!
 Call Write.Record(UserFile,Temp4!)
 UserRecord=UserRecord2
 Call Write.Record(UserFile,Temp3!)

 ' swap userfile data
 Call Swap.Team(Temp3!,Temp4!)
 Call Swap.UserInv(Temp3!,Temp4!)
 Call Swap.Containers(Temp3!,Temp4!)
 Call Swap.LogFile(Temp3!,Temp4!)
 Call Swap.ScrollFile(Temp3!,Temp4!)
 Return
ErrExit11b:
 Exit Sub
ErrResume11b:
 Resume ErrExit11b
End Sub

Sub Clear.Containers(VarX!)
 On Local Error Goto ErrResume11c
 For VarY!=1! To Lof(ContainerFile)/ContainerRecLen
    Call Read.Record(ContainerFile,VarY!)
    If ContainerRecord.UserNumber=VarX! Then
       Call Clear.Container
       Call Write.Record(ContainerFile,VarY!)
    Endif
 Next
ErrExit11c:
 Exit Sub
ErrResume11c:
 Resume ErrExit11c
End Sub

Sub Swap.Containers(VarX!,VarY!)
 On Local Error Goto ErrResume11d
 For VarZ!=1! To Lof(ContainerFile)/ContainerRecLen
    Call Read.Record(ContainerFile,VarZ!)
    If ContainerRecord.UserNumber=VarX! Then
       ContainerRecord.UserNumber=VarY!
       Call Write.Record(ContainerFile,VarZ!)
    Else
       If ContainerRecord.UserNumber=VarY! Then
          ContainerRecord.UserNumber=VarX!
          Call Write.Record(ContainerFile,VarZ!)
       Endif
    Endif
 Next
ErrExit11d:
 Exit Sub
ErrResume11d:
 Resume ErrExit11d
End Sub

Sub Clear.Team(VarX!)
 On Local Error Goto ErrResume11e
 For Var!=1! To Lof(TeamFile)/TeamRecLen
    Call Read.Record(TeamFile,Var!)
    For Var2=1 To 5
       Var1!=TeamRecord.UserIndex(Var2)
       If Var1!=VarX! Then
          TeamRecord.Member(Var2)=Nul
          TeamRecord.UserIndex(Var2)=SFalse
          TeamRecord.Activated(Var2)=False
          Call Write.Record(TeamFile,Var!)
       Endif
    Next
 Next
ErrExit11e:
 Exit Sub
ErrResume11e:
 Resume ErrExit11e
End Sub

Sub Update.Containers(VarX!,VarY!)
 On Local Error Goto ErrResume11f
 For VarZ!=1! To Lof(ContainerFile)/ContainerRecLen
    Call Read.Record(ContainerFile,VarZ!)
    If ContainerRecord.UserNumber=VarX! Then
       ContainerRecord.UserNumber=VarY!
       Call Write.Record(ContainerFile,VarZ!)
    Endif
 Next
ErrExit11f:
 Exit Sub
ErrResume11f:
 Resume ErrExit11f
End Sub

Sub Update.UserInv(VarX!,VarY!)
 On Local Error Goto ErrResume11g
 For Temp5!=1! To Lof(UserInvFile)/MessWorkRecLen6
    Call Read.Record(UserInvFile,Temp5!)
    If MessWorkRecord6.User=VarX! Then
       MessWorkRecord6.User=VarY!
       Call Write.Record(UserInvFile,Temp5!)
    Endif
 Next
ErrExit11g:
 Exit Sub
ErrResume11g:
 Resume ErrExit11g
End Sub

Sub Swap.UserInv(VarX!,VarY!)
 On Local Error Goto ErrResume11h
 For Var5!=1! To Lof(UserInvFile)/MessWorkRecLen6
    Call Read.Record(UserInvFile,Var5!)
    If MessWorkRecord6.User=VarX! Then
       MessWorkRecord6.User=VarY!
       Call Write.Record(UserInvFile,Var5!)
    Else
       If MessWorkRecord6.User=VarY! Then
          MessWorkRecord6.User=VarX!
          Call Write.Record(UserInvFile,Var5!)
       Endif
    Endif
 Next
ErrExit11h:
 Exit Sub
ErrResume11h:
 Resume ErrExit11h
End Sub

Sub Update.Team(VarX!,VarY!)
 On Local Error Goto ErrResume11i
 For Var!=1! To Lof(TeamFile)/TeamRecLen
    Call Read.Record(TeamFile,Var!)
    For Var2=1 To 5
       Var1!=TeamRecord.UserIndex(Var2)
       If Var1!=VarX! Then
          TeamRecord.UserIndex(Var2)=VarY!
          Call Write.Record(TeamFile,Var!)
       Endif
    Next
 Next
ErrExit11i:
 Exit Sub
ErrResume11i:
 Resume ErrExit11i
End Sub

Sub Swap.Team(VarX!,VarY!)
 On Local Error Goto ErrResume11j
 For Var!=1! To Lof(TeamFile)/TeamRecLen
    Call Read.Record(TeamFile,Var!)
    For Var2=1 To 5
       Var1!=TeamRecord.UserIndex(Var2)
       If Var1!=VarX! Then
          TeamRecord.UserIndex(Var2)=VarY!
          Call Write.Record(TeamFile,Var!)
       Else
          If Var1!=VarY! Then
             TeamRecord.UserIndex(Var2)=VarX!
             Call Write.Record(TeamFile,Var!)
          Endif
       Endif
    Next
 Next
ErrExit11j:
 Exit Sub
ErrResume11j:
 Resume ErrExit11j
End Sub

Sub Update.Users
 On Local Error Goto ErrResume12
 Call Search.Mess2(Var2)
 If Var2 Then
    Strng="Can't update while node/user online."
    Call IO.O
    Exit Sub
 Endif
 Strng="Delete dead users(y/n)? "
 Line.Length=TempD
 No.Input.Out="Y"
 Call IO.I
 TempX=Yes
 TempZ=False
 Strng="Delete users before date(y/n)? "
 Line.Length=TempD
 No.Input.Out="N"
 Call IO.I
 If Yes Then
    TempZ=True
    Strng="Enter date(form: MM-DD-YYYY)? "
    No.Input.Out="01-01-1980"
    Call IO.I
    TempQ=ValidDate(Out2)
    If TempQ Then
       Temp#=Int(DateValue(Out2))
    Endif
 Endif
 If TempX Or TempZ Then
    Graphics.Off=True
    Carriage.Return=True
    Strng="Updating user file"
    Call IO.O
    VarD=False
    VarE=False
    VarF!=Timeit!
    For Temp3!=1! To Lof(UserFile2)/UserRecLen
       Call Dot.Display(VarD,VarE,VarF!)
       Call Search.Mess.File(Temp3!,Var)
       If Var=False Then
          Call Read.Record(UserFile2,Temp3!)
          Call New.Stats(False)
          Out3=UserRecord2.CodeName
          Temp=False
          If Left$(Out3,9)<>Deleted$ Then
             If TempX Then
                If UserRecord2.Level=False Then
                   Temp=True
                Endif
             Endif
             If TempZ Then
                Out2=UserRecord2.DateOn
                TempQ=ValidDate(Out2)
                If TempQ Then
                   If Int(DateValue(Out2))<Temp# Then
                      Temp=True
                   Endif
                Endif
             Endif
          Endif
          If Temp Then
             Call Delete.User
             Call Write.Record(UserFile2,Temp3!)
             Call Clear.LogFile(Temp3!)
             Call Clear.ScrollFile(Temp3!)
             Call Clear.Team(Temp3!)
             Call Clear.UserInv(Temp3!)
             Call Clear.Containers(Temp3!)
          Endif
       Endif
    Next
    Call IO.O
    Graphics.Off=False
    Strng="User file updated."
    Call IO.O
    Call More.Prompt
 Endif
ErrExit12:
 Exit Sub
ErrResume12:
 Resume ErrExit12
End Sub

' add container to users.dat list
Sub Add.Container.To.User
 On Local Error Goto ErrResume141f
 VarA!=Lof(ContainerFile)/ContainerRecLen+1!
 Call Clear.Container
 ContainerRecord.ContainerName=TreasureRecord.TreasureName
 ContainerRecord.ContainerShort=TreasureRecord.ShortName
 ContainerRecord.ContainerMax=TreasureRecord.ContainerMax
 ContainerRecord.NamePrefix=TreasureRecord.ContainerPrefix
 ContainerRecord.Prefix1=TreasureRecord.Prefix1
 ContainerRecord.Size=TreasureRecord.ContainerSize
 ContainerRecord.Material=TreasureRecord.ContainerMaterial
 Strng="Invisible container(y/n)? "
 No.Input.Out="N"
 Call IO.I
 ContainerRecord.InvisibleContainer=Yes
 If TreasureRecord.KeyNumber Then
    ContainerRecord.KeyNumber=TreasureRecord.KeyNumber
    ContainerRecord.Closed=True
    ContainerRecord.Locked=True
 Endif
 If TreasureRecord.Locked Then
    ContainerRecord.Closed=True
    ContainerRecord.Locked=True
 Endif
 ContainerRecord.RoomNumber=SFalse
 ContainerRecord.UserNumber=Temp5!
 ContainerRecord.WithinContainer=SFalse
 ContainerRecord.Weight=TreasureRecord.Weight
 ContainerRecord.ContainerIndex=TempC!
 ContainerRecord.Disappears=TreasureRecord.ContainerDisappears
 ContainerRecord.SelfImplodes=TreasureRecord.ContainerSelfImplodes
 ContainerRecord.Permanent=TreasureRecord.Permanent
 ContainerRecord.First=SFalse
 ContainerRecord.Last=SFalse
 ContainerRecord.SwapFlag=SFalse
 ContainerRecord.Scanned=False
 For Var=1 To 3
    ContainerRecord.RestrictItem(Var)=TreasureRecord.RestrictItem(Var)
 Next
 ContainerRecord.TrapType=TreasureRecord.TrapType
 ContainerRecord.TrapHits=TreasureRecord.TrapHits
 ContainerRecord.TrapItem=TreasureRecord.TrapItem
 Call Write.Record(ContainerFile,VarA!)
 Call Add.User.Container(VarA!)
ErrExit141f:
 Exit Sub
ErrResume141f:
 Resume ErrExit141f
End Sub

Sub Clear.Container.Node
 On Local Error Goto ErrorTrp32c
 ContainerRecord.UserNumber=SFalse
 ContainerRecord.RoomNumber=SFalse
 ContainerRecord.DeletedContainer=True
 ContainerRecord.Prev=SFalse
 ContainerRecord.Next=SFalse
ErrorRsm32c:
 Exit Sub
ErrorTrp32c:
 Resume ErrorRsm32c
End Sub

Sub Add.User.Container(VarA!)
 On Local Error Goto ErrorTrp32e
 Call Read.Record(UserFile2,Temp5!)
 If UserRecord2.First2=SFalse Then
    UserRecord2.First2=VarA!
    UserRecord2.Last2=VarA!
    Call Write.Record(UserFile2,Temp5!)
    ContainerRecord.Prev=SFalse
    ContainerRecord.Next=SFalse
    Call Write.Record(ContainerFile,VarA!)
 Else
    ContainerRecord.Prev=UserRecord2.Last2
    ContainerRecord.Next=SFalse
    Call Write.Record(ContainerFile,VarA!)
    Call Read.Record(ContainerFile,UserRecord2.Last2)
    ContainerRecord.Next=VarA!
    Call Write.Record(ContainerFile,UserRecord2.Last2)
    Call Read.Record(ContainerFile,VarA!)
    UserRecord2.Last2=VarA!
    Call Write.Record(UserFile2,Temp5!)
 Endif
ErrorRsm32e:
 Exit Sub
ErrorTrp32e:
 Resume ErrorRsm32e
End Sub
