summaryrefslogtreecommitdiff
path: root/src/map/clif.c
diff options
context:
space:
mode:
authorDennis Friis <peavey@placid.dk>2008-04-10 01:04:30 +0000
committerDennis Friis <peavey@placid.dk>2008-04-10 01:04:30 +0000
commita870845a71dbe1879d6d316f0726c3f75e38249c (patch)
treeec1321e701bd8a821ed4ff2346533f948a794ab6 /src/map/clif.c
parent41b5cece10fb9b59e2b05796c54c4008b523f5b3 (diff)
downloadtmwa-a870845a71dbe1879d6d316f0726c3f75e38249c.tar.gz
tmwa-a870845a71dbe1879d6d316f0726c3f75e38249c.tar.bz2
tmwa-a870845a71dbe1879d6d316f0726c3f75e38249c.tar.xz
tmwa-a870845a71dbe1879d6d316f0726c3f75e38249c.zip
Add configurable anti spam system, with possible auto ban.
Diffstat (limited to 'src/map/clif.c')
-rw-r--r--src/map/clif.c51
1 files changed, 50 insertions, 1 deletions
diff --git a/src/map/clif.c b/src/map/clif.c
index f847a56..0a6559c 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -7397,7 +7397,7 @@ void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd) {
void clif_parse_GlobalMessage(int fd, struct map_session_data *sd) { // S 008c <len>.w <str>.?B
char *message = (char *) malloc(RFIFOW(fd,2) + 128);
char *buf = (char *) malloc(RFIFOW(fd,2) + 4);
-
+ int tick,elapsed = 0;
nullpo_retv(sd);
memset(message, '\0', RFIFOW(fd,2) + 128);
@@ -7413,6 +7413,55 @@ 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.
+ }
+
//printf("clif_parse_GlobalMessage: message: '%s'.\n", RFIFOP(fd,4));
if (strncmp(RFIFOP(fd,4), sd->status.name, strlen(sd->status.name)) != 0) {
printf("Hack on global message: character '%s' (account: %d), use an other name to send a (normal) message.\n", sd->status.name, sd->status.account_id);