diff --git a/l2jserver2-common/src/main/java/com/l2jserver/service/core/threading/ThreadServiceImpl.java b/l2jserver2-common/src/main/java/com/l2jserver/service/core/threading/ThreadServiceImpl.java index 64f9bc0a0..f6744d20c 100644 --- a/l2jserver2-common/src/main/java/com/l2jserver/service/core/threading/ThreadServiceImpl.java +++ b/l2jserver2-common/src/main/java/com/l2jserver/service/core/threading/ThreadServiceImpl.java @@ -62,8 +62,8 @@ public class ThreadServiceImpl extends AbstractService implements ThreadService @Override protected void doStart() throws ServiceStartException { - pool = createThreadPool("shared", 20); threadPools = CollectionFactory.newMap(); + pool = createThreadPool("shared", 20); pool.async(50, TimeUnit.MILLISECONDS, 50, new Runnable() { @Override diff --git a/l2jserver2-common/src/main/java/com/l2jserver/service/database/AbstractDAO.java b/l2jserver2-common/src/main/java/com/l2jserver/service/database/AbstractDAO.java index ba6aa9751..8187f4332 100644 --- a/l2jserver2-common/src/main/java/com/l2jserver/service/database/AbstractDAO.java +++ b/l2jserver2-common/src/main/java/com/l2jserver/service/database/AbstractDAO.java @@ -59,6 +59,16 @@ public abstract class AbstractDAO, I extends ID> this.database = database; } + @Override + public AsyncFuture selectAsync(final I id) { + return threadService.async(new Callable() { + @Override + public T call() throws Exception { + return select(id); + } + }); + } + @Override public int save(T object) { return save(object, false); diff --git a/l2jserver2-common/src/main/java/com/l2jserver/service/database/DataAccessObject.java b/l2jserver2-common/src/main/java/com/l2jserver/service/database/DataAccessObject.java index 3cee4013c..e85bd1b8d 100644 --- a/l2jserver2-common/src/main/java/com/l2jserver/service/database/DataAccessObject.java +++ b/l2jserver2-common/src/main/java/com/l2jserver/service/database/DataAccessObject.java @@ -58,6 +58,18 @@ public interface DataAccessObject, I extends ID> extends */ O select(I id); + /** + * Asynchronously load the instance represented by id from the + * database + * + * @param id + * the id + * @return the {@link AsyncFuture} that will load the selected object. + * {@link AsyncFuture} might return null if the object + * could not be found in the database. + */ + AsyncFuture selectAsync(I id); + /** * Loads an List of all {@link ID}s in the database * diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/game/net/Lineage2Client.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/game/net/Lineage2Client.java index c3cfbff78..f6e7dad8a 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/game/net/Lineage2Client.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/game/net/Lineage2Client.java @@ -16,8 +16,6 @@ */ package com.l2jserver.game.net; -import java.util.Set; - import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelFuture; @@ -33,14 +31,12 @@ import com.l2jserver.game.net.packet.server.SM_CHAR_INVENTORY_UPDATE.InventoryUp import com.l2jserver.game.net.packet.server.SM_COMMUNITY_HTML; import com.l2jserver.game.net.packet.server.SM_HTML; import com.l2jserver.game.net.packet.server.SM_SYSTEM_MESSAGE; +import com.l2jserver.model.game.Fort; +import com.l2jserver.model.game.Skill; import com.l2jserver.model.id.object.CharacterID; import com.l2jserver.model.template.item.ItemTemplate; import com.l2jserver.model.world.Item; import com.l2jserver.model.world.L2Character; -import com.l2jserver.service.game.world.WorldService; -import com.l2jserver.service.game.world.filter.impl.CharacterBroadcastFilter; -import com.l2jserver.service.network.NetworkService; -import com.l2jserver.util.factory.CollectionFactory; import com.l2jserver.util.html.markup.HtmlTemplate; /** @@ -48,7 +44,7 @@ import com.l2jserver.util.html.markup.HtmlTemplate; * database) to the controller (protocol stuff). *

* This class also provides handy methods for {@link #write(ServerPacket) - * writing} and {@link #broadcast(ServerPacket) broadcasting} packets. + * writing} packets. * * @author Rogiel */ @@ -71,32 +67,13 @@ public class Lineage2Client { */ private ProtocolVersion version; - // services - /** - * The {@link NetworkService} instance. This service is used to retrieve the - * {@link Lineage2Client} based on an {@link CharacterID}. - */ - private final NetworkService networkService; - /** - * The {@link WorldService} instance. This service is used to dynamically - * generate knownlists. - */ - private final WorldService worldService; - /** * Creates a new instance * - * @param worldService - * the world service - * @param networkService - * the network service * @param channel * the channel */ - public Lineage2Client(WorldService worldService, - NetworkService networkService, Channel channel) { - this.worldService = worldService; - this.networkService = networkService; + public Lineage2Client(Channel channel) { this.channel = channel; } @@ -274,6 +251,10 @@ public class Lineage2Client { packet.addItem((Item) obj); else if (obj instanceof Number) packet.addNumber((Integer) obj); + else if (obj instanceof Skill) + packet.addSkill((Skill) obj); + else if (obj instanceof Fort) + packet.addFort((Fort) obj); } return write(packet); } @@ -331,7 +312,7 @@ public class Lineage2Client { * @return the {@link ChannelFuture} that will be notified once the packet * has been written. */ - public ChannelFuture sendInventoryUpdate() { + public ChannelFuture updateEntireInventoryItems() { return write(new SM_CHAR_INVENTORY(characterID.getObject() .getInventory())); } @@ -375,32 +356,6 @@ public class Lineage2Client { items)); } - /** - * Broadcast a packet to all characters in this character knownlist. - *

- * Note that in the broadcasting process, this client will be included. - *

- * Please note that this method will not block for all packets to be - * sent. It is possible to check if all packets were sent successfully using - * the {@link ChannelFuture} instances. - * - * @param packet - * the packet - * @return an {@link Set} containing all {@link ChannelFuture} instances. - */ - public Set broadcast(ServerPacket packet) { - final Set futures = CollectionFactory.newSet(); - for (final L2Character character : worldService - .iterable(new CharacterBroadcastFilter(characterID.getObject()))) { - final Lineage2Client conn = networkService.discover(character - .getID()); - if (conn == null) - continue; - futures.add(conn.write(packet)); - } - return futures; - } - /** * Disconnects this client, without closing the channel. * diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/game/net/Lineage2PipelineFactory.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/game/net/Lineage2PipelineFactory.java index 32968aa24..1b316cc2a 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/game/net/Lineage2PipelineFactory.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/game/net/Lineage2PipelineFactory.java @@ -34,7 +34,6 @@ import com.l2jserver.game.net.codec.Lineage2PacketReader; import com.l2jserver.game.net.codec.Lineage2PacketWriter; import com.l2jserver.game.net.handler.Lineage2PacketHandler; import com.l2jserver.game.net.handler.Lineage2TimeoutHandler; -import com.l2jserver.service.game.world.WorldService; import com.l2jserver.service.network.NettyNetworkService; import com.l2jserver.service.network.NetworkService; @@ -53,10 +52,6 @@ public class Lineage2PipelineFactory implements ChannelPipelineFactory { * The {@link NettyNetworkService} */ private final NettyNetworkService nettyNetworkService; - /** - * The {@link WorldService} instance - */ - private final WorldService worldService; /** * Creates a new instance of this pipeline @@ -65,15 +60,12 @@ public class Lineage2PipelineFactory implements ChannelPipelineFactory { * the {@link Guice} {@link Injector} * @param networkService * the network service - * @param worldService - * the world service */ @Inject public Lineage2PipelineFactory(Injector injector, - NetworkService networkService, WorldService worldService) { + NetworkService networkService) { this.injector = injector; this.nettyNetworkService = (NettyNetworkService) networkService; - this.worldService = worldService; } @Override @@ -101,8 +93,8 @@ public class Lineage2PipelineFactory implements ChannelPipelineFactory { final Lineage2TimeoutHandler timeoutHandler = new Lineage2TimeoutHandler(); pipeline.addLast("packet.handler", new Lineage2PacketHandler( - nettyNetworkService, worldService, timeoutHandler)); - //pipeline.addLast("timeout.handler", timeoutHandler); + nettyNetworkService, timeoutHandler)); + // pipeline.addLast("timeout.handler", timeoutHandler); return pipeline; } diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/game/net/handler/Lineage2PacketHandler.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/game/net/handler/Lineage2PacketHandler.java index 0b6989082..e731c1cd5 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/game/net/handler/Lineage2PacketHandler.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/game/net/handler/Lineage2PacketHandler.java @@ -28,7 +28,6 @@ import org.jboss.netty.channel.SimpleChannelHandler; import com.google.common.base.Throwables; import com.l2jserver.game.net.Lineage2Client; import com.l2jserver.game.net.packet.ClientPacket; -import com.l2jserver.service.game.world.WorldService; import com.l2jserver.service.network.NettyNetworkService; import com.l2jserver.util.html.markup.HtmlTemplate; import com.l2jserver.util.html.markup.MarkupTag; @@ -44,10 +43,6 @@ public class Lineage2PacketHandler extends SimpleChannelHandler { * The {@link NettyNetworkService} */ private final NettyNetworkService nettyNetworkService; - /** - * The {@link WorldService} instance - */ - private final WorldService worldService; /** * The timeout handler is responsible for disconnecting idle clients. */ @@ -62,23 +57,19 @@ public class Lineage2PacketHandler extends SimpleChannelHandler { * * @param nettyNetworkService * the netty network service - * @param worldService - * the world service * @param timeoutHandler * the timeout handler */ public Lineage2PacketHandler(NettyNetworkService nettyNetworkService, - WorldService worldService, Lineage2TimeoutHandler timeoutHandler) { + Lineage2TimeoutHandler timeoutHandler) { this.nettyNetworkService = nettyNetworkService; - this.worldService = worldService; this.timeoutHandler = timeoutHandler; } @Override public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { - connection = new Lineage2Client(worldService, nettyNetworkService, - e.getChannel()); + connection = new Lineage2Client(e.getChannel()); connection.getPacketWriter().setConnection(connection); timeoutHandler.setConnection(connection); diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/game/net/packet/server/SM_CHAR_INVENTORY.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/game/net/packet/server/SM_CHAR_INVENTORY.java index a9363efe0..e418b7035 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/game/net/packet/server/SM_CHAR_INVENTORY.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/game/net/packet/server/SM_CHAR_INVENTORY.java @@ -58,12 +58,6 @@ public class SM_CHAR_INVENTORY extends AbstractServerPacket { // TODO implement real item slot int slot = 0; for (Item item : inventory) { - if (item.getLocation() == ItemLocation.WAREHOUSE - || item.getLocation() == ItemLocation.GROUND - || item.getLocation() == null) { - continue; - } - buffer.writeInt(item.getID().getID()); // obj id buffer.writeInt(item.getTemplateID().getID()); // item id buffer.writeInt(slot); // loc slot diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/model/dao/ItemDAO.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/model/dao/ItemDAO.java index c366458c0..d6d4974bc 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/model/dao/ItemDAO.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/model/dao/ItemDAO.java @@ -40,5 +40,10 @@ public interface ItemDAO extends DataAccessObject, Cacheable { */ int loadInventory(L2Character character); - List loadDroppedItems(); + /** + * Select from the database the items dropped on the ground + * + * @return an {@link List} of all items on the ground + */ + List selectDroppedItems(); } diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/database/jdbc/JDBCItemDAO.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/database/jdbc/JDBCItemDAO.java index ee6f7e66b..982b2ca53 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/database/jdbc/JDBCItemDAO.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/database/jdbc/JDBCItemDAO.java @@ -205,7 +205,7 @@ public abstract class JDBCItemDAO extends AbstractJDBCDAO } @Override - public List loadDroppedItems() { + public List selectDroppedItems() { return database.query(new SelectListQuery() { @Override protected String query() { diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/item/ItemServiceImpl.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/item/ItemServiceImpl.java index 68adf967d..34725a16e 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/item/ItemServiceImpl.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/game/item/ItemServiceImpl.java @@ -95,7 +95,7 @@ public class ItemServiceImpl extends AbstractService implements ItemService { @Override protected void doStart() throws ServiceStartException { - items = itemDao.loadDroppedItems(); + items = itemDao.selectDroppedItems(); try { for (final Item item : items) { spawnService.spawn(item, null); diff --git a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/network/NettyNetworkService.java b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/network/NettyNetworkService.java index 9081029d6..1368917b6 100644 --- a/l2jserver2-gameserver/src/main/java/com/l2jserver/service/network/NettyNetworkService.java +++ b/l2jserver2-gameserver/src/main/java/com/l2jserver/service/network/NettyNetworkService.java @@ -59,11 +59,6 @@ public class NettyNetworkService extends AbstractService implements */ private final Logger log = LoggerFactory.getLogger(this.getClass()); - /** - * The {@link WorldService} instance - */ - private final WorldService worldService; - /** * The network configuration object */ @@ -91,15 +86,12 @@ public class NettyNetworkService extends AbstractService implements * the configuration service * @param injector * the {@link Guice} {@link Injector} - * @param worldService - * the world service */ @Inject public NettyNetworkService(ConfigurationService configService, - Injector injector, WorldService worldService) { + Injector injector) { this.config = configService.get(NetworkConfiguration.class); this.injector = injector; - this.worldService = worldService; InternalLoggerFactory.setDefaultFactory(new Slf4JLoggerFactory()); } @@ -108,8 +100,7 @@ public class NettyNetworkService extends AbstractService implements server = new ServerBootstrap(new NioServerSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool())); - server.setPipelineFactory(new Lineage2PipelineFactory(injector, this, - worldService)); + server.setPipelineFactory(new Lineage2PipelineFactory(injector, this)); channel = (ServerChannel) server.bind(config.getListenAddress()); }