Skip to content

Commit

Permalink
Merge branch 'v1.16' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
joodicator committed Aug 19, 2020
2 parents 095191a + 2d9479c commit 3c84c2a
Show file tree
Hide file tree
Showing 33 changed files with 835 additions and 335 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,8 @@ target/
# sftp configuration file
sftp-config.json

### Visual Studio
.vscode

### pyCraft ###
credentials
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ python: 3.8

matrix:
include:
- python: 2.7
env: TOX_ENV=py27
- python: pypy
- python: pypy3
env: TOX_ENV=pypy
- python: 3.5
env: TOX_ENV=py35
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pyCraft is compatible with the following Minecraft releases:
* 1.13, 1.13.1, 1.13.2
* 1.14, 1.14.1, 1.14.2, 1.14.3, 1.14.4
* 1.15, 1.15.1, 1.15.2
* 1.16, 1.16.1, 1.16.2

In addition, some development snapshots and pre-release versions are supported:
`<minecraft/__init__.py>`_ contains a full list of supported Minecraft versions
Expand All @@ -50,7 +51,6 @@ Supported Python versions
-------------------------
pyCraft is compatible with (at least) the following Python implementations:

* Python 2.7
* Python 3.5
* Python 3.6
* Python 3.7
Expand All @@ -61,7 +61,7 @@ Requirements
------------
- `cryptography <https://github.com/pyca/cryptography#cryptography>`_
- `requests <http://docs.python-requests.org/en/latest/>`_
- `future <http://python-future.org/>`_
- `PyNBT <https://github.com/TkTech/PyNBT>`_

The requirements are also stored in ``setup.py``

Expand Down
80 changes: 72 additions & 8 deletions minecraft/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""

# The version number of the most recent pyCraft release.
__version__ = "0.6.0"
__version__ = "0.7.0"

# A dict mapping the ID string of each Minecraft version supported by pyCraft
# to the corresponding protocol version number. The ID string of a version is
Expand Down Expand Up @@ -225,20 +225,84 @@
'1.15.2-pre1': 576,
'1.15.2-pre2': 577,
'1.15.2': 578,
'20w06a': 701,
'20w07a': 702,
'20w08a': 703,
'20w09a': 704,
'20w10a': 705,
'20w11a': 706,
'20w12a': 707,
'20w13a': 708,
'20w13b': 709,
'20w14a': 710,
'20w15a': 711,
'20w16a': 712,
'20w17a': 713,
'20w18a': 714,
'20w19a': 715,
'20w20a': 716,
'20w20b': 717,
'20w21a': 718,
'20w22a': 719,
'1.16-pre1': 721,
'1.16-pre2': 722,
'1.16-pre3': 725,
'1.16-pre4': 727,
'1.16-pre5': 729,
'1.16-pre6': 730,
'1.16-pre7': 732,
'1.16-pre8': 733,
'1.16-rc1': 734,
'1.16': 735,
'1.16.1': 736,
'20w27a': 738,
'20w28a': 740,
'20w29a': 741,
'20w30a': 743,
'1.16.2-pre1': 744,
'1.16.2-pre2': 746,
'1.16.2-pre3': 748,
'1.16.2-rc1': 749,
'1.16.2-rc2': 750,
'1.16.2': 751,
}

# Those Minecraft versions supported by pyCraft which are "release" versions,
# i.e. not development snapshots or pre-release versions.
RELEASE_MINECRAFT_VERSIONS = {
vid: protocol for (vid, protocol) in SUPPORTED_MINECRAFT_VERSIONS.items()
if __import__('re').match(r'\d+(\.\d+)+$', vid)}
RELEASE_MINECRAFT_VERSIONS = {}

# The protocol versions of SUPPORTED_MINECRAFT_VERSIONS, without duplicates,
# in ascending numerical (and hence chronological) order.
SUPPORTED_PROTOCOL_VERSIONS = \
sorted(set(SUPPORTED_MINECRAFT_VERSIONS.values()))
SUPPORTED_PROTOCOL_VERSIONS = []

# The protocol versions of RELEASE_MINECRAFT_VERSIONS, without duplicates,
# in ascending numerical (and hence chronological) order.
RELEASE_PROTOCOL_VERSIONS = \
sorted(set(RELEASE_MINECRAFT_VERSIONS.values()))
RELEASE_PROTOCOL_VERSIONS = []


def initglobals():
'''Init the globals from the SUPPORTED_MINECRAFT_VERSIONS dict
This allows the SUPPORTED_MINECRAFT_VERSIONS dict to be updated, then the
other globals can be updated as well, to allow for dynamic version support.
All updates are done by reference to allow this to work else where in the
code.
'''
global RELEASE_MINECRAFT_VERSIONS, SUPPORTED_PROTOCOL_VERSIONS
global RELEASE_PROTOCOL_VERSIONS

import re

for (vid, protocol) in SUPPORTED_MINECRAFT_VERSIONS.items():
if re.match(r"\d+(\.\d+)+$", vid):
RELEASE_MINECRAFT_VERSIONS[vid] = protocol
if protocol not in RELEASE_PROTOCOL_VERSIONS:
RELEASE_PROTOCOL_VERSIONS.append(protocol)
if protocol not in SUPPORTED_PROTOCOL_VERSIONS:
SUPPORTED_PROTOCOL_VERSIONS.append(protocol)

SUPPORTED_PROTOCOL_VERSIONS.sort()
RELEASE_PROTOCOL_VERSIONS.sort()


initglobals()
24 changes: 0 additions & 24 deletions minecraft/compat.py

This file was deleted.

23 changes: 13 additions & 10 deletions minecraft/networking/connection.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import print_function

from collections import deque
from threading import RLock
import zlib
Expand All @@ -11,8 +9,6 @@
import json
import re

from future.utils import raise_

from .types import VarInt
from .packets import clientbound, serverbound
from . import packets
Expand Down Expand Up @@ -495,7 +491,8 @@ def _handle_exception(self, exc, exc_info):

# If allowed by the final exception handler, re-raise the exception.
if self.handle_exception is None and not caught:
raise_(*exc_info)
exc_value, exc_tb = exc_info[1:]
raise exc_value.with_traceback(exc_tb)

def _version_mismatch(self, server_protocol=None, server_version=None):
if server_protocol is None:
Expand All @@ -510,7 +507,10 @@ def _version_mismatch(self, server_protocol=None, server_version=None):
ss = 'supported, but not allowed for this connection' \
if server_protocol in SUPPORTED_PROTOCOL_VERSIONS \
else 'not supported'
raise VersionMismatch("Server's %s is %s." % (vs, ss))
err = VersionMismatch("Server's %s is %s." % (vs, ss))
err.server_protocol = server_protocol
err.server_version = server_version
raise err

def _handle_exit(self):
if not self.connected and self.handle_exit is not None:
Expand Down Expand Up @@ -593,7 +593,8 @@ def _run(self):
exc_info = None

if exc_info is not None:
raise_(*exc_info)
exc_value, exc_tb = exc_info[1:]
raise exc_value.with_traceback(exc_tb)


class PacketReactor(object):
Expand Down Expand Up @@ -644,14 +645,16 @@ def read_packet(self, stream, timeout=0):
packet_id = VarInt.read(packet_data)

# If we know the structure of the packet, attempt to parse it
# otherwise just skip it
# otherwise, just return an instance of the base Packet class.
if packet_id in self.clientbound_packets:
packet = self.clientbound_packets[packet_id]()
packet.context = self.connection.context
packet.read(packet_data)
return packet
else:
return packets.Packet(context=self.connection.context)
packet = packets.Packet()
packet.context = self.connection.context
packet.id = packet_id
return packet
else:
return None

Expand Down
9 changes: 5 additions & 4 deletions minecraft/networking/packets/clientbound/login/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from minecraft.networking.packets import Packet

from minecraft.networking.types import (
VarInt, String, VarIntPrefixedByteArray, TrailingByteArray
VarInt, String, VarIntPrefixedByteArray, TrailingByteArray, UUID,
)


Expand Down Expand Up @@ -54,9 +54,10 @@ def get_id(context):
0x02

packet_name = "login success"
definition = [
{'UUID': String},
{'Username': String}]
get_definition = staticmethod(lambda context: [
{'UUID': UUID if context.protocol_version >= 707 else String},
{'Username': String}
])


class SetCompressionPacket(Packet):
Expand Down
Loading

0 comments on commit 3c84c2a

Please sign in to comment.