home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / UTIL / WWIVE / BBSUTL1.C < prev    next >
Text File  |  1991-12-25  |  8KB  |  348 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.  
  22. int ok_local()
  23. {
  24.   if (syscfg.sysconfig& sysconfig_no_local)
  25.     return(0);
  26.   else
  27.     return(1);
  28. }
  29.  
  30.  
  31. int finduser1(char *sx)
  32. {
  33.   int i,i1,i2;
  34.   char s[81],s1[81],ch;
  35.   userrec u;
  36.  
  37.   if (sx[0]==0)
  38.     return(0);
  39.   i=finduser(sx);
  40.   if (i>0)
  41.     return(i);
  42.   strcpy(s,sx);
  43.   for (i=0; s[i]!=0; i++)
  44.     s[i]=upcase(s[i]);
  45.   i2=0;
  46.   for (i=0; (i<status.users) && (i2==0); i++) {
  47.     if (strstr(smallist[i].name,s)!=NULL) {
  48.       i1=smallist[i].number;
  49.       read_user(i1,&u);
  50.       sprintf(s1,"1Do you mean7 %s5 (Y/N/Q) ? ",nam(&u,i1));
  51.       prt(5,s1);
  52.       ch=onek("QYN");
  53.       if (ch=='Y')
  54.     i2=i1;
  55.       if (ch=='Q')
  56.     i=status.users;
  57.     }
  58.   }
  59.   return(i2);
  60. }
  61.  
  62.  
  63. void sl1(int cmd,char *s)
  64. {
  65.   static int midline=0,slf=-1;
  66.   static char f[81];
  67.   char l[180],ch1;
  68.   int i;
  69.  
  70.   switch(cmd) {
  71.     case 0: /* Write line to sysop's log */
  72.       if (slf<=0) {
  73.         slf=open(f,O_RDWR | O_CREAT | O_BINARY, S_IREAD | S_IWRITE);
  74.         if (filelength(slf)) {
  75.           lseek(slf,-1L,SEEK_END);
  76.           read(slf,((void *)&ch1),1);
  77.           if (ch1==26)
  78.             lseek(slf,-1L,SEEK_END);
  79.         }
  80.       }
  81.       if (midline) {
  82.         sprintf(l,"\r\n%s",s);
  83.         midline = 0;
  84.       } else
  85.         strcpy(l,s);
  86.       if (syscfg.sysconfig & sysconfig_printer)
  87.         fprintf(stdprn,"%s\r\n",s);
  88.       i=strlen(l);
  89.       l[i++]='\r';
  90.       l[i++]='\n';
  91.       l[i]=0;
  92.       write(slf,(void *)l,i);
  93.       break;
  94.     case 1: /* Close sysop's log */
  95.       if (slf>0) {
  96.         close(slf);
  97.         slf=-1;
  98.       }
  99.       break;
  100.     case 2: /* Set filename */
  101.       if (slf>0) {
  102.         close(slf);
  103.         slf=-1;
  104.       }
  105.       strcpy(f,syscfg.gfilesdir);
  106.       i=strlen(f);
  107.       f[i++]=s[6];
  108.       f[i++]=s[7];
  109.       f[i++]=s[0];
  110.       f[i++]=s[1];
  111.       f[i++]=s[3];
  112.       f[i++]=s[4];
  113.       f[i]=0;
  114.       strcat(f,".LOG");
  115.       break;
  116.     case 3: /* Close sysop's log  + return filename */
  117.       if (slf>0) {
  118.         close(slf);
  119.         slf=-1;
  120.       }
  121.       strcpy(s,&f[strlen(syscfg.gfilesdir)]);
  122.       break;
  123.     case 4:
  124.       if (slf <= 0) {
  125.       slf = open(f, O_RDWR | O_CREAT | O_BINARY, S_IREAD | S_IWRITE);
  126.       if (filelength(slf)) {
  127.         lseek(slf, -1L, SEEK_END);
  128.         read(slf, ((void *)&ch1), 1);
  129.         if (ch1 == 26)
  130.           lseek(slf, -1L, SEEK_END);
  131.         }
  132.       }
  133.      if (!midline || ((midline + 2 + strlen(s)) > 78)) {
  134.        strcpy(l, midline ? "\r\n   " : "   ");
  135.        strcat(l, s);
  136.        midline = 3 + strlen(s);
  137.        }
  138.      else {
  139.        strcpy(l, ", ");
  140.        strcat(l, s);
  141.        midline += (2 + strlen(s));
  142.        }
  143.      if (syscfg.sysconfig & sysconfig_printer)
  144.        fprintf(stdprn, "%s", l);
  145.      i = strlen(l);
  146.      write(slf, (void *)l, i);
  147.      break;
  148.   }
  149. }
  150.  
  151. void sysopchar(char *s)
  152. {
  153.   if ((incom || (actsl != 255)) && (s[0]))
  154.     sl1(4, s);
  155. }
  156.  
  157. void sysoplog(char *s)
  158. {
  159.   char s1[180];
  160.  
  161.   if ((incom) || (actsl!=255)) {
  162.     sprintf(s1,"   %s",s);
  163.     sl1(0,s1);
  164.   }
  165. }
  166.  
  167.  
  168. void ssm(int un, int sy, char *s)
  169. {
  170.   int  f,i,i1;
  171.   userrec u;
  172.   char s1[81];
  173.   shortmsgrec sm;
  174.  
  175.   if (sy!=0)
  176.     return;
  177.   sprintf(s1,"%sSMW.DAT",syscfg.datadir);
  178.   f=open(s1,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  179.   i=(int) (filelength(f) / sizeof(shortmsgrec));
  180.   i1=i-1;
  181.   if (i1>=0) {
  182.     lseek(f,((long) (i1)) * sizeof(shortmsgrec), SEEK_SET);
  183.     read(f,(void *)&sm,sizeof(shortmsgrec));
  184.     while ((sm.tosys==0) && (sm.touser==0) && (i1>0)) {
  185.       --i1;
  186.       lseek(f,((long) (i1)) * sizeof(shortmsgrec), SEEK_SET);
  187.       read(f,(void *)&sm,sizeof(shortmsgrec));
  188.     }
  189.     if ((sm.tosys) || (sm.touser))
  190.       ++i1;
  191.   } else
  192.     i1=0;
  193.   sm.tosys=sy;
  194.   sm.touser=un;
  195.   strcpy(sm.message,s);
  196.   lseek(f,((long) (i1)) * sizeof(shortmsgrec), SEEK_SET);
  197.   write(f,(void *)&sm,sizeof(shortmsgrec));
  198.   close(f);
  199.   if (sy==0) {
  200.     read_user(un,&u);
  201.     u.sysstatus |= sysstatus_smw;
  202.     if ((u.inact & inact_deleted)==0)
  203.       write_user(un,&u);
  204.     close_user();
  205.   }
  206. }
  207.  
  208. void rsm(int un, userrec *u)
  209. {
  210.   shortmsgrec sm;
  211.   int i,i1,f,any;
  212.   char s1[81];
  213.  
  214.   any=0;
  215.   if ((u->sysstatus) & sysstatus_smw) {
  216.     sprintf(s1,"%sSMW.DAT",syscfg.datadir);
  217.     f=open(s1,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  218.     i=(int) (filelength(f) / sizeof(shortmsgrec));
  219.     for (i1=0; i1<i; i1++) {
  220.       lseek(f,((long) (i1)) * sizeof(shortmsgrec),SEEK_SET);
  221.       read(f,(void *)&sm,sizeof(shortmsgrec));
  222.       if ((sm.touser==un) && (sm.tosys==0)) {
  223.         pl(sm.message);
  224.         sm.touser=0;
  225.         sm.tosys=0;
  226.         sm.message[0]=0;
  227.         lseek(f,((long) (i1)) * sizeof(shortmsgrec),SEEK_SET);
  228.         write(f,(void *)&sm,sizeof(shortmsgrec));
  229.     any=1;
  230.       }
  231.     }
  232.     close(f);
  233.     u->sysstatus ^= sysstatus_smw;
  234.     smwcheck=1;
  235.   }
  236.   if (any)
  237.     nl();
  238. }
  239.  
  240.  
  241. void show_chains(int *mapp, int *map)
  242. {
  243.   int abort,i,i1;
  244.   char s[81];
  245.  
  246.   abort=0;
  247.   nl();
  248.   for (i=0; (i<*mapp) && (!abort) && (!hangup); i++) {
  249.     sprintf(s,"7[1%d7]1.3 %s",i+1, chains[map[i]].description);
  250.     pla(s,&abort);
  251.   }
  252.   nl();
  253. }
  254.  
  255.  
  256. void run_chain(int cn)
  257. {
  258.   char s[255],s1[81],s2[81],s3[81];
  259.   int oc;
  260.   long l;
  261.  
  262.   itoa(com_speed, s1, 10);
  263.   itoa(syscfg.primaryport,s2,10);
  264.   itoa(modem_speed, s3, 10);
  265.   stuff_in(s,chains[cn].filename,create_chain_file("CHAIN.TXT"),s1,s2,s3,"");
  266.   sprintf(s2,"!Ran '%s'",chains[cn].description);
  267.   sysoplog(s2);
  268.   oc=chatcall;
  269.   chatcall=0;
  270.   l=thisuser.sysstatus;
  271.   if (chains[cn].ansir & ansir_no_pause)
  272.     thisuser.sysstatus &= ~sysstatus_pause_on_page;
  273.   if (chains[cn].ansir & ansir_no_DOS) {
  274.     set_protect(0);
  275.     if (chains[cn].ansir & ansir_shrink)
  276.       shrink_out(s,1,0,1,1);
  277.     else
  278.       run_external(s);
  279.     topscreen();
  280.   } else
  281.     if (chains[cn].ansir & ansir_shrink)
  282.       shrink_out(s,1,1,1,1);
  283.     else
  284.       full_external(s,0,1);
  285.   thisuser.sysstatus = l;
  286.   chatcall=oc;
  287. }
  288.  
  289.  
  290.  
  291. void do_chains()
  292. {
  293.   int map[50],mapp,i,i1,ok,done;
  294.   char s[81],s1[81],*ss;
  295.   chainfilerec c;
  296.  
  297.   mapp=0;
  298.   for (i=0; i<10; i++)
  299.     odc[i]=0;
  300.   for (i=0; i<numchain; i++) {
  301.     ok=1;
  302.     c=chains[i];
  303.     if ((c.ansir & ansir_ansi) && (!okansi()))
  304.       ok=0;
  305.     if ((c.ansir & ansir_no_300) && (modem_speed==300))
  306.       ok=0;
  307.     if (c.sl>actsl)
  308.       ok=0;
  309.     if (c.ar)
  310.       if ((c.ar & thisuser.ar)==0)
  311.         ok=0;
  312.     if (ok) {
  313.       map[mapp++]=i;
  314.       if ((mapp % 10) ==0)
  315.         odc[mapp/10 -1]='0'+(mapp/10);
  316.     }
  317.   }
  318.   if (mapp==0) {
  319.     nl();
  320.     nl();
  321.     pl("7Sorry, no games available.");
  322.     nl();
  323.     return;
  324.   }
  325.   if (mapp==1) {
  326.     run_chain(map[0]);
  327.     return;
  328.   }
  329.   show_chains(&mapp,map);
  330.   done=0;
  331.   do {
  332.     prt(1,"Which 7[5Q1=5Quit1,5 ?1=5List7]3 : ");
  333.     ss=mmkey(2);
  334.     i=atoi(ss);
  335.     if ((i>0) && (i<=mapp)) {
  336.       done=1;
  337.       run_chain(map[i-1]);
  338.     } else
  339.       if (strcmp(ss,"Q")==0)
  340.         done=1;
  341.       else
  342.         if (strcmp(ss,"?")==0)
  343.           show_chains(&mapp,map);
  344.   } while ((!hangup) && (!done));
  345. }
  346.  
  347.  
  348.