88 lines
2.1 KiB
Markdown
88 lines
2.1 KiB
Markdown
|
# Classes
|
||
|
|
||
|
## Player
|
||
|
|
||
|
### @id [Integer]
|
||
|
### @local [Integer]
|
||
|
### @team [Integer]
|
||
|
### @name [String]
|
||
|
### @clan [String]
|
||
|
### @country [Integer]
|
||
|
### @skin_parts [Array#String]
|
||
|
### @skin_custom_colors [Array#Integer]
|
||
|
### @skin_colors [Array#Integer]
|
||
|
|
||
|
## ChatMessage
|
||
|
|
||
|
### @mode [Integer]
|
||
|
### @client_id [Integer]
|
||
|
### @target_id [Integer]
|
||
|
### @message [Integer]
|
||
|
### @author [[Player](#player)]
|
||
|
|
||
|
## TeeworldsClient
|
||
|
|
||
|
### #hook_chat(&block)
|
||
|
|
||
|
**Parameter: block [Block]**
|
||
|
|
||
|
Takes a block that will be called when the client receives a chat message.
|
||
|
The block takes one parameter of type [ChatMessage](#chatmessage).
|
||
|
|
||
|
**Example:**
|
||
|
|
||
|
```ruby
|
||
|
client = TeeworldsClient.new
|
||
|
|
||
|
client.hook_chat do |msg|
|
||
|
puts "[chat] #{msg}"
|
||
|
end
|
||
|
|
||
|
client.connect('localhost', 8303, detach: true)
|
||
|
```
|
||
|
|
||
|
### connect(ip, port, options)
|
||
|
|
||
|
**Parameter: ip [String]**
|
||
|
|
||
|
**Parameter: port [Integer]**
|
||
|
|
||
|
**Parameter: options [Hash] (default: {detach: false})**
|
||
|
|
||
|
Connect to given server. The option ``:detach`` decides wether the connection should run in a background thread or not.
|
||
|
By default no thread will be spawned. And the ``connect()`` method blocks your main thread. Meaning no line below that will be run as long as the connection is up.
|
||
|
|
||
|
If you decide to provide the option ``detach: true`` it will spawn a thread and run the connection in there. Meaning it will jump to the next line after ``connect()`` is called. So it is your responsibility to keep the program running.
|
||
|
If the connection happens in the last line of your program it will just quit. So you have to keep it up using a loop for example.
|
||
|
|
||
|
**Example:**
|
||
|
|
||
|
```ruby
|
||
|
client = TeeworldsClient.new(verbose: true)
|
||
|
|
||
|
# this will spawn a background thread
|
||
|
client.connect('localhost', 8303, detach: true)
|
||
|
# this line will be run directly after the connection
|
||
|
|
||
|
# this line will be running as long as the connection is up
|
||
|
client.connect('localhost', 8303, detach: false)
|
||
|
# this line will only be run if the connection broke
|
||
|
```
|
||
|
|
||
|
|
||
|
### send_chat(str)
|
||
|
|
||
|
**Parameter: str [String]**
|
||
|
|
||
|
Send a chat message. Takes the chat message as String.
|
||
|
|
||
|
**Example:**
|
||
|
|
||
|
```ruby
|
||
|
client = TeeworldsClient.new(verbose: true)
|
||
|
|
||
|
client.connect('localhost', 8303, detach: true)
|
||
|
|
||
|
client.send_chat('hello world!')
|
||
|
```
|