diff options
-rw-r--r-- | pttbbs/include/proto.h | 6 | ||||
-rw-r--r-- | pttbbs/mbbsd/cal.c | 38 | ||||
-rw-r--r-- | pttbbs/mbbsd/voteboard.c | 37 |
3 files changed, 46 insertions, 35 deletions
diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index c3ae6878..3e862acf 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -150,6 +150,12 @@ int p_exmail(void); int mail_redenvelop(const char* from, const char* to, int money, char *fpath); void resolve_over18(void); int resolve_over18_user(const userec_t *u); +char *get_restriction_reason( + time4_t firstlogin, unsigned int numlogindays, + unsigned int numposts, unsigned int badpost, + time4_t limits_regtime, unsigned int limits_logins, + int limits_posts, unsigned int limits_badpost, + size_t sz_msg, char *msg); /* ccw (common chat window) */ int ccw_talk(int fd, int destuid); // common chat window: private talk diff --git a/pttbbs/mbbsd/cal.c b/pttbbs/mbbsd/cal.c index 95836a8c..21fa20ed 100644 --- a/pttbbs/mbbsd/cal.c +++ b/pttbbs/mbbsd/cal.c @@ -1,6 +1,44 @@ /* $Id$ */ #include "bbs.h" +// XXX numposts itself is an integer, but some records (by del post!?) may +// create invalid records as -1... so we'd better make it signed for real +// comparison. +char *get_restriction_reason( + time4_t firstlogin, unsigned int numlogindays, + unsigned int numposts, unsigned int badpost, + time4_t limits_regtime, unsigned int limits_logins, + int limits_posts, unsigned int limits_badpost, + size_t sz_msg, char *msg) { + + syncnow(); + if (firstlogin > (now - limits_regtime * MONTH_SECONDS)) { + snprintf(msg, sz_msg, "註冊時間(%d天) 未滿 %d 天", + (now - firstlogin) / MONTH_SECONDS * 30, + limits_regtime * 30); + return msg; + } + if (numlogindays / 10 < limits_logins) { + snprintf(msg, sz_msg, STR_LOGINDAYS "(%d" STR_LOGINDAYS_QTY + ") 未滿 %d " STR_LOGINDAYS, + numlogindays, limits_logins * 10); + return msg; + } + if (numposts / 10 < limits_posts) { + snprintf(msg, sz_msg, "各看板有效文章(%d篇) 未滿 %d 篇", + numposts, limits_posts * 10); + return msg; + } +#ifdef ASSESS + if (badpost > (255 - limits_badpost)) { + snprintf(msg, sz_msg, "劣文(%d篇)超過 %d 篇", + badpost, 255 - limits_badpost); + return msg; + } +#endif + return NULL; +} + /* 防堵 Multi play */ static int is_playing(int unmode) diff --git a/pttbbs/mbbsd/voteboard.c b/pttbbs/mbbsd/voteboard.c index aefc5415..a35b0a83 100644 --- a/pttbbs/mbbsd/voteboard.c +++ b/pttbbs/mbbsd/voteboard.c @@ -3,46 +3,13 @@ #define VOTEBOARD "NewBoard" -char *CheckVoteRestriction( - time4_t firstlogin, unsigned int numlogindays, - unsigned int numposts, unsigned int badpost, - time4_t limits_regtime, unsigned int limits_logins, - unsigned int limits_posts, unsigned int limits_badpost, - size_t sz_msg, char *msg) { - - syncnow(); - if (firstlogin > (now - limits_regtime * MONTH_SECONDS)) { - snprintf(msg, sz_msg, "註冊時間(%d天) 未滿 %d 天", - (now - firstlogin) / MONTH_SECONDS * 30, - limits_regtime * 30); - return msg; - } - if (numlogindays / 10 < limits_logins) { - snprintf(msg, sz_msg, STR_LOGINDAYS "(%d" STR_LOGINDAYS_QTY - ") 未滿 %d " STR_LOGINDAYS, - numlogindays, limits_logins * 10); - return msg; - } - if (numposts / 10 < limits_posts) { - snprintf(msg, sz_msg, "各看板有效文章(%d篇) 未滿 %d 篇", - numposts, limits_posts * 10); - return msg; - } - if (badpost > (255 - limits_badpost)) { - snprintf(msg, sz_msg, "劣文(%d篇)超過 %d 篇", - badpost, 255 - limits_badpost); - return msg; - } - return NULL; -} - char *CheckVoteRestrictionBoard(int bid, size_t sz_msg, char *msg) { boardheader_t *bh = getbcache(bid); if ((currmode & MODE_BOARD) || HasUserPerm(PERM_SYSOP)) return NULL; - return CheckVoteRestriction( + return get_restriction_reason( cuser.firstlogin, cuser.numlogindays, cuser.numposts, cuser.badpost, bh->vote_limit_regtime, bh->vote_limit_logins, bh->vote_limit_posts, bh->vote_limit_badpost, @@ -55,7 +22,7 @@ char *CheckVoteRestrictionFile( if ((currmode & MODE_BOARD) || HasUserPerm(PERM_SYSOP)) return NULL; - return CheckVoteRestriction( + return get_restriction_reason( cuser.firstlogin, cuser.numlogindays, cuser.numposts, cuser.badpost, fhdr->multi.vote_limits.regtime, fhdr->multi.vote_limits.logins, fhdr->multi.vote_limits.posts, fhdr->multi.vote_limits.badpost, |