Skip to content

Commit

Permalink
Moved packets back to l2jserver2-gameserver-core module
Browse files Browse the repository at this point in the history
  • Loading branch information
Rogiel committed May 3, 2012
1 parent df55c68 commit 2d80fac
Show file tree
Hide file tree
Showing 172 changed files with 1,089 additions and 8,888 deletions.
17 changes: 17 additions & 0 deletions l2jserver2-common/src/main/java/com/l2jserver/util/ArrayUtils.java
Expand Up @@ -19,6 +19,7 @@
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.StringTokenizer;

import com.l2jserver.util.factory.CollectionFactory;

Expand Down Expand Up @@ -74,4 +75,20 @@ public int compare(Object o1, Object o2) {
public final static <T> boolean contains(T[] array, T expected) {
return Arrays.binarySearch(array, expected) >= 0;
}

/**
* @param tokenizer
* the tokenizer
* @return an array of strings with each parameter
*/
public static String[] createArgumentArray(StringTokenizer tokenizer) {
if (!tokenizer.hasMoreTokens())
return new String[0];
final String[] args = new String[tokenizer.countTokens()];
int i = 0;
while (tokenizer.hasMoreTokens()) {
args[i++] = tokenizer.nextToken();
}
return args;
}
}
26 changes: 24 additions & 2 deletions ...ver/game/net/InterludeLineage2Client.java → ...2jserver/game/net/Lineage2ClientImpl.java 100644 → 100755
Expand Up @@ -37,6 +37,7 @@
import com.l2jserver.model.world.Item;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.service.network.model.Lineage2Client;
import com.l2jserver.service.network.model.Lineage2CryptographyKey;
import com.l2jserver.service.network.model.Lineage2Session;
import com.l2jserver.service.network.model.ProtocolVersion;
import com.l2jserver.service.network.model.SystemMessage;
Expand All @@ -52,7 +53,7 @@
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class InterludeLineage2Client implements Lineage2Client {
public class Lineage2ClientImpl implements Lineage2Client {
/**
* The connection channel
*/
Expand All @@ -77,7 +78,7 @@ public class InterludeLineage2Client implements Lineage2Client {
* @param channel
* the channel
*/
public InterludeLineage2Client(Channel channel) {
public Lineage2ClientImpl(Channel channel) {
this.channel = channel;
}

Expand Down Expand Up @@ -127,6 +128,16 @@ public void setSession(Lineage2Session session) {
this.session = session;
}

@Override
public void enableDecrypter(Lineage2CryptographyKey key) {
channel.getPipeline().get(Lineage2Decrypter.class).enable(key);
}

@Override
public void enableEncrypter(Lineage2CryptographyKey key) {
channel.getPipeline().get(Lineage2Encrypter.class).enable(key);
}

/**
* @return the version
*/
Expand Down Expand Up @@ -157,6 +168,17 @@ public boolean supports(ProtocolVersion version) {
return this.version.supports(version);
}

@Override
public boolean supports(ProtocolVersion from, ProtocolVersion to) {
if (to == this.version)
return true;
if (from == this.version)
return true;
if (to.supports(this.version))
return false;
return true;
}

/**
* Get the channel
*
Expand Down
Expand Up @@ -26,32 +26,32 @@
import org.jboss.netty.channel.SimpleChannelHandler;

import com.google.common.base.Throwables;
import com.l2jserver.game.net.FreyaLineage2Client;
import com.l2jserver.service.network.NettyNetworkService;
import com.l2jserver.game.net.Lineage2ClientImpl;
import com.l2jserver.service.network.AbstractNettyNetworkService;
import com.l2jserver.service.network.model.Lineage2Client;
import com.l2jserver.service.network.model.packet.ClientPacket;
import com.l2jserver.util.html.markup.HtmlTemplate;
import com.l2jserver.util.html.markup.MarkupTag;

/**
* This handler dispatches the {@link ClientPacket#process(Lineage2Client)}
* method and creates a new {@link Lineage2Client} once a new channel is open.
* method and creates a new {@link Lineage2ClientImpl} once a new channel is open.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class Lineage2PacketHandler extends SimpleChannelHandler {
/**
* The {@link NettyNetworkService}
* The {@link AbstractNettyNetworkService}
*/
private final NettyNetworkService nettyNetworkService;
private final AbstractNettyNetworkService nettyNetworkService;
/**
* The timeout handler is responsible for disconnecting idle clients.
*/
private final Lineage2TimeoutHandler timeoutHandler;
/**
* The Lineage 2 connection
*/
private FreyaLineage2Client connection;
private Lineage2ClientImpl connection;

/**
* Creates a new instance of the packet handler
Expand All @@ -61,7 +61,7 @@ public class Lineage2PacketHandler extends SimpleChannelHandler {
* @param timeoutHandler
* the timeout handler
*/
public Lineage2PacketHandler(NettyNetworkService nettyNetworkService,
public Lineage2PacketHandler(AbstractNettyNetworkService nettyNetworkService,
Lineage2TimeoutHandler timeoutHandler) {
this.nettyNetworkService = nettyNetworkService;
this.timeoutHandler = timeoutHandler;
Expand All @@ -70,7 +70,7 @@ public Lineage2PacketHandler(NettyNetworkService nettyNetworkService,
@Override
public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e)
throws Exception {
connection = new FreyaLineage2Client(e.getChannel());
connection = new Lineage2ClientImpl(e.getChannel());
connection.getPacketWriter().setConnection(connection);
timeoutHandler.setConnection(connection);

Expand Down
Expand Up @@ -28,6 +28,8 @@
import com.l2jserver.model.world.npc.NPCController.NPCControllerException;
import com.l2jserver.service.game.character.CannotSetTargetServiceException;
import com.l2jserver.service.game.character.CharacterAction;
import com.l2jserver.service.game.character.CharacterInventoryItemDoesNotExistException;
import com.l2jserver.service.game.character.CharacterInventoryItemExistsException;
import com.l2jserver.service.game.item.ItemNotOnGroundServiceException;
import com.l2jserver.service.game.item.ItemService;
import com.l2jserver.service.game.npc.ActionServiceException;
Expand Down Expand Up @@ -129,7 +131,9 @@ public void process(final Lineage2Client conn) {
.getName());
conn.sendActionFailed();
} catch (ItemNotOnGroundServiceException
| NotSpawnedServiceException e) {
| NotSpawnedServiceException
| CharacterInventoryItemExistsException
| CharacterInventoryItemDoesNotExistException e) {
conn.sendSystemMessage(SystemMessage.FAILED_TO_PICKUP_S1, item
.getTemplate().getName());
conn.sendActionFailed();
Expand Down
Expand Up @@ -100,6 +100,5 @@ public void process(final Lineage2Client conn) {
} catch (ChatTargetOfflineServiceException e) {
conn.sendSystemMessage(SystemMessage.S1_IS_NOT_ONLINE, target);
}

}
}
Expand Up @@ -28,6 +28,7 @@
import com.l2jserver.service.game.character.ShortcutService;
import com.l2jserver.service.game.character.ShortcutSlotNotFreeServiceException;
import com.l2jserver.service.network.model.Lineage2Client;
import com.l2jserver.service.network.model.ProtocolVersion;
import com.l2jserver.service.network.model.packet.AbstractClientPacket;

/**
Expand Down Expand Up @@ -96,7 +97,11 @@ public void read(Lineage2Client conn, ChannelBuffer buffer) {
int slot = buffer.readInt();
objectId = buffer.readInt();
level = buffer.readInt();
// actorType = ShortcutActorType.fromID(buffer.readInt()); FIXME interlude needs this?

// FIXME interlude needs this?
if (conn.supports(ProtocolVersion.FREYA)) {
actorType = ShortcutActorType.fromID(buffer.readInt());
}

this.slot = slot % 12;
this.page = slot / 12;
Expand All @@ -117,7 +122,7 @@ public void process(final Lineage2Client conn) {
shortcutService.create(character, item, page, slot);
break;
}
//TODO action, macro, recipe
// TODO action, macro, recipe
} catch (ShortcutSlotNotFreeServiceException e) {
conn.sendActionFailed();
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -22,6 +22,7 @@
import com.l2jserver.model.id.object.ItemID;
import com.l2jserver.model.id.object.provider.ItemIDProvider;
import com.l2jserver.model.world.Item;
import com.l2jserver.service.game.character.CharacterInventoryItemDoesNotExistException;
import com.l2jserver.service.game.item.ItemService;
import com.l2jserver.service.game.item.NonStackableItemsServiceException;
import com.l2jserver.service.game.item.NotEnoughItemsServiceException;
Expand Down Expand Up @@ -98,7 +99,8 @@ public void process(final Lineage2Client conn) {
conn.updateInventoryItems(item);
}
} catch (NotEnoughItemsServiceException
| NonStackableItemsServiceException e) {
| NonStackableItemsServiceException
| CharacterInventoryItemDoesNotExistException e) {
conn.sendSystemMessage(SystemMessage.CANNOT_DISCARD_THIS_ITEM);
}
}
Expand Down
Expand Up @@ -22,6 +22,7 @@
import com.l2jserver.model.id.object.ItemID;
import com.l2jserver.model.id.object.provider.ItemIDProvider;
import com.l2jserver.model.world.Item;
import com.l2jserver.service.game.character.CharacterInventoryItemDoesNotExistException;
import com.l2jserver.service.game.item.ItemAlreadyOnGroundServiceException;
import com.l2jserver.service.game.item.ItemService;
import com.l2jserver.service.game.item.NonStackableItemsServiceException;
Expand Down Expand Up @@ -120,7 +121,8 @@ public void process(final Lineage2Client conn) {
| AlreadySpawnedServiceException
| SpawnPointNotFoundServiceException
| NotEnoughItemsServiceException
| NonStackableItemsServiceException e) {
| NonStackableItemsServiceException
| CharacterInventoryItemDoesNotExistException e) {
conn.sendActionFailed();
}
}
Expand Down
Expand Up @@ -24,7 +24,6 @@

import com.google.inject.Inject;
import com.l2jserver.L2JConstant;
import com.l2jserver.game.net.InterludeLineage2Client;
import com.l2jserver.game.net.packet.server.SM_KEY;
import com.l2jserver.service.network.keygen.BlowfishKeygenService;
import com.l2jserver.service.network.model.Lineage2Client;
Expand Down Expand Up @@ -86,9 +85,7 @@ public void process(final Lineage2Client conn) {
final Lineage2CryptographyKey inKey = new Lineage2CryptographyKey(
keygen.generate());

final InterludeLineage2Client client = (InterludeLineage2Client) conn;

client.getDecrypter().enable(inKey);
conn.enableDecrypter(inKey);
final Lineage2CryptographyKey outKey = inKey.copy();
log.debug("Decrypter has been enabled");

Expand Down Expand Up @@ -117,8 +114,7 @@ public void operationComplete(ChannelFuture future)
throws Exception {
log.debug("Encrypter has been enabled");
// enable encrypter
client.getEncrypter().setKey(outKey);
client.getEncrypter().setEnabled(true);
conn.enableEncrypter(outKey);
}
});
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -41,6 +41,7 @@
import com.l2jserver.model.world.actor.ActorExperience;
import com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll;
import com.l2jserver.service.network.model.Lineage2Client;
import com.l2jserver.service.network.model.ProtocolVersion;
import com.l2jserver.service.network.model.packet.AbstractServerPacket;
import com.l2jserver.util.BufferUtils;

Expand Down Expand Up @@ -81,7 +82,7 @@ public void write(Lineage2Client conn, ChannelBuffer buffer) {
buffer.writeInt(character.getPoint().getX());
buffer.writeInt(character.getPoint().getY());
buffer.writeInt(character.getPoint().getZ());
buffer.writeInt((int)character.getPoint().getAngle());
buffer.writeInt((int) character.getPoint().getAngle());
buffer.writeInt(character.getID().getID());
BufferUtils.writeString(buffer, character.getName());
buffer.writeInt(character.getRace().id);
Expand Down Expand Up @@ -125,7 +126,7 @@ public void write(Lineage2Client conn, ChannelBuffer buffer) {
writePaperdollObjectID(buffer, character, RIGHT_HAND);
writePaperdollObjectID(buffer, character, HAIR1);
writePaperdollObjectID(buffer, character, HAIR2);

writePaperdollItemID(buffer, character, UNDERWEAR);
writePaperdollItemID(buffer, character, RIGHT_EAR);
writePaperdollItemID(buffer, character, LEFT_EAR);
Expand All @@ -143,7 +144,7 @@ public void write(Lineage2Client conn, ChannelBuffer buffer) {
writePaperdollItemID(buffer, character, RIGHT_HAND);
writePaperdollItemID(buffer, character, HAIR1);
writePaperdollItemID(buffer, character, HAIR2);

buffer.writeShort(0x00);
buffer.writeShort(0x00);
buffer.writeShort(0x00);
Expand Down Expand Up @@ -195,8 +196,10 @@ public void write(Lineage2Client conn, ChannelBuffer buffer) {

buffer.writeInt(character.getStats().getRunSpeed());
buffer.writeInt(character.getStats().getWalkSpeed());
buffer.writeInt(character.getStats().getRunSpeed()); // runspeed in water TODO
buffer.writeInt(character.getStats().getWalkSpeed()); //walkspeed in water TODO
buffer.writeInt(character.getStats().getRunSpeed()); // runspeed in
// water TODO
buffer.writeInt(character.getStats().getWalkSpeed()); // walkspeed in
// water TODO
buffer.writeInt(0); // unk
buffer.writeInt(0); // unk
buffer.writeInt(0); // fly speed -only if flying
Expand Down Expand Up @@ -243,7 +246,7 @@ public void write(Lineage2Client conn, ChannelBuffer buffer) {
// 0x40 leader rights
// siege flags: attacker - 0x180 sword over name, defender - 0x80
// shield, 0xC0 crown (|leader), 0x1C0 flag (|leader)
buffer.writeInt(0x40); //relation??
buffer.writeInt(0x40); // relation??
buffer.writeByte(0x00); // mount type
buffer.writeByte(0x00); // private store type
buffer.writeByte(0x00); // dwarven craft
Expand Down Expand Up @@ -300,25 +303,27 @@ public void write(Lineage2Client conn, ChannelBuffer buffer) {
// cursed weapon ID equipped
buffer.writeInt(0x00);

// // T1 Starts
// buffer.writeInt(0x00); // transformation id
//
// buffer.writeShort(0x00); // attack element
// buffer.writeShort(0x10); // attack element value
// buffer.writeShort(0x10); // fire defense value
// buffer.writeShort(0x10); // water def value
// buffer.writeShort(0x10); // wind def value
// buffer.writeShort(0x10); // earth def value
// buffer.writeShort(0x10); // holy def value
// buffer.writeShort(0x10); // dark def value
//
// buffer.writeInt(0x00); // getAgathionId
//
// // T2 Starts
// buffer.writeInt(0x00); // Fame
// buffer.writeInt(0x01); // Minimap on Hellbound
// buffer.writeInt(1); // Vitality Points
// buffer.writeInt(0x00); // special effects
// // T1 Starts
if (conn.supports(ProtocolVersion.FREYA)) {
buffer.writeInt(0x00); // transformation id

buffer.writeShort(0x00); // attack element
buffer.writeShort(0x10); // attack element value
buffer.writeShort(0x10); // fire defense value
buffer.writeShort(0x10); // water def value
buffer.writeShort(0x10); // wind def value
buffer.writeShort(0x10); // earth def value
buffer.writeShort(0x10); // holy def value
buffer.writeShort(0x10); // dark def value

buffer.writeInt(0x00); // getAgathionId

// T2 Starts
buffer.writeInt(0x00); // Fame
buffer.writeInt(0x01); // Minimap on Hellbound
buffer.writeInt(1); // Vitality Points
buffer.writeInt(0x00); // special effects
}
}

/**
Expand Down

0 comments on commit 2d80fac

Please sign in to comment.