class OpenRAReplay::Packet
Constants
- SERVER_LOBBY_PACKET
Attributes
byte_array[R]
client_id[R]
data[R]
frame[R]
length[R]
orders[R]
to_s[R]
Public Class Methods
new(options = {})
click to toggle source
# File lib/openrareplay/packet/packet.rb, line 34 def initialize(options = {}) if options[:byte_array] @byte_array = options[:byte_array] parse_byte_array elsif options[:orders] @client_id = options[:client_id] @frame = options[:frame] @orders = options[:orders] construct_byte_array :orders elsif options[:data] @client_id = options[:client_id] @frame = options[:frame] @data = options[:data] construct_byte_array :data else raise "Improper options given to initialize! #{options}" end end
Public Instance Methods
inspect()
click to toggle source
# File lib/openrareplay/packet/packet.rb, line 59 def inspect byte_array.inspect end
metadata?()
click to toggle source
# File lib/openrareplay/packet/packet.rb, line 71 def metadata? false end
server_lobby_packet?()
click to toggle source
# File lib/openrareplay/packet/packet.rb, line 53 def server_lobby_packet? (frame == SERVER_LOBBY_PACKET) end
unknown?()
click to toggle source
# File lib/openrareplay/packet/packet.rb, line 63 def unknown? if orders.length == 1 order = orders.first return false unless order.order? || order.special_command? end false end
Private Instance Methods
construct_byte_array(type)
click to toggle source
# File lib/openrareplay/packet/packet.rb, line 87 def construct_byte_array(type) case type when :data @length = data.length + 4 @byte_array = (encode_u32 client_id) + (encode_u32 length) + (encode_u32 frame) + data when :orders @data = ''.force_encoding('ASCII-8BIT') orders.each do |order| @data += order.serialize end construct_byte_array :data end end
parse_byte_array()
click to toggle source
# File lib/openrareplay/packet/packet.rb, line 77 def parse_byte_array @client_id = decode_u32 byte_array[0..3] @length = decode_u32 byte_array[4..7] @frame = decode_u32 byte_array[8..11] @data = byte_array[12..-1] @orders = [] d = StringIO.new(data) @orders.append Order.construct(d) until d.eof? end