home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / oct93 / comm / dcdd.lha / DCDD / DCDD.rexx < prev    next >
OS/2 REXX Batch file  |  1993-08-25  |  18KB  |  680 lines

  1. /*
  2.   DCDD.rexx                                                      930825.2308
  3.  
  4.  
  5.  
  6.                  DIRECT_CONNECT_DEMON DIALER  -  Version 1.8  
  7.  
  8.  
  9.   Use with Arexx Version 1.1 or better, BaudBandit 1.5 or better.
  10.   
  11.   Jerry Smith - Fresno, CA.             Contact BBS: F.A.A.X. (209) 226-7162
  12.  
  13.               Not copyrighted, fully in the public domain.
  14.       Various bits and pieces lifted from other PD ARexx programs.
  15.  
  16.   I would like to give special thanks to the following people:
  17.  
  18.     Dave Mullenix for his GREAT series of ARexx programs for dialing PC 
  19.     Pursuit. (Many of who's ideas are incorporated here)
  20.  
  21.     Darcy McConnell for the use of his BBS for tests, tests, tests, etc....
  22.  
  23.     Richard Stockton for his help with the Arexx and BaudBandit.
  24.  
  25.     My Wife and Best Friend (Diane) for her help, warmth and understanding.
  26.  
  27. */
  28.  
  29.  
  30. OPTIONS RESULTS
  31.  
  32. address BAUD 
  33.  
  34. parse arg filename
  35.  
  36. TRUE = (1=1)
  37. FALSE = ~ TRUE
  38. EXIT_TIMER = 0
  39.  
  40. if filename = '' then
  41.   DCDDPhone="DCDD"
  42. else
  43.   DCDDPhone=filename
  44.  
  45.  
  46. /* SHIFT F10 will stop this script before the next BBS is dialed
  47.              or break you out of a "stuck BBS"                    */
  48.  
  49. FKEY 'S10 \Mzap.continue.rexx' 
  50.  
  51. /*  GENERAL BAUDBANDIT SETTINGS BELOW                             */
  52.  
  53. mask on   /* turns on mask                                        */
  54.  
  55. set F     /* blanks screen w/form feed                            */  
  56.  
  57. set 8N1   /* set modem to 8N1                                     */  
  58.  
  59. set A     /* set default to Z modem (auto DL)                     */
  60.  
  61. Auto OFF
  62.  
  63. Popup OFF /* You MUST have this in your default config or else have the
  64.              Phone Book screen getting in you way. (see DCDD.doc) */
  65.  
  66. screen off  /* allows CON screen to come to the front */
  67.  
  68. Data 'RAM:-DL'  /* set up default download area for downloaded files */
  69.  
  70.  
  71.                     /* * * * * * * * * * * * * * * * * * * * 
  72.                       * * *  Open a full sized window * * *
  73.                      * * * * * * * * * * * * * * * * * * * */
  74.  
  75.  
  76. windev = "CON:1/11/640/189/ Direct Connect Demon Dialer . . . . . . . . . . . . phonebook "DCDDPhone
  77.  
  78. if ~open('wind',windev) then exit      /* Window for all activity */
  79.  
  80. NoError = 0
  81. NoTimeout = 0
  82.  
  83. maxnumbers = 80  /* maximum number of entries in phonebook */
  84.  
  85. call ReadPhoneBk
  86. call GetTotTime
  87.  
  88. temp= 'Hours used in' date(m)':' right(thours,2,'0')':'right(tmins,2,'0')':'right(tsecs,2,'0')
  89. call wsaych(temp)
  90. call wsay('  Select BBS(s):')
  91.  
  92. BBSelections = readln('wind')
  93.  
  94. screen on  /* turns BaudBandit screen on */
  95. send '\U'  /* brings BaudBandit screen to the front - here and now! 
  96.               The one in the main loop will bring the screen to the front
  97.               when a BBS is connected. */
  98.  
  99.  
  100. /* below allows you to enter an "A" as the first character in your BBSelections
  101.    to activate the AUTO function in Do_WHOEVER.rexx scripts. 
  102.  
  103.    See Do_FAAX.rexx for an example..... */
  104.  
  105. parse var BBSelections AUTO 2 .     
  106.  
  107. if upper(AUTO) = 'A' then do
  108.    address command 'makedir RAM:AUTO'
  109.    msg '********** -------------------- **********'
  110.    msg '********** AUTO PROCESS STARTED **********'
  111.    msg '********** -------------------- **********'
  112.    call delay(100)
  113.    end
  114.  
  115. /* below allows BBS number(s) separated by ,./;:\|+-*# or space(s) */
  116. y=translate(BBSelections,' ',',Aa./;:\|=+_*#') 
  117.  
  118. bbs2call=0
  119. do i = 1 to bbsnums
  120.   parse var y first y
  121.   bbs2call=bbs2call+1
  122.   bbs.i = first
  123.   if first == '' then leave  /* breaks out of DO FOREVER loop */
  124. end
  125.  
  126. bbs2call=bbs2call-1
  127. msg ' '
  128. msg bbs2call 'Selected BBSes to be Called'
  129. msg_x_flag = ' '
  130.  
  131. do z=1 to bbs2call
  132.   t=bbs.z
  133.   msg_x = ' '
  134.   do    /* below tests for AREXX SCRIPT in BBS for AUTO process */
  135.      if UPPER(AUTO) = 'A' then do 
  136.         if bbs.t.script = ' ' then do
  137.            msg_x = '****** MISSING AREXX SCRIPT ******'
  138.            msg_x_flag = 'bad'
  139.         end
  140.      end
  141.   end 
  142.   msg z':' bbs.t.name '  ' msg_x
  143. end 
  144.  
  145. if msg_x_flag = 'bad' then do
  146.    bbs2call = 0
  147.    msg ' '
  148.    msg ' '
  149.    msg '****** AUTO PROCESS ERROR - MISSING AREXX SCRIPT ******'
  150.    msg ' '
  151.    msg '10'
  152.    call delay(50)
  153.    msg '  9'
  154.    call delay(50)
  155.    msg '    8'
  156.    call delay(50)
  157.    msg '       7'
  158.    call delay(50)
  159.    msg '           6'
  160.    call delay(50)
  161.    msg '                5'
  162.    call delay(50)
  163.    msg '                       4'
  164.    call delay(50)
  165.    msg '                                3'
  166.    call delay(50)
  167.    msg '                                           2'
  168.    call delay(50)
  169.    msg '                                                          1'
  170.    call delay(50)
  171. end 
  172.  
  173.  
  174. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  175.  *                                                               *
  176.  *                          Main Loop                            *
  177.  *                                                               *
  178.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  179.  
  180.  
  181. listindex=1 ;
  182. do while bbs2call ~= 0                                        
  183.  
  184.   indx = bbs.listindex
  185.   
  186.   msg ''
  187.   if upper(AUTO) = 'A' then 
  188.      msg 'AUTO >> Dialing:' bbs.indx.name 
  189.   else
  190.      msg 'Dialing:' bbs.indx.name
  191.  
  192.   bbsconnect = false
  193.   nresult = ' '
  194.  
  195.   call at_codes  /* send AT codes to modem for selected BBS. This is VERY
  196.                     useful when using a SupraFAXmodem V32.bis at 14.4 */ 
  197.  
  198.      if CallBBS(bbs.indx.phone) = NoTimeout then do      
  199.        if pos('CARRIER',nresult) = 1 then do                 
  200.  
  201.          call time(R) 
  202.         
  203.          dateYYYYMM=left(date(sorted),6)               
  204.          dateYYMMDD=right(date(sorted),6)              
  205.          timea=translate(time(n),' ',':')              
  206.          parse value timea with timeHH timeMM timeSS .  
  207.          timeHHMM=timeHH||timeMM 
  208.  
  209.          beep 
  210.  
  211.   send '\u' /* (pull screen to front when bbs connected) 
  212.                You may or may not want to use this here. */
  213.  
  214.  /* Capt "RAM:-dl below puts all Capture Logs in to this dir */
  215.  
  216.           if bbs.indx.captitle ~= '' then                
  217.             Capt 'RAM:-dl/'bbs.indx.captitle'.'dateYYMMDD'.'timeHHMM'.1'    
  218.  
  219.  /* above gives you files like OLD_DOC.930719.1718.1 - Had to add time so
  220.     that files opened up on RAM:-dl would not duplicate files in DH1:-dl 
  221.     when they are transfered after logging out of a BBS. Really do need to
  222.     download into RAM when doing V32.bis 14.4 with a 68000 native CPU. */
  223.  
  224.           if bbs.indx.script ~= '' then do                    
  225.             title = bbs.indx.script
  226.             msg 'Starting Arexx Script: ' title
  227.             interpret 'call' title
  228.           end                                                 
  229.  
  230.           call DoPairs
  231.  
  232.           call wait4disconnect
  233.  
  234.           Capture OFF  
  235.           
  236. /* items below copy ALL data in RAM:-dl to DH1:-dl 
  237.          and then clears RAM:-dl for the next BBS called.
  238.  
  239.    At the end of a days BBSing I create a file called DH1:-dl-YYMMDD
  240.       and copy the contents of DH1:-dl into it and then clear DH1:-dl
  241.       for the next days activity. */
  242.  
  243. /* BE SURE DH1: has room for the files you DL!!!!!!!!!!!!!!!!! */
  244.  
  245.           address command 'copy RAM:-dl/#? DH1:-dl'
  246.           address command 'delete RAM:-dl/#?'
  247.  
  248.           call removebbs /* remove bbs from selection group */
  249.  
  250.         end
  251.  
  252.         send '\d'   /* drop DTR */
  253.         send '\ah'  /* hangs up modem */
  254.  
  255.         call selectnextbbs /* select next bbs from selection group */
  256.  
  257.         end                                                       
  258.  
  259.   call CONTINUE_TEST  /* test for ram:continue as flag to continue or quit*/
  260.  
  261.   if listindex > bbs2call then 
  262.      listindex = 1
  263.  
  264. end
  265.  
  266. /* next two lines force DCDD.rexx to quit */
  267.  
  268. address command 'delete RAM:continue'    
  269. call CONTINUE_TEST    
  270.  
  271. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  272.  *                                                             *
  273.  *                   Functions / Subroutines                   *
  274.  *                                                             *
  275.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  276.  
  277.  
  278. Continue_Test:
  279.  
  280. /* tests for RAM:continue as flag to continue or quit */
  281.  
  282. if exists('ram:continue')=0 then do
  283.    call delay(50)
  284.    msg ' '
  285.    msg ' '        
  286.    msg '**************************************************'
  287.    msg '*****                                       ******'
  288.    msg '***** EXITING * DIRECT CONNECT DEMON DIALER ******'
  289.    msg '*****                                       ******'
  290.    msg '**************************************************'
  291.    capture OFF  
  292.    call close('wind')
  293.    send '\d'   /* drop DTR */
  294.    send '\ah'  /* hangs up modem */
  295.    send '\aq'  /* closes BaudBandit  */
  296.    exit        /* exits Arexx        */
  297.    end
  298. else do
  299.    call delay(10)
  300.    beep
  301.    call delay(10)
  302.    beep
  303.    end
  304. return
  305.  
  306.  
  307. AT_codes:
  308.  
  309. /* sends special AT codes for currently selected BBS to modem */
  310.  
  311.    send 'AT&F2'  /* resets modem to factory settings          */
  312.    send '\w\r' 
  313.    send 'AT&F2'  /* resets modem to factory settings 2nd time */
  314.    send '\w\r'   /* don't know why it needs it but it do!     */ 
  315.  
  316. /* W1 below is necessary to set the CARRIER option so that the
  317.       baud rate at connect is captured.  */
  318.  
  319.   if bbs.indx.atcodes ~= '' then do 
  320.     send 'AT W1 'bbs.indx.atcodes
  321.     send '\w\r'
  322.     msg 'AT codes sent to modem - ' bbs.indx.atcodes
  323.     end
  324.   else do
  325.     send 'AT M W1'   /* M = speaker off, W1 = carrier - etc. */
  326.     send '\w\r' 
  327.     end
  328. return
  329.  
  330.  
  331. Wsay:
  332.  
  333. /* put string to window with EOL */
  334.  
  335.   parse arg strx   
  336.   call writeln('wind',strx)
  337. return
  338.  
  339.          
  340. WsayCH:
  341.   
  342. /* put string to window without EOL */
  343.  
  344.   parse arg strx   
  345.   call writech('wind',strx)
  346. return
  347.  
  348.          
  349. DoPairs:
  350.  
  351. /* Have BaudBandit execute script pairs just like in Phonebook */
  352.  
  353. /* Some BBS software needs an ESCAPE key (or two) to load and this can be
  354.    taken care of using a Script Pair that starts like:
  355.  
  356.    {Escape twice=\w\x1B\w\x1B\w\r}{....then your remaining stuff....
  357.  
  358. */
  359.  
  360.  if bbs.indx.pair ~= '' then do /* Do optional pairs after connect */
  361.     address BAUD 
  362.     pairs bbs.indx.pair
  363.  end 
  364.  
  365. return
  366.  
  367.  
  368. wait4disconnect:
  369.  
  370. if upper(AUTO) ~= 'A' then do
  371.   msg ''
  372.   msg '+--------------------------------------+'
  373.   msg '  WAITING FOR 'bbs.indx.name' DISCONNECT '
  374.   msg '+--------------------------------------+'
  375. end
  376.  
  377.   call delay(150) 
  378.  
  379.   do forever
  380.      ADDRESS BAUD
  381.      dcd
  382.  
  383. /*   note: RTEST holds RC value as RC resets after every Arexx command
  384.            is executed. */
  385.  
  386.      RTEST = RC
  387.      if RTEST = 0 then leave  /* breaks out of DO FOREVER loop */
  388.      call delay(250)  /* 5 second delay for FOREVER loop */
  389.  
  390. /* below uses shift F10 to get out of a "STUCK BBS". 
  391.    this routine also used for Arexx Script failed WAIT LOOP exiting. */
  392.  
  393.       if exists('ram:continue')=0 then do
  394.          msg '****** FORCED BBS LOGOFF BY USER ******'
  395.          address command 'makedir ram:continue'
  396.          call delay(50) 
  397.          leave    /* breaks out of DO FOREVER loop */
  398.       end
  399.  
  400. /* NOTE: process below replaced by NESTED DO FOREVER/WAIT LOOPS 
  401.          see Do_FAAX.rexx for an example... */
  402.  
  403. /* below uses RAM:exit_flag to get out of a "STUCK BBS" when 
  404.    you are using Arexx scripts for Auto late nite sessions
  405.    and want to be sure of exiting a BBS if they have changed
  406.    things and your script gets "HUNG UP". The EXIT_TIMER will
  407.    be reset to zero if RAM:exit_flag is abscent.  */
  408.  
  409.      if exists('ram:exit_flag')=0 then do 
  410.         exit_timer = 0
  411.         end
  412.      else do  
  413.         exit_timer = exit_timer + 5
  414.         if exit_timer > 300 then do 
  415.            msg '****** FORCED LOGOFF BY EXIT_TIMER ******'
  416.            call delay(50) 
  417.            address command 'delete ram:EXIT_TIMER'
  418.            leave     /* breaks out of DO FOREVER loop */
  419.            end
  420.         end
  421.  
  422.   end
  423.  
  424. /*  below is old OLD way of holding till logged off BBS.
  425.     it had a "BIG" problem with matching text during DL's.
  426.  
  427.     wait 'NO CARRIER'
  428.  
  429. */
  430.  
  431. /* Get connection elapsed time from Arexx timer */
  432.  
  433.   timeE=(time(e)) 
  434.   chours = timeE % 3600
  435.   choursrem = timeE // 3600
  436.   cmins = choursrem % 60
  437.   csecsx = choursrem // 60
  438.   csecs = csecsx % 1
  439.   cTOTAL = right(chours,2,'0')':'right(cmins,2,'0')':'right(csecs,2,'0')
  440.  
  441.   msg 'Updating Total Time'
  442.   discotitle='DCDDdiscos.'dateYYYYMM   
  443.   if open('discos',discotitle,'Append') = 0 then /* string for reference */
  444.      call open('discos',discotitle,'Write')  /* Append it to monthly file */
  445.      temp = dateYYMMDD timeHHMM cTOTAL bbs.indx.name SPEED 
  446.      call writeln('discos',temp)
  447.      call close('discos')
  448.  
  449.      timetitle='DCDDtime.'dateYYYYMM                
  450.  
  451.   if open('TotTime',timetitle,'R')=0 then do /* Total hours, mins, secs */
  452.      thours = 0
  453.      tmins = 0                     /* If file doesn't exist, set to zero */
  454.      tsecs = 0
  455.      end
  456.  
  457.      else do
  458.      thours=readln('TotTime')      /* If file does exist, read them */
  459.      tmins=readln('TotTime')
  460.      tsecs=readln('TotTime')
  461.      call close('TotTime')
  462.      end
  463.  
  464.   msg 'Monthly total:' right(thours,2,'0')':'right(tmins,2,'0')':'right(tsecs,2,'0')
  465.   msg '    This call:' cTOTAL
  466.   nhours = chours+thours
  467.  
  468.   if csecs > 0 then do  /* the Damn phone company rounds  */ 
  469.      cmins = cmins + 1  /* any seconds into a full minute */
  470.      csecs = 0        
  471.   end
  472.     
  473.   nmins = cmins+tmins
  474.   nsecs = csecs+tsecs
  475.  
  476.   nmins=nmins+nsecs%60 ; nsecs = nsecs//60
  477.   nhours=nhours+nmins%60 ; nmins = nmins//60
  478.  
  479. /* If bbs.indx.local = LOCAL do not update TotTime */
  480.  
  481.   if bbs.indx.local = '' then do 
  482.  
  483.      call open('TotTime',timetitle,'W')
  484.      call writeln('TotTime', nhours)
  485.      call writeln('TotTime', nmins)
  486.      call writeln('TotTime', nsecs)
  487.      call close('TotTime')
  488.      msg '               --------'
  489.      msg '    New Total:' right(nhours,2,'0')':'right(nmins,2,'0')':'right(nsecs,2,'0')
  490.      end
  491.   else do
  492.     msg 'Local BBS - TotTime not updated'
  493.     end
  494.  
  495. return
  496.  
  497.  
  498. removebbs:    
  499.  
  500. /* Done with that bbs, change ALL occurances to "called" in selection group */
  501.  
  502.   do j = 1 to bbs2call                  
  503.      if bbs.j = indx then do
  504.         bbs.j = 'called'
  505.      end                     
  506.   end                                   
  507.  
  508. return
  509.  
  510.  
  511. selectnextbbs:    
  512.  
  513. /* Select the next available BBS from selection group */
  514.  
  515.   yet2call = 0
  516.   wascalled = 0
  517.  
  518.   do k = 1 to bbs2call                         
  519.      if bbs.k = 'called' then do        
  520.         wascalled = wascalled + 1
  521.      end                                
  522.      else do                     
  523.         yet2call = yet2call + 1
  524.      end                         
  525.   end                                          
  526.  
  527.   if yet2call = 0 then do              
  528.      bbs2call = 0  
  529.      end                                  
  530.   else do                       
  531.  
  532.      loopcount = 0 
  533.  
  534.         do forever                           
  535.  
  536.         listindex=listindex + 1
  537.  
  538.         if listindex > bbs2call then        
  539.            listindex = 1
  540.            loopcount = loopcount + 1
  541.  
  542.         if bbs.listindex ~= 'called' then
  543.            leave   /* breaks out of DO FOREVER loop */
  544.  
  545.  
  546.         if loopcount > 2 then do  
  547.            msg '****** loopcount > 2 ******'
  548.            bbs2call = 0
  549.            leave   /* breaks out of DO FOREVER loop */
  550.  
  551.         end                       
  552.  
  553.      end                                          
  554.  
  555.      livecount = 0
  556.  
  557.      if yet2call ~= 0 or exists('ram:continue')=0 then do              
  558.         msg ' ' 
  559.         msg yet2call ' BBSes yet to be called'
  560.         do z=1 to bbs2call                            
  561.            t=bbs.z
  562.            if bbs.z ~= 'called' then do       
  563.               livecount = livecount + 1
  564.               msg livecount ':' bbs.t.name
  565.            end                                
  566.         end
  567.       end                                           
  568.   end                           
  569.  
  570. return
  571.  
  572.  
  573. CallBBS:
  574.  
  575. /* Dial Selected BBS */
  576.  
  577.   arg number
  578.   call delay(25)
  579.   timeout 120     /* wait continues if no connectstring within 2 minutes */
  580.   send 'ATDT'number'\r'
  581.   call shownotes
  582.   connectstring='CARRIER 14400,CARRIER 12000,CARRIER 9600,CARRIER 7200,CARRIER 2400,BUSY,OK,NO CARRIER,NO DIALTONE'
  583.   wait connectstring
  584.   NRC = RC
  585.   NRESULT = RESULT  
  586.   parse value NRESULT with AAA SPEED .
  587.  
  588. /* SPEED above used to capture arbitated carrier connect speed */
  589.  
  590. /* msg 'CALLBBS: nresult = ' nresult ' NRC = ' NRC */
  591.  
  592. return NRC
  593.  
  594.  
  595. shownotes:
  596.  
  597. /* Show BBS notes if present */
  598.  
  599.   if bbs.indx.notenum > 0 then do     
  600.     msg 'Notes for' bbs.indx.name':'
  601.     do notex = 1 to bbs.indx.notenum
  602.       msg bbs.indx.notes.notex
  603.     end
  604.   end
  605.  
  606.   else do
  607.      msg 'No notes for' bbs.indx.name
  608.   end
  609.   msg ' '
  610. return
  611.  
  612.  
  613. GetTotTime:
  614.  
  615. /* gets total time for the month */
  616.  
  617.   timetitle='DCDDtime.'left(date('S'),6)             /* DCDDtime.YYYYMM */
  618.   if open('TotTime',timetitle,'R')=0 then do /* Total hours, mins, secs */
  619.     thours = 0
  620.     tmins = 0                     /* If file doesn't exist, set to zero */
  621.     tsecs = 0
  622.   end
  623.  
  624.   else do
  625.     thours=readln('TotTime')      /* If file does exist, read them */
  626.     tmins=readln('TotTime')
  627.     tsecs=readln('TotTime')
  628.     call close('TotTime')
  629.   end
  630. return
  631.  
  632.  
  633. ReadPhoneBk:
  634.  
  635. /* Read Phone Book into Arexx array */
  636.  
  637. call open('PhoDir','Bandit.'DCDDPhone,'r')
  638.  
  639. bbsnums = 0                            /* Read BBS records */
  640. inline1=readln('PhoDir')
  641. do j=1 to maxnumbers until eof('PhoDir')
  642.   bbsnums = bbsnums + 1
  643.   bbs.j.name=strip(readln('PhoDir'))
  644.   bbs.j.phone=strip(readln('PhoDir'))
  645.   bbs.j.local=strip(readln('PhoDir'))
  646.   bbs.j.atcodes=strip(readln('PhoDir'))
  647.   bbs.j.captitle=strip(readln('PhoDir'))
  648.   bbs.j.script=strip(readln('PhoDir'))
  649.   bbs.j.pair=strip(readln('PhoDir'))
  650.  
  651.   /* Read optional notes */
  652.   notex=0 ; inline1=''
  653.   do until inline1 = '-----' | EOF('PhoDir')
  654.     inline1=readln('PhoDir')
  655.     if inline1 ~= '-----' then do
  656.       notex = notex + 1
  657.       bbs.j.notes.notex = inline1
  658.     end
  659.   end
  660.   bbs.j.notenum = notex
  661.  
  662.   /* Print BBS name */
  663.  
  664.   if j//4 ~= 0 then /* allows four across on CON window */
  665.  
  666. /* I use bbs.j.captitle instead of bbs.j.name below because all my files 
  667.    use the same name as my discos and capture files and I only have to 
  668.    remember one name. The FULL name is used when you connect to a BBS */
  669.  
  670.     call wsaych(right(j,2,' ')': 'left(bbs.j.captitle,15,' '))
  671.   else
  672.     call wsay(right(j,3,' ')': 'left(bbs.j.captitle,15,' '))
  673. end  
  674. call close('PhoDir')
  675.  
  676. bbsnums=bbsnums-1
  677. if bbsnums//2 = 0 then 
  678.   call wsay('')
  679. return
  680.