teeworlds_network/sample.rb
ChillerDragon 8fe595b0a6 Client info is actually used to display join msgs
Looked at the c++ client code and it actually does that.
The entergame message is only used in demos. Yeet on those.
2022-11-05 11:34:34 +01:00

40 lines
894 B
Ruby
Executable file

#!/usr/bin/env ruby
require_relative 'lib/teeworlds-client'
args = {verbose: false, ip: nil, port: nil}
ARGV.each do |arg|
if arg == '--help' || arg == '-h'
puts "usage: teeworlds.rb [OPTIONS..] [host] [port]"
echo "options:"
echo " --help|-h show this help"
echo " --verbose|-v verbose output"
echo "example:"
echo " teeworlds.rb --verbose localhost 8303"
exit(0)
elsif arg == '--verbose' || arg == '-v'
args[:verbose] = true
elsif args[:ip].nil?
args[:ip] = arg
elsif args[:port].nil?
args[:port] = arg.to_i
end
end
args[:ip] = args[:ip] || '127.0.0.1'
args[:port] = args[:port] || 8303
client = TeeworldsClient.new(verbose: args[:verbose])
client.on_chat do |msg|
puts "[chat] #{msg}"
end
Signal.trap('INT') do
client.disconnect
end
# connect and detach thread
client.connect(args[:ip], args[:port], detach: false)