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

Sub Node.Commands
 On Local Error Goto Error.Trap79
 Var=TempX

 ' check low psi for /send and /sendto
 If Var=9 Or Var=11 Then
    Call Check.Psi(VarX)
    If VarX=False Then
       Last.Command="<low psi>"
       Call Update.Mess(4)
       Exit Sub
    Endif
 Endif

 Select Case Var
 Case 2 ' /block
    Call Block
 Case 3 ' /brief
    Brief.Messages = NOT Brief.Messages
    If Brief.Messages Then
       Strng="Brief messaging on."
    Else
       Strng="Brief messaging off."
    Endif
    Call IO.O
 Case 5 ' /echo
    Call Flag.Toggles(2)
 Case 6 ' /group
    Call Group.Send
 Case 7 ' /nosend
    Call No.Send
 Case 8 ' /say
    If Parser=False Then
       Strng="Say what? "
       Call IO.I
       If Out2=Nul Then
          Strng="Nothing to say.."
          Call IO.O
          Exit Sub
       Endif
       Stored.Parsed.Command1=Out2
    Endif
    Call Send.Mess(3,SFalse,Room,Stored.Parsed.Command1)
 Case 9 ' /send
    If Parser=False Then
       Strng="Send what? "
       Call IO.I
       If Out2=Nul Then
          Strng="Nothing to send.."
          Call IO.O
          Exit Sub
       Endif
       Stored.Parsed.Command1=Out2
    Endif
    Call Send.Mess(1,SFalse,SFalse,Stored.Parsed.Command1)
 Case 10 ' /status
    Call Read.Status
 Case 11 ' /sendto
    Call Send.Message
 Case 12 ' /quit
    Strng="You are not in chat mode."
    Call IO.O
 Case 13 ' /whisper
    Call Whisper
 Case 15 ' /who
    Call Whos.On
 Case 16 ' /yell
    If Parser=False Then
       Strng="Yell what? "
       Call IO.I
       If Out2=Nul Then
          Strng="Nothing to yell.."
          Call IO.O
          Exit Sub
       Endif
       Stored.Parsed.Command1=Out2
    Endif
    Call Send.Mess(2,SFalse,-1!,Stored.Parsed.Command1)
 Case 17 ' !Broadcast
    Strng="Enter text: "
    Line.Length=80
    Call IO.I
    If Len(Out2) Then
       Out2=Mask$+Mask$+Mask$+" "+Out2
       Call Send.Mess(5,SFalse,SFalse,Out2)
       If Echo=False Then
          Strng="Broadcast sent."
          Call IO.O
       Endif
    Else
       Strng="Nothing to send."
       Call IO.O
    Endif
 Case 18 ' !Noid
    Strng="Enter no-id text: "
    Line.Length=80
    Call IO.I
    If Len(Out2) Then
       Call Send.Mess(5,SFalse,SFalse,Out2)
       If Echo=False Then
          Strng="Noid sent."
          Call IO.O
       Endif
    Else
       Strng="Nothing to send."
       Call IO.O
    Endif
 End Select
Error.Resume79:
 Exit Sub
Error.Trap79:
 Resume Error.Resume79
End Sub

Sub Group.Send
 On Local Error Goto Err.Trp16
 Graphics.Off=False
 Strng="Enter grouped message. 9 lines max."
 Call IO.O
 Strng="Press "+Enter$+" on a blank line to send."
 Call IO.O
 Graphics.Off=True
 TempZ=False
 Redim Temp.ArrayS(1 To 9) As String
 For TempX=1 To 9
    Line.Length=79
    Strng="?"
    Call IO.I
    If Lost.Carrier Then
       Exit Sub
    Endif
    If Out2=Nul Then
       Exit For
    Endif
    TempZ=TempZ+1
    Temp.ArrayS(TempZ)=Out2
 Next
 If TempZ Then
    Do
       TempA$=Str$(Timer)
       ' find group message with same time
       VarX=False
       For Var!=1! To Lof(MessWorkFile2)/MessWorkRecLen2
          Call Read.Record(MessWorkFile2,Var!)
          If MessWorkRecord2.MessageType=25 Then
             TempQ$=MessWorkRecord2.Message2
             TempQ$=Mid$(TempQ$,3)
             TempQ$=Rtrim$(TempQ$)
             If TempA$=TempQ$ Then
                VarX=True
                Exit For
             Endif
          Endif
       Next
       If VarX=False Then Exit Do
    Loop
    ' send group message
    For TempX=1 To TempZ
       VarZ$=Temp.ArrayS(TempX)
       Call Send.Mess(25,SFalse,Room,VarZ$)
    Next
 Endif
 Graphics.Off=False
 If TempZ Then
    Strng="Grouped message sent."
 Else
    Strng="No grouped message sent."
 Endif
 Call IO.O
 Erase Temp.ArrayS
Err.Rsm16:
 Exit Sub
Err.Trp16:
 Resume Err.Rsm16
End Sub

Sub Block
 On Local Error Goto Err.Trp14
 If Lcase$(Parsed.Command1)="self" Then
    Var=Not UserRecord.Block1
    UserRecord.Block1=Var
    If Var Then
       Strng="User block on."
    Else
       Strng="User block off."
    Endif
    Call IO.O
    Exit Sub
 Endif
 Call Get.Node(Var!)
 If Var!=SFalse Then
    Strng="That player is not online!"
    Call IO.O
    Exit Sub
 Endif
 TempC=Temp
 If TempC=Node Then
    Strng="Can't block yourself!"
    Call IO.O
    Exit Sub
 Endif
 Out2=Lcase$(Strng)
 Mid$(Out2,1,1)=Ucase$(Mid$(Out2,1,1))
 VarX2=Node+1
 Call Read.Message.Record(MessWorkFile1,VarX2)
 TempA=Val(Mid$(MessWorkRecord1.ReceiveFlags,TempC+1,1))
 If TempA=False Then
    TempA=1
    Strng="No longer blocking "+Out2+"."
 Else
    TempA=False
    Strng="Now blocking "+Out2+"."
 Endif
 Call IO.O
 Mid$(MessWorkRecord1.ReceiveFlags,TempC+1,1)=Ltrim$(Str$(TempA))
 VarX2=Node+1
 Call Write.Message.Record(MessWorkFile1,VarX2)
Err.Rsm14:
 Exit Sub
Err.Trp14:
 Resume Err.Rsm14
End Sub

Sub No.Send
 On Local Error Goto Err.Trp15
 If Lcase$(Parsed.Command1)="self" Then
    Var=Not UserRecord.Block2
    UserRecord.Block2=Var
    If Var Then
       Strng="User nosend on."
    Else
       Strng="User nosend off."
    Endif
    Call IO.O
    Exit Sub
 Endif
 Call Get.Node(Var!)
 If Var!=SFalse Then
    Strng="That player is not online!"
    Call IO.O
    Exit Sub
 Endif
 TempC=Temp
 If TempC=Node Then
    Strng="Can't nosend yourself!"
    Call IO.O
    Exit Sub
 Endif
 Out2=Lcase$(Strng)
 Mid$(Out2,1,1)=Ucase$(Mid$(Out2,1,1))
 VarX2=Node+1
 Call Read.Message.Record(MessWorkFile1,VarX2)
 TempA=Val(Mid$(MessWorkRecord1.SendFlags,TempC+1,1))
 If TempA=False Then
    TempA=1
    Strng="Now sending to "+Out2+"."
 Else
    TempA=False
    Strng="No longer sending to "+Out2+"."
 Endif
 Call IO.O
 Mid$(MessWorkRecord1.SendFlags,TempC+1,1)=Ltrim$(Str$(TempA))
 VarX2=Node+1
 Call Write.Message.Record(MessWorkFile1,VarX2)
Err.Rsm15:
 Exit Sub
Err.Trp15:
 Resume Err.Rsm15
End Sub

Sub Read.Status
 On Local Error Goto ErrTrap8
 If Parser Then
    If Lcase$(Parsed.Command1)="self" Then
       TempC=Node
       Gosub Read.Status.Header
       Gosub Read.User.Status
       Exit Sub
    Endif
    Call Get.Node(Var!)
    If Var!=SFalse Then
       Strng="That player is not online!"
       Call IO.O
    Else
       TempC=Temp
       Gosub Read.Status.Header
       Gosub Read.User.Status
    Endif
    Exit Sub
 Endif
 Gosub Read.Status.Header
 If Rtrim$(NodeX)=Nul Then
    Temp5=Temp5+1
    TempC=False
    Strng=UserRecord.CodeName
    Call Make.Mess.Work1
    Gosub Read.User.Status
 Endif
 For TempC=1 To MaxNodes
    Call Read.Message.Record(MessWorkFile1,TempC+1)
    Strng=Rtrim$(MessWorkRecord1.Username)
    Call Valid.Name(Strng)
    If TempA Then
       Gosub Read.User.Status
       Temp5=Temp5+1
       If Temp5>=User.Pagelength-2 Then
          If Continuous=False Then
             Call More.Prompt
             Temp5=False
             If No Or Quit Then
                Exit For
             Endif
             Gosub Read.Status.Header
          Endif
       Endif
    Endif
 Next
 If Temp5 Then
    Call More.Prompt
 Endif
 Exit Sub

Read.Status.Header:
 Temp5=4
 Graphics.Off=True
 Strng="DNDBBS v"+Version$+" Status Report For "+Left$(Fclock$,15)+"."
 Call IO.O
 Strng=Nul
 Call IO.O
 Select Case Temp0
 Case 3
    Strng="Port Y  H  Username                       Timeon   Last Command"
    Call IO.O
    Call Display.Line(63)
 Case 2
    Strng="Port Y  H  Username                       Timeon   Level"
    Call IO.O
    Call Display.Line(58)
 Case Else
    Strng="Port Y  H  Username                       Timeon"
    Call IO.O
    Call Display.Line(50)
 End Select
 Return

Read.User.Status:
 Select Case TempC
 Case 0
    Strng="P##"
 Case 1 To 10 ' 0-9
    Strng="P#"+Mid$(Str$(TempC-1),2)
 Case 11 To 36 ' A-Z
    Strng="P#"+Chr$(TempC+54)
 Case 37 To 126 ' 10-99
    Strng="P#"+Mid$(Str$(TempC-27),2)
 End Select
 Strng=Strng+Space$(5-Len(Strng))
 If TempC=Node Then
    Strng=Strng+"-- -- "
 Else
    VarX2=Node+1
    Call Read.Message.Record(MessWorkFile1,VarX2)
    Var1$=MessWorkRecord1.SendFlags
    Var2$=MessWorkRecord1.ReceiveFlags
    If Mid$(Var1$,TempC+1,1)="1" Then
       Strng=Strng+"S"
    Else
       Strng=Strng+" "
    Endif
    If Mid$(Var2$,TempC+1,1)="1" Then
       Strng=Strng+"R"
    Else
       Strng=Strng+" "
    Endif
    Strng=Strng+" "
    Call Read.Message.Record(MessWorkFile1,TempC+1)
    Var1$=MessWorkRecord1.SendFlags
    Var2$=MessWorkRecord1.ReceiveFlags
    If Mid$(MessWorkRecord1.SendFlags,Node+1,1)="1" Then
       Strng=Strng+"S"
    Else
       Strng=Strng+" "
    Endif
    If Mid$(MessWorkRecord1.ReceiveFlags,Node+1,1)="1" Then
       Strng=Strng+"R"
    Else
       Strng=Strng+" "
    Endif
    Strng=Strng+" "
 Endif
 Out3=Nul
 Out2=Lcase$(MessWorkRecord1.UserName)
 Mid$(Out2,1,1)=Ucase$(Mid$(Out2,1,1))
 If Temp0=2 Then
    Out3=Ltrim$(Str$(MessWorkRecord1.Level))
 Else
    If Temp0=3 Then
       Out3=MessWorkRecord1.LastCommand
       Select Case Left$(Out3,1)
       Case "a" To "z", "A" To "Z"
          Out3=Lcase$(Out3)
          Mid$(Out3,1,1)=Ucase$(Mid$(Out3,1,1))
       End Select
    Endif
 Endif
 Strng=Strng+Out2+" "+MessWorkRecord1.TimeOn+" "+Out3
 Call IO.O
 Return
ErrResume8:
 Exit Sub
ErrTrap8:
 Resume ErrResume8
End Sub

Sub Whos.On
 On Local Error Goto ErrorTrap19
 If Parser Then
    If Lcase$(Parsed.Command1)="self" Then
       TempC=Node
       Gosub Read.Who.Header
       Gosub Read.Who.Status
       Exit Sub
    Endif
    Call Get.Node(Var!)
    If Var!=SFalse Then
       Strng="That player is not online!"
       Call IO.O
    Else
       TempC=Temp
       Gosub Read.Who.Header
       Gosub Read.Who.Status
    Endif
    Exit Sub
 Endif
 Gosub Read.Who.Header
 If Rtrim$(NodeX)=Nul Then
    Temp5=Temp5+1
    TempC=False
    Strng=UserRecord.CodeName
    Call Make.Mess.Work1
    Gosub Read.Who.Status
 Endif
 For TempC=1 To MaxNodes
    Call Read.Message.Record(MessWorkFile1,TempC+1)
    Strng=Rtrim$(MessWorkRecord1.Username)
    Call Valid.Name(Strng)
    If TempA Then
       Gosub Read.Who.Status
       Temp5=Temp5+1
       If Temp5>=User.Pagelength-2 Then
          If Continuous=False Then
             Call More.Prompt
             Temp5=False
             If No Or Quit Then
                Exit FOr
             Endif
             Gosub Read.Who.Header
          Endif
       Endif
    Endif
 Next
 If Temp5 Then
    Call More.Prompt
 Endif
 Exit Sub

Read.Who.Header:
 Temp5=4
 Graphics.Off=True
 Strng="DNDBBS v"+Version$+" Who Status Report For "+Left$(Fclock$,15)+"."
 Call IO.O
 Strng=Nul
 Call IO.O
 If Temp0=2 Then
    Strng="Port Username                       Timeon   Room     Classname"
 Else
    Strng="Port Username                       Timeon   Room     Score"
 Endif
 Call IO.O
 Call Display.Line(71)
 Return

Read.Who.Status:
 Select Case TempC
 Case 0
    Strng="P##"
 Case 1 To 10 ' 0-9
    Strng="P#"+Mid$(Str$(TempC-1),2)
 Case 11 To 36 ' A-Z
    Strng="P#"+Chr$(TempC+54)
 Case 37 To 126 ' 10-99
    Strng="P#"+Mid$(Str$(TempC-27),2)
 End Select
 Strng=Strng+Space$(5-Len(Strng))
 Out2=Lcase$(MessWorkRecord1.UserName)
 Mid$(Out2,1,1)=Ucase$(Mid$(Out2,1,1))
 Out3=Mid$(Str$(MessWorkRecord1.RoomNumber),2)
 Out3=Out3+Space$(8-Len(Out3))
 If Temp0=2 Then
    Out4=Rtrim$(MessWorkRecord1.Classname)
 Else
    VarX#=MessWorkRecord1.Score3*MessWorkRecord1.Level*10+ _
    MessWorkRecord1.Score1*MessWorkRecord1.Level*2+ _
    MessWorkRecord1.Score2*MessWorkRecord1.Level
    Out4=Mid$(Str$(VarX#),2)
 Endif
 Strng=Strng+Out2+" "+MessWorkRecord1.TimeOn+" "+Out3+" "+Out4
 Call IO.O
 Return
ErrorResume19:
 Exit Sub
ErrorTrap19:
 Resume ErrorResume19
End Sub

Sub Whisper
 On Local Error Goto Err.Trp12
 If Parser=False Then
    Strng="Whisper to whom? "
    Call IO.I
    If Out2=Nul Then
       Strng="Nothing to whisper.."
       Call IO.O
       Exit Sub
    Endif
    Parsed.Command1=Out2
 Endif
 Call Search.Mess(SFalse)
 If Temp!<>Room Then
    Strng="That player is not in this room!"
    Call IO.O
    Exit Sub
 Endif
 If TempC=Node Then
    Strng="Can't whisper to yourself!"
    Call IO.O
    Exit Sub
 Endif
 Strng="Whisper what? "
 Call IO.I
 If Len(Out2) Then
    Call Send.Mess(7,TempB!,Room,Out2)
 Endif
Err.Rsm12:
 Exit Sub
Err.Trp12:
 Resume Err.Rsm12
End Sub

Sub Send.Message
 On Local Error Goto Err.Trp13
 If Parser=False Then
    Strng="Send to whom? "
    Call IO.I
    If Out2=Nul Then
       Exit Sub
    Endif
    Parsed.Command1=Out2
 Endif
 Call Get.Node(Var!)
 If Var!=SFalse Then
    Strng="That player is not online!"
    Call IO.O
    Exit Sub
 Endif
 TempC=Temp
 If TempC=Node Then
    Strng="Can't send to yourself!"
    Call IO.O
    Exit Sub
 Endif
 Strng="Send what? "
 Call IO.I
 If Len(Out2) Then
    Call Send.Mess(6,TempB!,SFalse,Out2)
 Endif
Err.Rsm13:
 Exit Sub
Err.Trp13:
 Resume Err.Rsm13
End Sub

Sub Get.Node(Var!)
 On Local Error Goto ErrorTrap1
 Temp=False
 Var!=SFalse
 Var$=Rtrim$(Ltrim$(Parsed.Command1))
 Select Case Len(Var$)
 Case 1
    Select Case Ucase$(Var$)
    Case "0" To "9" ' 1-10
       Temp=Val(Parsed.Command1)+1
    Case "A" To "Z" ' 11-36
       Temp=Asc(Ucase$(Var$))-54
    End Select
 Case 2
    VarX=Int(Val(Var$)+.5)
    If VarX>=10 And VarX<=99 Then
       Temp=VarX+27 ' 37-126
    Endif
 End Select
 If Temp Then
    Call Read.Message.Record(MessWorkFile1,Temp+1)
    Strng=Rtrim$(MessWorkRecord1.UserName)
    Call Valid.Name(Strng)
    If TempA Then
       Var!=MessWorkRecord1.UserIndex
       Exit Sub
    Endif
 Endif
 Call Search.Mess(SFalse)
 If Temp! Then
    Temp=TempC
    Var!=MessWorkRecord1.UserIndex
 Endif
ErrorResume1:
 Exit Sub
ErrorTrap1:
 Resume ErrorResume1
End Sub

Sub Check.Psi(VarX)
 On Local Error Goto Error.Trap32a
 Gosub Get.Config3
 VarX=True
 If Normal.User Then
    If UserRecord.Psionic<Option3 Then
       VarX=False
       Strng="Psi is to low."
       Call IO.O
       Exit Sub
    Endif
    If Option4>0 Then
       If UserRecord.Psionic-Option4<0 Then
          Strng="You don't have enough psionic points!"
          Call IO.O
          VarX=False
          Exit Sub
       Endif
       UserRecord.Psionic=UserRecord.Psionic-Option4
       If UserRecord.Psionic<0 Then
          UserRecord.Psionic=0
       Endif
    Endif
 Endif
 Exit Sub
Get.Config3:
 VarX=0
 Option3=1
 Option4=1
 Do
    VarX=VarX+1
    If VarX>Options.Lines Then
       Goto Next.Read
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
    If Ucase$(Var$)="[CMD153]" 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
             Var4$=Ltrim$(Rtrim$(Left$(Var$,Var-1)))
             Var5$=Ltrim$(Rtrim$(Mid$(Var$,Var+1)))
             Gosub Parse.Options
          Endif
       Loop
    Endif
 Loop
 Return
Next.Read:
 Close #TempFile1
 Filename$=DND.Path+"CMD153.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
          Option3=1
          Option4=1
          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
                Var4$=Ltrim$(Rtrim$(Left$(Var$,Var-1)))
                Var5$=Ltrim$(Rtrim$(Mid$(Var$,Var+1)))
                Gosub Parse.Options
             Endif
          Loop
       Endif
    Endif
 Loop
 Return
Parse.Options:
 Select Case Lcase$(Var4$)
 Case "psi.value"
    If Int(Val(Var5$)+.5)>=1 And Int(Val(Var5$)+.5)<=600 Then
       Option3=Int(Val(Var5$)+.5)
    Endif
 Case "decrease.psi.value"
    If Int(Val(Var5$)+.5)>=0 And Int(Val(Var5$)+.5)<=100 Then
       Option4=Int(Val(Var5$)+.5)
    Endif
 End Select
 Return
Error.Resume32a:
 Exit Sub
Error.Trap32a:
 Resume Error.Resume32a
End Sub
