Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • EventEmitter
    • Mage

Index

Properties

MageError

MageError: MageError

auth

auth: object

auth module

The auth module can be used to register and authenticate users

memberof

Mage

Type declaration

cli

cli: object

Command-line interface API

The cli property is a library that lets you extend and boot up the command-line argument parser.

type

{MageCore}

memberof

Mage

Type declaration

  • program: CommanderStatic

    Commander object which allows you to extend the provided CLI

    var cli = require('mage').cli;
    cli.program.option('--clown', 'Enables clown mode');
    cli.run();
    

    With the previous code, you should obtain the following:

    $ ./game --verbose --help
    
      Usage: game [options] [command]
    ...
      Options:
    ...
      --clown                Enables clown mode
    
  • run: function
    • run(): void
    • Parse the process arguments obtained via process.argv

      Returns void

core

core: IMageCore

Core modules

type

{MageCore}

memberof

Mage

logger

logger: Logger

Logger module

The logger module should be used to capture log entries; it can be configured to send logs to one or multiple logging backend (syslog, file, etc).

See https://mage.github.io/mage/#logging for more details.

type

{Logger}

memberof

Mage

magePackage

magePackage: any

Contains information from MAGE’s package.json file:

  • name: “mage”
  • version: The version of MAGE.
  • path: The path to MAGE on disk.
  • package: The parsed contents of MAGE’s package.json file.
type

{any}

memberof

Mage

rootPackage

rootPackage: any

Contains information from your project's package.json file:

  • name: “mage”
  • version: The version of MAGE.
  • path: The path to MAGE on disk.
  • package: The parsed contents of MAGE’s package.json file.
type

{any}

memberof

Mage

session

session: object

Session module

The session module can be used to create a session object, which will then normally be accessible through the state.session key on the state object received through user commands.

memberof

Mage

Type declaration

  • reassign: function
    • reassign(state: IState, fromActorId: string, toActorId: string, callback: Function): void
    • Transfer a session and its content to another user

      Mostly used for testing purposes.

      Parameters

      • state: IState
      • fromActorId: string
      • toActorId: string
      • callback: Function

      Returns void

  • register: function
    • register(state: IState, actorId: string, language: string, meta: any): void
    • Register a new session

      Parameters

      • state: IState
      • actorId: string
      • language: string
      • meta: any

      Returns void

task

task: object

The current task to execute. Internal value.

memberof

Mage

Type declaration

  • name: string

    The name of the task to execute

    type

    {string}

  • options: any

    Options passed to the task

    type

    {*}

time

time: object

Time module

The time module can be used to affect how time is perceived from the MAGE process' perspective. This is mostly useful when either writing tests (like unit tests) or simulations (run an instance of your game server faster to, for instance, play a full week of your game within a few hours).

See https://mage.github.io/mage/#time-manipulation for more details.

memberof

Mage

Type declaration

  • bend: function
    • bend(offset: number, accelerationFactor: number, startAt: number): void
    • Change the current time, and how quickly time advances

      You may use the offset to specify how far back or forward in time you wish to go, and the acceleration factor to decide how fast (or slow) should time pass.

      The startAt attribute might be a bit confusing; in essence, the only time you should need to set it is when you wish to specify from which time in the past timestamps should be translated based on the acceleration factor. Therefore, unless you use an acceleration factor other than 1, setting this will have no effect.

      In short, you should almost never have to use the startAt attribute.

      See https://github.com/Wizcorp/timer.js/blob/master/index.js#L37 for more details.

      Parameters

      • offset: number

        in milliseconds (default: 0)

      • accelerationFactor: number

        How fast should time move forward. (default: 1)

      • startAt: number

        From which point in time do we consider time to be accelerated (default: Date.now())

      Returns void

  • getConfig: function
    • Return the current time configuration (offset, acceleration factor and acceleration start time)

      Returns TimeConfig

  • msec: function
    • msec(): number
    • Get the current time according to MAGE, in milliseconds

      You can use this to instanciate Date objects:

      var date = Date(mage.time.msec());
      

      Returns number

  • sec: function
    • sec(): number
    • Get the current time according to MAGE, in seconds

      Returns number

  • translate: function
    • translate(timestamp: number, msecOut?: boolean): number
    • Translate a given timestamp

      Sometimes, you will need to take a given timestamp and calculate its relative representation according to MAGE time settings. In general, you will only need to use this when using mage.time.bend; however, using it when time is not bent will simply have no effect on the passed value.

      Parameters

      • timestamp: number

        The timestamp to translate

      • Optional msecOut: boolean

      Returns number

      The translated timestamp according to the current time rules enforced by mage.time.bend

  • unbend: function
    • unbend(): void
    • Remove the effect of mage.time.bend

      This effectively resets the clock to the current time.

      Returns void

version

version: string

The current version of MAGE

type

{string}

memberof

Mage

Optional workerId

workerId: number

The worker ID of the currently worker process

Will return false if the process is the master process, or if MAGE is running in single mode.

This differs from cluster.worker.id because it will remain consistent if restarted or reloaded.

Methods

addListener

  • addListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

addModulesPath

  • addModulesPath(path: string): void
  • Add a new lookup path when attempting to load modules

    memberof

    Mage

    Parameters

    • path: string

    Returns void

boot

  • boot(allback?: function): void
  • Boot the MAGE server

    You normally will not have to call this manually; the mage binary referred to in your project's package.json will call this for you.

    However, you will need to call this in cases where you wish to create your own binary entry point (when creating a debug console to run MAGE under special conditions, for instance).

    memberof

    Mage

    Parameters

    • Optional allback: function
        • (error: Error | null): void
        • Parameters

          • error: Error | null

          Returns void

    Returns void

emit

  • emit(event: string | symbol, ...args: any[]): boolean

eventNames

  • eventNames(): Array<string | symbol>

exit

  • exit(exitCode?: number, hard?: boolean): never
  • Shut down MAGE

    When setting hard to true, MAGE will not try to complete current I/O operations and exit immediately; you should avoid using hard unless there are no other options available to you.

    Note that this will behave similarly to process.exit; only the current process will be stopped, not the entire server. To stop the entire server, see mage.quit

    memberof

    Mage

    Parameters

    • Optional exitCode: number
    • Optional hard: boolean

    Returns never

getClientConfig

  • getClientConfig(appName: string, baseUrl: string): any
  • Retrieve a given app's configuration

    memberof

    Mage

    Parameters

    • appName: string
    • baseUrl: string

    Returns any

getMaxListeners

  • getMaxListeners(): number

getModulePath

  • getModulePath(name: string): string
  • Return the path from which a given module was loaded from

    memberof

    Mage

    Parameters

    • name: string

    Returns string

getRunState

  • getRunState(): "setup" | "running" | "quitting"
  • Return MAGE's current run state

    memberof

    Mage

    Returns "setup" | "running" | "quitting"

getTask

isCodeFileExtension

  • isCodeFileExtension(ext: string): boolean
  • Check if a file is considered like a source code file in MAGE

    Example:

    mage.isCodeFileExtension('.js');
    

    Parameters

    • ext: string

      File extension

    Returns boolean

    True if the extension is for a source code file

isDevelopmentMode

  • isDevelopmentMode(feature?: string): boolean
  • Verify if development mode is currently activated, or if a given development mode feature is activated

    memberof

    Mage

    Parameters

    • Optional feature: string

    Returns boolean

listModules

  • listModules(): string[]
  • List all loaded modules

    memberof

    Mage

    Returns string[]

listenerCount

  • listenerCount(type: string | symbol): number

listeners

  • listeners(event: string | symbol): Function[]

on

  • on(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

once

  • once(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependListener

  • prependListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependOnceListener

  • prependOnceListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

quit

  • quit(exitCode?: number, hard?: boolean): never
  • Quit MAGE

    This will stop ALL MAGE processes regardless of where it is called from. To stop only the local process (similarly to what process.exit would do, please see mage.exit)

    Parameters

    • Optional exitCode: number
    • Optional hard: boolean

    Returns never

rawListeners

  • rawListeners(event: string | symbol): Function[]

removeAllListeners

  • removeAllListeners(event?: string | symbol): this

removeListener

  • removeListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

require

  • require(packageName: string): any
  • Requiring MAGE's dependencies into games

    This should only be used to load the tomes module (when used).

    memberof

    Mage

    Parameters

    • packageName: string

    Returns any

setMaxListeners

  • setMaxListeners(n: number): this

setRunState

  • setRunState(state: "setup" | "running" | "quitting"): string
  • Set MAGE's current run state

    memberof

    Mage

    Parameters

    • state: "setup" | "running" | "quitting"

    Returns string

setTask

  • setTask(name: string, options: any): void
  • Set which MAGE task to execute.

    memberof

    Mage

    Parameters

    • name: string
    • options: any

    Returns void

setup

  • setup(cb?: function): Mage
  • Setup MAGE

    You should not need to call this manually unless you are trying to manually set up MAGE for some special use case.

    memberof

    Mage

    Parameters

    • Optional cb: function
        • (error: Error | null): void
        • Parameters

          • error: Error | null

          Returns void

    Returns Mage

setupModules

  • setupModules(cb: function): void
  • Setup MAGE modules.

    You should not need to call this manually unless you are trying to manually set up MAGE for some special use case.

    memberof

    Mage

    Parameters

    • cb: function
        • (error: Error | null): void
        • Parameters

          • error: Error | null

          Returns void

    Returns void

start

  • start(cb?: function): Mage
  • Start MAGE

    You should not need to call this manually unless you are trying to manually set up MAGE for some special use case.

    memberof

    Mage

    Parameters

    • Optional cb: function
        • (error: Error | null): void
        • Parameters

          • error: Error | null

          Returns void

    Returns Mage

useApplicationModules

  • useApplicationModules(): this
  • Tell MAGE to load all your application's modules

    MAGE will then load all modules found under your project's ./lib/modules folder.

    memberof

    Mage

    Returns this

useModules

  • useModules(moduleNames: string[]): this
  • Define which modules to load at runtime

    memberof

    Mage

    Parameters

    • moduleNames: string[]

    Returns this