PocketMine-MP 5.21.1 git-2ff647079265e7c600203af4fd902b15e99d49a4
NewIncomingConnection.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
32 protected function encodePayload(PacketSerializer $out) : void{
33 $out->putAddress($this->address);
34 foreach($this->systemAddresses as $address){
35 $out->putAddress($address);
36 }
37 $out->putLong($this->sendPingTime);
38 $out->putLong($this->sendPongTime);
39 }
40
41 protected function decodePayload(PacketSerializer $in) : void{
42 $this->address = $in->getAddress();
43
44 //TODO: HACK!
45 $stopOffset = strlen($in->getBuffer()) - 16; //buffer length - sizeof(sendPingTime) - sizeof(sendPongTime)
46 $dummy = new InternetAddress("0.0.0.0", 0, 4);
47 for($i = 0; $i < RakLib::$SYSTEM_ADDRESS_COUNT; ++$i){
48 if($in->getOffset() >= $stopOffset){
49 $this->systemAddresses[$i] = clone $dummy;
50 }else{
51 $this->systemAddresses[$i] = $in->getAddress();
52 }
53 }
54
55 $this->sendPingTime = $in->getLong();
56 $this->sendPongTime = $in->getLong();
57 }
58}
static int $SYSTEM_ADDRESS_COUNT
Definition: RakLib.php:27
const ID_NEW_INCOMING_CONNECTION
RakPeer - A remote system has successfully connected.