Skip to content

Commit

Permalink
TMCP 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ViliamVadocz authored Apr 24, 2021
2 parents e97c0c7 + 95c7f3a commit 8a8d361
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 18 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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).
Expand Down Expand Up @@ -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:
Expand All @@ -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()
```
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
setup(
name="tmcp",
packages=["tmcp"],
version="0.9.1",
version="1.0.0",
license="MIT",
description="Helper classes for the Team Match Communication Protocol.",
long_description=long_description,
long_description_content_type="text/markdown",
author="Viliam Vadocz",
author_email="[email protected]",
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=[
Expand Down
2 changes: 1 addition & 1 deletion tmcp/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
TMCP_VERSION = [0, 9]
TMCP_VERSION = [1, 0]
from tmcp.handler import TMCPHandler
from tmcp.message import TMCPMessage, ActionType
3 changes: 0 additions & 3 deletions tmcp/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 17 additions & 8 deletions tmcp/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,28 +78,37 @@ 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)
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)
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:
Expand Down

0 comments on commit 8a8d361

Please sign in to comment.