L2J Datapack Version: 5990
I add ChatFilter.java file to net/sf/l2j/gameserver/handler in l2 core with this code:
Code: Select all
/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * http://www.gnu.org/copyleft/gpl.html */ package net.sf.l2j.gameserver.handler; import java.sql.PreparedStatement;import java.sql.ResultSet;import java.util.List;import java.util.logging.Logger; import javolution.util.FastList;import net.sf.l2j.Config;import net.sf.l2j.L2DatabaseFactory;import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance; /** * @author Forsaiken */ public class ChatFilter{ private static Logger _log = Logger.getLogger(ChatFilter.class.getName()); private static ChatFilter _instance; public static ChatFilter getInstance() { if (_instance == null) _instance = new ChatFilter(); return _instance; } private List<String> _filterList; private ChatFilter() { loadFilterList(); } public void loadFilterList() { _filterList = new FastList<String>(); java.sql.Connection con = null; try { con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con.prepareStatement("SELECT word FROM sayfilter"); ResultSet rset = statement.executeQuery(); while (rset.next()) { _filterList.add(rset.getString("word").toLowerCase()); } } catch (Exception e) { _log.warning("Error loading Sayfilter from DB!"); } finally { try { con.close(); } catch(Exception e) {} } _log.info("Loaded "+_filterList.size()+" words!"); } public List<String> getFilterList() { return _filterList; } public void addWordToFilterList(L2PcInstance activeChar, String word) { String tmp = word.toLowerCase(); if (_filterList.contains(tmp)) { activeChar.sendMessage("Word: '" +tmp+ "' allready exists in table!"); return; } if (!_filterList.add(tmp)) { activeChar.sendMessage("Error adding word: "+tmp+"!"); return; } try { java.sql.Connection con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con.prepareStatement("INSERT INTO sayfilter VALUES (?)"); statement.setString(1, tmp); statement.execute(); statement.close(); activeChar.sendMessage("Word: "+tmp+" sussecfully added!"); } catch (Exception e) { activeChar.sendMessage("Error adding to DB, word: "+tmp+"!"); } } public void deleteWordFromFilterList(L2PcInstance activeChar, String word) { String tmp = word.toLowerCase(); if (!_filterList.contains(tmp)) { activeChar.sendMessage("Word: " +tmp+ " doesen`t exists in table!"); return; } if (!_filterList.remove(word)) { activeChar.sendMessage("Error deleting word: "+tmp+"!"); return; } try { java.sql.Connection con = L2DatabaseFactory.getInstance().getConnection(); PreparedStatement statement = con.prepareStatement("DELETE FROM sayfilter WHERE word = ?"); statement.setString(1, tmp); statement.execute(); statement.close(); activeChar.sendMessage("Word: "+tmp+" sussecfully removed!"); } catch (Exception e) { activeChar.sendMessage("Error deleting from DB, word: "+tmp+"!"); } } public final String filterText(L2PcInstance activeChar, final String text, final int type) { if (!Config.ENABLE_CHAT_FILTER) return text; for (final int chatType : Config.FILTERED_CHATS) { if (chatType == type) { int filteredWords = 0; String lowerCase = text.toLowerCase(); StringBuilder filtered = new StringBuilder(text); for (String word : _filterList) { while (lowerCase.contains(word)) { filteredWords++; int firstIndex = lowerCase.indexOf(word); filtered = filtered.replace(firstIndex, firstIndex + word.length(), "omg"); lowerCase = filtered.toString().toLowerCase(); } } if (Config.DEBUG) _log.info("Filtered " + filteredWords + "Words, from Character:" + activeChar.getName() + "!"); return filtered.toString(); } } return text; }}
and add to DP, gameserver\data\scripts\handlers\admincommandhandlers\ file AdminChatFilter.java with this code:
Code: Select all
/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * http://www.gnu.org/copyleft/gpl.html */package handlers.admincommandhandlers; import java.util.Collections;import java.util.Comparator;import java.util.List; import net.sf.l2j.gameserver.handler.ChatFilter;import javolution.text.TextBuilder;import javolution.util.FastList;import net.sf.l2j.gameserver.handler.IAdminCommandHandler;import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage; /** * Forsaiken */public final class AdminChatFilter implements IAdminCommandHandler{ private static final String[] ADMIN_COMMANDS = { "admin_textfilter", "admin_textfilter_add", "admin_textfilter_remove" }; public boolean useAdminCommand(String command, L2PcInstance activeChar) { if (command.equalsIgnoreCase("admin_textfilter")) showWordList(activeChar, 0, "ALL"); else if (command.startsWith("admin_textfilter ")) { String[] params = command.split(" "); if (params.length != 3) return false; showWordList(activeChar, Integer.valueOf(params[1]), params[2]); } else if (command.startsWith("admin_textfilter_add ")) { String[] params = command.split(" "); if (params.length < 2) return false; TextBuilder word = new TextBuilder(params[1]); if (params.length > 2) { for (int i = 2; i < params.length; i++) { word.append(" ").append(params[i]); } } ChatFilter.getInstance().addWordToFilterList(activeChar, word.toString()); showWordList(activeChar, 0, "ALL"); } else if (command.startsWith("admin_textfilter_delete ")) { String[] params = command.split(" "); if (params.length < 2) return false; TextBuilder word = new TextBuilder(params[1]); if (params.length > 2) { for (int i = 2; i < params.length; i++) { word.append(" ").append(params[i]); } } ChatFilter.getInstance().deleteWordFromFilterList(activeChar, word.toString()); showWordList(activeChar, 0, "ALL"); } return true; } private List<String> getWordsByFirstLetter(String letter) { List<String> sorted = new FastList<String>(); for (String word : ChatFilter.getInstance().getFilterList()) { if (word.startsWith(letter)) sorted.add(word); } return sorted; } public static class WordComparator implements Comparator<String> { public int compare(String s1, String s2) { return s1.compareTo(s2); } } public void showWordList(L2PcInstance activeChar, int page, String letter) { List<String> list = null; if (!letter.equals("ALL")) list = getWordsByFirstLetter(letter); else list = ChatFilter.getInstance().getFilterList(); Collections.sort(list, new WordComparator()); int MaxCharactersPerPage = 10; int MaxPages = list.size() / MaxCharactersPerPage; if (list.size() > MaxCharactersPerPage * MaxPages) MaxPages++; if (page > MaxPages) page = MaxPages; int ListStart = MaxCharactersPerPage * page; int ListEnd = list.size(); if (ListEnd - ListStart > MaxCharactersPerPage) ListEnd = ListStart + MaxCharactersPerPage; TextBuilder replyMSG = new TextBuilder("<html><body><table>"); if (!letter.equals("ALL")) { replyMSG.append("<tr><td>Showing only: ").append(letter).append("</td></tr>"); } replyMSG.append("<tr><td>Show only: <combobox width=90 var=letter list=\"ALL;A;B;C;D;E;F;G;H;I;J;K;L;M;N;O;P;Q;R;S;T;U;V;W;X;Y;Z\"></td></tr>"); replyMSG.append("<tr><td><a action=\"bypass -h admin_textfilter").append(page).append(" $letter\">SHOW</a></td></tr>"); replyMSG.append("<tr><td>Page: "); for (int x = 0; x < MaxPages; x++) { replyMSG.append("<a action=\"bypass -h admin_textfilter").append(x).append(" ").append(letter).append("\">").append(x + 1).append("</a>"); replyMSG.append(", "); } replyMSG.append("</td></tr><tr><td><table width=270><tr><td width=200>word:</td><td width=70>delete:</td></tr>"); for (int i = ListStart; i < ListEnd; i++) { replyMSG.append("<tr><td width=200>").append(list.get(i)).append("</td><td width=70><a action=\"bypass -h admin_textfilter_delete ").append(list.get(i)).append("\">delete</a></td></tr>"); } replyMSG.append("<tr></tr><tr><td width=200><edit var=\"word\" width=180></td><td width=70><a action=\"bypass -h admin_textfilter_add $word\">add</a></td></tr>"); replyMSG.append("</table></td></tr></table><br>"); NpcHtmlMessage adminReply = new NpcHtmlMessage(5); adminReply.setHtml(replyMSG.toString()); activeChar.sendPacket(adminReply); } public String[] getAdminCommandList() { return ADMIN_COMMANDS; }}
Code: Select all
import handlers.admincommandhandlers.AdminChatFilter;
Code: Select all
public class MasterHandler{ private static Logger _log = Logger.getLogger(MasterHandler.class.getName()); private static void loadAdminHandlers() { AdminCommandHandler.getInstance().registerAdminCommandHandler(new AdminChatFilter());...
Code: Select all
Client: [Character: Driada - Account: driada - IP: 89.254.199.37] - Failed running: [C] 5b SendBypassBuildCmd - L2J Server Version: 2943 - DP Revision: 5990java.lang.NullPointerException at java.lang.System.arraycopy(Native Method) at javolution.text.TextBuilder$2.run(TextBuilder.java:1004) at javax.realtime.MemoryArea.executeInArea(MemoryArea.java:27) at javolution.text.TextBuilder.increaseCapacity(TextBuilder.java:998) at javolution.text.TextBuilder.append(TextBuilder.java:349) at javolution.text.TextBuilder.append(TextBuilder.java:327) at javolution.text.TextBuilder.<init>(TextBuilder.java:89) at handlers.admincommandhandlers.AdminChatFilter.showWordList(Unknown Source) at handlers.admincommandhandlers.AdminChatFilter.useAdminCommand(Unknown Source) at net.sf.l2j.gameserver.network.clientpackets.SendBypassBuildCmd.runImpl(SendBypassBuildCmd.java:78) at net.sf.l2j.gameserver.network.clientpackets.L2GameClientPacket.run(L2GameClientPacket.java:76) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)