Skip to content

packet

Utilities for EO packets.

AccountReplySequenceStart

Bases: SimpleSequenceStart

A class representing the sequence start value sent with the ACCOUNT_REPLY server packet.

See Also
Source code in src/eolib/packet/sequence_start.py
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
class AccountReplySequenceStart(SimpleSequenceStart):
    """
    A class representing the sequence start value sent with the `ACCOUNT_REPLY` server packet.

    See Also:
        - [`AccountReplyServerPacket`][eolib.protocol._generated.net.server.AccountReplyServerPacket]
    """

    def __init__(self, value: int):
        super().__init__(value)

    @staticmethod
    def from_value(value: int) -> 'AccountReplySequenceStart':
        """
        Creates an instance of AccountReplySequenceStart from the value sent with the
        `ACCOUNT_REPLY` server packet.

        Args:
            value (int): The sequence start value sent with the `ACCOUNT_REPLY` server packet.

        Returns:
            AccountReplySequenceStart: An instance of AccountReplySequenceStart.
        """
        return AccountReplySequenceStart(value)

    @staticmethod
    def generate() -> 'AccountReplySequenceStart':
        """
        Generates an instance of AccountReplySequenceStart with a random value in the range 0-240.

        Returns:
            AccountReplySequenceStart: An instance of AccountReplySequenceStart.
        """
        return AccountReplySequenceStart(random.randrange(0, 240))

__init__(value)

Source code in src/eolib/packet/sequence_start.py
49
50
def __init__(self, value: int):
    super().__init__(value)

from_value(value) staticmethod

Creates an instance of AccountReplySequenceStart from the value sent with the ACCOUNT_REPLY server packet.

Parameters:

Name Type Description Default
value int

The sequence start value sent with the ACCOUNT_REPLY server packet.

required

Returns:

Name Type Description
AccountReplySequenceStart AccountReplySequenceStart

An instance of AccountReplySequenceStart.

Source code in src/eolib/packet/sequence_start.py
52
53
54
55
56
57
58
59
60
61
62
63
64
@staticmethod
def from_value(value: int) -> 'AccountReplySequenceStart':
    """
    Creates an instance of AccountReplySequenceStart from the value sent with the
    `ACCOUNT_REPLY` server packet.

    Args:
        value (int): The sequence start value sent with the `ACCOUNT_REPLY` server packet.

    Returns:
        AccountReplySequenceStart: An instance of AccountReplySequenceStart.
    """
    return AccountReplySequenceStart(value)

generate() staticmethod

Generates an instance of AccountReplySequenceStart with a random value in the range 0-240.

Returns:

Name Type Description
AccountReplySequenceStart AccountReplySequenceStart

An instance of AccountReplySequenceStart.

Source code in src/eolib/packet/sequence_start.py
66
67
68
69
70
71
72
73
74
@staticmethod
def generate() -> 'AccountReplySequenceStart':
    """
    Generates an instance of AccountReplySequenceStart with a random value in the range 0-240.

    Returns:
        AccountReplySequenceStart: An instance of AccountReplySequenceStart.
    """
    return AccountReplySequenceStart(random.randrange(0, 240))

InitSequenceStart

Bases: SimpleSequenceStart

A class representing the sequence start value sent with the INIT_INIT server packet.

See Also
Source code in src/eolib/packet/sequence_start.py
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
class InitSequenceStart(SimpleSequenceStart):
    """
    A class representing the sequence start value sent with the `INIT_INIT` server packet.

    See Also:
        - [`InitInitServerPacket`][eolib.protocol._generated.net.server.InitInitServerPacket]
    """

    _seq1: int
    _seq2: int

    def __init__(self, value: int, seq1: int, seq2: int):
        super().__init__(value)
        self._seq1 = seq1
        self._seq2 = seq2

    @property
    def seq1(self) -> int:
        """
        Returns the `seq1` byte value sent with the `INIT_INIT` server packet.

        Returns:
            int: The seq1 byte value.
        """
        return self._seq1

    @property
    def seq2(self) -> int:
        """
        Returns the `seq2` byte value sent with the `INIT_INIT` server packet.

        Returns:
            int: The seq2 byte value.
        """
        return self._seq2

    @staticmethod
    def from_init_values(seq1: int, seq2: int) -> 'InitSequenceStart':
        """
        Creates an instance of InitSequenceStart from the values sent with the `INIT_INIT` server
        packet.

        Args:
            seq1 (int): The `seq1` byte value sent with the `INIT_INIT` server packet.
            seq2 (int): The `seq2` byte value sent with the `INIT_INIT` server packet.

        Returns:
            InitSequenceStart: An instance of InitSequenceStart
        """
        value = seq1 * 7 + seq2 - 13
        return InitSequenceStart(value, seq1, seq2)

    @staticmethod
    def generate() -> 'InitSequenceStart':
        """
        Generates an instance of InitSequenceStart with a random value in the range 0-1757.

        Returns:
            InitSequenceStart: An instance of InitSequenceStart.
        """
        value = random.randrange(0, 1757)
        seq1_max = int((value + 13) / 7)
        seq1_min = max(0, int((value - (CHAR_MAX - 1) + 13 + 6) / 7))

        seq1 = random.randrange(0, seq1_max - seq1_min) + seq1_min
        seq2 = value - seq1 * 7 + 13

        return InitSequenceStart(value, seq1, seq2)

seq1: int property

Returns the seq1 byte value sent with the INIT_INIT server packet.

Returns:

Name Type Description
int int

The seq1 byte value.

seq2: int property

Returns the seq2 byte value sent with the INIT_INIT server packet.

Returns:

Name Type Description
int int

The seq2 byte value.

__init__(value, seq1, seq2)

Source code in src/eolib/packet/sequence_start.py
88
89
90
91
def __init__(self, value: int, seq1: int, seq2: int):
    super().__init__(value)
    self._seq1 = seq1
    self._seq2 = seq2

from_init_values(seq1, seq2) staticmethod

Creates an instance of InitSequenceStart from the values sent with the INIT_INIT server packet.

Parameters:

Name Type Description Default
seq1 int

The seq1 byte value sent with the INIT_INIT server packet.

required
seq2 int

The seq2 byte value sent with the INIT_INIT server packet.

required

Returns:

Name Type Description
InitSequenceStart InitSequenceStart

An instance of InitSequenceStart

Source code in src/eolib/packet/sequence_start.py
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
@staticmethod
def from_init_values(seq1: int, seq2: int) -> 'InitSequenceStart':
    """
    Creates an instance of InitSequenceStart from the values sent with the `INIT_INIT` server
    packet.

    Args:
        seq1 (int): The `seq1` byte value sent with the `INIT_INIT` server packet.
        seq2 (int): The `seq2` byte value sent with the `INIT_INIT` server packet.

    Returns:
        InitSequenceStart: An instance of InitSequenceStart
    """
    value = seq1 * 7 + seq2 - 13
    return InitSequenceStart(value, seq1, seq2)

generate() staticmethod

Generates an instance of InitSequenceStart with a random value in the range 0-1757.

Returns:

Name Type Description
InitSequenceStart InitSequenceStart

An instance of InitSequenceStart.

Source code in src/eolib/packet/sequence_start.py
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
@staticmethod
def generate() -> 'InitSequenceStart':
    """
    Generates an instance of InitSequenceStart with a random value in the range 0-1757.

    Returns:
        InitSequenceStart: An instance of InitSequenceStart.
    """
    value = random.randrange(0, 1757)
    seq1_max = int((value + 13) / 7)
    seq1_min = max(0, int((value - (CHAR_MAX - 1) + 13 + 6) / 7))

    seq1 = random.randrange(0, seq1_max - seq1_min) + seq1_min
    seq2 = value - seq1 * 7 + 13

    return InitSequenceStart(value, seq1, seq2)

PingSequenceStart

Bases: SimpleSequenceStart

A class representing the sequence start value sent with the CONNECTION_PLAYER server packet.

See Also
Source code in src/eolib/packet/sequence_start.py
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
class PingSequenceStart(SimpleSequenceStart):
    """
    A class representing the sequence start value sent with the `CONNECTION_PLAYER` server packet.

    See Also:
        - [`ConnectionPlayerServerPacket`][eolib.protocol._generated.net.server.ConnectionPlayerServerPacket]
    """

    def __init__(self, value: int, seq1: int, seq2: int):
        super().__init__(value)
        self._seq1 = seq1
        self._seq2 = seq2

    @property
    def seq1(self) -> int:
        """
        Returns the seq1 short value sent with the `CONNECTION_PLAYER` server packet.

        Returns:
            int: The seq1 short value.
        """
        return self._seq1

    @property
    def seq2(self) -> int:
        """
        Returns the seq2 char value sent with the `CONNECTION_PLAYER` server packet.

        Returns:
            int: The seq2 char value.
        """
        return self._seq2

    @staticmethod
    def from_ping_values(seq1: int, seq2: int) -> 'PingSequenceStart':
        """
        Creates an instance of PingSequenceStart from the values sent with the `CONNECTION_PLAYER`
        server packet.

        Args:
            seq1 (int): The `seq1` short value sent with the `CONNECTION_PLAYER` server packet.
            seq2 (int): The `seq2` char value sent with the `CONNECTION_PLAYER` server packet.

        Returns:
            PingSequenceStart: An instance of PingSequenceStart.
        """
        value = seq1 - seq2
        return PingSequenceStart(value, seq1, seq2)

    @staticmethod
    def generate() -> 'PingSequenceStart':
        """
        Generates an instance of PingSequenceStart with a random value in the range 0-1757.

        Returns:
            PingSequenceStart: An instance of PingSequenceStart.
        """
        value = random.randrange(0, 1757)
        seq1 = value + random.randrange(0, CHAR_MAX - 1)
        seq2 = seq1 - value

        return PingSequenceStart(value, seq1, seq2)

seq1: int property

Returns the seq1 short value sent with the CONNECTION_PLAYER server packet.

Returns:

Name Type Description
int int

The seq1 short value.

seq2: int property

Returns the seq2 char value sent with the CONNECTION_PLAYER server packet.

Returns:

Name Type Description
int int

The seq2 char value.

__init__(value, seq1, seq2)

Source code in src/eolib/packet/sequence_start.py
155
156
157
158
def __init__(self, value: int, seq1: int, seq2: int):
    super().__init__(value)
    self._seq1 = seq1
    self._seq2 = seq2

from_ping_values(seq1, seq2) staticmethod

Creates an instance of PingSequenceStart from the values sent with the CONNECTION_PLAYER server packet.

Parameters:

Name Type Description Default
seq1 int

The seq1 short value sent with the CONNECTION_PLAYER server packet.

required
seq2 int

The seq2 char value sent with the CONNECTION_PLAYER server packet.

required

Returns:

Name Type Description
PingSequenceStart PingSequenceStart

An instance of PingSequenceStart.

Source code in src/eolib/packet/sequence_start.py
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
@staticmethod
def from_ping_values(seq1: int, seq2: int) -> 'PingSequenceStart':
    """
    Creates an instance of PingSequenceStart from the values sent with the `CONNECTION_PLAYER`
    server packet.

    Args:
        seq1 (int): The `seq1` short value sent with the `CONNECTION_PLAYER` server packet.
        seq2 (int): The `seq2` char value sent with the `CONNECTION_PLAYER` server packet.

    Returns:
        PingSequenceStart: An instance of PingSequenceStart.
    """
    value = seq1 - seq2
    return PingSequenceStart(value, seq1, seq2)

generate() staticmethod

Generates an instance of PingSequenceStart with a random value in the range 0-1757.

Returns:

Name Type Description
PingSequenceStart PingSequenceStart

An instance of PingSequenceStart.

Source code in src/eolib/packet/sequence_start.py
196
197
198
199
200
201
202
203
204
205
206
207
208
@staticmethod
def generate() -> 'PingSequenceStart':
    """
    Generates an instance of PingSequenceStart with a random value in the range 0-1757.

    Returns:
        PingSequenceStart: An instance of PingSequenceStart.
    """
    value = random.randrange(0, 1757)
    seq1 = value + random.randrange(0, CHAR_MAX - 1)
    seq2 = seq1 - value

    return PingSequenceStart(value, seq1, seq2)

SequenceStart

Bases: ABC

A value sent by the server to update the client's sequence start, also known as the 'starting counter ID'.

Source code in src/eolib/packet/sequence_start.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class SequenceStart(ABC):
    """
    A value sent by the server to update the client's sequence start, also known as the 'starting
    counter ID'.
    """

    @abstractproperty
    def value(self) -> int:
        """
        int: Gets the sequence start value.
        """
        raise NotImplementedError()

    @staticmethod
    def zero() -> 'SequenceStart':
        """
        Returns an instance of SequenceStart with a value of 0.

        Returns:
            SequenceStart: An instance of SequenceStart.
        """
        return SimpleSequenceStart(0)

value()

int: Gets the sequence start value.

Source code in src/eolib/packet/sequence_start.py
12
13
14
15
16
17
@abstractproperty
def value(self) -> int:
    """
    int: Gets the sequence start value.
    """
    raise NotImplementedError()

zero() staticmethod

Returns an instance of SequenceStart with a value of 0.

Returns:

Name Type Description
SequenceStart SequenceStart

An instance of SequenceStart.

Source code in src/eolib/packet/sequence_start.py
19
20
21
22
23
24
25
26
27
@staticmethod
def zero() -> 'SequenceStart':
    """
    Returns an instance of SequenceStart with a value of 0.

    Returns:
        SequenceStart: An instance of SequenceStart.
    """
    return SimpleSequenceStart(0)

PacketSequencer

A class for generating packet sequences.

Source code in src/eolib/packet/packet_sequencer.py
 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
class PacketSequencer:
    """A class for generating packet sequences."""

    _start: SequenceStart
    _counter: int

    def __init__(self, start: SequenceStart):
        """
        Constructs a new PacketSequencer with the provided SequenceStart.

        Args:
            start (SequenceStart): The sequence start.
        """
        self._start = start
        self._counter = 0

    def next_sequence(self) -> int:
        """
        Returns the next sequence value, updating the sequence counter in the process.

        Note:
            This is not a monotonic operation. The sequence counter increases from 0 to 9 before
            looping back around to 0.

        Returns:
            int: The next sequence value.
        """
        result = self._start.value + self._counter
        self._counter = (self._counter + 1) % 10
        return result

    def set_sequence_start(self, start: SequenceStart) -> None:
        """
        Sets the sequence start, also known as the "starting counter ID".

        Note:
            This does not reset the sequence counter.

        Args:
            start (SequenceStart): The new sequence start.
        """
        self._start = start

__init__(start)

Constructs a new PacketSequencer with the provided SequenceStart.

Parameters:

Name Type Description Default
start SequenceStart

The sequence start.

required
Source code in src/eolib/packet/packet_sequencer.py
10
11
12
13
14
15
16
17
18
def __init__(self, start: SequenceStart):
    """
    Constructs a new PacketSequencer with the provided SequenceStart.

    Args:
        start (SequenceStart): The sequence start.
    """
    self._start = start
    self._counter = 0

next_sequence()

Returns the next sequence value, updating the sequence counter in the process.

Note

This is not a monotonic operation. The sequence counter increases from 0 to 9 before looping back around to 0.

Returns:

Name Type Description
int int

The next sequence value.

Source code in src/eolib/packet/packet_sequencer.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
def next_sequence(self) -> int:
    """
    Returns the next sequence value, updating the sequence counter in the process.

    Note:
        This is not a monotonic operation. The sequence counter increases from 0 to 9 before
        looping back around to 0.

    Returns:
        int: The next sequence value.
    """
    result = self._start.value + self._counter
    self._counter = (self._counter + 1) % 10
    return result

set_sequence_start(start)

Sets the sequence start, also known as the "starting counter ID".

Note

This does not reset the sequence counter.

Parameters:

Name Type Description Default
start SequenceStart

The new sequence start.

required
Source code in src/eolib/packet/packet_sequencer.py
35
36
37
38
39
40
41
42
43
44
45
def set_sequence_start(self, start: SequenceStart) -> None:
    """
    Sets the sequence start, also known as the "starting counter ID".

    Note:
        This does not reset the sequence counter.

    Args:
        start (SequenceStart): The new sequence start.
    """
    self._start = start