### Asynchronous pyOpenTTDAdmin Usage Example Source: https://pypi.org/project/pyOpenTTDAdmin/1.0.4 This snippet demonstrates the asynchronous usage of pyOpenTTDAdmin with async/await syntax. It mirrors the synchronous example by connecting, logging in, subscribing to chat, and handling chat messages, but uses asynchronous methods. ```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()) ``` -------------------------------- ### Synchronous pyOpenTTDAdmin Usage Example Source: https://pypi.org/project/pyOpenTTDAdmin/1.0.4 This snippet shows the basic synchronous usage of pyOpenTTDAdmin. It connects to a server, logs in, subscribes to chat updates, and sets up handlers to print and echo chat messages. ```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() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.