Class: Srcon::Packet
- Inherits:
-
Object
- Object
- Srcon::Packet
- Defined in:
- lib/srcon/packet.rb
Constant Summary collapse
- MINIMUM_BYTE_SIZE =
10- MAXIMUM_BYTE_SIZE =
4096- SERVERDATA_AUTH =
Packet types
3- SERVERDATA_AUTH_RESPONSE =
2- SERVERDATA_EXECCOMMAND =
2- SERVERDATA_RESPONSE_VALUE =
0
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(body = '', type = SERVERDATA_EXECCOMMAND, id = 1) ⇒ Packet
constructor
A new instance of Packet.
- #size ⇒ Object
- #to_b ⇒ Object
Constructor Details
#initialize(body = '', type = SERVERDATA_EXECCOMMAND, id = 1) ⇒ Packet
Returns a new instance of Packet.
20 21 22 23 24 |
# File 'lib/srcon/packet.rb', line 20 def initialize(body = '', type = SERVERDATA_EXECCOMMAND, id = 1) @body = body @type = type @id = id end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
12 13 14 |
# File 'lib/srcon/packet.rb', line 12 def body @body end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
12 13 14 |
# File 'lib/srcon/packet.rb', line 12 def id @id end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
12 13 14 |
# File 'lib/srcon/packet.rb', line 12 def type @type end |
Class Method Details
.from_message(body, addrinfo, rflags) ⇒ Object
14 15 16 17 |
# File 'lib/srcon/packet.rb', line 14 def self.(body, addrinfo, rflags) body_unpacked = body.unpack('l<l<l<Z*') new(body_unpacked[3], body_unpacked[2], body_unpacked[0]) end |
Instance Method Details
#size ⇒ Object
34 35 36 |
# File 'lib/srcon/packet.rb', line 34 def size MINIMUM_BYTE_SIZE + body.bytesize end |
#to_b ⇒ Object
38 39 40 41 42 43 44 45 |
# 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 |