home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Devil's Doorknob BBS Capture (1996-2003)
/
devilsdoorknobbbscapture1996-2003.iso
/
UTIL
/
WWIVE
/
OLDDEV.ARJ
/
UTILITY.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-12-24
|
21KB
|
1,002 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>
#include <math.h>
/* functions for external programs to call */
#pragma warn -par
void far interrupt inlii(unsigned bp, unsigned di, unsigned si,
unsigned ds, unsigned es, unsigned dx,
unsigned cx, unsigned bx, unsigned ax,
unsigned ip, unsigned cs, unsigned flags,
char *s1, char *s2, int i1, int i2)
{
inli(s1,s2,i1,i2);
}
void far interrupt checkai(unsigned bp, unsigned di, unsigned si,
unsigned ds, unsigned es, unsigned dx,
unsigned cx, unsigned bx, unsigned ax,
unsigned ip, unsigned cs, unsigned flags,
int *i1, int *i2)
{
checka(i1,i2);
}
void far interrupt plai(unsigned bp, unsigned di, unsigned si,
unsigned ds, unsigned es, unsigned dx,
unsigned cx, unsigned bx, unsigned ax,
unsigned ip, unsigned cs, unsigned flags,
char *s1, int *i1)
{
pla(s1,i1);
}
void far interrupt outchri(unsigned bp, unsigned di, unsigned si,
unsigned ds, unsigned es, unsigned dx,
unsigned cx, unsigned bx, unsigned ax,
unsigned ip, unsigned cs, unsigned flags,
char ch)
{
outchr(ch);
}
void far interrupt outstri(unsigned bp, unsigned di, unsigned si,
unsigned ds, unsigned es, unsigned dx,
unsigned cx, unsigned bx, unsigned ax,
unsigned ip, unsigned cs, unsigned flags,
char *s1)
{
outstr(s1);
}
void far interrupt nli(unsigned bp, unsigned di, unsigned si,
unsigned ds, unsigned es, unsigned dx,
unsigned cx, unsigned bx, unsigned ax,
unsigned ip, unsigned cs, unsigned flags)
{
nl();
}
void far interrupt pli(unsigned bp, unsigned di, unsigned si,
unsigned ds, unsigned es, unsigned dx,
unsigned cx, unsigned bx, unsigned ax,
unsigned ip, unsigned cs, unsigned flags,
char *s1)
{
pl(s1);
}
void far interrupt emptyi(unsigned bp, unsigned di, unsigned si,
unsigned ds, unsigned es, unsigned dx,
unsigned cx, unsigned bx, unsigned ax,
unsigned ip, unsigned cs, unsigned flags)
{
ax=empty();
}
void far interrupt inkeyi(unsigned bp, unsigned di, unsigned si,
unsigned ds, unsigned es, unsigned dx,
unsigned cx, unsigned bx, unsigned ax,
unsigned ip, unsigned cs, unsigned flags)
{
ax=(unsigned) empty();
}
void far interrupt getkeyi(unsigned bp, unsigned di, unsigned si,
unsigned ds, unsigned es, unsigned dx,
unsigned cx, unsigned bx, unsigned ax,
unsigned ip, unsigned cs, unsigned flags)
{
ax=(unsigned) getkey();
}
void far interrupt inputi(unsigned bp, unsigned di, unsigned si,
unsigned ds, unsigned es, unsigned dx,
unsigned cx, unsigned bx, unsigned ax,
unsigned ip, unsigned cs, unsigned flags,
char *s1, int i)
{
input(s1,i);
}
void far interrupt inputli(unsigned bp, unsigned di, unsigned si,
unsigned ds, unsigned es, unsigned dx,
unsigned cx, unsigned bx, unsigned ax,
unsigned ip, unsigned cs, unsigned flags,
char *s1, int i)
{
inputl(s1,i);
}
void far interrupt yni(unsigned bp, unsigned di, unsigned si,
unsigned ds, unsigned es, unsigned dx,
unsigned cx, unsigned bx, unsigned ax,
unsigned ip, unsigned cs, unsigned flags)
{
ax=yn();
}
void far interrupt nyi(unsigned bp, unsigned di, unsigned si,
unsigned ds, unsigned es, unsigned dx,
unsigned cx, unsigned bx, unsigned ax,
unsigned ip, unsigned cs, unsigned flags)
{
ax=ny();
}
void far interrupt ansici(unsigned bp, unsigned di, unsigned si,
unsigned ds, unsigned es, unsigned dx,
unsigned cx, unsigned bx, unsigned ax,
unsigned ip, unsigned cs, unsigned flags,
int i1)
{
ansic(i1);
}
void far interrupt oneki(unsigned bp, unsigned di, unsigned si,
unsigned ds, unsigned es, unsigned dx,
unsigned cx, unsigned bx, unsigned ax,
unsigned ip, unsigned cs, unsigned flags,
char *s1)
{
ax=(unsigned) onek(s1);
}
void far interrupt prti(unsigned bp, unsigned di, unsigned si,
unsigned ds, unsigned es, unsigned dx,
unsigned cx, unsigned bx, unsigned ax,
unsigned ip, unsigned cs, unsigned flags,
int i1, char *s1)
{
prt(i1,s1);
}
void far interrupt mpli(unsigned bp, unsigned di, unsigned si,
unsigned ds, unsigned es, unsigned dx,
unsigned cx, unsigned bx, unsigned ax,
unsigned ip, unsigned cs, unsigned flags,
int i1)
{
mpl(i1);
}
#pragma warn +par
/* end of functions for external programs to call */
void reset_act_sl()
{
actsl = thisuser.sl;
}
void remove_from_temp(char *fn, char *dir, int po)
{
int i,i1,f1,ok;
char s[81],s1[81];
struct ffblk ff;
uploadsrec u;
sprintf(s1,"%s%s",dir,stripfn(fn));
f1=findfirst(s1,&ff,0);
ok=1;
nl();
while ((f1==0) && (ok)) {
sprintf(s,"%s%s",dir,ff.ff_name);
if (po)
npr("Deleting %s\r\n",ff.ff_name);
_chmod(s,1,0);
unlink(s);
f1=findnext(&ff);
}
}
void check_event()
{
double tl;
if (syscfg.executetime) {
tl=time_event-timer();
if (tl<0.0)
tl += 24.0*3600.0;
if ((tl-last_time)>2.0)
do_event=1;
last_time=tl;
}
}
void run_event()
{
if ((do_event) && (syscfg.executetime)) {
do_event=0;
nl();
pl("Now running external event.");
nl();
if (syscfg.executestr[0]) {
holdphone(1);
shrink_out(syscfg.executestr,0,0,0,1);
/* run_external(syscfg.executestr); */
holdphone(0);
} else
end_bbs(oklevel);
}
clrscrb();
}
double freek(int dr)
{
float d;
struct dfree df;
getdfree(dr,&df);
d=(float) df.df_avail;
d*=((float) df.df_bsec);
d*=((float) df.df_sclus);
d/=1024.0;
if (df.df_sclus<0)
d=-1.0;
return(d);
}
unsigned char years_old(unsigned char m, unsigned char d, unsigned char y)
{
struct date today;
int a;
getdate(&today);
a=(int) (today.da_year-1900-y);
if (today.da_mon<m)
--a;
else
if ((today.da_mon==m) && (today.da_day<d))
--a;
return((unsigned char)a);
}
void itimer()
/* This function initializes the high-resolution timer */
{
outportb(0x43,0x34);
outportb(0x40,0x00);
outportb(0x40,0x00);
}
double timer()
/* This function returns the time, in seconds since midnight. */
{
double cputim;
unsigned short int h,m,l1,l2;
disable();
outportb(0x43,0x00);
m=peek(0x0040,0x006c);
h=peek(0x0040,0x006e);
l1=inportb(0x40);
l2=inportb(0x40);
enable();
l1=((l2*256)+l1) ^ 65535;
cputim=((h*65536. + m)*65536. + l1)*8.380955e-7;
return (cputim);
}
long timer1()
/* This function returns the time, in ticks since midnight. */
{
unsigned short h,m;
long l;
m=peek(0x0040,0x006c);
h=peek(0x0040,0x006e);
l=((long)h)*65536 + ((long)m);
return(l);
}
int sysop1()
/* This function returns the status of scoll lock. If scroll lock is active
* (ie, the user has hit scroll lock + the light is lit if there is a
* scoll lock LED), the sysop is assumed to be available.
*/
{
if ((peekb(0,1047) & 0x10)==0)
return(0);
else
return(1);
}
int okansi()
/* This function checks the status of the current user's record to see if
* the user has specified that he wants ANSI graphics displayed.
*/
{
if (thisuser.sysstatus & sysstatus_ansi)
return(1);
else
return(0);
}
void frequent_init()
/* This should be called after a user is logged off, and will initialize
* screen-access variables.
*/
{
curlsub=-1;
ansiptr=0;
curatr=0x07;
outcom=0;
incom=0;
charbufferpointer=0;
andwith=0xff;
checkit=0;
topline=0;
screenlinest=defscreenbottom+1;
if (!restoring_shrink)
clrscrb();
endofline[0]=0;
hangup=0;
hungup=0;
chatcall=0;
chatreason[0]=0;
useron=0;
change_color=0;
chatting=0;
echo=1;
irt[0]=0;
irt_name[0]=0;
okskey=0;
lines_listed=0;
read_user(1,&thisuser);
if (thisuser.inact & inact_deleted)
fwaiting=0;
else
fwaiting=thisuser.waiting;
okmacro=1;
okskey=1;
helpl=0;
ihelp=0;
mailcheck=0;
smwcheck=0;
in_extern=0;
gatfn[0]=0;
use_workspace=0;
extratimecall=0.0;
two_color=0;
using_modem=0;
set_global_handle(0);
live_user=1;
_chmod(dszlog,1,0);
unlink(dszlog);
}
void read_in_file(char *fn, messagerec *m, int maxary)
{
int i,i1,i2;
char *buf,s[81];
long l,l1;
for (i=0; i<maxary; i++) {
m[i].stored_as=0L;
m[i].storage_type=255;
}
sprintf(s,"%s%s",syscfg.gfilesdir,fn);
i=open(s,O_RDWR | O_BINARY);
if (i<0) {
printf("%s NOT FOUND.\n",s);
end_bbs(noklevel);
}
l=filelength(i);
buf=(char *) farmalloc(l);
lseek(i,0L,SEEK_SET);
if (buf==NULL) {
printf("NOT ENOUGH MEMORY.\n");
end_bbs(noklevel);
}
read(i,(void *) buf,l);
close(i);
i1=0;
for (l1=0; l1<l; l1++) {
if (buf[l1]=='`') {
i1=1;
i2=0;
} else
if (i1) {
if ((buf[l1]>='0') && (buf[l1]<='9')) {
i2*=10;
i2+=(buf[l1])-'0';
} else {
while ((l1<l) && (buf[l1]!=10))
++l1;
++l1;
if ((i2>=0) && (i2<maxary))
m[i2].stored_as=l1;
i1=0;
}
}
}
farfree((void *) buf);
}
void far *mallocx(unsigned long l)
{
void *x;
x=farmalloc(l);
if (!x) {
printf("NOT ENOUGH MEMORY.\n");
end_bbs(noklevel);
}
return(x);
}
void fix_user_rec(userrec *u)
{
u->name[30]=0;
u->realname[20]=0;
u->callsign[6]=0;
u->phone[12]=0;
u->pw[8]=0;
u->laston[8]=0;
u->note[40]=0;
u->macros[0][80]=0;
u->macros[1][80]=0;
u->macros[2][80]=0;
}
void close_user()
{
if (userfile!=-1) {
close(userfile);
userfile=-1;
}
}
void open_user()
{
char s[81];
if (userfile==-1) {
sprintf(s,"%sUSER.LST",syscfg.datadir);
userfile=open(s,O_RDWR | O_BINARY);
if (userfile<0) {
userfile=-1;
}
}
}
int number_userrecs()
{
open_user();
return((int) (filelength(userfile)/syscfg.userreclen)-1);
}
void read_user(unsigned int un, userrec *u)
{
long pos;
char s[80];
int i;
open_user();
if ((userfile<0) || (un>number_userrecs())) {
u->inact=inact_deleted;
fix_user_rec(u);
return;
}
if (((useron) && (un==usernum)) || ((wfc) && (un==1))) {
*u=thisuser;
fix_user_rec(u);
return;
}
pos=((long) syscfg.userreclen) * ((long) un);
lseek(userfile,pos,SEEK_SET);
i=read(userfile, (void *)u, syscfg.userreclen);
if (i==-1) {
open_user();
if ((userfile<0) || (un>number_userrecs())) {
u->inact=inact_deleted;
fix_user_rec(u);
return;
}
pos=((long) syscfg.userreclen) * ((long) un);
lseek(userfile,pos,SEEK_SET);
i=read(userfile, (void *)u, syscfg.userreclen);
if (i==-1) {
pl("COULDN'T READ USER.");
}
close_user();
}
fix_user_rec(u);
}
void write_user(unsigned int un, userrec *u)
{
long pos;
char s[80];
unsigned char oldsl;
int i;
if (userfile==-1) {
sprintf(s,"%sUSER.LST",syscfg.datadir);
userfile=open(s,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
}
if (((useron) && (un==usernum)) || ((wfc) && (un==1))) {
thisuser=*u;
}
pos=((long) syscfg.userreclen) * ((long) un);
lseek(userfile,pos,SEEK_SET);
i=write(userfile, (void *)u, syscfg.userreclen);
if (i==-1) {
sprintf(s,"%sUSER.LST",syscfg.datadir);
userfile=open(s,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
pos=((long) syscfg.userreclen) * ((long) un);
lseek(userfile,pos,SEEK_SET);
i=write(userfile, (void *)u, syscfg.userreclen);
if (i==-1) {
pl("COULDN'T WRITE USER.");
}
close_user();
}
}
void save_status()
{
char s[80];
sprintf(s,"%sSTATUS.DAT",syscfg.datadir);
statusfile=open(s,O_RDWR | O_BINARY);
write(statusfile, (void *)(&status), sizeof(statusrec));
close(statusfile);
statusfile=-1;
}
double ratio()
{
double r;
if (thisuser.dk==0)
return(99.999);
r=((float) thisuser.uk) / ((float) thisuser.dk);
if (r>99.998)
r=99.998;
return(r);
}
double post_ratio()
{
double r;
if (thisuser.logons==0)
return(99.999);
r=((float) thisuser.msgpost) / ((float) thisuser.logons);
if (r>99.998)
r=99.998;
return(r);
}
char *nam(userrec *u1, unsigned int un)
{
static char o[81];
int i,f,p;
userrec u;
u=*u1;
f=1;
for (p=0; p<strlen(u.name); p++) {
if (f) {
if ((u.name[p]>='A') && (u.name[p]<='Z'))
f=0;
o[p]=u.name[p];
} else {
if ((u.name[p]>='A') && (u.name[p]<='Z'))
o[p]=u.name[p]-'A'+'a';
else {
if ((u.name[p]>=' ') && (u.name[p]<='/'))
f=1;
o[p]=u.name[p];
}
}
}
o[p++]=32;
o[p++]='#';
itoa(un,&o[p],10);
return(o);
}
char *nam1(userrec *u1, unsigned int un, unsigned int sy)
{
static char o[81];
char s[10];
strcpy(o,nam(u1,un));
if (sy) {
sprintf(s," @%u",sy);
strcat(o,s);
}
return(o);
}
double nsl()
{
double tlt,tlc,tot,tpl,tpd,dd,rtn;
slrec xx;
dd=timer();
if (useron) {
if (timeon>dd)
timeon -= 24.0*3600.0;
tot=(dd-timeon);
xx=syscfg.sl[actsl];
tpl=((double) xx.time_per_logon) * 60.0;
tpd=((double) xx.time_per_day) * 60.0;
tlc = tpl - tot + (thisuser.extratime) + extratimecall;
tlt = tpd - tot - ((double) thisuser.timeontoday) + (thisuser.extratime);
tlt=(((tlc)<(tlt)) ? (tlc) : (tlt));
if (tlt<0.0)
tlt=0.0;
if (tlt>32767.0)
tlt=32767.0;
rtn=tlt;
} else {
rtn=1.00;
}
if (syscfg.executetime) {
tlt=time_event-dd;
if (tlt<0.0)
tlt += 24.0*3600.0;
if (rtn>tlt)
rtn=tlt;
check_event();
if (do_event)
rtn=0.0;
}
if (rtn<0.0)
rtn=0.0;
if (rtn>32767.0)
rtn=32767.0;
return(rtn);
}
char *date()
{
static char ds[9];
struct date today;
getdate(&today);
sprintf(ds,"%02d/%02d/%02d",today.da_mon,today.da_day,today.da_year-1900);
return(ds);
}
char *times()
{
static char ti[9];
int h,m,s;
double t;
t=timer();
h=(int) (t/3600.0);
t-=((double) (h)) * 3600.0;
m=(int) (t/60.0);
t-=((double) (m)) * 60.0;
s=(int) (t);
sprintf(ti,"%02d:%02d:%02d",h,m,s);
return(ti);
}
unsigned int finduser(char *s)
{
int un;
smalrec *sr;
userrec u;
char *ss;
if (strcmp(s,"NEW")==0)
return(-1);
if (strcmp(s,"!-@NETWORK@-!")==0)
return(-2);
if (strcmp(s,"!-@REMOTE@-!")==0)
return(-3);
if (strncmp(s,"!=@",3)==0) {
ss=s+strlen(s)-3;
if (strcmp(ss,"@=!")==0) {
strcpy(s,s+3);
s[strlen(s)-3]=0;
return(-4);
}
}
if ((un=atoi(s))>0) {
if (un>number_userrecs())
return(0);
read_user(un,&u);
if (u.inact & inact_deleted)
return(0);
return(un);
}
sr=(smalrec *) bsearch((void *)s,
(void *)smallist,
(size_t)status.users,
(size_t)sizeof(smalrec),
(int _Cdecl (*) (const void *, const void *))strcmp);
if (sr==0L)
return(0);
else {
read_user(sr->number,&u);
if (u.inact & inact_deleted)
return(0);
else
return(sr -> number);
}
}
void changedsl()
{
int i,i1,i2,i3,i4,ok,dp,ddp;
subboardrec s;
directoryrec d;
usersubrec s1;
topscreen();
dp=0;
dc[dp++]='/';
ddp=0;
dcd[ddp++]='/';
for (i=0; i<3; i++) {
s1.keys[i]=0;
}
s1.subnum=-1;
for (i=0; i<MAX_SUBS; i++)
usub[i]=s1;
for (i=0; i<MAX_DIRS; i++)
udir[i]=s1;
i1=1;
i2=0;
i3=0;
for (i=0; i<num_subs; i++) {
ok=1;
s=subboards[i];
if (actsl<s.readsl)
ok=0;
if (thisuser.age<s.age)
ok=0;
if ((s.ar!=0) && (((thisuser.ar) & (s.ar))==0))
ok=0;
if ((s.anony & anony_ansi_only) && (!okansi()))
ok=0;
if (ok) {
s1.subnum=i;
if (s.key!=0) {
s1.keys[0]=s.key;
s1.keys[1]=0;
s1.subnum=i;
usub[i3++]=s1;
} else {
if ((i1 % 10)==0)
dc[dp++]=('0'+(i1/10));
itoa(i1++,s1.keys,10);
s1.subnum=i;
for (i4=i3; i4>i2; i4--)
usub[i4]=usub[i4-1];
i3++;
usub[i2++]=s1;
}
}
}
i1=1;
i2=0;
for (i=0; i<num_dirs; i++) {
ok=1;
d=directories[i];
if (thisuser.dsl<d.dsl)
ok=0;
if (thisuser.age<d.age)
ok=0;
if (d.dar)
if ((d.dar & thisuser.dar)==0)
ok=0;
if (ok) {
s1.subnum=i;
if (i==0)
strcpy(s1.keys,"0");
else {
if ((i1 % 10)==0)
dcd[ddp++]=('0'+(i1/10));
itoa(i1++,s1.keys,10);
}
udir[i2++]=s1;
}
}
dcd[ddp]=0;
dc[dp]=0;
}
void isr(int un, char *name)
{
int cp,i;
char s[81];
smalrec sr;
cp=0;
while ((cp<status.users) && (strcmp(name,(smallist[cp].name))>0))
++cp;
memmove(&(smallist[cp+1]),&(smallist[cp]),sizeof(smalrec)*(status.users-cp));
strcpy(sr.name,name);
sr.number=un;
smallist[cp]=sr;
sprintf(s,"%sNAMES.LST",syscfg.datadir);
i=open(s,O_RDWR | O_BINARY | O_TRUNC);
if (i<0) {
printf("%s NOT FOUND.\n",s);
end_bbs(noklevel);
}
++status.users;
save_status();
write(i,(void *) (smallist), (sizeof(smalrec) * status.users));
close(i);
}
void dsr(char *name)
{
int cp,i;
char s[81];
smalrec sr;
cp=0;
while ((cp<status.users) && (strcmp(name,(smallist[cp].name))!=0))
++cp;
if (strcmp(name,(smallist[cp].name))) {
sprintf(s,"%s NOT ABLE TO BE DELETED#*#*#*#*#*#*#*#",name);
sl1(0,s);
sl1(0,"#*#*#*# Run //resetf to fix it");
return;
}
memmove(&(smallist[cp]),&(smallist[cp+1]),sizeof(smalrec)*(status.users-cp));
sprintf(s,"%sNAMES.LST",syscfg.datadir);
i=open(s,O_RDWR | O_BINARY | O_TRUNC | O_CREAT, S_IREAD | S_IWRITE);
if (i<0) {
printf("%s COULDN'T BE CREATED.\n",s);
end_bbs(noklevel);
}
--status.users;
save_status();
write(i,(void *) (smallist), (sizeof(smalrec) * status.users));
close(i);
}
void wait(double d)
{
long l1;
l1=((long) (18.2*d));
l1 += timer1();
enable();
while (timer1()<l1)
;
}
void wait1(long l)
{
long l1;
l1 = timer1()+l;
enable();
while (timer1()<l1)
;
}
double freek1(char *s)
{
int d;
d=cdir[0];
if (s[1]==':')
d=s[0];
d=d-'A'+1;
return(freek(d));
}
int exist(char *s)
{
int f;
f=open(s,O_RDONLY | O_BINARY);
close(f);
if (f>0)
return(1);
else
return(0);
}
void add_ass(int i, char *ss)
{
char s[81],s1[10];
strcpy(s,"*** ");
sysoplog(s);
strcat(s,ss);
sysoplog(s);
itoa(i,s1,10);
strcpy(s,"*** ASS-PTS: ");
strcat(s,s1);
sysoplog(s);
thisuser.ass_pts += i;
}