summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2013-03-13 21:27:17 +0800
committerpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2013-03-13 21:27:17 +0800
commitc23512c1cbb65ef873cb5fa02bb908a90754c66e (patch)
tree69b952ce46d4ba9a6cb4557ea1c98e62f4569919
parent83cb5567d104c1fef7c9235c306958b47257b290 (diff)
downloadpttbbs-c23512c1cbb65ef873cb5fa02bb908a90754c66e.tar
pttbbs-c23512c1cbb65ef873cb5fa02bb908a90754c66e.tar.gz
pttbbs-c23512c1cbb65ef873cb5fa02bb908a90754c66e.tar.bz2
pttbbs-c23512c1cbb65ef873cb5fa02bb908a90754c66e.tar.lz
pttbbs-c23512c1cbb65ef873cb5fa02bb908a90754c66e.tar.xz
pttbbs-c23512c1cbb65ef873cb5fa02bb908a90754c66e.tar.zst
pttbbs-c23512c1cbb65ef873cb5fa02bb908a90754c66e.zip
Revise angel activity and prepare for free angel to inactive masters.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk@5804 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--pttbbs/include/proto.h2
-rw-r--r--pttbbs/mbbsd/angel.c62
-rw-r--r--pttbbs/mbbsd/mbbsd.c6
3 files changed, 51 insertions, 19 deletions
diff --git a/pttbbs/include/proto.h b/pttbbs/include/proto.h
index 37c240c8..3d8f030b 100644
--- a/pttbbs/include/proto.h
+++ b/pttbbs/include/proto.h
@@ -36,7 +36,7 @@ int a_angelmsg2(void);
int a_angelreport(void);
int a_angelreload(void);
int angel_reject_me(userinfo_t * uin);
-void angel_notify_activity(void);
+void angel_notify_activity(const char *userid);
void angel_log_order_song(const char *angel_nick);
const char *angel_order_song(char *receiver, size_t sz_receiver);
void CallAngel(void);
diff --git a/pttbbs/mbbsd/angel.c b/pttbbs/mbbsd/angel.c
index 0e4d5ffe..a3ff4f3d 100644
--- a/pttbbs/mbbsd/angel.c
+++ b/pttbbs/mbbsd/angel.c
@@ -15,6 +15,10 @@
// 天使不在線上時的說明(附自訂訊息)
#define FN_ANGEL_OFFLINE2 "etc/angel_offline2"
+#ifndef ANGEL_INACTIVE_DAYS
+#define ANGEL_INACTIVE_DAYS (30*3)
+#endif
+
static const char
*PROMPT_ANGELBEATS = " Angel Beats! 天使公會 ",
*ERR_CONNECTION = "抱歉,無法連線至天使公會。\n"
@@ -59,18 +63,29 @@ angel_beats_do_request(int op, int master_uid, int angel_uid) {
// Local Angel Service
void
-angel_notify_activity() {
+angel_notify_activity(const char *userid) {
+ int master;
static time4_t t = 0;
- time4_t tick = now;
+ time4_t tick;
+
+#ifdef ANGEL_CIA_ACCOUNT
+ // Don't notify AngelBeats for CIA account.
+ if (strcasecmp(userid, ANGEL_CIA_ACCOUNT) != 0)
+ return;
+#endif
// tick: every 1 minutes.
- tick -= tick % (1 * 60);
+ syncnow();
+ tick = now - now % (1 * 60);
// ping daemon only in different ticks.
if (tick == t)
return;
+
+ master = searchuser(userid, NULL);
t = tick;
- angel_beats_do_request(ANGELBEATS_REQ_HEARTBEAT, 0, usernum);
+
+ angel_beats_do_request(ANGELBEATS_REQ_HEARTBEAT, master, usernum);
}
void
@@ -765,12 +780,38 @@ TalkToAngel(){
return;
}
+#ifdef ANGEL_CIA_ACCOUNT
+ if (strcasecmp(cuser.userid, ANGEL_CIA_ACCOUNT) == 0)
+ supervisor = 1;
+#endif
+
if (cuser.myangel[0] && !AngelPermChecked) {
- userec_t xuser;
- memset(&xuser, 0, sizeof(xuser));
- getuser(cuser.myangel, &xuser); // XXX if user doesn't exist
- if (!(xuser.userlevel & PERM_ANGEL))
+ userec_t xuser = {0};
+ if (getuser(cuser.myangel, &xuser) < 1 ||
+ !(xuser.userlevel & PERM_ANGEL)) {
pwcuSetMyAngel("");
+#ifdef USE_FREE_ANGEL_FOR_INACTIVE_MASTER
+ } else if (!supervisor &&
+ (now - cuser.timeplayangel >
+ ANGEL_INACTIVE_DAYS * DAY_SECONDS)) {
+ // Inactive master.
+ uent = search_ulist_userid(cuser.myangel);
+ if (uent == NULL || angel_reject_me(uent) ||
+ uent->angelpause || uent->mode == DEBUGSLEEPING) {
+ log_filef("log/auto_change_angel.log", LOG_CREAT,
+ "%s master %s (%d days), angel %s, state (%s)\n",
+ Cdatelite(&now), cuser.userid,
+ (now - cuser.timeplayangel) / DAY_SECONDS,
+ cuser.myangel,
+ !uent ? "not online" : angel_reject_me(uent) ?
+ "reject" : uent->angelpause ? "pause" : "debugsleep");
+ pwcuSetMyAngel("");
+ angel_beats_do_request(
+ ANGELBEATS_REQ_REMOVE_LINK, usernum,
+ searchuser(cuser.myangel, NULL));
+ }
+#endif
+ }
}
AngelPermChecked = 1;
@@ -790,11 +831,6 @@ TalkToAngel(){
// because it relies on this data.
angel_reload_nick();
-#ifdef ANGEL_CIA_ACCOUNT
- if (strcasecmp(cuser.userid, ANGEL_CIA_ACCOUNT) == 0)
- supervisor = 1;
-#endif
-
uent = search_ulist_userid(cuser.myangel);
if (uent == NULL || (!supervisor && angel_reject_me(uent)) ||
uent->mode == DEBUGSLEEPING){
diff --git a/pttbbs/mbbsd/mbbsd.c b/pttbbs/mbbsd/mbbsd.c
index a9495776..277a0971 100644
--- a/pttbbs/mbbsd/mbbsd.c
+++ b/pttbbs/mbbsd/mbbsd.c
@@ -406,11 +406,7 @@ show_call_in(int save, int which)
currutmp->msgs[which].last_call_in);
// I must be an Angel. Let's try to update angel beats info.
// TODO maybe it's better to move this to "sender".
-#ifdef ANGEL_CIA_ACCOUNT
- // Don't notify AngelBeats for CIA account.
- if (strcasecmp(currutmp->msgs[which].userid, ANGEL_CIA_ACCOUNT) != 0)
-#endif
- angel_notify_activity();
+ angel_notify_activity(currutmp->msgs[which].userid);
} else
#endif
snprintf(buf, sizeof(buf), ANSI_COLOR(1;33;46) "★%s" ANSI_COLOR(37;45)