[ENet-discuss] [PATCH] address of disconnected peer
Benoit Germain
bgermain at ubisoft.fr
Fri Nov 26 08:10:44 PST 2004
Hello,
When host servicing yields a DISCONNECT event, it is not possible to get the
address of the remote peer because the peer's structure contents have been
erased. So here is a little patch that enables the application to get the
information anyway:
Enet.h:
typedef struct _ENetEvent
{
ENetEventType type; /**< type of the event */
ENetPeer * peer; /**< peer that generated a connect,
disconnect or receive event */
enet_uint8 channelID;
ENetPacket * packet;
+ ENetAddress address; /**< when receiving a disconnect event,
the peer is cleared, so we can get the address here instead */
} ENetEvent;
Protocol.c, lines 33, 564, 972, 1221:
if (currentPeer -> state == ENET_PEER_STATE_ZOMBIE)
{
host -> recalculateBandwidthLimits = 1;
event -> type = ENET_EVENT_TYPE_DISCONNECT;
event -> peer = currentPeer;
+ event -> address = currentPeer -> address;
...
case ENET_PEER_STATE_DISCONNECTING:
if (commandNumber != ENET_PROTOCOL_COMMAND_DISCONNECT)
return 0;
host -> recalculateBandwidthLimits = 1;
event -> type = ENET_EVENT_TYPE_DISCONNECT;
event -> peer = peer;
+ event -> address = peer -> address;
...
if (outgoingCommand -> roundTripTimeout >= outgoingCommand ->
roundTripTimeoutLimit)
{
event -> type = ENET_EVENT_TYPE_DISCONNECT;
event -> peer = peer;
+ event -> address = peer -> address;
...
int
enet_host_service (ENetHost * host, ENetEvent * event, enet_uint32 timeout)
{
enet_uint32 waitCondition;
event -> type = ENET_EVENT_TYPE_NONE;
event -> peer = NULL;
event -> packet = NULL;
event -> address . host = 0 ;
+ event -> address . port = -1 ;
__________________________________
Benoit Germain
mailto:bgermain at ubisoft.fr <mailto:bgermain at ubisoft.fr>
Person who says it cannot be done should not interrupt person doing it.
-- Chinese Proverb
People who think they're smart annoy those of us who are.
-- double-U's Proverb ?
__________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.puremagic.com/pipermail/enet-discuss/attachments/20041126/77d8f327/attachment.htm
More information about the ENet-discuss
mailing list