Need a static variable which will be shared to all rooms

22 Feb 2019, 14:50

Hi,

I am new to colyseus. I just need a global static variable which will be shared to all rooms. The need of variable is due to stop login same account from multiple devices.

22 Feb 2019, 14:57

Nvm I am dumb, misunderstood the question...

22 Feb 2019, 14:58

You can use a database to do this, or redis. But you can't just share variables between rooms as they should be treated as if they have no way to communicate with each other.

22 Feb 2019, 15:00

You can have global variables only if you're running the server on a single-thread. If you're running on multiple threads, you can use this.presence inside the room handler (see docs for presence api)

As @seiyria suggested, for preventing the same user for joining multiple rooms (or the same room) it would make more sense to authenticate the user, and check the database instead during onAuth. Cheers!