home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Devil's Doorknob BBS Capture (1996-2003)
/
devilsdoorknobbbscapture1996-2003.iso
/
Dloads
/
OTHERUTI
/
WWIV412S.ZIP
/
CONNECT1.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-04-29
|
8KB
|
341 lines
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
#include <string.h>
#include <alloc.h>
#include <sys\stat.h>
#include <math.h>
#include <stdlib.h>
#include "vardec.h"
#include "net.h"
#include "fcns.h"
int num_sys,num_sys_list,num_call_sys,num_ncn;
net_interconnect_rec *cnn;
net_call_out_rec *con;
net_system_list_rec huge *csn;
net_contact_rec *ncn;
unsigned int *csn_index;
extern int noklevel;
extern configrec syscfg;
void read_call_out_list()
{
char s[161],b[256],s1[81],*ss;
int f,i,i1,i2,n,cur_sys;
long l,p;
float fl;
sprintf(s,"%sCALLOUT.NET",syscfg.datadir);
f=open(s,O_RDWR | O_BINARY);
if (f<0)
con=NULL;
else {
l=filelength(f);
if ((ss=malloca(l+512))==NULL)
end_bbs(noklevel);
read(f,(void *)ss,(int) l);
close(f);
num_call_sys=0;
for (p=0L; p<l; p++)
if (ss[p]=='@')
++num_call_sys;
farfree(ss);
if ((con=malloca(((long)(num_call_sys+2))*sizeof(net_call_out_rec)))==NULL)
end_bbs(noklevel);
f=open(s,O_RDWR | O_BINARY);
if ((ss=malloca(l+512))==NULL)
end_bbs(noklevel);
read(f,(void *)ss,(int) l);
close(f);
p=0L;
cur_sys=-1;
while (p<l) {
while ((p<l) && (strchr("@%/\"&-=+~!()",ss[p])==NULL))
++p;
if (p<l) {
switch(ss[p]) {
case '@':
++p;
++cur_sys;
con[cur_sys].macnum=0;
con[cur_sys].options=0;
con[cur_sys].call_anyway=0;
con[cur_sys].password[0]=0;
con[cur_sys].sysnum=atoi(&(ss[p]));
con[cur_sys].min_hr=-1;
con[cur_sys].max_hr=-1;
con[cur_sys].times_per_day=0;
break;
case '&':
con[cur_sys].options |= options_sendback;
++p;
break;
case '-':
con[cur_sys].options |= options_ATT_night;
++p;
break;
case '=':
con[cur_sys].options |= options_PCP_night;
++p;
break;
case '+':
con[cur_sys].options |= options_no_call;
++p;
break;
case '~':
con[cur_sys].options |= options_receive_only;
++p;
break;
case '!':
con[cur_sys].options |= options_once_per_day;
++p;
con[cur_sys].times_per_day=atoi(&(ss[p]));
if (!con[cur_sys].times_per_day)
con[cur_sys].times_per_day=1;
break;
case '%':
++p;
con[cur_sys].macnum=(unsigned char) atoi(&(ss[p]));
break;
case '/':
++p;
con[cur_sys].call_anyway=(unsigned char) atoi(&(ss[p]));
break;
case '(':
++p;
con[cur_sys].min_hr = (unsigned char) atoi(&(ss[p]));
break;
case ')':
++p;
con[cur_sys].max_hr = (unsigned char) atoi(&(ss[p]));
break;
case '\"':
++p;
i=0;
while ((i<40) && (ss[p+(long)i]!='"'))
++i;
for (i1=0; i1<i; i1++)
con[cur_sys].password[i1]=ss[p+(long)i1];
con[cur_sys].password[i]=0;
p+=(long)(i+1);
break;
}
}
}
farfree(ss);
}
}
void write_call_out_list()
{
char s[161],b[256],s1[81],*ss;
int f,i,i1,i2,n,cur_sys;
long l,p;
float fl;
sprintf(s,"%sCALLOUT.NET",syscfg.datadir);
f=open(s,O_RDWR | O_BINARY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
if (f>0) {
for (i=0; i<num_call_sys; i++) {
strcpy(s,"@");
itoa(con[i].sysnum,s1,10);
strcat(s,s1);
while (strlen(s)<8)
strcat(s," ");
if (con[i].macnum) {
strcat(s,"%");
itoa((int)con[i].macnum,s1,10);
strcat(s,s1);
for (i1=strlen(s1); i1<4; i1++)
strcat(s," ");
} else
for (i1=0; i1<5; i1++)
strcat(s," ");
if (con[i].call_anyway) {
strcat(s,"/");
itoa((int)con[i].call_anyway,s1,10);
strcat(s,s1);
for (i1=strlen(s1); i1<4; i1++)
strcat(s," ");
} else
for (i1=0; i1<5; i1++)
strcat(s," ");
if (con[i].options & options_sendback)
strcat(s,"& ");
else
strcat(s," ");
if (con[i].options & options_ATT_night)
strcat(s,"- ");
else
strcat(s," ");
if (con[i].options & options_PCP_night)
strcat(s,"= ");
else
strcat(s," ");
if (con[i].options & options_no_call)
strcat(s,"+ ");
else
strcat(s," ");
if (con[i].options & options_receive_only)
strcat(s,"~ ");
else
strcat(s," ");
if (con[i].options & options_once_per_day)
strcat(s,"! ");
else
strcat(s," ");
if (con[i].min_hr>0) {
strcat(s,"(");
itoa((int)con[i].min_hr,s1,10);
strcat(s,s1);
for (i1=strlen(s1); i1<4; i1++)
strcat(s," ");
} else
for (i1=0; i1<5; i1++)
strcat(s," ");
if (con[i].max_hr>0) {
strcat(s,")");
itoa((int)con[i].max_hr,s1,10);
strcat(s,s1);
for (i1=strlen(s1); i1<4; i1++)
strcat(s," ");
} else
for (i1=0; i1<5; i1++)
strcat(s," ");
strcat(s," ");
strcat(s,"\"");
strcat(s,con[i].password);
strcat(s,"\"\r\n");
write(f,(void *)s,strlen(s));
}
close(f);
}
}
void read_bbs_list()
{
char s[161];
int f,i;
long l,p;
csn=NULL;
cnn=NULL;
con=NULL;
num_sys=0;
num_sys_list=0;
num_call_sys=0;
if (syscfg.systemnumber==0)
return;
sprintf(s,"%sBBSDATA.NET",syscfg.datadir);
f=open(s,O_RDWR | O_BINARY);
if (f>0) {
l=filelength(f);
num_sys_list=(int) (l/sizeof(net_system_list_rec));
if ((csn=malloca(l+512L))==NULL)
end_bbs(noklevel);
for (i=0; i<num_sys_list; i+=256) {
read(f,(void *)&(csn[i]),256*sizeof(net_system_list_rec));
}
close(f);
read_call_out_list();
}
}
void read_bbs_list_index()
{
char s[161];
int f;
long l;
csn=NULL;
cnn=NULL;
con=NULL;
num_sys=0;
num_sys_list=0;
num_call_sys=0;
if (syscfg.systemnumber==0)
return;
sprintf(s,"%sBBSDATA.IND",syscfg.datadir);
f=open(s,O_RDWR | O_BINARY);
if (f>0) {
l=filelength(f);
num_sys_list=(int) (l/2);
if ((csn_index=malloca(l))==NULL)
end_bbs(noklevel);
read(f,(void *)csn_index,l);
close(f);
read_call_out_list();
} else
read_bbs_list();
}
net_system_list_rec *next_system(unsigned int ts)
{
int i,f;
static net_system_list_rec csne;
char s[81];
if (csn) {
for (i=0; i<num_sys_list; i++)
if (csn[i].sysnum==ts) {
if (csn[i].forsys==65535)
return(NULL);
else
return((net_system_list_rec *) &(csn[i]));
}
return(NULL);
} else {
for (i=0; i<num_sys_list; i++)
if (csn_index[i]==ts) {
sprintf(s,"%sBBSDATA.NET",syscfg.datadir);
f=open(s,O_RDONLY | O_BINARY);
lseek(f,sizeof(net_system_list_rec)*((long)i),SEEK_SET);
read(f,&csne,sizeof(net_system_list_rec));
close(f);
if (csne.forsys==65535)
return(NULL);
else
return(&csne);
}
return(NULL);
}
}
void read_contacts()
{
int i,f;
char s[81];
long l;
if (ncn!=NULL)
farfree(ncn);
ncn=NULL;
num_ncn=0;
sprintf(s,"%sCONTACT.NET",syscfg.datadir);
f=open(s,O_RDWR | O_BINARY);
if (f>=0) {
l=filelength(f);
num_ncn=(int) (l/sizeof(net_contact_rec));
if ((ncn=malloca((num_ncn+2)*sizeof(net_contact_rec)))==NULL)
end_bbs(noklevel);
lseek(f,0L,SEEK_SET);
read(f,(void *)ncn,num_ncn*sizeof(net_contact_rec));
close(f);
}
}