A multiplayer VR framework w/voice chat
at main 1.6 kB view raw
1use crate::{ 2 buffer::Buffer, 3 packets::{ 4 link_udp::LinkUDP, notify_connection_info::NotifyConnectionInfo, null::Null, player_join_packet::PlayerJoinPacket, player_leave_packet::PlayerLeavePacket, player_list_packet::PlayerListPacket, player_voice_packet::PlayerVoicePacket, update_clients_positions::UpdateClientsPositions, update_server_position::UpdateServerPositions 5 } 6}; 7 8#[derive(Debug, Clone)] 9pub enum PacketTypes{ 10 NotifyConnectionInfo(NotifyConnectionInfo), 11 LinkUDP(LinkUDP), 12 13 UpdateServerPositions(UpdateServerPositions), 14 UpdateClientsPositions(UpdateClientsPositions), 15 16 PlayerJoinPacket(PlayerJoinPacket), 17 PlayerListPacket(PlayerListPacket), 18 PlayerLeavePacket(PlayerLeavePacket), 19 20 PlayerVoicePacket(PlayerVoicePacket), 21 22 Null(Null) 23} 24 25pub trait Packet{ 26 fn from_buf(buf: &mut Buffer) -> Self; 27 fn to_buf(self) -> Buffer; 28} 29 30pub fn parse(buf: &mut Buffer) -> PacketTypes{ 31 let id = buf.get_u16(); 32 33 match id{ 34 0 => PacketTypes::NotifyConnectionInfo(NotifyConnectionInfo::from_buf(buf)), 35 1 => PacketTypes::LinkUDP(LinkUDP::from_buf(buf)), 36 37 2 => PacketTypes::UpdateServerPositions(UpdateServerPositions::from_buf(buf)), 38 6 => PacketTypes::UpdateClientsPositions(UpdateClientsPositions::from_buf(buf)), 39 40 3 => PacketTypes::PlayerJoinPacket(PlayerJoinPacket::from_buf(buf)), 41 4 => PacketTypes::PlayerListPacket(PlayerListPacket::from_buf(buf)), 42 5 => PacketTypes::PlayerLeavePacket(PlayerLeavePacket::from_buf(buf)), 43 44 7 => PacketTypes::PlayerVoicePacket(PlayerVoicePacket::from_buf(buf)), 45 46 _ => PacketTypes::Null(Null::from_buf(buf)) 47 } 48}