A teeworlds 0.7 network protocol library written in ruby
Go to file
ChillerDragon 10ca8238a8
Some checks failed
Runtime tests / syntax (push) Has been cancelled
Runtime tests / unit-tests (push) Has been cancelled
Runtime tests / hooks (push) Has been cancelled
Runtime tests / doc-index (push) Has been cancelled
Integration tests / connect-to-server (push) Has been cancelled
Integration tests / srv-chat (push) Has been cancelled
Static analysis / check (push) Has been cancelled
Style / lint (push) Has been cancelled
rubocop fixes
2024-06-24 11:45:45 +08:00
.github Run yard in ci 2024-02-21 10:45:34 +08:00
docs Generate server hooks docs 2024-02-21 12:39:04 +08:00
examples Add example only for the verbose snap 2024-02-18 15:35:33 +08:00
integration_test Play with failing CI 2024-02-20 17:06:51 +08:00
lib rubocop fixes 2024-06-24 11:45:45 +08:00
scripts Generate server hooks docs 2024-02-21 12:39:04 +08:00
spec Add tests for snapshot builder payload 2024-02-21 18:46:52 +08:00
.gitignore Add failing server side integration test 2024-01-20 23:56:10 +08:00
.rubocop.yml Add rubocop to CI (closed #2) 2022-11-05 17:57:12 +01:00
client_sample.rb Fix chat with cli arguments 2024-06-22 12:21:48 +08: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 fix typo in readme 2024-02-20 20:43:52 +08:00
server_sample.rb Add detach to server (closed #12) 2024-01-20 21:50:55 +08:00
teeworlds_network.gemspec Update huffman to v0.0.4 2024-02-18 16:52:16 +08: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/README.md for a full library documentation.