|
|
@ -32,21 +32,21 @@ namespace Response { |
|
|
std::optional<Type> Validate(u8* data, std::size_t size) { |
|
|
std::optional<Type> Validate(u8* data, std::size_t size) { |
|
|
if (size < sizeof(Header)) { |
|
|
if (size < sizeof(Header)) { |
|
|
LOG_DEBUG(Input, "Invalid UDP packet received"); |
|
|
LOG_DEBUG(Input, "Invalid UDP packet received"); |
|
|
return {}; |
|
|
|
|
|
|
|
|
return std::nullopt; |
|
|
} |
|
|
} |
|
|
Header header{}; |
|
|
Header header{}; |
|
|
std::memcpy(&header, data, sizeof(Header)); |
|
|
std::memcpy(&header, data, sizeof(Header)); |
|
|
if (header.magic != SERVER_MAGIC) { |
|
|
if (header.magic != SERVER_MAGIC) { |
|
|
LOG_ERROR(Input, "UDP Packet has an unexpected magic value"); |
|
|
LOG_ERROR(Input, "UDP Packet has an unexpected magic value"); |
|
|
return {}; |
|
|
|
|
|
|
|
|
return std::nullopt; |
|
|
} |
|
|
} |
|
|
if (header.protocol_version != PROTOCOL_VERSION) { |
|
|
if (header.protocol_version != PROTOCOL_VERSION) { |
|
|
LOG_ERROR(Input, "UDP Packet protocol mismatch"); |
|
|
LOG_ERROR(Input, "UDP Packet protocol mismatch"); |
|
|
return {}; |
|
|
|
|
|
|
|
|
return std::nullopt; |
|
|
} |
|
|
} |
|
|
if (header.type < Type::Version || header.type > Type::PadData) { |
|
|
if (header.type < Type::Version || header.type > Type::PadData) { |
|
|
LOG_ERROR(Input, "UDP Packet is an unknown type"); |
|
|
LOG_ERROR(Input, "UDP Packet is an unknown type"); |
|
|
return {}; |
|
|
|
|
|
|
|
|
return std::nullopt; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Packet size must equal sizeof(Header) + sizeof(Data)
|
|
|
// Packet size must equal sizeof(Header) + sizeof(Data)
|
|
|
@ -59,7 +59,7 @@ std::optional<Type> Validate(u8* data, std::size_t size) { |
|
|
Input, |
|
|
Input, |
|
|
"UDP Packet payload length doesn't match. Received: {} PayloadLength: {} Expected: {}", |
|
|
"UDP Packet payload length doesn't match. Received: {} PayloadLength: {} Expected: {}", |
|
|
size, header.payload_length, data_len + sizeof(Type)); |
|
|
size, header.payload_length, data_len + sizeof(Type)); |
|
|
return {}; |
|
|
|
|
|
|
|
|
return std::nullopt; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const u32 crc32 = header.crc; |
|
|
const u32 crc32 = header.crc; |
|
|
@ -70,7 +70,7 @@ std::optional<Type> Validate(u8* data, std::size_t size) { |
|
|
result.process_bytes(data, data_len + sizeof(Header)); |
|
|
result.process_bytes(data, data_len + sizeof(Header)); |
|
|
if (crc32 != result.checksum()) { |
|
|
if (crc32 != result.checksum()) { |
|
|
LOG_ERROR(Input, "UDP Packet CRC check failed. Offset: {}", offsetof(Header, crc)); |
|
|
LOG_ERROR(Input, "UDP Packet CRC check failed. Offset: {}", offsetof(Header, crc)); |
|
|
return {}; |
|
|
|
|
|
|
|
|
return std::nullopt; |
|
|
} |
|
|
} |
|
|
return header.type; |
|
|
return header.type; |
|
|
} |
|
|
} |
|
|
|