summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorscw <scw@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-06-20 16:42:52 +0800
committerscw <scw@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-06-20 16:42:52 +0800
commitbdd31693cd3b73ea5a3a9bdc78540e0377df59ec (patch)
treeb9fde34a33abcfe5ffd492346691588ca479496c
parent74cd20707c189fc522e7b44653f1d59a6219586c (diff)
downloadpttbbs-bdd31693cd3b73ea5a3a9bdc78540e0377df59ec.tar
pttbbs-bdd31693cd3b73ea5a3a9bdc78540e0377df59ec.tar.gz
pttbbs-bdd31693cd3b73ea5a3a9bdc78540e0377df59ec.tar.bz2
pttbbs-bdd31693cd3b73ea5a3a9bdc78540e0377df59ec.tar.lz
pttbbs-bdd31693cd3b73ea5a3a9bdc78540e0377df59ec.tar.xz
pttbbs-bdd31693cd3b73ea5a3a9bdc78540e0377df59ec.tar.zst
pttbbs-bdd31693cd3b73ea5a3a9bdc78540e0377df59ec.zip
Add statistic program for angel.
fix some warning and add svn:keywords Id for several files. git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2072 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--include/pttstruct.h4
-rw-r--r--mbbsd/assess.c1
-rw-r--r--mbbsd/chc.c1
-rw-r--r--mbbsd/fav.c1
-rw-r--r--mbbsd/mbbsd.c2
-rw-r--r--mbbsd/screen.c6
-rw-r--r--util/Makefile2
-rw-r--r--util/angel.c109
-rw-r--r--util/buildir.c7
9 files changed, 128 insertions, 5 deletions
diff --git a/include/pttstruct.h b/include/pttstruct.h
index c32c615b..99be5a50 100644
--- a/include/pttstruct.h
+++ b/include/pttstruct.h
@@ -121,10 +121,10 @@ 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 REJ_QUESTION 0x800 /* true if don't want to be angel for a while */
-#define REJECT_QUESTION (cuser.uflag2 & REJ_QUESTION)
#ifdef PLAY_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 */
diff --git a/mbbsd/assess.c b/mbbsd/assess.c
index 2e8ebd36..5ceb0564 100644
--- a/mbbsd/assess.c
+++ b/mbbsd/assess.c
@@ -1,3 +1,4 @@
+/* $Id$ */
#include "bbs.h"
#ifdef ASSESS
diff --git a/mbbsd/chc.c b/mbbsd/chc.c
index 4824af0f..5ab93a00 100644
--- a/mbbsd/chc.c
+++ b/mbbsd/chc.c
@@ -1,3 +1,4 @@
+/* $Id$ */
#include "bbs.h"
#define CENTER(a, b) (((a) + (b)) >> 1)
diff --git a/mbbsd/fav.c b/mbbsd/fav.c
index c5bd6c0d..e4766b1a 100644
--- a/mbbsd/fav.c
+++ b/mbbsd/fav.c
@@ -1,3 +1,4 @@
+/* $Id$ */
#include "bbs.h"
#ifdef MEM_CHECK
diff --git a/mbbsd/mbbsd.c b/mbbsd/mbbsd.c
index be7b32e7..402a71c6 100644
--- a/mbbsd/mbbsd.c
+++ b/mbbsd/mbbsd.c
@@ -778,9 +778,9 @@ setup_utmp(int mode)
if (enter_uflag & CLOAK_FLAG)
uinfo.invisible = YEA;
+#ifdef PLAY_ANGEL
if (REJECT_QUESTION)
uinfo.angel = 1;
-#ifdef PLAY_ANGEL
uinfo.angel |= ANGEL_STATUS() << 1;
#endif
diff --git a/mbbsd/screen.c b/mbbsd/screen.c
index 8c91434b..6ad8920b 100644
--- a/mbbsd/screen.c
+++ b/mbbsd/screen.c
@@ -306,6 +306,11 @@ outc(unsigned char c)
if (cur_col < slp->smod)
slp->smod = cur_col;
}
+#if 1
+ ++cur_col;
+#else
+ /* this comparison is always false (cur_col is unsigned char and scr_cols
+ * is 511). */
if (++cur_col >= scr_cols) {
if (standing && (slp->mode & STANDOUT)) {
standing = 0;
@@ -315,6 +320,7 @@ outc(unsigned char c)
if (cur_ln < scr_lns)
cur_ln++;
}
+#endif
}
int
diff --git a/util/Makefile b/util/Makefile
index 1faf486e..d4d1def3 100644
--- a/util/Makefile
+++ b/util/Makefile
@@ -23,7 +23,7 @@ CPROG_WITH_UTIL= \
indexuser yearsold toplazyBM toplazyBBM \
reaper buildAnnounce inndBM shmctl \
outmail chkhbf checkmoney merge_dir \
- transman
+ transman angel
# 下面這些程式, 會直接被 compile
CPROG_WITHOUT_UTIL= \
diff --git a/util/angel.c b/util/angel.c
new file mode 100644
index 00000000..4433aef2
--- /dev/null
+++ b/util/angel.c
@@ -0,0 +1,109 @@
+/* $Id$ */
+#include "bbs.h"
+
+#ifndef PLAY_ANGEL
+int main(){ return 0; }
+#else
+
+int total[MAX_USERS];
+int reject[4];
+int rej_question;
+
+int ListCmp(const void * a, const void * b){
+ return *(int*)b - *(int*)a;
+}
+
+int main(int argc, char* argv[]){
+ char* mailto = "SYSOP";
+ int (*list)[2];
+ int i, j;
+ time_t t;
+ int count;
+ int nReport = 100;
+ userec_t user;
+ FILE* fp = fopen(BBSHOME "/.PASSWDS", "rb");
+ int pipefd[2];
+
+ if(argc > 1)
+ mailto = argv[1];
+ if(argc > 2)
+ nReport = atoi(argv[2]);
+ attach_SHM();
+
+ j = count = 0;
+ while(fread(&user, sizeof(userec_t), 1, fp) == 1){
+ ++j; /* j == uid */
+ if(user.myangel[0]){
+ i = searchuser(user.myangel);
+ if(i)
+ ++total[i];
+ }
+ if(user.userlevel & PERM_ANGEL){
+ ++count;
+ ++reject[((user.uflag2 & ANGEL_MASK) >> 12)];
+ ++total[j]; /* make all angel have total > 0 */
+ if(user.uflag2 & REJ_QUESTION)
+ ++rej_question;
+ }
+ }
+ fclose(fp);
+
+ if(nReport > count)
+ nReport = count;
+
+ list = (int(*)[2]) malloc(count * sizeof(int[2]));
+ j = 0;
+ for(i = 0; i < MAX_USERS; ++i)
+ if(total[i]){
+ list[j][0] = total[i] - 1;
+ list[j][1] = i;
+ ++j;
+ }
+
+ qsort(list, count, sizeof(int[2]), ListCmp);
+
+ /* Ok, let's send the result. */
+ pipe(pipefd);
+ if((i = fork()) == -1){
+ fprintf(stderr, "fork error: %s\nDidn't send the result.\n",
+ strerror(errno));
+ return 0;
+ }else if(i == 0){
+ /* child */
+ dup2(pipefd[0], 0);
+ close(pipefd[0]); /* use 0 instead of pipefd[0], don't need any more */
+ close(pipefd[1]); /* close write site */
+ execlp("bbsmail", "bbsmail", mailto, NULL);
+ fprintf(stderr, "execlp error: %s\nDidn't send the result.\n",
+ strerror(errno));
+ return 0;
+ }
+ /* parent, don't need read site */
+ close(pipefd[0]);
+ fp = fdopen(pipefd[1], "w");
+
+ fprintf(fp, "Subject: 小天使統計資料\n"
+ "From: 站方統計\n"
+ "\n現在全站小天使有 %d 位\n"
+ "\n小主人數最多的 %d 位小天使:\n", count, nReport);
+ for(i = 0; i < nReport; ++i)
+ fprintf(fp, "%15s%3d 人\n", SHM->userid[list[i][1] - 1], list[i][0]);
+ fprintf(fp, "\n現在男女皆收的小天使有 %d 位\n"
+ "只收女生的有 %d 位 (共 %d 位收女生)\n"
+ "只收男生的有 %d 位 (共 %d 位收男生)\n"
+ "不接受新小天使的有 %d 位\n",
+ reject[0], reject[1], reject[1] + reject[0],
+ reject[2], reject[2] + reject[0], reject[3]);
+ fprintf(fp, "\n現在開放小主人問問題的小天使有 %d 位\n"
+ "不開放的有 %d 位\n",
+ count - rej_question, rej_question);
+
+ time(&t);
+ fprintf(fp, "\n--\n\n"
+ " 本資料由 angel 程式產生於 %s\n",
+ ctime(&t));
+ fclose(fp);
+ return 0;
+}
+
+#endif /* defined PLAY_ANGEL */
diff --git a/util/buildir.c b/util/buildir.c
index 573a0178..6b0917e7 100644
--- a/util/buildir.c
+++ b/util/buildir.c
@@ -1,7 +1,12 @@
/* $Id$ */
#include "bbs.h"
-int dirselect(struct dirent *dir) {
+#ifdef __linux__
+int dirselect(const struct dirent *dir)
+#else
+int dirselect(struct dirent *dir)
+#endif
+{
return strchr("MDSGH", dir->d_name[0]) && dir->d_name[1] == '.';
}