From a4ba6b74f6dc61cec1a6b258e1609d9f7f7ef8a5 Mon Sep 17 00:00:00 2001 From: piaip Date: Fri, 9 May 2008 19:21:08 +0000 Subject: - (internal) change 86400/... (seconds of day/month/...) to named constants. git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4284 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- include/common.h | 7 +++++++ include/proto.h | 1 + mbbsd/bbs.c | 18 +++++++++--------- mbbsd/board.c | 1 - mbbsd/brc.c | 2 +- mbbsd/chat.c | 4 ++-- mbbsd/friend.c | 4 ++-- mbbsd/register.c | 2 +- mbbsd/stuff.c | 18 ++++++++++++++++++ mbbsd/talk.c | 2 +- mbbsd/user.c | 8 ++++---- mbbsd/vote.c | 6 +++--- mbbsd/voteboard.c | 4 ++-- 13 files changed, 51 insertions(+), 26 deletions(-) diff --git a/include/common.h b/include/common.h index 7ef044ea..b0d1a61f 100644 --- a/include/common.h +++ b/include/common.h @@ -33,6 +33,7 @@ #define FN_TICKET_BRDLIST "boardlist" #define FN_BRDLISTHELP "etc/boardlist.help" #define FN_BOARDHELP "etc/board.help" +#define FN_USERMEMO "memo.txt" // 使用者個人記事本 // 自訂刪除文章時出現的標題與檔案 @@ -251,6 +252,12 @@ #define TYPEAHEAD_NONE (-1) #define TYPEAHEAD_STDIN (0) +/* ----------------------------------------------------- */ +/* Constants */ +/* ----------------------------------------------------- */ +#define DAY_SECONDS (86400) +#define MONTH_SECONDS (DAY_SECONDS*30) + /* ----------------------------------------------------- */ /* Macros */ /* ----------------------------------------------------- */ diff --git a/include/proto.h b/include/proto.h index affb2c26..74139931 100644 --- a/include/proto.h +++ b/include/proto.h @@ -629,6 +629,7 @@ int is_uBM(const char *list, const char *id); void FREE(void *ptr); #endif void syncnow(void); +void wait_penalty(int sec); /* syspost */ int post_msg(const char* bname, const char* title, const char *msg, const char* author); diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c index 7e6d3f3e..1db06646 100644 --- a/mbbsd/bbs.c +++ b/mbbsd/bbs.c @@ -160,7 +160,7 @@ anticrosspost(void) cuser.vl_count++; mail_id(cuser.userid, "Cross-Post罰單", "etc/crosspost.txt", BBSMNAME "警察部隊"); - if ((now - cuser.firstlogin) / 86400 < 14) + if ((now - cuser.firstlogin) / DAY_SECONDS < 14) delete_allpost(cuser.userid); kick_all(cuser.userid); // XXX: in2: wait for testing u_exit("Cross Post"); @@ -183,7 +183,7 @@ save_violatelaw(void) return 0; } - day = cuser.vl_count*3 - (now - cuser.timeviolatelaw)/86400; + day = cuser.vl_count*3 - (now - cuser.timeviolatelaw)/DAY_SECONDS; if (day > 0) { vmsgf("依照違規次數, 你還需要反省 %d 天才能繳罰單", day); return 0; @@ -381,7 +381,7 @@ int CheckPostRestriction(int bid) bp = getbcache(bid); // check first-login - if (cuser.firstlogin > (now - (time4_t)bp->post_limit_regtime * 2592000)) + if (cuser.firstlogin > (now - (time4_t)bp->post_limit_regtime * MONTH_SECONDS)) return 0; if (cuser.numlogins / 10 < (unsigned int)bp->post_limit_logins) return 0; @@ -876,7 +876,7 @@ static void setupbidinfo(bid_t *bidinfo) { char buf[PATHLEN]; - bidinfo->enddate = gettime(20, now+86400,"結束標案於"); + bidinfo->enddate = gettime(20, now+DAY_SECONDS,"結束標案於"); do{ getdata_str(21, 0, "底價:", buf, 8, LCECHO, "1"); } while( (bidinfo->high = atoi(buf)) <= 0 ); @@ -1180,7 +1180,7 @@ do_general(int isbid) if( !bp->level || (currbrdattr & BRD_POSTMASK)) { - if ((now - cuser.firstlogin) / 86400 < 14) + if ((now - cuser.firstlogin) / DAY_SECONDS < 14) do_crosspost("NEWIDPOST", &postfile, fpath, 0); if (!(currbrdattr & BRD_HIDE) ) @@ -2034,11 +2034,11 @@ read_post(int ent, fileheader_t * fhdr, const char *direct) int posttime=atoi(fhdr->filename+2); if(posttime>now-12*3600) STATINC(STAT_READPOST_12HR); - else if(posttime>now-1*86400) + else if(posttime>now-1*DAY_SECONDS) STATINC(STAT_READPOST_1DAY); - else if(posttime>now-3*86400) + else if(posttime>now-3*DAY_SECONDS) STATINC(STAT_READPOST_3DAY); - else if(posttime>now-7*86400) + else if(posttime>now-7*DAY_SECONDS) STATINC(STAT_READPOST_7DAY); else STATINC(STAT_READPOST_OLD); @@ -2978,7 +2978,7 @@ recommend(int ent, fileheader_t * fhdr, const char *direct) static int tolog = 0; if( tolog == 0 ) tolog = - (cuser.numlogins < 50 || (now - cuser.firstlogin) < 86400 * 7) + (cuser.numlogins < 50 || (now - cuser.firstlogin) < DAY_SECONDS * 7) ? 1 : 2; if( tolog == 1 ){ FILE *fp; diff --git a/mbbsd/board.c b/mbbsd/board.c index 189c7102..7235b532 100644 --- a/mbbsd/board.c +++ b/mbbsd/board.c @@ -13,7 +13,6 @@ #define NBRD_SYMBOLIC 64 #define TITLE_MATCH(bptr, key) ((key)[0] && !strcasestr((bptr)->title, (key))) -#define MONTH_SECONDS (86400*30) #define B_TOTAL(bptr) (SHM->total[(bptr)->bid - 1]) #define B_LASTPOSTTIME(bptr) (SHM->lastposttime[(bptr)->bid - 1]) diff --git a/mbbsd/brc.c b/mbbsd/brc.c index 4317dfd1..c7413612 100644 --- a/mbbsd/brc.c +++ b/mbbsd/brc.c @@ -401,7 +401,7 @@ brc_initialize(){ if (brc_initialized) return 1; brc_initialized = 1; - brc_expire_time = login_start_time - 365 * 86400; + brc_expire_time = login_start_time - 365 * DAY_SECONDS; read_brc_buf(); return 0; } diff --git a/mbbsd/chat.c b/mbbsd/chat.c index 88a0b497..3af6f4f6 100644 --- a/mbbsd/chat.c +++ b/mbbsd/chat.c @@ -376,9 +376,9 @@ t_chat(void) #endif #ifdef CHAT_REGDAYS - if ((now - cuser.firstlogin)/86400 < CHAT_REGDAYS) + if ((now - cuser.firstlogin)/DAY_SECONDS < CHAT_REGDAYS) { - int i = CHAT_REGDAYS - (now-cuser.firstlogin)/86400 +1; + int i = CHAT_REGDAYS - (now-cuser.firstlogin)/DAY_SECONDS +1; vmsgf("您還不夠資深喔 (再等 %d 天吧)", i); return 0; } diff --git a/mbbsd/friend.c b/mbbsd/friend.c index 9644aa1b..aa0a28bf 100644 --- a/mbbsd/friend.c +++ b/mbbsd/friend.c @@ -230,7 +230,7 @@ delete_friend_from_file(const char *file, const char *string, int case_sensitiv return ret; } -// (2^31)/86400/30 = 828 +// (2^31)/DAY_SECONDS/30 = 828 #define MAX_EXPIRE_MONTH (800) int @@ -244,7 +244,7 @@ friend_validate(int type, int expire) // expire is measured in month if (expire > 0 && expire < MAX_EXPIRE_MONTH) - expire *= 86400 *30; + expire *= DAY_SECONDS *30; else expire = 0; syncnow(); diff --git a/mbbsd/register.c b/mbbsd/register.c index 1bb2fb7b..38ed3cae 100644 --- a/mbbsd/register.c +++ b/mbbsd/register.c @@ -836,7 +836,7 @@ check_register(void) u_register(); #ifdef NEWUSER_LIMIT - if (cuser.lastlogin - cuser->firstlogin < 3 * 86400) + if (cuser.lastlogin - cuser->firstlogin < 3 * DAY_SECONDS) cuser.userlevel &= ~PERM_POST; more("etc/newuser", YEA); #endif diff --git a/mbbsd/stuff.c b/mbbsd/stuff.c index f67779a5..73515eca 100644 --- a/mbbsd/stuff.c +++ b/mbbsd/stuff.c @@ -165,6 +165,24 @@ void syncnow(void) #endif } +void +wait_penalty(int sec) +{ + static time4_t lastWait = 0; + + syncnow(); + if (now - lastWait < sec) + { + sec = now - lastWait; + if (sec < 0 || sec >= 5) + sec = 5; + sleep(sec); + peek_input(0.1, Ctrl('C')); + drop_input(); + } + lastWait = now; +} + // TODO // move this function to visio.c /** diff --git a/mbbsd/talk.c b/mbbsd/talk.c index 5812bc29..1fc2085c 100644 --- a/mbbsd/talk.c +++ b/mbbsd/talk.c @@ -2360,7 +2360,7 @@ draw_pickup(int drawall, pickup_t * pickup, int pickup_way, #ifdef SHOW_IDLE_TIME idletime = (now - uentp->lastact); - if (idletime > 86400) + if (idletime > DAY_SECONDS) strlcpy(idlestr, " -----", sizeof(idlestr)); else if (idletime >= 3600) snprintf(idlestr, sizeof(idlestr), "%dh%02d", diff --git a/mbbsd/user.c b/mbbsd/user.c index b766d36c..ffa5c235 100644 --- a/mbbsd/user.c +++ b/mbbsd/user.c @@ -86,7 +86,7 @@ int u_cancelbadpost(void) if (currutmp && (currutmp->alerts & ALERT_PWD)) currutmp->alerts &= ~ALERT_PWD; - day = 180 - (now - cuser.timeremovebadpost ) / 86400; + day = 180 - (now - cuser.timeremovebadpost ) / DAY_SECONDS; if(day>0 && day<=180) { vmsgf("每 180 天才能申請一次, 還剩 %d 天.", day); @@ -154,7 +154,7 @@ user_display(const userec_t * u, int adminmode) resolve_over18_user(u) ? "已" : "未"); prints("\t\t註冊日期: %s (已滿%d天)\n", - Cdate(&u->firstlogin), (int)((now - u->firstlogin)/86400)); + Cdate(&u->firstlogin), (int)((now - u->firstlogin)/DAY_SECONDS)); prints("\t\t上次上站: %s (%s)\n", u->lasthost, Cdate(&u->lastlogin)); @@ -235,7 +235,7 @@ user_display(const userec_t * u, int adminmode) "\n如果要提昇權限,請參考本站公佈欄辦理註冊"); #ifdef NEWUSER_LIMIT - if ((u->lastlogin - u->firstlogin < 3 * 86400) && !HasUserPerm(PERM_POST)) + if ((u->lastlogin - u->firstlogin < 3 * DAY_SECONDS) && !HasUserPerm(PERM_POST)) outs("\n新手上路,三天後開放權限"); #endif } @@ -328,7 +328,7 @@ violate_law(userec_t * u, int unum) // post -> logout -> login -> post. So both numlogin and numpost // are not good. // We changed the rule to registration date [2 month]. - if (HasUserPerm(PERM_POLICE) && ((now - u->firstlogin) >= 2*30*86400)) + if (HasUserPerm(PERM_POLICE) && ((now - u->firstlogin) >= 2*30*DAY_SECONDS)) { vmsg("使用者註冊已超過 60 天,無法砍除。"); return; diff --git a/mbbsd/vote.c b/mbbsd/vote.c index 323b0647..ff6cbb96 100644 --- a/mbbsd/vote.c +++ b/mbbsd/vote.c @@ -354,7 +354,7 @@ void auto_close_polls(void) { /* 最多一天開票一次 */ - if (now - SHM->close_vote_time > 86400) { + if (now - SHM->close_vote_time > DAY_SECONDS) { b_closepolls(); SHM->close_vote_time = now; } @@ -651,7 +651,7 @@ vote_maintain(const char *bname) getdata(6, 0, "註冊時間限制 (以'月'為單位,0~120):", inbuf, 4, DOECHO); closetime = atoi(inbuf); // borrow variable } while (closetime < 0 || closetime > 120); - fprintf(fp, "%d\n", now - (2592000 * closetime)); + fprintf(fp, "%d\n", now - (MONTH_SECONDS * closetime)); do { getdata(6, 0, "上站次數下限", inbuf, 6, DOECHO); closetime = atoi(inbuf); // borrow variable @@ -676,7 +676,7 @@ vote_maintain(const char *bname) else if (closetime > 30) closetime = 30; - closetime = closetime * 86400 + now; + closetime = closetime * DAY_SECONDS + now; setbfile(buf, bname, vbuf.control); fp = fopen(buf, "w"); assert(fp); diff --git a/mbbsd/voteboard.c b/mbbsd/voteboard.c index 096ecebf..84fea5fa 100644 --- a/mbbsd/voteboard.c +++ b/mbbsd/voteboard.c @@ -10,7 +10,7 @@ int CheckVoteRestriction(int bid) return 1; // check first-login - if (cuser.firstlogin > (now - (time4_t)bcache[bid - 1].vote_limit_regtime * 2592000)) + if (cuser.firstlogin > (now - (time4_t)bcache[bid - 1].vote_limit_regtime * MONTH_SECONDS)) return 0; if (cuser.numlogins / 10 < (unsigned int)bcache[bid - 1].vote_limit_logins) return 0; @@ -29,7 +29,7 @@ int CheckVoteRestrictionFile(const fileheader_t * fhdr) return 1; // check first-login - if (cuser.firstlogin > (now - (time4_t)fhdr->multi.vote_limits.regtime * 2592000)) + if (cuser.firstlogin > (now - (time4_t)fhdr->multi.vote_limits.regtime * MONTH_SECONDS)) return 0; if (cuser.numlogins / 10 < (unsigned int)fhdr->multi.vote_limits.logins) return 0; -- cgit v1.2.3