summaryrefslogtreecommitdiffstats
path: root/mbbsd
diff options
context:
space:
mode:
authorpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2008-02-14 23:03:51 +0800
committerpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2008-02-14 23:03:51 +0800
commit5112b895b68f7b5c06bca41b67546ee0cb73e876 (patch)
tree0bc203b1157a76c16477524d7db4da12c726589e /mbbsd
parent3c686bcc63c9bf7680a656b8635c33a6ef4fa8d6 (diff)
downloadpttbbs-5112b895b68f7b5c06bca41b67546ee0cb73e876.tar
pttbbs-5112b895b68f7b5c06bca41b67546ee0cb73e876.tar.gz
pttbbs-5112b895b68f7b5c06bca41b67546ee0cb73e876.tar.bz2
pttbbs-5112b895b68f7b5c06bca41b67546ee0cb73e876.tar.lz
pttbbs-5112b895b68f7b5c06bca41b67546ee0cb73e876.tar.xz
pttbbs-5112b895b68f7b5c06bca41b67546ee0cb73e876.tar.zst
pttbbs-5112b895b68f7b5c06bca41b67546ee0cb73e876.zip
- more options to prevent chatroom flooding
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3917 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd')
-rw-r--r--mbbsd/chat.c70
1 files changed, 65 insertions, 5 deletions
diff --git a/mbbsd/chat.c b/mbbsd/chat.c
index 85834a67..6743ece8 100644
--- a/mbbsd/chat.c
+++ b/mbbsd/chat.c
@@ -260,6 +260,7 @@ chat_cmd(char *buf, int fd)
#define MAXLASTCMD 6
static int chatid_len = 10;
+static time4_t lastEnter = 0;
int
t_chat(void)
@@ -274,14 +275,32 @@ t_chat(void)
struct ChatBuf chatbuf;
if(HasUserPerm(PERM_VIOLATELAW))
- {
- vmsg("請先繳罰單才能使用聊天室!");
- return -1;
- }
+ {
+ vmsg("請先繳罰單才能使用聊天室!");
+ return -1;
+ }
- memset(&chatbuf, 0, sizeof(chatbuf));
+ syncnow();
+
+#ifdef CHAT_GAPMINS
+ if ((now - lastEnter)/60 < CHAT_GAPMINS)
+ {
+ vmsg("您才剛離開聊天室,裡面正在整理中。請稍後再試。");
+ return 0;
+ }
+#endif
+#ifdef CHAT_REGDAYS
+ if ((now - cuser.firstlogin)/86400 < CHAT_REGDAYS)
+ {
+ vmsg("您還不夠資深喔");
+ return 0;
+ }
+#endif
+
+ memset(&chatbuf, 0, sizeof(chatbuf));
outs(" 驅車前往 請梢候........ ");
+
memset(&sin, 0, sizeof sin);
#ifdef __FreeBSD__
sin.sin_len = sizeof(sin);
@@ -312,6 +331,7 @@ t_chat(void)
chat_send(cfd, inbuf);
if (recv(cfd, inbuf, 3, 0) != 3) {
close(cfd);
+ vmsg("系統錯誤。");
return 0;
}
if (!strcmp(inbuf, CHAT_LOGIN_OK))
@@ -328,6 +348,8 @@ t_chat(void)
clrtoeol();
bell();
}
+ syncnow();
+ lastEnter = now;
add_io(cfd, 0);
@@ -423,6 +445,44 @@ t_chat(void)
}
} else if (ch == '\n' || ch == '\r') {
if (*inbuf) {
+
+#ifdef EXP_ANTIFLOOD
+ // prevent flooding */
+ static time4_t lasttime = 0;
+ static int flood = 0;
+
+ /* // debug anti flodding
+ move(b_lines-3, 0); clrtoeol();
+ prints("lasttime=%d, now=%d, flood=%d\n",
+ lasttime, now, flood);
+ refresh();
+ */
+ syncnow();
+ if (now - lasttime < 3 )
+ {
+ // 3 秒內洗半面是不行的 ((25-5)/2)
+ if( ++flood > 10 ){
+ // flush all input!
+ drop_input();
+ while (wait_input(1, 0))
+ {
+ if (num_in_buf())
+ drop_input();
+ else
+ tty_read((unsigned char*)inbuf, sizeof(inbuf));
+ }
+ drop_input();
+ vmsg("請勿大量剪貼或造成洗板面的效果。");
+ // log?
+ sleep(2);
+ continue;
+ }
+ } else {
+ lasttime = now;
+ flood = 0;
+ }
+#endif // anti-flood
+
chatting = chat_cmd(inbuf, cfd);
if (chatting == 0)
chatting = chat_send(cfd, inbuf);