Packet filtering

BaseIONetworkManager contains two fields: sendFilters and receiveFilters. You can filter packets just by adding your own filter to these filter sets. A filter is defined as BiPredicate<Packet, NetworkManager>. If the BiPredicate returns true the packet will be filtered and consequently no further processed. For performance purposes you should always check for the correct packet type first.

The NetworkManager instance is provided on purpose:
You can get Player connection information with
    ((InetSocketAddress)net.channel().remoteAddress()).getAddress().getHostAddress() (here: player's IP).
You can get the player object with
    ((NetHandlerPlayServer)net.getNetHandler()).playerEntity.
Keep in mind that depending on your packet you have other INetHandlers than NetHandlerPlayServer.

Example:

BaseIONetworkManager.receiveFilters.add((packet, networkManager) -> {
if (packet instanceof CPacketLoginStart) {
CPacketLoginStart packet = (CPacketLoginStart) p;
GameProfile player = packet.getProfile();
Logger.info("GameProfile " + player.toString() + " tries to connect");
}
return true;
});

Revision #2
Created 6 June 2017 08:17:45 by deregges
Updated 6 June 2017 09:15:31 by deregges