Skip to content

ServerAPI

Greg edited this page Nov 27, 2013 · 21 revisions

cloak

Global cloak object.

cloak.configure(config)

Configuration options are given in ServerConfiguration.

Example:

cloak.configure({
  roomLife: 5000,
  messages: {
    foo: function(arg, user) {
      console.log('foo from ' + user.id);
    }
  }
});

cloak.run()

Runs the server. Call cloak.configure first!

Example:

cloak.run();

cloak.userCount()

Returns the number of users on the server. Includes users that are disconnected but have not been pruned per the reconnectWait setting.

cloak.getUser(id)

Get a user by id.

cloak.getUsers(json)

Returns an array of all users. If optional json argument is true, return array of {id: str, name: str} objects.

cloak.messageAll(name, arg)

The same as doing user.message(name, arg) for every connected user.

cloak.createRoom(name, size)

Create a room. Size is the maximum number of allowed members. If size is omitted, uses the server's defaultRoomSize setting.

cloak.getRoom(id)

Get a room by its ID.

cloak.getRooms(json)

Return an array of rooms. Does not include the lobby. If the optional json argument is true, instead return an array of objects that look like this:

{
  id: ..., 
  name: ...,
  userCount: ...,
  users: [{id: ..., username: ...}...],
  size: ...
}

cloak.roomCount()

Get the total number of non-lobby rooms.

cloak.getLobby()

Get the one and only lobby room.

cloak.createTimer(name, millis, descending)

Creates and returns a Timer object. name is required. millis defaults to 0, descending defaults to false.

cloak.stop()

Stop the game loop, stop accepting new connections, disconnect all users.