From 5edc982e3e2e0c6fc643b229d1c06ea75a618d15 Mon Sep 17 00:00:00 2001 From: hemagx Date: Sat, 23 Apr 2016 21:37:16 +0200 Subject: Added a flood protection to IRC Bot Now it's possible to send as many messages as possible without get kicked for flood. --- src/map/irc-bot.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/map/irc-bot.h') diff --git a/src/map/irc-bot.h b/src/map/irc-bot.h index dc67e2fe8..949305bc9 100644 --- a/src/map/irc-bot.h +++ b/src/map/irc-bot.h @@ -39,6 +39,11 @@ struct irc_func { void (*func)(int, char*, char*, char*, char*); }; +struct message_flood { + char message[IRC_MESSAGE_LENGTH]; + struct message_flood *next; +}; + struct irc_bot_interface { int fd; bool isIn, isOn; @@ -46,6 +51,15 @@ struct irc_bot_interface { unsigned char fails; uint32 ip; unsigned short port; + /* messages flood protection */ + bool flood_protection_enabled; + int flood_protection_rate; + int flood_protection_burst; + int64 last_message_tick; + int messages_burst_count; + int queue_tid; + struct message_flood *message_current; + struct message_flood *message_last; /* */ struct channel_data *channel; /* */ @@ -67,7 +81,9 @@ struct irc_bot_interface { int (*identify_timer) (int tid, int64 tick, int id, intptr_t data); int (*join_timer) (int tid, int64 tick, int id, intptr_t data); /* */ - void (*send)(char *str); + int (*queue_timer) (int tid, int64 tick, int id, intptr_t data); + void (*queue) (char *str); + void (*send)(char *str, bool force); void (*relay) (const char *name, const char *msg); /* */ void (*pong) (int fd, char *cmd, char *source, char *target, char *msg); -- cgit v1.2.3-60-g2f50