larku / RakNet

RakNet is a cross platform, open source, C++ networking engine for game programmers.
Other
60 stars 27 forks source link

Timestamps read from incoming packets are in the wrong byte order and mismatch local GetTime() by a large offset #40

Open bluebear94 opened 7 years ago

bluebear94 commented 7 years ago

This at least happens on Linux (Ubuntu 16.04), and with 64-bit timestamps enabled or disabled.

Kiddinglife commented 7 years ago

Not really understanding your problem. As far as I can see, timestamps should be transformed into network order by library user.

bluebear94 commented 7 years ago

I am writing and reading them in network order using the BitStream class.

Actually, removing from Source/RakPeer.cpp the line (3799):

timeBS.EndianSwapBytes(0,sizeof(RakNet::Time));

fixes the issue. However, I'm not sure if this triggers any bugs with big-endian platforms.

Kiddinglife commented 7 years ago

I believe you client and server have different edian formate, one little, the other big. raknet in default uses big-endian if you enable endian swap macro. So, I am gussing the reason could be that endian-swao-macro is not enabled in either of your client and server.

bluebear94 commented 7 years ago

I'm building both the client and the server with the same library.

ltjax commented 6 years ago

Yea, I have the same problem as bluebear94. The ending swapping should be done by the BitStream on both sides... unless you have __BITSTREAM_NATIVE_END disabled. The way I see it, you should put host byte order into BitStream and it does the conversion, since that is what RakNet does itself (see NAT punch through server for example)