home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / UTIL / WWIVE / MYWIVE.ZIP / SYSOPF.C < prev    next >
Text File  |  1993-09-25  |  12KB  |  527 lines

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