/* Wildcat BBS Logon (JdeBP) */
/*  ******************************************************************  *\
 *    Wildcat.CMD --- Yes folks !  This is REXX !                       *
 *                                                                      *
 *    JdeBP's LiveWire script file for connecting to The Mish and       *
 *    performing a fully automated mail run.  This could probably       *
 *    be adapted to work with any Wildcat/Tomcat BBS.                   *
 *                                                                      *
 *    (c) Copyright 1994 Jonathan de Boyne Pollard                      *
 *        Jonathan.de.Boyne.Pollard@p3.f4.n440.z2.fidonet.org           *
 *        JdeBP@donor2.ukmail.net                                       *
 *                                                                      *
 *    Permission is hereby granted to post, steal and abuse this        *
 *    script for your own purposes to your heart's content, as long     *
 *    as you realise that I take no responsibility whatsoever for       *
 *    what it does to your machine, data, cat, or marital status.       *
\*  ******************************************************************  */

/* All of these adapted from the learned script */
Trace(Off);
SetLW(TimeOut,60);
SetLW(Pacing,40);
SetLW(Emulation, ANSI);
SetLW(Echo,0);
SetLW(Linefeeds,0);
SetLW(XonXoff,0);
SetLW(BSIsDel,0);


/*      Customise the following for your Wildcat setup.                 */

    Firstname = "Jonathan"
    Lastname  = "de Boyne Pollard"
    MyTown    = "Kenilworth"
    Password  = "password"              /* Yeah, right.  As if I would! */
    Telephone = "0000000000"            /* Ditto.                       */
    BirthDate = "000000"                /* Ditto.                       */

    UploadDir = GetLW("ULDir") ;
    if UploadDir \= "" then UploadDir = UploadDir||"\" ;
    RepFile = UploadDir||"Mission.rep" ;
    DownloadDir = GetLW("DLDir") ;
    if DownloadDir \= "" then DownloadDir = DownloadDir||"\" ;
    QWKFile = DownloadDir||"Mission.QWK" ;

/*    Protocol = GetLW("DialerProtocol") ;*/

/* Here's the main bit folks !                                          */

    SendUserName() ;              /* Enter the username and password    */
    VerifyUser() ;                /* Cope with any validation prompts   */

    /*  If you have !logon access to your local Wildcat! BBS, then      */
    /*  appropriate changes to SendUserName() can allow you to omit     */
    /*  the following two stages, and go directly to Tomcat.            */

    SkipBulletinsMailAndNews() ;  /* Erm ... guess !                    */
    SendLW("2") ;                 /* BBS specific hotkey to enter Tomcat*/

    Tomcat() ;                    /* Handle Tomcat                      */

    exit

/*  That wasn't as simple as the PCBoard one, mainly because the sysop  */
/*  is an obstinate sod, who doesn't give his users !logons.  (-:       */

/*                                                                      */
/*  SendUserName -  This function handles all of the initial logging    */
/*  on nastiness.  As with PCBoard, this is easiest as a loop.          */
/*                                                                      */

SendUserName:

    do until login=MyTown||"? [Y]"

       login = FindLW("-Pause-",              /* Esp. for Keith Barnes. */
                     ," is your first name?",
                     ," is your  last name?",
                     ," correctly? [N]",
                     ,MyTown||"? [Y]") ;

       select
       when login="-Pause-" then              SendLW("C") ;
       when login=" is your first name?" then SendLW(firstname||"^M") ;
       when login=" is your  last name?" then SendLW(lastname||"^M") ;
       when login=" correctly? [N]" then      SendLW("N^M") ;
       when login=MyTown||"? [Y]" then        SendLW("Y") ;
       end

    end

    return "" ;

/*                                                                      */
/*  VerifyUser -  This function handles post-login verification.  This  */
/*  could be combined with the SendUserName() function, but it is       */
/*  really a distinct stage for Wildcat, in that if you fail to verify  */
/*  you aren't prompted for a new user name.                            */
/*                                                                      */

VerifyUser:

    do forever

       /* Possibly you could add logic here to automatically handle     */
       /* entering the message editor when your verification fails.     */
       /* However, verification *shouldn't* fail if you have set the    */
       /* variables up correctly.                                       */

       verify=FindLW("[              ]",
                    ,"[   -   -    ]",
                    ,"[  /  /  ]",
                    ,Firstname) ;

       select
       when verify="[              ]" then SendLW(password||"^M") ;
       when verify="[   -   -    ]" then   SendLW(Telephone||"^M") ;
       when verify="[  /  /  ]" then       SendLW(BirthDate||"^M") ;
       when verify=Firstname then          Leave ;
       otherwise                           Nop ;
       end

    end

    return "" ;

/*                                                                      */
/*  I don't know about you, but *my* Wildcat sysop enjoys his logon     */
/*  screens far too much.  However, this little function should skip    */
/*  most of them with little fuss.                                      */
/*                                                                      */

SkipBulletinsMailAndNews:

    do forever

       /*  Note that I have chosen to [L]ist new personal mail.  For    */
       /*  TRULY unattended runs you may choose to [C]ontinue instead.  */

       nonstop=FindLW("-Pause-",
                     ,"new personal mail,",
                     ,"view the bulletin menu",
                     ,"you like to view",
                     ,"] to continue?") ;

       select
       when nonstop="-Pause-" then                 SendLW("C") ;
       when nonstop="new personal mail," then      SendLW("L") ;
       when nonstop="view the bulletin menu" then  SendLW("N") ;
       when nonstop="you like to view" then        SendLW("N") ;
       when nonstop="] to continue?" then          Leave ;
       otherwise                                   Nop ;
       end

    end

    /*  We are at the final "Press [ENTER]" prompt before the main      */
    /*  menu, so guess when we do now !                                 */

    SendLW("^M") ;

    return "" ;

/*                                                                      */
/*  Tomcat -- A function to handle the TomCat mail door.  This will     */
/*  upload a REP if it exists, download any prescanned REPs if it can,  */
/*  or download a REP scanned online.  It should be pretty easy to      */
/*  modify this to ONLY download prescanned REPs, as that was my        */
/*  original intention.                                                 */
/*                                                                      */

Tomcat:
    Uploaded = ( stream(RepFile, 'C', 'Query Exists')="" ) ;
    Downloaded = 0 ;
    PrescanPresent = 0 ;
    Done = 0 ;

    do until (Done)

       tomcat=FindLW("prescanned packet",
                     ,"TOMCAT MENU",
                     ,"Transfer successful") ;

       select
       when tomcat="prescanned packet" then
            PrescanPresent = 1 ;
       when tomcat="TOMCAT MENU" then do

            select
            when \ Uploaded then do
                 SendLW("U") ;
                 DelayLW(300) ;
                 SendFilesLW("Z", RepFile) ;                /* ZMODEM!  */
                 Uploaded = 1 ;
            end
            when PrescanPresent then do
                 SendLW("DG") ;
            end
            when \ Downloaded then do
                 SendLW("DG") ;
            end
            end

       end
       when tomcat="Transfer successful" then do

            /* This prompt is triggered at the end of BOTH uploads and  */
            /* downloads, so we only exit if a QWK packet now exists.   */

            /* Maybe in the future I will sort out the correct prompts  */
            /* to distinguish uploads and downloads, and even handle    */
            /* UNsuccessful tranfers ...                                */

            Done = \ ( stream(QwkFile, 'C', 'Query Exists')="" )
       end
       otherwise nop ;
       end

    end

    /* Again, the TRANSFER.BTM file takes the QWK from the download     */
    /* directory and copies and moves it in the background.             */

    Start "/bg /c Transfer Mission"

    return "" ;

