Closed dev-zetta closed 5 years ago
The idea of having two distinct events, playerConnected and playerJoinedGame does make sense. From the lance point of view, only the first one is really interesting, and the second one is more game-specific.
maybe the right place to demonstrate this would be in a sample game.
Hello there,
the onPlayerConnected handler is called after connection on the socket is made, ie. after you call io() on on client side.
In this handle, you call method getPlayerId that is unimplemented, and then you generate the player's ID using number from number of players.
This means, that you cannot send any data, e.g. player ID, when calling connect on the client's side. So you cannot generate the player ID using any custom data.
I think that this should be split to two separate events - socket/client connect and player connect.
So first you connect to the server and then you send event 'joinToGame', or something like that, where is the player actually joins the server and where is the playerID processed/assigned.