home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / W / DEVBBS.ZIP / MISCCMD.C < prev    next >
Text File  |  1992-07-20  |  15KB  |  622 lines

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