Query player pin and award handlers

This commit is contained in:
Ben 2019-08-05 19:21:59 +01:00
parent e0a834ccbd
commit 192e1822a7
2 changed files with 56 additions and 1 deletions

View File

@ -1,6 +1,44 @@
from houdini import handlers
from houdini.handlers import XTPacket
from houdini.data.item import Item
from houdini.data.item import Item, ItemCrumbsCollection
import time
from aiocache import cached
def get_pin_string_key(_, p, player_id):
return 'pins.{}'.format(player_id)
def get_awards_string_key(_, p, player_id):
return 'awards.{}'.format(player_id)
@cached(alias='default', key_builder=get_pin_string_key)
async def get_pin_string(p, player_id):
if player_id in p.server.penguins_by_id:
inventory = p.server.penguins_by_id[player_id].data.inventory
else:
inventory = await ItemCrumbsCollection.get_collection(player_id)
def get_string(pin):
pin = p.server.items[pin]
release_unix = int(time.mktime(pin.release_date.timetuple()))
return '|'.join(map(str, [pin.id, release_unix, int(pin.member)]))
pins = [get_string(pin) for pin in inventory.keys() if p.server.items[pin].is_flag()]
return '%'.join(pins)
@cached(alias='default', key_builder=get_awards_string_key)
async def get_awards_string(p, player_id):
if player_id in p.server.penguins_by_id:
inventory = p.server.penguins_by_id[player_id].data.inventory
else:
inventory = await ItemCrumbsCollection.get_collection(player_id)
awards = [str(award) for award in inventory.keys() if p.server.items[award].is_award()]
return '%'.join(awards)
@handlers.handler(XTPacket('i', 'gi'))
@ -26,3 +64,17 @@ async def handle_buy_inventory(p, item: Item):
return await p.send_error(401)
await p.add_inventory(item)
@handlers.handler(XTPacket('i', 'qpp'))
@handlers.depends_on_packet(XTPacket('i', 'gi'))
@handlers.cooldown(1)
async def handle_query_player_pins(p, player_id: int):
await p.send_xt('qpp', await get_pin_string(p, player_id))
@handlers.handler(XTPacket('i', 'qpa'))
@handlers.depends_on_packet(XTPacket('i', 'gi'))
@handlers.cooldown(1)
async def handle_query_player_awards(p, player_id: int):
await p.send_xt('qpa', await get_awards_string(p, player_id))

View File

@ -69,6 +69,9 @@ class Penguin(Spheniscidae):
self.logger.info('{} added \'{}\' to their clothing inventory'.format(
self.data.username, item.name))
await self.server.cache.delete('pins.{}'.format(self.data.id))
await self.server.cache.delete('awards.{}'.format(self.data.id))
return True
async def add_igloo(self, igloo, notify=True):