mingan
parent
05a00c8187
commit
b4995e599c
|
@ -101,10 +101,25 @@ public class ChatLogic {
|
|||
FriendManager friendManager = user.getFriendManager();
|
||||
|
||||
long nowTime = System.currentTimeMillis();
|
||||
String tmp = SensitivewordFilter.replaceSensitiveWord(message, 1, "*");
|
||||
String unSymbolWord = ShieldedWordUtils.replaceUnword(message);
|
||||
String tmp = SensitivewordFilter.replaceSensitiveWord(unSymbolWord, 1, "*");
|
||||
|
||||
|
||||
if(!tmp.equals(message)||playerInfoManager.getSilence()==1){
|
||||
if(tmp.contains("*") && !tmp.equals(message)||playerInfoManager.getSilence()==1){
|
||||
char[] chars = message.toCharArray();
|
||||
char[] original = unSymbolWord.toCharArray();
|
||||
char[] tmpChar = tmp.toCharArray();
|
||||
int j=0;
|
||||
char[] result = new char[chars.length];
|
||||
for(int i=0;i<chars.length;i++){
|
||||
char c= chars[i];
|
||||
if(original[j] == chars[i]){
|
||||
c = tmpChar[j];
|
||||
j++;
|
||||
}
|
||||
result[i]=c;
|
||||
}
|
||||
tmp = new String(result);
|
||||
ChatProto.ChatInfo chatInfo = CBean2Proto.getChatInfoBuilder(user,tmp,nowTime,-1);
|
||||
ChatProto.SendChatInfoResponse response = ChatProto.SendChatInfoResponse.newBuilder().setChatInfo(chatInfo).build();
|
||||
MessageUtil.sendMessage(iSession,1,msgId,response,true);
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.ljsd.jieling.logic.dao.root.User;
|
|||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
|
||||
public class ShieldedWordUtils {
|
||||
|
||||
|
@ -60,4 +61,14 @@ public class ShieldedWordUtils {
|
|||
boolean hasDirtyWords = SensitivewordFilter.isContaintSensitiveWord(userName, 1);
|
||||
return hasDirtyWords;
|
||||
}
|
||||
|
||||
public static String replaceUnword(String content) {
|
||||
// 只允许字母和数字
|
||||
// String regEx = "[^a-zA-Z0-9]";
|
||||
// 清除掉所有特殊字符
|
||||
String regEx="[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、? \\\\]";
|
||||
Pattern p = Pattern.compile(regEx);
|
||||
Matcher m = p.matcher(content);
|
||||
return m.replaceAll("").replaceAll(" ","");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue