Git Product home page Git Product logo

command's Introduction



Discussion forum

Multiplayer Framework for Node.js.
View documentation

Colyseus is an Authoritative Multiplayer Framework for Node.js, with SDKs available for the Web, Unity, Defold, Haxe, Cocos and Construct3. (See official SDKs)

The project focuses on providing synchronizable data structures for realtime and turn-based games, matchmaking, and ease of usage both on the server-side and client-side.

The mission of the framework is to be a standard netcode & matchmaking solution for any kind of project you can think of!

Key features:

  • WebSocket-based communication
  • Simple API in the server-side and client-side.
  • Automatic state synchronization from server-to-client (delta compressed)
  • Matchmaking clients into game rooms/sessions
  • Scale vertically or horizontally

See public roadmap for future plans.

๐Ÿš€ Quickstart

Create a bare-bones Colyseus server by using npm create colyseus-app@latest:

npm create colyseus-app@latest my-colyseus-server
cd my-colyseus-server
npm start

Sponsors

The sustainability of the project relies on Colyseus Cloud subscriptions and sponsorships. If you are not using Colyseus Cloud, please consider sponsoring the project ๐Ÿ’–

Contributors โœจ

Thanks goes to these wonderful people (emoji key):


Aymeric Chauvin

๐Ÿ’ฌ ๐Ÿ’ก

Brian Hay

๐Ÿ–‹

Damian A. Pastorini

๐Ÿ’ฌ ๐Ÿ“– ๐Ÿ›

Darek Greenly

๐Ÿ’ฌ ๐Ÿ› ๐Ÿ’ป

David Rydwanski

๐Ÿ’ฌ ๐Ÿ’ป

Dr. Burton

๐Ÿง‘โ€๐Ÿซ

Endel Dreyer

๐Ÿ’ป ๐Ÿ“– ๐Ÿ’ก

Enriqueto

๐Ÿ’ผ

Fazri Zubair

๐Ÿ’ผ

Federico

๐Ÿ› ๐Ÿ’ป

James Jacoby

๐Ÿ’ฌ ๐Ÿ’ก ๐Ÿ–‹

Jonas Voland

๐Ÿ’ฌ ๐Ÿ› ๐Ÿ’ป ๐Ÿค” ๐Ÿ’ก

Kyle J. Kemp

๐Ÿ’ฌ ๐Ÿ› ๐Ÿ’ป ๐Ÿค”

Luke Wood

๐Ÿ’ฌ ๐Ÿ› ๐Ÿ’ป

Milad Doorbash

๐Ÿ› ๐Ÿ’ป

Nikita Borisov

๐Ÿ› ๐Ÿ’ป ๐Ÿ’ผ ๐Ÿค”

Phil Harvey

๐Ÿ“–

Sergey

๐Ÿ› ๐Ÿ’ป

Tom

๐Ÿ’ฌ ๐Ÿ› ๐Ÿค”

Tommy Leung

๐Ÿง‘โ€๐Ÿซ

digimbyte

๐Ÿ“–

This project follows the all-contributors specification. Contributions of any kind are welcome!

Contributing

We encourage you to contribute to Colyseus! Please check out the Contributing guide for guidelines about how to proceed. Join us!

Everyone interacting in Colyseus and its sub-projects' codebases, issue trackers and chat rooms is expected to follow the code of conduct.

License

MIT

command's People

Contributors

antn9x avatar avatus avatar endel avatar ilyavorozhbit avatar wenish avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

command's Issues

Validate payload data types

The current typing of the optional validate method of commands assumes that the payload data is already checked for correct data types. As incoming messages by clients must never be trusted without data type checking, there should be a canonical way of doing so, e.g.

  • have the dispatcher call validate before setting the payload and have validate receive the payload as unknown data type. If the method returns true, the data can be trusted and is of the specified payload data type.
  • add a separate (optional) method to commands for checking the payload data, that is called by the dispatcher before setting the payload.

Either way the interface of Dispatcher.dispatch should then allow to pass unknown data.

Command Generic Room Type does not infer State Type

Library extends the Command class with Generic Types of <Room, Payload>
However it should be <Room, Payload>

Solution:

export abstract class Command<
  R extends Room<any, any> = Room,
  Payload = unknown,
> {
  payload: Payload;

PR coming soon

Run multiple commands at the same time

First of all, thank you for this library! It has been a blast so far ๐Ÿฅ‡

I have a use case where I want to dispatch two (or more) commands after a command finished. They're all promises.

Example;

export class OnJoinCommand extends Command<YourState, { sessionId: string }> {
  execute({ sessionId }) {
    this.state.players[sessionId] = new Player();
    return [
      new FirstCommand().setPayload({ sessionId }),
      new SecondCommand().setPayload({ sessionId })
    ];
  }
}

In that case SecondCommand would execute after FirstCommand finished, how would I execute both at the same time?

dispatch is not awaitable

The dispatch method does not return the result unless it actually has more commands to run."

Thus, it returns undefined if our Command is asynchronous.

We don't normally await the results, but we try to when the player exits/leaves the room, so that we ensure all commands have completed before we save the player state.

But if the promise is not returned, this isn't possible

Feature Request: Possibility to have a return value in the execute function

Imagine following scenario:
Creating a Unit Entity
After that create a Player Entity which can control this unit

onJoin(client: Client, options: any, auth: any) {
    const unit = this.dispatcher.dispatch(new UnitAddCommand(),{})
    this.dispatcher.dispatch(new PlayerAddCommand(), {
        sessionId: client.sessionId,
        unitId: unit.id
    });
}

So i would like to create a command like this:

export class UnitAddCommand extends Command<RoomState, UnitAddPayload> {
   execute(payload: UnitAddPayload): UnitState {
       const unit = new UnitState()
       this.state.units.set(unit.id, unit)
       return unit
   }
}

This would be a really nice feature IMO.

Feel free to ask questions.

Should I create dispatcher for every player in the room ?

Dispatcher will forcus cmds to execute in a queue. If I create single dispatcher for one room, dose it probabily block other players' cmds handling when one player's cmd awaiting ? So I am considering if it's necessary create dispatcher for every player in the room.

If all cmds are sync, is there no difference between single dispatcher mode and one-player-one-dispatcher mode, because of Node.js's single thread mechanism?

How should I judge how many dispatcher instance to create for one room

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.