From 871b12de7ee7877ac229e374ec080ee39a1f726f Mon Sep 17 00:00:00 2001 From: rswindell <> Date: Tue, 31 Jan 2006 02:51:59 +0000 Subject: [PATCH] Created a set of userdat module functions to atomically adjust user statistics, credits, and minutes - basically wrappers for adjustuserrec(). --- src/sbbs3/download.cpp | 5 ++- src/sbbs3/email.cpp | 13 +++----- src/sbbs3/ftpsrvr.c | 9 ++---- src/sbbs3/postmsg.cpp | 7 ++-- src/sbbs3/un_rep.cpp | 7 ++-- src/sbbs3/upload.cpp | 5 ++- src/sbbs3/userdat.c | 72 +++++++++++++++++++++++++++++++++++++++++- src/sbbs3/userdat.h | 10 +++++- 8 files changed, 95 insertions(+), 33 deletions(-) diff --git a/src/sbbs3/download.cpp b/src/sbbs3/download.cpp index 63effc0d95..8e62acc772 100644 --- a/src/sbbs3/download.cpp +++ b/src/sbbs3/download.cpp @@ -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); /**************************/ diff --git a/src/sbbs3/email.cpp b/src/sbbs3/email.cpp index 4952a8855e..17b0c830cf 100644 --- a/src/sbbs3/email.cpp +++ b/src/sbbs3/email.cpp @@ -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); diff --git a/src/sbbs3/ftpsrvr.c b/src/sbbs3/ftpsrvr.c index c0414f18ec..8d67ff3341 100644 --- a/src/sbbs3/ftpsrvr.c +++ b/src/sbbs3/ftpsrvr.c @@ -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 diff --git a/src/sbbs3/postmsg.cpp b/src/sbbs3/postmsg.cpp index 89e900d1bb..a6fa399e40 100644 --- a/src/sbbs3/postmsg.cpp +++ b/src/sbbs3/postmsg.cpp @@ -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" diff --git a/src/sbbs3/un_rep.cpp b/src/sbbs3/un_rep.cpp index befc1cb423..e8d6a25464 100644 --- a/src/sbbs3/un_rep.cpp +++ b/src/sbbs3/un_rep.cpp @@ -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" diff --git a/src/sbbs3/upload.cpp b/src/sbbs3/upload.cpp index d28dcd172d..d1690ae7a8 100644 --- a/src/sbbs3/upload.cpp +++ b/src/sbbs3/upload.cpp @@ -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 diff --git a/src/sbbs3/userdat.c b/src/sbbs3/userdat.c index abd7782016..a8b45ab757 100644 --- a/src/sbbs3/userdat.c +++ b/src/sbbs3/userdat.c @@ -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) diff --git a/src/sbbs3/userdat.h b/src/sbbs3/userdat.h index 5346aee44d..05113094eb 100644 --- a/src/sbbs3/userdat.h +++ b/src/sbbs3/userdat.h @@ -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 -- GitLab