public static string GetPlayPacketName(int id) { if (PlayFactory.TryGetPacket(id, out var p)) { return(p.GetType().Name.Replace("Packet", "")); } if (_playPacketNames.TryGetValue(id, out string result)) { return(result); } return("Unknown"); }
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); }