home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / UTIL / WWIVE / UTILITY.C < prev    next >
C/C++ Source or Header  |  1991-12-24  |  21KB  |  1,002 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.  
  19. #pragma hdrstop
  20.  
  21. #include <dir.h>
  22. #include <math.h>
  23.  
  24.  
  25.  
  26. /* functions for external programs to call */
  27.  
  28. #pragma warn -par
  29.  
  30. void far interrupt inlii(unsigned bp, unsigned di, unsigned si,
  31.                            unsigned ds, unsigned es, unsigned dx,
  32.                            unsigned cx, unsigned bx, unsigned ax,
  33.                            unsigned ip, unsigned cs, unsigned flags,
  34.                            char *s1, char *s2, int i1, int i2)
  35. {
  36.   inli(s1,s2,i1,i2);
  37. }
  38.  
  39. void far interrupt checkai(unsigned bp, unsigned di, unsigned si,
  40.                            unsigned ds, unsigned es, unsigned dx,
  41.                            unsigned cx, unsigned bx, unsigned ax,
  42.                            unsigned ip, unsigned cs, unsigned flags,
  43.                            int *i1, int *i2)
  44. {
  45.   checka(i1,i2);
  46. }
  47.  
  48.  
  49. void far interrupt plai(unsigned bp, unsigned di, unsigned si,
  50.                            unsigned ds, unsigned es, unsigned dx,
  51.                            unsigned cx, unsigned bx, unsigned ax,
  52.                            unsigned ip, unsigned cs, unsigned flags,
  53.                            char *s1, int *i1)
  54. {
  55.   pla(s1,i1);
  56. }
  57.  
  58.  
  59. void far interrupt outchri(unsigned bp, unsigned di, unsigned si,
  60.                            unsigned ds, unsigned es, unsigned dx,
  61.                            unsigned cx, unsigned bx, unsigned ax,
  62.                            unsigned ip, unsigned cs, unsigned flags,
  63.                            char ch)
  64. {
  65.   outchr(ch);
  66. }
  67.  
  68.  
  69. void far interrupt outstri(unsigned bp, unsigned di, unsigned si,
  70.                            unsigned ds, unsigned es, unsigned dx,
  71.                            unsigned cx, unsigned bx, unsigned ax,
  72.                            unsigned ip, unsigned cs, unsigned flags,
  73.                            char *s1)
  74. {
  75.   outstr(s1);
  76. }
  77.  
  78.  
  79. void far interrupt nli(unsigned bp, unsigned di, unsigned si,
  80.                            unsigned ds, unsigned es, unsigned dx,
  81.                            unsigned cx, unsigned bx, unsigned ax,
  82.                            unsigned ip, unsigned cs, unsigned flags)
  83. {
  84.   nl();
  85. }
  86.  
  87.  
  88. void far interrupt pli(unsigned bp, unsigned di, unsigned si,
  89.                            unsigned ds, unsigned es, unsigned dx,
  90.                            unsigned cx, unsigned bx, unsigned ax,
  91.                            unsigned ip, unsigned cs, unsigned flags,
  92.                            char *s1)
  93. {
  94.   pl(s1);
  95. }
  96.  
  97.  
  98. void far interrupt emptyi(unsigned bp, unsigned di, unsigned si,
  99.                            unsigned ds, unsigned es, unsigned dx,
  100.                            unsigned cx, unsigned bx, unsigned ax,
  101.                            unsigned ip, unsigned cs, unsigned flags)
  102. {
  103.   ax=empty();
  104. }
  105.  
  106.  
  107. void far interrupt inkeyi(unsigned bp, unsigned di, unsigned si,
  108.                            unsigned ds, unsigned es, unsigned dx,
  109.                            unsigned cx, unsigned bx, unsigned ax,
  110.                            unsigned ip, unsigned cs, unsigned flags)
  111. {
  112.   ax=(unsigned) empty();
  113. }
  114.  
  115.  
  116. void far interrupt getkeyi(unsigned bp, unsigned di, unsigned si,
  117.                            unsigned ds, unsigned es, unsigned dx,
  118.                            unsigned cx, unsigned bx, unsigned ax,
  119.                            unsigned ip, unsigned cs, unsigned flags)
  120. {
  121.   ax=(unsigned) getkey();
  122. }
  123.  
  124.  
  125. void far interrupt inputi(unsigned bp, unsigned di, unsigned si,
  126.                            unsigned ds, unsigned es, unsigned dx,
  127.                            unsigned cx, unsigned bx, unsigned ax,
  128.                            unsigned ip, unsigned cs, unsigned flags,
  129.                            char *s1, int i)
  130. {
  131.   input(s1,i);
  132. }
  133.  
  134.  
  135. void far interrupt inputli(unsigned bp, unsigned di, unsigned si,
  136.                            unsigned ds, unsigned es, unsigned dx,
  137.                            unsigned cx, unsigned bx, unsigned ax,
  138.                            unsigned ip, unsigned cs, unsigned flags,
  139.                            char *s1, int i)
  140. {
  141.   inputl(s1,i);
  142. }
  143.  
  144.  
  145. void far interrupt yni(unsigned bp, unsigned di, unsigned si,
  146.                            unsigned ds, unsigned es, unsigned dx,
  147.                            unsigned cx, unsigned bx, unsigned ax,
  148.                            unsigned ip, unsigned cs, unsigned flags)
  149. {
  150.   ax=yn();
  151. }
  152.  
  153.  
  154.  
  155. void far interrupt nyi(unsigned bp, unsigned di, unsigned si,
  156.                            unsigned ds, unsigned es, unsigned dx,
  157.                            unsigned cx, unsigned bx, unsigned ax,
  158.                            unsigned ip, unsigned cs, unsigned flags)
  159. {
  160.   ax=ny();
  161. }
  162.  
  163.  
  164. void far interrupt ansici(unsigned bp, unsigned di, unsigned si,
  165.                            unsigned ds, unsigned es, unsigned dx,
  166.                            unsigned cx, unsigned bx, unsigned ax,
  167.                            unsigned ip, unsigned cs, unsigned flags,
  168.                            int i1)
  169. {
  170.   ansic(i1);
  171. }
  172.  
  173.  
  174. void far interrupt oneki(unsigned bp, unsigned di, unsigned si,
  175.                            unsigned ds, unsigned es, unsigned dx,
  176.                            unsigned cx, unsigned bx, unsigned ax,
  177.                            unsigned ip, unsigned cs, unsigned flags,
  178.                            char *s1)
  179. {
  180.   ax=(unsigned) onek(s1);
  181. }
  182.  
  183.  
  184. void far interrupt prti(unsigned bp, unsigned di, unsigned si,
  185.                            unsigned ds, unsigned es, unsigned dx,
  186.                            unsigned cx, unsigned bx, unsigned ax,
  187.                            unsigned ip, unsigned cs, unsigned flags,
  188.                            int i1, char *s1)
  189. {
  190.   prt(i1,s1);
  191. }
  192.  
  193.  
  194.  
  195. void far interrupt mpli(unsigned bp, unsigned di, unsigned si,
  196.                            unsigned ds, unsigned es, unsigned dx,
  197.                            unsigned cx, unsigned bx, unsigned ax,
  198.                            unsigned ip, unsigned cs, unsigned flags,
  199.                            int i1)
  200. {
  201.   mpl(i1);
  202. }
  203.  
  204.  
  205. #pragma warn +par
  206.  
  207. /* end of functions for external programs to call */
  208.  
  209.  
  210. void reset_act_sl()
  211. {
  212.   actsl = thisuser.sl;
  213. }
  214.  
  215.  
  216. void remove_from_temp(char *fn, char *dir, int po)
  217. {
  218.   int i,i1,f1,ok;
  219.   char s[81],s1[81];
  220.   struct ffblk ff;
  221.   uploadsrec u;
  222.  
  223.   sprintf(s1,"%s%s",dir,stripfn(fn));
  224.   f1=findfirst(s1,&ff,0);
  225.   ok=1;
  226.   nl();
  227.   while ((f1==0) && (ok)) {
  228.     sprintf(s,"%s%s",dir,ff.ff_name);
  229.     if (po)
  230.       npr("Deleting %s\r\n",ff.ff_name);
  231.     _chmod(s,1,0);
  232.     unlink(s);
  233.     f1=findnext(&ff);
  234.   }
  235. }
  236.  
  237. void check_event()
  238. {
  239.   double tl;
  240.  
  241.   if (syscfg.executetime) {
  242.     tl=time_event-timer();
  243.     if (tl<0.0)
  244.       tl += 24.0*3600.0;
  245.     if ((tl-last_time)>2.0)
  246.       do_event=1;
  247.     last_time=tl;
  248.   }
  249. }
  250.  
  251.  
  252. void run_event()
  253. {
  254.   if ((do_event) && (syscfg.executetime)) {
  255.     do_event=0;
  256.     nl();
  257.     pl("Now running external event.");
  258.     nl();
  259.     if (syscfg.executestr[0]) {
  260.       holdphone(1);
  261.       shrink_out(syscfg.executestr,0,0,0,1);
  262.       /* run_external(syscfg.executestr); */
  263.       holdphone(0);
  264.     } else
  265.       end_bbs(oklevel);
  266.   }
  267.   clrscrb();
  268. }
  269.  
  270.  
  271. double freek(int dr)
  272. {
  273.   float d;
  274.   struct dfree df;
  275.  
  276.   getdfree(dr,&df);
  277.   d=(float) df.df_avail;
  278.   d*=((float) df.df_bsec);
  279.   d*=((float) df.df_sclus);
  280.   d/=1024.0;
  281.   if (df.df_sclus<0)
  282.   d=-1.0;
  283.   return(d);
  284. }
  285.  
  286.  
  287. unsigned char years_old(unsigned char m, unsigned char d, unsigned char y)
  288. {
  289.   struct date today;
  290.   int a;
  291.  
  292.   getdate(&today);
  293.   a=(int) (today.da_year-1900-y);
  294.   if (today.da_mon<m)
  295.     --a;
  296.   else
  297.     if ((today.da_mon==m) && (today.da_day<d))
  298.       --a;
  299.   return((unsigned char)a);
  300. }
  301.  
  302.  
  303.  
  304. void itimer()
  305. /* This function initializes the high-resolution timer */
  306. {
  307.   outportb(0x43,0x34);
  308.   outportb(0x40,0x00);
  309.   outportb(0x40,0x00);
  310.  
  311. }
  312.  
  313. double timer()
  314. /* This function returns the time, in seconds since midnight. */
  315. {
  316.   double cputim;
  317.   unsigned short int h,m,l1,l2;
  318.  
  319.   disable();
  320.   outportb(0x43,0x00);
  321.   m=peek(0x0040,0x006c);
  322.   h=peek(0x0040,0x006e);
  323.   l1=inportb(0x40);
  324.   l2=inportb(0x40);
  325.   enable();
  326.   l1=((l2*256)+l1) ^ 65535;
  327.   cputim=((h*65536. + m)*65536. + l1)*8.380955e-7;
  328.   return (cputim);
  329. }
  330.  
  331.  
  332. long timer1()
  333. /* This function returns the time, in ticks since midnight. */
  334. {
  335.   unsigned short h,m;
  336.   long l;
  337.  
  338.   m=peek(0x0040,0x006c);
  339.   h=peek(0x0040,0x006e);
  340.   l=((long)h)*65536 + ((long)m);
  341.   return(l);
  342. }
  343.  
  344.  
  345. int sysop1()
  346. /* This function returns the status of scoll lock.  If scroll lock is active
  347.  * (ie, the user has hit scroll lock + the light is lit if there is a
  348.  * scoll lock LED), the sysop is assumed to be available.
  349.  */
  350. {
  351.   if ((peekb(0,1047) & 0x10)==0)
  352.     return(0);
  353.   else
  354.     return(1);
  355. }
  356.  
  357.  
  358.  
  359. int okansi()
  360. /* This function checks the status of the current user's record to see if
  361.  * the user has specified that he wants ANSI graphics displayed.
  362.  */
  363. {
  364.   if (thisuser.sysstatus & sysstatus_ansi)
  365.     return(1);
  366.   else
  367.     return(0);
  368. }
  369.  
  370.  
  371. void frequent_init()
  372. /* This should be called after a user is logged off, and will initialize
  373.  * screen-access variables.
  374.  */
  375. {
  376.   curlsub=-1;
  377.   ansiptr=0;
  378.   curatr=0x07;
  379.   outcom=0;
  380.   incom=0;
  381.   charbufferpointer=0;
  382.   andwith=0xff;
  383.   checkit=0;
  384.   topline=0;
  385.   screenlinest=defscreenbottom+1;
  386.   if (!restoring_shrink)
  387.     clrscrb();
  388.   endofline[0]=0;
  389.   hangup=0;
  390.   hungup=0;
  391.   chatcall=0;
  392.   chatreason[0]=0;
  393.   useron=0;
  394.   change_color=0;
  395.   chatting=0;
  396.   echo=1;
  397.   irt[0]=0;
  398.   irt_name[0]=0;
  399.   okskey=0;
  400.   lines_listed=0;
  401.   read_user(1,&thisuser);
  402.   if (thisuser.inact & inact_deleted)
  403.     fwaiting=0;
  404.   else
  405.     fwaiting=thisuser.waiting;
  406.   okmacro=1;
  407.   okskey=1;
  408.   helpl=0;
  409.   ihelp=0;
  410.   mailcheck=0;
  411.   smwcheck=0;
  412.   in_extern=0;
  413.   gatfn[0]=0;
  414.   use_workspace=0;
  415.   extratimecall=0.0;
  416.   two_color=0;
  417.   using_modem=0;
  418.   set_global_handle(0);
  419.   live_user=1;
  420.   _chmod(dszlog,1,0);
  421.   unlink(dszlog);
  422. }
  423.  
  424.  
  425. void read_in_file(char *fn, messagerec *m, int maxary)
  426. {
  427.   int i,i1,i2;
  428.   char *buf,s[81];
  429.   long l,l1;
  430.  
  431.   for (i=0; i<maxary; i++) {
  432.     m[i].stored_as=0L;
  433.     m[i].storage_type=255;
  434.   }
  435.   sprintf(s,"%s%s",syscfg.gfilesdir,fn);
  436.   i=open(s,O_RDWR | O_BINARY);
  437.   if (i<0) {
  438.     printf("%s NOT FOUND.\n",s);
  439.     end_bbs(noklevel);
  440.   }
  441.   l=filelength(i);
  442.   buf=(char *) farmalloc(l);
  443.   lseek(i,0L,SEEK_SET);
  444.   if (buf==NULL) {
  445.     printf("NOT ENOUGH MEMORY.\n");
  446.     end_bbs(noklevel);
  447.   }
  448.   read(i,(void *) buf,l);
  449.   close(i);
  450.   i1=0;
  451.   for (l1=0; l1<l; l1++) {
  452.     if (buf[l1]=='`') {
  453.       i1=1;
  454.       i2=0;
  455.     } else
  456.       if (i1) {
  457.         if ((buf[l1]>='0') && (buf[l1]<='9')) {
  458.           i2*=10;
  459.           i2+=(buf[l1])-'0';
  460.         } else {
  461.           while ((l1<l) && (buf[l1]!=10))
  462.             ++l1;
  463.           ++l1;
  464.           if ((i2>=0) && (i2<maxary))
  465.             m[i2].stored_as=l1;
  466.           i1=0;
  467.         }
  468.       }
  469.   }
  470.   farfree((void *) buf);
  471. }
  472.  
  473.  
  474. void far *mallocx(unsigned long l)
  475. {
  476.   void *x;
  477.  
  478.   x=farmalloc(l);
  479.   if (!x) {
  480.     printf("NOT ENOUGH MEMORY.\n");
  481.     end_bbs(noklevel);
  482.   }
  483.   return(x);
  484. }
  485.  
  486.  
  487.  
  488. void fix_user_rec(userrec *u)
  489. {
  490.   u->name[30]=0;
  491.   u->realname[20]=0;
  492.   u->callsign[6]=0;
  493.   u->phone[12]=0;
  494.   u->pw[8]=0;
  495.   u->laston[8]=0;
  496.   u->note[40]=0;
  497.   u->macros[0][80]=0;
  498.   u->macros[1][80]=0;
  499.   u->macros[2][80]=0;
  500. }
  501.  
  502. void close_user()
  503. {
  504.   if (userfile!=-1) {
  505.     close(userfile);
  506.     userfile=-1;
  507.   }
  508. }
  509.  
  510. void open_user()
  511. {
  512.   char s[81];
  513.  
  514.   if (userfile==-1) {
  515.     sprintf(s,"%sUSER.LST",syscfg.datadir);
  516.     userfile=open(s,O_RDWR | O_BINARY);
  517.     if (userfile<0) {
  518.       userfile=-1;
  519.     }
  520.   }
  521. }
  522.  
  523.  
  524. int number_userrecs()
  525. {
  526.   open_user();
  527.   return((int) (filelength(userfile)/syscfg.userreclen)-1);
  528. }
  529.  
  530. void read_user(unsigned int un, userrec *u)
  531. {
  532.   long pos;
  533.   char s[80];
  534.   int i;
  535.  
  536.   open_user();
  537.   if ((userfile<0) || (un>number_userrecs())) {
  538.     u->inact=inact_deleted;
  539.     fix_user_rec(u);
  540.     return;
  541.   }
  542.  
  543.   if (((useron) && (un==usernum)) || ((wfc) && (un==1))) {
  544.     *u=thisuser;
  545.     fix_user_rec(u);
  546.     return;
  547.   }
  548.   pos=((long) syscfg.userreclen) * ((long) un);
  549.   lseek(userfile,pos,SEEK_SET);
  550.   i=read(userfile, (void *)u, syscfg.userreclen);
  551.   if (i==-1) {
  552.     open_user();
  553.     if ((userfile<0) || (un>number_userrecs())) {
  554.       u->inact=inact_deleted;
  555.       fix_user_rec(u);
  556.       return;
  557.     }
  558.     pos=((long) syscfg.userreclen) * ((long) un);
  559.     lseek(userfile,pos,SEEK_SET);
  560.     i=read(userfile, (void *)u, syscfg.userreclen);
  561.     if (i==-1) {
  562.       pl("COULDN'T READ USER.");
  563.     }
  564.     close_user();
  565.   }
  566.   fix_user_rec(u);
  567. }
  568.  
  569.  
  570. void write_user(unsigned int un, userrec *u)
  571. {
  572.   long pos;
  573.   char s[80];
  574.   unsigned char oldsl;
  575.   int i;
  576.  
  577.   if (userfile==-1) {
  578.     sprintf(s,"%sUSER.LST",syscfg.datadir);
  579.     userfile=open(s,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  580.   }
  581.   if (((useron) && (un==usernum)) || ((wfc) && (un==1))) {
  582.     thisuser=*u;
  583.   }
  584.   pos=((long) syscfg.userreclen) * ((long) un);
  585.   lseek(userfile,pos,SEEK_SET);
  586.   i=write(userfile, (void *)u, syscfg.userreclen);
  587.   if (i==-1) {
  588.     sprintf(s,"%sUSER.LST",syscfg.datadir);
  589.     userfile=open(s,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  590.     pos=((long) syscfg.userreclen) * ((long) un);
  591.     lseek(userfile,pos,SEEK_SET);
  592.     i=write(userfile, (void *)u, syscfg.userreclen);
  593.     if (i==-1) {
  594.       pl("COULDN'T WRITE USER.");
  595.     }
  596.     close_user();
  597.   }
  598. }
  599.  
  600.  
  601. void save_status()
  602. {
  603.   char s[80];
  604.  
  605.   sprintf(s,"%sSTATUS.DAT",syscfg.datadir);
  606.   statusfile=open(s,O_RDWR | O_BINARY);
  607.   write(statusfile, (void *)(&status), sizeof(statusrec));
  608.   close(statusfile);
  609.   statusfile=-1;
  610. }
  611.  
  612.  
  613.  
  614.  
  615. double ratio()
  616. {
  617.   double r;
  618.  
  619.   if (thisuser.dk==0)
  620.     return(99.999);
  621.   r=((float) thisuser.uk) / ((float) thisuser.dk);
  622.   if (r>99.998)
  623.     r=99.998;
  624.   return(r);
  625. }
  626.  
  627.  
  628. double post_ratio()
  629. {
  630.   double r;
  631.  
  632.   if (thisuser.logons==0)
  633.     return(99.999);
  634.   r=((float) thisuser.msgpost) / ((float) thisuser.logons);
  635.   if (r>99.998)
  636.     r=99.998;
  637.   return(r);
  638. }
  639.  
  640.  
  641. char *nam(userrec *u1, unsigned int un)
  642. {
  643.   static char o[81];
  644.   int i,f,p;
  645.   userrec u;
  646.  
  647.   u=*u1;
  648.   f=1;
  649.   for (p=0; p<strlen(u.name); p++) {
  650.     if (f) {
  651.       if ((u.name[p]>='A') && (u.name[p]<='Z'))
  652.     f=0;
  653.       o[p]=u.name[p];
  654.     } else {
  655.       if ((u.name[p]>='A') && (u.name[p]<='Z'))
  656.         o[p]=u.name[p]-'A'+'a';
  657.       else {
  658.         if ((u.name[p]>=' ') && (u.name[p]<='/'))
  659.           f=1;
  660.         o[p]=u.name[p];
  661.       }
  662.     }
  663.   }
  664.   o[p++]=32;
  665.   o[p++]='#';
  666.   itoa(un,&o[p],10);
  667.   return(o);
  668. }
  669.  
  670.  
  671. char *nam1(userrec *u1, unsigned int un, unsigned int sy)
  672. {
  673.   static char o[81];
  674.   char s[10];
  675.  
  676.   strcpy(o,nam(u1,un));
  677.   if (sy) {
  678.     sprintf(s," @%u",sy);
  679.     strcat(o,s);
  680.   }
  681.   return(o);
  682. }
  683.  
  684. double nsl()
  685. {
  686.   double tlt,tlc,tot,tpl,tpd,dd,rtn;
  687.   slrec xx;
  688.  
  689.   dd=timer();
  690.   if (useron) {
  691.     if (timeon>dd)
  692.       timeon -= 24.0*3600.0;
  693.     tot=(dd-timeon);
  694.     xx=syscfg.sl[actsl];
  695.     tpl=((double) xx.time_per_logon) * 60.0;
  696.     tpd=((double) xx.time_per_day) * 60.0;
  697.     tlc = tpl - tot + (thisuser.extratime) + extratimecall;
  698.     tlt = tpd - tot - ((double) thisuser.timeontoday) + (thisuser.extratime);
  699.  
  700.     tlt=(((tlc)<(tlt)) ? (tlc) : (tlt));
  701.     if (tlt<0.0)
  702.       tlt=0.0;
  703.     if (tlt>32767.0)
  704.       tlt=32767.0;
  705.     rtn=tlt;
  706.   } else {
  707.     rtn=1.00;
  708.   }
  709.   if (syscfg.executetime) {
  710.     tlt=time_event-dd;
  711.     if (tlt<0.0)
  712.       tlt += 24.0*3600.0;
  713.     if (rtn>tlt)
  714.       rtn=tlt;
  715.     check_event();
  716.     if (do_event)
  717.       rtn=0.0;
  718.   }
  719.   if (rtn<0.0)
  720.     rtn=0.0;
  721.   if (rtn>32767.0)
  722.     rtn=32767.0;
  723.   return(rtn);
  724. }
  725.  
  726.  
  727. char *date()
  728. {
  729.   static char ds[9];
  730.   struct date today;
  731.  
  732.   getdate(&today);
  733.   sprintf(ds,"%02d/%02d/%02d",today.da_mon,today.da_day,today.da_year-1900);
  734.   return(ds);
  735. }
  736.  
  737. char *times()
  738. {
  739.   static char ti[9];
  740.   int h,m,s;
  741.   double t;
  742.  
  743.   t=timer();
  744.   h=(int) (t/3600.0);
  745.   t-=((double) (h)) * 3600.0;
  746.   m=(int) (t/60.0);
  747.   t-=((double) (m)) * 60.0;
  748.   s=(int) (t);
  749.   sprintf(ti,"%02d:%02d:%02d",h,m,s);
  750.   return(ti);
  751. }
  752.  
  753.  
  754. unsigned int finduser(char *s)
  755. {
  756.   int un;
  757.   smalrec *sr;
  758.   userrec u;
  759.   char *ss;
  760.  
  761.   if (strcmp(s,"NEW")==0)
  762.     return(-1);
  763.   if (strcmp(s,"!-@NETWORK@-!")==0)
  764.     return(-2);
  765.   if (strcmp(s,"!-@REMOTE@-!")==0)
  766.     return(-3);
  767.   if (strncmp(s,"!=@",3)==0) {
  768.     ss=s+strlen(s)-3;
  769.     if (strcmp(ss,"@=!")==0) {
  770.       strcpy(s,s+3);
  771.       s[strlen(s)-3]=0;
  772.       return(-4);
  773.     }
  774.   }
  775.  
  776.   if ((un=atoi(s))>0) {
  777.     if (un>number_userrecs())
  778.       return(0);
  779.     read_user(un,&u);
  780.     if (u.inact & inact_deleted)
  781.       return(0);
  782.     return(un);
  783.   }
  784.  
  785.   sr=(smalrec *) bsearch((void *)s,
  786.              (void *)smallist,
  787.              (size_t)status.users,
  788.              (size_t)sizeof(smalrec),
  789.              (int _Cdecl (*) (const void *, const void *))strcmp);
  790.   if (sr==0L)
  791.     return(0);
  792.   else {
  793.     read_user(sr->number,&u);
  794.     if (u.inact & inact_deleted)
  795.       return(0);
  796.     else
  797.       return(sr -> number);
  798.   }
  799. }
  800.  
  801.  
  802. void changedsl()
  803. {
  804.   int i,i1,i2,i3,i4,ok,dp,ddp;
  805.   subboardrec s;
  806.   directoryrec d;
  807.   usersubrec s1;
  808.  
  809.   topscreen();
  810.   dp=0;
  811.   dc[dp++]='/';
  812.   ddp=0;
  813.   dcd[ddp++]='/';
  814.   for (i=0; i<3; i++) {
  815.     s1.keys[i]=0;
  816.   }
  817.   s1.subnum=-1;
  818.   for (i=0; i<MAX_SUBS; i++)
  819.     usub[i]=s1;
  820.   for (i=0; i<MAX_DIRS; i++)
  821.     udir[i]=s1;
  822.   i1=1;
  823.   i2=0;
  824.   i3=0;
  825.   for (i=0; i<num_subs; i++) {
  826.     ok=1;
  827.     s=subboards[i];
  828.     if (actsl<s.readsl)
  829.       ok=0;
  830.     if (thisuser.age<s.age)
  831.       ok=0;
  832.     if ((s.ar!=0) && (((thisuser.ar) & (s.ar))==0))
  833.       ok=0;
  834.     if ((s.anony & anony_ansi_only) && (!okansi()))
  835.       ok=0;
  836.     if (ok) {
  837.       s1.subnum=i;
  838.       if (s.key!=0) {
  839.         s1.keys[0]=s.key;
  840.         s1.keys[1]=0;
  841.         s1.subnum=i;
  842.         usub[i3++]=s1;
  843.       } else {
  844.         if ((i1 % 10)==0)
  845.           dc[dp++]=('0'+(i1/10));
  846.         itoa(i1++,s1.keys,10);
  847.         s1.subnum=i;
  848.         for (i4=i3; i4>i2; i4--)
  849.           usub[i4]=usub[i4-1];
  850.         i3++;
  851.         usub[i2++]=s1;
  852.       }
  853.     }
  854.   }
  855.   i1=1;
  856.   i2=0;
  857.   for (i=0; i<num_dirs; i++) {
  858.     ok=1;
  859.     d=directories[i];
  860.     if (thisuser.dsl<d.dsl)
  861.       ok=0;
  862.     if (thisuser.age<d.age)
  863.       ok=0;
  864.     if (d.dar)
  865.       if ((d.dar & thisuser.dar)==0)
  866.         ok=0;
  867.     if (ok) {
  868.       s1.subnum=i;
  869.       if (i==0)
  870.         strcpy(s1.keys,"0");
  871.       else {
  872.         if ((i1 % 10)==0)
  873.           dcd[ddp++]=('0'+(i1/10));
  874.         itoa(i1++,s1.keys,10);
  875.       }
  876.       udir[i2++]=s1;
  877.     }
  878.   }
  879.   dcd[ddp]=0;
  880.   dc[dp]=0;
  881. }
  882.  
  883.  
  884. void isr(int un, char *name)
  885. {
  886.   int cp,i;
  887.   char s[81];
  888.   smalrec sr;
  889.  
  890.   cp=0;
  891.   while ((cp<status.users) && (strcmp(name,(smallist[cp].name))>0))
  892.     ++cp;
  893.   memmove(&(smallist[cp+1]),&(smallist[cp]),sizeof(smalrec)*(status.users-cp));
  894.   strcpy(sr.name,name);
  895.   sr.number=un;
  896.   smallist[cp]=sr;
  897.   sprintf(s,"%sNAMES.LST",syscfg.datadir);
  898.   i=open(s,O_RDWR | O_BINARY | O_TRUNC);
  899.   if (i<0) {
  900.     printf("%s NOT FOUND.\n",s);
  901.     end_bbs(noklevel);
  902.   }
  903.   ++status.users;
  904.   save_status();
  905.   write(i,(void *) (smallist), (sizeof(smalrec) * status.users));
  906.   close(i);
  907. }
  908.  
  909.  
  910. void dsr(char *name)
  911. {
  912.   int cp,i;
  913.   char s[81];
  914.   smalrec sr;
  915.  
  916.   cp=0;
  917.   while ((cp<status.users) && (strcmp(name,(smallist[cp].name))!=0))
  918.     ++cp;
  919.   if (strcmp(name,(smallist[cp].name))) {
  920.     sprintf(s,"%s NOT ABLE TO BE DELETED#*#*#*#*#*#*#*#",name);
  921.     sl1(0,s);
  922.     sl1(0,"#*#*#*# Run //resetf to fix it");
  923.     return;
  924.   }
  925.   memmove(&(smallist[cp]),&(smallist[cp+1]),sizeof(smalrec)*(status.users-cp));
  926.   sprintf(s,"%sNAMES.LST",syscfg.datadir);
  927.   i=open(s,O_RDWR | O_BINARY | O_TRUNC | O_CREAT, S_IREAD | S_IWRITE);
  928.   if (i<0) {
  929.     printf("%s COULDN'T BE CREATED.\n",s);
  930.     end_bbs(noklevel);
  931.   }
  932.   --status.users;
  933.   save_status();
  934.   write(i,(void *) (smallist), (sizeof(smalrec) * status.users));
  935.   close(i);
  936. }
  937.  
  938.  
  939. void wait(double d)
  940. {
  941.   long l1;
  942.  
  943.   l1=((long) (18.2*d));
  944.   l1 += timer1();
  945.  
  946.   enable();
  947.   while (timer1()<l1)
  948.     ;
  949. }
  950.  
  951. void wait1(long l)
  952. {
  953.   long l1;
  954.  
  955.   l1 = timer1()+l;
  956.  
  957.   enable();
  958.   while (timer1()<l1)
  959.     ;
  960. }
  961.  
  962.  
  963. double freek1(char *s)
  964. {
  965.   int d;
  966.  
  967.   d=cdir[0];
  968.   if (s[1]==':')
  969.     d=s[0];
  970.   d=d-'A'+1;
  971.   return(freek(d));
  972. }
  973.  
  974.  
  975. int exist(char *s)
  976. {
  977.   int f;
  978.  
  979.   f=open(s,O_RDONLY | O_BINARY);
  980.   close(f);
  981.   if (f>0)
  982.     return(1);
  983.   else
  984.     return(0);
  985. }
  986.  
  987.  
  988. void add_ass(int i, char *ss)
  989. {
  990.   char s[81],s1[10];
  991.  
  992.   strcpy(s,"*** ");
  993.   sysoplog(s);
  994.   strcat(s,ss);
  995.   sysoplog(s);
  996.   itoa(i,s1,10);
  997.   strcpy(s,"*** ASS-PTS: ");
  998.   strcat(s,s1);
  999.   sysoplog(s);
  1000.   thisuser.ass_pts += i;
  1001. }
  1002.