summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2009-08-28 21:57:40 +0800
committerpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2009-08-28 21:57:40 +0800
commit2230c0a8c5a4eb2397673d37e709454195c5e284 (patch)
treed6b2f7d72e55aa8aa40af5a3bcbe5ffb296dcb20
parent209a53de9d25820b20e3b5591cd1efb7e221fc24 (diff)
downloadpttbbs-2230c0a8c5a4eb2397673d37e709454195c5e284.tar
pttbbs-2230c0a8c5a4eb2397673d37e709454195c5e284.tar.gz
pttbbs-2230c0a8c5a4eb2397673d37e709454195c5e284.tar.bz2
pttbbs-2230c0a8c5a4eb2397673d37e709454195c5e284.tar.lz
pttbbs-2230c0a8c5a4eb2397673d37e709454195c5e284.tar.xz
pttbbs-2230c0a8c5a4eb2397673d37e709454195c5e284.tar.zst
pttbbs-2230c0a8c5a4eb2397673d37e709454195c5e284.zip
* 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
-rw-r--r--include/proto.h31
-rw-r--r--include/pttstruct.h3
-rw-r--r--mbbsd/admin.c1
-rw-r--r--mbbsd/angel.c10
-rw-r--r--mbbsd/assess.c4
-rw-r--r--mbbsd/bbs.c29
-rw-r--r--mbbsd/cal.c5
-rw-r--r--mbbsd/edit.c2
-rw-r--r--mbbsd/emaildb.c4
-rw-r--r--mbbsd/mail.c3
-rw-r--r--mbbsd/mbbsd.c115
-rw-r--r--mbbsd/ordersong.c2
-rw-r--r--mbbsd/passwd.c287
-rw-r--r--mbbsd/talk.c7
-rw-r--r--mbbsd/user.c9
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;
}