home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / W / DEVBBS.ZIP / SYSOPF.C < prev    next >
C/C++ Source or Header  |  1992-07-21  |  12KB  |  509 lines

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