home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Devil's Doorknob BBS Capture (1996-2003)
/
devilsdoorknobbbscapture1996-2003.iso
/
Dloads
/
OTHERUTI
/
WWIV412S.ZIP
/
BBSUTL1.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-08-05
|
9KB
|
376 lines
/*****************************************************************************
WWIV Version 4
Copyright (C) 1988 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 <sys\stat.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <io.h>
#include <fcntl.h>
#include <alloc.h>
#include "vardec.h"
#include "fcns.h"
extern int hangup;
extern char dc[81],dcd[81],odc[81];
extern char charbuffer[161];
extern userrec thisuser;
extern int charbufferpointer,chatting;
extern int usernum,useron;
extern configrec syscfg;
extern int echo,smwcheck,okskey;
extern unsigned char realsl;
extern double timeon;
extern char curspeed[80];
extern unsigned int modem_speed,com_speed;
extern int cursub,curdir,curdloads,helpl;
extern usersubrec usub[32],udir[32];
extern statusrec status;
extern int incom,msgreadlogon,numchain;
extern int fsenttoday,userfile,chatcall;
extern char chatreason[81],irt[81];
extern subboardrec subboards[32];
extern smalrec *smallist;
extern chainfilerec *chains;
int ok_local()
{
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,"Do you mean %s (Y/N/Q) ? ",nam(&u,i1));
prt(5,s1);
ch=onek("QYN");
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) {
strcpy(l, "\r\n");
strcat(l, 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 || (thisuser.sl != 255)) && (s[0]))
sl1(4, s);
}
void sysoplog(char *s)
{
char s1[180];
if ((incom) || (thisuser.sl!=255)) {
strcpy(s1," ");
strcat(s1,s);
sl1(0,s1);
}
}
void ssm(int un, int sy, char *s)
{
int f,i,i1;
userrec u;
char s1[81];
shortmsgrec sm;
if (sy!=0)
return;
strcpy(s1,syscfg.datadir);
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;
strcpy(sm.message,s);
lseek(f,((long) (i1)) * sizeof(shortmsgrec), SEEK_SET);
write(f,(void *)&sm,sizeof(shortmsgrec));
close(f);
if (sy==0) {
read_user(un,&u);
u.sysstatus |= sysstatus_smw;
if ((u.inact & inact_deleted)==0)
write_user(un,&u);
close_user();
}
}
void rsm(int un, userrec *u)
{
shortmsgrec sm;
int i,i1,f,any;
char s1[81];
any=0;
if ((u->sysstatus) & sysstatus_smw) {
strcpy(s1,syscfg.datadir);
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++) {
itoa(i+1,s,10);
strcat(s,". ");
strcat(s,(chains[map[i]].description));
pla(s,&abort);
}
nl();
}
void run_chain(int cn)
{
char s[255],s1[81],s2[81];
int oc;
strcpy(s1,chains[cn].filename);
strcpy(s2,create_chain_file("CHAIN.TXT"));
stuff_in(s,s1,s2,"","","","");
sprintf(s2,"!Ran '%s'",chains[cn].description);
sysoplog(s2);
oc=chatcall;
chatcall=0;
if (chains[cn].ansir & ansir_no_DOS) {
set_protect(0);
if (chains[cn].ansir & ansir_shrink)
shrink_out(s,1,0,1,1);
else
run_external(s);
topscreen();
} else
if (chains[cn].ansir & ansir_shrink)
shrink_out(s,1,1,1,1);
else
full_external(s,0,1);
chatcall=oc;
}
void do_chains()
{
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.sl>thisuser.sl)
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("Sorry, no external programs available.");
nl();
return;
}
if (mapp==1) {
run_chain(map[0]);
return;
}
show_chains(&mapp,map);
done=0;
do {
prt(2,"Which (Q=Quit, ?=List) : ");
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));
}