home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Devil's Doorknob BBS Capture (1996-2003)
/
devilsdoorknobbbscapture1996-2003.iso
/
WWIV2.ZIP
/
NETSUP.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-12-03
|
20KB
|
897 lines
/*****************************************************************************
WWIV Version 4
Copyright (C) 1988-1993 by Wayne Bell
Distribution of the source code for WWIV, in any form, modified or unmodified,
without PRIOR, WRITTEN APPROVAL by the author, is expressly prohibited.
Distribution of compiled versions of WWIV is limited to copies compiled BY
THE AUTHOR. Distribution of any copies of WWIV not compiled by the author
is expressly prohibited.
*****************************************************************************/
#include "vars.h"
#pragma hdrstop
#include <dir.h>
#include "subxtr.h"
#define utoa(s,v,r) ultoa((unsigned long)(s),v,r)
int run_external1_x(char *cl)
{
char s[200];
int i;
unlink("WWIV_NET.DAT");
sprintf(s,"%s%s",net_data,cl);
i=run_external1(s);
if (i<0)
i=run_external1(cl);
return(i);
}
void shrink_out_x(char *cl)
{
char s[200];
int i;
sprintf(s,"%d\r\n",net_num);
i=open("WWIV_NET.DAT",O_RDWR|O_BINARY|O_TRUNC|O_CREAT, S_IREAD|S_IWRITE);
if (i>0) {
write(i,s,strlen(s));
close(i);
}
sprintf(s,"%s%s",net_data,cl);
shrink_out(s,0,0,0,0);
shrink_out(cl,0,0,0,0);
unlink("WWIV_NET.DAT");
}
void checkup(struct ftime *f1, struct ftime *f2, int *tf)
{
if ((f1->ft_year)>(f2->ft_year))
*tf=1;
else
if (f1->ft_year==f2->ft_year)
if (f1->ft_month>f2->ft_month)
*tf=1;
else
if (f1->ft_month==f2->ft_month)
if (f1->ft_day>f2->ft_day)
*tf=1;
else
if (f1->ft_day==f2->ft_day)
if (f1->ft_hour>f2->ft_hour)
*tf=1;
else
if (f1->ft_hour==f2->ft_hour)
if (f1->ft_min>f2->ft_min)
*tf=1;
else
if (f1->ft_min==f2->ft_min)
if (f1->ft_tsec>f2->ft_tsec)
*tf=1;
}
int checkup2(struct ftime *f, char *x)
{
int q;
char s[81];
struct ftime f2;
sprintf(s,"%s%s",net_data,x);
q=open(s,O_RDONLY);
if (q>0) {
getftime(q,&f2);
close(q);
q=0;
checkup(&f2,f,&q);
} else
q=1;
return(q);
}
int check_bbsdata(void)
{
char s[81];
int ok,ok2;
struct ftime ft;
sprintf(s,"%sCONNECT.UPD",net_data);
if ((ok=exist(s))==0) {
sprintf(s,"%sBBSLIST.UPD",net_data);
ok=exist(s);
}
if (ok && status.net_edit_stuff) {
holdphone(1);
run_external1_x("NETEDIT /U");
} else {
sprintf(s,"%sBBSDATA.NET",net_data);
ok=open(s,O_RDONLY);
if (ok>0) {
getftime(ok,&ft);
close(ok);
ok=checkup2(&ft,"BBSLIST.NET")||checkup2(&ft,"CONNECT.NET");
ok2=checkup2(&ft,"CALLOUT.NET");
} else
ok=ok2=1;
}
sprintf(s,"%sBBSLIST.NET",net_data);
if (!exist(s))
ok=ok2=0;
sprintf(s,"%sCONNECT.NET",net_data);
if (!exist(s))
ok=ok2=0;
sprintf(s,"%sCALLOUT.NET",net_data);
if (!exist(s))
ok=ok2=0;
if (ok||ok2) {
sprintf(s,"NETWORK3%s",(ok?" Y":""));
holdphone(1);
#ifdef OLD_WAY
ok=run_external1_x(s);
#else
shrink_out_x(s);
ok=0;
#endif
zap_call_out_list();
zap_contacts();
zap_bbs_list();
if (ok>=0)
return(1);
}
return(0);
}
void cleanup_net(void)
{
char s[81],s1[81];
int ok,ok2,abort,f,i,nn,any,i1;
long l,l1;
struct ffblk ff;
if ((net_networks[0].sysnum==0) && (net_num_max==1))
return;
any=1;
while (any) {
any=0;
for (nn=0; nn<net_num_max; nn++) {
set_net_num(nn);
if (!net_sysnum)
continue;
set_protect(0);
clrscrb();
ok2=1;
abort=0;
while ((ok2) && (!abort)) {
ok2=0;
ok=0;
sprintf(s,"%sP*.NET",net_data);
ok=(findfirst(s,&ff,0)==0);
if (ok) {
holdphone(1);
hangup=0;
using_modem=0;
if (run_external1_x("NETWORK1")<0)
abort=1;
else
any=1;
ok2=1;
}
sprintf(s,"%sLOCAL.NET",net_data);
if (exist(s)) {
holdphone(1);
any=1;
ok=1;
hangup=0;
using_modem=0;
save_status();
close_user();
sprintf(s,"%sNETUP.XXX",net_data);
if (exist(s))
shrink_out_x("NETWORK2");
else {
if (run_external1_x("NETWORK2")<0)
abort=1;
else
any=1;
}
ok2=1;
l1=status.qscanptr;
get_status();
if (l1!=status.qscanptr) {
/* a sub has probably been updated; invalidate sub cache */
for (i=0; i<num_subs; i++) {
for (i1=0; i1<xsubs[i].num_nets; i1++) {
if (xsubs[i].nets[i1].net_num==net_num)
sub_dates[i]=0L;
}
}
c_sub=0;
}
curlsub=-1;
if (wfc) {
wfc=0;
read_user(1,&thisuser);
fwaiting=thisuser.waiting;
wfc=1;
}
}
if (check_bbsdata())
ok2=1;
if (ok2) {
clrscrb();
zap_contacts();
}
}
}
}
holdphone(0);
}
void do_callout(int sn)
{
int i,i1,i2;
char s[81],s1[81];
float ffl;
long l;
net_system_list_rec *csne;
time(&l);
i=-1;
if (!net_networks[net_num].con)
read_call_out_list();
for (i1=0; i1<net_networks[net_num].num_con; i1++)
if (net_networks[net_num].con[i1].sysnum==sn)
i=i1;
if (i!=-1) {
csne=next_system(net_networks[net_num].con[i].sysnum);
if (csne) {
sprintf(s,"NETWORK /N%u /A%s /P%s /S%u /T%ld",
sn,
(net_networks[net_num].con[i].options & options_sendback)?"1":"0",
csne->phone,
modem_i->defl.com_speed,
l);
if (net_networks[net_num].con[i].macnum) {
sprintf(s1," /M%d",(int) net_networks[net_num].con[i].macnum);
strcat(s,s1);
}
if (strncmp(csne->phone,"000",3)) {
if (net_num_max>1) {
outstr(get_string(910));
outstr(net_name);
npr(" @%u\r\n",sn);
}
pl(s);
save_status();
holdphone(1);
wait(2.5);
run_external1_x(s);
zap_contacts();
get_status();
last_time_c=l;
global_xx=0;
cleanup_net();
holdphone(0);
imodem(0);
}
}
}
}
int ok_to_call(int i)
{
int ok;
struct time ti;
char ch,h,l;
net_call_out_rec *con;
con=&(net_networks[net_num].con[i]);
ok=((con->options & options_no_call)==0);
if (con->options & options_receive_only)
ok=0;
ch=dow();
gettime(&ti);
if (con->options & options_ATT_night) {
if ((ch!=0) && (ch!=6)) {
if ((ti.ti_hour<23) && (ti.ti_hour>=7))
ok=0;
}
if (ch==0) {
if ((ti.ti_hour<23) && (ti.ti_hour>=16))
ok=0;
}
}
if (con->options & options_PCP_night) {
if ((ch!=0) && (ch!=6)) {
if ((ti.ti_hour<18) && (ti.ti_hour>=7))
ok=0;
if ((ti.ti_hour==6) && (ti.ti_min>30))
ok=0;
}
}
l=con->min_hr;
h=con->max_hr;
if ((l>-1) && (h>-1) && (h!=l)) {
if ((h==0) || (h==24)) {
if (ti.ti_hour<l)
ok=0;
else
if ((ti.ti_hour==l) && (ti.ti_min<12))
ok=0;
else
if ((ti.ti_hour==23) && (ti.ti_min>30))
ok=0;
} else
if ((l==0) || (l==24)) {
if (ti.ti_hour>=h)
ok=0;
else
if ((ti.ti_hour==h-1) && (ti.ti_min>30))
ok=0;
else
if ((ti.ti_hour==0) && (ti.ti_min<12))
ok=0;
} else
if (h>l) {
if ((ti.ti_hour<l) || (ti.ti_hour>=h))
ok=0;
else
if ((ti.ti_hour==l) && (ti.ti_min<12))
ok=0;
else
if ((ti.ti_hour==h-1) && (ti.ti_min>30))
ok=0;
} else {
if ((ti.ti_hour>=h) && (ti.ti_hour<l))
ok=0;
else
if ((ti.ti_hour==l) && (ti.ti_min<12))
ok=0;
else
if ((ti.ti_hour==h-1) && (ti.ti_min>30))
ok=0;
}
}
return(ok);
}
#define WEIGHT 30.0
void fixup_long(long *f, long l)
{
if (*f>l)
*f=l;
if (*f+(86400L*30L)<l)
*f=l-86400L*30L;
}
void attempt_callout(void)
{
int **try,i,i1,i2,i3,ok,net_only,nn, num_call_sys, num_ncn,any;
float **weight,fl,fl1,fl2,ffl;
long l,l1;
char ch,s[81],s1[81];
struct time ti;
net_call_out_rec *con;
net_contact_rec *ncn;
net_only=1;
if (syscfg.netlowtime!= syscfg.nethightime) {
if (syscfg.nethightime>syscfg.netlowtime) {
if ((timer()<=(syscfg.netlowtime*60.0)) || (timer()>=(syscfg.nethightime*60.0)))
net_only=0;
} else {
if ((timer()<=(syscfg.netlowtime*60.0)) && (timer()>=(syscfg.nethightime*60.0)))
net_only=0;
}
} else
net_only=0;
time(&l);
if (last_time_c>l)
last_time_c=0L;
if (labs(last_time_c-l)<120)
return;
if (last_time_c==0L) {
last_time_c=l;
return;
}
if ((try=(int **)malloca(sizeof(int *) * net_num_max))==NULL)
return;
if ((weight=(float **)malloca(sizeof(float *) * net_num_max))==NULL) {
farfree(try);
return;
}
memset(try, 0, sizeof(int *) * net_num_max);
memset(weight, 0, sizeof(float *) * net_num_max);
fl2=0.0;
any=0;
for (nn=0; nn<net_num_max; nn++) {
set_net_num(nn);
if (!net_sysnum)
continue;
if (!net_networks[net_num].con)
read_call_out_list();
if (!net_networks[net_num].ncn)
read_contacts();
con=net_networks[net_num].con;
ncn=net_networks[net_num].ncn;
num_call_sys=net_networks[net_num].num_con;
num_ncn=net_networks[net_num].num_ncn;
try[nn]=(int *)malloca(sizeof(int)*num_call_sys);
if (!try[nn])
break;
weight[nn]=(float *)malloca(sizeof(float)*num_call_sys);
if (!weight[nn])
break;
for (i=0; i<num_call_sys; i++) {
try[nn][i]=0;
ok=ok_to_call(i);
i2=-1;
for (i1=0; i1<num_ncn; i1++)
if (ncn[i1].systemnumber==con[i].sysnum)
i2=i1;
if ((ok) && (i2!=-1)) {
if (ncn[i2].bytes_waiting==0L)
if (con[i].call_anyway) {
l1=(l-ncn[i2].lastcontact+60*3)/3600/24;
if (((unsigned char)l1 < con[i].call_anyway) ||
((con[i].options & options_sendback)==0))
if (!net_only)
ok=0;
} else
ok=0;
if (con[i].options & options_once_per_day) {
if (labs(l-ncn[i2].lastcontactsent)<(20L*3600L/con[i].times_per_day))
ok=0;
}
fixup_long((long *)&(ncn[i2].lastcontactsent),l);
fixup_long((long *)&(ncn[i2].lasttry),l);
if (ok) {
if (ncn[i2].bytes_waiting==0L)
fl=5.0*WEIGHT;
else
fl=1024.0/((float)ncn[i2].bytes_waiting)*WEIGHT*60.0;
fl1=(float) (l-ncn[i2].lasttry);
if ((fl<fl1) || (net_only)) {
try[nn][i]=1;
fl1=fl1/fl;
if (fl1<1.0)
fl1=1.0;
if (fl1>5.0)
fl1=5.0;
weight[nn][i]=fl1;
fl2 += fl1;
any++;
}
}
}
}
}
if (any) {
fl=fl2*((float)rand())/32767.0;
fl1=0.0;
for (nn=0; nn<net_num_max; nn++) {
set_net_num(nn);
if (!net_sysnum)
continue;
i1=-1;
for (i=0; (i<net_networks[net_num].num_con); i++) {
if (try[nn][i]) {
fl1 += weight[nn][i];
if (fl1>=fl) {
i1=i;
break;
}
}
}
if (i1!=-1) {
do_callout(net_networks[net_num].con[i1].sysnum);
time(&l);
last_time_c=l;
break;
}
}
}
for (nn=0; nn<net_num_max; nn++) {
if (try[nn])
farfree(try[nn]);
if (weight[nn])
farfree(weight[nn]);
}
farfree(try);
farfree(weight);
set_net_num(0);
}
void force_callout(void)
{
int i,i1,i2,i3,index,ok,sn,nn,onxi, odci,nv,nitu;
float fl,fl1,fl2,ffl;
long l,l1;
char ch,s[81],s1[81], onx[20],*ss,*ss1,*ss2,*mmk;
struct time ti;
net_system_list_rec *csne;
time(&l);
nl();
prt(2,get_string(911));
input(s,5);
sn=atoi(s);
odc[0]=0;
odci=0;
onx[0]='Q';
onx[1]=0;
onxi=1;
nv=0;
ss=malloc(net_num_max*3);
ss1=ss+net_num_max;
ss2=ss1+net_num_max;
for (nn=0; nn<net_num_max; nn++) {
set_net_num(nn);
if ((!net_sysnum) || (net_sysnum==sn))
continue;
if (!net_networks[net_num].con)
read_call_out_list();
i=-1;
for (i1=0; i1<net_networks[net_num].num_con; i1++) {
if (net_networks[net_num].con[i1].sysnum == sn) {
i=i1;
break;
}
}
if (i!=-1) {
if (!net_networks[net_num].ncn)
read_contacts();
i2=-1;
for (i1=0; i1<net_networks[net_num].num_ncn; i1++) {
if (net_networks[net_num].ncn[i1].systemnumber==sn) {
i2=i1;
break;
}
}
if (i2!=-1) {
ss[nv]=nn;
ss1[nv]=i;
ss2[nv++]=i2;
}
}
}
nitu=-1;
if (nv) {
if (nv==1)
nitu=0;
else {
nl();
for (i=0; i<nv; i++) {
set_net_num(ss[i]);
csne=next_system(sn);
if (csne) {
if (i<9) {
onx[onxi++]=i+'1';
onx[onxi]=0;
} else {
odci=(i+1)/10;
odc[odci-1]=odci+'0';
odc[odci]=0;
}
npr("%d. %s (%s)\r\n",i+1,net_name, csne->name);
}
}
pl(get_string(12));
nl();
prt(2,get_string(13));
if (nv<9) {
ch=onek(onx);
if (ch!='Q')
nitu=ch-'1';
} else {
mmk=mmkey(2);
if (*mmk!='Q')
nitu=atoi(mmk)-1;
}
}
}
if (nitu!=-1) {
set_net_num(ss[nitu]);
ok=ok_to_call(ss1[nitu]);
if (!ok) {
nl();
prt(5,get_string(465));
if (yn())
ok=1;
}
if (ok) {
if (net_networks[net_num].ncn[ss2[nitu]].bytes_waiting==0L)
if (!(net_networks[net_num].con[ss1[nitu]].options & options_sendback))
ok=0;
if (ok) {
do_callout(sn);
}
}
}
farfree(ss);
}
void print_pending_list(void)
{
int i,any=0,i1,i2,nn,num_ncn, num_call_sys;
char s[81],ch,s1[81];
long l;
net_call_out_rec *con;
net_contact_rec *ncn;
if ((net_networks[0].sysnum==0) && (net_num_max==1))
return;
time(&l);
nl();
nl();
pl(get_string(912));
nl();
if (net_num_max>1) {
pl(get_string(913));
pl(get_string(914));
} else {
pl(get_string(915));
pl(get_string(916));
}
for (nn=0; nn<net_num_max; nn++) {
set_net_num(nn);
if (!net_sysnum)
continue;
if (!net_networks[net_num].con)
read_call_out_list();
if (!net_networks[net_num].ncn)
read_contacts();
con=net_networks[net_num].con;
ncn=net_networks[net_num].ncn;
num_call_sys=net_networks[net_num].num_con;
num_ncn=net_networks[net_num].num_ncn;
for (i1=0; i1<num_call_sys; i1++) {
i2=-1;
for (i=0; i<num_ncn; i++) {
if (con[i1].sysnum==ncn[i].systemnumber) {
i2=i;
break;
}
}
if ((i2!=-1) && (ncn[i2].bytes_waiting)) {
if (ok_to_call(i1))
ch='*';
else
ch=' ';
any=1;
if (ncn[i2].lastcontactsent)
ltoa((l-ncn[i2].lastcontactsent)/3600,s1,10);
else
strcpy(s1,get_string(917));
if (net_num_max>1) {
sprintf(s,"%c%-11s %-5u %7ld %s",
ch,
net_name,
ncn[i2].systemnumber,
ncn[i2].bytes_waiting,
s1);
} else {
sprintf(s,"%c%-5u %7ld %s",
ch,
ncn[i2].systemnumber,
ncn[i2].bytes_waiting,
s1);
}
pl(s);
}
}
}
for (nn=0; nn<net_num_max; nn++) {
set_net_num(nn);
if (!net_sysnum)
continue;
sprintf(s,"%sDEAD.NET",net_data);
i=open(s,O_RDONLY | O_BINARY);
if (i>0) {
l=filelength(i);
any=1;
close(i);
if (net_num_max>1) {
sprintf(s," %-11s DEAD %7ld", net_name, l);
} else {
sprintf(s," DEAD %7ld", l);
}
pl(s);
}
}
if (!any)
pl(get_string(918));
nl();
if (!useron)
pausescr();
}
/****************************************************************************/
void gate_msg(net_header_rec *nh, char *text, unsigned short nn, char *byname, unsigned int *list, unsigned short fnn)
{
char newname[128], fn[100], qn[100], on[100];
char *ti, nm[82], *ss;
int f,i;
unsigned short ntl;
if (strlen(text)<80) {
ti=text;
text+=strlen(ti)+1;
ntl=nh->length-strlen(ti)-1;
ss=strchr(text,'\r');
if (ss && (ss-text<80) && (ss-text<ntl)) {
strncpy(nm,text,ss-text);
nm[ss-text]=0;
ss++;
if (*ss=='\n')
ss++;
nh->length-=(ss-text);
ntl-=(ss-text);
text=ss;
qn[0]=on[0]=0;
if (fnn==65535) {
strcpy(newname,nm);
ss=strrchr(newname,'@');
if (ss) {
sprintf(ss+1,"%u",net_networks[nn].sysnum);
ss=strrchr(nm,'@');
if (ss) {
++ss;
while ((*ss>='0') && (*ss<='9'))
++ss;
strcat(newname,ss);
}
strcat(newname,"\r\n");
}
} else {
if ((nm[0]=='`') && (nm[1]=='`')) {
for (i=strlen(nm)-2; i>0; i--) {
if ((nm[i]=='`') && (nm[i+1]=='`')) {
break;
}
}
if (i>0) {
i+=2;
strncpy(qn,nm,i);
qn[i]=' ';
qn[i+1]=0;
}
} else
i=0;
if (qn[0]==0) {
ss=strrchr(nm,'#');
if (ss) {
if ((ss[1]>='0') && (ss[1]<='9')) {
*ss=0;
ss--;
while ((ss>nm) && (*ss==' ')) {
*ss=0;
ss--;
}
}
}
if (nm[0]) {
if (nh->fromuser)
sprintf(qn,"``%s`` ",nm);
else
strcpy(on,nm);
}
}
if ((on[0]==0) && (nh->fromuser==0)) {
strcpy(on,nm+i);
}
if (on[0])
sprintf(newname,"%s%s %s AT %u\r\n",qn, net_networks[fnn].name,
on, nh->fromsys);
else
sprintf(newname,"%s%s #%u AT %u\r\n",qn, net_networks[fnn].name,
nh->fromuser, nh->fromsys);
nh->fromsys=net_networks[nn].sysnum;
nh->fromuser=0;
}
nh->length += strlen(newname);
if ((nh->main_type == main_type_email_name) ||
(nh->main_type == main_type_new_post))
nh->length += strlen(byname)+1;
sprintf(fn,"%sPGATE.NET",net_networks[nn].dir);
f=open(fn,O_RDWR|O_BINARY|O_CREAT, S_IREAD|S_IWRITE);
if (f) {
lseek(f,0L,SEEK_END);
if (!list)
nh->list_len=0;
if (nh->list_len)
nh->tosys=0;
write(f,nh, sizeof(net_header_rec));
if (nh->list_len)
write(f,list,2*(nh->list_len));
if ((nh->main_type == main_type_email_name) ||
(nh->main_type == main_type_new_post))
write(f,byname, strlen(byname)+1);
write(f,ti,strlen(ti)+1);
write(f,newname,strlen(newname));
write(f,text,ntl);
close(f);
}
}
}
}