mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-05 23:22:47 +00:00
Fixes a bug in ThreadService start method
This commit is contained in:
@@ -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).
|
||||
* <p>
|
||||
* 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>
|
||||
*/
|
||||
@@ -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.
|
||||
* <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.
|
||||
*
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -40,5 +40,10 @@ public interface ItemDAO extends DataAccessObject<Item, ItemID>, Cacheable {
|
||||
*/
|
||||
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
|
||||
public List<Item> loadDroppedItems() {
|
||||
public List<Item> selectDroppedItems() {
|
||||
return database.query(new SelectListQuery<Item>() {
|
||||
@Override
|
||||
protected String query() {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user