summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorscw <scw@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-05-18 17:14:32 +0800
committerscw <scw@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-05-18 17:14:32 +0800
commitd00edbdbd10efdd918837b5958dba4577be59e84 (patch)
tree8fc451c3f5443deda2d4167056dc9cf3e8546e00
parent36a55220bb41463b63308ea5b2c781bdfa453e9f (diff)
downloadpttbbs-d00edbdbd10efdd918837b5958dba4577be59e84.tar
pttbbs-d00edbdbd10efdd918837b5958dba4577be59e84.tar.gz
pttbbs-d00edbdbd10efdd918837b5958dba4577be59e84.tar.bz2
pttbbs-d00edbdbd10efdd918837b5958dba4577be59e84.tar.lz
pttbbs-d00edbdbd10efdd918837b5958dba4577be59e84.tar.xz
pttbbs-d00edbdbd10efdd918837b5958dba4577be59e84.tar.zst
pttbbs-d00edbdbd10efdd918837b5958dba4577be59e84.zip
Many changes in structure.
Add sex restriction. git-svn-id: http://opensvn.csie.org/pttbbs/branches/scw.angel@1999 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--include/proto.h5
-rw-r--r--include/pttstruct.h11
-rw-r--r--mbbsd/mbbsd.c7
-rw-r--r--mbbsd/talk.c49
-rw-r--r--mbbsd/user.c35
-rw-r--r--mbbsd/var.c4
-rw-r--r--util/AngelConvert.c15
7 files changed, 98 insertions, 28 deletions
diff --git a/include/proto.h b/include/proto.h
index fbbad672..fb1c75a1 100644
--- a/include/proto.h
+++ b/include/proto.h
@@ -540,6 +540,9 @@ int toconnect(char *host, int port);
int toread(int fd, void *buf, int len);
int towrite(int fd, void *buf, int len);
#endif
+#ifdef PLAY_ANGEL
+void pressanykey_or_callangel(void);
+#endif
/* syspost */
int post_msg(char* bname, char* title, char *msg, char* author);
@@ -584,6 +587,8 @@ int make_connection_to_somebody(userinfo_t *uin, int timeout);
#ifdef PLAY_ANGEL
int t_changeangel(void);
void CallAngel(void);
+void SwitchBeingAngel(void);
+void SwitchAngelSex(int);
int t_switchangel(void);
#endif
diff --git a/include/pttstruct.h b/include/pttstruct.h
index 353b5b53..eb0f34e4 100644
--- a/include/pttstruct.h
+++ b/include/pttstruct.h
@@ -121,7 +121,14 @@ typedef struct userec_t {
#define LIVERIGHT 0x200 /* true if get "liveright" already */
#define REJ_OUTTAMAIL 0x400 /* true if don't accept outside mails */
#define REJECT_OUTTAMAIL (cuser.uflag2 & REJ_OUTTAMAIL)
-#define BEING_ANGEL 0x1000 /* true if willing to be angel */
+#define REJ_QUESTION 0x800 /* true if don't want to be angel for a while */
+#define REJECT_QUESTION (cuser.uflag2 & REJ_QUESTION)
+#define ANGEL_MASK 0x3000
+#define ANGEL_R_MAEL 0x1000 /* true if reject male */
+#define ANGEL_R_FEMAEL 0x2000 /* true if reject female */
+#define ANGEL_STATUS() ((cuser.uflag2 & ANGEL_MASK) >> 12)
+#define ANGEL_SET(X) (cuser.uflag2 = (cuser.uflag2 & ~ANGEL_MASK) | \
+ ((X & 3) << 12))
#define BTLEN 48 /* Length of board title */
@@ -260,7 +267,7 @@ typedef struct userinfo_t {
unsigned char active; /* When allocated this field is true */
unsigned char invisible; /* Used by cloaking function in Xyz menu */
unsigned char sockactive; /* Used to coordinate talk requests */
- unsigned char being_angel;
+ unsigned char angel;
unsigned int userlevel;
unsigned char mode; /* UL/DL, Talk Mode, Chat Mode, ... */
unsigned char pager; /* pager toggle, YEA, or NA */
diff --git a/mbbsd/mbbsd.c b/mbbsd/mbbsd.c
index 8fef76de..345b9ad6 100644
--- a/mbbsd/mbbsd.c
+++ b/mbbsd/mbbsd.c
@@ -771,8 +771,11 @@ setup_utmp(int mode)
#endif
if (enter_uflag & CLOAK_FLAG)
uinfo.invisible = YEA;
- if (cuser.uflag2 & BEING_ANGEL)
- uinfo.being_angel = 1;
+
+ if (REJECT_QUESTION)
+ uinfo.angel = 1;
+ uinfo.angel |= ANGEL_STATUS() << 1;
+
getnewutmpent(&uinfo);
SHM->UTMPneedsort = 1;
if (!(cuser.numlogins % 20) && cuser.userlevel & PERM_BM)
diff --git a/mbbsd/talk.c b/mbbsd/talk.c
index af14b57f..4495ce7c 100644
--- a/mbbsd/talk.c
+++ b/mbbsd/talk.c
@@ -603,6 +603,8 @@ my_write2(void)
* 6. my_write2 flag = WATERBALL_CONFIRM, 4 (pre-edit but confirm)
* 7. (when defined PLAY_ANGEL)
* 呼叫小天使 flag = WATERBALL_ANGEL, 5 (隱藏 id)
+ * 8. (when defined PLAY_ANGEL)
+ * 回答小主人 flag = WATERBALL_ANSWER, 6
*/
int
my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t * puin)
@@ -709,7 +711,8 @@ my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t * puin)
kill(uin->pid, SIGUSR1);
} else if (flag != WATERBALL_ALOHA &&
#ifdef PLAY_ANGEL
- flag != WATERBALL_ANGEL && flag != WATERBALL_ANSWER &&
+ (flag != WATERBALL_ANGEL || (uin->angel & 1)) &&
+ flag != WATERBALL_ANSWER &&
/* Angel accept or not is checked outside.
* Avoiding new users don't know what pager is. */
#endif
@@ -1926,11 +1929,13 @@ draw_pickup(int drawall, pickup_t * pickup, int pickup_way,
int
call_in(userinfo_t * uentp, int fri_stat)
{
+#ifdef PLAY_ANGLE
static int CallInAngelWarning = 1;
if( CallInAngelWarning && ! strcasecmp(uentp->userid, cuser.myangel) ){
outmsg("直接丟水球給小天使是會被知道 ID 的喔!");
CallInAngelWarning = 0;
}
+#endif
if (iswritable_stat(uentp, fri_stat)) {
char genbuf[60];
@@ -2803,16 +2808,23 @@ t_changeangel(){
static int
FindAngel(void){
- /* TODO: randomized choose an online angel, shouldn't be themself */
int nAngel;
int i, j;
int choose;
int trial = 0;
+ int mask;
+
+ if (cuser.sex < 6) /* 正常性別 */
+ mask = 1 | (2 << (cuser.sex & 1));
+ else
+ mask = 7;
+
do{
nAngel = 0;
j = SHM->currsorted;
for (i = 0; i < SHM->UTMPnumber; ++i)
- if (SHM->sorted[j][0][i]->userlevel & PERM_ANGEL)
+ if ((SHM->sorted[j][0][i]->userlevel & PERM_ANGEL)
+ && (SHM->sorted[j][0][j]->angel & mask) == 0)
++nAngel;
if (nAngel == 0)
@@ -2821,10 +2833,11 @@ FindAngel(void){
choose = rand() % nAngel + 1;
j = SHM->currsorted;
for (i = 0; i < SHM->UTMPnumber && choose; ++i)
- if (SHM->sorted[j][0][i]->userlevel & PERM_ANGEL)
+ if ((SHM->sorted[j][0][i]->userlevel & PERM_ANGEL)
+ && (SHM->sorted[j][0][j]->angel & mask) == 0)
--choose;
- if (choose == 0 && SHM->sorted[j][0][i - 1] != currutmp){
+ if (choose == 0 && SHM->sorted[j][0][i - 1]->uid != currutmp->uid){
strlcpy(cuser.myangel, SHM->sorted[j][0][i - 1]->userid, IDLEN + 1);
return 1;
}
@@ -2864,12 +2877,15 @@ TalkToAngel(){
}
uent = search_ulist_userid(cuser.myangel);
- if (uent == 0 || !uent->being_angel){
+ if (uent == 0 || (uent->angel & 1)){
NoAngelFound("您的小天使現在不在線上");
return;
}
- /* TODO: complete first name-hiden waterball */
+ move(b_lines - 1, 0);
+ outs("現在你的id受到保密,回答你問題的小天使並不知道你是誰 \n"
+ "你可以選擇不向對方透露自己身份來保護自己 ");
+
snprintf(buf, 128, "問小天使 %s: ", cuser.myangel);
my_write(uent->pid, buf, cuser.myangel, WATERBALL_ANGEL, uent);
return;
@@ -2890,15 +2906,22 @@ CallAngel(){
redoscr();
}
-void SwitchBeingAngel(){
- cuser.uflag2 ^= BEING_ANGEL;
- currutmp->being_angel ^= 1;
+void
+SwitchBeingAngel(){
+ cuser.uflag2 ^= REJ_QUESTION;
+ currutmp->angel ^= 1;
}
-int t_switchangel(){
+void
+SwitchAngelSex(int newmode){
+ ANGEL_SET(newmode);
+ currutmp->angel = (currutmp->angel & ~0x6) | ((newmode & 3) << 1);
+}
+
+int
+t_switchangel(){
SwitchBeingAngel();
- outs(cuser.uflag2 & BEING_ANGEL ?
- "開放小主人問問題" : "休息一會兒");
+ outs(REJECT_QUESTION ? "休息一會兒" : "開放小主人問問題");
return XEASY;
}
#endif
diff --git a/mbbsd/user.c b/mbbsd/user.c
index cbb85d1d..e01f00c6 100644
--- a/mbbsd/user.c
+++ b/mbbsd/user.c
@@ -89,8 +89,10 @@ user_display(userec_t * u, int real)
get_num_records(genbuf, sizeof(fileheader_t)),
u->exmailbox, u->mobile,
u->month, u->day, u->year % 100, u->mychicken.name);
+#ifdef PLAY_ANGEL
prints(" 小 天 使: %s\n",
u->myangel[0] ? u->myangel : "無");
+#endif
prints(" 註冊日期: %s", ctime(&u->firstlogin));
prints(" 前次光臨: %s", ctime(&u->lastlogin));
prints(" 前次點歌: %s", ctime(&u->lastsong));
@@ -221,6 +223,9 @@ static void Customize(void)
char done = 0, mindbuf[5];
char *wm[3] = {"一般", "進階", "未來"};
int key;
+#ifdef PLAY_ANGEL
+ char *am[4] = {"男女皆可", "限女生", "限男生", "暫不接受新的小主人"};
+#endif
showtitle("個人化設定", "個人化設定");
memcpy(mindbuf, &currutmp->mind, 4);
@@ -240,8 +245,9 @@ static void Customize(void)
#ifdef PLAY_ANGEL
if( HAS_PERM(PERM_ANGEL) ){
prints("%-30s%10s\n", "F. 接受小主人詢問",
- ((cuser.uflag2 & BEING_ANGEL) ? "是" : "否"));
- key = getkey("請按 [A-F] 切換設定,按 [Return] 結束:");
+ (REJECT_QUESTION ? "否" : "是"));
+ prints("%-30s%10s\n", "G. 接受的小主人性別", am[ANGEL_STATUS()]);
+ key = getkey("請按 [A-G] 切換設定,按 [Return] 結束:");
}else
#endif
key = getkey("請按 [A-E] 切換設定,按 [Return] 結束:");
@@ -281,7 +287,15 @@ static void Customize(void)
#ifdef PLAY_ANGEL
case 'f':
if( HAS_PERM(PERM_ANGEL) ){
- t_switchangel();
+ SwitchBeingAngel();
+ break;
+ }
+ done = 1;
+ break;
+
+ case 'g':
+ if( HAS_PERM(PERM_ANGEL) ){
+ SwitchAngelSex(ANGEL_STATUS() + 1);
break;
}
#endif
@@ -394,6 +408,21 @@ uinfo_query(userec_t * u, int real, int unum)
i++;
break;
}
+
+#ifdef PLAY_ANGEL
+ if (real)
+ while (1) {
+ getdata_str(i, 0, "小天使:", buf, IDLEN + 1, DOECHO,
+ x.myangel);
+ if(buf[0] == 0 || (getuser(buf) &&
+ (xuser.userlevel & PERM_ANGEL))){
+ strlcpy(x.myangel, buf, IDLEN + 1);
+ ++i;
+ break;
+ }
+ }
+#endif
+
if (real) {
int l;
if (HAS_PERM(PERM_BBSADM)) {
diff --git a/mbbsd/var.c b/mbbsd/var.c
index b3afba22..c499663b 100644
--- a/mbbsd/var.c
+++ b/mbbsd/var.c
@@ -21,7 +21,11 @@ char *str_permid[] = {
"BBSADM", /* PERM_POSTMARK */
"不列入排行榜", /* PERM_NOTOP */
"違法通緝中", /* PERM_VIOLATELAW */
+#ifdef PLAY_ANGEL
"可擔任小天使", /* PERM_ANGEL */
+#else
+ "未使用",
+#endif
"不允許\認證碼註冊", /* PERM_NOREGCODE */
"視覺站長", /* PERM_VIEWSYSOP */
"觀察使用者行蹤", /* PERM_LOGUSER */
diff --git a/util/AngelConvert.c b/util/AngelConvert.c
index 04b4ac09..4d5cea07 100644
--- a/util/AngelConvert.c
+++ b/util/AngelConvert.c
@@ -6,25 +6,24 @@ int main(){
userec_t u;
int count = 0;
- orig_fd = open(BBSHOME "/.PASSWD", O_RDONLY);
+ orig_fd = open(BBSHOME "/.PASSWDS", O_RDONLY);
if( orig_fd < 0 ){
- perror("opening " BBSHOME "/.PASSWD for reading");
+ perror("opening " BBSHOME "/.PASSWDS for reading");
return 1;
}
- printf("Reading from " BBSHOME "/.PASSWD\n");
+ printf("Reading from " BBSHOME "/.PASSWDS\n");
- new_fd = open(BBSHOME "/PASSWD.NEW", O_WRONLY);
+ new_fd = open(BBSHOME "/PASSWDS.NEW", O_WRONLY | O_CREAT | O_TRUNC, 0600);
if( new_fd < 0 ){
- perror("opening " BBSHOME "/PASSWD.NEW for writing");
+ perror("opening " BBSHOME "/PASSWDS.NEW for writing");
return 1;
}
- printf("Writing to " BBSHOME "/PASSWD.NEW\n");
+ printf("Writing to " BBSHOME "/PASSWDS.NEW\n");
while(read(orig_fd, &u, sizeof(userec_t)) == sizeof(userec_t)){
- u.uflag2 &= 0x03ff; // clear 0x400 and 0x1000
+ u.uflag2 &= 0x03ff; // clear 0x400, 0x800, and 0x3000
if( u.userlevel & OLD_PERM_NOOUTMAIL )
u.uflag2 |= REJ_OUTTAMAIL;
- u.uflag2 |= BEING_ANGEL;
u.userlevel &= ~PERM_ANGEL;
bzero(u.myangel, IDLEN + 1);
write(new_fd, &u, sizeof(userec_t));