diff options
author | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2014-03-25 17:19:07 +0800 |
---|---|---|
committer | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2014-03-25 17:19:07 +0800 |
commit | a765c2a83a8fe8430f04d0c622772a90f97574c0 (patch) | |
tree | a5f6c61168bee12797c7d8bded9cd8de570a12f8 | |
parent | ff2e00bd705b41e4df18e31f818a40247b4cd879 (diff) | |
download | pttbbs-a765c2a83a8fe8430f04d0c622772a90f97574c0.tar pttbbs-a765c2a83a8fe8430f04d0c622772a90f97574c0.tar.gz pttbbs-a765c2a83a8fe8430f04d0c622772a90f97574c0.tar.bz2 pttbbs-a765c2a83a8fe8430f04d0c622772a90f97574c0.tar.lz pttbbs-a765c2a83a8fe8430f04d0c622772a90f97574c0.tar.xz pttbbs-a765c2a83a8fe8430f04d0c622772a90f97574c0.tar.zst pttbbs-a765c2a83a8fe8430f04d0c622772a90f97574c0.zip |
Add utility to update user online counter (lastlogin/numlogindays).
git-svn-id: http://opensvn.csie.org/pttbbs/trunk@5959 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | pttbbs/util/Makefile | 2 | ||||
-rw-r--r-- | pttbbs/util/update_online.c | 47 |
2 files changed, 48 insertions, 1 deletions
diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index fc552116..08d84e9a 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -23,7 +23,7 @@ CPROG_WITH_UTIL= \ angel gamblegive \ chesscountry tunepasswd buildir xchatd \ uhash_loader timecap_buildref showuser removebm \ - redir permreport setrole + redir permreport setrole update_online \ # 下面是 C++ 的程式 CPP_WITH_UTIL= \ diff --git a/pttbbs/util/update_online.c b/pttbbs/util/update_online.c new file mode 100644 index 00000000..0be7cafd --- /dev/null +++ b/pttbbs/util/update_online.c @@ -0,0 +1,47 @@ +#define _UTIL_C_ +#include "bbs.h" + +/* Update user online info. */ + +int check(void *data GCC_UNUSED, int n, userec_t *u) +{ + time4_t now; + userinfo_t *utmp; + if (!u->userid[0] || + (u->userlevel & PERM_VIOLATELAW) || + !(u->userlevel & PERM_LOGINOK)) + return 0; + + utmp = search_ulistn(n + 1, 1); + if (utmp == NULL) + return 0; + + // If the process does not exist... + if (utmp->pid <= 0 || kill(utmp->pid, 0) != 0) + return 0; + + // TODO how to make sure the UTMP has already logged? + now = (time4_t)time(0); + + /* user still online, let's mock it. */ + if (u->lastlogin + DAY_SECONDS <= now) + return 0; + + fprintf(stderr, "."); + u->lastlogin = now; + u->numlogindays++; + passwd_update(n + 1, u); + return 0; +} + +int main(int argc GCC_UNUSED, char **argv GCC_UNUSED) +{ + now = time(NULL); + chdir(BBSHOME); + + attach_SHM(); + if(passwd_init()) + exit(1); + passwd_fast_apply(NULL, check); + return 0; +} |