Note about defaults (closed #8)
This commit is contained in:
parent
425506d2a3
commit
8d639b57b8
61
README.md
61
README.md
|
@ -36,7 +36,7 @@ for msg in packet.messages:
|
||||||
| Deserialize 0.7 messages | 80% |
|
| Deserialize 0.7 messages | 80% |
|
||||||
| Deserialize 0.7 snapshots | |
|
| Deserialize 0.7 snapshots | |
|
||||||
| Serialize 0.7 packet headers | :heavy_check_mark: |
|
| Serialize 0.7 packet headers | :heavy_check_mark: |
|
||||||
| Serialize 0.7 chunk headers | |
|
| Serialize 0.7 chunk headers | :heavy_check_mark: |
|
||||||
| Serialize 0.7 messages | 80% |
|
| Serialize 0.7 messages | 80% |
|
||||||
| Deserialize 0.6 packet headers | |
|
| Deserialize 0.6 packet headers | |
|
||||||
| Deserialize 0.6 chunk headers | |
|
| Deserialize 0.6 chunk headers | |
|
||||||
|
@ -68,6 +68,65 @@ and when the client and server have to send what.
|
||||||
This [protocol documentation](https://chillerdragon.github.io/teeworlds-protocol/index.html)
|
This [protocol documentation](https://chillerdragon.github.io/teeworlds-protocol/index.html)
|
||||||
should get you started to understand the basics.
|
should get you started to understand the basics.
|
||||||
|
|
||||||
|
## Convenient defaults and fully customizable
|
||||||
|
|
||||||
|
```python
|
||||||
|
"""
|
||||||
|
The call to packet.pack() generates
|
||||||
|
a valid byte array that can be sent as an udp payload
|
||||||
|
|
||||||
|
It uses default values for things like:
|
||||||
|
security token, acknowledge number, packet flags,
|
||||||
|
chunk header (flags, size, seq),
|
||||||
|
vote type, vote value, vote reason, vote force
|
||||||
|
|
||||||
|
It computes a valid chunk header size field based
|
||||||
|
on the payload length.
|
||||||
|
|
||||||
|
It sets the correct num chunks field in the packet header
|
||||||
|
based on the amount of messages you added (1 in this case)
|
||||||
|
|
||||||
|
While this has all fields set that packet would be dropped by a vanilla
|
||||||
|
implementation because the security token and sequence number is wrong.
|
||||||
|
So you have to take care of those your self.
|
||||||
|
"""
|
||||||
|
packet = TwPacket()
|
||||||
|
msg = MsgClCallVote()
|
||||||
|
packet.messages.append(msg)
|
||||||
|
packet.pack()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
Here we also send a Call vote message.
|
||||||
|
But this time we set a security token and a few other fields.
|
||||||
|
|
||||||
|
Note that we set num_chunks to 6 which is wrong because
|
||||||
|
we only send one message (MsgClCallVote).
|
||||||
|
But this library allows you to do so.
|
||||||
|
And it will not compute the correct amount.
|
||||||
|
But use your explicitly set wrong one instead.
|
||||||
|
|
||||||
|
This allows you to have full control and craft any kind of packet.
|
||||||
|
May it be correct or not.
|
||||||
|
"""
|
||||||
|
packet = TwPacket()
|
||||||
|
packet.header.token = b'\x48\x1f\x93\xd7'
|
||||||
|
packet.header.num_chunks = 6
|
||||||
|
packet.header.ack = 638
|
||||||
|
packet.header.flags.control = False
|
||||||
|
packet.header.flags.compression = False
|
||||||
|
msg = MsgClCallVote()
|
||||||
|
msg.header.seq = 10
|
||||||
|
msg.type = 'option'
|
||||||
|
msg.value = 'test'
|
||||||
|
msg.reason = ''
|
||||||
|
msg.force = False
|
||||||
|
packet.messages.append(msg)
|
||||||
|
packet.pack()
|
||||||
|
```
|
||||||
|
|
||||||
## development setup
|
## development setup
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|
Loading…
Reference in a new issue