teeworlds_network/docs/v0.0.1/classes/TeeworldsClient.md
2023-09-17 11:51:46 +02:00

7.4 KiB

TeeworldsClient

#on_rcon_line(&block)

Parameter: block [Block |context|]

context.message is a RconLine

Example:

client = TeeworldsClient.new

client.on_rcon_line do |context|
  # TODO: generated documentation
end

client.connect('localhost', 8303, detach: false)

#on_auth_off(&block)

Parameter: block [Block |context|]

context.message is nil because there is no message payload.

Example:

client = TeeworldsClient.new

client.on_auth_off do |context|
  # TODO: generated documentation
end

client.connect('localhost', 8303, detach: false)

#on_auth_on(&block)

Parameter: block [Block |context|]

context.message is nil because there is no message payload.

Example:

client = TeeworldsClient.new

client.on_auth_on do |context|
  # TODO: generated documentation
end

client.connect('localhost', 8303, detach: false)

#on_input_timing(&block)

Parameter: block [Block |context|]

context.message is a InputTiming

Example:

client = TeeworldsClient.new

client.on_input_timing do |context|
  puts "intended_tick: #{context.message.intended_tick}"
  puts "time_left: #{context.message.time_left}"
end

client.connect('localhost', 8303, detach: false)

#on_maplist_entry_rem(&block)

Parameter: block [Block |context|]

context.message is a MaplistEntryRem

Example:

client = TeeworldsClient.new

client.on_maplist_entry_rem do |context|
  # print all map names the server
  # sends to the client
  puts context.message.name
end

client.connect('localhost', 8303, detach: false)

#on_maplist_entry_add(&block)

Parameter: block [Block |context|]

context.message is a MaplistEntryAdd

Example:

client = TeeworldsClient.new

client.on_maplist_entry_add do |context|
  # print all map names the server
  # sends to the client
  puts context.message.name
end

client.connect('localhost', 8303, detach: false)

#on_rcon_cmd_rem(&block)

Parameter: block [Block |context|]

context.message is a RconCmdRem

Example:

client = TeeworldsClient.new

client.on_rcon_cmd_rem do |context|
  # TODO: generated documentation
end

client.connect('localhost', 8303, detach: false)

#on_rcon_cmd_add(&block)

Parameter: block [Block |context|]

context.message is a RconCmdAdd

Example:

client = TeeworldsClient.new

client.on_rcon_cmd_add do |context|
  # TODO: generated documentation
end

client.connect('localhost', 8303, detach: false)

#on_snapshot(&block)

Parameter: block [Block |context|]

TODO: generated documentation

Example:

client = TeeworldsClient.new

client.on_snapshot do |context|
  # TODO: generated documentation
end

client.connect('localhost', 8303, detach: false)

#on_disconnect(&block)

Parameter: block [Block |context|]

TODO: generated documentation

Example:

client = TeeworldsClient.new

client.on_disconnect do |context|
  # TODO: generated documentation
end

client.connect('localhost', 8303, detach: false)

#on_connected(&block)

Parameter: block [Block |context|]

TODO: generated documentation

Example:

client = TeeworldsClient.new

client.on_connected do |context|
  # TODO: generated documentation
end

client.connect('localhost', 8303, detach: false)

#on_client_info(&block)

Parameter: block [Block |context|]

TODO: generated documentation

Example:

client = TeeworldsClient.new

client.on_client_info do |context|
  # TODO: generated documentation
end

client.connect('localhost', 8303, detach: false)

#on_chat(&block)

Parameter: block [Block |context, ChatMessage|]

Takes a block that will be called when the client receives a chat message. The block takes two parameters: context - pretty much useless as of right now ChatMessage - holds all the information of the chat message

Example:

client = TeeworldsClient.new

client.on_chat do |context, msg|
  puts "[chat] #{msg}"
end

client.connect('localhost', 8303, detach: false)

#on_map_change(&block)

Parameter: block [Block |context|]

Takes a block that will be called when the client receives a map change packet.

Example:

client = TeeworldsClient.new

client.on_map_change do |context|
  puts "Got new map!"

  # skip default behavior
  # in this case do not send the ready packet
  context.cancel
end

client.connect('localhost', 8303, detach: false)

#on_client_drop(&block)

Parameter: block [Block |context|]

Takes a block that will be called when the client receives a client drop packet.

Context.data:

[
  player: player_object,
  chunk: raw_packet_data,
  client_id: 0,
  reason: '',
  silent: false
]

Example:

client.on_client_drop do |ctx|
  unless ctx.data[:silent]
    reason = ctx.data[:reason] ? " (#{ctx.data[:reason]})" : ''
    puts "'#{ctx.data[:player].name}' left the game#{reason}"
  end
end

#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:

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:

client = TeeworldsClient.new(verbose: true)

client.connect('localhost', 8303, detach: false)

client.send_chat('hello world!')