summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2009-10-22 23:45:02 +0800
committerpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2009-10-22 23:45:02 +0800
commit3b4f145034b52fba0a188570eb1499850179eaa5 (patch)
tree444ff8866385151e89e9c384ef01a504820af42a
parent7cefaff62affbd51e71ebe00de7825bf4245507d (diff)
downloadpttbbs-3b4f145034b52fba0a188570eb1499850179eaa5.tar
pttbbs-3b4f145034b52fba0a188570eb1499850179eaa5.tar.gz
pttbbs-3b4f145034b52fba0a188570eb1499850179eaa5.tar.bz2
pttbbs-3b4f145034b52fba0a188570eb1499850179eaa5.tar.lz
pttbbs-3b4f145034b52fba0a188570eb1499850179eaa5.tar.xz
pttbbs-3b4f145034b52fba0a188570eb1499850179eaa5.tar.zst
pttbbs-3b4f145034b52fba0a188570eb1499850179eaa5.zip
* isolate anti-flood code
git-svn-id: http://opensvn.csie.org/pttbbs/trunk@4957 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--pttbbs/mbbsd/ccw.c59
1 files changed, 31 insertions, 28 deletions
diff --git a/pttbbs/mbbsd/ccw.c b/pttbbs/mbbsd/ccw.c
index 1d482ede..f66f7703 100644
--- a/pttbbs/mbbsd/ccw.c
+++ b/pttbbs/mbbsd/ccw.c
@@ -769,45 +769,48 @@ ccw_chat_recv(CCW_CTX *ctx)
return 0;
}
-static int
-ccw_chat_peek_cmd(CCW_CTX *ctx, const char *buf, int local)
+static void
+ccw_chat_anti_flood(CCW_CTX *ctx)
{
#ifdef EXP_ANTIFLOOD
- {
- // prevent flooding */
- static time4_t lasttime = 0;
- static int flood = 0;
+ // prevent flooding */
+ static time4_t lasttime = 0;
+ static int flood = 0;
- syncnow();
- if (now - lasttime < 3 )
+ syncnow();
+ if (now - lasttime < 3 )
+ {
+ // 3 秒內洗半面是不行的 ((25-5)/2)
+ if( ++flood > 10 )
{
- // 3 秒內洗半面是不行的 ((25-5)/2)
- if( ++flood > 10 )
+ // flush all input!
+ unsigned char garbage[STRLEN];
+ drop_input();
+ while (wait_input(1, 0))
{
- // flush all input!
- unsigned char garbage[STRLEN];
- drop_input();
- while (wait_input(1, 0))
- {
- if (num_in_buf())
- drop_input();
- else
- tty_read(garbage, sizeof(garbage));
- }
- drop_input();
- vmsg("請勿大量剪貼或造成洗板面的效果。");
- // log?
- sleep(2);
- return 1;
+ if (num_in_buf())
+ drop_input();
+ else
+ tty_read(garbage, sizeof(garbage));
}
- } else {
- lasttime = now;
- flood = 0;
+ drop_input();
+ vmsg("請勿大量剪貼或造成洗板面的效果。");
+
+ // log?
+ sleep(2);
}
+ } else {
+ lasttime = now;
+ flood = 0;
}
#endif // anti-flood
+}
+static int
+ccw_chat_peek_cmd(CCW_CTX *ctx, const char *buf, int local)
+{
ccw_chat_check_newmail(ctx);
+ ccw_chat_anti_flood(ctx);
if (buf[0] != '/') return 0;
buf ++;