summaryrefslogtreecommitdiffstats
path: root/mbbsd/chicken.c
diff options
context:
space:
mode:
authorpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2008-03-07 13:39:27 +0800
committerpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2008-03-07 13:39:27 +0800
commit80d861dff5d757ef5827054a0633fdbe56ff356a (patch)
tree799074eecacd8dea67e868f90cb7a8bf3ee34c05 /mbbsd/chicken.c
parentb6bbb6238653053f6f30211560166394bfcb7381 (diff)
downloadpttbbs-80d861dff5d757ef5827054a0633fdbe56ff356a.tar
pttbbs-80d861dff5d757ef5827054a0633fdbe56ff356a.tar.gz
pttbbs-80d861dff5d757ef5827054a0633fdbe56ff356a.tar.bz2
pttbbs-80d861dff5d757ef5827054a0633fdbe56ff356a.tar.lz
pttbbs-80d861dff5d757ef5827054a0633fdbe56ff356a.tar.xz
pttbbs-80d861dff5d757ef5827054a0633fdbe56ff356a.tar.zst
pttbbs-80d861dff5d757ef5827054a0633fdbe56ff356a.zip
- chicken/upgrade: add live upgrade function
- register: general source code refine git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3974 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd/chicken.c')
-rw-r--r--mbbsd/chicken.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/mbbsd/chicken.c b/mbbsd/chicken.c
index d2d10d4e..11bd267c 100644
--- a/mbbsd/chicken.c
+++ b/mbbsd/chicken.c
@@ -7,6 +7,8 @@
#define NUM_KINDS 15 /* 有多少種動物 */
#define CHICKENLOG "etc/chicken"
+// enable if you want to run live upgrade
+// #define CHICKEN_LIVE_UPGRADE
static const char * const cage[17] = {
"誕生", "週歲", "幼年", "少年", "青春", "青年",
@@ -133,6 +135,13 @@ void
chicken_query(const char *userid)
{
chicken_t xchicken;
+
+#ifdef CHICKEN_LIVE_UPGRADE
+ // live update
+ vmsg("PTT 系統進行更新,本週暫停開放寵物查詢。");
+ return;
+#endif
+
if (!load_chicken(userid, &xchicken))
{
move(1, 0);
@@ -851,6 +860,13 @@ void
chicken_toggle_death(const char *uid)
{
chicken_t *mychicken = load_live_chicken(uid);
+
+#ifdef CHICKEN_LIVE_UPGRADE
+ // live update
+ vmsg("PTT 系統進行更新,本週暫停開放寵物設定。");
+ return;
+#endif
+
if (!uid)
return;
if (!mychicken)
@@ -872,12 +888,48 @@ chicken_toggle_death(const char *uid)
#define lockreturn0(unmode, state) if(lockutmpmode(unmode, state)) return 0
+#ifdef CHICKEN_LIVE_UPGRADE
+static void
+chicken_live_upgrade()
+{
+ char fn[PATHLEN];
+ FILE *fp = NULL;
+ setuserfile(fn, FN_CHICKEN);
+
+ if (dashf(fn))
+ return;
+
+ if (!cuser.old_chicken.name[0] &&
+ !cuser.old_chicken.cbirth &&
+ !cuser.old_chicken.hp_max)
+ return;
+
+ // write to data.
+ fp = fopen(fn, "wb");
+ fwrite(&cuser.old_chicken, sizeof(chicken_t), 1, fp);
+ fclose(fp);
+#if 0 // enable if you want logs
+ log_filef("log/chicken_live_upgrade", LOG_CREAT,
+ "%s upgrade chicken at %s",
+ cuser.userid, ctime4(&now));
+#endif
+}
+#endif // CHICKEN_LIVE_UPGRADE
+
int
chicken_main(void)
{
int age;
chicken_t *mychicken = load_live_chicken(cuser.userid);
+#ifdef CHICKEN_LIVE_UPGRADE
+ if (mychicken == NULL)
+ {
+ chicken_live_upgrade();
+ mychicken = load_live_chicken(cuser.userid);
+ }
+#endif
+
lockreturn0(CHICKEN, LOCK_MULTI);
if (mychicken && !mychicken->name[0])
{