Navigation

  • Recent
  • Tags
  • Users
  • Search
  • Login
Colyseus
  • Login
  • Search
  • Recent
  • Tags
  • Users

Documentation GitHub

We're migrating to GitHub Discussions. This forum does not accept new registrations since April 6, 2023.
  1. Home
  2. deadwind88
  3. Posts
  • Profile
  • More
    • Continue chat with deadwind88
    • Flag Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

Posts made by deadwind88

RE: How to send message to client by client ID

@endel Thank you so much.
But i still not understand how to send the code to player who is invited.
For example:
Player A login, and see this lists
B, C, D
A want to invite C to duel, A send a message to Server "Hey, I want to make a duel with C"
I don't know how to make Server to send message to C "Hey A want to make a dule with C" and C can accept or not.
This is my code

// When a client sends a message
    onMessage (client, message) {
        switch (message.action) {
            //A send request to invite C to make a duel
            case 'request_dule':
                let guestId = message.data.guest_id;
                let guest = this.state.players[guestId];
                //find a client has id equal with C's client id
                for (let i = 0; i < this.clients.length; i++) {
                    if (this.clients[i].id == guest.client_Id) {
                        //send request to C's client and wait C accepting
                        this.send(this.clients[i], {action: 'request_dule', data: {host: client.id}});
                        break;
                    }
                }
                break;
            default:
                break;
        }
    }

Looking forward your advice. Thanks

posted in Questions & Help • 4 Feb 2019, 14:22
How to send message to client by client ID

Hi everyone.
I am new in Colyseus. I am learning to create a simple game.
All players will join only one room - Lobby
Then choose one in other players to invite to dule ( 1 vs 1 game)
If the invited player accepts, other players will see this two players are marked "Duling"
Then this two players will moved to Game screen to dule.
But i have problem in two steps

  1. How to send message to chosen player?
    I am going to use foreach to check all clients in the room with chosen player client ID. But i think it is bad solution.
  2. I don't know one client can connect to many room or not.
    Because as i understood, these two players will be moved to Game room that only has 2 players. But i still want to keep their name and status in Lobby screen.
    What is best solution?
    Thanks you so much.
posted in Questions & Help • 4 Feb 2019, 10:01

© 2023 Endel Dreyer