Commit 871b12de authored by rswindell's avatar rswindell
Browse files

Created a set of userdat module functions to atomically adjust user statistics,

credits, and minutes - basically wrappers for adjustuserrec().
parent 0c50bbb5
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2003 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2006 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
......@@ -67,8 +67,7 @@ void sbbs_t::downloadfile(file_t* f)
/****************************/
/* Update Downloader's Info */
/****************************/
useron.dls=(ushort)adjustuserrec(&cfg,useron.number,U_DLS,5,1);
useron.dlb=adjustuserrec(&cfg,useron.number,U_DLB,10,length);
user_downloaded(&cfg, &useron, 1, length);
if(!is_download_free(&cfg,f->dir,&useron))
subtract_cdt(&cfg,&useron,f->cdt);
/**************************/
......
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2005 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2006 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
......@@ -301,16 +301,11 @@ bool sbbs_t::email(int usernumber, char *top, char *subj, long mode)
return(false);
}
if(usernumber==1) {
useron.fbacks++;
if(usernumber==1)
logon_fbacks++;
putuserrec(&cfg,useron.number,U_FBACKS,5,ultoa(useron.fbacks,tmp,10)); }
else {
useron.emails++;
else
logon_emails++;
putuserrec(&cfg,useron.number,U_EMAILS,5,ultoa(useron.emails,tmp,10)); }
useron.etoday++;
putuserrec(&cfg,useron.number,U_ETODAY,5,ultoa(useron.etoday,tmp,10));
user_sent_email(&cfg, &useron, usernumber, 1);
bprintf(text[Emailed],username(&cfg,usernumber,tmp),usernumber);
sprintf(str,"%s sent e-mail to %s #%d"
,useron.alias,username(&cfg,usernumber,tmp),usernumber);
......
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2005 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2006 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
......@@ -1566,8 +1566,7 @@ static void send_thread(void* arg)
}
if(xfer.credits) {
xfer.user->dls=(ushort)adjustuserrec(&scfg, xfer.user->number,U_DLS,5,1);
xfer.user->dlb=adjustuserrec(&scfg, xfer.user->number,U_DLB,10,total);
user_downloaded(&scfg, xfer.user, 1, total);
if(xfer.dir>=0 && !is_download_free(&scfg,xfer.dir,xfer.user))
subtract_cdt(&scfg, xfer.user, xfer.credits);
}
......@@ -1837,9 +1836,7 @@ static void receive_thread(void* arg)
/**************************/
/* Update Uploader's Info */
/**************************/
if(!xfer.append && xfer.filepos==0)
xfer.user->uls=(short)adjustuserrec(&scfg, xfer.user->number,U_ULS,5,1);
xfer.user->ulb=adjustuserrec(&scfg, xfer.user->number,U_ULB,10,total);
user_uploaded(&scfg, xfer.user, (!xfer.append && xfer.filepos==0) ? 1:0, total);
if(scfg.dir[f.dir]->up_pct && scfg.dir[f.dir]->misc&DIR_CDTUL) { /* credit for upload */
if(scfg.dir[f.dir]->misc&DIR_CDTMIN && cps) /* Give min instead of cdt */
xfer.user->min=adjustuserrec(&scfg,xfer.user->number,U_MIN,10
......
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2005 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2006 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
......@@ -382,11 +382,8 @@ bool sbbs_t::postmsg(uint subnum, smbmsg_t *remsg, long wm_mode)
return(false);
}
useron.ptoday++;
useron.posts++;
logon_posts++;
putuserrec(&cfg,useron.number,U_POSTS,5,ultoa(useron.posts,str,10));
putuserrec(&cfg,useron.number,U_PTODAY,5,ultoa(useron.ptoday,str,10));
user_posted_msg(&cfg, &useron, 1);
bprintf(text[Posted],cfg.grp[cfg.sub[subnum]->grp]->sname
,cfg.sub[subnum]->lname);
sprintf(str,"%s posted on %s %s"
......
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2005 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2006 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
......@@ -447,11 +447,8 @@ bool sbbs_t::unpack_rep(char* repfile)
if(!qwktomsg(rep,block,0,n,0))
continue;
useron.ptoday++;
useron.posts++;
logon_posts++;
putuserrec(&cfg,useron.number,U_POSTS,5,ultoa(useron.posts,str,10));
putuserrec(&cfg,useron.number,U_PTODAY,5,ultoa(useron.ptoday,str,10));
user_posted_msg(&cfg, &useron, 1);
bprintf(text[Posted],cfg.grp[cfg.sub[n]->grp]->sname
,cfg.sub[n]->lname);
sprintf(str,"%s posted on %s %s"
......
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2005 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2006 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
......@@ -223,8 +223,7 @@ bool sbbs_t::uploadfile(file_t *f)
/**************************/
/* Update Uploader's Info */
/**************************/
useron.uls=(ushort)adjustuserrec(&cfg,useron.number,U_ULS,5,1);
useron.ulb=(ushort)adjustuserrec(&cfg,useron.number,U_ULB,10,length);
user_uploaded(&cfg, &useron, 1, length);
if(cfg.dir[f->dir]->up_pct && cfg.dir[f->dir]->misc&DIR_CDTUL) { /* credit for upload */
if(cfg.dir[f->dir]->misc&DIR_CDTMIN && cur_cps) /* Give min instead of cdt */
useron.min=adjustuserrec(&cfg,useron.number,U_MIN,10
......
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2005 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2006 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
......@@ -1875,6 +1875,76 @@ void DLLCALL subtract_cdt(scfg_t* cfg, user_t* user, long amt)
user->cdt=adjustuserrec(cfg, user->number,U_CDT,10,-amt);
}
BOOL DLLCALL user_posted_msg(scfg_t* cfg, user_t* user, int count)
{
if(user==NULL)
return(FALSE);
user->posts =(ushort)adjustuserrec(cfg, user->number, U_POSTS, 5, count);
user->ptoday=(ushort)adjustuserrec(cfg, user->number, U_PTODAY, 5, count);
return(TRUE);
}
BOOL DLLCALL user_sent_email(scfg_t* cfg, user_t* user, unsigned to_user, int count)
{
if(user==NULL)
return(FALSE);
if(to_user==1)
user->fbacks=(ushort)adjustuserrec(cfg, user->number, U_FBACKS, 5, count);
else
user->emails=(ushort)adjustuserrec(cfg, user->number, U_EMAILS, 5, count);
user->etoday=(ushort)adjustuserrec(cfg, user->number, U_ETODAY, 5, count);
return(TRUE);
}
BOOL DLLCALL user_downloaded(scfg_t* cfg, user_t* user, int files, long bytes)
{
if(user==NULL)
return(FALSE);
user->dls=(ushort)adjustuserrec(cfg, user->number, U_DLS, 5, files);
user->dlb=adjustuserrec(cfg, user->number, U_DLB, 10, bytes);
return(TRUE);
}
BOOL DLLCALL user_uploaded(scfg_t* cfg, user_t* user, int files, long bytes)
{
if(user==NULL)
return(FALSE);
user->uls=(ushort)adjustuserrec(cfg, user->number, U_ULS, 5, files);
user->ulb=adjustuserrec(cfg, user->number, U_ULB, 10, bytes);
return(TRUE);
}
BOOL DLLCALL user_credits_adjusted(scfg_t* cfg, user_t* user, long amount)
{
if(user==NULL)
return(FALSE);
if(amount<0) /* subtract */
subtract_cdt(cfg, user, -amount);
else /* add */
user->cdt=adjustuserrec(cfg, user->number, U_CDT, 10, amount);
return(TRUE);
}
BOOL DLLCALL user_minutes_adjusted(scfg_t* cfg, user_t* user, long amount)
{
if(user==NULL)
return(FALSE);
user->min=adjustuserrec(cfg, user->number, U_MIN, 10, amount);
return(TRUE);
}
/****************************************************************************/
/****************************************************************************/
BOOL DLLCALL logoutuserdat(scfg_t* cfg, user_t* user, time_t now, time_t logontime)
......
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2006 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
......@@ -109,6 +109,14 @@ DLLEXPORT int DLLCALL user_rec_len(int offset);
DLLEXPORT BOOL DLLCALL is_download_free(scfg_t* cfg, uint dirnum, user_t* user);
DLLEXPORT BOOL DLLCALL filter_ip(scfg_t* cfg, char* prot, char* reason, char* host, char* ip_addr, char* username, char* fname);
/* New atomic numeric user field adjustment functions: */
DLLEXPORT BOOL DLLCALL user_posted_msg(scfg_t* cfg, user_t* user, int count);
DLLEXPORT BOOL DLLCALL user_sent_email(scfg_t* cfg, user_t* user, unsigned to_user, int count);
DLLEXPORT BOOL DLLCALL user_downloaded(scfg_t* cfg, user_t* user, int files, long bytes);
DLLEXPORT BOOL DLLCALL user_uploaded(scfg_t* cfg, user_t* user, int files, long bytes);
DLLEXPORT BOOL DLLCALL user_credits_adjusted(scfg_t* cfg, user_t* user, long amount);
DLLEXPORT BOOL DLLCALL user_minutes_adjusted(scfg_t* cfg, user_t* user, long amount);
#ifdef __cplusplus
}
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment