class RuneRb::Net::Packet
Attributes
The buffer for this packet
The opcode for this packet
The packet type. Fixed, Variable or Variable Short
Public Class Methods
# File app/net/packet.rb, line 12 def initialize(opcode, type, buffer) @opcode = opcode @type = type @buffer = buffer end
Public Instance Methods
# File app/net/packet.rb, line 167 def <<(data) @buffer << data end
# File app/net/packet.rb, line 171 def empty? @buffer.empty? end
Is the packet raw data
# File app/net/packet.rb, line 19 def is_raw opcode == -1 end
# File app/net/packet.rb, line 175 def length @buffer.length end
Reads a series of bytes
# File app/net/packet.rb, line 151 def read(is, offset, length) (0...length).each {|e| is[offset + e] = read_byte } end
Reads a byte from the array, and seeks forward.
# File app/net/packet.rb, line 24 def read_byte val = @buffer.unpack("c").first @buffer.slice!(0...1) val end
Reads a byte type a, and seeks forward.
# File app/net/packet.rb, line 77 def read_byte_a (read_byte - 128).byte end
Reads byte type c from the array, and seeks forward.
# File app/net/packet.rb, line 67 def read_byte_c (-read_byte).byte end
Reads byte type s from the array, and seeks forward.
# File app/net/packet.rb, line 72 def read_byte_s (128 - read_byte).byte end
Reads several bytes from the array, and seeks forward.
# File app/net/packet.rb, line 31 def read_bytes(size) @buffer.slice!(0...size) end
Reads an int from the array, and seeks forward.
# File app/net/packet.rb, line 55 def read_int (read_ubyte << 24) + (read_ubyte << 16) + (read_ubyte << 8) + read_ubyte end
Reads a V1 integer.
# File app/net/packet.rb, line 115 def read_int1 end
Reads a V2 integer.
# File app/net/packet.rb, line 120 def read_int2 end
Reads a little-endian short from the array, and seeks forward.
# File app/net/packet.rb, line 82 def read_leshort i = read_ubyte | (read_ubyte << 8) if i > 32767 i -= 0x10000 end i.short end
Reads a little-endian short type a from the array, and seeks forward.
# File app/net/packet.rb, line 104 def read_leshort_a i = (read_byte - 128).ubyte | (read_ubyte << 8) if i > 32767 i -= 0x10000 end i.short end
Reads a long from the array, and seeks forward.
# File app/net/packet.rb, line 60 def read_long l = (read_int & 0xffffffff).long l1 = (read_int & 0xffffffff).long return ((l << 32) + l1).long end
Reads a series of bytes in reverse, and seeks forward.
# File app/net/packet.rb, line 141 def read_reverse(is, offset, length) end
Reads a series of bytes type a in reverse, and seeks forward.
# File app/net/packet.rb, line 146 def read_reverse_a(is, offset, length) end
Reads a short from the array, and seeks forward.
# File app/net/packet.rb, line 41 def read_short val = @buffer.unpack("n").first @buffer.slice!(0...2) val end
Reads a short type a from the array, and seeks forward.
# File app/net/packet.rb, line 93 def read_short_a i = (read_ubyte << 8) | (read_byte - 128).ubyte if i > 32767 i -= 0x10000 end i.short end
Reads a smart
# File app/net/packet.rb, line 158 def read_smart end
Reads a string from the array, and seeks forward.
# File app/net/packet.rb, line 130 def read_str(terminator = 10) str = "" while @buffer.length > 0 and (b = @buffer.unpack("C").first) != terminator str << b.chr @buffer.slice!(0...1) end @buffer.slice!(0...1) str end
Reads a three byte integer, and seeks forward.
# File app/net/packet.rb, line 125 def read_tribyte end
Reads an unsigned byte from the array, and seeks forward.
# File app/net/packet.rb, line 36 def read_ubyte read_byte.ubyte end
Reads a short from the array, and seeks forward.
# File app/net/packet.rb, line 48 def read_ushort val = @buffer.unpack("S").first @buffer.slice!(0...2) val end
Reads an unsigned smart
# File app/net/packet.rb, line 163 def read_usmart end
# File app/net/packet.rb, line 179 def size @buffer.size end
# File app/net/packet.rb, line 183 def slice!(range) @buffer.slice!(range) end