mirror of
https://github.com/solero/houdini.git
synced 2024-11-25 15:07:24 +00:00
Add boot event listener
This event is fired when server has just started up, but before it is accepting connections. Also implement `fire()` method in `DummyEventListenerManager` for more easily firing custom events.
This commit is contained in:
parent
9bd7bada62
commit
9a4acade3f
@ -188,6 +188,13 @@ class XMLListenerManager(_ListenerManager):
|
||||
class DummyEventListenerManager(_ListenerManager):
|
||||
ListenerClass = _DummyListener
|
||||
|
||||
async def fire(self, event, *args, **kwargs):
|
||||
dummy_event = DummyEventPacket(event)
|
||||
if dummy_event in self.server.dummy_event_listeners:
|
||||
dummy_event_listeners = self.server.dummy_event_listeners[dummy_event]
|
||||
for listener in dummy_event_listeners:
|
||||
await listener(*args, **kwargs)
|
||||
|
||||
|
||||
def handler(packet, **kwargs):
|
||||
if not issubclass(type(packet), _Packet):
|
||||
@ -197,6 +204,7 @@ def handler(packet, **kwargs):
|
||||
return _listener(listener_class, packet, **kwargs)
|
||||
|
||||
|
||||
boot = _listener(_DummyListener, DummyEventPacket('boot'))
|
||||
connected = _listener(_DummyListener, DummyEventPacket('connected'))
|
||||
disconnected = _listener(_DummyListener, DummyEventPacket('disconnected'))
|
||||
|
||||
|
@ -173,14 +173,13 @@ class Houdini:
|
||||
|
||||
await self.xml_listeners.setup(houdini.handlers, exclude_load='houdini.handlers.login.login')
|
||||
await self.xt_listeners.setup(houdini.handlers)
|
||||
await self.dummy_event_listeners.setup(houdini.handlers)
|
||||
self.logger.info('World server started')
|
||||
else:
|
||||
await self.xml_listeners.setup(houdini.handlers, 'houdini.handlers.login.login')
|
||||
self.logger.info('Login server started')
|
||||
|
||||
self.items = await ItemCollection.get_collection()
|
||||
self.logger.info(f'Loaded {len(self.items)} clothing items')
|
||||
await self.dummy_event_listeners.setup(houdini.handlers)
|
||||
await self.dummy_event_listeners.fire('boot', self)
|
||||
|
||||
self.igloos = await IglooCollection.get_collection()
|
||||
self.logger.info(f'Loaded {len(self.igloos)} igloos')
|
||||
|
@ -6,7 +6,7 @@ import defusedxml.cElementTree as Et
|
||||
from xml.etree.cElementTree import Element, SubElement, tostring
|
||||
|
||||
from houdini.constants import ClientType
|
||||
from houdini.handlers import AuthorityError, DummyEventPacket
|
||||
from houdini.handlers import AuthorityError
|
||||
|
||||
|
||||
class Spheniscidae:
|
||||
@ -142,21 +142,13 @@ class Spheniscidae:
|
||||
async def _client_connected(self):
|
||||
self.logger.info(f'Client {self.peer_name} connected')
|
||||
|
||||
dummy_event = DummyEventPacket('connected')
|
||||
if dummy_event in self.server.dummy_event_listeners:
|
||||
dummy_event_listeners = self.server.dummy_event_listeners[dummy_event]
|
||||
for listener in dummy_event_listeners:
|
||||
await listener(self)
|
||||
await self.server.dummy_event_listeners.fire('connected', self)
|
||||
|
||||
async def _client_disconnected(self):
|
||||
del self.server.peers_by_ip[self.peer_name]
|
||||
self.logger.info(f'Client {self.peer_name} disconnected')
|
||||
|
||||
dummy_event = DummyEventPacket('disconnected')
|
||||
if dummy_event in self.server.dummy_event_listeners:
|
||||
dummy_event_listeners = self.server.dummy_event_listeners[dummy_event]
|
||||
for listener in dummy_event_listeners:
|
||||
await listener(self)
|
||||
await self.server.dummy_event_listeners.fire('disconnected', self)
|
||||
|
||||
async def __data_received(self, data):
|
||||
data = data.decode()[:-1]
|
||||
|
Loading…
Reference in New Issue
Block a user