PocketMine-MP 5.18.2 git-00e39821f06a4b6d728d35053c2621dbb19369ff
ConnectionRequestAccepted.php
1<?php
2
3/*
4 * This file is part of RakLib.
5 * Copyright (C) 2014-2022 PocketMine Team <https://github.com/pmmp/RakLib>
6 *
7 * RakLib is not affiliated with Jenkins Software LLC nor RakNet.
8 *
9 * RakLib is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 */
14
15declare(strict_types=1);
16
17namespace raklib\protocol;
18
21use function strlen;
22
25
26 public InternetAddress $address;
28 public array $systemAddresses = [];
29 public int $sendPingTime;
30 public int $sendPongTime;
31
35 public static function create(InternetAddress $clientAddress, array $systemAddresses, int $sendPingTime, int $sendPongTime) : self{
36 $result = new self;
37 $result->address = $clientAddress;
38 $result->systemAddresses = $systemAddresses;
39 $result->sendPingTime = $sendPingTime;
40 $result->sendPongTime = $sendPongTime;
41 return $result;
42 }
43
44 public function __construct(){
45 $this->systemAddresses[] = new InternetAddress("127.0.0.1", 0, 4);
46 }
47
48 protected function encodePayload(PacketSerializer $out) : void{
49 $out->putAddress($this->address);
50 $out->putShort(0);
51
52 $dummy = new InternetAddress("0.0.0.0", 0, 4);
53 for($i = 0; $i < RakLib::$SYSTEM_ADDRESS_COUNT; ++$i){
54 $out->putAddress($this->systemAddresses[$i] ?? $dummy);
55 }
56
57 $out->putLong($this->sendPingTime);
58 $out->putLong($this->sendPongTime);
59 }
60
61 protected function decodePayload(PacketSerializer $in) : void{
62 $this->address = $in->getAddress();
63 $in->getShort(); //TODO: check this
64
65 $len = strlen($in->getBuffer());
66 $dummy = new InternetAddress("0.0.0.0", 0, 4);
67
68 for($i = 0; $i < RakLib::$SYSTEM_ADDRESS_COUNT; ++$i){
69 $this->systemAddresses[$i] = $in->getOffset() + 16 < $len ? $in->getAddress() : $dummy; //HACK: avoids trying to read too many addresses on bad data
70 }
71
72 $this->sendPingTime = $in->getLong();
73 $this->sendPongTime = $in->getLong();
74 }
75}
static int $SYSTEM_ADDRESS_COUNT
Definition: RakLib.php:27
static create(InternetAddress $clientAddress, array $systemAddresses, int $sendPingTime, int $sendPongTime)
const ID_CONNECTION_REQUEST_ACCEPTED
RakPeer - In a client/server environment, our connection request to the server has been accepted.