diff --git a/make_jar.jardesc b/make_jar.jardesc index d92d8c8..36822c7 100644 --- a/make_jar.jardesc +++ b/make_jar.jardesc @@ -1,6 +1,6 @@ - + diff --git a/resources/plugin.yml b/resources/plugin.yml index 55e257d..ec8675e 100644 --- a/resources/plugin.yml +++ b/resources/plugin.yml @@ -1,6 +1,6 @@ name: PandacraftUtils main: net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils -version: 2.2.1 +version: 2.3 diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/ConfigManager.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/ConfigManager.java index 6d8e501..52d4b48 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/ConfigManager.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/ConfigManager.java @@ -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 ChatAnalysis_badWords; // les insultes + + private void initChatAnalysisBadWord() { + ChatAnalysis_badWords = new ArrayList(); + + /* + * 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> CommandAlias_alias; diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/chat_analyzer/ChatAnalysisManager.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/chat_analyzer/ChatAnalysisManager.java index 9ba377c..965fdac 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/chat_analyzer/ChatAnalysisManager.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/chat_analyzer/ChatAnalysisManager.java @@ -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 "+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 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