PocketMine-MP 5.15.1 git-5ef247620a7c6301a849b54e5ef1009217729fc8
InternetAddress.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\utils;
18
19final class InternetAddress{
20 public function __construct(
21 private string $ip,
22 private int $port,
23 private int $version
24 ){
25 if($port < 0 or $port > 65535){
26 throw new \InvalidArgumentException("Invalid port range");
27 }
28 }
29
30 public function getIp() : string{
31 return $this->ip;
32 }
33
34 public function getPort() : int{
35 return $this->port;
36 }
37
38 public function getVersion() : int{
39 return $this->version;
40 }
41
42 public function __toString(){
43 return $this->ip . " " . $this->port;
44 }
45
46 public function toString() : string{
47 return $this->__toString();
48 }
49
50 public function equals(InternetAddress $address) : bool{
51 return $this->ip === $address->ip and $this->port === $address->port and $this->version === $address->version;
52 }
53}