Server architecture: not for fun

Good day! The thought occurred to create a game, so how to play one uninteresting - the game will be multiplayer.
The head of the client server architecture comes with minor amendments - from what I found on the Internet:

  1. The client sends messages to the server.
  2. The server receives them and notifies the other players - a change of coordinates, keystrokes, etc.

Here we have a few problems immediately appear:

  1. Everyone has different connection speed should be such as to make allowances for Ping, I do not even know how to make an adjustment.
  2. Continuous flooding, users asynchronously send messages to the server and for each message you need to notify all the other players.
    Solution: 1) send messages by timeout. 2) On the server, make the message queue and release them at the same time as the timeout.
  3. Player pressed the button to go and began to move in a certain direction at the client, but the message has not been received on the server and to the other players we have here going out of sync until the server is notified and the other players will not receive its new actions and coordinates amended.
    If someone is faced with problems in games or similar applications.
    Prompt the direction of solving the problem, what other problems may occur in a similar architecture. Thank you.

Networking is a fairly difficult topic to start with. I wouldn’t recommend it. also please note that many games get networking hoplessly wrong. See the different forums for your fav game to see the problems apon problems with the network side of life.

So start with a game. Add networking later. I’ll wait.

Now you have a single player game working fairly well we can start thinking about networking. There are libs and stuff to make the “marshaling” of messages or objects easier or harder. But we typically now come to the first important design question. Peer to Peer or server based. These days many people are just going server. But for smaller games like RTS etc peer to peer can still work well.

Bad connections do run badly and mostly we humans have got very good and adjusting ourself to things like lag. There is not much you can do about it. The speed of light is just too slow. (260ms ping for around the world is about as good as it gets, and in fiber it is a little slower).

Next is TCP or UDP, if your using a lib (you probably should) that will do this for you and you don’t need to worry about it. Mostly you should ALWAYS START WITH TCP. No UDP is not faster, and it is not “better”. there is one very narrow exception to that rule. A game where you can send the entire game state in a single packet and you send such packets at a fixed rate. Quake 3 and Unreal do this. Outside that use TCP. Seriously. Do you know what the 2 generals problem is? What flow control is? Congestion collapse? Packet fragmentation? Then you don’t know enough about networks to tell me UDP is better and you don’t know what TCP really does.

Now if your using a lib or TCP we finally get to your questions more or less. As stated before the simplest solution is to just send the full game state every game tick to all clients. this only works for small games. But when it does work it is a really simple system that is fairly easy to implement. Users send actions to the server. Server at the end of a game tick, processes all actions. Sends out new game state. Rinse and repeat.

More complicated systems are much harder to implement. But that is a good place to start. Esp if you havn’t done networking before.

For example simple messages.
Thread Socket + Queue and Timeouts
https://github.com/Padaboo/javasamples/blob/master/src/net/ThreadServerSample.java
Client:
https://github.com/Padaboo/javasamples/blob/master/src/net/ClientSocketSample.java

And messages from client like: {x, y, event, etc} + encryption

I want to make an RPG (like lineage) - a long and hard.
The first thing I’ll do it just chat messages (and include C libs for net and socket for benchmark) (java + websocket).
And the second is to be the shooter to test
What can advise? Thanks.

Also it depends on what type of game you are making. You’ll see very different solutions in say an RTS when compared with a FPS.

https://developer.valvesoftware.com/wiki/Source_Multiplayer_Networking

This goes into Sources latency solutions pretty in depth. Again though you gotta adapt… PvE or PvP can be a major difference maker. PvE allows you to take a lot of liberties in how you handle things :smiley:

EDIT: Just saw you say rpg. Planning on one server or multiple? Either way try to keep it simple this time round :wink: That way you might end up with a finished product

1 Like

what decisions and libraries can you recommend?

If we have 5 players in location ( 5-1) * 5 = 20 messages per time 0,25 sec for example
If we have 100 players in location (100 -1) *100 = 9900 messages (over 9000) :smile: per time 0,25 sec for example.
I’ts posible?

Well

  1. You can only try to hide, it is always there (see Valva/Quake3 style networking for more infos on ping compensation)
    → Also keep in mind that their tricks only barely work with physic engines

2.) Send the updates at a fixed rate instead, see Quake3 networking

3:) Complex, see Quake3 networking. Depdening on what game you have you might need a completly different solution.
→ Eg RTS have no problem with slightly delayed reactions
→ MMO’s usually can ignore the slight desync, as all hits ect. are done serverside automatic, and it does not really matter if you are 0.5meters off.
→ FPS now this is where it gets tricky, it depends on the type of fps
→ -> World of tanks can ignore slight dealys quite fine, as noone expects atank to react very fast
→ -> Quake 3 can replay parts as it has no physic, and retroactivly calculate what happesn
→ -> Coop games can ignore potential cheating stuff, and just play happy world networking

In practice I currenlty have a ok feeling, by only interpolating rotation client side, but do the actual moving serverside.
→ Rotation delays are percieved way stronger

Also note there are some mmo networkign middlewares, at least worth a look.

1 Like

Well, there is always SpiderMonkey already built into JME.

Thanks. I have fpm test for javascript http://www.gabrielgambetta.com/fpm_live.html

you are building packages for the client? I think [player1,player2,player3]
where player is surrealized object from server.
For example:
Player1{ focus:player2.(“fire_ball”,200), move(10,0,10),rotate(0.0.1f)}
Player2{focus.player2.(“heal”,100),move(0.0.0),rotate(0.0.0)}

or is there something better option? p2p?

server tick timer?

NIO tcp/upd
http://trac.bookofhook.com/bookofhook/trac.cgi/wiki/IntroductionToMultiplayerGameProgramming

If only JME already had a built in API for networking. We could call it SpiderMonkey and it could use efficient TCP and UDP communication and already be written and tested for you.

Oh wait!!! It does!!!

https://javadoc.jmonkeyengine.org/com/jme3/network/package-frame.html

And:
https://wiki.jmonkeyengine.org/doku.php/jme3:advanced:networking

multiplayer tcp/udp free documents (not pirate) https://yadi.sk/d/ZFKNnLI0qXZAe

We we discussed it on the forum. We need a specific format like jnon + events
Pattern observer.
I test messages during two days (in/nio/c) jmonkey networking (but its c++ sockets)

Ind we have idea a lazy messages and lazy load objects on map

1)I create an array [] [] grid that that becomes an abstraction map (the corresponding coordinates terrain/level)
2) character appears in one of the cells
3)character have a visible radius - self poin + 2 point arround
4)If an object falls into the range of the character - physical object becomes visible
5) if the radius of the character or monster drops they begin to exchange packets

And pseudo format [player1,player2,player3] - encrypted string
player - serialized object
which comprises steps, parameters, coordinates vector velocity character etc, actions
All clients receive the package.
all actions and modifiers apply

server - thread daemon with a timeout (tick) - collects and sends messages to client (player)

player send to server self serialized (action,parameters,vector,position)

Well, you can do things the hard way if you like… but the hard parts have already been done. No need to deal with low level sockets and stuff. Even people experienced in networking have problems getting that right. (Case in point, the original SpiderMonkey was basically non-functional until I rewrote it 5 years ago.)

pspeed, Hello, i use network. but the game should be 3-4 daemon (authorization,mechanic,chat,system like kron).
In some cases, apply Networking only main thread messaging?

Not if you use peer-to-peer, then it’s only 100 message (100 received and 100 sent).
Or if The Unicorn helps you, it can also make it faster.

It seems you are targeting pspeed… but i will try to answer anyway: with spidermonkey you can make multiple channels, maybe this is what you really want, because 3 daemons means 3 separate programs running in background.

jmonkey a wrapper over jogl?

server processes that exchange messages with each other
1)authorization server
2)chat daemon for player messages.
3)game mechanics
4)system processes (dump, updates,etc)
and website

This more flexible approach: 1) reduces the load 2) can be run these processes on different servers

“Not if you use peer-to-peer”
if customers will communicate with each other without server participation. then it will be possible to use the cheats.
then on each client must be “guard”?