teeworlds_network/README.md

41 lines
1.1 KiB
Markdown
Raw Normal View History

2022-10-25 12:07:56 +00:00
# teeworlds-client
A teeworlds 0.7 client 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
require_relative 'lib/teeworlds-client'
2022-11-04 15:26:24 +00:00
client = TeeworldsClient.new(verbose: false)
2022-11-01 13:25:56 +00:00
2022-11-05 08:39:16 +00:00
client.on_chat do |msg|
2022-11-05 10:07:16 +00:00
if msg.message[0] == '!'
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')
end
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
2022-11-04 15:57:50 +00:00
Checkout [docs/01.md](docs/01.md) for a full library documentation.