home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / W / WWIVSOR.ZIP / GFILES.C < prev    next >
Text File  |  1995-05-12  |  13KB  |  538 lines

  1. /*****************************************************************************
  2.  
  3.                 WWIV Version 4
  4.                     Copyright (C) 1988-1995 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. char *get_file(char *fn, long *len)
  24. {
  25.   int i;
  26.   char *s;
  27.  
  28.   i=sh_open1(fn,O_RDONLY | O_BINARY);
  29.   if (i<0) {
  30.     *len=0L;
  31.     return(NULL);
  32.   }
  33.   if ((s=malloca(filelength(i)+50))==NULL) {
  34.     *len=0L;
  35.     sh_close(i);
  36.     return(NULL);
  37.   }
  38.   *len=(long) sh_read(i,(void *)s, filelength(i));
  39.   sh_close(i);
  40.   return(s);
  41. }
  42.  
  43.  
  44. gfilerec *read_sec(int sn, int *nf)
  45. {
  46.   gfilerec *g;
  47.   int f,i;
  48.   char s[81];
  49.  
  50.   i=sizeof(gfilerec)*(gfilesec[sn].maxfiles);
  51.   if ((g=malloca((long) i))==NULL) {
  52.     *nf=0;
  53.     return(NULL);
  54.   }
  55.   sprintf(s,"%s%s.GFL",syscfg.datadir,gfilesec[sn].filename);
  56.   f=sh_open1(s,O_RDONLY | O_BINARY);
  57.   if (f<0)
  58.     *nf=0;
  59.   else {
  60.     *nf=sh_read(f,(void *)g,i)/sizeof(gfilerec);
  61.     sh_close(f);
  62.   }
  63.   return(g);
  64. }
  65.  
  66.  
  67. void list_sec(int *map, int nmap)
  68. {
  69.   int i,abort;
  70.   char s[81];
  71.  
  72.   abort=0;
  73.   pla("",&abort);
  74.   pla("",&abort);
  75.   pla(get_string(48),&abort);
  76.   pla("",&abort);
  77.   for (i=0; (i<nmap) && (!abort) && (!hangup); i++) {
  78.     sprintf(s,"%2d. %s",i+1, gfilesec[map[i]].name);
  79.     pla(s,&abort);
  80.   }
  81.   nl();
  82. }
  83.  
  84.  
  85. void list_gfiles(gfilerec *g, int nf)
  86. {
  87.   int i,abort;
  88.   char s[81];
  89.  
  90.   abort=0;
  91.   pla("",&abort);
  92.   pla("",&abort);
  93.   pla(get_string(49),&abort);
  94.   pla("",&abort);
  95.   if ((nf==0) && (abort==0)) {
  96.     nl();
  97.     pl(get_string(5));
  98.     nl();
  99.   }
  100.   for (i=0; (i<nf) && (!abort) && (!hangup); i++) {
  101.     sprintf(s,"%2d. %s",i+1, g[i].description);
  102.     pla(s,&abort);
  103.   }
  104.   nl();
  105.   if ((!abort) && (cs())) {
  106.     pl(get_string(50));
  107.     pl(get_string(51));
  108.     nl();
  109.   }
  110. }
  111.  
  112.  
  113. void gfile_sec(int sn)
  114. {
  115.   gfilerec *g;
  116.   int i,done,nf,i1,start=0;
  117.   char xdc[81],*ss,*ss1,s[81];
  118.  
  119.   g=read_sec(sn,&nf);
  120.   if (g==NULL)
  121.     return;
  122.   strcpy(xdc,odc);
  123.   for (i=0; i<20; i++)
  124.     odc[i]=0;
  125.   for (i=1; i<=nf/10; i++)
  126.     odc[i-1]=i+'0';
  127.   if ((menu_on() == 0) || rip_subset)
  128.     list_gfiles(g,nf);
  129.   done=0;
  130.   while ((!done) && (!hangup)) {
  131.     if (menu_on() && !rip_subset)
  132.       rip_list_gfiles(g, nf, start);
  133.     nl();
  134.     tleft(1);
  135.     prt(2,get_string(52));
  136.     ss=mmkey(2);
  137.     i=atoi(ss);
  138.     if (strcmp(ss,"Q")==0)
  139.       done=1;
  140.     else
  141.       if ((strcmp(ss,"A")==0) && (cs())) {
  142.         bbsfree(g);
  143.     fill_sec(sn);
  144.         g=read_sec(sn,&nf);
  145.         if (g==NULL)
  146.           return;
  147.         for (i=0; i<20; i++)
  148.           odc[i]=0;
  149.         for (i=1; i<=nf/10; i++)
  150.           odc[i-1]=i+'0';
  151.       } else if ((strcmp(ss,"D")==0) && (cs())) {
  152.         nl();
  153.         prt(2,get_string(53));
  154.         ss1=mmkey(2);
  155.         i=atoi(ss1);
  156.         if ((i>0) && (i<=nf)) {
  157.           sprintf(s,"%s %s? ",get_string(54), g[i-1].description);
  158.           prt(5,s);
  159.           if (yn()) {
  160.             prt(5,get_string(55));
  161.             if (yn()) {
  162.               sprintf(s,"%s%s\\%s",syscfg.gfilesdir,
  163.                     gfilesec[sn].filename,g[i-1].filename);
  164.               unlink(s);
  165.             }
  166.             for (i1=i; i1<nf; i1++)
  167.               g[i1-1]=g[i1];
  168.             --nf;
  169.             sprintf(s,"%s%s.GFL",syscfg.datadir,gfilesec[sn].filename);
  170.             i=sh_open(s,O_RDWR | O_BINARY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
  171.             sh_write(i,(void *)g,nf*sizeof(gfilerec));
  172.             sh_close(i);
  173.             nl();
  174.             pl(get_string(56));
  175.             nl();
  176.           }
  177.  
  178.         } else if (strcmp(ss1,"P")==0) {
  179.           if (start > 0)
  180.             start -= 14;
  181.           if (start < 0)
  182.             start = 0;
  183.         } else if (strcmp(ss1,"N")==0) {
  184.           if (start+14 < nf)
  185.             start += 14;
  186.         }
  187.       } else {
  188.           if (strcmp(ss,"?")==0) {
  189.         list_gfiles(g,nf);
  190.           } else {
  191.             if (menu_on()) {
  192.               rip_cls();
  193.               printmenu(321);
  194.             }
  195.             if ((i>0) && (i<=nf)) {
  196.               sprintf(s,"%s\\%s",gfilesec[sn].filename,g[i-1].filename);
  197.           i1=printfile(s);
  198.               thisuser.gfilesread++;
  199.           if (i1==0) {
  200.                 sprintf(s,get_stringx(1,15),g[i-1].filename);
  201.             sysoplog(s);
  202.           }
  203.             }
  204.           }
  205.       }
  206.   }
  207.   if (menu_on())
  208.     printmenu(321);
  209.   bbsfree(g);
  210.   strcpy(odc,xdc);
  211. }
  212.  
  213.  
  214. void gfiles(void)
  215. {
  216.   int i,i1,done,*map,nmap,ok,start=0;
  217.   char *ss;
  218.  
  219.   map=(int *)malloca(sysinfo.max_gfilesec * sizeof(int));
  220.   if (!map)
  221.     return;
  222.  
  223.   done=0;
  224.   nmap=0;
  225.   for (i=0; i<20; i++)
  226.     odc[i]=0;
  227.   for (i=0; i<num_sec; i++) {
  228.     ok=1;
  229.     if (thisuser.age<gfilesec[i].age)
  230.       ok=0;
  231.     if (actsl<gfilesec[i].sl)
  232.       ok=0;
  233.     if (((thisuser.ar & gfilesec[i].ar)==0) && (gfilesec[i].ar))
  234.       ok=0;
  235.     if (ok) {
  236.       map[nmap++]=i;
  237.       if ((nmap % 10)==0)
  238.         odc[nmap/10-1]='0'+(nmap/10);
  239.     }
  240.   }
  241.   if (nmap==0) {
  242.     nl();
  243.     pl(get_string(57));
  244.     nl();
  245.     bbsfree(map);
  246.     return;
  247.   }
  248.   if ((menu_on() == 0) || rip_subset)
  249.     list_sec(map,nmap);
  250.   while ((!done) && (!hangup)) {
  251.     if (menu_on() && !rip_subset)
  252.       rip_list_sec(map,nmap,start);
  253.     nl();
  254.     tleft(1);
  255.     prt(2,get_string(58));
  256.     ss=mmkey(2);
  257.     if (strcmp(ss,"Q")==0)
  258.       done=1;
  259.     else
  260.       if (strcmp(ss,"?")==0)
  261.         list_sec(map,nmap);
  262.       else
  263.     if ((strcmp(ss,"A")==0) && (cs())) {
  264.       i1=0;
  265.       for (i=0; (i<nmap) && (!i1); i++) {
  266.         nl();
  267.         outstr(get_string(59));
  268.         pl(gfilesec[map[i]].name);
  269.           nl();
  270.         i1=fill_sec(map[i]);
  271.       }
  272.     } else if (strcmp(ss,"P")==0) {
  273.       if (start > 0)
  274.             start -= 14;
  275.       if (start < 0)
  276.             start = 0;
  277.     } else if (strcmp(ss,"N")==0) {
  278.       if (start+14 < nmap)
  279.             start += 14;
  280.     } else {
  281.       i=atoi(ss);
  282.       if ((i>0) && (i<=nmap)) {
  283.         gfile_sec(map[i-1]);
  284.       }
  285.     }
  286.   }
  287.  
  288.   if (menu_on()) {
  289.     rip_cls();
  290.     printmenu(321);
  291.   }
  292.   bbsfree(map);
  293. }
  294.  
  295.  
  296. /****************************************************************************/
  297. /****************************************************************************/
  298.  
  299.  
  300. void hop_sub(void)
  301. {
  302.   unsigned char s1[81], s2[81], ch;
  303.   int c,i,i2,nc,abort=0,oc,os;
  304.  
  305.   nc=0;
  306.   while (uconfsub[nc].confnum!=-1)
  307.     nc++;
  308.  
  309.   nl();
  310.   prt(2,get_string(1161));
  311.   input(s1,40);
  312.   if (!s1[0])
  313.     return;
  314.   nl();
  315.  
  316.   c=0; oc=curconfsub; os=usub[cursub].subnum;
  317.  
  318.   while ((c<nc) && (!abort)) {
  319.     if (okconf(&thisuser))
  320.       setuconf(CONF_SUBS,c,-1);
  321.     i=0;
  322.     while ((i<num_subs) && (usub[i].subnum!=-1) && (!abort)) {
  323.       strcpy(s2,subboards[usub[i].subnum].name);
  324.       for (i2=0;(s2[i2]=upcase(s2[i2]))!=0;i2++)
  325.         ;
  326.       if (strstr(s2,s1)!=NULL) {
  327.         ansic(5);
  328.           npr("%s\"%s\"",get_string(1162),subboards[usub[i].subnum].name);
  329.         npr(get_string(1378));
  330.         ch=ynq();
  331.         if (ch=='Y') {
  332.           abort=1;
  333.           cursub=i;
  334.           break;
  335.         } else if (ch=='Q') {
  336.           abort=1;
  337.           if (okconf(&thisuser))
  338.             setuconf(CONF_SUBS, oc, os);
  339.           break;
  340.         }
  341.       }
  342.       ++i;
  343.     }
  344.     c++;
  345.     if (!okconf(&thisuser))
  346.       break;
  347.   }
  348.   if ((okconf(&thisuser)) && (!abort))
  349.     setuconf(CONF_SUBS, oc, os);
  350. }
  351.  
  352. void hop_dir(void)
  353. {
  354.   unsigned char s1[81],s2[81],ch;
  355.   int c,i,i2,nc,abort=0,oc,os;
  356.  
  357.   nc=0;
  358.   while (uconfdir[nc].confnum!=-1)
  359.     nc++;
  360.  
  361.   nl();
  362.   prt(2,get_string(1163));
  363.   input(s1,40);
  364.   if (!s1[0])
  365.     return;
  366.   nl();
  367.  
  368.   c=0; oc=curconfdir; os=udir[curdir].subnum;
  369.  
  370.   while ((c<nc) && (!abort)) {
  371.     if (okconf(&thisuser))
  372.       setuconf(CONF_DIRS,c,-1);
  373.     i=0;
  374.     while ((i<num_dirs) && (udir[i].subnum!=-1) && (!abort)) {
  375.       strcpy(s2,directories[udir[i].subnum].name);
  376.       for (i2=0;(s2[i2]=upcase(s2[i2]))!=0;i2++)
  377.         ;
  378.       if (strstr(s2,s1)!=NULL) {
  379.         ansic(5);
  380.           npr("%s\"%s\"",get_string(1162),directories[udir[i].subnum].name);
  381.         npr(get_string(1378));
  382.         ch=ynq();
  383.         if (ch=='Y') {
  384.           abort=1;
  385.           curdir=i;
  386.           break;
  387.         } else if (ch=='Q') {
  388.           abort=1;
  389.           if (okconf(&thisuser))
  390.             setuconf(CONF_DIRS, oc, os);
  391.           break;
  392.         }
  393.       }
  394.       ++i;
  395.     }
  396.     c++;
  397.     if (!okconf(&thisuser))
  398.       break;
  399.   }
  400.   if ((okconf(&thisuser)) && (!abort))
  401.     setuconf(CONF_DIRS, oc, os);
  402. }
  403.  
  404. /****************************************************************************/
  405.  
  406. void valscan(void)
  407. {  /* kcc */
  408.   int os, ac, sn, i, i1, done, val, next;
  409.   userrec tu;
  410.   postrec *p1, p2;
  411.   char s[81], ch;
  412.   unsigned long sq;
  413.  
  414.   /* Must be local cosysop or better */
  415.   if (!lcs())
  416.     return;
  417.  
  418.   ac=done=0; os=cursub;
  419.  
  420.   if ((uconfsub[1].confnum!=-1) && (okconf(&thisuser))) {
  421.     ac=1;
  422.     tmp_disable_conf(1);
  423.   }
  424.  
  425.   done=0;
  426.   for (sn=0; (sn<num_subs) && (!hangup) && (!done); sn++) {
  427.     if (!iscan(sn))
  428.       continue;
  429.     if (curlsub<0)
  430.       return;
  431.  
  432.     sq=qsc_p[sn];
  433.  
  434.     /* Must be sub with validation "on" */
  435.     if ((!(xsubs[curlsub].num_nets)) || (!(subboards[curlsub].anony & anony_val_net)))
  436.       continue;
  437.  
  438.     nl();
  439.     ansic(2);
  440.     npr("{{ %s %s }}",get_string(1623), subboards[curlsub].name);
  441.     nl();
  442.  
  443.     for (i=0; (i<=nummsgs) && (!hangup) && (!done); i++) {
  444.       if (get_post(i)->status & status_pending_net) {
  445.         checkhangup();
  446.         tleft(1);
  447.         if ((i>0) && (i<=nummsgs)) {
  448.           read_message(i,&next,&val);
  449.           npr("4[4%s: %s1]",get_string(1624), subboards[curlsub].name);
  450.           nl();
  451.           outstr(get_string(1499));
  452.           ch=onek("QDVMR");
  453.           switch (ch) {
  454.             case 'Q':
  455.               done=1;
  456.               break;
  457.             case 'R':
  458.               i--;
  459.               continue;
  460.             case 'V':
  461.               open_sub(1);
  462.               resynch(curlsub, &i, NULL);
  463.               p1=get_post(i);
  464.               p1->status &= ~status_pending_net;
  465.               write_post(i, p1);
  466.               close_sub();
  467.               send_net_post(p1, subboards[curlsub].filename, curlsub);
  468.               nl();
  469.               pl(get_string(1500));
  470.               nl();
  471.               break;
  472.             case 'M':
  473.               if ((lcs()) && (i>0) && (i<=nummsgs) &&
  474.                   (subboards[curlsub].anony & anony_val_net) &&
  475.                   (xsubs[curlsub].num_nets)) {
  476.                 open_sub(1);
  477.                 resynch(curlsub, &i, NULL);
  478.                 p1=get_post(i);
  479.                 p1->status &= ~status_pending_net;
  480.                 write_post(i, p1);
  481.                 close_sub();
  482.                 nl();
  483.                 pl(get_string(684));
  484.                 nl();
  485.               }
  486.               break;
  487.             case 'D':
  488.               if (lcs()) {
  489.                 if (i) {
  490.                   open_sub(1);
  491.                   resynch(curlsub, &i, NULL);
  492.                   p2=*get_post(i);
  493.                   delete(i);
  494.                   close_sub();
  495.                   if (p2.ownersys==0) {
  496.                     read_user(p2.owneruser,&tu);
  497.                     if ((tu.inact & inact_deleted)==0) {
  498.                       if (date_to_daten(tu.firston) < p2.daten) {
  499.                         nl();
  500.                         prt(2,get_string(980));
  501.                         mpl(3);
  502.                         input(s,3);
  503.                         if (s[0])
  504.                           i1=(atoi(s));
  505.                         else
  506.                           i1=1;
  507.                         if (i1>tu.msgpost)
  508.                           i1=tu.msgpost;
  509.                         if (i1)
  510.                           tu.msgpost-=i1;
  511.                         nl();
  512.                         ansic(3);
  513.                         outstr(get_string(993));
  514.                         pln(i1);
  515.                         tu.deletedposts++;
  516.                         write_user(p2.owneruser,&tu);
  517.                         topscreen();
  518.                       }
  519.                     }
  520.                   }
  521.                   resynch(curlsub, &i, &p2);
  522.                 }
  523.               }
  524.               break;
  525.           }
  526.         }
  527.       }
  528.     }
  529.     qsc_p[sn]=sq;
  530.   }
  531.  
  532.   if (ac)
  533.     tmp_disable_conf(0);
  534.  
  535.   cursub=os;
  536. }
  537.  
  538.