1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-08 08:23:11 +00:00

Implemented AccountID object

Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
2011-05-14 14:35:18 -03:00
parent fddc6fbfbb
commit d8d561688b
27 changed files with 200 additions and 54 deletions

View File

@@ -1,5 +1,7 @@
package com.l2jserver.game.net;
import com.l2jserver.model.id.AccountID;
/**
* Lineage 2 session with the username and loginserver keys
*
@@ -7,9 +9,9 @@ package com.l2jserver.game.net;
*/
public class Lineage2Session {
/**
* The username
* The account ID
*/
private final String username;
private final AccountID accountID;
/**
* The play key, part 1
@@ -32,8 +34,8 @@ public class Lineage2Session {
/**
* Creates a new instance
*
* @param username
* the username
* @param accountID
* the account ID
* @param playOK1
* the play key, part 1
* @param playOK2
@@ -43,9 +45,9 @@ public class Lineage2Session {
* @param loginOK2
* 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) {
this.username = username;
this.accountID = accountID;
this.playKey1 = playOK1;
this.playKey2 = playOK2;
this.loginKey1 = loginOK1;
@@ -53,10 +55,10 @@ public class Lineage2Session {
}
/**
* @return the username
* @return the account ID
*/
public String getUsername() {
return username;
public AccountID getAccountID() {
return accountID;
}
/**

View File

@@ -10,6 +10,8 @@ import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.Lineage2Session;
import com.l2jserver.game.net.packet.AbstractClientPacket;
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.util.BufferUtils;
@@ -24,6 +26,7 @@ public class AuthLoginPacket extends AbstractClientPacket {
public static final int OPCODE = 0x2b;
private final CharacterDAO characterDao;
private final AccountIDFactory accountIdFactory;
// packet
private String loginName;
@@ -33,8 +36,10 @@ public class AuthLoginPacket extends AbstractClientPacket {
private int loginKey2;
@Inject
public AuthLoginPacket(CharacterDAO characterDao) {
public AuthLoginPacket(CharacterDAO characterDao,
AccountIDFactory accountIdFactory) {
this.characterDao = characterDao;
this.accountIdFactory = accountIdFactory;
}
@Override
@@ -48,11 +53,11 @@ public class AuthLoginPacket extends AbstractClientPacket {
@Override
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));
final List<L2Character> chars = characterDao.selectByAccount(conn
.getSession().getUsername());
final List<L2Character> chars = characterDao.selectByAccount(accountId);
// conn.write(CharacterSelectionListPacket.fromL2Session(
// conn.getSession(), chars.toArray(new L2Character[0])));
conn.write(new CharacterEnterWorldPacket(chars.get(0), playKey1));

View File

@@ -35,7 +35,7 @@ public class RequestGotoLobby extends AbstractClientPacket {
@Override
public void process(final Lineage2Connection conn) {
final List<L2Character> chars = characterDao.selectByAccount(conn
.getSession().getUsername());
.getSession().getAccountID());
conn.write(CharacterSelectionListPacket.fromL2Session(
conn.getSession(), chars.toArray(new L2Character[0])));
}

View File

@@ -34,7 +34,7 @@ public class CharacterSelectionListPacket extends AbstractServerPacket {
public static CharacterSelectionListPacket fromL2Session(
Lineage2Session session, L2Character... characters) {
return new CharacterSelectionListPacket(session.getUsername(),
return new CharacterSelectionListPacket(session.getAccountID().getID(),
session.getPlayKey2(), -1, characters);
}

View 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);
}
}

View File

@@ -1,30 +1,27 @@
package com.l2jserver.model.id;
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
* represented by an unique ID.
* The ID interface. Each object must be represented by an unique ID.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class ID {
public abstract class ID<T> {
/**
* The id itself
*/
protected final int id;
protected final T id;
@Inject
protected ID(int id) {
protected ID(T id) {
this.id = id;
}
/**
* @return the id
*/
public int getID() {
public T getID() {
return id;
}
@@ -37,7 +34,7 @@ public abstract class ID {
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + id + this.getClass().hashCode();
result = prime * result + id.hashCode() + this.getClass().hashCode();
return result;
}
@@ -49,9 +46,14 @@ public abstract class ID {
return false;
if (getClass() != obj.getClass())
return false;
@SuppressWarnings("rawtypes")
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 true;
}
}

View File

@@ -14,7 +14,7 @@ import com.l2jserver.model.world.WorldObject;
* @param <T>
* 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
*

View File

@@ -8,7 +8,7 @@ import com.l2jserver.model.template.Template;
*
* @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
*

View File

@@ -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> {
}

View File

@@ -8,12 +8,12 @@ import com.l2jserver.model.id.ID;
*
* @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.
*
* @param id
* @return
*/
T createID(int id);
T createID(I id);
}

View File

@@ -25,6 +25,9 @@ public class IDFactoryModule extends AbstractModule {
bind(IDAllocator.class).to(BitSetIDAllocator.class)
.in(Scopes.SINGLETON);
// ACCOUNT ID
install(new FactoryModuleBuilder().build(AccountIDFactory.class));
// OBJECT IDS
bind(CharacterIDFactory.class).in(Scopes.SINGLETON);
install(new FactoryModuleBuilder().build(CharacterIDGuiceFactory.class));

View File

@@ -35,7 +35,7 @@ public class CharacterIDFactory implements ObjectIDFactory<CharacterID> {
}
@Override
public CharacterID createID(int id) {
public CharacterID createID(Integer id) {
return factory.create(id);
}

View File

@@ -34,7 +34,7 @@ public class ClanIDFactory implements ObjectIDFactory<ClanID> {
}
@Override
public ClanID createID(int id) {
public ClanID createID(Integer id) {
return factory.create(id);
}

View File

@@ -34,7 +34,7 @@ public class ItemIDFactory implements ObjectIDFactory<ItemID> {
}
@Override
public ItemID createID(int id) {
public ItemID createID(Integer id) {
return factory.create(id);
}

View File

@@ -3,7 +3,8 @@ package com.l2jserver.model.id.object.factory;
import com.l2jserver.model.id.ObjectID;
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
*

View File

@@ -34,7 +34,7 @@ public class PetIDFactory implements ObjectIDFactory<PetID> {
}
@Override
public PetID createID(int id) {
public PetID createID(Integer id) {
return factory.create(id);
}

View File

@@ -12,5 +12,5 @@ import com.l2jserver.model.id.factory.IDFactory;
* the subclass of {@link TemplateID} that will be createdF
*/
public interface TemplateIDFactory<T extends TemplateID<?>> extends
IDFactory<T> {
IDFactory<Integer, T> {
}

View File

@@ -2,6 +2,7 @@ package com.l2jserver.model.world;
import java.sql.Date;
import com.l2jserver.model.id.AccountID;
import com.l2jserver.model.id.object.CharacterID;
import com.l2jserver.model.id.object.ClanID;
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>
*/
public class L2Character extends Player {
/**
* The account id
*/
private AccountID accountID;
/**
* The clan id
*/
@@ -76,9 +81,19 @@ public class L2Character extends Player {
this.attributes = new CharacterCalculatedAttributes(this);
}
@Override
public CharacterID getID() {
return (CharacterID) super.getID();
/**
* @return the account ID
*/
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() {
return friendList;
}
@Override
public CharacterID getID() {
return (CharacterID) super.getID();
}
}

View File

@@ -1,6 +1,6 @@
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.filter.WorldObjectFilter;
@@ -13,7 +13,7 @@ public class IDFilter implements WorldObjectFilter<Positionable> {
/**
* The object id
*/
private final ID id;
private final ObjectID<?> id;
/**
* Creates a new instance
@@ -21,7 +21,7 @@ public class IDFilter implements WorldObjectFilter<Positionable> {
* @param id
* the desired object ID
*/
public IDFilter(final ID id) {
public IDFilter(final ObjectID<?> id) {
this.id = id;
}