back_recharge
wangyuan 2019-11-29 18:24:10 +08:00
parent 05a00c8187
commit b4995e599c
2 changed files with 28 additions and 2 deletions

View File

@ -101,10 +101,25 @@ public class ChatLogic {
FriendManager friendManager = user.getFriendManager(); FriendManager friendManager = user.getFriendManager();
long nowTime = System.currentTimeMillis(); 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.ChatInfo chatInfo = CBean2Proto.getChatInfoBuilder(user,tmp,nowTime,-1);
ChatProto.SendChatInfoResponse response = ChatProto.SendChatInfoResponse.newBuilder().setChatInfo(chatInfo).build(); ChatProto.SendChatInfoResponse response = ChatProto.SendChatInfoResponse.newBuilder().setChatInfo(chatInfo).build();
MessageUtil.sendMessage(iSession,1,msgId,response,true); MessageUtil.sendMessage(iSession,1,msgId,response,true);

View File

@ -6,6 +6,7 @@ import com.ljsd.jieling.logic.dao.root.User;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
public class ShieldedWordUtils { public class ShieldedWordUtils {
@ -60,4 +61,14 @@ public class ShieldedWordUtils {
boolean hasDirtyWords = SensitivewordFilter.isContaintSensitiveWord(userName, 1); boolean hasDirtyWords = SensitivewordFilter.isContaintSensitiveWord(userName, 1);
return hasDirtyWords; 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(" ","");
}
} }