2023-03-16 13:49:55 +00:00
|
|
|
A teeworlds network protocol library, designed according to sans I/O (http://sans-io.readthedocs.io/) principles
|
2023-03-12 21:12:07 +00:00
|
|
|
|
2023-03-19 10:44:40 +00:00
|
|
|
# THIS LIBRARY IS IN EARLY DEVELOPMENT
|
|
|
|
|
2023-03-31 08:17:44 +00:00
|
|
|
## Do not get bamboozled by the mature looking readme!
|
|
|
|
## This project is not in a very usable state yet. It is in very early development!
|
|
|
|
## APIs might change and many essential features are missing!
|
|
|
|
|
|
|
|
---
|
2023-03-19 10:44:40 +00:00
|
|
|
|
2023-03-16 15:56:37 +00:00
|
|
|
## install
|
|
|
|
|
|
|
|
```bash
|
|
|
|
pip install twnet_parser
|
|
|
|
```
|
|
|
|
|
2023-03-16 09:26:36 +00:00
|
|
|
## sample usage
|
2023-03-12 21:12:07 +00:00
|
|
|
|
|
|
|
```python
|
2023-03-16 15:56:37 +00:00
|
|
|
import twnet_parser.packet
|
2023-03-18 09:03:42 +00:00
|
|
|
packet = twnet_parser.packet.parse7(b'\x04\x0a\x00\xcf\x2e\xde\x1d\04') # 0.7 close
|
2023-03-16 11:08:02 +00:00
|
|
|
|
|
|
|
print(packet) # => <class: 'TwPacket'>: {'version': '0.7', 'header': <class: 'Header'>, 'messages': [<class: 'CtrlMessage'>]}
|
|
|
|
print(packet.header) # => <class: 'Header'>: {'flags': <class: 'PacketFlags7, 'size': 0, 'ack': 10, 'token': b'\xcf.\xde\x1d', 'num_chunks': 0}
|
|
|
|
print(packet.header.flags) # => <class: 'PacketFlags7'>: {'control': True, 'resend': False, 'compression': False, 'connless': False}
|
|
|
|
for msg in packet.messages:
|
2023-03-25 13:22:45 +00:00
|
|
|
print(msg.message_name) # => close
|
2023-03-12 21:12:07 +00:00
|
|
|
```
|
2023-03-14 21:58:06 +00:00
|
|
|
|
2023-03-18 08:35:43 +00:00
|
|
|
## Features
|
|
|
|
|
|
|
|
| Feature | Status |
|
|
|
|
| ------------------------------ | ------------------ |
|
|
|
|
| Deserialize 0.7 packet headers | :heavy_check_mark: |
|
2023-04-02 08:41:46 +00:00
|
|
|
| Deserialize 0.7 chunk headers | :heavy_check_mark: |
|
2023-04-06 15:45:05 +00:00
|
|
|
| Deserialize 0.7 messages | 70% |
|
2023-03-31 08:17:44 +00:00
|
|
|
| Deserialize 0.7 snapshots | |
|
2023-03-18 08:35:43 +00:00
|
|
|
| Serialize 0.7 packet headers | |
|
|
|
|
| Serialize 0.7 chunk headers | |
|
2023-04-06 15:45:05 +00:00
|
|
|
| Serialize 0.7 messages | 70% |
|
2023-03-18 08:35:43 +00:00
|
|
|
| Deserialize 0.6 packet headers | |
|
|
|
|
| Deserialize 0.6 chunk headers | |
|
|
|
|
| Deserialize 0.6 messages | |
|
2023-03-31 08:17:44 +00:00
|
|
|
| Deserialize 0.6 snapshots | |
|
2023-03-18 08:35:43 +00:00
|
|
|
| Serialize 0.6 packet headers | |
|
|
|
|
| Serialize 0.6 chunk headers | |
|
|
|
|
| Serialize 0.6 messages | |
|
|
|
|
|
|
|
|
## Non-Features (also not planned for this library)
|
|
|
|
|
|
|
|
| Feature | Status | Where to find it |
|
|
|
|
| ------------------------------ | ------- | ------------------------------------------- |
|
|
|
|
| Networking | :x: | TODO: link if someone implemented it on top |
|
|
|
|
| Protocol version detection | :x: | TODO: link if someone implemented it on top |
|
|
|
|
|
|
|
|
Look elsewhere for these features. Or use this library to implement them on top.
|
|
|
|
|
2023-03-16 14:04:01 +00:00
|
|
|
## development setup
|
2023-03-14 21:58:06 +00:00
|
|
|
|
|
|
|
```bash
|
|
|
|
git clone https://gitlab.com/teeworlds-network/twnet_parser
|
|
|
|
cd twnet_parser
|
|
|
|
python -m venv venv
|
|
|
|
source venv/bin/activate
|
2023-03-16 16:08:27 +00:00
|
|
|
pip install -r requirements/dev.txt
|
2023-03-14 21:58:06 +00:00
|
|
|
```
|
2023-03-16 13:04:48 +00:00
|
|
|
|
|
|
|
## tests and linting
|
|
|
|
|
|
|
|
```bash
|
2023-03-16 13:49:55 +00:00
|
|
|
# dev dependencies
|
|
|
|
pip install -r requirements/dev.txt
|
|
|
|
|
2023-03-16 13:04:48 +00:00
|
|
|
# run unit tests
|
|
|
|
pytest .
|
|
|
|
|
|
|
|
# run style linter
|
|
|
|
pylint src/
|
|
|
|
|
|
|
|
# run type checker
|
|
|
|
mypy src/
|
|
|
|
```
|
|
|
|
|
2023-03-16 13:49:55 +00:00
|
|
|
## package and release
|
|
|
|
|
|
|
|
```bash
|
2023-03-16 15:43:53 +00:00
|
|
|
# manual
|
2023-03-16 13:49:55 +00:00
|
|
|
pip install -r requirements/dev.txt
|
2023-03-16 15:43:53 +00:00
|
|
|
version=0.0.2
|
2023-04-06 16:11:49 +00:00
|
|
|
sed -i "s/^version =.*/version = \"$version\"/" pyproject.toml
|
2023-03-16 13:49:55 +00:00
|
|
|
python -m build
|
2023-03-16 15:43:53 +00:00
|
|
|
git tag -a "v$version" -m "# version $version"
|
2023-03-16 13:49:55 +00:00
|
|
|
python -m twine upload dist/*
|
2023-03-16 15:43:53 +00:00
|
|
|
|
|
|
|
# or use the interactive convience script
|
|
|
|
./scripts/release.sh
|
2023-03-16 13:49:55 +00:00
|
|
|
```
|