Metropoli BBS
VIEWER: lgthouse MODE: TEXT (LATIN1)
/* Ligthouse rexx script */

        /*use this to debug script  */
/*        TRACE A */     /* be carefull, Zoc rexx is too slow with trace on*/

        ADDRESS 'ZOC'                            /* send non rexx commands to zoc */
/*      Signal on Syntax
        Signal on Halt
        Signal on Novalue */                     /* all 3 do not work */

        /* set variables with default values - may be changed */
        waittodial   =  28                       /* time between dials */
        maxtry       =  400                      /* max number of trys  */
        phone        =  "01834-2427"             /* phone number to call  */
        reppath      =  "c:\com.map\"            /* REP file path */
        qwkpath      =  "c:\com.map\qwk\"        /* QWK file path  */
        dwnpath      =  "c:\com.map\"            /* download file path */
        uplpath      =  "c:\com.map\"            /* upload file path */
        Skppath      =  "c:\com.map\"            /* skip mail file (empty) */
        repfile      =  "lgthouse.rep"           /* REP file name */
        qwkfile      =  "lgthouse.qwk"           /* QWK file name */
        dwnfile      =  "lgthouse.dwn"           /* download description file name */
        uplfile      =  "lgthouse.upl"           /* upload description file name */
        Skpfile      =  "nomail"                 /* empty file with name nomail */
        noautoopts   =  "options\stannoau"       /* NOAUTO options file only for uploads */
        standardopts =  "options\standard"       /* STANDARD options */
        waittime     =  30                       /* 30 seconds to wait on response from BBS */
        waittimemail =  1500                     /* 30 minutes time for mail download */
        myname       =  "Arjen Meijer"           /* name */
        password     =  "secret"                 /* password */
        tune_on_connect = "no"                   /* play a tune after connect to bbs yes/no */
        logname "lgthouse.log"                   /* file name to log this script */
        logging 1                                /* logging on =1 off =0 */

        /* initialize some variables */
        Collect_mail = "yes"                     /* collect mail */
        Did_automatic_logoff = "no"              /* prevent double logoff */
        Select_manual = "no"                     /* keyboard intervention */
        Terminate_zoc = "exit"                   /* end this script with exit */

        /* Constants */
        cr     = '0D'x
        crlf   = '0A0D'x
        esc    = '1B'x

        arg Command_line_option                       /* parse parameter from command line */

        timeout waittime                              /* wait waittime  seconds */

        /* check, whether valid cd option is set or whether the script was started manually */
        SELECT
          when Command_line_option = 'AUTOMATIC' then /* dialing in Zoc */
            do
              call logon
              call what_to_do
              if did_automatic_logoff = "no" then call logoff
            end                                       /* end when command_ */
          when Command_line_option = 'MANUAL' then    /* dialing in zoc and manual selection */
            do
              call logon                              /* logon automaticaly */
              call manual                             /* selection actions */
            end                                       /* end when command_ */
          otherwise
            do
              Online = zoccarrier()
              SELECT
                when Online = 'N/A' then
                DO
                  WRITE '"Please enable CD Valid in OPTIONS SERIAL^M^J^M^J"'
                  EXIT
                END
                when Online = 'NO CARRIER' then 
                    do 
                    call automatic
                    Terminate_zoc = "endzoc"     /* end this script with endzoc */
                    end                          /* end do when Online */  
                when Online = 'CARRIER' then call manual
                otherwise
                  nop
              end                                /* end select otherwise */
            end                                  /* end do otherwise */
          end                                    /* end select command_line_option */
        if Terminate_zoc = "exit" then           /* who to end this script */
            exit                                 /* close script */
        else
            endzoc                               /* close zoc */

automatic:
        call check_modem
        call phonebbs 
        call logon   
        call what_to_do
        if did_automatic_logoff = "no" then call logoff
        return


manual:
    select_manual = "yes"                      /* return to the same menu everytime */
    do while (selection \="Quit script") & (did_automatic_logoff = "no")
      if Command_line_option = 'MANUAL' then
        request '"                           Lighthouse options" "Mail" "Files" "Logoff" "Quit script"'
      else
        request '"                           Lighthouse options" "Mail" "Files" "Logon/off" "Quit script"'
      selection= zocresult()
      SELECT
          when Selection = "Mail" then
            do
            request '"                      Mail options " "Download" "Upload" "Return"'
            selection= zocresult()
            SELECT
              when Selection = "Download" then call getmail
              when Selection = "Upload" then call sendmail
              otherwise nop
              end /* end select */
            end /* end do*/
          when Selection = "Files" then
            do
            request '"                      Files options " "Download" "Upload" "Return"'
            selection= zocresult()
              select
              when Selection = "Download" then call download
              when Selection = "Upload" then call upload
              otherwise nop
              end  /* end select */
            end /* end do */
          when Selection = "Logoff" then
            do 
            request '"                      Logoff options " " Logoff " " Return "'
            selection= zocresult()
              select
              when Selection = "Logoff" then call logoff
              otherwise nop
              end         /* end select */
            end         /* end do */
          when Selection = "Logon/off" then
            do
            request '"                      Logoff options " "Logon" "Logoff" "Return"'
            selection= zocresult()
              select
              when Selection = "Logon" then call logon_without_begin
              when Selection = "Logoff" then call logoff
              otherwise nop
              end  /* end select */
            end /* end do */
          OTHERWISE nop
       END   /* end select */
    end /* end do while */
    return

/*****************************************************************/
/*  start of the subroutines                                                                                       */
/*****************************************************************/
check_modem: 
        timeout 2                                /* wait 2 seconds */
        send "AT^M"                              /* a useless command */
        call wait_c OK                           /* answer of modem */
        timeout waittime                         /* wait waittime  seconds */
        return

wait_c:                                          /* wait line and check return code */
        Wait arg(1)                              /* wait on line */
        if rc=640 then                           /* check return code */
          do
          HANGUP                                /* phone on hook */
          writeln "***Error. No response from the BBS" /* Tell what is happening */
          write "***Timeout on line: "          /* waiting for string */
          writeln arg(1)                        /* line waiting for */
          exit                                  /* cancel script */
          end                                   /* end if rc */
        return                                  /* back to calling program */

logoff:
        send "G;Y"||cr                           /* goodbye from every screen */
        call wait_c "NO CARRIER"                 /* wait to complete */
        did_automatic_logoff = "yes"             /* prevent double logoff */
        return

what_to_do:

/*     skip mail if file skipmail exist. */
        file_path_name=stream(Skppath||Skpfile,'c','query exists')   /* query path en file name */
        if file_path_name \="" then
          do
          Collect_mail = "no"                              /* if it does exist, no mail */
          call delete_file Skppath||Skpfile                /* if you want to delete the file */
          end                                              /* end if */

/*     download file? */
        file_path_name=stream(Dwnpath||Dwnfile,'c','query exists')   /* query path en file name */
        if file_path_name \="" then call download          /* empty if it does not exist */

/*     upload file? */
        file_path_name=stream(Uplpath||Uplfile,'c','query exists')   /* query path en file name */
        if file_path_name \="" then call upload            /* empty if it does not exist */

/*     collect mail */
        if Collect_mail = 'yes' then call getmail          /* collect mail if we do not skip the mail */

/*     reply file? */
        file_path_name=stream(Reppath||Repfile,'c','query exists')   /* query path en file name */
        if file_path_name \="" then call sendmail              /* empty if it does not exist */

        return

logon_without_begin:                             /* where am I and logon */
        reply '"Press [ESCape] or [Tab] twice:"' esc||esc||cr
        reply '"Enter Language number to use (Enter)=default?"' "3"cr
        reply '"Do you want graphics (Enter)=YES?"' "N"cr
        reply '"What is your first name?"' '"'||myname||" "||password||cr||'"'
        reply '"Press (Enter) to continue?"' cr
        reply '"(H)elp, More?"' "N"cr            /* sometimes a news flash pops up */
        reply '"Scan Message Base Since 'Last Read' (Enter)=yes?"' "No"cr
        send esc||esc||cr                             /* send first command */
        call wait_c "Main Board Command?"
        reply '"Press [ESCape] or [Tab] twice:"' 
        reply '"Enter Language number to use (Enter)=default?"'
        reply '"Do you want graphics (Enter)=YES?"'
        reply '"What is your first name?"'
        reply '"Press (Enter) to continue?"'
        reply '"(H)elp, More?"'               /* cancel reply */
        reply '"Scan Message Base Since 'Last Read' (Enter)=yes?"'
        return                                   /* reply slows down zoc */

logon:                                           /* login to bbs */               
        cls                                      /* clear screen */
        call WAIT_c "Press [ESCape]"             /* response from BBS */
        send esc||esc||cr                        /* 2 x escape character chr(27) */
        call WAIT_c "Language number to use"     /* response from BBS */
        send "3"cr                               /* english for scripts  */
        call Wait_c "Do you want graphics (Enter)=YES?" /* response from BBS */
        send "N"cr                               /* no graphics is faster */
        call WAIT_c "What is your first name?"   /* response from BBS */
        send myname||" "||password||cr           /* login in 1 answer  */
        call Wait_c "(Enter) to continue"        /* response from BBS */
        send cr                                  /* send cariage return */ 
        reply '"(H)elp, More?"' "N"cr            /* sometimes a news flash pops up */
        reply '"Read your personal mail now:"' "N"cr /* if newmail pops up */
        call WAIT_c "Scan Message Base"          /* response from BBS */
        send "N"cr                               /* no, we use an offline mailreader */
        call WAIT_c "Main Board Command?"        /* response from BBS */
        reply '"(H)elp, More?"'                  /* cancel reply */
        reply '"Read your personal mail now:"'   /* cancel if newmail pops up */
       return

phonebbs:                                        /* Phone loop */
        do counter = 1 to Maxtry                 /* loop until counter to large */
          cls                                    /* clear screen */
          writeln "^[[H^[[2mTry #"counter" of "maxtry"^[[m"  /* write to screen  */
          write "Modem status: "
          dial phone                             /* dail with modem */
          call wait_c cr                         /* wait for a line */
          delay 1.5                              /* give zoc time to raise carrier signal */
          if zoccarrier() = 'CARRIER' then
            do
            if tune_on_connect = "yes" then call play_tune   /* play a tune */
            return                               /* out of do loop and back to calling program*/
            end                                  /* end if zoccarrier() */
          delay Waittodial                       /* WAIT some moments */
        end                                      /* end until, hence start again */
        write "Exceeded "maxtry "Script stoped."
        exit                                     /* end script */
        return

download:
        send "D"cr                               /* start menu download on BBS */
        call wait_c "Enter the filename to Download"    /* wait for text */
        do while lines(dwnpath||dwnfile) \= 0    /* til end of file */
           line = linein(dwnpath||dwnfile)       /* read line */
           if line \="" then
             do
             send line||cr                       /* send filenames */
             call wait_c "load (Enter)=none?"    /* wait to check  download */
             end                                 /* end if then do */
         end                                     /* end do while */
        Send cr                                  /* last line must be blank */
        call stream dwnpath||dwnfile, "command", "close"  /* close file , opened implicit with lines */
        getline                                  /* wait for a line */
        Correct_answer = Pos("Batch D/L Time:", zoclastline()) /* download 1 file or more? */
        say "**** Correct_answer:" Correct_answer
        say "**** Geline: "zoclastline()
        if Correct_answer = 0  then              /* got enter to continue */
          send cr                                /* no files to download */
        else
          do
          /*    Batch D/L Time:   4.9 minutes (approximate) */
          Approx_time = word(zoclastline(),4)    /* get number of minutes, 4th word */
          /* call wait_c "(P)rotocol, (Enter)=continue?" */
          /* Zoc rexx is to slow to catch this line. So don't wait. Just send enter */
          send cr                                /* Z-modem autostart within ZOC */
          timeout trunc(Approx_time*60*1.5)      /* wait approximate time to download x1.5 */
          call wait_c "Press (Enter) to continue?"    /* download ready */
          timeout waittime                       /* wait ñ1 minute */
          send cr                                /* continue */
          end                                    /* end if else */
        call wait_c "Main Board Command?"        /* wait on main menu */
        call delete_file dwnpath||dwnfile        /* if you want to delete the file */
        return

upload:
        send "U"cr                            /* start menu download on BBS */
        call wait_c "Enter the Filename to Upload (Enter)=none?"  /* wait for text */
        do while lines(uplpath||uplfile) \= 0
           line = linein(uplpath||uplfile)
           if line \="" then 
             do
             send line||cr          /* send filenames */
             call wait_c "? ("
             send "/a FILE_ID.DIZ in the upload should"cr
             call wait_c "? ("
             send "overwrite this file description"cr
             call wait_c "? ("
             send cr
             call wait_c "Enter the Filename to Upload (Enter)=none?"  /* wait for text */
             end                                 /* end if line */
        end                                      /* end do while */
        call stream uplpath||uplfile, "command", "close"  /* close file , opened implicit with lines */
        send cr
        call wait_c "(P)rotocol, (Enter)=continue?"     /* just start upload */
        loadopts Stannoau                        /* not automaticaly upload=user input */
        send cr                                  /* default protocol, no autostart within ZOC */
        timeout Waittimemail                     /* wait your ? minutes */
        do while lines(uplpath||uplfile) \= 0
           line = linein(uplpath||uplfile)
           if line \="" then 
             do
             upload Z line                       /* upload file */
             call wait_c "load (Enter)=none?"    /* wait to check  download !!!controleren!!!*/
             end                                 /* end if */
         end                                     /* end do while */
        call stream uplpath||uplfile, "command", "close"  /* close file , opened implicit with lines */
        loadopts Standardopts                    /* automatic upload */
        call wait_c "(H)ang up now, or press any other key to remain online"
        send cr
        call wait_c "Press (Enter) to continue?" /* download ready */
        send cr                                  /* continue */
        timeout Waittime                         /* wait ñ1 minute */
        call delete_file uplpath||uplfile        /* if you want to delete the file */
        call wait_c "Main Board Command?"        /* wait on main menu */
        return                                   /* back to main program */

getmail:
        send "QM;D;Y"cr                            /* load Quick Mail and Download messages */
        call wait_c "Qmail Command?"               /* just wait, doing noting */
        timeout Waittimemail                       /* wait Waittimemail seconds */
        reply '"Press any key to continue"' cr     /* Oke, we press */
        call wait_c  "You may use the command HELP [command] for extra information" 
        /* wait on menu from BBS Don't wait for Qmail Command, as this is echoed ?-times*/
        /* if the number of messages in a conference is larger than 400!*/
        reply '"Press any key to continue"'        /* cancel reply */
        timeout Waittime                           /* wait waittime seconds */
        if select_manual = "yes" then              /* every choice possible */
          do                                       /* so back to main menu */
          send "Q"cr                               /* back to main menu */
          call wait_c "Main Board Command?"        /* wait on main menu */
          end                                      /* end if select_manual */
        return

sendmail:
        if select_manual = "yes" | Collect_mail = "no" then /* yes or no */
          do
           send "QM"cr                           /* upload in the QWK Mail Services menu? */
           call wait_c "Qmail Command?"          /* just wait, doing noting */
          end                                    /* end if select_manual */
        send "U"cr                               /* select upload mail */
        call wait_c "Prepare to upload"          /* wait on signal to start */
        loadopts Noautoopts                      /* no automatic upload = user input! */
        upload Z Reppath||Repfile                /* upload file */
        loadopts Standardopts                    /* automatic download */
/* remove comments in position 1 if you don't logoff after the reply upload automatically
    and change Did_automatic_logoff to "no"

        call wait_c "Press (Enter) to continue?" /* wait until ready */
        send cr                                  /* answer on question from BBS */
        call wait_c "Qmail Command?"             /* wait on qmail menu */
*/
        call delete_file Reppath||Repfile        /* delete file */
        did_automatic_logoff = "yes"             /* prevent double logoff */
        if select_manual = "yes" then            /* every choice possible */
          do                                     /* so back to main menu */
          send "Q"cr                             /* back to main menu */
          call wait_c "Main Board Command?"      /* wait on main menu */
          end                                    /* end if select_manual */
        return

Delete_file:
         address cmd "del "arg(1)
         select
           when rc= 0 then say arg(1)' deleted successfully. '
           when rc= 1 then say '*** Error 'arg(1)' not found.'
           when rc= 2 then say '*** Error.  File not found. '
           when rc= 3 then say '*** Error.   Path not found. '
           when rc= 5 then say '*** Error.  Access denied. '
           when rc= 16 then say '*** Error.  Current directory. '
           when rc= 26 then say '*** Error.  Not DOS disk. '
           when rc= 32 then say '*** Error.  Sharing violation on 'arg(1)'. '
           when rc= 36 then say '*** Error.  Sharing buffer exceeded. '
           when rc= 87 then say '*** Error.  Invalid parameter. '
           when rc =108 then say '*** Error.  Drive locked. '
           when rc =206 then say '*** Error.  Filename exceeds range error. '
           otherwise say '*** Error. Source unknown'.
         end /* end select */
        return

play_tune:
        note.1 = 262    /* middle C */
        note.2 = 294    /*    D     */
        note.3 = 330    /*    E     */
        note.4 = 349    /*    F     */
        note.5 = 392    /*    G     */
        note.6 = 440    /*    A     */
        note.7 = 494    /*    B     */
        note.8 = 524    /*    C     */

        do i=1 to 8
        call beep note.i,250    /* hold each note for one-quarter second*/
        end
        return

Syntax:
    say ' A syntax condition was raised on line' sigl'!'
    say ' The error number is ' rc ', which means "'Errortext(rc)'"'
    problem_line = sigl
    Signal Abnormal_End

Halt:
    Say 'A Halt condition was raised on line' sigl'!'
    problem_line = sigl
    Signal Abnormal_End

Novalue:
    Say 'Novalue Condition raised on line' sigl'!'
    Say ' The variabele which  caused it is' Condition('Description')
    problem_line = sigl
    Signal Abnormal_end

Abnormal_End:
    Say ' That line is "'Sourceline(problem_line)'"'
    Say ' You can now debug if you want to.'
    Trace ?R
    Nop

Exit
/* END OF Lighthouse Rexx script */


[ RETURN TO DIRECTORY ]