summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLee Salzman <[email protected]>2013-01-07 20:46:31 +0200
committerLee Salzman <[email protected]>2013-01-07 20:46:31 +0200
commit9185dc80bc59bf7d39ae4f07a9d4d1f9220fd1a3 (patch)
tree382853811bfe579e2aaa725538afd06bf84a7f5d
parent2e708e5908ab2fc2fff3eb3ffc49ce855565d257 (diff)
downloadenet-9185dc80bc59bf7d39ae4f07a9d4d1f9220fd1a3.tar.gz
enet-9185dc80bc59bf7d39ae4f07a9d4d1f9220fd1a3.zip
state handling cleanups
-rw-r--r--protocol.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/protocol.c b/protocol.c
index c8c54fd..f951ac9 100644
--- a/protocol.c
+++ b/protocol.c
@@ -742,12 +742,18 @@ enet_protocol_handle_send_unreliable_fragment (ENetHost * host, ENetPeer * peer,
static int
enet_protocol_handle_ping (ENetHost * host, ENetPeer * peer, const ENetProtocol * command)
{
+ if (peer -> state != ENET_PEER_STATE_CONNECTED && peer -> state != ENET_PEER_STATE_DISCONNECT_LATER)
+ return -1;
+
return 0;
}
static int
enet_protocol_handle_bandwidth_limit (ENetHost * host, ENetPeer * peer, const ENetProtocol * command)
{
+ if (peer -> state != ENET_PEER_STATE_CONNECTED && peer -> state != ENET_PEER_STATE_DISCONNECT_LATER)
+ return -1;
+
peer -> incomingBandwidth = ENET_NET_TO_HOST_32 (command -> bandwidthLimit.incomingBandwidth);
peer -> outgoingBandwidth = ENET_NET_TO_HOST_32 (command -> bandwidthLimit.outgoingBandwidth);
@@ -769,6 +775,9 @@ enet_protocol_handle_bandwidth_limit (ENetHost * host, ENetPeer * peer, const EN
static int
enet_protocol_handle_throttle_configure (ENetHost * host, ENetPeer * peer, const ENetProtocol * command)
{
+ if (peer -> state != ENET_PEER_STATE_CONNECTED && peer -> state != ENET_PEER_STATE_DISCONNECT_LATER)
+ return -1;
+
peer -> packetThrottleInterval = ENET_NET_TO_HOST_32 (command -> throttleConfigure.packetThrottleInterval);
peer -> packetThrottleAcceleration = ENET_NET_TO_HOST_32 (command -> throttleConfigure.packetThrottleAcceleration);
peer -> packetThrottleDeceleration = ENET_NET_TO_HOST_32 (command -> throttleConfigure.packetThrottleDeceleration);
@@ -779,7 +788,7 @@ enet_protocol_handle_throttle_configure (ENetHost * host, ENetPeer * peer, const
static int
enet_protocol_handle_disconnect (ENetHost * host, ENetPeer * peer, const ENetProtocol * command)
{
- if (peer -> state == ENET_PEER_STATE_ZOMBIE || peer -> state == ENET_PEER_STATE_ACKNOWLEDGING_DISCONNECT)
+ if (peer -> state == ENET_PEER_STATE_DISCONNECTED || peer -> state == ENET_PEER_STATE_ZOMBIE || peer -> state == ENET_PEER_STATE_ACKNOWLEDGING_DISCONNECT)
return 0;
enet_peer_reset_queues (peer);
@@ -813,6 +822,9 @@ enet_protocol_handle_acknowledge (ENetHost * host, ENetEvent * event, ENetPeer *
receivedReliableSequenceNumber;
ENetProtocolCommand commandNumber;
+ if (peer -> state == ENET_PEER_STATE_DISCONNECTED || peer -> state == ENET_PEER_STATE_ZOMBIE)
+ return 0;
+
receivedSentTime = ENET_NET_TO_HOST_16 (command -> acknowledge.receivedSentTime);
receivedSentTime |= host -> serviceTime & 0xFFFF0000;
if ((receivedSentTime & 0x8000) > (host -> serviceTime & 0x8000))
@@ -1065,7 +1077,7 @@ enet_protocol_handle_incoming_commands (ENetHost * host, ENetEvent * event)
command -> header.reliableSequenceNumber = ENET_NET_TO_HOST_16 (command -> header.reliableSequenceNumber);
- switch (command -> header.command & ENET_PROTOCOL_COMMAND_MASK)
+ switch (commandNumber)
{
case ENET_PROTOCOL_COMMAND_ACKNOWLEDGE:
if (enet_protocol_handle_acknowledge (host, event, peer, command))
@@ -1073,6 +1085,8 @@ enet_protocol_handle_incoming_commands (ENetHost * host, ENetEvent * event)
break;
case ENET_PROTOCOL_COMMAND_CONNECT:
+ if (peer != NULL)
+ goto commandError;
peer = enet_protocol_handle_connect (host, header, command);
if (peer == NULL)
goto commandError;
@@ -1146,6 +1160,8 @@ enet_protocol_handle_incoming_commands (ENetHost * host, ENetEvent * event)
{
case ENET_PEER_STATE_DISCONNECTING:
case ENET_PEER_STATE_ACKNOWLEDGING_CONNECT:
+ case ENET_PEER_STATE_DISCONNECTED:
+ case ENET_PEER_STATE_ZOMBIE:
break;
case ENET_PEER_STATE_ACKNOWLEDGING_DISCONNECT: