home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / W / WWIVSOR.ZIP / CONNECT1.C < prev    next >
C/C++ Source or Header  |  1995-04-25  |  8KB  |  337 lines

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