home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Devil's Doorknob BBS Capture (1996-2003)
/
devilsdoorknobbbscapture1996-2003.iso
/
Dloads
/
WWIVMODS
/
421-421A.ZIP
/
NETSUP.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-07-18
|
16KB
|
722 lines
/*****************************************************************************
WWIV Version 4
Copyright (C) 1988-1991 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>
#define utoa(s,v,r) ultoa((unsigned long)(s),v,r)
int run_external1_x(char *cl)
{
char s[200];
int i;
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;
long l,l1;
struct ffblk ff;
if ((net_networks[0].sysnum==0) && (net_num_max==1))
return;
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;
ok2=1;
}
sprintf(s,"%sLOCAL.NET",net_data);
if (exist(s)) {
holdphone(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;
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++) {
if (subboards[i].type) {
if (((!net_num) && ((subboards[i].age&0x80) == 0)) ||
((subboards[i].age&0x80) && (subboards[i].name[40]==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) {
npr("Attempting callout to %s @%u\r\n",net_name, 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;
_AH=0x2a;
geninterrupt(0x21);
ch=_AL;
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;
}
}
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;
float fl,fl1,fl2,ffl;
long l,l1;
char ch,s[81],s1[81];
struct time ti;
time(&l);
nl();
prt(2,"Which system? ");
input(s,5);
sn=atoi(s);
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();
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();
ok=ok_to_call(i);
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)
ok=0;
else
if (!ok) {
nl();
prt(5,"Are you sure? ");
if (yn())
ok=1;
}
if (ok) {
if (net_networks[net_num].ncn[i2].bytes_waiting==0L)
if (!(net_networks[net_num].con[i].options & options_sendback))
ok=0;
if (ok) {
do_callout(sn);
}
}
break;
}
}
}
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(" Network data pending transmission:");
nl();
if (net_num_max>1) {
pl(" Network System Bytes Hours");
pl(" ------- ------ ------- -----");
} else {
pl(" System Bytes Hours");
pl(" ------ ------- -----");
}
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 (i=0; i<num_ncn; i++) {
if (ncn[i].bytes_waiting) {
i2=-1;
for (i1=0; i1<num_call_sys; i1++)
if (con[i1].sysnum==ncn[i].systemnumber)
i2=i1;
if (i2!=-1) {
if (ok_to_call(i2))
ch='*';
else
ch=' ';
any=1;
if (ncn[i].lastcontactsent)
ltoa((l-ncn[i].lastcontactsent)/3600,s1,10);
else
strcpy(s1,"-NEVER-");
if (net_num_max>1) {
sprintf(s,"%c%-11s %-5u %7ld %s",
ch,
net_name,
ncn[i].systemnumber,
ncn[i].bytes_waiting,
s1);
} else {
sprintf(s,"%c%-5u %7ld %s",
ch,
ncn[i].systemnumber,
ncn[i].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("--NONE--");
nl();
if (!useron)
pausescr();
}
void set_net_num(int n)
{
if ((n>=0) && (n<net_num_max)) {
net_num=n;
net_name=net_networks[net_num].name;
net_data=net_networks[net_num].dir;
net_sysnum=net_networks[net_num].sysnum;
sprintf(wwiv_net_no,"WWIV_NET=%d",net_num);
}
}