1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-10 09:22:49 +00:00

Written javadoc for many classes

Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
2011-05-14 01:51:40 -03:00
parent 14b928cc3b
commit e9c6f1b027
85 changed files with 1205 additions and 26 deletions

View File

@@ -18,17 +18,44 @@ import com.l2jserver.model.world.L2Character;
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class Lineage2Connection {
/**
* The connection channel
*/
private final Channel channel;
/**
* The character object
*/
private L2Character character;
/**
* The Lineage 2 session
*/
private Lineage2Session session;
/**
* The connection state
*/
private ConnectionState state = ConnectionState.CONNECTED;
/**
* Each connection is represented by an state: connected, authenticated and
* in-game.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public enum ConnectionState {
CONNECTED, AUTHENTICATED, IN_GAME;
}
/**
* The client supported protocol version
*/
private ProtocolVersion version;
/**
* Creates a new instance
*
* @param channel
* the channel
*/
public Lineage2Connection(Channel channel) {
this.channel = channel;
}
@@ -116,6 +143,10 @@ public class Lineage2Connection {
return version.supports(version);
}
/**
* Get the channel
* @return the channel
*/
public Channel getChannel() {
return channel;
}

View File

@@ -1,16 +1,39 @@
package com.l2jserver.game.net;
import java.util.Arrays;
import com.l2jserver.util.BlowFishKeygen;
/**
* Manages the cryptography key used to write/read packets. This class also
* updates the key once data has been sent/received.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class Lineage2CryptographyKey implements Cloneable {
/**
* The raw key
*/
public final byte[] key;
/**
* Creates a new instance
*
* @param key
* the raw key
*/
public Lineage2CryptographyKey(byte[] key) {
this.key = key;
}
/**
* Crates a new random key
*
* @return the random created key
*/
public static Lineage2CryptographyKey createRandomKey() {
return new Lineage2CryptographyKey(BlowFishKeygen.getRandomKey());
return new Lineage2CryptographyKey(Arrays.copyOf(
BlowFishKeygen.getRandomKey(), 16));
}
/**
@@ -20,10 +43,23 @@ public class Lineage2CryptographyKey implements Cloneable {
return key;
}
/**
* Get the key value for byte index <tt>i</tt>
*
* @param i
* the index i
* @return the key byte
*/
public byte get(int i) {
return key[i & 15];
}
/**
* Updates this key once data has been sent/received.
*
* @param size
* the data size
*/
public void update(int size) {
int old = key[8] & 0xff;
old |= key[9] << 8 & 0xff00;

View File

@@ -17,7 +17,16 @@ import com.l2jserver.game.net.codec.Lineage2PacketReader;
import com.l2jserver.game.net.codec.Lineage2PacketWriter;
import com.l2jserver.game.net.handler.Lineage2PacketHandler;
/**
* This class creates a new instance of {@link ChannelPipeline} and attaches all
* handlers and codecs.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class Lineage2PipelineFactory implements ChannelPipelineFactory {
/**
* The Google Guice {@link Injector}.
*/
private final Injector injector;
@Inject

View File

@@ -1,14 +1,48 @@
package com.l2jserver.game.net;
/**
* Lineage 2 session with the username and loginserver keys
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class Lineage2Session {
/**
* The username
*/
private final String username;
/**
* The play key, part 1
*/
private final int playKey1;
/**
* The play key, part 2
*/
private final int playKey2;
/**
* The login key, part 1
*/
private final int loginKey1;
/**
* The login key, part 2
*/
private final int loginKey2;
/**
* Creates a new instance
*
* @param username
* the username
* @param playOK1
* the play key, part 1
* @param playOK2
* the play key, part 2
* @param loginOK1
* the login key, part 1
* @param loginOK2
* the login key, part 2
*/
public Lineage2Session(String username, int playOK1, int playOK2,
int loginOK1, int loginOK2) {
this.username = username;

View File

@@ -7,10 +7,24 @@ import org.jboss.netty.handler.codec.oneone.OneToOneDecoder;
import com.l2jserver.game.net.Lineage2CryptographyKey;
/**
* Decrypts encrypted Lineage II packets
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class Lineage2Decrypter extends OneToOneDecoder {
/**
* The handler name
*/
public static final String HANDLER_NAME = "crypto.decoder";
/**
* Enabled state
*/
private boolean enabled = false;
/**
* Crypto key
*/
private Lineage2CryptographyKey key;
@Override
@@ -37,6 +51,11 @@ public class Lineage2Decrypter extends OneToOneDecoder {
return buffer;
}
/**
* Creates a random key and enables descrypting
*
* @return the generated key
*/
public Lineage2CryptographyKey enable() {
Lineage2CryptographyKey key = Lineage2CryptographyKey.createRandomKey();
this.setKey(key);
@@ -44,6 +63,12 @@ public class Lineage2Decrypter extends OneToOneDecoder {
return key;
}
/**
* Set this decrypter key. The key can only be set once.
*
* @param key
* the key
*/
public void setKey(Lineage2CryptographyKey key) {
if (this.key != null)
throw new IllegalStateException("Key is already set");

View File

@@ -7,10 +7,24 @@ import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
import com.l2jserver.game.net.Lineage2CryptographyKey;
/**
* Encrypts Lineage II packets
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class Lineage2Encrypter extends OneToOneEncoder {
/**
* The handler name
*/
public static final String HANDLER_NAME = "crypto.encoder";
/**
* Enabled state
*/
private boolean enabled = false;
/**
* Crypto key
*/
private Lineage2CryptographyKey key;
@Override
@@ -37,11 +51,23 @@ public class Lineage2Encrypter extends OneToOneEncoder {
return msg;
}
/**
* Enables this encrypter with the given <tt>key</tt>
*
* @param key
* the key
*/
public void enable(Lineage2CryptographyKey key) {
this.setKey(key);
this.setEnabled(true);
}
/**
* Set this decrypter key. The key can only be set once.
*
* @param key
* the key
*/
public void setKey(Lineage2CryptographyKey key) {
if (this.key != null)
throw new IllegalStateException("Key is already set");

View File

@@ -10,6 +10,12 @@ import org.jboss.netty.handler.codec.frame.FrameDecoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This decoder parses Lineage II frames. Each frame is has a header of 2 bytes
* unsigned short.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class Lineage2FrameDecoder extends FrameDecoder {
private static final int HEADER_SIZE = 2;

View File

@@ -5,6 +5,12 @@ import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
/**
* This encoder creates Lineage II frames. Each frame is has a header of 2 bytes
* unsigned short.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class Lineage2FrameEncoder extends OneToOneEncoder {
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel,

View File

@@ -21,15 +21,43 @@ import com.l2jserver.game.net.packet.client.RequestGotoLobby;
import com.l2jserver.game.net.packet.client.RequestKeyMapping;
import com.l2jserver.game.net.packet.client.RequestManorList;
/**
* This decoder reads an frame and decodes the packet in it. Each packet has an
* fixed single opcode byte. Once the packet has been identified, reading is
* done by the {@link ClientPacket} class.
* <p>
* Note that some packets have an additional opcode. This class also handle
* those cases.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class Lineage2PacketReader extends OneToOneDecoder {
/**
* The handler name
*/
public static final String HANDLER_NAME = "packet.reader";
/**
* The Google Guice {@link Injector}
*/
private final Injector injector;
/**
* The logger
*/
private final Logger logger = LoggerFactory
.getLogger(Lineage2PacketReader.class);
/**
* The active Lineage 2 connection
*/
private Lineage2Connection connection;
/**
* Creates a new instance
*
* @param injector
* the injector
*/
@Inject
public Lineage2PacketReader(Injector injector) {
this.injector = injector;
@@ -48,12 +76,26 @@ public class Lineage2PacketReader extends OneToOneDecoder {
return packet;
}
/**
* Crates a new instance of the packet <tt>type</tt>
*
* @param type
* the packet type
* @return the created packet
*/
private ClientPacket createPacket(Class<? extends ClientPacket> type) {
if (type == null)
return null;
return injector.getInstance(type);
}
/**
* Discovers the packet type
*
* @param buffer
* the buffer
* @return the packet class
*/
private Class<? extends ClientPacket> getPacketClass(ChannelBuffer buffer) {
final short opcode = buffer.readUnsignedByte();
switch (opcode) {

View File

@@ -13,12 +13,28 @@ import org.slf4j.LoggerFactory;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.ServerPacket;
/**
* This encoder writes the frame content and encodes the packet in it. Each
* packet has an fixed single opcode byte. Once the packet opcode has been
* written, packet data is written by the {@link ServerPacket} class.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class Lineage2PacketWriter extends OneToOneEncoder {
/**
* The handler name
*/
public static final String HANDLER_NAME = "packet.writer";
/**
* The logger
*/
private static final Logger log = LoggerFactory
.getLogger(Lineage2PacketWriter.class);
/**
* The active Lineage 2 connection
*/
private Lineage2Connection connection;
@Override

View File

@@ -8,7 +8,17 @@ import org.jboss.netty.channel.SimpleChannelHandler;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.ClientPacket;
/**
* This handler dispatches the {@link ClientPacket#process(Lineage2Connection)}
* method and creates a new {@link Lineage2Connection} once a new channel is
* open.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class Lineage2PacketHandler extends SimpleChannelHandler {
/**
* The Lineage 2 connection
*/
private Lineage2Connection connection;
@Override

View File

@@ -1,4 +1,10 @@
package com.l2jserver.game.net.packet;
/**
* An abstract {@link ClientPacket}
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
* @see ClientPacket
*/
public abstract class AbstractClientPacket implements ClientPacket {
}

View File

@@ -1,5 +1,11 @@
package com.l2jserver.game.net.packet;
/**
* An abstract {@link ServerPacket}
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
* @see ServerPacket
*/
public abstract class AbstractServerPacket implements ServerPacket {
private final int opcode;

View File

@@ -4,6 +4,11 @@ import org.jboss.netty.buffer.ChannelBuffer;
import com.l2jserver.game.net.Lineage2Connection;
/**
* Each implementation is an packet sent by the game client.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface ClientPacket extends Packet {
/**
* Read binary data in the {@link ChannelBuffer}.

View File

@@ -1,8 +1,14 @@
package com.l2jserver.game.net.packet;
import com.google.inject.AbstractModule;
import com.google.inject.Module;
import com.l2jserver.game.net.packet.client.ProtocolVersionPacket;
/**
* Google Guice {@link Module} for client packets
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class ClientPacketModule extends AbstractModule {
@Override
protected void configure() {

View File

@@ -1,4 +1,10 @@
package com.l2jserver.game.net.packet;
/**
* An simple packet. This must not be used directly, use {@link ClientPacket} or
* {@link ServerPacket} instead.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface Packet {
}

View File

@@ -1,7 +1,13 @@
package com.l2jserver.game.net.packet;
import com.google.inject.AbstractModule;
import com.google.inject.Module;
/**
* Google Guice {@link Module} for packets
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class PacketModule extends AbstractModule {
@Override
protected void configure() {

View File

@@ -4,6 +4,11 @@ import org.jboss.netty.buffer.ChannelBuffer;
import com.l2jserver.game.net.Lineage2Connection;
/**
* Each implementation is an packet sent by the game server.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface ServerPacket extends Packet {
/**
* Writes this packet binary data.

View File

@@ -1,8 +1,14 @@
package com.l2jserver.game.net.packet;
import com.google.inject.AbstractModule;
import com.google.inject.Module;
import com.l2jserver.game.net.packet.client.ProtocolVersionPacket;
/**
* Google Guice {@link Module} for server packets
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class ServerPacketModule extends AbstractModule {
@Override
protected void configure() {