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

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