2022-10-25 12:07:56 +00:00
|
|
|
# teeworlds-client
|
2022-11-01 13:26:40 +00:00
|
|
|
A teeworlds 0.7 client library written in ruby
|
2022-11-01 13:25:56 +00:00
|
|
|
|
2022-11-04 12:22:29 +00:00
|
|
|
## Simple chat printing client
|
|
|
|
|
2022-11-01 13:25:56 +00:00
|
|
|
```ruby
|
|
|
|
require_relative 'lib/teeworlds-client'
|
|
|
|
|
|
|
|
client = TwClient.new(verbose: false)
|
|
|
|
|
2022-11-04 12:22:29 +00:00
|
|
|
# print all incoming chat messages
|
2022-11-01 13:25:56 +00:00
|
|
|
client.hook_chat do |msg|
|
|
|
|
puts "chat: #{msg}"
|
|
|
|
end
|
|
|
|
|
2022-11-04 12:22:29 +00:00
|
|
|
# properly disconnect on ctrl+c
|
2022-11-04 12:07:34 +00:00
|
|
|
Signal.trap('INT') do
|
|
|
|
client.disconnect
|
|
|
|
end
|
|
|
|
|
2022-11-04 12:22:29 +00:00
|
|
|
# connect to localhost and block the current thread
|
|
|
|
client.connect('localhost', 8303, detach: false)
|
|
|
|
```
|
|
|
|
|
|
|
|
## Print all network traffic
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
require_relative 'lib/teeworlds-client'
|
|
|
|
|
|
|
|
client = TwClient.new(verbose: true)
|
|
|
|
|
|
|
|
# connect to localhost and block the current thread
|
|
|
|
client.connect('localhost', 8303, detach: false)
|
|
|
|
```
|
|
|
|
|
|
|
|
## Detach client (do not block the main thread)
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
require_relative 'lib/teeworlds-client'
|
|
|
|
|
|
|
|
client = TwClient.new(verbose: true)
|
|
|
|
|
|
|
|
# connect to localhost and detach a background thread
|
|
|
|
client.connect('localhost', 8303, detach: true)
|
|
|
|
|
|
|
|
loop do
|
|
|
|
# send a chat message every 5 seconds
|
|
|
|
sleep 5
|
|
|
|
client.send_chat('hello friends!')
|
|
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
## Set custom skin and other player infos
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
require_relative 'lib/teeworlds-client'
|
|
|
|
|
|
|
|
client = TwClient.new(verbose: true)
|
|
|
|
|
|
|
|
# all keys are optional
|
|
|
|
# if not provided they will fall back to the default value
|
|
|
|
client.set_startinfo(
|
|
|
|
name: "ruby gamer",
|
|
|
|
clan: "",
|
|
|
|
country: -1,
|
|
|
|
body: "spiky",
|
|
|
|
marking: "duodonny",
|
|
|
|
decoration: "",
|
|
|
|
hands: "standard",
|
|
|
|
feet: "standard",
|
|
|
|
eyes: "standard",
|
|
|
|
custom_color_body: 0,
|
|
|
|
custom_color_marking: 0,
|
|
|
|
custom_color_decoration: 0,
|
|
|
|
custom_color_hands: 0,
|
|
|
|
custom_color_feet: 0,
|
|
|
|
custom_color_eyes: 0,
|
|
|
|
color_body: 0,
|
|
|
|
color_marking: 0,
|
|
|
|
color_decoration: 0,
|
|
|
|
color_hands: 0,
|
|
|
|
color_feet: 0,
|
|
|
|
color_eyes: 0)
|
|
|
|
|
|
|
|
# connect to localhost and block the current thread
|
2022-11-01 14:32:47 +00:00
|
|
|
client.connect('localhost', 8303, detach: false)
|
2022-11-01 13:25:56 +00:00
|
|
|
```
|