Merged in Z61/holocore (pull request #11)

Fixed CORE-95
This commit is contained in:
Undercova
2015-05-08 20:37:07 +02:00
5 changed files with 31 additions and 8 deletions

View File

@@ -0,0 +1,3 @@
Han
Solo
Skywalker

View File

@@ -83,7 +83,8 @@ public class ClientVerifyAndLockNameResponse extends SWGPacket {
NAME_DECLINED_INTERNAL_ERROR,
NAME_DECLINED_RETRY,
NAME_DECLINED_TOO_FAST,
NAME_DECLINED_NOT_AUTHORIZED_FOR_SPECIES;
NAME_DECLINED_NOT_AUTHORIZED_FOR_SPECIES,
NAME_DECLINED_FICTIONALLY_RESERVED;
}
}

View File

@@ -69,10 +69,14 @@ public class CreateCharacterFailure extends SWGPacket {
return "name_declined_in_use";
case NAME_RETRY:
return "name_declined_retry";
case NAME_FICTIONALLY_INAPPRORIATE:
return "name_declined_syntax";
case NAME_SYNTAX:
return "name_declined_syntax";
case NAME_TOO_FAST:
return "name_declined_too_fast";
case NAME_DEV_RESERVED:
return "name_declined_developer";
}
return "name_declined_retry";
}
@@ -82,6 +86,8 @@ public class CreateCharacterFailure extends SWGPacket {
NAME_TOO_FAST,
NAME_RETRY,
NAME_SYNTAX,
NAME_IN_USE
NAME_IN_USE,
NAME_FICTIONALLY_INAPPRORIATE,
NAME_DEV_RESERVED;
}
}

View File

@@ -41,24 +41,29 @@ public class NameFilter {
private static final int [] MAX_ALLOWED = new int[] {1 , 1, 1};
private final List <String> profaneWords;
private final List <String> reservedWords;
private final List <String> fictionNames;
private final File profaneFile;
private final File reservedFile;
private final File fictionFile;
public NameFilter(String badWordsPath, String reservedPath) {
this(new File(badWordsPath), new File(reservedPath));
public NameFilter(String badWordsPath, String reservedPath, String fictionPath) {
this(new File(badWordsPath), new File(reservedPath), new File(fictionPath));
}
public NameFilter(File badWordsFile, File reservedFile) {
public NameFilter(File badWordsFile, File reservedFile, File fictionFile) {
this.profaneFile = badWordsFile;
this.reservedFile = reservedFile;
this.fictionFile = fictionFile;
this.profaneWords = new ArrayList<String>();
this.reservedWords = new ArrayList<String>();
this.fictionNames = new ArrayList<String>();
}
public boolean load() {
boolean success = true;
success = load(profaneWords, profaneFile) && success;
success = load(reservedWords, reservedFile) && success;
success = load(fictionNames, fictionFile) && success;
return success;
}
@@ -114,7 +119,9 @@ public class NameFilter {
public boolean isReserved(String name) {
return contains(reservedWords, name);
}
public boolean isFictionallyReserved(String name) {
return contains(fictionNames, name);
}
public boolean isFictionallyInappropriate(String name) {
boolean space = true;
for (int i = 0; i < name.length(); i++) {

View File

@@ -97,7 +97,7 @@ public class ZoneService extends Service {
public ZoneService() {
clientFac = new ClientFactory();
nameFilter = new NameFilter("namegen/bad_word_list.txt", "namegen/reserved_words.txt");
nameFilter = new NameFilter("namegen/bad_word_list.txt", "namegen/reserved_words.txt", "namegen/fiction_reserved.txt");
nameGenerator = new SWGNameGenerator(nameFilter);
}
@@ -214,6 +214,10 @@ public class ZoneService extends Service {
reason = NameFailureReason.NAME_IN_USE;
else if (err == ErrorMessage.NAME_DECLINED_EMPTY)
reason = NameFailureReason.NAME_DECLINED_EMPTY;
else if (err == ErrorMessage.NAME_DECLINED_FICTIONALLY_INAPPROPRIATE)
reason = NameFailureReason.NAME_FICTIONALLY_INAPPRORIATE;
else if (err == ErrorMessage.NAME_DECLINED_RESERVED)
reason = NameFailureReason.NAME_DEV_RESERVED;
System.err.println("ZoneService: Unable to create character [Name: " + create.getName() + " User: " + player.getUsername() + "] and put into database! Reason: " + err);
sendPacket(player, new CreateCharacterFailure(reason));
}
@@ -246,11 +250,13 @@ public class ZoneService extends Service {
if (nameFilter.isProfanity(modified)) // Contains profanity
return ErrorMessage.NAME_DECLINED_PROFANE;
if (nameFilter.isFictionallyInappropriate(modified))
return ErrorMessage.NAME_DECLINED_FICTIONALLY_INAPPROPRIATE;
return ErrorMessage.NAME_DECLINED_SYNTAX;
if (nameFilter.isReserved(modified) && !admin)
return ErrorMessage.NAME_DECLINED_RESERVED;
if (characterExistsForName(modified)) // User already exists.
return ErrorMessage.NAME_DECLINED_IN_USE;
if (nameFilter.isFictionallyReserved(modified))
return ErrorMessage.NAME_DECLINED_FICTIONALLY_RESERVED;
if (!modified.equals(name)) // If we needed to remove double spaces, trim the ends, etc
return ErrorMessage.NAME_APPROVED_MODIFIED;
return ErrorMessage.NAME_APPROVED;