https://github.com/openttd/py-protocol
OpenTTD's wire protocol as Python library
https://github.com/openttd/py-protocol
Last synced: 8 months ago
JSON representation
OpenTTD's wire protocol as Python library
- Host: GitHub
- URL: https://github.com/openttd/py-protocol
- Owner: OpenTTD
- License: lgpl-2.1
- Created: 2021-05-25T10:25:49.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-01-27T10:14:20.000Z (almost 2 years ago)
- Last Synced: 2025-04-20T14:42:55.765Z (9 months ago)
- Language: Python
- Homepage:
- Size: 66.4 KB
- Stars: 2
- Watchers: 4
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# openttd-protocol
[](https://github.com/OpenTTD/py-protocol/blob/main/LICENSE)
[](https://github.com/OpenTTD/py-protocol/releases)
[](https://github.com/OpenTTD/py-protocol/commits/main)
[](https://github.com/OpenTTD/py-protocol/actions?query=workflow%3ATesting)
[](https://github.com/OpenTTD/py-protocol/actions?query=workflow%3A%22Release%22)
This library implements the OpenTTD network protocol.
It mostly is meant to be used for OpenTTD's backend services, like [BaNaNaS server](https://github.com/OpenTTD/bananas-server) and [master server](https://github.com/OpenTTD/master-server).
# Usage
`pip install openttd-protocol`
Now in your Python code you can import the protocol.
Example:
```python
import asyncio
import logging
from openttd_protocol.protocol.coordinator import CoordinatorProtocol
log = logging.getLogger(__name__)
class Application:
async def receive_PACKET_COORDINATOR_CLIENT_REGISTER(self, source, protocol_version, game_type, server_port):
# Your logic goes here
pass
def main():
application = Application()
loop = asyncio.get_event_loop()
server = loop.run_until_complete(loop.create_server(lambda: CoordinatorProtocol(application), host="127.0.0.1", port=12345, reuse_port=True, start_serving=True))
try:
loop.run_until_complete(server.serve_forever())
except KeyboardInterrupt:
pass
log.info("Shutting down game_coordinator ...")
server.close()
if __name__ == "__main__":
main()
```