packet errors for unknown packets
This commit is contained in:
		
							parent
							
								
									415794794a
								
							
						
					
					
						commit
						7f32af6729
					
				| @ -160,7 +160,7 @@ fn generate_psopacket_impl(pkt_cmd: u16, name: syn::Ident, attrs: &Vec<AttrType> | ||||
|                 else { 0 }; | ||||
| 
 | ||||
|                 if cmd != #pkt_cmd { | ||||
|                     return Err(PacketParseError::WrongPacketCommand); | ||||
|                     return Err(PacketParseError::WrongPacketCommand {expected: #pkt_cmd, got: cmd}); | ||||
|                 } | ||||
| 
 | ||||
|                 if len as usize != data.len() { | ||||
| @ -422,7 +422,7 @@ fn generate_psomessage_impl(msg_cmd: u8, name: syn::Ident, attrs: &Vec<AttrType> | ||||
|                 let len = cur.read(&mut subbuf).unwrap(); | ||||
| 
 | ||||
|                 if cmd != #msg_cmd { | ||||
|                     return Err(PacketParseError::WrongPacketCommand); | ||||
|                     return Err(PacketParseError::WrongMessageCommand {expected: #msg_cmd, got: cmd}); | ||||
|                 } | ||||
| 
 | ||||
|                 if len != size as usize * 4 - 2 { | ||||
|  | ||||
| @ -12,9 +12,12 @@ use std::io::{Read, Seek}; | ||||
| #[derive(Debug, PartialEq)] | ||||
| pub enum PacketParseError { | ||||
|     NotEnoughBytes, | ||||
|     WrongPacketCommand, | ||||
|     WrongPacketCommand {expected: u16, got: u16}, | ||||
|     WrongPacketForServerType(u16, Vec<u8>), | ||||
|     UnknownPacket(u16, Vec<u8>), | ||||
|     WrongPacketSize(u16, usize), | ||||
|     WrongMessageCommand {expected: u8, got: u8}, | ||||
|     UnknownMessage(u8, Vec<u8>), | ||||
|     DataStructNotLargeEnough(u64, usize), | ||||
|     InvalidValue, | ||||
|     ReadError, | ||||
| @ -336,7 +339,7 @@ mod test { | ||||
|         let mut bytes = test.as_bytes(); | ||||
|         bytes[2] = 17; | ||||
|         let test2 = Test::from_bytes(&bytes); | ||||
|         assert!(test2 == Err(PacketParseError::WrongPacketCommand)); | ||||
|         assert!(test2 == Err(PacketParseError::WrongPacketCommand { expected: 0x23, got: 17})); | ||||
|     } | ||||
| 
 | ||||
|     #[test] | ||||
|  | ||||
| @ -110,7 +110,13 @@ impl PSOPacketData for GameMessage { | ||||
|             PlayerDoneChangingMap::CMD => Ok(GameMessage::PlayerDoneChangingMap(PlayerDoneChangingMap::from_bytes(&mut cur)?)), | ||||
|             TellOtherPlayerMyLocation::CMD => Ok(GameMessage::TellOtherPlayerMyLocation(TellOtherPlayerMyLocation::from_bytes(&mut cur)?)), | ||||
|             UnknownAE::CMD => Ok(GameMessage::UnknownAE(UnknownAE::from_bytes(&mut cur)?)), | ||||
|             _ => Err(PacketParseError::WrongPacketCommand), | ||||
|             _ => Err(PacketParseError::UnknownMessage(byte[0], | ||||
|                                                       { | ||||
|                                                           let mut b = vec![0; len[0] as usize * 4]; | ||||
|                                                           cur.read(&mut b).unwrap(); | ||||
|                                                           b.to_vec() | ||||
|                                                       } | ||||
|             )), | ||||
|         } | ||||
|     } | ||||
|     fn as_bytes(&self) -> Vec<u8> { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user