<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2658.2">
<TITLE>[PATCH] address of disconnected peer</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=2 FACE="Lucida Console">Hello,</FONT>
</P>
<BR>
<P><FONT SIZE=2 FACE="Lucida Console">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:</FONT></P>
<P><FONT SIZE=2 FACE="Lucida Console">Enet.h:</FONT>
</P>
<P><FONT SIZE=2 FACE="Lucida Console">typedef struct _ENetEvent </FONT>
<BR><FONT SIZE=2 FACE="Lucida Console">{</FONT>
<BR><FONT SIZE=2 FACE="Lucida Console"> ENetEventType type; /**< type of the event */</FONT>
<BR><FONT SIZE=2 FACE="Lucida Console"> ENetPeer * peer; /**< peer that generated a connect, disconnect or receive event */</FONT>
<BR><FONT SIZE=2 FACE="Lucida Console"> enet_uint8 channelID;</FONT>
<BR><FONT SIZE=2 FACE="Lucida Console"> ENetPacket * packet;</FONT>
<BR><FONT SIZE=2 FACE="Lucida Console">+ ENetAddress address; /**< when receiving a disconnect event, the peer is cleared, so we can get the address here instead */</FONT></P>
<P><FONT SIZE=2 FACE="Lucida Console">} ENetEvent;</FONT>
</P>
<BR>
<BR>
<P><FONT SIZE=2 FACE="Lucida Console">Protocol.c, lines 33, 564, 972, 1221:</FONT>
</P>
<P><FONT SIZE=2 FACE="Lucida Console"> if (currentPeer -> state == ENET_PEER_STATE_ZOMBIE)</FONT>
<BR><FONT SIZE=2 FACE="Lucida Console"> {</FONT>
<BR><FONT SIZE=2 FACE="Lucida Console"> host -> recalculateBandwidthLimits = 1;</FONT>
</P>
<P><FONT SIZE=2 FACE="Lucida Console"> event -> type = ENET_EVENT_TYPE_DISCONNECT;</FONT>
<BR><FONT SIZE=2 FACE="Lucida Console"> event -> peer = currentPeer;</FONT>
<BR><FONT SIZE=2 FACE="Lucida Console">+ event -> address = currentPeer -> address;</FONT>
</P>
<P><FONT SIZE=2 FACE="Lucida Console">...</FONT>
</P>
<P><FONT SIZE=2 FACE="Lucida Console"> case ENET_PEER_STATE_DISCONNECTING:</FONT>
<BR><FONT SIZE=2 FACE="Lucida Console"> if (commandNumber != ENET_PROTOCOL_COMMAND_DISCONNECT)</FONT>
<BR><FONT SIZE=2 FACE="Lucida Console"> return 0;</FONT>
</P>
<P><FONT SIZE=2 FACE="Lucida Console"> host -> recalculateBandwidthLimits = 1;</FONT>
</P>
<P><FONT SIZE=2 FACE="Lucida Console"> event -> type = ENET_EVENT_TYPE_DISCONNECT;</FONT>
<BR><FONT SIZE=2 FACE="Lucida Console"> event -> peer = peer;</FONT>
<BR><FONT SIZE=2 FACE="Lucida Console">+ event -> address = peer -> address;</FONT>
</P>
<P><FONT SIZE=2 FACE="Lucida Console">...</FONT>
</P>
<BR>
<P><FONT SIZE=2 FACE="Lucida Console"> if (outgoingCommand -> roundTripTimeout >= outgoingCommand -> roundTripTimeoutLimit)</FONT>
<BR><FONT SIZE=2 FACE="Lucida Console"> {</FONT>
<BR><FONT SIZE=2 FACE="Lucida Console"> event -> type = ENET_EVENT_TYPE_DISCONNECT;</FONT>
<BR><FONT SIZE=2 FACE="Lucida Console"> event -> peer = peer;</FONT>
<BR><FONT SIZE=2 FACE="Lucida Console">+ event -> address = peer -> address;</FONT>
</P>
<P><FONT SIZE=2 FACE="Lucida Console">...</FONT>
</P>
<P><FONT SIZE=2 FACE="Lucida Console">int</FONT>
<BR><FONT SIZE=2 FACE="Lucida Console">enet_host_service (ENetHost * host, ENetEvent * event, enet_uint32 timeout)</FONT>
<BR><FONT SIZE=2 FACE="Lucida Console">{</FONT>
<BR><FONT SIZE=2 FACE="Lucida Console"> enet_uint32 waitCondition;</FONT>
</P>
<P><FONT SIZE=2 FACE="Lucida Console"> event -> type = ENET_EVENT_TYPE_NONE;</FONT>
<BR><FONT SIZE=2 FACE="Lucida Console"> event -> peer = NULL;</FONT>
<BR><FONT SIZE=2 FACE="Lucida Console"> event -> packet = NULL;</FONT>
<BR><FONT SIZE=2 FACE="Lucida Console"> event -> address . host = 0 ;</FONT>
<BR><FONT SIZE=2 FACE="Lucida Console">+ event -> address . port = -1 ;</FONT>
</P>
<BR>
<BR>
<BR>
<P><FONT COLOR="#800000" SIZE=2 FACE="Lucida Console">__________________________________</FONT>
<BR><FONT COLOR="#800000" SIZE=2 FACE="Lucida Console">Benoit Germain</FONT>
<BR><A HREF="mailto:bgermain@ubisoft.fr"><U></U><U><FONT COLOR="#0000FF" SIZE=2 FACE="Lucida Console">mailto:bgermain@ubisoft.fr</FONT></U></A>
</P>
<P><FONT COLOR="#660000" SIZE=2 FACE="Lucida Console">Person who says it cannot be done should not interrupt person doing it.</FONT>
<BR><FONT COLOR="#660000" SIZE=2 FACE="Lucida Console">-- Chinese Proverb</FONT>
</P>
<P><FONT COLOR="#800000" SIZE=2 FACE="Lucida Console">People who think they're smart annoy those of us who are.</FONT>
<BR><FONT COLOR="#800000" SIZE=2 FACE="Lucida Console">-- double-U's Proverb ?</FONT>
<BR><FONT COLOR="#800000" SIZE=2 FACE="Lucida Console">__________________________________</FONT>
</P>
</BODY>
</HTML>