From 79874123b9e62276c67bc2f8e300d6b88d43e151 Mon Sep 17 00:00:00 2001 From: MadCamel Date: Wed, 26 Aug 2009 18:32:32 -0400 Subject: Autobans are now logged, more chat spam improvements Added a timeout to the total repeat counter. 5 minutes by default. --- src/map/atcommand.c | 38 +++++++++++++++++++++++++------------- src/map/atcommand.h | 1 + src/map/map.h | 1 + src/map/pc.c | 3 ++- src/map/tmw.c | 25 +++++++++++++++---------- 5 files changed, 44 insertions(+), 24 deletions(-) diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 39e62da..de44d77 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -544,13 +544,27 @@ int get_atcommand_level(const AtCommandType type) { /*======================================== * At-command logging */ +void log_atcommand(struct map_session_data *sd, const char *fmt, ...) { + char message[512]; + va_list ap; -int last_logfile_nr = 0; -char *gm_logfile_name = NULL; -static FILE *gm_logfile = NULL; + va_start(ap, fmt); + vsnprintf(message, 511, fmt, ap); + va_end(ap); -void log_atcommand(struct map_session_data *sd, const char *fmt, ...) -{ + if (pc_isGM(sd)) + gm_log("%s(%d,%d) %s : %s", map[sd->bl.m].name, sd->bl.x, + sd->bl.y, sd->status.name, message); +} + +char *gm_logfile_name = NULL; +/*========================================== + * Log a timestamped line to GM log file + *------------------------------------------ + */ +void gm_log(const char *fmt, ...) { + static int last_logfile_nr = 0; + static FILE *gm_logfile = NULL; time_t time_v; struct tm ctime; int month, year, logfile_nr; @@ -588,16 +602,14 @@ void log_atcommand(struct map_session_data *sd, const char *fmt, ...) last_logfile_nr = logfile_nr; } - if (gm_logfile && pc_isGM(sd)) { - fprintf(gm_logfile, "[%04d-%02d-%02d %02d:%02d:%02d] %s(%d,%d) %s : %s\n", - year, month, ctime.tm_mday, - ctime.tm_hour, ctime.tm_min, ctime.tm_sec, - map[sd->bl.m].name, sd->bl.x, sd->bl.y, sd->status.name, - message); - fflush(gm_logfile); - } + fprintf(gm_logfile, "[%04d-%02d-%02d %02d:%02d:%02d] %s\n", + year, month, ctime.tm_mday, ctime.tm_hour, + ctime.tm_min, ctime.tm_sec, message); + + fflush(gm_logfile); } + /*========================================== *is_atcommand @コマンドに存在するかどうか確認する *------------------------------------------ diff --git a/src/map/atcommand.h b/src/map/atcommand.h index af16b0c..df996b6 100644 --- a/src/map/atcommand.h +++ b/src/map/atcommand.h @@ -214,6 +214,7 @@ int atcommand_config_read(const char *cfgName); int msg_config_read(const char *cfgName); void log_atcommand(struct map_session_data *sd, const char *fmt, ...); +void gm_log(const char *fmt, ...); #endif diff --git a/src/map/map.h b/src/map/map.h index 0516d3a..c4e914f 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -356,6 +356,7 @@ struct map_session_data { short sg_count; time_t chat_reset_due; + time_t chat_repeat_reset_due; int chat_lines_in; int chat_total_repeats; char chat_lastmsg[513]; diff --git a/src/map/pc.c b/src/map/pc.c index 0c304ce..d7c2b28 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -816,7 +816,8 @@ int pc_authok(int id, int login_id2, time_t connect_until_time, short tmw_versio } } - sd->chat_reset_due = sd->chat_lines_in = sd->chat_total_repeats = 0; + // Initialize antispam vars + sd->chat_reset_due = sd->chat_lines_in = sd->chat_total_repeats = sd->chat_repeat_reset_due = 0; sd->chat_lastmsg[0] = '\0'; sd->trade_reset_due = sd->trades_in = 0; sd->sit_reset_due = sd->sits_in = 0; diff --git a/src/map/tmw.c b/src/map/tmw.c index dcb0b29..3923694 100644 --- a/src/map/tmw.c +++ b/src/map/tmw.c @@ -36,13 +36,18 @@ int tmw_CheckChatSpam(struct map_session_data *sd, char* message) { nullpo_retr(1, sd); time_t now = time(NULL); - if (pc_isGM(sd)) return 0; +// if (pc_isGM(sd)) return 0; if (now > sd->chat_reset_due) { sd->chat_reset_due = now + battle_config.chat_spam_threshold; sd->chat_lines_in = 0; } + if (now > sd->chat_repeat_reset_due) { + sd->chat_repeat_reset_due = now + (battle_config.chat_spam_threshold * 60); + sd->chat_total_repeats = 0; + } + sd->chat_lines_in++; // Penalty for repeats. @@ -64,10 +69,10 @@ int tmw_CheckChatSpam(struct map_session_data *sd, char* message) { sd->chat_lines_in = sd->chat_total_repeats = 0; if (battle_config.chat_spam_ban > 0) { - tmw_GmHackMsg("Spam detected from character '%s' (account: %d)", sd->status.name, sd->status.account_id); - clif_displaymessage(sd->fd, "You have been banned for spamming. Please do not spam."); - tmw_GmHackMsg("This player has been banned for %d hour(s).", battle_config.chat_spam_ban); + tmw_GmHackMsg("%s has been autobanned for chat spam", sd->status.name); + gm_log("server(0,0) Server : @autoban %s %dh (chat spam)", sd->status.name, battle_config.chat_spam_ban); + clif_displaymessage(sd->fd, "You have been banned for spamming. Please do not spam."); chrif_char_ask_name(-1, sd->status.name, 2, 0, 0, 0, battle_config.chat_spam_ban, 0, 0); // type: 2 - ban (year, month, day, hour, minute, second) clif_setwaitclose(sd->fd); } @@ -142,10 +147,10 @@ int tmw_CheckTradeSpam(struct map_session_data *sd) { sd->trades_in = 0; if (battle_config.trade_spam_ban > 0) { - tmw_GmHackMsg("Trade spam detected from character '%s' (account: %d)", sd->status.name, sd->status.account_id); - clif_displaymessage(sd->fd, "You have been banned for trade spamming. Please do not trade spam."); - tmw_GmHackMsg("This player has been banned for %d hour(s).", battle_config.trade_spam_ban); + tmw_GmHackMsg("%s has been autobanned for trade spam", sd->status.name); + gm_log("server(0,0) Server : @autoban %s %dh (trade spam)", sd->status.name, battle_config.trade_spam_ban); + clif_displaymessage(sd->fd, "You have been banned for trade spamming. Please do not trade spam."); chrif_char_ask_name(-1, sd->status.name, 2, 0, 0, 0, battle_config.trade_spam_ban, 0, 0); // type: 2 - ban (year, month, day, hour, minute, second) clif_setwaitclose(sd->fd); } @@ -177,10 +182,10 @@ int tmw_CheckSitSpam(struct map_session_data *sd) { sd->sits_in = 0; if (battle_config.sit_spam_ban > 0) { - tmw_GmHackMsg("Sit spam detected from character '%s' (account: %d)", sd->status.name, sd->status.account_id); - clif_displaymessage(sd->fd, "You have been banned for sit spamming. Please do not sit spam."); - tmw_GmHackMsg("This player has been banned for %d hour(s).", battle_config.sit_spam_ban); + tmw_GmHackMsg("%s has been autobanned for sit spam", sd->status.name); + gm_log("server(0,0) Server : @autoban %s %dh (sit spam)", sd->status.name, battle_config.sit_spam_ban); + clif_displaymessage(sd->fd, "You have been banned for sit spamming. Please do not sit spam."); chrif_char_ask_name(-1, sd->status.name, 2, 0, 0, 0, battle_config.sit_spam_ban, 0, 0); // type: 2 - ban (year, month, day, hour, minute, second) clif_setwaitclose(sd->fd); } -- cgit v1.2.3-70-g09d2