PocketMine-MP 5.15.1 git-5ef247620a7c6301a849b54e5ef1009217729fc8
PacketReliability.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
19abstract class PacketReliability{
20
21 /*
22 * From https://github.com/OculusVR/RakNet/blob/master/Source/PacketPriority.h
23 *
24 * Default: 0b010 (2) or 0b011 (3)
25 */
26
27 public const UNRELIABLE = 0;
28 public const UNRELIABLE_SEQUENCED = 1;
29 public const RELIABLE = 2;
30 public const RELIABLE_ORDERED = 3;
31 public const RELIABLE_SEQUENCED = 4;
32
33 /* The following reliabilities are used in RakNet internals, but never sent on the wire. */
34 public const UNRELIABLE_WITH_ACK_RECEIPT = 5;
35 public const RELIABLE_WITH_ACK_RECEIPT = 6;
36 public const RELIABLE_ORDERED_WITH_ACK_RECEIPT = 7;
37
38 public const MAX_ORDER_CHANNELS = 32;
39
40 public static function isReliable(int $reliability) : bool{
41 return (
42 $reliability === self::RELIABLE or
43 $reliability === self::RELIABLE_ORDERED or
44 $reliability === self::RELIABLE_SEQUENCED or
45 $reliability === self::RELIABLE_WITH_ACK_RECEIPT or
46 $reliability === self::RELIABLE_ORDERED_WITH_ACK_RECEIPT
47 );
48 }
49
50 public static function isSequenced(int $reliability) : bool{
51 return (
52 $reliability === self::UNRELIABLE_SEQUENCED or
53 $reliability === self::RELIABLE_SEQUENCED
54 );
55 }
56
57 public static function isOrdered(int $reliability) : bool{
58 return (
59 $reliability === self::RELIABLE_ORDERED or
60 $reliability === self::RELIABLE_ORDERED_WITH_ACK_RECEIPT
61 );
62 }
63
64 public static function isSequencedOrOrdered(int $reliability) : bool{
65 return (
66 $reliability === self::UNRELIABLE_SEQUENCED or
67 $reliability === self::RELIABLE_ORDERED or
68 $reliability === self::RELIABLE_SEQUENCED or
69 $reliability === self::RELIABLE_ORDERED_WITH_ACK_RECEIPT
70 );
71 }
72}