<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<TITLE>Framented packet bug ?</TITLE>

<META content="MSHTML 6.00.2800.1479" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=643570017-09122004><FONT 
face="Lucida Console" color=#0000ff size=2>It seems that the following fixes the 
problem, but I'd rather have an official fix :-)</FONT></SPAN><SPAN 
class=643570017-09122004><FONT face="Lucida Console" color=#0000ff 
size=2></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=643570017-09122004><FONT 
face="Lucida Console" color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=643570017-09122004><FONT 
face="Lucida Console" color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=643570017-09122004><FONT 
face="Lucida Console" color=#0000ff size=2>ENetIncomingCommand 
*<BR>enet_peer_queue_incoming_command (ENetPeer * peer, const ENetProtocol * 
command, ENetPacket * packet, enet_uint32 
fragmentCount)<BR>{<BR>&nbsp;&nbsp;&nbsp; ENetChannel * channel = &amp; peer 
-&gt; channels [command -&gt; header.channelID];<BR>&nbsp;&nbsp;&nbsp; 
enet_uint32 unreliableSequenceNumber = 0;<BR>&nbsp;&nbsp;&nbsp; 
ENetIncomingCommand * incomingCommand;<BR>&nbsp;&nbsp;&nbsp; ENetListIterator 
currentCommand;</FONT></SPAN></DIV>
<DIV><FONT face="Lucida Console" color=#0000ff size=2></FONT>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=643570017-09122004><FONT 
face="Lucida Console" color=#0000ff size=2>&nbsp;&nbsp;&nbsp; switch (command 
-&gt; header.command)<BR>&nbsp;&nbsp;&nbsp; {<BR>+&nbsp;&nbsp; case 
ENET_PROTOCOL_COMMAND_SEND_FRAGMENT:<BR>&nbsp;&nbsp;&nbsp; case 
ENET_PROTOCOL_COMMAND_SEND_RELIABLE:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for 
(currentCommand = enet_list_previous (enet_list_end (&amp; channel -&gt; 
incomingReliableCommands));<BR></FONT></SPAN></DIV>
<DIV><FONT face="Lucida Console" color=#0000ff size=2></FONT>&nbsp;</DIV>
<DIV><FONT face="Lucida Console" color=#0000ff size=2><SPAN 
class=643570017-09122004>There is another bug though, when the data being sent 
spans more that 32 fragments: the fragment reception bitfield is not properly 
updated, which causes all fragments above 32 included to be dropped, because 
(1&lt;&lt;n) where n&gt;31 is always 0.&nbsp;&nbsp;Thus the following fix. <SPAN 
class=643570017-09122004><FONT face="Lucida Console" color=#0000ff size=2>BTW, 
note that data copying into the reunited packet needs only to be done for new 
received fragments, hence the enclosing braces that I added:</FONT></SPAN><FONT 
face="Lucida Console"><BR></FONT></SPAN></FONT></DIV>
<DIV><FONT face="Lucida Console" color=#0000ff size=2></FONT>&nbsp;</DIV>
<DIV><FONT face="Lucida Console"><FONT color=#0000ff><FONT size=2><SPAN 
class=643570017-09122004>-</SPAN>&nbsp;&nbsp; if ((startCommand -&gt; fragments 
[fragmentNumber / 32] &amp; (1 &lt;&lt; fragmentNumber)) == 0)<BR><SPAN 
class=643570017-09122004>+</SPAN>&nbsp;&nbsp; if ((startCommand -&gt; fragments 
[fragmentNumber / 32] &amp; (1 &lt;&lt; (fragmentNumber &amp; 31))) == 
0)<BR><SPAN class=643570017-09122004>+</SPAN>&nbsp;&nbsp; 
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- startCommand -&gt; 
fragmentsRemaining;</FONT></FONT></FONT></DIV>
<DIV><FONT face="Lucida Console" color=#0000ff size=2></FONT>&nbsp;</DIV>
<DIV><FONT face="Lucida Console"><FONT color=#0000ff><FONT size=2><SPAN 
class=643570017-09122004>-</SPAN>&nbsp;&nbsp;&nbsp; startCommand -&gt; fragments 
[fragmentNumber / 32] |= (1 &lt;&lt; fragmentNumber);<BR><SPAN 
class=643570017-09122004>+</SPAN>&nbsp;&nbsp;&nbsp; startCommand -&gt; fragments 
[fragmentNumber / 32] |= (1 &lt;&lt; (fragmentNumber &amp; 
31));</FONT></FONT></FONT></DIV>
<DIV><FONT face="Lucida Console" color=#0000ff size=2></FONT>&nbsp;</DIV>
<DIV><FONT face="Lucida Console" color=#0000ff 
size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (fragmentOffset + fragmentLength &gt; 
startCommand -&gt; packet -&gt; 
dataLength)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fragmentLength = 
startCommand -&gt; packet -&gt; dataLength - fragmentOffset;</FONT></DIV>
<DIV><FONT face="Lucida Console" color=#0000ff size=2></FONT>&nbsp;</DIV>
<DIV><FONT face="Lucida Console" color=#0000ff 
size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; memcpy (packet_data(startCommand -&gt; 
packet) + 
fragmentOffset,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
(enet_uint8 *) command + sizeof 
(ENetProtocolSendFragment),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
fragmentLength);<BR><SPAN class=643570017-09122004>+</SPAN>&nbsp;&nbsp; 
}<BR>}</FONT></DIV>
<DIV><FONT><FONT face="Lucida Console"><FONT color=#0000ff 
size=2></FONT></FONT>&nbsp;</DIV></FONT>
<DIV><FONT face="Lucida Console" color=#0000ff size=2></FONT>&nbsp;</DIV>
<P><FONT face="Lucida Console" color=#800000 
size=2>__________________________________</FONT> <BR><FONT face="Lucida Console" 
color=#800000 size=2>Benoit Germain</FONT> <BR><FONT face="Lucida Console" 
color=#800000 size=2>][ Engineer</FONT> <BR><FONT face="Lucida Console" 
color=#800000 size=2><A 
href="mailto:bgermain@ubisoft.fr">mailto:bgermain@ubisoft.fr</A></FONT> 
<BR><FONT face="Lucida Console" color=#800000 
size=2>__________________________________</FONT> </P>
<DIV><FONT face="Lucida Console" color=#0000ff 
size=2></FONT>&nbsp;</DIV></BODY></HTML>