2022-11-09 07:40:17 +00:00
|
|
|
# teeworlds_network
|
|
|
|
A teeworlds 0.7 client & server library written in ruby
|
2022-11-01 13:25:56 +00:00
|
|
|
|
2022-11-04 15:57:50 +00:00
|
|
|
## Sample
|
|
|
|
|
|
|
|
Here a simple sample usage of the library.
|
|
|
|
Connecting a client to localhost on port 8303.
|
2022-11-05 10:08:19 +00:00
|
|
|
Acting as a simple chat bot.
|
2022-11-04 15:57:50 +00:00
|
|
|
Also properly disconnect when the program is killed gracefully.
|
|
|
|
|
|
|
|
For more sample usages checkout the [examples/](examples/) folder.
|
2022-11-04 12:22:29 +00:00
|
|
|
|
2022-11-01 13:25:56 +00:00
|
|
|
```ruby
|
2022-11-09 07:40:17 +00:00
|
|
|
require_relative 'lib/teeworlds_client'
|
2022-11-01 13:25:56 +00:00
|
|
|
|
2022-11-04 15:26:24 +00:00
|
|
|
client = TeeworldsClient.new(verbose: false)
|
2022-11-01 13:25:56 +00:00
|
|
|
|
2022-11-14 09:25:28 +00:00
|
|
|
client.on_chat do |_, msg|
|
2022-11-05 15:38:54 +00:00
|
|
|
# note use `next` instead of `return` in the block
|
2022-11-05 15:40:00 +00:00
|
|
|
next unless msg.message[0] == '!'
|
2022-11-05 15:38:54 +00:00
|
|
|
|
|
|
|
case msg.message[1..]
|
|
|
|
when 'ping' then client.send_chat('pong')
|
|
|
|
when 'whoami' then client.send_chat("You are: #{msg.author.name}")
|
|
|
|
when 'list' then client.send_chat(client.game_client.players.values.map(&:name).join(', '))
|
|
|
|
else client.send_chat('Unkown command! Commands: !ping, !whoami, !list')
|
2022-11-05 10:07:16 +00:00
|
|
|
end
|
2022-11-01 13:25:56 +00:00
|
|
|
end
|
|
|
|
|
2022-11-05 10:07:16 +00:00
|
|
|
# properly disconnect on ctrl+c
|
2022-11-04 12:07:34 +00:00
|
|
|
Signal.trap('INT') do
|
|
|
|
client.disconnect
|
|
|
|
end
|
|
|
|
|
2022-11-05 10:07:16 +00:00
|
|
|
# connect to localhost and block the current thread
|
2022-11-04 12:22:29 +00:00
|
|
|
client.connect('localhost', 8303, detach: false)
|
|
|
|
```
|
|
|
|
|
2022-11-04 15:57:50 +00:00
|
|
|
## Documentation
|
2022-11-04 12:22:29 +00:00
|
|
|
|
2023-09-17 15:31:10 +00:00
|
|
|
Checkout [docs/READE.md](docs/README.md) for a full library documentation.
|