修改获取随机名称通过敏感字服时,如果链接失败,直接抛出异常,而不是不断重复(容易导致死循环)

back_recharge
duhui 2022-07-11 17:54:40 +08:00
parent f3ecd4fc3f
commit 13e7fcc48a
3 changed files with 25 additions and 12 deletions

View File

@ -124,7 +124,7 @@ public class PlayerLogic {
MessageUtil.sendMessage(session,1, MessageTypeProto.MessageType.SAVE_NEW_PLAYER_GUIDE_POINT_RESPONSE_VALUE,null,true);
}
public String getRandomName2() {
public String getRandomName2() throws Exception {
String name = "";
Map<Integer, String> surnameMap = SRandomName.getSurnameMap();
Map<Integer, String> nameMap = SRandomName.getNameMap();
@ -143,7 +143,7 @@ public class PlayerLogic {
return name;
}
public String[] getRandomNameWithPreAndPost() {
public String[] getRandomNameWithPreAndPost() throws Exception {
String name ;
Map<Integer, String> surnameMap = SRandomName.getSurnameMap();
Map<Integer, String> nameMap = SRandomName.getNameMap();
@ -157,7 +157,8 @@ public class PlayerLogic {
while (checkNameShield(name));
return new String[]{name,pre,post};
}
private boolean checkNameShield(String name) {
private boolean checkNameShield(String name) throws Exception {
return SensitivewordFilter.isContaintSensitiveWord(name, 1);
}

View File

@ -1,6 +1,8 @@
package com.ljsd.jieling.util;
import com.ljsd.jieling.db.redis.RedisUtil;
import com.ljsd.jieling.exception.ErrorCode;
import com.ljsd.jieling.exception.ErrorCodeException;
import com.ljsd.jieling.thrift.idl.RPCRequestIFace;
import com.ljsd.jieling.thrift.pool.ClientAdapterPo;
import org.slf4j.Logger;
@ -32,7 +34,7 @@ public class SensitivewordFilter {
* @return truefalse
* @version 1.0
*/
public static boolean isContaintSensitiveWord(String txt, int matchType) {
public static boolean isContaintSensitiveWord(String txt, int matchType) throws Exception {
boolean hasDirtyWords = isContaintSensitiveWordThrift(txt, matchType);
return hasDirtyWords;
}
@ -118,11 +120,11 @@ public class SensitivewordFilter {
* @return0
* @version 1.0
*/
private static boolean isContaintSensitiveWordThrift(String userName, int type){
private static boolean isContaintSensitiveWordThrift(String userName, int type) throws ErrorCodeException {
Object o = RedisUtil.getInstence().get(SENSIT_WORD_FILTER_KEY);
if (o == null) {
LOGGER.info("getSensitiveWord 敏感字检测服未开启");
return true;
LOGGER.error("getSensitiveWord 敏感字检测服未开启");
throw new ErrorCodeException(ErrorCode.SYS_ERROR_CODE,"敏感字检测服未开启");
}
String address = (String) o;
String[] split = address.split("\\:");
@ -131,13 +133,13 @@ public class SensitivewordFilter {
try {
rPCClient = ClientAdapterPo.getClientAdapterPo(serviceKey);
if (rPCClient == null) {
return true;
throw new ErrorCodeException(ErrorCode.SYS_ERROR_CODE,"敏感字检测服rpc获取信息为null");
}
boolean result = rPCClient.getClient().isContaintSensitiveWord(userName, type);
return result;
} catch (Exception e) {
LOGGER.info("getSensitiveWord callback=>",e);
return true;
throw new ErrorCodeException(ErrorCode.SYS_ERROR_CODE,"敏感字检测服异常");
}finally {
if (rPCClient != null){
rPCClient.returnObject(serviceKey);

View File

@ -1,19 +1,24 @@
package com.ljsd.jieling.util;
import com.ljsd.jieling.chat.logic.ChatLogic;
import com.ljsd.jieling.dataReport.reportBeans_37.ChatContentType;
import com.ljsd.jieling.logic.dao.root.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ShieldedWordUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(ShieldedWordUtils.class);
public static boolean checkName(User user , String name,boolean validateSpecStr,ChatContentType chatContentType,User friend) {
return checkName(user,name,validateSpecStr,chatContentType);
}
public static boolean checkName(User user , String name,boolean validateSpecStr,ChatContentType chatContentType){
boolean result = true;
boolean result;
if(validateSpecStr){
result = validateUserName(name);
if(!result){
@ -21,7 +26,12 @@ public class ShieldedWordUtils {
}
}
result = isContaintSensitiveWord(name);
try {
result = isContaintSensitiveWord(name);
} catch (Exception e) {
LOGGER.error("检查名称,报错:"+e.getMessage());
return false;
}
if(result){
return false;
}
@ -47,7 +57,7 @@ public class ShieldedWordUtils {
return matcher.matches();
}
public static boolean isContaintSensitiveWord(String userName){
public static boolean isContaintSensitiveWord(String userName) throws Exception{
boolean hasDirtyWords = SensitivewordFilter.isContaintSensitiveWord(userName, 1);
return hasDirtyWords;
}