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/Makefile | 5 ++-- src/map/clif.c | 82 +++++++++++------------------------------------------ src/map/tmw.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/map/tmw.h | 5 ++++ 4 files changed, 110 insertions(+), 68 deletions(-) create mode 100644 src/map/tmw.c create mode 100644 src/map/tmw.h diff --git a/src/map/Makefile b/src/map/Makefile index 0201e59..f02d43f 100644 --- a/src/map/Makefile +++ b/src/map/Makefile @@ -11,7 +11,7 @@ obj: COMMON_OBJ = ../common/core.o ../common/socket.o ../common/timer.o ../common/grfio.o ../common/db.o ../common/lock.o ../common/nullpo.o ../common/malloc.o LIBS = -lz -lm -map-server: obj/magic-interpreter-lexer.o obj/magic-interpreter-parser.o obj/magic-interpreter-base.o obj/magic-expr.o obj/magic-stmt.o obj/magic.o obj/map.o obj/chrif.o obj/clif.o obj/pc.o obj/npc.o obj/chat.o obj/path.o obj/itemdb.o obj/mob.o obj/script.o obj/storage.o obj/skill.o obj/atcommand.o obj/battle.o obj/intif.o obj/trade.o obj/party.o obj/guild.o $(COMMON_OBJ) +map-server: obj/tmw.o obj/magic-interpreter-lexer.o obj/magic-interpreter-parser.o obj/magic-interpreter-base.o obj/magic-expr.o obj/magic-stmt.o obj/magic.o obj/map.o obj/chrif.o obj/clif.o obj/pc.o obj/npc.o obj/chat.o obj/path.o obj/itemdb.o obj/mob.o obj/script.o obj/storage.o obj/skill.o obj/atcommand.o obj/battle.o obj/intif.o obj/trade.o obj/party.o obj/guild.o $(COMMON_OBJ) $(CC) -o ../../$@ $> $(LIBS) obj/%.o: %.c @@ -31,7 +31,7 @@ obj/magic-stmt.o: magic-stmt.c magic-expr-eval.h magic-interpreter-aux.h magic-e obj/magic.o: magic.c magic.h magic-expr.h magic-interpreter.h chrif.h clif.h npc.h pc.h mob.h chat.h skill.h itemdb.h storage.h party.h atcommand.h ../common/core.h ../common/timer.h ../common/db.h ../common/grfio.h ../common/mmo.h obj/map.o: map.c map.h chrif.h clif.h npc.h pc.h mob.h chat.h skill.h itemdb.h storage.h party.h atcommand.h ../common/core.h ../common/timer.h ../common/db.h ../common/grfio.h ../common/mmo.h obj/chrif.o: chrif.c map.h battle.h chrif.h clif.h intif.h pc.h npc.h ../common/socket.h ../common/timer.h ../common/mmo.h -obj/clif.o: magic.h clif.c map.h chrif.h clif.h mob.h intif.h pc.h npc.h itemdb.h chat.h script.h storage.h party.h guild.h atcommand.h atcommand.h ../common/socket.h ../common/timer.h ../common/mmo.h ../common/version.h +obj/clif.o: magic.h clif.c map.h chrif.h clif.h mob.h intif.h pc.h npc.h itemdb.h chat.h script.h storage.h party.h guild.h atcommand.h atcommand.h ../common/socket.h ../common/timer.h ../common/mmo.h ../common/version.h tmw.h obj/pc.o: pc.c map.h clif.h intif.h pc.h npc.h mob.h itemdb.h battle.h skill.h script.h party.h guild.h trade.h storage.h chat.h ../common/timer.h ../common/mmo.h ../common/db.h obj/npc.o: npc.c map.h npc.h clif.h pc.h script.h mob.h itemdb.h battle.h ../common/db.h ../common/timer.h ../common/mmo.h obj/chat.o: chat.c map.h clif.h pc.h chat.h ../common/db.h ../common/mmo.h @@ -46,6 +46,7 @@ obj/battle.o: battle.c battle.h skill.h map.h mob.h pc.h guild.h ../common/timer obj/intif.o: intif.c intif.h chrif.h clif.h party.h guild.h storage.h map.h battle.h ../common/socket.h ../common/mmo.h obj/trade.o: trade.c trade.h clif.h itemdb.h map.h pc.h npc.h ../common/mmo.h obj/party.o: party.c party.h clif.h intif.h pc.h map.h battle.h ../common/db.h ../common/socket.h ../common/timer.h ../common/mmo.h +obj/tmw.o: tmw.c tmw.h map.h clif.h clean: rm -rf *.o ../../map-server obj diff --git a/src/map/clif.c b/src/map/clif.c index eec126e..fa008cf 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -41,6 +41,7 @@ #include "script.h" #include "skill.h" #include "storage.h" +#include "tmw.h" #include "trade.h" #ifdef MEMWATCH @@ -6478,7 +6479,6 @@ void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd) { void clif_parse_GlobalMessage(int fd, struct map_session_data *sd) { // S 008c .w .?B char *message = (char *) malloc(RFIFOW(fd,2) + 128); char *buf = (char *) malloc(RFIFOW(fd,2) + 4); - unsigned int tick,elapsed = 0; nullpo_retv(sd); memset(message, '\0', RFIFOW(fd,2) + 128); @@ -6494,53 +6494,11 @@ void clif_parse_GlobalMessage(int fd, struct map_session_data *sd) { // S 008c < return; } - if (!pc_isGM(sd)) - { - 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, RFIFOP(fd,4), 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, RFIFOP(fd,4), 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) - clif_setwaitclose(fd); // forced to disconnect - } - else - return; // just ignore, dont ban. - } - - if (strlen(RFIFOP(fd,4)) >= battle_config.chat_maxline) - return; // ignore lines exceeding the max length in config. + int ret = tmw_CheckChatSpam(sd, message); + if (ret == 2) clif_setwaitclose(fd); + if (ret > 0) { + free(message); + return; } //printf("clif_parse_GlobalMessage: message: '%s'.\n", RFIFOP(fd,4)); @@ -6807,27 +6765,20 @@ void clif_parse_Restart(int fd, struct map_session_data *sd) { void clif_parse_Wis(int fd, struct map_session_data *sd) { // S 0096 .w .24B .?B // rewritten by [Yor] struct map_session_data *dstsd; int i; - int gmlen = strlen(RFIFOP(fd,28)); if (RFIFOW(fd,2)-28 <= 0) return; - char gmbuf[512]; - char *gm_command = ((gmlen+28) > sizeof(gmbuf)) ? (char *) malloc(gmlen + 28) : gmbuf; - // 24+3+(RFIFOW(fd,2)-28)+1 or 24+3+(strlen(RFIFOP(fd,28))+1 (size can be wrong with hacker) + char *message = (char *) malloc(RFIFOW(fd,2) + 128); + memset(message, '\0', RFIFOW(fd,2) + 128); - //printf("clif_parse_Wis: message: '%s'.\n", RFIFOP(fd,28)); - memset(gm_command, 0, gmlen); - sprintf(gm_command, "%s : %s", sd->status.name, RFIFOP(fd,28)); - if ((is_atcommand(fd, sd, gm_command, 0) != AtCommand_None) || - ( sd && sd->sc_data && - (sd->sc_data[SC_BERSERK].timer!=-1 || //バーサーク時は会話も不可 - sd->sc_data[SC_NOCHAT].timer!=-1 ) )) //チャット禁止 - { - if (gm_command != gmbuf) - free(gm_command); + int ret = tmw_CheckChatSpam(sd, message); + if (ret == 2) clif_setwaitclose(fd); + if (ret > 0) { + printf("returning from whisper (spam)\n"); + free(message); return; - } + } // searching destination character dstsd = map_nick2sd(RFIFOP(fd,4)); @@ -6864,9 +6815,8 @@ void clif_parse_Wis(int fd, struct map_session_data *sd) { // S 0096 .w + +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 diff --git a/src/map/tmw.h b/src/map/tmw.h new file mode 100644 index 0000000..44970e6 --- /dev/null +++ b/src/map/tmw.h @@ -0,0 +1,5 @@ +// + +#include "map.h" + +int tmw_CheckChatSpam(struct map_session_data *sd, char* message); -- cgit v1.2.3-60-g2f50