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/channel.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'src/map/channel.c') diff --git a/src/map/channel.c b/src/map/channel.c index e4e3d069d..f36388bca 100644 --- a/src/map/channel.c +++ b/src/map/channel.c @@ -609,7 +609,10 @@ void read_channels_config(void) local_autojoin = 0, ally_autojoin = 0, allow_user_channel_creation = 0, irc_enabled = 0, - irc_autojoin = 0; + irc_autojoin = 0, + irc_flood_protection_rate = 0, + irc_flood_protection_burst = 0, + irc_flood_protection_enabled = 0; if( !libconfig->setting_lookup_string(settings, "map_local_channel_name", &local_name) ) local_name = "map"; @@ -686,7 +689,6 @@ void read_channels_config(void) libconfig->setting_lookup_bool(settings, "map_local_channel_autojoin", &local_autojoin); libconfig->setting_lookup_bool(settings, "ally_channel_autojoin", &ally_autojoin); libconfig->setting_lookup_bool(settings, "irc_channel_autojoin", &irc_autojoin); - if (local_autojoin) channel->config->local_autojoin = true; if (ally_autojoin) @@ -694,6 +696,26 @@ void read_channels_config(void) if (irc_autojoin) channel->config->irc_autojoin = true; + libconfig->setting_lookup_int(settings, "irc_flood_protection_burst", &irc_flood_protection_burst); + + if (irc_flood_protection_enabled) { + ircbot->flood_protection_enabled = true; + + libconfig->setting_lookup_bool(settings, "irc_flood_protection_enabled", &irc_flood_protection_enabled); + libconfig->setting_lookup_int(settings, "irc_flood_protection_rate", &irc_flood_protection_rate); + + if (irc_flood_protection_rate > 0) + ircbot->flood_protection_rate = irc_flood_protection_rate; + else + ircbot->flood_protection_rate = 1000; + if (irc_flood_protection_burst > 0) + ircbot->flood_protection_burst = irc_flood_protection_burst; + else + ircbot->flood_protection_burst = 3; + } else { + ircbot->flood_protection_enabled = false; + } + libconfig->setting_lookup_bool(settings, "allow_user_channel_creation", &allow_user_channel_creation); if( allow_user_channel_creation ) -- cgit v1.2.3-70-g09d2