class Srcon::Packet
Constants
- MAXIMUM_BYTE_SIZE
- MINIMUM_BYTE_SIZE
- SERVERDATA_AUTH
Packet
types- SERVERDATA_AUTH_RESPONSE
- SERVERDATA_EXECCOMMAND
- SERVERDATA_RESPONSE_VALUE
Attributes
body[R]
id[R]
type[R]
Public Class Methods
from_message(body, addrinfo, rflags)
click to toggle source
# File lib/srcon/packet.rb, line 14 def self.from_message(body, addrinfo, rflags) body_unpacked = body.unpack('l<l<l<Z*') new(body_unpacked[3], body_unpacked[2], body_unpacked[0]) end
new(body = '', type = SERVERDATA_EXECCOMMAND, id = 1)
click to toggle source
@param [String] body The message body for the packet
# File lib/srcon/packet.rb, line 20 def initialize(body = '', type = SERVERDATA_EXECCOMMAND, id = 1) @body = body @type = type @id = id end
Public Instance Methods
body=(new_body)
click to toggle source
# File lib/srcon/packet.rb, line 26 def body=(new_body) @body = new_body if size > MAXIMUM_BYTE_SIZE raise Srcon::MaxPacketSize.new("Maximum packet size is #{MAXIMUM_BYTE_SIZE} bytes") end end
size()
click to toggle source
# File lib/srcon/packet.rb, line 34 def size MINIMUM_BYTE_SIZE + body.bytesize end
to_b()
click to toggle source
# File lib/srcon/packet.rb, line 38 def to_b sizeb = [size].pack('l<') idb = [id].pack('l<') typeb = [type].pack('l<') bodyb = [body].pack('Z*') sizeb + idb + typeb + bodyb + "\0" end