From 2286d34c1de78415e1b838cdc071d1d8c56ccd80 Mon Sep 17 00:00:00 2001 From: piaip Date: Fri, 28 Dec 2007 05:28:06 +0000 Subject: - allow all non-guest user to use myfav (PERM_BASIC) - add GLOBAL_NEWBIE and GLOBAL_SYSOP to default fav (for new registered user, not empty fav) git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3748 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- mbbsd/board.c | 415 ++++++++++++++++++++++++++++++---------------------------- mbbsd/cal.c | 10 +- mbbsd/edit.c | 2 +- mbbsd/fav.c | 22 +++- mbbsd/mbbsd.c | 1 + 5 files changed, 244 insertions(+), 206 deletions(-) (limited to 'mbbsd') diff --git a/mbbsd/board.c b/mbbsd/board.c index 66402831..a04cfa21 100644 --- a/mbbsd/board.c +++ b/mbbsd/board.c @@ -18,6 +18,9 @@ #define B_TOTAL(bptr) (SHM->total[(bptr)->bid - 1]) #define B_LASTPOSTTIME(bptr) (SHM->lastposttime[(bptr)->bid - 1]) #define B_BH(bptr) (&bcache[(bptr)->bid - 1]) + +#define HasFavEditPerm() HasUserPerm(PERM_BASIC) + typedef struct { int bid; unsigned char myattr; @@ -998,13 +1001,13 @@ brdlist_foot(void) { outs( ANSI_COLOR(34;46) " 選擇看板 " ANSI_COLOR(31;47) " (c)" ANSI_COLOR(30) "新文章模式 " - ANSI_COLOR(31) "(v/V)" ANSI_COLOR(30) "標記已讀/未讀 " - ANSI_COLOR(31) "(y)" ANSI_COLOR(30) "篩選"); + ANSI_COLOR(31) "(v/V)" ANSI_COLOR(30) "標為已讀/未讀 " + ANSI_COLOR(31) "(y)" ANSI_COLOR(30)); if(IS_LISTING_FAV()) - outs("最愛"); + outs("列出全部"); else if (IS_LISTING_BRD()) - outs("部份"); - else outs("全部"); + outs("篩選列表"); + else outs("篩選列表"); // never reach here? outslr(" " ANSI_COLOR(31) "(m)" ANSI_COLOR(30) "切換最愛", 73, ANSI_RESET, 0); @@ -1076,11 +1079,11 @@ show_brdlist(int head, int clsflag, int newflag) // (a) or (i) needs HasUserPerm(PERM_LOGINOK)). // 3 = first line of empty area - if (!HasUserPerm(PERM_LOGINOK)) + if (!HasFavEditPerm()) { // TODO actually we cannot use 's' (for PTT)... mouts(3, 10, - "--- 註冊完成的使用者才能新增看板喔 (可按 s 手動選取) ---"); + "--- 註冊的使用者才能新增看板喔 (可按 s 手動選取) ---"); } else { // normal user. tell him what to do. mouts(3, 10, @@ -1308,10 +1311,28 @@ choose_board(int newflag) ch = cursor_key(3 + num - head, 0); switch (ch) { + + /////////////////////////////////////////////////////// + // General Hotkeys + /////////////////////////////////////////////////////// + + case 'h': + show_helpfile(fn_boardlisthelp); + show_brdlist(head, 1, newflag); + break; case Ctrl('W'): whereami(); head = -1; break; + + case 'c': + show_brdlist(head, 1, newflag ^= 1); + break; + case Ctrl('I'): + t_idle(); + show_brdlist(head, 1, newflag); + break; + case 'e': case KEY_LEFT: case EOF: @@ -1323,9 +1344,6 @@ choose_board(int newflag) ch = ' '; } break; - case 'c': - show_brdlist(head, 1, newflag ^= 1); - break; case KEY_PGUP: case 'P': case 'b': @@ -1347,10 +1365,6 @@ choose_board(int newflag) else num += p_lines; break; - case Ctrl('I'): - t_idle(); - show_brdlist(head, 1, newflag); - break; case KEY_UP: case 'p': case 'k': @@ -1416,17 +1430,7 @@ choose_board(int newflag) num = tmp; brdlist_foot(); break; - case 'F': - case 'f': - if (HasUserPerm(PERM_SYSOP)) { - getbcache(class_bid)->firstchild[cuser.uflag & BRDSORT_FLAG ? 1 : 0] = 0; - brdnum = -1; - } - break; - case 'h': - show_helpfile(fn_boardlisthelp); - show_brdlist(head, 1, newflag); - break; + case '/': getdata_buf(b_lines - 1, 0, "請輸入看板中文關鍵字:", keyword, sizeof(keyword), DOECHO); @@ -1447,29 +1451,136 @@ choose_board(int newflag) cuser.uflag ^= BRDSORT_FLAG; brdnum = -1; break; - case 'y': - if (HasUserPerm(PERM_LOGINOK)) { - if (get_current_fav() != NULL || !IS_LISTING_FAV()){ - if (cuser.userlevel) - yank_flag ^= 1; /* FAV <=> BRD */ + + + case 'v': + case 'V': + assert(0<=num && nummyattr &= ~NBRD_UNREAD; + brc_toggle_all_read(ptr->bid, 1); + } else { + brc_toggle_all_read(ptr->bid, 0); + ptr->myattr |= NBRD_UNREAD; + } + show_brdlist(head, 0, newflag); + break; + case 's': + if ((tmp = search_board()) == -1) { + show_brdlist(head, 1, newflag); + break; + } + head = -1; + num = tmp; + break; + + case KEY_RIGHT: + case '\n': + case '\r': + case 'r': + { + if (IS_LISTING_FAV()) { + assert(nbrdsize>0); + if (get_fav_type(&nbrd[0]) == 0) + break; + assert(0<=num && nummyattr & NBRD_LINE) + break; + if (ptr->myattr & NBRD_FOLDER){ + int t = num; + num = 0; + fav_folder_in(ptr->bid); + choose_board(0); + fav_folder_out(); + num = t; + LIST_FAV(); // XXX press 'y' in fav makes yank_flag = LIST_BRD + brdnum = -1; + head = 9999; + break; + } + } else { + assert(0<=num && nummyattr & NBRD_SYMBOLIC) { + replace_link_by_target(ptr); + } + } + + assert(0<=ptr->bid-1 && ptr->bid-1brdattr & BRD_GROUPBOARD)) { /* 非sub class */ + if (HasBoardPerm(B_BH(ptr))) { + brc_initial_board(B_BH(ptr)->brdname); + + if (newflag) { + setbdir(buf, currboard); + tmp = unread_position(buf, ptr); + head = tmp - t_lines / 2; + getkeep(buf, head > 1 ? head : 1, tmp + 1); + } + Read(); + check_newpost(ptr); + head = -1; + setutmpmode(newflag ? READNEW : READBRD); + } + } else { /* sub class */ + move(12, 1); + bidtmp = class_bid; + currmodetmp = currmode; + tmp1 = num; + num = 0; + if (!(B_BH(ptr)->brdattr & BRD_TOP)) + class_bid = ptr->bid; + else + class_bid = -1; /* 熱門群組用 */ + + if (!GROUPOP()) /* 如果還沒有小組長權限 */ + set_menu_BM(B_BH(ptr)->BM); + + if (now < B_BH(ptr)->bupdate) { + int mr = 0; + + setbfile(buf, B_BH(ptr)->brdname, fn_notes); + mr = more(buf, NA); + if (mr != -1 && mr != READ_NEXT) + pressanykey(); + } + tmp = currutmp->brc_id; + setutmpbid(ptr->bid); + free(nbrd); + nbrd = NULL; + nbrdsize = 0; + if (IS_LISTING_FAV()) { + LIST_BRD(); + choose_board(0); + LIST_FAV(); + } + else + choose_board(0); + currmode = currmodetmp; /* 離開板板後就把權限拿掉喔 */ + num = tmp1; + class_bid = bidtmp; + setutmpbid(tmp); + brdnum = -1; } - brdnum = -1; } break; - case 'D': - if (HasUserPerm(PERM_SYSOP) || - (HasUserPerm(PERM_SYSSUPERSUBOP) && GROUPOP())) { - assert(0<=num && nummyattr & NBRD_SYMBOLIC) { - if (getans("確定刪除連結?[N/y]") == 'y') - delete_symbolic_link(getbcache(ptr->bid), ptr->bid); + /////////////////////////////////////////////////////// + // MyFav Functionality (Require PERM_BASIC) + /////////////////////////////////////////////////////// + case 'y': + if (HasFavEditPerm()) { + if (get_current_fav() != NULL || !IS_LISTING_FAV()){ + yank_flag ^= 1; /* FAV <=> BRD */ } brdnum = -1; } break; case Ctrl('D'): - if (HasUserPerm(PERM_LOGINOK)) { + if (HasFavEditPerm()) { if (getans("刪除所有標記[N]?") == 'y'){ fav_remove_all_tagged_item(); brdnum = -1; @@ -1477,13 +1588,13 @@ choose_board(int newflag) } break; case Ctrl('A'): - if (HasUserPerm(PERM_LOGINOK)) { + if (HasFavEditPerm()) { fav_add_all_tagged_item(); brdnum = -1; } break; case Ctrl('T'): - if (HasUserPerm(PERM_LOGINOK)) { + if (HasFavEditPerm()) { fav_remove_all_tag(); brdnum = -1; } @@ -1492,6 +1603,7 @@ choose_board(int newflag) if (paste_taged_brds(class_bid)) brdnum = -1; break; + case 'L': if ((HasUserPerm(PERM_SYSOP) || (HasUserPerm(PERM_SYSSUPERSUBOP) && GROUPOP())) && IN_CLASS()) { @@ -1500,7 +1612,7 @@ choose_board(int newflag) brdnum = -1; head = 9999; } - else if (HasUserPerm(PERM_LOGINOK) && IS_LISTING_FAV()) { + else if (HasFavEditPerm() && IS_LISTING_FAV()) { if (fav_add_line() == NULL) { vmsg("新增失敗,分隔線/總最愛 數量達最大值。"); break; @@ -1513,17 +1625,10 @@ choose_board(int newflag) head = 9999; } break; -/* - case 'l': - if (HasUserPerm(PERM_SYSOP) && (nbrd[num].myattr & NBRD_SYMBOLIC)) { - replace_link_by_target(&nbrd[num]); - head = 9999; - } - break; -*/ + case 'z': case 'm': - if (HasUserPerm(PERM_LOGINOK)) { + if (HasFavEditPerm()) { assert(0<=num && nummyattr &= ~NBRD_UNREAD; - brc_toggle_all_read(ptr->bid, 1); - } else { - brc_toggle_all_read(ptr->bid, 0); - ptr->myattr |= NBRD_UNREAD; - } - show_brdlist(head, 0, newflag); - break; - case 's': - if ((tmp = search_board()) == -1) { - show_brdlist(head, 1, newflag); - break; - } - head = -1; - num = tmp; - break; - case 'E': - if (HasUserPerm(PERM_SYSOP | PERM_BOARD) || GROUPOP()) { - assert(0<=num && numbrdname); - brdnum = -1; - } - break; - case 'R': - if (HasUserPerm(PERM_SYSOP) || GROUPOP()) { - m_newbrd(class_bid, 1); - brdnum = -1; - } - break; - case 'B': - if (HasUserPerm(PERM_SYSOP) || GROUPOP()) { - m_newbrd(class_bid, 0); - brdnum = -1; - } - break; - case 'W': - if (IN_SUBCLASS() && - (HasUserPerm(PERM_SYSOP) || GROUPOP())) { - setbpath(buf, getbcache(class_bid)->brdname); - mkdir(buf, 0755); /* Ptt:開群組目錄 */ - b_note_edit_bname(class_bid); - brdnum = -1; - } - break; - case 'a': case 'i': - if(IS_LISTING_FAV() && HasUserPerm(PERM_LOGINOK)){ + if(IS_LISTING_FAV() && HasFavEditPerm()){ char bname[IDLEN + 1]; int bid; move(0, 0); @@ -1720,7 +1770,7 @@ choose_board(int newflag) break; case 'w': - /* allowing save once per 10 minutes */ + /* allowing save BRC/fav once per 10 minutes */ if (now - last_save_fav_and_brc > 10 * 60) { fav_save(); brc_finalize(); @@ -1729,96 +1779,61 @@ choose_board(int newflag) } break; - case KEY_RIGHT: - case '\n': - case '\r': - case 'r': - { - if (IS_LISTING_FAV()) { - assert(nbrdsize>0); - if (get_fav_type(&nbrd[0]) == 0) - break; - assert(0<=num && nummyattr & NBRD_LINE) - break; - if (ptr->myattr & NBRD_FOLDER){ - int t = num; - num = 0; - fav_folder_in(ptr->bid); - choose_board(0); - fav_folder_out(); - num = t; - LIST_FAV(); // XXX press 'y' in fav makes yank_flag = LIST_BRD - brdnum = -1; - head = 9999; - break; - } - } else { - assert(0<=num && nummyattr & NBRD_SYMBOLIC) { - replace_link_by_target(ptr); - } - } - - assert(0<=ptr->bid-1 && ptr->bid-1brdattr & BRD_GROUPBOARD)) { /* 非sub class */ - if (HasBoardPerm(B_BH(ptr))) { - brc_initial_board(B_BH(ptr)->brdname); + /////////////////////////////////////////////////////// + // Administrator Only + /////////////////////////////////////////////////////// - if (newflag) { - setbdir(buf, currboard); - tmp = unread_position(buf, ptr); - head = tmp - t_lines / 2; - getkeep(buf, head > 1 ? head : 1, tmp + 1); - } - Read(); - check_newpost(ptr); - head = -1; - setutmpmode(newflag ? READNEW : READBRD); - } - } else { /* sub class */ - move(12, 1); - bidtmp = class_bid; - currmodetmp = currmode; - tmp1 = num; - num = 0; - if (!(B_BH(ptr)->brdattr & BRD_TOP)) - class_bid = ptr->bid; - else - class_bid = -1; /* 熱門群組用 */ - - if (!GROUPOP()) /* 如果還沒有小組長權限 */ - set_menu_BM(B_BH(ptr)->BM); - - if (now < B_BH(ptr)->bupdate) { - int mr = 0; - - setbfile(buf, B_BH(ptr)->brdname, fn_notes); - mr = more(buf, NA); - if (mr != -1 && mr != READ_NEXT) - pressanykey(); - } - tmp = currutmp->brc_id; - setutmpbid(ptr->bid); - free(nbrd); - nbrd = NULL; - nbrdsize = 0; - if (IS_LISTING_FAV()) { - LIST_BRD(); - choose_board(0); - LIST_FAV(); - } - else - choose_board(0); - currmode = currmodetmp; /* 離開板板後就把權限拿掉喔 */ - num = tmp1; - class_bid = bidtmp; - setutmpbid(tmp); - brdnum = -1; + case 'F': + case 'f': + if (HasUserPerm(PERM_SYSOP)) { + getbcache(class_bid)->firstchild[cuser.uflag & BRDSORT_FLAG ? 1 : 0] = 0; + brdnum = -1; + } + break; + case 'D': + if (HasUserPerm(PERM_SYSOP) || + (HasUserPerm(PERM_SYSSUPERSUBOP) && GROUPOP())) { + assert(0<=num && nummyattr & NBRD_SYMBOLIC) { + if (getans("確定刪除連結?[N/y]") == 'y') + delete_symbolic_link(getbcache(ptr->bid), ptr->bid); } + brdnum = -1; + } + break; + case 'E': + if (HasUserPerm(PERM_SYSOP | PERM_BOARD) || GROUPOP()) { + assert(0<=num && numbrdname); + brdnum = -1; + } + break; + case 'R': + if (HasUserPerm(PERM_SYSOP) || GROUPOP()) { + m_newbrd(class_bid, 1); + brdnum = -1; + } + break; + case 'B': + if (HasUserPerm(PERM_SYSOP) || GROUPOP()) { + m_newbrd(class_bid, 0); + brdnum = -1; } + break; + case 'W': + if (IN_SUBCLASS() && + (HasUserPerm(PERM_SYSOP) || GROUPOP())) { + setbpath(buf, getbcache(class_bid)->brdname); + mkdir(buf, 0755); /* Ptt:開群組目錄 */ + b_note_edit_bname(class_bid); + brdnum = -1; + } + break; + } } while (ch != 'q'); free(nbrd); diff --git a/mbbsd/cal.c b/mbbsd/cal.c index fb5c12e6..0ed5f2b6 100644 --- a/mbbsd/cal.c +++ b/mbbsd/cal.c @@ -466,22 +466,24 @@ p_sysinfo(void) getrusage(RUSAGE_SELF, &ru); prints("記憶體用量: " #ifdef IA32 - "sbrk: %d KB, " + "sbrk: %u KB, " #endif #ifdef __linux__ "VmData: %d KB, VmStk: %d KB, " #endif "idrss: %d KB, isrss: %d KB\n", #ifdef IA32 - ((int)sbrk(0) - 0x8048000) / 1024, + ((unsigned int)sbrk(0) - 0x8048000) / 1024, #endif #ifdef __linux__ vmdata, vmstk, #endif (int)ru.ru_idrss, (int)ru.ru_isrss); prints("CPU 用量: %ld.%06ldu %ld.%06lds", - ru.ru_utime.tv_sec, ru.ru_utime.tv_usec, - ru.ru_stime.tv_sec, ru.ru_stime.tv_usec); + (long int)ru.ru_utime.tv_sec, + (long int)ru.ru_utime.tv_usec, + (long int)ru.ru_stime.tv_sec, + (long int)ru.ru_stime.tv_usec); #ifdef CPULIMIT prints(" (limit %d secs)", (int)(CPULIMIT * 60)); #endif diff --git a/mbbsd/edit.c b/mbbsd/edit.c index fc31619f..dded10a9 100644 --- a/mbbsd/edit.c +++ b/mbbsd/edit.c @@ -1766,7 +1766,7 @@ write_file(char *fpath, int saveheader, int *islocal, char *mytitle, int upload) } else if (currstat == REEDIT #ifndef ALL_REEDIT_LOG - && strcmp(currboard, str_sysop) == 0 + && strcmp(currboard, GLOBAL_SYSOP) == 0 #endif ) { ptime = localtime4(&now); diff --git a/mbbsd/fav.c b/mbbsd/fav.c index b01ba1b9..fae372df 100644 --- a/mbbsd/fav.c +++ b/mbbsd/fav.c @@ -510,7 +510,7 @@ static int read_favrec(FILE *frp, fav_t *fp) /** * 從記錄檔中 load 出我的最愛。 - * TODO create default fav, and add SYSOP/PttNewHand + * TODO create default fav, and add SYSOP/PttNewHand (see reginit_fav) */ int fav_load(void) { @@ -1207,6 +1207,24 @@ void subscribe_newfav(void) updatenewfav(0); } +// create defaults for new user +void reginit_fav(void) +{ + int bid = 0; + + fav_load(); // for creating root + + bid = getbnum(GLOBAL_SYSOP); + if (bid > 0) fav_add_board(bid); + +#ifdef GLOBAL_NEWBIE + bid = getbnum(GLOBAL_NEWBIE); + if (bid > 0) fav_add_board(bid); +#endif + + fav_save(); +} + #if 1 // DEPRECATED typedef struct { char fid; @@ -1285,3 +1303,5 @@ static void fav4_read_favrec(FILE *frp, fav_t *fp) } } #endif + +// vim:ts=8:sw=4 diff --git a/mbbsd/mbbsd.c b/mbbsd/mbbsd.c index 114b6fdf..4d76d46f 100644 --- a/mbbsd/mbbsd.c +++ b/mbbsd/mbbsd.c @@ -717,6 +717,7 @@ login_query(void) #ifdef LOGINASNEW new_register(); mkuserdir(cuser.userid); + reginit_fav(); break; #else outs("本系統目前無法以 new 註冊, 請用 guest 進入\n"); -- cgit v1.2.3