.dev

Protocol2 min read

Node, Python & Rust

Protocol libraries for servers that are not written in Java.

For servers and proxies that are not written in Java, Teho ships protocol libraries for Node.js, Python and Rust. They speak exactly the same frames as the Java SDK, so you can use every feature without a plugin.

LanguagePackageNeeds
Node.js@tehoclient/server-api, with TypeScript typesNode 16+
Pythonteho-apiPython 3.8+
Rustteho-api crate, no dependenciesRust 1.73+

Install

All three are hosted on Teho's own package repository, repo.tehoclient.dev, so there is nothing to sign up for. Package versions match the Java SDK.

Shell
npm install https://repo.tehoclient.dev/packages/npm/tehoclient-server-api-1.0.0.tgz

What each library gives you

  • encode and decode for all 108 framed messages and their nested types, with the same limits as the Java SDK: 32,000-byte frames, 1,024-byte strings (8,192 for grants and certificates) and capped list lengths.
  • frames and a Reassembler, which split messages over 32,000 bytes into Chunk frames and join them back: 4 MB per stream, at most 8 open streams, 30 seconds before a stream times out.
  • welcome, which answers a Hello by enabling the capabilities both sides support.
  • A Session that runs the handshake, drops messages for capabilities the player did not enable, reassembles chunks and matches replies to requests.

Using a session

  1. Register the teho:api plugin channel with your server software.
  2. Feed every incoming payload on that channel to session.receive(frame). The session answers Hello with Welcome by itself.
  3. Send features with session.send(...). Each frame you are handed goes out as one plugin message.
JavaScript
const teho = require('@tehoclient/server-api')

const session = new teho.Session({
  serverName: 'Skyline',
  send: (frame) => player.sendPluginMessage(teho.CHANNEL, frame),
})

player.onPluginMessage(teho.CHANNEL, (frame) => session.receive(frame))

session.send('Notify', { id: 'welcome', title: 'Welcome', body: 'Good luck!', accent: 0x4DA9FF, durationMs: 4000 })

const info = await session.request('InfoRequest', { fields: ['input'], reason: 'Matchmaking' })

Private capabilities

npc:1, statue:1, branding:1 and showcase:1 still need a private grant. Pass it as the grant option or field on the session, and the client checks it exactly as it does for the Java SDK.

One corpus, four languages

The message code is generated from teho_api.proto and the Java message classes, which hold the type ids and limits:

Shell
python generate.py

The generator also writes a shared corpus with one populated frame per message. Java's LightweightCorpusTest and each library's own tests check that every implementation encodes the corpus to the same bytes.

Shell
cd node && npm test
Shell
cd python && python -m unittest discover -s tests
Shell
cd rust && cargo test