home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / WWIV2.ZIP / NETSUP.C < prev    next >
C/C++ Source or Header  |  1992-12-03  |  20KB  |  897 lines

  1. /*****************************************************************************
  2.  
  3.                 WWIV Version 4
  4.                     Copyright (C) 1988-1993 by Wayne Bell
  5.  
  6. Distribution of the source code for WWIV, in any form, modified or unmodified,
  7. without PRIOR, WRITTEN APPROVAL by the author, is expressly prohibited.
  8. Distribution of compiled versions of WWIV is limited to copies compiled BY
  9. THE AUTHOR.  Distribution of any copies of WWIV not compiled by the author
  10. is expressly prohibited.
  11.  
  12.  
  13. *****************************************************************************/
  14.  
  15.  
  16.  
  17. #include "vars.h"
  18.  
  19. #pragma hdrstop
  20.  
  21. #include <dir.h>
  22. #include "subxtr.h"
  23.  
  24.  
  25.  
  26. #define utoa(s,v,r) ultoa((unsigned long)(s),v,r)
  27.  
  28.  
  29. int run_external1_x(char *cl)
  30. {
  31.   char s[200];
  32.   int i;
  33.  
  34.   unlink("WWIV_NET.DAT");
  35.   sprintf(s,"%s%s",net_data,cl);
  36.   i=run_external1(s);
  37.   if (i<0)
  38.     i=run_external1(cl);
  39.  
  40.   return(i);
  41. }
  42.  
  43.  
  44. void shrink_out_x(char *cl)
  45. {
  46.   char s[200];
  47.   int i;
  48.  
  49.   sprintf(s,"%d\r\n",net_num);
  50.   i=open("WWIV_NET.DAT",O_RDWR|O_BINARY|O_TRUNC|O_CREAT, S_IREAD|S_IWRITE);
  51.   if (i>0) {
  52.     write(i,s,strlen(s));
  53.     close(i);
  54.   }
  55.  
  56.   sprintf(s,"%s%s",net_data,cl);
  57.   shrink_out(s,0,0,0,0);
  58.   shrink_out(cl,0,0,0,0);
  59.  
  60.   unlink("WWIV_NET.DAT");
  61. }
  62.  
  63.  
  64. void checkup(struct ftime *f1, struct ftime *f2, int *tf)
  65. {
  66.   if ((f1->ft_year)>(f2->ft_year))
  67.     *tf=1;
  68.   else
  69.     if (f1->ft_year==f2->ft_year)
  70.       if (f1->ft_month>f2->ft_month)
  71.     *tf=1;
  72.       else
  73.     if (f1->ft_month==f2->ft_month)
  74.       if (f1->ft_day>f2->ft_day)
  75.         *tf=1;
  76.       else
  77.         if (f1->ft_day==f2->ft_day)
  78.           if (f1->ft_hour>f2->ft_hour)
  79.         *tf=1;
  80.           else
  81.         if (f1->ft_hour==f2->ft_hour)
  82.           if (f1->ft_min>f2->ft_min)
  83.             *tf=1;
  84.           else
  85.             if (f1->ft_min==f2->ft_min)
  86.               if (f1->ft_tsec>f2->ft_tsec)
  87.             *tf=1;
  88. }
  89.  
  90.  
  91. int checkup2(struct ftime *f, char *x)
  92. {
  93.   int q;
  94.   char s[81];
  95.   struct ftime f2;
  96.  
  97.   sprintf(s,"%s%s",net_data,x);
  98.   q=open(s,O_RDONLY);
  99.   if (q>0) {
  100.     getftime(q,&f2);
  101.     close(q);
  102.     q=0;
  103.     checkup(&f2,f,&q);
  104.   } else
  105.     q=1;
  106.   return(q);
  107. }
  108.  
  109.  
  110. int check_bbsdata(void)
  111. {
  112.   char s[81];
  113.   int ok,ok2;
  114.   struct ftime ft;
  115.  
  116.   sprintf(s,"%sCONNECT.UPD",net_data);
  117.   if ((ok=exist(s))==0) {
  118.     sprintf(s,"%sBBSLIST.UPD",net_data);
  119.     ok=exist(s);
  120.   }
  121.   if (ok  && status.net_edit_stuff) {
  122.     holdphone(1);
  123.     run_external1_x("NETEDIT /U");
  124.   } else {
  125.     sprintf(s,"%sBBSDATA.NET",net_data);
  126.     ok=open(s,O_RDONLY);
  127.     if (ok>0) {
  128.       getftime(ok,&ft);
  129.       close(ok);
  130.       ok=checkup2(&ft,"BBSLIST.NET")||checkup2(&ft,"CONNECT.NET");
  131.       ok2=checkup2(&ft,"CALLOUT.NET");
  132.     } else
  133.       ok=ok2=1;
  134.   }
  135.   sprintf(s,"%sBBSLIST.NET",net_data);
  136.   if (!exist(s))
  137.     ok=ok2=0;
  138.   sprintf(s,"%sCONNECT.NET",net_data);
  139.   if (!exist(s))
  140.     ok=ok2=0;
  141.   sprintf(s,"%sCALLOUT.NET",net_data);
  142.   if (!exist(s))
  143.     ok=ok2=0;
  144.   if (ok||ok2) {
  145.     sprintf(s,"NETWORK3%s",(ok?" Y":""));
  146.     holdphone(1);
  147.  
  148. #ifdef OLD_WAY
  149.     ok=run_external1_x(s);
  150. #else
  151.     shrink_out_x(s);
  152.     ok=0;
  153. #endif
  154.  
  155.     zap_call_out_list();
  156.     zap_contacts();
  157.     zap_bbs_list();
  158.     if (ok>=0)
  159.       return(1);
  160.   }
  161.   return(0);
  162. }
  163.  
  164.  
  165. void cleanup_net(void)
  166. {
  167.   char s[81],s1[81];
  168.   int ok,ok2,abort,f,i,nn,any,i1;
  169.   long l,l1;
  170.   struct ffblk ff;
  171.  
  172.   if ((net_networks[0].sysnum==0) && (net_num_max==1))
  173.     return;
  174.  
  175.   any=1;
  176.  
  177.   while (any) {
  178.     any=0;
  179.  
  180.     for (nn=0; nn<net_num_max; nn++) {
  181.  
  182.       set_net_num(nn);
  183.  
  184.       if (!net_sysnum)
  185.         continue;
  186.  
  187.       set_protect(0);
  188.       clrscrb();
  189.  
  190.       ok2=1;
  191.       abort=0;
  192.       while ((ok2) && (!abort)) {
  193.         ok2=0;
  194.         ok=0;
  195.         sprintf(s,"%sP*.NET",net_data);
  196.         ok=(findfirst(s,&ff,0)==0);
  197.         if (ok) {
  198.           holdphone(1);
  199.           hangup=0;
  200.           using_modem=0;
  201.           if (run_external1_x("NETWORK1")<0)
  202.             abort=1;
  203.           else
  204.             any=1;
  205.           ok2=1;
  206.         }
  207.         sprintf(s,"%sLOCAL.NET",net_data);
  208.         if (exist(s)) {
  209.           holdphone(1);
  210.           any=1;
  211.           ok=1;
  212.           hangup=0;
  213.           using_modem=0;
  214.           save_status();
  215.           close_user();
  216.           sprintf(s,"%sNETUP.XXX",net_data);
  217.           if (exist(s))
  218.             shrink_out_x("NETWORK2");
  219.           else {
  220.             if (run_external1_x("NETWORK2")<0)
  221.               abort=1;
  222.             else
  223.               any=1;
  224.           }
  225.           ok2=1;
  226.           l1=status.qscanptr;
  227.           get_status();
  228.           if (l1!=status.qscanptr) {
  229.             /* a sub has probably been updated; invalidate sub cache */
  230.             for (i=0; i<num_subs; i++) {
  231.               for (i1=0; i1<xsubs[i].num_nets; i1++) {
  232.                 if (xsubs[i].nets[i1].net_num==net_num)
  233.                   sub_dates[i]=0L;
  234.               }
  235.             }
  236.             c_sub=0;
  237.           }
  238.           curlsub=-1;
  239.           if (wfc) {
  240.             wfc=0;
  241.             read_user(1,&thisuser);
  242.             fwaiting=thisuser.waiting;
  243.             wfc=1;
  244.           }
  245.         }
  246.         if (check_bbsdata())
  247.           ok2=1;
  248.         if (ok2) {
  249.           clrscrb();
  250.           zap_contacts();
  251.         }
  252.       }
  253.     }
  254.   }
  255.   holdphone(0);
  256. }
  257.  
  258. void do_callout(int sn)
  259. {
  260.   int i,i1,i2;
  261.   char s[81],s1[81];
  262.   float ffl;
  263.   long l;
  264.   net_system_list_rec *csne;
  265.  
  266.   time(&l);
  267.   i=-1;
  268.   if (!net_networks[net_num].con)
  269.     read_call_out_list();
  270.   for (i1=0; i1<net_networks[net_num].num_con; i1++)
  271.     if (net_networks[net_num].con[i1].sysnum==sn)
  272.       i=i1;
  273.   if (i!=-1) {
  274.     csne=next_system(net_networks[net_num].con[i].sysnum);
  275.     if (csne) {
  276.       sprintf(s,"NETWORK /N%u /A%s /P%s /S%u /T%ld",
  277.         sn,
  278.         (net_networks[net_num].con[i].options & options_sendback)?"1":"0",
  279.         csne->phone,
  280.         modem_i->defl.com_speed,
  281.         l);
  282.       if (net_networks[net_num].con[i].macnum) {
  283.         sprintf(s1," /M%d",(int) net_networks[net_num].con[i].macnum);
  284.         strcat(s,s1);
  285.       }
  286.       if (strncmp(csne->phone,"000",3)) {
  287.         if (net_num_max>1) {
  288.           outstr(get_string(910));
  289.           outstr(net_name);
  290.           npr(" @%u\r\n",sn);
  291.         }
  292.         pl(s);
  293.         save_status();
  294.         holdphone(1);
  295.         wait(2.5);
  296.         run_external1_x(s);
  297.         zap_contacts();
  298.         get_status();
  299.         last_time_c=l;
  300.         global_xx=0;
  301.         cleanup_net();
  302.         holdphone(0);
  303.         imodem(0);
  304.       }
  305.     }
  306.   }
  307. }
  308.  
  309.  
  310. int ok_to_call(int i)
  311. {
  312.   int ok;
  313.   struct time ti;
  314.   char ch,h,l;
  315.   net_call_out_rec *con;
  316.  
  317.   con=&(net_networks[net_num].con[i]);
  318.  
  319.   ok=((con->options & options_no_call)==0);
  320.   if (con->options & options_receive_only)
  321.     ok=0;
  322.   ch=dow();
  323.   gettime(&ti);
  324.   if (con->options & options_ATT_night) {
  325.     if ((ch!=0) && (ch!=6)) {
  326.       if ((ti.ti_hour<23) && (ti.ti_hour>=7))
  327.         ok=0;
  328.     }
  329.     if (ch==0) {
  330.       if ((ti.ti_hour<23) && (ti.ti_hour>=16))
  331.         ok=0;
  332.     }
  333.   }
  334.   if (con->options & options_PCP_night) {
  335.     if ((ch!=0) && (ch!=6)) {
  336.       if ((ti.ti_hour<18) && (ti.ti_hour>=7))
  337.         ok=0;
  338.       if ((ti.ti_hour==6) && (ti.ti_min>30))
  339.         ok=0;
  340.     }
  341.   }
  342.  
  343.   l=con->min_hr;
  344.   h=con->max_hr;
  345.   if ((l>-1) && (h>-1) && (h!=l)) {
  346.     if ((h==0) || (h==24)) {
  347.       if (ti.ti_hour<l)
  348.         ok=0;
  349.       else
  350.         if ((ti.ti_hour==l) && (ti.ti_min<12))
  351.           ok=0;
  352.         else
  353.           if ((ti.ti_hour==23) && (ti.ti_min>30))
  354.             ok=0;
  355.     } else
  356.       if ((l==0) || (l==24)) {
  357.         if (ti.ti_hour>=h)
  358.           ok=0;
  359.         else
  360.           if ((ti.ti_hour==h-1) && (ti.ti_min>30))
  361.             ok=0;
  362.           else
  363.             if ((ti.ti_hour==0) && (ti.ti_min<12))
  364.               ok=0;
  365.       } else
  366.         if (h>l) {
  367.           if ((ti.ti_hour<l) || (ti.ti_hour>=h))
  368.             ok=0;
  369.           else
  370.             if ((ti.ti_hour==l) && (ti.ti_min<12))
  371.               ok=0;
  372.             else
  373.               if ((ti.ti_hour==h-1) && (ti.ti_min>30))
  374.                 ok=0;
  375.         } else {
  376.           if ((ti.ti_hour>=h) && (ti.ti_hour<l))
  377.             ok=0;
  378.           else
  379.             if ((ti.ti_hour==l) && (ti.ti_min<12))
  380.               ok=0;
  381.             else
  382.               if ((ti.ti_hour==h-1) && (ti.ti_min>30))
  383.                 ok=0;
  384.         }
  385.   }
  386.  
  387.   return(ok);
  388. }
  389.  
  390.  
  391.  
  392. #define WEIGHT 30.0
  393.  
  394. void fixup_long(long *f, long l)
  395. {
  396.   if (*f>l)
  397.     *f=l;
  398.  
  399.   if (*f+(86400L*30L)<l)
  400.     *f=l-86400L*30L;
  401. }
  402.  
  403. void attempt_callout(void)
  404. {
  405.   int **try,i,i1,i2,i3,ok,net_only,nn, num_call_sys, num_ncn,any;
  406.   float **weight,fl,fl1,fl2,ffl;
  407.   long l,l1;
  408.   char ch,s[81],s1[81];
  409.   struct time ti;
  410.   net_call_out_rec *con;
  411.   net_contact_rec *ncn;
  412.  
  413.   net_only=1;
  414.   if (syscfg.netlowtime!= syscfg.nethightime) {
  415.     if (syscfg.nethightime>syscfg.netlowtime) {
  416.       if ((timer()<=(syscfg.netlowtime*60.0)) || (timer()>=(syscfg.nethightime*60.0)))
  417.         net_only=0;
  418.     } else {
  419.       if ((timer()<=(syscfg.netlowtime*60.0)) && (timer()>=(syscfg.nethightime*60.0)))
  420.         net_only=0;
  421.     }
  422.   } else
  423.     net_only=0;
  424.   time(&l);
  425.   if (last_time_c>l)
  426.     last_time_c=0L;
  427.   if (labs(last_time_c-l)<120)
  428.     return;
  429.   if (last_time_c==0L) {
  430.     last_time_c=l;
  431.     return;
  432.   }
  433.  
  434.   if ((try=(int **)malloca(sizeof(int *) * net_num_max))==NULL)
  435.     return;
  436.   if ((weight=(float **)malloca(sizeof(float *) * net_num_max))==NULL) {
  437.     farfree(try);
  438.     return;
  439.   }
  440.   memset(try, 0, sizeof(int *) * net_num_max);
  441.   memset(weight, 0, sizeof(float *) * net_num_max);
  442.  
  443.   fl2=0.0;
  444.   any=0;
  445.  
  446.   for (nn=0; nn<net_num_max; nn++) {
  447.     set_net_num(nn);
  448.     if (!net_sysnum)
  449.       continue;
  450.  
  451.     if (!net_networks[net_num].con)
  452.       read_call_out_list();
  453.     if (!net_networks[net_num].ncn)
  454.       read_contacts();
  455.  
  456.     con=net_networks[net_num].con;
  457.     ncn=net_networks[net_num].ncn;
  458.     num_call_sys=net_networks[net_num].num_con;
  459.     num_ncn=net_networks[net_num].num_ncn;
  460.  
  461.     try[nn]=(int *)malloca(sizeof(int)*num_call_sys);
  462.     if (!try[nn])
  463.       break;
  464.     weight[nn]=(float *)malloca(sizeof(float)*num_call_sys);
  465.     if (!weight[nn])
  466.       break;
  467.  
  468.     for (i=0; i<num_call_sys; i++) {
  469.       try[nn][i]=0;
  470.       ok=ok_to_call(i);
  471.       i2=-1;
  472.       for (i1=0; i1<num_ncn; i1++)
  473.         if (ncn[i1].systemnumber==con[i].sysnum)
  474.           i2=i1;
  475.       if ((ok) && (i2!=-1)) {
  476.         if (ncn[i2].bytes_waiting==0L)
  477.           if (con[i].call_anyway) {
  478.             l1=(l-ncn[i2].lastcontact+60*3)/3600/24;
  479.             if (((unsigned char)l1 < con[i].call_anyway) ||
  480.                ((con[i].options & options_sendback)==0))
  481.               if (!net_only)
  482.                 ok=0;
  483.           } else
  484.             ok=0;
  485.         if (con[i].options & options_once_per_day) {
  486.           if (labs(l-ncn[i2].lastcontactsent)<(20L*3600L/con[i].times_per_day))
  487.             ok=0;
  488.         }
  489.  
  490.         fixup_long((long *)&(ncn[i2].lastcontactsent),l);
  491.         fixup_long((long *)&(ncn[i2].lasttry),l);
  492.         if (ok) {
  493.           if (ncn[i2].bytes_waiting==0L)
  494.             fl=5.0*WEIGHT;
  495.           else
  496.             fl=1024.0/((float)ncn[i2].bytes_waiting)*WEIGHT*60.0;
  497.           fl1=(float) (l-ncn[i2].lasttry);
  498.           if ((fl<fl1) || (net_only)) {
  499.             try[nn][i]=1;
  500.             fl1=fl1/fl;
  501.             if (fl1<1.0)
  502.               fl1=1.0;
  503.             if (fl1>5.0)
  504.               fl1=5.0;
  505.             weight[nn][i]=fl1;
  506.             fl2 += fl1;
  507.             any++;
  508.           }
  509.         }
  510.       }
  511.     }
  512.   }
  513.  
  514.   if (any) {
  515.     fl=fl2*((float)rand())/32767.0;
  516.     fl1=0.0;
  517.     for (nn=0; nn<net_num_max; nn++) {
  518.       set_net_num(nn);
  519.       if (!net_sysnum)
  520.         continue;
  521.  
  522.       i1=-1;
  523.       for (i=0; (i<net_networks[net_num].num_con); i++) {
  524.         if (try[nn][i]) {
  525.           fl1 += weight[nn][i];
  526.           if (fl1>=fl) {
  527.             i1=i;
  528.             break;
  529.           }
  530.         }
  531.       }
  532.       if (i1!=-1) {
  533.         do_callout(net_networks[net_num].con[i1].sysnum);
  534.         time(&l);
  535.         last_time_c=l;
  536.         break;
  537.       }
  538.     }
  539.   }
  540.  
  541.  
  542.   for (nn=0; nn<net_num_max; nn++) {
  543.     if (try[nn])
  544.       farfree(try[nn]);
  545.     if (weight[nn])
  546.       farfree(weight[nn]);
  547.   }
  548.   farfree(try);
  549.   farfree(weight);
  550.  
  551.   set_net_num(0);
  552. }
  553.  
  554. void force_callout(void)
  555. {
  556.   int i,i1,i2,i3,index,ok,sn,nn,onxi, odci,nv,nitu;
  557.   float fl,fl1,fl2,ffl;
  558.   long l,l1;
  559.   char ch,s[81],s1[81], onx[20],*ss,*ss1,*ss2,*mmk;
  560.   struct time ti;
  561.   net_system_list_rec *csne;
  562.  
  563.   time(&l);
  564.   nl();
  565.   prt(2,get_string(911));
  566.   input(s,5);
  567.   sn=atoi(s);
  568.   odc[0]=0;
  569.   odci=0;
  570.   onx[0]='Q';
  571.   onx[1]=0;
  572.   onxi=1;
  573.   nv=0;
  574.   ss=malloc(net_num_max*3);
  575.   ss1=ss+net_num_max;
  576.   ss2=ss1+net_num_max;
  577.  
  578.   for (nn=0; nn<net_num_max; nn++) {
  579.     set_net_num(nn);
  580.     if ((!net_sysnum) || (net_sysnum==sn))
  581.       continue;
  582.  
  583.     if (!net_networks[net_num].con)
  584.       read_call_out_list();
  585.  
  586.     i=-1;
  587.     for (i1=0; i1<net_networks[net_num].num_con; i1++) {
  588.       if (net_networks[net_num].con[i1].sysnum == sn) {
  589.         i=i1;
  590.         break;
  591.       }
  592.     }
  593.  
  594.     if (i!=-1) {
  595.       if (!net_networks[net_num].ncn)
  596.         read_contacts();
  597.  
  598.       i2=-1;
  599.       for (i1=0; i1<net_networks[net_num].num_ncn; i1++) {
  600.         if (net_networks[net_num].ncn[i1].systemnumber==sn) {
  601.           i2=i1;
  602.           break;
  603.         }
  604.       }
  605.  
  606.       if (i2!=-1) {
  607.         ss[nv]=nn;
  608.         ss1[nv]=i;
  609.         ss2[nv++]=i2;
  610.       }
  611.     }
  612.   }
  613.  
  614.   nitu=-1;
  615.   if (nv) {
  616.     if (nv==1)
  617.       nitu=0;
  618.     else {
  619.       nl();
  620.       for (i=0; i<nv; i++) {
  621.         set_net_num(ss[i]);
  622.         csne=next_system(sn);
  623.         if (csne) {
  624.           if (i<9) {
  625.             onx[onxi++]=i+'1';
  626.             onx[onxi]=0;
  627.           } else {
  628.             odci=(i+1)/10;
  629.             odc[odci-1]=odci+'0';
  630.             odc[odci]=0;
  631.           }
  632.           npr("%d. %s (%s)\r\n",i+1,net_name, csne->name);
  633.         }
  634.       }
  635.       pl(get_string(12));
  636.       nl();
  637.       prt(2,get_string(13));
  638.       if (nv<9) {
  639.         ch=onek(onx);
  640.         if (ch!='Q')
  641.           nitu=ch-'1';
  642.       } else {
  643.         mmk=mmkey(2);
  644.         if (*mmk!='Q')
  645.           nitu=atoi(mmk)-1;
  646.       }
  647.     }
  648.   }
  649.  
  650.   if (nitu!=-1) {
  651.     set_net_num(ss[nitu]);
  652.     ok=ok_to_call(ss1[nitu]);
  653.  
  654.     if (!ok) {
  655.       nl();
  656.       prt(5,get_string(465));
  657.       if (yn())
  658.         ok=1;
  659.     }
  660.     if (ok) {
  661.       if (net_networks[net_num].ncn[ss2[nitu]].bytes_waiting==0L)
  662.         if (!(net_networks[net_num].con[ss1[nitu]].options & options_sendback))
  663.           ok=0;
  664.       if (ok) {
  665.         do_callout(sn);
  666.       }
  667.     }
  668.   }
  669.   farfree(ss);
  670. }
  671.  
  672.  
  673. void print_pending_list(void)
  674. {
  675.   int i,any=0,i1,i2,nn,num_ncn, num_call_sys;
  676.   char s[81],ch,s1[81];
  677.   long l;
  678.   net_call_out_rec *con;
  679.   net_contact_rec *ncn;
  680.  
  681.   if ((net_networks[0].sysnum==0) && (net_num_max==1))
  682.     return;
  683.  
  684.   time(&l);
  685.  
  686.   nl();
  687.   nl();
  688.   pl(get_string(912));
  689.   nl();
  690.   if (net_num_max>1) {
  691.     pl(get_string(913));
  692.     pl(get_string(914));
  693.   } else {
  694.     pl(get_string(915));
  695.     pl(get_string(916));
  696.   }
  697.  
  698.   for (nn=0; nn<net_num_max; nn++) {
  699.  
  700.     set_net_num(nn);
  701.  
  702.     if (!net_sysnum)
  703.       continue;
  704.  
  705.     if (!net_networks[net_num].con)
  706.       read_call_out_list();
  707.     if (!net_networks[net_num].ncn)
  708.       read_contacts();
  709.  
  710.     con=net_networks[net_num].con;
  711.     ncn=net_networks[net_num].ncn;
  712.     num_call_sys=net_networks[net_num].num_con;
  713.     num_ncn=net_networks[net_num].num_ncn;
  714.  
  715.     for (i1=0; i1<num_call_sys; i1++) {
  716.       i2=-1;
  717.       for (i=0; i<num_ncn; i++) {
  718.         if (con[i1].sysnum==ncn[i].systemnumber) {
  719.           i2=i;
  720.           break;
  721.         }
  722.       }
  723.       if ((i2!=-1) && (ncn[i2].bytes_waiting)) {
  724.         if (ok_to_call(i1))
  725.           ch='*';
  726.         else
  727.           ch=' ';
  728.         any=1;
  729.         if (ncn[i2].lastcontactsent)
  730.           ltoa((l-ncn[i2].lastcontactsent)/3600,s1,10);
  731.         else
  732.           strcpy(s1,get_string(917));
  733.         if (net_num_max>1) {
  734.           sprintf(s,"%c%-11s %-5u       %7ld    %s",
  735.             ch,
  736.             net_name,
  737.             ncn[i2].systemnumber,
  738.             ncn[i2].bytes_waiting,
  739.             s1);
  740.         } else {
  741.           sprintf(s,"%c%-5u       %7ld    %s",
  742.             ch,
  743.             ncn[i2].systemnumber,
  744.             ncn[i2].bytes_waiting,
  745.             s1);
  746.         }
  747.         pl(s);
  748.       }
  749.     }
  750.   }
  751.  
  752.   for (nn=0; nn<net_num_max; nn++) {
  753.  
  754.     set_net_num(nn);
  755.  
  756.     if (!net_sysnum)
  757.       continue;
  758.  
  759.     sprintf(s,"%sDEAD.NET",net_data);
  760.     i=open(s,O_RDONLY | O_BINARY);
  761.     if (i>0) {
  762.       l=filelength(i);
  763.       any=1;
  764.       close(i);
  765.       if (net_num_max>1) {
  766.         sprintf(s," %-11s DEAD        %7ld", net_name, l);
  767.       } else {
  768.         sprintf(s," DEAD        %7ld", l);
  769.       }
  770.       pl(s);
  771.     }
  772.   }
  773.   if (!any)
  774.     pl(get_string(918));
  775.   nl();
  776.   if (!useron)
  777.     pausescr();
  778. }
  779.  
  780. /****************************************************************************/
  781.  
  782.  
  783. void gate_msg(net_header_rec *nh, char *text, unsigned short nn, char *byname, unsigned int *list, unsigned short fnn)
  784. {
  785.   char newname[128], fn[100], qn[100], on[100];
  786.   char *ti, nm[82], *ss;
  787.   int f,i;
  788.   unsigned short ntl;
  789.  
  790.   if (strlen(text)<80) {
  791.     ti=text;
  792.     text+=strlen(ti)+1;
  793.     ntl=nh->length-strlen(ti)-1;
  794.     ss=strchr(text,'\r');
  795.     if (ss && (ss-text<80) && (ss-text<ntl)) {
  796.       strncpy(nm,text,ss-text);
  797.       nm[ss-text]=0;
  798.       ss++;
  799.       if (*ss=='\n')
  800.         ss++;
  801.       nh->length-=(ss-text);
  802.       ntl-=(ss-text);
  803.       text=ss;
  804.  
  805.       qn[0]=on[0]=0;
  806.  
  807.       if (fnn==65535) {
  808.  
  809.         strcpy(newname,nm);
  810.         ss=strrchr(newname,'@');
  811.         if (ss) {
  812.           sprintf(ss+1,"%u",net_networks[nn].sysnum);
  813.           ss=strrchr(nm,'@');
  814.           if (ss) {
  815.             ++ss;
  816.             while ((*ss>='0') && (*ss<='9'))
  817.               ++ss;
  818.             strcat(newname,ss);
  819.           }
  820.           strcat(newname,"\r\n");
  821.         }
  822.       } else {
  823.         if ((nm[0]=='`') && (nm[1]=='`')) {
  824.           for (i=strlen(nm)-2; i>0; i--) {
  825.             if ((nm[i]=='`') && (nm[i+1]=='`')) {
  826.               break;
  827.             }
  828.           }
  829.           if (i>0) {
  830.             i+=2;
  831.             strncpy(qn,nm,i);
  832.             qn[i]=' ';
  833.             qn[i+1]=0;
  834.           }
  835.         } else
  836.           i=0;
  837.         if (qn[0]==0) {
  838.           ss=strrchr(nm,'#');
  839.           if (ss) {
  840.             if ((ss[1]>='0') && (ss[1]<='9')) {
  841.               *ss=0;
  842.               ss--;
  843.               while ((ss>nm) && (*ss==' ')) {
  844.                 *ss=0;
  845.                 ss--;
  846.               }
  847.             }
  848.           }
  849.           if (nm[0]) {
  850.             if (nh->fromuser)
  851.               sprintf(qn,"``%s`` ",nm);
  852.             else
  853.               strcpy(on,nm);
  854.           }
  855.         }
  856.         if ((on[0]==0) && (nh->fromuser==0)) {
  857.           strcpy(on,nm+i);
  858.         }
  859.         if (on[0])
  860.           sprintf(newname,"%s%s %s AT %u\r\n",qn, net_networks[fnn].name,
  861.                   on, nh->fromsys);
  862.         else
  863.           sprintf(newname,"%s%s #%u AT %u\r\n",qn, net_networks[fnn].name,
  864.                   nh->fromuser, nh->fromsys);
  865.  
  866.         nh->fromsys=net_networks[nn].sysnum;
  867.         nh->fromuser=0;
  868.       }
  869.  
  870.  
  871.       nh->length += strlen(newname);
  872.       if ((nh->main_type == main_type_email_name) ||
  873.           (nh->main_type == main_type_new_post))
  874.         nh->length += strlen(byname)+1;
  875.       sprintf(fn,"%sPGATE.NET",net_networks[nn].dir);
  876.       f=open(fn,O_RDWR|O_BINARY|O_CREAT, S_IREAD|S_IWRITE);
  877.       if (f) {
  878.         lseek(f,0L,SEEK_END);
  879.         if (!list)
  880.           nh->list_len=0;
  881.         if (nh->list_len)
  882.           nh->tosys=0;
  883.         write(f,nh, sizeof(net_header_rec));
  884.         if (nh->list_len)
  885.           write(f,list,2*(nh->list_len));
  886.         if ((nh->main_type == main_type_email_name) ||
  887.             (nh->main_type == main_type_new_post))
  888.           write(f,byname, strlen(byname)+1);
  889.         write(f,ti,strlen(ti)+1);
  890.         write(f,newname,strlen(newname));
  891.         write(f,text,ntl);
  892.         close(f);
  893.       }
  894.     }
  895.   }
  896. }
  897.