summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMadCamel <madcamel@gmail.com>2009-08-23 10:52:01 -0400
committerMadCamel <madcamel@gmail.com>2009-08-23 11:08:57 -0400
commit415983958551f0e7ff72bec2921a67918d96d130 (patch)
tree1f01b40acb8bb3dae186939f4d63589e90bf67a1 /src
parent3f230b8323518e90a0389d56ac0b4bbb5262f821 (diff)
downloadtmwa-415983958551f0e7ff72bec2921a67918d96d130.tar.gz
tmwa-415983958551f0e7ff72bec2921a67918d96d130.tar.bz2
tmwa-415983958551f0e7ff72bec2921a67918d96d130.tar.xz
tmwa-415983958551f0e7ff72bec2921a67918d96d130.zip
Improved chat spam detection
Repeats are now checked only to the length of the shortest line (last line, current line) so "SPAM!!" and "SPAM!!!!!" would be considered a repeat. Total repeats are now counted and a ban is triggered if they exceed battle_config.chat_spam_flood repeats, regardless of time frame.
Diffstat (limited to 'src')
-rw-r--r--src/map/map.h1
-rw-r--r--src/map/pc.c4
-rw-r--r--src/map/tmw.c44
-rw-r--r--src/map/tmw.h1
4 files changed, 28 insertions, 22 deletions
diff --git a/src/map/map.h b/src/map/map.h
index ad6575a..0516d3a 100644
--- a/src/map/map.h
+++ b/src/map/map.h
@@ -357,6 +357,7 @@ struct map_session_data {
time_t chat_reset_due;
int chat_lines_in;
+ int chat_total_repeats;
char chat_lastmsg[513];
time_t trade_reset_due;
diff --git a/src/map/pc.c b/src/map/pc.c
index 6f1cc86..0c304ce 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -816,11 +816,9 @@ int pc_authok(int id, int login_id2, time_t connect_until_time, short tmw_versio
}
}
- sd->chat_reset_due = sd->chat_lines_in = 0;
+ sd->chat_reset_due = sd->chat_lines_in = sd->chat_total_repeats = 0;
sd->chat_lastmsg[0] = '\0';
-
sd->trade_reset_due = sd->trades_in = 0;
-
sd->sit_reset_due = sd->sits_in = 0;
// message of the limited time of the account
diff --git a/src/map/tmw.c b/src/map/tmw.c
index 2331a23..dcb0b29 100644
--- a/src/map/tmw.c
+++ b/src/map/tmw.c
@@ -45,25 +45,23 @@ int tmw_CheckChatSpam(struct map_session_data *sd, char* message) {
sd->chat_lines_in++;
- if (message) {
- // Penalty for repeating
- if (strncmp(sd->chat_lastmsg, message, battle_config.chat_maxline) == 0)
- sd->chat_lines_in += battle_config.chat_lame_penalty;
-
- // Penalty for lame, it can stack on top of the repeat penalty.
- if (tmw_CheckChatLameness(sd, message))
- sd->chat_lines_in += battle_config.chat_lame_penalty;
-
- strncpy((char*)sd->chat_lastmsg, message, battle_config.chat_maxline);
+ // Penalty for repeats.
+ if (strncmp(sd->chat_lastmsg, message, tmw_ShorterStrlen(sd->chat_lastmsg, message)) == 0) {
+ sd->chat_lines_in += battle_config.chat_lame_penalty;
+ sd->chat_total_repeats++;
}
else {
- // No message means we're checking another type of spam.
- // Most other types are pretty lame..
- sd->chat_lines_in += battle_config.chat_lame_penalty;
+ sd->chat_total_repeats=0;
}
- if (sd->chat_lines_in >= battle_config.chat_spam_flood) {
- sd->chat_lines_in = 0;
+ // Penalty for lame, it can stack on top of the repeat penalty.
+ if (tmw_CheckChatLameness(sd, message))
+ sd->chat_lines_in += battle_config.chat_lame_penalty;
+
+ strncpy((char*)sd->chat_lastmsg, message, battle_config.chat_maxline);
+
+ if (sd->chat_lines_in >= battle_config.chat_spam_flood || sd->chat_total_repeats >= battle_config.chat_spam_flood) {
+ 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);
@@ -73,11 +71,12 @@ int tmw_CheckChatSpam(struct map_session_data *sd, char* message) {
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);
}
-
+
return 1;
}
- if (battle_config.chat_spam_ban && sd->chat_lines_in >= battle_config.chat_spam_warn) {
+ if (battle_config.chat_spam_ban &&
+ (sd->chat_lines_in >= battle_config.chat_spam_warn || sd->chat_total_repeats >= battle_config.chat_spam_warn)) {
clif_displaymessage(sd->fd, "WARNING : You are about to be automaticly banned for spam!");
clif_displaymessage(sd->fd, "WARNING : Please slow down, do not repeat, and do not SHOUT!");
}
@@ -85,6 +84,13 @@ int tmw_CheckChatSpam(struct map_session_data *sd, char* message) {
return 0;
}
+// Compares the length of two strings and returns that of the shorter
+int tmw_ShorterStrlen(char *s1, char *s2) {
+ int s1_len = strlen(s1);
+ int s2_len = strlen(s2);
+ return(s2_len >= s1_len ? s1_len : s2_len);
+}
+
// Returns true if more than 50% of input message is caps or punctuation
int tmw_CheckChatLameness(struct map_session_data *sd, char *message)
{
@@ -143,7 +149,7 @@ int tmw_CheckTradeSpam(struct map_session_data *sd) {
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);
}
-
+
return 1;
}
@@ -178,7 +184,7 @@ int tmw_CheckSitSpam(struct map_session_data *sd) {
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);
}
-
+
return 1;
}
diff --git a/src/map/tmw.h b/src/map/tmw.h
index 8580810..8248a71 100644
--- a/src/map/tmw.h
+++ b/src/map/tmw.h
@@ -3,6 +3,7 @@
#include "map.h"
int tmw_CheckChatSpam(struct map_session_data *sd, char* message);
+int tmw_ShorterStrlen(char *s1, char *s2);
int tmw_CheckChatLameness(struct map_session_data *sd, char *message);
void tmw_GmHackMsg(const char *fmt, ...);
int tmw_CheckTradeSpam(struct map_session_data *sd);