home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 2 BBS
/
02-BBS.zip
/
MAXMAILP.ZIP
/
MISC.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-01-02
|
15KB
|
583 lines
/****************************************************************************/
/* */
/* Misc.c :Miscellaneous routines for MaxMail */
/* */
/****************************************************************************/
#include "MaxMail.h"
#include <sys\timeb.h>
struct user_cfg uscfg;
int do_reset;
void signon()
{
char *p;
strout("MaxMail - a MAXIMUS mail/message archiver utility by Craig Derouen\r\n");
sprintf(temp,"\t *** Version %.2f (beta) ***\r\n",Version);
strout(temp);
strcpy(temp1,LastUser.name);
p = strtok(temp1," "); /* Fetch 1st name only, shows how friendly we are */
if (USERCFG.packcount) {
sprintf(temp,"\r\nWelcome back to MaxMail, %s.\r\n",p);
strout(temp);
sprintf(temp,"You have had %d previous successful downloads. Good luck!\r\n",USERCFG.packcount);
strout(temp);
}
else {
sprintf(temp,"\r\nWelcome to MaxMail, %s.\r\n",p);
strout(temp);
}
}
void menu(void)
{
char resp;
char *p1;
int choice;
int good;
unsigned msgs;
struct msgupd_st *msgupd;
choice = TRUE;
PackDone = FALSE;
while (choice) {
msgs = get_msgcount();
if (msgs) {
if (PackDone){
msgs = msgs < MaxMsgs ? msgs : MaxMsgs;
sprintf(temp,"\r\nYou have %u messages in %s. Select [T]ransmit to download\r\n",msgs,ArcFile);
strout(temp);
strout("or select [R]eset,[A]dd or [D]elete to scan more messages/areas\r\n");
strout("\r\nSelect a choice\r\n");
}
else {
sprintf(temp,"\r\n\r\nYou have %u new messages in areas:\r\n",msgs);
strout(temp);
show_areas(TRUE);
if (msgs > MaxMsgs) {
sprintf(temp,"\r\nSorry, but only %u new messages can be packed up during this run.\r\n",MaxMsgs);
strout(temp);
sprintf(temp,"MaxMail will pack up the first %u messages it finds.\r\n",MaxMsgs);
strout(temp);
}
strout("\r\nPress ENTER to capture new messages, or select a choice\r\n");
}
}
else {
strout("\r\n Sorry, but you have NO new messages to capture\r\n");
strout(" in the current message areas you have selected.\r\n");
strout("\r\nSelect a choice\r\n");
}
strout("-------------------------------------------------------\r\n");
strout("[C]hange configuration [L]ist configuration\r\n");
strout("[A]dd message areas [D]elete message areas\r\n");
strout("[R]eset message pointers [S]can for new messages\r\n");
strout("[Q]uit back to Maximus\r\n");
if (PackDone)
strout("[T]ransmit archive\r\n");
if (LastUser.priv >= SYSOP) {
strout("[U]ser stats (Sysop function)\r\n");
}
strout("\r\n");
good = FALSE;
while (!good) {
timeremain();
strout("Choice --> ");
strin(temp);
p1 = strtok(temp," \t\r\n");
if (p1)
resp = toupper(*p1);
else resp = 'S'; /* Scan messages as default */
good = TRUE;
switch (resp) {
case 'S':
if (msgs) {
if (scan_msgs() && totmsgs) {
if(Packit()) {
if (sendit()) {
PackDone = FALSE;
choice = FALSE;
}
}
}
}
else {
if (!IsLocal)
strout("\r\n");
good = FALSE;
}
break;
case 'C':
getconfig();
break;
case 'A':
add_msgareas();
break;
case 'D':
del_msgareas();
break;
case 'R':
edit_msgptrs();
break;
case 'T':
if (PackDone) {
if (sendit()) {
PackDone = FALSE;
choice = FALSE;
}
}
else good = FALSE;
break;
case 'L':
list_config();
break;
case 'Q':
choice = FALSE;
break;
case 'U':
if (LastUser.priv >= SYSOP)
Sys_menu(); /* We won't return from Sysop menu */
else good = FALSE;
break;
default:
good = FALSE;
if (!IsLocal)
strout("\r\n");
break;
}
}
}
if (PackDone) { /* Pack file aborted */
if (LogMode == VERBOSE) logit("User aborted message pack",'~');
unlink(ArcFile); /* Erase it and start over */
msgupd = MSGUPD_1;
while (msgupd) {
msgupd->update = FALSE;
msgupd = msgupd->next;
}
}
return;
}
void display_packers(void)
{
int x,col;
struct packer_st *pack1;
pack1 = PACKER_1;
col = 0;
for (x = 0; x < totpackers; x++) {
sprintf(temp,"[%d]%s",x +1,pack1->packname);
while (strlen(temp) < 32)
strcat(temp," ");
strout(temp);
if (col++) {
strout("\r\n");
col = 0;
}
pack1 = pack1->next;
}
if (col)
strout("\r\n");
return;
}
void display_protos(void)
{
int x,col;
struct proto_st *proto1;
proto1 = PROTO_1;
col = 0;
for (x = 0; x < totprotocols; x++) {
sprintf(temp,"[%d]%s",x +1,proto1->protoname);
while (strlen(temp) < 32)
strcat(temp," ");
strout(temp);
if (col++) {
strout("\r\n");
col = 0;
}
proto1 = proto1->next;
}
if (col)
strout("\r\n");
return;
}
/* Find the user in the config file */
int find_config(int handle,char *name,struct user_cfg *uscfg)
{
int x,y;
x = 0;
do_reset = FALSE;
lseek(handle,0L,SEEK_SET); /* Rewind to begginning */
while (1) {
y = read(handle,(char *) uscfg,sizeof(struct user_cfg));
if( y < sizeof(struct user_cfg))
return(-1);
if (strcmpi(uscfg->name,name) == 0) { /* It's found! */
return(x);
}
x++; /* Try next user */
}
}
/* Find a blank slot in the config file */
int find_blconfig(int handle)
{
int x,y;
x = 0;
lseek(handle,0L,SEEK_SET); /* Rewind to begginning */
while (1) {
y = read(handle,(char *) &uscfg,sizeof(struct user_cfg));
if( y < sizeof(struct user_cfg))
return(-1);
if (uscfg.isused == 0) /* It's found! */
return(x);
x++; /* Try next user */
}
}
/* Changed name so to not conflict with Maxi timeon var. */
int Timeon(void)
{
clock_t elapsed;
int t;
elapsed = clock();
elapsed = startsecs - elapsed;
elapsed = elapsed / CLOCKS_PER_SEC; /* Compute seconds */
t = (int) (elapsed / 60);
if (t < 0)
t = t * (-1);
return(t);
}
void timeremain(void)
{
int x;
char tstr[18];
x = LastUser.timeremaining - Timeon(); /* Fetch # of minutes on */
sprintf(tstr,"{%d min left} ",x);
strout(tstr);
}
struct proto_st *get_curprotolnk(void)
{
int x;
struct proto_st *proto1;
proto1 = PROTO_1; /* Point to first 1! */
for (x = 1; x < USERCFG.protocol; x++) {
proto1 = proto1->next;
}
return(proto1);
}
struct packer_st *get_curpacklnk(void)
{
int x;
struct packer_st *pack1;
if (!USERCFG.packer)
return NULL;
pack1 = PACKER_1; /* Point to first 1! */
for (x = 1; x < USERCFG.packer; x++) {
pack1 = pack1->next;
}
return(pack1);
}
int get_kminute(void)
{
int x,y;
x = LastUser.flag / 10; /* Compute cps */
y = LastUser.flag;
switch (LastUser.flag) {
case 300:
x -= (x * 0.08f); /* Slop off 8% */
break;
case 1200:
x -= (x * 0.18f); /* Slop off 18% */
break;
case 2400:
x -= (x * 0.22f);
break;
case 4800:
x -= (x * 0.25f);
break;
case 9600:
x -= (x * 0.28f);
break;
default:
x -= (x * 0.28f);
break;
}
x *= 60; /* Compute to minutes */
return x;
}
/* The sysop menu */
void Sys_menu(void)
{
int x,choice;
char *p1;
char resp;
choice = TRUE;
while (choice) {
strout("\r\n\r\nSysop menu. Select a choice.\r\n");
strout("----------------------------\r\n");
strout("[D]elete a user [F]orce reconfig\r\n");
strout("[L]ist users [K]ill old users\r\n");
strout("[E]xamine user msgareas [Q]uit\r\n");
strout("\r\n");
timeremain();
strout("Choice --> ");
strin(temp);
if (!IsLocal)
strout("\r\n");
p1 = strtok(temp," \t\r\n");
if (p1) {
resp = toupper(*p1);
switch (resp) {
case 'D': /* Delete single users */
delete_users();
break;
case 'E': /* List user message areas */
examine_user();
break;
case 'F': /* Force all users to re-do configuration */
if (!do_reset) {
strout("This will force all users to re-do their configuration.\r\n");
strout("Are you sure you want this? (y,N) ---> ");
strin(temp);
if (!IsLocal)
strout("\r\n");
p1 = strtok(temp," \t\r\n");
if (p1) {
resp = toupper(*p1);
if (resp == 'Y')
do_reset = reset_config();
}
}
else strout("\r\nYou have already reset all the users during this session.\r\n");
break;
case 'L': /* User stats */
user_stats();
break;
case 'K': /* Kill older users */
strout("\r\nThis will delete all MaxMail users who are no longer active on your bbs\r\n");
strout("Are you sure you want this? (y,N) ---> ");
strin(temp);
strout("\r\n");
p1 = strtok(temp," \t\r\n");
if (p1) {
resp = toupper(*p1);
if (resp == 'Y')
kill_oldusers();
}
break;
case 'Q': /* Quit */
choice = FALSE;
break;
}
}
}
strout("\r\n\r\n");
return;
}
void show_areas(int flag)
{
int x,col,msgpos;
struct msgupd_st *msgupd;
msgupd = MSGUPD_1;
col = TRUE;
while (col && msgupd) {
msgpos = 0;
while (msgupd && msgpos < 20) {
fseek(afile,msgupd->areaindex,SEEK_SET);
fread(&AREA,astrlen,1,afile);
if ((flag && msgupd->msgcount) || !flag) {
strncpy(temp1,AREA.msginfo,24);
temp1[24] = 0;
sprintf(temp," [%03d] %s",msgupd->areano,temp1);
while (strlen(temp) < 32)
strcat(temp," ");
sprintf(temp1," (%u new messages)\r\n",msgupd->msgcount);
strcat(temp,temp1);
strout(temp);
}
msgupd = msgupd->next;
msgpos++;
}
if (col && msgupd) {
strout("\r\nPress ESC to abort or any other key to continue");
x = chrin();
strout("\r\n");
if (x == 0x1b)
col = FALSE;
}
}
}
int is_selarea(int msgnum)
{
struct msgupd_st *msgupd;
int x;
msgupd = MSGUPD_1;
x = 1;
while (msgupd) {
if (msgupd->areano == (word) msgnum)
return x; /* Return linked list number */
msgupd = msgupd->next;
x++;
}
return(FALSE);
}
void update_msgs(void)
{
int x,first;
struct msgupd_st *msgupd;
char LastRdFile[65];
msgupd = MSGUPD_1;
first = TRUE;
while (msgupd) {
if (msgupd->update) {
if (LastUser.lastread_ptr)
sprintf(LastRdFile,"%slastread.bbs",msgupd->msgpath);
else sprintf(LastRdFile,"%slastread",msgupd->msgpath);
x = sopen(LastRdFile,O_RDWR | O_BINARY,SH_DENYNO,S_IWRITE); /* Poke into the lastread file */
if (x == -1) { /* Couldn't find! We must have it */
msgupd = msgupd->next;
continue;
}
if (lseek(x,(long)(LastUser.lastread_ptr * sizeof(int)),SEEK_SET) == -1)
close(x);
else {
msgupd->startmsg += msgupd->readmsgs;
write(x,(char *) &msgupd->startmsg,sizeof(int));
close(x);
if (first) {
strout("\r\nYour lastread message pointers are now being updated\r\n");
first = FALSE;
}
}
}
msgupd = msgupd->next;
}
}
struct msgupd_st *find_area(int msgnum)
{
struct msgupd_st *msgst;
msgst = MSGUPD_1;
while (msgst) {
if (msgst->areano == (word) msgnum)
break;
msgst = msgst->next;
}
return msgst;
}
void delay_s(unsigned n)
/* n = Number of seconds */
{
n *= 1000; /* Convert to seconds */
delay_ms(n);
}
void delay_ms(unsigned n)
/* milleseconds to delay */
{
struct timeb timebuf;
long end_time;
unsigned end_millitm;
/* get current time and calculate ending time */
ftime(&timebuf);
end_time = timebuf.time + (n / 1000);
end_millitm = timebuf.millitm + (n % 1000);
if (end_millitm >= 1000) {
++end_time;
end_millitm -= 1000;
}
/* loop until ending time reached */
do ftime(&timebuf);
while (timebuf.time < end_time ||
(timebuf.time == end_time && timebuf.millitm < end_millitm));
}
int find_realuser(char *name,int handle)
{
int x;
struct _usr USER;
lseek(handle,0L,SEEK_SET);
x = read(handle,(char *) &USER,user_slen);
while (x == user_slen) {
if (strcmpi(name,USER.name) == 0) {
if (USER.flag & UFLAG_deleted)
return(FALSE); /* It's there but it is deleted! */
else return(TRUE);
}
x = read(handle,(char *) &USER,user_slen);
}
return(FALSE); /* Couldn't find it */
}
/* Test to see if this message area is a skip one, if so, return TRUE */
int isskiparea(int msgarea)
{
int x;
if (LastUser.priv >= SYSOP || msgarea == 0)
return FALSE; /* Sysops should always be able to get ALL areas */
x = 0;
while (SkipAreas[x]) {
if (*SkipAreas[x] == msgarea)
return TRUE;
x++;
}
return FALSE;
}