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

' repair <item>
Sub Weapons.Shop
 On Local Error Goto Err.Trap19
 Gosub Get.Config
 Select Case UCase$(Parsed.Command1)
 Case "ROOM"
    If Option1=0 Then
       Strng="Repair room disabled!"
       Gosub Repair.Prompt
    Endif
    Call Repair.Room
    Exit Sub
 Case "INVENTORY"
    If Option2=0 Then
       Strng="Repair inventory disabled!"
       Gosub Repair.Prompt
    Endif
    Call Write.Record(UserFile,User.Index)
    Call Repair.User
    Exit Sub
 Case "CONTAINERS"
    If Option3=0 Then
       Strng="Repair containers disabled!"
       Gosub Repair.Prompt
    Endif
    Call Write.Record(UserFile,User.Index)
    Call Repair.Room.Containers
    Call Repair.User.Containers
    Call Repair.Within.Containers
    Call Repair.Container.Inventory
    Exit Sub
 End Select
 TempA=True
 If Config2(50)=False Then
    Call In.Room(14)
 Endif
 If TempA=False Then
    Strng="Find the Weapons Shoppe!"
    Call IO.O
    If Sysop Or Local.Mode Then
       Strng="Weapons shoppe: "+Rtrim$(Room.Array(14))
       Call IO.O
    Endif
    Exit Sub
 Endif
 Call Check.User.Items
 If Temp7!<=SFalse Then ' object
    Strng="The Blacksmith says: I can't repair that!"
    Call IO.O
    Exit Sub
 Endif
 If TreasureRecord.Spell Then ' magic item
    Strng="The Blacksmith says: I can't repair that!"
    Call IO.O
    Exit Sub
 Endif
 If MessWorkRecord6.Charges>False Then
    Strng="The Blacksmith says: That isn't broken!"
    Call IO.O
    Exit Sub
 Endif
 Temp!=Int(TreasureRecord.Gold*Config1(17))
 If Temp!=SFalse Then
    Temp!=1!
 Endif
 If Temp!>UserRecord.Gold Then
    Strng="The Blacksmith says: You don't have enough gold!"
    Call IO.O
    Exit Sub
 Endif
 Strng="The Blacksmith asks: How about"+Str$(Temp!)+" gold?"
 No.Input.Out="Y"
 Call IO.I
 If Yes Then
    UserRecord.Gold=UserRecord.Gold-Temp!
    MessWorkRecord6.Charges=TreasureRecord.Charges
    Call Write.Record(MessWorkFile6,Temp5!)
    Strng="The Blacksmith says: There, it's repaired."
    Call IO.O
    Exit Sub
 Endif
 If Rnd>.5 Then
    Strng="The Blacksmith says: Later then!"
 Else
    Strng="The Blacksmith says: Oh well!"
 Endif
 Call IO.O
 Exit Sub
Repair.Prompt:
 Call IO.O
 If Sysop Then
    Strng="Repair anyway(y/n)? "
    No.Input.Out="N"
    Call IO.I
    If Yes Then
       Return
    Endif
 Endif
 Exit Sub
Get.Config:
 VarX=0
 Option1=-1
 Option2=-1
 Option3=-1
 Do
    VarX=VarX+1
    If VarX>Options.Lines Then
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
    If Ucase$(Var$)="[CMD109]" 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.repair1"
                Select Case Lcase$(Var3$)
                Case "0", "false", "off"
                   Option1=0
                End Select
             Case "allow.repair2"
                Select Case Lcase$(Var3$)
                Case "0", "false", "off"
                   Option2=0
                End Select
             Case "allow.repair3"
                Select Case Lcase$(Var3$)
                Case "0", "false", "off"
                   Option3=0
                End Select
             End Select
          Endif
       Loop
    Endif
 Loop
 Return
Err.Resume19:
 Exit Sub
Err.Trap19:
 Resume Err.Resume19
End Sub

Sub Repair.Room
 On Local Error Goto ErrResume65a
 Graphics.Off=True
 Strng="Repairing room.."
 Call IO.O
 VarZ1!=SFalse
 If Room>SFalse And Room<=Lof(RoomFile)/RoomRecLen Then
    Call Read.Record(RoomFile,Room)
    Temp2!=RoomRecord.First
    Temp3!=RoomRecord.Last
    If Temp2!>SFalse And Temp3!>SFalse Then
       If Temp2!=Temp3! Then
          Call Read.Record(RoomInvFile,Temp2!)
          If MessWorkRecord6.Prev<>SFalse Or MessWorkRecord6.Next<>SFalse Then
             VarZ1!=VarZ1!+1!
             MessWorkRecord6.Prev=SFalse
             MessWorkRecord6.Next=SFalse
             Call Write.Record(RoomInvFile,Temp2!)
          Endif
       Else
          Call Read.Record(RoomInvFile,Temp2!)
          If MessWorkRecord6.Prev<>SFalse Then
             VarZ1!=VarZ1!+1!
             MessWorkRecord6.Prev=SFalse
             Call Write.Record(RoomInvFile,Temp2!)
          Endif
          Call Read.Record(RoomInvFile,Temp3!)
          If MessWorkRecord6.Next<>SFalse Then
             VarZ1!=VarZ1!+1!
             MessWorkRecord6.Next=SFalse
             Call Write.Record(RoomInvFile,Temp3!)
          Endif
       Endif
    Endif
 Endif
 VarZ2!=SFalse
 If Room>SFalse And Room<=Lof(RoomFile)/RoomRecLen Then
    Close #TempFile1
    FileName="TABLE"+NodeX+".BK3"
    Open FileName For Random Shared As #TempFile1 Len=4
    Field #TempFile1,4 As S$
    VarY1!=0!
    Call Read.Record(RoomFile,Room)
    Temp2!=RoomRecord.First
    If Temp2! Then
       Do
          Call Read.Record(RoomInvFile,Temp2!)
          VarY1!=VarY1!+1!
          Lset S$=Mks$(Temp2!)
          Put #TempFile1,VarY1!
          Temp6!=MessWorkRecord6.Next
          If Temp6!>SFalse Then
             Call Read.Record(RoomInvFile,Temp6!)
             For Temp7!=1! To VarY1!
                Get #TempFile1,Temp7!
                Temp8!=Cvs(S$)
                If Temp6!=Temp8! Then
                   Gosub Truncate1a
                   Exit Do
                Endif
             Next
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp2!=Temp6!
       Loop
    Endif
    VarY1!=0!
    Call Read.Record(RoomFile,Room)
    Temp2!=RoomRecord.Last
    If Temp2! Then
       Do
          Call Read.Record(RoomInvFile,Temp2!)
          VarY1!=VarY1!+1!
          Lset S$=Mks$(Temp2!)
          Put #TempFile1,VarY1!
          Temp6!=MessWorkRecord6.Prev
          If Temp6!>SFalse Then
             Call Read.Record(RoomInvFile,Temp6!)
             For Temp7!=1! To VarY1!
                Get #TempFile1,Temp7!
                Temp8!=Cvs(S$)
                If Temp6!=Temp8! Then
                   Gosub Truncate2a
                   Exit Do
                Endif
             Next
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp2!=Temp6!
       Loop
    Endif
 Endif
 Close #TempFile1
 If Room>SFalse And Room<=Lof(RoomFile)/RoomRecLen Then
    Call Read.Record(RoomFile,Room)
    Temp2!=RoomRecord.First
    If Temp2! Then
       Do While Lost.Carrier=False
          Call Read.Record(RoomInvFile,Temp2!)
          Temp6!=MessWorkRecord6.Next
          If Temp6!>SFalse Then
             Call Read.Record(RoomInvFile,Temp6!)
             If Temp2!<>MessWorkRecord6.Prev Then
                Gosub Truncate1a
                Exit Do
             Endif
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp2!=Temp6!
       Loop
    Endif
 Endif
 If Room>SFalse And Room<=Lof(RoomFile)/RoomRecLen Then
    Call Read.Record(RoomFile,Room)
    Temp2!=RoomRecord.Last
    If Temp2! Then
       Do While Lost.Carrier=False
          Call Read.Record(RoomInvFile,Temp2!)
          Temp6!=MessWorkRecord6.Prev
          If Temp6!>SFalse Then
             Call Read.Record(RoomInvFile,Temp6!)
             If Temp2!<>MessWorkRecord6.Next Then
                Gosub Truncate2a
                Exit Do
             Endif
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp2!=Temp6!
       Loop
    Endif
 Endif
 VarZ3!=SFalse
 If Room>SFalse And Room<=Lof(RoomFile)/RoomRecLen Then
    Call Read.Record(RoomFile,Room)
    Temp2!=RoomRecord.First
    If Temp2! Then
       Do While Lost.Carrier=False
          Call Read.Record(RoomInvFile,Temp2!)
          Temp6!=MessWorkRecord6.Next
          Temp3!=MessWorkRecord6.Room
          If Temp3!<>Room Then
             VarZ3!=VarZ3!+1!
             MessWorkRecord6.Room=Room
             Call Write.Record(RoomInvFile,Temp2!)
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp2!=Temp6!
       Loop
    Endif
 Endif
 Strng=" Reset"+Str$(VarZ1!)+" nodes."
 Call IO.O
 Strng=" Deleted"+Str$(VarZ2!)+" nodes."
 Call IO.O
 Strng=" Repaired"+Str$(VarZ3!)+" nodes."
 Call IO.O
 Exit Sub
Truncate1a:
 VarZ2!=VarZ2!+1!
 Call Read.Record(RoomInvFile,Temp2!)
 MessWorkRecord6.Next=SFalse
 Call Write.Record(RoomInvFile,Temp2!)
 RoomRecord.Last=Temp2!
 Call Write.Record(RoomFile,Room)
 Return
Truncate2a:
 VarZ2!=VarZ2!+1!
 Call Read.Record(RoomInvFile,Temp2!)
 MessWorkRecord6.Prev=SFalse
 Call Write.Record(RoomInvFile,Temp2!)
 RoomRecord.First=Temp2!
 Call Write.Record(RoomFile,Room)
 Return
ErrExit65a:
 Exit Sub
ErrResume65a:
 Resume ErrExit65a
End Sub

Sub Repair.User
 On Local Error Goto ErrResume11a
 Graphics.Off=True
 Strng="Repairing inventory.."
 Call IO.O
 Temp5!=SFalse
 VarZ1!=SFalse
 Call Read.Record(UserFile,User.Index)
 Temp2!=UserRecord.First
 Temp3!=UserRecord.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
 VarZ2!=SFalse
 Close #TempFile1
 FileName="TABLE"+NodeX+".BK3"
 Open FileName For Random Shared As #TempFile1 Len=4
 Field #TempFile1,4 As S$
 VarY1!=0!
 Call Read.Record(UserFile,User.Index)
 Temp2!=UserRecord.First
 If Temp2! Then
    Do
       Call Read.Record(UserInvFile,Temp2!)
       VarY1!=VarY1!+1!
       Lset S$=Mks$(Temp2!)
       Put #TempFile1,VarY1!
       Temp6!=MessWorkRecord6.Next
       If Temp6!>SFalse Then
          Call Read.Record(UserInvFile,Temp6!)
          For Temp7!=1! To VarY1!
             Get #TempFile1,Temp7!
             Temp8!=Cvs(S$)
             If Temp6!=Temp8! Then
                Gosub Truncate1c
                Exit Do
             Endif
          Next
       Endif
       If Temp6!=SFalse Then
          Exit Do
       Endif
       Temp2!=Temp6!
    Loop
 Endif
 Call Read.Record(UserFile,User.Index)
 VarY1!=0!
 Temp2!=UserRecord.Last
 If Temp2! Then
    Do
       Call Read.Record(UserInvFile,Temp2!)
       VarY1!=VarY1!+1!
       Lset S$=Mks$(Temp2!)
       Put #TempFile1,VarY1!
       Temp6!=MessWorkRecord6.Prev
       If Temp6!>SFalse Then
          Call Read.Record(UserInvFile,Temp6!)
          For Temp7!=1! To VarY1!
             Get #TempFile1,Temp7!
             Temp8!=Cvs(S$)
             If Temp6!=Temp8! Then
                Gosub Truncate2c
                Exit Do
             Endif
          Next
       Endif
       If Temp6!=SFalse Then
          Exit Do
       Endif
       Temp2!=Temp6!
    Loop
 Endif
 Close #TempFile1
 Call Read.Record(UserFile,User.Index)
 Temp2!=UserRecord.First
 If Temp2! Then
    Do While Lost.Carrier=False
       Call Read.Record(UserInvFile,Temp2!)
       Temp6!=MessWorkRecord6.Next
       If Temp6!>SFalse Then
          Call Read.Record(UserInvFile,Temp6!)
          If Temp2!<>MessWorkRecord6.Prev Then
             Gosub Truncate1c
             Exit Do
          Endif
       Endif
       If Temp6!=SFalse Then
          Exit Do
       Endif
       Temp2!=Temp6!
    Loop
 Endif
 Call Read.Record(UserFile,User.Index)
 Temp2!=UserRecord.Last
 If Temp2! Then
    Do While Lost.Carrier=False
       Call Read.Record(UserInvFile,Temp2!)
       Temp6!=MessWorkRecord6.Prev
       If Temp6!>SFalse Then
          Call Read.Record(UserInvFile,Temp6!)
          If Temp2!<>MessWorkRecord6.Next Then
             Gosub Truncate2c
             Exit Do
          Endif
       Endif
       If Temp6!=SFalse Then
          Exit Do
       Endif
       Temp2!=Temp6!
    Loop
 Endif
 VarZ3!=SFalse
 Call Read.Record(UserFile,User.Index)
 Temp2!=UserRecord.First
 If Temp2! Then
    Do While Lost.Carrier=False
       Call Read.Record(UserInvFile,Temp2!)
       Temp6!=MessWorkRecord6.Next
       Temp3!=MessWorkRecord6.User
       If Temp3!<>User.Index Then
          VarZ3!=VarZ3!+1!
          MessWorkRecord6.User=User.Index
          Call Write.Record(UserInvFile,Temp2!)
       Endif
       If Temp6!=SFalse Then
          Exit Do
       Endif
       Temp2!=Temp6!
    Loop
 Endif
 Strng=" Reset"+Str$(VarZ1!)+" nodes."
 Call IO.O
 Strng=" Deleted"+Str$(VarZ2!)+" nodes."
 Call IO.O
 Strng=" Repaired"+Str$(VarZ3!)+" nodes."
 Call IO.O
 Exit Sub
Truncate1c:
 VarZ2!=VarZ2!+1!
 Call Read.Record(UserInvFile,Temp2!)
 MessWorkRecord6.Next=SFalse
 Call Write.Record(UserInvFile,Temp2!)
 UserRecord.Last=Temp2!
 Call Write.Record(UserFile,User.Index)
 Return
Truncate2c:
 VarZ2!=VarZ2!+1!
 Call Read.Record(UserInvFile,Temp2!)
 MessWorkRecord6.Prev=SFalse
 Call Write.Record(UserInvFile,Temp2!)
 UserRecord.First=Temp2!
 Call Write.Record(UserFile,User.Index)
 Return
ErrExit11a:
 Exit Sub
ErrResume11a:
 Resume ErrExit11a
End Sub

Sub Repair.Room.Containers
 On Local Error Goto ErrResume11x1
 Graphics.Off=True
 Strng="Repairing room containers.."
 Call IO.O
 VarZ1!=SFalse
 If Room>SFalse And Room<=Lof(RoomFile)/RoomRecLen Then
    Call Read.Record(RoomFile,Room)
    Temp2!=RoomRecord.First2
    Temp3!=RoomRecord.Last2
    If Temp2!>SFalse And Temp3!>SFalse Then
       If Temp2!=Temp3! Then
          Call Read.Record(ContainerFile,Temp2!)
          If ContainerRecord.Prev<>SFalse Or ContainerRecord.Next<>SFalse Then
             VarZ1!=VarZ1!+1!
             ContainerRecord.Prev=SFalse
             ContainerRecord.Next=SFalse
             Call Write.Record(ContainerFile,Temp2!)
          Endif
       Else
          Call Read.Record(ContainerFile,Temp2!)
          If ContainerRecord.Prev<>SFalse Then
             VarZ1!=VarZ1!+1!
             ContainerRecord.Prev=SFalse
             Call Write.Record(ContainerFile,Temp2!)
          Endif
          Call Read.Record(ContainerFile,Temp3!)
          If ContainerRecord.Next<>SFalse Then
             VarZ1!=VarZ1!+1!
             ContainerRecord.Next=SFalse
             Call Write.Record(ContainerFile,Temp3!)
          Endif
       Endif
    Endif
 Endif
 VarZ2!=SFalse
 If Room>SFalse And Room<=Lof(RoomFile)/RoomRecLen Then
    Close #TempFile1
    FileName="TABLE"+NodeX+".BK3"
    Open FileName For Random Shared As #TempFile1 Len=4
    Field #TempFile1,4 As S$
    VarY1!=0!
    Call Read.Record(RoomFile,Room)
    Temp2!=RoomRecord.First2
    If Temp2! Then
       Do
          Call Read.Record(ContainerFile,Temp2!)
          VarY1!=VarY1!+1!
          Lset S$=Mks$(Temp2!)
          Put #TempFile1,VarY1!
          Temp6!=ContainerRecord.Next
          If Temp6!>SFalse Then
             Call Read.Record(ContainerFile,Temp6!)
             For Temp7!=1! To VarY1!
                Get #TempFile1,Temp7!
                Temp8!=Cvs(S$)
                If Temp6!=Temp8! Then
                   Gosub Truncate1f
                   Exit Do
                Endif
             Next
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp2!=Temp6!
       Loop
    Endif
    VarY1!=0!
    Call Read.Record(RoomFile,Room)
    Temp2!=RoomRecord.Last2
    If Temp2! Then
       Do
          Call Read.Record(ContainerFile,Temp2!)
          VarY1!=VarY1!+1!
          Lset S$=Mks$(Temp2!)
          Put #TempFile1,VarY1!
          Temp6!=ContainerRecord.Prev
          If Temp6!>SFalse Then
             Call Read.Record(ContainerFile,Temp6!)
             For Temp7!=1! To VarY1!
                Get #TempFile1,Temp7!
                Temp8!=Cvs(S$)
                If Temp6!=Temp8! Then
                   Gosub Truncate2f
                   Exit Do
                Endif
             Next
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp2!=Temp6!
       Loop
    Endif
 Endif
 Close #TempFile1
 If Room>SFalse And Room<=Lof(RoomFile)/RoomRecLen Then
    Call Read.Record(RoomFile,Room)
    Temp2!=RoomRecord.First2
    If Temp2! Then
       Do While Lost.Carrier=False
          Call Read.Record(ContainerFile,Temp2!)
          Temp6!=ContainerRecord.Next
          If Temp6!>SFalse Then
             Call Read.Record(ContainerFile,Temp6!)
             If Temp2!<>ContainerRecord.Prev Then
                Gosub Truncate1f
                Exit Do
             Endif
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp2!=Temp6!
       Loop
    Endif
 Endif
 If Room>SFalse And Room<=Lof(RoomFile)/RoomRecLen Then
    Call Read.Record(RoomFile,Room)
    Temp2!=RoomRecord.Last2
    If Temp2! Then
       Do While Lost.Carrier=False
          Call Read.Record(ContainerFile,Temp2!)
          Temp6!=ContainerRecord.Prev
          If Temp6!>SFalse Then
             Call Read.Record(ContainerFile,Temp6!)
             If Temp2!<>ContainerRecord.Next Then
                Gosub Truncate2f
                Exit Do
             Endif
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp2!=Temp6!
       Loop
    Endif
 Endif
 VarZ3!=SFalse
 If Room>SFalse And Room<=Lof(RoomFile)/RoomRecLen Then
    Call Read.Record(RoomFile,Room)
    Temp2!=RoomRecord.First2
    If Temp2! Then
       Do While Lost.Carrier=False
          Call Read.Record(ContainerFile,Temp2!)
          Temp6!=ContainerRecord.Next
          Temp3!=ContainerRecord.RoomNumber
          If Temp3!<>Room Then
             VarZ3!=VarZ3!+1!
             ContainerRecord.RoomNumber=Room
             Call Write.Record(ContainerFile,Temp2!)
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp2!=Temp6!
       Loop
    Endif
 Endif
 Strng=" Reset"+Str$(VarZ1!)+" nodes."
 Call IO.O
 Strng=" Deleted"+Str$(VarZ2!)+" nodes."
 Call IO.O
 Strng=" Repaired"+Str$(VarZ3!)+" nodes."
 Call IO.O
 Exit Sub
Truncate1f:
 VarZ2!=VarZ2!+1!
 Call Read.Record(ContainerFile,Temp2!)
 ContainerRecord.Next=SFalse
 Call Write.Record(ContainerFile,Temp2!)
 RoomRecord.Last2=Temp2!
 Call Write.Record(RoomFile,Room)
 Return
Truncate2f:
 VarZ2!=VarZ2!+1!
 Call Read.Record(ContainerFile,Temp2!)
 ContainerRecord.Prev=SFalse
 Call Write.Record(ContainerFile,Temp2!)
 RoomRecord.First2=Temp2!
 Call Write.Record(RoomFile,Room)
 Return
ErrExit11x1:
 Exit Sub
ErrResume11x1:
 Resume ErrExit11x1
End Sub

Sub Repair.User.Containers
 On Local Error Goto ErrResume11x2
 Graphics.Off=True
 Strng="Repairing user containers.."
 Call IO.O
 VarZ1!=SFalse
 Call Read.Record(UserFile,User.Index)
 Temp2!=UserRecord.First2
 Temp3!=UserRecord.Last2
 If Temp2!>SFalse And Temp3!>SFalse Then
    If Temp2!=Temp3! Then
       Call Read.Record(ContainerFile,Temp2!)
       If ContainerRecord.Prev<>SFalse Or ContainerRecord.Next<>SFalse Then
          VarZ1!=VarZ1!+1!
          ContainerRecord.Prev=SFalse
          ContainerRecord.Next=SFalse
          Call Write.Record(ContainerFile,Temp2!)
       Endif
    Else
       Call Read.Record(ContainerFile,Temp2!)
       If ContainerRecord.Prev<>SFalse Then
          VarZ1!=VarZ1!+1!
          ContainerRecord.Prev=SFalse
          Call Write.Record(ContainerFile,Temp2!)
       Endif
       Call Read.Record(ContainerFile,Temp3!)
       If ContainerRecord.Next<>SFalse Then
          VarZ1!=VarZ1!+1!
          ContainerRecord.Next=SFalse
          Call Write.Record(ContainerFile,Temp3!)
       Endif
    Endif
 Endif
 VarZ2!=SFalse
 Close #TempFile1
 FileName="TABLE"+NodeX+".BK3"
 Open FileName For Random Shared As #TempFile1 Len=4
 Field #TempFile1,4 As S$
 VarY1!=0!
 Call Read.Record(UserFile,User.Index)
 Temp2!=UserRecord.First2
 If Temp2! Then
    Do
       Call Read.Record(ContainerFile,Temp2!)
       VarY1!=VarY1!+1!
       Lset S$=Mks$(Temp2!)
       Put #TempFile1,VarY1!
       Temp6!=ContainerRecord.Next
       If Temp6!>SFalse Then
          Call Read.Record(ContainerFile,Temp6!)
          For Temp7!=1! To VarY1!
             Get #TempFile1,Temp7!
             Temp8!=Cvs(S$)
             If Temp6!=Temp8! Then
                Gosub Truncate1g
                Exit Do
             Endif
          Next
       Endif
       If Temp6!=SFalse Then
          Exit Do
       Endif
       Temp2!=Temp6!
    Loop
 Endif
 VarY1!=0!
 Call Read.Record(UserFile,User.Index)
 Temp2!=UserRecord.Last2
 If Temp2! Then
    Do
       Call Read.Record(ContainerFile,Temp2!)
       VarY1!=VarY1!+1!
       Lset S$=Mks$(Temp2!)
       Put #TempFile1,VarY1!
       Temp6!=ContainerRecord.Prev
       If Temp6!>SFalse Then
          Call Read.Record(ContainerFile,Temp6!)
          For Temp7!=1! To VarY1!
             Get #TempFile1,Temp7!
             Temp8!=Cvs(S$)
             If Temp6!=Temp8! Then
                Gosub Truncate2g
                Exit Do
             Endif
          Next
       Endif
       If Temp6!=SFalse Then
          Exit Do
       Endif
       Temp2!=Temp6!
    Loop
 Endif
 Close #TempFile1
 Call Read.Record(UserFile,User.Index)
 Temp2!=UserRecord.First2
 If Temp2! Then
    Do While Lost.Carrier=False
       Call Read.Record(ContainerFile,Temp2!)
       Temp6!=ContainerRecord.Next
       If Temp6!>SFalse Then
          Call Read.Record(ContainerFile,Temp6!)
          If Temp2!<>ContainerRecord.Prev Then
             Gosub Truncate1g
             Exit Do
          Endif
       Endif
       If Temp6!=SFalse Then
          Exit Do
       Endif
       Temp2!=Temp6!
    Loop
 Endif
 Call Read.Record(UserFile,User.Index)
 Temp2!=UserRecord.Last2
 If Temp2! Then
    Do While Lost.Carrier=False
       Call Read.Record(ContainerFile,Temp2!)
       Temp6!=ContainerRecord.Prev
       If Temp6!>SFalse Then
          Call Read.Record(ContainerFile,Temp6!)
          If Temp2!<>ContainerRecord.Next Then
             Gosub Truncate2g
             Exit Do
          Endif
       Endif
       If Temp6!=SFalse Then
          Exit Do
       Endif
       Temp2!=Temp6!
    Loop
 Endif
 VarZ3!=SFalse
 Call Read.Record(UserFile,User.Index)
 Temp2!=UserRecord.First2
 If Temp2! Then
    Do While Lost.Carrier=False
       Call Read.Record(ContainerFile,Temp2!)
       Temp6!=ContainerRecord.Next
       Temp3!=ContainerRecord.UserNumber
       If Temp3!<>User.Index Then
          VarZ3!=VarZ3!+1!
          ContainerRecord.UserNumber=User.Index
          Call Write.Record(ContainerFile,Temp2!)
       Endif
       If Temp6!=SFalse Then
          Exit Do
       Endif
       Temp2!=Temp6!
    Loop
 Endif
 Strng=" Reset"+Str$(VarZ1!)+" nodes."
 Call IO.O
 Strng=" Deleted"+Str$(VarZ2!)+" nodes."
 Call IO.O
 Strng=" Repaired"+Str$(VarZ3!)+" nodes."
 Call IO.O
 Exit Sub
Truncate1g:
 VarZ2!=VarZ2!+1!
 Call Read.Record(ContainerFile,Temp2!)
 ContainerRecord.Next=SFalse
 Call Write.Record(ContainerFile,Temp2!)
 UserRecord.Last2=Temp2!
 Call Write.Record(UserFile,User.Index)
 Return
Truncate2g:
 VarZ2!=VarZ2!+1!
 Call Read.Record(ContainerFile,Temp2!)
 ContainerRecord.Prev=SFalse
 Call Write.Record(ContainerFile,Temp2!)
 UserRecord.First2=Temp2!
 Call Write.Record(UserFile,User.Index)
 Return
ErrExit11x2:
 Exit Sub
ErrResume11x2:
 Resume ErrExit11x2
End Sub

Sub Repair.Container.Inventory
 On Local Error Goto ErrResume11b
 Graphics.Off=True
 Strng="Repairing container inventory.."
 Call IO.O
 VarZ1!=SFalse
 For Temp1!=1! To Lof(ContainerFile)/ContainerRecLen
    Call Read.Record(ContainerFile,Temp1!)
    Temp2!=ContainerRecord.First
    Temp3!=ContainerRecord.Last
    If Temp2!>SFalse And Temp3!>SFalse Then
       If Temp2!=Temp3! Then
          Call Read.Record(CtnInvFile,Temp2!)
          If MessWorkRecord6.Prev<>SFalse Or MessWorkRecord6.Next<>SFalse Then
             VarZ1!=VarZ1!+1!
             MessWorkRecord6.Prev=SFalse
             MessWorkRecord6.Next=SFalse
             Call Write.Record(CtnInvFile,Temp2!)
          Endif
       Else
          Call Read.Record(CtnInvFile,Temp2!)
          If MessWorkRecord6.Prev<>SFalse Then
             VarZ1!=VarZ1!+1!
             MessWorkRecord6.Prev=SFalse
             Call Write.Record(CtnInvFile,Temp2!)
          Endif
          Call Read.Record(CtnInvFile,Temp3!)
          If MessWorkRecord6.Next<>SFalse Then
             VarZ1!=VarZ1!+1!
             MessWorkRecord6.Next=SFalse
             Call Write.Record(CtnInvFile,Temp3!)
          Endif
       Endif
    Endif
 Next
 VarZ2!=SFalse
 Close #TempFile1
 FileName="TABLE"+NodeX+".BK3"
 Open FileName For Random Shared As #TempFile1 Len=4
 Field #TempFile1,4 As S$
 For Temp1!=1! To Lof(ContainerFile)/ContainerRecLen
    VarY1!=0!
    Call Read.Record(ContainerFile,Temp1!)
    Temp2!=ContainerRecord.First
    If Temp2! Then
       Do
          Call Read.Record(CtnInvFile,Temp2!)
          VarY1!=VarY1!+1!
          Lset S$=Mks$(Temp2!)
          Put #TempFile1,VarY1!
          Temp6!=MessWorkRecord6.Next
          If Temp6!>SFalse Then
             Call Read.Record(CtnInvFile,Temp6!)
             For Temp7!=1! To VarY1!
                Get #TempFile1,Temp7!
                Temp8!=Cvs(S$)
                If Temp6!=Temp8! Then
                   Gosub Truncate1e
                   Exit Do
                Endif
             Next
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp2!=Temp6!
       Loop
    Endif
 Next
 For Temp1!=1! To Lof(ContainerFile)/ContainerRecLen
    VarY1!=0!
    Call Read.Record(ContainerFile,Temp1!)
    Temp2!=ContainerRecord.Last
    If Temp2! Then
       Do
          Call Read.Record(CtnInvFile,Temp2!)
          VarY1!=VarY1!+1!
          Lset S$=Mks$(Temp2!)
          Put #TempFile1,VarY1!
          Temp6!=MessWorkRecord6.Prev
          If Temp6!>SFalse Then
             Call Read.Record(CtnInvFile,Temp6!)
             For Temp7!=1! To VarY1!
                Get #TempFile1,Temp7!
                Temp8!=Cvs(S$)
                If Temp6!=Temp8! Then
                   Gosub Truncate2e
                   Exit Do
                Endif
             Next
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp2!=Temp6!
       Loop
    Endif
 Next
 Close #TempFile1
 For Temp1!=1! To Lof(ContainerFile)/ContainerRecLen
    Call Read.Record(ContainerFile,Temp1!)
    Temp2!=ContainerRecord.First
    If Temp2! Then
       Do While Lost.Carrier=False
          Call Read.Record(CtnInvFile,Temp2!)
          Temp6!=MessWorkRecord6.Next
          If Temp6!>SFalse Then
             Call Read.Record(CtnInvFile,Temp6!)
             If Temp2!<>MessWorkRecord6.Prev Then
                Gosub Truncate1e
                Exit Do
             Endif
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp2!=Temp6!
       Loop
    Endif
 Next
 For Temp1!=1! To Lof(ContainerFile)/ContainerRecLen
    Call Read.Record(ContainerFile,Temp1!)
    Temp2!=ContainerRecord.Last
    If Temp2! Then
       Do While Lost.Carrier=False
          Call Read.Record(CtnInvFile,Temp2!)
          Temp6!=MessWorkRecord6.Prev
          If Temp6!>SFalse Then
             Call Read.Record(CtnInvFile,Temp6!)
             If Temp2!<>MessWorkRecord6.Next Then
                Gosub Truncate2e
                Exit Do
             Endif
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp2!=Temp6!
       Loop
    Endif
 Next
 VarZ3!=SFalse
 For Temp1!=1! To Lof(ContainerFile)/ContainerRecLen
    Call Read.Record(ContainerFile,Temp1!)
    Temp2!=ContainerRecord.First
    If Temp2! Then
       Do While Lost.Carrier=False
          Call Read.Record(CtnInvFile,Temp2!)
          Temp6!=MessWorkRecord6.Next
          Temp3!=MessWorkRecord6.Index
          If Temp3!<>Temp1! Then
             VarZ3!=VarZ3!+1!
             MessWorkRecord6.Index=Temp1!
             Call Write.Record(CtnInvFile,Temp2!)
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp2!=Temp6!
       Loop
    Endif
 Next
 Strng=" Reset"+Str$(VarZ1!)+" nodes."
 Call IO.O
 Strng=" Deleted"+Str$(VarZ2!)+" nodes."
 Call IO.O
 Strng=" Repaired"+Str$(VarZ3!)+" nodes."
 Call IO.O
 Exit Sub
Truncate1e:
 VarZ2!=VarZ2!+1!
 Call Read.Record(CtnInvFile,Temp2!)
 MessWorkRecord6.Next=SFalse
 Call Write.Record(CtnInvFile,Temp2!)
 ContainerRecord.Last=Temp2!
 Call Write.Record(ContainerFile,Temp1!)
 Return
Truncate2e:
 VarZ2!=VarZ2!+1!
 Call Read.Record(CtnInvFile,Temp2!)
 MessWorkRecord6.Prev=SFalse
 Call Write.Record(CtnInvFile,Temp2!)
 ContainerRecord.First=Temp2!
 Call Write.Record(ContainerFile,Temp1!)
 Return
ErrExit11b:
 Exit Sub
ErrResume11b:
 Resume ErrExit11b
End Sub

Sub Repair.Within.Containers
 On Local Error Goto ErrResume11x3
 Graphics.Off=True
 Strng="Repairing containers within containers.."
 Call IO.O
 VarZ1!=SFalse
 For Temp1!=1! To Lof(ContainerFile)/ContainerRecLen
    Call Read.Record(ContainerFile,Temp1!)
    Temp2!=ContainerRecord.First2
    Temp3!=ContainerRecord.Last2
    If Temp2!>SFalse And Temp3!>SFalse Then
       If Temp2!=Temp3! Then
          Call Read.Record(ContainerFile,Temp2!)
          If ContainerRecord.Prev<>SFalse Or ContainerRecord.Next<>SFalse Then
             VarZ1!=VarZ1!+1!
             ContainerRecord.Prev=SFalse
             ContainerRecord.Next=SFalse
             Call Write.Record(ContainerFile,Temp2!)
          Endif
       Else
          Call Read.Record(ContainerFile,Temp2!)
          If ContainerRecord.Prev<>SFalse Then
             VarZ1!=VarZ1!+1!
             ContainerRecord.Prev=SFalse
             Call Write.Record(ContainerFile,Temp2!)
          Endif
          Call Read.Record(ContainerFile,Temp3!)
          If ContainerRecord.Next<>SFalse Then
             VarZ1!=VarZ1!+1!
             ContainerRecord.Next=SFalse
             Call Write.Record(ContainerFile,Temp3!)
          Endif
       Endif
    Endif
 Next
 VarZ2!=SFalse
 Close #TempFile1
 FileName="TABLE"+NodeX+".BK3"
 Open FileName For Random Shared As #TempFile1 Len=4
 Field #TempFile1,4 As S$
 For Temp1!=1! To Lof(ContainerFile)/ContainerRecLen
    VarY1!=0!
    Call Read.Record(ContainerFile,Temp1!)
    Temp2!=ContainerRecord.First2
    If Temp2! Then
       Do
          Call Read.Record(ContainerFile,Temp2!)
          VarY1!=VarY1!+1!
          Lset S$=Mks$(Temp2!)
          Put #TempFile1,VarY1!
          Temp6!=ContainerRecord.Next
          If Temp6!>SFalse Then
             Call Read.Record(ContainerFile,Temp6!)
             For Temp7!=1! To VarY1!
                Get #TempFile1,Temp7!
                Temp8!=Cvs(S$)
                If Temp6!=Temp8! Then
                   Gosub Truncate1h
                   Exit Do
                Endif
             Next
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp2!=Temp6!
       Loop
    Endif
 Next
 For Temp1!=1! To Lof(ContainerFile)/ContainerRecLen
    VarY1!=0!
    Call Read.Record(ContainerFile,Temp1!)
    Temp2!=ContainerRecord.Last2
    If Temp2! Then
       Do
          Call Read.Record(ContainerFile,Temp2!)
          VarY1!=VarY1!+1!
          Lset S$=Mks$(Temp2!)
          Put #TempFile1,VarY1!
          Temp6!=ContainerRecord.Prev
          If Temp6!>SFalse Then
             Call Read.Record(ContainerFile,Temp6!)
             For Temp7!=1! To VarY1!
                Get #TempFile1,Temp7!
                Temp8!=Cvs(S$)
                If Temp6!=Temp8! Then
                   Gosub Truncate2h
                   Exit Do
                Endif
             Next
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp2!=Temp6!
       Loop
    Endif
 Next
 Close #TempFile1
 For Temp1!=1! To Lof(ContainerFile)/ContainerRecLen
    Call Read.Record(ContainerFile,Temp1!)
    Temp2!=ContainerRecord.First2
    If Temp2! Then
       Do While Lost.Carrier=False
          Call Read.Record(ContainerFile,Temp2!)
          Temp6!=ContainerRecord.Next
          If Temp6!>SFalse Then
             Call Read.Record(ContainerFile,Temp6!)
             If Temp2!<>ContainerRecord.Prev Then
                Gosub Truncate1h
                Exit Do
             Endif
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp2!=Temp6!
       Loop
    Endif
 Next
 For Temp1!=1! To Lof(ContainerFile)/ContainerRecLen
    Call Read.Record(ContainerFile,Temp1!)
    Temp2!=ContainerRecord.Last2
    If Temp2! Then
       Do While Lost.Carrier=False
          Call Read.Record(ContainerFile,Temp2!)
          Temp6!=ContainerRecord.Prev
          If Temp6!>SFalse Then
             Call Read.Record(ContainerFile,Temp6!)
             If Temp2!<>ContainerRecord.Next Then
                Gosub Truncate2h
                Exit Do
             Endif
          Endif
          If Temp6!=SFalse Then
             Exit Do
          Endif
          Temp2!=Temp6!
       Loop
    Endif
 Next
 Strng=" Reset"+Str$(VarZ1!)+" nodes."
 Call IO.O
 Strng=" Deleted"+Str$(VarZ2!)+" nodes."
 Call IO.O
 Exit Sub
Truncate1h:
 VarZ2!=VarZ2!+1!
 Call Read.Record(ContainerFile,Temp2!)
 ContainerRecord.Next=SFalse
 Call Write.Record(ContainerFile,Temp2!)
 Call Read.Record(ContainerFile,Temp1!)
 ContainerRecord.Last2=Temp2!
 Call Write.Record(ContainerFile,Temp1!)
 Return
Truncate2h:
 VarZ2!=VarZ2!+1!
 Call Read.Record(ContainerFile,Temp2!)
 ContainerRecord.Prev=SFalse
 Call Write.Record(ContainerFile,Temp2!)
 Call Read.Record(ContainerFile,Temp1!)
 ContainerRecord.First2=Temp2!
 Call Write.Record(ContainerFile,Temp1!)
 Return
ErrExit11x3:
 Exit Sub
ErrResume11x3:
 Resume ErrExit11x3
End Sub
