diff options
author | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2008-04-03 00:08:30 +0800 |
---|---|---|
committer | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2008-04-03 00:08:30 +0800 |
commit | b25a423c98a1ef5763b9810d554417546214417d (patch) | |
tree | 6c607913f0c5c89f4101bc289abd8986ec482125 | |
parent | c72299766768d9c73ad7ee2eda23afb5033eaec7 (diff) | |
download | pttbbs-b25a423c98a1ef5763b9810d554417546214417d.tar pttbbs-b25a423c98a1ef5763b9810d554417546214417d.tar.gz pttbbs-b25a423c98a1ef5763b9810d554417546214417d.tar.bz2 pttbbs-b25a423c98a1ef5763b9810d554417546214417d.tar.lz pttbbs-b25a423c98a1ef5763b9810d554417546214417d.tar.xz pttbbs-b25a423c98a1ef5763b9810d554417546214417d.tar.zst pttbbs-b25a423c98a1ef5763b9810d554417546214417d.zip |
- angel: allow user to call paged rejnew angel in hh mode, even if angel has not really replied.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4069 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | include/proto.h | 4 | ||||
-rw-r--r-- | mbbsd/angel.c | 74 | ||||
-rw-r--r-- | mbbsd/edit.c | 22 |
3 files changed, 67 insertions, 33 deletions
diff --git a/include/proto.h b/include/proto.h index 6cda35fa..dabdbc18 100644 --- a/include/proto.h +++ b/include/proto.h @@ -42,8 +42,10 @@ void merge_dir(const char *dir1, const char *dir2, int isoutter); int t_changeangel(void); int t_angelmsg(void); int angel_reject_me(userinfo_t * uin); -void angel_toggle_pause(); void CallAngel(void); +void angel_toggle_pause(); +void angel_load_my_nick(char *buf, int szbuf); +const char *angel_get_nick(); /* announce */ int a_menu(const char *maintitle, const char *path, int lastlevel, int lastbid, char *trans_buffer); diff --git a/mbbsd/angel.c b/mbbsd/angel.c index ef0a4fac..024091e9 100644 --- a/mbbsd/angel.c +++ b/mbbsd/angel.c @@ -19,6 +19,38 @@ angel_toggle_pause() cuser.uflag2 &= ~UF2_ANGEL_OLDMASK; } +void +angel_parse_nick_fp(FILE *fp, char *nick, int sznick) +{ + char buf[PATHLEN]; + // should be in first line + rewind(fp); + *buf = 0; + if (fgets(buf, sizeof(buf), fp)) + { + // verify first line + if (buf[0] == '%' && buf[1] == '%' && buf[2] == '[') + { + chomp(buf+3); + strlcpy(nick, buf+3, sznick); + } + } +} + +void +angel_load_my_nick(char *buf, int szbuf) +{ + char fn[PATHLEN]; + FILE *fp = NULL; + *buf = 0; + setuserfile(fn, FN_ANGELMSG); + if ((fp = fopen(fn, "rt"))) + { + angel_parse_nick_fp(fp, buf, szbuf); + fclose(fp); + } +} + // cache my angel's nickname static char _myangel[IDLEN+1] = "", _myangel_nick[IDLEN+1] = ""; @@ -78,21 +110,13 @@ angel_reload_nick() if (fp) { _valid_angelmsg = 1; - if (fgets(fn, sizeof(fn), fp)) - { - // verify first line - if (fn[0] == '%' && fn[1] == '%' && fn[2] == '[') - { - chomp(fn+3); - strlcpy(_myangel_nick, fn+3, sizeof(_myangel_nick)); - } - } + angel_parse_nick_fp(fp, _myangel_nick, sizeof(_myangel_nick)); fclose(fp); } } const char * -angel_get_nickprefix() +angel_get_nick() { angel_reload_nick(); return _myangel_nick; @@ -286,7 +310,7 @@ NoAngelFound(const char* msg){ outs(",請先在新手板上尋找答案或按 Ctrl-P 發問"); clrtoeol(); refresh(); - sleep(1); + sleep(3); GotoNewHand(); return; } @@ -352,7 +376,8 @@ AngelNotOnline(){ static void TalkToAngel(){ static char AngelPermChecked = 0; - userinfo_t* uent; + static userinfo_t* lastuent = NULL; + userinfo_t *uent; if (strcmp(cuser.myangel, "-") == 0){ NoAngelFound(NULL); @@ -369,6 +394,7 @@ TalkToAngel(){ AngelPermChecked = 1; if (cuser.myangel[0] == 0 && !FindAngel()){ + lastuent = NULL; NoAngelFound("現在沒有小天使在線上"); return; } @@ -377,11 +403,29 @@ TalkToAngel(){ angel_reload_nick(); uent = search_ulist_userid(cuser.myangel); - if (uent == 0 || uent->angelpause || angel_reject_me(uent)){ + if (uent == NULL || angel_reject_me(uent)){ + lastuent = NULL; AngelNotOnline(); return; } + // check angelpause: if talked then should accept. + if (uent == lastuent) { + // we've talked to angel. + // XXX what if uentp reused by other? chance very, very low... + if (uent->angelpause >= ANGELPAUSE_REJALL) + { + AngelNotOnline(); + return; + } + } else { + if (uent->angelpause) { + // lastuent = NULL; + AngelNotOnline(); + return; + } + } + more("etc/angel_usage", NA); /* 這段話或許可以在小天使回答問題時 show 出來 @@ -394,7 +438,9 @@ TalkToAngel(){ char xnick[IDLEN+1], prompt[IDLEN*2]; snprintf(xnick, sizeof(xnick), "%s小天使", _myangel_nick); snprintf(prompt, sizeof(prompt), "問%s小天使: ", _myangel_nick); - my_write(uent->pid, prompt, xnick, WATERBALL_ANGEL, uent); + // if success, record uent. + if (my_write(uent->pid, prompt, xnick, WATERBALL_ANGEL, uent)) + lastuent = uent; } return; } diff --git a/mbbsd/edit.c b/mbbsd/edit.c index 7ddd615a..4058aa05 100644 --- a/mbbsd/edit.c +++ b/mbbsd/edit.c @@ -1474,25 +1474,11 @@ write_header(FILE * fp, char *mytitle) // FIXME unused if (HasUserPerm(PERM_ANGEL) && currboard && strcmp(currboard, BN_ANGELPRAY) == 0) { - FILE *fpx = NULL; - char xbuf[PATHLEN]; - // try to load angel nick. sorry, dirty code again... - // ref: talk.c, AngelNotOnline. - setuserfile(xbuf, "angelmsg"); - fpx = fopen(xbuf, "rt"); - if (!fpx || !fgets(xbuf, sizeof(xbuf), fpx) || - strncmp(xbuf, "%%[", 3)) - { - strcpy(xbuf+3, "小天使"); - } - else - { - chomp(xbuf); - strlcat(xbuf, "小天使", sizeof(xbuf)); - } - if (fpx) fclose(fpx); + char mynick[IDLEN+1]; + angel_load_my_nick(mynick, sizeof(mynick)); + strlcat(mynick, "小天使", sizeof(mynick)); getdata_str(3, 0, "請輸入想用的名字(輸入[r]為真名): ", - real_name, sizeof(real_name), DOECHO, xbuf+3); + real_name, sizeof(real_name), DOECHO, mynick); } else #endif // PLAY_ANGEL && BN_ANGELPRAY if (defanony) |