A game server that runs in Node.js
JavaScript
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.

README.md

node-game-server

Build Status

A game server that works for at least one specific game, in Node. Provides a web interface, http api, and a game logic runner. Intended initially as a proof-of-concept, may evolve into something that's actually useful!

Requirements

Components

The game server handles logic by providing an interface between storage (redis) and game objects. Game objects can currently either be Maps or Players. All "active" game objects are kept in memory for easy direct access, but are persisted to redis at write time. See the documentation below for api methods available to these objects.

The web server is there to provide both a management interface to the game server and allow for a public api into the game.

Object API

Objects are run sandboxed and do not have direct access to server code or other objects. The world is exposed to them through the following api:

Players

Player objects can define handlers for several events:

  • onTick() - Called every second since the player was instantiated (or reloaded).
  • onCollision(player) - If the player object collides with another, this handler is called with the player hash of the colliding player.

Player objects can manipulate the world using these functions:

  • apiMove(x, y, z) - Moves the player to the given position, if the map rules allow for it.
  • apiGetPos() - Returns the player's current position as a hash with x, y, and z keys.

And get information about their world:

  • apiGetPlayersHere(callback) - Calls the function defined by callback with an array of players at the current player's position, excluding the current player.

Additionally, player objects can store/retrieve arbitrary data in a private key/value store:

  • apiStore(key, value) - value can be any data type.
  • apiGet(key, callback) - Calls the function defined by callback with the value associated with key, or undefined if there is no data for key.

There are utility functions:

  • log(msg) - Echoes msg to node's console log. For debugging.

Maps

  • apiGetMapBounds - Returns the bounds of the current map as a hash with width, height, and depth keys.

TODO

  • Authentication for the web server
  • Lots more event handlers and api methods!