This week I've tried to make a few Stencyl Extension blocks:
- get Player (ID / Name)
- get Room (ID / Name)
- assign Name [..] to [room/player] with id []
- List of Rooms
- List of Players
It took me a while to find out that client.id != player.id. It appears that player is instantiated with room.SessionId.
Then it took me a lot longer to get a list of rooms (of the same type).
getAvailableRooms seems to show a list of rooms where you can join to, not the ones that are full or something like that.
I (also) want rooms with large number of possible clients, so the client is now always joining the same room where I want the client to be able to create a new room.
Apparently we need to use the MatchMaker to get a list of rooms. But I fail to get it to use.
It is a Server component, but how do I access this from the client when the client isn't in a room?
I've also looked at the example on MatchMaker but it registered the rooms differently then I was seeing in the 02-state-change example
Source: https://github.com/colyseus/colyseus/blob/master/src/MatchMaker.ts
At last I've hacked something together that appears to be working for now.
globals.ts:
//
// Global data for the server
//
export abstract class Globals{
private static theRooms = [];
public static set(index:string,value:string){
this.theRooms[index]=value;
}
// get, remove as well when room gets disposed
}
This static class can hold 'server-wide' globals as long as you import them in your room-code, like:
import { Globals } from "../globals"; // global data from the server
// onInit :
Globals.set(""+this.roomId, "state_handler");
This method allows me to get the list of rooms from other client sessions and even for other rooms when I want...
I'm sure that there is another way to get this done using the MatchMaker but I couldn't find example of this.