diff options
-rw-r--r-- | src/map/tmw.c | 160 | ||||
-rw-r--r-- | src/map/tmw.h | 6 |
2 files changed, 75 insertions, 91 deletions
diff --git a/src/map/tmw.c b/src/map/tmw.c index 3c506c5..7070331 100644 --- a/src/map/tmw.c +++ b/src/map/tmw.c @@ -30,7 +30,7 @@ #include "skill.h" #include "storage.h" #include "trade.h" - + int tmw_CheckChatSpam (struct map_session_data *sd, char *message) { nullpo_retr (1, sd); @@ -78,20 +78,7 @@ 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 && !sd->auto_ban_info.in_progress) - { - 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); - - sd->auto_ban_info.in_progress = 1; - - 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); - } + tmw_AutoBan(sd, "chat", battle_config.chat_spam_ban); return 1; } @@ -109,51 +96,6 @@ 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) -{ - int count, lame; - - // Ignore the name - message += strlen (sd->status.name); - - for (count = lame = 0; *message; message++, count++) - if (isupper (*message) || ispunct (*message)) - lame++; - - if (count > 7 && lame > count / 2) - return (1); - - return (0); -} - -// Sends a whisper to all GMs -void tmw_GmHackMsg (const char *fmt, ...) -{ - char buf[512]; - va_list ap; - - va_start (ap, fmt); - vsnprintf (buf, 511, fmt, ap); - va_end (ap); - - char outbuf[512 + 5]; - strcpy (outbuf, "[GM] "); - strcat (outbuf, buf); - - intif_wis_message_to_gm (wisp_server_name, - battle_config.hack_info_GM_level, outbuf, - strlen (outbuf) + 1); -} - int tmw_CheckTradeSpam (struct map_session_data *sd) { nullpo_retr (1, sd); @@ -174,21 +116,7 @@ int tmw_CheckTradeSpam (struct map_session_data *sd) { sd->trades_in = 0; - if (battle_config.trade_spam_ban > 0 - && !sd->auto_ban_info.in_progress) - { - 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); - - sd->auto_ban_info.in_progress = 1; - - 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); - } + tmw_AutoBan(sd, "trade", battle_config.trade_spam_ban); return 1; } @@ -223,20 +151,7 @@ int tmw_CheckSitSpam (struct map_session_data *sd) { sd->sits_in = 0; - if (battle_config.sit_spam_ban > 0 && !sd->auto_ban_info.in_progress) - { - 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); - - sd->auto_ban_info.in_progress = 1; - - 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); - } + tmw_AutoBan(sd, "sit", battle_config.sit_spam_ban); return 1; } @@ -250,3 +165,70 @@ int tmw_CheckSitSpam (struct map_session_data *sd) return 0; } + +void tmw_AutoBan(struct map_session_data *sd, char *reason, int length) +{ + char anotherbuf[512]; + + if (length == 0 || sd->auto_ban_info.in_progress) + return; + + sd->auto_ban_info.in_progress = 1; + + tmw_GmHackMsg ("%s has been autobanned for %s spam", + sd->status.name, reason); + + gm_log ("%s(%d,%d) Server : @autoban %s %dh (%s spam)", + map[sd->bl.m].name, sd->bl.x, sd->bl.y, + sd->status.name, length, reason); + + snprintf(anotherbuf, 511, "You have been banned for %s spamming. Please do not spam.", reason); + clif_displaymessage (sd->fd, anotherbuf); + chrif_char_ask_name (-1, sd->status.name, 2, 0, 0, 0, length, 0, 0); // type: 2 - ban (year, month, day, hour, minute, second) + clif_setwaitclose (sd->fd); +} + +// 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) +{ + int count, lame; + + // Ignore the name + message += strlen (sd->status.name); + + for (count = lame = 0; *message; message++, count++) + if (isupper (*message) || ispunct (*message)) + lame++; + + if (count > 7 && lame > count / 2) + return (1); + + return (0); +} + +// Sends a whisper to all GMs +void tmw_GmHackMsg (const char *fmt, ...) +{ + char buf[512]; + va_list ap; + + va_start (ap, fmt); + vsnprintf (buf, 511, fmt, ap); + va_end (ap); + + char outbuf[512 + 5]; + strcpy (outbuf, "[GM] "); + strcat (outbuf, buf); + + intif_wis_message_to_gm (wisp_server_name, + battle_config.hack_info_GM_level, outbuf, + strlen (outbuf) + 1); +} diff --git a/src/map/tmw.h b/src/map/tmw.h index e23aa51..bf5fce0 100644 --- a/src/map/tmw.h +++ b/src/map/tmw.h @@ -3,8 +3,10 @@ #include "map.h" int tmw_CheckChatSpam (struct map_session_data *sd, char *message); +int tmw_CheckTradeSpam (struct map_session_data *sd); +int tmw_CheckSitSpam (struct map_session_data *sd); 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); -int tmw_CheckSitSpam (struct map_session_data *sd); +void tmw_AutoBan(struct map_session_data *sd, char *reason, int length); + |