From 8388bee4d1b8ca5210f51d4262f9aedc3bb5b72b Mon Sep 17 00:00:00 2001 From: VirxEC Date: Wed, 21 Apr 2021 17:01:49 -0400 Subject: [PATCH 1/3] Version bump + more flexible packet parsing --- setup.py | 2 +- tmcp/__init__.py | 2 +- tmcp/handler.py | 3 --- tmcp/message.py | 23 +++++++++++++++-------- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/setup.py b/setup.py index 04ddb9e..4e77a93 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( name="tmcp", packages=["tmcp"], - version="0.9.1", + version="0.1.0", license="MIT", description="Helper classes for the Team Match Communication Protocol.", long_description=long_description, diff --git a/tmcp/__init__.py b/tmcp/__init__.py index b92b1f9..12b29b7 100644 --- a/tmcp/__init__.py +++ b/tmcp/__init__.py @@ -1,3 +1,3 @@ -TMCP_VERSION = [0, 9] +TMCP_VERSION = [1, 0] from tmcp.handler import TMCPHandler from tmcp.message import TMCPMessage, ActionType diff --git a/tmcp/handler.py b/tmcp/handler.py index 0b4cdf7..917d760 100644 --- a/tmcp/handler.py +++ b/tmcp/handler.py @@ -92,9 +92,6 @@ def recv(self) -> List[TMCPMessage]: return messages def parse(self, message: dict) -> Optional[TMCPMessage]: - # Ignore messages using a different version of the protocol. - if message.get("tmcp_version") != TMCP_VERSION: - return None # Ignore messages by opposing team. if message.get("team") != self.team: return None diff --git a/tmcp/message.py b/tmcp/message.py index db83e97..787b471 100644 --- a/tmcp/message.py +++ b/tmcp/message.py @@ -78,28 +78,35 @@ def from_dict(cls, message: dict) -> Optional["TMCPMessage"]: assert isinstance(team, int) assert isinstance(index, int) + version = message["tmcp_version"] + assert isinstance(version, (list, tuple)) + assert len(version) == 2 + action: dict = message["action"] - action_type: ActionType = ActionType(action["type"]) + action_type: ActionType = ActionType(action["type"].upper()) if action_type == ActionType.BALL: - assert isinstance(action["time"], (float, int)) - direction = action["direction"] + action_time = action.get("time", -1) + assert isinstance(action_time, (float, int)) + direction = action.get("direction", [0.0, 0.0, 0.0]) assert isinstance(direction, (list, tuple)) assert len(direction) in (2, 3) assert all(isinstance(elem, (int, float)) for elem in direction) - msg = cls.ball_action(team, index, float(action["time"]), direction) + msg = cls.ball_action(team, index, float(action_time), direction) elif action_type == ActionType.BOOST: assert isinstance(action["target"], int) msg = cls.boost_action(team, index, action["target"]) elif action_type == ActionType.DEMO: assert isinstance(action["target"], int) - assert isinstance(action["time"], (float, int)) + action_time = action.get("time", -1) + assert isinstance(action_time, (float, int)) msg = cls.demo_action( - team, index, action["target"], float(action["time"]) + team, index, action["target"], float(action_time) ) elif action_type == ActionType.READY: - assert isinstance(action["time"], (float, int)) - msg = cls.ready_action(team, index, float(action["time"])) + action_time = action.get("time", -1) + assert isinstance(action_time, (float, int)) + msg = cls.ready_action(team, index, float(action_time)) elif action_type == ActionType.DEFEND: msg = cls.defend_action(team, index) else: From 19df5dfbea114d59d35b3e15752d9115391e19eb Mon Sep 17 00:00:00 2001 From: VirxEC Date: Wed, 21 Apr 2021 17:13:33 -0400 Subject: [PATCH 2/3] Make direction always be 3 items long README changes setup.py changes --- README.md | 9 +++++---- setup.py | 4 ++-- tmcp/message.py | 1 + 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ee0cd86..c6e3671 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # tmcp + ## Helper classes for the Team Match Communication Protocol Learn more about [TMCP](https://github.com/RLBot/RLBot/wiki/Team-Match-Communication-Protocol). @@ -63,15 +64,15 @@ if self.backlog: self.backlog.insert(0, backlog_message) ``` -## Avoiding breaking changes +## Avoiding major breaking changes This package is regularly updated according to the latest TMCP specification. -To avoid your bot breaking during tournaments, you can use a virtual_environment and pin a specific version of this package. +To avoid your bot breaking during tournaments due to major version updates, you can use a virtual_environment and pin a specific version of this package. In your requirements.txt: ```txt -tmcp==0.9 +tmcp==1.* ``` In your bot.cfg: @@ -88,6 +89,6 @@ This will not send or receive any messages, but will pretend as if it was sendin ```py from tmcp import TMCP_VERSION -if TMCP_VERSION != [0, 9]: +if TMCP_VERSION[0] != 1: my_handler.disable() ``` diff --git a/setup.py b/setup.py index 4e77a93..9194345 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( name="tmcp", packages=["tmcp"], - version="0.1.0", + version="1.0.0", license="MIT", description="Helper classes for the Team Match Communication Protocol.", long_description=long_description, @@ -14,7 +14,7 @@ author="Viliam Vadocz", author_email="viliam.vadocz@gmail.com", url="https://github.com/ViliamVadocz/tmcp/", - download_url="https://github.com/ViliamVadocz/tmcp/archive/v_0_9_1.tar.gz", + download_url="https://github.com/ViliamVadocz/tmcp/archive/v_1_0_0.tar.gz", keywords=["RLBot", "protocol"], install_requires=["rlbot"], classifiers=[ diff --git a/tmcp/message.py b/tmcp/message.py index 787b471..bd7425f 100644 --- a/tmcp/message.py +++ b/tmcp/message.py @@ -91,6 +91,7 @@ def from_dict(cls, message: dict) -> Optional["TMCPMessage"]: direction = action.get("direction", [0.0, 0.0, 0.0]) assert isinstance(direction, (list, tuple)) assert len(direction) in (2, 3) + if len(direction) == 2: direction.append(0.0) assert all(isinstance(elem, (int, float)) for elem in direction) msg = cls.ball_action(team, index, float(action_time), direction) elif action_type == ActionType.BOOST: From 95c7f3ae1677fb00397df34b11035b8888c7b8bf Mon Sep 17 00:00:00 2001 From: VirxEC Date: Sat, 24 Apr 2021 13:06:51 -0400 Subject: [PATCH 3/3] Fix bug --- tmcp/message.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tmcp/message.py b/tmcp/message.py index bd7425f..8ef0bfd 100644 --- a/tmcp/message.py +++ b/tmcp/message.py @@ -91,7 +91,8 @@ def from_dict(cls, message: dict) -> Optional["TMCPMessage"]: direction = action.get("direction", [0.0, 0.0, 0.0]) assert isinstance(direction, (list, tuple)) assert len(direction) in (2, 3) - if len(direction) == 2: direction.append(0.0) + if len(direction) == 2: + direction = [direction[0], direction[1], 0.0] assert all(isinstance(elem, (int, float)) for elem in direction) msg = cls.ball_action(team, index, float(action_time), direction) elif action_type == ActionType.BOOST: