Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
98 lines (68 sloc) 2.37 KB

Exec Service

Every multiplayer project needs to run the game code on the backend side. :doc:`game-master` perfectly does that task. But sometimes you don’t need that kind of complicity and just to want a simple script that players can connect to and do things here and there. In Javascript!

The service uses Git to host your code on, so you can setup a repository, put your javascript there, configure it on the service, and you’re all set.

.. seealso::
   :anthill-service-source:`Source Code <exec>`

Javascript support

EcmaScript 8 is supported.

Hello, world

function hello_world(args) {
    return "Hello, world!";

hello_world.allow_call = true;

As simple at it looks like. Then you can call it:

POST /call/test/1.0/hello_world
> Hello, world!


Only the functions that defined allow_call = true can be called by the client, thus declaring some functios “API ready”, others private.


Calling simple function is not always enough. Often the state between the calls has to be saved, wrapping the whole call sequence in a “session”. That’s what the Sessions are for.

function SessionHelloWorld(args)
    // this function is called upon session initialization = "unknown";

SessionHelloWorld.allow_session = true;

SessionHelloWorld.prototype.my_name_is = function(args)
{ = args["name"];
    return "Gotcha!"

SessionHelloWorld.prototype.hello = function(args)
    return "Hello, " + + "!";

Sessions are run by WebSockets, with JSON-RPC as transport protocol.

WebSocket /session/test/1.0/SessionHelloWorld

> Hello, unknown!
call("my_name_is", {"name": "world"})
> Gotcha!
> Hello, world!


Only constructor functions (SessionHelloWorld from example above) that define allow_session = true will be allowed to open session on. Also, methods that start with underscore are not allowed to call:

SessionHelloWorld.prototype._internal_method = function(args)
    return "I am so internal";


.. toctree::
   :maxdepth: 1

You can’t perform that action at this time.