Skip to main content

TCPR library for King Arthur's Gold

Project description

kagtcprlib · AUR Build Status

A TCPR library for King Arthur's Gold, aiming to provide a simple solution for writing interesting TCPR mods.

  • Supports async connections to multiple KAG servers.

The basic design of the library is that the user creates a Client instance:

client = Client(nickname="playercount", host="localhost", port=50301, rcon_password="ilovetrenchrun")

Then adds some handlers to it:

client.add_handler(PingHandler())

Then calls the client's connect method:

client.connect()

Whenever the client receives a line of text from KAG, all matching handlers will be run. If any handler returns some text, it will be sent back to KAG as an RCON command.

What each handler does is totally up to the user. This could involve creating entries in a database, posting to a web API, or just logging to a file.

Example

import logging
import kagtcprlib
from kagtcprlib.handlers import BaseHandler

class PingHandler(BaseHandler):
    """Respond to 'ping' from KAG with code to print 'pong' in chat.
    """
    def handle(self, client_nickname, timestamp, content):
        if content == "ping":
            logging.info("Got ping from %s, sending pong.", client_nickname)
            return "getNet().server_SendMsg('pong');"


if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO)
    client = kagtcprlib.Client(nickname="playercount", host="localhost", port=50301,
                               rcon_password="ilovetrenchrun")

    client.add_handler(PingHandler())
    client.connect_forever()

For more examples see the examples/ folder.

Contributing

You are welcome to contribute to this project.

Please ensure your feature branch is based on the master branch and is named like feature-foo-bar.

You must run pylint over your code and ensure it receives at least a score of 9.

Docs

https://benjamingorman.github.io/kagtcprlib/

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

kagtcprlib-0.2.1.tar.gz (244.1 kB view hashes)

Uploaded Source

Built Distribution

kagtcprlib-0.2.1-py3-none-any.whl (248.5 kB view hashes)

Uploaded Python 3

Supported by

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