玩家发言问题
parent
f4d4134e69
commit
f6267ce855
|
@ -128,10 +128,18 @@ public class PlayerLogic {
|
|||
String name = "";
|
||||
Map<Integer, String> surnameMap = SRandomName.getSurnameMap();
|
||||
Map<Integer, String> nameMap = SRandomName.getNameMap();
|
||||
int max = surnameMap.size() * nameMap.size();
|
||||
int i = 0;
|
||||
boolean result;
|
||||
do {
|
||||
name = surnameMap.get(MathUtils.random(1, surnameMap.size())) + nameMap.get(MathUtils.random(1, nameMap.size()));
|
||||
result = SensitivewordFilter.isContaintSensitiveWord(name,1);
|
||||
i++;
|
||||
}
|
||||
while (result && i < max);
|
||||
if (result){
|
||||
throw new ErrorCodeException("随机名称失败,一直包含有违禁字符,最后一次名字:"+name);
|
||||
}
|
||||
while (checkNameShield(name));
|
||||
return name;
|
||||
}
|
||||
public String getRandomName2WithOutVerify() {
|
||||
|
@ -144,25 +152,30 @@ public class PlayerLogic {
|
|||
}
|
||||
|
||||
public String[] getRandomNameWithPreAndPost() throws Exception {
|
||||
String name ;
|
||||
String name;
|
||||
Map<Integer, String> surnameMap = SRandomName.getSurnameMap();
|
||||
Map<Integer, String> nameMap = SRandomName.getNameMap();
|
||||
String pre ;
|
||||
String post ;
|
||||
String pre;
|
||||
String post;
|
||||
// 加入
|
||||
int max = surnameMap.size() * nameMap.size();
|
||||
int i = 0;
|
||||
boolean result;
|
||||
do {
|
||||
pre = surnameMap.get(MathUtils.random(1, surnameMap.size()));
|
||||
post = nameMap.get(MathUtils.random(1, nameMap.size()));
|
||||
name = pre + post;
|
||||
|
||||
result = SensitivewordFilter.isContaintSensitiveWord(name,1);
|
||||
i++;
|
||||
}
|
||||
while (result && i<max);
|
||||
if (result){
|
||||
throw new ErrorCodeException("随机名称失败2,一直包含有违禁字符,最后一次名字:"+name);
|
||||
}
|
||||
while (checkNameShield(name));
|
||||
return new String[]{name,pre,post};
|
||||
}
|
||||
|
||||
private boolean checkNameShield(String name) throws Exception {
|
||||
return SensitivewordFilter.isContaintSensitiveWord(name, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 起名字
|
||||
* @param name
|
||||
|
|
|
@ -35,8 +35,7 @@ public class SensitivewordFilter {
|
|||
* @version 1.0
|
||||
*/
|
||||
public static boolean isContaintSensitiveWord(String txt, int matchType) throws Exception {
|
||||
boolean hasDirtyWords = isContaintSensitiveWordThrift(txt, matchType);
|
||||
return hasDirtyWords;
|
||||
return isContaintSensitiveWordThrift(txt, matchType);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -21,12 +21,12 @@ public class ShieldedWordUtils {
|
|||
boolean result = true;
|
||||
// 校验特殊符号
|
||||
if(validateSpecStr){
|
||||
result = validateUserName(name);
|
||||
result = !validateUserName(name);
|
||||
}
|
||||
// 校验违禁字符
|
||||
if (result == true){
|
||||
try {
|
||||
result = isContaintSensitiveWord(name);
|
||||
result = !SensitivewordFilter.isContaintSensitiveWord(name,1);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("检查名称,报错:"+e.getMessage());
|
||||
result = false;
|
||||
|
@ -54,11 +54,6 @@ public class ShieldedWordUtils {
|
|||
return matcher.matches();
|
||||
}
|
||||
|
||||
public static boolean isContaintSensitiveWord(String userName) throws Exception{
|
||||
boolean hasDirtyWords = SensitivewordFilter.isContaintSensitiveWord(userName, 1);
|
||||
return hasDirtyWords;
|
||||
}
|
||||
|
||||
public static String replaceUnword(String content) {
|
||||
// 只允许字母和数字
|
||||
// String regEx = "[^a-zA-Z0-9]";
|
||||
|
|
Loading…
Reference in New Issue