1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-06 07:32:46 +00:00

Change-Id: If18611eb0a6296da808aead8f1da54be094db2a9

This commit is contained in:
rogiel
2011-04-29 20:17:45 -03:00
parent 43403d9a1e
commit 0662150229
48 changed files with 612 additions and 513 deletions

View File

@@ -1,11 +1,17 @@
package com.l2jserver;
import com.google.inject.AbstractModule;
import com.l2jserver.routines.GameServerInitializationRoutine;
import com.l2jserver.service.BasicServiceModule;
import com.l2jserver.service.ServiceModule;
public class GameServerModule extends AbstractModule {
@Override
protected void configure() {
// TODO Auto-generated method stub
install(new BasicServiceModule());
install(new ServiceModule());
// routines
bind(GameServerInitializationRoutine.class);
}
}

View File

@@ -6,5 +6,5 @@ public class L2JConstants {
* <p>
* This <b>MUST</b> be hard-coded!
*/
public static final int SUPPORTED_PROTOCOL = 10;
public static final int SUPPORTED_PROTOCOL = 216;
}

View File

@@ -1,13 +1,23 @@
package com.l2jserver;
public class L2JGameServerMain {
import com.l2jserver.routines.GameServerInitializationRoutine;
public class L2JGameServerMain {
/**
* @param args
* @throws InterruptedException
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
public static void main(String[] args) throws InterruptedException {
final L2JGameServer server = new L2JGameServer();
try {
server.getInjector()
.getInstance(GameServerInitializationRoutine.class).call();
} catch (Exception e) {
System.out.println("GameServer could not be started!");
e.printStackTrace();
}
Thread.sleep(60 * 60 * 1000);
}
}

View File

@@ -4,6 +4,8 @@ import static org.jboss.netty.channel.Channels.pipeline;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.handler.logging.LoggingHandler;
import org.jboss.netty.logging.InternalLogLevel;
import com.google.inject.Inject;
import com.google.inject.Injector;
@@ -28,20 +30,22 @@ public class Lineage2PipelineFactory implements ChannelPipelineFactory {
public ChannelPipeline getPipeline() throws Exception {
final ChannelPipeline pipeline = pipeline();
pipeline.addLast("header.encoder", new Lineage2Encoder());
pipeline.addLast("header.decoder", new Lineage2Decoder());
pipeline.addLast(Lineage2Encrypter.HANDLER_NAME,
new Lineage2Encrypter());
pipeline.addLast(Lineage2Decrypter.HANDLER_NAME,
new Lineage2Decrypter());
pipeline.addLast("header.encoder", new Lineage2Encoder());
pipeline.addLast("header.decoder", new Lineage2Decoder());
pipeline.addLast("packet.writer", new Lineage2PacketWriter());
pipeline.addLast("packet.reader", new Lineage2PacketReader(injector,
injector.getInstance(LoggingService.class)));
pipeline.addLast("packet.handler", new Lineage2PacketHandler());
pipeline.addLast("logger", new LoggingHandler(InternalLogLevel.WARN));
return pipeline;
}
}

View File

@@ -1,29 +1,39 @@
package com.l2jserver.game.net.codec;
import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder;
import java.nio.ByteOrder;
public class Lineage2Decoder extends LengthFieldBasedFrameDecoder {
// private static final int HEADER_SIZE = 2;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.handler.codec.frame.FrameDecoder;
public Lineage2Decoder() {
super(16 * 1024, 0, 2);
public class Lineage2Decoder extends FrameDecoder {
private static final int HEADER_SIZE = 2;
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel,
ChannelBuffer oldBuffer) throws Exception {
if (oldBuffer.readableBytes() < 2)
return null;
ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(oldBuffer
.toByteBuffer().order(ByteOrder.LITTLE_ENDIAN));
buffer.markReaderIndex();
final int pending = buffer.readUnsignedShort() - HEADER_SIZE;
System.out.println(ChannelBuffers.hexDump(buffer));
if (pending == 0) {
return null;
}
if (buffer.readableBytes() < pending) {
buffer.resetReaderIndex();
return null;
}
final ChannelBuffer b = buffer.copy(buffer.readerIndex(), pending);
oldBuffer.skipBytes(pending + HEADER_SIZE);
return ChannelBuffers.wrappedBuffer(b.toByteBuffer().order(
ByteOrder.LITTLE_ENDIAN));
}
// @Override
// protected Object decode(ChannelHandlerContext ctx, Channel channel,
// ChannelBuffer buffer) throws Exception {
// if (buffer.readableBytes() < 2)
// return null;
// buffer.markReaderIndex();
// final int pending = buffer.readUnsignedShort() - HEADER_SIZE;
// if(pending == 0)
// return null;
//
// if (buffer.readableBytes() < pending) {
// buffer.resetReaderIndex();
// return null;
// }
//
// return buffer.slice(buffer.readableBytes(), pending);
// }
}

View File

@@ -5,9 +5,11 @@ import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.handler.codec.oneone.OneToOneDecoder;
import com.l2jserver.util.BlowFishKeygen;
public class Lineage2Decrypter extends OneToOneDecoder {
public static final String HANDLER_NAME = "crypto.decoder";
private boolean enabled = false;
private final byte[] key = new byte[16];
@@ -19,12 +21,14 @@ public class Lineage2Decrypter extends OneToOneDecoder {
if (!enabled)
return msg;
final ChannelBuffer buffer = (ChannelBuffer) msg;
System.out.println("Decrypting...");
final int offset = buffer.readerIndex();
final int size = buffer.readableBytes();
int temp = 0;
for (int i = 0; i < size; i++) {
int temp2 = buffer.getUnsignedByte(offset + i);
int temp2 = buffer.getUnsignedByte(offset + i) & 0xFF;
buffer.setByte(offset + i, (byte) (temp2 ^ key[i & 15] ^ temp));
temp = temp2;
}
@@ -41,7 +45,14 @@ public class Lineage2Decrypter extends OneToOneDecoder {
key[10] = (byte) (old >> 0x10 & 0xff);
key[11] = (byte) (old >> 0x18 & 0xff);
return msg;
return buffer;
}
public byte[] enable() {
byte[] key = BlowFishKeygen.getRandomKey();
this.setKey(key);
this.setEnabled(true);
return key;
}
public void setKey(byte[] key) {

View File

@@ -1,9 +1,18 @@
package com.l2jserver.game.net.codec;
import org.jboss.netty.handler.codec.frame.LengthFieldPrepender;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
public class Lineage2Encoder extends LengthFieldPrepender {
public Lineage2Encoder() {
super(2);
public class Lineage2Encoder extends OneToOneEncoder {
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel,
Object msg) throws Exception {
if (!(msg instanceof ChannelBuffer))
return msg;
final ChannelBuffer buffer = (ChannelBuffer) msg;
buffer.setShort(0, buffer.readableBytes() - 2);
return buffer;
}
}

View File

@@ -1,10 +1,14 @@
package com.l2jserver.game.net.codec;
import java.util.Arrays;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
import com.l2jserver.util.BlowFishKeygen;
public class Lineage2Encrypter extends OneToOneEncoder {
public static final String HANDLER_NAME = "crypto.encoder";
@@ -16,7 +20,11 @@ public class Lineage2Encrypter extends OneToOneEncoder {
Object msg) throws Exception {
if (!(msg instanceof ChannelBuffer))
return msg;
if (!enabled)
return msg;
final ChannelBuffer buffer = (ChannelBuffer) msg;
System.out.println("Encrypting...");
final int offset = buffer.readerIndex();
final int size = buffer.readableBytes();
@@ -41,6 +49,11 @@ public class Lineage2Encrypter extends OneToOneEncoder {
return msg;
}
public void enable(byte[] key) {
this.setKey(key);
this.setEnabled(true);
}
public void setKey(byte[] key) {
for (int i = 0; i < 16; i++) {

View File

@@ -44,10 +44,8 @@ public class Lineage2PacketReader extends OneToOneDecoder {
switch (opcode) {
case ProtocolVersionPacket.OPCODE:
return ProtocolVersionPacket.class;
case 0x2b:
return null;
default:
logger.info("Unknown opcode: " + opcode);
logger.info("Unknown opcode: " + Integer.toHexString(opcode));
break;
}
return null;

View File

@@ -1,5 +1,7 @@
package com.l2jserver.game.net.codec;
import java.nio.ByteOrder;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
@@ -14,9 +16,12 @@ public class Lineage2PacketWriter extends OneToOneEncoder {
Object msg) throws Exception {
if (!(msg instanceof ServerPacket))
return msg;
final ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
final ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(
ByteOrder.LITTLE_ENDIAN, 10);
final ServerPacket packet = (ServerPacket) msg;
packet.write(buffer);
buffer.writeShort(0x0000);
buffer.writeByte(packet.getOpcode()); // packet opcode
packet.write(buffer);
return buffer;
}
}

View File

@@ -15,6 +15,9 @@ public class Lineage2PacketHandler extends SimpleChannelHandler {
public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e)
throws Exception {
connection = new Lineage2Connection(e.getChannel());
System.out.println(e);
super.channelOpen(ctx, e);
}
@@ -25,7 +28,7 @@ public class Lineage2PacketHandler extends SimpleChannelHandler {
if (!(msg instanceof ClientPacket))
return;
final ClientPacket packet = (ClientPacket) msg;
packet.process(connection, null);
packet.process(connection);
super.messageReceived(ctx, e);
}

View File

@@ -2,7 +2,6 @@ package com.l2jserver.game.net.packet;
import org.jboss.netty.buffer.ChannelBuffer;
import com.google.inject.Injector;
import com.l2jserver.game.net.Lineage2Connection;
public interface ClientPacket extends Packet {
@@ -17,8 +16,8 @@ public interface ClientPacket extends Packet {
/**
* Process the packet
*
* @param injector
* the injector
* @param conn
* The active Lineage2Connection
*/
void process(Lineage2Connection conn, Injector injector);
void process(Lineage2Connection conn);
}

View File

@@ -1,11 +1,13 @@
package com.l2jserver.game.net.packet.client;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.channel.ChannelFuture;
import org.jboss.netty.channel.ChannelFutureListener;
import com.google.inject.Injector;
import com.l2jserver.L2JConstants;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.AbstractClientPacket;
import com.l2jserver.game.net.packet.server.KeyPacket;
import com.l2jserver.service.logging.Logger;
import com.l2jserver.service.logging.guice.InjectLogger;
@@ -17,29 +19,48 @@ public class ProtocolVersionPacket extends AbstractClientPacket {
private final Logger logger = null;
// packet
private int version;
private long version;
@Override
public void read(ChannelBuffer buffer) {
this.version = buffer.readInt();
this.version = buffer.readUnsignedInt();
}
@Override
public void process(Lineage2Connection conn, Injector injector) {
public void process(final Lineage2Connection conn) {
// generate a new key
final byte[] key = conn.getDecrypter().enable();
if (L2JConstants.SUPPORTED_PROTOCOL != version) {
logger.info(
"Incorrect protocol version: {0}. Only {1} is supported.",
version, L2JConstants.SUPPORTED_PROTOCOL);
conn.close();
// notify wrong protocol and close connection
conn.write(new KeyPacket(key, false)).addListener(
new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future)
throws Exception {
// close connection
conn.close();
}
});
return;
}
// activate encrypter once packet has been sent.
conn.write(new KeyPacket(key, true)).addListener(
new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future)
throws Exception {
// enable encrypter
conn.getEncrypter().setKey(key);
conn.getEncrypter().setEnabled(true);
}
});
}
public int getVersion() {
public long getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
}

View File

@@ -1,18 +0,0 @@
package com.l2jserver.game.net.packet.server;
import org.jboss.netty.buffer.ChannelBuffer;
import com.l2jserver.game.net.packet.AbstractServerPacket;
public class TestPacket extends AbstractServerPacket {
public static final int OPCODE = 0x00;
@Override
public void write(ChannelBuffer buffer) {
}
public TestPacket() {
super(OPCODE);
}
}

View File

@@ -4,6 +4,7 @@ import com.l2jserver.model.id.ObjectID;
/**
* This is an abstract object representing all the world objects in Lineage II.
*
* @author Rogiel
*/
public abstract class AbstractObject implements WorldObject {
@@ -16,4 +17,29 @@ public abstract class AbstractObject implements WorldObject {
public void setId(ObjectID id) {
this.id = id;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
AbstractObject other = (AbstractObject) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
return true;
}
}

View File

@@ -54,4 +54,9 @@ public class Item extends AbstractObject implements Playable, Spawnable,
// TODO Auto-generated method stub
return null;
}
@Override
public void setPosition(Coordinate coord) {
}
}

View File

@@ -2,7 +2,7 @@ package com.l2jserver.model.world;
import com.l2jserver.model.id.CharacterID;
public class Character extends Player {
public class L2Character extends Player {
@Override
public CharacterID getId() {
return (CharacterID) super.getId();

View File

@@ -1,10 +1,30 @@
package com.l2jserver.model.world;
import com.l2jserver.model.world.capability.Child;
import com.l2jserver.model.world.capability.Summonable;
import com.l2jserver.util.Coordinate;
public class Pet extends Player implements Child<Character> {
public class Pet extends Player implements Child<L2Character>, Summonable {
@Override
public Character getParent() {
public L2Character getParent() {
return null;
}
@Override
public void teleport(Coordinate coordinate) {
// TODO Auto-generated method stub
}
@Override
public void summon(Coordinate coordinate) {
// TODO Auto-generated method stub
}
@Override
public boolean isSummoned() {
// TODO Auto-generated method stub
return false;
}
}

View File

@@ -1,94 +1,42 @@
package com.l2jserver.model.world;
import java.util.List;
import com.l2jserver.model.template.SkillTemplate;
import com.l2jserver.model.world.capability.Attackable;
import com.l2jserver.model.world.capability.Attacker;
import com.l2jserver.model.world.capability.Castable;
import com.l2jserver.model.world.capability.Caster;
import com.l2jserver.model.world.capability.Levelable;
import com.l2jserver.model.world.capability.Listenable;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.model.world.capability.Actor;
import com.l2jserver.model.world.capability.Parent;
import com.l2jserver.model.world.capability.Playable;
import com.l2jserver.model.world.capability.Spawnable;
import com.l2jserver.model.world.player.PlayerEvent;
import com.l2jserver.model.world.player.PlayerListener;
import com.l2jserver.model.world.capability.Teleportable;
import com.l2jserver.model.world.player.PlayerTeleportEvent;
import com.l2jserver.util.Coordinate;
import com.l2jserver.util.factory.CollectionFactory;
/**
* {@link Player} is any object that can be controlled by the player. The most
* common implementation is {@link Character}.
* common implementation is {@link L2Character}.
*
* @author Rogiel
*/
public abstract class Player extends AbstractObject implements Playable,
Spawnable, Attacker, Attackable,
Listenable<PlayerListener, PlayerEvent>, Caster, Parent, Levelable {
private final List<PlayerListener> listeners = CollectionFactory
.newList(PlayerListener.class);
public abstract class Player extends AbstractActor implements Playable, Actor,
Teleportable, Parent {
protected Lineage2Connection connection;
@Override
public void spawn(Coordinate coordinate) {
public void teleport(Coordinate coordinate) {
final PlayerTeleportEvent event = new PlayerTeleportEvent(this, coordinate);
this.setPosition(coordinate);
event.dispatch();
}
@Override
public void attack(Attackable target,
com.l2jserver.model.template.capability.Attackable weapon) {
/**
* @return the connection
*/
public Lineage2Connection getConnection() {
return connection;
}
@Override
public void receiveAttack(Attacker attacker,
com.l2jserver.model.template.capability.Attackable weapon) {
}
@Override
public void addListener(PlayerListener listener) {
listeners.add(listener);
}
@Override
public void removeListener(PlayerListener listener) {
listeners.remove(listener);
}
@Override
public void dispatch(PlayerEvent e) {
for (final PlayerListener listener : listeners) {
listener.dispatch(e);
}
}
@Override
public Coordinate getPosition() {
// TODO Auto-generated method stub
return null;
}
@Override
public void cast(SkillTemplate skill, Castable cast) {
// TODO Auto-generated method stub
}
@Override
public boolean isSpawned() {
// TODO Auto-generated method stub
return false;
}
@Override
public int getLevel() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void setLevel(int level) {
// TODO Auto-generated method stub
/**
* @param connection
* the connection to set
*/
public void setConnection(Lineage2Connection connection) {
this.connection = connection;
}
}

View File

@@ -1,52 +0,0 @@
package com.l2jserver.model.world;
import java.util.Iterator;
import java.util.Set;
import com.l2jserver.model.world.event.WorldEventDispatcher;
import com.l2jserver.model.world.filter.WorldObjectFilter;
import com.l2jserver.model.world.iterator.FilterIterator;
import com.l2jserver.util.factory.CollectionFactory;
public class World implements Iterable<WorldObject> {
private final Set<WorldObject> objects = CollectionFactory
.newSet(WorldObject.class);
private final WorldEventDispatcher dispatcher = new WorldEventDispatcher(
this);
public void add(WorldObject object) {
objects.add(object);
}
public void remove(WorldObject object) {
objects.remove(object);
}
public boolean contains(WorldObject object) {
return objects.contains(object);
}
public WorldEventDispatcher getDispatcher() {
return dispatcher;
}
@Override
public Iterator<WorldObject> iterator() {
return objects.iterator();
}
public <T extends WorldObject> Iterator<T> iterator(
final WorldObjectFilter<T> filter) {
return new FilterIterator<T>(filter, objects.iterator());
}
public <T extends WorldObject> Iterable<T> iterable(
final WorldObjectFilter<T> filter) {
return new Iterable<T>() {
@Override
public Iterator<T> iterator() {
return new FilterIterator<T>(filter, objects.iterator());
}
};
}
}

View File

@@ -8,5 +8,5 @@ import com.l2jserver.model.world.AbstractObject;
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface Conversable extends ObjectCapability {
void talk(Talker talker);
}

View File

@@ -1,12 +1,19 @@
package com.l2jserver.model.world.capability;
import com.l2jserver.model.world.AbstractObject;
import com.l2jserver.util.Coordinate;
/**
* Defines an {@link AbstractObject} that can be dropped on the ground.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface Dropable extends ObjectCapability {
void drop();
public interface Dropable extends Positionable {
/**
* When an item is dropped its position will be set as <tt>position</tt>
*
* @param position
* the position
*/
void drop(Coordinate position);
}

View File

@@ -10,4 +10,5 @@ import com.l2jserver.util.Coordinate;
*/
public interface Positionable extends ObjectCapability {
Coordinate getPosition();
void setPosition(Coordinate coord);
}

View File

@@ -1,7 +1,9 @@
package com.l2jserver.model.world.event;
import com.l2jserver.model.world.capability.Spawnable;
import com.l2jserver.util.Coordinate;
public interface SpawnEvent extends WorldEvent {
Spawnable getObject();
Coordinate getCoordinate();
}

View File

@@ -1,16 +0,0 @@
package com.l2jserver.model.world.event;
import com.l2jserver.model.world.World;
public class WorldEventDispatcher {
private final World world;
public WorldEventDispatcher(World world) {
this.world = world;
}
public void dispatch(WorldEvent event) {
//TODO implement threaded model
event.dispatch();
}
}

View File

@@ -3,6 +3,7 @@ package com.l2jserver.model.world.item;
import com.l2jserver.model.world.Item;
import com.l2jserver.model.world.Player;
import com.l2jserver.model.world.WorldObject;
import com.l2jserver.model.world.capability.Actor;
import com.l2jserver.model.world.player.PlayerEvent;
public class ItemDropEvent implements ItemEvent, PlayerEvent {
@@ -35,4 +36,9 @@ public class ItemDropEvent implements ItemEvent, PlayerEvent {
if (player != null)
player.dispatch(this);
}
@Override
public Actor getActor() {
return player;
}
}

View File

@@ -1,8 +1,8 @@
package com.l2jserver.model.world.player;
import com.l2jserver.model.world.Player;
import com.l2jserver.model.world.event.WorldEvent;
import com.l2jserver.model.world.actor.ActorEvent;
public interface PlayerEvent extends WorldEvent {
public interface PlayerEvent extends ActorEvent {
Player getPlayer();
}

View File

@@ -1,6 +1,22 @@
package com.l2jserver.model.world.player;
import com.l2jserver.model.world.event.WorldListener;
import com.l2jserver.model.world.actor.ActorEvent;
import com.l2jserver.model.world.actor.ActorListener;
public interface PlayerListener extends WorldListener<PlayerEvent> {
public abstract class PlayerListener implements ActorListener {
@Override
public void dispatch(ActorEvent e) {
if (!(e instanceof PlayerEvent))
return;
dispatch((PlayerEvent) e);
}
/**
* Once the event call is dispatched, the listener <b>WILL NOT</b> be
* removed. You must manually remove it from the <tt>event</tt> object.
*
* @param e
* the event
*/
protected abstract void dispatch(PlayerEvent e);
}

View File

@@ -1,14 +1,24 @@
package com.l2jserver.model.world.player;
import com.l2jserver.model.world.Player;
import com.l2jserver.model.world.capability.Actor;
import com.l2jserver.model.world.capability.Spawnable;
import com.l2jserver.model.world.event.SpawnEvent;
import com.l2jserver.util.Coordinate;
public class PlayerSpawnEvent implements PlayerEvent, SpawnEvent {
private final Player player;
private final Coordinate coordinate;
public PlayerSpawnEvent(Player player) {
public PlayerSpawnEvent(Player player, Coordinate coordinate) {
this.player = player;
this.coordinate = coordinate;
}
@Override
public void dispatch() {
if (player != null)
player.dispatch(this);
}
@Override
@@ -22,8 +32,12 @@ public class PlayerSpawnEvent implements PlayerEvent, SpawnEvent {
}
@Override
public void dispatch() {
if(player != null)
player.dispatch(this);
public Coordinate getCoordinate() {
return coordinate;
}
@Override
public Actor getActor() {
return player;
}
}

View File

@@ -1,8 +1,27 @@
package com.l2jserver.routines;
import com.google.inject.Inject;
import com.l2jserver.service.ServiceManager;
import com.l2jserver.service.configuration.ConfigurationService;
import com.l2jserver.service.database.DatabaseService;
import com.l2jserver.service.logging.LoggingService;
import com.l2jserver.service.network.NetworkService;
public class GameServerInitializationRoutine implements Routine<Boolean> {
private final ServiceManager serviceManager;
@Inject
public GameServerInitializationRoutine(ServiceManager serviceManager) {
this.serviceManager = serviceManager;
}
@Override
public Boolean call() {
return false;
public Boolean call() throws Exception {
serviceManager.start(LoggingService.class);
serviceManager.start(ConfigurationService.class);
serviceManager.start(DatabaseService.class);
serviceManager.start(NetworkService.class);
return true;
}
}

View File

@@ -1,19 +0,0 @@
package com.l2jserver.service;
public interface Service {
/**
* Start this service
*
* @throws ServiceStartException
* if an error occurred
*/
void start() throws ServiceStartException;
/**
* Stop this service
*
* @throws ServiceStartException
* if an error occurred
*/
void stop() throws ServiceStopException;
}

View File

@@ -1,21 +0,0 @@
package com.l2jserver.service;
public class ServiceException extends Exception {
private static final long serialVersionUID = 1L;
public ServiceException() {
super();
}
public ServiceException(String message, Throwable cause) {
super(message, cause);
}
public ServiceException(String message) {
super(message);
}
public ServiceException(Throwable cause) {
super(cause);
}
}

View File

@@ -1,10 +0,0 @@
package com.l2jserver.service;
import com.google.inject.AbstractModule;
public class ServiceModule extends AbstractModule {
@Override
protected void configure() {
install(new BasicServiceModule());
}
}

View File

@@ -1,21 +0,0 @@
package com.l2jserver.service;
public class ServiceStartException extends ServiceException {
private static final long serialVersionUID = 1L;
public ServiceStartException() {
super();
}
public ServiceStartException(String message, Throwable cause) {
super(message, cause);
}
public ServiceStartException(String message) {
super(message);
}
public ServiceStartException(Throwable cause) {
super(cause);
}
}

View File

@@ -1,21 +0,0 @@
package com.l2jserver.service;
public class ServiceStopException extends ServiceException {
private static final long serialVersionUID = 1L;
public ServiceStopException() {
super();
}
public ServiceStopException(String message, Throwable cause) {
super(message, cause);
}
public ServiceStopException(String message) {
super(message);
}
public ServiceStopException(Throwable cause) {
super(cause);
}
}

View File

@@ -0,0 +1,15 @@
package com.l2jserver.service.game.world;
import com.l2jserver.model.world.event.WorldEvent;
/**
* {@link WorldEventDispatcher} implementation
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class WorldEventDispatcherImpl implements WorldEventDispatcher {
public void dispatch(WorldEvent event) {
// TODO implement threaded model
event.dispatch();
}
}

View File

@@ -1,22 +1,95 @@
package com.l2jserver.service.game.world;
import java.util.Iterator;
import java.util.List;
import com.l2jserver.model.world.WorldObject;
import com.l2jserver.model.world.filter.WorldObjectFilter;
import com.l2jserver.service.Service;
/**
* Service responsible for managing {@link WorldObject} and dispatch events.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface WorldService extends Service, Iterable<WorldObject> {
/**
* Register a new {@link WorldObject} to the service.
* Adds an object into the world.
*
* @param object
* the object
*/
void register(WorldObject object);
public void add(WorldObject object);
/**
* Removes an registered {@link WorldObject} from the service.
* Removes an object of the world
*
* @param object
* the object
*/
void unregister(WorldObject object);
public void remove(WorldObject object);
/**
* Check if this object is in the world.
*
* @param object
* the object
* @return true if object exists
*/
public boolean contains(WorldObject object);
/**
* Get the event dispatcher
*
* @return the event dispatcher
*/
public WorldEventDispatcher getEventDispatcher();
/**
* Creates a list of all objects matching <tt>filter</tt>
*
* @param <T>
* the object type
* @param filter
* the filter
* @return the list of objects
*/
public <T extends WorldObject> List<T> list(WorldObjectFilter<T> filter);
/**
* Creates a list of all objects of type <tt>type</tt>
*
* @param <T>
* the type
* @param type
* the type class
* @return the list of objects
*/
<T extends WorldObject> List<T> list(Class<T> type);
/**
* Get the iterator for this <tt>filter</tt>
*
* @param <T>
* the object type
* @param filter
* the filter
* @return the iterator instance
*/
<T extends WorldObject> Iterator<T> iterator(
final WorldObjectFilter<T> filter);
/**
* Shortcut method for {@link Iterable#iterable()} with filters. The
* iterable instance returns the same {@link Iterator} as
* {@link #iterator(WorldObjectFilter)}.
*
* @param <T>
* the object type
* @param filter
* the filter
* @return the iterable instance
*/
<T extends WorldObject> Iterable<T> iterable(
final WorldObjectFilter<T> filter);
}

View File

@@ -1,45 +1,91 @@
package com.l2jserver.service.game.world;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import com.google.inject.Inject;
import com.l2jserver.model.world.WorldObject;
import com.l2jserver.model.world.filter.WorldObjectFilter;
import com.l2jserver.model.world.filter.impl.InstanceFilter;
import com.l2jserver.model.world.iterator.FilterIterator;
import com.l2jserver.service.ServiceStartException;
import com.l2jserver.service.ServiceStopException;
import com.l2jserver.util.factory.CollectionFactory;
public class WorldServiceImpl implements WorldService {
private final Set<WorldObject> objects = CollectionFactory
.newSet(WorldObject.class);
private final WorldEventDispatcher dispatcher;
@Inject
public WorldServiceImpl(WorldEventDispatcher dispatcher) {
this.dispatcher = dispatcher;
}
@Override
public void start() throws ServiceStartException {
// TODO Auto-generated method stub
objects.clear();
}
@Override
public void register(WorldObject object) {
// TODO Auto-generated method stub
public void add(WorldObject object) {
objects.add(object);
}
@Override
public void unregister(WorldObject object) {
// TODO Auto-generated method stub
public void remove(WorldObject object) {
objects.remove(object);
}
@Override
public boolean contains(WorldObject object) {
return objects.contains(object);
}
@Override
public WorldEventDispatcher getEventDispatcher() {
return dispatcher;
}
@Override
public <T extends WorldObject> List<T> list(WorldObjectFilter<T> filter) {
final List<T> list = CollectionFactory.newList(null);
for (final T object : this.iterable(filter)) {
list.add(object);
}
return list;
}
@Override
public <T extends WorldObject> List<T> list(Class<T> type) {
return list(new InstanceFilter<T>(type));
}
@Override
public Iterator<WorldObject> iterator() {
// return objects.iterator();
return null;
return objects.iterator();
}
public <T extends WorldObject> Iterator<T> iterator(WorldObjectFilter<T> filter) {
// return objects.iterator();
return null;
@Override
public <T extends WorldObject> Iterator<T> iterator(
final WorldObjectFilter<T> filter) {
return new FilterIterator<T>(filter, objects.iterator());
}
@Override
public <T extends WorldObject> Iterable<T> iterable(
final WorldObjectFilter<T> filter) {
return new Iterable<T>() {
@Override
public Iterator<T> iterator() {
return new FilterIterator<T>(filter, objects.iterator());
}
};
}
@Override
public void stop() throws ServiceStopException {
// TODO Auto-generated method stub
objects.clear();
}
}

View File

@@ -7,16 +7,22 @@ import org.jboss.netty.channel.ServerChannel;
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.Lineage2PipelineFactory;
import com.l2jserver.service.configuration.ConfigurationService;
public class NettyNetworkService implements NetworkService {
private final NetworkConfiguration config;
private final Injector injector;
private ServerBootstrap server;
private ServerChannel channel;
@Inject
public NettyNetworkService(ConfigurationService configService) {
public NettyNetworkService(ConfigurationService configService,
Injector injector) {
this.config = configService.get(NetworkConfiguration.class);
this.injector = injector;
}
@Override
@@ -24,6 +30,7 @@ public class NettyNetworkService implements NetworkService {
server = new ServerBootstrap(new NioServerSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool()));
server.setPipelineFactory(new Lineage2PipelineFactory(injector));
channel = (ServerChannel) server.bind(config.getListenAddress());
}

View File

@@ -13,7 +13,7 @@ public interface NetworkConfiguration extends Configuration {
*
* @return the listen address
*/
@ConfigurationPropertyGetter(name = "listen", defaultValue = "0.0.0.0:54")
@ConfigurationPropertyGetter(name = "listen", defaultValue = "0.0.0.0:7777")
InetSocketAddress getListenAddress();
/**

View File

@@ -1,7 +1,7 @@
package com.l2jserver.service.network;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.service.Service;
public interface NetworkService extends Service {
}

View File

@@ -4,7 +4,9 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;
/**
* Factory class to create {@link Collection} instances.
@@ -37,4 +39,21 @@ public class CollectionFactory {
public static final <T> Set<T> newSet(Class<T> type) {
return new HashSet<T>();
}
/**
* Creates a new weak map.
*
* @param <K>
* the key type
* @param <V>
* the value type
* @param key
* the key type class
* @param value
* the value type class
* @return the new map
*/
public static final <K, V> Map<K, V> newWeakMap(Class<K> key, Class<V> value) {
return new WeakHashMap<K, V>();
}
}