home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 189.img / TCS120S.ZIP / WAITCALL.PAS < prev    next >
Pascal/Delphi Source File  |  1989-04-06  |  18KB  |  678 lines

  1. {$R-,S-,I-,D-,F+,V-,B-,N-,L+,O+ }
  2. {$M 65500,0,0 }
  3.  
  4. unit waitcall;
  5.  
  6. interface
  7.  
  8. uses dos,crt,graph,
  9.      gentypes,statret,configrt,modem,gensubs,subs1,subs2,mailret,
  10.      overret1,mainr1,mainr2,mainmenu,getlogin,userret;
  11.  
  12. function waitforacall:boolean;
  13.  
  14. implementation
  15.  
  16. function waitforacall:boolean;
  17.  
  18.   var wscount:integer;
  19.       mustgetbaud:boolean;
  20.  
  21.   procedure maybewritestatus;
  22.   begin
  23.     wscount:=wscount+1;
  24.     if wscount>15 then begin
  25.       writestatus;
  26.       wscount:=0
  27.     end
  28.   end;
  29.  
  30. (***
  31.  
  32.   function checkforhayesreport:boolean;  { Looks for CONNECT 300 }
  33.   var n:longint;
  34.       q:sstr;
  35.       p,b:integer;
  36.       k:char;
  37.       brate:baudratetype;
  38.   const lookfor:sstr=#13#10'CONNECT ';
  39.   begin
  40.     checkforhayesreport:=false;
  41.     if numchars=0 then exit;
  42.     p:=1;
  43.     q:='';
  44.     b:=0;
  45.     repeat
  46.       n:=now;
  47.       repeat until (now>n+1) or (numchars>0);
  48.       if numchars=0 then exit else k:=getchar;
  49.       if (k=#13) and (length(q)>0) then begin
  50.         val (q,b,p);
  51.         brate:=b110;
  52.         while (brate<=b9600) and
  53.               ((b<>baudarray[brate])
  54.                 or (not (brate in supportedrates)))
  55.               do brate:=succ(brate);
  56.         if brate<=b9600 then begin
  57.           parity:=false;
  58.           baudrate:=b;
  59.           checkforhayesreport:=true;
  60.           mustgetbaud:=false;
  61.           n:=now;
  62.           repeat until carrier or (now>n+1)
  63.         end;
  64.         exit
  65.       end;
  66.       if p>length(lookfor) then q:=q+k else begin
  67.         if k=lookfor[p] then p:=p+1 else begin
  68.           b:=b+1;
  69.           if b=2 then exit
  70.         end
  71.       end
  72.     until false
  73.   end;
  74.  
  75. ***)
  76.  
  77. { procedure receivecall;
  78.   var b:byte;
  79.       timeout,autoswitch:integer;
  80.       k:char;
  81.       brate:baudratetype;
  82.  
  83.     procedure nextrate (var b:baudratetype);
  84.     var ob:baudratetype;
  85.     begin
  86.       ob:=b;
  87.       repeat
  88.         b:=succ(b);
  89.         if b>b9600 then b:=b110;
  90.         if b=ob then exit
  91.       until b in supportedrates
  92.     end;
  93.  
  94.     procedure disconnect;
  95.     begin
  96.       if carrier then hangupmodem;
  97.       baudrate:=defbaudrate;
  98.       parity:=false;
  99.       setparam (usecom,baudrate,parity);
  100.       setupmodem
  101.     end;
  102.  
  103.     function seconds:integer;
  104.     var r:registers;
  105.     begin
  106.       r.ah:=$2c;
  107.       intr ($21,r);
  108.       seconds:=r.dh
  109.     end; }
  110.  
  111.   procedure receivecall;
  112.   var b:byte;
  113.       timeout,autoswitch:integer;
  114.       k:char;
  115.       brate:baudratetype;
  116.       matrix:anystr;
  117.       joemam:anystr;
  118.       brow:integer;
  119.  
  120.     procedure nextrate (var b:baudratetype);
  121.     var ob:baudratetype;
  122.     begin
  123.       ob:=b;
  124.       repeat
  125.         b:=succ(b);
  126.         if b>b9600 then b:=b110;
  127.         if b=ob then exit
  128.       until b in supportedrates
  129.     end;
  130.  
  131.     procedure disconnect;
  132.     begin
  133.       if carrier then hangupmodem;
  134.       baudrate:=defbaudrate;
  135.       parity:=false;
  136.       setparam (usecom,baudrate,parity);
  137.       setupmodem
  138.     end;
  139.  
  140.     function seconds:integer;
  141.     var r:registers;
  142.     begin
  143.       r.ah:=$2c;
  144.       intr ($21,r);
  145.       seconds:=r.dh
  146.     end;
  147.  
  148.   label abort,connected;
  149.   begin
  150.     local:=false;
  151.     online:=false;
  152.     textcolor (normbotcolor);
  153.     window (1,1,80,25);
  154.     clrscr;
  155.     window (1,1,80,24);
  156.     writeln ('[Auto-Detecting Baud Rate]');
  157.   begin
  158.      matrix:=' ';
  159.      online:=true;
  160.      delay (200);
  161.     {if numchars>0 then b:=ord(waitchar);
  162.     if numchars>0 then k:=waitchar else k:=' ';}
  163.     if numchars>0 then begin
  164.     delay (100);
  165.     while numchars>0 do matrix:=matrix+getchar;
  166.     if (b=ord('1')) and (k<>'0') and (k<>'1') and (k<>'2') then begin
  167.        baudrate:=baudarray[b300];
  168.        goto connected;
  169.        end;
  170.     if pos('5',matrix)>0  then begin
  171.        baudrate:=baudarray[b1200];
  172.        goto connected;
  173.        end;
  174.     if pos('12',matrix)>0    then begin
  175.        baudrate:=baudarray[b1200];
  176.        goto connected;
  177.        end;
  178.     if pos('24',matrix)>0  then begin
  179.        baudrate:=baudarray[b2400];
  180.        goto connected;
  181.        end;
  182.     if  pos('11',matrix)>0  then begin
  183.        baudrate:=baudarray[b2400];
  184.        goto connected;
  185.        end;
  186.     if  pos('96',matrix)>0  then begin
  187.        baudrate:=baudarray[b9600];
  188.        goto connected;
  189.        end;
  190.     if pos('10',matrix)>0 then begin
  191.        baudrate:=baudarray[b2400];
  192.        goto connected;
  193.        end;
  194.     writeln (usr,matrix);
  195. end;
  196.   begin
  197.     local:=false;
  198.     online:=false;
  199.     textcolor (normbotcolor);
  200.     window (1,1,80,25);
  201.     clrscr;
  202.     window (1,1,80,24);
  203.     if not mustgetbaud then goto connected;
  204.     writeln (usr,'╒═════════════════════════════════════════════════╕');
  205.     writeln (usr,'│             Someone is calling...               │');
  206.     writeln (usr,'│    Waiting for the user to press the CR key     │');
  207.     writeln (usr,'│ Press CR yourself to choose displayed Baud Rate │');
  208.     writeln (usr,'│ Press [Space] to advance to the next Baud Rate  │');
  209.     writeln (usr,'│        Press [D] to Disconnect the caller       │');
  210.     writeln (usr,'╘═════════════════════════════════════════════════╛');
  211.     writeln;
  212.     brate:=b110;
  213.     parity:=false;
  214.     timeout:=timer+2;
  215.     sendchar ('P');
  216.     sendchar ('r');
  217.     sendchar ('e');
  218.     sendchar ('s');
  219.     sendchar ('s');
  220.     sendchar (' ');
  221.     sendchar ('[');
  222.     sendchar ('R');
  223.     sendchar ('e');
  224.     sendchar ('t');
  225.     sendchar ('u');
  226.     sendchar ('r');
  227.     sendchar ('n');
  228.     sendchar (']');
  229.     sendchar (':');
  230.     repeat
  231.       nextrate (brate);
  232.       baudrate:=baudarray[brate];
  233.       textcolor (outlockcolor);
  234.       textbackground (0);
  235.       write (usr,^M^J'Trying ',baudrate,' Baud: ');
  236.       setparam (usecom,baudrate,parity);
  237.       while numchars>0 do k:=getchar;
  238.       autoswitch:=seconds+3;
  239.       if autoswitch>59 then autoswitch:=autoswitch-60;
  240.       repeat until (not carrier) or (numchars>0) or (keyhit) or
  241.                    (timer>=timeout) or (autoswitch=seconds);
  242.       if timer>=timeout then hangupmodem;
  243.       if not carrier then goto abort;
  244.       if keyhit
  245.         then
  246.           begin
  247.             k:=bioskey;
  248.             case upcase(k) of
  249.               #13:goto connected;
  250.               'D':goto abort;
  251.             end
  252.           end
  253.         else
  254.           begin
  255.             if numchars>0 then begin
  256.               b:=ord(getchar);
  257.               write (usr,b,' received.')
  258.             end else b:=0;
  259.             if b<>13
  260.               then if b=141
  261.                 then parity:=true
  262.                 else
  263.                   begin
  264.                     delay (200);
  265.                     while numchars>0 do b:=ord(getchar)
  266.                   end
  267.           end
  268.     until (b=13) or (b=141) or (timer>timeout);
  269.     if timer<=timeout then begin
  270.       connected:
  271.       setparam (usecom,baudrate,parity);
  272.       if parity
  273.         then baudstr:='E,7'
  274.         else baudstr:='N,8';
  275.       baudstr:=strr(baudrate)+','+baudstr+',1';
  276.       online:=true;
  277.       urec.config:=[lowercase,linefeeds,eightycols];
  278.       writestr (^M^M'Connected at '+baudstr+^M^M);
  279.       newcalls:=newcalls+1;
  280.       if carrier then exit
  281.     end;
  282.     abort:
  283.     disconnect
  284.   end;
  285.   end;
  286.   end;
  287.  
  288.   procedure exitprog;
  289.   begin
  290.     dontanswer;
  291.     window (1,1,80,25);
  292.     textcolor (15);
  293.     textbackground (0);
  294.     clrscr;
  295.     gotoxy (17,2);
  296.     writeln (usr,'┌──────────────────────────────────────────────┐');
  297.     gotoxy (17,3);
  298.     write (usr,'│ ');
  299.     textcolor (9);
  300.     write (usr,'TCS BBS Software version '+ver+' - '+parsedate(date));
  301.     textcolor (15);
  302.     writeln (usr,' │');
  303.     gotoxy (17,4);
  304.     write (usr,'│ ');
  305.     textcolor (11);
  306.     write (usr,'  (c) 1988,89 by the TCS Programming Team.   ');
  307.     textcolor (15);
  308.     writeln (usr,'│');
  309.     gotoxy (17,5);
  310.     writeln (usr,'└──────────────────────────────────────────────┘');
  311.     ensureclosed;
  312.     halt(4)
  313.   end;
  314.  
  315.   procedure checkday;
  316.   begin
  317.     if lastdayup<>datestr(now) then begin
  318.       lastdayup:=datestr(now);
  319.       numdaysup:=numdaysup+1;
  320.       callstoday:=0;
  321.       writestatus
  322.     end
  323.   end;
  324.  
  325.   procedure dotimedevent;
  326.   var tf:text;
  327.   begin
  328.     window (1,1,80,25);
  329.     clrscr;
  330.     writeln (usr,'Executing timed event: ',eventbatch);
  331.     writeln (usr);
  332.     assign (tf,'Door.bat');
  333.     rewrite (tf);
  334.     writeln (tf,eventbatch);
  335.     textclose (tf);
  336.     timedeventdate:=datestr(now);
  337.     ensureclosed;
  338.     halt (3)
  339.   end;
  340.  
  341.   function statusscreen:char;
  342.   const statwindx=5;
  343.         statwindy=1;
  344.         firstcolx=15;
  345.         firstline=5;
  346.         secondcolx=54;
  347.  
  348.     procedure col1;
  349.     begin
  350.       window (statwindx+firstcolx,statwindy+firstline,80,25);
  351.     end;
  352.  
  353.     procedure col2;
  354.     begin
  355.       window (statwindx+secondcolx,statwindy+firstline,80,25);
  356.     end;
  357.  
  358.     procedure percent (r1,r2:real);
  359.     begin
  360.       if (r2<1) then exit;
  361.       r2:=round((r1/r2)*1000)/10;
  362.       writeln (usr,r2:0:1,'%')
  363.     end;
  364.  
  365.     procedure drawstatus;
  366.     var totalidle,totalup,totalmins,r:real;
  367.         tmp:integer;
  368.     begin
  369.       col1;
  370.       tmp:=timetillevent;
  371.       if tmp<=30 then begin
  372.         gotoxy (1,0);
  373.         write (usr,'Timed event scheduled in ',tmp,' minutes!  ');
  374.         if tmp<=5 then begin
  375.           dontanswer;
  376.           if tmp<=2 then dotimedevent
  377.         end
  378.       end;
  379.       if carrier or keyhit then exit;
  380.       gotoxy (1,2);
  381.       writeln (usr,callstoday);
  382.       tmp:=elapsedtime (numminsidle);
  383.       write (usr,tmp);
  384.       gotoxy (1,6);
  385.       writeln (usr,numdaysup);
  386.       r:=round(10*numcallers/numdaysup)/10;
  387.       writeln (usr,r:0:1);
  388.       writeln (usr,timestr(now),' ');
  389.       write (usr,datestr(now),'  ');
  390.       col2;
  391.       gotoxy (1,3);
  392.       totalidle:=numminsidle.total+elapsedtime(numminsidle);
  393.       writeln (usr,totalidle:0:0);
  394.       totalup:=totalidle+numminsused.total;
  395.       writeln (usr,totalup:0:0);
  396.       totalmins:=1440.0*(numdaysup-1.0)+timer;
  397.       if (totalup<1) or (totalmins<1) then exit;
  398.       percent (numminsused.total,totalmins);
  399.       percent (numminsxfer.total,totalmins);
  400.       percent (totalidle,totalmins);
  401.       percent (totalup,totalmins);
  402.       percent (totalmins-totalup,totalmins);
  403.       col1;
  404.       gotoxy (1,1);
  405.       maybewritestatus
  406.     end;
  407.  
  408.     procedure writeavail;
  409.     var m:sstr;
  410.     begin
  411.       gotoxy (1,12);
  412.       m:=sysopavailstr;
  413.       while length(m)<15 do m:=m+' ';
  414.       write (usr,m);
  415.       gotoxy (1,1)
  416.     end;
  417.  
  418.   var cnt,numsmail:integer;
  419.       k:char;
  420.       tmp:mstr;
  421.       b:byte;
  422.       done:boolean;
  423.  
  424.     function shouldexit:boolean;
  425.     begin
  426.       shouldexit:=done or carrier
  427.     end;
  428.  
  429.     procedure handlekey (k:char; beforeabout:boolean);
  430.     begin
  431.       b:=ord(k)-128;
  432.       case b of
  433.         availtogglechar:begin
  434.           toggleavail;
  435.           if not beforeabout then writeavail
  436.         end;
  437.         59,60,61,62,63,64,65,66,67,68:begin
  438.           done:=true;
  439.           statusscreen:=k
  440.         end
  441.       end
  442.     end;
  443.  
  444.     function interrupted (beforeabout:boolean):boolean;
  445.     begin
  446.       if keyhit then begin
  447.         k:=bioskey;
  448.         handlekey (k,beforeabout)
  449.       end;
  450.       done:=done or carrier;
  451.       interrupted:=done
  452.     end;
  453.  
  454.     procedure sendstring (x:lstr);
  455.     var cnt:integer;
  456.         k:char;
  457.     begin
  458.       for cnt:=1 to length(x) do begin
  459.         sendchar(x[cnt]);
  460.         delay (20);
  461.       end;
  462.       delay (50);
  463.       while numchars>0 do k:=getchar
  464.     end;
  465.  
  466.     procedure phonesringing;
  467.     begin
  468.       sendstring ('  ATA'#13)
  469.     end;
  470.  
  471.     procedure connectcode (k:char);
  472.     var timer:word absolute $40:$6c;
  473.         t:word;
  474.         k2:char;
  475.         bd:baudratetype;
  476.     begin
  477.       t:=timer+18;
  478.       repeat
  479.       until (timer>t) or carrier or (numchars>0);
  480.       k2:=getchar;  { Will be #0 if no chars }
  481.       case k of
  482.         '1':case k2 of
  483.               #0:bd:=b300;
  484.               '0':bd:=b2400;
  485.               else exit
  486.             end;
  487.         '5':bd:=b1200;
  488.         else exit
  489.       end;
  490.       if bd in supportedrates then begin
  491.         parity:=false;
  492.         baudrate:=baudarray[bd];
  493.         mustgetbaud:=false;
  494.         t:=timer+18;
  495.         repeat until carrier or (timer>t)
  496.       end
  497.     end;
  498.  
  499.   begin
  500.     while numchars>0 do k:=getchar;
  501.     statusscreen:=#0;
  502.     done:=false;
  503.     window (1,1,80,25);
  504.     textcolor (normbotcolor);
  505.     clrscr;
  506.     window (statwindx,statwindy,80,25);
  507.     gotoxy (1,1);
  508.     if interrupted (true) then exit;
  509.  
  510. textcolor (4);
  511. writeln (usr,'                         ▄▄▄▄▄   ▄▄▄   ▄▄▄▄ ');
  512. textcolor (normbotcolor);
  513. write (usr,'                      ╒ ');
  514. textcolor (5);
  515. write (usr,'   █    █     █      ');
  516. textcolor (normbotcolor);
  517. writeln (usr,'╕');
  518. write   (usr,'╒═════════════════════╡');
  519. textcolor (1);
  520. write (usr,'    █    █      ▀▀▀▄  ');
  521. textcolor (normbotcolor);
  522. writeln (usr,'╞═════════════════════╕');
  523. textcolor (normbotcolor);
  524. write   (usr,'│                     ╘');
  525. textcolor (1);
  526. write (usr,'    █    ▀▄▄▄  ▄▄▄▄▀  ');
  527. textcolor (normbotcolor);
  528. writeln (usr,'╛                     │');
  529. writeln (usr,'│                                                                  │');
  530.     if interrupted (true) then exit;
  531. writeln (usr,'│ Last caller:                      Total mins used:               │');
  532. writeln (usr,'│ Calls today:                      Used by transfer:              │');
  533. writeln (usr,'│ Mins idle:                        Total mins idle:               │');
  534.     if interrupted (true) then exit;
  535. writeln (usr,'│ Sysop mail:                       Total mins up:                 │');
  536. writeln (usr,'│ Total calls:                      Percent used:                  │');
  537. writeln (usr,'│ Total days:                       Percent xfer:                  │');
  538.     if interrupted (true) then exit;
  539. writeln (usr,'│ Calls/day:                        Percent idle:                  │');
  540. writeln (usr,'│ Time:                             Percent up:                    │');
  541. writeln (usr,'│ Date:                             Percent down:                  │');
  542.     if interrupted (true) then exit;
  543. writeln (usr,'│ Recent calls:                     Recent uploads:                │');
  544. writeln (usr,'│ Recent posts:                     Recent feedback:               │');
  545. writeln (usr,'│ Available:                        Recent mail:                   │');
  546. writeln (usr,'│                                                                  │');
  547. writeln (usr,'╘══════════════════════════════════════════════════════════════════╛');
  548.     if interrupted (true) then exit;
  549.     window (1,1,80,25);
  550.     textcolor (outlockcolor);
  551.     if length(getenv('DSZLOG'))<1 then begin
  552.      gotoxy (1,25);
  553.      write ('     Put string "DSZLOG='+dszlog+'" in AUTOEXEC.BAT *NOW* !!!');
  554.     end;
  555.     gotoxy (1,21);
  556.     writeln (usr,'    [F10] Log on Locally     [F1] Terminal Program     [F2] Exit TCS');
  557.     writeln (usr,'    [F3] Not used            [F4] Read Feedback        [F5] System Log');
  558.     write   (usr,'    [Alt-A] Chat Availability');
  559.     if interrupted (true) then exit;
  560.     numsmail:=getnummail(1)+numfeedback;
  561.     tmp:=getlastcaller;
  562.     col1;
  563.     gotoxy (1,1);
  564.     textcolor (normtopcolor);
  565.     write (usr,copy(tmp,1,20));
  566.     gotoxy (1,4);
  567.     writeln (usr,numsmail);
  568.     write (usr,numcallers:0:0);
  569.     gotoxy (1,10);
  570.     writeln (usr,newcalls);
  571.     write (usr,newposts);
  572.     writeavail;
  573.     col2;
  574.     gotoxy (1,1);
  575.     writeln (usr,numminsused.total:0:0);
  576.     write (usr,numminsxfer.total:0:0);
  577.     gotoxy (1,10);
  578.     writeln (usr,newuploads);
  579.     writeln (usr,newfeedback);
  580.     write (usr,newmail);
  581.     repeat
  582.       checkday;
  583.       drawstatus;
  584.       cnt:=0;
  585.       repeat
  586.         while hashayes and (not carrier) and (numchars>0) do begin
  587.           k:=getchar;
  588.           case k of
  589.             '2':phonesringing;
  590.             '1','5':connectcode (k)
  591.           end
  592.         end;
  593.         cnt:=cnt+1
  594.       until (cnt>=10000) or interrupted (false) or done
  595.     until done
  596.   end;
  597.  
  598. var k:char;
  599. label exit;
  600. begin
  601.   waitforacall:=false;
  602.   setparam (usecom,defbaudrate,false);
  603.   setupmodem;
  604.   starttimer (numminsidle);
  605.   wscount:=0;
  606.   local:=false;
  607.   clrscr;
  608.   repeat
  609.     doanswer;
  610.     mustgetbaud:=true;
  611.     k:=statusscreen;
  612.     if carrier then begin
  613.       receivecall;
  614.       if carrier then goto exit;
  615.     end;
  616.     case ord(k)-128 of
  617.       59:begin
  618.           { local:=false;
  619.            online:=false;
  620.            writestatus;
  621.            waitforacall:=true;
  622.            goto exit }
  623.            clrscr;
  624.            halt (121);
  625.          end;
  626.       60:exitprog;
  627.       61:;
  628.       62:begin
  629.           window (1,1,80,25);
  630.           clrscr;
  631.            unum:=lookupuser (sysopname);
  632.              if unum=0 then begin
  633.                writeln ('No Sysop Created.');
  634.                delay (1000);
  635.               end;
  636.             unum:=1;
  637.             readurec;
  638.             urec.timetoday:=999;
  639.            readfeedback;
  640.           end;
  641.       63:begin
  642.           window (1,1,80,25);
  643.           clrscr;
  644.           unum:=lookupuser (sysopname);
  645.            if unum=0 then begin
  646.             writeln ('No Sysop Created.');
  647.             delay (1000);
  648.            end;
  649.           unum:=1;
  650.           readurec;
  651.           urec.timetoday:=999;
  652.           viewsyslog2;
  653.           delsyslog;
  654.           clrscr;
  655.          end;
  656.       68:begin
  657.            dontanswer;
  658.            local:=true;
  659.            online:=false;
  660.            newfeedback:=0;
  661.            newuploads:=0;
  662.            newcalls:=0;
  663.            newposts:=0;
  664.            newmail:=0;
  665.            writestatus;
  666.            goto exit
  667.          end
  668.     end
  669.   until 0=1;
  670.   exit:
  671.   textcolor (normbotcolor);
  672.   window (1,1,80,25);
  673.   clrscr
  674. end;
  675.  
  676. begin
  677. end.
  678.