Please consider a donation to the Higher Intellect project. See https://preterhuman.net/donate.php or the Donate to Higher Intellect page for more info.

SERVER.C

From Higher Intellect Vintage Wiki
Jump to navigation Jump to search
/*  7PSERV interface utility for W0RLI BBS */

#include <stdio.h>
#include <stdlib.h>
#include <io.h>
#include <fcntl.h>
#include <string.h>
#include <process.h>
#include <share.h>
#include <sys\stat.h>


int mail_mb;
char *tocall[7];
char *fromcall[7];
char *atcall[7];
char *title[80];
long seek_ofs = 0L;
int servmailcnt = 0;


errormsg(char *errtype)
{
     printf("Error on %s file MAIL.MB\n",errtype);
     printf("Error number %d\n",errno);
}


filefix()
{
FILE* mail_out;
FILE* msgfile;
static char mailoutname[13],msgname[8];
char indx[2];
char msgstring[80]; 
int msg_no;
int result;

/*     strcpy(mailoutname,"MAIL");
     itoa(servmailcnt+1,indx,10);
     strcat(mailoutname,indx);
     strcat(mailoutname,".OUT"); */

     strcpy(mailoutname,"MAIL.OUT");
     
     mail_out = fopen(mailoutname,"wt");

     fprintf(mail_out,"%s","SP 7PSERV < ");

     lseek(mail_mb,seek_ofs+0x11,SEEK_SET);
     read(mail_mb,fromcall,7); 
     fprintf(mail_out,"%s\n",fromcall);
     
     lseek(mail_mb,seek_ofs+0x34,SEEK_SET);
     read(mail_mb,title,80);
     fprintf(mail_out,"%s\n",title);

     lseek(mail_mb,seek_ofs+0x04,SEEK_SET);
     read(mail_mb,&msg_no,2);
     itoa(msg_no,msgname,10);
     msgfile = fopen(msgname,"rt");     

     while(!feof(msgfile))
     {
          fgets(msgstring,80,msgfile);
          if (!feof(msgfile)) fputs(msgstring,mail_out);
     }

     fclose(msgfile);
     fclose(mail_out);

     lseek(mail_mb,seek_ofs+0x09,SEEK_SET);
     write(mail_mb,"\x04",1);                    /* KILL MESSAGE */
     servmailcnt++;         

     result = spawnl(P_WAIT, "\\bbs\\7pserv.exe", "", "\\bbs\\mail.out", NULL);
     if (result == -1)
     {
          printf("Error from spawnl\n");
          exit(1);
     }
}



main()
{
int mail_no,i,ch;
char dummy,msg_flags;

     printf("W0RLI BBS 7PSERV Interface v1.0 by Mats Petersson SM5SXL\n");

     mail_mb = sopen("MAIL.MB", O_RDWR | O_TEXT, SH_DENYNO, S_IFREG);

     if(!mail_mb)
     {
          errormsg("sopen");
          exit(1);
     }

     while( (bioskey(1) & 0xFF) != 27)
     {
          seek_ofs = 0L;

          lseek(mail_mb,2L,SEEK_SET);
          read(mail_mb,&mail_no,2);

          for(i = 0; i < mail_no; i++)
          {
               seek_ofs += 0x200L;

               lseek(mail_mb,seek_ofs+0x09L,SEEK_SET);
               read(mail_mb,&msg_flags,1);

               if(!(msg_flags & 4))          /* Only check if not killed  */
               {
                    read(mail_mb,tocall,7);

                    if(strcmp(tocall,"7PSERV") == 0)
                    {     
                         lseek(mail_mb,seek_ofs+0x18,SEEK_SET);
                         read(mail_mb,atcall,7);
                         if ((strlen(atcall) == 0) || (strcmp(atcall,"SM5SXL") == 0))
                              filefix();
                    }
               }
          }
     }
     ch = bioskey(0);
     printf("Server closed.\n");
     close(mail_mb);
}