REM  OPENDOOR Release 1.0 on 1-1-89 by Fast Fingers ... 313-247-0094

DECLARE SUB HitKey ()
DECLARE SUB HelpUser ()
DECLARE SUB ReadCommandLine (Command1$, Command2$, Drive$, Path$, Code$)
DECLARE SUB Delay (Seconds!)
DECLARE SUB ReadDEF (BBSName$, SysopFName$, SysopLName$, Port$, BBS$, MaxTime$, Debug$)
DECLARE SUB Filter (Name$)
DECLARE SUB RBBSBoard (BBS$, FirstName$, LastName$, UTime$, HookUp$, OkFlag!)
DECLARE SUB PcBoard (BBS$, FirstName$, LastName$, UTime$, HookUp$, OkFlag!)
DECLARE SUB FindFile (File$, FindSW!)
    
     TYPE PcBoardRecord
       PcDummy1 AS STRING * 10
       PcBaud AS STRING * 4
       PcName AS STRING * 27
       PcFirstName AS STRING * 15
       PcGraphicsSw AS STRING * 2
       PcDummy2 AS STRING * 71
     END TYPE
    
     IF COMMAND$ = "" THEN CALL HelpUser

     CLS
     PRINT "***********************************************"
     PRINT "*    OPENDOOR.EXE                     1/1/89  *"
     PRINT "* Fast Finger's Generic Ansi Graphics Utility *"
     PRINT "* To Open Doors for BBS Systems that output   *"
     PRINT "* PcBoard.Sys or DorInfo1.Def.  Release 1.0   *"
     PRINT "***********************************************"
     PRINT
     CALL ReadCommandLine(Command1$, Command2$, Drive$, Path$, Code$)
     PRINT
     CALL ReadDEF(BBSName$, SysopFName$, SysopLName$, Port$, BBS$, MaxTime$, Debug$)
     PRINT
     IF Debug$ = "ON" THEN CALL Delay(5)
     IF Command2$ = "LOCAL" THEN Port$ = "LOCAL"

     IF BBS$ = "PCBOARD.SYS" THEN
         CALL PcBoard(BBS$, UFName$, ULName$, UTime$, HookUp$, OkFlag)
         IF OkFlag THEN GOTO ChkHookUp
       END IF
     IF BBS$ = "DORINFO1.DEF" THEN
         CALL RBBSBoard(BBS$, UFName$, ULName$, UTime$, HookUp$, OkFlag)
         IF OkFlag THEN GOTO ChkHookUp
       END IF

     PRINT "Sorry, but this release of  OPENDOOR.EXE does not yet support"
     PRINT "the BBS door output you requested, => " + BBS$ + " in the"
     PRINT "file named  OPENDOOR.DEF     *** ABORTING DOOR REQUEST *** "
     CALL Delay(5)
     END
   
ChkHookUp:
    
     IF HookUp$ = "LOCAL" THEN GOTO StartOutput
     IF Port$ = "LOCAL" THEN HookUp$ = "LOCAL": GOTO StartOutput
     HookUp$ = Port$ + HookUp$
    
StartOutput:
    
     IF VAL(UTime$) = 0 THEN UTime$ = MaxTime$
     IF VAL(UTime$) > VAL(MaxTime$) THEN UTime$ = MaxTime$
    
     OutputFile$ = Path$ + "\" + "OPENDOOR.Sys"
     FileId = FREEFILE

     OPEN OutputFile$ FOR OUTPUT AS #FileId
       PRINT #FileId, BBSName$
       PRINT #FileId, SysopFName$
       PRINT #FileId, SysopLName$
       PRINT #FileId, HookUp$
       PRINT #FileId, UFName$
       PRINT #FileId, ULName$
       PRINT #FileId, UTime$
       PRINT #FileId, Debug$
     CLOSE #FileId
     
     IF Debug$ = "ON" THEN CALL Delay(5)
     PRINT
     PRINT "Data being Written into OPENDOOR.SYS"
     PRINT
     PRINT BBSName$
     PRINT SysopFName$
     PRINT SysopLName$
     PRINT HookUp$
     PRINT UFName$
     PRINT ULName$
     PRINT UTime$
     PRINT Debug$
     IF Debug$ = "ON" THEN CALL Delay(5)

StartDoor:

     SHELL Drive$
     CHDIR Path$
     RUN Code$: REM TURN OFF DURING DEVELOPMENT ****************************
    
     END

SUB Delay (Seconds)
 
  Time1! = TIMER
  Time2! = Time1!

ChkWaitTime:
 
  Time2! = TIMER
  WaitTime! = ABS(Time2! - Time1!)
  IF WaitTime! >= Seconds THEN EXIT SUB
  GOTO ChkWaitTime

END SUB

SUB Filter (Name$)

  A$ = UCASE$(Name$)
  x = LEN(A$)
  IF x < 1 THEN EXIT SUB

  FOR i = 1 TO x
    B$ = MID$(A$, i, 1)
    y = ASC(B$)
    IF y < 65 OR y > 90 THEN MID$(Name$, i, 1) = "-"
  NEXT i
 
END SUB

SUB FindFile (File$, FindSW)

'
' Input ...... File$ <= Path\Name of file to find
' Output ..... 1 = File Found
'              0 = File Not Found
'
  FileId = FREEFILE
  OPEN File$ FOR RANDOM AS #FileId LEN = 10
  IF LOF(FileId) < 1 THEN FindSW = 0 ELSE FindSW = 1
  CLOSE #FileId
  IF FindSW = 0 THEN KILL File$
'
END SUB

SUB HelpUser

 CLS
 Temp$ = " OPENDOOR " + COMMAND$
 PRINT Temp$

 PRINT
 PRINT "This BBS Door utility was written by Fast Fingers, the sysop of the"
 PRINT "Tool Box BBS.  Its purpose is to allow the Ansi Graphics doors I   "
 PRINT "have written to be easily interfaced with various BBS systems which"
 PRINT "each have their own way of sending information critical to a door's"
 PRINT "operation.  This is release 1.0 and the latest version can be found"
 PRINT "at my bbs 313-247-0094 @ 2400 baud.                                            "
 PRINT
 PRINT "Input comes from a text file you should create named  OPENDOOR.DEF  "
 PRINT "and the command line that calls this program.  Output is placed in "
 PRINT "the same directory as the door being called and is another text file"
 PRINT "called  OPENDOOR.SYS  This program will switch to the door's drive  "
 PRINT "and directory and then call the door.  This program and it's DEF   "
 PRINT "file should be placed in the same directory as your BBS.  You can  "
 PRINT "see these instructions anytime by simply typing in  OPENDOOR without"
 PRINT "any command line input.                                            "
 PRINT "                                                                   "
 PRINT "This release of  OPENDOOR will support Local operation and/or input "
 PRINT "from RBBS with (DORINFO1.DEF); and TAG or PCBOARD with (PCBOARD.SYS)."
 PRINT
 CALL HitKey

 CLS
 PRINT " OPENDOOR.EXE ... Command Line Input"
 PRINT
 PRINT "  This Program requires input on the Command Line"
 PRINT "    The first argument is the full name and location of"
 PRINT "    the ansi graphics door to be run and it is required."
 PRINT "    The second argument is optional and signals that you"
 PRINT "    wish to run the door in local mode."
 PRINT
 PRINT "  For Example:"
 PRINT "      OPENDOOR.EXE D:\Tag\Games\Maze.EXE"
 PRINT "      OPENDOOR.EXE D:\RBBS\DOORS\BJACK.EXE LOCAL"
 PRINT
 CALL HitKey

 CLS
 PRINT " OPENDOOR.EXE ...  OPENDOOR.DEF Input"
 PRINT
 PRINT "  Note: Both  OPENDOOR.EXE and  OPENDOOR.DEF should be in the"
 PRINT "        same directory as your BBS and this should be the"
 PRINT "        current directory!"
 PRINT
 PRINT "   OPENDOOR.DEF Format:      <= Text File"
 PRINT "    BBS Name                <= Line 1"
 PRINT "    Sysop's First Name      <= Line 2"
 PRINT "    Sysop's Last Name       <= Line 3"
 PRINT "    Port                    <= Line 4"
 PRINT "    BBS Info for Doors      <= Line 5"
 PRINT "    Max. Door Time          <= Line 6 (Minutes)"
 PRINT "    DebugSwitch             <= Line 7 (ON or OFF)"
 PRINT
 PRINT "  Line 4 Options: COM1: or COM2: or COM3: or COM4: or LOCAL"
 PRINT "  Line 5 Options: DORINFO1.DEF or PCBOARD.SYS or LOCAL"
 PRINT
 CALL HitKey

 CLS
 PRINT " OPENDOOR.EXE ... Local Mode Operation"
 PRINT
 PRINT "  Use of LOCAL on the command line will force door to run in"
 PRINT "  local mode.  LOCAL in either line 4 or line 5 of the file"
 PRINT "   OPENDOOR.DEF will also force Local operation."
 PRINT
 PRINT "  Some BBS systems also allow the BBS to execute doors directly"
 PRINT "  in local mode.  PcBoard and TAG support this mode of operation"
 PRINT "  and this situation is reflected in the information passed to"
 PRINT "  the door in the file PCBOARD.SYS  "
 PRINT
 CALL HitKey

 CLS
 PRINT " OPENDOOR.EXE ... Output ( OPENDOOR.SYS)"
 PRINT
 PRINT "  Output from this program is put in a file named  OPENDOOR.SYS"
 PRINT "  This file in placed in the same directory where the door is"
 PRINT "  located.  This is a simple text file with the following format."
 PRINT
 PRINT " OPENDOOR.SYS ... Format/Example"
 PRINT
 PRINT "The Tool Box        <= Line #1 ... BBS Name"
 PRINT "Fast                <= Line #2 ... Sysop's First Name"
 PRINT "Fingers             <= Line #3 ... Sysop's Last Name"
 PRINT "COM1: 2400,N,8,1    <= Line #4 ... Open Modem Info"
 PRINT "Joe                 <= Line #5 ... User's First Name"
 PRINT "Smith               <= Line #6 ... User's Last Name"
 PRINT "60                  <= Line #7 ... Minutes Allowed in Door "
 PRINT "OFF                 <= Line #8 ... Debug ON or OFF"
 PRINT
 CALL HitKey

 CLS
 PRINT " OPENDOOR.EXE ... Support for Other BBS Systems"
 PRINT
 PRINT "  Over time I suppect logic will be added for a growing list of"
 PRINT "  BBS systems.  However, in the hope of allowing you to bring up"
 PRINT "  an unsupported system I have encluded a copy of the Quick Basic"
 PRINT "  Release 4.0 source code.  The code is quite structured and really"
 PRINT "  requires only one subroutine be added to support each new BBS."
 PRINT
 PRINT "  The trick of course is understanding how to locate and read the"
 PRINT "  information your bbs has about the current attached user.  The"
 PRINT "  information required is:"
 PRINT "    The user's name, the baud rate, the connection word length and"
 PRINT "    stop bits, and the pariety of the connection.  You will also"
 PRINT "    need to know if the callers terminal program will support"
 PRINT "    ansi graphics."
 PRINT
 PRINT "  Good luck with the Ansi (Moving Graphics) Doors, Enjoy ..."
 PRINT
 PRINT "                                     Fast Fingers ..."
 PRINT "                                     313-247-0094"
 PRINT
 CALL HitKey

 END

END SUB

SUB HitKey

    PRINT "                 => Hit Any Key to Continue <="
    A$ = ""
WaitKey:
    A$ = INKEY$
    IF A$ = "" THEN GOTO WaitKey
   
END SUB

SUB PcBoard (BBS$, FirstName$, LastName$, UTime$, HookUp$, OkFlag)
    
     DIM RecPtr AS PcBoardRecord

     REM Default Output Values
    
     OkFlag = 1
     FirstName$ = "Fast"
     LastName$ = "Fingers"
     UTime$ = "0"
     HookUp$ = "LOCAL"
    
'
'    Logic for Reading PcBoard.Sys Door Data
'
     IF UCASE$(BBS$) <> "PCBOARD.SYS" THEN
       OkFlag = 0
       EXIT SUB
     END IF

     CALL FindFile(BBS$, FindSW)
     IF FindSW = 0 THEN
       PRINT "The PcBoard BBS logic could not find the file => " + BBS$
       CALL Delay(2)
       OkFlag = 0
       EXIT SUB
     END IF

     FileNo = FREEFILE
     OPEN BBS$ FOR RANDOM AS #FileNo LEN = 129
       GET #FileNo, 1, RecPtr
       Baud$ = LTRIM$(RTRIM$(RecPtr.PcBaud))
       FullName$ = LTRIM$(RTRIM$(RecPtr.PcName))
       FirstName$ = LTRIM$(RTRIM$(RecPtr.PcFirstName))
       GraphicsSW$ = LTRIM$(RTRIM$(RecPtr.PcGraphicsSw))
     CLOSE #FileNo

     IF Baud$ = "LOCA" THEN
       HookUp$ = "LOCAL"
     ELSE
       IF GraphicsSW$ = "-1" THEN
         HookUp$ = Baud$ + ",N,8,1"
       ELSE
         OkFlag = 0: REM Not an Ansi Graphics User
         EXIT SUB
       END IF
     END IF
    
     LenFName = LEN(FirstName$)
     LenFullName = LEN(FullName$)
     IF LenFName + 2 >= LenFullName THEN
       LastName$ = FirstName$
       FirstName$ = "Mr"
     ELSE
       LastName$ = MID$(FullName$, LenFName + 2, LenFullName - LenFName - 1)
     END IF
     CALL Filter(FirstName$)
     CALL Filter(LastName$)
    
     PRINT "BBS Door File Analysis for => PCBOARD.SYS"
     PRINT "  Hookup ....... "; HookUp$
     PRINT "  First Name ... "; FirstName$
     PRINT "  Last Name .... "; LastName$
'    PRINT "  PcGraphicsSw . "; GraphicsSW$

     EXIT SUB
'
END SUB

SUB RBBSBoard (BBS$, FirstName$, LastName$, UTime$, HookUp$, OkFlag)

     REM Default Output Values
   
     OkFlag = 1
     FirstName$ = "Fast"
     LastName$ = "Fingers"
     UTime$ = "0"
     HookUp$ = "LOCAL"

'    REM legal OUTPUT format expected  "2400,N,8,1" <= HookUp$ .. sub output
'    REM legal INPUT  format expected  "2400 BAUD,8,N,1" <= Baud$ .. dorinfo1

'
'    Logic for Reading DorInfo1.Def Door Data
'
     IF UCASE$(BBS$) <> "DORINFO1.DEF" THEN
       OkFlag = 0
       EXIT SUB
     END IF

     CALL FindFile(BBS$, FindSW)
     IF FindSW = 0 THEN
       PRINT "The DorInfo1.Def BBS logic could not find the file => " + BBS$
       CALL Delay(2)
       OkFlag = 0
       EXIT SUB
     END IF

     FileNo = FREEFILE
     OPEN BBS$ FOR INPUT AS #FileNo
       LINE INPUT #FileNo, BBSName$
       LINE INPUT #FileNo, SysopFirstName$
       LINE INPUT #FileNo, SysopLastName$
       LINE INPUT #FileNo, ComPort$
       LINE INPUT #FileNo, Baud$
       LINE INPUT #FileNo, Switch1$
       LINE INPUT #FileNo, FirstName$
       LINE INPUT #FileNo, LastName$
       LINE INPUT #FileNo, Address$
       LINE INPUT #FileNo, Switch2$
       LINE INPUT #FileNo, SecurityLevel$
       LINE INPUT #FileNo, UTime$

       GraphicsSW$ = "?": REM  fix later ********************************

     CLOSE #FileNo

     FullName$ = FirstName$ + " " + LastName$
     LenFName = LEN(FirstName$)
     LenFullName = LEN(FullName$)
     IF LenFName + 2 >= LenFullName THEN
       LastName$ = FirstName$
       FirstName$ = "Mr"
     END IF
     CALL Filter(FirstName$)
     CALL Filter(LastName$)
    
     x = INSTR(1, ComPort$, "0")
     IF x THEN
       HookUp$ = "LOCAL"
       GOTO QuitRbbsBoard
     END IF

     x = INSTR(1, Baud$, "LOC")
    
     IF x > 0 THEN
       HookUp$ = "LOCAL"
     ELSE
       x = LEN(Baud$)
       x1 = INSTR(1, Baud$, " BAUD")
       x2 = INSTR(1, Baud$, ",")
       IF x1 = 0 OR x2 = 0 OR x1 > (x2 - 1) THEN
         OkFlag = 0
         PRINT "confused with first line of dorinfo1.def .. bad format"
         EXIT SUB
       ELSE
         A$ = MID$(Baud$, 1, x1 - 1)
         B$ = MID$(Baud$, x2, x - x2 + 1)
         HookUp$ = A$ + B$
         x1 = INSTR(1, HookUp$, "N")
         x2 = INSTR(1, HookUp$, "8")
         x3 = INSTR(1, HookUp$, "1")
         IF x1 < 1 OR x2 < 1 OR x3 < 1 THEN
           OkFlag = 0
           PRINT "Not Graphics User based upon PARITY, DATA/STOP BITS"
           EXIT SUB
         END IF
       END IF
     END IF
  
QuitRbbsBoard:

     PRINT "BBS Door File Analysis for => DORINFO1.DEF"
     PRINT "  Hookup ....... "; HookUp$
     PRINT "  First Name ... "; FirstName$
     PRINT "  Last Name .... "; LastName$
'    PRINT "  PcGraphicsSw . "; GraphicsSW$

     EXIT SUB
'


END SUB

SUB ReadCommandLine (Command1$, Command2$, Drive$, Path$, Code$)
'
'    Logic for Local Mode Command input to  OPENDOOR.BAS
'
     Temp$ = UCASE$(COMMAND$)
   
     IF LEN(Temp$) < 1 THEN CALL HelpUser
'
'    Initilize OUTPUT to Defaults
'
     Command1$ = ""
     Command2$ = ""
     Drive$ = "C:"
     Path$ = "C:\TAG"
     Code$ = "Dummy.EXE"
'
'    Strip out first Command
'
     FOR i = 1 TO LEN(Temp$)
       A$ = MID$(Temp$, i, 1)
       IF A$ = " " THEN
         IF (i + 1) > LEN(Temp$) THEN Command2$ = "LOCAL"
         GOTO Lab1:
       END IF
       Command1$ = Command1$ + A$
     NEXT i

Lab1:         
     CALL FindFile(Command1$, FindSW)
     IF FindSW = 0 THEN
       PRINT "   OPENDOOR could not find => " + Command1$
       PRINT "  Program Aborting Door Execution"
       END
     END IF
'
'    Strip out Path from Command1
'
     Path$ = Command1$
Loop1:
     x = LEN(Path$)
     IF x < 2 THEN
       PRINT "   OPENDOOR could not understand the path for the door"
       PRINT "  Program Aborting Door Execution"
       END
     END IF
     A$ = MID$(Path$, x, 1)
     Path$ = MID$(Path$, 1, x - 1)
     IF A$ <> "\" THEN GOTO Loop1
    
     Drive$ = UCASE$(MID$(Path$, 1, 2))
     IF MID$(Drive$, 2, 1) <> ":" THEN Drive$ = "C:"
     Code$ = MID$(Command1$, x + 1, LEN(Command1$) - x)
    
     PRINT "Command Line Analysis"
     PRINT "  Command #1 ..... => "; Command1$
     PRINT "  Command #2 ..... => "; Command2$
     PRINT "  The Door is Program ................. => "; Code$
     PRINT "  The Door is on Drive ................ => "; Drive$
     PRINT "  The Door is located in Directory .... => "; Path$
    
END SUB

SUB ReadDEF (BBSName$, SysopFName$, SysopLName$, Port$, BBS$, MaxTime$, Debug$)
    
     PRINT "Reading file ...  OPENDOOR.Def"
     CALL FindFile("OPENDOOR.Def", FindSW)
     IF FindSW = 0 THEN
       BEEP
       PRINT "  OPENDOOR could not find file =>  OPENDOOR.DEF"
       PRINT "  Note: Both  OPENDOOR.EXE and  OPENDOOR.DEF should be in the"
       PRINT "        same directory as your BBS and this should be the"
       PRINT "        current directory!"
       PRINT
       PRINT "  OPENDOOR.DEF Format:      <= Text File"
       PRINT "    BBS Name                <= Line 1"
       PRINT "    Sysop's First Name      <= Line 2"
       PRINT "    Sysop's Last Name       <= Line 3"
       PRINT "    Port                    <= Line 4"
       PRINT "    BBS Output to Doors     <= Line 5"
       PRINT "    Maximum Time in door    <= Line 6 (Minutes)"
       PRINT "    DebugSwitch             <= Line 7 (ON or OFF)"
       PRINT
       PRINT "  Line 4 Options: COM1: or COM2: or COM3: or COM4: or LOCAL"
       PRINT "  Line 5 Options: DORINFO1.DEF or PCBOARD.SYS or LOCAL"
       PRINT
       PRINT "  Program Aborting Door Execution"
       CALL Delay(5)
       PRINT
       END
     END IF
   
     FileId = FREEFILE

     OPEN "OPENDOOR.def" FOR INPUT AS #FileId
      
       INPUT #FileId, BBSName$
       PRINT "  BBSName$ ................. "; BBSName$
      
       INPUT #FileId, SysopFName$
       CALL Filter(SysopFName$)
       PRINT "  Sysop's First Name ....... "; SysopFName$
      
       INPUT #FileId, SysopLName$
       CALL Filter(SysopLName$)
       PRINT "  Sysop's Last Name ........ "; SysopLName$
      
       INPUT #FileId, Port$
       Port$ = RTRIM$(LTRIM$(UCASE$(Port$)))
       IF Port$ = "COM1:" THEN GOTO OkPort
       IF Port$ = "COM2:" THEN GOTO OkPort
       IF Port$ = "COM3:" THEN GOTO OkPort
       IF Port$ = "COM4:" THEN GOTO OkPort
       IF Port$ = "LOCAL" THEN GOTO OkPort
       PRINT
       PRINT "   OPENDOOR.DEF Format:      <= Text File"
       PRINT "    BBS Name                <= Line 1"
       PRINT "    Sysop's First Name      <= Line 2"
       PRINT "    Sysop's Last Name       <= Line 3"
       PRINT "    Port                    <= Line 4"
       PRINT "    BBS Output to Doors     <= Line 5"
       PRINT "    Max Door Time (Minutes) <= Line 6"
       PRINT
       PRINT "  Line 4 Options: COM1: or COM2: or COM3: or COM4: or LOCAL"
       PRINT "  Line 5 Options: DORINFO1.DEF or PCBOARD.SYS or LOCAL"
       PRINT
       PRINT "  Program Aborting Door Execution because LINE 4 is BAD"
       CALL Delay(5)
       PRINT
       END
OkPort:
       PRINT "  Com Port Used by Doors ... "; Port$
      
       INPUT #FileId, BBS$
       BBS$ = UCASE$(BBS$)
       PRINT "  Type of BBS Door Output .. "; BBS$
      
       INPUT #FileId, MaxTime$
       PRINT "  Max. Minutes in Door ..... "; MaxTime$

       INPUT #FileId, Debug$
       Debug$ = UCASE$(Debug$)
       IF Debug$ <> "ON" THEN Debug$ = "OFF"
       PRINT "  Debug Switch ............. "; Debug$
      
     CLOSE #FileId
     
END SUB

