Commit Graph

26 Commits

Author SHA1 Message Date
joo 93db454cb5 Add test case reproducing #146 (fixed to behave consistently) 2020-12-04 17:06:39 +01:00
joo 7693961fb9 Let fake server tests override the default client exception handler
This can by done by adding an exception handler with `early=True'
in the `_start_client' method of a subclass of
`fake_server._FakeServerTest'.
2020-12-04 15:37:49 +01:00
joo 969419da3f Fix: non-monotonic protocol versions are not correctly handled
After 1.16.3, Mojang started publishing snapshot, pre-release and release
candidate versions of Minecraft with protocol version numbers of the form
`(1 << 30) | n' where 'n' is a small non-negative integer increasing with each
such version; the release versions continued to use the old format. For
example, these are the last 8 published Minecraft versions as of this commit:

release           1.16.3      uses protocol version 753
pre-release       1.16.4-pre1 uses protocol version 1073741825 == (1 << 30) | 1
pre-release       1.16.4-pre2 uses protocol version 1073741826 == (1 << 30) | 2
release candidate 1.16.4-rc1  uses protocol version 1073741827 == (1 << 30) | 3
release           1.16.4      uses protocol version 754
snapshot          20w45a      uses protocol version 1073741829 == (1 << 30) | 5
snapshot          20w46a      uses protocol version 1073741830 == (1 << 30) | 6
snapshot          20w48a      uses protocol version 1073741831 == (1 << 30) | 7

This means that protocol versions no longer increase monotonically with respect
to publication history, a property that was assumed to hold in much of
pyCraft's code relating to support of multiple protocol versions. This commit
rectifies the issue by replacing any comparison of protocol versions by their
numerical value with a comparison based on their publication time.

Newly defined is the dictionary `minecraft.PROTOCOL_VERSION_INDICES', which
maps each known protocol version to its index in the protocol chronology. As
such, the bound method `minecraft.PROTOCOL_VERSION_INDICES.get` can be used as
a key function for the built-in `sorted`, `min` and `max` functions to collate
protocol versions chronologically.

Two utility functions are provided for direct comparison of protocol versions:
    `minecraft.utility.protocol_earlier` and
    `minecraft.utility.protocol_earlier_eq`.

Additionally, four methods are added to the `ConnectionContext` type to ease
the most common cases where the protocol of a given context must be compared to
a given version number:
    `minecraft.connection.ConnectionContext.protocol_earlier`,
    `minecraft.connection.ConnectionContext.protocol_earlier_eq`,
    `minecraft.connection.ConnectionContext.protocol_later` and
    `minecraft.connection.ConnectionContext.protocol_later_eq`.
2020-12-02 15:11:39 +01:00
joo b79f8b30eb Remove support for Python 2.7 2020-08-17 07:10:10 +02:00
joodicator 7b1567c352 Improve test coverage wrt protocol versions; other fixes/improvements
Improvements to the test suite:
* List release version names and numbers in minecraft/__init__.py.
* Make some tests, which previously ran for *all* protocol versions,
  run only for release protocol versions (to improve test performance).
* Make some tests, which previously ran only for the latest protocol
  version, run for all release protocol versions (to improve coverage).
* Print each protocol version being tested to the debug log, to help
  identify sources of errors.
* Use the `nose-timer' plugin to show the run time of each test.

Fix errors revealed by increased test coverage:
* Fix: SoundEffectPacket.Pitch is not serialised correctly for early
  protocol versions.
* Fix: handleExceptionTest finishes later than necessary because
  the test overrode an exception handler used internally by
  `_FakeServerTest', causing the server thread to time out after 4s.
* Add support for multiple exception handlers in `Connection'
  (required for the above).

Improvements to data descriptors:
* Make syntax of property declarations more consistent/Pythonic.
* Factor the definition of several aliasing properties into the
  utility methods `attribute_alias' and `multi_attribute_alias',
  which construct suitable data descriptors.
* Define and use the named tuple `Direction' for (pitch, yaw) values.
2019-05-14 18:41:58 +02:00
joodicator 41ea36c642 Add test coverage for @listener. 2019-05-13 19:04:35 +02:00
joodicator 612fa8e324 Add support for Minecraft 18w43a to 1.14 (protocols 441 to 477)
This commit introduces two backward-incompatible changes which may break
existing code:

(1) `networking.packets.clientbound.play.SpawnObjectPacket.EntityType'
is no longer accessible as an attribute of the the `SpawnObjectPacket'
class: the values now depend on a `ConnectionContext`, and must be
accessed through an instance, or using `SpawnObjectPacket.field_enum'.
See the text of the `AttributeError` raised from the descriptor for
`SpawnObjectPacket.EntityType` for the full details.

(2) For some subclasses of `networking.types.Type', it is necessary to
call the methods `read_with_context' and `send_with_context' instead of
`read' and `send', supplying a `ConnectionContext' for those data types
- currently only `Position` - whose layout depends on it.
2019-05-11 08:43:51 +02:00
joo 48e1003f42 Fix issue #109 and add regression test. 2018-10-12 17:07:04 +01:00
joo adc8d15ddc Add support for Minecraft 1.13 and 1.13-pre3 to pre10 (protocols 385 to 393).
Add clientbound.login.PluginRequestPacket and serverbound.login.PluginResponsePacket.
2018-07-19 09:50:13 +01:00
joo d36a4170ed Add tests for various Connection edge cases. 2018-05-29 01:14:46 +01:00
joo 92f2eff681 Add several tests for the Connection class. 2018-05-27 07:40:13 +01:00
joo 3269a022a8 Add KeepAlivePacket test to ConnectTest and derived tests. 2017-08-22 18:16:07 +01:00
joo b79e7b5f28 Add tests for early and outgoing packet listeners. 2017-08-22 17:50:16 +01:00
joo 9497aae8fa Make FakeServer class more reusable, and extract it into its own module. 2017-08-22 14:22:12 +01:00
joo 593c98f168 Add support for early and outgoing packet listeners. 2017-08-21 21:06:28 +01:00
joo 46e058dd08 Update all tests, docs and code to use new packet names. 2017-08-09 20:53:54 +01:00
joo cf464d2da2 Add compression tests to test_connection. 2017-08-03 13:04:47 +01:00
Ammar Askar ca4fd6680e
Connect to localhost instead of the socket's binding address.
The bound address is 0.0.0.0 which usually implies all
available interfaces, which makes sense when listening
for something. However, when connecting to an address,
a specific address needs to be targeted. Hopefully, any
properly configured computer should have `localhost`
pointing to its loopback interface. Fixes #64
2017-07-16 00:19:30 -07:00
joo bf17f99083 Change version negotiator to use a status query. 2016-11-22 14:47:42 +00:00
joo d72f05c8b0 Show exceptions by default and add `handle_exception' parameter to Connection. 2016-11-20 06:04:22 +00:00
joo 115693f8c3 Implement full Server List Ping capability with test. 2016-11-20 06:04:22 +00:00
joo bb1de5ca21 test_connection: fix timing issues caused by resource leaks. 2016-09-01 23:32:51 +01:00
joo abd2ee774c Add thread timeout detection to test_connection. 2016-08-22 18:20:16 +01:00
joo 9af39f186a Make test_connection more deterministic. 2016-08-22 17:46:53 +01:00
joo ce63626bb1 Add 4 tests in 'test_connection.py' and fix related bugs. 2016-06-18 18:22:18 +01:00
Ammar Askar 5d56162300 Quick little base test for connection 2015-04-03 22:04:45 +05:00