home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / W / DEVBBS.ZIP / BBSUTL1.C < prev    next >
Text File  |  1992-07-20  |  11KB  |  484 lines

  1. /*****************************************************************************
  2.  
  3.                 WWIV Version 4
  4.                     Copyright (C) 1988-1991 by Wayne Bell
  5.  
  6. *****************************************************************************/
  7.  
  8. #include "vars.h"
  9. #pragma hdrstop
  10.  
  11. int ok_local()
  12. {
  13.   if (syscfg.sysconfig& sysconfig_no_local)
  14.     return(0);
  15.   else
  16.     return(1);
  17. }
  18.  
  19. int finduser1(char *sx)
  20. {
  21.   int i,i1,i2;
  22.   char s[81],s1[81],ch;
  23.   userrec u;
  24.  
  25.   if (sx[0]==0)
  26.     return(0);
  27.   i=finduser(sx);
  28.   if (i>0)
  29.     return(i);
  30.   strcpy(s,sx);
  31.   for (i=0; s[i]!=0; i++)
  32.     s[i]=upcase(s[i]);
  33.   i2=0;
  34.   for (i=0; (i<status.users) && (i2==0); i++) {
  35.     if (strstr(smallist[i].name,s)!=NULL) {
  36.       i1=smallist[i].number;
  37.       read_user(i1,&u);
  38.       sprintf(s1,"1Do you mean f%s 7(1Y7/1N7/1Q7) 1? ",nam(&u,i1));
  39.       prt(5,s1);
  40.       ch=onek("QYN");
  41.       if (ch=='Y')
  42.     i2=i1;
  43.       if (ch=='Q')
  44.     i=status.users;
  45.     }
  46.   }
  47.   return(i2);
  48. }
  49.  
  50. void sl1(int cmd,char *s)
  51. {
  52.   static int midline=0,slf=-1;
  53.   static char f[81];
  54.   char l[180],ch1;
  55.   int i;
  56.  
  57.   switch(cmd) {
  58.     case 0: /* Write line to sysop's log */
  59.       if (slf<=0) {
  60.         slf=open(f,O_RDWR | O_CREAT | O_BINARY, S_IREAD | S_IWRITE);
  61.         if (filelength(slf)) {
  62.           lseek(slf,-1L,SEEK_END);
  63.           read(slf,((void *)&ch1),1);
  64.           if (ch1==26)
  65.             lseek(slf,-1L,SEEK_END);
  66.         }
  67.       }
  68.       if (midline) {
  69.         sprintf(l,"\r\n%s",s);
  70.         midline = 0;
  71.       } else
  72.         strcpy(l,s);
  73.       if (syscfg.sysconfig & sysconfig_printer)
  74.         fprintf(stdprn,"%s\r\n",s);
  75.       i=strlen(l);
  76.       l[i++]='\r';
  77.       l[i++]='\n';
  78.       l[i]=0;
  79.       write(slf,(void *)l,i);
  80.       break;
  81.     case 1: /* Close sysop's log */
  82.       if (slf>0) {
  83.         close(slf);
  84.         slf=-1;
  85.       }
  86.       break;
  87.     case 2: /* Set filename */
  88.       if (slf>0) {
  89.         close(slf);
  90.         slf=-1;
  91.       }
  92.       strcpy(f,syscfg.gfilesdir);
  93.       i=strlen(f);
  94.       f[i++]=s[6];
  95.       f[i++]=s[7];
  96.       f[i++]=s[0];
  97.       f[i++]=s[1];
  98.       f[i++]=s[3];
  99.       f[i++]=s[4];
  100.       f[i]=0;
  101.       strcat(f,".LOG");
  102.       break;
  103.     case 3: /* Close sysop's log  + return filename */
  104.       if (slf>0) {
  105.         close(slf);
  106.         slf=-1;
  107.       }
  108.       strcpy(s,&f[strlen(syscfg.gfilesdir)]);
  109.       break;
  110.     case 4:
  111.       if (slf <= 0) {
  112.       slf = open(f, O_RDWR | O_CREAT | O_BINARY, S_IREAD | S_IWRITE);
  113.       if (filelength(slf)) {
  114.         lseek(slf, -1L, SEEK_END);
  115.         read(slf, ((void *)&ch1), 1);
  116.         if (ch1 == 26)
  117.           lseek(slf, -1L, SEEK_END);
  118.         }
  119.       }
  120.      if (!midline || ((midline + 2 + strlen(s)) > 78)) {
  121.        strcpy(l, midline ? "\r\n   " : "   ");
  122.        strcat(l, s);
  123.        midline = 3 + strlen(s);
  124.        }
  125.      else {
  126.        strcpy(l, ", ");
  127.        strcat(l, s);
  128.        midline += (2 + strlen(s));
  129.        }
  130.      if (syscfg.sysconfig & sysconfig_printer)
  131.        fprintf(stdprn, "%s", l);
  132.      i = strlen(l);
  133.      write(slf, (void *)l, i);
  134.      break;
  135.   }
  136. }
  137.  
  138. void sysopchar(char *s)
  139. {
  140.   if ((incom || (actsl != 255)) && (s[0]))
  141.     sl1(4, s);
  142. }
  143.  
  144. void sysoplog(char *s)
  145. {
  146.   char s1[180];
  147.  
  148.   if ((incom) || (actsl!=255)) {
  149.     sprintf(s1,"   %s",s);
  150.     sl1(0,s1);
  151.   }
  152. }
  153.  
  154. void ssm(int un, int sy, char *s)
  155. {
  156.   int  f,i,i1;
  157.   userrec u;
  158.   char s1[81];
  159.   shortmsgrec sm;
  160.  
  161.   if (sy!=0)
  162.     return;
  163.   sprintf(s1,"%sSMW.DAT",syscfg.datadir);
  164.   f=open(s1,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  165.   i=(int) (filelength(f) / sizeof(shortmsgrec));
  166.   i1=i-1;
  167.   if (i1>=0) {
  168.     lseek(f,((long) (i1)) * sizeof(shortmsgrec), SEEK_SET);
  169.     read(f,(void *)&sm,sizeof(shortmsgrec));
  170.     while ((sm.tosys==0) && (sm.touser==0) && (i1>0)) {
  171.       --i1;
  172.       lseek(f,((long) (i1)) * sizeof(shortmsgrec), SEEK_SET);
  173.       read(f,(void *)&sm,sizeof(shortmsgrec));
  174.     }
  175.     if ((sm.tosys) || (sm.touser))
  176.       ++i1;
  177.   } else
  178.     i1=0;
  179.   sm.tosys=sy;
  180.   sm.touser=un;
  181.   strcpy(sm.message,s);
  182.   lseek(f,((long) (i1)) * sizeof(shortmsgrec), SEEK_SET);
  183.   write(f,(void *)&sm,sizeof(shortmsgrec));
  184.   close(f);
  185.   if (sy==0) {
  186.     read_user(un,&u);
  187.     u.sysstatus |= sysstatus_smw;
  188.     if ((u.inact & inact_deleted)==0)
  189.       write_user(un,&u);
  190.     close_user();
  191.   }
  192. }
  193.  
  194. void rsm(int un, userrec *u)
  195. {
  196.   shortmsgrec sm;
  197.   int i,i1,f,any;
  198.   char s1[81];
  199.  
  200.   any=0;
  201.   if ((u->sysstatus) & sysstatus_smw) {
  202.     sprintf(s1,"%sSMW.DAT",syscfg.datadir);
  203.     f=open(s1,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  204.     i=(int) (filelength(f) / sizeof(shortmsgrec));
  205.     for (i1=0; i1<i; i1++) {
  206.       lseek(f,((long) (i1)) * sizeof(shortmsgrec),SEEK_SET);
  207.       read(f,(void *)&sm,sizeof(shortmsgrec));
  208.       if ((sm.touser==un) && (sm.tosys==0)) {
  209.         pl(sm.message);
  210.         sm.touser=0;
  211.         sm.tosys=0;
  212.         sm.message[0]=0;
  213.         lseek(f,((long) (i1)) * sizeof(shortmsgrec),SEEK_SET);
  214.         write(f,(void *)&sm,sizeof(shortmsgrec));
  215.     any=1;
  216.       }
  217.     }
  218.     close(f);
  219.     u->sysstatus ^= sysstatus_smw;
  220.     smwcheck=1;
  221.   }
  222.   if (any)
  223.     nl();
  224. }
  225.  
  226. void show_chains(int *mapp, int *map)
  227. {
  228.   int abort,i,i1;
  229.   char s[81];
  230.  
  231.   abort=0;
  232.   nl();
  233.   for (i=0; (i<*mapp) && (!abort) && (!hangup); i++) {
  234.     sprintf(s,"7[1%-2d7] f%s",i+1, chains[map[i]].description);
  235.     pla(s,&abort);
  236.   }
  237.   nl();
  238. }
  239.  
  240. void run_chain(int cn)
  241. {
  242.   char s[255],s1[81],s2[81],s3[81];
  243.   int oc;
  244.   long l;
  245.  
  246.   itoa(com_speed, s1, 10);
  247.   itoa(syscfg.primaryport,s2,10);
  248.   itoa(modem_speed, s3, 10);
  249.   stuff_in(s,chains[cn].filename,create_chain_file("CHAIN.TXT"),s1,s2,s3,"");
  250.   sprintf(s2,"!Ran '%s'",chains[cn].description);
  251.   sysoplog(s2);
  252.   oc=chatcall;
  253.   chatcall=0;
  254.   if (chains[cn].ansir & ansir_no_DOS) {
  255.     set_protect(0);
  256.     if (chains[cn].ansir & ansir_shrink)
  257.       shrink_out(s,1,0,1,1);
  258.     else
  259.       run_external(s);
  260.     topscreen();
  261.   } else {
  262.     if (chains[cn].ansir & ansir_shrink) {
  263.       if (chains[cn].ansir & ansir_no_pause) {
  264.         shrink_out(s,2,1,1,1);
  265.       } else {
  266.         shrink_out(s,1,1,1,1);
  267.       }
  268.     } else {
  269.       l=thisuser.sysstatus;
  270.       if (chains[cn].ansir & ansir_no_pause)
  271.         thisuser.sysstatus &= ~sysstatus_pause_on_page;
  272.       full_external(s,0,1);
  273.       thisuser.sysstatus = l;
  274.     }
  275.   }
  276.   chatcall=oc;
  277. }
  278.  
  279. void do_chains()
  280. {
  281.   int map[50],mapp,i,i1,ok,done;
  282.   char s[81],s1[81],*ss;
  283.   chainfilerec c;
  284.  
  285.   mapp=0;
  286.   for (i=0; i<10; i++)
  287.     odc[i]=0;
  288.   for (i=0; i<numchain; i++) {
  289.     ok=1;
  290.     c=chains[i];
  291.     if ((c.ansir & ansir_ansi) && (!okansi()))
  292.       ok=0;
  293.     if ((c.ansir & ansir_no_300) && (modem_speed==300))
  294.       ok=0;
  295.     if (c.sl>actsl)
  296.       ok=0;
  297.     if (c.ar)
  298.       if ((c.ar & thisuser.ar)==0)
  299.         ok=0;
  300.     if (ok) {
  301.       map[mapp++]=i;
  302.       if ((mapp % 10) ==0)
  303.         odc[mapp/10 -1]='0'+(mapp/10);
  304.     }
  305.   }
  306.   if (mapp==0) {
  307.     nl();
  308.     nl();
  309.     pl("Sorry, no external programs available.");
  310.     nl();
  311.     return;
  312.   }
  313.   if (mapp==1) {
  314.     run_chain(map[0]);
  315.     return;
  316.   }
  317.   show_chains(&mapp,map);
  318.   done=0;
  319.   do {
  320.     prt(1,"Which 7(1Q7=1Quit7, 1?7=1List7) 1: ");
  321.     ss=mmkey(2);
  322.     i=atoi(ss);
  323.     if ((i>0) && (i<=mapp)) {
  324.       done=1;
  325.       run_chain(map[i-1]);
  326.     } else
  327.       if (strcmp(ss,"Q")==0)
  328.         done=1;
  329.       else
  330.         if (strcmp(ss,"?")==0)
  331.           show_chains(&mapp,map);
  332.   } while ((!hangup) && (!done));
  333. }
  334.  
  335. void read_bbsadd()
  336. {
  337.   int i,i1,i2,i3,f,len,ptrbeg[10],ptrend[10];
  338.   char s[81],l[6][81],anon,buf[512];
  339.   slrec ss;
  340.  
  341.   strcpy(s,syscfg.gfilesdir);
  342.   strcat(s,"BBSADD.MSG");
  343.   f=open(s,O_RDWR | O_BINARY);
  344.   nl();
  345.   anon=status.amsganon;
  346.   if (f<1) {
  347.     prt(1,"No BBS Add, Make one by typing //BBSADD at the main menu");
  348.   } else {
  349.     len=read(f,(void *)buf,512);
  350.     close(f);
  351.     for (i=0; i<10; i++) {
  352.       ptrbeg[i]=0;
  353.       ptrend[i]=0;
  354.     }
  355.     i=0;
  356.     i1=0;
  357.     i2=0;
  358.     for(i=0; i<len; i++) {
  359.       if (i1) {
  360.         if (buf[i]==10) {
  361.           ptrbeg[i2]=i+1;
  362.           i1=0;
  363.         }
  364.       } else {
  365.         if (buf[i]==13) {
  366.           ptrend[i2]=i-1;
  367.           if (i2<6) {
  368.             for (i3=ptrbeg[i2]; i3<=ptrend[i2]; i3++)
  369.               l[i2][i3-ptrbeg[i2]]=buf[i3];
  370.               l[i2][ptrend[i2]-ptrbeg[i2]+1]=0;
  371.           }
  372.           ++i2;
  373.           i1=1;
  374.         }
  375.       }
  376.     }
  377.     ss=syscfg.sl[thisuser.sl];
  378.     if (anon)
  379.       if (ss.ability & ability_read_post_anony) {
  380.     strcpy(s,"1<<<f ");
  381.     strcat(s,&(l[0][0]));
  382.     strcat(s," 1>>>");
  383.       } else
  384.     strcpy(s,"7>1UNKNOWN7<");
  385.     else
  386.       strcpy(s,&(l[0][0]));
  387.     nl();
  388.     npr("f─────── 1BBS Add byf: 1%sf ───────\r\n",s);
  389.     nl();
  390.     i=1;
  391.     while ((ptrend[i]) && (i<6)) {
  392.       pl(&(l[i][0]));
  393.       ++i;
  394.     }
  395.   }
  396.   nl();
  397. }
  398.  
  399. void write_bbsadd1()
  400. {
  401.   int i,i1,f;
  402.   char s[81],l[4][81];
  403.   slrec ss;
  404.  
  405.   nl();
  406.   prt(1,"Please Enter your BBS Add, you have 3 lines:");
  407.   nl();
  408.   for (i=0; i<3; i++) {
  409.     outchr(i+'1');
  410.     outchr(':');
  411.     inputl(&(l[i][0]),39);
  412.     strcat(&(l[i][0]),"\r\n");
  413.   }
  414.   nl();
  415.   ss=syscfg.sl[thisuser.sl];
  416.   if (ss.ability & ability_post_anony) {
  417.     prt(5,"eAnonymous? ");
  418.     if (yn())
  419.       i1=anony_sender;
  420.     else
  421.       i1=0;
  422.   } else
  423.     i1=0;
  424.   prt(5,"eIs this OK? ");
  425.   if (yn()) {
  426.     status.amsganon=i1;
  427.     status.amsguser=usernum;
  428.     save_status();
  429.     strcpy(s,syscfg.gfilesdir);
  430.     strcat(s,"BBSADD.MSG");
  431.     f=open(s,O_RDWR | O_BINARY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
  432.     strcpy(s,nam(&thisuser,usernum));
  433.     strcat(s,"\r\n");
  434.     write(f,(void *)s,strlen(s));
  435.     for (i=0; i<3; i++)
  436.       write(f,(void *)&(l[i][0]),strlen(&(l[i][0])));
  437.     sysoplog("Changed BBS Add");
  438.     for (i=0; i<3; i++) {
  439.       strcpy(s,"   ");
  440.       l[i][strlen(&(l[i][0]))-2]=0;
  441.       strcat(s,&(l[i][0]));
  442.       sysoplog(s);
  443.     }
  444.     nl();
  445.     prt(3,"fThank you, Your BBS Add is Saved...");
  446.     nl();
  447.     close(f);
  448.   }
  449. }
  450.  
  451. void write_bbsadd()
  452. {
  453.   char ch;
  454.   int done,okwrite;
  455.   slrec ss;
  456.  
  457.   ss=syscfg.sl[thisuser.sl];
  458.   if (ss.posts)
  459.     okwrite=1;
  460.   else
  461.     okwrite=0;
  462.   done=0;
  463.   do {
  464.     nl();
  465.     if (okwrite) {
  466.       nl();
  467.       nl();
  468.       prt(5,"7[1R7]1Read,7[1W7]1Write,7[1Q7]1Quit");
  469.       ch=onek("QRW");
  470.     }
  471.     switch(ch) {
  472.       case 'Q':
  473.         done=1;
  474.         break;
  475.       case 'R':
  476.         read_bbsadd();
  477.         break;
  478.       case 'W':
  479.         write_bbsadd1();
  480.         break;
  481.     }
  482.   } while ((!done) && (!hangup));
  483. }
  484.