A teeworlds 0.7 network protocol library written in ruby
Go to file
ChillerDragon fff2e9efb0 First draft of sending inputs
Thanks a lot to @Swarfey for his tw-chatonly typescript package
https://www.npmjs.com/package/teeworlds

His simple calculation of the pred time was saving me a lot of time!
2022-11-06 20:15:47 +01:00
.github/workflows Add rcon support 2022-11-06 18:26:14 +01:00
docs Properly versioned documentation 2022-11-05 19:33:08 +01:00
examples Add rcon support 2022-11-06 18:26:14 +01:00
integration_test Add rcon support 2022-11-06 18:26:14 +01:00
lib First draft of sending inputs 2022-11-06 20:15:47 +01:00
spec All packer tests passing and verified 2022-11-06 16:43:32 +01:00
.gitignore Add integration test (closed #4) 2022-11-05 18:58:53 +01:00
.rubocop.yml Add rubocop to CI (closed #2) 2022-11-05 17:57:12 +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 Properly versioned documentation 2022-11-05 19:33:08 +01:00
sample.rb rubocop -A 2022-11-05 17:48:47 +01:00
teeworlds-client.gemspec rubocop -a 2022-11-05 17:19:05 +01:00

teeworlds-client

A teeworlds 0.7 client 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.md for a full library documentation.