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

  1. #include "vars.h"
  2.  
  3. #pragma hdrstop
  4.  
  5.  
  6. void far *malloca(unsigned long nbytes)
  7. {
  8.   void *buf;
  9.   char s[160];
  10.  
  11.   buf=farmalloc(nbytes+1);
  12.   if (buf==NULL) {
  13.     nl();
  14.     npr(get_stringx(1,31),nbytes);
  15.     nl();
  16.     sprintf(s,get_stringx(1,32),nbytes);
  17.     sysoplog(s);
  18.   }
  19.   return(buf);
  20. }
  21.  
  22.  
  23.  
  24. void stuff_in(char *s, char *s1, char *f1, char *f2, char *f3, char *f4, char *f5)
  25. {
  26.   int r=0,w=0;
  27.  
  28.   while (s1[r]!=0) {
  29.     if (s1[r]=='%') {
  30.       ++r;
  31.       s[w]=0;
  32.       switch(s1[r]) {
  33.         case '1': strcat(s,f1); break;
  34.         case '2': strcat(s,f2); break;
  35.         case '3': strcat(s,f3); break;
  36.         case '4': strcat(s,f4); break;
  37.         case '5': strcat(s,f5); break;
  38.       }
  39.       w=strlen(s);
  40.       r++;
  41.     } else
  42.       s[w++]=s1[r++];
  43.   }
  44.   s[w]=0;
  45. }
  46.  
  47. void copy_line(char *s, char *b, long *ptr, long len)
  48. {
  49.   int i;
  50.   long l;
  51.  
  52.   if (*ptr>=len) {
  53.     s[0]=0;
  54.     return;
  55.   }
  56.   l=*ptr;
  57.   i=0;
  58.   while ((b[l]!='\r') && (b[l]!='\n') && (l<len)) {
  59.     s[i++]=b[l++];
  60.   }
  61.   s[i]=0;
  62.   if ((b[l]=='\r') && (l<len))
  63.     ++l;
  64.   if ((b[l]=='\n') && (l<len))
  65.     ++l;
  66.   *ptr=l;
  67. }
  68.  
  69. char *mmkey(int dl)
  70. {
  71.   static unsigned char cmd1[10],cmd2[81],ch;
  72.   int i,i1,i2,p,cp;
  73.  
  74.   do {
  75.     do {
  76.       ch=getkey();
  77.     } while ((((ch<' ') && (ch!=13)) || (ch>126)) && (hangup==0));
  78.     ch=upcase(ch);
  79.     outchr(ch);
  80.     if (ch==13)
  81.       cmd1[0]=0;
  82.     else
  83.       cmd1[0]=ch;
  84.     cmd1[1]=0;
  85.     p=0;
  86.     switch(dl) {
  87.  
  88.     case 1:
  89.       if (strchr(dtc,ch)!=NULL)
  90.         p=2;
  91.       else if (strchr(dcd,ch)!=NULL)
  92.         p=1;
  93.       break;
  94.     case 2:
  95.       if (strchr(odc,ch)!=NULL)
  96.         p=1;
  97.       break;
  98.     case 0:
  99.       if (strchr(tc,ch)!=NULL)
  100.         p=2;
  101.       else if (strchr(dc,ch)!=NULL)
  102.         p=1;
  103.       break;
  104.     }
  105.     if (p) {
  106.       cp=1;
  107.       do {
  108.         do {
  109.           ch=getkey();
  110.         } while ((((ch<' ') && (ch!=13) && (ch!=8)) || (ch>126)) && (hangup==0));
  111.         ch=upcase(ch);
  112.         if (ch==13) {
  113.           nl();
  114.           return(cmd1);
  115.         } else {
  116.           if (ch==8) {
  117.             backspace();
  118.             cmd1[--cp]=0;
  119.           } else {
  120.             cmd1[cp++]=ch;
  121.             cmd1[cp]=0;
  122.             outchr(ch);
  123.             if ((ch=='/') && (cmd1[0]=='/')) {
  124.               input(cmd2,50);
  125.               return(cmd2);
  126.             } else if (cp==p+1) {
  127.               nl();
  128.               return(cmd1);
  129.             }
  130.           }
  131.         }
  132.       } while (cp);
  133.     } else {
  134.       nl();
  135.       return(cmd1);
  136.     }
  137.   } while (hangup==0);
  138.   cmd1[0]=0;
  139.   return(cmd1);
  140. }
  141.  
  142.  
  143. void inli(char *s, char *rollover, int maxlen, int crend)
  144. {
  145.   int cp,i,i1,done,cm,begx;
  146.   char s1[255],s2[255],*ss;
  147.   unsigned char ch;
  148.  
  149.   cm=chatting;
  150.  
  151.   begx=wherex();
  152.   if (rollover[0]!=0) {
  153.     ss=s2;
  154.     for (i=0; rollover[i]; i++) {
  155.       if (rollover[i]==3)
  156.         *ss++='P'-'@';
  157.       else
  158.         *ss++=rollover[i];
  159.     }
  160.     *ss=0;
  161.     if (charbufferpointer) {
  162.       strcpy(s1,s2);
  163.       strcat(s1,&charbuffer[charbufferpointer]);
  164.       strcpy(&charbuffer[1],s1);
  165.       charbufferpointer=1;
  166.     } else {
  167.       strcpy(&charbuffer[1],s2);
  168.       charbufferpointer=1;
  169.     }
  170.     rollover[0]=0;
  171.   }
  172.   cp=0;
  173.   done=0;
  174.   do {
  175.     ch=getkey();
  176.     if (two_color)
  177.       if (lastcon)
  178.     ansic(1);
  179.       else
  180.     ansic(0);
  181.     if (cm)
  182.       if (chatting==0)
  183.         ch=13;
  184.     if ((ch>=32)) {
  185.       if ((wherex()<(thisuser.screenchars-1)) && (cp<maxlen)) {
  186.         s[cp++]=ch;
  187.         outchr(ch);
  188.         if (wherex()==(thisuser.screenchars-1))
  189.           done=1;
  190.       } else {
  191.         if (wherex()>=(thisuser.screenchars-1))
  192.           done=1;
  193.       }
  194.     } else
  195.         switch(ch) {
  196.       case 7:
  197.         if ((chatting) && (outcom))
  198.           outcomch(7);
  199.         break;
  200.           case 13: /* C/R */
  201.             s[cp]=0;
  202.             done=1;
  203.             break;
  204.           case 8:  /* Backspace */
  205.             if (cp) {
  206.               if (s[cp-2]==3) {
  207.                 cp-=2;
  208.                 ansic(0);
  209.               } else
  210.                 if (s[cp-1]==8) {
  211.                   cp--;
  212.                   outchr(32);
  213.                 } else {
  214.                   cp--;
  215.                   backspace();
  216.                 }
  217.             }
  218.             break;
  219.           case 24: /* Ctrl-X */
  220.             while (wherex()>begx) {
  221.               backspace();
  222.               cp=0;
  223.             }
  224.             ansic(0);
  225.             break;
  226.           case 23: /* Ctrl-W */
  227.             if (cp) {
  228.               do {
  229.                 if (s[cp-2]==3) {
  230.                   cp-=2;
  231.                   ansic(0);
  232.                 } else
  233.                   if (s[cp-1]==8) {
  234.                     cp--;
  235.                     outchr(32);
  236.                   } else {
  237.                     cp--;
  238.                     backspace();
  239.                   }
  240.               } while ((cp) && (s[cp-1]!=32) && (s[cp-1]!=8));
  241.             }
  242.             break;
  243.           case 14: /* Ctrl-N */
  244.             if ((wherex()) && (cp<maxlen)) {
  245.               outchr(8);
  246.               s[cp++]=8;
  247.             }
  248.             break;
  249.           case 16: /* Ctrl-P */
  250.             if (cp<maxlen-1) {
  251.               ch=getkey();
  252.               if ((ch>='0') && (ch<='7')) {
  253.                 s[cp++]=3;
  254.                 s[cp++]=ch;
  255.                 ansic(ch-'0');
  256.               }
  257.             }
  258.             break;
  259.           case 9:  /* Tab */
  260.             i=5-(cp % 5);
  261.             if (((cp+i)<maxlen) && ((wherex()+i)<thisuser.screenchars)) {
  262.           i=5-((wherex()+1) % 5);
  263.               for (i1=0; i1<i; i1++) {
  264.                 s[cp++]=32;
  265.                 outchr(32);
  266.               }
  267.             }
  268.             break;
  269.         }
  270.   } while ((done==0) && (hangup==0));
  271.   if (ch!=13) {
  272.     i=cp-1;
  273.     while ((i>0) && (s[i]!=32) && (s[i]!=8))
  274.       i--;
  275.     if ((i>(wherex()/2)) && (i!=(cp-1))) {
  276.       i1=cp-i-1;
  277.       for (i=0; i<i1; i++)
  278.         outchr(8);
  279.       for (i=0; i<i1; i++)
  280.         outchr(32);
  281.       for (i=0; i<i1; i++)
  282.         rollover[i]=s[cp-i1+i];
  283.       rollover[i1]=0;
  284.       cp -= i1;
  285.     }
  286.     s[cp++]=1;
  287.     s[cp]=0;
  288.   }
  289.   if (crend)
  290.     nl();
  291.  
  292. }
  293.  
  294.  
  295. int so(void)
  296. {
  297.   if (actsl==255)
  298.     return(1);
  299.   else
  300.     return(0);
  301. }
  302.  
  303.  
  304.  
  305. int cs(void)
  306. {
  307.   slrec ss;
  308.  
  309.   ss=syscfg.sl[actsl];
  310.   if (so())
  311.     return(1);
  312.   if (ss.ability & ability_cosysop)
  313.     return(1);
  314.   else
  315.     return(0);
  316. }
  317.  
  318.  
  319. int lcs(void)
  320. {
  321.   slrec ss;
  322.  
  323.   ss=syscfg.sl[actsl];
  324.   if (cs())
  325.     return(1);
  326.   if (ss.ability & ability_limited_cosysop) {
  327.     if (*qsc==999)
  328.       return(1);
  329.     if (*qsc==usub[cursub].subnum)
  330.       return(1);
  331.     else
  332.       return(0);
  333.   } else
  334.     return(0);
  335. }
  336.  
  337.  
  338. void checka(int *abort, int *next)
  339. {
  340.   char ch;
  341.  
  342.   while ((!empty()) && (!(*abort)) && (!hangup)) {
  343.     checkhangup();
  344.     ch=inkey();
  345.     lines_listed=0;
  346.     switch(ch) {
  347.       case 14:
  348.         *next=1;
  349.       case 3:
  350.       case 32:
  351.       case 24:
  352.         *abort=1;
  353.         break;
  354.       case 'P':
  355.       case 'p':
  356.       case 19:
  357.         ch=getkey();
  358.         break;
  359.     }
  360.   }
  361. }
  362.  
  363.  
  364. void pla(char *s, int *abort)
  365. {
  366.   int i,next;
  367.  
  368.   i=0;
  369.   checkhangup();
  370.   if (hangup)
  371.     *abort=1;
  372.   checka(abort,&next);
  373.   while ((s[i]) && (!(*abort))) {
  374.     outchr(s[i++]);
  375.     checka(abort,&next);
  376.   }
  377.   if (!(*abort))
  378.     nl();
  379. }
  380.  
  381.  
  382. char *ctim(double d)
  383. {
  384.   static char ch[10];
  385.   long h,m,s;
  386.  
  387.   if (d<0)
  388.     d += 24.0*3600.0;
  389.   h=(long) (d/3600.0);
  390.   d-=(double) (h*3600);
  391.   m=(long) (d/60.0);
  392.   d-=(double) (m*60);
  393.   s=(long) (d);
  394.   sprintf(ch,"%02.2ld:%02.2ld:%02.2ld",h,m,s);
  395.  
  396.   return(ch);
  397. }
  398.  
  399.  
  400. int sysop2(void)
  401. {
  402.   int ok;
  403.  
  404.   ok=sysop1();
  405.   if (restrict_chat & thisuser.restrict)
  406.     ok=0;
  407.   if (syscfg.sysoplowtime != syscfg.sysophightime) {
  408.     if (syscfg.sysophightime>syscfg.sysoplowtime) {
  409.       if ((timer()<=(syscfg.sysoplowtime*60.0)) || (timer()>=(syscfg.sysophightime*60.0)))
  410.         ok=0;
  411.     } else {
  412.       if ((timer()<=(syscfg.sysoplowtime*60.0)) && (timer()>=(syscfg.sysophightime*60.0)))
  413.         ok=0;
  414.     }
  415.   }
  416.   return(ok);
  417. }
  418.  
  419. void reqchat(void)
  420. {
  421.   int ok;
  422.   char s[81];
  423.  
  424.   nl();
  425.   nl();
  426.   ok=sysop2();
  427.   if (restrict_chat & thisuser.restrict)
  428.     ok=0;
  429.   if (ok) {
  430.     if (chatcall) {
  431.       chatcall=0;
  432.       pl("1Chat call turned off7.");
  433.       topscreen();
  434.     } else {
  435.       prt(2,"1Reason 7: ");
  436.       inputl(s,70);
  437.       if (s[0]) {
  438.         chatcall=1;
  439.         sprintf(chatreason,"%s: %s",get_stringx(1,33), s);
  440.         nl();
  441.         sysoplog(chatreason);
  442.         for (ok=strlen(chatreason); ok<80; ok++)
  443.           chatreason[ok]=32;
  444.         chatreason[80]=0;
  445.         topscreen();
  446.     pl("1Chat call turned on7.");
  447.     nl();
  448.       }
  449.     }
  450.   } else {
  451.     pl("1Sysop is out Llama tipping3.");
  452.     nl();
  453.     pl("1Use feedback instead3.");
  454.     strcpy(irt,get_stringx(1,34));
  455.     irt_name[0]=0;
  456.     imail(1,0);
  457.   }
  458. }
  459.  
  460.  
  461. void yourinfo(void)
  462. {
  463.   outchr(12);
  464.   pl("3┌────────────────────────────────────────────────┐");
  465.   pl("3│ 5               Your Information                3│");
  466.   pl("3│                                                │");
  467.  npr("3│ 5Your name    2: 5%-32s3│\r\n",nam(&thisuser,usernum));
  468.  npr("3│ 5Phone number 2: 5%-32s3│\r\n",thisuser.phone);
  469.  npr("3│ 5Mail waiting 2: 5%-32d3│\r\n",thisuser.waiting);
  470.  npr("3│ 5Ass points   2: 5%-32d3│\r\n",thisuser.ass_pts);
  471.  if (actsl!=thisuser.sl) {
  472.  npr("3│ 5SL           2: 5%-3d 2(5Temp 2: %-3d 5)               3│\r\n",thisuser.sl,actsl);
  473.  npr("3│ 5DSL          2: 5%-32d3│\r\n",thisuser.dsl); }
  474.  else
  475.  npr("3│ 5SL           2: 5%-32d3│\r\n",thisuser.sl);
  476.  npr("3│ 5DSL          2: 5%-32d3│\r\n",thisuser.dsl);
  477.  npr("3│ 5Laston       2: 5%-32s3│\r\n",thisuser.laston);
  478.  npr("3│ 5Logons       2: 5%-32d3│\r\n",thisuser.logons);
  479.  npr("3│ 5On Today     2: 5%-32d3│\r\n",thisuser.ontoday);
  480.  npr("3│ 5Msgs Posted  2: 5%-32d3│\r\n",thisuser.msgpost);
  481.  npr("3│ 5E-mail sent  2: 5%-32d3│\r\n",(thisuser.emailsent+thisuser.feedbacksent+thisuser.emailnet));
  482.  npr("3│ 5Time spent on2: 5%-7ld Minutes                 3│\r\n",(long)((thisuser.timeon+timer()-timeon)/60.0));
  483.   pl("3└────────────────────────────────────────────────┘");
  484.   nl();
  485. }
  486.  
  487.  
  488. void upload_post(void)
  489. {
  490.   char s[81],s1[81],ch;
  491.   int i,i1,maxli,f;
  492.   long l,l1;
  493.  
  494.   if (actsl<45)
  495.     maxli=30;
  496.   else
  497.     if (actsl<60)
  498.       maxli=50;
  499.     else
  500.       if (actsl<80)
  501.         maxli=60;
  502.       else
  503.         maxli=80;
  504.   sprintf(s,"%sINPUT.MSG",syscfg.tempdir);
  505.   l1=250*(long)maxli;
  506.  
  507.   nl();
  508.   npr("1You may now upload a message7, 1max bytes 7: 1%ld\r\n",l1);
  509.   nl();
  510.   receive_file(s,&i1,&ch, "INPUT.MSG", -1);
  511.   f=open(s,O_RDWR | O_BINARY);
  512.   if (f>0) {
  513.     l=filelength(f);
  514.     if (l>l1) {
  515.       nl();
  516.       pl("1Sorry7, 1your message was too long7. 1Not saved7.");
  517.       nl();
  518.       close(f);
  519.       unlink(s);
  520.     } else {
  521.       close(f);
  522.       use_workspace=1;
  523.       nl();
  524.       pl("1Message uploaded7. 1The next post or e-mail will contain that text7.");
  525.       nl();
  526.     }
  527.   } else {
  528.     nl();
  529.     pl("1Nothing saved7.");
  530.     nl();
  531.   }
  532. }
  533.  
  534.  
  535. int checkcomp(char *s)
  536. {
  537.   if (strstr(ctypes[thisuser.comp_type],s))
  538.     return(1);
  539.   else
  540.     return(0);
  541. }
  542.  
  543.  
  544. int check_ansi(void)
  545. {
  546.   long l;
  547.   char ch;
  548.  
  549.   if (!incom)
  550.     return(1);
  551.  
  552.   while (comhit())
  553.     get1c();
  554.  
  555.   pr1("\x1b[6n");
  556.  
  557.   l=timer1()+36;
  558.   if (modem_flag & flag_ec)
  559.     l += 18;
  560.  
  561.   while ((timer1()<l) && (!hangup)) {
  562.     checkhangup();
  563.     ch=get1c();
  564.     if (ch=='\x1b') {
  565.       l=timer1()+18;
  566.       while ((timer1()<l) && (!hangup)) {
  567.         if ((timer1()+1820)<l)
  568.           l=timer1()+18;
  569.         checkhangup();
  570.         ch=get1c();
  571.         if (ch) {
  572.           if (((ch<'0') || (ch>'9')) && (ch!=';') && (ch!='['))
  573.             return(1);
  574.         }
  575.       }
  576.       return(1);
  577.     } else if (ch=='N')
  578.       return(-1);
  579.     if ((timer1()+1820)<l)
  580.       l=timer1()+36;
  581.   }
  582.   return(0);
  583. }
  584.  
  585. /****************************************************************************/
  586.  
  587. int read_in_file(char *fn, messagerec *m, int maxary)
  588. {
  589.   int i,i1,i2;
  590.   char *buf,s[81];
  591.   long l,l1;
  592.  
  593.   for (i=0; i<maxary; i++) {
  594.     m[i].stored_as=0L;
  595.     m[i].storage_type=255;
  596.   }
  597.   sprintf(s,"%s%s",languagedir,fn);
  598.   i=open(s,O_RDWR | O_BINARY);
  599.   if (i<0) {
  600.     return(1);
  601.   }
  602.   l=filelength(i);
  603.   buf=(char *) farmalloc(l);
  604.   lseek(i,0L,SEEK_SET);
  605.   if (buf==NULL) {
  606.     printf("NOT ENOUGH MEMORY.\n");
  607.     end_bbs(noklevel);
  608.   }
  609.   read(i,(void *) buf,l);
  610.   close(i);
  611.   i1=0;
  612.   for (l1=0; l1<l; l1++) {
  613.     if (buf[l1]=='`') {
  614.       i1=1;
  615.       i2=0;
  616.     } else
  617.       if (i1) {
  618.         if ((buf[l1]>='0') && (buf[l1]<='9')) {
  619.           i2*=10;
  620.           i2+=(buf[l1])-'0';
  621.         } else {
  622.           while ((l1<l) && (buf[l1]!=10))
  623.             ++l1;
  624.           ++l1;
  625.           if ((i2>=0) && (i2<maxary))
  626.             m[i2].stored_as=l1;
  627.           i1=0;
  628.         }
  629.       }
  630.   }
  631.   farfree((void *) buf);
  632.  
  633.   return(0);
  634. }
  635.  
  636.  
  637.  
  638. /****************************************************************************/
  639.  
  640.  
  641. int set_language_1(int n)
  642. {
  643.   int i, fail=0;
  644.   char s[81];
  645.  
  646.   cur_lang=n;
  647.  
  648.   languagedir=syscfg.gfilesdir;
  649.  
  650.   if (set_strings_fn(0, languagedir, "BBS.STR", 0)) {
  651.     printf("Couldn't open %sBBS.STR for language #%d\n",
  652.             languagedir, n);
  653.     if (n==0) {
  654.       printf("Copy ENGLISH.STR from the distribution archive to %sBBS.STR\n",
  655.              languagedir);
  656.     }
  657.     fail=1;
  658.   }
  659.  
  660.   if (n==0) {
  661.     if (set_strings_fn(1, languagedir, "SYSOPLOG.STR", 0)) {
  662.       printf("Couldn't open %sSYSOPLOG.STR for language #%d\n",
  663.              languagedir, n);
  664.       printf("Copy SYSOPLOG.STR from the distribution archive to %sSYSOPLOG.STR\n",
  665.               languagedir);
  666.       fail=1;
  667.     }
  668.   }
  669.  
  670.   if (fail)
  671.     return(fail);
  672.  
  673.   set_strings_fn(2, languagedir, "YES.STR", 0);
  674.   set_strings_fn(3, languagedir, "NO.STR", 0);
  675.  
  676.   strncpy(str_yes,get_string(1), sizeof(str_yes)-1);
  677.   strncpy(str_no,get_string(2), sizeof(str_no)-1);
  678.   strncpy(str_quit,get_string(929), sizeof(str_quit)-1);
  679.   strncpy(str_pause,get_string(923), sizeof(str_pause)-1);
  680.   str_yes[0]=upcase(str_yes[0]);
  681.   str_no[0]=upcase(str_no[0]);
  682.   str_quit[0]=upcase(str_quit[0]);
  683.  
  684.   if (read_in_file("MENUS.MSG",menus,sizeof(menus)/sizeof(menus[0]))) {
  685.     printf("Couldn't open %sMENUS.MSG for language #%d\n",languagedir,n);
  686.     return(1);
  687.   }
  688.   if (read_in_file("HELP.MSG",helps,sizeof(helps)/sizeof(helps[0]))) {
  689.     printf("Couldn't open %sHELP.MSG for language #%d\n",languagedir,n);
  690.     return(1);
  691.   }
  692.   read_in_file("MENUSANS.MSG",menus1,sizeof(menus1)/sizeof(menus1[0]));
  693.   read_in_file("MENUS40.MSG",menus2,sizeof(menus2)/sizeof(menus2[0]));
  694.  
  695.   return(0);
  696. }
  697.  
  698. /****************************************************************************/
  699.  
  700. int set_language(int n)
  701. {
  702.   int pl;
  703.  
  704.   if (cur_lang==n)
  705.     return(0);
  706.  
  707.   pl=cur_lang;
  708.  
  709.   if (set_language_1(n)) {
  710.     if (pl>=0) {
  711.       if (set_language_1(pl))
  712.         set_language_1(0);
  713.     }
  714.     return(1);
  715.   }
  716.  
  717.   return(0);
  718. }
  719.