summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2009-09-21 07:22:48 +0800
committerpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2009-09-21 07:22:48 +0800
commit24d848bc545c35e9420f30c4fac7ded75072cfaa (patch)
treee67915b3817858f51487e7deab726185f76baedb
parent0f1c03fda85c111bbd551c10774b84af1ef08aff (diff)
downloadpttbbs-24d848bc545c35e9420f30c4fac7ded75072cfaa.tar
pttbbs-24d848bc545c35e9420f30c4fac7ded75072cfaa.tar.gz
pttbbs-24d848bc545c35e9420f30c4fac7ded75072cfaa.tar.bz2
pttbbs-24d848bc545c35e9420f30c4fac7ded75072cfaa.tar.lz
pttbbs-24d848bc545c35e9420f30c4fac7ded75072cfaa.tar.xz
pttbbs-24d848bc545c35e9420f30c4fac7ded75072cfaa.tar.zst
pttbbs-24d848bc545c35e9420f30c4fac7ded75072cfaa.zip
* merge uflag2 and uflag, and refine flag bitmask names
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4871 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--UPDATING6
-rw-r--r--include/proto.h2
-rw-r--r--include/pttstruct.h2
-rw-r--r--include/uflags.h109
-rw-r--r--mbbsd/bbs.c6
-rw-r--r--mbbsd/board.c10
-rw-r--r--mbbsd/chess.c2
-rw-r--r--mbbsd/edit.c2
-rw-r--r--mbbsd/fav.c4
-rw-r--r--mbbsd/mail.c7
-rw-r--r--mbbsd/mbbsd.c6
-rw-r--r--mbbsd/menu.c4
-rw-r--r--mbbsd/passwd.c27
-rw-r--r--mbbsd/register.c23
-rw-r--r--mbbsd/screen.c4
-rw-r--r--mbbsd/talk.c14
-rw-r--r--mbbsd/user.c83
-rw-r--r--upgrade/r4871_uflag.c106
-rw-r--r--util/bbsmail.c2
19 files changed, 234 insertions, 185 deletions
diff --git a/UPDATING b/UPDATING
index eb01ece9..81752ee0 100644
--- a/UPDATING
+++ b/UPDATING
@@ -20,8 +20,14 @@ https://opensvn.csie.org/traccgi/pttbbs/changeset/2273
make r4194_passwd
make r4826_numlogin
make r4848_watermode
+ make r4871_uflag
-----------------------------------------------------------------------------
+r4871: [uflag]
+由於兩個 uflag 實在太容易令人寫錯、而且 uflag 的空間還很大,
+決定把 uflag/uflag2 整合。
+請注意 util/bbsmail 要重 build (因為它會看 (cuser.uflags2 & REJ_OUTTAMAIL))
+
r4848: [water mode]
決定把 uflag2 的 WATERMODE (2 bit) 移出來放到獨立的變數。
uflag / uflag2 還是放單一 bit 的東西較好。
diff --git a/include/proto.h b/include/proto.h
index 76507556..793fc8b9 100644
--- a/include/proto.h
+++ b/include/proto.h
@@ -624,7 +624,7 @@ int u_list(void);
#ifdef DBCSAWARE
int u_detectDBCSAwareEvilClient();
#endif
-#define ISDBCSAWARE() (cuser.uflag & DBCSAWARE_FLAG)
+#define ISDBCSAWARE() (cuser.uflag & UF_DBCSAWARE)
/* vote */
void b_suckinfile(FILE *fp, const char *fname);
diff --git a/include/pttstruct.h b/include/pttstruct.h
index fb6fb78e..1e50a795 100644
--- a/include/pttstruct.h
+++ b/include/pttstruct.h
@@ -61,7 +61,7 @@ typedef struct userec_t {
char pad_1;
uint32_t uflag; /* 習慣1 , see uflags.h */
- uint32_t uflag2; /* 習慣2 , see uflags.h */
+ uint32_t deprecated_uflag2; /* deprecated: 習慣2 , see uflags.h */
uint32_t userlevel; /* 權限 */
uint32_t numlogindays; /* 上線資歷 (每日最多+1的登入次數) */
uint32_t numposts; /* 文章篇數 */
diff --git a/include/uflags.h b/include/uflags.h
index 5192fcce..6bac95ea 100644
--- a/include/uflags.h
+++ b/include/uflags.h
@@ -4,79 +4,54 @@
#ifndef INCLUDE_UFLAGS_H
#define INCLUDE_UFLAGS_H
-// TODO in order to prevent masking with wrong variables
-// (since we have 2 flags), it is better to rename the
-// masks with their flag index, eg:
-// UF_PAGER,
-// UF2_WATER_ORIG,
-
/* -------------------- userec_t.uflag (unsigned int) */
-/* UNKNOWN */
-
-/* TRADITIONAL BBS UFLAG */
-//#define UNKNOWN_FLAG 0x00000001 // deprecated ?
-//#define UNKNOWN_FLAG2 0x00000002 // deprecated ?
-//#define PAGER_FLAG 0x00000004 /* deprecated by cuser.pager: true if pager was OFF last session */
-//#define CLOAK_FLAG 0x00000008 /* deprecated by cuser.invisible: true if cloak was ON last session */
-#define FRIEND_FLAG 0x00000010 /* true if show friends only */
-#define BRDSORT_FLAG 0x00000020 /* true if the boards sorted alphabetical */
-#define ADBANNER_FLAG 0x00000040 /* (was: MOVIE_FLAG, true if show advertisement banner */
-#define ADBANNER_USONG_FLAG 0x00000080 /* true if show user songs in banner */
-/* deprecated flag */
-//#define MIND_FLAG 0x00000100 /* true if mind search mode open <-Heat*/
-
-/* DBCS CONFIG */
-/* please keep these even if you don't have DBCSAWARE features turned on */
-#define DBCSAWARE_FLAG 0x00000200 /* true if DBCS-aware enabled. */
-#define DBCS_NOINTRESC 0x00000400 /* no Escapes interupting DBCS characters */
-// #define DBCS__??? 0x00000800
-
-/* Modification Mark (~) */
-#define NO_MODMARK_FLAG 0x00001000 /* true if modified files are NOT marked */
-#define COLORED_MODMARK 0x00002000 /* true if mod-mark is coloured. */
-
-/* Backup Preference */
-#define DEFBACKUP_FLAG 0x00010000 /* true if user defaults to backup */
-
-#define TOBACKUP(x) ((cuser.uflag & DEFBACKUP_FLAG) ? \
+#define UF_FAV_NOHILIGHT 0x00000001 // false if hilight favorite
+#define UF_FAV_ADDNEW 0x00000002 // true to add new board into one's fav
+// #define UF_PAGER 0x00000004 // deprecated by cuser.pager: true if pager was OFF last session
+// #define UF_CLOAK 0x00000008 // deprecated by cuser.invisible: true if cloak was ON last session
+#define UF_FRIEND 0x00000010 // true if show friends only
+#define UF_BRDSORT 0x00000020 // true if the boards sorted alphabetical
+#define UF_ADBANNER 0x00000040 // (was: MOVIE_FLAG, true if show advertisement banner
+#define UF_ADBANNER_USONG 0x00000080 // true if show user songs in banner
+// #define UF_MIND 0x00000100 // deprecated: true if mind search mode open <-Heat
+#define UF_DBCSAWARE 0x00000200 // true if DBCS-aware enabled.
+#define UF_DBCS_NOINTRESC 0x00000400 // no Escapes interupting DBCS characters
+// #define UF_DBCS_??? 0x00000800 // reserved
+#define UF_NO_MODMARK 0x00001000 // true if modified files are NOT marked
+#define UF_COLORED_MODMARK 0x00002000 // true if mod-mark is coloured.
+// #define UF_MODMARK_??? 0x00004000 // reserved
+// #define UF_MODMARK_??? 0x00008000 // reserved
+#define UF_DEFBACKUP 0x00010000 // true if user defaults to backup
+// #define UF_??? 0x00020000 // reserved
+#define UF_REJ_OUTTAMAIL 0x00040000 // true if don't accept outside mails
+// #define UF_??? 0x00080000 // reserved
+#define UF_FOREIGN 0x00100000 // true if a foreign
+#define UF_LIVERIGHT 0x00200000 // true if get "liveright" already
+// #define UF_COUNTRY_??? 0x00400000 // reserved
+// #define UF_COUNTRY_??? 0x00800000 // reserved
+// #define UF_??? 0x01000000 // reserved
+// #define UF_??? 0x02000000 // reserved
+// #define UF_??? 0x04000000 // reserved
+// #define UF_??? 0x08000000 // reserved
+// #define UF_??? 0x10000000 // reserved
+// #define UF_??? 0x20000000 // reserved
+// #define UF_??? 0x40000000 // reserved
+// #define UF_??? 0x80000000 // reserved
+
+// Helper Macros
+#define HasUserFlag(x) (cuser.uflag & (x))
+#define TOBACKUP(x) ((cuser.uflag & UF_DEFBACKUP) ? \
(x != 'n') : \
(x == 'y') )
-
-/* NEW ENTRY HERE */
-// #define ??__??? 0x00100000
+#define REJECT_OUTTAMAIL(x) (x.uflag & UF_REJ_OUTTAMAIL)
/* -------------------- userec_t.uflag2 (unsigned int) */
-// WATER_* is moved to PAGER_UI_* in modes.h
-// #define WATER_ORIG 0x00000000
-// #define WATER_NEW 0x00000001
-// #define WATER_OFO 0x00000002
-// #define WATERMODE(mode) ((cuser.uflag2 & WATER_MASK) == mode)
-// #define WATER_MASK 0x00000003 /* water mask */
-// #define WATER_??? 0x00000004
-// #define WATER_??? 0x00000008
-
-/* MYFAV */
-#define FAVNOHILIGHT 0x00000010 /* false if hilight favorite */
-#define FAVNEW_FLAG 0x00000020 /* true if add new board into one's fav */
-// #define FAV_??? 0x00000040
-// #define FAV_??? 0x00000080
-
-/* MISC */
-#define FOREIGN 0x00000100 /* true if a foreign */
-#define LIVERIGHT 0x00000200 /* true if get "liveright" already */
-#define REJ_OUTTAMAIL 0x00000400 /* true if don't accept outside mails */
-#define REJECT_OUTTAMAIL (cuser.uflag2 & REJ_OUTTAMAIL)
-
-/* ANGEL [deprecated] */
-// #define ANGEL_??? 0x00000800 /* deprecated: true if don't want to be angel for a while */
-// #define ANGEL_??? 0x00001000 // deprecated: ???
-// #define ANGEL_??? 0x00002000 // deprecated: ???
-// #define ANGEL_??? 0x00004000 // reserved then deprecated
-// #define ANGEL_??? 0x00008000 // reserved then deprecated
-
-/* NEW ENTRY HERE */
-// #define ???_??? 0x00010000
+#define OUF2_FAVNOHILIGHT 0x00000010 /* false if hilight favorite */
+#define OUF2_FAVNEW_FLAG 0x00000020 /* true if add new board into one's fav */
+#define OUF2_FOREIGN 0x00000100 /* true if a foreign */
+#define OUF2_LIVERIGHT 0x00000200 /* true if get "liveright" already */
+#define OUF2_REJ_OUTTAMAIL 0x00000400 /* true if don't accept outside mails */
#endif // INCLUDE_UFLAGS_H
diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c
index e7c9d77b..38b60d86 100644
--- a/mbbsd/bbs.c
+++ b/mbbsd/bbs.c
@@ -482,12 +482,12 @@ readdoent(int num, fileheader_t * ent)
if (isunread == 2)
{
// ignore unread, if user doesn't want to show it.
- if (cuser.uflag & NO_MODMARK_FLAG)
+ if (HasUserFlag(UF_NO_MODMARK))
{
oisunread = isunread = 0;
}
// if user wants colored marks, use 'read' marks
- else if (cuser.uflag & COLORED_MODMARK)
+ else if (HasUserFlag(UF_COLORED_MODMARK))
{
isunread = 0;
typeattr = ANSI_COLOR(36);
@@ -940,7 +940,7 @@ do_general(int garbage)
if( !CheckPostPerm()
#ifdef FOREIGN_REG
// 不是外籍使用者在 PttForeign 板
- && !((cuser.uflag2 & FOREIGN) &&
+ && !(HasUserFlag(UF_FOREIGN) &&
strcmp(bp->brdname, BN_FOREIGN) == 0)
#endif
) {
diff --git a/mbbsd/board.c b/mbbsd/board.c
index 3692daf8..f4195daa 100644
--- a/mbbsd/board.c
+++ b/mbbsd/board.c
@@ -876,7 +876,7 @@ cmpboardfriends(const void *brd, const void *tmp)
static void
load_boards(char *key)
{
- int type = (cuser.uflag & BRDSORT_FLAG) ? 1 : 0;
+ int type = (HasUserFlag(UF_BRDSORT)) ? 1 : 0;
int i;
int state;
@@ -1256,10 +1256,10 @@ show_brdlist(int head, int clsflag, int newflag)
// fight with users...
// think about new way some otherday.
prints("%sMyFavFolder" ANSI_RESET " 目錄 □%-34s",
- !(cuser.uflag2 & FAVNOHILIGHT)?HILIGHT_COLOR : "",
+ !(HasUserFlag(UF_FAV_NOHILIGHT))?HILIGHT_COLOR : "",
title);
/*
- if (!(cuser.uflag2 & FAVNOHILIGHT))
+ if (!(HasUserFlag(UF_FAV_NOHILIGHT)))
outs(HILIGHT_COLOR);
prints("%-12s", "[Folder]");
outs(ANSI_RESET);
@@ -1299,7 +1299,7 @@ show_brdlist(int head, int clsflag, int newflag)
if (!IN_CLASSROOT()) {
prints("%s%-13s" ANSI_RESET "%s%5.5s" ANSI_COLOR(0;37)
"%2.2s" ANSI_RESET "%-34.34s",
- ((!(cuser.uflag2 & FAVNOHILIGHT) &&
+ ((!(HasUserFlag(UF_FAV_NOHILIGHT)) &&
getboard(ptr->bid) != NULL))? HILIGHT_COLOR : "",
B_BH(ptr)->brdname,
make_class_color(B_BH(ptr)->title),
@@ -1997,7 +1997,7 @@ choose_board(int newflag)
case 'F':
case 'f':
if (HasUserPerm(PERM_SYSOP)) {
- getbcache(class_bid)->firstchild[cuser.uflag & BRDSORT_FLAG ? 1 : 0] = 0;
+ getbcache(class_bid)->firstchild[HasUserFlag(UF_BRDSORT) ? 1 : 0] = 0;
brdnum = -1;
}
break;
diff --git a/mbbsd/chess.c b/mbbsd/chess.c
index 84fda17f..cfd0906e 100644
--- a/mbbsd/chess.c
+++ b/mbbsd/chess.c
@@ -1010,7 +1010,7 @@ ChessGenLog(ChessInfo* info, ChessGameResult result)
ChessGenLogGlobal(info, result);
}
- a = vans((cuser.uflag & DEFBACKUP_FLAG) ?
+ a = vans(HasUserFlag(UF_DEFBACKUP) ?
"是否將棋譜寄回信箱? [Y/n]" :
"是否將棋譜寄回信箱? [y/N]");
diff --git a/mbbsd/edit.c b/mbbsd/edit.c
index d262f90e..2dd23eee 100644
--- a/mbbsd/edit.c
+++ b/mbbsd/edit.c
@@ -3486,7 +3486,7 @@ vedit2(const char *fpath, int saveheader, int *islocal, char title[STRLEN], int
currutmp->destuid = currstat;
#ifdef DBCSAWARE
- mbcs_mode = (cuser.uflag & DBCSAWARE_FLAG) ? 1 : 0;
+ mbcs_mode = (HasUserFlag(UF_DBCSAWARE)) ? 1 : 0;
#endif
enter_edit_buffer();
diff --git a/mbbsd/fav.c b/mbbsd/fav.c
index 3a466578..e34cc2b6 100644
--- a/mbbsd/fav.c
+++ b/mbbsd/fav.c
@@ -1122,7 +1122,7 @@ void fav_set_folder_title(fav_type_t *ft, char *title)
#define BRD_NEW 1
#define BRD_END 2
/**
- * 如果 user 開啟 FAVNEW_FLAG 的功能:
+ * 如果 user 開啟 UF_FAV_ADDNEW 的功能:
* mode == 1: update 看板,並將新看板加入我的最愛。
* mode == 0: update 資訊但不加入。
*
@@ -1136,7 +1136,7 @@ int updatenewfav(int mode)
int count = 0;
char fname[80], *brd;
- if(!(cuser.uflag2 & FAVNEW_FLAG))
+ if(!(HasUserFlag(UF_FAV_ADDNEW)))
return 0;
setuserfile(fname, FAVNB);
diff --git a/mbbsd/mail.c b/mbbsd/mail.c
index 96b2259f..a328b5dd 100644
--- a/mbbsd/mail.c
+++ b/mbbsd/mail.c
@@ -384,7 +384,7 @@ hold_mail(const char *fpath, const char *receiver, const char *title)
char buf[4];
getdata(b_lines - 1, 0,
- (cuser.uflag & DEFBACKUP_FLAG) ?
+ (HasUserFlag(UF_DEFBACKUP)) ?
"已順利寄出,是否自存底稿(Y/N)?[Y] " :
"已順利寄出,是否自存底稿(Y/N)?[N] ",
buf, sizeof(buf), LCECHO);
@@ -1073,7 +1073,8 @@ mailtitle(void)
showtitle("郵件選單", BBSName);
outs("[←]離開[↑↓]選擇[→]閱\讀信件 [X]轉錄看板[F]轉寄站外 ");
- prints(" [O]站外信:%s [h]求助\n" , REJECT_OUTTAMAIL ? ANSI_COLOR(31) "關" ANSI_RESET : "開");
+ prints(" [O]站外信:%s [h]求助\n" ,
+ REJECT_OUTTAMAIL(cuser) ? ANSI_COLOR(31) "關" ANSI_RESET : "開");
vbarf(ANSI_REVERSE " 編號 %s 作 者 信 件 標 題\t%s ",
(showmail_mode == SHOWMAIL_SUM) ? "大 小":"日 期",
buf);
@@ -1723,7 +1724,7 @@ mail_waterball(int ent GCC_UNUSED, fileheader_t * fhdr, const char *direct GCC_U
return -2;
move(b_lines-4, 0); clrtobot();
- if( strstr(address, ".bbs") && REJECT_OUTTAMAIL ){
+ if( strstr(address, ".bbs") && REJECT_OUTTAMAIL(cuser) ){
outs("\n您必須要打開接受站外信, 水球整理系統才能寄入結果\n"
"請麻煩到【郵件選單】按大寫 O改成接受站外信 (在右上角)\n"
"再重新執行本功\能 :)\n");
diff --git a/mbbsd/mbbsd.c b/mbbsd/mbbsd.c
index 0328852a..5aba270f 100644
--- a/mbbsd/mbbsd.c
+++ b/mbbsd/mbbsd.c
@@ -1154,7 +1154,7 @@ static void init_guest_info(void)
#if FOREIGN_REG_DAY > 0
inline static void foreign_warning(void){
- if ((cuser.uflag2 & FOREIGN) && !(cuser.uflag2 & LIVERIGHT)){
+ if ((HasUserFlag(UF_FOREIGN)) && !(HasUserFlag(UF_LIVERIGHT))){
if (login_start_time - cuser.firstlogin > (FOREIGN_REG_DAY - 5) * 24 * 3600){
mail_muser(cuser, "[出入境管理局]", "etc/foreign_expired_warn");
}
@@ -1272,7 +1272,7 @@ user_login(void)
if (last_login_time < ADBANNER_USONG_TIMEBOMB)
{
if (query_adbanner_usong_pref_changed(cuser_ref, 1))
- pwcuToggleUserFlag(ADBANNER_USONG_FLAG);
+ pwcuToggleUserFlag(UF_ADBANNER_USONG);
}
#endif
@@ -1314,7 +1314,7 @@ user_login(void)
foreign_warning();
#endif
- if(cuser.uflag2 & FAVNEW_FLAG) {
+ if(HasUserFlag(UF_FAV_ADDNEW)) {
fav_load();
if (get_fav_root() != NULL) {
int num;
diff --git a/mbbsd/menu.c b/mbbsd/menu.c
index 2c33f06b..7a4160f8 100644
--- a/mbbsd/menu.c
+++ b/mbbsd/menu.c
@@ -305,7 +305,7 @@ adbanner(int menu_index)
int i = menu_index;
// don't show if stat in class or user wants to skip adbanners
- if (currstat == CLASS || !(cuser.uflag & ADBANNER_FLAG))
+ if (currstat == CLASS || !(HasUserFlag(UF_ADBANNER)))
return;
// also prevent SHM busy status
@@ -336,7 +336,7 @@ adbanner(int menu_index)
SHM->last_usong < SHM->last_film);
if (SHM->last_film > N_SYSADBANNER) {
- if (cuser.uflag & ADBANNER_USONG_FLAG || !valid_usong_range)
+ if (HasUserFlag(UF_ADBANNER_USONG) || !valid_usong_range)
i = N_SYSADBANNER + slideshow_index % (SHM->last_film+1-N_SYSADBANNER);
else
i = SHM->last_usong + 1 + slideshow_index % (SHM->last_film - SHM->last_usong);
diff --git a/mbbsd/passwd.c b/mbbsd/passwd.c
index 65ffdb67..38c84987 100644
--- a/mbbsd/passwd.c
+++ b/mbbsd/passwd.c
@@ -210,9 +210,9 @@ int
pwcuToggleOutMail()
{
PWCU_START();
- u.uflag2 ^= REJ_OUTTAMAIL;
- _SETBY_BIT(cuser.uflag2, REJ_OUTTAMAIL,
- u.uflag2 & REJ_OUTTAMAIL);
+ u.uflag ^= UF_REJ_OUTTAMAIL;
+ _SETBY_BIT(cuser.uflag, UF_REJ_OUTTAMAIL,
+ u.uflag & UF_REJ_OUTTAMAIL);
PWCU_END();
}
@@ -272,7 +272,7 @@ int pwcuRegisterSetInfo (const char *rname,
u.year = year;
u.month = month;
u.day = day;
- _SETBY_BIT(u.uflag2, FOREIGN, is_foreign);
+ _SETBY_BIT(u.uflag, UF_FOREIGN, is_foreign);
// duplicate to cuser
@@ -286,7 +286,7 @@ int pwcuRegisterSetInfo (const char *rname,
cuser.year = year;
cuser.month = month;
cuser.day = day;
- _SETBY_BIT(cuser.uflag2, FOREIGN, is_foreign);
+ _SETBY_BIT(cuser.uflag, UF_FOREIGN, is_foreign);
PWCU_END();
}
@@ -403,21 +403,11 @@ pwcuToggleUserFlag (unsigned int mask)
}
int
-pwcuToggleUserFlag2 (unsigned int mask)
-{
- PWCU_START();
- u.uflag2 ^= mask;
- _SETBY_BIT(cuser.uflag2, mask,
- u.uflag2 & mask);
- PWCU_END();
-}
-
-int
pwcuToggleSortBoard ()
{
// XXX if this is executed too often,
// put it into 'non-important variable list'.
- return pwcuToggleUserFlag(BRDSORT_FLAG);
+ return pwcuToggleUserFlag(UF_BRDSORT);
}
int
@@ -425,7 +415,7 @@ pwcuToggleFriendList()
{
// XXX if this is executed too often,
// put it into 'non-important variable list'.
- return pwcuToggleUserFlag(FRIEND_FLAG);
+ return pwcuToggleUserFlag(UF_FRIEND);
}
// non-important variables (only save on exit)
@@ -610,8 +600,7 @@ int pwcuInitAdminPerm ()
void pwcuInitGuestPerm ()
{
cuser.userlevel = 0;
- cuser.uflag = BRDSORT_FLAG;
- cuser.uflag2= 0; // we don't need FAVNEW_FLAG or anything else.
+ cuser.uflag = UF_BRDSORT;
cuser.pager = PAGER_OFF;
# ifdef GUEST_DEFAULT_DBCS_NOINTRESC
_ENABLE_BIT(cuser.uflag, DBCS_NOINTRESC);
diff --git a/mbbsd/register.c b/mbbsd/register.c
index 6a0d9599..b5a22faf 100644
--- a/mbbsd/register.c
+++ b/mbbsd/register.c
@@ -625,13 +625,13 @@ setupnewuser(const userec_t *user)
int
query_adbanner_usong_pref_changed(const userec_t *u, char force_yn)
{
- char old = (cuser.uflag & ADBANNER_USONG_FLAG) ? 1 : 0,
+ char old = (u->uflag & UF_ADBANNER_USONG) ? 1 : 0,
new = 0,
defyes = 0,
ans = 1;
assert(u);
- if ( !(u->uflag & ADBANNER_FLAG) )
+ if ( !(u->uflag & UF_ADBANNER) )
return 0;
#ifdef ADBANNER_DEFAULT_YES
@@ -706,22 +706,21 @@ new_register(void)
memset(&newuser, 0, sizeof(newuser));
newuser.version = PASSWD_VERSION;
newuser.userlevel = PERM_DEFAULT;
- newuser.uflag = BRDSORT_FLAG | ADBANNER_FLAG;
- newuser.uflag2 = 0;
+ newuser.uflag = UF_BRDSORT | UF_ADBANNER;
newuser.firstlogin = newuser.lastlogin = now;
newuser.pager = PAGER_ON;
strlcpy(newuser.lasthost, fromhost, sizeof(newuser.lasthost));
-#ifdef ADBANNER_USONG_FLAG
+#ifdef UF_ADBANNER_USONG
if (query_adbanner_usong_pref_changed(&newuser, 0))
- newuser.uflag |= ADBANNER_USONG_FLAG;
+ newuser.uflag |= UF_ADBANNER_USONG;
#endif
#ifdef DBCSAWARE
if(u_detectDBCSAwareEvilClient())
- newuser.uflag &= ~DBCSAWARE_FLAG;
+ newuser.uflag &= ~UF_DBCSAWARE;
else
- newuser.uflag |= DBCSAWARE_FLAG;
+ newuser.uflag |= UF_DBCSAWARE;
#endif
more("etc/register", NA);
@@ -1265,7 +1264,7 @@ u_register(void)
char inregcode[14], regcode[50];
char ans[3], *errcode;
int i = 0;
- int isForeign = (cuser.uflag2 & FOREIGN) ? 1 : 0;
+ int isForeign = (HasUserFlag(UF_FOREIGN)) ? 1 : 0;
if (cuser.userlevel & PERM_LOGINOK) {
outs("您的身份確認已經完成,不需填寫申請表");
@@ -1360,7 +1359,7 @@ u_register(void)
}
mail_muser(cuser, "[註冊成功\囉]", "etc/registeredmail");
#if FOREIGN_REG_DAY > 0
- if(cuser.uflag2 & FOREIGN)
+ if(HasUserFlag(UF_FOREIGN))
mail_muser(cuser, "[出入境管理局]", "etc/foreign_welcome");
#endif
snprintf(justify, sizeof(justify), "<E-Mail>: %s", Cdate(&now));
@@ -1749,7 +1748,7 @@ regform_accept(const char *userid, const char *justify)
// According to suggestions by PTT BBS account sysops,
// it is better to use anonymous here.
#if FOREIGN_REG_DAY > 0
- if(muser.uflag2 & FOREIGN)
+ if(muser.uflag & UF_FOREIGN)
mail_log2id(muser.userid, "[System] Registration Complete ", "etc/foreign_welcome",
"[SYSTEM]", 1, 0);
else
@@ -2180,7 +2179,7 @@ ui_display_regform_single(
ANSI_COLOR(1;31) " [T:禁止使用認證碼註冊]" ANSI_RESET:
"");
prints("0.%-12s: %s%s\n", "真實姓名", pre->u.realname,
- xuser->uflag2 & FOREIGN ? " (外籍)" :
+ xuser->uflag & UF_FOREIGN ? " (外籍)" :
"");
prints("1.%-12s: %s\n", "服務單位", pre->u.career);
prints("2.%-12s: %s\n", "目前住址", pre->u.address);
diff --git a/mbbsd/screen.c b/mbbsd/screen.c
index 23d00c20..1389afd9 100644
--- a/mbbsd/screen.c
+++ b/mbbsd/screen.c
@@ -242,7 +242,7 @@ redrawwin(void)
#ifdef DBCSAWARE
if (!(bp->mode & STANDOUT) &&
- (cuser.uflag & DBCS_NOINTRESC) &&
+ (HasUserFlag(UF_DBCS_NOINTRESC)) &&
DBCS_RemoveIntrEscape(bp->data, &len))
{
// if anything changed, dirty whole line.
@@ -339,7 +339,7 @@ doupdate(void)
#ifdef DBCSAWARE
if (!(bp->mode & STANDOUT) &&
- (cuser.uflag & DBCS_NOINTRESC) &&
+ (HasUserFlag(UF_DBCS_NOINTRESC)) &&
DBCS_RemoveIntrEscape(bp->data, &len))
{
// if anything changed, dirty whole line.
diff --git a/mbbsd/talk.c b/mbbsd/talk.c
index 1144de63..28284f28 100644
--- a/mbbsd/talk.c
+++ b/mbbsd/talk.c
@@ -2086,7 +2086,7 @@ int
pickup_maxpages(int pickupway, int nfriends)
{
int number;
- if (cuser.uflag & FRIEND_FLAG)
+ if (HasUserFlag(UF_FRIEND))
number = nfriends;
else
number = SHM->UTMPnumber +
@@ -2171,7 +2171,7 @@ pickup(pickup_t * currpickup, int pickup_way, int *page,
/* 產生好友區 */
which = *page * nPickups;
- if( (cuser.uflag & FRIEND_FLAG) || /* 只顯示好友模式 */
+ if( (HasUserFlag(UF_FRIEND)) || /* 只顯示好友模式 */
((pickup_way == 0) && /* [嗨! 朋友] mode */
(
/* 含板友, 好友區最多只會有 (friendtotal + 板友) 個*/
@@ -2212,7 +2212,7 @@ pickup(pickup_t * currpickup, int pickup_way, int *page,
} else
*nfriend = 0;
- if (!(cuser.uflag & FRIEND_FLAG) && size < nPickups) {
+ if (!(HasUserFlag(UF_FRIEND)) && size < nPickups) {
sorted_way = ((pickup_way == 0) ? 7 : (pickup_way - 1));
ulist = SHM->sorted[currsorted][sorted_way];
which = *page * nPickups - *nfriend;
@@ -2292,7 +2292,7 @@ draw_pickup(int drawall, pickup_t * pickup, int pickup_way,
}
if (drawall) {
- showtitle((cuser.uflag & FRIEND_FLAG) ? "好友列表" : "休閒聊天",
+ showtitle((HasUserFlag(UF_FRIEND)) ? "好友列表" : "休閒聊天",
BBSName);
move(2, 0);
@@ -2649,7 +2649,7 @@ userlist(void)
break;
case 's':
- if (!(cuser.uflag & FRIEND_FLAG)) {
+ if (!(HasUserFlag(UF_FRIEND))) {
int si; /* utmpshm->sorted[X][0][si] */
int fi; /* allpickuplist[fi] */
char swid[IDLEN + 1];
@@ -2759,7 +2759,7 @@ userlist(void)
#endif
case 'b': /* broadcast */
- if (cuser.uflag & FRIEND_FLAG || HasUserPerm(PERM_SYSOP)) {
+ if (HasUserFlag(UF_FRIEND) || HasUserPerm(PERM_SYSOP)) {
char genbuf[60]="[廣播]";
char ans[4];
@@ -2770,7 +2770,7 @@ userlist(void)
ans, sizeof(ans), LCECHO) ||
ans[0] != 'y')
break;
- if (!(cuser.uflag & FRIEND_FLAG) && HasUserPerm(PERM_SYSOP)) {
+ if (!(HasUserFlag(UF_FRIEND)) && HasUserPerm(PERM_SYSOP)) {
msgque_t msg;
getdata(1, 0, "再次確定站長廣播? [N]",
ans, sizeof(ans), LCECHO);
diff --git a/mbbsd/user.c b/mbbsd/user.c
index 36079f67..f915ddbe 100644
--- a/mbbsd/user.c
+++ b/mbbsd/user.c
@@ -136,12 +136,12 @@ user_display(const userec_t * u, int adminmode)
prints("\t\t真實姓名: %s", u->realname);
#if FOREIGN_REG_DAY > 0
prints(" %s%s",
- u->uflag2 & FOREIGN ? "(外籍: " : "",
- u->uflag2 & FOREIGN ?
- (u->uflag2 & LIVERIGHT) ? "永久居留)" : "未取得居留權)"
+ u->uflag & UF_FOREIGN ? "(外籍: " : "",
+ u->uflag & UF_FOREIGN ?
+ (u->uflag & UF_LIVERIGHT) ? "永久居留)" : "未取得居留權)"
: "");
#elif defined(FOREIGN_REG)
- prints(" %s", u->uflag2 & FOREIGN ? "(外籍)" : "");
+ prints(" %s", u->uflag & UF_FOREIGN ? "(外籍)" : "");
#endif
outs("\n"); // end of realname
prints("\t\t職業學歷: %s\n", u->career);
@@ -367,14 +367,17 @@ void Customize(void)
/* cuser.uflag settings */
static const unsigned int masks1[] = {
- ADBANNER_FLAG,
- ADBANNER_USONG_FLAG,
- NO_MODMARK_FLAG ,
- COLORED_MODMARK,
- DEFBACKUP_FLAG,
+ UF_ADBANNER,
+ UF_ADBANNER_USONG,
+ UF_REJ_OUTTAMAIL,
+ UF_DEFBACKUP,
+ UF_FAV_ADDNEW,
+ UF_FAV_NOHILIGHT,
+ UF_NO_MODMARK ,
+ UF_COLORED_MODMARK,
#ifdef DBCSAWARE
- DBCSAWARE_FLAG,
- DBCS_NOINTRESC,
+ UF_DBCSAWARE,
+ UF_DBCS_NOINTRESC,
#endif
0,
};
@@ -382,9 +385,12 @@ void Customize(void)
static const char* desc1[] = {
"顯示動態看板",
"顯示使用者心情點播 (需開啟動態看板)",
+ "拒收站外信",
+ "預設備份信件與其它記錄", //"與聊天記錄",
+ "新板自動進我的最愛",
+ "單色顯示我的最愛",
"隱藏文章修改符號(推文/修文) (~)",
"改用色彩代替修改符號 (+)",
- "預設備份信件與其它記錄", //"與聊天記錄",
#ifdef DBCSAWARE
"自動偵測雙位元字集(如全型中文)",
"禁止在雙位元中使用色碼(去一字雙色)",
@@ -392,23 +398,8 @@ void Customize(void)
0,
};
- /* cuser.uflag2 settings */
- static const unsigned int masks2[] = {
- REJ_OUTTAMAIL,
- FAVNEW_FLAG,
- FAVNOHILIGHT,
- 0,
- };
-
- static const char* desc2[] = {
- "拒收站外信",
- "新板自動進我的最愛",
- "單色顯示我的最愛",
- 0,
- };
-
while ( !done ) {
- int i = 0, ia = 0, ic = 0; /* general uflags */
+ int i = 0, ia = 0; /* general uflags */
int iax = 0; /* extended flags */
clear();
@@ -424,18 +415,7 @@ void Customize(void)
prints( ANSI_COLOR(1;36) "%c" ANSI_RESET
". %-40s%s\n",
'a' + ia, desc1[i],
- (cuser.uflag & masks1[i]) ?
- ANSI_COLOR(1;36) "是" ANSI_RESET : "否");
- }
- ic = i;
- /* print uflag2 options */
- for (i = 0; masks2[i]; i++, ia++)
- {
- clrtoeol();
- prints( ANSI_COLOR(1;36) "%c" ANSI_RESET
- ". %-40s%s" ANSI_RESET "\n",
- 'a' + ia, desc2[i],
- (cuser.uflag2 & masks2[i]) ?
+ HasUserFlag(masks1[i]) ?
ANSI_COLOR(1;36) "是" ANSI_RESET : "否");
}
/* extended stuff */
@@ -479,14 +459,7 @@ void Customize(void)
/* normal pref */
key -= 'a';
dirty = 1;
-
-
- if(key < ic)
- {
- pwcuToggleUserFlag(masks1[key]);
- } else {
- pwcuToggleUserFlag2(masks2[key-ic]);
- }
+ pwcuToggleUserFlag(masks1[key]);
continue;
}
@@ -955,23 +928,23 @@ uinfo_query(const char *orig_uid, int adminmode, int unum)
x.chc_win, x.chc_lose, x.chc_tie,
x.go_win, x.go_lose, x.go_tie);
#ifdef FOREIGN_REG
- if (getdata_str(y++, 0, "住在 1)台灣 2)其他:", buf, 2, DOECHO, x.uflag2 & FOREIGN ? "2" : "1"))
+ if (getdata_str(y++, 0, "住在 1)台灣 2)其他:", buf, 2, DOECHO, x.uflag & UF_FOREIGN ? "2" : "1"))
if ((tmp = atoi(buf)) > 0){
if (tmp == 2){
- x.uflag2 |= FOREIGN;
+ x.uflag |= UF_FOREIGN;
}
else
- x.uflag2 &= ~FOREIGN;
+ x.uflag &= ~UF_FOREIGN;
}
- if (x.uflag2 & FOREIGN)
- if (getdata_str(y++, 0, "永久居留權 1)是 2)否:", buf, 2, DOECHO, x.uflag2 & LIVERIGHT ? "1" : "2")){
+ if (x.uflag & UF_FOREIGN)
+ if (getdata_str(y++, 0, "永久居留權 1)是 2)否:", buf, 2, DOECHO, x.uflag & UF_LIVERIGHT ? "1" : "2")){
if ((tmp = atoi(buf)) > 0){
if (tmp == 1){
- x.uflag2 |= LIVERIGHT;
+ x.uflag |= UF_LIVERIGHT;
x.userlevel |= (PERM_LOGINOK | PERM_POST);
}
else{
- x.uflag2 &= ~LIVERIGHT;
+ x.uflag &= ~UF_LIVERIGHT;
x.userlevel &= ~(PERM_LOGINOK | PERM_POST);
}
}
diff --git a/upgrade/r4871_uflag.c b/upgrade/r4871_uflag.c
new file mode 100644
index 00000000..0a2ac1bd
--- /dev/null
+++ b/upgrade/r4871_uflag.c
@@ -0,0 +1,106 @@
+#define _UTIL_C_
+#include "bbs.h"
+#include <time.h>
+
+// old uflag2 bits
+#ifndef OUF2_FAVNOHILIGHT
+#define OUF2_FAVNOHILIGHT 0x00000010 /* false if hilight favorite */
+#define OUF2_FAVNEW_FLAG 0x00000020 /* true if add new board into one's fav */
+#define OUF2_FOREIGN 0x00000100 /* true if a foreign */
+#define OUF2_LIVERIGHT 0x00000200 /* true if get "liveright" already */
+#define OUF2_REJ_OUTTAMAIL 0x00000400 /* true if don't accept outside mails */
+#endif
+
+const unsigned int ufmap_from[] = {
+ OUF2_FAVNOHILIGHT,
+ OUF2_FAVNEW_FLAG,
+ OUF2_FOREIGN,
+ OUF2_LIVERIGHT,
+ OUF2_REJ_OUTTAMAIL,
+ 0,
+};
+
+const unsigned int ufmap_to[] = {
+ UF_FAV_NOHILIGHT,
+ UF_FAV_ADDNEW,
+ UF_FOREIGN,
+ UF_LIVERIGHT,
+ UF_REJ_OUTTAMAIL,
+ 0,
+};
+
+const char *ufmap_names [] = {
+ "FAV_NOHILIGHT",
+ "FAV_ADDNEW",
+ "FOREIGN",
+ "LIVERIGHT",
+ "REJ_OUTTAMAIL",
+};
+
+int transform(userec_t *new, userec_t *old, int i)
+{
+ userec_t *u = new;
+ int dirty = 0;
+
+ memcpy(new, old, sizeof(userec_t));
+ if (!u->userid[0])
+ return 0;
+
+ for (i = 0; ufmap_from[i]; i++)
+ {
+ int ov = (u->deprecated_uflag2 & ufmap_from[i]) ? 1 : 0,
+ nv = (u->uflag & ufmap_to[i]) ? 1 : 0;
+ if (ov == nv)
+ continue;
+
+ if (dirty++ == 0) printf("%s: %08X => [", u->userid, u->uflag);
+ u->uflag &= ~(ufmap_to[i]);
+ if (u->deprecated_uflag2 & ufmap_from[i])
+ {
+ u->uflag |= ufmap_to[i];
+ printf("%s ", ufmap_names[i]);
+ }
+ }
+ if (!dirty)
+ return 0;
+
+ printf("] => %08X\n", u->uflag);
+ // force convert!
+ // passwd_update(n+1, u);
+
+ return 0;
+}
+
+int main(void)
+{
+ int fd, fdw;
+ userec_t new;
+ userec_t old;
+ int i = 0;
+
+ printf("sizeof(userec_t)=%u\n", (unsigned int)sizeof(userec_t));
+ printf("You're going to convert your .PASSWDS\n");
+ printf("The new file will be named .PASSWDS.trans.tmp\n");
+
+ if (chdir(BBSHOME) < 0) {
+ perror("chdir");
+ exit(-1);
+ }
+
+ if ((fd = open(FN_PASSWD, O_RDONLY)) < 0 ||
+ (fdw = open(FN_PASSWD".trans.tmp", O_WRONLY | O_CREAT | O_TRUNC, 0600)) < 0 ) {
+ perror("open");
+ exit(-1);
+ }
+
+ while (read(fd, &old, sizeof(old)) > 0) {
+ transform(&new, &old, ++i);
+ write(fdw, &new, sizeof(new));
+ }
+
+ close(fd);
+ close(fdw);
+
+ // printf("total %d records converted.\n", accs);
+ return 0;
+}
diff --git a/util/bbsmail.c b/util/bbsmail.c
index 0e1c6eb1..9bfcbd7d 100644
--- a/util/bbsmail.c
+++ b/util/bbsmail.c
@@ -89,7 +89,7 @@ int mail2bbs(char *userid)
return -1;//EX_NOUSER;
}
- if( xuser.uflag2 & REJ_OUTTAMAIL )
+ if (REJECT_OUTTAMAIL(xuser))
return -1; //不接受站外信
sprintf(filename, BBSHOME "/home/%c/%s", xuser.userid[0], xuser.userid);