LttP: Implement DeathLink

This commit is contained in:
Fabian Dill
2021-11-01 19:37:47 +01:00
parent 8ff01ca979
commit 0e0cc0ad16
7 changed files with 99 additions and 50 deletions

View File

@@ -5,6 +5,7 @@ import urllib.parse
import sys
import os
import typing
import time
import websockets
@@ -135,6 +136,8 @@ class CommonContext():
self.input_queue = asyncio.Queue()
self.input_requests = 0
self.last_death_link: float = time.time() # last send/received death link on AP layer
# game state
self.player_names: typing.Dict[int: str] = {0: "Archipelago"}
self.exit_event = asyncio.Event()
@@ -256,6 +259,20 @@ class CommonContext():
except Exception as e: # safeguard against permissions that may be implemented in the future
logger.exception(e)
def on_deathlink(self, data: dict):
"""Gets dispatched when a new DeathLink is triggered by another linked player."""
raise NotImplementedError
async def send_death(self):
self.last_death_link = time.time()
await self.send_msgs([{
"cmd": "Bounce", "tags": ["DeathLink"],
"data": {
"time": self.last_death_link,
"source": self.player_names[self.slot]
}
}])
async def keep_alive(ctx: CommonContext, seconds_between_checks=100):
"""some ISPs/network configurations drop TCP connections if no payload is sent (ignore TCP-keep-alive)
@@ -461,7 +478,9 @@ async def process_server_cmd(ctx: CommonContext, args: dict):
logger.warning(f"Invalid Packet of {args['type']}: {args['text']}")
elif cmd == "Bounced":
pass
tags = args.get("tags", [])
if "DeathLink" in tags and ctx.last_death_link != args["data"]["time"]:
ctx.on_deathlink(args["data"])
else:
logger.debug(f"unknown command {cmd}")