-- cgit v1.2.3 From 2230c0a8c5a4eb2397673d37e709454195c5e284 Mon Sep 17 00:00:00 2001 From: piaip Date: Fri, 28 Aug 2009 13:57:40 +0000 Subject: * moving into the new pwcu (password - current user helper) API git-svn-id: http://opensvn.csie.org/pttbbs/branches/pttbbs.pwcu@4783 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- include/proto.h | 31 ++++-- include/pttstruct.h | 3 +- mbbsd/admin.c | 1 + mbbsd/angel.c | 10 +- mbbsd/assess.c | 4 +- mbbsd/bbs.c | 29 +++--- mbbsd/cal.c | 5 +- mbbsd/edit.c | 2 +- mbbsd/emaildb.c | 4 +- mbbsd/mail.c | 3 +- mbbsd/mbbsd.c | 115 ++++----------------- mbbsd/ordersong.c | 2 +- mbbsd/passwd.c | 287 +++++++++++++++++++++++++++++++++++++++++++++++++--- mbbsd/talk.c | 7 +- mbbsd/user.c | 9 +- 15 files changed, 346 insertions(+), 166 deletions(-) diff --git a/include/proto.h b/include/proto.h index 80265894..00fffb2e 100644 --- a/include/proto.h +++ b/include/proto.h @@ -187,8 +187,8 @@ const char *ask_tmpbuf(int y); /* emaildb */ #ifdef USE_EMAILDB -int emaildb_check_email(char * email, int email_len); -int emaildb_update_email(char * userid, int userid_len, char * email, int email_len); +int emaildb_check_email (const char * email, int email_len); +int emaildb_update_email(const char * userid, int userid_len, const char * email, int email_len); #endif #ifdef USE_REGCHECKD int regcheck_ambiguous_userid_exist(const char *userid); @@ -615,7 +615,7 @@ int isvalidemail(char *email); void uinfo_query(userec_t *u, int real, int unum); int showsignature(char *fname, int *j, SigInfo *psi); int u_cancelbadpost(); -void kick_all(char *user); +void kick_all(const char *user); void violate_law(userec_t * u, int unum); void mail_violatelaw(const char* crime, const char* police, const char* reason, const char* result); int u_info(void); @@ -692,12 +692,31 @@ void passwd_force_update(int flag); int passwd_sync_update (int num, userec_t * buf); int passwd_sync_query (int num, userec_t * buf); -// int passwd_add_my_numpost(int diff); // temporary hack before new account system ready. - // current user help utilities -int pwcuSetSignature (unsigned char newsig); int pwcuBitSetLevel (unsigned int mask); int pwcuBitUnsetLevel (unsigned int mask); +int pwcuSetSignature (unsigned char newsig); +int pwcuIncNumPost (); +int pwcuDecNumPost (); +int pwcuSetGoodPost (unsigned int newgp); +int pwcuViolateLaw (); +int pwcuSaveViolateLaw (); +int pwcuAddExMailBox (int m); +int pwcuToggleOutMail (); +int pwcuSetLoginView (unsigned int bits); +int pwcuSetWaterballMode(unsigned int bm); +int pwcuSetLastSongTime (time4_t clk); +int pwcuSetMyAngel (const char *angel_uid); +int pwcuSetNickname (const char *nickname); + +// session save +int pwcuLoginSave (); +int pwcuExitSave (); + +// initialization +void pwcuInitGuestPerm (); +void pwcuInitGuestInfo (); +int pwcuInitAdminPerm (); /* calendar */ int calendar(void); diff --git a/include/pttstruct.h b/include/pttstruct.h index 2c3591c4..c0ea9f64 100644 --- a/include/pttstruct.h +++ b/include/pttstruct.h @@ -94,8 +94,9 @@ typedef struct userec_t { char career[40]; /* 學歷職業 */ char phone[20]; /* 電話 */ + uint32_t numlogindays; /* 登入天次 */ - char chkpad1[52]; + char chkpad1[48]; time4_t chkpad2[3]; /* in case 有人忘了把 time4_t 調好... */ // 以上應為 sizeof(chicken_t) 同等大小 diff --git a/mbbsd/admin.c b/mbbsd/admin.c index cab1089f..b1f6f1c7 100644 --- a/mbbsd/admin.c +++ b/mbbsd/admin.c @@ -103,6 +103,7 @@ upgrade_passwd(userec_t *puser) memset(puser->chkpad0, 0, sizeof(puser->chkpad0)); memset(puser->chkpad1, 0, sizeof(puser->chkpad1)); memset(puser->chkpad2, 0, sizeof(puser->chkpad2)); + puser->numlogindays = 0; puser->version = PASSWD_VERSION; return; } diff --git a/mbbsd/angel.c b/mbbsd/angel.c index 240e51a2..ab4f2bbc 100644 --- a/mbbsd/angel.c +++ b/mbbsd/angel.c @@ -14,9 +14,6 @@ angel_toggle_pause() return; currutmp->angelpause ++; currutmp->angelpause %= ANGELPAUSE_MODES; - - // maintain deprecated value - cuser.uflag2 &= ~UF2_ANGEL_OLDMASK; } void @@ -140,7 +137,7 @@ t_changeangel(){ Cdatelite(&now), cuser.userid, cuser.myangel); log_file(BBSHOME "/log/changeangel.log", LOG_CREAT, buf); - cuser.myangel[0] = 0; + pwcuSetMyAngel(""); outs("小天使更新完成,下次呼叫時會選出新的小天使"); } return XEASY; @@ -269,8 +266,7 @@ FindAngel(void){ (u->userlevel & PERM_ANGEL) && !angel_reject_me(u) && u->userid[0]){ - strlcpy(cuser.myangel, u->userid, sizeof(cuser.myangel)); - passwd_sync_update(usernum, &cuser); + pwcuSetMyAngel(u->userid); return 1; } }while(++trial < 5); @@ -394,7 +390,7 @@ TalkToAngel(){ memset(&xuser, 0, sizeof(xuser)); getuser(cuser.myangel, &xuser); // XXX if user doesn't exist if (!(xuser.userlevel & PERM_ANGEL)) - cuser.myangel[0] = 0; + pwcuSetMyAngel(""); } AngelPermChecked = 1; diff --git a/mbbsd/assess.c b/mbbsd/assess.c index 64bc7ad5..e11ac70f 100644 --- a/mbbsd/assess.c +++ b/mbbsd/assess.c @@ -231,10 +231,8 @@ u_fixgoodpost(void) log_filef("log/fixgoodpost.log", LOG_CREAT, "%s %s 自動修正優文數: 由 %d 變為 %d\n", Cdate(&now), cuser.userid, cuser.goodpost, newgp); - cuser.goodpost = newgp; // update passwd file here? - passwd_force_update(ALERT_PWD_GOODPOST); - passwd_sync_update(usernum, &cuser); + pwcuSetGoodPost(newgp); vmsgf("更新優文數目為%d。", newgp); } diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c index 528e61b4..d1f268e3 100644 --- a/mbbsd/bbs.c +++ b/mbbsd/bbs.c @@ -170,9 +170,7 @@ anticrosspost(void) cuser.userid, Cdatelite(&now)); post_violatelaw(cuser.userid, BBSMNAME "系統警察", "Cross-post", "罰單處份"); - cuser.userlevel |= PERM_VIOLATELAW; - cuser.timeviolatelaw = now; - cuser.vl_count++; + pwcuViolateLaw(); mail_id(cuser.userid, "Cross-Post罰單", "etc/crosspost.txt", BBSMNAME "警察部隊"); if ((now - cuser.firstlogin) / DAY_SECONDS < 14) @@ -243,11 +241,7 @@ save_violatelaw(void) } demoney(-1000 * cuser.vl_count); - cuser.userlevel &= (~PERM_VIOLATELAW); - // force overriding alerts - if(currutmp) - currutmp->alerts &= ~ALERT_PWD_PERM; - passwd_sync_update(usernum, &cuser); + pwcuSaveViolateLaw(); sendalert(cuser.userid, ALERT_PWD_PERM); log_filef("log/violation", LOG_CREAT, "%s %s pay-violation: $%d complete.\n", @@ -908,7 +902,8 @@ do_general(int garbage) int i, j; int defanony, ifuseanony; int money = 0; - char genbuf[PATHLEN], *owner; + char genbuf[PATHLEN]; + const char *owner; char ctype[8][5] = {"問題", "建議", "討論", "心得", "閒聊", "請益", "公告", "情報"}; boardheader_t *bp; @@ -1128,9 +1123,10 @@ do_general(int garbage) if (money > 0) { demoney(money); + pwcuIncNumPost(); addPost = 1; prints("這是您的第 %d 篇有效文章,稿酬 %d 元", - ++cuser.numposts, money); + cuser.numposts, money); } else { // no money, no record. outs("本篇不列入記錄,敬請包涵。"); @@ -3125,10 +3121,11 @@ del_post(int ent, fileheader_t * fhdr, char *direct) if (tusernum) { userec_t xuser; - passwd_sync_query(tusernum, &xuser); - if (xuser.numposts) + assert(tusernum != usernum); + passwd_query(tusernum, &xuser); + if (xuser.numposts > 0) xuser.numposts--; - passwd_sync_update(tusernum, &xuser); + passwd_update(tusernum, &xuser); sendalert_uid(tusernum, ALERT_PWD_POSTS); // TODO alert user? @@ -3143,11 +3140,9 @@ del_post(int ent, fileheader_t * fhdr, char *direct) else { // owner case - if (cuser.numposts){ - cuser.numposts--; - sendalert(cuser.userid, ALERT_PWD_POSTS); - } + pwcuDecNumPost(); demoney(-fhdr->multi.money); + sendalert(cuser.userid, ALERT_PWD_POSTS); vmsgf("您的文章減為 %d 篇,支付清潔費 %d 元", cuser.numposts, fhdr->multi.money); } diff --git a/mbbsd/cal.c b/mbbsd/cal.c index 2e3b441a..342049b8 100644 --- a/mbbsd/cal.c +++ b/mbbsd/cal.c @@ -84,10 +84,7 @@ vice(int money, const char *item) static int inmailbox(int m) { - userec_t xuser; - passwd_sync_query(usernum, &xuser); - cuser.exmailbox = xuser.exmailbox + m; - passwd_sync_update(usernum, &cuser); + pwcuAddExMailBox(m); return cuser.exmailbox; } diff --git a/mbbsd/edit.c b/mbbsd/edit.c index 78a3e83a..d262f90e 100644 --- a/mbbsd/edit.c +++ b/mbbsd/edit.c @@ -1741,7 +1741,7 @@ browse_sigs: ch = buf[0]; else ch = '1' + random() % (si.max+1); - cuser.signature = buf[0]; + pwcuSetSignature(buf[0]); if (ch != '0') { fpath[i] = ch; diff --git a/mbbsd/emaildb.c b/mbbsd/emaildb.c index d8718b1b..931aee66 100644 --- a/mbbsd/emaildb.c +++ b/mbbsd/emaildb.c @@ -5,7 +5,7 @@ #ifdef USE_EMAILDB -int emaildb_check_email(char * email, int email_len) +int emaildb_check_email(const char * email, int email_len) { int count = -1; int fd = -1; @@ -38,7 +38,7 @@ int emaildb_check_email(char * email, int email_len) return count; } -int emaildb_update_email(char * userid, int userid_len, char * email, int email_len) +int emaildb_update_email(const char * userid, int userid_len, const char * email, int email_len) { int result = -1; int fd = -1; diff --git a/mbbsd/mail.c b/mbbsd/mail.c index f64f7269..96b2259f 100644 --- a/mbbsd/mail.c +++ b/mbbsd/mail.c @@ -1401,8 +1401,7 @@ mail_edit(int ent GCC_UNUSED, fileheader_t * fhdr, const char *direct) static int mail_nooutmail(int ent GCC_UNUSED, fileheader_t * fhdr GCC_UNUSED, const char *direct GCC_UNUSED) { - cuser.uflag2 ^= REJ_OUTTAMAIL; - passwd_sync_update(usernum, &cuser); + pwcuToggleOutMail(); return FULLUPDATE; } diff --git a/mbbsd/mbbsd.c b/mbbsd/mbbsd.c index 7782c5ed..99394c0b 100644 --- a/mbbsd/mbbsd.c +++ b/mbbsd/mbbsd.c @@ -190,15 +190,6 @@ log_usies(const char *mode, const char *mesg) } -static void -setflags(int mask, int value) -{ - if (value) - cuser.uflag |= mask; - else - cuser.uflag &= ~mask; -} - void u_exit(const char *mode) { @@ -210,27 +201,15 @@ u_exit(const char *mode) // verify if utmp is valid. only flush data if utmp is correct. assert(strncmp(currutmp->userid,cuser.userid, IDLEN)==0); - if(strncmp(currutmp->userid,cuser.userid, IDLEN)!=0) + if(strncmp(currutmp->userid, cuser.userid, IDLEN)!=0) return; auto_backup(); save_brdbuf(); brc_finalize(); - /* - cuser.goodpost = currutmp->goodpost; - cuser.badpost = currutmp->badpost; - */ - // no need because in later passwd_sync_update will reload money from SHM. - // reload_money(); - - setflags(PAGER_FLAG, currutmp->pager != PAGER_ON); - setflags(CLOAK_FLAG, currutmp->invisible); - - cuser.invisible = currutmp->invisible; - cuser.withme = currutmp->withme; - cuser.pager = currutmp->pager; - memcpy(cuser.mind, currutmp->mind, 4); + // XXX TOTO for guests, skip the save process? + pwcuExitSave(); setutmpbid(0); if (!SHM->GV2.e.shutdown) { @@ -239,11 +218,6 @@ u_exit(const char *mode) do_aloha("<<下站通知>> -- 我走囉!"); } - // 小於 60 秒不計 login 次數 - if (time(0) - login_start_time < 60 && cuser.numlogins > 0) - --cuser.numlogins; - - passwd_sync_update(usernum, &cuser); purge_utmp(currutmp); log_usies(mode, NULL); } @@ -739,13 +713,7 @@ load_current_user(const char *uid) if (strcasecmp(uid, STR_GUEST) == 0) { if (initcuser(STR_GUEST)< 1) exit (0) ; - cuser.userlevel = 0; - cuser.uflag = PAGER_FLAG | BRDSORT_FLAG | MOVIE_FLAG; - cuser.uflag2= 0; // we don't need FAVNEW_FLAG or anything else. - -# ifdef GUEST_DEFAULT_DBCS_NOINTRESC - cuser.uflag |= DBCS_NOINTRESC; -# endif + pwcuInitGuestPerm(); // can we prevent mkuserdir() here? mkuserdir(cuser.userid); } else @@ -763,11 +731,7 @@ load_current_user(const char *uid) exit(0); #else /* 自動加上各個主要權限 */ // TODO only allow in local connection? - cuser.userlevel = PERM_BASIC | PERM_CHAT | PERM_PAGE | - PERM_POST | PERM_LOGINOK | PERM_MAILLIMIT | - PERM_CLOAK | PERM_SEECLOAK | PERM_XEMPT | - PERM_SYSOPHIDE | PERM_BM | PERM_ACCOUNTS | - PERM_CHATROOM | PERM_BOARD | PERM_SYSOP | PERM_BBSADM; + pwcuInitAdminPerm(); #endif } /* 早該有 home 了, 不知道為何有的帳號會沒有, 被砍掉了? */ @@ -1022,14 +986,15 @@ where(const char *from) static void check_BM(void) { - /* XXX: -_- */ - int i; + int i; - cuser.userlevel &= ~PERM_BM; + assert(HasUserPerm(PERM_BM)); for( i = 0 ; i < numboards ; ++i ) if( is_BM_cache(i + 1) ) /* XXXbid */ return; - //for (i = 0, bhdr = bcache; i < numboards && !is_BM(bhdr->BM); i++, bhdr++); + + // disable BM permission + pwcuBitUnsetLevel(PERM_BM); } static void @@ -1067,10 +1032,10 @@ setup_utmp(int mode) uinfo.go_tie = cuser.go_tie; uinfo.invisible = cuser.invisible % 2; uinfo.pager = cuser.pager % PAGER_MODES; + uinfo.withme = cuser.withme & ~WITHME_ALLFLAG; if(cuser.withme & (cuser.withme<<1) & (WITHME_ALLFLAG<<1)) - cuser.withme = 0; /* unset all if contradict */ - uinfo.withme = cuser.withme & ~WITHME_ALLFLAG; + uinfo.withme = 0; getnewutmpent(&uinfo); @@ -1161,11 +1126,6 @@ inline static void birthday_make_a_wish(const struct tm *ptime, const struct tm } } -inline static void record_lasthost(const char *fromhost) -{ - strlcpy(cuser.lasthost, fromhost, sizeof(cuser.lasthost)); -} - inline static void check_mailbox_quota(void) { if (chkmailbox()) @@ -1174,31 +1134,7 @@ inline static void check_mailbox_quota(void) static void init_guest_info(void) { - int i; - char *nick[13] = { - "椰子", "貝殼", "內衣", "寶特瓶", "翻車魚", - "樹葉", "浮萍", "鞋子", "潛水艇", "魔王", - "鐵罐", "考卷", "大美女" - }; - char *name[13] = { - "大王椰子", "鸚鵡螺", "比基尼", "可口可樂", "仰泳的魚", - "憶", "高岡屋", "AIR Jordon", "紅色十月號", "批踢踢", - "SASAYA椰奶", "鴨蛋", "布魯克鱈魚香絲" - }; - char *addr[13] = { - "天堂樂園", "大海", "綠島小夜曲", "美國", "綠色珊瑚礁", - "遠方", "原本海", "NIKE", "蘇聯", "男八618室", - "愛之味", "天上", "藍色珊瑚礁" - }; - i = login_start_time % 13; - snprintf(cuser.nickname, sizeof(cuser.nickname), - "海邊漂來的%s", nick[(int)i]); - strlcpy(currutmp->nickname, cuser.nickname, - sizeof(currutmp->nickname)); - strlcpy(cuser.realname, name[(int)i], sizeof(cuser.realname)); - strlcpy(cuser.address, addr[(int)i], sizeof(cuser.address)); - memset(cuser.mind, 0, sizeof(cuser.mind)); - cuser.sex = i % 8; + pwcuInitGuestInfo(); currutmp->pager = PAGER_DISABLE; } @@ -1209,7 +1145,7 @@ inline static void foreign_warning(void){ mail_muser(cuser, "[出入境管理局]", "etc/foreign_expired_warn"); } else if (login_start_time - cuser.firstlogin > FOREIGN_REG_DAY * 24 * 3600){ - cuser.userlevel &= ~(PERM_LOGINOK | PERM_POST); + pwcuBitUnsetLevel(PERM_LOGINOK | PERM_POST); vmsg("警告:請至出入境管理局申請永久居留"); } } @@ -1231,8 +1167,6 @@ user_login(void) /* 初始化 uinfo、flag、mode */ setup_utmp(LOGIN); - if (cuser.userlevel) - ++cuser.numlogins; /* log usies */ log_usies("ENTER", fromhost); @@ -1306,7 +1240,7 @@ user_login(void) check_mailbox_quota(); check_birthday(); check_register(); - record_lasthost(fromhost); + pwcuLoginSave(); restore_backup(); } else if (strcmp(cuser.userid, STR_GUEST) == 0) { /* guest */ @@ -1334,34 +1268,19 @@ user_login(void) /* If you wanna do incremental upgrade * (like, added a function/flag that wants user to confirm againe) * put it here. + * But you must use 'lasttime' because cuser.lastlogin + * is already changed. */ -#if defined(DBCSAWARE) && defined(DBCSAWARE_UPGRADE_STARTTIME) - // define the real time you upgraded in your pttbbs.conf - if(cuser.lastlogin < DBCSAWARE_UPGRADE_STARTTIME) - { - if (u_detectDBCSAwareEvilClient()) - cuser.uflag &= ~DBCSAWARE_FLAG; - else - cuser.uflag |= DBCSAWARE_FLAG; - } -#endif /* login time update */ - if(ptime.tm_yday!=lasttime.tm_yday) STATINC(STAT_TODAYLOGIN_MIN); - - - cuser.lastlogin = login_start_time; - } #if FOREIGN_REG_DAY > 0 foreign_warning(); #endif - passwd_sync_update(usernum, &cuser); - if(cuser.uflag2 & FAVNEW_FLAG) { fav_load(); if (get_fav_root() != NULL) { diff --git a/mbbsd/ordersong.c b/mbbsd/ordersong.c index 7163e1a5..be9844d8 100644 --- a/mbbsd/ordersong.c +++ b/mbbsd/ordersong.c @@ -147,7 +147,7 @@ do_order_song(void) log_filef("etc/osong.log", LOG_CREAT, "id: %-12s ◇ %s 點給 %s : \"%s\", 轉寄至 %s\n", cuser.userid, sender, receiver, say, address); if (append_record(OSONGPATH "/" FN_DIR, &mail, sizeof(mail)) != -1) { - cuser.lastsong = now; + pwcuSetLastSongTime(now); /* Jaky 超過 MAX_MOVIE 首歌就開始砍 */ // XXX 載入的順序會長得像是: // 3. ◆ <系統> 動態看板 SYSOP [01/23/08] diff --git a/mbbsd/passwd.c b/mbbsd/passwd.c index 405e5d7c..b1a240a6 100644 --- a/mbbsd/passwd.c +++ b/mbbsd/passwd.c @@ -5,8 +5,6 @@ #error sorry, mbbsd/passwd.c does not support utility mode anymore. please use libcmbbs instead. #endif -static uint32_t latest_numposts; - void passwd_force_update(int flag) { @@ -19,7 +17,6 @@ int initcuser(const char *userid) { usernum = passwd_load_user(userid, &cuser); - latest_numposts = cuser.numposts; return usernum; } @@ -55,10 +52,6 @@ passwd_sync_update(int num, userec_t * buf) memcpy(buf->email, u.email, sizeof(u.email)); memcpy(cuser.email, u.email, sizeof(u.email)); } - cuser.numposts += u.numposts - latest_numposts; - // XXX bad workaround - but.... let's use it until we've solved the sync issue - if ((int)cuser.numposts < 0) - cuser.numposts = 0; currutmp->alerts &= ~ALERT_PWD; // ALERT_PWD_RELOAD: reload all! No need to write. @@ -72,13 +65,6 @@ passwd_sync_update(int num, userec_t * buf) if (passwd_update(num, buf) != 0) return -1; - if (currutmp && usernum > 0 && - latest_numposts != cuser.numposts) - { - sendalert_uid(usernum, ALERT_PWD_POSTS); - latest_numposts = cuser.numposts; - } - return 0; } @@ -90,8 +76,277 @@ passwd_sync_query(int num, userec_t * buf) if (passwd_query(num, buf) < 0) return -1; - if (buf == &cuser) - latest_numposts = cuser.numposts; + return 0; +} + +// pwcu*: current user password helpers +static int +pwcuInitCUser(userec_t *u) +{ + assert(usernum > 0 && usernum <= MAX_USERS); + if (passwd_query(usernum, u) != 0) + return -1; + assert(strncmp(u->userid, cuser.userid, IDLEN) == 0); + if (strncmp(u->userid, cuser.userid, IDLEN) != 0) + return -1; return 0; } + +static int +pwcuFinalCUser(userec_t *u) +{ + assert(usernum > 0 && usernum <= MAX_USERS); + assert(strcmp(u->userid, cuser.userid) == 0); + if (passwd_update(usernum, u) != 0) + return -1; + return 0; +} + +#define PWCU_START() userec_t u; if(pwcuInitCUser (&u) != 0) return -1 +#define PWCU_END() if (pwcuFinalCUser(&u) != 0) return -1; return 0 + +int pwcuBitSetLevel (unsigned int mask) +{ + PWCU_START(); + cuser.userlevel |= mask; + u.userlevel |= mask; + PWCU_END(); +} + +int pwcuBitUnsetLevel (unsigned int mask) +{ + PWCU_START(); + cuser.userlevel &= ~mask; + u.userlevel &= ~mask; + PWCU_END(); +} + +int +pwcuIncNumPost() +{ + PWCU_START(); + cuser.numposts = ++u.numposts; + PWCU_END(); +} + +int +pwcuDecNumPost() +{ + PWCU_START(); + if (u.numposts > 0) + u.numposts--; + cuser.numposts = u.numposts; + PWCU_END(); +} + +int +pwcuSetGoodPost(unsigned int newgp) +{ + PWCU_START(); + cuser.goodpost = u.goodpost = newgp; + // passwd_force_update(ALERT_PWD_GOODPOST); + PWCU_END(); +} + +int +pwcuSetSignature(unsigned char newsig) +{ + PWCU_START(); + cuser.signature = u.signature = newsig; + PWCU_END(); +} + +int +pwcuViolateLaw () +{ + PWCU_START(); + u.userlevel |= PERM_VIOLATELAW; + cuser.userlevel |= PERM_VIOLATELAW; + u.timeviolatelaw = now; + cuser.timeviolatelaw = u.timeviolatelaw; + u.vl_count++; + cuser.vl_count = u.vl_count; + PWCU_END(); +} + +int +pwcuSaveViolateLaw() +{ + PWCU_START(); + u.userlevel &= (~PERM_VIOLATELAW); + cuser.userlevel &= (~PERM_VIOLATELAW); + PWCU_END(); +} + +int +pwcuAddExMailBox(int m) +{ + PWCU_START(); + u.exmailbox += m; + cuser.exmailbox = u.exmailbox; + PWCU_END(); +} + +int +pwcuToggleOutMail() +{ + PWCU_START(); + u.uflag2 ^= REJ_OUTTAMAIL; + cuser.uflag2 ^= REJ_OUTTAMAIL; + PWCU_END(); +} + +int +pwcuSetLoginView(unsigned int bits) +{ + PWCU_START(); + u.loginview = bits; + cuser.loginview = u.loginview; + PWCU_END(); +} + +int +pwcuSetWaterballMode(unsigned int bm) +{ + PWCU_START(); + bm &= WATER_MASK; + u.uflag2 &= ~WATER_MASK; + cuser.uflag2 &= ~WATER_MASK; + u.uflag2 |= bm; + cuser.uflag2 |= bm; + PWCU_END(); +} + +int pwcuSetLastSongTime (time4_t clk) +{ + PWCU_START(); + u.lastsong = clk; + cuser.lastsong = clk; + PWCU_END(); +} + +int pwcuSetMyAngel (const char *angel_uid) +{ + PWCU_START(); + strlcpy(u.myangel, angel_uid, sizeof(u.myangel)); + strlcpy(cuser.myangel, angel_uid, sizeof(cuser.myangel)); + PWCU_END(); +} + +int pwcuSetNickname (const char *nickname) +{ + PWCU_START(); + strlcpy(u.nickname, nickname, sizeof(u.nickname)); + strlcpy(cuser.nickname, nickname, sizeof(cuser.nickname)); + PWCU_END(); +} + +#if 0 +static void +_setflags(int mask, int value) +{ + if (value) + cuser.uflag |= mask; + else + cuser.uflag &= ~mask; +} +#endif + +// XXX this is a little different - only invoked at login, +// which we should update/calculate every variables to log. +int pwcuLoginSave () +{ + PWCU_START(); // XXX no need to reload for speed up? + + // new host from 'fromhost' + strlcpy(cuser.lasthost, fromhost, sizeof(cuser.lasthost)); + + // XXX keep 'lastlogin' and 'disp_lastlogin'... + // new 'lastlogin' + if (!PERM_HIDE(currutmp)) + cuser.lastlogin = login_start_time; + + // calculate numlogins + + PWCU_END(); +} + +// XXX this is a little different - only invoked at exist, +// so no need to sync back to cuser. +int pwcuExitSave () +{ + PWCU_START(); + + u.uflag &= ~(PAGER_FLAG | CLOAK_FLAG); + if (currutmp->pager != PAGER_ON) + u.uflag |= PAGER_FLAG; + if (currutmp->invisible) + u.uflag |= CLOAK_FLAG; + u.invisible = currutmp->invisible; + u.withme = currutmp->withme; + u.pager = currutmp->pager; + + // XXX 當初設計的人把 mind 設計成非 NULL terminated 的... + // assert(sizeof(u.mind) == sizeof(currutmp->mind)); + memcpy(u.mind,currutmp->mind, sizeof(u.mind)); + + reload_money(); + + // TODO deal with numlogin? + + PWCU_END(); +} + +// Initialization + +int pwcuInitAdminPerm () +{ + PWCU_START(); + cuser.userlevel = PERM_BASIC | PERM_CHAT | PERM_PAGE | + PERM_POST | PERM_LOGINOK | PERM_MAILLIMIT | + PERM_CLOAK | PERM_SEECLOAK | PERM_XEMPT | + PERM_SYSOPHIDE | PERM_BM | PERM_ACCOUNTS | + PERM_CHATROOM | PERM_BOARD | PERM_SYSOP | PERM_BBSADM; + PWCU_END(); +} + +void pwcuInitGuestPerm () +{ + cuser.userlevel = 0; + cuser.uflag = PAGER_FLAG | BRDSORT_FLAG | MOVIE_FLAG; + cuser.uflag2= 0; // we don't need FAVNEW_FLAG or anything else. +# ifdef GUEST_DEFAULT_DBCS_NOINTRESC + cuser.uflag |= DBCS_NOINTRESC; +# endif +} + +#define GUEST_INFO_RANDMAX (13) +void pwcuInitGuestInfo () +{ + int i; + char *nick[GUEST_INFO_RANDMAX] = { + "椰子", "貝殼", "內衣", "寶特瓶", "翻車魚", + "樹葉", "浮萍", "鞋子", "潛水艇", "魔王", + "鐵罐", "考卷", "大美女" + }; + char *name[GUEST_INFO_RANDMAX] = { + "大王椰子", "鸚鵡螺", "比基尼", "可口可樂", "仰泳的魚", + "憶", "高岡屋", "AIR Jordon", "紅色十月號", "批踢踢", + "SASAYA椰奶", "鴨蛋", "布魯克鱈魚香絲" + }; + char *addr[GUEST_INFO_RANDMAX] = { + "天堂樂園", "大海", "綠島小夜曲", "美國", "綠色珊瑚礁", + "遠方", "原本海", "NIKE", "蘇聯", "男八618室", + "愛之味", "天上", "藍色珊瑚礁" + }; + i = random() % GUEST_INFO_RANDMAX; + snprintf(cuser.nickname, sizeof(cuser.nickname), + "海邊漂來的%s", nick[(int)i]); + strlcpy(currutmp->nickname, cuser.nickname, + sizeof(currutmp->nickname)); + strlcpy(cuser.realname, name[(int)i], sizeof(cuser.realname)); + strlcpy(cuser.address, addr[(int)i], sizeof(cuser.address)); + memset(cuser.mind, 0, sizeof(cuser.mind)); + cuser.sex = i % 8; +} diff --git a/mbbsd/talk.c b/mbbsd/talk.c index f1a884d7..d7925696 100644 --- a/mbbsd/talk.c +++ b/mbbsd/talk.c @@ -2999,10 +2999,11 @@ userlist(void) if (HasUserPerm(PERM_LOGINOK)) { int tmp; char *wm[3] = {"一般", "進階", "未來"}; + + tmp = cuser.uflag2 & WATER_MASK; - cuser.uflag2 -= tmp; tmp = (tmp + 1) % 3; - cuser.uflag2 |= tmp; + pwcuSetWaterballMode(tmp); /* vmsg cannot support multi lines */ move(b_lines - 4, 0); clrtobot(); @@ -3035,7 +3036,7 @@ userlist(void) if (getdata_str(1, 0, "新的暱稱: ", tmp_nick, sizeof(tmp_nick), DOECHO, cuser.nickname) > 0) { - strlcpy(cuser.nickname, tmp_nick, sizeof(cuser.nickname)); + pwcuSetNickname(tmp_nick); strlcpy(currutmp->nickname, cuser.nickname, sizeof(currutmp->nickname)); } redrawall = redraw = 1; diff --git a/mbbsd/user.c b/mbbsd/user.c index 822b09a7..05071eea 100644 --- a/mbbsd/user.c +++ b/mbbsd/user.c @@ -65,11 +65,11 @@ u_loginview(void) } if (pbits != cuser.loginview) { - cuser.loginview = pbits; - passwd_sync_update(usernum, &cuser); + pwcuSetLoginView(pbits); } return 0; } + int u_cancelbadpost(void) { int day; @@ -269,7 +269,7 @@ mail_violatelaw(const char *crime, const char *police, const char *reason, const } void -kick_all(char *user) +kick_all(const char *user) { userinfo_t *ui; int num = searchuser(user, NULL), i=1; @@ -489,8 +489,7 @@ void Customize(void) { int currentset = cuser.uflag2 & WATER_MASK; currentset = (currentset + 1) % 3; - cuser.uflag2 &= ~WATER_MASK; - cuser.uflag2 |= currentset; + pwcuSetWaterballMode(currentset); vmsg("修正水球模式後請正常離線再重新上線"); dirty = 1; } -- cgit v1.2.3 From f70549636d72d203ed0f50fb66688319c3fcb878 Mon Sep 17 00:00:00 2001 From: piaip Date: Fri, 28 Aug 2009 14:15:05 +0000 Subject: * modify more APIs git-svn-id: http://opensvn.csie.org/pttbbs/branches/pttbbs.pwcu@4784 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- include/proto.h | 10 +++++--- mbbsd/cache.c | 2 +- mbbsd/passwd.c | 73 +++++++++++++++++++++++++++++++++------------------------ mbbsd/talk.c | 2 +- 4 files changed, 52 insertions(+), 35 deletions(-) diff --git a/include/proto.h b/include/proto.h index 00fffb2e..4263dd01 100644 --- a/include/proto.h +++ b/include/proto.h @@ -130,7 +130,7 @@ const char * postperm_msg(const char *bname); int give_tax(int money); const char* money_level(int money); int vice(int money, const char* item); -#define reload_money() cuser.money=moneyof(usernum) +#define reload_money() // cuser.money=moneyof(usernum) int lockutmpmode(int unmode, int state); int unlockutmpmode(void); int x_file(void); @@ -695,7 +695,6 @@ int passwd_sync_query (int num, userec_t * buf); // current user help utilities int pwcuBitSetLevel (unsigned int mask); int pwcuBitUnsetLevel (unsigned int mask); -int pwcuSetSignature (unsigned char newsig); int pwcuIncNumPost (); int pwcuDecNumPost (); int pwcuSetGoodPost (unsigned int newgp); @@ -704,11 +703,16 @@ int pwcuSaveViolateLaw (); int pwcuAddExMailBox (int m); int pwcuToggleOutMail (); int pwcuSetLoginView (unsigned int bits); -int pwcuSetWaterballMode(unsigned int bm); int pwcuSetLastSongTime (time4_t clk); int pwcuSetMyAngel (const char *angel_uid); int pwcuSetNickname (const char *nickname); +// non-important based variables (only save on exit) +int pwcuSetSignature (unsigned char newsig); +int pwcuSetWaterballMode(unsigned int bm); +int pwcuToggleSortBoard (); +int pwcuToggleFriendList(); + // session save int pwcuLoginSave (); int pwcuExitSave (); diff --git a/mbbsd/cache.c b/mbbsd/cache.c index e56c162a..e9d057c4 100644 --- a/mbbsd/cache.c +++ b/mbbsd/cache.c @@ -160,7 +160,7 @@ int is_BM_cache(int bid) /* bid starts from 1 */ { // auto enable BM permission if (!HasUserPerm(PERM_BM)) - cuser.userlevel |= PERM_BM; + pwcuBitSetLevel(PERM_BM); return 1; } return 0; diff --git a/mbbsd/passwd.c b/mbbsd/passwd.c index b1a240a6..e529a874 100644 --- a/mbbsd/passwd.c +++ b/mbbsd/passwd.c @@ -149,14 +149,6 @@ pwcuSetGoodPost(unsigned int newgp) PWCU_END(); } -int -pwcuSetSignature(unsigned char newsig) -{ - PWCU_START(); - cuser.signature = u.signature = newsig; - PWCU_END(); -} - int pwcuViolateLaw () { @@ -188,6 +180,30 @@ pwcuAddExMailBox(int m) PWCU_END(); } +int pwcuSetLastSongTime (time4_t clk) +{ + PWCU_START(); + u.lastsong = clk; + cuser.lastsong = clk; + PWCU_END(); +} + +int pwcuSetMyAngel (const char *angel_uid) +{ + PWCU_START(); + strlcpy(u.myangel, angel_uid, sizeof(u.myangel)); + strlcpy(cuser.myangel, angel_uid, sizeof(cuser.myangel)); + PWCU_END(); +} + +int pwcuSetNickname (const char *nickname) +{ + PWCU_START(); + strlcpy(u.nickname, nickname, sizeof(u.nickname)); + strlcpy(cuser.nickname, nickname, sizeof(cuser.nickname)); + PWCU_END(); +} + int pwcuToggleOutMail() { @@ -206,41 +222,38 @@ pwcuSetLoginView(unsigned int bits) PWCU_END(); } + +// non-important variables (only save on exit) + +int +pwcuSetSignature(unsigned char newsig) +{ + cuser.signature = newsig; + return 0; +} + int pwcuSetWaterballMode(unsigned int bm) { - PWCU_START(); - bm &= WATER_MASK; - u.uflag2 &= ~WATER_MASK; + bm &= WATER_MASK; cuser.uflag2 &= ~WATER_MASK; - u.uflag2 |= bm; cuser.uflag2 |= bm; - PWCU_END(); + return 0; } -int pwcuSetLastSongTime (time4_t clk) +int pwcuToggleSortBoard () { - PWCU_START(); - u.lastsong = clk; - cuser.lastsong = clk; - PWCU_END(); + cuser.uflag ^= BRDSORT_FLAG; + return 0; } -int pwcuSetMyAngel (const char *angel_uid) +int pwcuToggleFriendList() { - PWCU_START(); - strlcpy(u.myangel, angel_uid, sizeof(u.myangel)); - strlcpy(cuser.myangel, angel_uid, sizeof(cuser.myangel)); - PWCU_END(); + cuser.uflag ^= FRIEND_FLAG; + return 0; } -int pwcuSetNickname (const char *nickname) -{ - PWCU_START(); - strlcpy(u.nickname, nickname, sizeof(u.nickname)); - strlcpy(cuser.nickname, nickname, sizeof(cuser.nickname)); - PWCU_END(); -} +// session save #if 0 static void diff --git a/mbbsd/talk.c b/mbbsd/talk.c index d7925696..f04c4ddb 100644 --- a/mbbsd/talk.c +++ b/mbbsd/talk.c @@ -2914,7 +2914,7 @@ userlist(void) case 'f': if (HasUserPerm(PERM_LOGINOK)) { - cuser.uflag ^= FRIEND_FLAG; + pwcuToggleFriendList(); redrawall = redraw = 1; } break; -- cgit v1.2.3 From e40b5f174956a652514959e367df348c0ad66d9f Mon Sep 17 00:00:00 2001 From: piaip Date: Sat, 29 Aug 2009 12:59:17 +0000 Subject: * enable lastseen and CONST_CUSER, also use cuser_ref as "&cuser". git-svn-id: http://opensvn.csie.org/pttbbs/branches/pttbbs.pwcu@4786 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- include/proto.h | 1 + include/pttstruct.h | 13 +++++++++++-- mbbsd/board.c | 4 ++-- mbbsd/cal.c | 2 +- mbbsd/ch_go.c | 10 +++++----- mbbsd/ch_gomo.c | 10 +++++----- mbbsd/chat.c | 3 ++- mbbsd/chc.c | 10 +++++----- mbbsd/mbbsd.c | 2 +- mbbsd/passwd.c | 16 +++++++++++++--- mbbsd/register.c | 5 +++-- mbbsd/talk.c | 4 ++-- mbbsd/user.c | 11 ++++++----- mbbsd/var.c | 2 +- 14 files changed, 58 insertions(+), 35 deletions(-) diff --git a/include/proto.h b/include/proto.h index 4263dd01..bd547eea 100644 --- a/include/proto.h +++ b/include/proto.h @@ -718,6 +718,7 @@ int pwcuLoginSave (); int pwcuExitSave (); // initialization +void pwcuInitZero (); void pwcuInitGuestPerm (); void pwcuInitGuestInfo (); int pwcuInitAdminPerm (); diff --git a/include/pttstruct.h b/include/pttstruct.h index c0ea9f64..cd0c98df 100644 --- a/include/pttstruct.h +++ b/include/pttstruct.h @@ -66,7 +66,7 @@ typedef struct userec_t { uint32_t numlogins; /* 上站次數 */ uint32_t numposts; /* 文章篇數 */ time4_t firstlogin; /* 註冊時間 */ - time4_t lastlogin; /* 最近上站時間 */ + time4_t lastlogin; /* 最近上站時間(包含隱身) */ char lasthost[IPV4LEN+1];/* 上次上站來源 */ int32_t money; /* Ptt幣 */ @@ -97,7 +97,8 @@ typedef struct userec_t { uint32_t numlogindays; /* 登入天次 */ char chkpad1[48]; - time4_t chkpad2[3]; /* in case 有人忘了把 time4_t 調好... */ + time4_t lastseen; /* 最近上站時間(隱身不計) */ + time4_t chkpad2[2]; /* in case 有人忘了把 time4_t 調好... */ // 以上應為 sizeof(chicken_t) 同等大小 time4_t lastsong; /* 上次點歌時間 */ @@ -138,6 +139,14 @@ typedef struct userec_t { char pad_tail[28]; } PACKSTRUCT userec_t; +#ifdef CONST_CUSER +# define cuser ((const userec_t ) pwcuser) +# define cuser_ref ((const userec_t*)&pwcuser) +#else +# define cuser pwcuser +# define cuser_ref (&cuser) +#endif + /* flags in userec_t.withme */ #define WITHME_ALLFLAG 0x55555555 #define WITHME_TALK 0x00000001 diff --git a/mbbsd/board.c b/mbbsd/board.c index a3101175..e2bad4a8 100644 --- a/mbbsd/board.c +++ b/mbbsd/board.c @@ -1343,7 +1343,7 @@ set_menu_BM(char *BM) { if (!HasUserPerm(PERM_NOCITIZEN) && (HasUserPerm(PERM_ALLBOARD) || is_uBM(BM, cuser.userid))) { currmode |= MODE_GROUPOP; - cuser.userlevel |= PERM_SYSSUBOP | PERM_BM; + // cuser.userlevel |= PERM_SYSSUBOP | PERM_BM; } } @@ -1599,7 +1599,7 @@ choose_board(int newflag) fav_sort_by_class(); } else - cuser.uflag ^= BRDSORT_FLAG; + pwcuToggleSortBoard(); brdnum = -1; break; diff --git a/mbbsd/cal.c b/mbbsd/cal.c index 342049b8..c920aeb1 100644 --- a/mbbsd/cal.c +++ b/mbbsd/cal.c @@ -402,7 +402,7 @@ resolve_over18_user(const userec_t *u) void resolve_over18(void) { - over18 = resolve_over18_user(&cuser); + over18 = resolve_over18_user(cuser_ref); } int diff --git a/mbbsd/ch_go.c b/mbbsd/ch_go.c index 9c7256cd..a9e68005 100644 --- a/mbbsd/ch_go.c +++ b/mbbsd/ch_go.c @@ -819,9 +819,9 @@ go_gameend(ChessInfo* info, ChessGameResult result) currutmp->go_tie++; } - go_usr_put(&cuser, user1); + go_usr_put(cuser_ref, user1); - passwd_sync_update(usernum, &cuser); + passwd_sync_update(usernum, cuser_ref); } else if (info->mode == CHESS_MODE_REPLAY) { free(info->board); free(info->tag); @@ -936,9 +936,9 @@ gochess(int s, ChessGameMode mode) if (info->mode == CHESS_MODE_VERSUS) { /* Assume that info->user1 is me. */ info->user1.lose++; - passwd_sync_query(usernum, &cuser); - go_usr_put(&cuser, &info->user1); - passwd_sync_update(usernum, &cuser); + passwd_sync_query(usernum, cuser_ref); + go_usr_put(cuser_ref, &info->user1); + passwd_sync_update(usernum, cuser_ref); } if (mode == CHESS_MODE_WATCH) diff --git a/mbbsd/ch_gomo.c b/mbbsd/ch_gomo.c index b8a74cb6..0bffe04a 100644 --- a/mbbsd/ch_gomo.c +++ b/mbbsd/ch_gomo.c @@ -410,9 +410,9 @@ gomo_gameend(ChessInfo* info, ChessGameResult result) currutmp->five_tie++; } - gomoku_usr_put(&cuser, user1); + gomoku_usr_put(cuser_ref, user1); - passwd_sync_update(usernum, &cuser); + passwd_sync_update(usernum, cuser_ref); } else if (info->mode == CHESS_MODE_REPLAY) { free(info->board); free(info->tag); @@ -535,9 +535,9 @@ gomoku(int s, ChessGameMode mode) if (info->mode == CHESS_MODE_VERSUS) { /* Assume that info->user1 is me. */ info->user1.lose++; - passwd_sync_query(usernum, &cuser); - gomoku_usr_put(&cuser, &info->user1); - passwd_sync_update(usernum, &cuser); + passwd_sync_query(usernum, cuser_ref); + gomoku_usr_put(cuser_ref, &info->user1); + passwd_sync_update(usernum, cuser_ref); } if (mode == CHESS_MODE_WATCH) diff --git a/mbbsd/chat.c b/mbbsd/chat.c index e6a78842..f51524ff 100644 --- a/mbbsd/chat.c +++ b/mbbsd/chat.c @@ -210,7 +210,8 @@ chat_query(char *arg) printchatline(buf); snprintf(buf, sizeof(buf), - "最近(%s)從[%s]上站", Cdate(&xuser.lastlogin), + "最近(%s)從[%s]上站", + Cdate(&xuser.lastseen), (xuser.lasthost[0] ? xuser.lasthost : "(不詳)")); printchatline(buf); diff --git a/mbbsd/chc.c b/mbbsd/chc.c index b250a01e..2a52f43b 100644 --- a/mbbsd/chc.c +++ b/mbbsd/chc.c @@ -848,9 +848,9 @@ chc(int s, ChessGameMode mode) /* Assume that info->user1 is me. */ info->user1.lose++; count_chess_elo_rating(&info->user1, &info->user2, 0.0); - passwd_sync_query(usernum, &cuser); - chcusr_put(&cuser, &info->user1); - passwd_sync_update(usernum, &cuser); + passwd_sync_query(usernum, cuser_ref); + chcusr_put(cuser_ref, &info->user1); + passwd_sync_update(usernum, cuser_ref); } if (mode == CHESS_MODE_WATCH) @@ -904,8 +904,8 @@ chc_gameend(ChessInfo* info, ChessGameResult result) currutmp->chc_tie++; } currutmp->chess_elo_rating = user1->rating; - chcusr_put(&cuser, user1); - passwd_sync_update(usernum, &cuser); + chcusr_put(cuser_ref, user1); + passwd_sync_update(usernum, cuser_ref); } else if (info->mode == CHESS_MODE_REPLAY) { free(info->board); free(info->tag); diff --git a/mbbsd/mbbsd.c b/mbbsd/mbbsd.c index 99394c0b..8c27da5e 100644 --- a/mbbsd/mbbsd.c +++ b/mbbsd/mbbsd.c @@ -775,7 +775,7 @@ login_query(char *ruid) sleep(3); exit(1); } - bzero(&cuser, sizeof(cuser)); + pwcuInitZero(); #ifdef DEBUG move(19, 0); diff --git a/mbbsd/passwd.c b/mbbsd/passwd.c index e529a874..5803b5b8 100644 --- a/mbbsd/passwd.c +++ b/mbbsd/passwd.c @@ -1,10 +1,16 @@ /* $Id$ */ +#define PWCU_IMPL #include "bbs.h" #ifdef _BBS_UTIL_C_ #error sorry, mbbsd/passwd.c does not support utility mode anymore. please use libcmbbs instead. #endif +#ifdef CONST_CUSER + #undef cuser + #define cuser pwcuser +#endif + void passwd_force_update(int flag) { @@ -274,11 +280,10 @@ int pwcuLoginSave () // new host from 'fromhost' strlcpy(cuser.lasthost, fromhost, sizeof(cuser.lasthost)); + cuser.lastlogin = login_start_time; - // XXX keep 'lastlogin' and 'disp_lastlogin'... - // new 'lastlogin' if (!PERM_HIDE(currutmp)) - cuser.lastlogin = login_start_time; + cuser.lastseen = login_start_time; // calculate numlogins @@ -313,6 +318,11 @@ int pwcuExitSave () // Initialization +void pwcuInitZero () +{ + bzero(&cuser, sizeof(cuser)); +} + int pwcuInitAdminPerm () { PWCU_START(); diff --git a/mbbsd/register.c b/mbbsd/register.c index 495fdfcd..224f480a 100644 --- a/mbbsd/register.c +++ b/mbbsd/register.c @@ -1,4 +1,5 @@ /* $Id$ */ +#define PWCU_IMPL #include "bbs.h" #define FN_REGISTER_LOG "register.log" // global registration history @@ -1287,7 +1288,7 @@ toregister(char *email) snprintf(cuser.justify, sizeof(cuser.justify), ""); #endif - email_justify(&cuser); + email_justify(cuser_ref); } } @@ -1581,7 +1582,7 @@ u_register(void) toregister(email); // update cuser - passwd_sync_update(usernum, &cuser); + passwd_sync_update(usernum, cuser_ref); return FULLUPDATE; } diff --git a/mbbsd/talk.c b/mbbsd/talk.c index f04c4ddb..068cd567 100644 --- a/mbbsd/talk.c +++ b/mbbsd/talk.c @@ -458,7 +458,7 @@ my_query(const char *uident) { // XXX there're still users asking why money is not updated... reload_money(); - memcpy(&muser, &cuser, sizeof(muser)); + memcpy(&muser, cuser_ref, sizeof(muser)); } if ((uentp = (userinfo_t *) search_ulist(tuid))) @@ -494,7 +494,7 @@ my_query(const char *uident) ? "《私人信箱》有新進信件還沒看\n" : "《私人信箱》所有信件都看過了\n"); prints("《上次上站》%-28.28s《上次故鄉》", - Cdate(&muser.lastlogin)); + Cdate(&muser.lastseen)); // print out muser.lasthost #ifdef USE_MASKED_FROMHOST if(!HasUserPerm(PERM_SYSOP|PERM_ACCOUNTS)) diff --git a/mbbsd/user.c b/mbbsd/user.c index 05071eea..c14d5bf1 100644 --- a/mbbsd/user.c +++ b/mbbsd/user.c @@ -1,4 +1,5 @@ /* $Id$ */ +#define PWCU_IMPL #include "bbs.h" static char * const sex[8] = { @@ -79,7 +80,7 @@ int u_cancelbadpost(void) if(search_ulistn(usernum,2)) {vmsg("請登出其他視窗, 否則不受理."); return 0;} - passwd_sync_query(usernum, &cuser); + passwd_sync_query(usernum, cuser_ref); if (currutmp && (currutmp->alerts & ALERT_PWD)) currutmp->alerts &= ~ALERT_PWD; @@ -104,7 +105,7 @@ int u_cancelbadpost(void) { int prev = cuser.badpost--; cuser.timeremovebadpost = now; - passwd_sync_update(usernum, &cuser); + passwd_sync_update(usernum, cuser_ref); log_filef("log/cancelbadpost.log", LOG_CREAT, "%s %s 刪除一篇劣文 (%d -> %d 篇)\n", Cdate(&now), cuser.userid, prev, cuser.badpost); @@ -526,7 +527,7 @@ void Customize(void) if(dirty) { - passwd_sync_update(usernum, &cuser); + passwd_sync_update(usernum, cuser_ref); outs("設定已儲存。\n"); } else { outs("結束設定。\n"); @@ -1123,8 +1124,8 @@ u_info(void) { move(2, 0); reload_money(); - user_display(&cuser, 0); - uinfo_query(&cuser, 0, usernum); + user_display(cuser_ref, 0); + uinfo_query (cuser_ref, 0, usernum); strlcpy(currutmp->nickname, cuser.nickname, sizeof(currutmp->nickname)); return 0; } diff --git a/mbbsd/var.c b/mbbsd/var.c index a9f52c73..727e9163 100644 --- a/mbbsd/var.c +++ b/mbbsd/var.c @@ -98,7 +98,7 @@ char margs[64] = "\0"; /* main argv list */ pid_t currpid; /* current process ID */ time4_t login_start_time; time4_t start_time; -userec_t cuser; /* current user structure */ +userec_t pwcuser; /* current user structure */ crosspost_t postrecord; /* anti cross post */ unsigned int currbrdattr; unsigned int currstat; -- cgit v1.2.3 From 3a5906defc274d40f0e58eec77048cdeb8ad64fa Mon Sep 17 00:00:00 2001 From: piaip Date: Sat, 29 Aug 2009 14:23:20 +0000 Subject: * (pwcu branch) end support of r2275 version password git-svn-id: http://opensvn.csie.org/pttbbs/branches/pttbbs.pwcu@4790 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/admin.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/mbbsd/admin.c b/mbbsd/admin.c index b1f6f1c7..48ebba94 100644 --- a/mbbsd/admin.c +++ b/mbbsd/admin.c @@ -89,13 +89,18 @@ static int retrieve_backup(userec_t *user) return -1; } -void +int upgrade_passwd(userec_t *puser) { if (puser->version == PASSWD_VERSION) - return; + return 1; if (!puser->userid[0]) - return; + return 1; + // unknown version + return 0; + +#if 0 + // this is a sample. if (puser->version == 2275) // chicken change { memset(puser->career, 0, sizeof(puser->career)); @@ -104,9 +109,11 @@ upgrade_passwd(userec_t *puser) memset(puser->chkpad1, 0, sizeof(puser->chkpad1)); memset(puser->chkpad2, 0, sizeof(puser->chkpad2)); puser->numlogindays = 0; + puser->lastseen = 0; puser->version = PASSWD_VERSION; - return; + return ; } +#endif } static int @@ -160,7 +167,8 @@ search_key_user(const char *passwdfile, int mode) } // XXX 這裡會取舊資料,要小心 PWD 的 upgrade - upgrade_passwd(&user); + if (!upgrade_passwd(&user)) + continue; keymatch = NULL; -- cgit v1.2.3 From 6b2f2f3e275322f0cfeccf57d35350edae0de6a0 Mon Sep 17 00:00:00 2001 From: piaip Date: Sat, 29 Aug 2009 14:31:57 +0000 Subject: * (pwcu branch) remove the 'goodpost' ~ I love this commit. git-svn-id: http://opensvn.csie.org/pttbbs/branches/pttbbs.pwcu@4791 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/assess.c | 213 +-------------------------------------------------------- mbbsd/bbs.c | 39 ----------- mbbsd/menu.c | 2 - mbbsd/passwd.c | 11 --- mbbsd/talk.c | 2 +- mbbsd/user.c | 7 +- 6 files changed, 3 insertions(+), 271 deletions(-) diff --git a/mbbsd/assess.c b/mbbsd/assess.c index e11ac70f..aa9abe71 100644 --- a/mbbsd/assess.c +++ b/mbbsd/assess.c @@ -26,217 +26,6 @@ int inc_##_attr(const char *userid, int num) \ return 0;\ } -modify_column(goodpost); /* inc_goodpost */ modify_column(badpost); /* inc_badpost */ -// how long is AID? see read.c... -#ifndef AIDC_LEN -#define AIDC_LEN (20) -#endif // AIDC_LEN - -// #define MAXGP (100) -#define MAXGP (UCHAR_MAX) - -int -u_fixgoodpost(void) -{ - char endinput = 0; - unsigned int newgp = 0; - int bid; - char bname[IDLEN+1]; - char xaidc[AIDC_LEN+1]; - - aidu_t gpaids[MAXGP+1]; - int gpbids[MAXGP+1]; - int cgps = 0; - - clear(); - vs_hdr("自動優文修正程式"); - - outs("開始修正優文之前,有些功\課要麻煩您先查好:\n\n" - "請先找到你所有的優文文章的看板與" AID_DISPLAYNAME "\n" - AID_DISPLAYNAME "的查詢方法是在該篇文章前面按下大寫 Q 。\n" - "查好後請把這些資料放在手邊,等下會請您輸入。\n" - "另外,若有多重登入請先關閉其它連線。\n" - "\n"); - outs("如果一切都準備好了,請按下 y 開始,或其它任意鍵跳出。\n\n"); - if (vans("優文的資料都查好了嗎?") != 'y') - { - vmsg("跳出修正程式。"); - return 0; - } - while (!endinput && newgp < MAXGP) - { - int y; - boardheader_t *bh = NULL; - - move(1, 0); clrtobot(); - outs("請依序輸入優文資訊,全部完成後按 ENTER 即可停止。\n"); - - move(b_lines-2, 0); clrtobot(); - prints("目前已確認優文數目: %d" ANSI_RESET "\n\n", newgp); - - if (!getdata(5, 0, "請輸入優文文章所在看板名稱: ", - bname, sizeof(bname), DOECHO)) - { - move(5, 0); - if (vans(ANSI_COLOR(1;33)"確定全部輸入完成了嗎? " - ANSI_RESET "[y/N]: ") != 'y') - continue; - endinput = 1; break; - } - move (6, 0); - outs("確認看板... "); - if (bname[0] == '\0' || !(bid = getbnum(bname))) - { - outs(ANSI_COLOR(1;31) "看板不存在!"); - vmsg("請重新輸入。"); - continue; - } - assert(0<=bid-1 && bid-1brdname, sizeof(bname)); - prints("已找到看板 --> %s\n", bname); - y = vgety(); - - // loop AID query - while (newgp < MAXGP) - { - int n; - int fd; - char dirfile[PATHLEN]; - char *sp; - aidu_t aidu = 0; - fileheader_t fh; - - move(y, 0); clrtobot(); - move(b_lines-2, 0); clrtobot(); - prints("目前已確認優文數目: %d" ANSI_RESET "\n\n", newgp); - - if (getdata(y, 0, "請輸入" AID_DISPLAYNAME ": #", - xaidc, AIDC_LEN, DOECHO) == 0) - break; - - sp = xaidc; - while(*sp == ' ') sp ++; - if(*sp == '#') sp ++; - - if((aidu = aidc2aidu(sp)) <= 0) - { - outs(ANSI_COLOR(1;31) AID_DISPLAYNAME "格式不正確!"); - vmsg("請重新輸入。"); - continue; - } - - // check repeated input of same board+AID. - for (n = 0; n < cgps; n++) - { - if (gpaids[n] == aidu && gpbids[n] == bid) - { - vmsg("您已輸入過此優文了,請重新輸入。"); - aidu = 0; - break; - } - } - - if (aidu <= 0) - continue; - - // find aidu in board - n = -1; - // see read.c, search .bottom first. - if (n < 0) - { - outs("搜尋置底文章..."); - setbfile(dirfile, bname, FN_DIR ".bottom"); - n = search_aidu(dirfile, aidu); - } - if (n < 0) { - // search board - outs("未找到。\n搜尋看板文章.."); - setbfile(dirfile, bname, FN_DIR); - n = search_aidu(dirfile, aidu); - } - if (n < 0) - { - // search digest - outs("未找到。\n搜尋文摘.."); - setbfile(dirfile, currboard, fn_mandex); - n = search_aidu(dirfile, aidu); - } - if (n < 0) - { - // search failed... - outs("未找到\n" ANSI_COLOR(1;31) "找不到文章!"); - vmsg("請確認後重新輸入。"); - continue; - } - - // found something - fd = open(dirfile, O_RDONLY); - if (fd < 0) - { - outs(ANSI_COLOR(1;31) "系統錯誤。 請稍候再重試。\n"); - vmsg("若持續發生請至" BN_BUGREPORT "報告。"); - continue; - } - - lseek(fd, n*sizeof(fileheader_t), SEEK_SET); - memset(&fh, 0, sizeof(fh)); - read(fd, &fh, sizeof(fh)); - outs("\n開始核對資料...\n"); - n = 1; - // XXX 要接受大小寫不同嗎? (改 id) - // 常改 id 不是好事,要改就要承受無法回復的風險,完。 - if (strcmp(fh.owner, cuser.userid) != 0) - n = 0; - prints("作者: %s (%s)\n", fh.owner, n ? "正確" : - ANSI_COLOR(1;31) "錯誤" ANSI_RESET); - if (!(fh.filemode & FILE_MARKED)) - n = 0; - prints("M文: %s\n", (fh.filemode & FILE_MARKED) ? "正確" : - ANSI_COLOR(1;31) "錯誤" ANSI_RESET); - prints("推薦: %d\n", fh.recommend); - close(fd); - if (!n) - { - vmsg("輸入的文章並非優文,請重新輸入。"); - continue; - } - n = fh.recommend / 10; - prints("計算優文數值: %+d\n", n); - - if (n > 0) - { - // log new data - newgp += n; - gpaids[cgps] = aidu; - gpbids[cgps] = bid; - cgps ++; - } - - clrtobot(); - - - vmsg("優文已確認。若要輸入其它看板文章請在AID欄空白按 ENTER"); - } - vmsgf("%s 看板輸入完成。", bname); - } - if (newgp > MAXGP) - newgp = MAXGP; - if (newgp <= cuser.goodpost) - { - vmsg("確認優文數目未高於已有優文數,不調整。"); - } else { - log_filef("log/fixgoodpost.log", LOG_CREAT, - "%s %s 自動修正優文數: 由 %d 變為 %d\n", Cdate(&now), cuser.userid, - cuser.goodpost, newgp); - // update passwd file here? - pwcuSetGoodPost(newgp); - vmsgf("更新優文數目為%d。", newgp); - } - - return 0; -} - -#endif +#endif // ASSESS diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c index d1f268e3..f0356a46 100644 --- a/mbbsd/bbs.c +++ b/mbbsd/bbs.c @@ -2342,14 +2342,6 @@ recommend_cancel(int ent, fileheader_t * fhdr, const char *direct) getdata(b_lines - 1, 0, "確定要推薦歸零[y/N]? ", yn, 5, LCECHO); if (yn[0] != 'y') return FULLUPDATE; -#ifdef ASSESS - // to save resource - if (fhdr->recommend > 9) - { - inc_goodpost(fhdr->owner, -1 * (fhdr->recommend / 10)); - sendalert(fhdr->owner, ALERT_PWD_GOODPOST); - } -#endif fhdr->recommend = 0; substitute_ref_record(direct, fhdr, ent); @@ -2765,20 +2757,6 @@ recommend(int ent, fileheader_t * fhdr, const char *direct) } do_add_recommend(direct, fhdr, ent, buf, type); - -#ifdef ASSESS - /* 每 10 次推文 加一次 goodpost */ - // TODO 轉來的怎麼辦? - // when recommend reaches MAX_RECOMMENDS... - if (type == RECTYPE_GOOD && (fhdr->filemode & FILE_MARKED) && - (fhdr->recommend != oldrecom) && - fhdr->recommend % 10 == 0) - { - inc_goodpost(fhdr->owner, 1); - sendalert(fhdr->owner, ALERT_PWD_GOODPOST); - } -#endif - lastrecommend = now; lastrecommend_bid = currbid; strlcpy(lastrecommend_fname, fhdr->filename, sizeof(lastrecommend_fname)); @@ -2801,23 +2779,6 @@ mark_post(int ent, fileheader_t * fhdr, const char *direct) return DONOTHING; fhdr->filemode ^= FILE_MARKED; - -#ifdef ASSESS - if (fhdr->filemode & FILE_MARKED) - { - if (!(currbrdattr & BRD_BAD) && fhdr->recommend >= 10) - { - inc_goodpost(fhdr->owner, fhdr->recommend / 10); - sendalert(fhdr->owner, ALERT_PWD_GOODPOST); - } - } - else if (fhdr->recommend > 9) - { - inc_goodpost(fhdr->owner, -1 * (fhdr->recommend / 10)); - sendalert(fhdr->owner, ALERT_PWD_GOODPOST); - } -#endif - substitute_ref_record(direct, fhdr, ent); check_locked(fhdr); return PART_REDRAW; diff --git a/mbbsd/menu.c b/mbbsd/menu.c index bd598cea..fdba2381 100644 --- a/mbbsd/menu.c +++ b/mbbsd/menu.c @@ -585,7 +585,6 @@ u_myfiles() } -int u_fixgoodpost(void); // assess.c void Customize(); // user.c static int @@ -611,7 +610,6 @@ static const commands_t userlist[] = { {u_register, MENU_UNREGONLY, "RRegister 填寫《註冊申請單》"}, #ifdef ASSESS {u_cancelbadpost,PERM_LOGINOK, "BBye BadPost 申請刪除劣文"}, - {u_fixgoodpost, PERM_LOGINOK, "FFix GoodPost 修復優文"}, #endif // ASSESS {NULL, 0, NULL} }; diff --git a/mbbsd/passwd.c b/mbbsd/passwd.c index 5803b5b8..73f3f6fc 100644 --- a/mbbsd/passwd.c +++ b/mbbsd/passwd.c @@ -47,8 +47,6 @@ passwd_sync_update(int num, userec_t * buf) if(alerts & ALERT_PWD_BADPOST) cuser.badpost = buf->badpost = u.badpost; - if(alerts & ALERT_PWD_GOODPOST) - cuser.goodpost = buf->goodpost = u.goodpost; if(alerts & ALERT_PWD_PERM) cuser.userlevel = buf->userlevel = u.userlevel; if(alerts & ALERT_PWD_JUSTIFY) @@ -146,15 +144,6 @@ pwcuDecNumPost() PWCU_END(); } -int -pwcuSetGoodPost(unsigned int newgp) -{ - PWCU_START(); - cuser.goodpost = u.goodpost = newgp; - // passwd_force_update(ALERT_PWD_GOODPOST); - PWCU_END(); -} - int pwcuViolateLaw () { diff --git a/mbbsd/talk.c b/mbbsd/talk.c index 068cd567..14f55478 100644 --- a/mbbsd/talk.c +++ b/mbbsd/talk.c @@ -481,7 +481,7 @@ my_query(const char *uident) #endif move(2, 40); #ifdef ASSESS - prints("《有效文章篇數》%d篇 (優:%d/劣:%d)\n", muser.numposts, muser.goodpost, muser.badpost); + prints("《有效文章篇數》%d篇 (劣:%d)\n", muser.numposts, muser.badpost); #else prints("《有效文章篇數》%d篇\n", muser.numposts); #endif diff --git a/mbbsd/user.c b/mbbsd/user.c index c14d5bf1..84a2d83e 100644 --- a/mbbsd/user.c +++ b/mbbsd/user.c @@ -197,8 +197,7 @@ user_display(const userec_t * u, int adminmode) // conditional fields #ifdef ASSESS - prints("\t\t優 劣 文: 優:%d / 劣:%d\n", - u->goodpost, u->badpost); + prints("\t\t劣文數目: %d\n", u->badpost); #endif // ASSESS #ifdef CHESSCOUNTRY @@ -816,10 +815,6 @@ uinfo_query(userec_t *u, int adminmode, int unum) if ((tmp = atoi(buf)) >= 0) x.numposts = tmp; #ifdef ASSESS - snprintf(genbuf, sizeof(genbuf), "%d", u->goodpost); - if (getdata_str(y++, 0, "優良文章數:", buf, 10, DOECHO, genbuf)) - if ((tmp = atoi(buf)) >= 0) - x.goodpost = tmp; snprintf(genbuf, sizeof(genbuf), "%d", u->badpost); if (getdata_str(y++, 0, "惡劣文章數:", buf, 10, DOECHO, genbuf)) if ((tmp = atoi(buf)) >= 0) -- cgit v1.2.3 From 9d9efb47decf91be83230ff1f2318d6f2d981265 Mon Sep 17 00:00:00 2001 From: piaip Date: Sat, 29 Aug 2009 15:53:49 +0000 Subject: * (pwcu branch) code refine * also changed numlogin formula to 'only increase max to one per each day', which allow us to update the value in login state instead of logout stage git-svn-id: http://opensvn.csie.org/pttbbs/branches/pttbbs.pwcu@4792 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- include/proto.h | 4 +-- mbbsd/cache.c | 2 +- mbbsd/mbbsd.c | 4 +-- mbbsd/passwd.c | 89 +++++++++++++++++++++++++-------------------------------- util/xchatd.c | 2 +- 5 files changed, 45 insertions(+), 56 deletions(-) diff --git a/include/proto.h b/include/proto.h index bd547eea..6b14f475 100644 --- a/include/proto.h +++ b/include/proto.h @@ -693,8 +693,8 @@ int passwd_sync_update (int num, userec_t * buf); int passwd_sync_query (int num, userec_t * buf); // current user help utilities -int pwcuBitSetLevel (unsigned int mask); -int pwcuBitUnsetLevel (unsigned int mask); +int pwcuBitEnableLevel (unsigned int mask); +int pwcuBitDisableLevel (unsigned int mask); int pwcuIncNumPost (); int pwcuDecNumPost (); int pwcuSetGoodPost (unsigned int newgp); diff --git a/mbbsd/cache.c b/mbbsd/cache.c index e9d057c4..cac2135c 100644 --- a/mbbsd/cache.c +++ b/mbbsd/cache.c @@ -160,7 +160,7 @@ int is_BM_cache(int bid) /* bid starts from 1 */ { // auto enable BM permission if (!HasUserPerm(PERM_BM)) - pwcuBitSetLevel(PERM_BM); + pwcuBitEnableLevel(PERM_BM); return 1; } return 0; diff --git a/mbbsd/mbbsd.c b/mbbsd/mbbsd.c index 8c27da5e..e193bf12 100644 --- a/mbbsd/mbbsd.c +++ b/mbbsd/mbbsd.c @@ -994,7 +994,7 @@ check_BM(void) return; // disable BM permission - pwcuBitUnsetLevel(PERM_BM); + pwcuBitDisableLevel(PERM_BM); } static void @@ -1145,7 +1145,7 @@ inline static void foreign_warning(void){ mail_muser(cuser, "[出入境管理局]", "etc/foreign_expired_warn"); } else if (login_start_time - cuser.firstlogin > FOREIGN_REG_DAY * 24 * 3600){ - pwcuBitUnsetLevel(PERM_LOGINOK | PERM_POST); + pwcuBitDisableLevel(PERM_LOGINOK | PERM_POST); vmsg("警告:請至出入境管理局申請永久居留"); } } diff --git a/mbbsd/passwd.c b/mbbsd/passwd.c index 73f3f6fc..2bdc93fd 100644 --- a/mbbsd/passwd.c +++ b/mbbsd/passwd.c @@ -110,19 +110,22 @@ pwcuFinalCUser(userec_t *u) #define PWCU_START() userec_t u; if(pwcuInitCUser (&u) != 0) return -1 #define PWCU_END() if (pwcuFinalCUser(&u) != 0) return -1; return 0 -int pwcuBitSetLevel (unsigned int mask) +#define _ENABLE_BIT( var,mask) var |= (mask) +#define _DISABLE_BIT(var,mask) var &= ~(mask) + +int pwcuBitEnableLevel (unsigned int mask) { PWCU_START(); - cuser.userlevel |= mask; - u.userlevel |= mask; + _ENABLE_BIT( u.userlevel, mask); + _ENABLE_BIT(cuser.userlevel, mask); PWCU_END(); } -int pwcuBitUnsetLevel (unsigned int mask) +int pwcuBitDisableLevel (unsigned int mask) { PWCU_START(); - cuser.userlevel &= ~mask; - u.userlevel &= ~mask; + _DISABLE_BIT( u.userlevel, mask); + _DISABLE_BIT(cuser.userlevel, mask); PWCU_END(); } @@ -148,8 +151,8 @@ int pwcuViolateLaw () { PWCU_START(); - u.userlevel |= PERM_VIOLATELAW; - cuser.userlevel |= PERM_VIOLATELAW; + _ENABLE_BIT( u.userlevel, PERM_VIOLATELAW); + _ENABLE_BIT(cuser.userlevel, PERM_VIOLATELAW); u.timeviolatelaw = now; cuser.timeviolatelaw = u.timeviolatelaw; u.vl_count++; @@ -161,8 +164,8 @@ int pwcuSaveViolateLaw() { PWCU_START(); - u.userlevel &= (~PERM_VIOLATELAW); - cuser.userlevel &= (~PERM_VIOLATELAW); + _DISABLE_BIT( u.userlevel, PERM_VIOLATELAW); + _DISABLE_BIT(cuser.userlevel, PERM_VIOLATELAW); PWCU_END(); } @@ -186,7 +189,7 @@ int pwcuSetLastSongTime (time4_t clk) int pwcuSetMyAngel (const char *angel_uid) { PWCU_START(); - strlcpy(u.myangel, angel_uid, sizeof(u.myangel)); + strlcpy( u.myangel, angel_uid, sizeof( u.myangel)); strlcpy(cuser.myangel, angel_uid, sizeof(cuser.myangel)); PWCU_END(); } @@ -194,7 +197,7 @@ int pwcuSetMyAngel (const char *angel_uid) int pwcuSetNickname (const char *nickname) { PWCU_START(); - strlcpy(u.nickname, nickname, sizeof(u.nickname)); + strlcpy( u.nickname, nickname, sizeof( u.nickname)); strlcpy(cuser.nickname, nickname, sizeof(cuser.nickname)); PWCU_END(); } @@ -203,8 +206,9 @@ int pwcuToggleOutMail() { PWCU_START(); - u.uflag2 ^= REJ_OUTTAMAIL; - cuser.uflag2 ^= REJ_OUTTAMAIL; + u.uflag2 ^= REJ_OUTTAMAIL; + cuser.uflag2 &= ~REJ_OUTTAMAIL; + cuser.uflag2 |= (REJ_OUTTAMAIL & u.uflag2); PWCU_END(); } @@ -250,17 +254,6 @@ int pwcuToggleFriendList() // session save -#if 0 -static void -_setflags(int mask, int value) -{ - if (value) - cuser.uflag |= mask; - else - cuser.uflag &= ~mask; -} -#endif - // XXX this is a little different - only invoked at login, // which we should update/calculate every variables to log. int pwcuLoginSave () @@ -269,13 +262,18 @@ int pwcuLoginSave () // new host from 'fromhost' strlcpy(cuser.lasthost, fromhost, sizeof(cuser.lasthost)); + + // calculate numlogins (only increase one per each key) + if (((login_start_time - cuser.firstlogin) % 86400) != + ((cuser.lastlogin - cuser.firstlogin) % 86400) ) + cuser.numlogins++; + + // update last login time cuser.lastlogin = login_start_time; if (!PERM_HIDE(currutmp)) cuser.lastseen = login_start_time; - // calculate numlogins - PWCU_END(); } @@ -285,11 +283,12 @@ int pwcuExitSave () { PWCU_START(); - u.uflag &= ~(PAGER_FLAG | CLOAK_FLAG); + _DISABLE_BIT(u.uflag, (PAGER_FLAG | CLOAK_FLAG)); if (currutmp->pager != PAGER_ON) - u.uflag |= PAGER_FLAG; + _ENABLE_BIT(u.uflag, PAGER_FLAG); if (currutmp->invisible) - u.uflag |= CLOAK_FLAG; + _ENABLE_BIT(u.uflag, CLOAK_FLAG); + u.invisible = currutmp->invisible; u.withme = currutmp->withme; u.pager = currutmp->pager; @@ -300,8 +299,6 @@ int pwcuExitSave () reload_money(); - // TODO deal with numlogin? - PWCU_END(); } @@ -329,36 +326,28 @@ void pwcuInitGuestPerm () cuser.uflag = PAGER_FLAG | BRDSORT_FLAG | MOVIE_FLAG; cuser.uflag2= 0; // we don't need FAVNEW_FLAG or anything else. # ifdef GUEST_DEFAULT_DBCS_NOINTRESC - cuser.uflag |= DBCS_NOINTRESC; + _ENABLE_BIT(cuser.uflag, DBCS_NOINTRESC); # endif } -#define GUEST_INFO_RANDMAX (13) +#undef DIM +#define DIM(x) (sizeof(x)/sizeof(x[0])) + void pwcuInitGuestInfo () { int i; - char *nick[GUEST_INFO_RANDMAX] = { + char *nick[] = { "椰子", "貝殼", "內衣", "寶特瓶", "翻車魚", "樹葉", "浮萍", "鞋子", "潛水艇", "魔王", "鐵罐", "考卷", "大美女" }; - char *name[GUEST_INFO_RANDMAX] = { - "大王椰子", "鸚鵡螺", "比基尼", "可口可樂", "仰泳的魚", - "憶", "高岡屋", "AIR Jordon", "紅色十月號", "批踢踢", - "SASAYA椰奶", "鴨蛋", "布魯克鱈魚香絲" - }; - char *addr[GUEST_INFO_RANDMAX] = { - "天堂樂園", "大海", "綠島小夜曲", "美國", "綠色珊瑚礁", - "遠方", "原本海", "NIKE", "蘇聯", "男八618室", - "愛之味", "天上", "藍色珊瑚礁" - }; - i = random() % GUEST_INFO_RANDMAX; + + i = random() % DIM(nick); snprintf(cuser.nickname, sizeof(cuser.nickname), - "海邊漂來的%s", nick[(int)i]); + "海邊漂來的%s", nick[i]); strlcpy(currutmp->nickname, cuser.nickname, sizeof(currutmp->nickname)); - strlcpy(cuser.realname, name[(int)i], sizeof(cuser.realname)); - strlcpy(cuser.address, addr[(int)i], sizeof(cuser.address)); - memset(cuser.mind, 0, sizeof(cuser.mind)); + strlcpy(cuser.realname, "guest", sizeof(cuser.realname)); + memset (cuser.mind, 0, sizeof(cuser.mind)); cuser.sex = i % 8; } diff --git a/util/xchatd.c b/util/xchatd.c index e0c82201..912d0d7a 100644 --- a/util/xchatd.c +++ b/util/xchatd.c @@ -151,7 +151,7 @@ static char msg_not_here[] = " #define FUZZY_USER ((ChatUser *) -1) - +#undef cuser typedef struct userec_t ACCT; /* ----------------------------------------------------- */ -- cgit v1.2.3 From 8c66da7267b5b91eb47b3321892a505e7824d5e6 Mon Sep 17 00:00:00 2001 From: piaip Date: Sun, 30 Aug 2009 00:29:10 +0000 Subject: * (pwch branch) change chess results to use pwcu API git-svn-id: http://opensvn.csie.org/pttbbs/branches/pttbbs.pwcu@4793 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- include/proto.h | 2 ++ mbbsd/bbs.c | 3 -- mbbsd/ch_go.c | 31 +++------------- mbbsd/ch_gomo.c | 31 +++------------- mbbsd/chc.c | 37 ++++++++------------ mbbsd/passwd.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 6 files changed, 128 insertions(+), 83 deletions(-) diff --git a/include/proto.h b/include/proto.h index 6b14f475..1276c1f1 100644 --- a/include/proto.h +++ b/include/proto.h @@ -706,6 +706,8 @@ int pwcuSetLoginView (unsigned int bits); int pwcuSetLastSongTime (time4_t clk); int pwcuSetMyAngel (const char *angel_uid); int pwcuSetNickname (const char *nickname); +int pwcuChessResult (int sigType, ChessGameResult); +int pwcuSetChessEloRating(uint16_t elo_rating); // non-important based variables (only save on exit) int pwcuSetSignature (unsigned char newsig); diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c index f0356a46..aeffdc27 100644 --- a/mbbsd/bbs.c +++ b/mbbsd/bbs.c @@ -2428,9 +2428,6 @@ recommend(int ent, fileheader_t * fhdr, const char *direct) int isGuest = (strcmp(cuser.userid, STR_GUEST) == EQUSTR); int logIP = 0; int ymsg = b_lines -1; -#ifdef ASSESS - char oldrecom = fhdr->recommend; -#endif // ASSESS if (!fhdr || !fhdr->filename[0]) return DONOTHING; diff --git a/mbbsd/ch_go.c b/mbbsd/ch_go.c index a9e68005..308061b8 100644 --- a/mbbsd/ch_go.c +++ b/mbbsd/ch_go.c @@ -792,36 +792,15 @@ go_post_game(ChessInfo* info) return result; } -static void -go_usr_put(userec_t* userec, const ChessUser* user) -{ - userec->go_win = user->win; - userec->go_lose = user->lose; - userec->go_tie = user->tie; -} - static void go_gameend(ChessInfo* info, ChessGameResult result) { if (info->mode == CHESS_MODE_VERSUS) { - ChessUser* const user1 = &info->user1; - /* ChessUser* const user2 = &info->user2; */ - - user1->lose--; - if (result == CHESS_RESULT_WIN) { - user1->win++; - currutmp->go_win++; - } else if (result == CHESS_RESULT_LOST) { - user1->lose++; - currutmp->go_lose++; - } else { - user1->tie++; - currutmp->go_tie++; - } - go_usr_put(cuser_ref, user1); + // lost was already initialized + if (result != CHESS_RESULT_LOST) + pwcuChessResult(SIG_GO, result); - passwd_sync_update(usernum, cuser_ref); } else if (info->mode == CHESS_MODE_REPLAY) { free(info->board); free(info->tag); @@ -936,9 +915,7 @@ gochess(int s, ChessGameMode mode) if (info->mode == CHESS_MODE_VERSUS) { /* Assume that info->user1 is me. */ info->user1.lose++; - passwd_sync_query(usernum, cuser_ref); - go_usr_put(cuser_ref, &info->user1); - passwd_sync_update(usernum, cuser_ref); + pwcuChessResult(SIG_GO, CHESS_RESULT_LOST); } if (mode == CHESS_MODE_WATCH) diff --git a/mbbsd/ch_gomo.c b/mbbsd/ch_gomo.c index 0bffe04a..fb1a4182 100644 --- a/mbbsd/ch_gomo.c +++ b/mbbsd/ch_gomo.c @@ -230,14 +230,6 @@ gomo_move_warn(int style, char buf[]) return NULL; } -static void -gomoku_usr_put(userec_t* userec, const ChessUser* user) -{ - userec->five_win = user->win; - userec->five_lose = user->lose; - userec->five_tie = user->tie; -} - static char* gomo_getstep(const gomo_step_t* step, char buf[]) { @@ -395,24 +387,11 @@ static void gomo_gameend(ChessInfo* info, ChessGameResult result) { if (info->mode == CHESS_MODE_VERSUS) { - ChessUser* const user1 = &info->user1; - /* ChessUser* const user2 = &info->user2; */ - - user1->lose--; - if (result == CHESS_RESULT_WIN) { - user1->win++; - currutmp->five_win++; - } else if (result == CHESS_RESULT_LOST) { - user1->lose++; - currutmp->five_lose++; - } else { - user1->tie++; - currutmp->five_tie++; - } - gomoku_usr_put(cuser_ref, user1); + // lost was already initialized + if (result != CHESS_RESULT_LOST) + pwcuChessResult(SIG_GOMO, result); - passwd_sync_update(usernum, cuser_ref); } else if (info->mode == CHESS_MODE_REPLAY) { free(info->board); free(info->tag); @@ -535,9 +514,7 @@ gomoku(int s, ChessGameMode mode) if (info->mode == CHESS_MODE_VERSUS) { /* Assume that info->user1 is me. */ info->user1.lose++; - passwd_sync_query(usernum, cuser_ref); - gomoku_usr_put(cuser_ref, &info->user1); - passwd_sync_update(usernum, cuser_ref); + pwcuChessResult(SIG_GOMO, CHESS_RESULT_LOST); } if (mode == CHESS_MODE_WATCH) diff --git a/mbbsd/chc.c b/mbbsd/chc.c index 2a52f43b..6d4a2f4e 100644 --- a/mbbsd/chc.c +++ b/mbbsd/chc.c @@ -657,15 +657,6 @@ chc_ischeck(board_t board, int turn) * End of the rule function. */ -static void -chcusr_put(userec_t* userec, const ChessUser* user) -{ - userec->chc_win = user->win; - userec->chc_lose = user->lose; - userec->chc_tie = user->tie; - userec->chess_elo_rating = user->rating; -} - static void chc_init_user(const userinfo_t *uinfo, ChessUser *user) { @@ -848,9 +839,7 @@ chc(int s, ChessGameMode mode) /* Assume that info->user1 is me. */ info->user1.lose++; count_chess_elo_rating(&info->user1, &info->user2, 0.0); - passwd_sync_query(usernum, cuser_ref); - chcusr_put(cuser_ref, &info->user1); - passwd_sync_update(usernum, cuser_ref); + pwcuChessResult(SIG_CHC, CHESS_RESULT_LOST); } if (mode == CHESS_MODE_WATCH) @@ -876,36 +865,38 @@ chc_gameend(ChessInfo* info, ChessGameResult result) /* NOTE, 若紅方斷線則無 log */ time_t t = time(NULL); char buf[100]; + uint16_t lose1 = user1->lose, lose2 = user2->lose; + if (lose1 > 0) lose1--; + if (lose2 > 0) lose2--; sprintf(buf, "%s %s(%d,W%d/D%d/L%d) %s %s(%d,W%d/D%d/L%d)\n", ctime(&t), user1->userid, user1->rating, user1->win, - user1->tie, user1->lose - 1, + user1->tie, lose1, (result == CHESS_RESULT_TIE ? "和" : result == CHESS_RESULT_WIN ? "勝" : "負"), user2->userid, user2->rating, user2->win, - user2->tie, user2->lose - 1); + user2->tie, lose2); buf[24] = ' '; // replace '\n' log_file(BBSHOME "/log/chc.log", LOG_CREAT, buf); } + // lost was already initialized + if (result != CHESS_RESULT_LOST) + pwcuChessResult(SIG_CHC, result); + user1->rating = user1->orig_rating; - user1->lose--; + + // TODO update and save the elo rating if (result == CHESS_RESULT_WIN) { count_chess_elo_rating(user1, user2, 1.0); - user1->win++; - currutmp->chc_win++; } else if (result == CHESS_RESULT_LOST) { count_chess_elo_rating(user1, user2, 0.0); - user1->lose++; - currutmp->chc_lose++; } else { count_chess_elo_rating(user1, user2, 0.5); - user1->tie++; - currutmp->chc_tie++; } currutmp->chess_elo_rating = user1->rating; - chcusr_put(cuser_ref, user1); - passwd_sync_update(usernum, cuser_ref); + pwcuSetChessEloRating(user1->rating); + } else if (info->mode == CHESS_MODE_REPLAY) { free(info->board); free(info->tag); diff --git a/mbbsd/passwd.c b/mbbsd/passwd.c index 2bdc93fd..61e472a8 100644 --- a/mbbsd/passwd.c +++ b/mbbsd/passwd.c @@ -111,7 +111,8 @@ pwcuFinalCUser(userec_t *u) #define PWCU_END() if (pwcuFinalCUser(&u) != 0) return -1; return 0 #define _ENABLE_BIT( var,mask) var |= (mask) -#define _DISABLE_BIT(var,mask) var &= ~(mask) +#define _DISABLE_BIT(var,mask) var &= ~(mask) +#define _SETBY_BIT(var,mask,val) if (val) { _ENABLE_BIT(var, (mask)); } else { _DISABLE_BIT(var, (mask)); } int pwcuBitEnableLevel (unsigned int mask) { @@ -207,8 +208,8 @@ pwcuToggleOutMail() { PWCU_START(); u.uflag2 ^= REJ_OUTTAMAIL; - cuser.uflag2 &= ~REJ_OUTTAMAIL; - cuser.uflag2 |= (REJ_OUTTAMAIL & u.uflag2); + _SETBY_BIT(cuser.uflag2, REJ_OUTTAMAIL, + u.uflag2 & REJ_OUTTAMAIL); PWCU_END(); } @@ -221,6 +222,106 @@ pwcuSetLoginView(unsigned int bits) PWCU_END(); } +#include "chess.h" +int +pwcuChessResult(int sigType, ChessGameResult r) +{ + uint16_t *utmp_win = NULL, *cuser_win = NULL, *u_win = NULL, + *utmp_lose= NULL, *cuser_lose= NULL, *u_lose= NULL, + *utmp_tie = NULL, *cuser_tie = NULL, *u_tie = NULL; + + PWCU_START(); + + // verify variable size + assert(sizeof(* utmp_win) == sizeof(currutmp->chc_win)); + assert(sizeof(*cuser_lose)== sizeof( cuser.five_lose)); + assert(sizeof(* u_tie) == sizeof( u.go_tie)); + + // determine variables + switch(sigType) + { + case SIG_CHC: + utmp_win = &(currutmp->chc_win); + utmp_lose = &(currutmp->chc_lose); + utmp_tie = &(currutmp->chc_tie); + cuser_win = &( cuser.chc_win); + cuser_lose= &( cuser.chc_lose); + cuser_tie = &( cuser.chc_tie); + u_win = &( u.chc_win); + u_lose = &( u.chc_lose); + u_tie = &( u.chc_tie); + break; + + case SIG_GO: + utmp_win = &(currutmp->go_win); + utmp_lose = &(currutmp->go_lose); + utmp_tie = &(currutmp->go_tie); + cuser_win = &( cuser.go_win); + cuser_lose= &( cuser.go_lose); + cuser_tie = &( cuser.go_tie); + u_win = &( u.go_win); + u_lose = &( u.go_lose); + u_tie = &( u.go_tie); + break; + + case SIG_GOMO: + utmp_win = &(currutmp->five_win); + utmp_lose = &(currutmp->five_lose); + utmp_tie = &(currutmp->five_tie); + cuser_win = &( cuser.five_win); + cuser_lose= &( cuser.five_lose); + cuser_tie = &( cuser.five_tie); + u_win = &( u.five_win); + u_lose = &( u.five_lose); + u_tie = &( u.five_tie); + break; + + default: + assert(!"unknown sigtype"); + break; + } + + // perform action + switch(r) + { + case CHESS_RESULT_WIN: + *utmp_win = *cuser_win = + ++(*u_win); + // recover init lose + if (*u_lose > 0) + *utmp_lose = *cuser_lose = + --(*u_lose); + break; + + case CHESS_RESULT_TIE: + *utmp_tie = *cuser_tie = + ++*u_tie; + // recover init lose + if (*u_lose > 0) + *utmp_lose = *cuser_lose = + --(*u_lose); + break; + + case CHESS_RESULT_LOST: + *utmp_lose = *cuser_lose = + ++(*u_lose); + break; + + default: + assert(!"unknown result"); + return -1; + } + + PWCU_END(); +} + +int +pwcuSetChessEloRating(uint16_t elo_rating) +{ + PWCU_START(); + cuser.chess_elo_rating = u.chess_elo_rating = elo_rating; + PWCU_END(); +} // non-important variables (only save on exit) -- cgit v1.2.3 From 2962ffe9d364a629996465a1cf08770791823db3 Mon Sep 17 00:00:00 2001 From: piaip Date: Sun, 30 Aug 2009 03:00:49 +0000 Subject: * (pwcu branch) make user compatible to pwcu API git-svn-id: http://opensvn.csie.org/pttbbs/branches/pttbbs.pwcu@4794 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- include/proto.h | 9 ++- mbbsd/admin.c | 7 ++- mbbsd/mbbsd.c | 2 +- mbbsd/passwd.c | 68 +++++++++++++++++++++-- mbbsd/read.c | 2 +- mbbsd/talk.c | 2 +- mbbsd/user.c | 168 +++++++++++++++++++++++++++++++------------------------- 7 files changed, 172 insertions(+), 86 deletions(-) diff --git a/include/proto.h b/include/proto.h index 1276c1f1..b01e8712 100644 --- a/include/proto.h +++ b/include/proto.h @@ -612,7 +612,7 @@ int kill_user(int num, const char *userid); int u_editcalendar(void); void user_display(const userec_t *u, int real); int isvalidemail(char *email); -void uinfo_query(userec_t *u, int real, int unum); +void uinfo_query(const char *uid, int real, int unum); int showsignature(char *fname, int *j, SigInfo *psi); int u_cancelbadpost(); void kick_all(const char *user); @@ -700,6 +700,7 @@ int pwcuDecNumPost (); int pwcuSetGoodPost (unsigned int newgp); int pwcuViolateLaw (); int pwcuSaveViolateLaw (); +int pwcuCancelBadpost (); int pwcuAddExMailBox (int m); int pwcuToggleOutMail (); int pwcuSetLoginView (unsigned int bits); @@ -708,16 +709,20 @@ int pwcuSetMyAngel (const char *angel_uid); int pwcuSetNickname (const char *nickname); int pwcuChessResult (int sigType, ChessGameResult); int pwcuSetChessEloRating(uint16_t elo_rating); +int pwcuSaveUserFlags (); // non-important based variables (only save on exit) int pwcuSetSignature (unsigned char newsig); int pwcuSetWaterballMode(unsigned int bm); int pwcuToggleSortBoard (); int pwcuToggleFriendList(); +int pwcuToggleUserFlag (unsigned int mask); // not saved until pwcuSaveUserFlags +int pwcuToggleUserFlag2 (unsigned int mask); // not saved until pwcuSaveUserFlags -// session save +// session management int pwcuLoginSave (); int pwcuExitSave (); +int pwcuReload (); // initialization void pwcuInitZero (); diff --git a/mbbsd/admin.c b/mbbsd/admin.c index 48ebba94..0ed06412 100644 --- a/mbbsd/admin.c +++ b/mbbsd/admin.c @@ -43,7 +43,7 @@ m_user(void) if ((id = getuser(genbuf, &xuser))) { user_display(&xuser, 1); if( HasUserPerm(PERM_ACCOUNTS) ) - uinfo_query(&xuser, 1, id); + uinfo_query(xuser.userid, 1, id); else pressanykey(); } else { @@ -217,10 +217,13 @@ search_key_user(const char *passwdfile, int mode) // user_display does not have linefeed in tail. if (isCurrentPwd && HasUserPerm(PERM_ACCOUNTS)) - uinfo_query(&user, 1, unum); + uinfo_query(user.userid, 1, unum); else outs("\n"); + // XXX don't trust 'user' variable after here + // because uinfo_query may have changed it. + outs(ANSI_COLOR(44) " 空白鍵" \ ANSI_COLOR(37) ":搜尋下一個 " \ ANSI_COLOR(33)" Q" ANSI_COLOR(37)": 離開"); diff --git a/mbbsd/mbbsd.c b/mbbsd/mbbsd.c index e193bf12..c77b508e 100644 --- a/mbbsd/mbbsd.c +++ b/mbbsd/mbbsd.c @@ -342,7 +342,7 @@ signal_xcpu_handler(int sig) last_time_exceeded = login_start_time; assert(last_time_exceeded); // 不用 (time(0) - login_start_time) 來平均, 避免用好幾天之後突然狂吃 cpu 的狀況. - if (time(0) - last_time_exceeded < 86400) + if (time(0) - last_time_exceeded < DAY_SECONDS) give_more_time = false; last_time_exceeded = time(0); diff --git a/mbbsd/passwd.c b/mbbsd/passwd.c index 61e472a8..e8ed21e2 100644 --- a/mbbsd/passwd.c +++ b/mbbsd/passwd.c @@ -170,6 +170,25 @@ pwcuSaveViolateLaw() PWCU_END(); } +int +pwcuCancelBadpost() +{ + int day; + PWCU_START(); + + // check timebomb again + day = (now - u.timeremovebadpost ) / DAY_SECONDS; + if (day <= 180) + return -1; + if (u.badpost < 1) + return -1; + + cuser.badpost = --u.badpost; + cuser.timeremovebadpost = u.timeremovebadpost = now; + + PWCU_END(); +} + int pwcuAddExMailBox(int m) { @@ -323,6 +342,15 @@ pwcuSetChessEloRating(uint16_t elo_rating) PWCU_END(); } +int +pwcuSaveUserFlags() +{ + PWCU_START(); + u.uflag = cuser.uflag; + u.uflag2 = cuser.uflag2; + PWCU_END(); +} + // non-important variables (only save on exit) int @@ -341,18 +369,34 @@ pwcuSetWaterballMode(unsigned int bm) return 0; } -int pwcuToggleSortBoard () +int +pwcuToggleSortBoard () { cuser.uflag ^= BRDSORT_FLAG; return 0; } -int pwcuToggleFriendList() +int +pwcuToggleFriendList() { cuser.uflag ^= FRIEND_FLAG; return 0; } +int +pwcuToggleUserFlag (unsigned int mask) +{ + cuser.uflag ^= mask; + return 0; +} + +int +pwcuToggleUserFlag2 (unsigned int mask) +{ + cuser.uflag2 ^= mask; + return 0; +} + // session save // XXX this is a little different - only invoked at login, @@ -365,8 +409,8 @@ int pwcuLoginSave () strlcpy(cuser.lasthost, fromhost, sizeof(cuser.lasthost)); // calculate numlogins (only increase one per each key) - if (((login_start_time - cuser.firstlogin) % 86400) != - ((cuser.lastlogin - cuser.firstlogin) % 86400) ) + if (((login_start_time - cuser.firstlogin) % DAY_SECONDS) != + ((cuser.lastlogin - cuser.firstlogin) % DAY_SECONDS) ) cuser.numlogins++; // update last login time @@ -380,10 +424,16 @@ int pwcuLoginSave () // XXX this is a little different - only invoked at exist, // so no need to sync back to cuser. -int pwcuExitSave () +int +pwcuExitSave () { PWCU_START(); + // uflag and uflag2: always trust cuser except REJ_OUTTAMAIL + _SETBY_BIT(cuser.uflag2, REJ_OUTTAMAIL, (u.uflag2 & REJ_OUTTAMAIL)); + u.uflag = cuser.uflag; + u.uflag2= cuser.uflag2; + _DISABLE_BIT(u.uflag, (PAGER_FLAG | CLOAK_FLAG)); if (currutmp->pager != PAGER_ON) _ENABLE_BIT(u.uflag, PAGER_FLAG); @@ -403,6 +453,14 @@ int pwcuExitSave () PWCU_END(); } +int +pwcuReload () +{ + int r = passwd_sync_query(usernum, &cuser); + // XXX TODO verify cuser structure? + return r; +} + // Initialization void pwcuInitZero () diff --git a/mbbsd/read.c b/mbbsd/read.c index 4dca75c4..6071ac39 100644 --- a/mbbsd/read.c +++ b/mbbsd/read.c @@ -985,7 +985,7 @@ i_read_key(const onekey_t * rcmdlist, keeploc_t * locmem, if ((id = getuser(headers[locmem->crs_ln - locmem->top_ln].owner, &muser))) { user_display(&muser, 1); if( HasUserPerm(PERM_ACCOUNTS) ) - uinfo_query(&muser, 1, id); + uinfo_query(muser.userid, 1, id); else pressanykey(); } diff --git a/mbbsd/talk.c b/mbbsd/talk.c index 14f55478..bc728b8d 100644 --- a/mbbsd/talk.c +++ b/mbbsd/talk.c @@ -2835,7 +2835,7 @@ userlist(void) if ((id = getuser(uentp->userid, &muser)) > 0) { user_display(&muser, 1); if( HasUserPerm(PERM_ACCOUNTS) ) - uinfo_query(&muser, 1, id); + uinfo_query(muser.userid, 1, id); else pressanykey(); } diff --git a/mbbsd/user.c b/mbbsd/user.c index 84a2d83e..0b356eab 100644 --- a/mbbsd/user.c +++ b/mbbsd/user.c @@ -73,43 +73,51 @@ u_loginview(void) int u_cancelbadpost(void) { - int day; - if(cuser.badpost==0) - {vmsg("你並沒有劣文."); return 0;} - - if(search_ulistn(usernum,2)) - {vmsg("請登出其他視窗, 否則不受理."); return 0;} + int day, prev = cuser.badpost; - passwd_sync_query(usernum, cuser_ref); - if (currutmp && (currutmp->alerts & ALERT_PWD)) - currutmp->alerts &= ~ALERT_PWD; + // early check. + if(cuser.badpost==0) { + vmsg("你並沒有劣文."); + return 0; + } + + // early check for race condition + if(search_ulistn(usernum,2)) { + vmsg("請登出其他視窗, 否則不受理."); + return 0; + } + // early check for time (must do again later) day = 180 - (now - cuser.timeremovebadpost ) / DAY_SECONDS; - if(day>0 && day<=180) - { - vmsgf("每 180 天才能申請一次, 還剩 %d 天.", day); - vmsg("您也可以注意站方是否有勞動服務方式刪除劣文."); - return 0; - } - - if( - vmsg("我願意尊守站方規定,組規,以及板規[y/N]?")!='y' || - vmsg("我願意尊重不歧視族群,不鬧板,尊重各板主權力[y/N]?")!='y' || - vmsg("我願意謹慎發表有意義言論,不謾罵攻擊,不跨板廣告[y/N]?")!='y' ) - - {vmsg("請您思考清楚後再來申請刪除."); return 0;} - - if(search_ulistn(usernum,2)) - {vmsg("請登出其他視窗, 否則不受理."); return 0;} - if(cuser.badpost) + if(day>0 && day<=180) { + vmsgf("每 180 天才能申請一次, 還剩 %d 天.", day); + return 0; + } + + // 無聊的 disclaimer... + if( vmsg("我願意尊守站方規定,組規,以及板規[y/N]?")!='y' || + vmsg("我願意尊重不歧視族群,不鬧板,尊重各板主權力[y/N]?")!='y' || + vmsg("我願意謹慎發表有意義言論,不謾罵攻擊,不跨板廣告[y/N]?")!='y' ) { - int prev = cuser.badpost--; - cuser.timeremovebadpost = now; - passwd_sync_update(usernum, cuser_ref); - log_filef("log/cancelbadpost.log", LOG_CREAT, - "%s %s 刪除一篇劣文 (%d -> %d 篇)\n", - Cdate(&now), cuser.userid, prev, cuser.badpost); + vmsg("請您思考清楚後再來申請刪除."); + return 0; + } + + // check again for race condition + if(search_ulistn(usernum,2)) { + vmsg("請登出其他視窗, 否則不受理."); + return 0; + } + + if (pwcuCancelBadpost() != 0) { + vmsg("刪除失敗,請洽站務人員。"); + return 0; } + + log_filef("log/cancelbadpost.log", LOG_CREAT, + "%s %s 刪除一篇劣文 (%d -> %d 篇)\n", + Cdate(&now), cuser.userid, prev, cuser.badpost); + vmsg("恭喜您已經成功\刪除一篇劣文."); return 0; } @@ -466,12 +474,12 @@ void Customize(void) key -= 'a'; dirty = 1; + if(key < ic) { - cuser.uflag ^= masks1[key]; + pwcuToggleUserFlag(masks1[key]); } else { - key -= ic; - cuser.uflag2 ^= masks2[key]; + pwcuToggleUserFlag2(masks2[key]); } continue; } @@ -526,7 +534,7 @@ void Customize(void) if(dirty) { - passwd_sync_update(usernum, cuser_ref); + pwcuSaveUserFlags(); outs("設定已儲存。\n"); } else { outs("結束設定。\n"); @@ -538,7 +546,7 @@ void Customize(void) void -uinfo_query(userec_t *u, int adminmode, int unum) +uinfo_query(const char *orig_uid, int adminmode, int unum) { userec_t x; int i = 0, fail; @@ -552,24 +560,35 @@ uinfo_query(userec_t *u, int adminmode, int unum) int money_changed; int tokill = 0; int changefrom = 0; + int xuid; fail = 0; mail_changed = money_changed = perm_changed = 0; + // verify unum + xuid = getuser(orig_uid, &x); + if (xuid == 0) { - // verify unum - int xuid = getuser(u->userid, &x); - if (xuid != unum) - { - move(b_lines-1, 0); clrtobot(); - prints(ANSI_COLOR(1;31) "錯誤資訊: unum=%d (lookup xuid=%d)" - ANSI_RESET "\n", unum, xuid); - vmsg("系統錯誤: 使用者資料號碼 (unum) 不合。請至 " BN_BUGREPORT "報告。"); - return; - } + vmsgf("找不到使用者 %s。", orig_uid); + return; + } + if (xuid != unum) + { + move(b_lines-1, 0); clrtobot(); + prints(ANSI_COLOR(1;31) "錯誤資訊: unum=%d (lookup xuid=%d)" + ANSI_RESET "\n", unum, xuid); + vmsg("系統錯誤: 使用者資料號碼 (unum) 不合。請至 " BN_BUGREPORT "報告。"); + return; + } + if (strcmp(orig_uid, x.userid) != 0) + { + move(b_lines-1, 0); clrtobot(); + prints(ANSI_COLOR(1;31) "錯誤資訊: userid=%s (lookup userid=%s)" + ANSI_RESET "\n", orig_uid, x.userid); + vmsg("系統錯誤: 使用者 ID 記錄不不合。請至 " BN_BUGREPORT "報告。"); + return; } - memcpy(&x, u, sizeof(userec_t)); ans = vans(adminmode ? "(1)改資料(2)密碼(3)權限(4)砍帳號(5)改ID(6)寵物(7)審判(M)信箱 [0]結束 " : "請選擇 (1)修改資料 (2)設定密碼 (M)修改信箱 (C) 個人化設定 ==> [0]結束 "); @@ -680,23 +699,19 @@ uinfo_query(userec_t *u, int adminmode, int unum) snprintf(buf, sizeof(buf), "%010d", x.mobile); getdata_buf(y++, 0, "手機號碼:", buf, 11, NUMECHO); x.mobile = atoi(buf); - snprintf(genbuf, sizeof(genbuf), "%d", (u->sex + 1) % 8); + snprintf(genbuf, sizeof(genbuf), "%d", (x.sex + 1) % 8); getdata_str(y++, 0, "性別 (1)葛格 (2)姐接 (3)底迪 (4)美眉 (5)薯叔 " "(6)阿姨 (7)植物 (8)礦物:", buf, 3, NUMECHO, genbuf); if (buf[0] >= '1' && buf[0] <= '8') x.sex = (buf[0] - '1') % 8; else - x.sex = u->sex % 8; + x.sex = x.sex % 8; while (1) { snprintf(genbuf, sizeof(genbuf), "%04i/%02i/%02i", - u->year + 1900, u->month, u->day); - if (getdata_str(y, 0, "生日 西元/月月/日日:", buf, 11, DOECHO, genbuf) == 0) { - x.month = u->month; - x.day = u->day; - x.year = u->year; - } else { + x.year + 1900, x.month, x.day); + if (getdata_str(y, 0, "生日 西元/月月/日日:", buf, 11, DOECHO, genbuf) != 0) { int y, m, d; if (ParseDate(buf, &y, &m, &d)) continue; @@ -743,7 +758,7 @@ uinfo_query(userec_t *u, int adminmode, int unum) int j, k; FILE* fp; for(j = 0; j < 2; ++j){ - sethomefile(genbuf, u->userid, chess_photo_name[j]); + sethomefile(genbuf, x.userid, chess_photo_name[j]); fp = fopen(genbuf, "r"); if(fp != NULL){ FILE* newfp; @@ -757,7 +772,7 @@ uinfo_query(userec_t *u, int adminmode, int unum) getdata_buf(y, 0, mybuf, genbuf + 11, 80 - 11, DOECHO); ++y; - sethomefile(mybuf, u->userid, chess_photo_name[j]); + sethomefile(mybuf, x.userid, chess_photo_name[j]); strcat(mybuf, ".new"); if((newfp = fopen(mybuf, "w")) != NULL){ rewind(fp); @@ -770,8 +785,8 @@ uinfo_query(userec_t *u, int adminmode, int unum) fclose(newfp); - sethomefile(genbuf, u->userid, chess_photo_name[j]); - sethomefile(mybuf, u->userid, chess_photo_name[j]); + sethomefile(genbuf, x.userid, chess_photo_name[j]); + sethomefile(mybuf, x.userid, chess_photo_name[j]); strcat(mybuf, ".new"); Rename(mybuf, genbuf); @@ -810,24 +825,24 @@ uinfo_query(userec_t *u, int adminmode, int unum) if (getdata_str(y++, 0, "上線次數:", buf, 10, DOECHO, genbuf)) if ((tmp = atoi(buf)) >= 0) x.numlogins = tmp; - snprintf(genbuf, sizeof(genbuf), "%d", u->numposts); + snprintf(genbuf, sizeof(genbuf), "%d", x.numposts); if (getdata_str(y++, 0, "文章數目:", buf, 10, DOECHO, genbuf)) if ((tmp = atoi(buf)) >= 0) x.numposts = tmp; #ifdef ASSESS - snprintf(genbuf, sizeof(genbuf), "%d", u->badpost); + snprintf(genbuf, sizeof(genbuf), "%d", x.badpost); if (getdata_str(y++, 0, "惡劣文章數:", buf, 10, DOECHO, genbuf)) if ((tmp = atoi(buf)) >= 0) x.badpost = tmp; #endif // ASSESS - snprintf(genbuf, sizeof(genbuf), "%d", u->vl_count); + snprintf(genbuf, sizeof(genbuf), "%d", x.vl_count); if (getdata_str(y++, 0, "違法記錄:", buf, 10, DOECHO, genbuf)) if ((tmp = atoi(buf)) >= 0) x.vl_count = tmp; snprintf(genbuf, sizeof(genbuf), - "%d/%d/%d", u->five_win, u->five_lose, u->five_tie); + "%d/%d/%d", x.five_win, x.five_lose, x.five_tie); if (getdata_str(y++, 0, "五子棋戰績 勝/敗/和:", buf, 16, DOECHO, genbuf)) while (1) { @@ -848,7 +863,7 @@ uinfo_query(userec_t *u, int adminmode, int unum) break; } snprintf(genbuf, sizeof(genbuf), - "%d/%d/%d", u->chc_win, u->chc_lose, u->chc_tie); + "%d/%d/%d", x.chc_win, x.chc_lose, x.chc_tie); if (getdata_str(y++, 0, "象棋戰績 勝/敗/和:", buf, 16, DOECHO, genbuf)) while (1) { @@ -898,7 +913,7 @@ uinfo_query(userec_t *u, int adminmode, int unum) y = 19; if (!adminmode) { if (!getdata(y++, 0, "請輸入原密碼:", buf, PASSLEN, NOECHO) || - !checkpasswd(u->passwd, buf)) { + !checkpasswd(x.passwd, buf)) { outs("\n\n您輸入的密碼不正確\n"); fail++; break; @@ -959,7 +974,7 @@ uinfo_query(userec_t *u, int adminmode, int unum) } pre_confirmed = 1; - sprintf(title, "%s 的密碼重設通知 (by %s)",u->userid, cuser.userid); + sprintf(title, "%s 的密碼重設通知 (by %s)",x.userid, cuser.userid); unlink("etc/updatepwd.log"); if(! (fp = fopen("etc/updatepwd.log", "w"))) { @@ -971,11 +986,11 @@ uinfo_query(userec_t *u, int adminmode, int unum) fprintf(fp, "%s 要求密碼重設:\n" "見證人為 %s, %s, %s", - u->userid, witness[0], witness[1], witness[2] ); + x.userid, witness[0], witness[1], witness[2] ); fclose(fp); post_file(BN_SECURITY, title, "etc/updatepwd.log", "[系統安全局]"); - mail_id(u->userid, title, "etc/updatepwd.log", cuser.userid); + mail_id(x.userid, title, "etc/updatepwd.log", cuser.userid); for(i=0; i<3; i++) { mail_id(witness[i], title, "etc/updatepwd.log", cuser.userid); @@ -1029,9 +1044,11 @@ uinfo_query(userec_t *u, int adminmode, int unum) strlcpy(x.userid, genbuf, sizeof(x.userid)); } break; + case '6': chicken_toggle_death(x.userid); break; + default: return; } @@ -1058,10 +1075,11 @@ uinfo_query(userec_t *u, int adminmode, int unum) mail_id(x.userid, "翅膀長出來了!", "etc/angel_notify", "[上帝]"); #endif } - if (strcmp(u->userid, x.userid)) { + + if (strcmp(orig_uid, x.userid)) { char src[STRLEN], dst[STRLEN]; - kick_all(u->userid); - sethomepath(src, u->userid); + kick_all(orig_uid); + sethomepath(src, orig_uid); sethomepath(dst, x.userid); Rename(src, dst); setuserid(unum, x.userid); @@ -1070,7 +1088,7 @@ uinfo_query(userec_t *u, int adminmode, int unum) // wait registration. x.userlevel &= ~(PERM_LOGINOK | PERM_POST); } - memcpy(u, &x, sizeof(x)); + if (tokill) { kick_all(x.userid); delete_allpost(x.userid); @@ -1120,7 +1138,9 @@ u_info(void) move(2, 0); reload_money(); user_display(cuser_ref, 0); - uinfo_query (cuser_ref, 0, usernum); + uinfo_query (cuser.userid, 0, usernum); + // XXX TODO update from u to cuser + pwcuReload(); strlcpy(currutmp->nickname, cuser.nickname, sizeof(currutmp->nickname)); return 0; } -- cgit v1.2.3 From 7b2cc2e83030882b319bbf87932c7727c174adc7 Mon Sep 17 00:00:00 2001 From: piaip Date: Sun, 30 Aug 2009 07:33:13 +0000 Subject: * (pwcu branch) const cuser code complete git-svn-id: http://opensvn.csie.org/pttbbs/branches/pttbbs.pwcu@4795 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- include/proto.h | 14 +++++- include/pttstruct.h | 5 +- mbbsd/bbs.c | 8 ---- mbbsd/mbbsd.c | 1 - mbbsd/passwd.c | 66 +++++++++++++++++++++++++ mbbsd/register.c | 136 +++++++--------------------------------------------- 6 files changed, 98 insertions(+), 132 deletions(-) diff --git a/include/proto.h b/include/proto.h index b01e8712..e0f784c0 100644 --- a/include/proto.h +++ b/include/proto.h @@ -458,7 +458,6 @@ int setupnewuser(const userec_t *user); int regform_estimate_queuesize(); void new_register(void); void check_register(void); -void check_birthday(void); int check_regmail(char *email); // check and prompt for invalid reason; will str_lower() mail domain. void delregcodefile(void); @@ -710,6 +709,19 @@ int pwcuSetNickname (const char *nickname); int pwcuChessResult (int sigType, ChessGameResult); int pwcuSetChessEloRating(uint16_t elo_rating); int pwcuSaveUserFlags (); +int pwcuRegCompleteJustify (const char *justify); +int pwcuRegSetTemporaryJustify(const char *justify, const char *email); +int pwcuRegisterSetInfo (const char *rname, + const char *addr, + const char *career, + const char *phone, + const char *email, + int mobile, + uint8_t sex, + uint8_t year, + uint8_t month, + uint8_t day, + uint8_t is_foreign); // non-important based variables (only save on exit) int pwcuSetSignature (unsigned char newsig); diff --git a/include/pttstruct.h b/include/pttstruct.h index cd0c98df..a79e2bb6 100644 --- a/include/pttstruct.h +++ b/include/pttstruct.h @@ -140,11 +140,12 @@ typedef struct userec_t { } PACKSTRUCT userec_t; #ifdef CONST_CUSER -# define cuser ((const userec_t ) pwcuser) +// const userec_t cuser; # define cuser_ref ((const userec_t*)&pwcuser) +# define cuser (*cuser_ref) #else -# define cuser pwcuser # define cuser_ref (&cuser) +# define cuser pwcuser #endif /* flags in userec_t.withme */ diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c index aeffdc27..d19c8d91 100644 --- a/mbbsd/bbs.c +++ b/mbbsd/bbs.c @@ -3878,11 +3878,3 @@ Select(void) return do_select(); } -#ifdef HAVEMOBILE -void -mobile_message(const char *mobile, char *message) -{ - // this is for validation. - bsmtp(fpath, title, rcpt, "non-exist"); -} -#endif diff --git a/mbbsd/mbbsd.c b/mbbsd/mbbsd.c index c77b508e..30117471 100644 --- a/mbbsd/mbbsd.c +++ b/mbbsd/mbbsd.c @@ -1238,7 +1238,6 @@ user_login(void) } check_bad_login(); check_mailbox_quota(); - check_birthday(); check_register(); pwcuLoginSave(); restore_backup(); diff --git a/mbbsd/passwd.c b/mbbsd/passwd.c index e8ed21e2..161239bd 100644 --- a/mbbsd/passwd.c +++ b/mbbsd/passwd.c @@ -241,6 +241,72 @@ pwcuSetLoginView(unsigned int bits) PWCU_END(); } +int +pwcuRegCompleteJustify(const char *justify) +{ + PWCU_START(); + strlcpy( u.justify, justify, sizeof(u.justify)); + strlcpy(cuser.justify, justify, sizeof(cuser.justify)); + _ENABLE_BIT( u.userlevel, (PERM_POST | PERM_LOGINOK)); + _ENABLE_BIT(cuser.userlevel, (PERM_POST | PERM_LOGINOK)); + PWCU_END(); +} + +int +pwcuRegSetTemporaryJustify(const char *justify, const char *email) +{ + PWCU_START(); + strlcpy( u.email, email, sizeof(u.email)); + strlcpy(cuser.email, email, sizeof(cuser.email)); + strlcpy( u.justify, justify, sizeof(u.justify)); + strlcpy(cuser.justify, justify, sizeof(cuser.justify)); + _DISABLE_BIT( u.userlevel, (PERM_POST | PERM_LOGINOK)); + _DISABLE_BIT(cuser.userlevel, (PERM_POST | PERM_LOGINOK)); + PWCU_END(); +} + +int pwcuRegisterSetInfo (const char *rname, + const char *addr, + const char *career, + const char *phone, + const char *email, + int mobile, + uint8_t sex, + uint8_t year, + uint8_t month, + uint8_t day, + uint8_t is_foreign) +{ + PWCU_START(); + strlcpy(u.realname, rname, sizeof(u.realname)); + strlcpy(u.address, addr, sizeof(u.address)); + strlcpy(u.career, career, sizeof(u.career)); + strlcpy(u.phone, phone, sizeof(u.phone)); + strlcpy(u.email, email, sizeof(u.email)); + u.mobile = mobile; + u.sex = sex; + u.year = year; + u.month = month; + u.day = day; + _SETBY_BIT(u.uflag2, FOREIGN, is_foreign); + + // duplicate to cuser + + strlcpy(cuser.realname, rname, sizeof(cuser.realname)); + strlcpy(cuser.address, addr, sizeof(cuser.address)); + strlcpy(cuser.career, career, sizeof(cuser.career)); + strlcpy(cuser.phone, phone, sizeof(cuser.phone)); + strlcpy(cuser.email, email, sizeof(cuser.email)); + cuser.mobile = mobile; + cuser.sex = sex; + cuser.year = year; + cuser.month = month; + cuser.day = day; + _SETBY_BIT(cuser.uflag2, FOREIGN, is_foreign); + + PWCU_END(); +} + #include "chess.h" int pwcuChessResult(int sigType, ChessGameResult r) diff --git a/mbbsd/register.c b/mbbsd/register.c index 224f480a..ac490c76 100644 --- a/mbbsd/register.c +++ b/mbbsd/register.c @@ -515,12 +515,7 @@ email_justify(const userec_t *muser) snprintf(buf, sizeof(buf), " " BBSENAME " - [ %s ]", makeregcode(genbuf)); -#ifdef HAVEMOBILE - if (strcmp(muser->email, "m") == 0 || strcmp(muser->email, "M") == 0) - mobile_message(mobile, buf); - else -#endif - bsmtp("etc/registermail", buf, muser->email, "non-exist"); + bsmtp("etc/registermail", buf, muser->email, "non-exist"); move(20,0); clrtobot(); outs("我們即將寄出認證信 (您應該會在 10 分鐘內收到)\n" @@ -959,56 +954,6 @@ check_regmail(char *email) return allow; } -void -check_birthday(void) -{ - // check birthday - int changed = 0; - time_t t = (time_t)now; - struct tm tm; - - localtime_r(&t, &tm); - while ( cuser.year < 40 || // magic number 40: see user.c - cuser.year+3 > tm.tm_year) - { - char birthday[sizeof("mmmm/yy/dd ")]; - int y, m, d; - - clear(); - vs_hdr("輸入生日"); - move(2,0); - outs("本站為配合實行內容分級制度,請您輸入正確的生日資訊。"); - - getdata(5, 0, "生日 (西元年/月/日, 如 " DATE_SAMPLE "):", birthday, - sizeof(birthday), DOECHO); - - if (strcmp(birthday, DATE_SAMPLE) == 0) { - vmsg("不要複製範例! 請輸入你真實生日"); - continue; - } - if (ParseDate(birthday, &y, &m, &d)) { - vmsg("日期格式不正確"); - continue; - } else if (y < 1930) { - vmsg(MSG_ERR_TOO_OLD); - continue; - } else if (y+3 > tm.tm_year+1900) { - vmsg(MSG_ERR_TOO_YOUNG); - continue; - } - - cuser.year = (unsigned char)(y-1900); - cuser.month = (unsigned char)m; - cuser.day = (unsigned char)d; - changed = 1; - } - - if (changed) { - clear(); - resolve_over18(); - } -} - ///////////////////////////////////////////////////////////////////////////// // User Registration (Phase 2: Validation) ///////////////////////////////////////////////////////////////////////////// @@ -1153,8 +1098,7 @@ create_regform_request() file_append_record(FN_REQLIST, cuser.userid); // save justify information - snprintf(cuser.justify, sizeof(cuser.justify), - ""); + pwcuRegSetTemporaryJustify("", "x"); return 1; } @@ -1183,12 +1127,6 @@ toregister(char *email) "* 輸入後發生認證碼錯誤請重填一次 E-Mail *\n" "**********************************************************\n"); -#ifdef HAVEMOBILE - outs(" 3.若您有手機門號且想採取手機簡訊認證的方式 , 請輸入 m \n" - " 我們將會寄發含有認證碼的簡訊給您 \n" - " 收到後請到(U)ser => (R)egister 輸入認證碼, 即可通過認證\n"); -#endif - while (1) { email[0] = 0; getfield(15, "身分認證用", REGNOTES_ROOT "email", "E-Mail Address", email, 50); @@ -1196,24 +1134,6 @@ toregister(char *email) if (strcmp(email, "X") == 0) email[0] = 'x'; if (strcmp(email, "x") == 0) break; -#ifdef HAVEMOBILE - else if (strcmp(email, "m") == 0 || strcmp(email, "M") == 0) { - if (isvalidmobile(mobile)) { - char yn[3]; - getdata(16, 0, "請再次確認您輸入的手機號碼正確嘛? [y/N]", - yn, sizeof(yn), LCECHO); - if (yn[0] == 'y') - break; - } else { - move(15, 0); clrtobot(); - move(17, 0); - outs("指定的手機號碼不正確," - "若您無手機門號請選擇其他方式認證"); - pressanykey(); - } - - } -#endif else if (check_regmail(email)) { char yn[3]; #ifdef USE_EMAILDB @@ -1273,26 +1193,17 @@ toregister(char *email) return; } #endif - strlcpy(cuser.email, email, sizeof(cuser.email)); REGFORM2: if (strcasecmp(email, "x") == 0) { /* 手動認證 */ if (!create_regform_request()) - { vmsg("註冊申請單建立失敗。請至 " BN_BUGREPORT " 報告。"); - } } else { // register by mail or mobile - snprintf(cuser.justify, sizeof(cuser.justify), ""); -#ifdef HAVEMOBILE - if (phone != NULL && email[1] == 0 && tolower(email[0]) == 'm') - snprintf(cuser.justify, sizeof(cuser.justify), - ""); -#endif - email_justify(cuser_ref); + pwcuRegSetTemporaryJustify("", email); + email_justify(cuser_ref); } } - int u_register(void) { @@ -1302,9 +1213,7 @@ u_register(void) char inregcode[14], regcode[50]; char ans[3], *errcode; int i = 0; -#ifdef FOREIGN_REG int isForeign = (cuser.uflag2 & FOREIGN) ? 1 : 0; -#endif if (cuser.userlevel & PERM_LOGINOK) { outs("您的身份確認已經完成,不需填寫申請表"); @@ -1388,7 +1297,8 @@ u_register(void) // make it case insensitive. if (strcasecmp(inregcode, getregcode(regcode)) == 0) { - int unum; + int unum; + char justify[sizeof(cuser.justify)] = ""; delregcodefile(); if ((unum = searchuser(cuser.userid, NULL)) == 0) { vmsg("系統錯誤,查無此人!"); @@ -1400,15 +1310,16 @@ u_register(void) if(cuser.uflag2 & FOREIGN) mail_muser(cuser, "[出入境管理局]", "etc/foreign_welcome"); #endif - cuser.userlevel |= (PERM_LOGINOK | PERM_POST); + snprintf(justify, sizeof(justify), ": %s", Cdate(&now)); + pwcuRegCompleteJustify(justify); outs("\n註冊成功\, 重新上站後將取得完整權限\n" "請按下任一鍵跳離後重新上站~ :)"); - snprintf(cuser.justify, sizeof(cuser.justify), - ": %s", Cdate(&now)); pressanykey(); u_exit("registed"); exit(0); + // XXX shall never reach here. return QUIT; + } else if (strcasecmp(inregcode, "x") != 0) { if (regcode[0]) { @@ -1557,33 +1468,18 @@ u_register(void) if (ans[0] == 'y') break; } +#ifndef FOREIGN_REG + isForeign = 0; +#endif // copy values to cuser - strlcpy(cuser.realname, rname, sizeof(cuser.realname)); - strlcpy(cuser.address, addr, sizeof(cuser.address)); - strlcpy(cuser.email, email, sizeof(cuser.email)); - strlcpy(cuser.career, career, sizeof(cuser.career)); - strlcpy(cuser.phone, phone, sizeof(cuser.phone)); - - cuser.mobile = atoi(mobile); - cuser.sex = (sex_is[0] - '1') % 8; - cuser.month = mon; - cuser.day = day; - cuser.year = year; - -#ifdef FOREIGN_REG - if (isForeign) - cuser.uflag2 |= FOREIGN; - else - cuser.uflag2 &= ~FOREIGN; -#endif + pwcuRegisterSetInfo(rname, addr, career, phone, email, + atoi(mobile), (sex_is[0] - '1') % 8, + year, mon, day, isForeign); // if reach here, email is apparently 'x'. toregister(email); - // update cuser - passwd_sync_update(usernum, cuser_ref); - return FULLUPDATE; } -- cgit v1.2.3 From 37019e5c460e64a6dec35863d53603fbe9825ce1 Mon Sep 17 00:00:00 2001 From: piaip Date: Sun, 30 Aug 2009 08:25:07 +0000 Subject: * (pwcu branch) code refine, remove unused code, and finetune alerts git-svn-id: http://opensvn.csie.org/pttbbs/branches/pttbbs.pwcu@4796 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- common/bbs/cache.c | 3 +++ common/bbs/passwd.c | 3 +++ include/pttstruct.h | 10 ++-------- mbbsd/announce.c | 10 ---------- mbbsd/bbs.c | 20 ++++++++++++-------- mbbsd/card.c | 22 ---------------------- mbbsd/passwd.c | 43 +------------------------------------------ mbbsd/read.c | 8 -------- mbbsd/register.c | 7 ------- mbbsd/talk.c | 11 +---------- mbbsd/user.c | 3 --- 11 files changed, 22 insertions(+), 118 deletions(-) diff --git a/common/bbs/cache.c b/common/bbs/cache.c index 1166a85b..a23326bd 100644 --- a/common/bbs/cache.c +++ b/common/bbs/cache.c @@ -27,7 +27,10 @@ // these cannot be used! #define currutmp YOU_FAILED #define usernum YOU_FAILED +#undef cuser +#undef cuser_ref #define cuser YOU_FAILED +#define cuser_ref YOU_FAILED #define abort_bbs YOU_FAILED #define log_usies YOU_FAILED diff --git a/common/bbs/passwd.c b/common/bbs/passwd.c index 3e55d4d2..71d995d9 100644 --- a/common/bbs/passwd.c +++ b/common/bbs/passwd.c @@ -23,7 +23,10 @@ // these cannot be used! #define currutmp YOU_FAILED #define usernum YOU_FAILED +#undef cuser +#undef cuser_ref #define cuser YOU_FAILED +#define cuser_ref YOU_FAILED #define abort_bbs YOU_FAILED #define log_usies YOU_FAILED diff --git a/include/pttstruct.h b/include/pttstruct.h index a79e2bb6..3d554e54 100644 --- a/include/pttstruct.h +++ b/include/pttstruct.h @@ -315,14 +315,8 @@ typedef struct msgque_t { #define ALERT_NEW_MAIL (0x01) #define ISNEWMAIL(utmp) (utmp->alerts & ALERT_NEW_MAIL) -#define ALERT_PWD_PERM (0x02) -#define ALERT_PWD_BADPOST (0x04) -#define ALERT_PWD_GOODPOST (0x08) -#define ALERT_PWD_JUSTIFY (0x10) -// #define ALERT_PWD_LOGINS (0x20) -#define ALERT_PWD_POSTS (0x40) -#define ALERT_PWD_RELOAD (0x80) // reload entire pwd -#define ALERT_PWD (ALERT_PWD_PERM|ALERT_PWD_BADPOST|ALERT_PWD_GOODPOST|ALERT_PWD_JUSTIFY|ALERT_PWD_POSTS|ALERT_PWD_RELOAD) +#define ALERT_PWD_PERM (0x02) +#define ISNEWPERM(utmp) (utmp->alerts & ALERT_PWD_PERM) // userinfo_t.angelpause values #define ANGELPAUSE_NONE (0) // reject none (accept all) diff --git a/mbbsd/announce.c b/mbbsd/announce.c index 8663d392..0ec3f6ce 100644 --- a/mbbsd/announce.c +++ b/mbbsd/announce.c @@ -119,10 +119,6 @@ int copyqueue_toggle(CopyQueue *pcq) int i = copyqueue_locate(pcq); if(i >= 0) { -#if 0 - if (vans("已標記過此檔,要取消標記嗎 [y/N]: ") != 'y') - return 1; -#endif /* remove it */ used_copyqueue --; if(head_copyqueue > used_copyqueue) @@ -172,14 +168,8 @@ a_copyitem(const char *fpath, const char *title, const char *owner, int mode) //copyqueue_append(&cq); copyqueue_toggle(&cq); if (mode && flFirstAlert) { -#if 0 - move(b_lines-2, 0); clrtoeol(); - prints("目前已標記 %d 個檔案。[注意] 拷貝後才能刪除原文!", - copyqueue_querysize()); -#else vmsg("[注意] 提醒您複製/標記後要貼上(p)或附加(a)後才能刪除原文!"); flFirstAlert = 0; -#endif } } diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c index d19c8d91..dc8390b5 100644 --- a/mbbsd/bbs.c +++ b/mbbsd/bbs.c @@ -242,12 +242,12 @@ save_violatelaw(void) demoney(-1000 * cuser.vl_count); pwcuSaveViolateLaw(); - sendalert(cuser.userid, ALERT_PWD_PERM); log_filef("log/violation", LOG_CREAT, "%s %s pay-violation: $%d complete.\n", Cdate(&now), cuser.userid, (int)cuser.vl_count*1000); - vmsg("罰單已付,請盡速重新登入。"); + vmsg("罰單已付,請重新登入。"); + exit(0); return 0; } @@ -340,6 +340,13 @@ CheckPostPerm(void) if (currmode & MODE_DIGEST) return 0; + // check if my own permission is changed. + if (ISNEWPERM(currutmp)) + { + currmode &= ~MODE_POSTCHECKED; + pwcuReload(); + } + if (currmode & MODE_POSTCHECKED) { /* checked? let's check if perm reloaded */ @@ -3021,7 +3028,7 @@ del_post(int ent, fileheader_t * fhdr, char *direct) xuser.timeviolatelaw = now; passwd_sync_update(tusernum, &xuser); } - sendalert(userid, ALERT_PWD_BADPOST); + sendalert(userid, ALERT_PWD_PERM); mail_id(userid, genbuf, newpath, cuser.userid); #ifdef BAD_POST_RECORD @@ -3084,11 +3091,8 @@ del_post(int ent, fileheader_t * fhdr, char *direct) if (xuser.numposts > 0) xuser.numposts--; passwd_update(tusernum, &xuser); - sendalert_uid(tusernum, ALERT_PWD_POSTS); - - // TODO alert user? deumoney(tusernum, -fhdr->multi.money); - + sendalert_uid(tusernum, ALERT_PWD_PERM); #ifdef USE_COOLDOWN if (bp->brdattr & BRD_COOLDOWN) add_cooldowntime(tusernum, 15); @@ -3100,7 +3104,7 @@ del_post(int ent, fileheader_t * fhdr, char *direct) // owner case pwcuDecNumPost(); demoney(-fhdr->multi.money); - sendalert(cuser.userid, ALERT_PWD_POSTS); + sendalert(cuser.userid, ALERT_PWD_PERM); vmsgf("您的文章減為 %d 篇,支付清潔費 %d 元", cuser.numposts, fhdr->multi.money); } diff --git a/mbbsd/card.c b/mbbsd/card.c index 5735c4c6..48f29b98 100644 --- a/mbbsd/card.c +++ b/mbbsd/card.c @@ -441,28 +441,6 @@ game_log(int type, int money) if (money > 0) card_add_money(money); - // if the money is not real user money, no need to log anymore. -#if 0 - FILE *fp; - - switch (type) { - case JACK: - fp = fopen(BBSHOME "/etc/card/jack.log", "a"); - if (!fp) - return 0; - fprintf(fp, "%s win:%d\n", cuser.userid, money); - fclose(fp); - break; - case TEN_HALF: - fp = fopen(BBSHOME "/etc/card/tenhalf.log", "a"); - if (!fp) - return 0; - fprintf(fp, "%s win:%d\n", cuser.userid, money); - fclose(fp); - break; - } -#endif - return 0; } diff --git a/mbbsd/passwd.c b/mbbsd/passwd.c index 161239bd..05363661 100644 --- a/mbbsd/passwd.c +++ b/mbbsd/passwd.c @@ -11,14 +11,6 @@ #define cuser pwcuser #endif -void -passwd_force_update(int flag) -{ - if(!currutmp || (currutmp->alerts & ALERT_PWD) == 0) - return; - currutmp->alerts &= ~flag; -} - int initcuser(const char *userid) { @@ -26,60 +18,27 @@ initcuser(const char *userid) return usernum; } -// XXX I don't like the stupid synchronization here, -// but simply following previous work here... int passwd_sync_update(int num, userec_t * buf) { - int alerts; - if (num < 1 || num > MAX_USERS) return -1; // money update should be done before everything. buf->money = moneyof(num); - - if(usernum == num && currutmp && ((alerts = currutmp->alerts) & ALERT_PWD)) - { - userec_t u; - if (passwd_sync_query(num, &u) != 0) - return -1; - - if(alerts & ALERT_PWD_BADPOST) - cuser.badpost = buf->badpost = u.badpost; - if(alerts & ALERT_PWD_PERM) - cuser.userlevel = buf->userlevel = u.userlevel; - if(alerts & ALERT_PWD_JUSTIFY) - { - memcpy(buf->justify, u.justify, sizeof(u.justify)); - memcpy(cuser.justify, u.justify, sizeof(u.justify)); - memcpy(buf->email, u.email, sizeof(u.email)); - memcpy(cuser.email, u.email, sizeof(u.email)); - } - currutmp->alerts &= ~ALERT_PWD; - - // ALERT_PWD_RELOAD: reload all! No need to write. - if (alerts & ALERT_PWD_RELOAD) - { - memcpy(&cuser, &u, sizeof(u)); - return 0; - } - } - if (passwd_update(num, buf) != 0) return -1; return 0; } -// XXX I don't like the stupid synchronization here, -// but simply following previous work here... int passwd_sync_query(int num, userec_t * buf) { if (passwd_query(num, buf) < 0) return -1; + buf->money = moneyof(num); return 0; } diff --git a/mbbsd/read.c b/mbbsd/read.c index 6071ac39..4616cd62 100644 --- a/mbbsd/read.c +++ b/mbbsd/read.c @@ -87,14 +87,6 @@ Tagger(time4_t chrono, int recno, int mode) return YEA; } -#if 0 -static void -EnumTagName(char *fname, int locus) /* unused */ -{ - snprintf(fname, sizeof(fname), "M.%d.A", (int)TagList[locus].chrono); -} -#endif - void EnumTagFhdr(fileheader_t * fhdr, char *direct, int locus) { diff --git a/mbbsd/register.c b/mbbsd/register.c index ac490c76..9f9a2b74 100644 --- a/mbbsd/register.c +++ b/mbbsd/register.c @@ -246,12 +246,6 @@ compute_user_value(const userec_t * urec, time4_t clock) return 30 - value; #endif -#if 0 - if (!urec->numlogins) /* 未 login 成功者,不保留 */ - return -1; - if (urec->numlogins <= 3) /* #login 少於三者,保留 20 天 */ - return 20 * 24 * 60 - value; -#endif /* 未完成註冊者,保留 15 天 */ /* 一般情況,保留 120 天 */ return (urec->userlevel & PERM_LOGINOK ? 120 : 15) * 24 * 60 - value; @@ -1690,7 +1684,6 @@ regform_accept(const char *userid, const char *justify) // alert online users? if (search_ulist(unum)) { - sendalert(muser.userid, ALERT_PWD_PERM|ALERT_PWD_JUSTIFY); // force to reload perm kick_all(muser.userid); } diff --git a/mbbsd/talk.c b/mbbsd/talk.c index bc728b8d..da909076 100644 --- a/mbbsd/talk.c +++ b/mbbsd/talk.c @@ -450,16 +450,7 @@ my_query(const char *uident) move(1, 0); setutmpmode(TQUERY); currutmp->destuid = tuid; - - // XXX some users keep complaining that query result (for numpost) - // is not synced... - // well, make them happy now. - if (tuid == usernum) - { - // XXX there're still users asking why money is not updated... - reload_money(); - memcpy(&muser, cuser_ref, sizeof(muser)); - } + reload_money(); if ((uentp = (userinfo_t *) search_ulist(tuid))) fri_stat = friend_stat(currutmp, uentp); diff --git a/mbbsd/user.c b/mbbsd/user.c index 0b356eab..b03ac25b 100644 --- a/mbbsd/user.c +++ b/mbbsd/user.c @@ -1122,10 +1122,7 @@ uinfo_query(const char *orig_uid, int adminmode, int unum) passwd_sync_update(unum, &x); if (adminmode) - { - sendalert(x.userid, ALERT_PWD_RELOAD); kick_all(x.userid); - } // resolve_over18 only works for cuser if (!adminmode) -- cgit v1.2.3 From 19e36427e3fdfebc319fd7e0a92054ea9db85fd1 Mon Sep 17 00:00:00 2001 From: piaip Date: Sun, 30 Aug 2009 08:35:46 +0000 Subject: * code refine git-svn-id: http://opensvn.csie.org/pttbbs/branches/pttbbs.pwcu@4797 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/bbs.c | 1 + mbbsd/xyz.c | 6 +----- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c index dc8390b5..0d1a1a9a 100644 --- a/mbbsd/bbs.c +++ b/mbbsd/bbs.c @@ -247,6 +247,7 @@ save_violatelaw(void) Cdate(&now), cuser.userid, (int)cuser.vl_count*1000); vmsg("罰單已付,請重新登入。"); + u_exit("save_violate"); exit(0); return 0; } diff --git a/mbbsd/xyz.c b/mbbsd/xyz.c index 8f1e7ed3..7f52a28d 100644 --- a/mbbsd/xyz.c +++ b/mbbsd/xyz.c @@ -273,17 +273,13 @@ Goodbye(void) else if (genbuf[0] == 'n') note(); } - clear(); - - show_80x24_screen("etc/Logout"); - { int diff = (now - login_start_time) / 60; snprintf(genbuf, sizeof(genbuf), "此次停留時間: %d 小時 %2d 分", diff / 60, diff % 60); } - if(!(cuser.userlevel & PERM_LOGINOK)) + if(!HasUserPerm(PERM_LOGINOK)) vmsg("尚未完成註冊。如要提昇權限請參考本站公佈欄辦理註冊"); else vmsg(genbuf); -- cgit v1.2.3 From 5f589c904a3be5b6eaa5abd57052b481d6a24c18 Mon Sep 17 00:00:00 2001 From: piaip Date: Sun, 30 Aug 2009 10:08:49 +0000 Subject: * fix numlogindays git-svn-id: http://opensvn.csie.org/pttbbs/branches/pttbbs.pwcu@4799 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- include/pttstruct.h | 5 ++--- mbbsd/admin.c | 1 - mbbsd/bbs.c | 2 +- mbbsd/chat.c | 6 +++--- mbbsd/chess.c | 4 ++-- mbbsd/kaede.c | 2 +- mbbsd/mbbsd.c | 9 ++++----- mbbsd/passwd.c | 34 +++++++++++++++++++++++++++------- mbbsd/pmore.c | 2 +- mbbsd/register.c | 2 +- mbbsd/talk.c | 47 +++++++++++++++++++++++++++++++---------------- mbbsd/user.c | 12 ++++++------ mbbsd/vote.c | 10 ++++------ util/birth.c | 6 +++--- util/reaper.c | 2 +- 15 files changed, 87 insertions(+), 57 deletions(-) diff --git a/include/pttstruct.h b/include/pttstruct.h index 3d554e54..2e130628 100644 --- a/include/pttstruct.h +++ b/include/pttstruct.h @@ -63,7 +63,7 @@ typedef struct userec_t { uint32_t uflag; /* 習慣1 , see uflags.h */ uint32_t uflag2; /* 習慣2 , see uflags.h */ uint32_t userlevel; /* 權限 */ - uint32_t numlogins; /* 上站次數 */ + uint32_t numlogindays; /* 上線資歷 (每日最多+1的登入次數) */ uint32_t numposts; /* 文章篇數 */ time4_t firstlogin; /* 註冊時間 */ time4_t lastlogin; /* 最近上站時間(包含隱身) */ @@ -94,9 +94,8 @@ typedef struct userec_t { char career[40]; /* 學歷職業 */ char phone[20]; /* 電話 */ - uint32_t numlogindays; /* 登入天次 */ - char chkpad1[48]; + char chkpad1[52]; time4_t lastseen; /* 最近上站時間(隱身不計) */ time4_t chkpad2[2]; /* in case 有人忘了把 time4_t 調好... */ // 以上應為 sizeof(chicken_t) 同等大小 diff --git a/mbbsd/admin.c b/mbbsd/admin.c index 0ed06412..9dcc5b8a 100644 --- a/mbbsd/admin.c +++ b/mbbsd/admin.c @@ -108,7 +108,6 @@ upgrade_passwd(userec_t *puser) memset(puser->chkpad0, 0, sizeof(puser->chkpad0)); memset(puser->chkpad1, 0, sizeof(puser->chkpad1)); memset(puser->chkpad2, 0, sizeof(puser->chkpad2)); - puser->numlogindays = 0; puser->lastseen = 0; puser->version = PASSWD_VERSION; return ; diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c index 0d1a1a9a..183bc16f 100644 --- a/mbbsd/bbs.c +++ b/mbbsd/bbs.c @@ -2714,7 +2714,7 @@ recommend(int ent, fileheader_t * fhdr, const char *direct) static int tolog = 0; if( tolog == 0 ) tolog = - (cuser.numlogins < 50 || (now - cuser.firstlogin) < DAY_SECONDS * 7) + (cuser.numlogindays < 50 || (now - cuser.firstlogin) < DAY_SECONDS * 7) ? 1 : 2; if( tolog == 1 ){ FILE *fp; diff --git a/mbbsd/chat.c b/mbbsd/chat.c index f51524ff..9c73c39d 100644 --- a/mbbsd/chat.c +++ b/mbbsd/chat.c @@ -204,14 +204,14 @@ chat_query(char *arg) char buf[ANSILINELEN], *ptr; FILE *fp; - snprintf(buf, sizeof(buf), "%s(%s) 共上站 %d 次,發表過 %d 篇文章", + snprintf(buf, sizeof(buf), "%s(%s) 上站資歷 %d 點,發表過 %d 篇文章", xuser.userid, xuser.nickname, - xuser.numlogins, xuser.numposts); + xuser.numlogindays, xuser.numposts); printchatline(buf); snprintf(buf, sizeof(buf), "最近(%s)從[%s]上站", - Cdate(&xuser.lastseen), + Cdate(xuser.lastseen ? &xuser.lastseen : &xuser.lastlogin), (xuser.lasthost[0] ? xuser.lasthost : "(不詳)")); printchatline(buf); diff --git a/mbbsd/chess.c b/mbbsd/chess.c index 7c58b6a8..11cb2a6f 100644 --- a/mbbsd/chess.c +++ b/mbbsd/chess.c @@ -1441,7 +1441,7 @@ ChessPhotoInitial(ChessInfo* info) switch (line) { case 0: sprintf(genbuf, " <代號> %s", xuser.userid); break; case 1: sprintf(genbuf, " <暱稱> %.16s", xuser.nickname); break; - case 2: sprintf(genbuf, " <上站> %d", xuser.numlogins); break; + case 2: sprintf(genbuf, " <上站> %d", xuser.numlogindays); break; case 3: sprintf(genbuf, " <文章> %d", xuser.numposts); break; case 4: sprintf(genbuf, " <職位> %-4s %s", country, level); break; case 5: sprintf(genbuf, " <來源> %.16s", xuser.lasthost); break; @@ -1494,7 +1494,7 @@ ChessPhotoInitial(ChessInfo* info) switch (line - 9) { case 0: sprintf(PHOTO(line), "<代號> %-16.16s ", xuser.userid); break; case 1: sprintf(PHOTO(line), "<暱稱> %-16.16s ", xuser.nickname); break; - case 2: sprintf(PHOTO(line), "<上站> %-16d ", xuser.numlogins); break; + case 2: sprintf(PHOTO(line), "<上站> %-16d ", xuser.numlogindays); break; case 3: sprintf(PHOTO(line), "<文章> %-16d ", xuser.numposts); break; case 4: sprintf(PHOTO(line), "<職位> %-4s %-10s ", country, level); break; case 5: sprintf(PHOTO(line), "<來源> %-16.16s ", xuser.lasthost); break; diff --git a/mbbsd/kaede.c b/mbbsd/kaede.c index 5a5545e5..628f51df 100644 --- a/mbbsd/kaede.c +++ b/mbbsd/kaede.c @@ -30,7 +30,7 @@ expand_esc_star(char *buf, const char *src, int szbuf) strlcpy(buf, cuser.nickname, szbuf); return 2; case 'l': // current user logins - snprintf(buf, szbuf, "%d", cuser.numlogins); + snprintf(buf, szbuf, "%d", cuser.numlogindays); return 2; case 'p': // current user posts snprintf(buf, szbuf, "%d", cuser.numposts); diff --git a/mbbsd/mbbsd.c b/mbbsd/mbbsd.c index 30117471..04e9cbb8 100644 --- a/mbbsd/mbbsd.c +++ b/mbbsd/mbbsd.c @@ -1049,9 +1049,9 @@ setup_utmp(int mode) strip_nonebig5((unsigned char *)currutmp->nickname, sizeof(currutmp->nickname)); strip_nonebig5((unsigned char *)currutmp->mind, sizeof(currutmp->mind)); - // XXX 不用每 20 才檢查吧 // XXX 這個 check 花不少時間,有點間隔比較好 - if ((cuser.userlevel & PERM_BM) && !(cuser.numlogins % 20)) + // TODO XXX 使用 numlogindays 有點問題,同一天內多次 login 會狂檢查... + if ((cuser.userlevel & PERM_BM) && !(cuser.numlogindays % 20)) check_BM(); /* Ptt 自動取下離職板主權力 */ // resolve fromhost @@ -1090,15 +1090,14 @@ setup_utmp(int mode) inline static void welcome_msg(void) { - prints(ANSI_RESET " 歡迎您第 " - ANSI_COLOR(1;33) "%d" ANSI_COLOR(0;37) " 度拜訪本站,上次您是從 " + prints(ANSI_RESET " 歡迎您再度拜訪本站,上次您是從 " ANSI_COLOR(1;33) "%s" ANSI_COLOR(0;37) " 連往本站," ANSI_CLRTOEND "\n" " 我記得那天是 " ANSI_COLOR(1;33) "%s" ANSI_COLOR(0;37) "。" ANSI_CLRTOEND "\n" ANSI_CLRTOEND "\n" , - cuser.numlogins, cuser.lasthost, Cdate(&(cuser.lastlogin))); + cuser.lasthost, Cdate(&(cuser.lastlogin))); pressanykey(); } diff --git a/mbbsd/passwd.c b/mbbsd/passwd.c index 05363661..83fb45a5 100644 --- a/mbbsd/passwd.c +++ b/mbbsd/passwd.c @@ -428,21 +428,41 @@ pwcuToggleUserFlag2 (unsigned int mask) // which we should update/calculate every variables to log. int pwcuLoginSave () { - PWCU_START(); // XXX no need to reload for speed up? + // XXX because LoginSave was called very long after + // login_start_time, so we must reload passwd again + // here to prevent race condition. + // If you want to remove this reload, make sure + // pwcuLoginSave is called AFTER login_start_time + // was decided. + int regdays = 0, prev_regdays = 0; + int reftime = login_start_time; + PWCU_START(); // new host from 'fromhost' + strlcpy( u.lasthost, fromhost, sizeof( u.lasthost)); strlcpy(cuser.lasthost, fromhost, sizeof(cuser.lasthost)); - // calculate numlogins (only increase one per each key) - if (((login_start_time - cuser.firstlogin) % DAY_SECONDS) != - ((cuser.lastlogin - cuser.firstlogin) % DAY_SECONDS) ) - cuser.numlogins++; + // this must be valid. + assert(login_start_time > 0); + + // invalid session? + if (reftime < u.lastlogin) + reftime = u.lastlogin; + + regdays = ( reftime - u.firstlogin) / DAY_SECONDS; + prev_regdays = (u.lastlogin - u.firstlogin) / DAY_SECONDS; + // assert(regdays >= prev_regdays); + + // calculate numlogindays (only increase one per each key) + if (regdays > prev_regdays) + ++u.numlogindays; + cuser.numlogindays = u.numlogindays; // update last login time - cuser.lastlogin = login_start_time; + cuser.lastlogin = u.lastlogin = reftime; if (!PERM_HIDE(currutmp)) - cuser.lastseen = login_start_time; + cuser.lastseen = u.lastseen = reftime; PWCU_END(); } diff --git a/mbbsd/pmore.c b/mbbsd/pmore.c index 1968f557..4304b55e 100644 --- a/mbbsd/pmore.c +++ b/mbbsd/pmore.c @@ -594,7 +594,7 @@ expand_esc_star(char *buf, const char *src, int szbuf) strlcpy(buf, cuser.userid, szbuf); return 2; case 'l': // current user logins - snprintf(buf, szbuf, "%d", cuser.numlogins); + snprintf(buf, szbuf, "%d", cuser.numlogindays); return 2; case 'p': // current user posts snprintf(buf, szbuf, "%d", cuser.numposts); diff --git a/mbbsd/register.c b/mbbsd/register.c index 9f9a2b74..af04508e 100644 --- a/mbbsd/register.c +++ b/mbbsd/register.c @@ -259,7 +259,7 @@ check_and_expire_account(int uid, const userec_t * urec, int expireRange) if ((val = compute_user_value(urec, now)) < 0) { snprintf(genbuf, sizeof(genbuf), "#%d %-12s %s %d %d %d", uid, urec->userid, Cdatelite(&(urec->lastlogin)), - urec->numlogins, urec->numposts, val); + urec->numlogindays, urec->numposts, val); // 若超過 expireRange 則砍人, // 不然就 return 0 diff --git a/mbbsd/talk.c b/mbbsd/talk.c index da909076..997e7e8e 100644 --- a/mbbsd/talk.c +++ b/mbbsd/talk.c @@ -455,37 +455,50 @@ my_query(const char *uident) if ((uentp = (userinfo_t *) search_ulist(tuid))) fri_stat = friend_stat(currutmp, uentp); - prints("《ID暱稱》%s (%s)%*s《經濟狀況》%s", + // ------------------------------------------------------------ + + prints( "《ID暱稱》%s (%s)%*s", muser.userid, muser.nickname, strlen(muser.userid) + strlen(muser.nickname) >= 25 ? 0 : - (int)(25 - strlen(muser.userid) - strlen(muser.nickname)), "", + (int)(25 - strlen(muser.userid) - strlen(muser.nickname)), ""); + + prints( "《經濟狀況》%s", money_level(muser.money)); if (uentp && ((fri_stat & HFM && !uentp->invisible) || strcmp(muser.userid,cuser.userid) == 0)) prints(" ($%d)", muser.money); outc('\n'); - prints("《上站次數》%d次", muser.numlogins); + // ------------------------------------------------------------ + + prints("《上站資歷》%d 點", muser.numlogindays); #ifdef SHOW_LOGINOK if (!(muser.userlevel & PERM_LOGINOK)) outs(" (尚未通過認證)"); #endif - move(2, 40); + + move(vgety(), 40); + prints("《有效文章》%d 篇", muser.numposts); #ifdef ASSESS - prints("《有效文章篇數》%d篇 (劣:%d)\n", muser.numposts, muser.badpost); -#else - prints("《有效文章篇數》%d篇\n", muser.numposts); + prints(" (劣:%d)", muser.badpost); #endif + outc('\n'); + + // ------------------------------------------------------------ prints(ANSI_COLOR(1;33) "《目前動態》%-28.28s" ANSI_RESET, (uentp && isvisible_stat(currutmp, uentp, fri_stat)) ? - modestring(uentp, 0) : "不在站上"); + modestring(uentp, 0) : "不在站上"); + + if ((uentp && ISNEWMAIL(uentp)) || load_mailalert(muser.userid)) + outs("《私人信箱》有新進信件還沒看\n"); + else + outs("《私人信箱》所有信件都看過了\n"); + + // ------------------------------------------------------------ - outs(((uentp && ISNEWMAIL(uentp)) || load_mailalert(muser.userid)) - ? "《私人信箱》有新進信件還沒看\n" : - "《私人信箱》所有信件都看過了\n"); prints("《上次上站》%-28.28s《上次故鄉》", - Cdate(&muser.lastseen)); + Cdate(muser.lastseen ? &muser.lastseen : &muser.lastlogin)); // print out muser.lasthost #ifdef USE_MASKED_FROMHOST if(!HasUserPerm(PERM_SYSOP|PERM_ACCOUNTS)) @@ -494,8 +507,10 @@ my_query(const char *uident) outs(muser.lasthost[0] ? muser.lasthost : "(不詳)"); outs("\n"); - prints("《五子棋戰績》%3d 勝 %3d 敗 %3d 和 " - "《象棋戰績》%3d 勝 %3d 敗 %3d 和\n", + // ------------------------------------------------------------ + + prints("《 五子棋 》%5d 勝 %5d 敗 %5d 和 " + "《象棋戰績》%5d 勝 %5d 敗 %5d 和\n", muser.five_win, muser.five_lose, muser.five_tie, muser.chc_win, muser.chc_lose, muser.chc_tie); @@ -3292,8 +3307,8 @@ talkreply(void) strlcpy(currutmp->msgs[0].last_call_in, "呼叫、呼叫,聽到請回答 (Ctrl-R)", sizeof(currutmp->msgs[0].last_call_in)); currutmp->msgs[0].msgmode = MSGMODE_TALK; - prints("對方來自 [%s],共上站 %d 次,文章 %d 篇\n", - uip->from, xuser.numlogins, xuser.numposts); + prints("對方來自 [%s],上站資歷 %d 點,文章共 %d 篇\n", + uip->from, xuser.numlogindays, xuser.numposts); if (is_chess) ChessShowRequest(); diff --git a/mbbsd/user.c b/mbbsd/user.c index b03ac25b..386e5a23 100644 --- a/mbbsd/user.c +++ b/mbbsd/user.c @@ -173,8 +173,8 @@ user_display(const userec_t * u, int adminmode) prints("\t\t認證資料: %s\n", u->justify); } - prints("\t\t上站文章: 上站 %d 次 / 文章 %d 篇\n", - u->numlogins, u->numposts); + prints("\t\t上站文章: 上站資歷 %d / 文章 %d 篇\n", + u->numlogindays, u->numposts); sethomedir(genbuf, u->userid); prints("\t\t私人信箱: %d 封 (購買信箱: %d 封)\n", @@ -821,10 +821,10 @@ uinfo_query(const char *orig_uid, int adminmode, int unum) getdata_buf(y++, 0, "最近光臨機器:", x.lasthost, sizeof(x.lasthost), DOECHO); - snprintf(genbuf, sizeof(genbuf), "%d", x.numlogins); - if (getdata_str(y++, 0, "上線次數:", buf, 10, DOECHO, genbuf)) + snprintf(genbuf, sizeof(genbuf), "%d", x.numlogindays); + if (getdata_str(y++, 0, "上線資歷:", buf, 10, DOECHO, genbuf)) if ((tmp = atoi(buf)) >= 0) - x.numlogins = tmp; + x.numlogindays = tmp; snprintf(genbuf, sizeof(genbuf), "%d", x.numposts); if (getdata_str(y++, 0, "文章數目:", buf, 10, DOECHO, genbuf)) if ((tmp = atoi(buf)) >= 0) @@ -1419,7 +1419,7 @@ u_list_CB(void *data, int num, userec_t * uentp) prints("%-14s %-27.27s%5d %5d %s %s\n", uentp->userid, uentp->nickname, - uentp->numlogins, uentp->numposts, + uentp->numlogindays, uentp->numposts, HasUserPerm(PERM_SEEULEVELS) ? permstr : "", ptr); ctx->usercounter++; ctx->y++; diff --git a/mbbsd/vote.c b/mbbsd/vote.c index 8eb2c756..030c6704 100644 --- a/mbbsd/vote.c +++ b/mbbsd/vote.c @@ -646,11 +646,9 @@ vote_maintain(const char *bname) closetime = atoi(inbuf); // borrow variable } while (closetime < 0 || closetime > 120); fprintf(fp, "%d\n", now - (MONTH_SECONDS * closetime)); - do { - getdata(6, 0, "上站次數下限", inbuf, 6, DOECHO); - closetime = atoi(inbuf); // borrow variable - } while (closetime < 0); - fprintf(fp, "%d\n", closetime); + + fprintf(fp, "%d\n", 0); // was: numlogins + do { getdata(6, 0, "文章篇數下限", inbuf, 6, DOECHO); closetime = atoi(inbuf); // borrow variable @@ -791,7 +789,7 @@ user_vote_one(const vote_buffer_t *vbuf, const char *bname) fclose(lfp); // XXX if this is a private vote (limited), I think we don't need to check limits? if (cuser.firstlogin > closetime || cuser.numposts < limits_posts || - cuser.numlogins < limits_logins) { + cuser.numlogindays < limits_logins) { vmsg("你不夠資深喔!"); return FULLUPDATE; } diff --git a/util/birth.c b/util/birth.c index 436c37a6..bac1bad3 100644 --- a/util/birth.c +++ b/util/birth.c @@ -12,7 +12,7 @@ int bad_user_id(const char *userid) { int j; if (strlen(user.userid) < 2 || !isalpha(user.userid[0])) return 1; - if (user.numlogins == 0 || user.numlogins > 15000) + if (user.numlogindays == 0 || user.numlogindays > 15000) return 1; if (user.numposts > 15000) return 1; @@ -66,13 +66,13 @@ int main(argc, argv) Link(path, genbuf); sprintf(genbuf, BBSHOME "/home/%c/%s/.DIR", user.userid[0], user.userid); append_record(genbuf, &mymail, sizeof(mymail)); - if ((user.numlogins + user.numposts) < 20) + if ((user.numlogindays + user.numposts) < 20) continue; fprintf(fp1, " [%2d/%-2d] %-14s %-24s login:%-5d post:%-5d\n", ptime->tm_mon + 1, ptime->tm_mday, user.userid, - user.nickname, user.numlogins, user.numposts); + user.nickname, user.numlogindays, user.numposts); } } fclose(fp1); diff --git a/util/reaper.c b/util/reaper.c index d89f6e56..70bd3814 100644 --- a/util/reaper.c +++ b/util/reaper.c @@ -136,7 +136,7 @@ int check_last_login(void *data, int n, userec_t *u) { { // invalid record printf("使用者 %-*s (登入%3d 次, %s%s, %s [%04X])\n 最後登入日期異常 [%04X]: %s", - IDLEN, u->userid, u->numlogins, + IDLEN, u->userid, u->numlogindays, (u->userlevel & PERM_LOGINOK) ? "已過認證" : "未過認證", (u->userlevel & PERM_SYSOP) ? "[SYSOP]" : "", buf, -- cgit v1.2.3 From be508920d9516539c9423d351fa2ba7fe2b910e1 Mon Sep 17 00:00:00 2001 From: piaip Date: Sun, 30 Aug 2009 10:15:42 +0000 Subject: * allow numlogindays to be upgraded on-the-fly. git-svn-id: http://opensvn.csie.org/pttbbs/branches/pttbbs.pwcu@4800 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/passwd.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mbbsd/passwd.c b/mbbsd/passwd.c index 83fb45a5..514959c5 100644 --- a/mbbsd/passwd.c +++ b/mbbsd/passwd.c @@ -453,6 +453,9 @@ int pwcuLoginSave () prev_regdays = (u.lastlogin - u.firstlogin) / DAY_SECONDS; // assert(regdays >= prev_regdays); + if (u.numlogindays > prev_regdays) + u.numlogindays = prev_regdays; + // calculate numlogindays (only increase one per each key) if (regdays > prev_regdays) ++u.numlogindays; -- cgit v1.2.3 From 48b5100a347dfb5bb48a4d695a44c81e4378d69d Mon Sep 17 00:00:00 2001 From: piaip Date: Sun, 30 Aug 2009 12:47:31 +0000 Subject: * allow setting chess_go results and lastlogin git-svn-id: http://opensvn.csie.org/pttbbs/branches/pttbbs.pwcu@4801 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/calendar.c | 38 +++++++++++++++++++++++++++++++---- mbbsd/user.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 92 insertions(+), 6 deletions(-) diff --git a/mbbsd/calendar.c b/mbbsd/calendar.c index dad8bc46..a8c63eb3 100644 --- a/mbbsd/calendar.c +++ b/mbbsd/calendar.c @@ -31,28 +31,58 @@ Days(int y, int m, int d) } /** - * return 1 if date is invalid + * return 1 if date and time is invalid */ -int ParseDate(const char *date, int *year, int *month, int *day) +int ParseDateTime(const char *date, int *year, int *month, int *day, + int *hour, int *min, int *sec) { - char *y, *m, *d; + char *y, *m, *d, *hh, *mm, *ss; char buf[128]; char *strtok_pos; strlcpy(buf, date, sizeof(buf)); y = strtok_r(buf, "/", &strtok_pos); if (!y) return 1; m = strtok_r(NULL, "/", &strtok_pos);if (!m) return 1; - d = strtok_r(NULL, "", &strtok_pos); if (!d) return 1; + d = strtok_r(NULL, " ", &strtok_pos); if (!d) return 1; + + if (hour) { + hh = strtok_r(NULL, ":", &strtok_pos); + if (!hh) return 1; + *hour = atoi(hh); + } + if (min ) { + mm = strtok_r(NULL, ":", &strtok_pos); + if (!mm) return 1; + *min = atoi(mm); + } + if (sec ) { + ss = strtok_r(NULL, "", &strtok_pos); + if (!ss) return 1; + *sec = atoi(ss); + } *year = atoi(y); *month = atoi(m); *day = atoi(d); + + if (hour && (*hour < 0 || *hour > 23)) return 1; + if (min && (*min < 0 || *min > 59)) return 1; + if (sec && (*sec < 0 || *sec > 59)) return 1; + if (*year < 1 || *month < 1 || *month > 12 || *day < 1 || *day > MonthDay(*month, is_leap_year(*year))) return 1; return 0; } +/** + * return 1 if date is invalid + */ +int ParseDate(const char *date, int *year, int *month, int *day) +{ + return ParseDateTime(date, year, month, day, NULL, NULL, NULL); +} + /** * return 1 if date is invalid */ diff --git a/mbbsd/user.c b/mbbsd/user.c index 386e5a23..ef73930f 100644 --- a/mbbsd/user.c +++ b/mbbsd/user.c @@ -821,6 +821,32 @@ uinfo_query(const char *orig_uid, int adminmode, int unum) getdata_buf(y++, 0, "最近光臨機器:", x.lasthost, sizeof(x.lasthost), DOECHO); + while (1) { + struct tm t = {0}; + time4_t clk = x.lastlogin; + localtime4_r(&clk, &t); + snprintf(genbuf, sizeof(genbuf), "%04i/%02i/%02i %02i:%02i:%02i", + t.tm_year + 1900, t.tm_mon+1, t.tm_mday, + t.tm_hour, t.tm_min, t.tm_sec); + if (getdata_str(y, 0, "最近上線時間:", buf, 20, DOECHO, genbuf) != 0) { + int y, m, d, hh, mm, ss; + if (ParseDateTime(buf, &y, &m, &d, &hh, &mm, &ss)) + continue; + t.tm_year = y-1900; + t.tm_mon = m-1; + t.tm_mday = d; + t.tm_hour = hh; + t.tm_min = mm; + t.tm_sec = ss; + clk = mktime(&t); + if (!clk) + continue; + x.lastlogin= clk; + } + y++; + break; + } + snprintf(genbuf, sizeof(genbuf), "%d", x.numlogindays); if (getdata_str(y++, 0, "上線資歷:", buf, 10, DOECHO, genbuf)) if ((tmp = atoi(buf)) >= 0) @@ -831,10 +857,13 @@ uinfo_query(const char *orig_uid, int adminmode, int unum) x.numposts = tmp; #ifdef ASSESS snprintf(genbuf, sizeof(genbuf), "%d", x.badpost); - if (getdata_str(y++, 0, "惡劣文章數:", buf, 10, DOECHO, genbuf)) + if (getdata_str(y, 0, "惡劣文章數:", buf, 10, DOECHO, genbuf)) if ((tmp = atoi(buf)) >= 0) x.badpost = tmp; #endif // ASSESS + move(y-1, 0); clrtobot(); + prints("文章數目: %d (劣: %d)\n", + x.numposts, x.badpost); snprintf(genbuf, sizeof(genbuf), "%d", x.vl_count); if (getdata_str(y++, 0, "違法記錄:", buf, 10, DOECHO, genbuf)) @@ -864,7 +893,7 @@ uinfo_query(const char *orig_uid, int adminmode, int unum) } snprintf(genbuf, sizeof(genbuf), "%d/%d/%d", x.chc_win, x.chc_lose, x.chc_tie); - if (getdata_str(y++, 0, "象棋戰績 勝/敗/和:", buf, 16, DOECHO, + if (getdata_str(y++, 0, " 象棋 戰績 勝/敗/和:", buf, 16, DOECHO, genbuf)) while (1) { char *p; @@ -883,6 +912,33 @@ uinfo_query(const char *orig_uid, int adminmode, int unum) x.chc_tie = atoi(p); break; } + snprintf(genbuf, sizeof(genbuf), + "%d/%d/%d", x.go_win, x.go_lose, x.go_tie); + if (getdata_str(y++, 0, " 圍棋 戰績 勝/敗/和:", buf, 16, DOECHO, + genbuf)) + while (1) { + char *p; + char *strtok_pos; + p = strtok_r(buf, "/\r\n", &strtok_pos); + if (!p) + break; + x.go_win = atoi(p); + p = strtok_r(NULL, "/\r\n", &strtok_pos); + if (!p) + break; + x.go_lose = atoi(p); + p = strtok_r(NULL, "/\r\n", &strtok_pos); + if (!p) + break; + x.go_tie = atoi(p); + break; + } + y -= 3; // rollback games set to get more space + move(y++, 0); clrtobot(); + prints("棋類: (五子棋)%d/%d/%d (象棋)%d/%d/%d (圍棋)%d/%d/%d\n", + x.five_win, x.five_lose, x.five_tie, + x.chc_win, x.chc_lose, x.chc_tie, + x.go_win, x.go_lose, x.go_tie); #ifdef FOREIGN_REG if (getdata_str(y++, 0, "住在 1)台灣 2)其他:", buf, 2, DOECHO, x.uflag2 & FOREIGN ? "2" : "1")) if ((tmp = atoi(buf)) > 0){ -- cgit v1.2.3 From c7ec45b470726d9b50e7d549a09569e22e2a9a69 Mon Sep 17 00:00:00 2001 From: piaip Date: Sun, 30 Aug 2009 12:56:13 +0000 Subject: * add more checking to numlogindays git-svn-id: http://opensvn.csie.org/pttbbs/branches/pttbbs.pwcu@4802 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- include/proto.h | 2 ++ mbbsd/user.c | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/include/proto.h b/include/proto.h index e0f784c0..bc32e07d 100644 --- a/include/proto.h +++ b/include/proto.h @@ -745,5 +745,7 @@ int pwcuInitAdminPerm (); /* calendar */ int calendar(void); int ParseDate(const char *date, int *year, int *month, int *day); +int ParseDateTime(const char *date, int *year, int *month, int *day, + int *hour, int *min, int *sec); #endif diff --git a/mbbsd/user.c b/mbbsd/user.c index ef73930f..0e8fdb53 100644 --- a/mbbsd/user.c +++ b/mbbsd/user.c @@ -847,10 +847,22 @@ uinfo_query(const char *orig_uid, int adminmode, int unum) break; } - snprintf(genbuf, sizeof(genbuf), "%d", x.numlogindays); - if (getdata_str(y++, 0, "上線資歷:", buf, 10, DOECHO, genbuf)) - if ((tmp = atoi(buf)) >= 0) - x.numlogindays = tmp; + do { + int max_days = (x.lastlogin - x.firstlogin) / DAY_SECONDS; + snprintf(genbuf, sizeof(genbuf), "%d", x.numlogindays); + if (getdata_str(y++, 0, "上線資歷:", buf, 10, DOECHO, genbuf)) + if ((tmp = atoi(buf)) >= 0) + x.numlogindays = tmp; + if (x.numlogindays > max_days) + { + x.numlogindays = max_days; + vmsgf("根據此使用者最後上線時間,資歷最大值為 %d.", max_days); + move(--y, 0); clrtobot(); + continue; + } + break; + } while (1); + snprintf(genbuf, sizeof(genbuf), "%d", x.numposts); if (getdata_str(y++, 0, "文章數目:", buf, 10, DOECHO, genbuf)) if ((tmp = atoi(buf)) >= 0) -- cgit v1.2.3 From 3fbfbac63d50619f92d98140fa7f59f570a180c7 Mon Sep 17 00:00:00 2001 From: piaip Date: Mon, 31 Aug 2009 05:54:49 +0000 Subject: * merge pwcu branch with trunk git-svn-id: http://opensvn.csie.org/pttbbs/branches/pttbbs.pwcu@4806 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- include/proto.h | 4 ++-- mbbsd/admin.c | 2 +- mbbsd/bbs.c | 9 ++++++++- mbbsd/friend.c | 41 ++++++++++++++++++++++++++++++++--------- mbbsd/gamble.c | 16 ++++++++++++++-- mbbsd/ordersong.c | 8 ++++---- mbbsd/screen.c | 3 ++- mbbsd/user.c | 1 - 8 files changed, 63 insertions(+), 21 deletions(-) diff --git a/include/proto.h b/include/proto.h index bc32e07d..a70298b3 100644 --- a/include/proto.h +++ b/include/proto.h @@ -187,8 +187,8 @@ const char *ask_tmpbuf(int y); /* emaildb */ #ifdef USE_EMAILDB -int emaildb_check_email (const char * email, int email_len); -int emaildb_update_email(const char * userid, int userid_len, const char * email, int email_len); +int emaildb_check_email (const char *email, int email_len); +int emaildb_update_email(const char *userid, int userid_len, const char *email, int email_len); #endif #ifdef USE_REGCHECKD int regcheck_ambiguous_userid_exist(const char *userid); diff --git a/mbbsd/admin.c b/mbbsd/admin.c index 9dcc5b8a..011f81e7 100644 --- a/mbbsd/admin.c +++ b/mbbsd/admin.c @@ -108,7 +108,7 @@ upgrade_passwd(userec_t *puser) memset(puser->chkpad0, 0, sizeof(puser->chkpad0)); memset(puser->chkpad1, 0, sizeof(puser->chkpad1)); memset(puser->chkpad2, 0, sizeof(puser->chkpad2)); - puser->lastseen = 0; + puser->lastseen= 0; puser->version = PASSWD_VERSION; return ; } diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c index 183bc16f..2bcf9538 100644 --- a/mbbsd/bbs.c +++ b/mbbsd/bbs.c @@ -1235,7 +1235,12 @@ do_generalboardreply(/*const*/ fileheader_t * fhdr) if (!CheckPostRestriction(currbid)) { - getdata(b_lines - 1, 0, ANSI_COLOR(1;31) "▲ 無法回應至看板。 " ANSI_RESET + getdata(b_lines - 1, 0, +#ifdef USE_PFTERM + ANSI_COLOR(1;31) "▲ 無法回應至看板。 " ANSI_RESET +#else + "▲ 無法回應至看板。 " +#endif "改回應至 (M)作者信箱 (Q)取消?[Q] ", genbuf, sizeof(genbuf), LCECHO); switch (genbuf[0]) { @@ -3212,6 +3217,8 @@ view_postinfo(int ent, const fileheader_t * fhdr, const char *direct, int crs_ln outc(' '); outs(ANSI_CLRTOEND); move(area_l, 0); + // TODO XXX support wide terminal someday. + prints("┌─────────────────────────────────────┐\n"); aidu = fn2aidu((char *)fhdr->filename); diff --git a/mbbsd/friend.c b/mbbsd/friend.c index 1d63335e..f3f88925 100644 --- a/mbbsd/friend.c +++ b/mbbsd/friend.c @@ -234,7 +234,7 @@ delete_friend_from_file(const char *file, const char *string, int case_sensitiv #define MAX_EXPIRE_MONTH (800) int -friend_validate(int type, int expire) +friend_validate(int type, int expire, int badpost) { FILE *fp = NULL, *nfp = NULL; char fpath[PATHLEN]; @@ -247,6 +247,8 @@ friend_validate(int type, int expire) expire *= DAY_SECONDS *30; else expire = 0; + if (badpost < 0 || badpost > UCHAR_MAX) + badpost = 0; syncnow(); setfriendfile(fpath, type); @@ -271,12 +273,25 @@ friend_validate(int type, int expire) if (searchuser(buf, NULL)) { - if (expire > 0) { + if (expire > 0 || badpost > 0) { + userec_t *pu = &u; // drop user if (now-lastlogin) longer than expire*month getuser(buf, &u); - if (now - u.lastlogin > expire) - continue; + if (expire > 0) + { + // XXX lastlogin was NOT counting people with PERM_HIDE... + // although we will have 'lastseen' in future, + // never count people with PERM_HIDE. + if (!(PERM_HIDE(pu)) && + now - u.lastlogin > expire) + continue; + } + if (badpost > 0) + { + if (u.badpost >= badpost) + continue; + } } fputs(genbuf, nfp); } @@ -486,9 +501,8 @@ friend_edit(int type) } getdata(1, 0, (count ? "(A)增加(D)刪除(E)修改(P)引入(L)列出(K)清空" - ANSI_COLOR(33) "(C)整理有效名單" ANSI_RESET - "(W)水球(Q)結束?[Q] " : - "(A)增加 (P)引入其他名單 (Q)結束?[Q] "), + "(C)整理有效名單(W)水球(Q)結束?[Q] " : + "(A)增加 (P)引入其他名單 (Q)結束?[Q] "), uident, 3, LCECHO); if (uident[0] == 'a') { move(1, 0); @@ -498,11 +512,20 @@ friend_edit(int type) dirty = 1; } } else if (uident[0] == 'c') { + int expire = 0, badpost = 0; getdata(2, 0, - "要從名單中清除幾個月沒上站(包含帳號已消失)的使用者?", + "要從名單中清除幾個月沒上站(包含帳號已消失)的使用者? (0=不清除)[0] ", uident, 4, NUMECHO); + expire = atoi(uident); +#ifdef ASSESS + getdata(3, 0, + "要從名單中清除有幾篇以上劣文的使用者? (0=不清除)[0] ", + uident, 4, NUMECHO); +#endif + badpost = atoi(uident); + // delete all users that not in list. - friend_validate(type, atoi(uident)); + friend_validate(type, expire, badpost); dirty = 1; } else if (uident[0] == 'p') { friend_append(type, count); diff --git a/mbbsd/gamble.c b/mbbsd/gamble.c index 93388e1f..a3d59236 100644 --- a/mbbsd/gamble.c +++ b/mbbsd/gamble.c @@ -258,7 +258,13 @@ openticket(int bid) do { do { getdata(20, 0, - ANSI_COLOR(1) "選擇中獎的號碼(0:不開獎 99:取消退錢)" ANSI_RESET ":", buf, 3, LCECHO); +#ifdef USE_PFTERM + ANSI_COLOR(1) "選擇中獎的號碼(0:不開獎 99:取消退錢)" + ANSI_RESET ":" +#else + "選擇中獎的號碼(0:不開獎 99:取消退錢):" +#endif + , buf, 3, LCECHO); bet = atoi(buf); move(0, 0); clrtoeol(); @@ -267,7 +273,13 @@ openticket(int bid) unlockutmpmode(); return 0; } - getdata(21, 0, ANSI_COLOR(1) "再次確認輸入號碼" ANSI_RESET ":", buf, 3, LCECHO); + getdata(21, 0, +#ifdef USE_PFTERM + ANSI_COLOR(1) "再次確認輸入號碼" ANSI_RESET ":" +#else + "再次確認輸入號碼:" +#endif + , buf, 3, LCECHO); } while (bet != atoi(buf)); // before we fork to process, diff --git a/mbbsd/ordersong.c b/mbbsd/ordersong.c index be9844d8..477b85f1 100644 --- a/mbbsd/ordersong.c +++ b/mbbsd/ordersong.c @@ -45,15 +45,15 @@ do_order_song(void) "公然侮辱 誹謗\n" "若有上述違規情形,站方將保留決定是否公開播放的權利\n" "如不同意請按 (3) 離開。" ANSI_RESET "\n"); + getdata(18, 0, #ifdef USE_PFTERM - getdata(18, 0, "請選擇 " ANSI_COLOR(1) "1)" ANSI_RESET " 開始點歌、" + "請選擇 " ANSI_COLOR(1) "1)" ANSI_RESET " 開始點歌、" ANSI_COLOR(1) "2)" ANSI_RESET " 看歌本、" "或是 " ANSI_COLOR(1) "3)" ANSI_RESET " 離開: ", - ans, sizeof(ans), DOECHO); #else - getdata(18, 0, "請選擇 1)開始點歌 2)看歌本 3)離開: ", - ans, sizeof(ans), DOECHO); + "請選擇 1)開始點歌 2)看歌本 3)離開: ", #endif + ans, sizeof(ans), DOECHO); if (ans[0] == '1') break; diff --git a/mbbsd/screen.c b/mbbsd/screen.c index 5537a4f3..23d00c20 100644 --- a/mbbsd/screen.c +++ b/mbbsd/screen.c @@ -160,7 +160,8 @@ getyx_ansi(int *py, int *px) if (slp->len < 1) return; c = slp->data[x]; - *px += (strlen((char*)slp->data) - strlen_noansi((char*)slp->data)); + slp->data[x] = 0; + *px -= (strlen((char*)slp->data) - strlen_noansi((char*)slp->data)); slp->data[x] = c; } diff --git a/mbbsd/user.c b/mbbsd/user.c index 0e8fdb53..76f3593b 100644 --- a/mbbsd/user.c +++ b/mbbsd/user.c @@ -1204,7 +1204,6 @@ u_info(void) reload_money(); user_display(cuser_ref, 0); uinfo_query (cuser.userid, 0, usernum); - // XXX TODO update from u to cuser pwcuReload(); strlcpy(currutmp->nickname, cuser.nickname, sizeof(currutmp->nickname)); return 0; -- cgit v1.2.3 From 9625ba5c2eec9ec4e0deb037acf1b1398710cf0b Mon Sep 17 00:00:00 2001 From: piaip Date: Mon, 31 Aug 2009 14:59:29 +0000 Subject: * optimize exit save git-svn-id: http://opensvn.csie.org/pttbbs/branches/pttbbs.pwcu@4807 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/passwd.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/mbbsd/passwd.c b/mbbsd/passwd.c index 514959c5..548342c9 100644 --- a/mbbsd/passwd.c +++ b/mbbsd/passwd.c @@ -381,6 +381,7 @@ pwcuSaveUserFlags() int pwcuSetSignature(unsigned char newsig) { + // XXX you MUST save this variable in pwcuExitSave(); cuser.signature = newsig; return 0; } @@ -388,6 +389,7 @@ pwcuSetSignature(unsigned char newsig) int pwcuSetWaterballMode(unsigned int bm) { + // XXX you MUST save this variable in pwcuExitSave(); bm &= WATER_MASK; cuser.uflag2 &= ~WATER_MASK; cuser.uflag2 |= bm; @@ -397,6 +399,7 @@ pwcuSetWaterballMode(unsigned int bm) int pwcuToggleSortBoard () { + // XXX you MUST save this variable in pwcuExitSave(); cuser.uflag ^= BRDSORT_FLAG; return 0; } @@ -404,6 +407,7 @@ pwcuToggleSortBoard () int pwcuToggleFriendList() { + // XXX you MUST save this variable in pwcuExitSave(); cuser.uflag ^= FRIEND_FLAG; return 0; } @@ -411,6 +415,7 @@ pwcuToggleFriendList() int pwcuToggleUserFlag (unsigned int mask) { + // XXX you MUST save this variable in pwcuExitSave(); cuser.uflag ^= mask; return 0; } @@ -418,6 +423,7 @@ pwcuToggleUserFlag (unsigned int mask) int pwcuToggleUserFlag2 (unsigned int mask) { + // XXX you MUST save this variable in pwcuExitSave(); cuser.uflag2 ^= mask; return 0; } @@ -475,8 +481,21 @@ int pwcuLoginSave () int pwcuExitSave () { + int dirty = 0; + uint32_t uflag, uflag2, withme; + uint8_t invisible, pager; + int32_t money; + PWCU_START(); + // save variables for dirty check + uflag = u.uflag; + uflag2= u.uflag2; + withme= u.withme; + pager = u.pager; + invisible = u.invisible; + money = u.money; + // uflag and uflag2: always trust cuser except REJ_OUTTAMAIL _SETBY_BIT(cuser.uflag2, REJ_OUTTAMAIL, (u.uflag2 & REJ_OUTTAMAIL)); u.uflag = cuser.uflag; @@ -491,12 +510,38 @@ pwcuExitSave () u.invisible = currutmp->invisible; u.withme = currutmp->withme; u.pager = currutmp->pager; + u.money = moneyof(usernum); // XXX 當初設計的人把 mind 設計成非 NULL terminated 的... // assert(sizeof(u.mind) == sizeof(currutmp->mind)); - memcpy(u.mind,currutmp->mind, sizeof(u.mind)); + if (memcmp(u.mind, currutmp->mind, sizeof(u.mind)) != 0) + { + memcpy(u.mind,currutmp->mind, sizeof(u.mind)); + dirty = 1; + } + + // check dirty + if (!dirty && ( + uflag != u.uflag || + uflag2 != u.uflag2|| + withme != u.withme|| + pager != u.pager || + money != u.money || + invisible != u.invisible)) + { + dirty = 1; + } + +#ifdef DEBUG + log_filef("log/pwcu_exitsave.log", LOG_CREAT, + "%s exit %s at %s\n", u.userid, + dirty ? "DIRTY" : "CLEAN", + Cdatelite(&now)); +#endif - reload_money(); + // no need to save data. + if (!dirty) + return 0; PWCU_END(); } -- cgit v1.2.3 From f57bb85ab4790b70354c84e74aabebf4b72c5624 Mon Sep 17 00:00:00 2001 From: piaip Date: Sat, 5 Sep 2009 13:25:16 +0000 Subject: * fix: user habit: wrong index in uflag2 selection git-svn-id: http://opensvn.csie.org/pttbbs/branches/pttbbs.pwcu@4808 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/user.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mbbsd/user.c b/mbbsd/user.c index 76f3593b..056c2cda 100644 --- a/mbbsd/user.c +++ b/mbbsd/user.c @@ -479,7 +479,7 @@ void Customize(void) { pwcuToggleUserFlag(masks1[key]); } else { - pwcuToggleUserFlag2(masks2[key]); + pwcuToggleUserFlag2(masks2[key-ic]); } continue; } -- cgit v1.2.3 From 2933c380c0ffa5422cc5bc74e23e6a92440cca92 Mon Sep 17 00:00:00 2001 From: piaip Date: Sat, 5 Sep 2009 14:22:59 +0000 Subject: * change display name of numlogindays to macro (we may change it again in future) git-svn-id: http://opensvn.csie.org/pttbbs/branches/pttbbs.pwcu@4809 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- include/common.h | 2 ++ mbbsd/chat.c | 2 +- mbbsd/talk.c | 4 ++-- mbbsd/user.c | 6 +++--- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/include/common.h b/include/common.h index d3fee9b5..bf7a1cef 100644 --- a/include/common.h +++ b/include/common.h @@ -111,6 +111,8 @@ #define STR_POST1 "看板:" #define STR_POST2 "站內:" +#define STR_LOGINDAYS "登入天次" + /* AIDS */ #define AID_DISPLAYNAME "文章代碼(AID)" /* end of AIDS */ diff --git a/mbbsd/chat.c b/mbbsd/chat.c index 9c73c39d..fcf63144 100644 --- a/mbbsd/chat.c +++ b/mbbsd/chat.c @@ -204,7 +204,7 @@ chat_query(char *arg) char buf[ANSILINELEN], *ptr; FILE *fp; - snprintf(buf, sizeof(buf), "%s(%s) 上站資歷 %d 點,發表過 %d 篇文章", + snprintf(buf, sizeof(buf), "%s(%s) " STR_LOGINDAYS " %d ,發表過 %d 篇文章", xuser.userid, xuser.nickname, xuser.numlogindays, xuser.numposts); printchatline(buf); diff --git a/mbbsd/talk.c b/mbbsd/talk.c index 997e7e8e..2ed5b5c8 100644 --- a/mbbsd/talk.c +++ b/mbbsd/talk.c @@ -471,7 +471,7 @@ my_query(const char *uident) // ------------------------------------------------------------ - prints("《上站資歷》%d 點", muser.numlogindays); + prints("《" STR_LOGINDAYS "》%d ", muser.numlogindays); #ifdef SHOW_LOGINOK if (!(muser.userlevel & PERM_LOGINOK)) outs(" (尚未通過認證)"); @@ -3307,7 +3307,7 @@ talkreply(void) strlcpy(currutmp->msgs[0].last_call_in, "呼叫、呼叫,聽到請回答 (Ctrl-R)", sizeof(currutmp->msgs[0].last_call_in)); currutmp->msgs[0].msgmode = MSGMODE_TALK; - prints("對方來自 [%s],上站資歷 %d 點,文章共 %d 篇\n", + prints("對方來自 [%s]," STR_LOGINDAYS " %d ,文章共 %d 篇\n", uip->from, xuser.numlogindays, xuser.numposts); if (is_chess) diff --git a/mbbsd/user.c b/mbbsd/user.c index 056c2cda..5f94c135 100644 --- a/mbbsd/user.c +++ b/mbbsd/user.c @@ -173,7 +173,7 @@ user_display(const userec_t * u, int adminmode) prints("\t\t認證資料: %s\n", u->justify); } - prints("\t\t上站文章: 上站資歷 %d / 文章 %d 篇\n", + prints("\t\t上站文章: " STR_LOGINDAYS " %d / 文章 %d 篇\n", u->numlogindays, u->numposts); sethomedir(genbuf, u->userid); @@ -850,13 +850,13 @@ uinfo_query(const char *orig_uid, int adminmode, int unum) do { int max_days = (x.lastlogin - x.firstlogin) / DAY_SECONDS; snprintf(genbuf, sizeof(genbuf), "%d", x.numlogindays); - if (getdata_str(y++, 0, "上線資歷:", buf, 10, DOECHO, genbuf)) + if (getdata_str(y++, 0, STR_LOGINDAYS, buf, 10, DOECHO, genbuf)) if ((tmp = atoi(buf)) >= 0) x.numlogindays = tmp; if (x.numlogindays > max_days) { x.numlogindays = max_days; - vmsgf("根據此使用者最後上線時間,資歷最大值為 %d.", max_days); + vmsgf("根據此使用者最後上線時間,最大值為 %d.", max_days); move(--y, 0); clrtobot(); continue; } -- cgit v1.2.3 From 12fe18273839304131da83bbb54a639896fd69f0 Mon Sep 17 00:00:00 2001 From: piaip Date: Sun, 6 Sep 2009 13:07:50 +0000 Subject: * experimental: add user recent login history view git-svn-id: http://opensvn.csie.org/pttbbs/branches/pttbbs.pwcu@4810 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- include/common.h | 4 ++++ mbbsd/mbbsd.c | 22 ++++++++++++++++++++++ mbbsd/menu.c | 21 ++++++++++++++++++++- 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/include/common.h b/include/common.h index bf7a1cef..da8a20be 100644 --- a/include/common.h +++ b/include/common.h @@ -43,6 +43,10 @@ #define FN_BOARDHELP "etc/board.help" #define FN_USERMEMO "memo.txt" // 使用者個人記事本 #define FN_BADLOGIN "logins.bad" // in BBSHOME & user directory +#define FN_RECENTLOGIN "logins.recent" // in user directory +#ifndef SZ_RECENTLOGIN +#define SZ_RECENTLOGIN (32000) +#endif // 自訂刪除文章時出現的標題與檔案 diff --git a/mbbsd/mbbsd.c b/mbbsd/mbbsd.c index 04e9cbb8..a99a5145 100644 --- a/mbbsd/mbbsd.c +++ b/mbbsd/mbbsd.c @@ -1115,6 +1115,26 @@ inline static void check_bad_login(void) } } +inline static void append_log_recent_login() +{ + char buf[STRLEN], logfn[PATHLEN]; + int szlogfn = 0, szlogentry = 0; + + // prepare log format + snprintf(buf, sizeof(buf), "%s %-15s\n", + Cdatelite(&login_start_time), fromhost); + szlogentry = strlen(buf); // should be the same for all entries + + setuserfile(logfn, FN_RECENTLOGIN); + szlogfn = dashs(logfn); + if (szlogfn > SZ_RECENTLOGIN) { + // rotate to 1/4 of SZ_RECENTLOGIN + delete_records(logfn, szlogentry, 1, + (szlogfn-(SZ_RECENTLOGIN/4)) / szlogentry); + } + log_file(logfn, LOG_CREAT, buf); +} + inline static void birthday_make_a_wish(const struct tm *ptime, const struct tm *tmp) { if (tmp->tm_mday != ptime->tm_mday) { @@ -1235,6 +1255,8 @@ user_login(void) if( vans("是否要顯示「壽星」於使用者名單上?(y/N)") == 'y' ) currutmp->birth = 1; } + + append_log_recent_login(); check_bad_login(); check_mailbox_quota(); check_register(); diff --git a/mbbsd/menu.c b/mbbsd/menu.c index fdba2381..fbffa4da 100644 --- a/mbbsd/menu.c +++ b/mbbsd/menu.c @@ -570,6 +570,12 @@ static const commands_t namelist[] = { {NULL, 0, NULL} }; +static int u_view_recentlogin() +{ + char fn[PATHLEN]; + setuserfile(fn, FN_RECENTLOGIN); + return more(fn, YEA); +} static const commands_t myfilelist[] = { {u_editplan, PERM_LOGINOK, "QQueryEdit 編輯名片檔"}, @@ -577,6 +583,11 @@ static const commands_t myfilelist[] = { {NULL, 0, NULL} }; +static const commands_t myuserlog[] = { + {u_view_recentlogin, 0, "LLRecent Login 最近上站記錄"}, + {NULL, 0, NULL} +}; + static int u_myfiles() { @@ -584,6 +595,13 @@ u_myfiles() return 0; } +static int +u_mylogs() +{ + domenu(M_UMENU, "個人記錄", 'L', myuserlog); + return 0; +} + void Customize(); // user.c @@ -600,8 +618,9 @@ static const commands_t userlist[] = { {u_customize, PERM_BASIC, "UUCustomize 個人化設定"}, {u_info, PERM_LOGINOK, "IInfo 設定個人資料與密碼"}, {calendar, PERM_LOGINOK, "CCalendar 行事曆"}, - {u_loginview, PERM_BASIC, "LLogin View 選擇進站畫面"}, + {u_loginview, PERM_BASIC, "VVLogin View 選擇進站畫面"}, {u_myfiles, PERM_LOGINOK, "MMy Files 【個人檔案】 (名片,簽名檔...)"}, + {u_mylogs, PERM_LOGINOK, "LLMy Logs 【個人記錄】 (最近上線...)"}, #if HAVE_FREECLOAK {u_cloak, PERM_LOGINOK, "KKCloak 隱身術"}, #else -- cgit v1.2.3 From cdc7c144df5bfa137d3f9dcdcb3fcbdd1561e579 Mon Sep 17 00:00:00 2001 From: piaip Date: Sun, 6 Sep 2009 13:09:10 +0000 Subject: let's try this name git-svn-id: http://opensvn.csie.org/pttbbs/branches/pttbbs.pwcu@4811 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- include/common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/common.h b/include/common.h index da8a20be..6e25ce2b 100644 --- a/include/common.h +++ b/include/common.h @@ -115,7 +115,7 @@ #define STR_POST1 "看板:" #define STR_POST2 "站內:" -#define STR_LOGINDAYS "登入天次" +#define STR_LOGINDAYS "登入次數" /* AIDS */ #define AID_DISPLAYNAME "文章代碼(AID)" -- cgit v1.2.3 From 2eb5731c5011ca46377f4301965c15cf7750b49a Mon Sep 17 00:00:00 2001 From: piaip Date: Sun, 6 Sep 2009 13:25:08 +0000 Subject: * adjust numlogindays calculation - should be rounded to each day. git-svn-id: http://opensvn.csie.org/pttbbs/branches/pttbbs.pwcu@4812 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/passwd.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mbbsd/passwd.c b/mbbsd/passwd.c index 548342c9..3bb8e352 100644 --- a/mbbsd/passwd.c +++ b/mbbsd/passwd.c @@ -442,6 +442,7 @@ int pwcuLoginSave () // was decided. int regdays = 0, prev_regdays = 0; int reftime = login_start_time; + time4_t baseref = 0; PWCU_START(); // new host from 'fromhost' @@ -451,12 +452,15 @@ int pwcuLoginSave () // this must be valid. assert(login_start_time > 0); + // adjust base reference by rounding to beginning of each day (0:00am) + baseref = u.firstlogin - (u.firstlogin % DAY_SECONDS); + // invalid session? if (reftime < u.lastlogin) reftime = u.lastlogin; - regdays = ( reftime - u.firstlogin) / DAY_SECONDS; - prev_regdays = (u.lastlogin - u.firstlogin) / DAY_SECONDS; + regdays = ( reftime - baseref) / DAY_SECONDS; + prev_regdays = (u.lastlogin - baseref) / DAY_SECONDS; // assert(regdays >= prev_regdays); if (u.numlogindays > prev_regdays) -- cgit v1.2.3 From e2a6b4b4502bd8926777c9b17747e65528422464 Mon Sep 17 00:00:00 2001 From: piaip Date: Sun, 6 Sep 2009 13:38:14 +0000 Subject: * refine message with quantity git-svn-id: http://opensvn.csie.org/pttbbs/branches/pttbbs.pwcu@4813 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- include/common.h | 1 + mbbsd/chat.c | 3 ++- mbbsd/talk.c | 4 ++-- mbbsd/user.c | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/common.h b/include/common.h index 6e25ce2b..59316fb3 100644 --- a/include/common.h +++ b/include/common.h @@ -116,6 +116,7 @@ #define STR_POST2 "站內:" #define STR_LOGINDAYS "登入次數" +#define STR_LOGINDAYS_QTY "次" /* AIDS */ #define AID_DISPLAYNAME "文章代碼(AID)" diff --git a/mbbsd/chat.c b/mbbsd/chat.c index fcf63144..9ce7d6c3 100644 --- a/mbbsd/chat.c +++ b/mbbsd/chat.c @@ -204,7 +204,8 @@ chat_query(char *arg) char buf[ANSILINELEN], *ptr; FILE *fp; - snprintf(buf, sizeof(buf), "%s(%s) " STR_LOGINDAYS " %d ,發表過 %d 篇文章", + snprintf(buf, sizeof(buf), + "%s(%s) " STR_LOGINDAYS " %d " STR_LOGINDAYS_QTY ",發表過 %d 篇文章", xuser.userid, xuser.nickname, xuser.numlogindays, xuser.numposts); printchatline(buf); diff --git a/mbbsd/talk.c b/mbbsd/talk.c index 2ed5b5c8..b11799c5 100644 --- a/mbbsd/talk.c +++ b/mbbsd/talk.c @@ -471,7 +471,7 @@ my_query(const char *uident) // ------------------------------------------------------------ - prints("《" STR_LOGINDAYS "》%d ", muser.numlogindays); + prints("《" STR_LOGINDAYS "》%d " STR_LOGINDAYS_QTY, muser.numlogindays); #ifdef SHOW_LOGINOK if (!(muser.userlevel & PERM_LOGINOK)) outs(" (尚未通過認證)"); @@ -3307,7 +3307,7 @@ talkreply(void) strlcpy(currutmp->msgs[0].last_call_in, "呼叫、呼叫,聽到請回答 (Ctrl-R)", sizeof(currutmp->msgs[0].last_call_in)); currutmp->msgs[0].msgmode = MSGMODE_TALK; - prints("對方來自 [%s]," STR_LOGINDAYS " %d ,文章共 %d 篇\n", + prints("對方來自 [%s]," STR_LOGINDAYS " %d " STR_LOGINDAYS_QTY ",文章共 %d 篇\n", uip->from, xuser.numlogindays, xuser.numposts); if (is_chess) diff --git a/mbbsd/user.c b/mbbsd/user.c index 5f94c135..e1d6dc26 100644 --- a/mbbsd/user.c +++ b/mbbsd/user.c @@ -173,7 +173,7 @@ user_display(const userec_t * u, int adminmode) prints("\t\t認證資料: %s\n", u->justify); } - prints("\t\t上站文章: " STR_LOGINDAYS " %d / 文章 %d 篇\n", + prints("\t\t上站文章: " STR_LOGINDAYS " %d " STR_LOGINDAYS_QTY "/ 文章 %d 篇\n", u->numlogindays, u->numposts); sethomedir(genbuf, u->userid); -- cgit v1.2.3 From d4d7b4113cf03c906f9d408526b0dee082adde53 Mon Sep 17 00:00:00 2001 From: piaip Date: Mon, 7 Sep 2009 02:11:19 +0000 Subject: * allow query old login number (for self only) * merge latest git-svn-id: http://opensvn.csie.org/pttbbs/branches/pttbbs.pwcu@4816 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- include/common.h | 2 +- include/pttstruct.h | 3 ++- mbbsd/bbs.c | 2 +- mbbsd/talk.c | 13 +++++++++++-- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/include/common.h b/include/common.h index 59316fb3..d5400070 100644 --- a/include/common.h +++ b/include/common.h @@ -45,7 +45,7 @@ #define FN_BADLOGIN "logins.bad" // in BBSHOME & user directory #define FN_RECENTLOGIN "logins.recent" // in user directory #ifndef SZ_RECENTLOGIN -#define SZ_RECENTLOGIN (32000) +#define SZ_RECENTLOGIN (16000) // size of max recent log before rotation #endif diff --git a/include/pttstruct.h b/include/pttstruct.h index 2e130628..deae733a 100644 --- a/include/pttstruct.h +++ b/include/pttstruct.h @@ -95,7 +95,8 @@ typedef struct userec_t { char career[40]; /* 學歷職業 */ char phone[20]; /* 電話 */ - char chkpad1[52]; + uint32_t old_numlogins; /* 轉換前的 numlogins, 備份檢視用 */ + char chkpad1[48]; time4_t lastseen; /* 最近上站時間(隱身不計) */ time4_t chkpad2[2]; /* in case 有人忘了把 time4_t 調好... */ // 以上應為 sizeof(chicken_t) 同等大小 diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c index 2bcf9538..11ad652e 100644 --- a/mbbsd/bbs.c +++ b/mbbsd/bbs.c @@ -1133,7 +1133,7 @@ do_general(int garbage) demoney(money); pwcuIncNumPost(); addPost = 1; - prints("這是您的第 %d 篇有效文章,稿酬 %d 元", + prints("這是您的第 %d 篇有效文章,獲得稿酬 %d 元", cuser.numposts, money); } else { // no money, no record. diff --git a/mbbsd/talk.c b/mbbsd/talk.c index b11799c5..5c906e9c 100644 --- a/mbbsd/talk.c +++ b/mbbsd/talk.c @@ -436,6 +436,7 @@ my_query(const char *uident) { userec_t muser; int tuid, fri_stat = 0; + int is_self = 0; userinfo_t *uentp; const char *sex[8] = {MSG_BIG_BOY, MSG_BIG_GIRL, @@ -454,6 +455,8 @@ my_query(const char *uident) if ((uentp = (userinfo_t *) search_ulist(tuid))) fri_stat = friend_stat(currutmp, uentp); + if (strcmp(muser.userid, cuser.userid) == 0) + is_self =1; // ------------------------------------------------------------ @@ -465,17 +468,23 @@ my_query(const char *uident) prints( "《經濟狀況》%s", money_level(muser.money)); - if (uentp && ((fri_stat & HFM && !uentp->invisible) || strcmp(muser.userid,cuser.userid) == 0)) + if (uentp && ((fri_stat & HFM && !uentp->invisible) || is_self)) prints(" ($%d)", muser.money); outc('\n'); // ------------------------------------------------------------ prints("《" STR_LOGINDAYS "》%d " STR_LOGINDAYS_QTY, muser.numlogindays); + + if (is_self && muser.old_numlogins) + prints(" (舊值: %d) ", muser.old_numlogins); + else + { #ifdef SHOW_LOGINOK if (!(muser.userlevel & PERM_LOGINOK)) outs(" (尚未通過認證)"); #endif + } move(vgety(), 40); prints("《有效文章》%d 篇", muser.numposts); @@ -514,7 +523,7 @@ my_query(const char *uident) muser.five_win, muser.five_lose, muser.five_tie, muser.chc_win, muser.chc_lose, muser.chc_tie); - if ((uentp && ((fri_stat & HFM) || strcmp(muser.userid,cuser.userid) == 0) && !uentp->invisible)) + if ((uentp && ((fri_stat & HFM) || is_self) && !uentp->invisible)) prints("《 性 別 》%-28.28s\n", sex[muser.sex % 8]); showplans_userec(&muser); -- cgit v1.2.3 From dfeb1a9e710617bb8b800ec0a11350d1c9f79489 Mon Sep 17 00:00:00 2001 From: piaip Date: Mon, 7 Sep 2009 05:54:36 +0000 Subject: * move oldnumlogin display from talk=>query to user=>info. git-svn-id: http://opensvn.csie.org/pttbbs/branches/pttbbs.pwcu@4817 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/talk.c | 6 ------ mbbsd/user.c | 7 +++++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/mbbsd/talk.c b/mbbsd/talk.c index 5c906e9c..e807cf64 100644 --- a/mbbsd/talk.c +++ b/mbbsd/talk.c @@ -475,16 +475,10 @@ my_query(const char *uident) // ------------------------------------------------------------ prints("《" STR_LOGINDAYS "》%d " STR_LOGINDAYS_QTY, muser.numlogindays); - - if (is_self && muser.old_numlogins) - prints(" (舊值: %d) ", muser.old_numlogins); - else - { #ifdef SHOW_LOGINOK if (!(muser.userlevel & PERM_LOGINOK)) outs(" (尚未通過認證)"); #endif - } move(vgety(), 40); prints("《有效文章》%d 篇", muser.numposts); diff --git a/mbbsd/user.c b/mbbsd/user.c index e1d6dc26..8d93d95e 100644 --- a/mbbsd/user.c +++ b/mbbsd/user.c @@ -173,8 +173,11 @@ user_display(const userec_t * u, int adminmode) prints("\t\t認證資料: %s\n", u->justify); } - prints("\t\t上站文章: " STR_LOGINDAYS " %d " STR_LOGINDAYS_QTY "/ 文章 %d 篇\n", - u->numlogindays, u->numposts); + prints("\t\t使用記錄: " STR_LOGINDAYS " %d " STR_LOGINDAYS_QTY + ,u->numlogindays); + if (u->old_numlogins) + prints(" (轉換新制前: %d)", u->old_numlogins); + prints(" / 文章 %d 篇\n", u->numposts); sethomedir(genbuf, u->userid); prints("\t\t私人信箱: %d 封 (購買信箱: %d 封)\n", -- cgit v1.2.3 From 8a3a6d8827cf9ba4073dbdff48e0cdfeb7d012c3 Mon Sep 17 00:00:00 2001 From: piaip Date: Tue, 8 Sep 2009 00:23:32 +0000 Subject: * improve check_BM frequency * refine messages git-svn-id: http://opensvn.csie.org/pttbbs/branches/pttbbs.pwcu@4819 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/mbbsd.c | 14 ++++++++------ mbbsd/passwd.c | 3 +++ mbbsd/user.c | 2 +- mbbsd/var.c | 3 ++- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/mbbsd/mbbsd.c b/mbbsd/mbbsd.c index a99a5145..f10bec3d 100644 --- a/mbbsd/mbbsd.c +++ b/mbbsd/mbbsd.c @@ -1049,11 +1049,6 @@ setup_utmp(int mode) strip_nonebig5((unsigned char *)currutmp->nickname, sizeof(currutmp->nickname)); strip_nonebig5((unsigned char *)currutmp->mind, sizeof(currutmp->mind)); - // XXX 這個 check 花不少時間,有點間隔比較好 - // TODO XXX 使用 numlogindays 有點問題,同一天內多次 login 會狂檢查... - if ((cuser.userlevel & PERM_BM) && !(cuser.numlogindays % 20)) - check_BM(); /* Ptt 自動取下離職板主權力 */ - // resolve fromhost #if defined(WHERE) @@ -1260,9 +1255,16 @@ user_login(void) check_bad_login(); check_mailbox_quota(); check_register(); - pwcuLoginSave(); + pwcuLoginSave(); // is_first_login_of_today is only valid after pwcuLoginSave. restore_backup(); + // XXX 這個 check 花不少時間,有點間隔比較好 + if (HasUserPerm(PERM_BM) && + (cuser.numlogindays % 10 == 0) && // when using numlogindays, check with is_first_login_of_today + is_first_login_of_today ) + check_BM(); /* 自動取下離職板主權力 */ + + } else if (strcmp(cuser.userid, STR_GUEST) == 0) { /* guest */ init_guest_info(); diff --git a/mbbsd/passwd.c b/mbbsd/passwd.c index 3bb8e352..bfb64224 100644 --- a/mbbsd/passwd.c +++ b/mbbsd/passwd.c @@ -468,7 +468,10 @@ int pwcuLoginSave () // calculate numlogindays (only increase one per each key) if (regdays > prev_regdays) + { ++u.numlogindays; + is_first_login_of_today = 1; + } cuser.numlogindays = u.numlogindays; // update last login time diff --git a/mbbsd/user.c b/mbbsd/user.c index 8d93d95e..1656869c 100644 --- a/mbbsd/user.c +++ b/mbbsd/user.c @@ -176,7 +176,7 @@ user_display(const userec_t * u, int adminmode) prints("\t\t使用記錄: " STR_LOGINDAYS " %d " STR_LOGINDAYS_QTY ,u->numlogindays); if (u->old_numlogins) - prints(" (轉換新制前: %d)", u->old_numlogins); + prints("(轉換新制前結算:%d)", u->old_numlogins); prints(" / 文章 %d 篇\n", u->numposts); sethomedir(genbuf, u->userid); diff --git a/mbbsd/var.c b/mbbsd/var.c index 727e9163..eb178940 100644 --- a/mbbsd/var.c +++ b/mbbsd/var.c @@ -371,9 +371,10 @@ char local_article; char fromhost[STRLEN] = "\0"; char fromhost_masked[32] = "\0"; // masked 'fromhost' char water_usies = 0; +char over18 = 0; +char is_first_login_of_today = 0; FILE *fp_writelog = NULL; water_t *water, *swater[6], *water_which; -char over18 = 0; /* chc_play.c */ -- cgit v1.2.3 From ca5ee5b2867227c04827eb952685f8212715d1c7 Mon Sep 17 00:00:00 2001 From: piaip Date: Tue, 8 Sep 2009 03:33:23 +0000 Subject: * merge trunk * merge current * allow view old 'goodpost' just like old numlogin git-svn-id: http://opensvn.csie.org/pttbbs/branches/pttbbs.pwcu@4820 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- include/proto.h | 4 ---- mbbsd/user.c | 3 ++- util/mandex.c | 37 +++++++++++++++++++++++++++++++------ 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/include/proto.h b/include/proto.h index a70298b3..ea232c78 100644 --- a/include/proto.h +++ b/include/proto.h @@ -53,11 +53,7 @@ void BlogMain(int); #endif /* assess */ -int inc_goodpost(const char *, int num); int inc_badpost(const char *, int num); -int inc_goodsale(const char *, int num); -int inc_badsale(const char *, int num); -//void set_assess(int uid, unsigned char num, int type); /* bbs */ void delete_allpost(const char *userid); diff --git a/mbbsd/user.c b/mbbsd/user.c index 1656869c..b6bc04b0 100644 --- a/mbbsd/user.c +++ b/mbbsd/user.c @@ -208,7 +208,8 @@ user_display(const userec_t * u, int adminmode) // conditional fields #ifdef ASSESS - prints("\t\t劣文數目: %d\n", u->badpost); + prints("\t\t劣文數目: %u (舊優文結算: %u)\n", + (unsigned int)u->badpost, (unsigned int)u->goodpost); #endif // ASSESS #ifdef CHESSCOUNTRY diff --git a/util/mandex.c b/util/mandex.c index eb8de895..14399476 100644 --- a/util/mandex.c +++ b/util/mandex.c @@ -108,6 +108,7 @@ man_index(const char * brdname) stat(buf, &st); curr_brdinfo.k = st.st_size; printf("(%s)[%dK] d: %d f: %d\n", buf, curr_brdinfo.k, curr_brdinfo.ndir, curr_brdinfo.nfile); + fflush(stdout); // in case the output is redirected... setdirpath(fpath, buf, fn_index); rename(buf, fpath); @@ -198,7 +199,7 @@ output_chart(const boardinfo_t * board, const int nbrds) } fclose(fp); } -static boardinfo_t board[MAX_BOARD]; +static boardinfo_t board[MAX_BOARD+1]; static const char dirs[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', @@ -257,10 +258,22 @@ int main(int argc, char* argv[]) /* process all boards */ if (checkrebuild && (fd = open("man/.rank.cache", O_RDONLY)) >= 0) { + int dirty = 0; read(fd, board, sizeof(board)); close(fd); qsort(board, MAX_BOARD, sizeof(boardinfo_t), sortbyname); - for (nb = 0; board[nb].bname[0] != 0; ++nb); + for (nb = 0; board[nb].bname[0] != 0; ++nb) { + /* delete non-exist boards */ + if (getbnum(board[nb].bname) == 0) { + memset(&(board[nb]), 0, sizeof(boardinfo_t)); + dirty = 1; + } + } + /* sort again if dirty */ + if (dirty) { + qsort(board, MAX_BOARD, sizeof(boardinfo_t), sortbyname); + for (nb = 0; board[nb].bname[0] != 0; ++nb); + } nSorted = nb; } else { memset(board, 0, sizeof(board)); @@ -285,6 +298,7 @@ int main(int argc, char* argv[]) sprintf(fpath, "man/boards/%c/%s/.rebuild", dirs[i], fname); if (access(fpath, 0) < 0) { printf("skip no modify board %s\n", fname); + fflush(stdout); // in case the output is redirected... continue; } unlink(fpath); @@ -292,11 +306,22 @@ int main(int argc, char* argv[]) man_index(fname); - if (curr_brdinfo.k) { - if (!(biptr = bsearch(fname, board, nSorted, sizeof(boardinfo_t), sortbyname))) - biptr = &board[nb++]; - memcpy(biptr, &curr_brdinfo, sizeof(boardinfo_t)); + if (!curr_brdinfo.k) + continue; + + // determine if this board was not seen in partial update queue + biptr = bsearch(fname, board, nSorted, sizeof(boardinfo_t), sortbyname); + if (!biptr) + { + // give up if exceeded max entry + if (nb >= MAX_BOARD) + continue; + biptr = &board[nb++]; } + + // update record + assert(biptr); + memcpy(biptr, &curr_brdinfo, sizeof(boardinfo_t)); } closedir(dirp); } -- cgit v1.2.3 From 4a8c783de7fad2c94d0be94549904d7c542a7e74 Mon Sep 17 00:00:00 2001 From: piaip Date: Tue, 8 Sep 2009 07:01:02 +0000 Subject: * message refine * adjust login time base (must consider timezone when rounding to midnight) git-svn-id: http://opensvn.csie.org/pttbbs/branches/pttbbs.pwcu@4821 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/passwd.c | 12 ++++++++++-- mbbsd/user.c | 3 ++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/mbbsd/passwd.c b/mbbsd/passwd.c index bfb64224..cfddca87 100644 --- a/mbbsd/passwd.c +++ b/mbbsd/passwd.c @@ -1,6 +1,7 @@ /* $Id$ */ #define PWCU_IMPL #include "bbs.h" +#include "time.h" #ifdef _BBS_UTIL_C_ #error sorry, mbbsd/passwd.c does not support utility mode anymore. please use libcmbbs instead. @@ -442,7 +443,9 @@ int pwcuLoginSave () // was decided. int regdays = 0, prev_regdays = 0; int reftime = login_start_time; - time4_t baseref = 0; + time4_t baseref = 0; + struct tm baseref_tm = {0}; + PWCU_START(); // new host from 'fromhost' @@ -453,7 +456,12 @@ int pwcuLoginSave () assert(login_start_time > 0); // adjust base reference by rounding to beginning of each day (0:00am) - baseref = u.firstlogin - (u.firstlogin % DAY_SECONDS); + baseref = u.firstlogin; + if (localtime4_r(&baseref, &baseref_tm)) + { + baseref_tm.tm_sec = baseref_tm.tm_min = baseref_tm.tm_hour = 0; + baseref = mktime(&baseref_tm); + } // invalid session? if (reftime < u.lastlogin) diff --git a/mbbsd/user.c b/mbbsd/user.c index b6bc04b0..edfbc17f 100644 --- a/mbbsd/user.c +++ b/mbbsd/user.c @@ -173,7 +173,8 @@ user_display(const userec_t * u, int adminmode) prints("\t\t認證資料: %s\n", u->justify); } - prints("\t\t使用記錄: " STR_LOGINDAYS " %d " STR_LOGINDAYS_QTY + // XXX enable STR_LOGINDAYS_QTY after removed old_numlogins. + prints("\t\t使用記錄: " STR_LOGINDAYS " %d " // STR_LOGINDAYS_QTY ,u->numlogindays); if (u->old_numlogins) prints("(轉換新制前結算:%d)", u->old_numlogins); -- cgit v1.2.3 From 2c65881a1feb924fd5e5658735167db2586a58d7 Mon Sep 17 00:00:00 2001 From: piaip Date: Tue, 8 Sep 2009 11:54:02 +0000 Subject: * refine message, due to too many new BMs not knowing why their registration was canceled. git-svn-id: http://opensvn.csie.org/pttbbs/branches/pttbbs.pwcu@4822 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/register.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mbbsd/register.c b/mbbsd/register.c index af04508e..fcca3b6b 100644 --- a/mbbsd/register.c +++ b/mbbsd/register.c @@ -1055,7 +1055,7 @@ check_register(void) " 通告站長以獲得進階使用權力。\n\n"); outs(" 如果您之前曾使用 email 等認證方式通過註冊認證但又看到此訊息,\n" - " 代表您的認證由於資料不完整已被取消。\n"); + " 代表您的認證由於資料不完整已被取消 (常見於申請開新看板的板主)。\n"); u_register(); @@ -1223,7 +1223,8 @@ u_register(void) move(3, 0); prints(" 您的註冊申請單尚在處理中(處理順位: %d),請耐心等候\n\n", i); outs(" * 如果您之前曾使用 email 等認證方式通過註冊認證但又看到此訊息,\n" - " 代表您的認證由於資料不完整已被取消。\n\n" + " 代表您的認證由於資料不完整已被取消 (由於建立新看板的流程中\n" + " 有驗證板主註冊資料的程序,若您最近有申請開新看板中則屬此項)\n\n" " * 如果您已收到註冊碼卻看到這個畫面,代表您在使用 Email 註冊後\n" " " ANSI_COLOR(1;31) "又另外申請了站長直接人工審核的註冊申請單。" ANSI_RESET "\n" -- cgit v1.2.3 From 2e8dbc427eb9b70b674018ff8f96b0eca105f0a2 Mon Sep 17 00:00:00 2001 From: piaip Date: Thu, 10 Sep 2009 09:01:36 +0000 Subject: * code refine git-svn-id: http://opensvn.csie.org/pttbbs/branches/pttbbs.pwcu@4823 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/bbs.c | 10 ++++++---- mbbsd/board.c | 3 ++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c index 11ad652e..efac93c4 100644 --- a/mbbsd/bbs.c +++ b/mbbsd/bbs.c @@ -3093,10 +3093,12 @@ del_post(int ent, fileheader_t * fhdr, char *direct) { userec_t xuser; assert(tusernum != usernum); - passwd_query(tusernum, &xuser); - if (xuser.numposts > 0) - xuser.numposts--; - passwd_update(tusernum, &xuser); + // TODO we're doing redundant i/o here... merge and refine someday + if (passwd_sync_query(tusernum, &xuser) == 0) { + if (xuser.numposts > 0) + xuser.numposts--; + passwd_sync_update(tusernum, &xuser); + } deumoney(tusernum, -fhdr->multi.money); sendalert_uid(tusernum, ALERT_PWD_PERM); #ifdef USE_COOLDOWN diff --git a/mbbsd/board.c b/mbbsd/board.c index e2bad4a8..6bc7f6da 100644 --- a/mbbsd/board.c +++ b/mbbsd/board.c @@ -1343,7 +1343,8 @@ set_menu_BM(char *BM) { if (!HasUserPerm(PERM_NOCITIZEN) && (HasUserPerm(PERM_ALLBOARD) || is_uBM(BM, cuser.userid))) { currmode |= MODE_GROUPOP; - // cuser.userlevel |= PERM_SYSSUBOP | PERM_BM; + // XXX 不是很確定是否該在這邊 save level? + pwcuBitEnableLevel(PERM_SYSSUBOP | PERM_BM); } } -- cgit v1.2.3 From f115309f094fb58ce49a14a24d58144aa13d3e5c Mon Sep 17 00:00:00 2001 From: piaip Date: Thu, 10 Sep 2009 09:03:31 +0000 Subject: * make const_cuser default git-svn-id: http://opensvn.csie.org/pttbbs/branches/pttbbs.pwcu@4824 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- include/pttstruct.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/pttstruct.h b/include/pttstruct.h index deae733a..4a8b76a9 100644 --- a/include/pttstruct.h +++ b/include/pttstruct.h @@ -139,7 +139,7 @@ typedef struct userec_t { char pad_tail[28]; } PACKSTRUCT userec_t; -#ifdef CONST_CUSER +#ifndef NO_CONST_CUSER // const userec_t cuser; # define cuser_ref ((const userec_t*)&pwcuser) # define cuser (*cuser_ref) -- cgit v1.2.3