mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-06 07:32:46 +00:00
7
pom.xml
7
pom.xml
@@ -78,6 +78,13 @@
|
|||||||
<type>jar</type>
|
<type>jar</type>
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-collections</groupId>
|
||||||
|
<artifactId>commons-collections</artifactId>
|
||||||
|
<version>20040616</version>
|
||||||
|
<type>jar</type>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<issueManagement>
|
<issueManagement>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.l2jserver.db.dao;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.l2jserver.model.id.AccountID;
|
||||||
import com.l2jserver.model.id.ID;
|
import com.l2jserver.model.id.ID;
|
||||||
import com.l2jserver.model.id.object.CharacterID;
|
import com.l2jserver.model.id.object.CharacterID;
|
||||||
import com.l2jserver.model.world.L2Character;
|
import com.l2jserver.model.world.L2Character;
|
||||||
@@ -36,11 +37,12 @@ public interface CharacterDAO extends DataAccessObject<L2Character>, Cacheable {
|
|||||||
/**
|
/**
|
||||||
* Select an character by its name.
|
* Select an character by its name.
|
||||||
*
|
*
|
||||||
* @param name
|
* @param account
|
||||||
* the character name
|
* the account id
|
||||||
* @return the found character. Null if does not exists.
|
* @return the found characters. An empty list if this account has no
|
||||||
|
* characters.
|
||||||
*/
|
*/
|
||||||
List<L2Character> selectByAccount(String username);
|
List<L2Character> selectByAccount(AccountID account);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads an List of all {@link ID}s in the database
|
* Loads an List of all {@link ID}s in the database
|
||||||
|
|||||||
@@ -1,11 +1,17 @@
|
|||||||
package com.l2jserver.db.dao;
|
package com.l2jserver.db.dao;
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
|
import com.google.inject.Module;
|
||||||
import com.google.inject.Scopes;
|
import com.google.inject.Scopes;
|
||||||
import com.l2jserver.db.dao.mysql5.MySQL5CharacterDAO;
|
import com.l2jserver.db.dao.mysql5.MySQL5CharacterDAO;
|
||||||
import com.l2jserver.db.dao.mysql5.MySQL5CharacterFriendDAO;
|
import com.l2jserver.db.dao.mysql5.MySQL5CharacterFriendDAO;
|
||||||
import com.l2jserver.db.dao.mysql5.MySQL5ItemDAO;
|
import com.l2jserver.db.dao.mysql5.MySQL5ItemDAO;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Google Guice {@link Module} for MySQL5 DAOs
|
||||||
|
*
|
||||||
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
|
*/
|
||||||
public class DAOModuleMySQL5 extends AbstractModule {
|
public class DAOModuleMySQL5 extends AbstractModule {
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
|
|||||||
@@ -5,7 +5,18 @@ import com.l2jserver.service.database.AbstractDAO;
|
|||||||
import com.l2jserver.service.database.DatabaseService;
|
import com.l2jserver.service.database.DatabaseService;
|
||||||
import com.l2jserver.service.database.MySQLDatabaseService;
|
import com.l2jserver.service.database.MySQLDatabaseService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link AbstractDAO} for MySQL DAO implementation
|
||||||
|
*
|
||||||
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
|
*
|
||||||
|
* @param <T>
|
||||||
|
* the object for the DAO
|
||||||
|
*/
|
||||||
public class AbstractMySQL5DAO<T> extends AbstractDAO<T> {
|
public class AbstractMySQL5DAO<T> extends AbstractDAO<T> {
|
||||||
|
/**
|
||||||
|
* The MySQL Database Service
|
||||||
|
*/
|
||||||
protected final MySQLDatabaseService database;
|
protected final MySQLDatabaseService database;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import java.util.List;
|
|||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.l2jserver.db.dao.CharacterDAO;
|
import com.l2jserver.db.dao.CharacterDAO;
|
||||||
|
import com.l2jserver.model.id.AccountID;
|
||||||
|
import com.l2jserver.model.id.factory.AccountIDFactory;
|
||||||
import com.l2jserver.model.id.object.CharacterID;
|
import com.l2jserver.model.id.object.CharacterID;
|
||||||
import com.l2jserver.model.id.object.factory.CharacterIDFactory;
|
import com.l2jserver.model.id.object.factory.CharacterIDFactory;
|
||||||
import com.l2jserver.model.id.template.CharacterTemplateID;
|
import com.l2jserver.model.id.template.CharacterTemplateID;
|
||||||
@@ -27,10 +29,25 @@ import com.l2jserver.service.database.MySQLDatabaseService.SelectListQuery;
|
|||||||
import com.l2jserver.service.database.MySQLDatabaseService.SelectSingleQuery;
|
import com.l2jserver.service.database.MySQLDatabaseService.SelectSingleQuery;
|
||||||
import com.l2jserver.util.Coordinate;
|
import com.l2jserver.util.Coordinate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link CharacterDAO} implementation for MySQL5
|
||||||
|
*
|
||||||
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
|
*/
|
||||||
public class MySQL5CharacterDAO extends AbstractMySQL5DAO<L2Character>
|
public class MySQL5CharacterDAO extends AbstractMySQL5DAO<L2Character>
|
||||||
implements CharacterDAO {
|
implements CharacterDAO {
|
||||||
|
/**
|
||||||
|
* The {@link CharacterID} factory
|
||||||
|
*/
|
||||||
private final CharacterIDFactory idFactory;
|
private final CharacterIDFactory idFactory;
|
||||||
|
/**
|
||||||
|
* The {@link CharacterTemplateID} factory
|
||||||
|
*/
|
||||||
private final CharacterTemplateIDFactory templateIdFactory;
|
private final CharacterTemplateIDFactory templateIdFactory;
|
||||||
|
/**
|
||||||
|
* The {@link AccountID} factory
|
||||||
|
*/
|
||||||
|
private final AccountIDFactory accountIdFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Character table name
|
* Character table name
|
||||||
@@ -60,10 +77,12 @@ public class MySQL5CharacterDAO extends AbstractMySQL5DAO<L2Character>
|
|||||||
@Inject
|
@Inject
|
||||||
public MySQL5CharacterDAO(DatabaseService database,
|
public MySQL5CharacterDAO(DatabaseService database,
|
||||||
final CharacterIDFactory idFactory,
|
final CharacterIDFactory idFactory,
|
||||||
CharacterTemplateIDFactory templateIdFactory) {
|
CharacterTemplateIDFactory templateIdFactory,
|
||||||
|
AccountIDFactory accountIdFactory) {
|
||||||
super(database);
|
super(database);
|
||||||
this.idFactory = idFactory;
|
this.idFactory = idFactory;
|
||||||
this.templateIdFactory = templateIdFactory;
|
this.templateIdFactory = templateIdFactory;
|
||||||
|
this.accountIdFactory = accountIdFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -88,6 +107,9 @@ public class MySQL5CharacterDAO extends AbstractMySQL5DAO<L2Character>
|
|||||||
final L2Character character = new L2Character(
|
final L2Character character = new L2Character(
|
||||||
template.getBaseAttributes());
|
template.getBaseAttributes());
|
||||||
character.setID(idFactory.createID(rs.getInt(CHAR_ID)));
|
character.setID(idFactory.createID(rs.getInt(CHAR_ID)));
|
||||||
|
character.setAccountID(accountIdFactory.createID(rs
|
||||||
|
.getString(ACCOUNT_ID)));
|
||||||
|
|
||||||
character.setName(rs.getString(NAME));
|
character.setName(rs.getString(NAME));
|
||||||
|
|
||||||
character.setRace(Race.valueOf(rs.getString(RACE)));
|
character.setRace(Race.valueOf(rs.getString(RACE)));
|
||||||
@@ -158,7 +180,7 @@ public class MySQL5CharacterDAO extends AbstractMySQL5DAO<L2Character>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<L2Character> selectByAccount(final String username) {
|
public List<L2Character> selectByAccount(final AccountID account) {
|
||||||
return database.query(new SelectListQuery<L2Character>() {
|
return database.query(new SelectListQuery<L2Character>() {
|
||||||
@Override
|
@Override
|
||||||
protected String query() {
|
protected String query() {
|
||||||
@@ -168,7 +190,7 @@ public class MySQL5CharacterDAO extends AbstractMySQL5DAO<L2Character>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void parametize(PreparedStatement st) throws SQLException {
|
protected void parametize(PreparedStatement st) throws SQLException {
|
||||||
st.setString(1, username);
|
st.setString(1, account.getID());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -221,7 +243,7 @@ public class MySQL5CharacterDAO extends AbstractMySQL5DAO<L2Character>
|
|||||||
int i = 1;
|
int i = 1;
|
||||||
|
|
||||||
st.setInt(i++, character.getID().getID());
|
st.setInt(i++, character.getID().getID());
|
||||||
st.setString(i++, "rogiel"); // FIXME
|
st.setString(i++, character.getAccountID().getID()); // FIXME
|
||||||
st.setString(i++, character.getName());
|
st.setString(i++, character.getName());
|
||||||
|
|
||||||
st.setString(i++, character.getRace().name());
|
st.setString(i++, character.getRace().name());
|
||||||
|
|||||||
@@ -16,8 +16,16 @@ import com.l2jserver.service.database.MySQLDatabaseService.InsertUpdateQuery;
|
|||||||
import com.l2jserver.service.database.MySQLDatabaseService.Mapper;
|
import com.l2jserver.service.database.MySQLDatabaseService.Mapper;
|
||||||
import com.l2jserver.service.database.MySQLDatabaseService.SelectListQuery;
|
import com.l2jserver.service.database.MySQLDatabaseService.SelectListQuery;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link CharacterFriendDAO} implementation for MySQL5
|
||||||
|
*
|
||||||
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
|
*/
|
||||||
public class MySQL5CharacterFriendDAO extends AbstractMySQL5DAO<CharacterID>
|
public class MySQL5CharacterFriendDAO extends AbstractMySQL5DAO<CharacterID>
|
||||||
implements CharacterFriendDAO {
|
implements CharacterFriendDAO {
|
||||||
|
/**
|
||||||
|
* The {@link CharacterID} factory
|
||||||
|
*/
|
||||||
private final CharacterIDFactory idFactory;
|
private final CharacterIDFactory idFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.l2jserver.db.dao.ItemDAO;
|
import com.l2jserver.db.dao.ItemDAO;
|
||||||
|
import com.l2jserver.model.id.object.CharacterID;
|
||||||
import com.l2jserver.model.id.object.ItemID;
|
import com.l2jserver.model.id.object.ItemID;
|
||||||
import com.l2jserver.model.id.object.factory.CharacterIDFactory;
|
import com.l2jserver.model.id.object.factory.CharacterIDFactory;
|
||||||
import com.l2jserver.model.id.object.factory.ItemIDFactory;
|
import com.l2jserver.model.id.object.factory.ItemIDFactory;
|
||||||
@@ -21,9 +22,23 @@ import com.l2jserver.service.database.MySQLDatabaseService.Mapper;
|
|||||||
import com.l2jserver.service.database.MySQLDatabaseService.SelectListQuery;
|
import com.l2jserver.service.database.MySQLDatabaseService.SelectListQuery;
|
||||||
import com.l2jserver.service.database.MySQLDatabaseService.SelectSingleQuery;
|
import com.l2jserver.service.database.MySQLDatabaseService.SelectSingleQuery;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link ItemDAO} implementation for MySQL5
|
||||||
|
*
|
||||||
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
|
*/
|
||||||
public class MySQL5ItemDAO extends AbstractMySQL5DAO<Item> implements ItemDAO {
|
public class MySQL5ItemDAO extends AbstractMySQL5DAO<Item> implements ItemDAO {
|
||||||
|
/**
|
||||||
|
* The {@link ItemID} factory
|
||||||
|
*/
|
||||||
private final ItemIDFactory idFactory;
|
private final ItemIDFactory idFactory;
|
||||||
|
/**
|
||||||
|
* The {@link ItemTemplateID} factory
|
||||||
|
*/
|
||||||
private final ItemTemplateIDFactory templateIdFactory;
|
private final ItemTemplateIDFactory templateIdFactory;
|
||||||
|
/**
|
||||||
|
* The {@link CharacterID} factory
|
||||||
|
*/
|
||||||
private final CharacterIDFactory charIdFactory;
|
private final CharacterIDFactory charIdFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -46,7 +61,17 @@ public class MySQL5ItemDAO extends AbstractMySQL5DAO<Item> implements ItemDAO {
|
|||||||
this.charIdFactory = charIdFactory;
|
this.charIdFactory = charIdFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class CharacterMapper implements Mapper<Item> {
|
/**
|
||||||
|
* The {@link Mapper} instance
|
||||||
|
*/
|
||||||
|
private final ItemMapper mapper = new ItemMapper();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link Item} mapper class
|
||||||
|
*
|
||||||
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
|
*/
|
||||||
|
private final class ItemMapper implements Mapper<Item> {
|
||||||
@Override
|
@Override
|
||||||
public Item map(ResultSet rs) throws SQLException {
|
public Item map(ResultSet rs) throws SQLException {
|
||||||
final ItemTemplateID templateId = templateIdFactory.createID(rs
|
final ItemTemplateID templateId = templateIdFactory.createID(rs
|
||||||
@@ -77,7 +102,7 @@ public class MySQL5ItemDAO extends AbstractMySQL5DAO<Item> implements ItemDAO {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Mapper<Item> mapper() {
|
protected Mapper<Item> mapper() {
|
||||||
return new CharacterMapper();
|
return mapper;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -99,7 +124,7 @@ public class MySQL5ItemDAO extends AbstractMySQL5DAO<Item> implements ItemDAO {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Mapper<Item> mapper() {
|
protected Mapper<Item> mapper() {
|
||||||
return new CharacterMapper();
|
return mapper;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
inventory.load(items);
|
inventory.load(items);
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.l2jserver.game.net;
|
package com.l2jserver.game.net;
|
||||||
|
|
||||||
|
import com.l2jserver.model.id.AccountID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lineage 2 session with the username and loginserver keys
|
* Lineage 2 session with the username and loginserver keys
|
||||||
*
|
*
|
||||||
@@ -7,9 +9,9 @@ package com.l2jserver.game.net;
|
|||||||
*/
|
*/
|
||||||
public class Lineage2Session {
|
public class Lineage2Session {
|
||||||
/**
|
/**
|
||||||
* The username
|
* The account ID
|
||||||
*/
|
*/
|
||||||
private final String username;
|
private final AccountID accountID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The play key, part 1
|
* The play key, part 1
|
||||||
@@ -32,8 +34,8 @@ public class Lineage2Session {
|
|||||||
/**
|
/**
|
||||||
* Creates a new instance
|
* Creates a new instance
|
||||||
*
|
*
|
||||||
* @param username
|
* @param accountID
|
||||||
* the username
|
* the account ID
|
||||||
* @param playOK1
|
* @param playOK1
|
||||||
* the play key, part 1
|
* the play key, part 1
|
||||||
* @param playOK2
|
* @param playOK2
|
||||||
@@ -43,9 +45,9 @@ public class Lineage2Session {
|
|||||||
* @param loginOK2
|
* @param loginOK2
|
||||||
* the login key, part 2
|
* the login key, part 2
|
||||||
*/
|
*/
|
||||||
public Lineage2Session(String username, int playOK1, int playOK2,
|
public Lineage2Session(AccountID accountID, int playOK1, int playOK2,
|
||||||
int loginOK1, int loginOK2) {
|
int loginOK1, int loginOK2) {
|
||||||
this.username = username;
|
this.accountID = accountID;
|
||||||
this.playKey1 = playOK1;
|
this.playKey1 = playOK1;
|
||||||
this.playKey2 = playOK2;
|
this.playKey2 = playOK2;
|
||||||
this.loginKey1 = loginOK1;
|
this.loginKey1 = loginOK1;
|
||||||
@@ -53,10 +55,10 @@ public class Lineage2Session {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the username
|
* @return the account ID
|
||||||
*/
|
*/
|
||||||
public String getUsername() {
|
public AccountID getAccountID() {
|
||||||
return username;
|
return accountID;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import com.l2jserver.game.net.Lineage2Connection;
|
|||||||
import com.l2jserver.game.net.Lineage2Session;
|
import com.l2jserver.game.net.Lineage2Session;
|
||||||
import com.l2jserver.game.net.packet.AbstractClientPacket;
|
import com.l2jserver.game.net.packet.AbstractClientPacket;
|
||||||
import com.l2jserver.game.net.packet.server.CharacterEnterWorldPacket;
|
import com.l2jserver.game.net.packet.server.CharacterEnterWorldPacket;
|
||||||
|
import com.l2jserver.model.id.AccountID;
|
||||||
|
import com.l2jserver.model.id.factory.AccountIDFactory;
|
||||||
import com.l2jserver.model.world.L2Character;
|
import com.l2jserver.model.world.L2Character;
|
||||||
import com.l2jserver.util.BufferUtils;
|
import com.l2jserver.util.BufferUtils;
|
||||||
|
|
||||||
@@ -24,6 +26,7 @@ public class AuthLoginPacket extends AbstractClientPacket {
|
|||||||
public static final int OPCODE = 0x2b;
|
public static final int OPCODE = 0x2b;
|
||||||
|
|
||||||
private final CharacterDAO characterDao;
|
private final CharacterDAO characterDao;
|
||||||
|
private final AccountIDFactory accountIdFactory;
|
||||||
|
|
||||||
// packet
|
// packet
|
||||||
private String loginName;
|
private String loginName;
|
||||||
@@ -33,8 +36,10 @@ public class AuthLoginPacket extends AbstractClientPacket {
|
|||||||
private int loginKey2;
|
private int loginKey2;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public AuthLoginPacket(CharacterDAO characterDao) {
|
public AuthLoginPacket(CharacterDAO characterDao,
|
||||||
|
AccountIDFactory accountIdFactory) {
|
||||||
this.characterDao = characterDao;
|
this.characterDao = characterDao;
|
||||||
|
this.accountIdFactory = accountIdFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -48,11 +53,11 @@ public class AuthLoginPacket extends AbstractClientPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void process(final Lineage2Connection conn) {
|
public void process(final Lineage2Connection conn) {
|
||||||
conn.setSession(new Lineage2Session(loginName, playKey1, playKey2,
|
final AccountID accountId = accountIdFactory.createID(loginName);
|
||||||
|
conn.setSession(new Lineage2Session(accountId, playKey1, playKey2,
|
||||||
loginKey1, loginKey2));
|
loginKey1, loginKey2));
|
||||||
|
|
||||||
final List<L2Character> chars = characterDao.selectByAccount(conn
|
final List<L2Character> chars = characterDao.selectByAccount(accountId);
|
||||||
.getSession().getUsername());
|
|
||||||
// conn.write(CharacterSelectionListPacket.fromL2Session(
|
// conn.write(CharacterSelectionListPacket.fromL2Session(
|
||||||
// conn.getSession(), chars.toArray(new L2Character[0])));
|
// conn.getSession(), chars.toArray(new L2Character[0])));
|
||||||
conn.write(new CharacterEnterWorldPacket(chars.get(0), playKey1));
|
conn.write(new CharacterEnterWorldPacket(chars.get(0), playKey1));
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public class RequestGotoLobby extends AbstractClientPacket {
|
|||||||
@Override
|
@Override
|
||||||
public void process(final Lineage2Connection conn) {
|
public void process(final Lineage2Connection conn) {
|
||||||
final List<L2Character> chars = characterDao.selectByAccount(conn
|
final List<L2Character> chars = characterDao.selectByAccount(conn
|
||||||
.getSession().getUsername());
|
.getSession().getAccountID());
|
||||||
conn.write(CharacterSelectionListPacket.fromL2Session(
|
conn.write(CharacterSelectionListPacket.fromL2Session(
|
||||||
conn.getSession(), chars.toArray(new L2Character[0])));
|
conn.getSession(), chars.toArray(new L2Character[0])));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public class CharacterSelectionListPacket extends AbstractServerPacket {
|
|||||||
|
|
||||||
public static CharacterSelectionListPacket fromL2Session(
|
public static CharacterSelectionListPacket fromL2Session(
|
||||||
Lineage2Session session, L2Character... characters) {
|
Lineage2Session session, L2Character... characters) {
|
||||||
return new CharacterSelectionListPacket(session.getUsername(),
|
return new CharacterSelectionListPacket(session.getAccountID().getID(),
|
||||||
session.getPlayKey2(), -1, characters);
|
session.getPlayKey2(), -1, characters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
21
src/main/java/com/l2jserver/model/id/AccountID.java
Normal file
21
src/main/java/com/l2jserver/model/id/AccountID.java
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package com.l2jserver.model.id;
|
||||||
|
|
||||||
|
import com.google.inject.assistedinject.Assisted;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Each account is identified by its {@link ID}. This {@link ID} is equal to the
|
||||||
|
* account username or login.
|
||||||
|
*
|
||||||
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
|
*/
|
||||||
|
public class AccountID extends ID<String> {
|
||||||
|
/**
|
||||||
|
* Creates a new instance
|
||||||
|
*
|
||||||
|
* @param login
|
||||||
|
* the login
|
||||||
|
*/
|
||||||
|
public AccountID(@Assisted String login) {
|
||||||
|
super(login);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,30 +1,27 @@
|
|||||||
package com.l2jserver.model.id;
|
package com.l2jserver.model.id;
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.l2jserver.model.template.Template;
|
|
||||||
import com.l2jserver.model.world.WorldObject;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The ID interface. Each {@link WorldObject} or {@link Template} must be
|
* The ID interface. Each object must be represented by an unique ID.
|
||||||
* represented by an unique ID.
|
|
||||||
*
|
*
|
||||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
*/
|
*/
|
||||||
public abstract class ID {
|
public abstract class ID<T> {
|
||||||
/**
|
/**
|
||||||
* The id itself
|
* The id itself
|
||||||
*/
|
*/
|
||||||
protected final int id;
|
protected final T id;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected ID(int id) {
|
protected ID(T id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the id
|
* @return the id
|
||||||
*/
|
*/
|
||||||
public int getID() {
|
public T getID() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,7 +34,7 @@ public abstract class ID {
|
|||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
int result = 1;
|
int result = 1;
|
||||||
result = prime * result + id + this.getClass().hashCode();
|
result = prime * result + id.hashCode() + this.getClass().hashCode();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,9 +46,14 @@ public abstract class ID {
|
|||||||
return false;
|
return false;
|
||||||
if (getClass() != obj.getClass())
|
if (getClass() != obj.getClass())
|
||||||
return false;
|
return false;
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
ID other = (ID) obj;
|
ID other = (ID) obj;
|
||||||
if (id != other.id)
|
if (id == null) {
|
||||||
|
if (other.id != null)
|
||||||
|
return false;
|
||||||
|
} else if (!id.equals(other.id))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import com.l2jserver.model.world.WorldObject;
|
|||||||
* @param <T>
|
* @param <T>
|
||||||
* the {@link WorldObject} type
|
* the {@link WorldObject} type
|
||||||
*/
|
*/
|
||||||
public abstract class ObjectID<T extends WorldObject> extends ID {
|
public abstract class ObjectID<T extends WorldObject> extends ID<Integer> {
|
||||||
/**
|
/**
|
||||||
* Creates a new instance
|
* Creates a new instance
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import com.l2jserver.model.template.Template;
|
|||||||
*
|
*
|
||||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
*/
|
*/
|
||||||
public abstract class TemplateID<T extends Template<?>> extends ID {
|
public abstract class TemplateID<T extends Template<?>> extends ID<Integer> {
|
||||||
/**
|
/**
|
||||||
* Creates a new instance
|
* Creates a new instance
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.l2jserver.model.id.factory;
|
||||||
|
|
||||||
|
import com.l2jserver.model.id.AccountID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link AccountID}
|
||||||
|
*
|
||||||
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
|
*/
|
||||||
|
public interface AccountIDFactory extends IDFactory<String, AccountID> {
|
||||||
|
}
|
||||||
@@ -8,12 +8,12 @@ import com.l2jserver.model.id.ID;
|
|||||||
*
|
*
|
||||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
*/
|
*/
|
||||||
public interface IDFactory<T extends ID> {
|
public interface IDFactory<I, T extends ID<?>> {
|
||||||
/**
|
/**
|
||||||
* Creates the ID object for an <b>EXISTING</b> ID.
|
* Creates the ID object for an <b>EXISTING</b> ID.
|
||||||
*
|
*
|
||||||
* @param id
|
* @param id
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
T createID(int id);
|
T createID(I id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,9 @@ public class IDFactoryModule extends AbstractModule {
|
|||||||
bind(IDAllocator.class).to(BitSetIDAllocator.class)
|
bind(IDAllocator.class).to(BitSetIDAllocator.class)
|
||||||
.in(Scopes.SINGLETON);
|
.in(Scopes.SINGLETON);
|
||||||
|
|
||||||
|
// ACCOUNT ID
|
||||||
|
install(new FactoryModuleBuilder().build(AccountIDFactory.class));
|
||||||
|
|
||||||
// OBJECT IDS
|
// OBJECT IDS
|
||||||
bind(CharacterIDFactory.class).in(Scopes.SINGLETON);
|
bind(CharacterIDFactory.class).in(Scopes.SINGLETON);
|
||||||
install(new FactoryModuleBuilder().build(CharacterIDGuiceFactory.class));
|
install(new FactoryModuleBuilder().build(CharacterIDGuiceFactory.class));
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public class CharacterIDFactory implements ObjectIDFactory<CharacterID> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharacterID createID(int id) {
|
public CharacterID createID(Integer id) {
|
||||||
return factory.create(id);
|
return factory.create(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public class ClanIDFactory implements ObjectIDFactory<ClanID> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ClanID createID(int id) {
|
public ClanID createID(Integer id) {
|
||||||
return factory.create(id);
|
return factory.create(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public class ItemIDFactory implements ObjectIDFactory<ItemID> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemID createID(int id) {
|
public ItemID createID(Integer id) {
|
||||||
return factory.create(id);
|
return factory.create(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ package com.l2jserver.model.id.object.factory;
|
|||||||
import com.l2jserver.model.id.ObjectID;
|
import com.l2jserver.model.id.ObjectID;
|
||||||
import com.l2jserver.model.id.factory.IDFactory;
|
import com.l2jserver.model.id.factory.IDFactory;
|
||||||
|
|
||||||
public interface ObjectIDFactory<T extends ObjectID<?>> extends IDFactory<T> {
|
public interface ObjectIDFactory<T extends ObjectID<?>> extends
|
||||||
|
IDFactory<Integer, T> {
|
||||||
/**
|
/**
|
||||||
* Generates a new ID
|
* Generates a new ID
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public class PetIDFactory implements ObjectIDFactory<PetID> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PetID createID(int id) {
|
public PetID createID(Integer id) {
|
||||||
return factory.create(id);
|
return factory.create(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,5 +12,5 @@ import com.l2jserver.model.id.factory.IDFactory;
|
|||||||
* the subclass of {@link TemplateID} that will be createdF
|
* the subclass of {@link TemplateID} that will be createdF
|
||||||
*/
|
*/
|
||||||
public interface TemplateIDFactory<T extends TemplateID<?>> extends
|
public interface TemplateIDFactory<T extends TemplateID<?>> extends
|
||||||
IDFactory<T> {
|
IDFactory<Integer, T> {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.l2jserver.model.world;
|
|||||||
|
|
||||||
import java.sql.Date;
|
import java.sql.Date;
|
||||||
|
|
||||||
|
import com.l2jserver.model.id.AccountID;
|
||||||
import com.l2jserver.model.id.object.CharacterID;
|
import com.l2jserver.model.id.object.CharacterID;
|
||||||
import com.l2jserver.model.id.object.ClanID;
|
import com.l2jserver.model.id.object.ClanID;
|
||||||
import com.l2jserver.model.id.object.PetID;
|
import com.l2jserver.model.id.object.PetID;
|
||||||
@@ -19,6 +20,10 @@ import com.l2jserver.model.world.character.CharacterInventory;
|
|||||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
*/
|
*/
|
||||||
public class L2Character extends Player {
|
public class L2Character extends Player {
|
||||||
|
/**
|
||||||
|
* The account id
|
||||||
|
*/
|
||||||
|
private AccountID accountID;
|
||||||
/**
|
/**
|
||||||
* The clan id
|
* The clan id
|
||||||
*/
|
*/
|
||||||
@@ -76,9 +81,19 @@ public class L2Character extends Player {
|
|||||||
this.attributes = new CharacterCalculatedAttributes(this);
|
this.attributes = new CharacterCalculatedAttributes(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public CharacterID getID() {
|
* @return the account ID
|
||||||
return (CharacterID) super.getID();
|
*/
|
||||||
|
public AccountID getAccountID() {
|
||||||
|
return accountID;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param accountID
|
||||||
|
* the account ID to set
|
||||||
|
*/
|
||||||
|
public void setAccountID(AccountID accountID) {
|
||||||
|
this.accountID = accountID;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -223,4 +238,9 @@ public class L2Character extends Player {
|
|||||||
public CharacterFriendList getFriendList() {
|
public CharacterFriendList getFriendList() {
|
||||||
return friendList;
|
return friendList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CharacterID getID() {
|
||||||
|
return (CharacterID) super.getID();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.l2jserver.model.world.filter.impl;
|
package com.l2jserver.model.world.filter.impl;
|
||||||
|
|
||||||
import com.l2jserver.model.id.ID;
|
import com.l2jserver.model.id.ObjectID;
|
||||||
import com.l2jserver.model.world.capability.Positionable;
|
import com.l2jserver.model.world.capability.Positionable;
|
||||||
import com.l2jserver.model.world.filter.WorldObjectFilter;
|
import com.l2jserver.model.world.filter.WorldObjectFilter;
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ public class IDFilter implements WorldObjectFilter<Positionable> {
|
|||||||
/**
|
/**
|
||||||
* The object id
|
* The object id
|
||||||
*/
|
*/
|
||||||
private final ID id;
|
private final ObjectID<?> id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance
|
* Creates a new instance
|
||||||
@@ -21,7 +21,7 @@ public class IDFilter implements WorldObjectFilter<Positionable> {
|
|||||||
* @param id
|
* @param id
|
||||||
* the desired object ID
|
* the desired object ID
|
||||||
*/
|
*/
|
||||||
public IDFilter(final ID id) {
|
public IDFilter(final ObjectID<?> id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ public class IDFactoryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateID() {
|
public void testCreateID() {
|
||||||
final ID id1 = charIdFactory.createID();
|
final ID<Integer> id1 = charIdFactory.createID();
|
||||||
final ID id2 = charIdFactory.createID();
|
final ID<Integer> id2 = charIdFactory.createID();
|
||||||
Assert.assertNotNull(id1);
|
Assert.assertNotNull(id1);
|
||||||
Assert.assertFalse(id1.equals(id2));
|
Assert.assertFalse(id1.equals(id2));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user