home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Devil's Doorknob BBS Capture (1996-2003)
/
devilsdoorknobbbscapture1996-2003.iso
/
WWIV2.ZIP
/
BBSUTL1.C
< prev
next >
Wrap
Text File
|
1995-12-11
|
8KB
|
364 lines
#include "vars.h"
#pragma hdrstop
int ok_local(void)
{
if (syscfg.sysconfig& sysconfig_no_local)
return(0);
else
return(1);
}
int finduser1(char *sx)
{
int i,i1,i2;
char s[81],s1[81],ch;
userrec u;
if (sx[0]==0)
return(0);
i=finduser(sx);
if (i>0)
return(i);
strcpy(s,sx);
for (i=0; s[i]!=0; i++)
s[i]=upcase(s[i]);
i2=0;
for (i=0; (i<status.users) && (i2==0); i++) {
if (strstr(smallist[i].name,s)!=NULL) {
i1=smallist[i].number;
read_user(i1,&u);
sprintf(s1,"1Do you mean 2%s7? (1Y7/1N7/1Q7) ",nam(&u,i1));
prt(5,s1);
ch=ynq();
if (ch=='Y')
i2=i1;
if (ch=='Q')
i=status.users;
}
}
return(i2);
}
void sl1(int cmd,char *s)
{
static int midline=0,slf=-1;
static char f[81];
char l[180],ch1;
int i;
switch(cmd) {
case 0: /* Write line to sysop's log */
if (slf<=0) {
slf=open(f,O_RDWR | O_CREAT | O_BINARY, S_IREAD | S_IWRITE);
if (filelength(slf)) {
lseek(slf,-1L,SEEK_END);
read(slf,((void *)&ch1),1);
if (ch1==26)
lseek(slf,-1L,SEEK_END);
}
}
if (midline) {
sprintf(l,"\r\n%s",s);
midline = 0;
} else
strcpy(l,s);
if (syscfg.sysconfig & sysconfig_printer)
fprintf(stdprn,"%s\r\n",s);
i=strlen(l);
l[i++]='\r';
l[i++]='\n';
l[i]=0;
write(slf,(void *)l,i);
break;
case 1: /* Close sysop's log */
if (slf>0) {
close(slf);
slf=-1;
}
break;
case 2: /* Set filename */
if (slf>0) {
close(slf);
slf=-1;
}
strcpy(f,syscfg.gfilesdir);
i=strlen(f);
f[i++]=s[6];
f[i++]=s[7];
f[i++]=s[0];
f[i++]=s[1];
f[i++]=s[3];
f[i++]=s[4];
f[i]=0;
strcat(f,".LOG");
break;
case 3: /* Close sysop's log + return filename */
if (slf>0) {
close(slf);
slf=-1;
}
strcpy(s,&f[strlen(syscfg.gfilesdir)]);
break;
case 4:
if (slf <= 0) {
slf = open(f, O_RDWR | O_CREAT | O_BINARY, S_IREAD | S_IWRITE);
if (filelength(slf)) {
lseek(slf, -1L, SEEK_END);
read(slf, ((void *)&ch1), 1);
if (ch1 == 26)
lseek(slf, -1L, SEEK_END);
}
}
if (!midline || ((midline + 2 + strlen(s)) > 78)) {
strcpy(l, midline ? "\r\n " : " ");
strcat(l, s);
midline = 3 + strlen(s);
}
else {
strcpy(l, ", ");
strcat(l, s);
midline += (2 + strlen(s));
}
if (syscfg.sysconfig & sysconfig_printer)
fprintf(stdprn, "%s", l);
i = strlen(l);
write(slf, (void *)l, i);
break;
}
}
void sysopchar(char *s)
{
if ((incom || (actsl != 255)) && (s[0]))
sl1(4, s);
}
void sysoplog(char *s)
{
char s1[180];
if ((incom) || (actsl!=255)) {
sprintf(s1," %s",s);
sl1(0,s1);
}
}
void ssm(unsigned int un, unsigned int sy, char *s)
{
int f,i,i1;
userrec u;
char s1[161];
shortmsgrec sm;
net_header_rec nh;
if ((un==65535) || (un==0))
return;
if (sy==0) {
read_user(un,&u);
if (!(u.inact & inact_deleted)) {
sprintf(s1,"%sSMW.DAT",syscfg.datadir);
f=open(s1,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
i=(int) (filelength(f) / sizeof(shortmsgrec));
i1=i-1;
if (i1>=0) {
lseek(f,((long) (i1)) * sizeof(shortmsgrec), SEEK_SET);
read(f,(void *)&sm,sizeof(shortmsgrec));
while ((sm.tosys==0) && (sm.touser==0) && (i1>0)) {
--i1;
lseek(f,((long) (i1)) * sizeof(shortmsgrec), SEEK_SET);
read(f,(void *)&sm,sizeof(shortmsgrec));
}
if ((sm.tosys) || (sm.touser))
++i1;
} else
i1=0;
sm.tosys=sy;
sm.touser=un;
strncpy(sm.message,s,80);
sm.message[80]=0;
lseek(f,((long) (i1)) * sizeof(shortmsgrec), SEEK_SET);
write(f,(void *)&sm,sizeof(shortmsgrec));
close(f);
u.sysstatus |= sysstatus_smw;
write_user(un,&u);
}
close_user();
} else if (net_sysnum && valid_system(sy)) {
nh.tosys=sy;
nh.touser=un;
nh.fromsys=net_sysnum;
nh.fromuser=usernum;
nh.main_type = main_type_ssm;
nh.minor_type=0;
nh.list_len=0;
time((long *)&nh.daten);
if (strlen(s)>80)
s[80]=0;
nh.length=strlen(s);
nh.method=0;
sprintf(s1,"%sP0.NET",net_data);
f=open(s1,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
lseek(f,0L,SEEK_END);
write(f,(void *)&nh,sizeof(net_header_rec));
write(f,(void *)s,nh.length);
close(f);
}
}
void rsm(int un, userrec *u)
{
shortmsgrec sm;
int i,i1,f,any;
char s1[81];
any=0;
if ((u->sysstatus) & sysstatus_smw) {
sprintf(s1,"%sSMW.DAT",syscfg.datadir);
f=open(s1,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
i=(int) (filelength(f) / sizeof(shortmsgrec));
for (i1=0; i1<i; i1++) {
lseek(f,((long) (i1)) * sizeof(shortmsgrec),SEEK_SET);
read(f,(void *)&sm,sizeof(shortmsgrec));
if ((sm.touser==un) && (sm.tosys==0)) {
pl(sm.message);
sm.touser=0;
sm.tosys=0;
sm.message[0]=0;
lseek(f,((long) (i1)) * sizeof(shortmsgrec),SEEK_SET);
write(f,(void *)&sm,sizeof(shortmsgrec));
any=1;
}
}
close(f);
u->sysstatus ^= sysstatus_smw;
smwcheck=1;
}
if (any)
nl();
}
void show_chains(int *mapp, int *map)
{
int abort,i,i1;
char s[81];
abort=0;
nl();
for (i=0; (i<*mapp) && (!abort) && (!hangup); i++) {
sprintf(s,"1[7%-2d1] 7%s",i+1, chains[map[i]].description);
pla(s,&abort);
}
nl();
}
void run_chain(int cn)
{
char s[255],s1[81],s2[81],s3[81];
int oc;
long l;
itoa(com_speed, s1, 10);
itoa(syscfg.primaryport,s2,10);
itoa(modem_speed, s3, 10);
stuff_in(s,chains[cn].filename,create_chain_file("CHAIN.TXT"),s1,s2,s3,"");
sprintf(s2,get_stringx(1,35),chains[cn].description);
sysoplog(s2);
oc=chatcall;
if (chains[cn].ansir & ansir_no_DOS) {
set_protect(0);
if (chains[cn].ansir & ansir_shrink)
shrink_out(s,1,0,1,1);
else {
chatcall=0;
run_external(s);
}
} else {
if (chains[cn].ansir & ansir_shrink) {
if (chains[cn].ansir & ansir_no_pause) {
shrink_out(s,2,1,1,1);
} else {
shrink_out(s,1,1,1,1);
}
} else {
l=thisuser.sysstatus;
if (chains[cn].ansir & ansir_no_pause)
thisuser.sysstatus &= ~sysstatus_pause_on_page;
chatcall=0;
full_external(s,0,1);
thisuser.sysstatus = l;
}
}
chatcall=oc;
topscreen();
}
void do_chains(void)
{
int map[50],mapp,i,i1,ok,done;
char s[81],s1[81],*ss;
chainfilerec c;
mapp=0;
for (i=0; i<10; i++)
odc[i]=0;
for (i=0; i<numchain; i++) {
ok=1;
c=chains[i];
if ((c.ansir & ansir_ansi) && (!okansi()))
ok=0;
if ((c.ansir & ansir_no_300) && (modem_speed==300))
ok=0;
if ((c.ansir & ansir_local_only) && (using_modem))
ok=0;
if (c.sl>actsl)
ok=0;
if (c.ar)
if ((c.ar & thisuser.ar)==0)
ok=0;
if (ok) {
map[mapp++]=i;
if ((mapp % 10) ==0)
odc[mapp/10 -1]='0'+(mapp/10);
}
}
if (mapp==0) {
nl();
nl();
pl(get_string(620));
nl();
return;
}
if (mapp==1) {
run_chain(map[0]);
return;
}
show_chains(&mapp,map);
done=0;
do {
prt(2,"1Which 7(1Q7=1Quit7, 1?7=1List7)");
ss=mmkey(2);
i=atoi(ss);
if ((i>0) && (i<=mapp)) {
done=1;
run_chain(map[i-1]);
} else
if (strcmp(ss,"Q")==0)
done=1;
else
if (strcmp(ss,"?")==0)
show_chains(&mapp,map);
} while ((!hangup) && (!done));
}