diff options
-rw-r--r-- | include/proto.h | 1 | ||||
-rw-r--r-- | mbbsd/bbs.c | 11 | ||||
-rw-r--r-- | mbbsd/board.c | 25 | ||||
-rw-r--r-- | mbbsd/cache.c | 49 |
4 files changed, 52 insertions, 34 deletions
diff --git a/include/proto.h b/include/proto.h index 19a4eddd..7475042d 100644 --- a/include/proto.h +++ b/include/proto.h @@ -134,6 +134,7 @@ unsigned int getutmpmode(void); void setadir(char *buf, const char *path); int apply_boards(int (*func)(boardheader_t *)); int haspostperm(const char *bname); +const char * postperm_msg(const char *bname); void setbtotal(int bid); void setbottomtotal(int bid); unsigned int safe_sleep(unsigned int seconds); diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c index b1b616e3..beb48a8c 100644 --- a/mbbsd/bbs.c +++ b/mbbsd/bbs.c @@ -360,17 +360,20 @@ CheckPostPerm(void) int CheckPostRestriction(int bid) { + boardheader_t *bp; if ((currmode & MODE_BOARD) || HasUserPerm(PERM_SYSOP)) return 1; + assert(0<=bid-1 && bid-1<MAX_BOARD); + bp = getbcache(bid); // check first-login - if (cuser.firstlogin > (now - (time4_t)bcache[bid - 1].post_limit_regtime * 2592000)) + if (cuser.firstlogin > (now - (time4_t)bp->post_limit_regtime * 2592000)) return 0; - if (cuser.numlogins / 10 < (unsigned int)bcache[bid - 1].post_limit_logins) + if (cuser.numlogins / 10 < (unsigned int)bp->post_limit_logins) return 0; - if (cuser.numposts / 10 < (unsigned int)bcache[bid - 1].post_limit_posts) + if (cuser.numposts / 10 < (unsigned int)bp->post_limit_posts) return 0; - if (cuser.badpost > (255 - (unsigned int)bcache[bid - 1].post_limit_badpost)) + if (cuser.badpost > (255 - (unsigned int)bp->post_limit_badpost)) return 0; return 1; diff --git a/mbbsd/board.c b/mbbsd/board.c index 18ae88e7..c87a968d 100644 --- a/mbbsd/board.c +++ b/mbbsd/board.c @@ -397,7 +397,12 @@ b_config(void) ipostres = b_lines - LNPOSTRES; move_ansi(ipostres++, COLPOSTRES-2); - outs(ANSI_COLOR(1;32) "發文限制" ANSI_RESET); + + if (CheckPostPerm() && CheckPostRestriction(currbid)) + outs(ANSI_COLOR(1;32)); + else + outs(ANSI_COLOR(1;31)); + outs("發文限制" ANSI_RESET); #define POSTRESTRICTION(msg,utag) \ prints(msg, attr ? ANSI_COLOR(1) : "", i, attr ? ANSI_RESET : "") @@ -431,17 +436,15 @@ b_config(void) prints("劣文篇數 %d 篇以下", i); if (attr) outs(ANSI_RESET); - if (bp->brdattr & BRD_POSTMASK) { - // see haspostperm() - unsigned int permok = bp->level & ~PERM_POST; - permok = permok ? HasUserPerm(permok) : 1; - move_ansi(ipostres++, COLPOSTRES); - prints("使用者等級: %s限定(%s要求)%s\n", - permok ? "" : ANSI_COLOR(31), - permok ? "已達" : "未達", - permok ? "" : ANSI_RESET - ); + const char *msg = postperm_msg(bp->brdname); + if (msg) // some reasons + { + move_ansi(ipostres++, COLPOSTRES); + outs(ANSI_COLOR(1;31)); + outs(msg); + outs(ANSI_RESET); + } } { diff --git a/mbbsd/cache.c b/mbbsd/cache.c index 7df6a49a..5a30c24f 100644 --- a/mbbsd/cache.c +++ b/mbbsd/cache.c @@ -789,44 +789,55 @@ getbnum(const char *bname) return 0; } -int -haspostperm(const char *bname) +const char * +postperm_msg(const char *bname) { register int i; - char buf[200]; + char buf[PATHLEN]; + boardheader_t *bp = NULL; setbfile(buf, bname, fn_water); if (belong(buf, cuser.userid)) - return 0; + return "使用者水桶中"; if (!strcasecmp(bname, DEFAULT_BOARD)) - return 1; + return NULL; if (!(i = getbnum(bname))) - return 0; + return "看板不存在"; + assert(0<=i-1 && i-1<MAX_BOARD); + bp = getbcache(i); - if (bcache[i - 1].brdattr & BRD_GUESTPOST) - return 1; + if (bp->brdattr & BRD_GUESTPOST) + return NULL; if (!HasUserPerm(PERM_POST)) - return 0; + return "無發文權限"; /* 秘密看板特別處理 */ - if (bcache[i - 1].brdattr & BRD_HIDE) - return 1; - else if (bcache[i - 1].brdattr & BRD_RESTRICTEDPOST && + if (bp->brdattr & BRD_HIDE) + return NULL; + else if (bp->brdattr & BRD_RESTRICTEDPOST && !is_hidden_board_friend(i, usernum)) - return 0; + return "看板限制發文"; - i = bcache[i - 1].level; - - if (HasUserPerm(PERM_VIOLATELAW) && (i & PERM_VIOLATELAW)) - return 1; + if (HasUserPerm(PERM_VIOLATELAW) && (bp->level & PERM_VIOLATELAW)) + return NULL; else if (HasUserPerm(PERM_VIOLATELAW)) - return 0; + return "罰單未繳"; - return (i & ~PERM_POST) ? HasUserPerm(i & ~PERM_POST) : 1; + if (!(bp->level & ~PERM_POST)) + return NULL; + if (!HasUserPerm(bp->level & ~PERM_POST)) + return "未達看板要求權限"; + return NULL; +} + +int +haspostperm(const char *bname) +{ + return postperm_msg(bname) == NULL ? 1 : 0; } void buildBMcache(int bid) /* bid starts from 1 */ |