pyOpenTTDAdmin


NamepyOpenTTDAdmin JSON
Version 1.0.2 PyPI version JSON
download
home_pagehttps://github.com/liki-mc/pyOpenTTDAdmin/
SummaryPython library to communicate with OpenTTD Admin port
upload_time2024-08-17 00:28:03
maintainerNone
docs_urlNone
authorliki-mc
requires_pythonNone
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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:
```python
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:
```python
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.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/liki-mc/pyOpenTTDAdmin/",
    "name": "pyOpenTTDAdmin",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "liki-mc",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/c8/ca/059ba1919d1d702e04e33b4d557476f64d768907d2d3441f341ee5ca1149/pyopenttdadmin-1.0.2.tar.gz",
    "platform": null,
    "description": "# pyOpenTTDAdmin\r\n\r\npyOpenTTDAdmin 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.\r\n\r\nThis 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.\r\n\r\n## Features\r\n\r\n- **Authentication**: Authenticate with an OpenTTD server using the provided password.\r\n- **Packet Handling**: Receive and parse packets from the server, allowing developers to react to different events and messages.\r\n- **Sending Commands**: Send commands to the OpenTTD server, such as chat messages, remote console commands, and more.\r\n- **Subscription to Updates**: Subscribe to various types of updates from the server, including chat messages, client information, company data, and more.\r\n- **Flexible Usage**: The library provides a flexible framework for building custom applications that interact with OpenTTD servers.\r\n\r\n\r\n## Usage\r\nThe basic usage of pyOpenTTDAdmin involves creating an instance of the `Admin` class, subscribing to updates from the server, and handling the received packets.\r\n\r\nExample code for an echo bot can be found here:\r\n```python\r\nfrom pyopenttdadmin import Admin, AdminUpdateType, openttdpacket\r\n\r\n# Set the IP address and port number for connection\r\nip_address = \"127.0.0.1\"\r\nport_number = 3977\r\n\r\n# Instantiate the Admin class and establish connection to the server\r\nadmin = Admin(ip = ip_address, port = port_number)\r\nadmin.login(\"pyOpenTTDAdmin\", password = \"toor\") # assuming the password is \"toor\"\r\n\r\n# Subscribe to receive chat updates\r\nadmin.subscribe(AdminUpdateType.CHAT)\r\n\r\n# Print chat packets\r\n@admin.add_handler(openttdpacket.ChatPacket)\r\ndef chat_packet(admin: Admin, packet: openttdpacket.ChatPacket):\r\n    print(f'ID: {packet.id} Message: {packet.message}')\r\n\r\n# Echo chat\r\n@admin.add_handler(openttdpacket.ChatPacket)\r\ndef echo_chat(admin: Admin, packet: openttdpacket.ChatPacket):\r\n    admin.send_global(packet.message)\r\n\r\n# Run admin\r\nadmin.run()\r\n```\r\n\r\npyOpenTTDAdmin also support async/await syntax:\r\n```python\r\nimport asyncio\r\nfrom aiopyopenttdadmin import Admin, AdminUpdateType, openttdpacket\r\n\r\n# Set the IP address and port number for connection\r\nip_address = \"127.0.0.1\"\r\nport_number = 3977\r\n\r\nasync def main():\r\n    # Instantiate the Admin class and establish connection to the server\r\n    admin = Admin(ip = ip_address, port = port_number)\r\n    await admin.login(\"pyOpenTTDAdmin\", password = \"toor\") # assuming the password is \"toor\"\r\n\r\n    # Subscribe to receive chat updates\r\n    await admin.subscribe(AdminUpdateType.CHAT)\r\n\r\n    # Print chat packets\r\n    @admin.add_handler(openttdpacket.ChatPacket)\r\n    async def chat_packet(admin: Admin, packet: openttdpacket.ChatPacket):\r\n        print(f'ID: {packet.id} Message: {packet.message}')\r\n\r\n    # Echo chat\r\n    @admin.add_handler(openttdpacket.ChatPacket)\r\n    async def echo_chat(admin: Admin, packet: openttdpacket.ChatPacket):\r\n        await admin.send_global(packet.message)\r\n\r\n    # Run admin\r\n    print(\"running\")\r\n    await admin.run()\r\n\r\n\r\nif __name__ == \"__main__\":\r\n    asyncio.run(main())\r\n```\r\n\r\n## Available Subscribe Types and Packet Types\r\n\r\nThe following are the available subscribe types that can be used with the library:\r\n\r\n- DATE: Updates about the date of the game.\r\n- CLIENT_INFO: Updates about the information of clients.\r\n- COMPANY_INFO: Updates about the generic information of companies.\r\n- COMPANY_ECONOMY: Updates about the economy of companies.\r\n- COMPANY_STATS: Updates about the statistics of companies.\r\n- CHAT: The admin would like to have chat messages.\r\n- CONSOLE: The admin would like to have console messages.\r\n- CMD_NAMES: The admin would like a list of all DoCommand names.\r\n- CMD_LOGGING: The admin would like to have DoCommand information.\r\n- GAMESCRIPT: The admin would like to have gamescript messages.\r\n\r\nHere you find a list of all the packets that can be received from the server:\r\n\r\n- Errorpacket: The server tells the admin an error has occurred.\r\n- AdminJoinPacket: The admin announces and authenticates itself to the server.\r\n- ProtocolPacket: The server tells the admin its protocol version.\r\n- WelcomePacket: The server welcomes the admin to a game.\r\n- NewGamePacket: The server tells the admin its going to start a new game.\r\n- ShutdownPacket: The server tells the admin its shutting down.\r\n- DatePacket: The server tells the admin what the current game date is.\r\n- ClientJoinPacket: The server tells the admin that a client has joined.\r\n- ClientInfoPacket: The server gives the admin information about a client.\r\n- ClientUpdatePacket: The server gives the admin an information update on a client.\r\n- ClientQuitPacket: The server tells the admin that a client quit.\r\n- ClientErrorPacket: The server tells the admin that a client caused an error.\r\n- CompanyNewPacket: The server tells the admin that a new company has started.\r\n- CompanyInfoPacket: The server gives the admin information about a company.\r\n- CompanyUpdatePacket: The server gives the admin an information update on a company.\r\n- CompanyRemovePacket: The server tells the admin that a company has been removed.\r\n- CompanyEconomyPacket: The server gives the admin some economy related company information.\r\n- CompanyStatsPacket: The server gives the admin some statistics about a company.\r\n- ChatPacket: The server received a chat message and relays it.\r\n- RconEndPacket: The server indicates that the remote console command has completed.\r\n- RconPacket: The server's reply to a remote console command.\r\n- ConsolePacket: The server gives the admin the data that got printed to its console.\r\n- GamescriptPacket: The server gives the admin information from the GameScript in JSON.\r\n- CmdNamesPacket: The server sends out the names of the DoCommands to the admins.\r\n- CmdLoggingPacket: The server gives the admin copies of incoming command packets.\r\n- AdminRconPacket: The admin sends a remote console command.\r\n- AdminChatPacket: The admin sends a chat message to be distributed.\r\n- AdminSubscribePacket: The admin tells the server the update frequency of a particular piece of information.\r\n\r\n## Contributing\r\n\r\nContributions 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.\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Python library to communicate with OpenTTD Admin port",
    "version": "1.0.2",
    "project_urls": {
        "Homepage": "https://github.com/liki-mc/pyOpenTTDAdmin/"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a18341fda35c5be747d7c0e334e41fac55691386df7f8cbada992e28f6cb9d45",
                "md5": "0e4b65c9eee26f0c524a3c96a5ac5f52",
                "sha256": "35fab2b8ff1275a4f2e55148f3f9805d649bee325c5b3f0400efe69d7908679e"
            },
            "downloads": -1,
            "filename": "pyOpenTTDAdmin-1.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0e4b65c9eee26f0c524a3c96a5ac5f52",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 15134,
            "upload_time": "2024-08-17T00:28:02",
            "upload_time_iso_8601": "2024-08-17T00:28:02.757789Z",
            "url": "https://files.pythonhosted.org/packages/a1/83/41fda35c5be747d7c0e334e41fac55691386df7f8cbada992e28f6cb9d45/pyOpenTTDAdmin-1.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c8ca059ba1919d1d702e04e33b4d557476f64d768907d2d3441f341ee5ca1149",
                "md5": "9d9868c447b7eeb37d6a9a83df05a862",
                "sha256": "711a43427fd1ed61d41d65c9d671ac31106a02a2fe596f4c123213dc8c9122bf"
            },
            "downloads": -1,
            "filename": "pyopenttdadmin-1.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "9d9868c447b7eeb37d6a9a83df05a862",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 12239,
            "upload_time": "2024-08-17T00:28:03",
            "upload_time_iso_8601": "2024-08-17T00:28:03.708372Z",
            "url": "https://files.pythonhosted.org/packages/c8/ca/059ba1919d1d702e04e33b4d557476f64d768907d2d3441f341ee5ca1149/pyopenttdadmin-1.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-17 00:28:03",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "liki-mc",
    "github_project": "pyOpenTTDAdmin",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pyopenttdadmin"
}
        
Elapsed time: 0.48232s