summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2009-09-17 22:40:00 +0800
committerpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2009-09-17 22:40:00 +0800
commit966e30ac3e3bac63b329126a1ca9d06a5e82e3c9 (patch)
treec413ec8c8fb489288eb779c728b1f2e2c810b56e
parent37e523a52a0c7f19e328f645584fb29abb20a8a8 (diff)
downloadpttbbs-966e30ac3e3bac63b329126a1ca9d06a5e82e3c9.tar
pttbbs-966e30ac3e3bac63b329126a1ca9d06a5e82e3c9.tar.gz
pttbbs-966e30ac3e3bac63b329126a1ca9d06a5e82e3c9.tar.bz2
pttbbs-966e30ac3e3bac63b329126a1ca9d06a5e82e3c9.tar.lz
pttbbs-966e30ac3e3bac63b329126a1ca9d06a5e82e3c9.tar.xz
pttbbs-966e30ac3e3bac63b329126a1ca9d06a5e82e3c9.tar.zst
pttbbs-966e30ac3e3bac63b329126a1ca9d06a5e82e3c9.zip
* refine pwcuExitSave again, prevent the initial query if possible.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4851 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--include/proto.h2
-rw-r--r--mbbsd/passwd.c111
-rw-r--r--mbbsd/talk.c2
-rw-r--r--mbbsd/user.c2
4 files changed, 51 insertions, 66 deletions
diff --git a/include/proto.h b/include/proto.h
index db785acc..a3e87a7a 100644
--- a/include/proto.h
+++ b/include/proto.h
@@ -721,7 +721,7 @@ int pwcuRegisterSetInfo (const char *rname,
// non-important based variables (only save on exit)
int pwcuSetSignature (unsigned char newsig);
-int pwcuSetWaterballMode(unsigned int bm);
+int pwcuSetPagerUIType (unsigned int uitype);
int pwcuToggleSortBoard ();
int pwcuToggleFriendList();
int pwcuToggleUserFlag (unsigned int mask); // not saved until pwcuSaveUserFlags
diff --git a/mbbsd/passwd.c b/mbbsd/passwd.c
index efa23f43..ab7fb86e 100644
--- a/mbbsd/passwd.c
+++ b/mbbsd/passwd.c
@@ -417,11 +417,19 @@ pwcuToggleFriendList()
// non-important variables (only save on exit)
+static char
+pwcu_dirty;
+
int
-pwcuSetWaterballMode(unsigned int bm)
+pwcuSetPagerUIType (unsigned int uitype)
{
// XXX you MUST save this variable in pwcuExitSave();
- cuser.pager_ui_type = bm % PAGER_UI_TYPES;
+ uitype %= PAGER_UI_TYPES;
+ if (cuser.pager_ui_type != uitype)
+ {
+ pwcu_dirty = 1;
+ cuser.pager_ui_type = uitype;
+ }
return 0;
}
@@ -429,7 +437,11 @@ int
pwcuSetSignature(unsigned char newsig)
{
// XXX you MUST save this variable in pwcuExitSave();
- cuser.signature = newsig;
+ if (cuser.signature != newsig)
+ {
+ pwcu_dirty = 1;
+ cuser.signature = newsig;
+ }
return 0;
}
@@ -450,6 +462,7 @@ int pwcuLoginSave ()
time4_t baseref = 0;
struct tm baseref_tm = {0};
+ // XXX one more read here... can we avoid it?
PWCU_START();
// new host from 'fromhost'
@@ -500,79 +513,51 @@ int pwcuLoginSave ()
int
pwcuExitSave ()
{
- int dirty = 0;
- uint32_t uflag, uflag2, withme;
- uint8_t invisible, pager, signature, pager_ui_type;
- int32_t money;
-
- PWCU_START();
-
- // XXX if PWCU_START uses sync_query, then money is
- // already changed... however, maybe not a problem here,
- // since every deumoney() should write difference.
-
- // save variables for dirty check
- uflag = u.uflag;
- uflag2 = u.uflag2;
-
- withme = u.withme;
- pager = u.pager;
- invisible = u.invisible;
-
- money = u.money;
- signature = u.signature;
- pager_ui_type = u.pager_ui_type;
+ // determine dirty
+ if (pwcu_dirty ||
+ cuser.withme != currutmp->withme ||
+ cuser.pager != currutmp->pager ||
+ cuser.invisible != currutmp->invisible ||
+ (memcmp(cuser.mind,currutmp->mind, sizeof(cuser.mind)) != 0) )
+ {
+ // maybe dirty, let's work harder.
+ PWCU_START();
+ pwcu_dirty = 1;
- // configure new utmp values
- u.withme = currutmp->withme;
- u.pager = currutmp->pager;
- u.invisible = currutmp->invisible;
+ // XXX we may work harder to determine if this is a real
+ // dirty cache, however maybe it's not that important.
- u.signature = cuser.signature;
- u.money = moneyof(usernum);
- u.pager_ui_type = cuser.pager_ui_type;
+ // configure new utmp values
+ u.withme = currutmp->withme;
+ u.pager = currutmp->pager;
+ u.invisible = currutmp->invisible;
+ memcpy(u.mind, currutmp->mind, sizeof(u.mind)); // XXX u.mind is NOT NULL-terminated.
- // XXX 當初設計的人把 mind 設計成非 NULL terminated 的...
- // assert(sizeof(u.mind) == sizeof(currutmp->mind));
- if (memcmp(u.mind, currutmp->mind, sizeof(u.mind)) != 0)
- {
- memcpy(u.mind,currutmp->mind, sizeof(u.mind));
- dirty = 1;
- }
+ // configure those changed by 'not important variables' API
+ u.signature = cuser.signature;
+ u.pager_ui_type = cuser.pager_ui_type;
+ // u.money = moneyof(usernum); // should be already updated by deumoney
- // check dirty
- if (!dirty && (
- uflag != u.uflag ||
- uflag2 != u.uflag2||
- withme != u.withme||
- pager != u.pager ||
- money != u.money ||
- pager_ui_type != u.pager_ui_type ||
- signature != u.signature||
- invisible != u.invisible))
- {
- dirty = 1;
+#ifdef DEBUG
+ log_filef("log/pwcu_exitsave.log", LOG_CREAT, "%-13s exit %s at %s\n",
+ cuser.userid, pwcu_dirty ? "DIRTY" : "CLEAN", Cdatelite(&now));
+#endif
+ PWCU_END();
+ // XXX return 0 here (PWCU_END), following code is not executed.
}
-
#ifdef DEBUG
- log_filef("log/pwcu_exitsave.log", LOG_CREAT,
- "%s exit %s at %s\n", u.userid,
- dirty ? "DIRTY" : "CLEAN",
- Cdatelite(&now));
+ log_filef("log/pwcu_exitsave.log", LOG_CREAT, "%-13s exit %s at %s\n",
+ cuser.userid, pwcu_dirty ? "DIRTY" : "CLEAN", Cdatelite(&now));
#endif
-
- // no need to save data.
- if (!dirty)
- return 0;
-
- PWCU_END();
+ return 0;
}
int
pwcuReload ()
{
- int r = passwd_sync_query(usernum, &cuser);
// XXX TODO verify cuser structure?
+ int r = passwd_sync_query(usernum, &cuser);
+ pwcu_dirty = 0;
return r;
}
diff --git a/mbbsd/talk.c b/mbbsd/talk.c
index bbeb7c30..1144de63 100644
--- a/mbbsd/talk.c
+++ b/mbbsd/talk.c
@@ -3015,7 +3015,7 @@ userlist(void)
if (HasUserPerm(PERM_LOGINOK)) {
static const char *wm[PAGER_UI_TYPES] = {"一般", "進階", "未來"};
- pwcuSetWaterballMode((cuser.pager_ui_type +1) % PAGER_UI_TYPES_USER);
+ pwcuSetPagerUIType((cuser.pager_ui_type +1) % PAGER_UI_TYPES_USER);
/* vmsg cannot support multi lines */
move(b_lines - 4, 0);
clrtobot();
diff --git a/mbbsd/user.c b/mbbsd/user.c
index 29951d77..c71cf6fe 100644
--- a/mbbsd/user.c
+++ b/mbbsd/user.c
@@ -499,7 +499,7 @@ void Customize(void)
{
case 0:
{
- pwcuSetWaterballMode((cuser.pager_ui_type +1) % PAGER_UI_TYPES_USER);
+ pwcuSetPagerUIType((cuser.pager_ui_type +1) % PAGER_UI_TYPES_USER);
vmsg("修改水球模式後請正常離線再重新上線");
dirty = 1;
}