3
\$\begingroup\$

About 8 months ago, I asked this question, and received a lot of valuable information from the community.

I have switched to nodejs, since then, and am finishing up my game. I am deeply concerned about networking issues pertaining to the usage of WebSocket data being sent through my current architecture; especially since my game uses an authoritarian server, and doesn't utilize peer to peer.

My game is a Diablo 2 inspired action RPG. As we know, for action RPGs, players utilize a lot of skills, and if games are instanced based, all players in the game need to be notified.


I am worried about scalability. Here is an example:

Shooting a fireball has a 0.5 second cool-down. This is how the data is sent:

  • Client [Skill id, Skill rotation] -> Server
  • Server [Checks cooldown, notify's players skill is being used]
  • Client [If fireball hits monster, send attack signal] -> Server
  • Server [Checks cooldown, player's range to mob, calculates damage, etc & spits out damage numbers to all players]

All this happens in less than 1 second. The WebSocket server is not even sending out the Monster AI update packets to do damage to the player, nor the monster's fireballs. So now, basically double the amount of data is being sent through the WebSocket and to all player's in a game. It gets worse; imagine if 20 players are online attacking monsters. My nodejs server will be on fire.

This method is not even 100% cheat proof, as I'm waiting for the fireball to hit the monster on the client-side to send the attack signal, instead of doing all that on the server. The problem is, I would have to be running a physics engine on the server, which would bog down nodejs's event loop even more. I'm using the P2 Physics engine from Phaser, and not simple AABB; otherwise, I could just check for collisions server-side.

To close, when a player moves around the map, the server notifys everyone else in the same game. The same goes for when a player drops an item, or when loot is generated from a monster. I just feel like I'm clogging my WebSocket server up, and am doing something wrong with all this data being sent across the pipe.


So with all this said,

  • Am I worrying too much about the amount of data being sent across WebSockets?

  • Is this data being sent normal for a games that utilizes an authoritarian server?

  • Would a Redis Pub Sub system be an ideal solution to my problems?

\$\endgroup\$
6
  • \$\begingroup\$ Are you sure you even have a problem? Did you test it in a profiler with 20 automated players? All of this sounds like premture optimization to me. \$\endgroup\$
    – Philipp
    Nov 19, 2015 at 9:59
  • 1
    \$\begingroup\$ Client [If fireball hits monster, send attack signal] -> Server This is suboptimal and the first hooking point for cheaters. The client sends the attack signal and the server checks if fireball hits the monster. \$\endgroup\$
    – monty
    Nov 19, 2015 at 13:13
  • 1
    \$\begingroup\$ @NiCkNewman Doing regular performance tests during development can be very useful. The earlier you catch a problem the easier it will be to fix it. But it is important that you test first and fix when you have proven that there is a problem. Otherwise you risk wasting time on solving problems you don't actually have. \$\endgroup\$
    – Philipp
    Nov 19, 2015 at 13:33
  • 1
    \$\begingroup\$ You might implement some of the optimizations I discussed in this article: gamasutra.com/blogs/AlessandroAlinone/20131127/205705/… \$\endgroup\$ Nov 19, 2015 at 17:09
  • 1
    \$\begingroup\$ @AlessandroAlinone Thanks alessandro, I found your presentation as well, as well. This is amazingly good stuff. \$\endgroup\$ Nov 19, 2015 at 17:22

1 Answer 1

3
\$\begingroup\$

Send as few packets as possible, with as much detail in them as needed, without impacting on the players' experience of the game.

Do not send every entity's movement to every player. "Activate" entities for players based on whether they're within a certain range (sight + 20%, perhaps) and inform them about actions only then.

As for the attack function, it's bad because it doesn't sync very well. Client needs to tell the server that it fired a fireball at X time. If that's within Y, server will accept it as legitimate and tell nearby players that at X time, a fireball is moving in Z direction, so that they can re-create the exact trajectory of the fireball.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .