diff options
-rw-r--r-- | pttbbs/daemon/angelbeats/angelbeats.c | 24 | ||||
-rw-r--r-- | pttbbs/include/daemons.h | 5 | ||||
-rw-r--r-- | pttbbs/pttbbs.mk | 5 | ||||
-rw-r--r-- | pttbbs/util/account.c | 4 | ||||
-rw-r--r-- | pttbbs/util/angel.c | 10 |
5 files changed, 39 insertions, 9 deletions
diff --git a/pttbbs/daemon/angelbeats/angelbeats.c b/pttbbs/daemon/angelbeats/angelbeats.c index 56900f82..fabfb412 100644 --- a/pttbbs/daemon/angelbeats/angelbeats.c +++ b/pttbbs/daemon/angelbeats/angelbeats.c @@ -17,6 +17,7 @@ // and/or other materials provided with the distribution. // -------------------------------------------------------------------------- // TODO cache report results. +// TODO able to persist perf data. #include <stdio.h> #include <stdlib.h> @@ -209,7 +210,14 @@ int suggest_online_angel(int master_uid) { size_t i; int is_pause, logins; - int uid = 0; + int uid = 0, do_perf = 0; + static time_t perf_time = 0; + time_t clk = time(0); + + if (clk - perf_time > ANGELBEATS_PERF_MIN_PERIOD) { + perf_time = clk; + do_perf = 1; + } for (i = 0; i < g_angel_list_size; i++) { AngelInfo *kanade = g_angel_list + i; @@ -221,14 +229,18 @@ suggest_online_angel(int master_uid) { if (!get_angel_state(kanade, &is_pause, &logins)) continue; - // update perf data - kanade->perf.samples++; - kanade->perf.pause1 += (is_pause == 1); - kanade->perf.pause2 += (is_pause == 2); - // select if angel is online and not paused. if (!uid && !is_pause) uid = kanade->uid; + + // update perf data; otherwise abort. + if (do_perf) { + kanade->perf.samples++; + kanade->perf.pause1 += (is_pause == 1); + kanade->perf.pause2 += (is_pause == 2); + } else if (uid) { + break; + } } return uid; } diff --git a/pttbbs/include/daemons.h b/pttbbs/include/daemons.h index bea523e3..86015d9a 100644 --- a/pttbbs/include/daemons.h +++ b/pttbbs/include/daemons.h @@ -59,6 +59,11 @@ typedef struct login_data #define ANGELBEATS_ADDR ":5132" #endif +// Merge perf in every X seconds. +#ifndef ANGELBEATS_PERF_MIN_PERIOD +#define ANGELBEATS_PERF_MIN_PERIOD (600) +#endif + enum ANGELBEATS_OPERATIONS { ANGELBEATS_REQ_INVALID = 0, ANGELBEATS_REQ_REPORT, diff --git a/pttbbs/pttbbs.mk b/pttbbs/pttbbs.mk index c0463882..44c1e7e5 100644 --- a/pttbbs/pttbbs.mk +++ b/pttbbs/pttbbs.mk @@ -121,6 +121,11 @@ WITHOUT_PROFILE:=yes .MAIN: all +.clang_complete: + make CC='~/.vim/bin/cc_args.py clang' clean all + $(SRCROOT)/include/var.h: $(SRCROOT)/mbbsd/var.c perl $(SRCROOT)/util/parsevar.pl < $(SRCROOT)/mbbsd/var.c > $(SRCROOT)/include/var.h + +.PHONY: .clang_complete ctags diff --git a/pttbbs/util/account.c b/pttbbs/util/account.c index 822969b8..2e69642a 100644 --- a/pttbbs/util/account.c +++ b/pttbbs/util/account.c @@ -408,10 +408,10 @@ main(/*int argc, char **argv*/) // Re-output today's user stats, because keeplog removes it output_today(&tm_adjusted, act, peak_hour_login, day_login); - snprintf(buf, sizeof(buf), "[公安報告] 使用者上線監控 [%02d/%02d:%02d]", + snprintf(buf, sizeof(buf), "[安全報告] 使用者上線監控 [%02d/%02d:%02d]", tm_now.tm_mon + 1, tm_now.tm_mday, tm_now.tm_hour); keeplog("usies", "Security", buf, "usies"); - printf("[公安報告] 使用者上線監控\n"); + printf("[安全報告] 使用者上線監控\n"); sprintf(buf, "-%02d%02d%02d", tm_adjusted.tm_year % 100, tm_adjusted.tm_mon + 1, tm_adjusted.tm_mday); diff --git a/pttbbs/util/angel.c b/pttbbs/util/angel.c index a893d7c3..54465111 100644 --- a/pttbbs/util/angel.c +++ b/pttbbs/util/angel.c @@ -1,5 +1,11 @@ /* $Id$ */ #include "bbs.h" +#include "daemons.h" + +#define QUOTE(x) #x +#define EXPAND_AND_QUOTE(x) QUOTE(x) +#define STR_ANGELBEATS_PERF_MIN_PERIOD \ + EXPAND_AND_QUOTE(ANGELBEATS_PERF_MIN_PERIOD) #ifndef PLAY_ANGEL int main(){ return 0; } @@ -127,7 +133,9 @@ void sendResult(){ " Pause1 指的是 Samples 中有幾次神諭呼叫器設停收\n" " Pause2 指的是 Samples 中有幾次神諭呼叫器設關閉\n" " 因此,Samples 與其它人差太多代表不常上線\n" - " Pause2 接近 Samples 代表此天使都在打混)\n" + " Pause2 接近 Samples 代表此天使都在打混\n" + " 另外, Samples 每" STR_ANGELBEATS_PERF_MIN_PERIOD + "秒最多更新一次)\n" ); appendLogFile(fp, BBSHOME "/log/changeangel.log", "\n== 本周更換小天使記錄 ==\n"); |