检查名字逻辑修改

master_haizei01
grimm 2024-07-22 14:25:06 +08:00
parent cd34e26acf
commit cdac0990ee
6 changed files with 44 additions and 47 deletions

View File

@ -5,7 +5,6 @@ import com.google.gson.Gson;
import com.ljsd.GameApplication; import com.ljsd.GameApplication;
import com.ljsd.jieling.chat.ChatRedisEntity; import com.ljsd.jieling.chat.ChatRedisEntity;
import com.ljsd.jieling.chat.messge.MessageCache; import com.ljsd.jieling.chat.messge.MessageCache;
import com.ljsd.jieling.dataReport.reportBeans_37.ChatContentType;
import com.ljsd.jieling.db.redis.RedisKey; import com.ljsd.jieling.db.redis.RedisKey;
import com.ljsd.jieling.db.redis.RedisUtil; import com.ljsd.jieling.db.redis.RedisUtil;
import com.ljsd.jieling.exception.ErrorCode; import com.ljsd.jieling.exception.ErrorCode;
@ -163,16 +162,16 @@ public class ChatLogic {
if(strs.length==3){ if(strs.length==3){
s = strs[2]; s = strs[2];
} }
result = ShieldedWordUtils.checkName(user,s,false, ChatContentType.WORLD_CHAT); result = ShieldedWordUtils.checkName(s,false);
break; break;
case 2: case 2:
result = ShieldedWordUtils.checkName(user,message,false,ChatContentType.FAMILY); result = ShieldedWordUtils.checkName(message,false);
break; break;
case 3: case 3:
result = ShieldedWordUtils.checkName(user,message,false,ChatContentType.PRIVATE_CHAT,UserManager.getUser(friendId)); result = ShieldedWordUtils.checkName(message,false);
break; break;
case 4: case 4:
result = ShieldedWordUtils.checkName(user,message,false,ChatContentType.CROSS_CHAT); result = ShieldedWordUtils.checkName(message,false);
break; break;
default: default:
break; break;

View File

@ -5,7 +5,6 @@ import com.ljsd.jieling.config.clazzStaticCfg.CommonStaticConfig;
import com.ljsd.jieling.core.FunctionIdEnum; import com.ljsd.jieling.core.FunctionIdEnum;
import com.ljsd.jieling.core.GlobalsDef; import com.ljsd.jieling.core.GlobalsDef;
import com.ljsd.jieling.core.VipPrivilegeType; import com.ljsd.jieling.core.VipPrivilegeType;
import com.ljsd.jieling.dataReport.reportBeans_37.ChatContentType;
import com.ljsd.jieling.db.redis.RedisKey; import com.ljsd.jieling.db.redis.RedisKey;
import com.ljsd.jieling.db.redis.RedisUtil; import com.ljsd.jieling.db.redis.RedisUtil;
import com.ljsd.jieling.exception.ErrorCode; import com.ljsd.jieling.exception.ErrorCode;
@ -2405,7 +2404,7 @@ public class MapLogic {
User user = UserManager.getUser(session.getUid()); User user = UserManager.getUser(session.getUid());
MapManager mapManager = user.getMapManager(); MapManager mapManager = user.getMapManager();
if (type == 1) { if (type == 1) {
boolean result = ShieldedWordUtils.checkName(user, content, false, ChatContentType.OTHER); boolean result = ShieldedWordUtils.checkName(content, false);
String error; String error;
if (!result) { if (!result) {
error = "输入有敏感字符"; error = "输入有敏感字符";

View File

@ -2,7 +2,6 @@ package com.ljsd.jieling.kefu;
import com.ljsd.jieling.config.clazzStaticCfg.CommonStaticConfig; import com.ljsd.jieling.config.clazzStaticCfg.CommonStaticConfig;
import com.ljsd.jieling.core.FunctionIdEnum; import com.ljsd.jieling.core.FunctionIdEnum;
import com.ljsd.jieling.dataReport.reportBeans_37.ChatContentType;
import com.ljsd.jieling.db.mongo.MongoUtil; import com.ljsd.jieling.db.mongo.MongoUtil;
import com.ljsd.jieling.db.redis.RedisKey; import com.ljsd.jieling.db.redis.RedisKey;
import com.ljsd.jieling.db.redis.RedisUtil; import com.ljsd.jieling.db.redis.RedisUtil;
@ -21,6 +20,7 @@ import config.SGlobalActivity;
import manager.STableManager; import manager.STableManager;
import rpc.protocols.MessageTypeProto; import rpc.protocols.MessageTypeProto;
import rpc.protocols.PlayerInfoProto; import rpc.protocols.PlayerInfoProto;
import util.StringUtil;
import util.TimeUtils; import util.TimeUtils;
import java.util.Map; import java.util.Map;
@ -90,7 +90,7 @@ public class Cmd_changename extends GmRoleAbstract {
} else if (args.length == 0) { } else if (args.length == 0) {
for (int i = 0; i < 50; i++) { for (int i = 0; i < 50; i++) {
name = PlayerLogic.getInstance().getRandomName2(); name = PlayerLogic.getInstance().getRandomName2();
if (doCheck(name)) { if (!StringUtil.isEmpty(name) && doCheck(name)) {
return true; return true;
}else { }else {
LOGGER.error("名称检查失败"); LOGGER.error("名称检查失败");
@ -116,7 +116,7 @@ public class Cmd_changename extends GmRoleAbstract {
if (length > STableManager.getFigureConfig(CommonStaticConfig.class).getGameSetting().getMaxNameLength() || length < 1) { if (length > STableManager.getFigureConfig(CommonStaticConfig.class).getGameSetting().getMaxNameLength() || length < 1) {
return false; return false;
} }
boolean result = ShieldedWordUtils.checkName(getUser(), name, true, ChatContentType.ROLE_NAME); boolean result = ShieldedWordUtils.checkName(name, true);
if (!result) { if (!result) {
return false; return false;
} }

View File

@ -4,7 +4,6 @@ import com.google.common.collect.Lists;
import com.google.protobuf.GeneratedMessage; import com.google.protobuf.GeneratedMessage;
import com.ljsd.GameApplication; import com.ljsd.GameApplication;
import com.ljsd.jieling.core.GlobalsDef; import com.ljsd.jieling.core.GlobalsDef;
import com.ljsd.jieling.dataReport.reportBeans_37.ChatContentType;
import com.ljsd.jieling.db.mongo.AreaManager; import com.ljsd.jieling.db.mongo.AreaManager;
import com.ljsd.jieling.db.mongo.MongoUtil; import com.ljsd.jieling.db.mongo.MongoUtil;
import com.ljsd.jieling.db.redis.RedisKey; import com.ljsd.jieling.db.redis.RedisKey;
@ -225,7 +224,7 @@ public class GuildLogic {
throw new ErrorCodeException(ErrorCode.NULL_NAME); throw new ErrorCodeException(ErrorCode.NULL_NAME);
} }
if(!StringUtil.isEmpty(announce)){ if(!StringUtil.isEmpty(announce)){
if (!ShieldedWordUtils.checkName(user,familyName,false,ChatContentType.FAMILY_NAME)||!ShieldedWordUtils.checkName(user,announce,false,ChatContentType.FAMILY_NAME)) { if (!ShieldedWordUtils.checkName(familyName,false)||!ShieldedWordUtils.checkName(announce,false)) {
throw new ErrorCodeException(ErrorCode.FAMILY_IN_SENSITIVE); throw new ErrorCodeException(ErrorCode.FAMILY_IN_SENSITIVE);
} }
} }
@ -783,7 +782,7 @@ public class GuildLogic {
if(uidType>2){ if(uidType>2){
throw new ErrorCodeException(ErrorCode.FAMILY_NO_ACCESS); throw new ErrorCodeException(ErrorCode.FAMILY_NO_ACCESS);
} }
boolean result = ShieldedWordUtils.checkName(user,content,false,ChatContentType.ANNOUNCE); boolean result = ShieldedWordUtils.checkName(content,false);
int resultCode = 1; int resultCode = 1;
String err = "修改成功"; String err = "修改成功";
if (!result) { if (!result) {

View File

@ -6,9 +6,7 @@ import com.ljsd.jieling.config.clazzStaticCfg.CommonStaticConfig;
import com.ljsd.jieling.config.clazzStaticCfg.TaskStaticConfig; import com.ljsd.jieling.config.clazzStaticCfg.TaskStaticConfig;
import com.ljsd.jieling.core.GlobalsDef; import com.ljsd.jieling.core.GlobalsDef;
import com.ljsd.jieling.core.VipPrivilegeType; import com.ljsd.jieling.core.VipPrivilegeType;
import com.ljsd.jieling.dataReport.reportBeans_37.ChatContentType;
import com.ljsd.jieling.db.mongo.AreaManager; import com.ljsd.jieling.db.mongo.AreaManager;
import com.ljsd.jieling.db.mongo.MongoUtil;
import com.ljsd.jieling.db.redis.RedisKey; import com.ljsd.jieling.db.redis.RedisKey;
import com.ljsd.jieling.db.redis.RedisUtil; import com.ljsd.jieling.db.redis.RedisUtil;
import com.ljsd.jieling.exception.ErrorCode; import com.ljsd.jieling.exception.ErrorCode;
@ -26,9 +24,6 @@ import com.ljsd.jieling.logic.activity.crossService.CrossServiceLogic;
import com.ljsd.jieling.logic.activity.event.GuildForceChangeEvent; import com.ljsd.jieling.logic.activity.event.GuildForceChangeEvent;
import com.ljsd.jieling.logic.activity.event.Poster; import com.ljsd.jieling.logic.activity.event.Poster;
import com.ljsd.jieling.logic.activity.event.SaveHeroForceEvent; import com.ljsd.jieling.logic.activity.event.SaveHeroForceEvent;
import com.ljsd.jieling.logic.dao.Pokemon;
import com.ljsd.jieling.logic.dao.PropertyItem;
import com.ljsd.jieling.logic.dao.TeamPosHeroInfo;
import com.ljsd.jieling.logic.dao.*; import com.ljsd.jieling.logic.dao.*;
import com.ljsd.jieling.logic.dao.cross.CSPlayer; import com.ljsd.jieling.logic.dao.cross.CSPlayer;
import com.ljsd.jieling.logic.dao.root.GuildInfo; import com.ljsd.jieling.logic.dao.root.GuildInfo;
@ -44,7 +39,7 @@ import com.ljsd.jieling.logic.store.BuyGoodsNewLogic;
import com.ljsd.jieling.logic.store.newRechargeInfo.bean.ReceiveWelfareBag; import com.ljsd.jieling.logic.store.newRechargeInfo.bean.ReceiveWelfareBag;
import com.ljsd.jieling.logic.store.newRechargeInfo.rechargeHandler.RechargeHandler; import com.ljsd.jieling.logic.store.newRechargeInfo.rechargeHandler.RechargeHandler;
import com.ljsd.jieling.network.session.ISession; import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.thrift.idl.*; import com.ljsd.jieling.thrift.idl.RPCRequestIFace;
import com.ljsd.jieling.thrift.pool.ClientAdapterPo; import com.ljsd.jieling.thrift.pool.ClientAdapterPo;
import com.ljsd.jieling.util.*; import com.ljsd.jieling.util.*;
import config.*; import config.*;
@ -58,7 +53,6 @@ import util.MathUtils;
import util.TimeUtils; import util.TimeUtils;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public class PlayerLogic { public class PlayerLogic {
@ -113,53 +107,63 @@ public class PlayerLogic {
MessageUtil.sendMessage(session,1, MessageTypeProto.MessageType.SAVE_NEW_PLAYER_GUIDE_POINT_RESPONSE_VALUE,null,true); MessageUtil.sendMessage(session,1, MessageTypeProto.MessageType.SAVE_NEW_PLAYER_GUIDE_POINT_RESPONSE_VALUE,null,true);
} }
public String getRandomName2() throws Exception { public String getRandomName2() {
String name; String name;
Map<Integer, String> surnameMap = SRandomName.getSurnameMap(); Map<Integer, String> surnameMap = SRandomName.getSurnameMap();
Map<Integer, String> nameMap = SRandomName.getNameMap(); Map<Integer, String> nameMap = SRandomName.getNameMap();
int max = surnameMap.size() * nameMap.size(); int max = surnameMap.size() * nameMap.size();
int i = 0; int i = 0;
boolean result; boolean result = true;
do { do {
name = surnameMap.get(MathUtils.random(1, surnameMap.size())) + nameMap.get(MathUtils.random(1, nameMap.size())); name = surnameMap.get(MathUtils.random(1, surnameMap.size())) + nameMap.get(MathUtils.random(1, nameMap.size()));
result = SensitivewordFilter.isContaintSensitiveWord(name,1); try {
result = SensitivewordFilter.isContaintSensitiveWord(name,1);
} catch (Exception e) {
LOGGER.error("随机名称失败包含有违禁字符最后一次名字2"+name);
e.printStackTrace();
}
i++; i++;
} }
while (result && i < max); while (result && i < max);
if (result){ if (result){
throw new ErrorCodeException("随机名称失败,一直包含有违禁字符,最后一次名字:"+name); name = "";
} }
return name; return name;
} }
public String getRandomName2WithOutVerify() {
String name;
Map<Integer, String> surnameMap = SRandomName.getSurnameMap();
Map<Integer, String> nameMap = SRandomName.getNameMap();
name = surnameMap.get(MathUtils.random(1, surnameMap.size())) + nameMap.get(MathUtils.random(1, nameMap.size()));
return name;
}
public String[] getRandomNameWithPreAndPost() throws Exception { // public String getRandomName2WithOutVerify() {
String name; // String name;
// Map<Integer, String> surnameMap = SRandomName.getSurnameMap();
// Map<Integer, String> nameMap = SRandomName.getNameMap();
// name = surnameMap.get(MathUtils.random(1, surnameMap.size())) + nameMap.get(MathUtils.random(1, nameMap.size()));
// return name;
// }
public String[] getRandomNameWithPreAndPost() throws ErrorCodeException {
Map<Integer, String> surnameMap = SRandomName.getSurnameMap(); Map<Integer, String> surnameMap = SRandomName.getSurnameMap();
Map<Integer, String> nameMap = SRandomName.getNameMap(); Map<Integer, String> nameMap = SRandomName.getNameMap();
String name;
String pre; String pre;
String post; String post;
// 加入 // 加入
int max = surnameMap.size() * nameMap.size(); int max = surnameMap.size() * nameMap.size();
int i = 0; int i = 0;
boolean result; boolean result = true;
do { do {
pre = surnameMap.get(MathUtils.random(1, surnameMap.size())); pre = surnameMap.get(MathUtils.random(1, surnameMap.size()));
post = nameMap.get(MathUtils.random(1, nameMap.size())); post = nameMap.get(MathUtils.random(1, nameMap.size()));
name = pre + post; name = pre + post;
try {
result = SensitivewordFilter.isContaintSensitiveWord(name,1); result = SensitivewordFilter.isContaintSensitiveWord(name,1);
} catch (Exception e) {
LOGGER.error("随机名称失败,包含有违禁字符,最后一次名字:"+name);
e.printStackTrace();
}
i++; i++;
} }
while (result && i<max); while (result && i<max);
if (result){ if (result){
throw new ErrorCodeException("随机名称失败2一直包含有违禁字符最后一次名字"+name); throw new ErrorCodeException(ErrorCode.NAME_ILLEGAL);
} }
return new String[]{name,pre,post}; return new String[]{name,pre,post};
} }
@ -175,7 +179,7 @@ public class PlayerLogic {
User user = UserManager.getUser(uid); User user = UserManager.getUser(uid);
PlayerManager playerInfoManager = user.getPlayerInfoManager(); PlayerManager playerInfoManager = user.getPlayerInfoManager();
TeamPosManager teamPosManager = user.getTeamPosManager(); TeamPosManager teamPosManager = user.getTeamPosManager();
if (checkName(iSession, name)){ if (checkName(name)){
return; return;
} }
if (type == 1||type == 3) { if (type == 1||type == 3) {
@ -224,7 +228,7 @@ public class PlayerLogic {
MessageUtil.sendMessage(iSession,1,msgId,null,true); MessageUtil.sendMessage(iSession,1,msgId,null,true);
} }
private boolean checkName(ISession iSession, String name) throws Exception { private boolean checkName(String name) throws Exception {
int length = getStrLength(name); int length = getStrLength(name);
if (length == -1) { if (length == -1) {
throw new ErrorCodeException(ErrorCode.NAME_ILLEGAL); throw new ErrorCodeException(ErrorCode.NAME_ILLEGAL);
@ -232,7 +236,7 @@ public class PlayerLogic {
if (length > 18 || length < 1) { if (length > 18 || length < 1) {
throw new ErrorCodeException(ErrorCode.NAME_LENTH); throw new ErrorCodeException(ErrorCode.NAME_LENTH);
} }
boolean result = ShieldedWordUtils.checkName(UserManager.getUser(iSession.getUid()),name,true,ChatContentType.ROLE_NAME); boolean result = ShieldedWordUtils.checkName(name,true);
if (!result) { if (!result) {
throw new ErrorCodeException(ErrorCode.NAME_ILLEGAL); throw new ErrorCodeException(ErrorCode.NAME_ILLEGAL);
} }

View File

@ -1,7 +1,5 @@
package com.ljsd.jieling.util; package com.ljsd.jieling.util;
import com.ljsd.jieling.dataReport.reportBeans_37.ChatContentType;
import com.ljsd.jieling.logic.dao.root.User;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -12,11 +10,8 @@ public class ShieldedWordUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(ShieldedWordUtils.class); 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(String name, boolean validateSpecStr){
public static boolean checkName(User user,String name,boolean validateSpecStr,ChatContentType chatContentType){
boolean result = true; boolean result = true;
// 校验特殊符号 // 校验特殊符号
if(validateSpecStr){ if(validateSpecStr){
@ -27,7 +22,8 @@ public class ShieldedWordUtils {
try { try {
result = !SensitivewordFilter.isContaintSensitiveWord(name,1); result = !SensitivewordFilter.isContaintSensitiveWord(name,1);
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("检查名称,报错:"+e.getMessage()); LOGGER.error("检查名称报错:{}",name);
e.printStackTrace();
} }
} }
return result; return result;