2022-11-01 13:25:56 +00:00
|
|
|
#!/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
|
|
|
|
|
2022-11-04 15:26:24 +00:00
|
|
|
client = TeeworldsClient.new(verbose: args[:verbose])
|
2022-11-01 13:25:56 +00:00
|
|
|
|
2022-11-05 08:39:16 +00:00
|
|
|
client.on_chat do |msg|
|
2022-11-04 15:26:24 +00:00
|
|
|
puts "[chat] #{msg}"
|
2022-11-01 13:25:56 +00:00
|
|
|
end
|
|
|
|
|
2022-11-04 12:07:34 +00:00
|
|
|
Signal.trap('INT') do
|
|
|
|
client.disconnect
|
|
|
|
end
|
|
|
|
|
2022-11-04 12:04:51 +00:00
|
|
|
# connect and detach thread
|
2022-11-04 11:55:01 +00:00
|
|
|
client.connect(args[:ip], args[:port], detach: false)
|