From e49aaf7a6fe63937e56f2efaebad3f37574fd93f Mon Sep 17 00:00:00 2001 From: eihrul Date: Thu, 20 May 2010 16:55:27 +0000 Subject: checksum is now a run-time option --- protocol.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'protocol.c') diff --git a/protocol.c b/protocol.c index 21460b1..4150a2a 100644 --- a/protocol.c +++ b/protocol.c @@ -245,9 +245,9 @@ enet_protocol_handle_connect (ENetHost * host, ENetProtocolHeader * header, ENet ENetPeer * currentPeer; ENetProtocol verifyCommand; -#ifdef USE_CRC32 + if (host -> checksum != NULL) { - enet_uint32 crc = header -> checksum; + enet_uint32 checksum = header -> checksum; ENetBuffer buffer; command -> header.reliableSequenceNumber = ENET_HOST_TO_NET_16 (command -> header.reliableSequenceNumber); @@ -257,12 +257,11 @@ enet_protocol_handle_connect (ENetHost * host, ENetProtocolHeader * header, ENet buffer.data = host -> receivedData; buffer.dataLength = host -> receivedDataLength; - if (enet_crc32 (& buffer, 1) != crc) + if (host -> checksum (& buffer, 1) != checksum) return NULL; command -> header.reliableSequenceNumber = ENET_NET_TO_HOST_16 (command -> header.reliableSequenceNumber); } -#endif channelCount = ENET_NET_TO_HOST_32 (command -> connect.channelCount); @@ -834,9 +833,9 @@ enet_protocol_handle_incoming_commands (ENetHost * host, ENetEvent * event) peer -> address.host != ENET_HOST_BROADCAST)) return 0; -#ifdef USE_CRC32 + if (host -> checksum != NULL) { - enet_uint32 crc = header -> checksum; + enet_uint32 checksum = header -> checksum; ENetBuffer buffer; header -> checksum = peer -> sessionID; @@ -844,13 +843,12 @@ enet_protocol_handle_incoming_commands (ENetHost * host, ENetEvent * event) buffer.data = host -> receivedData; buffer.dataLength = host -> receivedDataLength; - if (enet_crc32 (& buffer, 1) != crc) + if (host -> checksum (& buffer, 1) != checksum) return 0; } -#else + else if (header -> checksum != peer -> sessionID) return 0; -#endif peer -> address.host = host -> receivedAddress.host; peer -> address.port = host -> receivedAddress.port; @@ -1415,9 +1413,8 @@ enet_protocol_send_outgoing_commands (ENetHost * host, ENetEvent * event, int ch else host -> buffers -> dataLength = (size_t) & ((ENetProtocolHeader *) 0) -> sentTime; -#ifdef USE_CRC32 - header.checksum = enet_crc32 (host -> buffers, host -> bufferCount); -#endif + if (host -> checksum != NULL) + header.checksum = host -> checksum (host -> buffers, host -> bufferCount); currentPeer -> lastSendTime = host -> serviceTime; -- cgit v1.2.3