mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-06 07:32:46 +00:00
Fixes a bug in ThreadService start method
This commit is contained in:
@@ -62,8 +62,8 @@ public class ThreadServiceImpl extends AbstractService implements ThreadService
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doStart() throws ServiceStartException {
|
protected void doStart() throws ServiceStartException {
|
||||||
pool = createThreadPool("shared", 20);
|
|
||||||
threadPools = CollectionFactory.newMap();
|
threadPools = CollectionFactory.newMap();
|
||||||
|
pool = createThreadPool("shared", 20);
|
||||||
|
|
||||||
pool.async(50, TimeUnit.MILLISECONDS, 50, new Runnable() {
|
pool.async(50, TimeUnit.MILLISECONDS, 50, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -59,6 +59,16 @@ public abstract class AbstractDAO<T extends Model<?>, I extends ID<?>>
|
|||||||
this.database = database;
|
this.database = database;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AsyncFuture<T> selectAsync(final I id) {
|
||||||
|
return threadService.async(new Callable<T>() {
|
||||||
|
@Override
|
||||||
|
public T call() throws Exception {
|
||||||
|
return select(id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int save(T object) {
|
public int save(T object) {
|
||||||
return save(object, false);
|
return save(object, false);
|
||||||
|
|||||||
@@ -58,6 +58,18 @@ public interface DataAccessObject<O extends Model<?>, I extends ID<?>> extends
|
|||||||
*/
|
*/
|
||||||
O select(I id);
|
O select(I id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asynchronously load the instance represented by <tt>id</tt> from the
|
||||||
|
* database
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* the id
|
||||||
|
* @return the {@link AsyncFuture} that will load the selected object.
|
||||||
|
* {@link AsyncFuture} might return <tt>null</tt> if the object
|
||||||
|
* could not be found in the database.
|
||||||
|
*/
|
||||||
|
AsyncFuture<O> selectAsync(I id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads an List of all {@link ID}s in the database
|
* Loads an List of all {@link ID}s in the database
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -16,8 +16,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.l2jserver.game.net;
|
package com.l2jserver.game.net;
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.jboss.netty.channel.Channel;
|
import org.jboss.netty.channel.Channel;
|
||||||
import org.jboss.netty.channel.ChannelFuture;
|
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_COMMUNITY_HTML;
|
||||||
import com.l2jserver.game.net.packet.server.SM_HTML;
|
import com.l2jserver.game.net.packet.server.SM_HTML;
|
||||||
import com.l2jserver.game.net.packet.server.SM_SYSTEM_MESSAGE;
|
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.id.object.CharacterID;
|
||||||
import com.l2jserver.model.template.item.ItemTemplate;
|
import com.l2jserver.model.template.item.ItemTemplate;
|
||||||
import com.l2jserver.model.world.Item;
|
import com.l2jserver.model.world.Item;
|
||||||
import com.l2jserver.model.world.L2Character;
|
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;
|
import com.l2jserver.util.html.markup.HtmlTemplate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -48,7 +44,7 @@ import com.l2jserver.util.html.markup.HtmlTemplate;
|
|||||||
* database) to the controller (protocol stuff).
|
* database) to the controller (protocol stuff).
|
||||||
* <p>
|
* <p>
|
||||||
* This class also provides handy methods for {@link #write(ServerPacket)
|
* This class also provides handy methods for {@link #write(ServerPacket)
|
||||||
* writing} and {@link #broadcast(ServerPacket) broadcasting} packets.
|
* writing} packets.
|
||||||
*
|
*
|
||||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
*/
|
*/
|
||||||
@@ -71,32 +67,13 @@ public class Lineage2Client {
|
|||||||
*/
|
*/
|
||||||
private ProtocolVersion version;
|
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
|
* Creates a new instance
|
||||||
*
|
*
|
||||||
* @param worldService
|
|
||||||
* the world service
|
|
||||||
* @param networkService
|
|
||||||
* the network service
|
|
||||||
* @param channel
|
* @param channel
|
||||||
* the channel
|
* the channel
|
||||||
*/
|
*/
|
||||||
public Lineage2Client(WorldService worldService,
|
public Lineage2Client(Channel channel) {
|
||||||
NetworkService networkService, Channel channel) {
|
|
||||||
this.worldService = worldService;
|
|
||||||
this.networkService = networkService;
|
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -274,6 +251,10 @@ public class Lineage2Client {
|
|||||||
packet.addItem((Item) obj);
|
packet.addItem((Item) obj);
|
||||||
else if (obj instanceof Number)
|
else if (obj instanceof Number)
|
||||||
packet.addNumber((Integer) obj);
|
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);
|
return write(packet);
|
||||||
}
|
}
|
||||||
@@ -331,7 +312,7 @@ public class Lineage2Client {
|
|||||||
* @return the {@link ChannelFuture} that will be notified once the packet
|
* @return the {@link ChannelFuture} that will be notified once the packet
|
||||||
* has been written.
|
* has been written.
|
||||||
*/
|
*/
|
||||||
public ChannelFuture sendInventoryUpdate() {
|
public ChannelFuture updateEntireInventoryItems() {
|
||||||
return write(new SM_CHAR_INVENTORY(characterID.getObject()
|
return write(new SM_CHAR_INVENTORY(characterID.getObject()
|
||||||
.getInventory()));
|
.getInventory()));
|
||||||
}
|
}
|
||||||
@@ -375,32 +356,6 @@ public class Lineage2Client {
|
|||||||
items));
|
items));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Broadcast a packet to all characters in this character knownlist.
|
|
||||||
* <p>
|
|
||||||
* Note that in the broadcasting process, this client will be included.
|
|
||||||
* <p>
|
|
||||||
* Please note that this method will <b>not</b> 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<ChannelFuture> broadcast(ServerPacket packet) {
|
|
||||||
final Set<ChannelFuture> 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.
|
* Disconnects this client, without closing the channel.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ import com.l2jserver.game.net.codec.Lineage2PacketReader;
|
|||||||
import com.l2jserver.game.net.codec.Lineage2PacketWriter;
|
import com.l2jserver.game.net.codec.Lineage2PacketWriter;
|
||||||
import com.l2jserver.game.net.handler.Lineage2PacketHandler;
|
import com.l2jserver.game.net.handler.Lineage2PacketHandler;
|
||||||
import com.l2jserver.game.net.handler.Lineage2TimeoutHandler;
|
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.NettyNetworkService;
|
||||||
import com.l2jserver.service.network.NetworkService;
|
import com.l2jserver.service.network.NetworkService;
|
||||||
|
|
||||||
@@ -53,10 +52,6 @@ public class Lineage2PipelineFactory implements ChannelPipelineFactory {
|
|||||||
* The {@link NettyNetworkService}
|
* The {@link NettyNetworkService}
|
||||||
*/
|
*/
|
||||||
private final NettyNetworkService nettyNetworkService;
|
private final NettyNetworkService nettyNetworkService;
|
||||||
/**
|
|
||||||
* The {@link WorldService} instance
|
|
||||||
*/
|
|
||||||
private final WorldService worldService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance of this pipeline
|
* Creates a new instance of this pipeline
|
||||||
@@ -65,15 +60,12 @@ public class Lineage2PipelineFactory implements ChannelPipelineFactory {
|
|||||||
* the {@link Guice} {@link Injector}
|
* the {@link Guice} {@link Injector}
|
||||||
* @param networkService
|
* @param networkService
|
||||||
* the network service
|
* the network service
|
||||||
* @param worldService
|
|
||||||
* the world service
|
|
||||||
*/
|
*/
|
||||||
@Inject
|
@Inject
|
||||||
public Lineage2PipelineFactory(Injector injector,
|
public Lineage2PipelineFactory(Injector injector,
|
||||||
NetworkService networkService, WorldService worldService) {
|
NetworkService networkService) {
|
||||||
this.injector = injector;
|
this.injector = injector;
|
||||||
this.nettyNetworkService = (NettyNetworkService) networkService;
|
this.nettyNetworkService = (NettyNetworkService) networkService;
|
||||||
this.worldService = worldService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -101,7 +93,7 @@ public class Lineage2PipelineFactory implements ChannelPipelineFactory {
|
|||||||
|
|
||||||
final Lineage2TimeoutHandler timeoutHandler = new Lineage2TimeoutHandler();
|
final Lineage2TimeoutHandler timeoutHandler = new Lineage2TimeoutHandler();
|
||||||
pipeline.addLast("packet.handler", new Lineage2PacketHandler(
|
pipeline.addLast("packet.handler", new Lineage2PacketHandler(
|
||||||
nettyNetworkService, worldService, timeoutHandler));
|
nettyNetworkService, timeoutHandler));
|
||||||
// pipeline.addLast("timeout.handler", timeoutHandler);
|
// pipeline.addLast("timeout.handler", timeoutHandler);
|
||||||
|
|
||||||
return pipeline;
|
return pipeline;
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import org.jboss.netty.channel.SimpleChannelHandler;
|
|||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
import com.l2jserver.game.net.Lineage2Client;
|
import com.l2jserver.game.net.Lineage2Client;
|
||||||
import com.l2jserver.game.net.packet.ClientPacket;
|
import com.l2jserver.game.net.packet.ClientPacket;
|
||||||
import com.l2jserver.service.game.world.WorldService;
|
|
||||||
import com.l2jserver.service.network.NettyNetworkService;
|
import com.l2jserver.service.network.NettyNetworkService;
|
||||||
import com.l2jserver.util.html.markup.HtmlTemplate;
|
import com.l2jserver.util.html.markup.HtmlTemplate;
|
||||||
import com.l2jserver.util.html.markup.MarkupTag;
|
import com.l2jserver.util.html.markup.MarkupTag;
|
||||||
@@ -44,10 +43,6 @@ public class Lineage2PacketHandler extends SimpleChannelHandler {
|
|||||||
* The {@link NettyNetworkService}
|
* The {@link NettyNetworkService}
|
||||||
*/
|
*/
|
||||||
private final NettyNetworkService nettyNetworkService;
|
private final NettyNetworkService nettyNetworkService;
|
||||||
/**
|
|
||||||
* The {@link WorldService} instance
|
|
||||||
*/
|
|
||||||
private final WorldService worldService;
|
|
||||||
/**
|
/**
|
||||||
* The timeout handler is responsible for disconnecting idle clients.
|
* The timeout handler is responsible for disconnecting idle clients.
|
||||||
*/
|
*/
|
||||||
@@ -62,23 +57,19 @@ public class Lineage2PacketHandler extends SimpleChannelHandler {
|
|||||||
*
|
*
|
||||||
* @param nettyNetworkService
|
* @param nettyNetworkService
|
||||||
* the netty network service
|
* the netty network service
|
||||||
* @param worldService
|
|
||||||
* the world service
|
|
||||||
* @param timeoutHandler
|
* @param timeoutHandler
|
||||||
* the timeout handler
|
* the timeout handler
|
||||||
*/
|
*/
|
||||||
public Lineage2PacketHandler(NettyNetworkService nettyNetworkService,
|
public Lineage2PacketHandler(NettyNetworkService nettyNetworkService,
|
||||||
WorldService worldService, Lineage2TimeoutHandler timeoutHandler) {
|
Lineage2TimeoutHandler timeoutHandler) {
|
||||||
this.nettyNetworkService = nettyNetworkService;
|
this.nettyNetworkService = nettyNetworkService;
|
||||||
this.worldService = worldService;
|
|
||||||
this.timeoutHandler = timeoutHandler;
|
this.timeoutHandler = timeoutHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e)
|
public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
connection = new Lineage2Client(worldService, nettyNetworkService,
|
connection = new Lineage2Client(e.getChannel());
|
||||||
e.getChannel());
|
|
||||||
connection.getPacketWriter().setConnection(connection);
|
connection.getPacketWriter().setConnection(connection);
|
||||||
timeoutHandler.setConnection(connection);
|
timeoutHandler.setConnection(connection);
|
||||||
|
|
||||||
|
|||||||
@@ -58,12 +58,6 @@ public class SM_CHAR_INVENTORY extends AbstractServerPacket {
|
|||||||
// TODO implement real item slot
|
// TODO implement real item slot
|
||||||
int slot = 0;
|
int slot = 0;
|
||||||
for (Item item : inventory) {
|
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.getID().getID()); // obj id
|
||||||
buffer.writeInt(item.getTemplateID().getID()); // item id
|
buffer.writeInt(item.getTemplateID().getID()); // item id
|
||||||
buffer.writeInt(slot); // loc slot
|
buffer.writeInt(slot); // loc slot
|
||||||
|
|||||||
@@ -40,5 +40,10 @@ public interface ItemDAO extends DataAccessObject<Item, ItemID>, Cacheable {
|
|||||||
*/
|
*/
|
||||||
int loadInventory(L2Character character);
|
int loadInventory(L2Character character);
|
||||||
|
|
||||||
List<Item> loadDroppedItems();
|
/**
|
||||||
|
* Select from the database the items dropped on the ground
|
||||||
|
*
|
||||||
|
* @return an {@link List} of all items on the ground
|
||||||
|
*/
|
||||||
|
List<Item> selectDroppedItems();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -205,7 +205,7 @@ public abstract class JDBCItemDAO extends AbstractJDBCDAO<Item, ItemID>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Item> loadDroppedItems() {
|
public List<Item> selectDroppedItems() {
|
||||||
return database.query(new SelectListQuery<Item>() {
|
return database.query(new SelectListQuery<Item>() {
|
||||||
@Override
|
@Override
|
||||||
protected String query() {
|
protected String query() {
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ public class ItemServiceImpl extends AbstractService implements ItemService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doStart() throws ServiceStartException {
|
protected void doStart() throws ServiceStartException {
|
||||||
items = itemDao.loadDroppedItems();
|
items = itemDao.selectDroppedItems();
|
||||||
try {
|
try {
|
||||||
for (final Item item : items) {
|
for (final Item item : items) {
|
||||||
spawnService.spawn(item, null);
|
spawnService.spawn(item, null);
|
||||||
|
|||||||
@@ -59,11 +59,6 @@ public class NettyNetworkService extends AbstractService implements
|
|||||||
*/
|
*/
|
||||||
private final Logger log = LoggerFactory.getLogger(this.getClass());
|
private final Logger log = LoggerFactory.getLogger(this.getClass());
|
||||||
|
|
||||||
/**
|
|
||||||
* The {@link WorldService} instance
|
|
||||||
*/
|
|
||||||
private final WorldService worldService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The network configuration object
|
* The network configuration object
|
||||||
*/
|
*/
|
||||||
@@ -91,15 +86,12 @@ public class NettyNetworkService extends AbstractService implements
|
|||||||
* the configuration service
|
* the configuration service
|
||||||
* @param injector
|
* @param injector
|
||||||
* the {@link Guice} {@link Injector}
|
* the {@link Guice} {@link Injector}
|
||||||
* @param worldService
|
|
||||||
* the world service
|
|
||||||
*/
|
*/
|
||||||
@Inject
|
@Inject
|
||||||
public NettyNetworkService(ConfigurationService configService,
|
public NettyNetworkService(ConfigurationService configService,
|
||||||
Injector injector, WorldService worldService) {
|
Injector injector) {
|
||||||
this.config = configService.get(NetworkConfiguration.class);
|
this.config = configService.get(NetworkConfiguration.class);
|
||||||
this.injector = injector;
|
this.injector = injector;
|
||||||
this.worldService = worldService;
|
|
||||||
InternalLoggerFactory.setDefaultFactory(new Slf4JLoggerFactory());
|
InternalLoggerFactory.setDefaultFactory(new Slf4JLoggerFactory());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,8 +100,7 @@ public class NettyNetworkService extends AbstractService implements
|
|||||||
server = new ServerBootstrap(new NioServerSocketChannelFactory(
|
server = new ServerBootstrap(new NioServerSocketChannelFactory(
|
||||||
Executors.newCachedThreadPool(),
|
Executors.newCachedThreadPool(),
|
||||||
Executors.newCachedThreadPool()));
|
Executors.newCachedThreadPool()));
|
||||||
server.setPipelineFactory(new Lineage2PipelineFactory(injector, this,
|
server.setPipelineFactory(new Lineage2PipelineFactory(injector, this));
|
||||||
worldService));
|
|
||||||
channel = (ServerChannel) server.bind(config.getListenAddress());
|
channel = (ServerChannel) server.bind(config.getListenAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user