internal static void Register <TPacket>(PacketDirection packetDirection, ConnectionState state, int packetId, Func <TPacket> createFunc) where TPacket : Packet { if (packetDirection == PacketDirection.ServerBound) { switch (state) { case ConnectionState.Handshake: HandshakeFactory.Register(packetId, createFunc); break; case ConnectionState.Status: StatusFactory.Register(packetId, createFunc); break; case ConnectionState.Login: LoginFactory.Register(packetId, createFunc); break; case ConnectionState.Play: PlayFactory.Register(packetId, createFunc); break; default: throw new ArgumentOutOfRangeException(nameof(state), state, null); } } else { switch (state) { case ConnectionState.Handshake: ServerHandshakeFactory.Register(packetId, createFunc); break; case ConnectionState.Status: ServerStatusFactory.Register(packetId, createFunc); break; case ConnectionState.Login: ServerLoginFactory.Register(packetId, createFunc); break; case ConnectionState.Play: ServerPlayFactory.Register(packetId, createFunc); break; default: throw new ArgumentOutOfRangeException(nameof(state), state, null); } } }
public static Packet GetPacket(PacketDirection packetDirection, ConnectionState state, int packetId) { bool success; Packet outPacket; if (packetDirection == PacketDirection.ServerBound) { switch (state) { case ConnectionState.Handshake: success = HandshakeFactory.TryGetPacket(packetId, out outPacket); break; case ConnectionState.Status: success = StatusFactory.TryGetPacket(packetId, out outPacket); break; case ConnectionState.Login: success = LoginFactory.TryGetPacket(packetId, out outPacket); break; case ConnectionState.Play: success = PlayFactory.TryGetPacket(packetId, out outPacket); break; default: throw new ArgumentOutOfRangeException(nameof(state), state, null); } } else { switch (state) { case ConnectionState.Handshake: success = ServerHandshakeFactory.TryGetPacket(packetId, out outPacket); break; case ConnectionState.Status: success = ServerStatusFactory.TryGetPacket(packetId, out outPacket); break; case ConnectionState.Login: success = ServerLoginFactory.TryGetPacket(packetId, out outPacket); break; case ConnectionState.Play: success = ServerPlayFactory.TryGetPacket(packetId, out outPacket); break; default: throw new ArgumentOutOfRangeException(nameof(state), state, null); } } if (!success) { return(null); } outPacket.PacketId = packetId; return(outPacket); }