 Rem File: Cmd210.bas
 Rem Sub: Vote
 Rem $Include: 'dndbbs.inc'
 Type Vote
    VoteFrom As String*30
    VoteTo As String*30
    ThumbUp As Integer
    ThumbDown As Integer
    Stars As Integer ' 1-5
    Rating As Integer ' 1-10
    VoteAs As Integer
    DatePost As String*10
    TimePost As String*8
    Deleted As Integer
    PostLevel As Integer
    Comment As String*79
    Buffer1 As Integer
    Buffer2 As Integer
    Buffer3 As Single
    Buffer4 As Single
    Buffer5 As Double
    Buffer6 As Double
 End Type
 Dim Shared Voting As Vote
 Dim Shared VoteFileName As String
 Dim Shared VoteFileRecLen As Integer
 VoteFileRecLen=Len(Voting)

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

Sub Vote
 On Local Error Goto Error.Trap34
 Gosub Get.Config
 If VarZ Then
    Gosub Reset.Options
 Endif
 If GuestLogin Then
    'If GuestRecord.GuestAllowMail=False Then
    If optionx9=0 Then
       Strng="Guests cannot use Vote.."
       Call IO.O
       Exit Sub
    Endif
 Endif
 Strng="The Voting Booth Master welcomes you!"
 Call IO.O
 Gosub Vote.Help
 Do While Lost.Carrier=False
    Call Vote.Status.Line
    No.Input.Out="Q"
    Graphics.Off=False
    Strng="Vote selection(?=Help): "
    Call IO.I
    VarX=True
    Out3=Ucase$(Out2)
    Select Case Out3
    Case "?"
       Gosub Vote.Help
    Case "Q"
       Exit Do
    Case "B"
       Call Vote.Booth
    Case "D"
       Call Vote.Delete
    Case "E"
       VarQ=0
       If UserRecord.ClassType=AsstDM Then
          If optionx6 Then
             VarQ=-1
          Endif
       Endif
       If UserRecord.ClassType=DM Then
          If optionx7 Then
             VarQ=-1
          Endif
       Endif
       If UserRecord.Flags And Special.Char4 Then ' sysop
          VarQ=-1
       Endif
       If VarQ Then
          Call Vote.Edit
       Endif
    Case "L"
       Call Vote.List
    Case "S"
       Call Vote.Search
    Case "T"
       Call Vote.Count
    Case "V"
       Call Vote.Command(optionx1,optionx2,optionx3,optionx4,optionx5,optionx8,optionx10)
    End Select
 Loop
 Exit Sub
Vote.Help:
 Graphics.Off=False
 Strng="Vote functions:"
 Call IO.O
 Graphics.Off=True
 Strng="[B]oothlock"
 Call IO.O
 Strng="[D]elete"
 Call IO.O
 VarQ=0
 If UserRecord.ClassType=AsstDM Then
    If optionx6 Then
       VarQ=-1
    Endif
 Endif
 If UserRecord.ClassType=DM Then
    If optionx7 Then
       VarQ=-1
    Endif
 Endif
 If UserRecord.Flags And Special.Char4 Then ' sysop
    VarQ=-1
 Endif
 If VarQ Then
    Strng="[E]dit"
    Call IO.O
 Endif
 Strng="[L]ist"
 Call IO.O
 Strng="[S]earch"
 Call IO.O
 Strng="[T]otals"
 Call IO.O
 Strng="[V]ote"
 Call IO.O
 Return
Get.Config:
 Gosub Reset.Options
 VarX=0
 VarZ=0
 Do
    VarX=VarX+1
    If VarX>Options.Lines Then
       Goto Next.Read
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
    If Ucase$(Var$)="[CMD210]" Then
       Do
          VarX=VarX+1
          If VarX>Options.Lines Then
             Goto Next.Read
             Return
          Endif
          Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
          If Ucase$(Var$)="[END]" Then
             Goto Next.Read
             Return
          Endif
          Var=Instr(Var$,"=")
          If Var Then
             Var2$=Ltrim$(Rtrim$(Left$(Var$,Var-1)))
             Var3$=Ltrim$(Rtrim$(Mid$(Var$,Var+1)))
             Gosub Parse.Options
          Endif
       Loop
    Endif
 Loop
 Return
Next.Read:
 Close #TempFile1
 Filename$=DND.Path+"CMD210.CFG"
 If Dir$(Filename$)="" Then
    Return
 Endif
 Open Filename$ For Input As #TempFile1
 Do
    If Eof(TempFile1) Then
       Exit Do
    Endif
    Line Input #TempFile1, Var$
    Var$=Ltrim$(Rtrim$(Var$))
    If Left$(Var$,1)<>";" Then
       VarX$=UserRecord.CodeName
       VarX$=Rtrim$(VarX$)
       VarX$=Ucase$(VarX$)
       If Ucase$(Var$)="["+VarX$+"]" Then
          VarZ=0
          Gosub Reset.Options
          Do
             If Eof(TempFile1) Then
                Exit Do
             Endif
             Line Input #TempFile1, Var$
             If Ucase$(Var$)="[END]" Then
                Return
             Endif
             Var=Instr(Var$,"=")
             If Var Then
                Var2$=Ltrim$(Rtrim$(Left$(Var$,Var-1)))
                Var3$=Ltrim$(Rtrim$(Mid$(Var$,Var+1)))
                Gosub Parse.Options
             Endif
          Loop
       Endif
    Endif
 Loop
 Return
Reset.Options:
 optionx1=0: optionx2=0: optionx3=0: optionx4=0
 optionx5=0: optionx6=0: optionx7=0: optionx8=0: optionx9=0: optionx10=0
 TempD!=100!
 Return
Parse.Options:
 Select Case Lcase$(Var2$)
 Case "disable.mailbox.lock"
    Select Case Lcase$(Var3$)
    Case "-1", "true", "on"
       optionx1=-1
    Case "0", "false", "off"
       optionx1=0
    End Select
 Case "allow.vote.self"
    Select Case Lcase$(Var3$)
    Case "-1", "true", "on"
       optionx2=-1
    Case "0", "false", "off"
       optionx2=0
    End Select
 Case "allow.adm.vote.self"
    Select Case Lcase$(Var3$)
    Case "-1", "true", "on"
       optionx3=-1
    Case "0", "false", "off"
       optionx3=0
    End Select
 Case "allow.dm.vote.self"
    Select Case Lcase$(Var3$)
    Case "-1", "true", "on"
       optionx4=-1
    Case "0", "false", "off"
       optionx4=0
    End Select
 Case "allow.adm.vote.edit"
    Select Case Lcase$(Var3$)
    Case "-1", "true", "on"
       optionx6=-1
    Case "0", "false", "off"
       optionx6=0
    End Select
 Case "allow.dm.vote.edit"
    Select Case Lcase$(Var3$)
    Case "-1", "true", "on"
       optionx7=-1
    Case "0", "false", "off"
       optionx7=0
    End Select
 Case "allow.guest.vote"
    Select Case Lcase$(Var3$)
    Case "-1", "true", "on"
       optionx9=-1
    Case "0", "false", "off"
       optionx9=0
    End Select
 Case "allow.dead.vote"
    Select Case Lcase$(Var3$)
    Case "-1", "true", "on"
       optionx10=-1
    Case "0", "false", "off"
       optionx10=0
    End Select
 Case "required.level.to.vote"
    If Int(Val(Var3$)+.5)>0 And Int(Val(Var3$)+.5)<=32767 Then
       optionx5=Int(Val(Var3$)+.5)
    Endif
 Case "required.intelligence.to.vote"
    If Int(Val(Var3$)+.5)>0 And Int(Val(Var3$)+.5)<=32767 Then
       optionx8=Int(Val(Var3$)+.5)
    Endif
 Case "voting.reward"
    If Int(Val(Var3$)+.5)>=10 And Int(Val(Var3$)+.5)<=32767 Then
       TempD!=Csng(Int(Val(Var3$)+.5))
    Endif
 End Select
 Return
Error.Resume34:
 Exit Sub
Error.Trap34:
 Resume Error.Resume34
End Sub

Sub Vote.Count
 On Local Error Goto Error.Trap58x4
 Close #TempFile2
 Open VoteFileName$ For Random Shared As #TempFile2 Len=VoteFileRecLen
 VarZ!=Lof(TempFile2)/VoteFileRecLen
 Strng="Total of"+Str$(VarZ!)+" users have voted."
 Call IO.O
 For Var!=1! To Lof(TempFile2)/VoteFileRecLen
    Get #TempFile2,Var!,Voting
    If Voting.Deleted Then TotalDeleted=TotalDeleted+1
    If Voting.Deleted=0 Then
       If Voting.ThumbUp=1 Then ThumbsUp=ThumbsUp+1
       If Voting.ThumbDown=1 Then ThumbsDown=ThumbsDown+1
       If Voting.Stars Then
          NumberStars=NumberStars+1
          TotalStars=TotalStars+Voting.Stars
       Endif
       If Voting.Rating Then
          NumberPoints=NumberPoints+1
          TotalPoints=TotalPoints+Voting.Rating
       Endif
    Endif
 Next
 Strng="For total"+Str$(Thumbsup)+" ThumbsUp"
 Strng=Strng+Str$(Thumbsdown)+" ThumbsDown"
 Strng=Strng+Str$(TotalStars)+" Stars"
 Strng=Strng+Str$(TotalPoints)+" Points"
 Call IO.O
 If NumberStars>0 Then
    Var1!=Csng(TotalStars): Var2!=Csng(NumberStars)
    VarZ!=Var1!/Var2!
    Strng2=Str$(VarZ!)
    If Instr(Strng2,".") Then Strng2=Left$(Strng2,Instr(Strng2,".")+2)
    Strng="Averaging"+Strng2+" stars."
    Call IO.O
 Endif
 If NumberPoints>0 Then
    Var1!=Csng(TotalPoints): Var2!=Csng(NumberPoints)
    VarZ!=Var1!/Var2!
    Strng2=Str$(VarZ!)
    If Instr(Strng2,".") Then Strng2=Left$(Strng2,Instr(Strng2,".")+2)
    Strng="Averaging"+Strng2+" rating."
    Call IO.O
 Endif
 If TotalDeleted>0 Then
    Strng="Total votes deleted:"+Str$(TotalDeleted)+"."
    Call IO.O
 Endif
Error.Resume58x4:
 Exit Sub
Error.Trap58x4:
 Resume Error.Resume58x4
End Sub

Sub Vote.Search
 On Local Error Goto Error.Trap58x3
 Close #TempFile2
 Open VoteFileName$ For Random Shared As #TempFile2 Len=VoteFileRecLen
 Strng="Enter username who voted for you: "
 Call IO.I
 VarX$=Ltrim$(Rtrim$(Out2))
 If Len(VarX$) Then
    Found=0
    VarX$=Ucase$(VarX$)
    VarZ=0
    For Var!=1! To Lof(TempFile2)/VoteFileRecLen
       Var1$=UserRecord.CodeName
       Var1$=Rtrim$(Var1$)
       Var1$=Ucase$(Var1$)
       Get #TempFile2,Var!,Voting
       If Voting.Deleted Then Goto Next.Search2
       Var2$=Voting.VoteTo
       Var2$=Rtrim$(Var2$)
       Var2$=Ucase$(Var2$)
       If Var1$=Var2$ Then
          VarY$=Voting.VoteFrom
          VarY$=Rtrim$(VarY$)
          VarY$=Ucase$(VarY$)
          If Var2$=VarY$ Then VarZ=-1 ' voted for self
          Strng=VarY$
          Call InstrSUB1(Var,VarX$,0)
          'If VarX$=VarY$ Then
          If Var Then
             Found=Found+1
             If Voting.ThumbUp=1 Then
                ThumbUp=ThumbUp+1
             Endif
             If Voting.ThumbDown=1 Then
                ThumbDown=ThumbDown+1
             Endif
             If Voting.Stars>0 Then
                NumberStars=NumberStars+1!
                TotalStars=TotalStars+Csng(Voting.Stars)
             Endif
             If Voting.Rating>0 Then
                NumberRating=NumberRating+1!
                TotalRating=TotalRating+Voting.Rating
             Endif
          Endif
       Endif
Next.Search2:
    Next
    If Found=0 Then
       Strng="User has not voted for you."
       Call IO.O
    Else
       If VarZ Then
          Strng="You have voted for yourself"
       Else
          Strng=Rtrim$(Voting.VoteFrom)
          Strng=Lcase$(Strng)
          Mid$(Strng,1,1)=Ucase$(Mid$(Strng,1,1))
          Strng=Strng+" has voted for you"
       Endif
       If Found=1 Then
          Strng=Strng+" 1 time."
       Else
          Strng=Strng+Str$(Found)+" times."
       Endif
       Call IO.O
       Strng=Str$(ThumbUp)+" thumbs up."
       Call IO.O
       Strng=Str$(ThumbDown)+" thumbs down."
       Call IO.O
       If NumberStars=0 Then
          Strng=" 0 stars."
          Call IO.O
       Endif
       If NumberStars>0 Then
          Strng=Str$(TotalStars)+" stars. "
          Var1!=Csng(TotalStars): Var2!=Csng(NumberStars)
          VarZ!=Var1!/Var2!
          Strng2=Str$(VarZ!)
          If Instr(Strng2,".") Then Strng2=Left$(Strng2,Instr(Strng2,".")+2)
          Strng=Strng+"Averaging"+Strng2+" stars."
          Call IO.O
       Endif
       If NumberRating=0 Then
          Strng=" 0 points."
          Call IO.O
       Endif
       If NumberRating>0 Then
          Strng=Str$(TotalRating)+" points. "
          Var1!=Csng(TotalRating): Var2!=Csng(NumberRating)
          VarZ!=Var1!/Var2!
          Strng2=Str$(VarZ!)
          If Instr(Strng2,".") Then Strng2=Left$(Strng2,Instr(Strng2,".")+2)
          Strng=Strng+"Averaging"+Strng2+" rating."
          Call IO.O
       Endif
    Endif
 Endif
Error.Resume58x3:
 Exit Sub
Error.Trap58x3:
 Resume Error.Resume58x3
End Sub

Sub Vote.Delete
 On Local Error Goto Error.Trap58x5
 VarC=0
 Close #TempFile2
 Open VoteFileName$ For Random Shared As #TempFile2 Len=VoteFileRecLen
 Strng="Enter post to delete: "
 Call IO.I
 VarZ!=Int(Val(Out2)+.5)
 If VarZ!>0! And VarZ!<=Lof(TempFile2)/VoteFileRecLen Then
    Get #TempFile,VarZ!,Voting
    Var$=Voting.VoteFrom
    Var$=Rtrim$(Var$)
    Var$=Ucase$(Var$)
    Var1$=UserRecord.CodeName
    Var1$=Rtrim$(Var1$)
    Var1$=Ucase$(Var1$)
    If Var$=Var1$ Then
       Voting.Deleted=-1
       Strng="Voting record deleted."
       Call IO.O
       Gosub Delete.Vote2
    Else
       Strng="Voting record not found."
       Call IO.O
    Endif
 Endif
 Exit Sub
 ' lock in vote.
Delete.Vote2:
 Lock #TempFile2
 Put #TempFile2,VarZ!,Voting
 Unlock #TempFile2
 Return
Error.Resume58x5:
 Exit Sub
Error.Trap58x5:
 If Err=70 Then ' share violation
    VarC=VarC+1
    If VarC<5 Then
       Sleep 1
       Resume Delete.Vote2
    Endif
 Endif
 Strng="Voting file error."
 Call IO.O
 Resume Error.Resume58x5
End Sub

Sub Vote.List
 On Local Error Goto Error.Trap58x2
 VarC=0: VarD=0
 Close #TempFile2
 Open VoteFileName$ For Random Shared As #TempFile2 Len=VoteFileRecLen
 For Var!=1! To Lof(TempFile2)/VoteFileRecLen
    Var1$=UserRecord.CodeName
    Var1$=Rtrim$(Var1$)
    Var1$=Ucase$(Var1$)
    Get #TempFile2,Var!,Voting
    Var2$=Voting.VoteTo
    Var2$=Rtrim$(Var2$)
    Var2$=Ucase$(Var2$)
    If Voting.Deleted Then Var2$=Nul
    If Var1$=Var2$ Then
       Strng=Voting.VoteFrom
       Strng=Rtrim$(Strng)
       Strng=Lcase$(Strng)
       Mid$(Strng,1,1)=Ucase$(Mid$(Strng,1,1))
       Strng=Strng+" voted for you on "+Voting.DatePost+" "+Voting.TimePost
       Call IO.O
       Strng=Nul
       If Voting.ThumbUp=1 Then
          Strng=Strng+" -- one thumbs up."
       Endif
       If Voting.ThumbDown=1 Then
          Strng=Strng+" -- one thumbs down."
       Endif
       If Voting.Stars>0 Then
          Strng=Strng+" --"+Str$(Voting.Stars)+" stars."
       Endif
       If Voting.Rating>0 Then
          Strng=Strng+" --"+Str$(Voting.Rating)+" points."
       Endif
       If Len(Strng) Then
          Graphics.Off=True
          Call IO.O
       Endif
       If Rtrim$(Voting.Comment)<>"" Then
          Strng="Comment:"
          Call IO.O
          Strng=Rtrim$(Voting.Comment)
          Call IO.O
          VarC=VarC+2
       Endif
       VarD=-1
       VarC=VarC+1
       If VarC>=Max.Row-2 Then
          VarC=0
          Call More.Prompt
       Endif
    Endif
 Next
 If VarD=0 Then
    Strng="No voting entries found."
    Call IO.O
 Endif
Error.Resume58x2:
 Exit Sub
Error.Trap58x2:
 Resume Error.Resume58x2
End Sub

Sub Vote.Edit
 On Local Error Goto Error.Trap58x6
 Close #TempFile2
 Open VoteFileName$ For Random Shared As #TempFile2 Len=VoteFileRecLen
 Var!=Lof(TempFile2)/VoteFileRecLen
 If Var!=0! Then
    Strng="No Votes found."
    Call IO.O
 Endif
 Strng="Vote number or name to edit(1-"+Ltrim$(Str$(Var!))+")?"
 Call IO.I
 Var1!=Csng(Val(Out2)):Var1!=Int(Var1!)
 Var2=0
 If Var1!=0 Then
    Var1$=Rtrim$(Ucase$(Out2))
    If Left$(Var1$,1)="#" Then
       Var2$=Mid$(Var1$,2): Var1!=Csng(Val(Var2$)): Var1!=Int(Var1!)
       Goto Next.Search
    Endif
    If Instr(Var1$,"#") Then
       Var2$=Mid$(Var1$,Instr(Var1$,"#")+1): Var2=Int(Val(Var2$)+.5)
       Var1$=Left$(Var1$,Instr(Var1$,"#")-1)
    Endif
    Num=0
    For VarX!=1! To Lof(TempFile2)/VoteFileRecLen
       Get #TempFile2,VarX!,Voting
       From$=Ucase$(Rtrim$(Voting.VoteFrom))
       Strng=From$
       Call InstrSUB1(Var,Var1$,0)
       'If From$=Var1$ Then
       If Var Then
          Num=Num+1
          If Num=Var2 Or Var2=0 Then
             Var1!=VarX!
             Exit For
          Endif
       Endif
    Next
 Endif
Next.Search:
 If Var1!>0! And Var1!<=Var! Then
    Get #TempFile2,Var1!,Voting
    VarZ$=Rtrim$(Voting.VoteFrom)
    VarZ$=Lcase$(VarZ$)
    Mid$(VarZ$,1,1)=Ucase$(Mid$(VarZ$,1,1))
    Strng="Now editing Vote"+Str$(Var1!)+" from "+VarZ$
    Call IO.O
    Do While Lost.Carrier=False
       'Call Vote.Status.Line
       No.Input.Out="Q"
       Graphics.Off=False
       Strng="Voting booth edit command(?=Help): "
       Call IO.I
       VarX$=Ucase$(Out2)
       Select Case VarX$
       Case "?"
          Gosub Vote.Command.Help2
       Case "Q"
          Exit Do
       Case "C" ' comment
          Strng="Comment:"
          Call IO.O
          Line.Length=79
          Strng="?"
          Call IO.I
          Out2=Rtrim$(Out2)
          If Out2="" Then
             Strng="Comment deleted."
             Call IO.O
             Voting.Comment=Nul
          Else
             Strng="Comment added."
             Call IO.O
             Voting.Comment=Out2
          Endif
       Case "T" ' thumbs
          Strng="Thumbs (U)p/(D)own?"
          Call IO.I
          VarZ$=Ucase$(Out2)
          Select Case VarZ$
          Case "U"
             If Voting.ThumbUp=0 Then
                Voting.ThumbUp=1
                Strng="Thumbs up now set."
                Call IO.O
             Else
                If Voting.ThumbUp=1 Then
                   Voting.ThumbUp=0
                   Strng="Thumbs up now reset."
                   Call IO.O
                Else
                   Voting.ThumbUp=0
                   Strng="Thumbs up init."
                   Call IO.O
                Endif
             Endif
          Case "D"
             If Voting.ThumbDown=0 Then
                Voting.ThumbDown=1
                Strng="Thumbs down now set."
                Call IO.O
             Else
                If Voting.ThumbDown=1 Then
                   Voting.ThumbDown=0
                   Strng="Thumbs down now reset."
                   Call IO.O
                Else
                   Voting.ThumbDown=0
                   Strng="Thumbs down init."
                   Call IO.O
                Endif
             Endif
          End Select
       Case "S" ' stars
          Strng="Stars(1-5)?"
          Call IO.I
          VarX=Int(Val(Out2)+.5)
          If VarX>=0 And VarX<=5 Then
             Voting.Stars=VarX
             Strng="Stars reset."
             Call IO.O
          Endif
       Case "R" ' rating
          Strng="Rating(1-10)?"
          Call IO.I
          VarX=Int(Val(Out2)+.5)
          If VarX>=0 And VarX<=10 Then
             Voting.Rating=VarX
             Strng="Rating reset."
             Call IO.O
          Endif
       Case "L" ' level
          Strng="Userlevel(0-32767)?"
          Call IO.I
          VarX=Int(Val(Out2)+.5)
          If VarX>=0 And VarX<=32767 Then
             Voting.PostLevel=VarX
             Strng="Level reset."
             Call IO.O
          Endif
       Case "1" ' delete
          Voting.Deleted=-1
          Strng="Vote deleted."
          Call IO.O
       Case "2" ' undelete
          Voting.Deleted=0
          Strng="Vote undeleted."
          Call IO.O
       Case "D" ' display
          VarZ1$=Rtrim$(Voting.VoteFrom)
          VarZ1$=Lcase$(VarZ1$)
          Mid$(VarZ1$,1,1)=Ucase$(Mid$(VarZ1$,1,1))
          VarZ2$=Rtrim$(Voting.VoteTo)
          VarZ2$=Lcase$(VarZ2$)
          Mid$(VarZ2$,1,1)=Ucase$(Mid$(VarZ2$,1,1))
          Strng=VarZ1$+" voted for "+VarZ2$+" on "+Voting.DatePost+" "+Voting.TimePost
          Call IO.O
          If Voting.Deleted Then
             Strng="Vote deleted."
             Call IO.O
          Endif
          Strng="Thumbs up:"+Str$(Voting.ThumbUp)
          Call IO.O
          Strng="Thumbs down:"+Str$(Voting.ThumbDown)
          Call IO.O
          Strng="Userlevel:"+Str$(Voting.PostLevel)
          Call IO.O
          Strng="Stars:"+Str$(Voting.Stars)
          Call IO.O
          Strng="Rating:"+Str$(Voting.Rating)
          Call IO.O
          VarZ3$=Rtrim$(Voting.Comment)
          If VarZ3$="" Then
             Strng="No comment."
             Call IO.O
          Else
             Strng="Comment:"
             Call IO.O
             Strng=VarZ3$
             Call IO.O
          Endif
          Call More.Prompt
       Case "U"
          VarC=0
          Gosub Write.Vote3
          Strng="Vote updated."
          Call IO.O
       End Select
    Loop
    Exit Sub
 Endif
 Strng="Vote not found."
 Call IO.O
 Exit Sub
Write.Vote3:
 Lock #TempFile2, Var1!
 Put #TempFile2,Var1!,Voting
 Unlock #TempFile2, Var1!
 Return
Error.Resume58x6:
 Exit Sub
Error.Trap58x6:
 If Err=70 Then ' share violation
    VarC=VarC+1
    If VarC<5 Then
       Sleep 1
       Resume Write.Vote3
    Endif
 Endif
 Strng="Voting file error."
 Call IO.O
 Resume Error.Resume58x6
Vote.Command.Help2:
 Graphics.Off=False
 Strng="Vote functions:"
 Call IO.O
 Graphics.Off=True
 Strng="[1]delete"
 Call IO.O
 Strng="[2]undelete"
 Call IO.O
 Strng="[C]omment"
 Call IO.O
 Strng="[L]evel"
 Call IO.O
 Strng="[T]humbs"
 Call IO.O
 Strng="[S]tars"
 Call IO.O
 Strng="[R]ating"
 Call IO.O
 Strng="[D]isplay"
 Call IO.O
 Strng="[U]pdate"
 Call IO.O
 Return
End Sub

Sub Vote.Command(optionx1,optionx2,optionx3,optionx4,optionx5,optionx8,optionx10)
 On Local Error Goto Error.Trap58x
 If UserRecord.Level=0 Then
    If optionx10=0 Then
       Strng="Dead users can't vote."
       Call IO.O
       Exit Sub
    Endif
    Strng="Dead user may vote."
    Call IO.O
 Endif
 ' asstdm/dm/sysop can always vote.
 If UserRecord.ClassType=AsstDM Then
    Goto Next.Check2
 Endif
 If UserRecord.ClassType=DM Then
    Goto Next.Check2
 Endif
 If UserRecord.Flags And Special.Char4 Then ' sysop
    Goto Next.Check2
 Endif
 ' check user level required to vote.
 If optionx5>0 Then
    If UserRecord.Level<optionx5 Then
       Strng="Can't vote until level"+Str$(optionx5)+"."
       Call IO.O
       Exit Sub
    Endif
 Endif
 ' check user intelligence required to vote.
 If optionx8>0 Then
    If UserRecord.Stats(2)<optionx8 Then
       Strng="Can't vote until intelligence is"+Str$(optionx8)+"."
       Call IO.O
       Exit Sub
    Endif
 Endif
Next.Check2:
 ' open voting datafile.
 Close #TempFile1
 Close #TempFile2
 Open VoteFileName$ For Random Shared As #TempFile2 Len=VoteFileRecLen
 Strng="Welcome to the Voting Booth.."
 Call IO.O
 ' start voting booth.
 Strng="Enter username to vote for: "
 Call IO.I
 Out2=Ucase$(Out2)
 If Out2=Nul Then Exit Sub
 Found=0
 For Temp.User.Index=1! To Lof(UserFile2)/UserRecLen
    Call Read.Record(UserFile2,Temp.User.Index)
    Strng=UserRecord2.CodeName
    Strng=Rtrim$(Strng)
    Strng=Ucase$(Strng)
    If Out2=Strng Then
       If optionx2=0 Then
          If User.Index=Temp.User.Index Then
             If UserRecord.ClassType=AsstDM Then
                If optionx3 Then
                   Goto Next.Check
                Endif
             Endif
             If UserRecord.ClassType=DM Then
                If optionx4 Then
                   Goto Next.Check
                Endif
             Endif
             If UserRecord.Flags And Special.Char4 Then ' sysop
                Goto Next.Check
             Endif
             Strng="Can't vote for yourself."
             Call IO.O
             Exit Sub
          Endif
       Endif
Next.Check:
       Found=-1
       Exit For
    Endif
 Next
 If Found=0 Then
    Strng="Username not found."
    Call IO.O
    Exit Sub
 Endif
 If optionx1=0 Then
    If (UserRecord2.Flags2 And 2) = 2 Then
       Strng="Voting Booth locked."
       Call IO.O
       Exit Sub
    Endif
 Endif
 VoteFor$=Lcase$(Out2)
 Mid$(VoteFor$,1,1)=Ucase$(Mid$(VoteFor$,1,1))
 Strng="Now voting for "+Chr$(34)+VoteFor$+Chr$(34)
 Call IO.O
 Gosub Vote.Command.Help
 Do While Lost.Carrier=False
    Call Vote.Status.Line
    No.Input.Out="Q"
    Graphics.Off=False
    Strng="Voting booth command(?=Help): "
    Call IO.I
    VarX=True
    Out3=Ucase$(Out2)
    Select Case Out3
    Case "C" ' comment
       Strng="Enter comment(79 char):"
       Call IO.O
       Line.Length=79
       Strng="?"
       Call IO.I
       Out2=Rtrim$(Out2)
       Comment$=Out2
       If Len(Comment$) Then
          Strng="User comment added."
          Call IO.O
          Voting.Comment=Comment$
          Voting.Deleted=0
          Voting.VoteFrom=UserRecord.Codename
          Voting.VoteTo=VoteFor$
          Voting.ThumbUp=0
          Voting.ThumbDown=0
          Voting.Stars=0
          Voting.Rating=0
          Voting.VoteAs=0
          Voting.DatePost=Date$
          Voting.TimePost=Time$
          Voting.PostLevel=UserRecord.Level
          VarC=0
          Gosub Write.Vote
       Endif
    Case "T" ' thumbs
       Strng="(U)p/(D)own? "
       Call IO.I
       If Ucase$(Out2)="U" Then
          Voting.Comment=Nul
          Voting.Deleted=0
          Voting.VoteFrom=UserRecord.Codename
          Voting.VoteTo=VoteFor$
          Voting.ThumbUp=1
          Voting.ThumbDown=0
          Voting.Stars=0
          Voting.Rating=0
          Voting.VoteAs=0
          Voting.DatePost=Date$
          Voting.TimePost=Time$
          Voting.PostLevel=UserRecord.Level
          Strng="User voted 1 thumbs up."
          Call IO.O
          VarC=0
          Gosub Write.Vote
       Endif
       If Ucase$(Out2)="D" Then
          Voting.Comment=Nul
          Voting.Deleted=0
          Voting.VoteFrom=UserRecord.Codename
          Voting.VoteTo=VoteFor$
          Voting.ThumbUp=0
          Voting.ThumbDown=1
          Voting.Stars=0
          Voting.Rating=0
          Voting.VoteAs=0
          Voting.DatePost=Date$
          Voting.TimePost=Time$
          Voting.PostLevel=UserRecord.Level
          Strng="User voted 1 thumbs down."
          Call IO.O
          VarC=0
          Gosub Write.Vote
       Endif
    Case "S" ' stars
       Strng="Stars(1-5)?"
       Call IO.I
       If Int(Val(Out2)+.5)>=1 And Int(Val(Out2)+.5)<=5 Then
          Voting.Comment=Nul
          Voting.Deleted=0
          Voting.VoteFrom=UserRecord.Codename
          Voting.VoteTo=VoteFor$
          Voting.ThumbUp=0
          Voting.ThumbDown=0
          Voting.Stars=Int(Val(Out2)+.5)
          Voting.Rating=0
          Voting.VoteAs=0
          Voting.DatePost=Date$
          Voting.TimePost=Time$
          Voting.PostLevel=UserRecord.Level
          Strng="User voted"+Str$(Int(Val(Out2)+.5))+" stars."
          Call IO.O
          VarC=0
          Gosub Write.Vote
       Endif
    Case "R" ' rating
       Strng="Rating(1-10)?"
       Call IO.I
       If Int(Val(Out2)+.5)>=1 And Int(Val(Out2)+.5)<=10 Then
          Voting.Comment=Nul
          Voting.Deleted=0
          Voting.VoteFrom=UserRecord.Codename
          Voting.VoteTo=VoteFor$
          Voting.ThumbUp=0
          Voting.ThumbDown=0
          Voting.Stars=0
          Voting.Rating=Int(Val(Out2)+.5)
          Voting.VoteAs=0
          Voting.DatePost=Date$
          Voting.TimePost=Time$
          Voting.PostLevel=UserRecord.Level
          Strng="User voted"+Str$(Int(Val(Out2)+.5))+" rating."
          Call IO.O
          VarC=0
          Gosub Write.Vote
       Endif
    Case "U"
       VarC=0
       Gosub Write.Vote
    Case "V"
       Strng="Total votes:"
       Strng=Strng+Str$(Lof(TempFile2)/VoteFileRecLen)+" records."
       Call IO.O
       TotalDeleted=0
       TotalDead=0
       For Var!=1! To Lof(TempFile2)/VoteFileRecLen
          Get #TempFile2,Var!,Voting
          If Voting.Deleted Then TotalDeleted=TotalDeleted+1
          If Voting.PostLevel=0 Then TotalDead=TotalDead+1
       Next
       If TotalDeleted>0 Then
          Strng="Total deleted:"+Str$(TotalDeleted)+"."
          Call IO.O
       Endif
       If TotalDead>0 Then
          Strng="Total dead:"+Str$(TotalDead)+"."
          Call IO.O
       Endif
       Strng="Record length:"
       Strng=Strng+Str$(VoteFileRecLen)+" bytes."
       Call IO.O
    Case "?" ' help
       Gosub Vote.Command.Help
    Case "Q" ' quit
       Exit Sub
    End Select
 Loop
 Exit Sub
 ' lock in vote.
Write.Vote:
 If TempD!>0! Then
    Strng="You are rewarded"+Str$(TempD!)+" Gold for voting!"
    Call IO.O
    UserRecord.Gold=UserRecord.Gold+TempD!
    Call Write.Record(UserFile,User.Index)
 Endif
 TempX!=Lof(TempFile2)/VoteFileRecLen+1!
Write.Vote2:
 Lock #TempFile2
 Put #TempFile2,TempX!,Voting
 Unlock #TempFile2
 Return
Error.Resume58x:
 Exit Sub
Error.Trap58x:
 If Err=70 Then ' share violation
    VarC=VarC+1
    If VarC<5 Then
       Sleep 1
       Resume Write.Vote2
    Endif
 Endif
 Strng="Voting file error."
 Call IO.O
 Resume Error.Resume58x
Vote.Command.Help:
 Graphics.Off=False
 Strng="Vote functions:"
 Call IO.O
 Graphics.Off=True
 Strng="[C]omment"
 Call IO.O
 Strng="[T]humbs"
 Call IO.O
 Strng="[S]tars"
 Call IO.O
 Strng="[R]ating"
 Call IO.O
 Strng="[U]pdate vote"
 Call IO.O
 Strng="[V]ote totals"
 Call IO.O
 Return
End Sub

Sub Vote.Booth
 On Local Error Goto Error.Trap35x
 If (UserRecord.Flags2 And 2) = 2 Then
    UserRecord.Flags2=(UserRecord.Flags2 And Not 2)
    Strng="Voting booth unlocked."
    Call IO.O
 Else
    UserRecord.Flags2=(UserRecord.Flags2 Or 2)
    Strng="Voting booth locked."
    Call IO.O
 Endif
 Call Write.Record(UserFile,User.Index)
Error.Resume35x:
 Exit Sub
Error.Trap35x:
 Resume Error.Resume35x
End Sub

Sub Vote.Status.Line
 On Local Error Goto Error.Trap35
 Temp$=UserRecord.CodeName
 Temp$=Rtrim$(Temp$)
 Temp$=Lcase$(Temp$)
 Mid$(Temp$,1,1)=Ucase$(Mid$(Temp$,1,1))
 Temp$=Temp$+" <timeon: "+Fclock$+"> "
 If (UserRecord.Flags2 And 2) = 2 Then
    Temp$=Temp$+"Voting Booth locked"
 Else
    Temp$=Temp$+"Voting Booth unlocked"
 Endif
 Call Suffix(UserRecord.Gold,VarX$)
 Temp$=Temp$+" Gold: "+Ltrim$(VarX$)
 Temp$=Left$(Temp$,79)
 Temp$=Temp$+Space$(79-Len(Temp$))
 Call Display.Status.Line(True)
Error.Resume35:
 Exit Sub
Error.Trap35:
 Resume Error.Resume35
End Sub

' calculate byte suffix
SUB Suffix(Var#, Var3$)

 REM B  (Byte) = 00x - 0FFx (hexidecimal zero-based) 
 REM KB (Kilobyte) = 1024 B
 REM MB (Megabyte) = 1024 KB (1 MB B) 
 REM GB (Gigabyte) = 1024 MB
 REM TB (Terabyte) = 1024 GB (1 MB MB) 
 REM PB (Petabyte) = 1024 TB
 REM EB (Exabyte) = 1024 PB (1 MB TB) 
 REM ZB (Zettabyte) = 1024 EB
 REM YB (Yottabyte) = 1024 ZB (1 MB EB) 

 ' store double
 VarX# = Var#

 ' calculate bytes
 TempA = False
 DO
    IF VarX# >= 1024 THEN
       VarX# = VarX# / 1024
       TempA = TempA + 1
       IF TempA = 8 THEN
	  EXIT DO
       END IF
    ELSE
       EXIT DO
    END IF
 LOOP

 ' calculate byte string
 Var3$ = FORMAT$(VarX#, "#,##0.0;;")
 If Instr(Var3$,",") Then
    Var3$=Left$(Var3$,Instr(Var3$,",")-1)
    Var3$=Var3$+".0"
 Endif

 ' calculate byte suffix
 Var$ = Nul
 IF TempA > 0 THEN
    Var$ = MID$("KMGTPEZY", TempA, 1)
 END IF
 Var3$ = Var3$ + " " + Var$ + "B"
END SUB

Sub Amount2(Var#,Var$)
 VarX$=Ltrim$(Str$(Var#)) ' 1.111D308
 V=Instr(VarX$,"D")
 If V Then
    If Mid$(VarX$,2,1)="." Then
       VarX$=Left$(VarX$,1)+Mid$(VarX$,V)
    Endif
    Var$=" "+VarX$
 Else
    Var$=" "+Form$(Var#)
 Endif
End Sub

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Sub Back.Space2(Var)
 On Local Error Goto Error.Trap27z
 If Local.Mode=False Then
    If Remote.ANSI.Color Or Remote.Avatar.Color Then
       For Var2=1 To Var
          Var$=Chr$(27)+"[D"
          Call Put.Modem(Var$)
       Next
    Else
       For Var2=1 To Var
          Var$=Chr$(8)
          Call Put.Modem(Var$)
       Next
    Endif
 Endif
 If Local.ANSI.Color Or Local.Avatar.Color Then
    For Var2=1 To Var
       Var$=Chr$(27)+"[D"
       Call Put.Screen(Var$)
    Next
 Else
    For Var2=1 To Var
       Locate Csrlin,Pos(0)-1,1
    Next
 Endif
Error.Resume27z:
 Exit Sub
Error.Trap27z:
 Resume Error.Resume27z
End Sub

' function to match case-sensitive substring with ?, * characters in substring
'  see if Var$ matches in Strng.
SUB InstrSUB1(Var,Var$,VarQ)

' see if Var$ matches in Strng
On Local Error Goto ErrorTrap24x5

' store case-sensitive string match variables
If VarQ Then
   S2$ = Var$
   S3$ = Strng
Else
   S2$ = Lcase$(Var$)
   S3$ = Lcase$(Strng)
Endif

' check default instr
IF INSTR(S2$, "*") = 0 THEN
   IF INSTR(S2$, "?") = 0 THEN
      Var = INSTR(S3$, S2$)
      EXIT SUB
   END IF
END IF

Var = -1 ' assume match

' see if S2$ matches in S3$ with substrings
FOR S3 = 1 TO LEN(S3$)
   S1$ = MID$(S3$, S3)
   P1 = 1 ' pointer to S1$
   P2 = 1 ' pointer to S2$
   P3 = S3 ' position match
   DO
      ' check match
      IF P2 > LEN(S2$) THEN
         Var = P3
         EXIT SUB
      END IF

      ' check character in S2$ at P2
      V$ = MID$(S2$, P2, 1)
      SELECT CASE V$
      CASE "*" ' global character
         ' scan to next char
         IF P2 > LEN(S2$) THEN
            EXIT DO
         END IF
         S4$ = MID$(S2$, P2 + 1, 1)
         SELECT CASE S4$
         CASE "*", "?"
            P2 = P2 + 1
         CASE ELSE
            DO
               IF MID$(S1$, P1, 1) = S4$ THEN
                  EXIT DO
               END IF
               IF P1 >= LEN(S1$) THEN
                  EXIT DO
               END IF
               P1 = P1 + 1
            LOOP
            P3 = P1
            P2 = P2 + 1
         END SELECT
      CASE "?" ' wildcard character
         P1 = P1 + 1
         P2 = P2 + 1
      CASE ELSE ' ascii character
         IF MID$(S1$, P1, 1) <> V$ THEN ' no match
            EXIT DO
         END IF
         P1 = P1 + 1
         P2 = P2 + 1
      END SELECT
   LOOP
NEXT
Var = 0 ' no match
EXIT SUB
ErrorResume24x5:
 Exit Sub
ErrorTrap24x5:
 Resume ErrorResume24x5
End Sub

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