home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / WWIV2.ZIP / CONNECT1.C < prev    next >
C/C++ Source or Header  |  1992-12-03  |  7KB  |  321 lines

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