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
V

visgotti

@visgotti

Chat Follow Unfollow
3
Reputation
11
Posts
2.0k
Profile views
1
Followers
1
Following
Joined 18 Sept 2018, 13:40 Last Online 1 Jan 2019, 21:47

  • Profile
  • More
    • Continue chat with visgotti
    • Flag Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups
visgotti Follow

Posts made by visgotti

RE: Can't run basic examples.

@ianbellomy maybe it didn't bundle colyseus.js for whatever reason.. you can just grab it here

https://github.com/gamestdio/colyseus.js/blob/master/dist/colyseus.js

put it in a lib folder or anywhere and make sure you import it in the html

posted in Questions & Help • 16 Dec 2018, 01:51
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
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
Have multiple rooms live and be managed inside a room?

Basically I want to have a master server that manages connections with clients and then relays messages from the client to area servers, and then vice versa. I want to do something like have an array of area rooms my master server is connected to and then relay state updates to clients based on which area state was updated.. Has anyone accomplished anything like this with or without hacks?

posted in Questions & Help • 4 Dec 2018, 19:55
RE: Using multiple rooms to support one large map?

@endel Thank you!! and yes definitely can't wait till I get to show off what I've been building :P This framework is awesome. I was using pomelo before this and I can say for sure working with colyseus has been a way better experience. Speed, complexity, documentation, etc all trump it.

Amazing work. Thank you again for your efforts in building such an awesome framework.

posted in Questions & Help • 21 Sept 2018, 23:22
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: Using multiple rooms to support one large map?

@endel I see. So there's no way to have a room assigned to a process and have another one assigned to another process? I'm guessing Colyseus will just automatically balance out traffic between all the workers?

posted in Questions & Help • 21 Sept 2018, 22:51
RE: Using multiple rooms to support one large map?

When I try joining game1 just once on my client my requestJoin logs out

requesting to join
This process is your pid 8739
requesting to join
This process is your pid 8739

posted in Questions & Help • 21 Sept 2018, 03:59
RE: Using multiple rooms to support one large map?
if(cluster.isMaster) {
    const cpus = os.cpus().length;
    for (let i = 0; i < 2; ++i) {
        cluster.fork();
    }
} else {
    const gameServer = new colyseus.Server({
        server: http.createServer(),
        presence: new colyseus.MemsharedPresence()
    });

    const id = cluster.worker.id;
    gameServer.register("game" + id, Game); // should be able to join game1, game2, etc from client
    gameServer.listen(8081);
}

When I try to run this I can connect to game1 but it says the game2 handler does not exist.

Do I need to be listening on a different port? I want the client to be able to join in and out of rooms so creating a new connection seems overkill.. I feel like it should be working without that. Any idea how to fix this problem?

posted in Questions & Help • 21 Sept 2018, 03:30
Using multiple rooms to support one large map?

Hi before trying to implement this I want to get some feedback about this design approach.

Basically I want to have a large map, with the possibility of 1000+ players on it. But to save bandwidth I want to section the map off into its own rooms, possibly having each room living on a different process. And then each room would have logic that tells the client when they need to connect to another room, dynamically leaving/joining rooms as needed.

Is this the correct approach to accomplish this?

posted in Questions & Help • 20 Sept 2018, 15:14

© 2023 Endel Dreyer