1 | <?php |
||
15 | class Message |
||
16 | { |
||
17 | /** |
||
18 | * The reply type of a failed authentication request. |
||
19 | * |
||
20 | * @var int |
||
21 | */ |
||
22 | const TYPE_AUTH_FAILURE = -1; |
||
23 | |||
24 | /** |
||
25 | * Type for server responses. |
||
26 | */ |
||
27 | const TYPE_RESPONSE_VALUE = 0; |
||
28 | |||
29 | /** |
||
30 | * Standard type for commands. |
||
31 | * |
||
32 | * @var int |
||
33 | */ |
||
34 | const TYPE_COMMAND = 2; |
||
35 | |||
36 | /** |
||
37 | * Type for authentication with the server. |
||
38 | * |
||
39 | * @var int |
||
40 | */ |
||
41 | const TYPE_AUTH = 3; |
||
42 | |||
43 | /** |
||
44 | * @var mixed The type of this message. |
||
45 | */ |
||
46 | protected $type; |
||
47 | |||
48 | /** |
||
49 | * The body of this message. |
||
50 | * |
||
51 | * @var string |
||
52 | */ |
||
53 | protected $body; |
||
54 | |||
55 | /** |
||
56 | * The id of this message. |
||
57 | * |
||
58 | * @var int |
||
59 | */ |
||
60 | protected $id; |
||
61 | |||
62 | /** |
||
63 | * @param string $body |
||
64 | * @param int $type |
||
65 | * @param null $id |
||
66 | */ |
||
67 | public function __construct($body = '', $type = Message::TYPE_COMMAND, $id = null) |
||
73 | |||
74 | /** |
||
75 | * The message id used for this message. |
||
76 | * This will be encoded in the RconData. |
||
77 | * |
||
78 | * @param int $id |
||
79 | * |
||
80 | * @return string |
||
81 | */ |
||
82 | public function convertToRconData($id) |
||
93 | |||
94 | /** |
||
95 | * Get the type of this message. |
||
96 | * |
||
97 | * @return int|mixed |
||
98 | */ |
||
99 | public function getType() |
||
103 | |||
104 | /** |
||
105 | * Parses data from a RCON Response. |
||
106 | * Note: the first 4 bytes that indicate the size of the packet MUST not be included. |
||
107 | * |
||
108 | * @param $data |
||
109 | * @param bool|$fragmented If the data comes from a fragmented response only the id and body will be present. |
||
110 | * |
||
111 | * @throws InvalidPacketException |
||
112 | */ |
||
113 | public function initializeFromRconData($data, $fragmented = false) |
||
139 | |||
140 | /** |
||
141 | * The content of this message. |
||
142 | * |
||
143 | * @return string |
||
144 | */ |
||
145 | public function getBody() |
||
149 | |||
150 | /** |
||
151 | * Get the id of this message. |
||
152 | * |
||
153 | * @return int |
||
154 | */ |
||
155 | public function getId() |
||
159 | |||
160 | /** |
||
161 | * Append a message to this message. |
||
162 | * This will only append the body, the id/type will be unchanged. |
||
163 | * |
||
164 | * @param Message $message |
||
165 | */ |
||
166 | public function append(Message $message) |
||
170 | } |
||
171 |