Skip to main content

Sending Topic packets to BYOND servers, and receive responses

Project description

byond.topic

A python module for sending packets to BYOND servers, for calling /world/Topic() and receiving a response. In the same vein as BYOND.TopicSender, but in python!

Installation

Open the directory, and pip install .!

Exports

send(address, port, query)

Sends a Topic() packet to the specified server, and (ideally) returns the response from the server.

  • address: The address (IP, or DNS) of the target DreamDaemon instance to send the Topic() packet to.
  • port: Port that the DreamDaemon instance is serving the world on
  • query: Query string to be sent. This is an urlencoded series of keys (and, where required, values.) (...Yeah. it really is just an url query string.)

Returns: A tuple containing the response-type, and the response from the server.

If the response-type is TOPIC_RESPONSE_STRING, the response will be a dict of key-value pairs, parsed out from the URL query-format string returned from the server.

The actual data returned from the server depends on the codebase that the server is running, and the query that was sent.

If the response-type is TOPIC_RESPONSE_FLOAT, the response will be a floating point numeric value.

(send automatically opens a socket, transmits the packet, receives the reply, and then closes the socket again.)

queryStatus(address, port)

Sends a Topic() packet to the specified server, querying the ?status endpoint. This returns a string of JSON, or None for an invalid response.

queryPlayerCount(address, port)

Sends a Topic() packet to the specified server, querying the ?playing endpoint. This should return the number of currently-connected players, or None for an invalid response.

Constants

  • TOPIC_PACKET_ID: The signature that identifies a Topic() packet.
  • TOPIC_RESPONSE_STRING: Response-type: string
  • TOPIC_RESPONSE_FLOAT: Response-type: float/numeric
  • MALF_PACKET_ID: Packet-id that identifies that the server is unhappy with the request you just sent.

Examples

Requesting World Status

import byond.topic as Topic

responseType, responseData = Topic.send("localhost", 26200, '?status')
if(responseType == Topic.TOPIC_RESPONSE_STRING):
    print(f"We're currently playing a {responseData['mode'][0]} round on {responseData['map_name'][0]}, with {responseData['players'][0]} players!")

(The values available in your status response data depend on the codebase you're querying. Try it and see, first!)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

byond_topic-0.1.2.tar.gz (4.6 kB view details)

Uploaded Source

File details

Details for the file byond_topic-0.1.2.tar.gz.

File metadata

  • Download URL: byond_topic-0.1.2.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for byond_topic-0.1.2.tar.gz
Algorithm Hash digest
SHA256 9eee27a4d3d3b6804cb91dc6fc41e0d3a5fb009aa0cd5b07392d5a901f66acb0
MD5 6aba9a892130ab48a7715bbdc2f5b4b9
BLAKE2b-256 abf986180e619a4bb2d9784f263ef5b68dc9f06c2cab5f581194878cf0b33913

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page