Rem File: Dndcnfg5 for Dndbbs Version v5.0a Release r2.0 Tweak t5.0a

Defint A-Z
Rem $Dynamic

Common Node.List1() As String
Common Node.List2() As String

On Error Goto Error.Routine

Dim File.Byte As String*1

Gosub Passwrd11

If Var=0 Then
   Color 7,0
   End
Endif

Color 15, 0
Print "Dndcnfg2 config replication utility v5.0a"
COlor 14,0
Print "Enter config replicate choice:"
Print "1)Guest config file"
Print "2)Start config file"
Print "3)Option config file"
Print "4)DND config file"
Color 15,0
Print "Enter choice(1-4), Q to quit: ";
Do
   Locate ,,1
   X$=Inkey$
   X$=Ucase$(X$)
   Select Case X$
   Case "1" To "4"
      Print X$
      X=Int(Val(X$)+.5)
      Exit Do
   Case "Q"
      Print X$
      Color 7,0
      Print "Exiting config utility"
      End
   End Select
Loop
Color 15,0
Print "Enter source config template node(0-9,A-Z,10-99,<enter> for none)? ";
Do
   Z$=""
   Do
      X$=Inkey$
      Locate ,,1
      If Len(X$)=1 Then
         If X$=Chr$(13) Then
            Exit Do
         Endif
         If X$=Chr$(8) Then
            If Len(Z$) Then
               Print Chr$(29);" ";Chr$(29);
               Z$=Left$(Z$,Len(Z$)-1)
            Endif
         Else
            Z$=Z$+X$
            Print X$;
         Endif
      Endif
   Loop
   Print
   Z$=Ucase$(Z$)
   Select Case Len(Z$)
   Case 0
      Exit Do
   Case 1
      Select Case Z$
      Case "0" To "9"
         Exit Do
      Case "A" To "Z"
         Exit Do
      Case Else
         Color 12,0
         Print "Invalid node."
         Color 15,0
      End Select
   Case 2
      Select Case Int(Val(Z$)+.5)
      Case 10 To 99
         Exit Do
      Case Else
         Color 12,0
         Print "Invalid node.
         Color 15,0
      End Select
   Case Else
      Color 12,0
      Print "Invalid node."
      Color 15,0
   End Select
Loop
Redim Node.List1(0 To 99) As String
Redim Node.List2(1 To 26) As String
Select Case X
Case 1
   Source.Filename$="GUEST"+Z$+".CFG"
Case 2
   Source.Filename$="START"+Z$+".CFG"
Case 3
   Source.Filename$="OPTION"+Z$+".CFG"
Case 4
   Source.Filename$="DND"+Z$+".CFG"
   Close #1
   Node.Filename$="ports.dat"
   If Dir$(Node.Filename$)="" Then
      Print "Ports.dat file not found. Continue anyway(y/n)? ";
      Do
         Locate ,,1
         A$=Inkey$
         A$=Ucase$(A$)
         If Len(A$) Then
            If A$="N" Then
               Print A$
               Print "Use 'Dndutil /w4' to create ports.dat file."
               Color 7,0
               End
            Endif
            If A$="Y" Then
               Print A$
               Exit Do
            Endif
         Endif
      Loop
   Endif
   If Dir$(Node.Filename$)<>"" Then
      Open Node.Filename$ For Input As #1
      Do
         If Eof(1) Then
            Exit Do
         Endif
         Line Input #1,A$
         A$=Rtrim$(A$)
         A$=Ltrim$(A$)
         A2$=Ucase$(A$)
         If Len(A$) Then
            If Left$(A$,1)=";" Then
               Q$ = ""
            Else
               V=Instr(A$,",")
               If V Then
                  A$=Left$(A$,V-1)
               Endif
               A$=Ucase$(A$)
               Select Case Len(A$)
               Case 1
                  Select Case A$
                  Case "0" To "9"
                     V=Int(Val(A$)+.5)
                     Node.List1(V)=A2$
                  Case "A" To "Z"
                     V=Asc(A$)-64
                     Node.List2(V)=A2$
                  End Select   
               Case 2
                  V=Int(Val(A$)+.5)
                  If V>=10 And V<=99 Then
                     Node.List1(V)=A2$
                  Endif
               End Select
            Endif
         Endif
      Loop
   Endif
End Select
Close #1
If Dir$(Source.Filename$)="" Then
   Print "Source file: "+Source.Filename$+" not found."
   Color 7,0
   End
Endif
Open Source.Filename$ For Input As #1
Close #2
Temp.Filename$="DNDCNFG2.DAT"
Open Temp.Filename$ For Output As #2
Do
   If Eof(1) Then
      Exit Do
   Endif
   Line Input #1,A$
   Print #2,A$
Loop
Close #1
Close #2
Start.Node:
Color 15,0
Print "Enter target config nodes(delimiter separated - and , specs)"
Print "Example: 1-4,A,B,10-13, or press <enter> to quit: ";
Do
   B$=""
   Do
      X$=Inkey$
      Locate ,,1
      If Len(X$)=1 Then
         If X$=Chr$(13) Then
            Exit Do
         Endif
         If X$=Chr$(8) Then
            If Len(B$) Then
               Print Chr$(29);" ";Chr$(29);
               B$=Left$(B$,Len(B$)-1)
            Endif
         Else
            B$=B$+X$
            Print X$;
         Endif
      Endif
   Loop
   Print
   B$=Ucase$(B$)
   If Len(B$)=0 Then
      Color 7,0
      Print "Exiting utility."
      End
   Endif
   Exit Do
Loop
Do
   V=Instr(B$," ")
   If V Then
      B$=Left$(B$,V-1)+Mid$(B$,V+1)
   Else
      Exit Do
   Endif
Loop
C$=B$
Do
   If C$="" Then
      Exit Do
   Endif
   V=Instr(C$,",")
   If V Then
      D$=Left$(C$,V-1)
      C$=Mid$(C$,V+1)
   Else
      D$=C$
      C$=""
   Endif
   V=Instr(D$,"-")
   If V Then
      E$=Left$(D$,V-1)
      F$=Mid$(D$,V+1)
   Else
      E$=D$
      F$=""
   Endif
   Select Case Len(E$)
   Case 0
      Color 12,0
      Print "Invalid node.
      Color 15,0
      Goto Start.Node
   Case 1
      Select Case E$
      Case "0" To "9"
         Q$ = ""
      Case "A" To "Z"
         Q$ = ""
      Case Else
         Color 12,0
         Print "Invalid node.
         Color 15,0
         Goto Start.Node
      End Select
   Case 2
      Select Case Int(Val(E$)+.5)
      Case 10 To 99
         Q$ = ""
      Case Else
         Color 12,0
         Print "Invalid node.
         Color 15,0
         Goto Start.Node
      End Select
   Case Else
      Color 12,0
      Print "Invalid node.
      Color 15,0
      Goto Start.Node
   End Select
   If Len(F$) Then
      Select Case Len(F$)
      Case 0
         Color 12,0
         Print "Invalid node.
         Color 15,0
         Goto Start.Node
      Case 1
         Select Case F$
         Case "0" To "9"
            Q$ = ""
         Case "A" To "Z"
            Q$ = ""
         Case Else
            Color 12,0
            Print "Invalid node.
            Color 15,0
            Goto Start.Node
         End Select
      Case 2
         Select Case Int(Val(F$)+.5)
         Case 10 To 99
            Q$ = ""
         Case Else
            Color 12,0
            Print "Invalid node.
            Color 15,0
            Goto Start.Node
         End Select
      Case Else
         Color 12,0
         Print "Invalid node.
         Color 15,0
         Goto Start.Node
      End Select
      Select Case Len(E$)
      Case 1
         If E$<F$ Then
            Q$ = ""
         Else
            Color 12,0
            Print "Invalid node.
            Color 15,0
            Goto Start.Node
         Endif
      Case 2
         If Int(Val(E$)+.5)<Int(Val(F$)+.5) Then
            Q$ = ""
         Else
            Color 12,0
            Print "Invalid node.
            Color 15,0
            Goto Start.Node
         Endif
      End Select
   Endif
Loop
Print "Press any key to write files, or 'Q' to quit: ";
Do
   Locate ,,1
   A$=Inkey$
   A$=Ucase$(A$)
   If Len(A$) Then
      If A$="Q" Then
         Print A$
         Color 7,0
         End
      Else
         Print
         Exit Do
      Endif
   Endif
Loop
C$=B$
Do
   If C$="" Then
      Exit Do
   Endif
   V=Instr(C$,",")
   If V Then
      D$=Left$(C$,V-1)
      C$=Mid$(C$,V+1)
   Else
      D$=C$
      C$=""
   Endif
   V=Instr(D$,"-")
   If V Then
      E$=Left$(D$,V-1)
      F$=Mid$(D$,V+1)
   Else
      E$=D$
      F$=""
   Endif
   If Len(F$)=0 Then
      Select Case X
      Case 1
         Target.Filename$="GUEST"+E$+".CFG"
      Case 2
         Target.Filename$="START"+E$+".CFG"
      Case 3
         Target.Filename$="OPTION"+E$+".CFG"
      Case 4
         Target.Filename$="DND"+E$+".CFG"
         A3$=""
         Select Case Len(E$)
         Case 1
            Select Case E$
            Case "0" To "9"
               A3$=Node.List1(Int(Val(E$)+.5))
               Gosub Read.Node
            Case "A" To "Z"
               A3$=Node.List2(Asc(E$)-64)
               Gosub Read.Node
            End Select
         Case 2
            N=Int(Val(E$)+.5)
            If N>=10 And N<=99 Then
               A3$=Node.List1(N)
            Endif
            Gosub Read.Node
         End Select
      End Select
      Close #1
      Open Temp.Filename$ For Input As #1
      Close #2
      Open Target.Filename$ For Output As #2
      C1=0
      Do
         If Eof(1) Then
            Exit Do
         Endif
         Line Input #1,A$
         C1=C1+1
         If X=4 Then
            If C1=87 Then
               A$=Mid$(Str$(Port),2)
            Endif
            If C1=155 Then
               A$=Mid$(Str$(Base.Address),2)
            Endif
            If C1=274 Then ' door.node
               A$=E$
            Endif
         Endif
         Print #2,A$
      Loop
   Else
      ' E$ to F$
      If E$>="A" And E$<="Z" Then
         X1=Asc(E$)
         X2=Asc(F$)
         For Z=X1 To X2
            Select Case X
            Case 1
               Target.Filename$="GUEST"+Chr$(Z)+".CFG"
            Case 2
               Target.Filename$="START"+Chr$(Z)+".CFG"
            Case 3
               Target.Filename$="OPTION"+Chr$(Z)+".CFG"
            Case 4
               Target.Filename$="DND"+Chr$(Z)+".CFG"
               A3$=Node.List2(Z-64)
               Gosub Read.Node
            End Select
            Close #1
            Open Temp.Filename$ For Input As #1
            Close #2
            Open Target.Filename$ For Output As #2
            C1=0
            Do
               If Eof(1) Then
                  Exit Do
               Endif
               Line Input #1,A$
               C1=C1+1
               If X=4 Then
                  If C1=87 Then
                     A$=Mid$(Str$(Port),2)
                  Endif
                  If C1=155 Then
                     A$=Mid$(Str$(Base.Address),2)
                  Endif
                  If C1=274 Then ' door.node
                     A$=Chr$(Z)
                  Endif
               Endif
               Print #2,A$
            Loop
         Next
      Else
         X1=Int(Val(E$)+.5)
         X2=Int(Val(F$)+.5)
         For Z=X1 To X2
            Select Case X
            Case 1
               Target.Filename$="GUEST"+Mid$(Str$(Z),2)+".CFG"
            Case 2
               Target.Filename$="START"+Mid$(Str$(Z),2)+".CFG"
            Case 3
               Target.Filename$="OPTION"+Mid$(Str$(Z),2)+".CFG"
            Case 4
               Target.Filename$="DND"+Mid$(Str$(Z),2)+".CFG"
               A3$=Node.List1(Z)
               Gosub Read.Node
            End Select
            Close #1
            Open Temp.Filename$ For Input As #1
            Close #2
            Open Target.Filename$ For Output As #2
            C1=0
            Do
               If Eof(1) Then
                  Exit Do
               Endif
               Line Input #1,A$
               C1=C1+1
               If X=4 Then
                  If C1=87 Then
                     A$=Mid$(Str$(Port),2)
                  Endif
                  If C1=155 Then
                     A$=Mid$(Str$(Base.Address),2)
                  Endif
                  If C1=274 Then ' door.node
                     A$=Mid$(Str$(Z),2)
                  Endif
               Endif
               Print #2,A$
            Loop
         Next
      Endif
   Endif
Loop
Color 7,0
Print "Config file(s) written to disk."
End

' Port=Config2(46)-1 (+41)=87
' Base.Address=Config2(114) (+41)=155
' Door.Node=Config3(83) (+41+150)=274
Read.Node:
 Port=0
 Base.Address=0
 A3$=Rtrim$(A3$)
 If A3$<>"" Then
    V1=Instr(A3$,",")
    If V1 Then
       Node=Int(Val(Left$(A3$,V1-1))+.5)
       A3$=Mid$(A3$,V1+1)
       V1=Instr(A3$,",")
       If V1 Then
          Port=Val(Left$(A3$,V1-1))
          A3$=Mid$(A3$,V1+1)
          If Len(A3$) Then
             Base.Address=Val("&H"+A3$)
          Endif
       Endif
    Endif
 Endif
 Return

Passwrd11:
 Var=-1
 Close #1
 DND.Path$=Environ$("DNDBBS")
 If DND.Path$<>"" Then
    If Right$(DND.Path$,1)<>"\" Then
       DND.Path$=DND.Path$+"\"
    Endif
 Endif
 FileName$=DND.Path$+"DNDCNFG2.EXE"
 Open FileName$ For Binary As #1
 File.Length!=Lof(1)
 Get 1,File.Length!,File.Byte
 Byte.Value=Asc(File.Byte)
 Password$=""
 If Byte.Value=255 Then
    For File.Position!=File.Length!-20 To File.Length!-1
       Get 1,File.Position!,File.Byte
       Password$=Password$+File.Byte
    Next
    For VarX=1 To Len(Password$)
       VarZ=Asc(Mid$(Password$,VarX,1)) Xor Len(Password$)
       Mid$(Password$,VarX,1)=Chr$(VarZ)
    Next
    Password$=Rtrim$(Password$)
    If Password$="" Then
       Return
    Endif
    Color 15,0
    Print "Enter password: ";
    Locate ,,1
    TempA$=""
    Do
       Input.Char$=""
       While Input.Char$=""
          Input.Char$=Inkey$
       Wend
       If Input.Char$=Chr$(13) Then
          Exit Do
       Endif
       TempA$=TempA$+Input.Char$
       Print "#";
    Loop
    Print
    If TempA$<>Password$ Then
       Color 14,0
       Print "Illegal password!"
       Var=0
    Endif
 Endif
 Return

Error.Routine:
 Color 15,0
 Error.Number=Err
 Select Case Error.Number
 Case 53
    Print "File not found."
 Case 57
    Print "Device I/O error."
 Case 61
    Print "Disk full."
 Case 62
    Print "Input past eof."
 Case 67
    Print "Not enough file handles."
 Case 68
    Print "Device unavailable."
 Case 70
    Print "Permission denied."
 Case 71
    Print "Disk not ready."
 Case Else
    Print "Error";Error.Number
 End Select
 Color 7,0
 End
