Strategy for creating online game?

So I’ve been making a (two player) game for a while, and I want to add an online mode. I’m able to get the Server, Client, etc. classes working the way I want, so that’s fine. I’m just wondering how I would go about making the actual game playable over the internet. I’ve decided that one player will have a server as well as a client, and the second player will have just the client. These are the two strategies I thought of:

  1. Have the client-only player send their control inputs to the server player. The server player sends them back a picture of the screen, and the sounds they should be playing. (both players have the same camera view in the offline mode, btw)
    PROS: Simple to implement, and if I ever want to add more than two players it will be easy to do.
    CONS: Essentially streaming a video to the client, which seems like it would be pretty slow. Sure, the client has all the audio assets, and the screen resolution is only 640x480 (it’s a retro-style game), but it’s still video streaming.

  2. Player 1 sends their inputs to player 2, and vice versa. Each player process the inputs and runs the game on their own.
    PROS: This is the more “normal” way of doing things, and would likely be much faster than the other method.
    CONS: There’s more of a risk of gameplay becoming… “desynced”? For lack of a better word. If any of the inputs get dropped, or if I forget to keep the same seed for any of my random number generators, gameplay between the two players will end up differently. This can be prevented, but it will be much more work.

What do you all advise? Some variation of these? A third method?

(I’ve been trying to find tutorials for this, but my Google-Fu must not be that great. So, sorry if this has already been answered)

The first one is really a bad idea. The second one is fine, but it depends on what game you are doing, if you have some sort of result from these inputs you can just send it.
For example on an fps game you would send player positions, not key inputs.
About the synchronization: multiplayer games are always out of sync, the goal is to make the player believe they aren’t, but how you do that depends again on the kind of game you are making.

Check these articles out. Even if you aren’t making an FPS, they are a good foundation in the issues of real time networking:
https://developer.valvesoftware.com/wiki/Source_Multiplayer_Networking
https://developer.valvesoftware.com/wiki/Latency_Compensating_Methods_in_Client/Server_In-game_Protocol_Design_and_Optimization

1 Like

@RiccardoBlb
It’s a 2D fighting game, FYI.

I could send the inputs to the server, then have the server send back things like the position of all entities, and the current frame of the current animation (e.g. frame 2 of punch1 animation)? I’d probably have to modify or extend the Picture class so that it remembers the source of its images, but I guess that could work?

@pspeed

Which seems to be what that first link is talking about- sending the current world state and generating the video and audio on the client side.

So… does that work?

Nah. No one plays any Valve games. :slight_smile:

Yeah, but “extending the Picture class” is already thinking about this the wrong way. Game state != visuals. Your visuals are going to want to interpolate between some known game state values.

It gets a bit complicated.

I wrote a library on top of SpiderMonkey for doing this sort of thing but it’s completely undocumented right now.

At least one other person was able to grab it and figure it out, though. (Using it in a space MMO.)

Hmm… maybe if I made some sort of “special entity” that can be created with any sprite sheet, then I could just send the position, animation name, and frame number to the client?

A 2d fighting game like tekken?

If so i don’t think SimEthereal would fit. The usual approach for these games is to send input keys, use authoritative clients, sync the actions by adding artificial latency and hide glitches with animations.
You can for example send a fixed number of packets per seconds that carry the timestamp and one or none input, when there is one missing, you pause the simulation and wait.

Authoritative clients- meaning, a server hosted somewhere, and both players are only clients?

If so, I realize that’s the standard for fighters, but it’s not really practical to do for me for various reasons.

Of course, nothing’s stopping me from pausing the simulation on both ends when a packet is missing regardless. So this is still helpful information.

Authoritative clients- meaning, a server hosted somewhere, and both players are only clients?

No, well it can be also two clients and no server, it doesn’t really matter.

To make an example, authoritative server is when your client say “I throw a punch” and the server reply “You hit something”, authoritative client is when your client say “I throw a punch and hit something” and the server/other client believe you.
With authoritative clients you basically trust the player that may use cheats, but you avoid some latency.

Then off course you can mix both ways.

Of course, nothing’s stopping me from pausing the simulation on both
ends when a packet is missing regardless. So this is still helpful information.

Yes, you have to do this in any case, since there is always latency in both ends, no matter what.

Ah, ok.