home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / WWIV2.ZIP / SUBREQ.C < prev    next >
C/C++ Source or Header  |  1992-12-03  |  10KB  |  402 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 "subxtr.h"
  22.  
  23.  
  24.  
  25. static void maybe_netmail(xtrasubsnetrec *ni, int add)
  26. {
  27.   prt(5,get_string(217));
  28.   if (yn()) {
  29.     strcpy(irt,get_string(218));
  30.     strcat(irt,ni->stype);
  31.     if (add)
  32.       strcat(irt,get_string(219));
  33.     else
  34.       strcat(irt,get_string(220));
  35.     set_net_num(ni->net_num);
  36.     email(1, ni->host, 0, 0);
  37.   }
  38. }
  39.  
  40. /****************************************************************************/
  41.  
  42.  
  43. void sub_req(int main_type, int minor_type, int tosys, char *extra)
  44. {
  45.   net_header_rec nh;
  46.  
  47.   nh.tosys=tosys;
  48.   nh.touser=1;
  49.   nh.fromsys=net_sysnum;
  50.   nh.fromuser=1;
  51.   nh.main_type=main_type;
  52.   nh.minor_type=minor_type;
  53.   nh.list_len=0;
  54.   time((long *)&nh.daten);
  55.   if (!minor_type)
  56.     nh.length=strlen(extra)+1;
  57.   else {
  58.     nh.length=1;
  59.     extra="";
  60.   }
  61.   nh.method=0;
  62.  
  63.   send_net(&nh, NULL, extra, NULL);
  64.  
  65.   nl();
  66.   if (main_type == main_type_sub_add_req)
  67.     outstr(get_string(221));
  68.   else
  69.     outstr(get_string(222));
  70.   pln(tosys);
  71.   pausescr();
  72. }
  73.  
  74. /****************************************************************************/
  75.  
  76. #define OPT_AUTO   0x0001
  77. #define OPT_NO_TAG 0x0002
  78.  
  79.  
  80. int find_hostfor(char *type, unsigned short *ui, char *desc, unsigned short *opt)
  81. {
  82.   int i,i1,done=0;
  83.   char s[161],*ss;
  84.   FILE *f;
  85.   unsigned short h, o,rc=0;
  86.  
  87.   if (desc)
  88.     *desc=0;
  89.   *opt=0;
  90.  
  91.   for (i=0; (i<256) && (!done); i++) {
  92.     if (i)
  93.       sprintf(s,"%sSUBS.%d",net_data,i);
  94.     else
  95.       sprintf(s,"%sSUBS.LST",net_data);
  96.     f=fopen(s,"r");
  97.     if (f) {
  98.       while ((!done) && fgets(s,160,f)) {
  99.         if (s[0]>' ') {
  100.           ss=strtok(s," \r\n\t");
  101.           if (ss) {
  102.             if (stricmp(ss,type)==0) {
  103.               ss=strtok(NULL," \r\n\t");
  104.               if (ss) {
  105.                 h=(unsigned short) atol(ss);
  106.                 o=0;
  107.                 ss=strtok(NULL,"\r\n");
  108.                 if (ss) {
  109.                   i1=0;
  110.                   while (*ss && ((*ss==' ') || (*ss=='\t'))) {
  111.                     ++ss;
  112.                     ++i1;
  113.                   }
  114.                   if (i1<4) {
  115.                     while (*ss && (*ss!=' ') && (*ss!='\t')) {
  116.                       switch(*ss) {
  117.                         case 'T': o |= OPT_NO_TAG; break;
  118.                         case 'R': o |= OPT_AUTO; break;
  119.                       }
  120.                       ++ss;
  121.                     }
  122.                     while (*ss && ((*ss==' ') || (*ss=='\t')))
  123.                       ++ss;
  124.                   }
  125.                   if (*ui) {
  126.                     if (*ui==h) {
  127.                       done=1;
  128.                       *opt=o;
  129.                       rc=h;
  130.                       if (desc)
  131.                         strcpy(desc,ss);
  132.                     }
  133.                   } else {
  134.                     nl();
  135.                     outstr(get_string(223)); pl(type);
  136.                     outstr(get_string(224)); npr("%u\r\n",h);
  137.                     outstr(get_string(225)); npr("%s\r\n",ss);
  138.                     nl();
  139.                     prt(5,get_string(226));
  140.                     if (yn()) {
  141.                       done=1;
  142.                       *ui=h;
  143.                       *opt=o;
  144.                       rc=h;
  145.                       if (desc)
  146.                         strcpy(desc,ss);
  147.                     }
  148.                   }
  149.                 }
  150.               }
  151.             }
  152.           }
  153.         }
  154.       }
  155.       fclose(f);
  156.     } else {
  157.       done=1;
  158.     }
  159.   }
  160.  
  161.   return(rc);
  162. }
  163.  
  164. /****************************************************************************/
  165.  
  166. void sub_xtr_del(int n, int nn, int f)
  167. {
  168.   xtrasubsnetrec xn;
  169.   int i,ok;
  170.   unsigned short opt;
  171.  
  172.   xn=xsubs[n].nets[nn];
  173.  
  174.   if (f) {
  175.     xsubs[n].num_nets--;
  176.  
  177.     for (i=nn; i<xsubs[n].num_nets; i++)
  178.       xsubs[n].nets[i]=xsubs[n].nets[i+1];
  179.   }
  180.  
  181.   set_net_num(xn.net_num);
  182.  
  183.   if ((xn.host) && (valid_system(xn.host))) {
  184.     ok=find_hostfor(xn.stype, (unsigned short *)&xn.host, NULL, &opt);
  185.     if (ok) {
  186.       if (opt&OPT_AUTO) {
  187.         if (status.net_version>=29)
  188.           sub_req(main_type_sub_drop_req, xn.type, xn.host, xn.stype);
  189.         else
  190.           maybe_netmail(&xn, 0);
  191.       } else {
  192.         maybe_netmail(&xn, 0);
  193.       }
  194.     } else {
  195.       prt(5,get_string(227));
  196.       if (yn())
  197.         sub_req(main_type_sub_drop_req, xn.type, xn.host, xn.stype);
  198.       else
  199.         maybe_netmail(&xn, 0);
  200.     }
  201.   }
  202. }
  203.  
  204. /****************************************************************************/
  205.  
  206. void sub_xtr_add(int n, int nn)
  207. {
  208.   unsigned short opt, ok, i,i1,f;
  209.   char desc[100],s[100],onx[20],*mmk,ch,*ss;
  210.   int onxi, odci,ii;
  211.   xtrasubsnetrec *xnp;
  212.   FILE *ff;
  213.  
  214.   if ((nn<0) || (nn>=xsubs[n].num_nets)) {
  215.  
  216.     if (xsubs[n].num_nets_max<=xsubs[n].num_nets) {
  217.       i1=xsubs[n].num_nets+4;
  218.       xnp=(xtrasubsnetrec *)malloca(i1*sizeof(xtrasubsnetrec));
  219.       if (!xnp)
  220.         return;
  221.       for (i=0; i<xsubs[n].num_nets; i++)
  222.         xnp[i]=xsubs[n].nets[i];
  223.  
  224.       if (xsubs[n].flags&XTRA_MALLOCED)
  225.         farfree(xsubs[n].nets);
  226.  
  227.       xsubs[n].nets=xnp;
  228.       xsubs[n].num_nets_max=i1;
  229.       xsubs[n].flags|=XTRA_MALLOCED;
  230.     }
  231.     xnp=&(xsubs[n].nets[xsubs[n].num_nets]);
  232.   } else
  233.     xnp=&(xsubs[n].nets[nn]);
  234.  
  235.   memset(xnp, 0, sizeof(xtrasubsnetrec));
  236.  
  237.   if (net_num_max>1) {
  238.     odc[0]=0;
  239.     odci=0;
  240.     onx[0]='Q';
  241.     onx[1]=0;
  242.     onxi=1;
  243.     nl();
  244.     for (ii=0; ii<net_num_max; ii++) {
  245.       if (ii<9) {
  246.         onx[onxi++]=ii+'1';
  247.         onx[onxi]=0;
  248.       } else {
  249.         odci=(ii+1)/10;
  250.         odc[odci-1]=odci+'0';
  251.         odc[odci]=0;
  252.       }
  253.       npr("%d. %s\r\n",ii+1,net_networks[ii].name);
  254.     }
  255.     pl(get_string(12));
  256.     nl();
  257.     prt(2,get_string(13));
  258.     if (net_num_max<9) {
  259.       ch=onek(onx);
  260.       if (ch=='Q')
  261.         ii=-1;
  262.       else
  263.         ii=ch-'1';
  264.     } else {
  265.       mmk=mmkey(2);
  266.       if (*mmk=='Q')
  267.         ii=-1;
  268.       else
  269.         ii=atoi(mmk)-1;
  270.     }
  271.     if ((ii>=0) && (ii<net_num_max)) {
  272.       set_net_num(ii);
  273.     } else
  274.       return;
  275.   }
  276.   xnp->net_num=net_num;
  277.  
  278.   nl();
  279.   prt(2,get_string(228));
  280.   input(xnp->stype,7);
  281.   if (xnp->stype[0]==0)
  282.     return;
  283.  
  284.   xnp->type=atoi(xnp->stype);
  285.  
  286.   if ((!xnp->type) && (status.net_version<32)) {
  287.     nl();
  288.     pl(get_string(229));
  289.     nl();
  290.     pausescr();
  291.     return;
  292.   }
  293.  
  294.   if (xnp->type)
  295.     sprintf(xnp->stype,"%u",xnp->type);
  296.  
  297.   prt(5,get_string(230));
  298.   if (yn()) {
  299.  
  300.     sprintf(s,"%sN%s.NET",net_data,xnp->stype);
  301.     f=open(s,O_RDWR|O_BINARY|O_CREAT, S_IREAD|S_IWRITE);
  302.     if (f>0)
  303.       close(f);
  304.  
  305.     prt(5,get_string(231));
  306.     if (ny())
  307.       xnp->flags |= XTRA_NET_AUTO_ADDDROP;
  308.  
  309.     prt(5,get_string(232));
  310.     if (ny()) {
  311.       xnp->flags |= XTRA_NET_AUTO_INFO;
  312.  
  313.       sprintf(s,"%sCATEG.NET",net_data);
  314.       ff=fopen(s,"r");
  315.       if (ff) {
  316.         nl();
  317.         pl(get_string(930));
  318.         ii=0;
  319.         while (!ii && fgets(s,100,ff)) {
  320.           ss=strchr(s,'\n');
  321.           if (ss)
  322.             *ss=0;
  323.           pla(s,&ii);
  324.         }
  325.         rewind(ff);
  326.  
  327.         nl();
  328.         prt(2,get_string(931));
  329.         input(s,3);
  330.  
  331.         i=atoi(s);
  332.         if (i) {
  333.           while (fgets(s,100,ff)) {
  334.             i1=atoi(s);
  335.             if (i1==i) {
  336.               xnp->category=i;
  337.               break;
  338.             }
  339.           }
  340.           if (!xnp->category)
  341.             pl(get_string(932));
  342.         }
  343.  
  344.         fclose(ff);
  345.       }
  346.     }
  347.  
  348.   } else {
  349.     ok=find_hostfor(xnp->stype, (unsigned short *) &(xnp->host), desc, &opt);
  350.  
  351.     if (!ok) {
  352.       nl();
  353.       prt(2,get_string(233));
  354.       input(desc,6);
  355.       xnp->host=(unsigned short) atol(desc);
  356.       desc[0]=0;
  357.     }
  358.  
  359.     if (!xsubs[n].desc[0])
  360.       strcpy(xsubs[n].desc, desc);
  361.  
  362.     if (xnp->host==net_sysnum)
  363.       xnp->host=0;
  364.  
  365.     if (xnp->host) {
  366.       if (valid_system(xnp->host)) {
  367.         if (ok) {
  368.           if (opt & OPT_NO_TAG) {
  369.             subboards[n].anony |= anony_no_tag;
  370.           }
  371.           nl();
  372.           if ((opt & OPT_AUTO) && (status.net_version>=29)) {
  373.             sub_req(main_type_sub_add_req, xnp->type, xnp->host, xnp->stype);
  374.           } else {
  375.             maybe_netmail(xnp, 1);
  376.           }
  377.         } else {
  378.           if (status.net_version>=29) {
  379.             nl();
  380.             prt(5,get_string(234));
  381.             ok=yn();
  382.           } else {
  383.             ok=0;
  384.           }
  385.           if (ok) {
  386.             sub_req(main_type_sub_add_req, xnp->type, xnp->host, xnp->stype);
  387.           } else {
  388.             maybe_netmail(xnp, 1);
  389.           }
  390.         }
  391.       } else {
  392.         nl();
  393.         pl(get_string(235));
  394.         pausescr();
  395.       }
  396.     }
  397.   }
  398.   if ((nn<0) || (nn>=xsubs[n].num_nets)) {
  399.     xsubs[n].num_nets++;
  400.   }
  401. }
  402.