diff options
author | scw <scw@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2004-05-16 19:30:16 +0800 |
---|---|---|
committer | scw <scw@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2004-05-16 19:30:16 +0800 |
commit | 280c2707ef087a032cd9a846f3fd9549e194fa19 (patch) | |
tree | d307be9b02e36ba3c132cdc73c33d04fb8eddf45 /mbbsd | |
parent | 3d0fa7c79b4d5d08868f32f44052392d03638074 (diff) | |
download | pttbbs-280c2707ef087a032cd9a846f3fd9549e194fa19.tar pttbbs-280c2707ef087a032cd9a846f3fd9549e194fa19.tar.gz pttbbs-280c2707ef087a032cd9a846f3fd9549e194fa19.tar.bz2 pttbbs-280c2707ef087a032cd9a846f3fd9549e194fa19.tar.lz pttbbs-280c2707ef087a032cd9a846f3fd9549e194fa19.tar.xz pttbbs-280c2707ef087a032cd9a846f3fd9549e194fa19.tar.zst pttbbs-280c2707ef087a032cd9a846f3fd9549e194fa19.zip |
merge from trunk.
git-svn-id: http://opensvn.csie.org/pttbbs/branches/scw.angel@1995 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd')
-rw-r--r-- | mbbsd/admin.c | 37 | ||||
-rw-r--r-- | mbbsd/announce.c | 15 | ||||
-rw-r--r-- | mbbsd/bbs.c | 489 | ||||
-rw-r--r-- | mbbsd/board.c | 43 | ||||
-rw-r--r-- | mbbsd/cache.c | 41 | ||||
-rw-r--r-- | mbbsd/cal.c | 70 | ||||
-rw-r--r-- | mbbsd/calendar.c | 1 | ||||
-rw-r--r-- | mbbsd/card.c | 50 | ||||
-rw-r--r-- | mbbsd/chat.c | 2 | ||||
-rw-r--r-- | mbbsd/chc.c | 6 | ||||
-rw-r--r-- | mbbsd/chicken.c | 92 | ||||
-rw-r--r-- | mbbsd/dark.c | 46 | ||||
-rw-r--r-- | mbbsd/edit.c | 35 | ||||
-rw-r--r-- | mbbsd/fav.c | 5 | ||||
-rw-r--r-- | mbbsd/gamble.c | 4 | ||||
-rw-r--r-- | mbbsd/gomo.c | 2 | ||||
-rw-r--r-- | mbbsd/io.c | 112 | ||||
-rw-r--r-- | mbbsd/mail.c | 180 | ||||
-rw-r--r-- | mbbsd/mbbsd.c | 44 | ||||
-rw-r--r-- | mbbsd/menu.c | 31 | ||||
-rw-r--r-- | mbbsd/more.c | 56 | ||||
-rw-r--r-- | mbbsd/name.c | 14 | ||||
-rw-r--r-- | mbbsd/othello.c | 4 | ||||
-rw-r--r-- | mbbsd/read.c | 936 | ||||
-rw-r--r-- | mbbsd/record.c | 60 | ||||
-rw-r--r-- | mbbsd/register.c | 21 | ||||
-rw-r--r-- | mbbsd/screen.c | 2 | ||||
-rw-r--r-- | mbbsd/stuff.c | 137 | ||||
-rw-r--r-- | mbbsd/talk.c | 51 | ||||
-rw-r--r-- | mbbsd/user.c | 66 | ||||
-rw-r--r-- | mbbsd/var.c | 3 | ||||
-rw-r--r-- | mbbsd/vote.c | 3 | ||||
-rw-r--r-- | mbbsd/xyz.c | 6 |
33 files changed, 1051 insertions, 1613 deletions
diff --git a/mbbsd/admin.c b/mbbsd/admin.c index 53140e27..c5d94ca6 100644 --- a/mbbsd/admin.c +++ b/mbbsd/admin.c @@ -134,7 +134,6 @@ search_key_user(char *passwdfile, int mode) fclose(fp1); return 0; } else { - move(b_lines - 1, 0); getdata(0, 0, "目前的 PASSWD 檔沒有此 ID,新增嗎?[y/N]", genbuf, 3, LCECHO); @@ -232,9 +231,10 @@ setperms(unsigned int pbits, char *pstring[]) ((pbits >> (i + 16)) & 1 ? "ˇ" : "X")); } clrtobot(); - while (getdata(b_lines - 1, 0, "請按 [A-5] 切換設定,按 [Return] 結束:", - choice, sizeof(choice), LCECHO)) { - i = choice[0] - 'a'; + while ( + (i = getkey("請按 [A-5] 切換設定,按 [Return] 結束:"))!='\r') + { + i = i - 'a'; if (i < 0) i = choice[0] - '0' + 26; if (i >= NUMPERMS) @@ -263,6 +263,7 @@ void delete_symbolic_link(boardheader_t *bh, int bid) memset(bh, 0, sizeof(boardheader_t)); substitute_record(fn_board, bh, sizeof(boardheader_t), bid); reset_board(bid); + sort_bcache(); log_usies("DelLink", bh->brdname); } @@ -361,6 +362,7 @@ m_mod_board(char *bname) post_msg("Security", bh.title, "請注意刪除的合法性", "[系統安全局]"); substitute_record(fn_board, &bh, sizeof(bh), bid); reset_board(bid); + sort_bcache(); log_usies("DelBoard", bh.title); outs("刪板完畢"); } @@ -448,6 +450,7 @@ m_mod_board(char *bname) setup_man(&newbh); substitute_record(fn_board, &newbh, sizeof(newbh), bid); reset_board(bid); + sort_bcache(); log_usies("SetBoard", newbh.brdname); } } @@ -607,6 +610,7 @@ static int add_board_record(boardheader_t *board) if ((bid = getbnum("")) > 0) { substitute_record(fn_board, board, sizeof(boardheader_t), bid); reset_board(bid); + sort_bcache(); } else if (append_record(fn_board, (fileheader_t *)board, sizeof(boardheader_t)) == -1) { return -1; } else { @@ -955,15 +959,13 @@ scan_register_form(char *regfile, int automode, int neednum) prints("%d.%-12s:%s\n", n - 2, finfo[n], fdata[n]); } if (muser.userlevel & PERM_LOGINOK) { - getdata(b_lines - 1, 0, "\033[1;32m此帳號已經完成註冊, " - "更新(Y/N/Skip)?\033[m[N] ", ans, sizeof(ans), LCECHO); + ans[0] = getkey("此帳號已經完成註冊, " + "更新(Y/N/Skip)?[N] "); if (ans[0] != 'y' && ans[0] != 's') ans[0] = 'd'; } else { - move(b_lines - 1, 0); - prints("是否接受此資料(Y/N/Q/Del/Skip)?[S] "); if (search_ulist(unum) == NULL) - ans[0] = igetch(); + ans[0] = vmsg_lines(22, "是否接受此資料(Y/N/Q/Del/Skip)?[S])"); else ans[0] = 's'; if ('A' <= ans[0] && ans[0] <= 'Z') @@ -1067,14 +1069,14 @@ 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); + snprintf(genbuf, sizeof(genbuf), "%s:%s:%s", + fdata[5], fdata[3], uid); + strlcpy(muser.justify, genbuf, sizeof(muser.justify)); passwd_update(unum, &muser); + sethomefile(buf, muser.userid, "justify"); + log_file(buf, LOG_CREAT, genbuf); + if ((fout = fopen(logfile, "a"))) { for (n = 0; field[n]; n++) fprintf(fout, "%s: %s\n", field[n], fdata[n]); @@ -1161,10 +1163,9 @@ cat_register() { if (system("cat register.new.tmp >> register.new") == 0 && system("rm -f register.new.tmp") == 0) - mprints(22, 0, "OK 嚕~~ 繼續去奮鬥吧!!"); + vmsg("OK 嚕~~ 繼續去奮鬥吧!!"); else - mprints(22, 0, "沒辦法CAT過去呢 去檢查一下系統吧!!"); - pressanykey(); + vmsg("沒辦法CAT過去呢 去檢查一下系統吧!!"); return 0; } diff --git a/mbbsd/announce.c b/mbbsd/announce.c index 21696789..092723db 100644 --- a/mbbsd/announce.c +++ b/mbbsd/announce.c @@ -317,8 +317,7 @@ a_pasteitem(menu_t * pm, int mode) if (dashd(copyfile)) { for (i = 0; copyfile[i] && copyfile[i] == pm->path[i]; i++); if (!copyfile[i]) { - outs("將目錄拷進自己的子目錄中,會造成無窮迴圈!"); - igetch(); + vmsg("將目錄拷進自己的子目錄中,會造成無窮迴圈!"); return; } } @@ -682,9 +681,7 @@ a_showname(menu_t * pm) sym = 1; } if (sym) { - pressanykey(); - move(b_lines - 1, 1); - prints("此 symbolic link 指向 %s\n", &buf[i + 1]); + vmsg("此 symbolic link 指向 %s\n", &buf[i + 1]); } } } @@ -914,21 +911,19 @@ a_menu(char *maintitle, char *path, int lastlevel) Fexit = 1; if (currstat == OSONG) { /* XXX: 只選歌未點歌可灌排行榜 */ - char buf[128]; - snprintf(buf, sizeof(buf), + log_file(FN_USSONG, LOG_CREAT | LOG_VF, "%s\n", fhdr->title); - log_file(FN_USSONG, buf, 1); } free(me.header); return FULLUPDATE; } } - if (more_result == 1) { + if (more_result == READ_PREV) { if (--me.now < 0) { me.now = 0; break; } - } else if (more_result == 3) { + } else if (more_result == READ_NEXT) { if (++me.now >= me.num) { me.now = me.num - 1; break; diff --git a/mbbsd/bbs.c b/mbbsd/bbs.c index 519ac5aa..e9d92805 100644 --- a/mbbsd/bbs.c +++ b/mbbsd/bbs.c @@ -1,6 +1,8 @@ /* $Id$ */ #include "bbs.h" +#define WHEREAMI_LEVEL 16 + static int recommend(int ent, fileheader_t * fhdr, char *direct); #ifdef ASSESS @@ -30,12 +32,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", LOG_CREAT | LOG_VF, + "\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; @@ -57,7 +56,7 @@ save_violatelaw() stand_title("繳罰單中心"); if (!(cuser.userlevel & PERM_VIOLATELAW)) { - mprints(22, 0, "\033[1;31m你無聊啊? 你又沒有被開罰單~~\033[m"); + mouts(22, 0, "\033[1;31m你無聊啊? 你又沒有被開罰單~~\033[m"); pressanykey(); return 0; } @@ -66,7 +65,7 @@ save_violatelaw() snprintf(buf, sizeof(buf), "\033[1;31m這是你第 %d 次違反本站法規" "必須繳出 %d $Ptt ,你只有 %d 元, 錢不夠啦!!\033[m", (int)cuser.vl_count, (int)cuser.vl_count * 1000, cuser.money); - mprints(22, 0, buf); + mouts(22, 0, buf); pressanykey(); return 0; } @@ -77,19 +76,19 @@ save_violatelaw() if (!getdata(10, 0, "確定嗎?[y/n]:", ok, sizeof(ok), LCECHO) || ok[0] == 'n' || ok[0] == 'N') { - mprints(22, 0, "\033[1;31m等你想通了再來吧!! " + mouts(22, 0, "\033[1;31m等你想通了再來吧!! " "我相信你不會知錯不改的~~~\033[m"); pressanykey(); return 0; } snprintf(buf, sizeof(buf), "這是你第 %d 次違法 必須繳出 %d $Ptt", cuser.vl_count, cuser.vl_count * 1000); - mprints(11, 0, buf); + mouts(11, 0, buf); if (!getdata(10, 0, "要付錢[y/n]:", ok, sizeof(ok), LCECHO) || ok[0] == 'N' || ok[0] == 'n') { - mprints(22, 0, "\033[1;31m 嗯 存夠錢 再來吧!!!\033[m"); + mouts(22, 0, "\033[1;31m 嗯 存夠錢 再來吧!!!\033[m"); pressanykey(); return 0; } @@ -215,6 +214,10 @@ readdoent(int num, fileheader_t * ent) sprintf(recom,"3m%2d",ent->recommend); else if(ent->recommend>0) sprintf(recom,"2m%2d",ent->recommend); + else if(ent->recommend<-99) + sprintf(recom,"0mXX"); + else if(ent->recommend<-10) + sprintf(recom,"0mX%d",-ent->recommend); else strcpy(recom,"0m "); prints( @@ -238,21 +241,9 @@ readdoent(int num, fileheader_t * ent) } int -cmpfilename(fileheader_t * fhdr) -{ - return (!strcmp(fhdr->filename, currfile)); -} - -int -cmpfmode(fileheader_t * fhdr) -{ - return (fhdr->filemode & currfmode); -} - -int whereami(int ent, fileheader_t * fhdr, char *direct) { - boardheader_t *bh, *p[32], *root; + boardheader_t *bh, *p[WHEREAMI_LEVEL], *root; int i, j; if (!currutmp->brc_id) @@ -263,7 +254,7 @@ whereami(int ent, fileheader_t * fhdr, char *direct) bh = getbcache(currutmp->brc_id); root = getbcache(1); p[0] = bh; - for (i = 0; i < 31 && p[i]->parent != root && p[i]->parent; i++) + for (i = 0; i < WHEREAMI_LEVEL && p[i]->parent != root && p[i]->parent; i++) p[i + 1] = p[i]->parent; j = i; prints("我在哪?\n%-40.40s %.13s\n", p[j]->title + 7, p[j]->BM); @@ -276,27 +267,7 @@ whereami(int ent, fileheader_t * fhdr, char *direct) return FULLUPDATE; } -static int -substitute_check(fileheader_t * fhdr) -{ - fileheader_t hdr; - char genbuf[100]; - int num = 0; - - /* rocker.011018: 串接模式用reference增進效率 */ - if ((currmode & MODE_SELECT) && (fhdr->money & FHR_REFERENCE)) { - num = fhdr->money & ~FHR_REFERENCE; - setbdir(genbuf, currboard); - get_record(genbuf, &hdr, sizeof(hdr), num); - - /* 再這裡要check一下原來的dir裡面是不是有被人動過... */ - if (strcmp(hdr.filename, fhdr->filename)) - num = getindex(genbuf, fhdr->filename, sizeof(fileheader_t)); - substitute_record(genbuf, fhdr, sizeof(*fhdr), num); - } - return num; -} static int do_select(int ent, fileheader_t * fhdr, char *direct) { @@ -809,26 +780,6 @@ do_generalboardreply(fileheader_t * fhdr) *quote_file = 0; } -int -getindex(char *fpath, char *fname, int size) -{ -#define READSIZE 64 // 8192 / sizeof(fileheader_t) - int fd, i, len, now = 1; /* now starts from 1 */ - fileheader_t fhdrs[READSIZE]; - - if ((fd = open(fpath, O_RDONLY, 0)) != -1) { - while( (len = read(fd, fhdrs, sizeof(fhdrs))) > 0 ){ - len /= sizeof(fileheader_t); - for( i = 0 ; i < len ; ++i, ++now ) - if (!strcmp(fhdrs[i].filename, fname)) { - close(fd); - return now; - } - } - close(fd); - } - return 0; -} int invalid_brdname(char *brd) @@ -936,8 +887,7 @@ reply_post(int ent, fileheader_t * fhdr, char *direct) static int edit_post(int ent, fileheader_t * fhdr, char *direct) { - int num; - char fpath[80], fpath0[80]; + char fpath[80]; char genbuf[200]; fileheader_t postfile; boardheader_t *bp = getbcache(currbid); @@ -961,52 +911,19 @@ edit_post(int ent, fileheader_t * fhdr, char *direct) #endif setutmpmode(REEDIT); + setbpath(fpath, currboard); + stampfile(fpath, &postfile); setdirpath(genbuf, direct, fhdr->filename); local_article = fhdr->filemode & FILE_LOCAL; + Copy(genbuf, fpath); strlcpy(save_title, fhdr->title, sizeof(save_title)); - /* rocker.011018: 這裡是不是該檢查一下修改文章後的money和原有的比較? */ - if (vedit(genbuf, 0, NULL) != -1) { - substitute_record(direct, fhdr, sizeof(*fhdr), ent); - setbpath(fpath, currboard); - stampfile(fpath, &postfile); - strlcpy(genbuf, fhdr->filename, sizeof(genbuf)); - setbfile(fpath0, currboard, fhdr->filename); - - for(num = 2; genbuf[num] != 0; num++){ - if(genbuf[num] == '.'){ - genbuf[num] = 0; - break; - } - } - - sprintf(postfile.filename, "%s.A.%3.3X", genbuf, rand() & 0xFFF); - setdirpath(fpath, fpath, postfile.filename); - unlink(fpath); - - Rename(fpath0, fpath); - - /* rocker.011018: fix 串接模式改文章後文章就不見的bug */ - if ((currmode & MODE_SELECT) && (fhdr->money & FHR_REFERENCE)) { - fileheader_t hdr; - - num = fhdr->money & ~FHR_REFERENCE; - setbdir(fpath0, currboard); - get_record(fpath0, &hdr, sizeof(hdr), num); - - /* 再這裡要check一下原來的dir裡面是不是有被人動過... */ - if (!strcmp(hdr.filename, fhdr->filename)) { - strlcpy(hdr.filename, postfile.filename, sizeof(hdr.filename)); - strlcpy(hdr.title, save_title, sizeof(hdr.title)); - substitute_record(fpath0, &hdr, sizeof(hdr), num); - } - } - strlcpy(fhdr->filename, postfile.filename, sizeof(fhdr->filename)); - strlcpy(fhdr->title, save_title, sizeof(fhdr->title)); - brc_addlist(postfile.filename); - substitute_record(direct, fhdr, sizeof(*fhdr), ent); + if (vedit(fpath, 0, NULL) != -1) { + Rename(fpath, genbuf); +/* Ptt: The code is unnecessary now because use the same name as original name if (!(currbrdattr & BRD_HIDE) && (!bp->level || (currbrdattr & BRD_POSTMASK))) do_crosspost(ALLPOST, fhdr, fpath); +*/ } return FULLUPDATE; } @@ -1129,110 +1046,35 @@ read_post(int ent, fileheader_t * fhdr, char *direct) int more_result; if (fhdr->owner[0] == '-') - return DONOTHING; + return READ_SKIP; setdirpath(genbuf, direct, fhdr->filename); if ((more_result = more(genbuf, YEA)) == -1) - return FULLUPDATE; + return READ_SKIP; brc_addlist(fhdr->filename); strncpy(currtitle, subject(fhdr->title), TTLEN); - strncpy(currowner, subject(fhdr->owner), IDLEN + 2); - - switch (more_result) { - case 1: - return READ_PREV; - case 2: - return RELATE_PREV; - case 3: - return READ_NEXT; - case 4: - return RELATE_NEXT; - case 5: - return RELATE_FIRST; - case 6: - return FULLUPDATE; - case 7: - case 8: - if (CheckPostPerm()) { - strlcpy(quote_file, genbuf, sizeof(quote_file)); - do_reply(fhdr); - *quote_file = 0; - } - return FULLUPDATE; - case 9: - return 'A'; - case 10: - return 'a'; - case 11: - return '/'; - case 12: - return '?'; - } - - - outmsg("\033[34;46m 閱\讀文章 \033[31;47m (R/Y)\033[30m回信 \033[31m" - "(=[]<>)\033[30m相關主題 \033[31m(↑↓)\033[30m上下封 \033[31m(←)" - "\033[30m離開 \033[m"); - - switch (egetch()) { - case 'q': - case 'Q': - case KEY_LEFT: - break; - - case ' ': - case KEY_RIGHT: - case KEY_DOWN: - case KEY_PGDN: - case 'n': - case Ctrl('N'): - return READ_NEXT; - - case KEY_UP: - case 'p': - case Ctrl('P'): - case KEY_PGUP: - return READ_PREV; - - case '=': - return RELATE_FIRST; - - case ']': - case 't': - return RELATE_NEXT; - - case '[': - return RELATE_PREV; - case '.': - case '>': - return THREAD_NEXT; - - case ',': - case '<': - return THREAD_PREV; - - case Ctrl('I'): - t_idle(); - return FULLUPDATE; - - case 'X': - recommend(ent, fhdr, direct); - return FULLUPDATE; - - case 'y': - case 'r': - case 'R': - case 'Y': - if (CheckPostPerm()) { - strlcpy(quote_file, genbuf, sizeof(quote_file)); - do_reply(fhdr); - *quote_file = 0; - } - } - return FULLUPDATE; + if (more_result) + { + if(more_result == 999) + { + if (CheckPostPerm()) { + strlcpy(quote_file, genbuf, sizeof(quote_file)); + do_reply(fhdr); + *quote_file = 0; + } + return FULLUPDATE; + } + if(more_result == 998) + { + recommend(ent, fhdr, direct); + return FULLUPDATE; + } + else return more_result; + } +return FULLUPDATE; } /* ----------------------------------------------------- */ @@ -1321,9 +1163,7 @@ hold_gamble(int ent, fileheader_t * fhdr, char *direct) openticket(currbid); return FULLUPDATE; } else if (dashf(genbuf)) { - move(b_lines - 1, 0); - prints(" 目前系統正在處理開獎事宜, 請結果出爐後再舉辦......."); - pressanykey(); + vmsg(" 目前系統正在處理開獎事宜, 請結果出爐後再舉辦......."); return FULLUPDATE; } getdata(b_lines - 2, 0, "要舉辦賭盤 (N/y):", yn, 3, LCECHO); @@ -1432,9 +1272,7 @@ edit_title(int ent, fileheader_t * fhdr, char *direct) getdata(b_lines - 1, 0, "確定(Y/N)?[n] ", genbuf, 3, DOECHO); if ((genbuf[0] == 'y' || genbuf[0] == 'Y') && dirty) { *fhdr = tmpfhdr; - substitute_record(direct, fhdr, sizeof(*fhdr), ent); - /* rocker.011018: 這裡應該改成用reference的方式取得原來的檔案 */ - substitute_check(fhdr); + substitute_ref_record(direct, fhdr, ent); } return FULLUPDATE; } @@ -1446,7 +1284,7 @@ solve_post(int ent, fileheader_t * fhdr, char *direct) { if (HAS_PERM(PERM_SYSOP)) { fhdr->filemode ^= FILE_SOLVED; - substitute_record(direct, fhdr, sizeof(*fhdr), ent); + substitute_ref_record(direct, fhdr, ent); return PART_REDRAW; } return DONOTHING; @@ -1468,15 +1306,14 @@ recommend_cancel(int ent, fileheader_t * fhdr, char *direct) #endif fhdr->recommend = 0; - substitute_record(direct, fhdr, sizeof(*fhdr), ent); - substitute_check(fhdr); + substitute_ref_record(direct, fhdr, ent); return FULLUPDATE; } static int -do_add_recommend(char *direct, fileheader_t *fhdr, int ent, char *buf) +do_add_recommend(char *direct, fileheader_t *fhdr, int ent, char *buf, int type) { char path[256]; - int fd; + int update=0; /* race here: 為了減少 system calls , 現在直接用當前的推文數 +1 寫入 .DIR 中. @@ -1484,27 +1321,35 @@ do_add_recommend(char *direct, fileheader_t *fhdr, int ent, char *buf) 1.若該文檔名被換掉的話, 推文將寫至舊檔名中 (造成幽靈檔) 2.沒有重新讀一次, 所以推文數可能被少算 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; } - /* get_record(direct, fhdr, sizeof(fhdr), ent); - * This is a solution to avoid most racing (still some), but cost four + /* This is a solution to avoid most racing (still some), but cost four * system calls. */ - - if( fhdr->recommend < 100 ){ - fileheader_t t; - if( (fd = open(direct, O_WRONLY)) < 0 ) + if(type == 0 && fhdr->recommend < 100 ) + update = 1; + else if(type == 1 && fhdr->recommend > -100) + update = -1; + + if( update ){ + int fd; + //Ptt: update only necessary + if( (fd = open(direct, O_RDWR)) < 0 ) return -1; - - ++(fhdr->recommend); - if( lseek(fd, (off_t)(sizeof(*fhdr) * (ent - 1) + - (int)&t.recommend - (int)&t), SEEK_SET) >= 0) + if( lseek(fd, (off_t)(sizeof(fileheader_t) * (ent - 1) + + (int)&fhdr->recommend - (int)fhdr), SEEK_SET) >= 0) // 如果 lseek 失敗就不會 write + { + read(fd, &fhdr->recommend, sizeof(char)); + fhdr->recommend += update; + lseek(fd, -1, SEEK_CUR); write(fd, &fhdr->recommend, sizeof(char)); + } close(fd); } @@ -1547,6 +1392,7 @@ do_bid(int ent, fileheader_t * fhdr, boardheader_t *bp, char *direct, struct t break; } bidinfo.flag |= SALE_COMMENTED; + substitute_record(fpath, &bidinfo, sizeof(bidinfo), 1); } } @@ -1610,7 +1456,7 @@ do_bid(int ent, fileheader_t * fhdr, boardheader_t *bp, char *direct, struct t money, next, fromhost, ptime->tm_mon + 1, ptime->tm_mday); - do_add_recommend(direct, fhdr, ent, genbuf); + do_add_recommend(direct, fhdr, ent, genbuf, 0); if(next > bidinfo.usermax) { bidinfo.usermax=mymax; @@ -1630,7 +1476,7 @@ do_bid(int ent, fileheader_t * fhdr, boardheader_t *bp, char *direct, struct t 20 - strlen(cuser.userid) , " ",money, bidinfo.high, ptime->tm_mon + 1, ptime->tm_mday); - do_add_recommend(direct, fhdr, ent, genbuf); + do_add_recommend(direct, fhdr, ent, genbuf, 0); } else { @@ -1644,7 +1490,7 @@ do_bid(int ent, fileheader_t * fhdr, boardheader_t *bp, char *direct, struct t 20 - strlen(bidinfo.userid) , " ", money, bidinfo.high, ptime->tm_mon + 1, ptime->tm_mday); - do_add_recommend(direct, fhdr, ent, genbuf); + do_add_recommend(direct, fhdr, ent, genbuf, 0); } substitute_record(fpath, &bidinfo, sizeof(bidinfo), 1); vmsg("恭喜您! 以最高價搶標完成!"); @@ -1655,13 +1501,15 @@ static int recommend(int ent, fileheader_t * fhdr, char *direct) { struct tm *ptime = localtime(&now); - char buf[200], path[200], yn[5]; + char buf[200], path[200], + *ctype[3] = {"37m推","31m噓","31m→"}; + int type; boardheader_t *bp; static time_t lastrecommend = 0; bp = getbcache(currbid); - if( bp->brdattr & BRD_NORECOMMEND ){ - vmsg("抱歉, 本板禁止推薦或競標"); + if( bp->brdattr & BRD_NORECOMMEND){ + vmsg("抱歉, 此處禁止推薦或競標"); return FULLUPDATE; } if (!CheckPostPerm() || bp->brdattr & BRD_VOTEBOARD || fhdr->filemode & FILE_VOTE) { @@ -1680,37 +1528,37 @@ recommend(int ent, fileheader_t * fhdr, char *direct) } setdirpath(path, direct, fhdr->filename); + type = vmsg_lines(b_lines-2, "您要對這篇文章 1.推薦 2.噓聲 [1]?") - '1'; + if (fhdr->recommend == 0 && strcmp(cuser.userid, fhdr->owner) == 0){ - vmsg("警告! 本人不能推薦第一次!"); - return FULLUPDATE; - } + mouts(b_lines-1, 0, "本人推薦或噓第一次, 改以 → 加註方式"); + type = 2; + } #ifndef DEBUG - if (!(currmode & MODE_BOARD) && getuser(cuser.userid) && - now - lastrecommend < 40) { - move(b_lines - 1, 0); - prints("離上次推薦時間太近囉, 請多花點時間仔細閱\讀文章!"); - pressanykey(); - return FULLUPDATE; + if (!(currmode & MODE_BOARD)&& now - lastrecommend < 90) { + mouts(b_lines-1, 0,"推薦時間太近, 改以 → 加註方式"); + type = 2; } #endif - - - if (!getdata(b_lines - 2, 0, "推薦語:", path, 40, DOECHO) || - path == NULL || - !getdata(b_lines - 1, 0, "確定要推薦, 請仔細考慮(Y/N)?[n] ", - yn, 5, LCECHO) - || yn[0] != 'y') + if(type > 2 || type < 0) type = 0; + + if (!getdata(b_lines - 2, 0, "要說的話:", path, 40, DOECHO) || + path == NULL || getans("確定要\033[%s\033[m嗎? 請仔細考慮(Y/N)?[n]", ctype[type])!='y') return FULLUPDATE; snprintf(buf, sizeof(buf), - "\033[1;31m→ \033[33m%s\033[m\033[33m:%s\033[m%*s推%15s %02d/%02d\n", - cuser.userid, path, - 51 - strlen(cuser.userid) - strlen(path), " ", fromhost, + "\033[1;%s \033[33m%s\033[m\033[33m:%s\033[m%*s%15s %02d/%02d\n", + ctype[type], + cuser.userid, + path, + 53 - strlen(cuser.userid) - strlen(path) , + " ", + fromhost, ptime->tm_mon + 1, ptime->tm_mday); - do_add_recommend(direct, fhdr, ent, buf); + do_add_recommend(direct, fhdr, ent, buf, type); #ifdef ASSESS /* 每 10 次推文 加一次 goodpost */ - if ((fhdr->filemode & FILE_MARKED) && fhdr->recommend % 10 == 0) { + if (type ==0 && (fhdr->filemode & FILE_MARKED) && fhdr->recommend % 10 == 0) { int uid = searchuser(fhdr->owner); if (uid > 0) inc_goodpost(uid, 1); @@ -1747,9 +1595,8 @@ mark_post(int ent, fileheader_t * fhdr, char *direct) inc_goodpost(searchuser(fhdr->owner), -1 * (fhdr->recommend / 10)); } #endif - - substitute_record(direct, fhdr, sizeof(*fhdr), ent); - substitute_check(fhdr); + + substitute_ref_record(direct, fhdr, ent); return PART_REDRAW; } @@ -1790,33 +1637,8 @@ del_range(int ent, fileheader_t *fhdr, char *direct) if (*num1 == 'y') { outmsg("處理中,請稍後..."); refresh(); - if (currmode & MODE_SELECT) { - int fd, size = sizeof(fileheader_t); - char genbuf[100]; - fileheader_t rsfh; - int i = inum1, now; - if (currstat == RMAIL) - sethomedir(genbuf, cuser.userid); - else - setbdir(genbuf, currboard); - if ((fd = (open(direct, O_RDONLY, 0))) != -1) { - if (lseek(fd, (off_t) (size * (inum1 - 1)), SEEK_SET) != - -1) { - while (read(fd, &rsfh, size) == size) { - if (i > inum2) - break; - now = getindex(genbuf, rsfh.filename, size); - strlcpy(currfile, rsfh.filename, sizeof(currfile)); - delete_record(genbuf, sizeof(fileheader_t), now); - // cmpfilename); - i++; - } - } - close(fd); - } - } #ifdef SAFE_ARTICLE_DELETE - if(bp && bp->nuser > 20 ) + if(bp && !(currmode & MODE_DIGEST) && bp->nuser > 20 ) safe_article_delete_range(direct, inum1, inum2); else delete_range(direct, inum1, inum2); @@ -1839,7 +1661,7 @@ static int del_post(int ent, fileheader_t * fhdr, char *direct) { char genbuf[100], newpath[256]; - int not_owned; + int num, not_owned; boardheader_t *bp; bp = getbcache(currbid); @@ -1856,35 +1678,19 @@ del_post(int ent, fileheader_t * fhdr, char *direct) !strcmp(cuser.userid, STR_GUEST)) return DONOTHING; + if (currmode & MODE_SELECT) { + vmsg("請回到一般模式再刪除文章"); + return DONOTHING; + } getdata(1, 0, msg_del_ny, genbuf, 3, LCECHO); if (genbuf[0] == 'y') { - strlcpy(currfile, fhdr->filename, sizeof(currfile)); if( #ifdef SAFE_ARTICLE_DELETE - (bp->nuser>20 && !safe_article_delete(ent, fhdr, direct)) || + (bp->nuser>20 && !(currmode & MODE_DIGEST) && + !safe_article_delete(ent, fhdr, direct)) || #endif !delete_record(direct, sizeof(fileheader_t), ent) ) { - int num; - if (currmode & MODE_SELECT) { - /* rocker.011018: 利用reference減低loading */ - fileheader_t hdr; - - /* fhdr->money is not real money now, it's a reference instead. - * see select_read() in read.c */ - num = fhdr->money & ~FHR_REFERENCE; - setbdir(genbuf, currboard); - get_record(genbuf, &hdr, sizeof(hdr), num); - - /* 再這裡要check一下原來的dir裡面是不是有被人動過... */ - if (strcmp(hdr.filename, fhdr->filename)) { - num = getindex(genbuf, fhdr->filename, sizeof(fileheader_t)); - get_record(genbuf, &hdr, sizeof(hdr), num); - } - /* rocker.011018: 這裡要還原被破壞的money */ - fhdr->money = hdr.money; - delete_record(genbuf, sizeof(fileheader_t), num); - } cancelpost(fhdr, not_owned, newpath); if(fhdr->filemode & FILE_ANONYMOUS) @@ -1933,13 +1739,9 @@ del_post(int ent, fileheader_t * fhdr, char *direct) if (cuser.numposts) cuser.numposts--; if (!(currmode & MODE_DIGEST && currmode & MODE_BOARD)){ - move(b_lines - 1, 0); - clrtoeol(); demoney(-fhdr->money); - prints("%s,您的文章減為 %d 篇,支付清潔費 %d 銀", msg_del_ok, + vmsg("您的文章減為 %d 篇,支付清潔費 %d 銀", cuser.numposts, fhdr->money); - refresh(); - pressanykey(); } } return DIRCHANGED; @@ -1953,30 +1755,24 @@ show_filename(int ent, fileheader_t * fhdr, char *direct) { if(!HAS_PERM(PERM_SYSOP)) return DONOTHING; - move(b_lines - 1, 0); - prints("檔案名稱: %s ", fhdr->filename); - pressanykey(); + vmsg("檔案名稱: %s ", fhdr->filename); return PART_REDRAW; } static int view_postmoney(int ent, fileheader_t * fhdr, char *direct) { - move(b_lines - 1, 0); if(currmode & MODE_SELECT){ vmsg("請在離開目前的選擇模式再查詢"); return FULLUPDATE; } - clrtoeol(); if(fhdr->filemode & FILE_ANONYMOUS) /* When the file is anonymous posted, fhdr->money is author. * see do_general() */ - prints("匿名管理編號: %d (同一人被查詢時編號相同, 此編號每人看到不相同)", + vmsg("匿名管理編號: %d (同一人號碼會一樣)", fhdr->money + currutmp->pid); else - prints("這一篇文章值 %d 銀", fhdr->money); - refresh(); - pressanykey(); + vmsg("這一篇文章值 %d 銀", fhdr->money); return FULLUPDATE; } @@ -2078,7 +1874,7 @@ sequent_messages(fileheader_t * fptr) "\033[30m下一封 \033[31m(←,q)\033[30m離開 \033[m"); continue_flag = 0; - switch (egetch()) { + switch (igetch()) { case KEY_LEFT: case 'e': case 'q': @@ -2291,20 +2087,6 @@ board_digest() return NEWDIRECT; } -int -board_etc() -{ - if (!HAS_PERM(PERM_SYSOP)) - return DONOTHING; - currmode ^= MODE_ETC; - if (currmode & MODE_ETC) - currmode &= ~MODE_POST; - else if (haspostperm(currboard)) - currmode |= MODE_POST; - - setbdir(currdirect, currboard); - return NEWDIRECT; -} static int push_bottom(int ent, fileheader_t * fhdr, char *direct) @@ -2313,13 +2095,13 @@ push_bottom(int ent, fileheader_t * fhdr, char *direct) char buf[256]; if ((currmode & MODE_DIGEST) || !(currmode & MODE_BOARD)) return DONOTHING; - setbottomtotal(currbid); // Ptt : will be remove when stable + setbottomtotal(currbid); // <- Ptt : will be remove when stable num = getbottomtotal(currbid); if(getans(fhdr->filemode & FILE_BOTTOM ? "取消置底公告?(y/N)": "加入置底公告?(y/N)")!='y') return READ_REDRAW; fhdr->filemode ^= FILE_BOTTOM; - if(fhdr->filemode & FILE_BOTTOM) + if(fhdr->filemode & FILE_BOTTOM ) { sprintf(buf, "%s.bottom", direct); if(num >= 5) @@ -2327,7 +2109,9 @@ push_bottom(int ent, fileheader_t * fhdr, char *direct) vmsg("不得超過 5 篇重要公告 請精簡!"); return READ_REDRAW; } + fhdr->money = ent | FHR_REFERENCE; append_record(buf, fhdr, sizeof(fileheader_t)); + } else { @@ -2401,26 +2185,7 @@ good_post(int ent, fileheader_t * fhdr, char *direct) delta = 1000; } } - substitute_record(direct, fhdr, sizeof(*fhdr), ent); - /* rocker.011018: 串接模式用reference增進效率 */ - if ((currmode & MODE_SELECT) && (fhdr->money & FHR_REFERENCE)) { - fileheader_t hdr; - char genbuf[100]; - int num; - - num = fhdr->money & ~FHR_REFERENCE; - setbdir(genbuf, currboard); - get_record(genbuf, &hdr, sizeof(hdr), num); - - /* 再這裡要check一下原來的dir裡面是不是有被人動過... */ - if (strcmp(hdr.filename, fhdr->filename)) { - num = getindex(genbuf, fhdr->filename, sizeof(fileheader_t)); - get_record(genbuf, &hdr, sizeof(hdr), num); - } - fhdr->money = hdr.money + delta; - - substitute_record(genbuf, fhdr, sizeof(*fhdr), num); - } + substitute_ref_record(direct, fhdr, ent); return FULLUPDATE; } @@ -2490,7 +2255,7 @@ change_hidden(int ent, fileheader_t * fhdr, char *direct) bp = getbcache(currbid); if (((bp->brdattr & BRD_HIDE) && (bp->brdattr & BRD_POSTMASK))) { - if (getans("目前板在隱形狀態, 要解隱形嘛(Y/N)?[N]") != 'y') + if (getans("目前板在隱形狀態, 要解隱形嘛(y/N)?") != 'y') return FULLUPDATE; bp->brdattr &= ~BRD_HIDE; bp->brdattr &= ~BRD_POSTMASK; @@ -2498,7 +2263,7 @@ change_hidden(int ent, fileheader_t * fhdr, char *direct) board_hidden_status = 0; hbflreload(currbid); } else { - if (getans("目前板在現形狀態, 要隱形嘛(Y/N)?[N]") != 'y') + if (getans("目前板在現形狀態, 要隱形嘛(y/N)?") != 'y') return FULLUPDATE; bp->brdattr |= BRD_HIDE; bp->brdattr |= BRD_POSTMASK; @@ -2585,7 +2350,7 @@ onekey_t read_comms[] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, // 'A' 65 bh_title_edit, // 'B' - board_etc, // 'C' + NULL, // 'C' del_range, // 'D' edit_post, // 'E' NULL, // 'F' @@ -2708,12 +2473,10 @@ 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, LOG_CREAT | LOG_VF, + "USE %-20.20s Stay: %5ld (%s) %s\n", + mode, usetime, cuser.userid, ctime(&now)); } } #endif diff --git a/mbbsd/board.c b/mbbsd/board.c index 7cfeabd1..c7968d67 100644 --- a/mbbsd/board.c +++ b/mbbsd/board.c @@ -131,8 +131,7 @@ load_uidofgid(const int gid, const int type) int n, childcount = 0; currbptr = &bcache[gid - 1]; for (n = 0; n < numboards; ++n) { - bptr = SHM->bsorted[type][n]; - if (bptr->brdname[0] == '\0') + if( !(bptr = SHM->bsorted[type][n]) || bptr->brdname[0] == '\0' ) continue; if (bptr->gid == gid) { if (currbptr == &bcache[gid - 1]) @@ -300,8 +299,9 @@ load_boards(char *key) } addnewbrdstat(n, state); } - if(childcount != brdnum) //fix soon - getbcache(class_bid)->childcount = brdnum; + if(childcount < brdnum) //Ptt: dirty fix fix soon + getbcache(class_bid)->childcount = 0; + } } @@ -390,11 +390,26 @@ brdlist_foot() yank_flag == 0 ? "最愛" : yank_flag == 1 ? "部份" : "全部"); } + +static inline char * +make_class_color(char *name) +{ + char *colorset[8] = {"", "\033[32m", + "\033[33m", "\033[36m", "\033[34m", "\033[1m", + "\033[1;32m", "\033[1;33m"}; + + return colorset[(unsigned int) + (name[0] + name[1] + + name[2] + name[3]) & 07]; +} + +#define HILIGHT_COLOR "\033[1;36m" + static void show_brdlist(int head, int clsflag, int newflag) { int myrow = 2; - if (class_bid == 1) { + if (unlikely(class_bid == 1)) { currstat = CLASS; myrow = 6; showtitle("分類看板", BBSName); @@ -428,11 +443,12 @@ show_brdlist(int head, int clsflag, int newflag) char *color[8] = {"", "\033[32m", "\033[33m", "\033[36m", "\033[34m", "\033[1m", "\033[1;32m", "\033[1;33m"}; - char *unread[2] = {"\33[37m \033[m", "\033[1;31mˇ\033[m"}; - - if (yank_flag == 0 && get_fav_type(&nbrd[0]) == 0){ + char *unread[2] = {"\33[37m \033[m", "\033[1;31mˇ\033[m"}; + + if (yank_flag == 0 && get_data_number(get_current_fav()) == 0){ + // brdnum > 0 ??? move(3, 0); - prints(" --- 空目錄 ---"); + outs(" --- 空目錄 ---"); return; } @@ -577,8 +593,9 @@ paste_taged_brds(int gid) getans("貼上標記的看板?(y/N)")=='n') return 0; fav = get_current_fav(); for (tmp = 0; tmp < fav->DataTail; tmp++) { - bid = fav_getid(&fav->favh[tmp]); - boardheader_t *bh = getbcache(bid); + boardheader_t *bh; + bid = fav_getid(&fav->favh[tmp]); + bh = getbcache(bid); if( !is_set_attr(&fav->favh[tmp], FAVH_ADM_TAG)) continue; set_attr(&fav->favh[tmp], FAVH_ADM_TAG, 0); @@ -590,6 +607,7 @@ paste_taged_brds(int gid) log_usies("SetBoardGID", bh->brdname); } } + sort_bcache(); return 1; } @@ -614,9 +632,8 @@ choose_board(int newflag) load_boards(keyword); if (brdnum <= 0 && yank_flag > 0) { if (keyword[0] != 0) { - mprints(b_lines - 1, 0, "沒有任何看板標題有此關鍵字 " + vmsg("沒有任何看板標題有此關鍵字 " "(板主應注意看板標題命名)"); - pressanykey(); keyword[0] = 0; brdnum = -1; continue; diff --git a/mbbsd/cache.c b/mbbsd/cache.c index 15398ece..842cedad 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 @@ -504,11 +500,15 @@ cmpboardclass(boardheader_t ** brd, boardheader_t ** tmp) strcasecmp((*brd)->brdname, (*tmp)->brdname); } -static void +void sort_bcache(void) { int i; - /* critical section 不能單獨呼叫 呼叫reload_bcache or reset_board */ + /* critical section 盡量不要呼叫 */ + /* 只有新增 或移除看板 需要呼叫到 */ + if(SHM->Bbusystate) + { sleep(1); return; } + SHM->Bbusystate = 1; for (i = 0; i < SHM->Bnumber; i++) { SHM->bsorted[1][i] = SHM->bsorted[0][i] = &bcache[i]; } @@ -516,6 +516,12 @@ sort_bcache(void) (QCAST) cmpboardname); qsort(SHM->bsorted[1], SHM->Bnumber, sizeof(boardheader_t *), (QCAST) cmpboardclass); + + for (i = 0; i < SHM->Bnumber; i++) { + bcache[i].firstchild[0] = NULL; + bcache[i].firstchild[1] = NULL; + } + SHM->Bbusystate = 0; } void @@ -525,7 +531,7 @@ reload_bcache(void) safe_sleep(1); } else { - int fd, i; + int fd; SHM->Bbusystate = 1; if ((fd = open(fn_board, O_RDONLY)) > 0) { @@ -538,12 +544,8 @@ reload_bcache(void) /* 等所有 boards 資料更新後再設定 uptime */ SHM->Buptime = SHM->Btouchtime; log_usies("CACHE", "reload bcache"); - sort_bcache(); - for (i = 0; i < SHM->Bnumber; ++i) { - bcache[i].firstchild[0] = NULL; - bcache[i].firstchild[1] = NULL; - } SHM->Bbusystate = 0; + sort_bcache(); } } @@ -566,12 +568,13 @@ void addbrd_touchcache(void) SHM->Bnumber++; numboards = SHM->Bnumber; reset_board(numboards); + sort_bcache(); } void reset_board(int bid) /* XXXbid: from 1 */ { /* Ptt: 這樣就不用老是touch board了 */ - int fd, i, nuser; + int fd, nuser; boardheader_t *bhdr; if (--bid < 0) @@ -589,11 +592,6 @@ reset_board(int bid) /* XXXbid: from 1 */ read(fd, bhdr, sizeof(boardheader_t)); close(fd); } - sort_bcache(); - for (i = 0; i < SHM->Bnumber; i++) { - bcache[i].firstchild[0] = NULL; - bcache[i].firstchild[1] = NULL; - } SHM->busystate_b[bid] = 0; buildBMcache(bid + 1); /* XXXbid */ @@ -628,6 +626,9 @@ setbottomtotal(int bid) n = get_num_records(genbuf, sizeof(fileheader_t)); if(n>5) { +#ifdef DEBUG_BOTTOM + log_file("fix_bottom", LOG_CREAT | LOG_VF, "%s n:%d\n", genbuf, n); +#endif unlink(genbuf); SHM->n_bottom[bid-1]=0; } @@ -877,7 +878,7 @@ reload_fcache(void) buf[0] != '\n') { sscanf(buf, "%s", SHM->domain[SHM->top]); // XXX check buffer size po = buf + strlen(SHM->domain[SHM->top]); - while (*po == ' ') + while (*po == ' ' || *po == '\t') po++; strncpy(SHM->replace[SHM->top], po, 49); SHM->replace[SHM->top] diff --git a/mbbsd/cal.c b/mbbsd/cal.c index dca13c4d..a59eb9f9 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, LOG_CREAT | LOG_VF, "%8.8d\n", viceserial); snprintf(buf, sizeof(buf), "%s 花了%d$ 編號[%08d]", item, money, viceserial); mail_id(cuser.userid, buf, "etc/vice.txt", "Ptt經濟部"); @@ -96,18 +95,13 @@ osong(char *defaultid) /* Jaky 一人一天點一首 */ if (!strcmp(buf, Cdatedate(&cuser.lastsong)) && !HAS_PERM(PERM_SYSOP)) { move(22, 0); - outs("你今天已經點過囉,明天再點吧...."); - refresh(); - pressanykey(); - + vmsg("你今天已經點過囉,明天再點吧...."); unlockutmpmode(); return 0; } if (cuser.money < 200) { move(22, 0); - outs("點歌要200銀唷!...."); - refresh(); - pressanykey(); + vmsg("點歌要200銀唷!...."); unlockutmpmode(); return 0; } @@ -262,18 +256,12 @@ inmailbox(int m) int p_cloak() { - char buf[4]; - getdata(b_lines - 1, 0, - currutmp->invisible ? "確定要現身?[y/N]" : "確定要隱身?[y/N]", - buf, sizeof(buf), LCECHO); - if (buf[0] != 'y') + if (getans(currutmp->invisible ? "確定要現身?[y/N]" : "確定要隱身?[y/N]") != 'y') return 0; if (cuser.money >= 19) { vice(19, "付費隱身"); currutmp->invisible %= 2; - outs((currutmp->invisible ^= 1) ? MSG_CLOAKED : MSG_UNCLOAK); - refresh(); - safe_sleep(1); + vmsg((currutmp->invisible ^= 1) ? MSG_CLOAKED : MSG_UNCLOAK); } return 0; } @@ -282,10 +270,7 @@ p_cloak() int p_from() { - char ans[4]; - - getdata(b_lines - 2, 0, "確定要改故鄉?[y/N]", ans, sizeof(ans), LCECHO); - if (ans[0] != 'y') + if (getans("確定要改故鄉?[y/N]") != 'y') return 0; reload_money(); if (cuser.money < 49) @@ -305,8 +290,7 @@ p_exmail() int n; if (cuser.exmailbox >= MAX_EXKEEPMAIL) { - prints("容量最多增加 %d 封,不能再買了。", MAX_EXKEEPMAIL); - refresh(); + vmsg("容量最多增加 %d 封,不能再買了。", MAX_EXKEEPMAIL); return 0; } snprintf(buf, sizeof(buf), @@ -375,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); @@ -390,12 +374,9 @@ 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); - genbuf[0] = 'n'; - getdata(3, 0, "要自行書寫紅包袋嗎?[y/N]", genbuf, 2, LCECHO); - mail_redenvelop(cuser.userid, id, money - tax, genbuf[0]); + log_file(FN_MONEY, LOG_CREAT | LOG_VF, "%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; } @@ -444,26 +425,3 @@ p_sysinfo(void) return 0; } -/* 小計算機 */ -#if 0 -static void -ccount(float *a, float b, int cmode) -{ - switch (cmode) { - case 0: - case 1: - case 2: - *a += b; - break; - case 3: - *a -= b; - break; - case 4: - *a *= b; - break; - case 5: - *a /= b; - break; - } -} -#endif diff --git a/mbbsd/calendar.c b/mbbsd/calendar.c index 5cb644c2..7928f8a2 100644 --- a/mbbsd/calendar.c +++ b/mbbsd/calendar.c @@ -116,6 +116,7 @@ FreeEvent(event_t * e) while (e) { n = e->next; + free(e->content); /* from strdup() */ free(e); e = n; } diff --git a/mbbsd/card.c b/mbbsd/card.c index 2ed12260..b46ce2bc 100644 --- a/mbbsd/card.c +++ b/mbbsd/card.c @@ -41,7 +41,7 @@ card_select(int *now) (*now == 2) ? cc[1] : cc[0], (*now == 3) ? cc[1] : cc[0], (*now == 4) ? cc[1] : cc[0]); - switch (egetch()) { + switch (igetch()) { case 'Q': case 'q': return 0; @@ -450,16 +450,12 @@ card_jack(int *db) if ((card_number(me[0]) == 0 && card_number(me[1]) == 12) || (card_number(me[1]) == 0 && card_number(me[0]) == 12)) { if (card_flower(me[0]) == 0 && card_flower(me[1]) == 0) { - move(b_lines - 1, 0); - prints("非常不錯唷! (超級黑傑克!! 加 %d 元)", JACK * 10); game_log(JACK, JACK * 10); - pressanykey(); + vmsg("非常不錯唷! (超級黑傑克!! 加 %d 元)", JACK * 10); return 0; } else { - move(b_lines - 1, 0); - prints("很不錯唷! (黑傑克!! 加 %d 元)", JACK * 5); game_log(JACK, JACK * 5); - pressanykey(); + vmsg("很不錯唷! (黑傑克!! 加 %d 元)", JACK * 5); return 0; } } @@ -467,10 +463,8 @@ card_jack(int *db) (card_number(cpu[1]) == 0 && card_number(cpu[0]) == 12)) { c[0] = 1; card_show(cpu, c, me, m); - move(b_lines - 1, 0); - prints("嘿嘿...不好意思....黑傑克!!"); game_log(JACK, 0); - pressanykey(); + vmsg("嘿嘿...不好意思....黑傑克!!"); return 0; } if ((*db < 0) && (card_number(me[0]) == card_number(me[1])) && @@ -485,27 +479,21 @@ card_jack(int *db) m[i] = 1; card_show(cpu, c, me, m); if (card_alls_lower(me) > 21) { - move(b_lines - 1, 0); - prints("嗚嗚...爆掉了!"); game_log(JACK, 0); - pressanykey(); + vmsg("嗚嗚...爆掉了!"); return 0; } i++; if ((i == 3) && (card_number(me[0]) == 7) && (card_number(me[1]) == 7) && (card_number(me[2]) == 7)) { - move(b_lines - 1, 0); - prints("很不錯唷! (幸運七號!! 加 %d 元)", JACK * 7); game_log(JACK, JACK * 7); - pressanykey(); + vmsg("很不錯唷! (幸運七號!! 加 %d 元)", JACK * 7); return 0; } } if (i == 5) { /* 過五關 */ - move(b_lines - 1, 0); - prints("好厲害唷! 過五關嘍! 加P幣 %d 元!", 5 * JACK); game_log(JACK, JACK * 5); - pressanykey(); + vmsg("好厲害唷! 過五關嘍! 加P幣 %d 元!", 5 * JACK); return 0; } j = 2; @@ -516,19 +504,15 @@ card_jack(int *db) c[j] = 1; if (card_alls_lower(cpu) > 21) { card_show(cpu, c, me, m); - move(b_lines - 1, 0); - prints("呵呵...電腦爆掉了! 你贏了! 可得P幣 %d 元", JACK * 2); game_log(JACK, JACK * 2); - pressanykey(); + vmsg("呵呵...電腦爆掉了! 你贏了! 可得P幣 %d 元", JACK * 2); return 0; } j++; } card_show(cpu, c, me, m); - move(b_lines - 1, 0); - prints("哇哇...電腦贏了!"); game_log(JACK, 0); - pressanykey(); + vmsg("哇哇...電腦贏了!"); return 0; } @@ -595,19 +579,15 @@ ten_helf() m[i] = 1; card_show(cpu, c, me, m); if (card_all(me) > 21) { - move(b_lines - 1, 0); - prints("嗚嗚...爆掉了!"); game_log(TEN_HALF, 0); - pressanykey(); + vmsg("嗚嗚...爆掉了!"); return 0; } i++; } if (i == 5) { /* 過五關 */ - move(b_lines - 1, 0); - prints("好厲害唷! 過五關嘍! 加P幣 %d 元!", 5 * PMONEY); game_log(TEN_HALF, PMONEY * 5); - pressanykey(); + vmsg("好厲害唷! 過五關嘍! 加P幣 %d 元!", 5 * PMONEY); return 0; } j = 1; @@ -618,19 +598,15 @@ ten_helf() c[j] = 1; if (card_all(cpu) > 21) { card_show(cpu, c, me, m); - move(b_lines - 1, 0); - prints("呵呵...電腦爆掉了! 你贏了! 可得P幣 %d 元", PMONEY * 2); game_log(TEN_HALF, PMONEY * 2); - pressanykey(); + vmsg("呵呵...電腦爆掉了! 你贏了! 可得P幣 %d 元", PMONEY * 2); return 0; } j++; } card_show(cpu, c, me, m); - move(b_lines - 1, 0); - prints("哇哇...電腦贏了!"); game_log(TEN_HALF, 0); - pressanykey(); + vmsg("哇哇...電腦贏了!"); return 0; } diff --git a/mbbsd/chat.c b/mbbsd/chat.c index f94cfc5f..06f706c3 100644 --- a/mbbsd/chat.c +++ b/mbbsd/chat.c @@ -386,7 +386,7 @@ t_chat() while (chatting) { move(b_lines - 1, currchar + chatid_len); - ch = igetkey(); + ch = igetch(); switch (ch) { case KEY_DOWN: diff --git a/mbbsd/chc.c b/mbbsd/chc.c index 12aed0ad..d80cf276 100644 --- a/mbbsd/chc.c +++ b/mbbsd/chc.c @@ -575,14 +575,14 @@ hisplay(int s, chcusr_t *user1, chcusr_t *user2, board_t board, board_t tmpbrd) if (chc_lefttime < 0) { chc_lefttime = 0; - /* to make him break out igetkey() */ + /* to make him break out igetch() */ chc_from.r = -2; chc_broadcast_send(act_list, board); } chc_drawline(board, user1, user2, TIME_ROW); move(1, 0); oflush(); - switch (igetkey()) { + switch (igetch()) { case 'q': endgame = 2; endturn = 1; @@ -653,7 +653,7 @@ myplay(int s, chcusr_t *user1, chcusr_t *user2, board_t board, board_t tmpbrd) chc_drawline(board, user1, user2, TIME_ROW); chc_movecur(chc_cursor.r, chc_cursor.c); oflush(); - ch = igetkey(); + ch = igetch(); chc_lefttime = CHC_TIMEOUT - (now - start_time); if (chc_lefttime < 0) ch = 'q'; diff --git a/mbbsd/chicken.c b/mbbsd/chicken.c index 1685d842..78bcf358 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,19 +115,18 @@ 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]; if (cuser.money < price) { - prints("\n 錢不夠買蛋蛋,蛋蛋要 %d 元", price); - refresh(); + vmsg("\n 錢不夠買蛋蛋,蛋蛋要 %d 元", price); return 0; } vice(price, "寵物蛋"); @@ -136,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, LOG_CREAT | LOG_VF, + "\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; @@ -400,12 +397,10 @@ ch_buyitem(int money, char *picture, int *item, int haveticket) else demoney(-money * num); show_file(picture, 5, 14, NO_RELOAD); + pressanykey(); } else { - move(b_lines - 1, 0); - clrtoeol(); - outs("現金不夠 !!!"); + vmsg("現金不夠 !!!"); } - pressanykey(); } static void @@ -443,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, LOG_CREAT | LOG_VF, "\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; } } @@ -485,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; @@ -508,15 +499,14 @@ 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, LOG_CREAT | LOG_VF, + "\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); @@ -653,7 +643,6 @@ deadtype(chicken_t * thechicken) { chicken_t *mychicken = &cuser.mychicken; int i; - char buf[150]; if (thechicken->hp <= 0) /* hp用盡 */ i = 1; @@ -670,13 +659,10 @@ deadtype(chicken_t * thechicken) return 0; if (thechicken == mychicken) { - snprintf(buf, sizeof(buf), - "\033[31m%s\033[m 所疼愛的\033[33m %s\033[32m %s " - "\033[m掛了 於 %s\n", - cuser.userid, thechicken->name, - chicken_type[(int)thechicken->type], - ctime(&now)); - log_file(CHICKENLOG, buf, 1); + log_file(CHICKENLOG, LOG_CREAT | LOG_VF, + "\033[31m%s\033[m 所疼愛的\033[33m %s\033[32m %s " + "\033[m掛了 於 %s\n", cuser.userid, thechicken->name, + chicken_type[(int)thechicken->type], ctime(&now)); mychicken->name[0] = 0; passwd_update(usernum, &cuser); } @@ -723,20 +709,18 @@ static void ch_changename() { chicken_t *mychicken = &cuser.mychicken; - char buf[150], newname[20] = ""; + char newname[20] = ""; getdata_str(b_lines - 1, 0, "嗯..改個好名字吧:", newname, 18, DOECHO, mychicken->name); if (strlen(newname) >= 3 && strcmp(newname, mychicken->name)) { - snprintf(buf, sizeof(buf), - "\033[31m%s\033[m 把疼愛的\033[33m %s\033[32m %s " - "\033[m改名為\033[33m %s\033[m 於 %s\n", - cuser.userid, mychicken->name, - chicken_type[(int)mychicken->type], - newname, ctime(&now)); strlcpy(mychicken->name, newname, sizeof(mychicken->name)); - log_file(CHICKENLOG, buf, 1); + log_file(CHICKENLOG, LOG_CREAT | LOG_VF, + "\033[31m%s\033[m 把疼愛的\033[33m %s\033[32m %s " + "\033[m改名為\033[33m %s\033[m 於 %s\n", + cuser.userid, mychicken->name, + chicken_type[(int)mychicken->type], newname, ctime(&now)); } } @@ -928,20 +912,18 @@ chickenpk(int fd) memcpy(&ouser, &xuser, sizeof(userec_t)); reload_chicken(); if (!ochicken->name[0] || !mychicken->name[0]) { - outmsg("有一方沒有寵物"); /* Ptt:妨止page時把寵物賣掉 */ bell(); - refresh(); + vmsg("有一方沒有寵物"); /* Ptt:妨止page時把寵物賣掉 */ add_io(0, 0); close(fd); unlockutmpmode(); - sleep(1); return 0; } show_chicken_data(ochicken, mychicken); add_io(fd, 3); /* 把fd加到igetch監視 */ while (1) { r = rand(); - ch = igetkey(); + ch = igetch(); getuser(mateid); memcpy(&ouser, &xuser, sizeof(userec_t)); reload_chicken(); diff --git a/mbbsd/dark.c b/mbbsd/dark.c index 4c9c6486..e26dd890 100644 --- a/mbbsd/dark.c +++ b/mbbsd/dark.c @@ -1,4 +1,4 @@ -/* $Id: dark.c,v 1.8 2002/07/22 19:02:00 in2 Exp $ */ +/* $Id$ */ #include "bbs.h" #define RED 1 @@ -33,14 +33,6 @@ brdswap(sint y, sint x, sint ly, sint lx) brd[ly][lx].value = -1; } -static void -pprints(sint y, sint x, char *s) -{ - move(y, x); - clrtoeol(); - prints("%s", s); -} - static sint Is_win(item att, item det, sint y, sint x, sint ly, sint lx) { @@ -370,11 +362,11 @@ main_dark(int fd, userinfo_t * uin) if (currutmp->turn) { brd_rand(); send(fd, &brd, sizeof(brd), 0); - pprints(21, 0, " [1;37m[1;33m◆[1;37m你是先手[m"); - pprints(22, 0, " [1;33m◆[5;35m輪到你下了[m"); + mouts(21, 0, " [1;37m[1;33m◆[1;37m你是先手[m"); + mouts(22, 0, " [1;33m◆[5;35m輪到你下了[m"); } else { recv(fd, &brd, sizeof(brd), 0); - pprints(21, 0, " [1;33m◆[1;37m你是後手[m"); + mouts(21, 0, " [1;33m◆[1;37m你是後手[m"); } move(12, 3); prints("%s[0勝0敗][5;31mvs[1;37m.[m%s[0勝0敗]", currutmp->userid, currutmp->mateid); @@ -396,7 +388,7 @@ main_dark(int fd, userinfo_t * uin) end = -1; break; } - ch = igetkey(); + ch = igetch(); if (ch == I_OTHERDATA) { ch = recv(fd, &curr, sizeof(curr), 0); if (ch != sizeof(curr)) { @@ -412,20 +404,20 @@ main_dark(int fd, userinfo_t * uin) break; } if (curr.end == -3) - pprints(23, 30, "\033[33m要求合棋\033[m"); + mouts(23, 30, "\033[33m要求合棋\033[m"); else if (curr.end == -4) - pprints(23, 30, "\033[33m要求換邊\033[m"); + mouts(23, 30, "\033[33m要求換邊\033[m"); else if (curr.end == -5) - pprints(23, 30, "\033[33m要求連吃\033[m"); + mouts(23, 30, "\033[33m要求連吃\033[m"); else - pprints(23, 30, ""); + mouts(23, 30, ""); recv(fd, &brd, sizeof(brd), 0); my = curr.y; mx = curr.x; redraw(); if (curr.end) - pprints(22, 0, " [1;33m◆[5;35m輪到你下了[m"); + mouts(22, 0, " [1;33m◆[5;35m輪到你下了[m"); move(cury[my], curx[mx]); } else { if (currutmp->turn == 'p') { @@ -434,7 +426,7 @@ main_dark(int fd, userinfo_t * uin) currutmp->turn = 'e'; break; } else { - pprints(23, 30, ""); + mouts(23, 30, ""); *buf = 0; currutmp->turn = (uin->turn) ? 0 : 1; } @@ -442,17 +434,17 @@ main_dark(int fd, userinfo_t * uin) if (ch == 'y') { currutmp->color = (currutmp->color == '1') ? '0' : '1'; uin->color = (uin->color == '1') ? '0' : '1'; - pprints(21, 0, (currutmp->color == '1') ? " \033[1;33m◆[1;31m你持紅色棋\033[m" : " \033[1;33m◆[1;36m你持黑色棋\033[m"); + mouts(21, 0, (currutmp->color == '1') ? " \033[1;33m◆[1;31m你持紅色棋\033[m" : " \033[1;33m◆[1;36m你持黑色棋\033[m"); } else { - pprints(23, 30, ""); + mouts(23, 30, ""); currutmp->turn = (uin->turn) ? 0 : 1; } } else if (currutmp->turn == 'g') { if (ch == 'y') { cont = 1; - pprints(21, 0, " \033[1;33m◆[1;31m你持紅色棋\033[m 可連吃"); + mouts(21, 0, " \033[1;33m◆[1;31m你持紅色棋\033[m 可連吃"); } else { - pprints(23, 30, ""); + mouts(23, 30, ""); currutmp->turn = (uin->turn) ? 0 : 1; } } @@ -460,7 +452,7 @@ main_dark(int fd, userinfo_t * uin) if (uin->turn == 'g') { cont = 1; uin->turn = (currutmp->turn) ? 0 : 1; - pprints(21, 10, "可連吃"); + mouts(21, 10, "可連吃"); } end = playing(fd, currutmp->color - '0', ch, &go_on, uin); @@ -493,12 +485,12 @@ main_dark(int fd, userinfo_t * uin) continue; } if (!i && currutmp->color == '1') { - pprints(21, 0, " \033[1;33m◆[1;31m你持紅色棋\033[m"); + mouts(21, 0, " \033[1;33m◆[1;31m你持紅色棋\033[m"); i++; move(cury[my], curx[mx]); } if (!i && currutmp->color == '0') { - pprints(21, 0, " \033[1;33m◆[1;36m你持黑色棋\033[m"); + mouts(21, 0, " \033[1;33m◆[1;36m你持黑色棋\033[m"); i++; move(cury[my], curx[mx]); } @@ -540,7 +532,7 @@ main_dark(int fd, userinfo_t * uin) } break; case -3: - pprints(22, 0, "[1;31m合棋唷!! 下次在分高下吧 ^_^[m"); + mouts(22, 0, "[1;31m合棋唷!! 下次在分高下吧 ^_^[m"); break; default: add_io(0, 0); diff --git a/mbbsd/edit.c b/mbbsd/edit.c index acc7bac0..d8f376fc 100644 --- a/mbbsd/edit.c +++ b/mbbsd/edit.c @@ -258,7 +258,7 @@ ask(char *prompt) standout(); prints("%s", prompt); standend(); - ch = igetkey(); + ch = igetch(); move(0, 0); clrtoeol(); return (ch); @@ -966,7 +966,6 @@ write_file(char *fpath, int saveheader, int *islocal) switch (ans[0]) { case 'a': outs("文章\033[1m 沒有 \033[m存入"); - safe_sleep(1); aborted = -1; break; case 'r': @@ -1051,7 +1050,7 @@ write_file(char *fpath, int saveheader, int *islocal) } currline = NULL; - if (postrecord.times > MAX_CROSSNUM - 1) + if (postrecord.times > MAX_CROSSNUM-1 && hbflcheck(currbid, currutmp->uid)) anticrosspost(); if (po && sum == 3) { @@ -1682,7 +1681,7 @@ vedit(char *fpath, int saveheader, int *islocal) move(curr_window_line, ch); if (!line_dirty && strcmp(line, currline->data)) strcpy(line, currline->data); - ch = igetkey(); + ch = igetch(); /* jochang debug */ if ((interval = (now - th))) { th = now; @@ -1697,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'): @@ -1836,28 +1822,27 @@ vedit(char *fpath, int saveheader, int *islocal) char *tmp, *apos = ans; int fg, bg; - strlcpy(color, "\033[", sizeof(color)); + strcpy(color, "\033["); if (isdigit(*apos)) { - snprintf(color, sizeof(color), - "%s%c", color, *(apos++)); + sprintf(color,"%s%c", color, *(apos++)); if (*apos) - snprintf(color, sizeof(color), "%s;", color); + strcat(color, ";"); } if (*apos) { if ((tmp = strchr(t, toupper(*(apos++))))) fg = tmp - t + 30; else fg = 37; - snprintf(color, sizeof(color), "%s%d", color, fg); + sprintf(color, "%s%d", color, fg); } if (*apos) { if ((tmp = strchr(t, toupper(*(apos++))))) bg = tmp - t + 40; else bg = 40; - snprintf(color, sizeof(color), "%s;%d", color, bg); + sprintf(color, "%s;%d", color, bg); } - snprintf(color, sizeof(color), "%sm", color); + strcat(color, "m"); insert_string(color); } else insert_string(reset_color); @@ -2023,7 +2008,7 @@ vedit(char *fpath, int saveheader, int *islocal) case '\n': #ifdef MAX_EDIT_LINE if( totaln == MAX_EDIT_LINE ){ - vmsg("MAX_EDIT_LINE exceed"); + outs("MAX_EDIT_LINE exceed"); break; } #endif diff --git a/mbbsd/fav.c b/mbbsd/fav.c index 8d1381cb..c5bd6c0d 100644 --- a/mbbsd/fav.c +++ b/mbbsd/fav.c @@ -456,10 +456,9 @@ 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", LOG_CREAT | LOG_VF, + "%s %s", cuser.userid, ctime(&now)); return -1; } Rename(buf, buf2); diff --git a/mbbsd/gamble.c b/mbbsd/gamble.c index 33e67bb8..512df7f2 100644 --- a/mbbsd/gamble.c +++ b/mbbsd/gamble.c @@ -159,9 +159,7 @@ ticket(int bid) ch_buyitem(price, "etc/buyticket", &n, 0); if (bid && !dashf(fn_ticket)) { - move(b_lines - 1, 0); - prints("哇!! 耐ㄚ捏...板主已經停止下注了 不能賭嚕"); - pressanykey(); + vmsg("哇!! 耐ㄚ捏...板主已經停止下注了 不能賭嚕"); break; } diff --git a/mbbsd/gomo.c b/mbbsd/gomo.c index 55060b67..82e9af8f 100644 --- a/mbbsd/gomo.c +++ b/mbbsd/gomo.c @@ -371,7 +371,7 @@ gomoku(int fd) } else clrtoeol(); BGOTOCUR(mv.x, mv.y); - ch = igetkey(); + ch = igetch(); if (ch != I_OTHERDATA) iwantpass = 0; if (ch == 'q') { @@ -174,6 +174,7 @@ dogetch() if (len == 0 || errno != EINTR) abort_bbs(0); /* raise(SIGHUP); */ + } #ifdef SKIP_TELNET_CONTROL_SIGNAL } while( inbuf[0] == -1 ); @@ -198,9 +199,31 @@ static int water_which_flag = 0; int igetch() { - register int ch; - while ((ch = dogetch())) { + register int ch, mode = 0, last = 0; + while ((ch = dogetch())) { + if (mode == 0 && ch == KEY_ESC) // here is state machine for 2 bytes key + mode = 1; + else if (mode == 1) { /* Escape sequence */ + if (ch == '[' || ch == 'O') + mode = 2; + else if (ch == '1' || ch == '4') + { mode = 3; last = ch; } + else + { + KEY_ESC_arg = ch; + return KEY_ESC; + } + } else if (mode == 2 && ch >= 'A' && ch <= 'D') /* Cursor key */ + return KEY_UP + (ch - 'A'); + else if (mode == 2 && ch >= '1' && ch <= '6') + { mode = 3; last = ch; } + else if (mode == 3 && ch == '~') { /* Ins Del Home End PgUp PgDn */ + return KEY_HOME + (last - '1'); + } + else // here is switch for default keys switch (ch) { + case IAC: /* filters */ + continue; #ifdef DEBUG case Ctrl('Q'):{ struct rusage ru; @@ -234,8 +257,8 @@ igetch() free(screen0); redoscr(); continue; - } else - return (ch); + } + return ch; case KEY_TAB: if (WATERMODE(WATER_ORIG) || WATERMODE(WATER_NEW)) if (currutmp != NULL && watermode > 0) { @@ -244,8 +267,7 @@ igetch() t_display_new(); continue; } - return ch; - break; + return ch; case Ctrl('R'): if (currutmp == NULL) @@ -334,7 +356,7 @@ igetch() continue; } } - return (ch); + return ch; case Ctrl('F'): if (WATERMODE(WATER_NEW)) { @@ -353,7 +375,7 @@ igetch() continue; } } - return ch; + return ch; case Ctrl('G'): if (WATERMODE(WATER_NEW)) { @@ -376,13 +398,8 @@ igetch() #endif continue; - case IAC: - // disallow user input telnet protocol leading char IAC chr(255) - // TODO parse telnet protocol - continue; - default: - return ch; + return ch; } } return 0; @@ -508,7 +525,7 @@ oldgetdata(int line, int col, char *prompt, char *buf, int len, int echo) edit_outs(buf); clen = currchar = strlen(buf); - while (move(y, x + currchar), (ch = igetkey()) != '\r') { + while (move(y, x + currchar), (ch = igetch()) != '\r') { switch (ch) { case KEY_DOWN: case Ctrl('N'): case KEY_UP: case Ctrl('P'): @@ -610,14 +627,6 @@ getdata_buf(int line, int col, char *prompt, char *buf, int len, int echo) return oldgetdata(line, col, prompt, buf, len, echo); } -char -getans(char *prompt) -{ - char ans[5]; - - getdata(b_lines, 0, prompt, ans, sizeof(ans), LCECHO); - return ans[0]; -} int getdata_str(int line, int col, char *prompt, char *buf, int len, int echo, char *defaultstr) @@ -634,61 +643,4 @@ getdata(int line, int col, char *prompt, char *buf, int len, int echo) return oldgetdata(line, col, prompt, buf, len, echo); } -int -rget(int x, char *prompt) -{ - register int ch; - - move(x, 0); - clrtobot(); - outs(prompt); - refresh(); - - ch = igetch(); - if (ch >= 'A' && ch <= 'Z') - ch = tolower(ch); - - return ch; -} - - -int -igetkey() -{ - int mode; - int ch, last; - mode = last = 0; - while (1) { - if( !(ch = igetch()) ) - continue; - if (mode == 0) { - if (ch == KEY_ESC) - mode = 1; - else - return ch; /* Normal Key */ - } else if (mode == 1) { /* Escape sequence */ - if (ch == '[' || ch == 'O') - mode = 2; - else if (ch == '1' || ch == '4') - mode = 3; - else { - KEY_ESC_arg = ch; - return KEY_ESC; - } - } else if (mode == 2) { /* Cursor key */ - if (ch >= 'A' && ch <= 'D') - return KEY_UP + (ch - 'A'); - else if (ch >= '1' && ch <= '6') - mode = 3; - else - return ch; - } else if (mode == 3) { /* Ins Del Home End PgUp PgDn */ - if (ch == '~') - return KEY_HOME + (last - '1'); - else - return ch; - } - last = ch; - } -} diff --git a/mbbsd/mail.c b/mbbsd/mail.c index f3e7a855..b8da8226 100644 --- a/mbbsd/mail.c +++ b/mbbsd/mail.c @@ -24,20 +24,14 @@ setforward() getdata(b_lines, 0, "確定開啟自動轉信功\能?(Y/n)", yn, sizeof(yn), LCECHO); if (yn[0] != 'n' && (fp = fopen(buf, "w"))) { - move(b_lines, 0); - clrtoeol(); fprintf(fp, "%s", ip); fclose(fp); - outs("設定完成!"); - refresh(); + vmsg("設定完成!"); return 0; } } - move(b_lines, 0); - clrtoeol(); - outs("取消自動轉信!"); unlink(buf); - refresh(); + vmsg("取消自動轉信!"); return 0; } @@ -163,27 +157,13 @@ chkmailbox() mailmaxkeep = max_keepmail + cuser.exmailbox; m_init(); if ((mailkeep = get_num_records(currmaildir, sizeof(fileheader_t))) > - mailmaxkeep) { - move(b_lines, 0); - clrtoeol(); + mailmaxkeep || + (mailsum = get_sum_records(currmaildir, sizeof(fileheader_t))) > + mailsumlimit) { bell(); - prints("您保存信件數目 %d 超出上限 %d, 請整理", - mailkeep, mailmaxkeep); bell(); - refresh(); - igetch(); - return mailkeep; - } - if ((mailsum = get_sum_records(currmaildir, sizeof(fileheader_t))) > - mailsumlimit) { - move(b_lines, 0); - clrtoeol(); - bell(); - prints("您保存信件容量 %d(k)超出上限 %d(k), 請整理", - mailsum, mailsumlimit); - bell(); - refresh(); - igetch(); + vmsg("您保存信件數目或容量 %d 超出上限 %d, 請整理", + mailkeep, mailmaxkeep); return mailkeep; } } @@ -498,13 +478,9 @@ multi_send(char *title) if (vedit(fpath, YEA, NULL) == -1) { unlink(fpath); curredit = 0; - outs(msg_cancel); - pressanykey(); + vmsg(msg_cancel); return; } - stand_title("寄信中..."); - refresh(); - listing = 80; for (p = toplev; p; p = p->next) { @@ -530,15 +506,14 @@ multi_send(char *title) mymail.filemode |= FILE_MULTI; /* multi-send flag */ sethomedir(genbuf, p->word); if (append_record_forward(genbuf, &mymail, sizeof(mymail)) == -1) - outs(err_uid); + vmsg(err_uid); mailalert(p->word); } hold_mail(fpath, NULL); unlink(fpath); curredit = 0; } else - outs(msg_cancel); - pressanykey(); + vmsg(msg_cancel); } static int @@ -636,8 +611,7 @@ mail_all() outs(err_uid); snprintf(genbuf, sizeof(genbuf), "%*s %5d / %5d", IDLEN + 1, userid, i + 1, unum); - outmsg(genbuf); - refresh(); + vmsg(genbuf); } } return 0; @@ -726,32 +700,21 @@ read_new_mail(fileheader_t * fptr) while (!done) { int more_result = more(fname, YEA); - switch (more_result) { - case 1: - return READ_PREV; - case 2: - return RELATE_PREV; - case 3: - return READ_NEXT; - case 4: - return RELATE_NEXT; - case 5: - return RELATE_FIRST; - case 6: - return 0; - case 7: + switch (more_result) { + case 999: mail_reply(idc, fptr, currmaildir); - return FULLUPDATE; - case 8: - multi_reply(idc, fptr, currmaildir); - return FULLUPDATE; - } - move(b_lines, 0); - clrtoeol(); - outs(msg_mailer); - refresh(); - - switch (egetch()) { + return FULLUPDATE; + case -1: + return READ_SKIP; + case 0: + break; + default: + return more_result; + } + + outmsg(msg_mailer); + + switch (igetch()) { case 'r': case 'R': mail_reply(idc, fptr, currmaildir); @@ -860,22 +823,19 @@ mail_del(int ent, fileheader_t * fhdr, char *direct) if (fhdr->filemode & FILE_MARKED) return DONOTHING; - getdata(1, 0, msg_del_ny, genbuf, 3, LCECHO); - if (genbuf[0] == 'y') { - strlcpy(currfile, fhdr->filename, sizeof(currfile)); + if (currmode & MODE_SELECT) { + vmsg("請先回到正常模式後再進行刪除..."); + return READ_REDRAW; + } + + if (getans(msg_del_ny) == 'y') { if (!delete_record(direct, sizeof(*fhdr), ent)) { setdirpath(genbuf, direct, fhdr->filename); unlink(genbuf); - if ((currmode & MODE_SELECT)) { - int index; - sethomedir(genbuf, cuser.userid); - index = getindex(genbuf, fhdr->filename, sizeof(fileheader_t)); - delete_record(genbuf, sizeof(fileheader_t), index); - } return DIRCHANGED; } } - return TITLE_REDRAW; + return READ_REDRAW; } static int @@ -893,42 +853,22 @@ mail_read(int ent, fileheader_t * fhdr, char *direct) if (more_result != -1) { fhdr->filemode |= FILE_READ; - if ((currmode & MODE_SELECT)) { - int index; - - index = getindex(currmaildir, fhdr->filename, - sizeof(fileheader_t)); - substitute_record(currmaildir, fhdr, sizeof(*fhdr), index); - substitute_record(direct, fhdr, sizeof(*fhdr), ent); - } else - substitute_record(currmaildir, fhdr, sizeof(*fhdr), ent); + substitute_ref_record(direct, fhdr, ent); } switch (more_result) { - case 1: - return READ_PREV; - case 2: - return RELATE_PREV; - case 3: - return READ_NEXT; - case 4: - return RELATE_NEXT; - case 5: - return RELATE_FIRST; - case 6: - return FULLUPDATE; - case 7: + case 999: mail_reply(ent, fhdr, direct); return FULLUPDATE; - case 8: - multi_reply(ent, fhdr, direct); - return FULLUPDATE; + case -1: + return READ_SKIP; + case 0: + break; + default: + return more_result; } - move(b_lines, 0); - clrtoeol(); - refresh(); - outs(msg_mailer); + outmsg(msg_mailer); - switch (egetch()) { + switch (igetch()) { case 'r': case 'R': replied = YEA; @@ -950,14 +890,7 @@ mail_read(int ent, fileheader_t * fhdr, char *direct) mail_del(ent, fhdr, direct); else { fhdr->filemode |= FILE_READ; - if ((currmode & MODE_SELECT)) { - int index; - - index = getindex(currmaildir, fhdr->filename, sizeof(fileheader_t)); - substitute_record(currmaildir, fhdr, sizeof(*fhdr), index); - substitute_record(direct, fhdr, sizeof(*fhdr), ent); - } else - substitute_record(currmaildir, fhdr, sizeof(*fhdr), ent); + substitute_ref_record(direct, fhdr, ent); } return FULLUPDATE; } @@ -1049,14 +982,7 @@ mail_mark(int ent, fileheader_t * fhdr, char *direct) { fhdr->filemode ^= FILE_MARKED; - if ((currmode & MODE_SELECT)) { - int index; - - index = getindex(currmaildir, fhdr->filename, sizeof(fileheader_t)); - substitute_record(currmaildir, fhdr, sizeof(*fhdr), index); - substitute_record(direct, fhdr, sizeof(*fhdr), ent); - } else - substitute_record(currmaildir, fhdr, sizeof(*fhdr), ent); + substitute_ref_record(direct, fhdr, ent); return PART_REDRAW; } @@ -1606,8 +1532,7 @@ doforward(char *direct, fileheader_t * fh, int mode) strlcpy(address, cuser.email, sizeof(address)); if( mode == 'U' ){ - move(b_lines, 0); - prints("將進行 uuencode 。若您不清楚什麼是 uuencode 請改用 F轉寄。"); + vmsg("將進行 uuencode 。若您不清楚什麼是 uuencode 請改用 F轉寄。"); } if (address[0]) { @@ -1632,7 +1557,7 @@ doforward(char *direct, fileheader_t * fh, int mode) snprintf(address, sizeof(address), "%s.bbs@%s", fname, MYHOSTNAME); } else { - outmsg("取消轉寄"); + vmsg("取消轉寄"); return 1; } } while (mode == 'Z' && strstr(address, MYHOSTNAME)); @@ -1640,19 +1565,12 @@ doforward(char *direct, fileheader_t * fh, int mode) if (invalidaddr(address)) return -2; - snprintf(fname, sizeof(fname), "正轉寄給 %s, 請稍候...", address); - outmsg(fname); - move(b_lines, 0); + outmsg("正轉寄請稍候..."); 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 f8d2dc31..8fef76de 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, LOG_CREAT | LOG_VF, "%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, LOG_CREAT | LOG_VF, "%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"); } @@ -183,18 +169,6 @@ u_exit(char *mode) } void -system_abort() -{ - if (currmode) - u_exit("ABORT"); - - clear(); - refresh(); - fprintf(stdout, "謝謝光臨, 記得常來喔 !\n"); - exit(0); -} - -void abort_bbs(int sig) { if (currmode) @@ -429,7 +403,7 @@ write_request(int sig) memmove(&currutmp->msgs[0], &currutmp->msgs[1], sizeof(msgque_t) * currutmp->msgcount); - igetkey(); + igetch(); } } @@ -478,14 +452,12 @@ multi_user_check() log_usies("KICK ", cuser.username); } else { if (search_ulistn(usernum, 3) != NULL) - system_abort(); /* Goodbye(); */ + abort_bbs(0); /* Goodbye(); */ } } else { /* allow multiple guest user */ if (search_ulistn(usernum, 100) != NULL) { - outs("\n抱歉,目前已有太多 guest 在站上, 請用new註冊。\n"); - pressanykey(); - oflush(); + vmsg("\n抱歉,目前已有太多 guest 在站上, 請用new註冊。\n"); exit(1); } } @@ -880,7 +852,7 @@ static void init_guest_info(void) currutmp->pager = 2; } -#ifdef FOREIGN_REG +#ifdef FOREIGN_REG_DAY inline static void foreign_warning(void){ if ((cuser.uflag2 & FOREIGN) && !(cuser.uflag2 & LIVERIGHT)){ if (login_start_time - cuser.firstlogin > (FOREIGN_REG_DAY - 5) * 24 * 3600){ @@ -988,7 +960,7 @@ user_login() if (!PERM_HIDE(currutmp)) cuser.lastlogin = login_start_time; -#ifdef FOREIGN_REG +#ifdef FOREIGN_REG_DAY foreign_warning(); #endif passwd_update(usernum, &cuser); diff --git a/mbbsd/menu.c b/mbbsd/menu.c index bafff3fb..3db2800b 100644 --- a/mbbsd/menu.c +++ b/mbbsd/menu.c @@ -5,25 +5,6 @@ static int refscreen = NA; extern char *boardprefix; extern struct utmpfile_t *utmpshm; - -int -egetch() -{ - int rval; - - while (1) { - rval = igetkey(); - if (talkrequest) { - talkreply(); - refscreen = YEA; - return rval; - } - if (rval != Ctrl('L')) - return rval; - redoscr(); - } -} - extern char *fn_board; extern char board_hidden_status; @@ -70,7 +51,7 @@ showtitle(char *title, char *mid) clear(); prints(TITLE_COLOR "【%s】%s\033[33m%s%s%s\033[3%s《", title, buf, mid, buf, " " + pad, - currmode & MODE_SELECT ? "6m系列" : currmode & MODE_ETC ? "5m其他" : + currmode & MODE_SELECT ? "6m系列" : currmode & MODE_DIGEST ? "2m文摘" : "7m看板"); if (strcmp(currboard, lastboard)) { /* change board */ @@ -87,7 +68,7 @@ showtitle(char *title, char *mid) else prints("%s", currboard); prints("\033[3%dm》\033[0m\n", currmode & MODE_SELECT ? 6 : - currmode & MODE_ETC ? 5 : currmode & MODE_DIGEST ? 2 : 7); + currmode & MODE_DIGEST ? 2 : 7); } /* 動畫處理 */ @@ -314,7 +295,7 @@ domenu(int cmdmode, char *cmdtitle, int cmd, commands_t cmdtable[]) pos++; cursor_show(menu_row + pos, menu_column); - } while (((cmd = egetch()) != EOF) || refscreen); + } while (((cmd = igetch()) != EOF) || refscreen); abort_bbs(0); } @@ -399,7 +380,7 @@ static commands_t namelist[] = { static commands_t userlist[] = { {u_info, PERM_LOGINOK, "IInfo 設定個人資料與密碼"}, {calendar, PERM_LOGINOK, "CCalendar 個人行事曆"}, - {u_editcalendar, PERM_LOGINOK, "EEditCalendar 編輯個人行事曆"}, + {u_editcalendar, PERM_LOGINOK, "CDEditCalendar 編輯個人行事曆"}, {u_loginview, PERM_LOGINOK, "LLogin View 選擇進站畫面"}, {u_ansi, 0, "AANSI 切換 ANSI \033[36m彩\033[35m色\033[37m/" "\033[30;47m黑\033[1;37m白\033[m模示"}, @@ -410,9 +391,9 @@ static commands_t userlist[] = { {u_editplan, PERM_LOGINOK, "QQueryEdit 編輯名片檔"}, {u_editsig, PERM_LOGINOK, "SSignature 編輯簽名檔"}, #if HAVE_FREECLOAK - {u_cloak, PERM_LOGINOK, "CCloak 隱身術"}, + {u_cloak, PERM_LOGINOK, "KKCloak 隱身術"}, #else - {u_cloak, PERM_CLOAK, "CCloak 隱身術"}, + {u_cloak, PERM_CLOAK, "KKCloak 隱身術"}, #endif {u_register, PERM_BASIC, "RRegister 填寫《註冊申請單》"}, {u_list, PERM_SYSOP, "UUsers 列出註冊名單"}, diff --git a/mbbsd/more.c b/mbbsd/more.c index 5e3c993a..c55d6220 100644 --- a/mbbsd/more.c +++ b/mbbsd/more.c @@ -26,7 +26,6 @@ static char *more_help[] = { "(a/A) 跳至同一作者下/上篇", "([/]) 主題式閱\讀 上/下", "(t) 主題式循序閱\讀", - "(Ctrl-C) 小計算機", "(q)(←) 結束", "(h)(H)(?) 輔助說明畫面", NULL @@ -329,7 +328,7 @@ more(char *fpath, int promptend) while (line == b_lines || (line > 0 && viewed == fsize)) { - switch ((ch = egetch())) { + switch ((ch = igetch())) { case ':': { char buf[10]; @@ -382,47 +381,42 @@ more(char *fpath, int promptend) lino = line = 0; } break; - case 'r': + case 'r': // Ptt: put all reply/recommend function here case 'R': case 'Y': - close(fd); - return 7; case 'y': close(fd); - return 8; + return 999; + case 'X': + close(fd); + return 998; case 'A': close(fd); - return 9; + return AUTHOR_PREV; case 'a': close(fd); - return 10; + return AUTHOR_NEXT; case 'F': + case 'f': close(fd); - return 11; + return READ_NEXT; case 'B': + case 'b': close(fd); - return 12; + return READ_PREV; case KEY_LEFT: - close(fd); - return 6; case 'q': close(fd); - return 0; - case 'b': - close(fd); - return 1; - case 'f': - close(fd); - return 3; + return FULLUPDATE; case ']': /* Kaede 為了主題閱讀方便 */ close(fd); - return 4; + return RELATE_NEXT; case '[': /* Kaede 為了主題閱讀方便 */ close(fd); - return 2; + return RELATE_PREV; case '=': /* Kaede 為了主題閱讀方便 */ close(fd); - return 5; + return RELATE_FIRST; case Ctrl('F'): case KEY_PGDN: line = 1; @@ -430,14 +424,14 @@ more(char *fpath, int promptend) case 't': if (viewed == fsize) { close(fd); - return 4; + return RELATE_NEXT; } line = 1; break; case ' ': if (viewed == fsize) { close(fd); - return 3; + return READ_NEXT; } line = 1; break; @@ -454,7 +448,7 @@ more(char *fpath, int promptend) if (viewed == fsize || (promptend == 2 && (ch == '\r' || ch == '\n'))) { close(fd); - return 3; + return READ_NEXT; } line = t_lines - 2; break; @@ -489,12 +483,8 @@ more(char *fpath, int promptend) getdata(b_lines - 2, 0, "把這篇文章收入到暫存檔?[y/N] ", buf, 4, LCECHO); if (buf[0] == 'y') { - char tmpbuf[128]; - - setuserfile(tmpbuf, ask_tmpbuf(b_lines - 1)); - snprintf(buf, sizeof(buf), - "cp -f %s %s", fpath, tmpbuf); - system(buf); + setuserfile(buf, ask_tmpbuf(b_lines - 1)); + Copy(fpath, buf); } if (pageno) pageno--; @@ -525,7 +515,7 @@ more(char *fpath, int promptend) pageno = line = 0; else { close(fd); - return 1; + return READ_PREV; } } } @@ -538,7 +528,7 @@ more(char *fpath, int promptend) if (pageno <= 1) { if (lino == 1 || !pageno) { close(fd); - return 1; + return READ_PREV; } if (header && lino <= 5) { more_goto(fd, viewed = pagebreak[scrollup = lino = diff --git a/mbbsd/name.c b/mbbsd/name.c index 9d467352..3cb2b698 100644 --- a/mbbsd/name.c +++ b/mbbsd/name.c @@ -264,7 +264,6 @@ namecomplete(char *prompt, char *data) prints("%*s", IDLEN + 1, ""); standend(); move(y, x); - refresh(); while ((ch = igetch()) != EOF) { if (ch == '\n' || ch == '\r') { @@ -309,8 +308,7 @@ namecomplete(char *prompt, char *data) len = MaxLen(morelist, p_lines); } if (morelist) { - move(b_lines, 0); - outs(msg_more); + vmsg(msg_more); } move(y, x); continue; @@ -356,7 +354,6 @@ namecomplete(char *prompt, char *data) raise(SIGHUP); /* jochang: don't know if this is * necessary... */ outc('\n'); - refresh(); if (clearbot) { move(2, 0); clrtobot(); @@ -434,8 +431,7 @@ usercomplete(char *prompt, char *data) len = UserMaxLen((arrptr) cwlist, cwnum, morenum, p_lines); } if (morenum < cwnum) { - move(b_lines, 0); - outs(msg_more); + vmsg(msg_more); } else morenum = 0; move(y, x); @@ -478,7 +474,6 @@ usercomplete(char *prompt, char *data) /* longjmp(byebye, -1); */ raise(SIGHUP); /* jochang: don't know if this is necessary */ outc('\n'); - refresh(); if (clearbot) { move(2, 0); clrtobot(); @@ -561,7 +556,6 @@ generalnamecomplete(char *prompt, char *data, int len, size_t nmemb, prints("%*s", IDLEN + 1, ""); standend(); move(y, x); - refresh(); ptr = 0; data[ptr] = 0; @@ -611,8 +605,7 @@ generalnamecomplete(char *prompt, char *data, int len, size_t nmemb, col += len + 2; } if (morelist != end + 1) { - move(b_lines, 0); - outs(msg_more); + vmsg(msg_more); } move(y, x); continue; @@ -651,7 +644,6 @@ generalnamecomplete(char *prompt, char *data, int len, size_t nmemb, } outc('\n'); - refresh(); if (clearbot) { move(2, 0); clrtobot(); diff --git a/mbbsd/othello.c b/mbbsd/othello.c index 96fea2e2..eba90375 100644 --- a/mbbsd/othello.c +++ b/mbbsd/othello.c @@ -124,7 +124,7 @@ get_key(char nowx, char nowy) int ch; move(STARTX - 1 + nowx * 2, STARTY - 1 + nowy * 4); - ch = igetkey(); + ch = igetch(); move(STARTX - 1 + nowx * 2, STARTY - 2 + nowy * 4); if (nowboard[(int)nowx][(int)nowy] != HINT || if_hint == 1) outs(CHESS_TYPE[(int)nowboard[(int)nowx][(int)nowy]]); @@ -274,7 +274,7 @@ end_of_game(int quit) if (fp) fclose(fp); move(1, 1); - igetkey(); + igetch(); } static void diff --git a/mbbsd/read.c b/mbbsd/read.c index 59eae987..58ec63ca 100644 --- a/mbbsd/read.c +++ b/mbbsd/read.c @@ -3,7 +3,6 @@ static fileheader_t *headers = NULL; static int last_line; // PTT: last_line 游標可指的最後一個 -static int hit_thread; #include <sys/mman.h> @@ -95,7 +94,7 @@ AskTag(char *msg) num = TagNum; snprintf(buf, sizeof(buf), "◆ %s A)文章 T)標記 Q)uit?", msg); - switch (rget(b_lines - 1, buf)) { + switch (getans(buf)) { case 'q': num = -1; break; @@ -172,7 +171,7 @@ TagPruner(int bid) if (getans("刪除所有標記[N]?") != 'y') return READ_REDRAW; #ifdef SAFE_ARTICLE_DELETE - if(bp && bp->nuser>20) + if(bp && !(currmode & MODE_DIGEST) && bp->nuser>20 ) safe_delete_range(currdirect, 0, 0); else #endif @@ -230,182 +229,77 @@ fixkeep(char *s, int first) /* calc cursor pos and show cursor correctly */ static int -cursor_pos(keeploc_t * locmem, int val, int from_top) +cursor_pos(keeploc_t * locmem, int val, int from_top, int isshow) { int top=locmem->top_ln; - if (!last_line) - { - cursor_show(3 , 0); - return DONOTHING; - } - if (val > last_line) { - bell(); + if (!last_line){ + cursor_show(3 , 0); + return DONOTHING; + } + if (val > last_line){ + bell(); val = last_line; } - if (val <= 0) { - bell(); + if (val <= 0){ + bell(); val = 1; } if (val >= top && val < top + p_lines) { - cursor_clear(3 + locmem->crs_ln - top, 0); + if(isshow){ + cursor_clear(3 + locmem->crs_ln - top, 0); + cursor_show(3 + val - top, 0); + } locmem->crs_ln = val; - cursor_show(3 + val - top, 0); return DONOTHING; } locmem->top_ln = val - from_top; if (locmem->top_ln <= 0) locmem->top_ln = 1; locmem->crs_ln = val; - return PARTUPDATE; + return isshow ? PARTUPDATE : HEADERS_RELOAD; } - static int -thread(keeploc_t * locmem, int stype, int *new_ln) +thread(keeploc_t * locmem, int stypen) { - static char a_ans[32], t_ans[32]; - char ans[32], s_pmt[64]; - register char *tag, *query = NULL; - register int now, pos, match, near = 0; - fileheader_t fh; - int circulate_flag = 1; /* circulate at end or begin */ - int fd = -1; - - match = hit_thread = 0; - now = pos = locmem->crs_ln; - if (stype == 'A') { - if (!*currowner) - return DONOTHING; - str_lower(a_ans, currowner); - query = a_ans; - circulate_flag = 0; - stype = 0; - } else if (stype == 'a') { - if (!*currowner) - return DONOTHING; - str_lower(a_ans, currowner); - query = a_ans; - circulate_flag = 0; - stype = RS_FORWARD; - } else if (stype == '/') { - if (!*t_ans) - return DONOTHING; - query = t_ans; - circulate_flag = 0; - stype = RS_TITLE | RS_FORWARD; - } else if (stype == '?') { - if (!*t_ans) - return DONOTHING; - circulate_flag = 0; - query = t_ans; - stype = RS_TITLE; - } else if (stype & RS_RELATED) { - tag = headers[pos - locmem->top_ln].title; - if (stype & RS_CURRENT) { - if (stype & RS_FIRST) { - if (!strncmp(currtitle, tag, TTLEN)) - return DONOTHING; - near = 0; + fileheader_t fh; + int pos = locmem->crs_ln, jump = 200, new_ln; + int fd = -1, step = stypen & RS_FORWARD ? 1 : -1; + char *key = + (stypen & RS_AUTHOR ? headers[pos - locmem->top_ln].owner : + (subject( stypen & RS_CURRENT ? + currtitle : + headers[pos - locmem->top_ln].title ))); + + for(new_ln = pos + step ; + new_ln > 0 && new_ln <= last_line && --jump>0; + new_ln += step) { + get_record_keep(currdirect, &fh, sizeof(fileheader_t), new_ln, &fd); + if(stypen & RS_TITLE){ + if(stypen & RS_FIRST) { + if(!strcmp(fh.title, key)) break; } - query = currtitle; - } else { - query = subject(tag); - if (stype & RS_FIRST) { - if (query == tag) - return DONOTHING; - near = 0; - } - } - } else if (!(stype & RS_THREAD)) { - query = (stype & RS_TITLE) ? t_ans : a_ans; - if (!*query && query == a_ans) { - if (*currowner) - strlcpy(a_ans, currowner, sizeof(a_ans)); - else if (*currauthor) - strlcpy(a_ans, currauthor, sizeof(a_ans)); - } - snprintf(s_pmt, sizeof(s_pmt), - "%s搜尋%s [%s] ", (stype & RS_FORWARD) ? "往後" : "往前", - (stype & RS_TITLE) ? "標題" : "作者", query); - getdata(b_lines - 1, 0, s_pmt, ans, sizeof(ans), DOECHO); - if (*ans) - strcpy(query, ans); - else if (*query == '\0') - return DONOTHING; - } - tag = fh.owner; - - do { - if (!circulate_flag || stype & RS_RELATED) { - if (stype & RS_FORWARD) { - if (++now > last_line){ - if( fd != -1 ) - close(fd); - return DONOTHING; - } - } else { - if (--now <= 0 || now < pos - 200) { - if( fd ) - close(fd); - if ((stype & RS_FIRST) && (near)) { - hit_thread = 1; - *new_ln = near; - } - return DONOTHING; - } - } - } else { - if (stype & RS_FORWARD) { - if (++now > last_line) - now = 1; - } else if (--now <= 0) - now = last_line; + else + if(!strcmp(subject(fh.title), key)) break; } - - get_record_keep(currdirect, &fh, sizeof(fileheader_t), now, &fd); - - if (fh.owner[0] == '-') - continue; - - if (stype & RS_THREAD) { - if (strncasecmp(fh.title, str_reply, 3)) { - hit_thread = 1; - if( fd ) - close(fd); - *new_ln = now; - return DONOTHING; - } - continue; + else if(stypen & RS_NEWPOST){ + if(strncmp(fh.title,"Re:",3)) break; } - if (stype & RS_TITLE) - tag = subject(fh.title); - - if (((stype & RS_RELATED) && !strncmp(tag, query, 40)) || - (!(stype & RS_RELATED) && ((query == currowner) ? - !strcmp(tag, query) : - strstr_lower(tag, query)))) { - if ((stype & RS_FIRST) && tag != fh.title) { - near = now; - continue; - } - hit_thread = 1; - *new_ln = now; - if ((!(stype & RS_CURRENT)) && - (stype & RS_RELATED) && - strncmp(currtitle, query, TTLEN)) { - strncpy(currtitle, query, TTLEN); - match = PARTUPDATE; - } - break; + else{ // RS_AUTHOR + if(!strcmp(subject(fh.owner), key)) break; } - } while (now != pos); - + } if( fd != -1 ) close(fd); - return match; + if( jump <=0 || new_ln<=0 || new_ln > last_line ) + new_ln = pos; //didn't find + else{ + strncpy(currtitle, fh.title, TTLEN); + strncpy(currtitle, fh.title, TTLEN); + } + return new_ln; } - #ifdef INTERNET_EMAIL static void mail_forward(fileheader_t * fhdr, char *direct, int mode) @@ -419,19 +313,17 @@ mail_forward(fileheader_t * fhdr, char *direct, int mode) *p = '\0'; switch (i = doforward(buf, fhdr, mode)) { case 0: - outmsg(msg_fwd_ok); + vmsg(msg_fwd_ok); break; case -1: - outmsg(msg_fwd_err1); + vmsg(msg_fwd_err1); break; case -2: - outmsg(msg_fwd_err2); + vmsg(msg_fwd_err2); break; default: break; } - refresh(); - sleep(1); } #endif @@ -439,301 +331,297 @@ static int select_read(keeploc_t * locmem, int sr_mode) { #define READSIZE 64 // 8192 / sizeof(fileheader_t) - char *tag, *query = NULL, *temp; - fileheader_t fhs[READSIZE]; - char fpath[80], genbuf[MAXPATHLEN], buf3[5]; - static char t_ans[TTLEN + 1] = ""; - static char a_ans[TTLEN + 1] = ""; - int fd, fr, size = sizeof(fileheader_t), i, len; - struct stat st; - /* rocker.011018: make a reference number for process article */ - int reference = 0; - - if ((currmode & MODE_SELECT)) - return -1; - if (sr_mode == RS_TITLE) - query = subject(headers[locmem->crs_ln - locmem->top_ln].title); - else if (sr_mode == RS_NEWPOST) { - strlcpy(buf3, "Re: ", sizeof(buf3)); - query = buf3; - } - else if (sr_mode == RS_THREAD) { - - } else { - char buff[80]; - char newdata[35]; - - query = (sr_mode == RS_RELATED) ? t_ans : a_ans; - snprintf(buff, sizeof(buff), "搜尋%s [%s] ", - (sr_mode == RS_RELATED) ? "標題" : "作者", query); - getdata(b_lines, 0, buff, newdata, sizeof(newdata), DOECHO); - if (newdata[0]) - strcpy(query, newdata); - if (!(*query)) - return DONOTHING; + fileheader_t fhs[READSIZE]; + char newdirect[MAXPATHLEN]; + char keyword[TTLEN + 1] = ""; + char genbuf[MAXPATHLEN], *p = strstr(currdirect, "SR"); + static int _mode = 0; + int len, fd, fr, i, count=0, reference = 0; + + fileheader_t *fh = &headers[locmem->crs_ln - locmem->top_ln]; + if(sr_mode & RS_AUTHOR) + { + if(!getdata(b_lines, 0, + currmode & MODE_SELECT ? "增加條件 作者:":"搜尋作者:", + keyword, IDLEN+1, LCECHO)) + return READ_REDRAW; + } + else if(sr_mode & RS_KEYWORD) + { + if(!getdata(b_lines, 0, + currmode & MODE_SELECT ? "增加條件 標題:":"搜尋標題:", + keyword, TTLEN, DOECHO)) + return READ_REDRAW; +#ifdef KEYWORD_LOG + log_file("keyword_search_log", LOG_CREAT | LOG_VF, + "%s:%s\n", currboard, keyword); +#endif + } + else + { + if(p && _mode & sr_mode & (RS_TITLE | RS_NEWPOST | RS_MARK)) + return DONOTHING; + // Ptt: only once for these modes. + if(sr_mode & RS_TITLE) + strcpy(keyword, subject(fh->title)); } - if ((fd = open(currdirect, O_RDONLY, 0)) != -1) { - snprintf(genbuf, sizeof(genbuf), "SR.%s", cuser.userid); - if (currstat == RMAIL) - sethomefile(fpath, cuser.userid, genbuf); - else - setbfile(fpath, currboard, genbuf); - if (((fr = open(fpath, O_WRONLY | O_CREAT | O_TRUNC, 0600)) != -1)) { - switch (sr_mode) { - case RS_TITLE: - while( (len = read(fd, fhs, sizeof(fhs))) > 0 ){ - len /= sizeof(fileheader_t); - for( i = 0 ; i < len ; ++i ){ - ++reference; - tag = subject(fhs[i].title); - if (!strncmp(tag, query, 40)) { - fhs[i].money = reference | FHR_REFERENCE; - write(fr, &fhs[i], size); - } - } - } - break; - case RS_RELATED: - while( (len = read(fd, fhs, sizeof(fhs))) > 0 ){ - len /= sizeof(fileheader_t); - for( i = 0 ; i < len ; ++i ){ - ++reference; - tag = fhs[i].title; - if (strcasestr(tag, query)) { - fhs[i].money = reference | FHR_REFERENCE; - write(fr, &fhs[i], size); - } - } - } - break; - case RS_NEWPOST: - while( (len = read(fd, fhs, sizeof(fhs))) > 0 ){ - len /= sizeof(fileheader_t); - for( i = 0 ; i < len ; ++i ){ - ++reference; - tag = fhs[i].title; - temp = strstr(tag, query); - if (temp == NULL || temp != tag) { - fhs[i].money = reference | FHR_REFERENCE; - write(fr, &fhs[i], size); - } - } - } - break; - case RS_AUTHOR: - while( (len = read(fd, fhs, sizeof(fhs))) > 0 ){ - len /= sizeof(fileheader_t); - for( i = 0 ; i < len ; ++i ){ - ++reference; - tag = fhs[i].owner; - if (strcasestr(tag, query)) { - fhs[i].money = reference | FHR_REFERENCE; - write(fr, &fhs[i], size); - } - } - } - break; - case RS_THREAD: - while( (len = read(fd, fhs, sizeof(fhs))) > 0 ){ - len /= sizeof(fileheader_t); - for( i = 0 ; i < len ; ++i ){ - ++reference; - if (fhs[i].filemode & FILE_MARKED) { - fhs[i].money = reference | FHR_REFERENCE; - write(fr, &fhs[i], size); - } - } - } - break; - } - fstat(fr, &st); - close(fr); - } - close(fd); - if (st.st_size) { - currmode |= MODE_SELECT; - strlcpy(currdirect, fpath, sizeof(currdirect)); - } - } - return READ_REDRAW; + if(p == NULL) + _mode = sr_mode; + else + _mode |= sr_mode; + + snprintf(genbuf, sizeof(genbuf), "%s.%X.%X.%X", + p ? p : "SR", + sr_mode, strlen(keyword), StringHash(keyword)); + if( strlen(genbuf) > MAXPATHLEN - 50 ) + return READ_REDRAW; // avoid overflow + + if (currstat == RMAIL) + sethomefile(newdirect, cuser.userid, genbuf); + else + setbfile(newdirect, currboard, genbuf); + + if( now - dasht(newdirect) < 3600 ) + count = dashs(newdirect); + else { + if( (fd = open(newdirect, O_CREAT | O_RDWR, 0600)) == -1 ) + return READ_REDRAW; + if( (fr = open(currdirect, O_RDONLY, 0)) != -1 ) { + while( (len = read(fr, fhs, sizeof(fhs))) > 0 ){ + len /= sizeof(fileheader_t); + for( i = 0 ; i < len ; ++i ){ + reference++; + if( sr_mode & RS_MARK && + !(fhs[i].filemode & FILE_MARKED) ) + continue; + else if(sr_mode & RS_NEWPOST && + !strncmp(fhs[i].title, "Re:", 3)) + continue; + else if(sr_mode & RS_AUTHOR && + !strcasestr(fhs[i].owner, keyword)) + continue; + else if(sr_mode & RS_KEYWORD && + !strcasestr(fhs[i].title, keyword)) + continue; + else if(sr_mode & RS_TITLE && + strcmp(subject(fhs[i].title), keyword)) + continue; + ++count; + if(p == NULL) + fhs[i].money = reference | FHR_REFERENCE; + write(fd, &fhs[i], sizeof(fileheader_t)); + } + } // end while + close(fr); + } + close(fd); + } + + if(count) { + strlcpy(currdirect, newdirect, sizeof(currdirect)); + currmode |= MODE_SELECT; + return NEWDIRECT; + } + return READ_REDRAW; } -#define select_read_mode(m) select_read(locmem, m) ? NEWDIRECT:READ_REDRAW static int -i_read_key(onekey_t * rcmdlist, char default_ch, keeploc_t * locmem, +i_read_key(onekey_t * rcmdlist, keeploc_t * locmem, int bid, int bottom_line) { - int mode = DONOTHING; - int num; - char direct[60]; - int ch, new_ln= locmem->crs_ln; + int mode = DONOTHING, num, new_top=10; + int ch, new_ln = locmem->crs_ln, lastmode=0; + char direct[60]; + static char default_ch = 0; do { - if(default_ch) - { - ch = default_ch; - default_ch=0; - } - else - { - if((mode=cursor_pos(locmem, new_ln, 10))!=DONOTHING) - return mode; - ch = egetch(); - } - switch (ch) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - if((num = search_num(ch, last_line))!=-1) - new_ln = num; - break; + if( (mode = cursor_pos(locmem, new_ln, new_top, default_ch ? 0 : 1)) + != DONOTHING ) + return mode; + + if( !default_ch ) + ch = igetch(); + else{ + if(new_ln != locmem->crs_ln) {// move fault + default_ch=0; + return FULLUPDATE; + } + ch = default_ch; + } + + new_top = 10; // default 10 + switch (ch) { + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + if( (num = search_num(ch, last_line)) != -1 ) + new_ln = num + 1; + break; case 'q': case 'e': case KEY_LEFT: - if(currmode & MODE_SELECT){ - char genbuf[256]; - fileheader_t *fhdr = &headers[locmem->crs_ln - locmem->top_ln]; - board_select(); - setbdir(genbuf, currboard); - locmem = getkeep(genbuf, 0, 1); - locmem->crs_ln = - getindex(genbuf, fhdr->filename, sizeof(fileheader_t)); - num = locmem->crs_ln - p_lines + 1; - locmem->top_ln = num < 1 ? 1 : num; - - return NEWDIRECT; - } - return (currmode & MODE_ETC) ? board_etc() : - (currmode & MODE_DIGEST) ? board_digest() : DOQUIT; - case Ctrl('L'): - redoscr(); - break; + if(currmode & MODE_SELECT){ + char genbuf[256]; + fileheader_t *fhdr = &headers[locmem->crs_ln - locmem->top_ln]; + board_select(); + setbdir(genbuf, currboard); + locmem = getkeep(genbuf, 0, 1); + locmem->crs_ln = fhdr->money & ~FHR_REFERENCE; + num = locmem->crs_ln - p_lines + 1; + locmem->top_ln = num < 1 ? 1 : num; + mode = NEWDIRECT; + } + else + mode = + (currmode & MODE_DIGEST) ? board_digest() : DOQUIT; + break; + case Ctrl('L'): + redoscr(); + break; - case Ctrl('H'): - mode = select_read_mode(RS_NEWPOST); + case Ctrl('H'): + mode = select_read(locmem, RS_NEWPOST); break; - case 'a': - case 'A': - mode = select_read_mode(RS_AUTHOR); - break; - case 'G': - mode = select_read_mode(RS_THREAD); - break; - case '/': - case '?': - mode = select_read_mode(RS_RELATED); - break; - case 'S': - mode = select_read_mode(RS_TITLE); - break; - case '=': - mode = thread(locmem, RELATE_FIRST, &new_ln); - break; - case '\\': - mode = thread(locmem, CURSOR_FIRST, &new_ln); - break; - case ']': - mode = thread(locmem, RELATE_NEXT, &new_ln); - break; - case '+': - mode = thread(locmem, CURSOR_NEXT, &new_ln); - break; - case '[': - mode = thread(locmem, RELATE_PREV, &new_ln); - break; - case '-': - mode = thread(locmem, CURSOR_PREV, &new_ln); - break; + + case 'a': + case 'A': + mode = select_read(locmem, RS_AUTHOR); + break; + + case 'G': + mode = select_read(locmem, RS_MARK); + break; + + case '/': + case '?': + mode = select_read(locmem, RS_KEYWORD); + break; + + case 'S': + mode = select_read(locmem, RS_TITLE); + break; + + case '=': + new_ln = thread(locmem, RELATE_FIRST); + break; + + case '\\': + new_ln = thread(locmem, CURSOR_FIRST); + break; + + case ']': + new_ln = thread(locmem, RELATE_NEXT); + break; + + case '+': + new_ln = thread(locmem, CURSOR_NEXT); + break; + + case '[': + new_ln = thread(locmem, RELATE_PREV); + break; + + case '-': + new_ln = thread(locmem, CURSOR_PREV); + break; + case '<': case ',': - mode = thread(locmem, THREAD_PREV, &new_ln); - break; + new_ln = thread(locmem, NEWPOST_PREV); + break; + case '.': case '>': - mode = thread(locmem, THREAD_NEXT, &new_ln); - break; + new_ln = thread(locmem, NEWPOST_NEXT); + break; + case 'p': case 'k': - case KEY_UP: - new_ln = locmem->crs_ln - 1; - break; - case 'n': - case 'j': - case KEY_DOWN: - new_ln = locmem->crs_ln + 1; - break; - case ' ': - case KEY_PGDN: - case 'N': - case Ctrl('F'): - new_ln = locmem->crs_ln + p_lines; - break; - case KEY_PGUP: - case Ctrl('B'): - case 'P': - new_ln = locmem->crs_ln - p_lines; - break; - case KEY_END: - case '$': - new_ln = last_line; - break; - case 'F': - case 'U': - if (HAS_PERM(PERM_FORWARD)) { - mail_forward(&headers[locmem->crs_ln - locmem->top_ln], - currdirect, ch /* == 'U' */ ); - /* by CharlieL */ - mode = READ_REDRAW; - } - break; - case Ctrl('Q'): - mode = my_query(headers[locmem->crs_ln - locmem->top_ln].owner); - case Ctrl('S'): - if (HAS_PERM(PERM_ACCOUNTS)) { - int id; - userec_t muser; - - strlcpy(currauthor, - headers[locmem->crs_ln - locmem->top_ln].owner, - sizeof(currauthor)); - stand_title("使用者設定"); - move(1, 0); - if ((id = getuser(headers[locmem->crs_ln - locmem->top_ln].owner))) - { - memcpy(&muser, &xuser, sizeof(muser)); - user_display(&muser, 1); - uinfo_query(&muser, 1, id); + case KEY_UP: + new_ln = locmem->crs_ln - 1; + new_top = p_lines - 2; + break; + + case 'n': + case 'j': + case KEY_DOWN: + new_ln = locmem->crs_ln + 1; + new_top = 1; + break; + + case ' ': + case KEY_PGDN: + case 'N': + case Ctrl('F'): + new_ln = locmem->top_ln + p_lines; + new_top = 0; + break; + + case KEY_PGUP: + case Ctrl('B'): + case 'P': + new_ln = locmem->top_ln - p_lines; + new_top = 0; + break; + + case KEY_END: + case '$': + new_ln = last_line; + new_top = p_lines-1; + break; + + case 'F': + case 'U': + if (HAS_PERM(PERM_FORWARD)) { + mail_forward(&headers[locmem->crs_ln - locmem->top_ln], + currdirect, ch /* == 'U' */ ); + /* by CharlieL */ + mode = READ_REDRAW; } - mode = FULLUPDATE; - } - break; + break; + + case Ctrl('Q'): + mode = my_query(headers[locmem->crs_ln - locmem->top_ln].owner); + break; - /* rocker.011018: 採用新的tag模式 */ - case 't': - /* 將原本在 Read() 裡面的 "TagNum = 0" 移至此處 */ - if ((currstat & RMAIL && TagBoard != 0) || + case Ctrl('S'): + if (HAS_PERM(PERM_ACCOUNTS)) { + int id; + userec_t muser; + + strlcpy(currauthor, + headers[locmem->crs_ln - locmem->top_ln].owner, + sizeof(currauthor)); + stand_title("使用者設定"); + move(1, 0); + if ((id = getuser(headers[locmem->crs_ln - locmem->top_ln].owner))) { + memcpy(&muser, &xuser, sizeof(muser)); + user_display(&muser, 1); + uinfo_query(&muser, 1, id); + } + mode = FULLUPDATE; + } + break; + + /* rocker.011018: 採用新的tag模式 */ + case 't': + /* 將原本在 Read() 裡面的 "TagNum = 0" 移至此處 */ + if ((currstat & RMAIL && TagBoard != 0) || (!(currstat & RMAIL) && TagBoard != bid)) { - if (currstat & RMAIL) - TagBoard = 0; - else - TagBoard = bid; - TagNum = 0; - } - /* rocker.011112: 解決再select mode標記文章的問題 */ - if (Tagger(atoi(headers[locmem->crs_ln - locmem->top_ln].filename + 2), - (currmode & MODE_SELECT) ? - (headers[locmem->crs_ln - locmem->top_ln].money & ~FHR_REFERENCE) : - locmem->crs_ln, TAG_TOGGLE)) - new_ln = locmem->crs_ln + 1; - break; + if (currstat & RMAIL) + TagBoard = 0; + else + TagBoard = bid; + TagNum = 0; + } + /* rocker.011112: 解決再select mode標記文章的問題 */ + if (Tagger(atoi(headers[locmem->crs_ln - locmem->top_ln].filename + 2), + (currmode & MODE_SELECT) ? + (headers[locmem->crs_ln - locmem->top_ln].money & ~FHR_REFERENCE) : + locmem->crs_ln, TAG_TOGGLE)) + locmem->crs_ln = locmem->crs_ln + 1; + mode = PART_REDRAW; + break; case Ctrl('C'): if (TagNum) { @@ -745,38 +633,82 @@ i_read_key(onekey_t * rcmdlist, char default_ch, keeploc_t * locmem, case Ctrl('T'): mode = TagThread(currdirect); break; + case Ctrl('D'): mode = TagPruner(bid); break; + case '\n': case '\r': case 'l': case KEY_RIGHT: ch = 'r'; default: - if( ch == 'h' && currmode & (MODE_ETC | MODE_DIGEST) ) + if( ch == 'h' && currmode & (MODE_DIGEST) ) break; if (ch > 0 && ch <= onekey_size) { int (*func)() = rcmdlist[ch - 1]; - if (func != NULL) - { - num = locmem->crs_ln - bottom_line; + if (func != NULL){ + num = locmem->crs_ln - bottom_line; - if (num>0) - { + if( num > 0 ){ sprintf(direct,"%s.bottom", currdirect); - mode= (*func)(num, &headers[locmem->crs_ln-locmem->top_ln], - direct); - } - else + mode= (*func)(num, &headers[locmem->crs_ln-locmem->top_ln], + direct); + } + else mode = (*func)(locmem->crs_ln, - &headers[locmem->crs_ln - locmem->top_ln], currdirect); - } - } + &headers[locmem->crs_ln - locmem->top_ln], + currdirect); + if(mode == READ_SKIP) + mode = lastmode; + + // 以下這幾種 mode 要再處理游標 + if(mode == READ_PREV || mode == READ_NEXT || + mode == RELATE_PREV || mode == RELATE_FIRST || + mode == AUTHOR_NEXT || mode == AUTHOR_PREV || + mode == RELATE_NEXT){ + lastmode = mode; + + switch(mode){ + case READ_PREV: + new_ln = locmem->crs_ln - 1; + break; + case READ_NEXT: + new_ln = locmem->crs_ln + 1; + break; + case RELATE_PREV: + new_ln = thread(locmem, RELATE_PREV); + break; + case RELATE_NEXT: + new_ln = thread(locmem, RELATE_NEXT); + /* XXX: 讀到最後一篇要跳出來 */ + if( new_ln == locmem->crs_ln ){ + default_ch = 0; + return FULLUPDATE; + } + break; + case RELATE_FIRST: + new_ln = thread(locmem, RELATE_FIRST); + break; + case AUTHOR_PREV: + new_ln = thread(locmem, AUTHOR_PREV); + break; + case AUTHOR_NEXT: + new_ln = thread(locmem, AUTHOR_NEXT); + break; + } + mode = DONOTHING; default_ch = 'r'; + } + else { + default_ch = 0; + lastmode = 0; + } + } //end if (func != NULL) + } // ch > 0 && ch <= onekey_size break; - } // end switch - } - while (mode == DONOTHING); + } // end switch + } while (mode == DONOTHING); return mode; } @@ -784,37 +716,39 @@ int get_records_and_bottom(char *direct, fileheader_t* headers, int recbase, int p_lines, int last_line, int bottom_line) { - int n = bottom_line - recbase + 1, rv; - char directbottom[60]; + int n = bottom_line - recbase + 1, rv; + char directbottom[60]; - if(!last_line) return 0; - if(n>=p_lines || (currmode & (MODE_SELECT | MODE_DIGEST))) - return get_records(direct, headers, sizeof(fileheader_t), recbase, - p_lines); + if( !last_line ) + return 0; + if( n >= p_lines || (currmode & (MODE_SELECT | MODE_DIGEST)) ) + return get_records(direct, headers, sizeof(fileheader_t), recbase, + p_lines); sprintf(directbottom, "%s.bottom", direct); - if (n<=0) - return get_records(directbottom, headers, sizeof(fileheader_t), 1-n, - last_line-recbase + 1); + if( n <= 0 ) + return get_records(directbottom, headers, sizeof(fileheader_t), 1-n, + last_line-recbase + 1); - rv = get_records(direct, headers, sizeof(fileheader_t), recbase, n); + rv = get_records(direct, headers, sizeof(fileheader_t), recbase, n); + + if( bottom_line < last_line ) + rv += get_records(directbottom, headers+n, sizeof(fileheader_t), 1, + p_lines - n ); + return rv; +} - if(bottom_line<last_line) - rv += get_records(directbottom, headers+n, sizeof(fileheader_t), 1, - p_lines - n ); - return rv; -} void -i_read(int cmdmode, char *direct, void (*dotitle) (), void (*doentry) (), onekey_t * rcmdlist, int bidcache) +i_read(int cmdmode, char *direct, void (*dotitle) (), + void (*doentry) (), onekey_t * rcmdlist, int bidcache) { keeploc_t *locmem = NULL; int recbase = 0, mode; int num = 0, entries = 0, n_bottom=0; int i; - char currdirect0[64], default_ch = 0; + char currdirect0[64]; int last_line0 = last_line; int bottom_line = 0; - int hit_thread0 = hit_thread; fileheader_t *headers0 = headers; strlcpy(currdirect0, currdirect, sizeof(currdirect0)); @@ -853,11 +787,10 @@ i_read(int cmdmode, char *direct, void (*dotitle) (), void (*doentry) (), onekey case PARTUPDATE: if (last_line < locmem->top_ln + p_lines) { - if (bidcache > 0 && !(currmode & (MODE_SELECT | MODE_DIGEST))) - { - bottom_line = getbtotal(currbid); - num = bottom_line+getbottomtotal(currbid); - } + if (bidcache > 0 && !(currmode & (MODE_SELECT | MODE_DIGEST))){ + bottom_line = getbtotal(currbid); + num = bottom_line+getbottomtotal(currbid); + } else num = get_num_records(currdirect, FHSZ); @@ -866,7 +799,7 @@ i_read(int cmdmode, char *direct, void (*dotitle) (), void (*doentry) (), onekey recbase = -1; } } - if (recbase != locmem->top_ln) { + if (recbase != locmem->top_ln) { //headers reload recbase = locmem->top_ln; if (recbase > last_line) { recbase = last_line - p_lines + 1; @@ -883,11 +816,11 @@ i_read(int cmdmode, char *direct, void (*dotitle) (), void (*doentry) (), onekey clrtobot(); case PART_REDRAW: move(3, 0); - if(last_line==0) + if( last_line == 0 ) outs(" 沒有文章..."); else - for (i = 0; i < entries; i++) - (*doentry) (locmem->top_ln + i, &headers[i]); + for( i = 0; i < entries ; i++ ) + (*doentry) (locmem->top_ln + i, &headers[i]); case READ_REDRAW: outmsg(curredit & EDIT_ITEM ? "\033[44m 私人收藏 \033[30;47m 繼續? \033[m" : @@ -895,50 +828,29 @@ i_read(int cmdmode, char *direct, void (*dotitle) (), void (*doentry) (), onekey break; case TITLE_REDRAW: (*dotitle) (); - break; - } - - mode = i_read_key(rcmdlist, default_ch, locmem, currbid, - bottom_line); - switch(mode) // 以下這幾種 mode 要再處理游標 - { - case READ_PREV: - default_ch = 'r'; - mode = cursor_pos(locmem, locmem->crs_ln - 1, 10); - break; - case READ_NEXT: - default_ch = 'r'; - mode = cursor_pos(locmem, locmem->crs_ln + 1, 10); - break; - case RELATE_PREV: - default_ch = 'r'; - mode = thread(locmem, RELATE_PREV, &locmem->crs_ln); - break; - case RELATE_NEXT: - default_ch = 'r'; - mode = thread(locmem, RELATE_NEXT, &locmem->crs_ln); - break; - case RELATE_FIRST: - default_ch = 'r'; - mode = thread(locmem, RELATE_FIRST, &locmem->crs_ln); - break; - case 'A': - default_ch = 'r'; - mode = thread(locmem, 'A', &locmem->crs_ln); - break; - case 'a': - default_ch = 'r'; - mode = thread(locmem, 'a', &locmem->crs_ln); - break; - default: - default_ch=0; - } + break; + + case HEADERS_RELOAD: + if (recbase != locmem->top_ln) { + recbase = locmem->top_ln; + if (recbase > last_line) { + recbase = last_line - p_lines + 1; + if (recbase < 1) + recbase = 1; + locmem->top_ln = recbase; + } + entries = + get_records_and_bottom(currdirect, headers, recbase, + p_lines, last_line, bottom_line); + } + break; + } //end switch + mode = i_read_key(rcmdlist, locmem, currbid, bottom_line); } while (mode != DOQUIT); #undef FHSZ free(headers); last_line = last_line0; - hit_thread = hit_thread0; headers = headers0; strlcpy(currdirect, currdirect0, sizeof(currdirect)); return; diff --git a/mbbsd/record.c b/mbbsd/record.c index efc1089c..c8393f6f 100644 --- a/mbbsd/record.c +++ b/mbbsd/record.c @@ -127,6 +127,66 @@ substitute_record(char *fpath, void *rptr, int size, int id) return 0; } +int +substitute_ref_record(char *direct, fileheader_t * fhdr, int ent) +{ + fileheader_t hdr; + char genbuf[256]; + int num = 0; + + /* rocker.011018: 串接模式用reference增進效率 */ + if ((fhdr->money & FHR_REFERENCE) && + (num = fhdr->money & ~FHR_REFERENCE)){ + setdirpath(genbuf, direct, ".DIR"); + get_record(genbuf, &hdr, sizeof(hdr), num); + if (strcmp(hdr.filename, fhdr->filename)) + { + if((num = getindex(genbuf, fhdr, num))>0) + { + substitute_record(genbuf, fhdr, sizeof(*fhdr), num); + } + } + else if(num>0) + { + fhdr->money = hdr.money; + substitute_record(genbuf, fhdr, sizeof(*fhdr), num); + } + fhdr->money = FHR_REFERENCE | num ; // Ptt: update now! + } + substitute_record(direct, fhdr, sizeof(*fhdr), ent); + return num; +} + +int +getindex(char *direct, fileheader_t *fh_o, int end) +{ // Ptt: 從前面找很費力 太暴力 + int fd=-1, begin=1, i, stamp, s; + fileheader_t fh; + + i = get_num_records(direct, sizeof(fileheader_t)); + if(end>i) end = i; + stamp = atoi(fh_o->filename+2); + i=(begin+end)/2; + for(; end>begin+1; i=(begin+end)/2) + { + if(get_record_keep(direct, &fh, sizeof(fileheader_t), i, &fd)==-1) + break; + if(!fh.filename[0]) break; + s = atoi(fh.filename+2); + if (s > stamp) end = i+1; + else if(s == stamp) + { + close(fd); + fh_o->money = fh.money; + return i; + } + else begin = i; + } + if(fd==-1) close(fd); + return 0; +} + + /* rocker.011022: 避免lock檔開啟時不正常斷線,造成永久lock */ #ifndef _BBS_UTIL_C_ static int diff --git a/mbbsd/register.c b/mbbsd/register.c index 9e6c60b3..71d653a2 100644 --- a/mbbsd/register.c +++ b/mbbsd/register.c @@ -175,9 +175,7 @@ getnewuserid() i = searchnewuser(1); if ((i <= 0) || (i > MAX_USERS)) { passwd_unlock(); - if (more("etc/user_full", NA) == -1) - fprintf(stdout, "抱歉,使用者帳號已經滿了,無法註冊新的帳號\n\r"); - safe_sleep(2); + vmsg("抱歉,使用者帳號已經滿了,無法註冊新的帳號"); exit(1); } snprintf(genbuf, sizeof(genbuf), "uid %d", i); @@ -203,10 +201,7 @@ new_register() if( passbuf[0] == 'y' ) break; if( passbuf[0] == 'n' ){ - clear(); - outs("\n抱歉, 您須要接受使用者條款才能註冊帳號享受我們的服務唷!"); - pressanykey(); - oflush(); + vmsg("\n抱歉, 您須要接受使用者條款才能註冊帳號享受我們的服務唷!"); exit(1); } vmsg("請輸入 y表示接受, n表示不接受"); @@ -217,11 +212,7 @@ new_register() try = 0; while (1) { if (++try >= 6) { - outs("\n您嘗試錯誤的輸入太多,請下次再來吧\n"); - refresh(); - - pressanykey(); - oflush(); + vmsg("\n您嘗試錯誤的輸入太多,請下次再來吧\n"); exit(1); } getdata(17, 0, msg_uid, newuser.userid, @@ -243,11 +234,7 @@ new_register() try = 0; while (1) { if (++try >= 6) { - outs("\n您嘗試錯誤的輸入太多,請下次再來吧\n"); - refresh(); - - pressanykey(); - oflush(); + vmsg("\n您嘗試錯誤的輸入太多,請下次再來吧\n"); exit(1); } if ((getdata(19, 0, "請設定密碼:", passbuf, diff --git a/mbbsd/screen.c b/mbbsd/screen.c index 94a42d60..04dcec40 100644 --- a/mbbsd/screen.c +++ b/mbbsd/screen.c @@ -445,7 +445,7 @@ prints(char *fmt,...) } void -mprints(int y, int x, char *str) +mouts(int y, int x, char *str) { move(y, x); clrtoeol(); diff --git a/mbbsd/stuff.c b/mbbsd/stuff.c index 7ce5e720..10e6d69b 100644 --- a/mbbsd/stuff.c +++ b/mbbsd/stuff.c @@ -64,7 +64,6 @@ void setbdir(char *buf, char *boardname) { sprintf(buf, str_board_file, boardname[0], boardname, - currmode & MODE_ETC ? ".ETC" : (currmode & MODE_DIGEST ? fn_mandex : str_dotdir)); } @@ -401,25 +400,28 @@ capture_screen() } } -void -pressanykey() +int +vmsg_lines(const int lines, const char msg[]) { int ch; - outmsg("\033[37;45;1m " - "● 請按 \033[33m(Space/Return)\033[37m 繼續 ●" - " \033[33m(^T)\033[37m 存暫存檔 \033[m"); - do { - ch = igetkey(); + move(lines, 0); + clrtoeol(); - if (ch == Ctrl('T')) { + if (msg) + outs((char *)msg); + else + outs("\033[45;1m \033[37m" + "\033[200m\033[1431m\033[506m□ 請按 \033[33m(Space/Return)\033[37m 繼續 □\033[201m (^T) 收到暫存檔 \033[m"); + + do { + if( (ch = igetch()) == Ctrl('T') ) capture_screen(); - break; - } - } while ((ch != ' ') && (ch != KEY_LEFT) && (ch != '\r') && (ch != '\n')); - move(b_lines, 0); + } while( ch == 0 ); + + move(lines, 0); clrtoeol(); - refresh(); + return ch; } #ifdef PLAY_ANGEL @@ -427,11 +429,14 @@ void pressanykey_or_callangel(){ int ch; - outmsg("\033[37;45;1m \033[33m(h)\033[37m 呼叫小天使 " + move(b_lines, 0); + clrtoeol(); + + outs("\033[37;45;1m \033[33m(h)\033[37m 呼叫小天使 " "● 請按 \033[33m(Space/Return)\033[37m 繼續 ●" " \033[33m(^T)\033[37m 存暫存檔 \033[m"); do { - ch = igetkey(); + ch = igetch(); if (ch == Ctrl('T')) { capture_screen(); @@ -443,47 +448,49 @@ pressanykey_or_callangel(){ } while ((ch != ' ') && (ch != KEY_LEFT) && (ch != '\r') && (ch != '\n')); move(b_lines, 0); clrtoeol(); - refresh(); } #endif -int -vmsg(const char *fmt,...) +char getans(const char *fmt,...) { - va_list ap; - char msg[80] = {0}; - int ch; - + char msg[256]; + char ans[5]; + va_list ap; va_start(ap, fmt); - vsnprintf(msg, sizeof(msg), fmt, ap); + vsnprintf(msg , 128, fmt, ap); va_end(ap); - move(b_lines, 0); - clrtoeol(); - - if (*msg) - prints("\033[1;36;44m ◆ %-55.54s \033[33;46m \033[200m\033[1431m\033[506m[請按任意鍵繼續]\033[201m \033[m", msg); - else - outs("\033[46;1m \033[37m" - "\033[200m\033[1431m\033[506m□ 請按 \033[33m(Space/Return)\033[37m 繼續 □\033[201m" - " \033[m"); - - do { - ch = igetkey(); - - if (ch == Ctrl('T')) { - capture_screen(); - break; - } - } while ((ch != ' ') && (ch != KEY_LEFT) && (ch != '\r') && (ch != '\n')); + getdata(b_lines, 0, msg, ans, sizeof(ans), LCECHO); + return ans[0]; +} +int +getkey(const char *fmt,...) +{ + char msg[256], i; + va_list ap; + va_start(ap, fmt); + i = vsnprintf(msg , 128, fmt, ap); + va_end(ap); + return vmsg_lines(b_lines, msg); +} - move(b_lines, 0); - clrtoeol(); - refresh(); - return ch; +int +vmsg(const char *fmt,...) +{ + char msg[256] = "\033[1;36;44m ◆ ", i; + va_list ap; + va_start(ap, fmt); + i = vsnprintf(msg + 14, 128, fmt, ap); + va_end(ap); + for(i = i + 14; i < 71; i++) + msg[(int)i] = ' '; + strcat(msg + 71, + "\033[33;46m \033[200m\033[1431m\033[506m[按任意鍵繼續]\033[201m \033[m"); + return vmsg_lines(b_lines, msg); } + void bell() { @@ -573,7 +580,7 @@ cursor_key(int row, int column) int ch; cursor_show(row, column); - ch = egetch(); + ch = igetch(); move(row, column); outs(STR_UNCUR); return ch; @@ -602,13 +609,41 @@ 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, LOG_CREAT | LOG_VF, + "%s: %s %s", cuser.userid, msg, Cdate(&now)); +} + +int log_file(char *fn, int flag, const char *fmt,...) { int fd; - if( (fd = open(fn, O_APPEND | O_WRONLY | (ifcreate ? O_CREAT : 0), - (ifcreate ? 0664 : 0))) < 0 ) + char msg[256]; + const char *realmsg; + if( !(flag & LOG_VF) ){ + realmsg = fmt; + } + else{ + va_list ap; + va_start(ap, fmt); + vsnprintf(msg , 128, fmt, ap); + va_end(ap); + realmsg = msg; + } + + if( (fd = open(fn, O_APPEND | O_WRONLY | ((flag & LOG_CREAT)? O_CREAT : 0), + ((flag & LOG_CREAT) ? 0664 : 0))) < 0 ) return -1; - if( write(fd, buf, strlen(buf)) < 0 ){ + if( write(fd, realmsg, strlen(realmsg)) < 0 ){ close(fd); return -1; } diff --git a/mbbsd/talk.c b/mbbsd/talk.c index 22535b9e..96181b4f 100644 --- a/mbbsd/talk.c +++ b/mbbsd/talk.c @@ -512,7 +512,7 @@ my_write2(void) which = 0; do { - switch ((ch = igetkey())) { + switch ((ch = igetch())) { case Ctrl('T'): case KEY_UP: if (water_usies != 1) { @@ -622,9 +622,7 @@ my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t * puin) */ if (!uin && !(flag == WATERBALL_GENERAL && water_which->count > 0)) { - outmsg("\033[1;33;41m糟糕! 對方已落跑了(不在站上)! \033[37m~>_<~\033[m"); - clrtoeol(); - refresh(); + vmsg("糟糕! 對方已落跑了(不在站上)! "); watermode = -1; return 0; } @@ -642,9 +640,6 @@ my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t * puin) /* 一般水球 */ watermode = 0; if (!(len = getdata(0, 0, prompt, msg, 56, DOECHO))) { - outmsg("\033[1;33;42m算了! 放你一馬...\033[m"); - clrtoeol(); - refresh(); currutmp->chatid[0] = c0; currutmp->mode = mode0; currstat = currstat0; @@ -674,9 +669,6 @@ my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t * puin) snprintf(buf, sizeof(buf), "丟給 %s : %s [Y/n]?", destid, msg); getdata(0, 0, buf, genbuf, 3, LCECHO); if (genbuf[0] == 'n') { - outmsg("\033[1;33;42m算了! 放你一馬...\033[m"); - clrtoeol(); - refresh(); currutmp->chatid[0] = c0; currutmp->mode = mode0; currstat = currstat0; @@ -690,9 +682,7 @@ my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t * puin) && flag != WATERBALL_ANSWER #endif )) { - outmsg("\033[1;33;41m糟糕! 對方已落跑了(不在站上)! \033[37m~>_<~\033[m"); - clrtoeol(); - refresh(); + vmsg("糟糕! 對方已落跑了(不在站上)! "); currutmp->chatid[0] = c0; currutmp->mode = mode0; currstat = currstat0; @@ -785,7 +775,6 @@ my_write(pid_t pid, char *prompt, char *id, int flag, userinfo_t * puin) } clrtoeol(); - refresh(); currutmp->chatid[0] = c0; currutmp->mode = mode0; @@ -1128,7 +1117,7 @@ do_talk(int fd) add_io(fd, 0); while (1) { - ch = igetkey(); + ch = igetch(); if (ch == I_OTHERDATA) { datac = recv(fd, data, sizeof(data), 0); if (datac <= 0) @@ -1926,7 +1915,7 @@ draw_pickup(int drawall, pickup_t * pickup, int pickup_way, #endif ); - refresh(); + //refresh(); } } @@ -2240,11 +2229,12 @@ userlist(void) case 'b': /* broadcast */ if (cuser.uflag & FRIEND_FLAG || HAS_PERM(PERM_SYSOP)) { - char genbuf[60]; + char genbuf[60]="[廣播]"; char ans[4]; - if (!getdata(0, 0, "廣播訊息:", genbuf, sizeof(genbuf), DOECHO)) + if (!getdata(0, 0, "廣播訊息:", genbuf+6, 54, DOECHO)) break; + if (getdata(0, 0, "確定廣播? [Y]", ans, sizeof(ans), LCECHO) && *ans == 'n') @@ -2386,7 +2376,7 @@ userlist(void) case 'g': if (HAS_PERM(PERM_LOGINOK) && strcmp(uentp->userid, cuser.userid) != 0) { - char genbuf[128]; + char genbuf[10]; move(b_lines - 2, 0); prints("要給 %s 多少錢呢? ", uentp->userid); if (getdata(b_lines - 1, 0, "[銀行轉帳]: ", @@ -2396,8 +2386,8 @@ userlist(void) redrawall = redraw = 1; break; } - sprintf(genbuf, "確定要給 %s %d Ptt 幣嗎? [N/y]", uentp->userid, ch); - if (getans(genbuf) != 'y'){ + if (getans("確定要給 %s %d Ptt 幣嗎? [N/y]", + uentp->userid, ch) != 'y'){ redrawall = redraw = 1; break; } @@ -2407,19 +2397,16 @@ userlist(void) outs("\033[41m 現金不足~~\033[m"); } else { deumoney(uentp->uid, ch - give_tax(ch)); - prints("\033[44m 嗯..還剩下 %d 錢.." - "\033[m", demoney(-ch)); - snprintf(genbuf, sizeof(genbuf), - "%s\t給%s\t%d\t%s\n", cuser.userid, - uentp->userid, ch, - ctime(&currutmp->lastact)); - log_file(FN_MONEY, genbuf, 1); + log_file(FN_MONEY, LOG_CREAT | LOG_VF, + "%s\t給%s\t%d\t%s\n", cuser.userid, + uentp->userid, ch, ctime(&currutmp->lastact)); mail_redenvelop(cuser.userid, uentp->userid, ch - give_tax(ch), 'Y'); + vmsg(" 嗯..還剩下 %d 錢..", demoney(-ch)); } } else { clrtoeol(); - outs("\033[41m 交易取消! \033[m"); + vmsg(" 交易取消! "); } redrawall = redraw = 1; } @@ -2476,12 +2463,9 @@ userlist(void) cuser.uflag2 -= tmp; tmp = (tmp + 1) % 3; cuser.uflag2 |= tmp; - move(4, 0); - prints("系統提供 一般 進階 未來 三種模式\n" + vmsg("系統提供 一般 進階 未來 三種模式\n" "在切換後請正常下線再重新登入, 以確保結構正確\n" "目前切換到 %s 水球模式\n", wm[tmp]); - refresh(); - sleep(2); redrawall = redraw = 1; } break; @@ -2695,7 +2679,6 @@ talkreply(void) char genbuf[200]; int a, sig = currutmp->sig; - talkrequest = NA; uip = &SHM->uinfo[currutmp->destuip]; snprintf(page_requestor, sizeof(page_requestor), "%s (%s)", uip->userid, uip->username); diff --git a/mbbsd/user.c b/mbbsd/user.c index 6b141c38..cbb85d1d 100644 --- a/mbbsd/user.c +++ b/mbbsd/user.c @@ -23,7 +23,6 @@ u_loginview() { int i; unsigned int pbits = cuser.loginview; - char choice[5]; clear(); move(4, 0); @@ -32,9 +31,9 @@ u_loginview() loginview_file[i][1], ((pbits >> i) & 1 ? "ˇ" : "X")); clrtobot(); - while (getdata(b_lines - 1, 0, "請按 [A-N] 切換設定,按 [Return] 結束:", - choice, 3, LCECHO)) { - i = choice[0] - 'a'; + while ((i = getkey("請按 [A-N] 切換設定,按 [Return] 結束:"))!='\r') + { + i = i - 'a'; if (i >= NUMVIEWFILE || i < 0) bell(); else { @@ -219,8 +218,9 @@ violate_law(userec_t * u, int unum) static void Customize(void) { - char ans[4], done = 0, mindbuf[5]; + char done = 0, mindbuf[5]; char *wm[3] = {"一般", "進階", "未來"}; + int key; showtitle("個人化設定", "個人化設定"); memcpy(mindbuf, &currutmp->mind, 4); @@ -241,15 +241,12 @@ static void Customize(void) if( HAS_PERM(PERM_ANGEL) ){ prints("%-30s%10s\n", "F. 接受小主人詢問", ((cuser.uflag2 & BEING_ANGEL) ? "是" : "否")); - getdata(b_lines - 1, 0, "請按 [A-F] 切換設定,按 [Return] 結束:", - ans, 3, DOECHO); + key = getkey("請按 [A-F] 切換設定,按 [Return] 結束:"); }else #endif - getdata(b_lines - 1, 0, "請按 [A-E] 切換設定,按 [Return] 結束:", - ans, 3, DOECHO); + key = getkey("請按 [A-E] 切換設定,按 [Return] 結束:"); - switch( ans[0] ){ - case 'A': + switch( key ){ case 'a':{ int currentset = cuser.uflag2 & WATER_MASK; currentset = (currentset + 1) % 3; @@ -258,18 +255,14 @@ static void Customize(void) vmsg("修正水球模式後請正常離線再重新上線"); } break; - case 'B': case 'b': cuser.uflag2 ^= REJ_OUTTAMAIL; break; - - case 'C': case 'c': cuser.uflag2 ^= FAVNEW_FLAG; if (cuser.uflag2 & FAVNEW_FLAG) subscribe_newfav(); break; - case 'D': case 'd':{ getdata(b_lines - 1, 0, "現在的心情? ", mindbuf, sizeof(mindbuf), DOECHO); @@ -281,13 +274,11 @@ static void Customize(void) memcpy(currutmp->mind, mindbuf, 4); } break; - case 'E': case 'e': cuser.uflag2 ^= FAVNOHILIGHT; break; #ifdef PLAY_ANGEL - case 'F': case 'f': if( HAS_PERM(PERM_ANGEL) ){ t_switchangel(); @@ -300,7 +291,7 @@ static void Customize(void) } passwd_update(usernum, &cuser); } - pressanykey(); + vmsg("設定完成"); } void @@ -308,8 +299,8 @@ uinfo_query(userec_t * u, int real, int unum) { userec_t x; register int i = 0, fail, mail_changed; - int uid; - char ans[4], buf[STRLEN], *p; + int uid, ans; + char buf[STRLEN], *p; char genbuf[200], reason[50]; int money = 0; fileheader_t fhdr; @@ -320,23 +311,22 @@ uinfo_query(userec_t * u, int real, int unum) fail = mail_changed = 0; memcpy(&x, u, sizeof(userec_t)); - getdata(b_lines - 1, 0, real ? + ans = getans(real ? "(1)改資料(2)設密碼(3)設權限(4)砍帳號(5)改ID" "(6)殺/復活寵物(7)審判 [0]結束 " : - "請選擇 (1)修改資料 (2)設定密碼 (C) 個人化設定 ==> [0]結束 ", - ans, sizeof(ans), DOECHO); + "請選擇 (1)修改資料 (2)設定密碼 (C) 個人化設定 ==> [0]結束 "); - if (ans[0] > '2' && ans[0] != 'C' && ans[0] != 'c' && !real) - ans[0] = '0'; + if (ans > '2' && ans != 'C' && ans != 'c' && !real) + ans = '0'; - if (ans[0] == '1' || ans[0] == '3') { + if (ans == '1' || ans == '3') { clear(); i = 1; move(i++, 0); outs(msg_uid); outs(x.userid); } - switch (ans[0]) { + switch (ans) { case 'C': case 'c': Customize(); @@ -608,8 +598,7 @@ uinfo_query(userec_t * u, int real, int unum) pressanykey(); return; } - getdata(b_lines - 1, 0, msg_sure_ny, ans, 3, LCECHO); - if (*ans == 'y') { + if (getans(msg_sure_ny) == 'y') { if (flag) post_change_perm(temp, i, cuser.userid, x.userid); if (strcmp(u->userid, x.userid)) { @@ -841,7 +830,6 @@ u_editcalendar() getdata(b_lines - 1, 0, "行事曆 (D)刪除 (E)編輯 [Q]取消?[Q] ", genbuf, 3, LCECHO); - sethomefile(genbuf, cuser.userid, "calendar"); if (genbuf[0] == 'e') { int aborted; @@ -852,6 +840,7 @@ u_editcalendar() vmsg("行事曆更新完畢"); return 0; } else if (genbuf[0] == 'd') { + sethomefile(genbuf, cuser.userid, "calendar"); unlink(genbuf); vmsg("行事曆刪除完畢"); } @@ -1146,13 +1135,15 @@ static char *isvalidcareer(char *career) return "麻煩請加學校系所"; if (strcmp(career, "學生高中") == 0) return "麻煩輸入學校名稱"; +#else + if( strlen(career) < 6 ) + return "您的輸入不正確"; #endif return NULL; } static char *isvalidaddr(char *addr) { -#ifndef FOREIGN_REG char *rejectstr[] = {"地球", "銀河", "火星", NULL}; @@ -1171,7 +1162,6 @@ static char *isvalidaddr(char *addr) strcmp(&addr[strlen(addr) - 2], "市") == 0 || strcmp(&addr[strlen(addr) - 2], "街") == 0 ) return "這個地址並不合法"; -#endif return NULL; } @@ -1291,6 +1281,10 @@ u_register(void) "請按下任一鍵跳離後重新上站~ :)"); sethomefile(genbuf, cuser.userid, "justify.wait"); unlink(genbuf); + snprintf(cuser.justify, sizeof(cuser.justify), + "%s:%s:auto", phone, career); + sethomefile(genbuf, cuser.userid, "justify"); + log_file(genbuf, LOG_CREAT, cuser.justify); pressanykey(); u_exit("registed"); exit(0); @@ -1388,11 +1382,11 @@ u_register(void) getfield(11, "含\033[1;33m縣市\033[m及門寢號碼" "(台北請加\033[1;33m行政區\033[m)", "目前住址", addr, 50); - if( (errcode = isvalidaddr(addr) + if( (errcode = isvalidaddr(addr)) == NULL #ifdef FOREIGN_REG - && fore[0] ==0 + || fore[0] #endif - ) == NULL ) + ) break; else vmsg(errcode); @@ -1571,6 +1565,6 @@ u_list() clrtoeol(); prints("\033[34;46m 已顯示 %d/%d 的使用者(系統容量無上限) " "\033[31;47m (請按任意鍵繼續) \033[m", usercounter, totalusers); - egetch(); + igetch(); return 0; } diff --git a/mbbsd/var.c b/mbbsd/var.c index d239fbec..b3afba22 100644 --- a/mbbsd/var.c +++ b/mbbsd/var.c @@ -84,9 +84,7 @@ char paste_title[STRLEN]; char paste_path[256]; char currtitle[TTLEN + 1] = "\0"; char vetitle[TTLEN + 1] = "\0"; -char currowner[IDLEN + 2] = "\0"; char currauthor[IDLEN + 2] = "\0"; -char currfile[FNLEN];/* current file name @ bbs.c mail.c */ char *currboard = "\0"; char currBM[IDLEN * 3 + 10]; char reset_color[4] = "\033[m"; @@ -383,7 +381,6 @@ char real_name[IDLEN + 1]; int local_article; /* mbbsd.c */ -int talkrequest = NA; char fromhost[STRLEN] = "\0"; char water_usies = 0; FILE *fp_writelog = NULL; diff --git a/mbbsd/vote.c b/mbbsd/vote.c index a6cb52c4..5325e64c 100644 --- a/mbbsd/vote.c +++ b/mbbsd/vote.c @@ -535,7 +535,7 @@ vote_view_all(char *bname) setbfile(buf, bname, STR_new_control); move(0, 0); if ((fp = fopen(buf, "r"))) { - prints("(0) "); + outs("(0) "); x = 0; fclose(fp); @@ -760,7 +760,6 @@ vote_maintain(char *bname) move((i % 15) + 2, (i / 15) * 40); prints(buf); } - refresh(); } snprintf(buf, sizeof(buf), "%c) ", num + 'A'); getdata((num % 15) + 2, (num / 15) * 40, buf, diff --git a/mbbsd/xyz.c b/mbbsd/xyz.c index e0b850b5..b20b9d74 100644 --- a/mbbsd/xyz.c +++ b/mbbsd/xyz.c @@ -180,9 +180,7 @@ note() notedata_t myitem; if (cuser.money < 5) { - outmsg("\033[1;41m 哎呀! 要投五銀才能留言...沒錢耶..\033[m"); - clrtoeol(); - refresh(); + vmsg("\033[1;41m 哎呀! 要投五銀才能留言...沒錢耶..\033[m"); return 0; } setutmpmode(EDNOTE); @@ -313,7 +311,7 @@ mail_sysop() move(12, 0); clrtobot(); - prints("%16s %-18s權責劃分\n\n", "編號", "站長 ID"); + outs(" 編號 站長 ID 權責劃分\n\n"); for (i = 0; i < j; i++) prints("%15d. \033[1;%dm%-16s%s\033[0m\n", |