0
\$\begingroup\$

I'm currently playing around with phasio.io and socket.io to create a really simple multiplayer.

For the beginning i created basic movement which is synched via socket.io. The clients are sending their positions to the server and the server broadcasts it to the other clients. This works fine, however I'm aware of the fact that every user could simply cheat by emiting wrong positions.

Exactly this is where I need some new ideas. I'd really like to use phaser because it is really helful with all the animations and rotations etc. However, I kinda know i should calculate movements etc. in the backend - not in the client.

But is there a way to use phaser.io on a node server to run a game instance which then calculates the positions? Or do I need to build my "own game engine" in the backend?

An basic example would be: A player shots ( in a tank game for example ) towards another player. Using phaser only this would be very simple. But in a multiplayer i would now need to do the collision calculation on my own - right?

Any ideas ?

\$\endgroup\$
  • \$\begingroup\$ You could build your server using Unity with Unity Networking High level API docs.unity3d.com/Manual/UNetUsingHLAPI.html Unity takes care of syncing game objects between the clients and the server, so you would have a list of players game object characters on the server and the position would update automatically when each client move the character. \$\endgroup\$ – David Martinez Jul 7 '16 at 16:12
1
\$\begingroup\$

What you can do is not to send to the server the game statuses(like positions), just the clients inputs.

So on client input (lets say that clientA press 'fire' button), you can send this event to the server ('fire from clientA'), then the server broadcasts the event to all clients and are the clients whom finally make the changes, with the Phaser engine (on_client_fire render the bullet... and the same thing for movement or whatever).

On this way you will also start dealing with latency.

EDIT (with a practical example of what I meant):

If, in your update loop, you have something like this in order to move the tank:

if (cursors.left.isDown ){
    tank.body.velocity.x = -400;
}

What I suggest is changing it with womething like this:

On client, first emit that the tank wants to move:

if (cursors.left.isDown){
    socket.emit("move_left");
}

Then, on server, listen for the move and broadcasts when it arrives:

io.sockets.on("connection", on_socket_connection);

function on_socket_connection(client) {
    client.on("move_left", function(){
        io.emit("move_left_from_server", client.id);
    });
}

And back on client, listen for the server event and finally change the velocity:

socket.on("move_left_from_server", move_left_from_server_function);

function move_left_from_server_function(id) {
    //assuming you have all tanks in an array...
    tank[id].body.velocity.x = -400;
}
\$\endgroup\$
  • \$\begingroup\$ But this means my server would need to calculate the positions depending on the inputs right? I somehow understand this concept, but i really would like to have something like a gamesever which is able to use phasers calculation functions instead of writing my own one. You have any ideas for this? \$\endgroup\$ – Frank Provost Jul 7 '16 at 11:02
  • \$\begingroup\$ I think I didn't express very well, check the update with a basic example. That way, just emitting inputs, the server doesn't need to know anything about clients implementation. \$\endgroup\$ – jolmos Jul 7 '16 at 12:28
  • \$\begingroup\$ Thanks :) however, I still see tons of problems, but I'll give it a try \$\endgroup\$ – Frank Provost Jul 7 '16 at 12:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.