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

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