diff options
author | ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2004-04-30 02:13:39 +0800 |
---|---|---|
committer | ptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2004-04-30 02:13:39 +0800 |
commit | 6c783cd8609ba2e65267eaa2cda8c46d7fc4ac8c (patch) | |
tree | 8829f8b00e4343f8d8ea97606ce4e58ccb186034 | |
parent | 4b2f5eeff9950ef1b7dd620d77efffc876aa76fa (diff) | |
download | pttbbs-6c783cd8609ba2e65267eaa2cda8c46d7fc4ac8c.tar pttbbs-6c783cd8609ba2e65267eaa2cda8c46d7fc4ac8c.tar.gz pttbbs-6c783cd8609ba2e65267eaa2cda8c46d7fc4ac8c.tar.bz2 pttbbs-6c783cd8609ba2e65267eaa2cda8c46d7fc4ac8c.tar.lz pttbbs-6c783cd8609ba2e65267eaa2cda8c46d7fc4ac8c.tar.xz pttbbs-6c783cd8609ba2e65267eaa2cda8c46d7fc4ac8c.tar.zst pttbbs-6c783cd8609ba2e65267eaa2cda8c46d7fc4ac8c.zip |
change log_file()
log_user()
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1889 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | mbbsd/admin.c | 5 | ||||
-rw-r--r-- | mbbsd/bbs.c | 18 | ||||
-rw-r--r-- | mbbsd/cache.c | 8 | ||||
-rw-r--r-- | mbbsd/cal.c | 16 | ||||
-rw-r--r-- | mbbsd/chicken.c | 50 | ||||
-rw-r--r-- | mbbsd/edit.c | 13 | ||||
-rw-r--r-- | mbbsd/fav.c | 4 | ||||
-rw-r--r-- | mbbsd/mail.c | 9 | ||||
-rw-r--r-- | mbbsd/mbbsd.c | 20 | ||||
-rw-r--r-- | mbbsd/read.c | 2 | ||||
-rw-r--r-- | mbbsd/stuff.c | 39 |
11 files changed, 76 insertions, 108 deletions
diff --git a/mbbsd/admin.c b/mbbsd/admin.c index 2175f764..6e98ff2e 100644 --- a/mbbsd/admin.c +++ b/mbbsd/admin.c @@ -1065,12 +1065,9 @@ scan_register_form(char *regfile, int automode, int neednum) strlcpy(muser.realname, fdata[2], sizeof(muser.realname)); strlcpy(muser.address, fdata[4], sizeof(muser.address)); strlcpy(muser.email, fdata[6], sizeof(muser.email)); - snprintf(genbuf, sizeof(genbuf), - "%s:%s:%s", fdata[5], fdata[3], uid); strncpy(muser.justify, genbuf, REGLEN); sethomefile(buf, muser.userid, "justify"); - strncat(genbuf, "\n", sizeof(genbuf)); - log_file(buf, genbuf, 1); + log_file(buf, 1, "%s:%s:%s\n", fdata[5], fdata[3], uid); passwd_update(unum, &muser); if ((fout = fopen(logfile, "a"))) { diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c index c78f270b..194bb972 100644 --- a/mbbsd/bbs.c +++ b/mbbsd/bbs.c @@ -30,12 +30,9 @@ mail_by_link(char *owner, char *title, char *path) void anticrosspost() { - char buf[200]; - - snprintf(buf, sizeof(buf), - "\033[1;33;46m%s \033[37;45mcross post 文章 \033[37m %s\033[m\n", - cuser.userid, ctime(&now)); - log_file("etc/illegal_money", buf, 1); + log_file("etc/illegal_money", 1, + "\033[1;33;46m%s \033[37;45mcross post 文章 \033[37m %s\033[m\n", + cuser.userid, ctime(&now)); post_violatelaw(cuser.userid, "Ptt系統警察", "Cross-post", "罰單處份"); cuser.userlevel |= PERM_VIOLATELAW; @@ -1409,7 +1406,7 @@ do_add_recommend(char *direct, fileheader_t *fhdr, int ent, char *buf) 3.若推的時候前文被刪, 將加到後文的推文數 */ setdirpath(path, direct, fhdr->filename); - if( log_file(path, buf, 0) == -1 ){ // 不 CREATE + if( log_file(path, 0, buf) == -1 ){ // 不 CREATE vmsg("推薦/競標失敗"); return -1; } @@ -2620,12 +2617,9 @@ ReadSelect() static void log_board(char *mode, time_t usetime) { - char buf[256]; - if (usetime > 30) { - snprintf(buf, sizeof(buf), "USE %-20.20s Stay: %5ld (%s) %s\n", - mode, usetime, cuser.userid, ctime(&now)); - log_file(FN_USEBOARD, buf, 1); + log_file(FN_USEBOARD, 1, "USE %-20.20s Stay: %5ld (%s) %s\n", + mode, usetime, cuser.userid, ctime(&now)); } } #endif diff --git a/mbbsd/cache.c b/mbbsd/cache.c index 8a43cfd6..f77bd2a7 100644 --- a/mbbsd/cache.c +++ b/mbbsd/cache.c @@ -471,13 +471,9 @@ setutmpmode(unsigned int mode) { if (currstat != mode) currutmp->mode = currstat = mode; - /* 追蹤使用者 */ if (HAS_PERM(PERM_LOGUSER)) { - char msg[200]; - snprintf(msg, sizeof(msg), "%s setutmpmode to %s(%d) at %s", - cuser.userid, modestring(currutmp, 0), mode, Cdate(&COMMON_TIME)); - log_user(msg); + log_user("setutmpmode to %s(%d)", modestring(currutmp, 0), mode); } } #endif @@ -628,7 +624,7 @@ setbottomtotal(int bid) n = get_num_records(genbuf, sizeof(fileheader_t)); if(n>5) { - log_file("fix_bottom", genbuf, 1); + log_file("fix_bottom", 1, "%s n:%d\n", genbuf, n); unlink(genbuf); SHM->n_bottom[bid-1]=0; } diff --git a/mbbsd/cal.c b/mbbsd/cal.c index 3430ae75..a2b1ae48 100644 --- a/mbbsd/cal.c +++ b/mbbsd/cal.c @@ -59,13 +59,12 @@ unlockutmpmode() int vice(int money, char *item) { - char buf[128], vice[12]; + char buf[128]; unsigned int viceserial = (currutmp->lastact % 1000000) * 100 + rand() % 100; demoney(-money); setuserfile(buf, VICE_NEW); - sprintf(vice,"%8.8d\n", viceserial); - log_file(buf, vice, 1); + log_file(buf, 1, "%8.8d\n", viceserial); snprintf(buf, sizeof(buf), "%s 花了%d$ 編號[%08d]", item, money, viceserial); mail_id(cuser.userid, buf, "etc/vice.txt", "Ptt經濟部"); @@ -360,14 +359,14 @@ int p_give() { int money, tax; - char id[IDLEN + 1], genbuf[90]; + char id[IDLEN + 1], money_buf[20]; move(1, 0); usercomplete("這位幸運兒的id:", id); if (!id[0] || !strcmp(cuser.userid, id) || - !getdata(2, 0, "要給多少錢:", genbuf, 7, LCECHO)) + !getdata(2, 0, "要給多少錢:", money_buf, 7, LCECHO)) return 0; - money = atoi(genbuf); + money = atoi(money_buf); reload_money(); if (money > 0 && cuser.money >= money) { tax = give_tax(money); @@ -375,9 +374,8 @@ p_give() return 0; /* 繳完稅就沒錢給了 */ deumoney(searchuser(id), money - tax); demoney(-money); - snprintf(genbuf, sizeof(genbuf), "%s\t給%s\t%d\t%s", - cuser.userid, id, money - tax, ctime(&now)); - log_file(FN_MONEY, genbuf, 1); + log_file(FN_MONEY,1, "%s\t給%s\t%d\t%s", + cuser.userid, id, money - tax, ctime(&now)); mail_redenvelop(cuser.userid, id, money - tax, getans("要自行書寫紅包袋嗎?[y/N]")); } return 0; diff --git a/mbbsd/chicken.c b/mbbsd/chicken.c index e285856d..78268e49 100644 --- a/mbbsd/chicken.c +++ b/mbbsd/chicken.c @@ -102,8 +102,7 @@ static int new_chicken() { chicken_t *mychicken = &cuser.mychicken; - char buf[150]; - int price; + int price, i; clear(); move(2, 0); @@ -116,13 +115,13 @@ new_chicken() "(k)忍者 $85 (l)阿扁 $200 (m)馬英九 $200 (n)就可人$100 " "[o]羅莉 $77\n" "[0]自己 $0\n"); - getdata_str(7, 0, "請選擇你要養的動物:", buf, 3, LCECHO, "0"); + i = getans("請選擇你要養的動物:"); - buf[0] -= 'a'; - if (buf[0] < 0 || buf[0] > NUM_KINDS - 1) + i -= 'a'; + if (i < 0 || i > NUM_KINDS - 1) return 0; - mychicken->type = buf[0]; + mychicken->type = i; reload_money(); price = egg_price[(int)mychicken->type]; @@ -135,11 +134,10 @@ new_chicken() getdata(8, 0, "幫牠取個好名字:", mychicken->name, sizeof(mychicken->name), DOECHO); - snprintf(buf, sizeof(buf), - "\033[31m%s \033[m養了一隻叫\033[33m %s \033[m的 " - "\033[32m%s\033[m 於 %s\n", cuser.userid, - mychicken->name, chicken_type[(int)mychicken->type], ctime(&now)); - log_file(CHICKENLOG, buf, 1); + log_file(CHICKENLOG, 1, + "\033[31m%s \033[m養了一隻叫\033[33m %s \033[m的 " + "\033[32m%s\033[m 於 %s\n", cuser.userid, + mychicken->name, chicken_type[(int)mychicken->type], ctime(&now)); mychicken->lastvisit = mychicken->birthday = mychicken->cbirth = now; mychicken->food = 0; mychicken->weight = time_change[(int)mychicken->type][WEIGHT] / 3; @@ -440,20 +438,17 @@ static void ch_kill() { chicken_t *mychicken = &cuser.mychicken; - char buf[150], ans[4]; + int ans; - snprintf(buf, sizeof(buf), "棄養這%s要被罰 100 元, 是否要棄養?(y/N)", - chicken_type[(int)mychicken->type]); - getdata_str(23, 0, buf, ans, sizeof(ans), DOECHO, "N"); - if (ans[0] == 'y') { + ans = getans("棄養要被罰 100 元, 是否要棄養?(y/N)"); + if (ans == 'y') { vice(100, "棄養寵物費"); more(CHICKEN_PIC "/deadth", YEA); - snprintf(buf, sizeof(buf), + log_file(CHICKENLOG, 1, "\033[31m%s \033[m把 \033[33m%s\033[m\033[32m %s " "\033[m宰了 於 %s\n", cuser.userid, mychicken->name, chicken_type[(int)mychicken->type], ctime(&now)); - log_file(CHICKENLOG, buf, 1); mychicken->name[0] = 0; } } @@ -482,8 +477,7 @@ ch_sell() int money = (age * food_price[(int)mychicken->type] * 3 + (mychicken->hp_max * 10 + mychicken->weight) / time_change[(int)mychicken->type][HP_MAX]) * 3 / 2 - - mychicken->sick; - char buf[150], ans[4]; + mychicken->sick, ans; if (money < 0) money = 0; @@ -505,15 +499,13 @@ ch_sell() pressanykey(); return 0; } - snprintf(buf, sizeof(buf), "這隻%d歲%s可以賣 %d 元, 是否要賣?(y/N)", age, - chicken_type[(int)mychicken->type], money); - getdata_str(23, 0, buf, ans, sizeof(ans), DOECHO, "N"); - if (ans[0] == 'y') { - snprintf(buf, sizeof(buf), "\033[31m%s\033[m 把 \033[33m%s\033[m " - "\033[32m%s\033[m 用 \033[36m%d\033[m 賣了 於 %s\n", - cuser.userid, mychicken->name, - chicken_type[(int)mychicken->type], money, ctime(&now)); - log_file(CHICKENLOG, buf, 1); + ans = getans("這隻%d歲%s可以賣 %d 元, 是否要賣?(y/N)", age, + chicken_type[(int)mychicken->type], money); + if (ans == 'y') { + log_file(CHICKENLOG, 1, "\033[31m%s\033[m 把 \033[33m%s\033[m " + "\033[32m%s\033[m 用 \033[36m%d\033[m 賣了 於 %s\n", + cuser.userid, mychicken->name, + chicken_type[(int)mychicken->type], money, ctime(&now)); mychicken->lastvisit = mychicken->name[0] = 0; passwd_update(usernum, &cuser); more(CHICKEN_PIC "/sell", YEA); diff --git a/mbbsd/edit.c b/mbbsd/edit.c index ac03696c..d8f376fc 100644 --- a/mbbsd/edit.c +++ b/mbbsd/edit.c @@ -1696,19 +1696,6 @@ vedit(char *fpath, int saveheader, int *islocal) count = 0; tin = interval; } - /* 連續240個interval一樣 , 分明是在斂財 - if (count >= 240) { - char buf[200]; - snprintf(buf, sizeof(buf), "\033[1;33;46m%s\033[37m在\033[37;45m%s\n" - "\033[37m板違法賺錢 , %s\033[m", cuser.userid, - currboard, ctime(&now)); - log_file("etc/illegal_money", buf, 1); - money = 0; - post_violatelaw(cuser.userid, "Ptt 系統警察", "違法賺錢", "扣除不法所得"); - mail_violatelaw(cuser.userid, "Ptt 系統警察", "違法賺錢", "扣除不法所得"); - demoney(10000); - abort_bbs(0); - } */ if (raw_mode) switch (ch) { case Ctrl('S'): diff --git a/mbbsd/fav.c b/mbbsd/fav.c index 8d1381cb..fddccbb8 100644 --- a/mbbsd/fav.c +++ b/mbbsd/fav.c @@ -456,10 +456,8 @@ int fav_save(void) write_favrec(fd, fp); close(fd); if (dashs(buf) == 4) { - char buf3[128]; time_t now = time(NULL); - sprintf(buf3, "%s %s", cuser.userid, ctime(&now)); - log_file(BBSHOME"/dirty.hack", buf3, 1); + log_file(BBSHOME"/dirty.hack", 1, "%s %s", cuser.userid, ctime(&now)); return -1; } Rename(buf, buf2); diff --git a/mbbsd/mail.c b/mbbsd/mail.c index 4e2b9389..053796a9 100644 --- a/mbbsd/mail.c +++ b/mbbsd/mail.c @@ -1594,13 +1594,8 @@ doforward(char *direct, fileheader_t * fh, int mode) refresh(); /* 追蹤使用者 */ - if (HAS_PERM(PERM_LOGUSER)) { - char msg[200]; - - snprintf(msg, sizeof(msg), "%s mailforward to %s at %s", - cuser.userid, address, Cdate(&now)); - log_user(msg); - } + if (HAS_PERM(PERM_LOGUSER)) + log_user("mailforward to %s ",address); if (mode == 'Z') { snprintf(fname, sizeof(fname), TAR_PATH " cfz /tmp/home.%s.tgz home/%c/%s; " diff --git a/mbbsd/mbbsd.c b/mbbsd/mbbsd.c index 8cef890c..804b2af3 100644 --- a/mbbsd/mbbsd.c +++ b/mbbsd/mbbsd.c @@ -98,36 +98,22 @@ reapchild(int sig) } void -log_user(char *msg) -{ - char filename[200], buf[200]; - - snprintf(filename, sizeof(filename), BBSHOME "/home/%c/%s/USERLOG", - cuser.userid[0], cuser.userid); - snprintf(buf, sizeof(buf), "%s\n", msg); - log_file(filename, msg, 1); -} - - -void log_usies(char *mode, char *mesg) { - char genbuf[200]; if (!mesg) - snprintf(genbuf, sizeof(genbuf), + log_file(FN_USIES, 1, "%s %s %-12s Stay:%d (%s)\n", Cdate(&now), mode, cuser.userid , (int)(now - login_start_time) / 60, cuser.username); else - snprintf(genbuf, sizeof(genbuf), + log_file(FN_USIES, 1, "%s %s %-12s %s\n", Cdate(&now), mode, cuser.userid, mesg); - log_file(FN_USIES, genbuf, 1); /* 追蹤使用者 */ if (HAS_PERM(PERM_LOGUSER)) - log_user(genbuf); + log_user("logout"); } diff --git a/mbbsd/read.c b/mbbsd/read.c index c6c35aea..a53be8b0 100644 --- a/mbbsd/read.c +++ b/mbbsd/read.c @@ -352,7 +352,7 @@ select_read(keeploc_t * locmem, int sr_mode) currmode & MODE_SELECT ? "增加條件 標題:":"搜尋標題:", keyword, TTLEN, DOECHO)) return READ_REDRAW; - log_file("keyword_search_log", keyword, 1); + log_file("keyword_search_log", 1, "%s:%s", currboard, keyword); } else if(sr_mode & RS_TITLE) strcpy(keyword, subject(fh->title)); diff --git a/mbbsd/stuff.c b/mbbsd/stuff.c index 7ffc4f92..be260cf3 100644 --- a/mbbsd/stuff.c +++ b/mbbsd/stuff.c @@ -425,11 +425,16 @@ vmsg_lines(const int lines, const char msg[]) return ch; } -char getans(char *prompt) +char getans(const char *fmt,...) { - char ans[5]; + char msg[256]; + char ans[5]; + va_list ap; + va_start(ap, fmt); + vsnprintf(msg , 128, fmt, ap); + va_end(ap); - getdata(b_lines, 0, prompt, ans, sizeof(ans), LCECHO); + getdata(b_lines, 0, msg, ans, sizeof(ans), LCECHO); return ans[0]; } @@ -439,7 +444,7 @@ getkey(const char *fmt,...) char msg[256], i; va_list ap; va_start(ap, fmt); - i = vsnprintf(msg , 100, fmt, ap); + i = vsnprintf(msg , 128, fmt, ap); va_end(ap); return vmsg_lines(b_lines, msg); } @@ -450,7 +455,7 @@ vmsg(const char *fmt,...) char msg[256] = "\033[1;36;44m ◆ ", i; va_list ap; va_start(ap, fmt); - i = vsnprintf(msg + 14, 100, fmt, ap); + i = vsnprintf(msg + 14, 128, fmt, ap); va_end(ap); for(i = i + 14; i < 71; i++) msg[(int)i] = ' '; @@ -578,13 +583,33 @@ printdash(char *mesg) outch('\n'); } -int log_file(char *fn, char *buf, int ifcreate) +int +log_user(const char *fmt, ...) +{ + char msg[256], filename[256]; + va_list ap; + + va_start(ap, fmt); + vsnprintf(msg , 128, fmt, ap); + va_end(ap); + + sethomefile(filename, cuser.userid, "USERLOG"); + return log_file(filename, 1, "%s: %s %s", cuser.userid, msg, Cdate(&now)); +} + +int log_file(char *fn, int ifcreate, const char *fmt,...) { int fd; + char msg[256]; + va_list ap; + va_start(ap, fmt); + vsnprintf(msg , 128, fmt, ap); + va_end(ap); + if( (fd = open(fn, O_APPEND | O_WRONLY | (ifcreate ? O_CREAT : 0), (ifcreate ? 0664 : 0))) < 0 ) return -1; - if( write(fd, buf, strlen(buf)) < 0 ){ + if( write(fd, msg, strlen(msg)) < 0 ){ close(fd); return -1; } |