Cleaned up SitOnObjectCmdCallback. Now uses CreatureObject.sendObservers().

Fixed a bug where name uniqueness was based on the entire character name instead of just the character's first name.
Character name uniqueness check is now case insensitive.
This commit is contained in:
wallaceg09
2015-04-02 21:41:27 -05:00
parent 79cc2c0b77
commit a4cbca259f
2 changed files with 17 additions and 14 deletions
@@ -40,14 +40,7 @@ public class SitOnObjectCmdCallback implements ICmdCallback {
creature.setMovementScale(0);
creature.setTurnScale(0);
player.sendPacket(sot);
List <Player> observers = player.getCreatureObject().getObservers();
for (Player observer : observers) {
if (observer.getCreatureObject() == null)
continue;
observer.sendPacket(new SitOnObject(observer.getCreatureObject().getObjectId(), sot));
}
creature.sendObservers(new SitOnObject(creature.getObjectId(), sot));
}
}
+16 -6
View File
@@ -66,6 +66,7 @@ public class ZoneService extends Service {
private PreparedStatement createCharacter;
private PreparedStatement getCharacter;
private PreparedStatement getLikeCharacterName;
public ZoneService() {
clientFac = new ClientFactory();
@@ -77,7 +78,8 @@ public class ZoneService extends Service {
public boolean initialize() {
String createCharacterSql = "INSERT INTO characters (id, name, race, userId, galaxyId) VALUES (?, ?, ?, ?, ?)";
createCharacter = getLocalDatabase().prepareStatement(createCharacterSql);
getCharacter = getLocalDatabase().prepareStatement("SELECT * FROM characters WHERE name = ?");
getCharacter = getLocalDatabase().prepareStatement("SELECT * FROM characters WHERE name == ?");
getLikeCharacterName = getLocalDatabase().prepareStatement("SELECT name FROM characters WHERE name ilike ?"); //NOTE: ilike is not SQL standard. It is an extension for postgres only.
nameGenerator.loadAllRules();
loadProfTemplates();
if (!nameFilter.load())
@@ -208,7 +210,7 @@ public class ZoneService extends Service {
}
}
private ErrorMessage getNameValidity(String name, boolean admin) {
private ErrorMessage getNameValidity(String name, boolean admin) {//FIXME: This seems to be called twice in character creation...
String modified = nameFilter.cleanName(name);
if (nameFilter.isEmpty(modified)) // Empty name
return ErrorMessage.NAME_DECLINED_EMPTY;
@@ -220,7 +222,7 @@ public class ZoneService extends Service {
return ErrorMessage.NAME_DECLINED_FICTIONALLY_INAPPROPRIATE;
if (nameFilter.isReserved(modified) && !admin)
return ErrorMessage.NAME_DECLINED_RESERVED;
if (characterExistsForName(modified)) // User already exists
if (characterExistsForName(modified)) // User already exists.
return ErrorMessage.NAME_DECLINED_IN_USE;
if (!modified.equals(name)) // If we needed to remove double spaces, trim the ends, etc
return ErrorMessage.NAME_APPROVED_MODIFIED;
@@ -231,9 +233,17 @@ public class ZoneService extends Service {
synchronized (getCharacter) {
ResultSet set = null;
try {
getCharacter.setString(1, name);
set = getCharacter.executeQuery();
return set.next();
String nameSplitStr[] = name.split(" ");
String charExistsPrepStmtStr = nameSplitStr[0] + "%"; //Only the first name should be unique.
getLikeCharacterName.setString(1, charExistsPrepStmtStr);
set = getLikeCharacterName.executeQuery();
while (set.next()){
String dbName = set.getString("name");
if(nameSplitStr[0].equalsIgnoreCase(dbName.split(" ")[0])){
return true;
}
}
return false;
} catch (SQLException e) {
e.printStackTrace();
return false;