' STRT_1.BAS  GRMEYER v1.1 10/30/93
' Automates logging onto GEnie's ST RT BB, Library, RTC, or email
' If this is accidently invoked while online it will MOVE to the destination
' REQUIRES:
'  - Dialing entry of "GEnie" with correct phone number. Note that settings
'    and autologon for this entry are ignored, they're handled by script.
'  - ASCII file named GENIE.PWD in Storm directory. Contains ACCOUNT & PASSWD
'    each on own line terminated with a carriage return
'
' == Initialzation ==
READ n
DIM p$(n),c$(n)
FOR x = 1 to n
    READ p$(x),c$(x)
NEXT x
'
IF CARRIER THEN
  title$=" Move to... "
ELSE
  title$=" Logon to... "
ENDIF
' == Mainline ==
dest = POPUP (1,title$,p$(1),p$(2),p$(3),p$(4),p$(5))
'
IF dest = 5 THEN GOTO EXIT:' 'cancel' was the selection
IF CARRIER THEN
    SEND c$(dest)
ELSE
    gosub logon
ENDIF
GOTO EXIT
'
' == Finalization ==
EXIT:
    END
'
' == logon subroutine ==
logon:
' this routine searches the dialing dir for entry "GEnie", gets the
' phone number, then handles the dialing, connecting, and logging on
' we'll jump straight to exit if an error is detected
'
entry$="0":' init the entry number of "GEnie" in the dialing dir
'            if this stays zero we didn't find the entry
temp$=""
nent$=SET$("STORM","Dialer","Entries"):' find # of entries in dial dir
FAST ON
FOR x = 1 to val(nent$)
    temp$=SET$("DIALDIR",str$(x),"Name")
    IF temp$ = "GEnie" THEN entry$=str$(x)
NEXT x
FAST OFF
IF entry$="0" THEN
    TOPW:PRINT "Error: No entry found for GEnie!";:PRINT chr$(7)
    GOTO EXIT
ENDIF
'
' get our genie password and account. If file doesn't exist we'll error off
OPEN "r",#1,"GENIE.PWD":' it'd be nice to do a fsfirst() here but oh well
INPUT #1,acct$
INPUT #1,pwd$
CLOSE #1
'
' set up some known settings for GEnie then read STORM.INI for specifics
' about the modem setup
DUPLEX HALF
BAUD 2400
SBITS 1
PARITY NONE
prefix$=SET$("STORM","Modem","Prefix"):' dialing prefix
con1$=SET$("STORM","Modem","Connect1")
con2$=SET$("STORM","Modem","Connect2")
fail1$=SET$("STORM","Modem","Fail1")
fail2$=SET$("STORM","Modem","Fail2")
timeout=SET("STORM","Modem","Timeout"):' get dialing timeout value
IF con1$="" THEN con1$="XXXXXXXXXXXXX":'just in case these are empty
IF con2$="" THEN con2$="XXXXXXXXXXXXX":'if they are empty, wait() will
IF fail1$="" THEN fail1$="XXXXXXXXXXX":'return too quickly when we use it
if fail2$="" THEN fail2$="XXXXXXXXXXX":'later in this routine
'
TOPW 1:SEND prefix$+set$("DIALDIR",entry$,"#"):' dial the GEnie number
WAIT timeout,con1$,con2$,fail1$,fail2$
IF WAIT(0)=3 OR WAIT(0)=4 THEN
    TOPW:PRINT "Error: GEnie didn't answer";chr$(7):GOTO EXIT
ENDIF
IF CARRIER=FALSE THEN
    TOPW:PRINT "Error: No carrier. (didn't answer?)";chr$(7):GOTO EXIT
ENDIF
'
SEND "HHH";
WAIT 20,"U#=":REM Wait 20 seconds for prompt
IF WAIT(0)=0 THEN TOPW :PRINT "Logon Failed";:PRINT chr$(7):GOTO EXIT
DUPLEX FULL :'so password doesn't appear on screen
SEND acct$+","+pwd$+","+mid$(c$(dest),2):' strip "M" off dest$
' The pause ensures that the password is sent before duplex is switched back
PAUSE 2:DUPLEX HALF
WAIT 30,"continue?":' welcome menu prompt
SEND "":' skip it. We're now moving to our destination
'
RETURN
'
' == DATA AREA ==
DATA 5
DATA "  Library ","M475;3"
DATA "  BB ","M475;1"
DATA "  RTC ","M475;2"
DATA "  Mail ","M200"
DATA "  <cancel>",""










