home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / Dloads / OTHERUTI / WWIV420S.ZIP / SYSOPF.C < prev    next >
C/C++ Source or Header  |  1991-04-23  |  13KB  |  546 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.  
  23. void isr1(int un, char *name)
  24. {
  25.   int cp,i;
  26.   char s[81];
  27.   smalrec sr;
  28.  
  29.   cp=0;
  30.   while ((cp<status.users) && (strcmp(name,(smallist[cp].name))>0))
  31.     ++cp;
  32.   memmove(&(smallist[cp+1]),&(smallist[cp]),sizeof(smalrec)*(status.users-cp));
  33.   strcpy(sr.name,name);
  34.   sr.number=un;
  35.   smallist[cp]=sr;
  36.   ++status.users;
  37. }
  38.  
  39.  
  40.  
  41. void reset_files()
  42. {
  43.   int i,i1;
  44.   userrec u;
  45.   char s[81];
  46.  
  47.   status.users=0;
  48.  
  49.   read_user(1,&u);
  50.   i1=number_userrecs();
  51.   for (i=1; i<=i1; i++) {
  52.     read_user(i,&u);
  53.     if ((u.inact & inact_deleted)==0)
  54.       isr1(i,u.name);
  55.     if ((i % 10)==0) {
  56.       itoa(i,s,10);
  57.       pl(s);
  58.     }
  59.   }
  60.  
  61.   sprintf(s,"%sNAMES.LST",syscfg.datadir);
  62.   i=open(s,O_RDWR | O_BINARY | O_TRUNC);
  63.   if (i<0) {
  64.     printf("%s NOT FOUND.\n",s);
  65.     abort();
  66.   }
  67.   write(i,(void *) (smallist), (sizeof(smalrec) * status.users));
  68.   close(i);
  69.  
  70.   save_status();
  71.   close_user();
  72. }
  73.  
  74.  
  75. void get_status()
  76. {
  77.   char s[81];
  78.   int statusfile;
  79.  
  80.   sprintf(s,"%sSTATUS.DAT",syscfg.datadir);
  81.   statusfile=open(s,O_RDWR | O_BINARY);
  82.   if (statusfile>=0) {
  83.     read(statusfile,(void *)(&status), sizeof(statusrec));
  84.     close(statusfile);
  85.   } else
  86.     save_status();
  87. }
  88.  
  89.  
  90.  
  91.  
  92. void prstatus()
  93. {
  94.   int i;
  95.   long l;
  96.  
  97.   outchr(12);
  98.   npr("New User Pass   : %s\r\n",syscfg.newuserpw);
  99.   npr("Board is        : %s\r\n",syscfg.closedsystem?"Closed":"Open");
  100.   npr("Number Users    : %d\r\n",status.users);
  101.   npr("Number Calls    : %ld\r\n",status.callernum1);
  102.   npr("Last Date       : %s\r\n",status.date1);
  103.   npr("Time            : %s\r\n",times());
  104.   npr("Active Today    : %d\r\n",status.activetoday);
  105.   npr("Calls Today     : %d\r\n",status.callstoday);
  106.   npr("M Posted Today  : %d\r\n",status.msgposttoday);
  107.   npr("E Sent Today    : %d\r\n",status.emailtoday);
  108.   npr("F Sent Today    : %d\r\n",status.fbacktoday);
  109.   npr("Uploads Today   : %d\r\n",status.uptoday);
  110.   npr("Feedback Waiting: %d\r\n",fwaiting);
  111.   i=3;
  112.   l=(long) freek(3);
  113.   while ((l>0) && ((i+'@')<=cdir[0])) {
  114.     npr("%c: Free Space   : %ldk\r\n",i+'@',l);
  115.     i++;
  116.     if ((i+'@')<=cdir[0])
  117.       l=(long) freek(i);
  118.   }
  119.   npr("Sysop           : %sAvailable\r\n",sysop2()?"":"NOT ");
  120. }
  121.  
  122. void valuser(int un)
  123. {
  124.   userrec u;
  125.   char s[81],s1[81],s2[81],s3[81],ar1[20],dar1[20],ch1;
  126.   int i,i1,ar2,dar2;
  127.  
  128.   read_user(un,&u);
  129.   if ((u.inact & inact_deleted)==0) {
  130.     nl();
  131.     npr("Name: %s\r\n",nam(&u,un));
  132.     npr("RN  : %s\r\n",(u.realname));
  133.     npr("PH  : %s\r\n",(u.phone));
  134.     npr("Age : %d %c\r\n", u.age, u.sex);
  135.     npr("Comp: %s\r\n",&(ctypes[u.comp_type][0]));
  136.     if (u.note[0])
  137.       npr("Note: %s\r\n",u.note);
  138.     nl();
  139.     npr("SL  : %d\r\n",u.sl);
  140.     if ((u.sl!=255) && (u.sl<actsl)) {
  141.       outstr("New ? ");
  142.       input(s,3);
  143.       if (s[0]) {
  144.         i=atoi(s);
  145.         if ((!wfc) && (i>=actsl))
  146.           i=-2;
  147.         if ((i>=0) && (i<255))
  148.           u.sl=i;
  149.     if (i==-1) {
  150.       nl();
  151.       prt(5,"Delete? ");
  152.       if (yn()) {
  153.             deluser(un);
  154.         nl();
  155.         pl("Deleted.");
  156.         nl();
  157.       } else {
  158.         nl();
  159.         pl("NOT deleted.");
  160.       }
  161.       return;
  162.     }
  163.       }
  164.     }
  165.     nl();
  166.     npr("DSL : %d\r\n",u.dsl);
  167.     if ((u.dsl!=255) && (u.dsl<thisuser.dsl)) {
  168.       outstr("New ? ");
  169.       input(s,3);
  170.       if (s[0]) {
  171.         i=atoi(s);
  172.         if ((!wfc) && (i>=thisuser.dsl))
  173.           i=-1;
  174.         if ((i>=0) && (i<255))
  175.           u.dsl=i;
  176.       }
  177.     }
  178.     strcpy(s3,restrict_string);
  179.     ar2=1;
  180.     dar2=1;
  181.     ar1[0]=13;
  182.     dar1[0]=13;
  183.     for (i=0; i<=15; i++) {
  184.       if (u.ar & (1 << i))
  185.         s[i]='A'+i;
  186.       else
  187.         s[i]=32;
  188.       if (thisuser.ar & (1 << i))
  189.         ar1[ar2++]='A'+i;
  190.       if (u.dar & (1 << i))
  191.         s1[i]='A'+i;
  192.       else
  193.         s1[i]=32;
  194.       if (thisuser.dar & (1 << i))
  195.         dar1[dar2++]='A'+i;
  196.       if (u.restrict & (1 << i))
  197.         s2[i]=s3[i];
  198.       else
  199.         s2[i]=32;
  200.     }
  201.     s[16]=0;
  202.     s1[16]=0;
  203.     s2[16]=0;
  204.     ar1[ar2]=0;
  205.     dar1[dar2]=0;
  206.     nl();
  207.     ch1=0;
  208.     if (ar2>1)
  209.       do {
  210.         npr("AR  : %s\r\n",s);
  211.         prt(2,"Togl? ");
  212.         ch1=onek(ar1);
  213.         if (ch1!=13) {
  214.           ch1-='A';
  215.           if (s[ch1]==32)
  216.             s[ch1]=ch1+'A';
  217.           else
  218.             s[ch1]=32;
  219.           u.ar ^= (1 << ch1);
  220.           ch1=0;
  221.         }
  222.       } while ((!hangup) && (ch1!=13));
  223.     nl();
  224.     ch1=0;
  225.     if (dar2>1)
  226.       do {
  227.         npr("DAR : %s\r\n",s1);
  228.         prt(2,"Togl? ");
  229.         ch1=onek(dar1);
  230.         if (ch1!=13) {
  231.           ch1-='A';
  232.           if (s1[ch1]==32)
  233.             s1[ch1]=ch1+'A';
  234.           else
  235.             s1[ch1]=32;
  236.           u.dar ^= (1 << ch1);
  237.           ch1=0;
  238.         }
  239.       } while ((!hangup) && (ch1!=13));
  240.     nl();
  241.     ch1=0;
  242.     s[0]=13;
  243.     s[1]='?';
  244.     strcpy(&(s[2]),restrict_string);
  245.     do {
  246.       npr("      %s\r\n",s3);
  247.       npr("Rstr: %s\r\n",s2);
  248.       prt(2,"Togl? ");
  249.       ch1=onek(s);
  250.       if ((ch1!=13) && (ch1!=32) && (ch1!='?')) {
  251.         i=-1;
  252.         for (i1=0; i1<16; i1++)
  253.           if (ch1==s[i1+2])
  254.             i=i1;
  255.         if (i>-1) {
  256.           u.restrict ^= (1 << i);
  257.           if (s2[i]==32)
  258.             s2[i]=s3[i];
  259.           else
  260.             s2[i]=32;
  261.         }
  262.         ch1=0;
  263.       }
  264.       if (ch1=='?') {
  265.         ch1=0;
  266.         printmenu(10);
  267.       }
  268.     } while ((!hangup) && (ch1==0));
  269.     write_user(un,&u);
  270.     close_user();
  271.     nl();
  272.   } else {
  273.     nl();
  274.     pl("No Such User.");
  275.     nl();
  276.   }
  277. }
  278.  
  279.  
  280. void print_net_listing(unsigned int ss)
  281. {
  282.   int i,i1,i2,abort,f;
  283.   char s[161],ch;
  284.   net_system_list_rec csne;
  285.  
  286.   ss = ss%10000;
  287.  
  288.   abort=0;
  289.   nl();
  290.   pla("  Num  Phone         Name                                     Hop  Next Grp",&abort);
  291.   pla("-----  ============  ---------------------------------------- === ----- ===",&abort);
  292.   sprintf(s,"%sBBSDATA.NET",syscfg.datadir);
  293.   f=open(s,O_RDONLY | O_BINARY);
  294.   for (i=0; (i<num_sys_list) && (!abort); i++) {
  295.     read(f,&csne,sizeof(net_system_list_rec));
  296.     if ((csne.forsys!=65535) && ((csne.sysnum%10000)>=ss)){
  297.       if (csne.other & other_net_coord)
  298.         ch='&';
  299.       else if (csne.other & other_group_coord)
  300.         ch='%';
  301.       else if (csne.other & other_coordinator)
  302.         ch='^';
  303.       else
  304.         ch=' ';
  305.       sprintf(s,"%5d%c %12s  %-40s %3d %5d %3d",
  306.         csne.sysnum,ch,csne.phone,csne.name,csne.numhops,
  307.         csne.forsys, csne.group);
  308.       pla(s,&abort);
  309.       ss=0;
  310.     }
  311.   }
  312.   close(f);
  313. }
  314.  
  315.  
  316. void read_new_stuff()
  317. {
  318.   int i;
  319.   char s[81];
  320.  
  321.   if (ncn!=NULL)
  322.     farfree(ncn);
  323.   if (cnn!=NULL)
  324.     farfree(cnn);
  325.   if (csn!=NULL)
  326.     farfree((void far *) csn);
  327.   if (con!=NULL)
  328.     farfree(con);
  329.   ncn=NULL;
  330.   cnn=NULL;
  331.   csn=NULL;
  332.   con=NULL;
  333.   read_in_file("MENUS.MSG",(menus),30);
  334.   read_in_file("HELP.MSG",(helps),50);
  335.   for (i=0; i<30; i++) {
  336.     menus1[i].stored_as=0L;
  337.     menus1[i].storage_type=255;
  338.     menus2[i].stored_as=0L;
  339.     menus2[i].storage_type=255;
  340.   }
  341.   sprintf(s,"%sMENUSANS.MSG",syscfg.gfilesdir);
  342.   if (exist(s))
  343.     read_in_file("MENUSANS.MSG",(menus1),30);
  344.   sprintf(s,"%sMENUS40.MSG",syscfg.gfilesdir);
  345.   if (exist(s))
  346.     read_in_file("MENUS40.MSG",(menus2),30);
  347.  
  348.   if (csn!=NULL)
  349.     farfree((void far *)csn);
  350.   if (cnn!=NULL)
  351.     farfree(cnn);
  352.   if (con!=NULL)
  353.     farfree(con);
  354.   read_bbs_list_index();
  355.   read_contacts();
  356. }
  357.  
  358.  
  359. void mailr()
  360. {
  361.   int i,abort,a,f,next;
  362.   mailrec m;
  363.   char c,s[81];
  364.   userrec u;
  365.  
  366.   sprintf(s,"%sEMAIL.DAT",syscfg.datadir);
  367.   f=open(s,O_BINARY | O_RDWR);
  368.   if (f!=-1) {
  369.     i=filelength(f)/sizeof(mailrec)-1;
  370.     c=' ';
  371.     while ((i>=0) && (c!='Q') && (!hangup)) {
  372.       lseek(f,((long) (i)) * ((long) sizeof(mailrec)),SEEK_SET);
  373.       read(f,(void *)&m,sizeof(mailrec));
  374.       if (m.touser!=0) {
  375.         do {
  376.           if (m.tosys!=0) {
  377.         outstr("To   : System #");
  378.         itoa(m.tosys,s,10);
  379.         pl(s);
  380.       } else {
  381.         read_user(m.touser,&u);
  382.             npr("To   : %s\r\n",nam(&u,m.touser));
  383.       }
  384.           npr("Title: %s\r\n",m.title);
  385.           setorigin(m.fromsys, m.fromuser);
  386.           read_message1(&(m.msg),m.anony & 0x0f,1,&next,"EMAIL");
  387.           prt(2,"R,D,Q,<space>  : ");
  388.           if (next)
  389.         c=' ';
  390.       else
  391.         c=onek("QRD ");
  392.           if (c=='D') {
  393.             delmail(f,i);
  394.         if ((!useron) && (m.touser==1) && (m.tosys==0))
  395.           --thisuser.waiting;
  396.           }
  397.           nl();
  398.       nl();
  399.         } while ((c=='R') && (!hangup));
  400.       }
  401.       i-=1;
  402.     }
  403.     close(f);
  404.     close_user();
  405.   }
  406. }
  407.  
  408.  
  409. void chuser()
  410. {
  411.   char s[81];
  412.   int i;
  413.  
  414.   if (!checkpw())
  415.     return;
  416.   if (!so())
  417.     return;
  418.   prt(2,"User to change to? ");
  419.   input(s,30);
  420.   i=finduser1(s);
  421.   if (i>0) {
  422.     write_user(usernum,&thisuser);
  423.     read_user(i,&thisuser);
  424.     usernum=i;
  425.     close_user();
  426.     actsl=255;
  427.     sprintf(s,"#*#*#* Changed to %s",nam(&thisuser,usernum));
  428.     topscreen();
  429.     sysoplog(s);
  430.   } else
  431.     pl("Unknown user.");
  432. }
  433.  
  434. void zlog()
  435. {
  436.   zlogrec z;
  437.   char s[81];
  438.   int abort,f,i,i1;
  439.  
  440.   sprintf(s,"%sZLOG.DAT",syscfg.datadir);
  441.   f=open(s,O_RDWR | O_BINARY);
  442.   if (f<0)
  443.     return;
  444.   i=0;
  445.   abort=0;
  446.   read(f,(void *)&z,sizeof(zlogrec));
  447.   pla("  Date     Calls  Active   Posts   Email   Fback    U/L    %Act   T/user",&abort);
  448.   pla("--------   -----  ------   -----   -----   -----    ---    ----   ------",&abort);
  449.   while ((i<97) && (!abort) && (!hangup) && (z.date[0]!=0)) {
  450.     if (z.calls)
  451.       i1=z.active/z.calls;
  452.     else
  453.       i1=0;
  454.     sprintf(s,"%s    %4d    %4d     %3d     %3d     %3d    %3d     %3d      %3d",
  455.          z.date,z.calls,z.active,z.posts,z.email,z.fback,z.up,10*z.active/144,i1);
  456.     pla(s,&abort);
  457.     ++i;
  458.     if (i<97) {
  459.       lseek(f,((long) i) * sizeof(zlogrec),SEEK_SET);
  460.       read(f,(void *)&z,sizeof(zlogrec));
  461.     }
  462.   }
  463.   close(f);
  464. }
  465.  
  466.  
  467. void beginday()
  468. {
  469.   char s[255];
  470.   zlogrec z,z1;
  471.   int f,i,i1;
  472.  
  473.   double fk;
  474.   int    nus;
  475.  
  476.   strcpy(z.date,status.date1);
  477.   z.active=status.activetoday;
  478.   z.calls=status.callstoday;
  479.   z.posts=status.msgposttoday;
  480.   z.email=status.emailtoday;
  481.   z.fback=status.fbacktoday;
  482.   z.up=status.uptoday;
  483.   status.callstoday=0;
  484.   status.msgposttoday=0;
  485.   status.emailtoday=0;
  486.   status.fbacktoday=0;
  487.   status.uptoday=0;
  488.   status.activetoday=0;
  489.   strcpy(status.date3,status.date2);
  490.   strcpy(status.date2,status.date1);
  491.   strcpy(status.date1,date());
  492.   strcpy(status.log2,status.log1);
  493.   sl1(3,status.log1);
  494.   sl1(2,date());
  495.   if (1) {
  496.     sprintf(s,"%s%s",syscfg.gfilesdir, status.log2);
  497.     unlink(s);
  498.   }
  499.   sprintf(s,"%sUSER.LOG",syscfg.gfilesdir);
  500.   unlink(s);
  501.   save_status();
  502.   sprintf(s,"%sZLOG.DAT",syscfg.datadir);
  503.   f=open(s,O_RDWR | O_BINARY);
  504.   if (f<0) {
  505.     f=open(s,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  506.     z1.date[0]=0;
  507.     z1.active=0;
  508.     z1.calls=0;
  509.     z1.posts=0;
  510.     z1.email=0;
  511.     z1.fback=0;
  512.     z1.up=0;
  513.     for (i=0; i<97; i++)
  514.       write(f,(void *)&z1,sizeof(zlogrec));
  515.   } else {
  516.     for (i=96; i>=1; i--) {
  517.       lseek(f,(long) ((i-1) * sizeof(zlogrec)),SEEK_SET);
  518.       read(f,(void *)&z1,sizeof(zlogrec));
  519.       lseek(f,(long) (i * sizeof(zlogrec)),SEEK_SET);
  520.       write(f,(void *)&z1,sizeof(zlogrec));
  521.     }
  522.   }
  523.   lseek(f,0L,SEEK_SET);
  524.   write(f,(void *)&z,sizeof(zlogrec));
  525.   close(f);
  526.   if (syscfg.beginday_c[0]) {
  527.     stuff_in(s,syscfg.beginday_c,create_chain_file("CHAIN.TXT"),"","","","");
  528.     full_external(s,0,1);
  529.   }
  530.  
  531.   fk=freek1(syscfg.datadir);
  532.   nus=syscfg.maxusers-status.users;
  533.  
  534.   if (fk<512.0) {
  535.     sprintf(s,"Only %dk free in data directory.",(int) fk);
  536.     ssm(1,0,s);
  537.   }
  538.  
  539.   if ((!syscfg.closedsystem) && (nus<15)){
  540.     sprintf(s,"Only %d new user slots left.",nus);
  541.     ssm(1,0,s);
  542.   }
  543. }
  544.  
  545.  
  546.