This commit is contained in:
Light2
2013-12-28 19:17:41 +01:00
55 changed files with 1058 additions and 197 deletions
+29
View File
@@ -461,5 +461,34 @@ public class CharacterService implements INetworkDispatch {
}
return characters;
}
/**
* Checks the database for if the name of the player exists. The name is
* formated automatically in the method for checking the database, so no conversion is required.
* @param name Name to check for in the database
* @return Returns True if the player exists
*/
public boolean playerExists(String name) {
if (!name.equals("")) {
if (name.contains(" ")) {
name = name.split(" ")[0];
}
name = name.replace("'", "''");
name = name.toLowerCase();
try {
PreparedStatement ps = databaseConnection.preparedStatement("SELECT id FROM characters WHERE LOWER(\"firstName\")=?");
ps.setString(1, name);
ResultSet resultSet = ps.executeQuery();
boolean isDuplicate = resultSet.next();
resultSet.getStatement().close();
if (isDuplicate) { return true; }
else { return false; }
}
catch (SQLException e) { e.printStackTrace(); }
}
return false;
}
}