-
Notifications
You must be signed in to change notification settings - Fork 8
ClientManager
The ClientManager class is a wrapper for a collection of Client objects. It manages data coming in from client users, and can broadcast data back out. It is the main method of managing data across clients. Typically, you will want to pass Client objects into a ClientManager in the Server connection callback:
var server = new Server(function(client) {
gameManager.addClient(client);
});A ClientManager is usually used to handle Client objects in various states. For example, you may have a lobbyManager which handles users that are in a game lobby, or a gameManager that handles users in-game.
Creates a new client manager and prepares it for receiving clients.
Returns an array containing every Client instance in this ClientManager.
Returns the number of clients currently in this ClientManager.
Saves data to this instance to be used later.
Returns data saved with .set()
Adds the given Client to this ClientManager
Removes the client with the matching clientId from this instance and returns the client it removed, or undefined if no client was found with the given clientId
Destroys and removes the given client, firing a clientDropped event. Useful for non-graceful client drops.
Sends the given command to all Client objects in this instance. As with Client.send, specifying the command string is optional if the data object is a fully formed command object.
Runs the command handler for the given command data object with the given Client as the sending client. This function is meant for internal use, but could be used manually if you really wanted to.
Register a function to run when this instance receives a command object from a Client. The function will be passed the client that sent the command, and the command object.
clientManager.addCommandListener('chat', function(client, data) {
console.log(client.clientId + ' says: ' + data.message);
});Removes the given function that has been registered as a command listener.
Register a function to run for a given ClientManager event. See ClientManager events for a full list of events you can register on.
Enables or disables Tick Mode for this ClientManager. Disabling tick mode with this method will stop ticking.
Set the rate that this ClientManager should tick at when tick mode is enabled and running. newTickRate is the time in milliseconds between ticks. Default tick rate is 1000 / 60 (60 ticks per second)
Begins ticking once tick mode is enabled with .setTickMode
Stops ticking when ticking is running
Runs a tick for all Client objects in this ClientManager
Fires when a command is received from any client in this ClientManager. Passes the triggering client object and the data sent by that client (a command object) to the handler function.
Fires when a client is added into this ClientManager. Passes the added client to the handler.
Fires when a client closes its connection to the server. Passes an object with client and reason as keys to the handler. This is different from when a client is removed from this ClientManager, as it only fires when the client itself has ended the connection (typically meaning the player has quit the game)
Fires when a tick happens when Tick Mode is enabled and running.