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();
}
}
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();
}
}
Aggregations