A teeworlds 0.7 network protocol library written in ruby
Go to file
2022-11-26 11:25:23 +01:00
.github/workflows Generate hooks documentation 2022-11-13 13:13:14 +01:00
docs/v0.0.1 Call chunks messages (closed #6) 2022-11-26 11:25:23 +01:00
examples Call chunks messages (closed #6) 2022-11-26 11:25:23 +01:00
integration_test Fix crash on server messages and add tests for it 2022-11-20 10:13:07 +01:00
lib Call chunks messages (closed #6) 2022-11-26 11:25:23 +01:00
scripts Move all network payload classes to messages/ 2022-11-16 09:37:47 +01:00
spec First workin snap item parser 2022-11-17 15:43:27 +01:00
.gitignore Read password from autoexec.cfg 2022-11-24 10:39:30 +01:00
.rubocop.yml Add rubocop to CI (closed #2) 2022-11-05 17:57:12 +01:00
client_sample.rb Opsi I write too much bash 2022-11-20 09:42:24 +01:00
Gemfile Add tests (closed #3) 2022-11-05 17:13:23 +01:00
Rakefile Add tests (closed #3) 2022-11-05 17:13:23 +01:00
README.md Make client callbacks arrays 2022-11-14 10:25:28 +01:00
server_sample.rb Make server log look nice in non verbose mode 2022-11-13 10:42:49 +01:00
teeworlds-client.gemspec Layout server control msg structure 2022-11-09 08:56:18 +01:00

teeworlds_network

A teeworlds 0.7 client & server library written in ruby

Sample

Here a simple sample usage of the library. Connecting a client to localhost on port 8303. Acting as a simple chat bot. Also properly disconnect when the program is killed gracefully.

For more sample usages checkout the examples/ folder.

require_relative 'lib/teeworlds_client'

client = TeeworldsClient.new(verbose: false)

client.on_chat do |_, msg|
  # note use `next` instead of `return` in the block
  next unless 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

# properly disconnect on ctrl+c
Signal.trap('INT') do
  client.disconnect
end

# connect to localhost and block the current thread
client.connect('localhost', 8303, detach: false)

Documentation

Checkout docs/v0.0.1/READE.md for a full library documentation.