Skip to main content

pyOpenTTDAdmin

pyOpenTTDAdmin is a Python library designed to facilitate communication with OpenTTD's Admin port. OpenTTD (Open Transport Tycoon Deluxe) is an open-source simulation game where players manage a transport company.

This library enables developers to interact with an OpenTTD server programmatically, allowing them to perform various administrative tasks and receive real-time updates from the game server.

Features

  • Authentication: Authenticate with an OpenTTD server using the provided password.
  • Packet Handling: Receive and parse packets from the server, allowing developers to react to different events and messages.
  • Sending Commands: Send commands to the OpenTTD server, such as chat messages, remote console commands, and more.
  • Subscription to Updates: Subscribe to various types of updates from the server, including chat messages, client information, company data, and more.
  • Flexible Usage: The library provides a flexible framework for building custom applications that interact with OpenTTD servers.

Usage

The basic usage of pyOpenTTDAdmin involves creating an instance of the Admin class, subscribing to updates from the server, and handling the received packets.

Example code for an echo bot can be found here:

from pyopenttdadmin import Admin, AdminUpdateType, openttdpacket

# Set the IP address and port number for connection
ip_address = "127.0.0.1"
port_number = 3977

# Instantiate the Admin class and establish connection to the server
admin = Admin(ip = ip_address, port = port_number)
admin.login("pyOpenTTDAdmin", password = "toor") # assuming the password is "toor"

# Subscribe to receive chat updates
admin.subscribe(AdminUpdateType.CHAT)

# Print chat packets
@admin.add_handler(openttdpacket.ChatPacket)
def chat_packet(admin: Admin, packet: openttdpacket.ChatPacket):
    print(f'ID: {packet.id} Message: {packet.message}')

# Echo chat
@admin.add_handler(openttdpacket.ChatPacket)
def echo_chat(admin: Admin, packet: openttdpacket.ChatPacket):
    admin.send_global(packet.message)

# Run admin
admin.run()

pyOpenTTDAdmin also support async/await syntax:

import asyncio
from aiopyopenttdadmin import Admin, AdminUpdateType, openttdpacket

# Set the IP address and port number for connection
ip_address = "127.0.0.1"
port_number = 3977

async def main():
    # Instantiate the Admin class and establish connection to the server
    admin = Admin(ip = ip_address, port = port_number)
    await admin.login("pyOpenTTDAdmin", password = "toor") # assuming the password is "toor"

    # Subscribe to receive chat updates
    await admin.subscribe(AdminUpdateType.CHAT)

    # Print chat packets
    @admin.add_handler(openttdpacket.ChatPacket)
    async def chat_packet(admin: Admin, packet: openttdpacket.ChatPacket):
        print(f'ID: {packet.id} Message: {packet.message}')

    # Echo chat
    @admin.add_handler(openttdpacket.ChatPacket)
    async def echo_chat(admin: Admin, packet: openttdpacket.ChatPacket):
        await admin.send_global(packet.message)

    # Run admin
    print("running")
    await admin.run()


if __name__ == "__main__":
    asyncio.run(main())

Available Subscribe Types and Packet Types

The following are the available subscribe types that can be used with the library:

  • DATE: Updates about the date of the game.
  • CLIENT_INFO: Updates about the information of clients.
  • COMPANY_INFO: Updates about the generic information of companies.
  • COMPANY_ECONOMY: Updates about the economy of companies.
  • COMPANY_STATS: Updates about the statistics of companies.
  • CHAT: The admin would like to have chat messages.
  • CONSOLE: The admin would like to have console messages.
  • CMD_NAMES: The admin would like a list of all DoCommand names.
  • CMD_LOGGING: The admin would like to have DoCommand information.
  • GAMESCRIPT: The admin would like to have gamescript messages.

Here you find a list of all the packets that can be received from the server:

  • Errorpacket: The server tells the admin an error has occurred.
  • AdminJoinPacket: The admin announces and authenticates itself to the server.
  • ProtocolPacket: The server tells the admin its protocol version.
  • WelcomePacket: The server welcomes the admin to a game.
  • NewGamePacket: The server tells the admin its going to start a new game.
  • ShutdownPacket: The server tells the admin its shutting down.
  • DatePacket: The server tells the admin what the current game date is.
  • ClientJoinPacket: The server tells the admin that a client has joined.
  • ClientInfoPacket: The server gives the admin information about a client.
  • ClientUpdatePacket: The server gives the admin an information update on a client.
  • ClientQuitPacket: The server tells the admin that a client quit.
  • ClientErrorPacket: The server tells the admin that a client caused an error.
  • CompanyNewPacket: The server tells the admin that a new company has started.
  • CompanyInfoPacket: The server gives the admin information about a company.
  • CompanyUpdatePacket: The server gives the admin an information update on a company.
  • CompanyRemovePacket: The server tells the admin that a company has been removed.
  • CompanyEconomyPacket: The server gives the admin some economy related company information.
  • CompanyStatsPacket: The server gives the admin some statistics about a company.
  • ChatPacket: The server received a chat message and relays it.
  • RconEndPacket: The server indicates that the remote console command has completed.
  • RconPacket: The server's reply to a remote console command.
  • ConsolePacket: The server gives the admin the data that got printed to its console.
  • GamescriptPacket: The server gives the admin information from the GameScript in JSON.
  • CmdNamesPacket: The server sends out the names of the DoCommands to the admins.
  • CmdLoggingPacket: The server gives the admin copies of incoming command packets.
  • AdminRconPacket: The admin sends a remote console command.
  • AdminChatPacket: The admin sends a chat message to be distributed.
  • AdminSubscribePacket: The admin tells the server the update frequency of a particular piece of information.

Contributing

Contributions to pyOpenTTDAdmin are welcome! If you find any issues or have ideas for improvements, feel free to open an issue or submit a pull request on GitHub.

Metadata

Release files for pyOpenTTDAdmin 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyOpenTTDAdmin 1.0.3
File Size Uploaded
pyopenttdadmin-1.0.3.tar.gz 12.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyOpenTTDAdmin 1.0.3
File Interpreter ABI Platform
pyopenttdadmin-1.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 27.5 kB

Release files / pyopenttdadmin-1.0.3.tar.gz

Download URL pyopenttdadmin-1.0.3.tar.gz
Size 12.4 kB
Tags Source
SHA-256 checksum
How to use checksums
be84f57f715414a57a13f4f7d442bcbc18689051899eec09130da50425a24634
BLAKE2b-256 checksum
How to use checksums
9174313613dd1937d37bbca9f9cedb4f1cda780ea0dc0f27721a04e3481eb4fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.9

Release files / pyopenttdadmin-1.0.3-py3-none-any.whl

Download URL pyopenttdadmin-1.0.3-py3-none-any.whl
Size 15.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b1d1e8b57e20865f0c248acdbba6c09732e35850d2100d2af8c300465ea9f573
BLAKE2b-256 checksum
How to use checksums
a14b205d5bcf384df9c3551fe7829c913434b319ca609bee338cbd3ea3a4a6da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.9

Release history Release notifications | RSS feed

1.1.0

73 release files

1.0.4

2 release files

This release

1.0.3 This release

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page