From 896a8d2b9f6f4a8b1ca70aac0aa25fa6fd3985e6 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Thu, 2 Apr 2009 22:04:36 -0600 Subject: Block whisper spam --- src/map/tmw.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 src/map/tmw.c (limited to 'src/map/tmw.c') diff --git a/src/map/tmw.c b/src/map/tmw.c new file mode 100644 index 0000000..c6bfc40 --- /dev/null +++ b/src/map/tmw.c @@ -0,0 +1,86 @@ +// + +#include "tmw.h" + +#include "socket.h" +#include "timer.h" +#include "malloc.h" +#include "version.h" +#include "nullpo.h" + +#include "atcommand.h" +#include "battle.h" +#include "chat.h" +#include "chrif.h" +#include "clif.h" +#include "guild.h" +#include "intif.h" +#include "itemdb.h" +#include "magic.h" +#include "map.h" +#include "mob.h" +#include "npc.h" +#include "party.h" +#include "pc.h" +#include "script.h" +#include "skill.h" +#include "storage.h" +#include "tmw.h" +#include "trade.h" + +#include + +int tmw_CheckChatSpam(struct map_session_data *sd, char* message) { + unsigned int tick,elapsed = 0; + nullpo_retr(1, sd); + + if (pc_isGM(sd)) return 0; + + tick = gettick(); + elapsed = tick - sd->chat_lastmsg_time; + sd->chat_lastmsg_time = tick; + + if (elapsed < battle_config.spam_time) + sd->chat_threshold++; + + sd->chat_threshold -= (int)(elapsed / (battle_config.spam_time/2)); + + if (sd->chat_threshold < 0) + sd->chat_threshold = 0; + + if (strncmp(sd->chat_lastmsg, message, battle_config.chat_maxline) == 0) + sd->chat_repeatmsg++; + else + sd->chat_repeatmsg--; + + if (sd->chat_repeatmsg < 0) + sd->chat_repeatmsg = 0; + + strncpy((char*)sd->chat_lastmsg, message, battle_config.chat_maxline); + + if (sd->chat_threshold > battle_config.spam_threshold || sd->chat_repeatmsg > battle_config.spam_threshold) { + sprintf(message, "Spam detected from character '%s' (account: %d), threshold was exceeded.", sd->status.name, sd->status.account_id); + printf("%s\n", message); + intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message, strlen(message) + 1); + + if (battle_config.spam_ban > 0) + sprintf(message, "This player has been banned for %d hours(s).", battle_config.spam_ban); + else + sprintf(message, "This player hasn't been banned (Ban option is disabled)."); + printf("%s\n", message); + intif_wis_message_to_gm(wisp_server_name, battle_config.hack_info_GM_level, message, strlen(message) + 1); + + if (battle_config.spam_ban > 0) + { + chrif_char_ask_name(-1, sd->status.name, 2, 0, 0, 0, battle_config.spam_ban, 0, 0); // type: 2 - ban (year, month, day, hour, minute, second) + return 2; // forced to disconnect + } + else + return 1; // just ignore, dont ban. + } + + if (strlen(message) >= battle_config.chat_maxline) + return 1; // ignore lines exceeding the max length in config. + + return 0; +} \ No newline at end of file -- cgit v1.2.3-60-g2f50