Support for handlers to depend on specific packets

This commit is contained in:
Ben 2019-06-21 01:49:04 +01:00
parent 4c673ea089
commit 5abc62ed1d
3 changed files with 12 additions and 0 deletions

View File

@ -217,6 +217,16 @@ def check_for_packet(listener, p):
allow_once = check(check_for_packet)
def depends_on_packet(*packets):
def check_for_packets(_, p):
for packet in packets:
if packet not in p.received_packets:
return False
return True
return check(check_for_packets)
def player_attribute(**attrs):
def check_for_attributes(_, p):
for attr, value in attrs.items():

View File

@ -17,6 +17,7 @@ from datetime import datetime
@handlers.handler(XMLPacket('login'))
@handlers.allow_once
@handlers.depends_on_packet(XMLPacket('verChk'), XMLPacket('rndK'))
async def handle_login(p, credentials: Credentials):
loop = asyncio.get_event_loop()

View File

@ -12,6 +12,7 @@ handle_random_key = login.handle_random_key
@handlers.handler(XMLPacket('login'))
@handlers.allow_once
@handlers.depends_on_packet(XMLPacket('verChk'), XMLPacket('rndK'))
async def handle_login(p, credentials: WorldCredentials):
tr = p.server.redis.multi_exec()
tr.get('{}.lkey'.format(credentials.id))