Chat readable by default and debug opt in
This commit is contained in:
parent
c9495dd293
commit
9ae89fa173
29
teeworlds.rb
29
teeworlds.rb
|
@ -51,25 +51,26 @@ class NetBase
|
|||
@ack.to_s(2).rjust(10, '0') + # aa aaaa aaaa
|
||||
num_chunks.to_s(2).rjust(8, '0') # NNNN NNNN
|
||||
|
||||
puts "header bits: #{header_bits}"
|
||||
header = header_bits.chars.groups_of(8).map do |eight_bits|
|
||||
eight_bits.join('').to_i(2)
|
||||
end
|
||||
puts "header bytes: #{str_hex(header.pack("C*"))}"
|
||||
|
||||
header = header + str_bytes(@server_token)
|
||||
data = (header + payload).pack('C*')
|
||||
@s.send(data, 0, @ip, @port)
|
||||
|
||||
if @verbose
|
||||
p = Packet.new(data, '>')
|
||||
puts p.to_s
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class TwClient
|
||||
attr_reader :state
|
||||
|
||||
def initialize
|
||||
def initialize(options = {})
|
||||
@verbose = options[:verbose] || false
|
||||
@client_token = MY_TOKEN.map { |b| b.to_s(16) }.join('')
|
||||
puts "client token #{@client_token}"
|
||||
@s = UDPSocket.new
|
||||
|
@ -238,9 +239,11 @@ class TwClient
|
|||
when NETMSGTYPE_SV_EMOTICON then on_emoticon(chunk)
|
||||
when NETMSGTYPE_SV_CHAT then on_chat(chunk)
|
||||
else
|
||||
if @verbose
|
||||
puts "todo non sys chunks. skipped msg: #{chunk.msg}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def process_chunk(chunk)
|
||||
if !chunk.sys
|
||||
|
@ -266,8 +269,10 @@ class TwClient
|
|||
chunks.each do |chunk|
|
||||
if chunk.flags_vital && !chunk.flags_resend
|
||||
@netbase.ack = (@netbase.ack + 1) % NET_MAX_SEQUENCE
|
||||
if @verbose
|
||||
puts "got ack: #{@netbase.ack}"
|
||||
end
|
||||
end
|
||||
process_chunk(chunk)
|
||||
end
|
||||
end
|
||||
|
@ -284,7 +289,9 @@ class TwClient
|
|||
data = pck.first
|
||||
|
||||
packet = Packet.new(data, '<')
|
||||
if @verbose
|
||||
puts packet.to_s
|
||||
end
|
||||
|
||||
# process connless packets data
|
||||
if packet.flags_control
|
||||
|
@ -305,7 +312,21 @@ class TwClient
|
|||
end
|
||||
end
|
||||
|
||||
client = TwClient.new
|
||||
verbose = false
|
||||
|
||||
ARGV.reverse_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"
|
||||
exit(0)
|
||||
elsif arg == '--verbose' || arg == '-v'
|
||||
verbose = true
|
||||
ARGV.pop
|
||||
end
|
||||
end
|
||||
|
||||
client = TwClient.new(verbose: verbose)
|
||||
client.connect(ARGV[0] || "localhost", ARGV[1] ? ARGV[1].to_i : 8303)
|
||||
|
||||
|
|
Loading…
Reference in a new issue