use of io.xol.chunkstories.api.net.PacketWorld in project chunkstories by Hugobros3.
the class WorldServer method processIncommingPackets.
public void processIncommingPackets() {
try {
entitiesLock.writeLock().lock();
Iterator<PendingPlayerDatagram> iterator = packetsQueue.iterator();
while (iterator.hasNext()) {
PendingPlayerDatagram incomming = iterator.next();
iterator.remove();
ServerPlayer player = incomming.player;
LogicalPacketDatagram datagram = incomming.datagram;
try {
// this.getContentTranslator().getPacketForId(datagram.packetTypeId);
PacketDefinitionImplementation definition = (PacketDefinitionImplementation) datagram.packetDefinition;
Packet packet = definition.createNew(false, this);
if (definition.getGenre() != PacketGenre.WORLD || !(packet instanceof PacketWorld)) {
logger().error(definition + " isn't a PacketWorld");
} else {
PacketWorld packetWorld = (PacketWorld) packet;
// packetsProcessor.getSender() is equivalent to player here
packetWorld.process(player, datagram.getData(), player.getPlayerConnection().getPacketsContext());
}
} catch (IOException | PacketProcessingException e) {
logger().warn("Networking Exception while processing datagram: " + e.getMessage());
} catch (Exception e) {
logger().warn("Exception while processing datagram: " + e.getMessage());
}
datagram.dispose();
}
} finally {
entitiesLock.writeLock().unlock();
}
}
use of io.xol.chunkstories.api.net.PacketWorld in project chunkstories by Hugobros3.
the class WorldClientRemote method processIncommingPackets.
// Accepts and processes synched packets
public void processIncommingPackets() {
try {
entitiesLock.writeLock().lock();
@SuppressWarnings("unused") int packetsThisTick = 0;
Iterator<LogicalPacketDatagram> i = incommingDatagrams.iterator();
while (i.hasNext()) {
LogicalPacketDatagram datagram = i.next();
try {
// this.getContentTranslator().getPacketForId(datagram.packetTypeId);
PacketDefinitionImplementation definition = (PacketDefinitionImplementation) datagram.packetDefinition;
Packet packet = definition.createNew(true, this);
if (definition.getGenre() != PacketGenre.WORLD || !(packet instanceof PacketWorld)) {
logger().error(definition + " isn't a PacketWorld");
} else {
PacketWorld packetWorld = (PacketWorld) packet;
// packetsProcessor.getSender() is equivalent to getRemoteServer() here
packetWorld.process(packetsProcessor.getInterlocutor(), datagram.getData(), packetsProcessor);
}
} catch (IOException | PacketProcessingException e) {
logger().warn("Networking Exception while processing datagram: " + e.getMessage());
} catch (Exception e) {
logger().warn("Exception while processing datagram: " + e.getMessage());
}
datagram.dispose();
i.remove();
packetsThisTick++;
}
} finally {
entitiesLock.writeLock().unlock();
}
}
Aggregations