summaryrefslogtreecommitdiffstats
path: root/mbbsd
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
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')
-rw-r--r--mbbsd/chicken.c52
-rw-r--r--mbbsd/register.c50
2 files changed, 81 insertions, 21 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])
{
diff --git a/mbbsd/register.c b/mbbsd/register.c
index 538060a8..3eb9e8e3 100644
--- a/mbbsd/register.c
+++ b/mbbsd/register.c
@@ -1,6 +1,11 @@
/* $Id$ */
#include "bbs.h"
+#define FN_REGISTER_LOG "register.log"
+#define FN_JUSTIFY "justify"
+#define FN_JUSTIFY_WAIT "justify.wait"
+#define FN_REJECT_NOTIFY "justify.reject"
+
////////////////////////////////////////////////////////////////////////////
// Password Hash
////////////////////////////////////////////////////////////////////////////
@@ -51,7 +56,8 @@ checkpasswd(const char *passwd, char *plain)
////////////////////////////////////////////////////////////////////////////
// Value Validation
////////////////////////////////////////////////////////////////////////////
-static int HaveRejectStr(const char *s, const char **rej)
+static int
+HaveRejectStr(const char *s, const char **rej)
{
int i;
char *ptr, *rejectstr[] =
@@ -118,7 +124,8 @@ bad_user_id(const char *userid)
return 0;
}
-char *isvalidname(char *rname)
+static char *
+isvalidname(char *rname)
{
#ifdef FOREIGN_REG
return NULL;
@@ -142,7 +149,8 @@ char *isvalidname(char *rname)
}
-static char *isvalidcareer(char *career)
+static char *
+isvalidcareer(char *career)
{
#ifndef FOREIGN_REG
const char *rejectstr[] = {NULL};
@@ -162,7 +170,8 @@ static char *isvalidcareer(char *career)
return NULL;
}
-char *isvalidaddr(char *addr)
+static char *
+isvalidaddr(char *addr)
{
const char *rejectstr[] =
{"地球", "銀河", "火星", NULL};
@@ -186,7 +195,8 @@ char *isvalidaddr(char *addr)
return NULL;
}
-static char *isvalidphone(char *phone)
+static char *
+isvalidphone(char *phone)
{
int i;
for( i = 0 ; phone[i] != 0 ; ++i )
@@ -333,7 +343,7 @@ justify_wait(char *userid, char *phone, char *career,
char *rname, char *addr, char *mobile)
{
char buf[PATHLEN];
- sethomefile(buf, userid, "justify.wait");
+ sethomefile(buf, userid, FN_JUSTIFY_WAIT);
if (phone[0] != 0) {
FILE* fn = fopen(buf, "w");
assert(fn);
@@ -343,7 +353,8 @@ justify_wait(char *userid, char *phone, char *career,
}
}
-static void email_justify(const userec_t *muser)
+static void
+email_justify(const userec_t *muser)
{
char tmp[IDLEN + 1], buf[256], genbuf[256];
/*
@@ -699,9 +710,7 @@ check_register(void)
if (HasUserPerm(PERM_LOGINOK))
return;
- // see admin.c
- setuserfile(fn, "justify.reject");
-
+ setuserfile(fn, FN_REJECT_NOTIFY);
/*
* 避免使用者被退回註冊單後,在知道退回的原因之前,
@@ -938,7 +947,7 @@ u_register(void)
sex_is[0] = (cuser.sex % 8) + '1';
sex_is[1] = 0;
career[0] = phone[0] = '\0';
- sethomefile(genbuf, cuser.userid, "justify.wait");
+ sethomefile(genbuf, cuser.userid, FN_JUSTIFY_WAIT);
if ((fn = fopen(genbuf, "r"))) {
fgets(genbuf, sizeof(genbuf), fn);
chomp(genbuf);
@@ -1019,11 +1028,11 @@ u_register(void)
cuser.userlevel |= (PERM_LOGINOK | PERM_POST);
outs("\n註冊成功\, 重新上站後將取得完整權限\n"
"請按下任一鍵跳離後重新上站~ :)");
- sethomefile(genbuf, cuser.userid, "justify.wait");
+ sethomefile(genbuf, cuser.userid, FN_JUSTIFY_WAIT);
unlink(genbuf);
snprintf(cuser.justify, sizeof(cuser.justify),
"%s:%s:email", phone, career);
- sethomefile(genbuf, cuser.userid, "justify");
+ sethomefile(genbuf, cuser.userid, FN_JUSTIFY);
log_file(genbuf, LOG_CREAT, cuser.justify);
pressanykey();
u_exit("registed");
@@ -1180,7 +1189,6 @@ u_register(void)
// Administration (SYSOP Validation)
/////////////////////////////////////////////////////////////////////////////
-#define FN_REGISTER_LOG "register.log"
#define REJECT_REASONS (6)
#define REASON_LEN (60)
static const char *reasonstr[REJECT_REASONS] = {
@@ -1214,11 +1222,11 @@ regform_accept(const char *userid, const char *justify)
strlcpy(muser.email, "x", sizeof(muser.email));
// handle files
- sethomefile(buf, muser.userid, "justify.wait");
+ sethomefile(buf, muser.userid, FN_JUSTIFY_WAIT);
unlink(buf);
- sethomefile(buf, muser.userid, "justify.reject");
+ sethomefile(buf, muser.userid, FN_REJECT_NOTIFY);
unlink(buf);
- sethomefile(buf, muser.userid, "justify");
+ sethomefile(buf, muser.userid, FN_JUSTIFY);
log_filef(buf, LOG_CREAT, "%s\n", muser.justify);
// update password file
@@ -1251,7 +1259,7 @@ regform_reject(const char *userid, char *reason)
muser.userlevel &= ~(PERM_LOGINOK | PERM_POST);
// handle files
- sethomefile(buf, muser.userid, "justify.wait");
+ sethomefile(buf, muser.userid, FN_JUSTIFY_WAIT);
unlink(buf);
// update password file
@@ -1335,7 +1343,7 @@ prompt_regform_ui()
ANSI_RESET);
}
-void
+static void
resolve_reason(char *s, int y)
{
// should start with REASON_FIRSTABBREV
@@ -1799,7 +1807,7 @@ scan_register_form(const char *regfile, int automode, const char *target_uid)
// XXX TODO notify users?
sendalert(muser.userid, ALERT_PWD_PERM); // force to reload perm
- sethomefile(buf, muser.userid, "justify");
+ sethomefile(buf, muser.userid, FN_JUSTIFY);
log_file(buf, LOG_CREAT, genbuf);
if ((fout = fopen(FN_REGISTER_LOG, "a"))) {
@@ -1810,7 +1818,7 @@ scan_register_form(const char *regfile, int automode, const char *target_uid)
fprintf(fout, "----\n");
fclose(fout);
}
- sethomefile(genbuf, muser.userid, "justify.wait");
+ sethomefile(genbuf, muser.userid, FN_JUSTIFY_WAIT);
unlink(genbuf);
break;
}