home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / UTIL / WWIVE / CONNECT1.C < prev    next >
C/C++ Source or Header  |  1991-05-26  |  8KB  |  314 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. #include <math.h>
  22.  
  23.  
  24.  
  25. void read_call_out_list()
  26. {
  27.   char s[161],b[256],s1[81],*ss;
  28.   int f,i,i1,i2,n,cur_sys;
  29.   long l,p;
  30.   float fl;
  31.  
  32.   sprintf(s,"%sCALLOUT.NET",syscfg.datadir);
  33.   f=open(s,O_RDWR | O_BINARY);
  34.   if (f<0)
  35.     con=NULL;
  36.   else {
  37.     l=filelength(f);
  38.     if ((ss=malloca(l+512))==NULL)
  39.       end_bbs(noklevel);
  40.     read(f,(void *)ss,(int) l);
  41.     close(f);
  42.     num_call_sys=0;
  43.     for (p=0L; p<l; p++)
  44.       if (ss[p]=='@')
  45.     ++num_call_sys;
  46.     farfree(ss);
  47.     if ((con=malloca(((long)(num_call_sys+2))*sizeof(net_call_out_rec)))==NULL)
  48.       end_bbs(noklevel);
  49.     f=open(s,O_RDWR | O_BINARY);
  50.     if ((ss=malloca(l+512))==NULL)
  51.       end_bbs(noklevel);
  52.     read(f,(void *)ss,(int) l);
  53.     close(f);
  54.     p=0L;
  55.     cur_sys=-1;
  56.     while (p<l) {
  57.       while ((p<l) && (strchr("@%/\"&-=+~!();",ss[p])==NULL))
  58.     ++p;
  59.       if (p<l) {
  60.     switch(ss[p]) {
  61.       case '@':
  62.         ++p;
  63.         ++cur_sys;
  64.         con[cur_sys].macnum=0;
  65.         con[cur_sys].options=0;
  66.         con[cur_sys].call_anyway=0;
  67.         con[cur_sys].password[0]=0;
  68.         con[cur_sys].sysnum=atoi(&(ss[p]));
  69.             con[cur_sys].min_hr=-1;
  70.             con[cur_sys].max_hr=-1;
  71.             con[cur_sys].times_per_day=0;
  72.         break;
  73.           case '&':
  74.         con[cur_sys].options |= options_sendback;
  75.         ++p;
  76.         break;
  77.           case '-':
  78.         con[cur_sys].options |= options_ATT_night;
  79.         ++p;
  80.         break;
  81.           case '=':
  82.         con[cur_sys].options |= options_PCP_night;
  83.         ++p;
  84.         break;
  85.           case '+':
  86.         con[cur_sys].options |= options_no_call;
  87.         ++p;
  88.         break;
  89.       case '~':
  90.         con[cur_sys].options |= options_receive_only;
  91.         ++p;
  92.         break;
  93.       case '!':
  94.         con[cur_sys].options |= options_once_per_day;
  95.         ++p;
  96.             con[cur_sys].times_per_day=atoi(&(ss[p]));
  97.             if (!con[cur_sys].times_per_day)
  98.               con[cur_sys].times_per_day=1;
  99.         break;
  100.       case '%':
  101.         ++p;
  102.         con[cur_sys].macnum=(unsigned char) atoi(&(ss[p]));
  103.         break;
  104.       case '/':
  105.         ++p;
  106.         con[cur_sys].call_anyway=(unsigned char) atoi(&(ss[p]));
  107.         break;
  108.           case '(':
  109.             ++p;
  110.             con[cur_sys].min_hr = (unsigned char) atoi(&(ss[p]));
  111.             break;
  112.           case ')':
  113.             ++p;
  114.             con[cur_sys].max_hr = (unsigned char) atoi(&(ss[p]));
  115.             break;
  116.           case ';':
  117.             ++p;
  118.             con[cur_sys].options |= options_compress;
  119.             break;
  120.       case '\"':
  121.         ++p;
  122.         i=0;
  123.             while ((i<40) && (ss[p+(long)i]!='\"'))
  124.           ++i;
  125.         for (i1=0; i1<i; i1++)
  126.           con[cur_sys].password[i1]=ss[p+(long)i1];
  127.         con[cur_sys].password[i]=0;
  128.         p+=(long)(i+1);
  129.         break;
  130.     }
  131.       }
  132.     }
  133.     farfree(ss);
  134.   }
  135. }
  136.  
  137.  
  138. void write_call_out_list()
  139. {
  140.   char s[161],b[256],s1[81],*ss;
  141.   int f,i,i1,i2,n,cur_sys;
  142.   long l,p;
  143.   float fl;
  144.  
  145.   sprintf(s,"%sCALLOUT.NET",syscfg.datadir);
  146.   f=open(s,O_RDWR | O_BINARY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
  147.   if (f>0) {
  148.     for (i=0; i<num_call_sys; i++) {
  149.       sprintf(s,"@%-6u ",con[i].sysnum);
  150.       if (con[i].macnum) {
  151.         sprintf(s1,"%%%-3u ",(int) con[i].macnum);
  152.     strcat(s,s1);
  153.       } else
  154.         strcat(s,"     ");
  155.       if (con[i].call_anyway) {
  156.         sprintf(s1,"/%-3u ",(int) con[i].call_anyway);
  157.     strcat(s,s1);
  158.       } else
  159.         strcat(s,"     ");
  160.       sprintf(s1,"%c %c %c %c %c %c %c",
  161.         (con[i].options & options_sendback)?'&':' ',
  162.         (con[i].options & options_ATT_night)?'-':' ',
  163.         (con[i].options & options_PCP_night)?'=':' ',
  164.         (con[i].options & options_no_call)?'+':' ',
  165.         (con[i].options & options_receive_only)?'~':' ',
  166.         (con[i].options & options_compress)     ? ';' : ' ',
  167.         (con[i].options & options_once_per_day) ? '!' : ' ');
  168.       strcat(s,s1);
  169.       if ((con[i].options & options_once_per_day) &&
  170.           (con[i].times_per_day!=1)) {
  171.         sprintf(s1,"%-3u ",(int) con[i].times_per_day);
  172.         strcat(s,s1);
  173.       } else
  174.         strcat(s,"    ");
  175.       if (con[i].min_hr>0) {
  176.         sprintf(s1,"(%-3u ",(int) con[i].min_hr);
  177.         strcat(s,s1);
  178.       } else
  179.         strcat(s,"     ");
  180.       if (con[i].max_hr>0) {
  181.         sprintf(s1,")%-3u ",(int) con[i].max_hr);
  182.         strcat(s,s1);
  183.       } else
  184.         strcat(s,"     ");
  185.  
  186.       sprintf(s1,"\"%s\"\r\n",con[i].password);
  187.       strcat(s,s1);
  188.       write(f,(void *)s,strlen(s));
  189.     }
  190.     close(f);
  191.   }
  192. }
  193.  
  194.  
  195.  
  196. void read_bbs_list()
  197. {
  198.   char s[161];
  199.   int f,i;
  200.   long l,p;
  201.  
  202.   csn=NULL;
  203.   cnn=NULL;
  204.   con=NULL;
  205.   num_sys=0;
  206.   num_sys_list=0;
  207.   num_call_sys=0;
  208.   if (syscfg.systemnumber==0)
  209.     return;
  210.   sprintf(s,"%sBBSDATA.NET",syscfg.datadir);
  211.   f=open(s,O_RDWR | O_BINARY);
  212.   if (f>0) {
  213.     l=filelength(f);
  214.     num_sys_list=(int) (l/sizeof(net_system_list_rec));
  215.     if ((csn=malloca(l+512L))==NULL)
  216.       end_bbs(noklevel);
  217.     for (i=0; i<num_sys_list; i+=256) {
  218.       read(f,(void *)&(csn[i]),256*sizeof(net_system_list_rec));
  219.     }
  220.     close(f);
  221.     read_call_out_list();
  222.   }
  223. }
  224.  
  225.  
  226. void read_bbs_list_index()
  227. {
  228.   char s[161];
  229.   int f;
  230.   long l;
  231.  
  232.   csn=NULL;
  233.   cnn=NULL;
  234.   con=NULL;
  235.   num_sys=0;
  236.   num_sys_list=0;
  237.   num_call_sys=0;
  238.   if (syscfg.systemnumber==0)
  239.     return;
  240.   sprintf(s,"%sBBSDATA.IND",syscfg.datadir);
  241.   f=open(s,O_RDWR | O_BINARY);
  242.   if (f>0) {
  243.     l=filelength(f);
  244.     num_sys_list=(int) (l/2);
  245.     if ((csn_index=malloca(l))==NULL)
  246.       end_bbs(noklevel);
  247.     read(f,(void *)csn_index,l);
  248.     close(f);
  249.     read_call_out_list();
  250.   } else
  251.     read_bbs_list();
  252. }
  253.  
  254.  
  255.  
  256. net_system_list_rec *next_system(unsigned int ts)
  257. {
  258.   int i,f;
  259.   static net_system_list_rec csne;
  260.   char s[81];
  261.  
  262.   if (csn) {
  263.     for (i=0; i<num_sys_list; i++)
  264.       if (csn[i].sysnum==ts) {
  265.         if (csn[i].forsys==65535)
  266.           return(NULL);
  267.         else
  268.           return((net_system_list_rec *) &(csn[i]));
  269.       }
  270.     return(NULL);
  271.   } else {
  272.     for (i=0; i<num_sys_list; i++)
  273.       if (csn_index[i]==ts) {
  274.         sprintf(s,"%sBBSDATA.NET",syscfg.datadir);
  275.         f=open(s,O_RDONLY | O_BINARY);
  276.         lseek(f,sizeof(net_system_list_rec)*((long)i),SEEK_SET);
  277.         read(f,&csne,sizeof(net_system_list_rec));
  278.         close(f);
  279.         if (csne.forsys==65535)
  280.           return(NULL);
  281.         else
  282.           return(&csne);
  283.       }
  284.     return(NULL);
  285.   }
  286. }
  287.  
  288.  
  289.  
  290. void read_contacts()
  291. {
  292.   int i,f;
  293.   char s[81];
  294.   long l;
  295.  
  296.   if (ncn!=NULL)
  297.     farfree(ncn);
  298.   ncn=NULL;
  299.   num_ncn=0;
  300.  
  301.   sprintf(s,"%sCONTACT.NET",syscfg.datadir);
  302.   f=open(s,O_RDWR | O_BINARY);
  303.   if (f>=0) {
  304.     l=filelength(f);
  305.     num_ncn=(int) (l/sizeof(net_contact_rec));
  306.     if ((ncn=malloca((num_ncn+2)*sizeof(net_contact_rec)))==NULL)
  307.       end_bbs(noklevel);
  308.     lseek(f,0L,SEEK_SET);
  309.     read(f,(void *)ncn,num_ncn*sizeof(net_contact_rec));
  310.     close(f);
  311.   }
  312. }
  313.  
  314.