diff options
author | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2008-03-29 04:08:52 +0800 |
---|---|---|
committer | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2008-03-29 04:08:52 +0800 |
commit | b4cfd7600a14957e4d75a0a84dc3dcb4fe3c15b9 (patch) | |
tree | d8be290082c441ae25ec5d9b44d5e6efec5544b3 | |
parent | b1feff5b340ae2fe4f2c4dc0e38fa9fbb13e1c29 (diff) | |
download | pttbbs-b4cfd7600a14957e4d75a0a84dc3dcb4fe3c15b9.tar pttbbs-b4cfd7600a14957e4d75a0a84dc3dcb4fe3c15b9.tar.gz pttbbs-b4cfd7600a14957e4d75a0a84dc3dcb4fe3c15b9.tar.bz2 pttbbs-b4cfd7600a14957e4d75a0a84dc3dcb4fe3c15b9.tar.lz pttbbs-b4cfd7600a14957e4d75a0a84dc3dcb4fe3c15b9.tar.xz pttbbs-b4cfd7600a14957e4d75a0a84dc3dcb4fe3c15b9.tar.zst pttbbs-b4cfd7600a14957e4d75a0a84dc3dcb4fe3c15b9.zip |
- make regform2 complete by upgrading scripts.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4035 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | UPDATING | 4 | ||||
-rw-r--r-- | include/proto.h | 3 | ||||
-rw-r--r-- | mbbsd/chicken.c | 2 | ||||
-rw-r--r-- | mbbsd/menu.c | 2 | ||||
-rw-r--r-- | mbbsd/register.c | 82 | ||||
-rw-r--r-- | mbbsd/var.c | 1 | ||||
-rw-r--r-- | upgrade/r4035_regnew.c | 169 |
7 files changed, 228 insertions, 35 deletions
@@ -15,6 +15,10 @@ https://opensvn.csie.org/traccgi/pttbbs/changeset/2273 ----------------------------------------------------------------------------- +r4035: [REGISTER] +���U�t�ξɤJ Regform v2, �Х� upgrade/r4035_regnew �ಾ�w����U��C +(Regform2 �i�� USE_REGFORM2 �}��) + r3968: [CHICKEN] �� Chicken �h�X PASSWD, �åB��� mmap �P�B�C �аO�o��������� upgrade/r3968_chicken �ಾ��ƫ�A���} BBS�C diff --git a/include/proto.h b/include/proto.h index 2fabbfba..f324d338 100644 --- a/include/proto.h +++ b/include/proto.h @@ -514,10 +514,11 @@ int getindex(const char *fpath, fileheader_t *fh, int start); /* register */ int u_register(void); -int getnewuserid(void); int bad_user_id(const char *userid); +int getnewuserid(void); int checkpasswd(const char *passwd, char *test); int setupnewuser(const userec_t *user); +int regform_estimate_queuesize(); void new_register(void); void check_register(void); void delregcodefile(void); diff --git a/mbbsd/chicken.c b/mbbsd/chicken.c index 4de2bb85..368ddd19 100644 --- a/mbbsd/chicken.c +++ b/mbbsd/chicken.c @@ -846,7 +846,7 @@ recover_chicken(chicken_t * thechicken) chicken_type[(int)thechicken->type], price); outmsg(buf); bell(); - getdata_str(21, 0, " ��ܡG(N:�|�H��/y:��������)", buf, 3, LCECHO, "N"); + getdata(21, 0, " ��� (N:�|�H��/y:��������): ", buf, 3, LCECHO); if (buf[0] == 'y' || buf[0] == 'Y') { reload_money(); if (cuser.money < price) { diff --git a/mbbsd/menu.c b/mbbsd/menu.c index 6aaf3399..e34685db 100644 --- a/mbbsd/menu.c +++ b/mbbsd/menu.c @@ -55,7 +55,7 @@ showtitle(const char *title, const char *mid) mid = " �A���s�H�� "; mid_attr = ANSI_COLOR(41;5); } else if ( HasUserPerm(PERM_ACCTREG) ) { - int nreg = dashs((char *)fn_register) / 163; + int nreg = regform_estimate_queuesize(); if(nreg > 100) { sprintf(buf, " �� %03d ���f�� ", nreg); diff --git a/mbbsd/register.c b/mbbsd/register.c index b1dc3975..face58b2 100644 --- a/mbbsd/register.c +++ b/mbbsd/register.c @@ -6,6 +6,9 @@ #define FN_JUSTIFY_WAIT "justify.wait" #define FN_REJECT_NOTIFY "justify.reject" +// Regform1 file name (deprecated) +#define fn_register "register.new" + // New style (Regform2) file names: #define FN_REGFORM "regform" // registration form in user home #define FN_REGFORM_LOG "regform.log" // regform history in user home @@ -945,46 +948,54 @@ u_register(void) char phone[20], career[40], email[50], birthday[11], sex_is[2]; unsigned char year, mon, day; char inregcode[14], regcode[50]; - char ans[3], *ptr, *errcode; + char ans[3], *errcode; char genbuf[200]; FILE *fn; + int i = 0; if (cuser.userlevel & PERM_LOGINOK) { outs("�z�������T�{�w�g�����A���ݶ�g�ӽЪ�"); return XEASY; } - if ((fn = fopen(fn_register, "r"))) { - int i =0; - while (fgets(genbuf, STRLEN, fn)) { - if ((ptr = strchr(genbuf, '\n'))) - *ptr = '\0'; - if (strncmp(genbuf, "uid: ", 5) != 0) - continue; - i++; - if(strcmp(genbuf + 5, cuser.userid) != 0) - continue; - fclose(fn); - /* idiots complain about this, so bug them */ - clear(); - move(3, 0); - prints(" �z�����U�ӽг�|�b�B�z��(�B�z����: %d)�A�Э@�ߵ���\n\n", i); - outs(" �p�G�z�w������U�X�o�ݨ�o�ӵe���A���N���z�b�ϥ� Email ���U��\n"); - outs(" " ANSI_COLOR(1;31) "�S�t�~�ӽФF���������H�u�f�֪����U�ӽг�C" - ANSI_RESET "\n\n"); - outs(" �i�J�H�u�f�ֵ{�ǫ� Email ���U�۰ʥ��ġA�����U�X�]�S�ΡA\n"); - outs(" �n����f�֧��� (�|�h��ܦh�ɶ��A�q�`�_�X�Ƥ�) �A�ҥH�Э@�ߵ��ԡC\n\n"); - - /* �U���O����� code �һݭn�� message */ + +#ifdef USE_REGFORM2 + // TODO REGFORM 2 checks 2 parts. + i = file_find_record(FN_REQLIST, cuser.userid); +#else + fn = fopen(fn_register, "rt"); + while (fn && fgets(genbuf, STRLEN, fn)) { + if (strncmp(genbuf, "uid: ", 5) != 0) + continue; + i++; + if ((ptr = strchr(genbuf, '\n'))) + *ptr = '\0'; + if(strcmp(genbuf + 5, cuser.userid) == 0) + break; + genbuf[0] = 0; + } + if (!genbuf[0]) i = 0; // drop index if not found. + if (fn) fclose(fn); +#endif // !USE_REGFORM2 + + if (i > 0) + { + clear(); + move(3, 0); + prints(" �z�����U�ӽг�|�b�B�z��(�B�z����: %d)�A�Э@�ߵ���\n\n", i); + outs(" �p�G�z�w������U�X�o�ݨ�o�ӵe���A���N���z�b�ϥ� Email ���U��\n"); + outs(" " ANSI_COLOR(1;31) "�S�t�~�ӽФF���������H�u�f�֪����U�ӽг�C" + ANSI_RESET "\n\n"); + outs(" �i�J�H�u�f�ֵ{�ǫ� Email ���U�۰ʥ��ġA�����U�X�]�S�ΡA\n"); + outs(" �n����f�֧��� (�|�h��ܦh�ɶ��A�q�`�_�X�Ƥ�) �A�ҥH�Э@�ߵ��ԡC\n\n"); + /* �U���O����� code �һݭn�� message */ #if 0 - outs(" �t�~�Ъ`�N�A�Y�����f���U��ɱz���b���W�h�|�L�k�f�֡B�۰ʸ��L�C\n"); - outs(" �ҥH���Լf�֮ɽФű����C�Y�W�L��T�Ѥ����Q�f��A�q�`�N�O�o�ӭ�]�C\n"); + outs(" �t�~�Ъ`�N�A�Y�����f���U��ɱz���b���W�h�|�L�k�f�֡B�۰ʸ��L�C\n"); + outs(" �ҥH���Լf�֮ɽФű����C�Y�W�L��T�Ѥ����Q�f��A�q�`�N�O�o�ӭ�]�C\n"); #endif - - vmsg("�z�����U�ӽг�|�b�B�z��"); - return FULLUPDATE; - } - fclose(fn); + vmsg("�z�����U�ӽг�|�b�B�z��"); + return FULLUPDATE; } + strlcpy(rname, cuser.realname, sizeof(rname)); strlcpy(addr, cuser.address, sizeof(addr)); strlcpy(email, cuser.email, sizeof(email)); @@ -1355,6 +1366,15 @@ append_regform(const RegformEntry *pre, const char *logfn, return 1; } +int regform_estimate_queuesize() +{ +#ifdef USE_REGFORM2 + return dashs(FN_REQLIST) / IDLEN; +#else + return dashs(fn_register) / 163; +#endif // !USE_REGFORM2 +} + ///////////////////////////////////////////////////////////////////////////// // Administration (SYSOP Validation) ///////////////////////////////////////////////////////////////////////////// @@ -2319,7 +2339,7 @@ regform2_validate_page(int dryrun) // finishing clear(); move(5, 0); - prints("�z�f�F %d �����U����C", tid); + prints("�z�f�F %d �����U��C", tid); pressanykey(); return 0; } diff --git a/mbbsd/var.c b/mbbsd/var.c index e48b94c3..9f1932cb 100644 --- a/mbbsd/var.c +++ b/mbbsd/var.c @@ -112,7 +112,6 @@ unsigned char currfmode; /* current file mode */ char * const fn_passwd = FN_PASSWD; char * const fn_board = FN_BOARD; -char * const fn_register = "register.new"; char * const fn_note_ans = FN_NOTE_ANS; const char * const fn_plans = "plans"; const char * const fn_writelog = "writelog"; diff --git a/upgrade/r4035_regnew.c b/upgrade/r4035_regnew.c new file mode 100644 index 00000000..8af4cd6f --- /dev/null +++ b/upgrade/r4035_regnew.c @@ -0,0 +1,169 @@ +/* $Id$ */ +#include "bbs.h" +#include "cmbbs.h" + +// New style (Regform2) file names: +#define FN_REGFORM "regform" // registration form in user home +#define FN_REGFORM_LOG "regform.log" // regform history in user home +#define FN_REQLIST "reg.wait" // request list file, in global directory (replacing fn_register) + +#define FN_OLDREG "register.new" + +//////////////////////////////////////////////////////////////////////////// +// Regform Utilities +//////////////////////////////////////////////////////////////////////////// + +// TODO define and use structure instead, even in reg request file. +typedef struct { + // current format: + // (optional) num: unum, date + // [0] uid: xxxxx (IDLEN=12) + // [1] name: RRRRRR (20) + // [2] career: YYYYYYYYYYYYYYYYYYYYYYYYYY (40) + // [3] addr: TTTTTTTTT (50) + // [4] phone: 02DDDDDDDD (20) + // [5] email: x (50) (deprecated) + // [6] mobile: (deprecated) + // [7] ---- + // lasthost: 16 + char userid[IDLEN+1]; + + char exist; + char online; + char pad [ 5]; // IDLEN(12)+1+1+1+5=20 + + char name [20]; + char career[40]; + char addr [50]; + char phone [20]; +} RegformEntry; + +// regform format utilities +int +load_regform_entry(RegformEntry *pre, FILE *fp) +{ + char buf[STRLEN]; + char *v; + + memset(pre, 0, sizeof(RegformEntry)); + while (fgets(buf, sizeof(buf), fp)) + { + if (buf[0] == '-') + break; + buf[sizeof(buf)-1] = 0; + v = strchr(buf, ':'); + if (v == NULL) + continue; + *v++ = 0; + if (*v == ' ') v++; + chomp(v); + + if (strcmp(buf, "uid") == 0) + strlcpy(pre->userid, v, sizeof(pre->userid)); + else if (strcmp(buf, "name") == 0) + strlcpy(pre->name, v, sizeof(pre->name)); + else if (strcmp(buf, "career") == 0) + strlcpy(pre->career, v, sizeof(pre->career)); + else if (strcmp(buf, "addr") == 0) + strlcpy(pre->addr, v, sizeof(pre->addr)); + else if (strcmp(buf, "phone") == 0) + strlcpy(pre->phone, v, sizeof(pre->phone)); + } + return pre->userid[0] ? 1 : 0; +} + +int +print_regform_entry(const RegformEntry *pre, FILE *fp, int close) +{ + fprintf(fp, "uid: %s\n", pre->userid); + fprintf(fp, "name: %s\n", pre->name); + fprintf(fp, "career: %s\n", pre->career); + fprintf(fp, "addr: %s\n", pre->addr); + fprintf(fp, "phone: %s\n", pre->phone); + if (close) + fprintf(fp, "----\n"); + return 1; +} + +//////////////////////////////////////////////////////////////////////////// +// Regform2 API +//////////////////////////////////////////////////////////////////////////// + +// registration queue +int +regq_append(const char *userid) +{ + if (file_append_record(FN_REQLIST, userid) < 0) + return 0; + return 1; +} + +int +regq_find(const char *userid) +{ + return file_find_record(FN_REQLIST, userid); +} + +// user home regform operation +int +regfrm_exist(const char *userid) +{ + char fn[PATHLEN]; + sethomefile(fn, userid, FN_REGFORM); + return dashf(fn) ? 1 : 0; +} + +int +regfrm_load(const char *userid, RegformEntry *pre) +{ + FILE *fp = NULL; + char fn[PATHLEN]; + int ret = 0; + sethomefile(fn, userid, FN_REGFORM); + if (!dashf(fn)) + return 0; + + fp = fopen(fn, "rt"); + if (!fp) + return 0; + ret = load_regform_entry(pre, fp); + fclose(fp); + return ret; +} + +int +regfrm_save(const char *userid, const RegformEntry *pre) +{ + FILE *fp = NULL; + char fn[PATHLEN]; + int ret = 0; + sethomefile(fn, userid, FN_REGFORM); + + fp = fopen(fn, "wt"); + if (!fp) + return 0; + ret = print_regform_entry(pre, fp, 1); + fclose(fp); + return ret; +} + +int main() +{ + FILE *fp = NULL; + RegformEntry re; + chdir(BBSHOME); + fp = fopen(FN_OLDREG, "rt"); + if(!fp) { + printf("no register.new file. abort.\n"); + return 0; + } + while (load_regform_entry(&re, fp)) + { + printf("converting: %s\n", re.userid); + regfrm_save(re.userid, &re); + if (!regq_find(re.userid)) + regq_append(re.userid); + } + fclose(fp); + return 0; +} |