From 95c901b5e0ce59134b89bcc31dc52043e0bdafc3 Mon Sep 17 00:00:00 2001 From: victor Date: Mon, 27 Oct 2003 01:35:04 +0000 Subject: complete assess git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1264 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/assess.c | 25 +++++++++++++------------ mbbsd/bbs.c | 10 ++++++---- mbbsd/talk.c | 11 ++++++----- util/cleanpasswd.c | 36 +++++++++++++++++++++++++++++------- 4 files changed, 54 insertions(+), 28 deletions(-) diff --git a/mbbsd/assess.c b/mbbsd/assess.c index 02498263..059fc078 100644 --- a/mbbsd/assess.c +++ b/mbbsd/assess.c @@ -1,20 +1,21 @@ #include "bbs.h" +/* do (*num) + n, n is integer. */ inline static void inc(unsigned char *num, int n) { - if (SALE_MAXVALUE - *num >= n) - (*num) += n; - else - (*num) = SALE_MAXVALUE; -} - -inline static void dec(unsigned char *num, int n) -{ - if (*num < n) - (*num) -= n; - else - (*num) = 0; + if (n > 0){ + if (SALE_MAXVALUE - *num < n) + (*num) = SALE_MAXVALUE; + else + (*num) += n; + } + else { + if (*num < n) + (*num) = 0; + else + (*num) -= n; + } } void inc_goodpost(int uid, int num) diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c index eb4c627d..478c7a37 100644 --- a/mbbsd/bbs.c +++ b/mbbsd/bbs.c @@ -1602,10 +1602,12 @@ mark_post(int ent, fileheader_t * fhdr, char *direct) fhdr->filemode ^= FILE_MARKED; - if (fhdr->filemode) - inc_goodpost(searchuser(fhdr->owner), fhdr->recommend); - else - inc_badpost(searchuser(fhdr->owner), fhdr->recommend); + if (!(fhdr->filemode & FILE_BID)){ + if (fhdr->filemode & FILE_MARKED) + inc_goodpost(searchuser(fhdr->owner), fhdr->recommend / 10); + else + inc_goodpost(searchuser(fhdr->owner), -1 * (fhdr->recommend / 10)); + } substitute_record(direct, fhdr, sizeof(*fhdr), ent); substitute_check(fhdr); diff --git a/mbbsd/talk.c b/mbbsd/talk.c index b1a3d712..07c94c45 100644 --- a/mbbsd/talk.c +++ b/mbbsd/talk.c @@ -358,11 +358,12 @@ my_query(char *uident) 26 - strlen(muser.userid) - strlen(muser.username), "", money[i]); if ((uentp && ((fri_stat & HFM) || strcmp(muser.userid,cuser.userid) == 0) && !uentp->invisible)) - prints(" (%d)", muser.money); + prints(" ($%d)", muser.money); prints("\n"); + prints("《上站次數》%d次", muser.numlogins); move(2, 40); - prints("《文章篇數》%d篇\n", muser.numposts); + prints("《文章篇數》%d篇 (佳作%d/劣文%d)\n", muser.numposts, muser.goodpost, muser.badpost); prints("\033[1;33m《目前動態》%-28.28s\033[m", (uentp && isvisible_stat(currutmp, uentp, fri_stat)) ? @@ -374,15 +375,15 @@ my_query(char *uident) prints("《上次上站》%-28.28s《上次故鄉》%s\n", Cdate(&muser.lastlogin), (muser.lasthost[0] ? muser.lasthost : "(不詳)")); - prints("《文章評比》 優 %-3d 劣 %-3d 《競標評比》 優 %-3d 劣 %-3d\n", - muser.goodpost, muser.badpost, - muser.goodsale, muser.badsale); prints("《五子棋戰績》%3d 勝 %3d 敗 %3d 和 " "《象棋戰績》%3d 勝 %3d 敗 %3d 和\n", muser.five_win, muser.five_lose, muser.five_tie, muser.chc_win, muser.chc_lose, muser.chc_tie); + prints("《競標評比》 優 %d / 劣 %d", muser.goodsale, muser.badsale); + move(6, 40); if ((uentp && ((fri_stat & HFM) || strcmp(muser.userid,cuser.userid) == 0) && !uentp->invisible)) prints("《 性 別 》%-28.28s\n", sex[muser.sex % 8]); + showplans(uident); pressanykey(); return FULLUPDATE; diff --git a/util/cleanpasswd.c b/util/cleanpasswd.c index 3632ad5e..c5f8a251 100644 --- a/util/cleanpasswd.c +++ b/util/cleanpasswd.c @@ -2,8 +2,6 @@ #define _UTIL_C_ #include "bbs.h" -extern userec_t xuser; - /* 當資料欄位有異動 例如用了舊的欄位 可用這個程式清除舊值 */ int clean_unused_var(userec_t *rec) { @@ -17,10 +15,34 @@ int clean_unused_var(userec_t *rec) int main(int argc, char *argv[]) { - attach_SHM(); - if(passwd_init()) - exit(1); - if (passwd_apply(clean_unused_var) == 0) - printf("ERROR\n"); + int i, fd, fdw; + userec_t user; + + if ((fd = open(BBSHOME"/.PASSWDS", O_RDONLY)) < 0){ + perror("open .PASSWDS error"); + exit(-1); + } + + if ((fdw = open(BBSHOME"/.PASSWDS.new", O_WRONLY | O_TRUNC | O_CREAT, 0600)) < 0){ + perror("open .PASSWDS.new error"); + exit(-1); + } + + for(i = 0; i < MAX_USERS; i++){ + if (read(fd, &user, sizeof(user)) != sizeof(user)) + break; + clean_unused_var(&user); + write(fdw, &user, sizeof(user)); + } + close(fd); + close(fdw); + + if (i != MAX_USERS) + fprintf(stderr, "ERROR\n"); + else{ + fprintf(stderr, "DONE\n"); + system("/bin/mv " BBSHOME "/.PASSWDS " BBSHOME "/.PASSWDS.bak"); + system("/bin/mv " BBSHOME "/.PASSWDS.new " BBSHOME "/.PASSWDS"); + } return 0; } -- cgit v1.2.3