diff options
-rw-r--r-- | pttbbs/include/proto.h | 3 | ||||
-rw-r--r-- | pttbbs/mbbsd/cache.c | 46 | ||||
-rw-r--r-- | pttbbs/mbbsd/vote.c | 24 |
3 files changed, 49 insertions, 24 deletions
diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h index 9a7313d5..b726da31 100644 --- a/pttbbs/include/proto.h +++ b/pttbbs/include/proto.h @@ -133,7 +133,8 @@ void invalid_board_permission_cache(const char *board); int is_BM_cache(int); int apply_boards(int (*func)(boardheader_t *)); int haspostperm(const char *bname); -const char * postperm_msg(const char *bname); +const char *postperm_msg(const char *bname); +const char *banned_msg(const char *bname); /* cal */ const char* money_level(int money); diff --git a/pttbbs/mbbsd/cache.c b/pttbbs/mbbsd/cache.c index 1b403f67..b5b187ef 100644 --- a/pttbbs/mbbsd/cache.c +++ b/pttbbs/mbbsd/cache.c @@ -185,6 +185,28 @@ is_BM_cache(int bid) /* bid starts from 1 */ // TODO move this to board.c const char * +banned_msg(const char *bname) +{ +#ifdef USE_NEW_BAN_SYSTEM + // static is bad, but this is faster... + static char ban_msg[STRLEN]; + time4_t expire = is_banned_by_board(bname); + if (expire > now) { + sprintf(ban_msg, "使用者水桶中(尚有%d天)", + ((expire - now) / DAY_SECONDS) +1); + return ban_msg; + } +#else + char buf[PATHLEN]; + setbfile(buf, bname, fn_water); + if (file_exist_record(buf, cuser.userid)) + return "使用者水桶中"; +#endif + return NULL; +} + +// TODO move this to board.c +const char * postperm_msg(const char *bname) { register int i; @@ -200,25 +222,11 @@ postperm_msg(const char *bname) if (HasUserPerm(PERM_SYSOP)) return NULL; -#ifdef USE_NEW_BAN_SYSTEM - { - // static is bad, but this is faster... - static char ban_msg[STRLEN]; - time4_t expire = is_banned_by_board(bname); - if (expire > now) { - sprintf(ban_msg, "使用者水桶中(尚有%d天)", - ((expire - now) / DAY_SECONDS) +1); - return ban_msg; - } - } -#else - { - char buf[PATHLEN]; - setbfile(buf, bname, fn_water); - if (file_exist_record(buf, cuser.userid)) - return "使用者水桶中"; - } -#endif + do { + const char *msg; + if ((msg = banned_msg(bname)) != NULL) + return msg; + } while (0); if (!strcasecmp(bname, DEFAULT_BOARD)) return NULL; diff --git a/pttbbs/mbbsd/vote.c b/pttbbs/mbbsd/vote.c index 1a02b076..383dc32c 100644 --- a/pttbbs/mbbsd/vote.c +++ b/pttbbs/mbbsd/vote.c @@ -985,6 +985,19 @@ user_vote_one(const vote_buffer_t *vbuf, const char *bname) return FULLUPDATE; } +static const char * +voteperm_msg(const char *bname) +{ + if (!HasBasicUserPerm(PERM_LOGINOK)) + return "對不起! 您未完成註冊程序, 還沒有投票權喔!"; + + const char *msg; + if ((msg = banned_msg(bname)) != NULL) + return msg; + + return NULL; +} + static int user_vote(const char *bname) { @@ -1009,10 +1022,13 @@ user_vote(const char *bname) vmsg("目前並沒有任何投票舉行。"); return FULLUPDATE; } - if (!HasBasicUserPerm(PERM_LOGINOK)) { - vmsg("對不起! 您未完成註冊程序, 還沒有投票權喔!"); - return FULLUPDATE; - } + do { + const char *msg; + if ((msg = voteperm_msg(bname)) != NULL) { + vmsg(msg); + return FULLUPDATE; + } + } while (0); // XXX I think such loop is ineffective... // According to the creation code, the vote is ranged as [1..MAX_VOTE_NR] |