home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / W / DEVBBS.ZIP / BBSUTL.C < prev    next >
Text File  |  1992-08-25  |  13KB  |  617 lines

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