-
Notifications
You must be signed in to change notification settings - Fork 8
Client
The Client
class represents a single connection from a user client. It can be put into a ClientManager instance, and is the primary way to send data to and receive data from remote players.
Create a new client instance. This is almost never necessary to call manually, as the Server will pass instantiated Client
instances into its callback when a new user connects.
Send a command object to the client over the network. If command
is defined, it will be automatically included in the command object that is sent over the network. Otherwise, you can just pass .send
a fully constructed command object to send:
client.send('message', {content: 'hello world'});
client.send({command: 'message', content: 'hello world'});
Save data to this client instance. This data exists on the server only and is not sent to the client. Use this to store information locally about the client.
Gets data stored with .set
.
Registers an event handler on the underlying net.Socket object in this client.
Specify a callback function to pass any data received from this client into. This is primarily used by ClientManager
instances, but you can specify extra handlers manually.
Register a function to run when this instance receives a command object. The function will be passed the the command object.
client.addCommandListener('register', function(client, data) {
console.log(client.clientId + ' has registered');
});
Removes the given function that has been registered as a command listener.
Turn on or off Tick Mode for this Client
. When tick mode is on, commands passed into .send()
will be stored until .tick()
is called and then sent together.
Sends all queued commands since the last time .tick
was called when tick mode is on for this client.
Converts data from a socket buffer into a JavaScript data object.