mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-05 23:22:47 +00:00
Improves character count checks
This commit is contained in:
@@ -1069,7 +1069,7 @@ public abstract class AbstractOrientDatabaseService extends
|
||||
|
||||
@Override
|
||||
public boolean filter(OQueryContextNative record) {
|
||||
record = query(record);
|
||||
record = query(record, entity);
|
||||
if (record == null)
|
||||
return true;
|
||||
return record.go();
|
||||
@@ -1084,8 +1084,11 @@ public abstract class AbstractOrientDatabaseService extends
|
||||
*
|
||||
* @param record
|
||||
* the document record
|
||||
* @param e
|
||||
* the entity
|
||||
* @return the record instance or <code>null</code>
|
||||
*/
|
||||
protected abstract OQueryContextNative query(OQueryContextNative record);
|
||||
protected abstract OQueryContextNative query(
|
||||
OQueryContextNative record, E e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1094,7 +1094,7 @@ public abstract class AbstractSQLDatabaseService extends
|
||||
SQLQueryFactory<? extends AbstractSQLQuery<?>, ?, ?, ?, ?, ?> factory,
|
||||
DatabaseService database) {
|
||||
final AbstractSQLQuery<?> count = factory.query().from(entity);
|
||||
query(count);
|
||||
query(count, entity);
|
||||
return (int) count.count();
|
||||
}
|
||||
|
||||
@@ -1103,7 +1103,8 @@ public abstract class AbstractSQLDatabaseService extends
|
||||
*
|
||||
* @param q
|
||||
* the query clause
|
||||
* @param e the entity
|
||||
*/
|
||||
protected abstract void query(AbstractSQLQuery<?> q);
|
||||
protected abstract void query(AbstractSQLQuery<?> q, E e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,4 +58,13 @@ public interface CharacterDAO extends
|
||||
* characters.
|
||||
*/
|
||||
List<L2Character> selectByAccount(AccountID account);
|
||||
|
||||
/**
|
||||
* Counts the amount of characters for an given <code>account</code>.
|
||||
*
|
||||
* @param account
|
||||
* the account id
|
||||
* @return the number of characters for that <code>account</code>
|
||||
*/
|
||||
int countByAccount(AccountID account);
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import com.l2jserver.service.database.DatabaseService;
|
||||
import com.l2jserver.service.database.mapper.CharacterMapper;
|
||||
import com.l2jserver.service.database.model.QCharacter;
|
||||
import com.l2jserver.service.database.orientdb.AbstractOrientDBDAO;
|
||||
import com.l2jserver.service.database.orientdb.AbstractOrientDatabaseService.CountQuery;
|
||||
import com.l2jserver.service.database.orientdb.AbstractOrientDatabaseService.DeleteQuery;
|
||||
import com.l2jserver.service.database.orientdb.AbstractOrientDatabaseService.InsertQuery;
|
||||
import com.l2jserver.service.database.orientdb.AbstractOrientDatabaseService.SelectListQuery;
|
||||
@@ -117,6 +118,17 @@ public class OrientDBCharacterDAO extends
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int countByAccount(final AccountID account) {
|
||||
return database.query(new CountQuery<QCharacter>(QCharacter.character) {
|
||||
@Override
|
||||
protected OQueryContextNative query(OQueryContextNative record,
|
||||
QCharacter e) {
|
||||
return record.field(name(e.accountId)).eq(account.getID());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CharacterID> selectIDs() {
|
||||
return database
|
||||
@@ -145,7 +157,8 @@ public class OrientDBCharacterDAO extends
|
||||
@Override
|
||||
protected OQueryContextNative query(OQueryContextNative record,
|
||||
L2Character o) {
|
||||
return record.field(name(entity.characterId)).eq(o.getID().getID());
|
||||
return record.field(name(entity.characterId)).eq(
|
||||
o.getID().getID());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -157,7 +170,8 @@ public class OrientDBCharacterDAO extends
|
||||
@Override
|
||||
protected OQueryContextNative query(OQueryContextNative record,
|
||||
L2Character o) {
|
||||
return record.field(name(entity.characterId)).eq(o.getID().getID());
|
||||
return record.field(name(entity.characterId)).eq(
|
||||
o.getID().getID());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import com.l2jserver.service.database.DatabaseService;
|
||||
import com.l2jserver.service.database.mapper.CharacterMapper;
|
||||
import com.l2jserver.service.database.model.QCharacter;
|
||||
import com.l2jserver.service.database.sql.AbstractSQLDAO;
|
||||
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService.CountQuery;
|
||||
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService.DeleteQuery;
|
||||
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService.InsertQuery;
|
||||
import com.l2jserver.service.database.sql.AbstractSQLDatabaseService.SelectListQuery;
|
||||
@@ -113,6 +114,16 @@ public class SQLCharacterDAO extends AbstractSQLDAO<L2Character, CharacterID>
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int countByAccount(final AccountID account) {
|
||||
return database.query(new CountQuery<QCharacter>(QCharacter.character) {
|
||||
@Override
|
||||
protected void query(AbstractSQLQuery<?> q, QCharacter e) {
|
||||
q.where(e.accountId.eq(account.getID()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CharacterID> selectIDs() {
|
||||
return database
|
||||
|
||||
@@ -161,10 +161,10 @@ public class CharacterServiceImpl extends
|
||||
*/
|
||||
@Inject
|
||||
public CharacterServiceImpl(BroadcastService broadcastService,
|
||||
WorldEventDispatcherService eventDispatcher, SpawnService spawnService,
|
||||
NPCService npcService, GameGuardService ggService,
|
||||
CharacterDAO characterDao, ItemDAO itemDao,
|
||||
CharacterShortcutDAO shortcutDao,
|
||||
WorldEventDispatcherService eventDispatcher,
|
||||
SpawnService spawnService, NPCService npcService,
|
||||
GameGuardService ggService, CharacterDAO characterDao,
|
||||
ItemDAO itemDao, CharacterShortcutDAO shortcutDao,
|
||||
CharacterTemplateIDProvider charTemplateIdProvider,
|
||||
CharacterIDProvider charIdProvider) {
|
||||
super(CharacterServiceConfiguration.class);
|
||||
@@ -184,7 +184,7 @@ public class CharacterServiceImpl extends
|
||||
public boolean canCreate(AccountID accountID) {
|
||||
if (!config.isCharacterCreationAllowed())
|
||||
return false;
|
||||
return characterDao.selectByAccount(accountID).size() < config
|
||||
return characterDao.countByAccount(accountID) < config
|
||||
.getMaxCharactersPerAccount();
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ public class CharacterServiceImpl extends
|
||||
CharacterInvalidSexException, TooManyCharactersException {
|
||||
if (!config.isCharacterCreationAllowed())
|
||||
throw new CharacteCreationNotAllowedException();
|
||||
if(characterDao.selectByAccount(accountID).size() < config
|
||||
if (characterDao.countByAccount(accountID) < config
|
||||
.getMaxCharactersPerAccount())
|
||||
throw new TooManyCharactersException();
|
||||
|
||||
|
||||
@@ -47,7 +47,6 @@ import com.l2jserver.util.factory.CollectionFactory;
|
||||
import com.sun.org.apache.xml.internal.serialize.OutputFormat;
|
||||
import com.sun.org.apache.xml.internal.serialize.XMLSerializer;
|
||||
|
||||
@SuppressWarnings("restriction")
|
||||
public class SkillTemplateConverter {
|
||||
private static final String JDBC_URL = "jdbc:mysql://localhost/l2jlegacy";
|
||||
private static final String JDBC_USERNAME = "l2j";
|
||||
|
||||
Reference in New Issue
Block a user