Conflicts:
	src/resources/commands/callbacks/SitOnObjectCmdCallback.java
This commit is contained in:
Obique
2015-04-07 10:39:34 -05:00
committed by Obique
2 changed files with 16 additions and 15 deletions
+15 -5
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())
@@ -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;