Example #1
0
 /**
  * Append a message to this message.
  * This will only append the body, the id/type will be unchanged.
  *
  * @param Message $message
  */
 public function append(Message $message)
 {
     $this->body .= $message->getBody();
 }
Example #2
0
 function it_gives_us_response_objects_for_our_sent_data(\Socket\Raw\Socket $socket, \gries\Rcon\Message $message)
 {
     $message->convertToRconData(2)->willReturn('abc1234');
     $expectedMessage = new Message('mycommand', Message::TYPE_COMMAND, 1);
     $this->sendMessage($message)->shouldBeAMessageLike($expectedMessage);
 }
Example #3
0
 /**
  * This handles a fragmented response.
  * (https://developer.valvesoftware.com/wiki/Source_RCON_Protocol#Multiple-packet_Responses)
  *
  * We basically send a RESPONSE_VALUE Message to the server to force the response of the rest of the package,
  * until we receive another package or an empty response.
  *
  * All the received data is then appended to the current ResponseMessage.
  *
  * @param $responseMessage
  * @throws Exception\InvalidPacketException
  */
 protected function handleFragmentedResponse(Message $responseMessage)
 {
     do {
         usleep(20000);
         // some servers stop responding if we send to many packages so we wait 20ms
         $this->client->write(Message::TYPE_RESPONSE_VALUE);
         $responseData = $this->client->read(4096);
         if (empty($responseData)) {
             break;
         }
         $fragmentedMessage = new Message();
         $fragmentedMessage->initializeFromRconData($responseData, true);
         $responseMessage->append($fragmentedMessage);
         if ($fragmentedMessage->getType() !== Message::TYPE_RESPONSE_VALUE) {
             break;
         }
     } while (true);
 }