Skip to content

Search

Documentation

gamend

The Gamend backend: session, REST API and realtime socket. Each call returns an id to await, answering a map whose kind is an EVENT_ constant; what a…

On this page

The Gamend backend: session, REST API and realtime socket. Each call returns an id to await, answering a map whose kind is an EVENT_* constant; what a socket says also reaches the node connect names, on its on_gamend_event (or on_event).

20 functions, 9 constants. Scripts reach it as gamend::.

Functions

Argument kinds are the script values a call passes: node is a node handle, any a table or value of any kind, fn a callback.

function acts on what it does
activity() -> [gamend::Entry] — The last calls and socket messages, newest first, as { seq, request, kind, what, status, ms, args, reply }, seq counting every row ever kept; ms is nil while a call waits, and only the newest fifty keep args and reply. An observer: never simulate from it.
call_hook(int, string, string, any) -> int — Call a server plugin's function over the socket; the reply's response holds data or error.
clear_activity() — Forget the calls and messages activity holds.
close(int) -> bool — Shut the socket down; false when the connection was already gone.
configure(str?) -> string — Point the plugin at another server and answer its url; with none, the one server answers. The first call that reaches a server does this on its own.
connect(Node?, events::ListenOptions?) -> int — Open the realtime socket and return the id join, push, leave, call_hook and close take, which task.wait resumes on with the open or error event. A dropped connection comes back on its own: the handler hears reconnecting before each try, then reopened once its topics are joined again, or error when it gives up.
connection() -> gamend::Connection — The configured url, who is signed in (user_id, username), and each socket as { socket, open, topics, reason }.
interrupt(int) -> bool — Cut the connection as a network failure would, to try a game's reconnect path: the socket reports reconnecting, then reopened. False when it is already gone.
join(int, string, any) -> int — Subscribe the socket to a topic and return the id the server's reply answers.
leave(int, string) -> int — Unsubscribe the socket from a topic, returning the id the reply answers.
login(gamend::Credentials) -> int — Open a session from a device_id, or an email and password, and return the id its login result answers.
push(int, string, string, any) -> int — Send an event and its payload to a topic on the socket, returning the id the reply answers.
refuse(string) -> int — Send nothing, and return an id whose error result carries the message: what a wrapper over rest answers for a call it will not make, so an await on it still resumes.
register(gamend::Credentials) -> int — Make an account from an email and a password (and a username, generated when left out) and open its session, as login does; its result is a login one. The server mails the address its confirmation link.
reply(int) -> any — What a call answered, as its event map, once it has; nil while it waits. The newest sixty-four are kept, so a drawing loop can issue a call and read it back on a later frame.
rest(string, string, any) -> int — Call a path on the configured server over HTTP, and return the id whose result carries the status and the decoded body. The body is the JSON the path takes, or left out for none.
restore(gamend::Session?) -> bool — Sign in from a session a previous run kept, as session answers it, without asking the server; nil signs out here. False when there is no server to sign in to, or the map carries no access_token.
run_id() -> string — This run's id: every call sends it as x-gamend-session and the socket as client_session, so the server files a run's lines together. The log shipper names its run with it.
server() -> gamend::Server — The server this run talks to until a script names another: { name, url, production, local, plugin } from [gamend], name being production or local.
session() -> gamend::Session? — The signed-in session as { user_id, username, display_name, access_token, refresh_token, expires_in, expires_at }, expires_at read from the token itself; nil when nobody is signed in.

Constants

name value
EVENT_CLOSED "closed"
EVENT_ERROR "error"
EVENT_LOGIN "login"
EVENT_MESSAGE "message"
EVENT_OPEN "open"
EVENT_RECONNECTING "reconnecting"
EVENT_REOPENED "reopened"
EVENT_REPLY "reply"
EVENT_REST "rest"

Are you sure?