作者itoc.bbs@cpu.tfcis.org (核心動力) 看板: itoc
標題Re: [功能] manage.c 板主自訂看板:發文門檻限制
時間動力核心 (2007/04/18 Wed 22:24:16)
: struct.h 加入這段於 struct BRD 之後
typedef struct
{
int age;
int numlogins;
int numposts;
} THRESHOLD;
: global.h
#define FN_CZH ".CZH"
+ #define FN_THRESHOLD "threshold" /* 看板發文門檻 */
: battr.h
#define BRD_ANONYMOUS 0x20 /* 匿名看板 */
+ #define BRD_THRESHOLD 0x40 /* 發文門檻限制 */
...
...
- #define NUMBATTRS 6
+ #define NUMBATTRS 7
- #define STR_BATTR "zTcsvA"
+ #define STR_BATTR "zTcsvAT"
: battr.h:battr_tbl[]
"匿名看板", /* BRD_ANONYMOUS */
+ "發文門檻限制", /* BRD_THRESHOLD */
> ──────────────────────────────────── <
: post.c:do_post()
if (!(bbstate & STAT_POST))
{
...
...
return XO_FOOT;
}
+ else if (currbattr & BRD_THRESHOLD)
+ {
+ THRESHOLD th;
+ char msg[80];
+
+ brd_fpath(fpath, currboard, FN_THRESHOLD);
+ if (!rec_gec(fpath, &th, sizeof(THRESHOLD), 0))
+ {
+ if (cuser.lastlogin - cuser.firstlogin < th.age * 86400)
+ {
+ sprintf(msg, "註冊時間 %d 天以上,方可在此看板發表文章", th.age);
+ vmsg(msg);
+ return XO_FOOT;
+ }
+ if (cuser.numlogins < th.numlogins)
+ {
+ sprintf(msg, "上站次數 %d 次以上,方可在此看板發表文章", th.numlogins)
;
+ vmsg(msg);
+ return XO_FOOT;
+ }
+ if (cuser.numposts < th.numposts)
+ {
+ sprintf(msg, "發表文章 %d 篇以上,方可在此看板發表文章", th.numposts);
+ vmsg(msg);
+ return XO_FOOT;
+ }
+ }
+ }
film_out(FILM_POST, 0);
> ──────────────────────────────────── <
: manage.c 把以下這段加在 post_battr_noscore() 後面
static int
post_battr_threshold(xo)
XO *xo;
{
int ans, echo, num;
BRD *oldbrd, newbrd;
THRESHOLD th;
char fpath[64], buf[80];
oldbrd = bshm->bcache + currbno;
memcpy(&newbrd, oldbrd, sizeof(BRD));
brd_fpath(fpath, newbrd.brdname, FN_THRESHOLD);
switch (ans = vans("◎ 發文門檻限制 1)不限制門檻 2)限制門檻 [Q] "))
{
case '1':
newbrd.battr &= ~BRD_THRESHOLD;
break;
case '2':
newbrd.battr |= BRD_THRESHOLD;
echo = rec_gec(fpath, &th, sizeof(THRESHOLD), 0) ? DOECHO : GCARRY;
if (echo & GCARRY)
sprintf(buf, "%d", th.age);
if (!vgets(b_lines, 0, "請輸入發文門檻-註冊幾天以上?", buf, 4, echo))
return XO_FOOT;
if ((num = atoi(buf)) < 0)
return XO_FOOT;
th.age = num;
if (echo & GCARRY)
sprintf(buf, "%d", th.numlogins);
if (!vgets(b_lines, 0, "請輸入發文門檻-登入幾次以上", buf, 4, echo))
return XO_FOOT;
if ((num = atoi(buf)) < 0)
return XO_FOOT;
th.numlogins = num;
if (echo & GCARRY)
sprintf(buf, "%d", th.numposts);
if (!vgets(b_lines, 0, "請輸入發文門檻-發文幾篇以上", buf, 4, echo))
return XO_FOOT;
if ((num = atoi(buf)) < 0)
return XO_FOOT;
th.numposts = num;
if (th.age <= 0 && th.numlogins <= 0 && th.numposts <= 0)
return XO_FOOT;
break;
default:
return XO_FOOT;
}
if ((memcmp(&newbrd, oldbrd, sizeof(BRD)) || (ans == '2')) &&
vans(msg_sure_ny) == 'y')
{
memcpy(oldbrd, &newbrd, sizeof(BRD));
rec_put(FN_BRD, &newbrd, sizeof(BRD), currbno, NULL);
if (ans == '1')
unlink(fpath);
else /* if (ans == '2') */
rec_put(fpath, &th, sizeof(THRESHOLD), 0);
}
return XO_FOOT;
}
: manage.c:post_manage()
# ifdef HAVE_SCORE
"Score 設定可否評分",
# endif
+ "ZLevel 發文門檻限制",
...
...
# ifdef HAVE_SCORE
" (S)評分"
# endif
+ " (Z)限制"
...
...
#ifdef HAVE_SCORE
case 's':
return post_battr_noscore(xo);
#endif
+ case 'z':
+ return post_battr_threshold(xo);
--
其實應該把限制寫在 struct BRD 裡面
不過由於不想轉換 .BRD,所以就另外存一個檔案
--
=[﹎:�摃�◣��:﹎ Origin ]|[ ���O���� cpu.tfcis.org ]|[�搟說�﹎:]=
=[﹊:�摃�╱��:﹊ Author ]|[218-168-183-53.dynamic.hin]|[���插�﹊:]=