Sending "secret" data to individual players in the Lance Game

I am wondering if there is an easy way in lance-gg to send the data of a specific player to only each player and not pass all the data to all players.

I want to create a poker game, and I don't want the data around what each player broadcasts to all the players, but instead only get every player, get information about their own cards.

Is this easily achievable between the current GameEngine and ServerEngine?

During the game, you must complete the following steps:

  • "Deal" cards to each player (issue cards to each player individually, and broadcast an event to indicate that other clients should animate the recipient of the cards receiving them).
  • store and keep open cards outside of other data to be updated.
  • draw players' cards if a player needs to be disconnected and then reconnect during a hand.
  • show cards (broadcast any up cards such as flop and showdown to all players).

Player cards must also be kept on the server, but not re-broadcast with each step.

+3


source to share


1 answer


There is a low-level network layer that can be used for client-server communication in the Lance.

For example, if the server wants to send an event shakeItUp

with data to shakeData = { ... }

all clients, the Game Server Engine will call:

this.io.sockets.emit('shakeItUp', shakeData);

      

To send events and data to specific players, the serverEngine class can do



for (let socketId of Object.keys(this.connectedPlayers)) {
    let player = this.connectedPlayers[socketId];
    let playerId = player.socket.playerId;

    let message = `hello player ${playerId}`;
    this.connectedPlayers[socketId].socket.emit('secret', message);
}

      

The client listens for messages from the clientEngine class:

this.socket.on('secret', (e) => {
    console.log(`my secret: ${e}`);
});

      

+4


source







All Articles