Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 21 Mar 2003
Offline Last Active Nov 11 2014 03:25 PM

#5158340 Network Game Design / Architecture Question

Posted by 0BZEN on 05 June 2014 - 04:26 AM

The simple way :

- Client sends inputs to the host.

- host processes inputs.

- host calculates the game state (positions of objects).

- host sends game state to clients.


Example : The original Quake networking (for LAN games).

Advantages : simple.

Disadvantages : lag becomes a serious issue. Round-trip latencies will make the client input laggy.




The way it is corrected :

- client reads his inputs, and calculates a local prediction of the player position.

- client sends inputs to the host, as well as his local prediction calculation. The input+prediction packet is marked with a unique number (aka Sequence Number, aka SQN).

- client also stores the input+prediction packet in a buffer.

- Host receives the client inputs+prediction+SQN. 
- host calculate the real player position, using those inputs.
- host then compares the player location with the client prediction.
- if a difference is detected (within an arbitrary margin of error), the host sends a correction packet back to the client (containing corrected_position+SQN).
- client receives the correction packet.
- client looks up the original input+prediction packet in his buffer, using the SQN. 
- client substitutes the predicted position with the corrected position.
- client then replays his input stack from that point onwards, to adjust his current prediction with the server correction.
Example : Counterstrike, Quake 3, Unreal Tournament, Team Fortress...
Advantages : Nullify the input latency, by allowing the client to locally predict the effect of the player's inputs. 
Disadvantages : client will experience jitter and rubber-banding when a discrepancy between the client prediction and the server calculation is detected (i.e. two players jumping on top of each other). 
looksy here.

#5152313 Why is it that some say that open source multiplayer games are less secure?

Posted by 0BZEN on 08 May 2014 - 08:05 AM

Open source makes finding exploits a lot easier. If you play it fast and loose, it'll be a lot quicker for hackers to find exploits within the code or even your design assumptions. If your game isn't particularly secure but the code cannot be reversed engineered easily, it can take more time. Ultimately, if your game is popular, you will be found out either way. 

#5150331 Your most valuable debugging techniques for Networked games?

Posted by 0BZEN on 29 April 2014 - 07:37 AM

- Make sure you also do some unit testing. smile.png


More stuff, maybe :


- Internet conditions simulation. Either basic, for a quick test, or pro-level stuff, with dedicated hardware. Will not replace real-world conditions but I find it always useful.


- Since you're dealing with binary data (most likely), some form of checksum / type-checking / range-checking verification. This mostly applies to debugging things like serialisation / deserialisation and marshaling.


- Some form of binary -> readable text conversion on packets. Usually packets are tightly packed binary streams and virtually unreadable. So, some form of analyzing packet content can be useful if you run into trouble with your packets turning up as garbage.


- Recording packets, game states, inputs, and replay features. Pretty high level, and a lot of work in itself, so you may want to skip that. 


Checksum and replay especially useful if you have the intention of running a deterministic lock-step engine.


At a game level : 


- A basic versioning system. If your packet / message format isn't backward compatible, you'll end up with garbage data. 


- Dependencies check. Making sure whoever connects to your server has all the custom content it needs to being able to play the game. Either the right version, the map data, ect... 

- A replay system can also help you catching strange game exploits. And if your game supports replays, then why not smile.png

#5148952 Your most valuable debugging techniques for Networked games?

Posted by 0BZEN on 23 April 2014 - 07:26 AM

logging everything. 

#5148567 Fast-moving 2D collisions?

Posted by 0BZEN on 21 April 2014 - 12:22 PM

to summarise :


1) approximate to a point and do a raycast test. 

2) use a swept sphere test (solving second order equations).

3) use substep collision detection. Divide your frame timestep into smaller timestep (based on the speed and size of the object), and do multiple checks along the path.


1) can be a good approximation for 'bullet hell' type of games. do a segment intersection between from the start position to the end position of the bullet from frame to frame.

2) is probably the most accurate, more math intensive. You can also do more complex swept tests with polygons, or testing fast moving objects against each other, and do proper physics as well (points of contact, accurate deflection and collision response, ect...). 

3) is the easiest to do (since it's just multiple collision detection tests). but not the cheapest computationally, or the most accurate. But can also helps with fast spinning objects, like blades. 

#5146782 Catching illegal movement with partial data

Posted by 0BZEN on 13 April 2014 - 06:13 PM

What you have isn't really server-authoritative, therefore not secure. You need to send all the inputs of the clients to the server, as well as the client's predicted position every now and then, so the server can correct the client if needed. If you send partial inputs, you leave yourself opened to exploits. If you send all the inputs, then you know exactly what the client tried to do, where it landed, and if you need to send a correction. Then the client can 'rewind' his input stack, and correct himself.




Client->server bandwidth is at a premium but luckily, if the client only has to send inputs, commands, and sometimes positions, that bandwidth usage is actually very low, even at 100hz. Do the maths, see how much data that actually is. e.g. 100 fps x 100 byte / input = 10kbytes / sec = 80 kbits / sec (plus TCP packet overheads). Secondly, since you will send your inputs reliably, you can use compression techniques to further reduce that bandwidth. 


And since you use TCP, if you start sending too much too fast, the TCP frame will drop (i.e. the send() command will not complete, or will block). But in any case, short of a network issue, you should be easily be within the bandwidth limitations of home broadband. What you can do in case your TCP stream starts breaking up, is pause the game on the client side, to let the stream recover enough. 

#5145294 How we solved the infamous sliding bug

Posted by 0BZEN on 08 April 2014 - 05:23 AM


FWIW: That's basically what GGPO does, as well as various other networked physics engines. It's not that hard to build if you can either store a log of physics state for each object, or you can allocate all needed physics state in a single block of RAM. You just have to make sure your engine is set up for it ahead of time, rather than trying to retro-fit it.

Does GGPO also do the full determinism? I know it does the rewind/resimulate thing, but I never heard it also does full determinism.



In general, If you think you need prefect determinism, you should be able to adapt your algorithms to use more 'loose' tolerances. 


What I'm thinking of :


1) some error tolerance on your objects (object position, velocity, ect...), beyond which a de-sync is detected.


2) rollback objects affected by the de-sync, re-apply the fix that reduces or eliminate the error.


3) replay those de-synced objects up to current time.

#5140069 Getting a direction constant from normalized vector

Posted by 0BZEN on 18 March 2014 - 11:27 AM

@papalazaru: Is it really simply if one needs to stare 2 minutes onto 5 lines of code until understanding it? Is it really simple if you use the word "quadrant" although you compute 6 and 2 sections, resp.? Is it really simple if you need 12 elements in the mapping, although 8 are expected? And why do you use 30° and 60° as limits, which causes obviously not an equal quantization w.r.t. the angle, without any textual hint about that? And what is the check (x >= 0.0f) good for?


If you can't read code, then I can't help you.

#5139100 Free to Play Windows games using purely UDP

Posted by 0BZEN on 14 March 2014 - 05:39 PM

Quake 3 is pure UDP. Not sure about Unreal tech. Wouldn't be surprised if they were also pure UDP. 

#5138255 Calculate relative rotation matrix

Posted by 0BZEN on 11 March 2014 - 06:08 PM

A,inverse() * B?


I think.

#5110477 [C++, eNet] Sending player state client <=> server

Posted by 0BZEN on 19 November 2013 - 08:52 AM

dont use sprintf, it's unsafe. use sprintf_s, or whatever the bound checked version is.


As for your problem, I can't say at a glance. Looks like you'll have to get better at debugging. Print out what data goes out, what data comes in, into the console, or a file, put breakpoints, and just step through the code.


Here's a simpler way to generate packets.

char packet[256];
int packetlen = sprintf_s(packet, sizeof(packet), "POS%d%s=%dx%d", nick.size(), (const char*)nick[0], pos.x, pos.y);

Finally, I would refrain from using that sort of verbose format, and use some form of binary serialisation, or some other library that will give you the opportunity to format, and parse text strings more efficiently.



Or if you want some readable packet, for debugging, 'tokenise' the string. Much easier to digest on the other end.

char packet[256];
int packetlen = sprintf_s(packet, sizeof(packet), "msgid=%s, player=%s, posx=%d, posy=%d", "POS", (const char*)nick[0], pos.x, pos.y);

#5094544 Oculus Rift SDL2 code sample

Posted by 0BZEN on 16 September 2013 - 04:17 PM

Hey guys and gals,


For anyone interested, present or future, in the Oculus Rift, but found it hard to get going through the samples and their various layers of encapsulation, I've made a short-(ish) little implementation demo. 




It's a 1,000 lines of code, uses OpenGL + SDL2 as the framework, implements the distortion filter, sensor inputs and most of the goodies. 



#5013200 shl, bitshifting by 32 bits, does nothing. nothing!

Posted by 0BZEN on 21 December 2012 - 12:23 PM

Actually, I'm a bit retarded.

instead of using a mask, for example

mask = (0xffffffff >> (32 - bitcount));

I can use

mask = ~(0xffffffff << bitcount);


#5009828 Client/Server logic on same machine, singleplayer as a local multiplayer

Posted by 0BZEN on 12 December 2012 - 08:16 AM

You could call that reflection, and is pretty much what I've seen done, with added synchronisation mechanisms.

There are a few caveats. For example, do your objects require in-order notifications of changes, or can work out of order.

For example, a change in one entity might trigger a given behaviour in another. If this arrives out of order, mayhem can ensue.

Also, does it requires an entity state to be mirrored (meaning any changes in the entity must be reflected together), or you can run updates on atomic elements out-of-order (your elements when changed will be flagged for transmission, and you can transmit the changes in any order and time you want).

This mainly depends on data dependencies, what entities depend on others, and what atomic elements / components depend on others, ect... In general, the less the dependencies, the better.

#5009060 L want design a mini game,what game can l choose?

Posted by 0BZEN on 10 December 2012 - 06:48 AM

Tetris or Pacman sounds like a natural step up. Tetris easier.

I'd look around for tutorials, and see what sort of general direction they used.