Ajout d'un système de censure pour le chat (insultes, pub pour un autre serveur)
This commit is contained in:
parent
22916afa05
commit
3de34319b5
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<jardesc>
|
||||
<jar path="PandacraftUtils/jar_export/PandacraftUtils-2.2.1.jar"/>
|
||||
<jar path="PandacraftUtils/jar_export/PandacraftUtils-2.3.jar"/>
|
||||
<options buildIfNeeded="true" compress="true" descriptionLocation="/PandacraftUtils/make_jar.jardesc" exportErrors="true" exportWarnings="true" includeDirectoryEntries="false" overwrite="false" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/>
|
||||
<storedRefactorings deprecationInfo="true" structuralOnly="false"/>
|
||||
<selectedProjects/>
|
||||
|
@ -1,6 +1,6 @@
|
||||
name: PandacraftUtils
|
||||
main: net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils
|
||||
version: 2.2.1
|
||||
version: 2.3
|
||||
|
||||
|
||||
|
||||
|
@ -22,20 +22,80 @@ public class ConfigManager {
|
||||
instance = this;
|
||||
|
||||
|
||||
initChatAnalysisBadWord();
|
||||
initCommandAlias();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Configuration AFK
|
||||
*/
|
||||
|
||||
public int AFK_timeoutAutoAfkMessage = 60*5; // 5 min
|
||||
public int AFK_timeoutAutoAfkKick = 60*10; // 10 min
|
||||
|
||||
|
||||
public long AntiSpam_timeBeforeResendSameMessage = 30000;// 30 sec
|
||||
public long AntiSpam_timeBeforeResendSameCommand = 30000;// 30 sec
|
||||
public long AntiSpam_timePerCaracterForNewMessage = 100;// 0.1 sec
|
||||
public int AntiSpam_maxViolationLevel = 20;
|
||||
public int AntiSpam_nbSecondForOneVLDown = 10;
|
||||
|
||||
|
||||
/*
|
||||
* Configuration analyse du chat et des messages privés
|
||||
* (antispam, insultes, publicité)
|
||||
*/
|
||||
|
||||
public long ChatAnalysis_timeBeforeResendSameMessage = 30000;// 30 sec
|
||||
public long ChatAnalysis_timeBeforeResendSameCommand = 30000;// 30 sec
|
||||
public long ChatAnalysis_timePerCaracterForNewMessage = 100;// 0.1 sec
|
||||
public int ChatAnalysis_maxViolationLevel = 20;
|
||||
public int ChatAnalysis_nbSecondForOneVLDown = 10;
|
||||
|
||||
public List<String> ChatAnalysis_badWords; // les insultes
|
||||
|
||||
private void initChatAnalysisBadWord() {
|
||||
ChatAnalysis_badWords = new ArrayList<String>();
|
||||
|
||||
/*
|
||||
* Insultes
|
||||
*/
|
||||
ChatAnalysis_badWords.add("putes?");
|
||||
ChatAnalysis_badWords.add("conn?a(rd?|ss?e?)");
|
||||
ChatAnalysis_badWords.add("sal(o|au)pe?s?");
|
||||
ChatAnalysis_badWords.add("[ea]ncul(é|e|er|ai(s|t|))");
|
||||
ChatAnalysis_badWords.add("merdes?");
|
||||
ChatAnalysis_badWords.add("ni(qu|k)e? ta m(è|e|é)re?");
|
||||
ChatAnalysis_badWords.add("fil?s de putes?");
|
||||
ChatAnalysis_badWords.add("ta m(è|e|é)re? l(a|e) putes?");
|
||||
ChatAnalysis_badWords.add("ta m(è|e|é)re?");
|
||||
ChatAnalysis_badWords.add("tafiole?s?");
|
||||
ChatAnalysis_badWords.add("vas? te pendre");
|
||||
ChatAnalysis_badWords.add("fuck");
|
||||
ChatAnalysis_badWords.add("mother ?fuc?ker");
|
||||
ChatAnalysis_badWords.add("dick");
|
||||
ChatAnalysis_badWords.add("ass");
|
||||
ChatAnalysis_badWords.add("bitch");
|
||||
//ChatAnalysis_badWords.add("");
|
||||
|
||||
|
||||
/*
|
||||
* Pub pour des serveurs (avec sous domaines type *.mtxserv.fr ou nom de serveur connu genre Minefield)
|
||||
*/
|
||||
ChatAnalysis_badWords.add("minefield");
|
||||
ChatAnalysis_badWords.add("mineplex");
|
||||
ChatAnalysis_badWords.add("hypixel");
|
||||
//ChatAnalysis_badWords.add("");
|
||||
//ChatAnalysis_badWords.add("");
|
||||
//ChatAnalysis_badWords.add("");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Alias pour les commandes
|
||||
*/
|
||||
|
||||
public List<Map<String, String>> CommandAlias_alias;
|
||||
|
||||
|
@ -13,7 +13,7 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class ChatAnalysisManager implements Listener {
|
||||
|
||||
private ChatAnalysisPlayer[] aPlayers;
|
||||
private ChatAnalysisPlayer[] CAPlayers;
|
||||
|
||||
private PandacraftUtils plugin;
|
||||
|
||||
@ -23,7 +23,7 @@ public class ChatAnalysisManager implements Listener {
|
||||
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
|
||||
aPlayers = new ChatAnalysisPlayer[plugin.getServer().getMaxPlayers()];
|
||||
CAPlayers = new ChatAnalysisPlayer[plugin.getServer().getMaxPlayers()];
|
||||
|
||||
|
||||
// analyse des joueurs déjà en ligne (/reload)
|
||||
@ -35,7 +35,7 @@ public class ChatAnalysisManager implements Listener {
|
||||
public void onAsyncPlayerChat(AsyncPlayerChatEvent event)
|
||||
{
|
||||
try {
|
||||
getAPlayer(event.getPlayer()).onAsyncPlayerChat(event);
|
||||
getCAPlayer(event.getPlayer()).onAsyncPlayerChat(event);
|
||||
} catch (NullPointerException e) { }
|
||||
}
|
||||
|
||||
@ -43,18 +43,18 @@ public class ChatAnalysisManager implements Listener {
|
||||
public void onPlayerCommandPreprocess (PlayerCommandPreprocessEvent event)
|
||||
{
|
||||
try {
|
||||
getAPlayer(event.getPlayer()).onPlayerCommandPreprocess(event);
|
||||
getCAPlayer(event.getPlayer()).onPlayerCommandPreprocess(event);
|
||||
} catch (NullPointerException e) { }
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public ChatAnalysisPlayer getAPlayer(Player p)
|
||||
public ChatAnalysisPlayer getCAPlayer(Player p)
|
||||
{
|
||||
if (p == null || !p.isOnline())
|
||||
return null;
|
||||
for (ChatAnalysisPlayer ap : aPlayers)
|
||||
for (ChatAnalysisPlayer ap : CAPlayers)
|
||||
{
|
||||
if (ap != null && ap.getPlayer() == p)
|
||||
return ap;
|
||||
@ -68,8 +68,8 @@ public class ChatAnalysisManager implements Listener {
|
||||
public void onPlayerJoin (PlayerJoinEvent event)
|
||||
{
|
||||
int i=0;
|
||||
while (i<aPlayers.length && aPlayers[i] != null) i++;
|
||||
if (aPlayers[i] == null) aPlayers[i] = new ChatAnalysisPlayer(plugin, event.getPlayer());
|
||||
while (i<CAPlayers.length && CAPlayers[i] != null) i++;
|
||||
if (CAPlayers[i] == null) CAPlayers[i] = new ChatAnalysisPlayer(plugin, event.getPlayer());
|
||||
}
|
||||
|
||||
|
||||
@ -77,12 +77,12 @@ public class ChatAnalysisManager implements Listener {
|
||||
public void onPlayerQuit (PlayerQuitEvent event)
|
||||
{
|
||||
|
||||
for (int i=0; i<aPlayers.length; i++)
|
||||
for (int i=0; i<CAPlayers.length; i++)
|
||||
{
|
||||
if (aPlayers[i] == null)
|
||||
if (CAPlayers[i] == null)
|
||||
continue;
|
||||
if (aPlayers[i].getPlayer() == event.getPlayer())
|
||||
aPlayers[i] = null;
|
||||
if (CAPlayers[i].getPlayer() == event.getPlayer())
|
||||
CAPlayers[i] = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,18 +11,18 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.util.NumberConversions;
|
||||
|
||||
public class ChatAnalysisPlayer {
|
||||
private long time_before_resend_same_message = ConfigManager.getInstance().AntiSpam_timeBeforeResendSameMessage;// 30 sec
|
||||
private long time_before_resend_same_command = ConfigManager.getInstance().AntiSpam_timeBeforeResendSameCommand;// 30 sec
|
||||
private long time_before_resend_same_message = ConfigManager.getInstance().ChatAnalysis_timeBeforeResendSameMessage;// 30 sec
|
||||
private long time_before_resend_same_command = ConfigManager.getInstance().ChatAnalysis_timeBeforeResendSameCommand;// 30 sec
|
||||
|
||||
// définit si un message a été tapé super vite ou non
|
||||
/* pour un message reçu, on prends la durée depuis le message précédent,
|
||||
* et on le compare au produit de cette variable par le nombre de caractère du nouveau message
|
||||
* */
|
||||
private long time_per_caracter_for_new_message = ConfigManager.getInstance().AntiSpam_timePerCaracterForNewMessage;// 0.1 sec
|
||||
private long time_per_caracter_for_new_message = ConfigManager.getInstance().ChatAnalysis_timePerCaracterForNewMessage;// 0.1 sec
|
||||
|
||||
private int max_violation_level = ConfigManager.getInstance().AntiSpam_maxViolationLevel;
|
||||
private int max_violation_level = ConfigManager.getInstance().ChatAnalysis_maxViolationLevel;
|
||||
|
||||
private int nb_second_for_1_vl_down = ConfigManager.getInstance().AntiSpam_nbSecondForOneVLDown;
|
||||
private int nb_second_for_1_vl_down = ConfigManager.getInstance().ChatAnalysis_nbSecondForOneVLDown;
|
||||
|
||||
|
||||
|
||||
@ -52,11 +52,12 @@ public class ChatAnalysisPlayer {
|
||||
private void addVL(int nb)
|
||||
{
|
||||
violation_level += nb;
|
||||
plugin.getLogger().info("ViolationLevel for player "+player.getDisplayName()+"§r : +"+nb+" -> "+violation_level);
|
||||
if (violation_level >= max_violation_level)
|
||||
Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
player.kickPlayer("Ralentissez la cadance, les spams sont interdits !");
|
||||
player.kickPlayer("Les spams/insultes/publicités sont interdits !");
|
||||
}
|
||||
}, 1L);
|
||||
|
||||
@ -95,6 +96,8 @@ public class ChatAnalysisPlayer {
|
||||
event.getPlayer().sendMessage(ChatColor.RED+"Evitez de renvoyer le même message !");
|
||||
if (violation_level >= max_violation_level/2)
|
||||
event.setCancelled(true);
|
||||
else
|
||||
event.setMessage(analyseString(message));
|
||||
addVL(5);
|
||||
return;
|
||||
}
|
||||
@ -107,6 +110,7 @@ public class ChatAnalysisPlayer {
|
||||
|
||||
event.getPlayer().sendMessage(ChatColor.RED+"Vous parlez un peu trop vite, ralentissez x)");
|
||||
addVL(4);
|
||||
event.setMessage(analyseString(message));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -129,47 +133,112 @@ public class ChatAnalysisPlayer {
|
||||
return;
|
||||
if (event.getPlayer().hasPermission("pandacraft.antispam.exempt"))
|
||||
return;
|
||||
String[] command_line = event.getMessage().split(" ");
|
||||
String command_line = event.getMessage();
|
||||
String[] command_line_split = event.getMessage().split(" ");
|
||||
long time = System.currentTimeMillis();
|
||||
String commande = command_line[0].substring(1);
|
||||
if (commande.equalsIgnoreCase("afk")
|
||||
|| commande.equalsIgnoreCase("away")
|
||||
|| commande.equalsIgnoreCase("time")
|
||||
|| commande.equalsIgnoreCase("day")
|
||||
|| commande.equalsIgnoreCase("night")
|
||||
|| commande.equalsIgnoreCase("me")
|
||||
|| commande.equalsIgnoreCase("action")
|
||||
|| commande.equalsIgnoreCase("describe")
|
||||
|| commande.equalsIgnoreCase("tpa")
|
||||
|| commande.equalsIgnoreCase("call")
|
||||
|| commande.equalsIgnoreCase("tpask")
|
||||
|| commande.equalsIgnoreCase("r")
|
||||
|| commande.equalsIgnoreCase("reply")
|
||||
|| commande.equalsIgnoreCase("msg")
|
||||
|| commande.equalsIgnoreCase("m")
|
||||
|| commande.equalsIgnoreCase("tell")
|
||||
|| commande.equalsIgnoreCase("t")
|
||||
|| commande.equalsIgnoreCase("whisper")
|
||||
|| commande.equalsIgnoreCase("w")
|
||||
|| commande.equalsIgnoreCase("mail")
|
||||
|| commande.equalsIgnoreCase("email"))
|
||||
String commande = command_line_split[0].substring(1).toLowerCase();
|
||||
|
||||
if (commande.equals("")) return;
|
||||
|
||||
// traitement du contenu des messages (si elle existe, comme MP ou /me)
|
||||
// ici, le message, c'est dès le permier paramètre
|
||||
if ((commande.equals("me")
|
||||
|| commande.equals("action")
|
||||
|| commande.equals("describe")
|
||||
|| commande.equals("r")
|
||||
|| commande.equals("reply"))
|
||||
&& command_line_split.length > 1) {
|
||||
try {
|
||||
String message = command_line.substring(1+commande.length()+1); // "/"+commande+" "
|
||||
message = analyseString(message);
|
||||
command_line = "/"+commande+" "+message;
|
||||
} catch (IndexOutOfBoundsException e) { }
|
||||
|
||||
}
|
||||
// ici, le message, c'est dès le deuxième paramètre
|
||||
else if((commande.equals("msg")
|
||||
|| commande.equals("m")
|
||||
|| commande.equals("tell")
|
||||
|| commande.equals("t")
|
||||
|| commande.equals("whisper")
|
||||
|| commande.equals("w"))
|
||||
&& command_line_split.length > 2) {
|
||||
try {
|
||||
String message = command_line.substring(1+commande.length()
|
||||
+1+command_line_split[1].length()
|
||||
+1); // "/"+commande+" "+pseudo+" "
|
||||
message = analyseString(message);
|
||||
command_line = "/"+commande+" "+command_line_split[1]+" "+message;
|
||||
} catch (IndexOutOfBoundsException e) { }
|
||||
}
|
||||
// ici, le message, c'est dès le troisième paramètre
|
||||
else if((commande.equals("mail")
|
||||
|| commande.equals("email"))
|
||||
&& command_line_split.length > 3) {
|
||||
try {
|
||||
String message = command_line.substring(1+commande.length()
|
||||
+1+command_line_split[1].length()
|
||||
+1+command_line_split[2].length()
|
||||
+1); // "/"+commande+" "+sub_command+" "+pseudo+" "
|
||||
message = analyseString(message);
|
||||
command_line = "/"+commande+" "+command_line_split[1]+" "+command_line_split[2]+" "+message;
|
||||
} catch (IndexOutOfBoundsException e) { }
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (commande.equals("afk")
|
||||
|| commande.equals("away")
|
||||
|| commande.equals("time")
|
||||
|| commande.equals("day")
|
||||
|| commande.equals("night")
|
||||
|| commande.equals("me")
|
||||
|| commande.equals("action")
|
||||
|| commande.equals("describe")
|
||||
|| commande.equals("tpa")
|
||||
|| commande.equals("call")
|
||||
|| commande.equals("tpask")
|
||||
|| commande.equals("r")
|
||||
|| commande.equals("reply")
|
||||
|| commande.equals("msg")
|
||||
|| commande.equals("m")
|
||||
|| commande.equals("tell")
|
||||
|| commande.equals("t")
|
||||
|| commande.equals("whisper")
|
||||
|| commande.equals("w")
|
||||
|| commande.equals("mail")// reste à traiter pour la censure
|
||||
|| commande.equals("email"))// reste à traiter pour la censure
|
||||
{
|
||||
if (last_command != null)
|
||||
{
|
||||
if (last_command.equals(event.getMessage()) && time - last_command_time < time_before_resend_same_command)
|
||||
if (last_command.equals(command_line) && time - last_command_time < time_before_resend_same_command)
|
||||
{
|
||||
event.getPlayer().sendMessage(ChatColor.RED+"Patientez avant de renvoyer cette commande !");
|
||||
if (violation_level >= max_violation_level/2)
|
||||
event.setCancelled(true);
|
||||
addVL(5);
|
||||
event.setMessage(command_line);
|
||||
return;
|
||||
}
|
||||
}
|
||||
removeVL(NumberConversions.floor(((time - last_command_time)/1000)/nb_second_for_1_vl_down));
|
||||
|
||||
last_command = event.getMessage();
|
||||
last_command = command_line;
|
||||
last_command_time = time;
|
||||
|
||||
event.setMessage(command_line);
|
||||
}
|
||||
|
||||
}
|
||||
@ -182,7 +251,7 @@ public class ChatAnalysisPlayer {
|
||||
|
||||
// évite les suites d'au moins 4 caractàres à la suite
|
||||
char[] cs = s.toCharArray();
|
||||
String ret = s.substring(0, (s.length()>=3)?3:s.length());
|
||||
String r = s.substring(0, (s.length()>=3)?3:s.length());
|
||||
int nb_duplicated_char = 0;
|
||||
for (int i=3; i<cs.length; i++)
|
||||
{
|
||||
@ -192,7 +261,7 @@ public class ChatAnalysisPlayer {
|
||||
continue;
|
||||
}
|
||||
|
||||
ret = ret.concat(String.valueOf(cs[i]));
|
||||
r = r.concat(String.valueOf(cs[i]));
|
||||
}
|
||||
|
||||
if (nb_duplicated_char > 0)
|
||||
@ -202,13 +271,13 @@ public class ChatAnalysisPlayer {
|
||||
|
||||
}
|
||||
|
||||
s = ret;
|
||||
s = r;
|
||||
char[] sChar = s.toCharArray();
|
||||
char[] minChar = s.toLowerCase().toCharArray();
|
||||
|
||||
|
||||
// vérification des majuscules
|
||||
if (sChar.length > 10)
|
||||
if (sChar.length > 5)
|
||||
{
|
||||
int nb_caps = 0;
|
||||
for (int i=0; i<sChar.length; i++)
|
||||
@ -220,12 +289,37 @@ public class ChatAnalysisPlayer {
|
||||
// si plus de 70% des caractères sont majuscules
|
||||
// ou plus de 20 majuscules
|
||||
addVL(4);
|
||||
ret = s.toLowerCase();
|
||||
s = s.toLowerCase();
|
||||
player.sendMessage(ChatColor.RED+"Il y a trop de majuscules dans votre message, faites attention avant d'envoyer votre message ;)");
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
|
||||
|
||||
// traiter les insultes et masquage Pub ici
|
||||
|
||||
|
||||
// adresse IPv4 basique
|
||||
if (s.matches("(.*)([0-9]{1,3}\\.){3}[0-9]{1,3}(:[0-9]{1,5})?(.*)"))
|
||||
{
|
||||
s = s.replaceAll("[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}", "**.**.**.**");
|
||||
addVL(3);
|
||||
}
|
||||
|
||||
|
||||
// pour chaque insultes présentes dans la configuration du plugin
|
||||
for (String regex : ConfigManager.getInstance().ChatAnalysis_badWords)
|
||||
{
|
||||
if (s.matches("(?i:(.+[^a-zA-Z]|)"+regex+"(|[^a-zA-Z].+))"))
|
||||
{
|
||||
s = s.replaceAll("(?i:"+regex+")", "*****");
|
||||
addVL(5);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return s;
|
||||
|
||||
}
|
||||
|
||||
|
@ -147,8 +147,8 @@ public class CommandList implements CommandExecutor {
|
||||
{
|
||||
try
|
||||
{
|
||||
int vl = plugin.chatAnalysisManager.getAPlayer(p).getVL();
|
||||
int max_vl = plugin.chatAnalysisManager.getAPlayer(p).getMaxVL();
|
||||
int vl = plugin.chatAnalysisManager.getCAPlayer(p).getVL();
|
||||
int max_vl = plugin.chatAnalysisManager.getCAPlayer(p).getMaxVL();
|
||||
aff_list.add("§f"+name+"§r - §7"+vl+"/"+max_vl);
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user