Advertisement

randomness over the net

Started by February 21, 2005 04:02 AM
6 comments, last by bjogio 20 years ago
considering an application that uses random values and these values are important for gameplay (amount of damages, monster spawn etc). How you ensure that the randomness will be the same in every client? In my app I only send keystroke. What about setting a well-known seed as random init function (srand)? If I remember well with an N value as seed the M generated pseudo-random number will be the same.
[ILTUOMONDOFUTURO]
should work. However you might run into trouble if you do cross-platform development or if you ever change compilers or versions, because the pseudo-random number generator might change. To guard against that I recommend you implement your own PRNG in code, to make certain it is consistent.

(by the way, this might invite some hacks, e.g. using a look-ahead to see how much gold will be dropped by the next monster, and waiting to kill it until it exceeds some threshold.)
Advertisement
boost library has some PRNGs - I suspect they're crossplatform and consistent
Quote:
Original post by Anonymous Poster
As a general rule, do not use keystrokes in packets. Open invitation for 12 year old morons to cheat. I hate coding multiplayer stuff, you have to worry about possible hacks alot, and the mere thought of somebody cheating in an online game raises my blood pressure.

Er yea, don't use keystrokes.

dear anonimous I do not work with the source code for the apps I write so the only way to let them communicate is sending keystroke. Cracks are possible for every kind of network code.
[ILTUOMONDOFUTURO]
Hi,

There's also a good random number generator here: mersenne twister

It's the one that kenta cho guy uses for his games (eg. parsec 47)

-j
Jonathan Makqueasy gamesgate 88[email=jon.mak@utoronto.ca]email[/email]
OpenTTD uses just such a scheme.

All commands that the user affects are queued and sent to the server (after locally checking that they're acceptable). All game state is maintained independently in each client.

Each command is timestamped so they're applied at the right frame and in the right order. Random numbers are used to determine various events in the game, but the RNGs in the different clients (and server) stay in sync because they use a portable RNG which is seeded from the same value.

Commands are acted on locally only when they come back from the server (even if they originated locally). So the server will have checked and timestamped them, so all the clients' games should stay in sync (which they don't always, but mostly.)

OpenTTD is cross-platform and clients on win32, Mac and Linux can all play against each other seamlessly.

Mark
Advertisement
unlucky to say but I cannot use these libs. My prog (fiercegear.combovideos.com) is an interface for some games that are shipped without source so I have to make some little trick. Only hope that these games uses srand & rand. Thanks for the reply
[ILTUOMONDOFUTURO]

This topic is closed to new replies.

Advertisement