home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / WWIV2.ZIP / MISCCMD.C < prev    next >
Text File  |  1995-12-10  |  14KB  |  634 lines

  1. #include "vars.h"
  2.  
  3. #pragma hdrstop
  4.  
  5.  
  6. void read_automessage(void)
  7. {
  8.   int i,i1,i2,i3,f,len,ptrbeg[10],ptrend[10];
  9.   char s[81],l[6][81],anon,buf[512];
  10.   slrec ss;
  11.  
  12.   sprintf(s,"%sAUTO.MSG",syscfg.gfilesdir);
  13.   f=open(s,O_RDWR | O_BINARY);
  14.   nl();
  15.   anon=status.amsganon;
  16.   if (f<1) {
  17.     pl("2No auto-message.");
  18.   } else {
  19.     len=read(f,(void *)buf,512);
  20.     close(f);
  21.     for (i=0; i<10; i++) {
  22.       ptrbeg[i]=0;
  23.       ptrend[i]=0;
  24.     }
  25.     i=0;
  26.     i1=0;
  27.     i2=0;
  28.     for(i=0; i<len; i++) {
  29.       if (i1) {
  30.         if (buf[i]==10) {
  31.           ptrbeg[i2]=i+1;
  32.           i1=0;
  33.         }
  34.       } else {
  35.         if (buf[i]==13) {
  36.           ptrend[i2]=i-1;
  37.           if (i2<6) {
  38.             for (i3=ptrbeg[i2]; i3<=ptrend[i2]; i3++)
  39.               l[i2][i3-ptrbeg[i2]]=buf[i3];
  40.               l[i2][ptrend[i2]-ptrbeg[i2]+1]=0;
  41.           }
  42.           ++i2;
  43.           i1=1;
  44.         }
  45.       }
  46.     }
  47.     ss=syscfg.sl[actsl];
  48.     if (anon)
  49.       if (ss.ability & ability_read_post_anony) {
  50.     sprintf(s,"3<<< 5%s 3>>>",&(l[0][0]));
  51.       } else
  52.     strcpy(s,"7>1Unknown7<");
  53.     else
  54.       strcpy(s,&(l[0][0]));
  55.     nl();
  56.     pl("3┌──────────────────────────────────────∙∙∙∙∙ ∙ ∙  ∙");
  57.    npr("3│ 1Auto message by7: 1"); pl(s);
  58.     pl("3├──────────────────────────────────────∙∙∙∙∙ ∙ ∙  ∙");
  59.     i=1;
  60.     while ((ptrend[i]) && (i<6)) {
  61.       npr("3│ 5");
  62.       pl(&(l[i][0]));
  63.       ++i;
  64.     }
  65.   }
  66.   pl("3└──────────────────────────────────────∙∙∙∙∙ ∙ ∙  ∙");
  67.   nl();
  68. }
  69.  
  70. void write_automessage1(void)
  71. {
  72.   int i,i1,f;
  73.   char s[81],l[4][81];
  74.   slrec ss;
  75.  
  76.   nl();
  77.   pl(get_string(484));
  78.   nl();
  79.   for (i=0; i<3; i++) {
  80.     npr("%d:",i+1);
  81.     inputl(&(l[i][0]),39);
  82.     strcat(&(l[i][0]),"\r\n");
  83.   }
  84.   nl();
  85.   ss=syscfg.sl[actsl];
  86.   if (ss.ability & ability_post_anony) {
  87.     prt(5,get_string(485));
  88.     if (yn())
  89.       i1=anony_sender;
  90.     else
  91.       i1=0;
  92.   } else
  93.     i1=0;
  94.   prt(5,get_string(438));
  95.   if (yn()) {
  96.     status.amsganon=i1;
  97.     status.amsguser=usernum;
  98.     save_status();
  99.     sprintf(s,"%sAUTO.MSG",syscfg.gfilesdir);
  100.     f=open(s,O_RDWR | O_BINARY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
  101.     strcpy(s,nam(&thisuser,usernum));
  102.     strcat(s,"\r\n");
  103.     write(f,(void *)s,strlen(s));
  104.     for (i=0; i<3; i++)
  105.       write(f,(void *)&(l[i][0]),strlen(&(l[i][0])));
  106.     sysoplog(get_stringx(1,24));
  107.     for (i=0; i<3; i++) {
  108.       strcpy(s,"   ");
  109.       l[i][strlen(&(l[i][0]))-2]=0;
  110.       strcat(s,&(l[i][0]));
  111.       sysoplog(s);
  112.     }
  113.     nl();
  114.     pl(get_string(486));
  115.     nl();
  116.     close(f);
  117.   }
  118.  
  119. }
  120.  
  121. void write_automessage(void)
  122. {
  123.   char ch;
  124.   int done,okwrite;
  125.   slrec ss;
  126.  
  127.   ss=syscfg.sl[actsl];
  128.   if (ss.posts)
  129.     okwrite=1;
  130.   else
  131.     okwrite=0;
  132.   if (thisuser.restrict & restrict_automessage)
  133.     okwrite=0;
  134.   done=0;
  135.   do {
  136.     nl();
  137.     if (okwrite) {
  138.       prt(2,get_string(487));
  139.       ch=onek("QRWA");
  140.     } else {
  141.       prt(2,get_string(488));
  142.       ch=onek("QRA");
  143.     }
  144.     switch(ch) {
  145.       case 'Q':
  146.         done=1;
  147.         break;
  148.       case 'R':
  149.         read_automessage();
  150.         break;
  151.       case 'W':
  152.         write_automessage1();
  153.         break;
  154.       case 'A':
  155.         grab_quotes(NULL, NULL);
  156.         if (status.amsguser)
  157.           email(status.amsguser,0,0,status.amsganon);
  158.         break;
  159.     }
  160.   } while ((!done) && (!hangup));
  161.  
  162. }
  163.  
  164.  
  165. void bbslist(void)
  166. {
  167.   int i,i1,i2,f,done,ok;
  168.   char s[150],s1[150],s2[150],ch,ch1,*ss;
  169.   char phone[13], name[51], speed[5], type[5];
  170.   long l,l1;
  171.  
  172.   done=0;
  173.   do {
  174.     nl();
  175.     prt(2,get_string(489));
  176.     ch=onek("QRNA");
  177.     switch(ch) {
  178.       case 'Q':
  179.         done=1;
  180.         break;
  181.       case 'R':
  182.         printfile("BBSLIST.MSG");
  183.         break;
  184.       case 'N':
  185.         print_net_listing(0);
  186.     break;
  187.       case 'A':
  188.         if ((actsl<=10)) {
  189.           nl();
  190.           nl();
  191.           pl(get_string(490));
  192.           nl();
  193.           break;
  194.         }
  195.     if (thisuser.restrict & restrict_automessage) {
  196.           nl();
  197.           nl();
  198.           pl(get_string(491));
  199.           nl();
  200.           break;
  201.     }
  202.         nl();
  203.         pl(get_string(492));
  204.         pl(get_string(493));
  205.         outstr(":");
  206.         mpl(12);
  207.         input(phone,12);
  208.         if ((phone[3]!='-') || (phone[7]!='-'))
  209.           phone[0]=0;
  210.         if (strlen(phone)==12) {
  211.           ok=1;
  212.           sprintf(s1,"%sBBSLIST.MSG",syscfg.gfilesdir);
  213.           f=open(s1,O_RDWR | O_CREAT | O_BINARY, S_IREAD | S_IWRITE);
  214.           if (f>0) {
  215.             lseek(f,0L,SEEK_SET);
  216.             l=filelength(f);
  217.             if ((ss=malloca(l+500L))==NULL) {
  218.               close(f);
  219.               return;
  220.             }
  221.             read(f,ss,(int)l);
  222.             l1=0L;
  223.             while ((l1<l) && (ok)) {
  224.               i=0;
  225.               do {
  226.                 ch=ss[l1++];
  227.                 s1[i]=ch;
  228.                 if (ch==13)
  229.                   s1[i]=0;
  230.                 ++i;
  231.               } while ((ch!=10) && (i<120) && (l1<l));
  232.               if (strstr(s1,phone)!=NULL)
  233.                 ok=0;
  234.               if (strncmp(s1,phone,12)==0)
  235.         ok=0;
  236.             }
  237.             farfree(ss);
  238.             close(f);
  239.           }
  240.           if (ok) {
  241.             pl(get_string(494));
  242.             nl();
  243.             nl();
  244.             pl(get_string(495));
  245.             outstr(":");
  246.             mpl(50);
  247.             inputl(name,50);
  248.             nl();
  249.             pl(get_string(496));
  250.             pl(get_string(497));
  251.             outstr(":");
  252.             mpl(4);
  253.             input(speed,4);
  254.             nl();
  255.             pl(get_string(498));
  256.             outstr(":");
  257.             mpl(4);
  258.             input(type,4);
  259.             sprintf(s,"%12s  %-50s  [%4s] (%4s)\r\n",
  260.               phone, name, speed, type);
  261.             nl();
  262.             nl();
  263.             pl(s);
  264.             nl();
  265.             prt(5,get_string(499));
  266.             if (yn()) {
  267.               sprintf(s1,"%sBBSLIST.MSG",syscfg.gfilesdir);
  268.               f=open(s1,O_RDWR | O_CREAT | O_BINARY, S_IREAD | S_IWRITE);
  269.           if (filelength(f)) {
  270.                 lseek(f,-1L,SEEK_END);
  271.                 read(f,((void *)&ch1),1);
  272.                 if (ch1==26)
  273.                   lseek(f,-1L,SEEK_END);
  274.           }
  275.               write(f,(void *)s,strlen(s));
  276.               close(f);
  277.               nl();
  278.               pl(get_string(500));
  279.             }
  280.           } else {
  281.             pl(get_string(501));
  282.             nl();
  283.             nl();
  284.           }
  285.         } else {
  286.       nl();
  287.       pl(get_string(502));
  288.       nl();
  289.     }
  290.         break;
  291.     }
  292.   } while ((!done) && (!hangup));
  293. }
  294.  
  295.  
  296. void kill_old_email(void)
  297. {
  298.   int cur,max,i,i1,f,done,done1,forward;
  299.   char s[81],s1[81],ch;
  300.   long l;
  301.   mailrec m;
  302.   userrec u;
  303.   slrec ss;
  304.  
  305.   prt(5,get_string(503));
  306.   forward=(yn());
  307.   ss=syscfg.sl[actsl];
  308.   sprintf(s,"%sEMAIL.DAT",syscfg.datadir);
  309.   f=open(s,O_RDWR | O_BINARY);
  310.   if (f==-1) {
  311.     nl();
  312.     pl(get_string(504));
  313.     return;
  314.   }
  315.   max=(int) (filelength(f) / sizeof(mailrec));
  316.   if (forward)
  317.     cur=max-1;
  318.   else
  319.     cur=0;
  320.   done=0;
  321.   do {
  322.     lseek(f,((long) cur) * sizeof(mailrec), SEEK_SET);
  323.     read(f,(void *)&m,sizeof(mailrec));
  324.     while (((m.fromsys!=0) || (m.fromuser!=usernum) || (m.touser==0)) && (cur<max) && (cur>=0)) {
  325.       if (forward)
  326.         --cur;
  327.       else
  328.         ++cur;
  329.       if ((cur<max) && (cur>=0)) {
  330.         lseek(f,((long) cur) * sizeof(mailrec), SEEK_SET);
  331.         read(f,(void *)&m,sizeof(mailrec));
  332.       }
  333.     }
  334.     if ((m.fromsys!=0) || (m.fromuser!=usernum) || (m.touser==0) || (cur>=max) || (cur<0))
  335.       done=1;
  336.     else {
  337.       do {
  338.         done1=0;
  339.         nl();
  340.         outstr(get_string(325));
  341.         if (m.tosys==0) {
  342.           read_user(m.touser,&u);
  343.           strcpy(s1,nam(&u,m.touser));
  344.           if ((m.anony & (anony_receiver | anony_receiver_pp | anony_receiver_da))
  345.               && ((ss.ability & ability_read_email_anony)==0))
  346.             strcpy(s1,get_string(482));
  347.           pl(s1);
  348.         } else {
  349.           npr("#%u @%u\r\n",m.touser, m.tosys);
  350.         }
  351.         outstr(get_string(326));
  352.         pl(m.title);
  353.         time(&l);
  354.         i=(int) ((l-m.daten)/24.0/3600.0);
  355.         outstr(get_string(505));
  356.         npr("%d ",i);
  357.         pl(get_string(506));
  358.         nl();
  359.         prt(2,get_string(507));
  360.         ch=onek("QRDN");
  361.         switch(ch) {
  362.           case 'Q':
  363.             done1=1;
  364.             done=1;
  365.             break;
  366.           case 'N':
  367.             done1=1;
  368.             if (forward)
  369.               --cur;
  370.             else
  371.               ++cur;
  372.             if ((cur>=max) || (cur<0))
  373.               done=1;
  374.             break;
  375.           case 'D':
  376.             done1=1;
  377.             delmail(f,cur);
  378.             nl();
  379.             pl(get_string(508));
  380.             nl();
  381.             sysoplog(get_stringx(1, 100));
  382.             break;
  383.           case 'R':
  384.             nl();
  385.             nl();
  386.             outstr(get_string(326));
  387.             pl(m.title);
  388.             setorigin(0,0);
  389.             read_message1(&m.msg,(m.anony & 0x0f), 0, &i1,"EMAIL");
  390.             break;
  391.         }
  392.       } while ((!hangup) && (!done1));
  393.     }
  394.   } while ((!done) && (!hangup));
  395.   close(f);
  396. }
  397.  
  398. void list_users(void)
  399. {
  400.   subboardrec s;
  401.   userrec u;
  402.   int i,nu,abort,ok,num;
  403.   char st[81];
  404.  
  405.   if (usub[cursub].subnum==-1) {
  406.     nl();
  407.     pl(get_string(510));
  408.     nl();
  409.     return;
  410.   }
  411.   s=subboards[usub[cursub].subnum];
  412.   nl();
  413.   pl(get_string(511));
  414.   nl();
  415.   abort=0;
  416.   num=0;
  417.   for (i=0; (i<status.users) && (!abort) && (!hangup); i++) {
  418.     read_user(smallist[i].number,&u);
  419.     ok=1;
  420.     if (u.sl<s.readsl)
  421.       ok=0;
  422.     if (u.age<(s.age&0x7f))
  423.       ok=0;
  424.     if ((s.ar!=0) && ((u.ar & s.ar)==0))
  425.       ok=0;
  426.     if (ok) {
  427.       pla(nam(&u,smallist[i].number),&abort);
  428.       ++num;
  429.     }
  430.   }
  431.   if (!abort) {
  432.     nl();
  433.     npr("%d ",num);
  434.     pl(get_string(512));
  435.     nl();
  436.   }
  437. }
  438.  
  439. void print_quest(int f, int mapp, int map[21])
  440. {
  441.   char s[100];
  442.   int i,abort;
  443.   votingrec v;
  444.  
  445.   outchr(12);
  446.   abort=0;
  447.   for (i=1; (i<=mapp) && (abort==0); i++) {
  448.     lseek(f,((long) (map[i])) * sizeof(votingrec), SEEK_SET);
  449.     read(f,(void *)&v,sizeof(votingrec));
  450.     sprintf(s,"%c %2d: %s",
  451.       thisuser.votes[map[i]]?' ':'*',i, v.question);
  452.     pla(s,&abort);
  453.   }
  454.   nl();
  455.   if (abort)
  456.     nl();
  457. }
  458.  
  459.  
  460. int print_question(int f, int i, int ii)
  461. {
  462.   char s[81],s1[81],s2[81];
  463.   int i1,i2,i3,t,t1,abort;
  464.   votingrec v;
  465.   voting_response vr;
  466.  
  467.   lseek(f,((long) ii)*sizeof(votingrec),SEEK_SET);
  468.   read(f,(void *)&v,sizeof(votingrec));
  469.   abort=0;
  470.  
  471.   outchr(12);
  472.   sprintf(s,"%s%d",get_string(513),i); /*Voting Question # */
  473.   pla(s,&abort);
  474.   pla(v.question,&abort);
  475.   nl();
  476.   t=0;
  477.   for (i1=0; i1<v.numanswers; i1++) {
  478.     vr=v.responses[i1];
  479.     t+=vr.numresponses;
  480.   }
  481.  
  482.   sprintf(s,"%s: %4.1f%%\r\n",get_string(514),
  483.     ((double) t) / ((double) status.users) * 100.0);
  484.   pla(s,&abort);
  485.   nl();
  486.   if (t)
  487.     t1=t;
  488.   else
  489.     t1=1;
  490.   pla(get_string(515),&abort);
  491.   for (i1=0; i1<5; i1++)
  492.     odc[i1]=0;
  493.   for (i1=0; (i1<v.numanswers) && (!abort); i1++) {
  494.     vr=v.responses[i1];
  495.     if (((i1+1) % 10)==0)
  496.       odc[((i1+1)/10)-1]='0'+((i1+1)/10);
  497.     sprintf(s,"%2d: %-60s : %4d  %5.1f%%",
  498.       i1+1, vr.response, vr.numresponses,
  499.       ((float)vr.numresponses)/((float)t1)*100.0);
  500.     pla(s,&abort);
  501.   }
  502.   nl();
  503.   if (abort)
  504.     nl();
  505.   return(!abort);
  506. }
  507.  
  508.  
  509. void vote_question(int f, int i, int ii)
  510. {
  511.   int ok,pqo,i1,i2;
  512.   char s[81],*ss;
  513.   votingrec v;
  514.   voting_response vr;
  515.  
  516.   pqo=print_question(f,i,ii);
  517.   ok=pqo;
  518.   ok=1;
  519.   if (restrict_vote & thisuser.restrict)
  520.     ok=0;
  521.   if (actsl<=10)
  522.     ok=0;
  523.   if (!ok)
  524.     return;
  525.  
  526.   lseek(f,((long) ii)*sizeof(votingrec),SEEK_SET);
  527.   read(f,(void *)&v,sizeof(votingrec));
  528.  
  529.   strcpy(s,get_string(516)); /* Your vote: */
  530.   vr=v.responses[thisuser.votes[ii]-1];
  531.   if (thisuser.votes[ii])
  532.     strcat(s,vr.response);
  533.   else
  534.     strcat(s,get_string(517)); /* No Comment */
  535.   pl(s);
  536.   nl();
  537.   prt(5,get_string(264)); /* Change it? */
  538.   if (!yn())
  539.     return;
  540.  
  541.   prt(2,get_string(297)); /* Which */
  542.   ss=mmkey(2);
  543.   i1=atoi(ss);
  544.   if (i1>v.numanswers)
  545.     i1=0;
  546.   if ((i1==0) && (strcmp(ss,"0")))
  547.     return;
  548.  
  549.   if (thisuser.votes[ii]) {
  550.     vr=v.responses[thisuser.votes[ii]-1];
  551.     --vr.numresponses;
  552.     v.responses[thisuser.votes[ii]-1]=vr;
  553.   }
  554.   thisuser.votes[ii]=i1;
  555.   if (i1) {
  556.     vr=v.responses[thisuser.votes[ii]-1];
  557.     ++vr.numresponses;
  558.     v.responses[thisuser.votes[ii]-1]=vr;
  559.   }
  560.   lseek(f,((long) ii)*sizeof(votingrec),SEEK_SET);
  561.   write(f,(void *)&v,sizeof(votingrec));
  562.   nl();
  563.   nl();
  564. }
  565.  
  566.  
  567. void vote(void)
  568. {
  569.   int i,i1,i2,mod1,mo,f,map[21],mapp,abort,n,done;
  570.   char s[81],s1[81],s2[81],sodc[10],*ss;
  571.   votingrec v;
  572.  
  573.   sprintf(s,"%sVOTING.DAT",syscfg.datadir);
  574.   f=open(s,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  575.   n=(int) (filelength(f) / sizeof(votingrec)) -1;
  576.   if (n<20) {
  577.     v.question[0]=0;
  578.     v.numanswers=0;
  579.     for (i=n; i<20; i++)
  580.       write(f,(void *)&v,sizeof(votingrec));
  581.   }
  582.   mapp=0;
  583.   for (i=0; i<5; i++)
  584.     odc[i]=0;
  585.   for (i=0; i<20; i++) {
  586.     lseek(f,((long) i) * sizeof(votingrec),SEEK_SET);
  587.     read(f,(void *)&v,sizeof(votingrec));
  588.     if (v.numanswers) {
  589.       map[++mapp]=i;
  590.       if ((mapp % 10)==0)
  591.         odc[(mapp/10)-1]='0'+(mapp/10);
  592.     }
  593.   }
  594.   strcpy(sodc,odc);
  595.   if (mapp==0) {
  596.     nl();
  597.     nl();
  598.     pl(get_string(518)); /*No Voting Questions */
  599.     nl();
  600.     close(f);
  601.     return;
  602.   }
  603.   print_quest(f,mapp,&map[0]);
  604.   done=0;
  605.   do {
  606.     nl();
  607.     nl();
  608.     prt(2,get_string(519)); /*Voting #, Q? */
  609.     strcpy(odc,sodc);
  610.     ss=mmkey(2);
  611.     i=atoi(ss);
  612.     if ((i>0) && (i<=mapp))
  613.       vote_question(f,i,map[i]);
  614.     else
  615.       if (strcmp(ss,"Q")==0) {
  616.      mod1=0;
  617.   for (mo=0; mo<20; mo++) {
  618.     if (questused[mo])
  619.       if (thisuser.votes[mo]==0)
  620.     mod1=1;
  621.   }      if (mod1==1) { prt(1,"You can't quit yet! You didn't vote!\r\n");
  622. }
  623.        else
  624.     done=1;
  625.     }
  626.       else
  627.         if (strcmp(ss,"?")==0)
  628.           print_quest(f,mapp,&map[0]);
  629.   } while ((!done) && (!hangup));
  630.   close(f);
  631. }
  632.  
  633.  
  634.