From d25df447cc6858990555c0cae998797a08598d85 Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 12 Jun 2020 15:17:12 +0100 Subject: [PATCH] Move background task calls to their respective handler modules --- houdini/handlers/play/music.py | 5 +++++ houdini/handlers/play/pet.py | 2 ++ houdini/handlers/play/player.py | 6 ++++++ houdini/houdini.py | 11 ----------- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/houdini/handlers/play/music.py b/houdini/handlers/play/music.py index 7f6ca62..812d91a 100644 --- a/houdini/handlers/play/music.py +++ b/houdini/handlers/play/music.py @@ -157,6 +157,11 @@ def determine_song_length(track_pattern): return int(track_length, 16) // 1000 +@handlers.boot +async def music_service_start(server): + server.music = SoundStudio(server) + + @handlers.handler(XTPacket('musictrack', 'broadcastingmusictracks'), client=ClientType.Vanilla) @handlers.player_in_room(SoundStudio.StudioRoomId) async def handle_broadcasting_tracks(p): diff --git a/houdini/handlers/play/pet.py b/houdini/handlers/play/pet.py index a392732..73e2a74 100644 --- a/houdini/handlers/play/pet.py +++ b/houdini/handlers/play/pet.py @@ -231,6 +231,8 @@ async def puffles_load(server): server.puffle_furniture_treasure = await PuffleTreasureFurniture.query.gino.all() server.puffle_clothing_treasure = await PuffleTreasureItem.query.gino.all() + server.puffle_killer = asyncio.create_task(decrease_stats(server)) + @handlers.handler(XMLPacket('login'), priority=Priority.Low) @handlers.allow_once diff --git a/houdini/handlers/play/player.py b/houdini/handlers/play/player.py index 3d0ffe4..af9e8a3 100644 --- a/houdini/handlers/play/player.py +++ b/houdini/handlers/play/player.py @@ -68,6 +68,12 @@ async def server_egg_timer(server): await p.send_error_and_disconnect(910) +@handlers.boot +async def heartbeat_service_start(server): + server.heartbeat = asyncio.create_task(server_heartbeat(server)) + server.egg_timer = asyncio.create_task(server_egg_timer(server)) + + MemberWarningDaysToExpiry = 14 MemberWarningPostcardsVanilla = [122, 123] MemberWarningPostcardsLegacy = [163] diff --git a/houdini/houdini.py b/houdini/houdini.py index 95ea61c..1a52348 100644 --- a/houdini/houdini.py +++ b/houdini/houdini.py @@ -26,11 +26,6 @@ from houdini.handlers import XTListenerManager, XMLListenerManager, DummyEventLi from houdini.plugins import PluginManager from houdini.commands import CommandManager -from houdini.handlers.play.player import server_heartbeat, server_egg_timer -from houdini.handlers.play.pet import decrease_stats - -from houdini.handlers.play.music import SoundStudio - class Houdini: @@ -178,12 +173,6 @@ class Houdini: await self.plugins.setup(houdini.plugins) - self.heartbeat = asyncio.create_task(server_heartbeat(self)) - self.egg_timer = asyncio.create_task(server_egg_timer(self)) - self.puffle_killer = asyncio.create_task(decrease_stats(self)) - - self.music = SoundStudio(self) - async with self.server: await self.server.serve_forever()