Document on_connected hook

This commit is contained in:
ChillerDragon 2023-09-17 13:09:03 +02:00
parent 08560d0c92
commit 4810628386
2 changed files with 11 additions and 16 deletions

View file

@ -17,21 +17,6 @@ client.on_map_change do |context|
end
```
### @client [[TeeworldsClient](../classes/TeeworldsClient.md)]
Access the network client to send packets.
**Example:**
Reimplement your on on_connected logic and cancel the default one
```ruby
client.on_connected do |ctx|
ctx.client.send_msg_start_info
ctx.cancel
end
```
### @data [Hash]
This hash holds all the current data. They keys might vary depending on the current context.

View file

@ -23,12 +23,22 @@ client.connect('localhost', 8303, detach: false)
context.message is nil because there is no message payload.
By default the client will respond with the startinfo message.
This is crucial to establish a healthy connection to the server.
If you know what you are doing and do not want to send this message call `context.cancel`
**Example:**
```ruby
client = TeeworldsClient.new
client.on_connected do |context|
# TODO: generated documentation
puts "we got NETMSG_CON_READY from server"
# skip default behavior
context.cancel
# send start info manually
client.send_msg_start_info
end
client.connect('localhost', 8303, detach: false)