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. visgotti
  3. Best
  • Profile
  • More
    • Continue chat with visgotti
    • Flag Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

Best posts made by visgotti

RE: Using multiple rooms to support one large map?

@endel Sounds good. Thank you! For persisting data between rooms, I'm using the room.presence functions for getting/setting player attributes on onAuth and onLeave. Is this acceptable or is there a more efficient way of accomplishing the same thing?

posted in Questions & Help • 21 Sept 2018, 23:02
RE: How to generate unique 6 digit game code?

It's a bit of a loaded quesiton, and colyseus doesn't really support this out of the box but it's possible.

Without touching colyseus's code, I would probably have the 6 digit code mapped to a pre existing game type you have handlers for- Capture The Flag, King of the Hill, or however you're naming you're handlers. Register as many as them as you think you'll need and make sure they have a unique ROOM ID this is for colyseus, this is NOT the id your host is coming up with. So "Capture The Flag 1" "Capture The Flag 2" etc.

Then what'd I do is basically have another room called something like "RoomCreator"... a more suitable name would probably be "RoomMapper" which the host will first connect to, then from there the host can tell the RoomMapper "Hey, I want to create a Capture The Flag room with the ID "jellitans awesome ctf". Then the room mapper will basically look through the registered CTF handlers and see which ones are not already in use. It will then send back the host to connect to the room "Capture The Flag 1" So your client winds up connecting to "Capture The Flag 1" but the RoomMapper will be able to foward future requests of "jellitans awesome ctf" to "Capture The Flag 1"

Or another approach could be just simply registering a handler upon request. You'll probably run into some issues if you're using a presence. Not 100% sure. But I'm 95% the first method would work well regardless of using a presence or not as long as you have the RoomMapper keep track of connected players correctly.

posted in Questions & Help • 14 Dec 2018, 18:28
RE: How to generate unique 6 digit game code?

If you're talking about the custom game code? That's what you're "RoomMapper" room would basically do.

var ctfRoomInUseLookup = {};
var ctfRoomName = "ctfRoom";
// register Capture the flag rooms
for(var i = 0; i < 10; i++) {
    uniqueCtfRoomName = ctfRoomName + i;
    ctfRoomInUseLookup[uniqueCtfRoomName] = false;
    gameServer.register(uniqueCtfRoomName, CTF)
}

gameServer.register("RoomMapper", RoomMapper, { ctfRoomInUseLookup })

then inside your RoomMapper class you can keep track of which rooms are in use then you can also have another lookup like

// might need to get from redis or database for each new connection if room doesnt stay persisted
customIdsToRoomId = {
    "custom1": "ctfRoom0",
    "cool_kid_room": "ctfRoom1",
}

if someone wants to create a room.. theres a lot of ways to do this just going to write some pseudo code real quick

requestCreateRoom(roomType, uniqueId) {
    // room doesnt already exist for unique custom id
    if(!(uniqueId in customIdsToRoomId)) {
         // find room not in use
        for(var key in ctfRoomInUseLookup) {
            if(!(ctfRoomInUseLookup[key]) {
                 // found room that isnt being used
                    client.send({ msg: "CREATE_CUSTOM_GRANTED", roomId: key })
                    ctfRoomInUseLookup[key] = true;
                    customIdsToRoomId[uniqueId] = key;
           }
   }

}

then basically you can do something like when someone requests to connect to a custom id

if("custom1" in customIdsToRoomId) {
    client.send({ msg: "FOUND_ROOM_REQUESTED", roomId: customIdsToRoomId["custom1"]
}

Youd need to add logic to manage what happens when a player leaves a room and stuff. Actually on second thought it wouldnt be able to work EXACTLY like my code... since rooms dont persist when theres no more users connected so youd basically have to hack "RoomMapper" room to stay persistent somehow or youd have to use Redis or some sort of database to get and edit the look up maps.

Hope that makes some sense. I really need to get back to my own code now lol

edit:Formatting

posted in Questions & Help • 14 Dec 2018, 19:00

© 2023 Endel Dreyer