home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / UTIL / WWIVE / BBSUTL.C < prev    next >
Text File  |  1992-05-05  |  16KB  |  636 lines

  1. /*****************************************************************************
  2.  
  3.                 WWIV Version 4
  4.                     Copyright (C) 1988-1991 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. #include <ctype.h>
  19.  
  20. #pragma hdrstop
  21.  
  22.  
  23. void far *malloca(unsigned long nbytes)
  24. {
  25.   void *buf;
  26.  
  27.   buf=farmalloc(nbytes+1);
  28.   if (buf==NULL) {
  29.     nl();
  30.     npr("Not enough memory, needed %ld bytes.\r\n",nbytes);
  31.     nl();
  32.     sysoplog("!!! Ran out of memory !!!");
  33.   }
  34.   return(buf);
  35. }
  36.  
  37.  
  38.  
  39. void stuff_in(char *s, char *s1, char *f1, char *f2, char *f3, char *f4, char *f5)
  40. {
  41.   int r=0,w=0;
  42.  
  43.   while (s1[r]!=0) {
  44.     if (s1[r]=='%') {
  45.       ++r;
  46.       s[w]=0;
  47.       switch(s1[r]) {
  48.         case '1': strcat(s,f1); break;
  49.         case '2': strcat(s,f2); break;
  50.         case '3': strcat(s,f3); break;
  51.         case '4': strcat(s,f4); break;
  52.         case '5': strcat(s,f5); break;
  53.       }
  54.       w=strlen(s);
  55.       r++;
  56.     } else
  57.       s[w++]=s1[r++];
  58.   }
  59.   s[w]=0;
  60. }
  61.  
  62. void copy_line(char *s, char *b, long *ptr, long len)
  63. {
  64.   int i;
  65.   long l;
  66.  
  67.   if (*ptr>=len) {
  68.     s[0]=0;
  69.     return;
  70.   }
  71.   l=*ptr;
  72.   i=0;
  73.   while ((b[l]!='\r') && (b[l]!='\n') && (l<len)) {
  74.     s[i++]=b[l++];
  75.   }
  76.   s[i]=0;
  77.   if ((b[l]=='\r') && (l<len))
  78.     ++l;
  79.   if ((b[l]=='\n') && (l<len))
  80.     ++l;
  81.   *ptr=l;
  82. }
  83.  
  84. char *mmkey(int dl)
  85. {
  86.   static unsigned char cmd1[10],cmd2[81],ch;
  87.   int i,i1,i2,p;
  88.  
  89.   do {
  90.     do {
  91.       ch=getkey();
  92.     } while ((((ch<' ') && (ch!=13)) || (ch>126)) && (hangup==0));
  93.     ch=upcase(ch);
  94.     outchr(ch);
  95.     if (ch==13)
  96.       cmd1[0]=0;
  97.     else
  98.       cmd1[0]=ch;
  99.     cmd1[1]=0;
  100.     p=0;
  101.     switch(dl) {
  102.  
  103.     case 1: /*Transfer Section*/
  104.       if (strchr(dcd,ch)!=NULL)
  105.     p=1;
  106.       if (ch=='?')npr("\b 4 Help","");
  107.       if (ch=='*')npr("\b 4 List Directories ","");
  108.       if (ch=='A')npr("\b 4 ARC Listing of File ","");
  109.       if (ch=='B')npr("\b 4 Batch d'load Commands ","");
  110.       if (ch=='C')npr("\b 4 Chat with SysOp ","");
  111.       if (ch=='D')npr("\b 4 Download a File ","");
  112.       if (ch=='E')npr("\b 4 Extract a File ","");
  113.       if (ch=='F')npr("\b 4 Find a File ","");
  114.       if (ch=='G')npr("\b 4 ARC Commands ","");
  115.       if (ch=='Y')npr("\b 4 Your Information ","");
  116.       if (ch=='L')npr("\b 4 List Files ","");
  117.       if (ch=='M')npr("\b 4 Move a File ","");
  118.       if (ch=='N')npr("\b 4 New Scan ","");
  119.       if (ch=='O')npr("\b 4 Log Off ","");
  120.       if (ch=='P')npr("\b 4 Set N-Scan Date ","");
  121.       if (ch=='Q')npr("\b 4 Quit to Main Menu ","");
  122.       if (ch=='R')npr("\b 4 Remove a File ","");
  123.       if (ch=='S')npr("\b 4 Search For File ","");
  124.       if (ch=='T')npr("\b 4 Transfer Defaults ","");
  125.       if (ch=='U')npr("\b 4 Upload a File ","");
  126.       if (ch=='V')npr("\b 4 View a File ","");
  127.       if (ch=='X')npr("\b 4 Batch Download ","");
  128.       if (ch=='Z')npr("\b 4 Upload to SysOp ","");
  129.       if ((ch=='>') || (ch=='+'))npr("\b 4 Up 1 Directory ","");
  130.       if ((ch=='<') || (ch=='-'))npr("\b 4 Down 1 Directory ","");
  131.       break;
  132.     case 2:
  133.       if (strchr(odc,ch)!=NULL)
  134.         p=1;
  135.       break;
  136.     case 0: /*Main Menu*/
  137.       if (strchr(dc,ch)!=NULL)
  138.     p=1;
  139.       if ((ch=='>') || (ch=='+'))npr("\b 4 Up 1 Sub ","");
  140.       if ((ch=='<') || (ch=='-'))npr("\b 4 Down 1 Sub ","");
  141.       if (ch=='*')npr("\b 4 List Subs ","");
  142.       if (ch=='?')npr("\b 4 Help ","");
  143.       if (ch=='.')npr("\b 4 Online Games ","");
  144.       if (ch=='A')npr("\b 4 Auto-Message ","");
  145.       if (ch=='B')npr("\b 4 BBS List ","");
  146.       if (ch=='C')npr("\b 4 Chat with SysOp ","");
  147.       if (ch=='D')npr("\b 4 Defaults ","");
  148.       if (ch=='E')npr("\b 4 E-Mail a User ","");
  149.       if (ch=='F')npr("\b 4 Feedback to SysOp ","");
  150.       if (ch=='G')npr("\b 4 G-Files ","");
  151.       if (ch=='I')npr("\b 4 Information ","");
  152.       if (ch=='K')npr("\b 4 Kill old Email ","");
  153.       if (ch=='L')npr("\b 4 Log of Callers ","");
  154.       if (ch=='M')npr("\b 4 Mail Read ","");
  155.       if (ch=='N')npr("\b 4 New Scan ","");
  156.       if (ch=='O')npr("\b 4 Log Off ","");
  157.       if (ch=='P')npr("\b 4 Post a Message ","");
  158.       if (ch=='Q')npr("\b 4 Q-Scan Current Sub ","");
  159.       if (ch=='R')npr("\b 4 Remove a Post ","");
  160.       if (ch=='S')npr("\b 4 Scan Sub ","");
  161.       if (ch=='T')npr("\b 4 Transfer Section ","");
  162.       if (ch=='U')npr("\b 4 List Users ","");
  163.       if (ch=='V')npr("\b 4 Voting Section ","");
  164.       if (ch=='X')npr("\b 4 Expert/Novice Toggle ","");
  165.       if (ch=='Y')npr("\b 4 Your Information ","");
  166.       if (ch=='Z')npr("\b 4 Express N-Scan ","");
  167.       break;
  168.     }
  169.     if (p) {
  170.       do {
  171.         ch=getkey();
  172.       } while ((((ch<' ') && (ch!=13) && (ch!=8)) || (ch>126)) && (hangup==0));
  173.       ch=upcase(ch);
  174.       if (ch==13) {
  175.         nl();
  176.         return(cmd1);
  177.       } else
  178.         if (ch==8) {
  179.           backspace();
  180.         } else {
  181.           cmd1[1]=ch;
  182.           cmd1[2]=0;
  183.           outchr(ch);
  184.           if (ch=='/') {
  185.             input(cmd2,50);
  186.             return(cmd2);
  187.           } else
  188.             nl();
  189.             return(cmd1);
  190.         }
  191.     } else {
  192.       nl();
  193.       return(cmd1);
  194.     }
  195.   } while (hangup==0);
  196.   cmd1[0]=0;
  197.   return(cmd1);
  198. }
  199.  
  200.  
  201. void inli(char *s, char *rollover, int maxlen, int crend)
  202. {
  203.   int cp,i,i1,done,cm,begx,remove,count,posit;
  204.   char s1[255],s2[255];
  205.   unsigned char ch;
  206.  
  207.   cm=chatting;
  208.  
  209.   begx=wherex();
  210.   if (rollover[0]!=0) {
  211.   if (charbufferpointer) {
  212.     strcpy(s1,rollover);
  213.     strcat(s1,&charbuffer[charbufferpointer]);
  214.     strcpy(&charbuffer[1],s1);
  215.     charbufferpointer=1;
  216.   } else {
  217.     strcpy(&charbuffer[1],rollover);
  218.     charbufferpointer=1; }
  219.     rollover[0]=0;
  220.   }
  221.   cp=0;
  222.   done=0;
  223.   do {
  224.     ch=getkey();
  225.     if (two_color)
  226.       if (lastcon)
  227.     ansic(1);
  228.       else
  229.     ansic(0);
  230.     if (cm)
  231.       if (chatting==0)
  232.         ch=13;
  233.     if ((ch>=32)) {
  234.       if ((wherex()<(thisuser.screenchars-1)) && (cp<maxlen)) {
  235.         s[cp++]=ch;
  236.     outchr(ch);
  237.         if (wherex()==(thisuser.screenchars-1))
  238.           done=1;
  239.       } else {
  240.         if (wherex()>=(thisuser.screenchars-1))
  241.           done=1;
  242.       }
  243.     } else
  244.         switch(ch) {
  245.       case 7:
  246.         if ((chatting) && (outcom))
  247.           outcomch(7);
  248.         break;
  249.           case 13: /* C/R */
  250.             s[cp]=0;
  251.             done=1;
  252.             break;
  253.           case 8:  /* Backspace */
  254.             if (cp) {
  255.               if (s[cp-2]==3) {
  256.                 cp-=2;
  257.                 ansic(0);
  258.               } else
  259.                 if (s[cp-1]==8) {
  260.                   cp--;
  261.                   outchr(32);
  262.                 } else {
  263.                   cp--;
  264.                   backspace();
  265.                 }
  266.             }
  267.             break;
  268.           case 24: /* Ctrl-X */
  269.             while (wherex()>begx) {
  270.               backspace();
  271.               cp=0;
  272.             }
  273.             ansic(0);
  274.             break;
  275.           case 23: /* Ctrl-W */
  276.             if (cp) {
  277.               do {
  278.                 if (s[cp-2]==3) {
  279.                   cp-=2;
  280.                   ansic(0);
  281.                 } else
  282.                   if (s[cp-1]==8) {
  283.                     cp--;
  284.                     outchr(32);
  285.                   } else {
  286.                     cp--;
  287.                     backspace();
  288.                   }
  289.           } while ((cp) && (s[cp-1]!=32) && (s[cp-1]!=8) && (s[cp-2]!=3));
  290.         }
  291.         break;
  292.       case 14: /* Ctrl-N */
  293.         if ((wherex()) && (cp<maxlen)) {
  294.           outchr(8);
  295.           s[cp++]=8;
  296.         }
  297.         break;
  298.       case 16: /* Ctrl-P */
  299.         if (cp<maxlen-1) {
  300.           ch=getkey();
  301.           if (((ch>='0') && (ch<='9')) || ((ch>='A') && (ch<='F')) || ((ch>='a') && (ch<='f'))) {
  302.         s[cp++]=3;
  303.         s[cp++]=ch;
  304.         if ((ch>='0') && (ch<='9'))
  305.         ansic(ch-'0');
  306.           else if ((ch>='A') && (ch<='F'))
  307.         ansic(ch-'A'+10);
  308.           else ansic(ch-'a'+10);
  309.           }
  310.         }
  311.             break;
  312.           case 9:  /* Tab */
  313.             i=5-(cp % 5);
  314.             if (((cp+i)<maxlen) && ((wherex()+i)<thisuser.screenchars)) {
  315.           i=5-((wherex()+1) % 5);
  316.               for (i1=0; i1<i; i1++) {
  317.                 s[cp++]=32;
  318.                 outchr(32);
  319.               }
  320.             }
  321.             break;
  322.     }
  323. /*Profanity restrictor*/
  324.   if ((thisuser.ar & 4)==0)
  325.    {
  326.     remove=0;
  327.     strcpy(s2,"    ");
  328.     if (cp>=4) {
  329.        posit=1;count=0;
  330.        while ((posit<=cp) && (count<4))
  331.     if (isdigit(s[cp-posit]) && (s[cp-(posit+1)]==3)) posit+=2;
  332.       else if (s[cp-posit]==8) {posit++;remove++;}
  333.         else if (remove>0) {remove--;posit++;}
  334.              else {s2[3-count]=s[cp-posit];count++;posit++;}
  335.        strupr(s2);
  336.        if ((strcmp(s2,"DIS(")==0) || (strcmp(s2,"DIS!")==0) ||
  337.        (strcmp(s2,"DIS ")==0) || (strcmp(s2,"D!S ")==0) ||
  338.        (strcmp(s2,"DíS ")==0) || (strcmp(s2," YO ")==0) ||
  339.        (strcmp(s2,"JIVE")==0) || (strcmp(s2," RAP")==0) ||
  340.        (strcmp(s2,"MAMA")==0) || (strcmp(s2," YO!")==0) ||
  341.        (strcmp(s2,"YO! ")==0) || (strcmp(s2,"YO!Y")==0) ||
  342.        (strcmp(s2,"'YO'")==0) || (strcmp(s2,"DIS.")==0) ||
  343.        (strcmp(s2,"DAT ")==0) || (strcmp(s2,"DAT.")==0) ||
  344.        (strcmp(s2,"DAT!")==0) || (strcmp(s2,"DäT ")==0))
  345.      /*(strcmp(s2,"A$$ ")==0) || (strcmp(s2,"CHYT")==0) ||
  346.        (strcmp(s2,"AS$ ")==0) || (strcmp(s2," AS$")==0) ||
  347.        (strcmp(s2," ASS")==0) || (strcmp(s2,"FUKI")==0) ||
  348.        (strcmp(s2,"FUK ")==0) || (strcmp(s2,"SHLT")==0) ||
  349.        (strcmp(s2,"SH1T")==0) || (strcmp(s2,"SHYT")==0) ||
  350.        (strcmp(s2,"COCK")==0) || (strcmp(s2,"BAST")==0) ||
  351.        (strcmp(s2,"SH!T")==0) || (strcmp(s2,"SHT ")==0) ||
  352.        (strcmp(s2,"ASSS")==0) || (strcmp(s2,"PUSY")==0))*/
  353.        {backspace();backspace();backspace();backspace();
  354.        for (count=1;count<posit;count++) cp--;
  355.        outstr("\a6[CENSORED]0\a\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b");}
  356.        }
  357.     }
  358.   } while ((done==0) && (hangup==0));
  359.   if (ch!=13) {
  360.     i=cp-1;
  361.     while ((i>0) && (s[i]!=32) && (s[i]!=8) || (s[i-1]==3))
  362.       i--;
  363.     if ((i>(wherex()/2)) && (i!=(cp-1))) {
  364.       i1=cp-i-1;
  365.       for (i=0; i<i1; i++)
  366.         outchr(8);
  367.       for (i=0; i<i1; i++)
  368.         outchr(32);
  369.       for (i=0; i<i1; i++)
  370.         rollover[i]=s[cp-i1+i];
  371.       rollover[i1]=0;
  372.       cp -= i1;
  373.     }
  374.     s[cp++]=1;
  375.     s[cp]=0;
  376.   }
  377.   if (crend)
  378.     nl();
  379.  
  380. }
  381.  
  382.  
  383. int so()
  384. {
  385.   if (actsl==255)
  386.     return(1);
  387.   else
  388.     return(0);
  389. }
  390.  
  391.  
  392.  
  393. int cs()
  394. {
  395.   slrec ss;
  396.  
  397.   ss=syscfg.sl[actsl];
  398.   if (so())
  399.     return(1);
  400.   if (ss.ability & ability_cosysop)
  401.     return(1);
  402.   else
  403.     return(0);
  404. }
  405.  
  406.  
  407. int lcs()
  408. {
  409.   slrec ss;
  410.  
  411.   ss=syscfg.sl[actsl];
  412.   if (cs())
  413.     return(1);
  414.   if (ss.ability & ability_limited_cosysop) {
  415.     if (thisuser.sysopsub==255)
  416.       return(1);
  417.     if (thisuser.sysopsub==usub[cursub].subnum)
  418.       return(1);
  419.     else
  420.       return(0);
  421.   } else
  422.     return(0);
  423. }
  424.  
  425.  
  426. void checka(int *abort, int *next)
  427. {
  428.   char ch;
  429.  
  430.   while ((!empty()) && (!(*abort)) && (!hangup)) {
  431.     checkhangup();
  432.     ch=inkey();
  433.     lines_listed=0;
  434.     switch(ch) {
  435.       case 14:
  436.         *next=1;
  437.       case 3:
  438.       case 32:
  439.       case 24:
  440.         *abort=1;
  441.         break;
  442.       case 'P':
  443.       case 'p':
  444.       case 19:
  445.         ch=getkey();
  446.         break;
  447.     }
  448.   }
  449. }
  450.  
  451.  
  452. void pla(char *s, int *abort)
  453. {
  454.   int i,next;
  455.  
  456.   i=0;
  457.   checkhangup();
  458.   if (hangup)
  459.     *abort=1;
  460.   checka(abort,&next);
  461.   while ((s[i]) && (!(*abort))) {
  462.     outchr(s[i++]);
  463.     checka(abort,&next);
  464.   }
  465.   if (!(*abort))
  466.     nl();
  467. }
  468.  
  469.  
  470. char *ctim(double d)
  471. {
  472.   static char ch[10];
  473.   long h,m,s;
  474.  
  475.   h=(long) (d/3600.0);
  476.   d-=(double) (h*3600);
  477.   m=(long) (d/60.0);
  478.   d-=(double) (m*60);
  479.   s=(long) (d);
  480.   sprintf(ch,"%02.2ld:%02.2ld:%02.2ld",h,m,s);
  481.  
  482.   return(ch);
  483. }
  484.  
  485.  
  486. int sysop2()
  487. {
  488.   int ok;
  489.  
  490.   ok=sysop1();
  491.   if (restrict_chat & thisuser.restrict)
  492.     ok=0;
  493.   if (syscfg.sysoplowtime != syscfg.sysophightime) {
  494.     if (syscfg.sysophightime>syscfg.sysoplowtime) {
  495.       if ((timer()<=(syscfg.sysoplowtime*60.0)) || (timer()>=(syscfg.sysophightime*60.0)))
  496.         ok=0;
  497.     } else {
  498.       if ((timer()<=(syscfg.sysoplowtime*60.0)) && (timer()>=(syscfg.sysophightime*60.0)))
  499.         ok=0;
  500.     }
  501.   }
  502.   return(ok);
  503. }
  504.  
  505. void reqchat()
  506. {
  507.   int ok;
  508.   char s[81];
  509.  
  510.   nl();
  511.   nl();
  512.   ok=sysop2();
  513.   if (restrict_chat & thisuser.restrict)
  514.     ok=0;
  515.   if (ok) {
  516.     if (chatcall) {
  517.       chatcall=0;
  518.       pl("1Chat call turned off.");
  519.       topscreen();
  520.     } else {
  521.       prt(5,"What's the reason? ");
  522.       inputl(s,70);
  523.       if (s[0]) {
  524.         chatcall=1;
  525.         sprintf(chatreason,"Chat: %s",s);
  526.         nl();
  527.         sysoplog(chatreason);
  528.         for (ok=strlen(chatreason); ok<80; ok++)
  529.           chatreason[ok]=32;
  530.         chatreason[80]=0;
  531.         topscreen();
  532.     pl("6Chat call turned ON.");
  533.     nl();
  534.       }
  535.     }
  536.   } else {
  537.     pl("1Sysop ain't here.");
  538.     nl();
  539.     prt(1,"You wanna use feedback instead?");
  540.     if (yn())
  541.       feedback();
  542.   }
  543. }
  544.  
  545.  
  546. void yourinfo()
  547. {
  548.   outchr(12);
  549.   npr("1Your name     6 :7 %s\r\n",nam(&thisuser,usernum));
  550.   npr("1Phone number  6 :7 %s\r\n",thisuser.phone);
  551.   if (thisuser.waiting)
  552.     npr("1Mail waiting 6  :7 %d\r\n",thisuser.waiting);
  553.   if (actsl==thisuser.sl)
  554.     npr("1Sec Lev       6 :7 %d\r\n",thisuser.sl);
  555.   else
  556.     npr("1Sec Lev       6 :7 %d (temporarily %d)\r\n",thisuser.sl, actsl);
  557.   npr("1Transfer SecLev6:7 %d\r\n",thisuser.dsl);
  558.   npr("1Last on       6 :7 %s\r\n",thisuser.laston);
  559.   npr("1Times on      6 :7 %d\r\n",thisuser.logons);
  560.   npr("1On today      6 :7 %d\r\n",thisuser.ontoday);
  561.   npr("1Messages posted6:7 %d\r\n",thisuser.msgpost);
  562.   npr("1E-mail sent   6 :7 %d\r\n",
  563.     (thisuser.emailsent+thisuser.feedbacksent+thisuser.emailnet));
  564.   npr("1Time spent on  6:7 %ld Minutes\r\n", (long)
  565.     ((thisuser.timeon+timer()-timeon)/60.0));
  566.   npr("1Ass Points    6 :7 %d\r\n",thisuser.ass_pts);
  567.   nl();
  568. }
  569.  
  570.  
  571. void upload_post()
  572. {
  573.   char s[81],s1[81],ch;
  574.   int i,i1,maxli,f;
  575.   long l,l1;
  576.  
  577.   if (actsl<45)
  578.     maxli=30;
  579.   else
  580.     if (actsl<60)
  581.       maxli=50;
  582.     else
  583.       if (actsl<80)
  584.         maxli=60;
  585.       else
  586.         maxli=80;
  587.   sprintf(s,"%sINPUT.MSG",syscfg.tempdir);
  588.   l1=250*(long)maxli;
  589.  
  590.   nl();
  591.   npr("1You may now upload a message, max6 %ld1 bytes.\r\n",l1);
  592.   nl();
  593.   receive_file(s,&i1,&ch, "INPUT.MSG", -1);
  594.   f=open(s,O_RDWR | O_BINARY);
  595.   if (f>0) {
  596.     l=filelength(f);
  597.     if (l>l1) {
  598.       nl();
  599.       pl("7Sorry, your message is too long.6  Not saved.");
  600.       nl();
  601.       close(f);
  602.       unlink(s);
  603.     } else {
  604.       close(f);
  605.       use_workspace=1;
  606.       nl();
  607.       pl("1Message uploaded.  The next post or email will contain that text.");
  608.       nl();
  609.     }
  610.   } else {
  611.     nl();
  612.     pl("6Nothing saved.");
  613.     nl();
  614.   }
  615. }
  616.  
  617.  
  618. int checkcomp(char *s)
  619. {
  620.   if (strstr(ctypes[thisuser.comp_type],s))
  621.     return(1);
  622.   else
  623.     return(0);
  624. }
  625.  
  626. void game_ratio()
  627. {
  628. if ((syscfg.post_call_ratio>post_ratio())) {
  629. npr("1Your Post/Call Ratio is 6%-5.3f1 You Need6 %-5.3f1 To Play Games",post_ratio(),syscfg.post_call_ratio);
  630. }
  631. if ((syscfg.post_call_ratio<=post_ratio())) {
  632. do_chains();
  633. }
  634. }
  635.  
  636.