# Rediculous question

This topic is 4999 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

My game server and client both send updates to each other 20 times per second. Each packet has an unsigned int ID which is incremented each time the server or client sends. So, this means that there should be a wrap to 0 at about 2^32 /20/60/60/24 = 2485 days = 6.8 years. Should this problem even be dealt with? I suppose all that needs to be worried about is
if(packet.id>last_read_packet){
//use teh packet lolol!
}

I suppose I'd solve it by checking if the difference is around 4 billion. But, that's if I really need to worry about it.

##### Share on other sites
Do you really expect clients to be connected continuously for 6.8 years?

##### Share on other sites
if(packet.id>=2^32-LAG_FACTOR){      tell_user_to_get_a_life___and_then_quit();}

lol

##### Share on other sites
Quote:
 Original post by matt_jif(packet.id>=2^32-LAG_FACTOR){ tell_user_to_get_a_life___and_then_quit();}

Yep, thats the best solution. I use it, too. But only in debug mode..

##### Share on other sites
Quote:
 Original post by matt_jif(packet.id>=2^32-LAG_FACTOR){ tell_user_to_get_a_life___and_then_quit();}

[lol] Great! But you shouldn't even waste the CPU cycles checking every time. I mean when the number gets that high it will just loop over, giving anyone who tries running your game over 6 years a suprise [smile]

##### Share on other sites
When you deal with things that can cycle around, your best bet is to always deal with differences, rather than absolute numbers. Thus:

void some_function( size_t a, size_t b ) {  if( ssize_t(a-b) < 0 ) {    you_are_behind();  }  else {    you_are_ahead();  }}

When wrapping, it doesn't matter in this case -- as long as your CPU is 2's complement, of course :-)

##### Share on other sites
use long longs.

Thats 2^64 * 1/20 = 922337203685477580 seconds. (to nearest one)

Thats a long time.

From,
Nice coder

##### Share on other sites
Or, after 6.8 years, people's games will crash, and I'll get bug reports. So, I'll get on the compiler, change the version number from "1.0" to "1.1", re-compile, and make sure the affected users download it.

Yup, that solves anything. If the bug pops up again, it should probably be easy to fix...

##### Share on other sites
you do start at 0 each round right?
Unless you're talking about an official game server, no one is ever going to run past the wrap time in a row.
And even if it is so, Every official game server out there, even for MMOG, has been down for maintenance within a single year.

So, you don't have to patch it. Sounds fine like it is.

About that difference algorithm, yeah thats the good way, but add this for the wrap: check if the difference is too big and with the proper sign. Say, half the size of the datatype.

1. 1
Rutin
42
2. 2
3. 3
4. 4
5. 5

• 9
• 26
• 20
• 14
• 14
• ### Forum Statistics

• Total Topics
633384
• Total Posts
3011596
• ### Who's Online (See full list)

There are no registered users currently online

×