Search in sources :

Example 1 with IllegalPacketException

use of io.xol.chunkstories.api.exceptions.net.IllegalPacketException 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();
    }
}
Also used : PacketProcessingException(io.xol.chunkstories.api.exceptions.PacketProcessingException) SocketException(java.net.SocketException) EOFException(java.io.EOFException) IllegalPacketException(io.xol.chunkstories.api.exceptions.net.IllegalPacketException) IOException(java.io.IOException) UnknowPacketException(io.xol.chunkstories.api.exceptions.net.UnknowPacketException) LogicalPacketDatagram(io.xol.chunkstories.net.LogicalPacketDatagram)

Example 2 with IllegalPacketException

use of io.xol.chunkstories.api.exceptions.net.IllegalPacketException in project chunkstories by Hugobros3.

the class LocalClientLoadingAgent method handleServerResponse.

public void handleServerResponse(PacketWorldUser packet) throws IllegalPacketException {
    try {
        lock.lock();
        // The server refused to register us to this chunk. We gracefully accept.
        if (packet.getType() == Type.UNREGISTER_CHUNK) {
            ChunkHolder holder = world.getRegionChunkCoordinates(packet.getX(), packet.getY(), packet.getZ()).getChunkHolder(packet.getX(), packet.getY(), packet.getZ());
            // Apparently we already figured we didn't need this anyway
            if (holder == null)
                return;
            WorldInfo worldInfo = world.getWorldInfo();
            WorldInfo.WorldSize size = worldInfo.getSize();
            int filteredChunkX = holder.getChunkCoordinateX() & (size.maskForChunksCoordinates);
            int filteredChunkY = Math2.clampi(holder.getChunkCoordinateY(), 0, 31);
            int filteredChunkZ = holder.getChunkCoordinateZ() & (size.maskForChunksCoordinates);
            int summed = ((filteredChunkX << size.bitlengthOfVerticalChunksCoordinates) | filteredChunkY) << size.bitlengthOfHorizontalChunksCoordinates | filteredChunkZ;
            // We remove it from our list
            fastChunksMask.remove(summed);
            usedChunks.remove(holder);
            // And we unsub.
            holder.unregisterUser(player);
        // This is the same but for region summaries
        } else if (packet.getType() == Type.UNREGISTER_SUMMARY) {
            Heightmap regionSummary = world.getRegionsSummariesHolder().getHeightmap(packet.getX(), packet.getZ());
            if (regionSummary == null)
                return;
            usedRegionSummaries.remove(regionSummary);
            regionSummary.unregisterUser(player);
        } else
            // We only expect UNREGISTER packets from the server !
            throw new IllegalPacketException(packet);
    } finally {
        lock.unlock();
    }
}
Also used : Heightmap(io.xol.chunkstories.api.world.heightmap.Heightmap) ChunkHolder(io.xol.chunkstories.api.world.chunk.ChunkHolder) WorldInfo(io.xol.chunkstories.api.world.WorldInfo) IllegalPacketException(io.xol.chunkstories.api.exceptions.net.IllegalPacketException)

Aggregations

IllegalPacketException (io.xol.chunkstories.api.exceptions.net.IllegalPacketException)2 PacketProcessingException (io.xol.chunkstories.api.exceptions.PacketProcessingException)1 UnknowPacketException (io.xol.chunkstories.api.exceptions.net.UnknowPacketException)1 WorldInfo (io.xol.chunkstories.api.world.WorldInfo)1 ChunkHolder (io.xol.chunkstories.api.world.chunk.ChunkHolder)1 Heightmap (io.xol.chunkstories.api.world.heightmap.Heightmap)1 LogicalPacketDatagram (io.xol.chunkstories.net.LogicalPacketDatagram)1 EOFException (java.io.EOFException)1 IOException (java.io.IOException)1 SocketException (java.net.SocketException)1