-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPacket.php
52 lines (40 loc) · 1.08 KB
/
Packet.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
declare(strict_types=1);
require_once('VO/InfoType.php');
final class Packet
{
/**
* @var Server
*/
private $server;
/**
* @var InfoType
*/
private $infoType;
/**
* @var string
*/
private $payload;
public function __construct(Server $server, InfoType $infoType, ?string $payload = null) {
$this->server = $server;
$this->infoType = $infoType;
$this->payload = $payload;
}
public function __toString(): string {
return $this->getHeader($this->infoType) . $this->getPayload();
}
public function getHeader(InfoType $infoType): string {
$header = 'SAMP';
$octets = explode('.', $this->server->getHost());
foreach($octets as $octet) {
$header .= chr($octet);
}
$header .= chr($this->server->getPort() & 0xFF);
$header .= chr($this->server->getPort() >> 8 & 0xFF);
$header .= $infoType->getType();
return $header;
}
public function getPayload(): string {
return $this->payload ?? '';
}
}