use of io.xol.chunkstories.api.exceptions.PacketProcessingException in project chunkstories by Hugobros3.
the class StreamGobbler method run.
@Override
public void run() {
try {
while (connection.isOpen()) {
LogicalPacketDatagram datagram = connection.getPacketsContext().digestIncommingPacket(in);
connection.handleDatagram(datagram);
}
} catch (SocketException e) {
// Natural
if (connection.isOpen()) {
logger.info("Closing socket.");
}
connection.close();
} catch (EOFException e) {
// Natural too
connection.close();
logger.info("Connection closed");
} catch (IOException e) {
connection.close();
logger.info("Connection error", e);
} catch (UnknowPacketException e) {
logger.error("Unknown packet", e);
connection.close();
} catch (PacketProcessingException e) {
connection.close();
logger.error("Error processing packet", e);
} catch (IllegalPacketException e) {
logger.error("Illegal packet", e);
connection.close();
}
}
use of io.xol.chunkstories.api.exceptions.PacketProcessingException 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.exceptions.PacketProcessingException 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