home *** CD-ROM | disk | FTP | other *** search
/ norge.freeshell.org (192.94.73.8) / 192.94.73.8.tar / 192.94.73.8 / pub / computers / pcjr / comm / TLXPCP10.LZH / CITYDIAL.SLT < prev    next >
Text File  |  1988-12-10  |  18KB  |  644 lines

  1. //These are the user configurable variables of this script
  2.  
  3. str user_id[10]="XXXXXXXX",
  4.     password[10]="YYYYYYYY",
  5.     busy_tone[]="Y",
  6.     message_tone[]="y",
  7.     connect_tone[]="y";
  8.  
  9.  
  10. ///////////////////////////////////////////////////////////////////////////////
  11. //                                                                           //
  12. //                  citydial v1.0 Copyright (c) by Charles Lee               //
  13. //                            November 1988                                  //
  14. //                                                                           //
  15. ///////////////////////////////////////////////////////////////////////////////
  16.  
  17. //Declare the dialing arrays
  18. str city_str[1000],
  19.     city_dial_str[1000],
  20.     city_search_buffer[1000];
  21.  
  22. connect_alarm()
  23. {
  24.     if((connect_tone=="y")|(connect_tone=="Y"))
  25.     {
  26.         alarm(2);
  27.     }
  28. }
  29.  
  30. beep(int freq)
  31. {
  32.     if((message_tone=="y")|(message_tone=="Y"))
  33.     {
  34.         tone(freq,20);
  35.     }
  36. }
  37.  
  38. display_cities(int start)
  39. {
  40.     str highlight_test[10],
  41.         buffer[10];
  42.     int count;
  43.  
  44.     for(count=0;count<20;count=count+1)
  45.     {
  46.         substr(city_dial_str,((start+count)*8),8,highlight_test);
  47.         substr(city_str,((start+count)*8),8,buffer);
  48.         if(highlight_test=="********")
  49.         {
  50.             pstraxy(" ",26,(count+2),14);
  51.             pstraxy(buffer,27,(count+2),14);
  52.             pstraxy(" ",35,(count+2),14);
  53.         }
  54.         else
  55.        {
  56.             pstraxy(" ",26,(count+2),0x1f);
  57.             pstraxy(buffer,27,(count+2),0x1f);
  58.             pstraxy(" ",35,(count+2),0x1f);
  59.        }
  60.     }
  61. }
  62.  
  63. display_bar(int menu_bar_pos,int city_bar_pos)
  64. {
  65.     str buffer[10];
  66.  
  67.     substr(city_str,(city_bar_pos*8),8,buffer);
  68.     pstraxy(" ",26,(menu_bar_pos+2),0x4f);
  69.     pstraxy(buffer,27,(menu_bar_pos+2),0x4f);
  70.     pstraxy(" ",35,(menu_bar_pos+2),0x4f);
  71. }
  72.  
  73.  
  74. un_display_bar(int menu_bar_pos,int city_bar_pos)
  75. {
  76.     str buffer[10],
  77.         highlight_test[10];
  78.  
  79.     substr(city_str,(city_bar_pos*8),8,buffer);
  80.     substr(city_dial_str,(city_bar_pos*8),8,highlight_test);
  81.     if(highlight_test=="********")
  82.     {
  83.         pstraxy(" ",26,(menu_bar_pos+2),14);
  84.         pstraxy(buffer,27,(menu_bar_pos+2),14);
  85.         pstraxy(" ",35,(menu_bar_pos+2),14);
  86.     }
  87.     else
  88.     {
  89.         pstraxy(" ",26,(menu_bar_pos+2),0x1f);
  90.         pstraxy(buffer,27,(menu_bar_pos+2),0x1f);
  91.         pstraxy(" ",35,(menu_bar_pos+2),0x1f);
  92.     }
  93. }
  94.  
  95.  
  96. dial_these()
  97. {
  98.     str buffer[10],
  99.         highlight_test[10],
  100.         pcp_cities_file[76],
  101.         pcp_dial_queue[76];
  102.  
  103.     int fp,
  104.         done=0,
  105.         menu_bar_pos=0,
  106.         city_bar_pos=0,
  107.         menu_top=0,
  108.         city_str_amt=0,
  109.         menu_scroll=1,
  110.         key,
  111.         last_char;
  112.  
  113.     //Build city_str
  114.     pcp_cities_file=_script_dir;
  115.     strcat(pcp_cities_file,"cities.pcp");
  116.     fp=fopen(pcp_cities_file,"r");
  117.     if(!fp)
  118.     {
  119.         beep(500);
  120.         status_wind("Can't find PC Pursuit City file!.  Aborting.",10);
  121.         return 0;
  122.     }
  123.     while(fread(buffer,8,fp)==8)
  124.     {
  125.         fseek(fp,2,1);
  126.         strcat(city_str,buffer);
  127.         city_str_amt=city_str_amt+1;
  128.     }
  129.     fclose(fp);
  130.  
  131.     pcp_dial_queue=_script_dir;
  132.     strcat(pcp_dial_queue,"queue.pcp");
  133.     fp=fopen(pcp_dial_queue,"r");
  134.     if(!fp)
  135.     {
  136.         //The dialing queue doesn't exist.  Create it.
  137.         for(fp=0;fp<city_str_amt;fp=fp+1)
  138.         {
  139.             strcat(city_dial_str,"********");
  140.         }
  141.     }
  142.     else
  143.     {
  144.         fread(city_dial_str,1000,fp);
  145.         fclose(fp);
  146.     }
  147.     box(25,1,36,22,3,0,11);
  148.     box(38,10,66,12,3,0,11);
  149.     pstraxy("PC Pursuit City Menu",43,11,15);
  150.     pstraxy("  moves select bar   ",40,14,12);
  151.     pstraxy("Space selects/deselects",40,15,12);
  152.     pstraxy("C clears all selected  ",40,16,12);
  153.     pstraxy("┘ exits to city dialer",40,17,12);
  154.  
  155.     _scr_chk_key=0;
  156.     cursor_onoff(0);
  157.  
  158.     while(!done)
  159.     {
  160.         cursor_onoff(0);
  161.         if(menu_scroll)
  162.         {
  163.             display_cities(menu_top);
  164.             menu_scroll=0;
  165.         }
  166.         while(1)
  167.         {
  168.            display_bar(menu_bar_pos,city_bar_pos);
  169.            //Get key pressed and empty the keyboard buffer
  170.            key=inkeyw();
  171.            last_char=1;
  172.            while(last_char)
  173.            {
  174.                 last_char=inkey();
  175.            }
  176.            un_display_bar(menu_bar_pos,city_bar_pos);
  177.             //Up key
  178.             if(key==0x4800)
  179.             {
  180.                 if(menu_bar_pos==0)
  181.                 {
  182.                     if(city_bar_pos==0)
  183.                     {
  184.                         beep(500);
  185.                     }
  186.                     else
  187.                     {
  188.                         menu_top=menu_top-20;
  189.                         city_bar_pos=city_bar_pos-1;
  190.                         menu_bar_pos=19;
  191.  
  192.                         if(menu_top<0)
  193.                         {
  194.                             menu_top=0;
  195.                             city_bar_pos=19;
  196.                         }
  197.                         menu_scroll=1;
  198.                     }
  199.                 }
  200.                 else
  201.                 {
  202.                     menu_bar_pos=menu_bar_pos-1;
  203.                     city_bar_pos=city_bar_pos-1;
  204.                 }
  205.                 break;
  206.             }
  207.  
  208.             //Dn key
  209.             if(key==0x5000)
  210.             {
  211.                 if(menu_bar_pos==19)
  212.                 {
  213.                     if(city_bar_pos==(city_str_amt-1))
  214.                     {
  215.                         beep(500);
  216.                     }
  217.                     else
  218.                     {
  219.                         city_bar_pos=city_bar_pos+1;
  220.                         menu_top=menu_top+20;
  221.                         menu_bar_pos=0;
  222.                         if((menu_top+20)>city_str_amt)
  223.                         {
  224.                             menu_top=city_str_amt-20;
  225.                             city_bar_pos=city_str_amt-20;
  226.                         }
  227.                         menu_scroll=1;
  228.                     }
  229.                 }
  230.                 else
  231.                 {
  232.                     menu_bar_pos=menu_bar_pos+1;
  233.                     city_bar_pos=city_bar_pos+1;
  234.                 }
  235.                 break;
  236.             }
  237.  
  238.             //Space key
  239.             if(key==0x20)
  240.             {
  241.                 menu_scroll=1;
  242.                 subchrs(city_str,(8*city_bar_pos),8,buffer);
  243.                 subchrs(city_dial_str,(8*city_bar_pos),8,highlight_test);
  244.                 if(highlight_test=="********")
  245.                 {
  246.                     copychrs(buffer,city_dial_str,(8*city_bar_pos),8);
  247.                 }
  248.                 else
  249.                 {
  250.                     copychrs("********",city_dial_str,(8*city_bar_pos),8);
  251.                 }
  252.                 beep(3000);
  253.                 break;
  254.             }
  255.  
  256.             //Enter key
  257.             if(key==0x0d)
  258.             {
  259.                 done=1;
  260.                 break;
  261.             }
  262.             if((key=='c')|(key=='C'))
  263.             {
  264.                 city_dial_str="";
  265.                 menu_bar_pos=0;
  266.                 city_bar_pos=0;
  267.                 menu_top=0;
  268.                 menu_scroll=1;
  269.                 beep(3000);
  270.                 status_wind("Clearing all selected cities!",10);
  271.  
  272.                 for(fp=0;fp<city_str_amt;fp=fp+1)
  273.                 {
  274.                     strcat(city_dial_str,"********");
  275.                 }
  276.                 break;
  277.             }
  278.  
  279.             beep(500);
  280.             status_wind("Unknown command!",10);
  281.             cursor_onoff(0);
  282.         }
  283.     }
  284.     //Save the highlighted cities
  285.     fp=fopen(pcp_dial_queue,"w+");
  286.     fwrite(city_dial_str,strlen(city_dial_str),fp);
  287.     fputc(0,fp);
  288.     fclose(fp);
  289.  
  290.     //Remove * from city_dial_str
  291.     for(fp=0;fp<strlen(city_dial_str);fp=fp+8)
  292.     {
  293.         if(subchr(city_dial_str,fp)=='*')
  294.         {
  295.             delchrs(city_dial_str,fp,8);
  296.             fp=fp-8;
  297.         }
  298.     }
  299.     return (strlen(city_dial_str)/8);
  300.  
  301. }
  302. dequeue(str city)
  303. {
  304.     int fp,
  305.         status;
  306.  
  307.     str pcp_dial_queue[76];
  308.  
  309.     pcp_dial_queue=_script_dir;
  310.     strcat(pcp_dial_queue,"queue.pcp");
  311.     fp=fopen(pcp_dial_queue,"r");
  312.     fread(city_search_buffer,1000,fp);
  313.     fclose(fp);
  314.  
  315.     status=strpos(city_search_buffer,city,0);
  316.     if(status!=-1)
  317.     {
  318.         copychrs("********",city_search_buffer,status,8);
  319.         fp=fopen(pcp_dial_queue,"w+");
  320.         fwrite(city_search_buffer,strlen(city_search_buffer),fp);
  321.         fputc(0,fp);
  322.         fclose(fp);
  323.     }
  324.  
  325. return;
  326. }
  327.  
  328. dial_cities(int quantity)
  329. {
  330.     int t0,t1,t2,t3,t4,t5,status,count,test_count,flag,fp,dir_length,t_handle;
  331.  
  332.     str pcp_command[25],
  333.         city[10],
  334.         fon_path[76],
  335.         fon_name[76],
  336.         dir_length_buffer[3],
  337.         pcp_dial_queue[76],
  338.         empty_fon_path[76],
  339.         dos_command[80]="copy ";
  340.  
  341.  
  342.     _strip_high=1;
  343.  
  344.     if(!quantity)
  345.     {
  346.         beep(500);
  347.         status_wind("No cities selected!",10);
  348.         return 4;
  349.     }
  350. while(1)
  351. {
  352.     for(count=0;count<quantity;count=count+1)
  353.     {
  354.         prints(" ");
  355.         prints(" ");
  356.  
  357.         flushbuf();
  358.         t0=track("STILL",1);
  359.         t1=track(" CONNECTED",1);
  360.         t2=track("BUSY",1);
  361.         t3=track("ADDRESS",1);
  362.         t4=track("NOT OPERATING",1);
  363.  
  364.  
  365.         substr(city_dial_str,(count*8),8,city);
  366.  
  367.         if(city!="Net Exch")
  368.         {
  369.             pcp_command="C D/";
  370.             strcat(pcp_command,city);
  371.             strcat(pcp_command,",");
  372.             strcat(pcp_command,user_id);
  373.             strcat(pcp_command,"^M");
  374.  
  375.             cputs_tr(pcp_command);
  376.  
  377.             status=waitfor("PASSWORD",3);
  378.             if(!status)
  379.             {
  380.                 cputs_tr("^M");
  381.             }
  382.             else
  383.             {
  384.                 cputs_tr(password);
  385.                 cputs_tr("^M");
  386.             }
  387.         }
  388.         else
  389.         {
  390.             cputs_tr("C PURSUIT^M");
  391.         }
  392.         flushbuf();
  393.         t_handle=timer_start(100);  //Set the timeout value.
  394.         while(1)
  395.         {
  396.             terminal();
  397.             status=track_hit(0);
  398.             if(time_up(t_handle))
  399.             {
  400.                 timer_free(t_handle);
  401.                 beep(500);
  402.                 status_wind("City timed out!",10);
  403.                 track_free(0);
  404.                 cputs_tr("^M");
  405.                 if(!waitfor("@",5))
  406.                 {
  407.                     beep(500);
  408.                     status_wind("Lock up error! Aborting.",10);
  409.                     return 5;
  410.                 }
  411.                 break;
  412.             }
  413.  
  414.             if(inkey()==0x20)
  415.             {
  416.                 status_wind("Exiting City Dialer!",10);
  417.                 track_free(0);
  418.                 timer_free(t_handle);
  419.                 return 2;
  420.             }
  421.             if(status==t0)
  422.             {
  423.                 beep(500);
  424.                 status_wind("Still connected!  Must disconnect from city first.",10);
  425.                 track_free(0);
  426.                 timer_free(t_handle);
  427.                 return 1;
  428.             }
  429.             if(status==t1)
  430.             {
  431.                 track_free(0);
  432.                 timer_free(t_handle);
  433.  
  434.                 if(city!="Net Exch")
  435.                 {
  436.                     connect_alarm();
  437.                     status_wind("Connected! Now testing city modem.",10);
  438.                     flag=1;
  439.                     //Check for RV mode and get out of it
  440.                     cputs_tr("^M");
  441.                     if(waitfor("*",2))
  442.                     {
  443.                         cputs_tr("I~^M");
  444.                     }
  445.                     for(test_count=0;test_count<2;test_count=test_count+1)
  446.                     {
  447.                         cputs_tr("^M~~ATZ~~^M");
  448.                         if(waitfor("OK",2))
  449.                         {
  450.                             flag=0;
  451.                             dequeue(city);
  452.                             beep(3000);
  453.                             status_wind("Modem ok! Loading dialing directory.",10);
  454.                             break;
  455.                         }
  456.                     }
  457.                     if(flag)
  458.                     {
  459.                         beep(500);
  460.                         status_wind("Bad city modem!  Disconnecting city.",10);
  461.                         cputs_tr("^M~~@~~^M");
  462.                         cputs_tr("d~~^M");
  463.                         if(!(waitfor("@",4)))
  464.                         {
  465.                             beep(500);
  466.                             status_wind("Unable to disconnect city!  Aborting.",10);
  467.                             return 5;
  468.                         }
  469.                         break;
  470.                     }
  471.  
  472.                     delchrs(city,5,3);
  473.                     fon_path=_telix_dir;
  474.                     strcat(fon_path,"pcpfon\");
  475.                     empty_fon_path=fon_path;
  476.                     strcat(empty_fon_path,"empty.fon");
  477.                     strcat(fon_path,city);
  478.                     strcat(fon_path,".fon");
  479.                     if(!(loadfon(fon_path)))
  480.                     {
  481.                         beep(500);
  482.                         status_wind("Creating it.",10);
  483.                         strcat(dos_command,empty_fon_path);
  484.                         strcat(dos_command," ");
  485.                         strcat(dos_command,fon_path);
  486.                         dos(dos_command,0);
  487.                         loadfon(fon_path);
  488.                     }
  489.                     _dial_time=90;
  490.                     _strip_high=0;
  491.  
  492.                     //Adjust baud rates in the directory file
  493.                     fp=fopen(fon_path,"r+");
  494.                     if(!fp)
  495.                     {
  496.                         beep(500);
  497.                         status_wind("Not able to adjust directory baud rates!",10);
  498.                     }
  499.                     fseek(fp,6,0);
  500.                     fread(dir_length_buffer,2,fp);
  501.                     dir_length=subchr(dir_length_buffer,0)+(subchr(dir_length_buffer,1)*256);
  502.                     fseek(fp,106,0);
  503.                     for(;dir_length;dir_length=dir_length-1)
  504.                     {
  505.                         if(get_baud()==1200)
  506.                         {
  507.                             fputc(1,fp);
  508.                         }
  509.                         else
  510.                         {
  511.                             fputc(2,fp);
  512.                         }
  513.                         fseek(fp,85,1);
  514.                     }
  515.                     fclose(fp);
  516.  
  517.                     //Save the current city name to disk
  518.                     fon_name=_script_dir;
  519.                     strcat(fon_name,"fondir.pcp");
  520.                     fp=fopen(fon_name,"w+");
  521.                     fputs(fon_path,fp);
  522.                     fputc(0x0a,fp);
  523.                     fclose(fp);
  524.  
  525.                     call("dialbbs.slc");
  526.                 }
  527.                 else
  528.                 {
  529.                     
  530.                     t0=track("FIRST",1);
  531.                     t1=track("@",1);
  532.                     t2=track("CONTINUE",1);
  533.                     while(1)
  534.                     {
  535.                         terminal();
  536.                         status=track_hit(0);
  537.                         if(status==t0)
  538.                         {
  539.                             connect_alarm();
  540.                             status_wind("Connected to the Network Exchange!",10);
  541.                             track_free(0);
  542.                             dequeue(city);
  543.                             return 3;
  544.                         }
  545.                         if(status==t1)
  546.                         {
  547.                             track_free(0);
  548.                             break;
  549.                         }
  550.                         if(status==t2)
  551.                         {
  552.                             cputs_tr("~~~~^M");
  553.                         }
  554.                     }
  555.                     break;
  556.                 }
  557.                 return 0;
  558.             }
  559.  
  560.             if(status==t2)
  561.             {
  562.                 if((busy_tone=="y")|(busy_tone=="Y"))
  563.                 {
  564.                     tone(3000,20);
  565.                 }
  566.                 track_free(0);
  567.                 timer_free(t_handle);
  568.                 break;
  569.             }
  570.             if(status==t3)
  571.             {
  572.                 beep(500);
  573.                 dequeue(city);
  574.                 status_wind("City is not recognized by PCP!  Removing from queue.",10);
  575.                 delchrs(city_dial_str,(count*8),8);
  576.                 track_free(0);
  577.                 timer_free(t_handle);
  578.                 count=0;
  579.                 quantity=quantity-1;
  580.                 if(!quantity)
  581.                 {
  582.                     return 4;
  583.                 }
  584.                 break;
  585.             }
  586.             if(status==t4)
  587.             {
  588.                 beep(500);
  589.                 dequeue(city);
  590.                 status_wind("City is not operating! Removing from queue.",10);
  591.                 delchrs(city_dial_str,(count*8),8);
  592.                 track_free(0);
  593.                 timer_free(t_handle);
  594.                 count=0;
  595.                 quantity=quantity-1;
  596.                 if(!quantity)
  597.                 {
  598.                     return 4;
  599.                 }
  600.                 break;
  601.             }
  602.  
  603.            
  604.         }
  605.     }
  606. }
  607. }
  608.  
  609.  
  610.  
  611. main()
  612. {
  613.     int flag,
  614.         quantity,
  615.         scr_handle,
  616.         status;
  617.  
  618.     _scr_chk_key=0;
  619.     cputs("^M");
  620.     cputs("@");
  621.     cputs("^M");
  622.     flag=waitfor("@",5);
  623.     if(!flag)
  624.     {
  625.         status_wind("Pursuit not responding!",30);
  626.         prints("+++ Pursuit did not respond! +++");
  627.         beep(500);
  628.         hangup();
  629.         return();
  630.     }
  631.     status_wind("Loading PC Pursuit City Menu!",10);
  632.     scr_handle=vsavearea(0,0,79,25);
  633.     clear_scr();
  634.     quantity=dial_these();
  635.     vrstrarea(scr_handle);
  636.     status=dial_cities(quantity);
  637.     if(status==4)
  638.     {
  639.         beep(500);
  640.         status_wind("Dialing queue is empty!",10);
  641.     }
  642. }
  643.  
  644.