In my game every packet type has a enum value assigned to it (so when packets come in between the server and the client I can tell what the packet is meant for e.g. is it a login packet, or a ping packet). My server currently has a class to handle the packets that the server gets sent:
public class PacketHandler {
public static void HandlePacket(byte[] data, InetAddress ipAddress, int port){
String message = PacketUtils.GetDataFromByteStream(data);
Packets type = PacketUtils.GetPacketIdFromByteStream(data);
switch(type) {
case INVALID:
//do whatever if we get an invalid packet
break;
case ALIVE:
//do whatever if we get an alive packet
break;
case DISCONNECT:
//do whatever if we get an disconnect packet
break;
default:
break;
}
}
in the switch statement we will perform whatever action we need to depending on what packet we recieve. My problem is this is really going to be hard to maintain. Is there a better and cleaner way of doing this. Having all of this code in one file is going to make this file really big.
Any inputs into the matter would be amazing. I really want to know what are some cleaner ways of doing this expecally from a OOPS stand point.