* @throws SQLException if there is any problem at database
*/
public boolean isCharacterCreationLimitReached(DBTransaction transaction,
String username, String address) throws IOException, SQLException {
Configuration conf = Configuration.getConfiguration();
String whiteList = "," + conf.get("ip_whitelist", "127.0.0.1") + ",";
if (whiteList.indexOf("," + address + ",") > -1) {
return false;
}
Map<String, Object> params = new HashMap<String, Object>();
params.put("address", address);
params.put("username", username);
// apply the time frame
Calendar calendar = new GregorianCalendar();
calendar.add(Calendar.SECOND, -1 * conf.getInt("character_creation_counting_time", TimeoutConf.CHARACTER_CREATION_COUNTINGTIME));
params.put("timestamp", new Timestamp(calendar.getTimeInMillis()).toString());
// count the number of recently created characters from this ip-address
String query = "SELECT count(DISTINCT charname) "
+ "FROM characters, account "
+ "WHERE characters.player_id=account.id AND account.username='[username]' AND characters.timedate>'[timestamp]'";
// do the database query and evaluate the result
int attemps = transaction.querySingleCellInt(query, params);
if (attemps > conf.getInt("character_creation_limit", TimeoutConf.CHARACTER_CREATION_LIMIT)) {
return true;
}
// count the number of recently created characters from this ip-address
query = "SELECT count(DISTINCT charname) "
+ "FROM characters, account, loginEvent "
+ "WHERE characters.player_id=account.id AND account.id=loginEvent.player_id AND address='[address]' AND characters.timedate>'[timestamp]'";
attemps = transaction.querySingleCellInt(query, params);
return attemps > conf.getInt("character_creation_limit", TimeoutConf.CHARACTER_CREATION_LIMIT);
}