home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / UTIL / WWIVE / MYWIVE.ZIP / BBSUTL1.C < prev    next >
Text File  |  1992-08-29  |  11KB  |  480 lines

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