From cfe274e67f3a1e40dce713bda39cfbd9fb47909d Mon Sep 17 00:00:00 2001 From: Ben Date: Mon, 2 Dec 2019 23:24:28 +0000 Subject: [PATCH] EPF com message handlers --- houdini/data/penguin.py | 9 +++++++++ houdini/handlers/play/epf.py | 25 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/houdini/data/penguin.py b/houdini/data/penguin.py index 182e5ca..81deb9f 100644 --- a/houdini/data/penguin.py +++ b/houdini/data/penguin.py @@ -43,6 +43,7 @@ class Penguin(db.Model): career_medals = db.Column(db.Integer, nullable=False, server_default=db.text("0")) agent_medals = db.Column(db.Integer, nullable=False, server_default=db.text("0")) last_field_op = db.Column(db.DateTime, nullable=False, server_default=db.text("now()")) + com_message_read_date = db.Column(db.DateTime, nullable=False, server_default=db.text("now()")) ninja_rank = db.Column(db.SmallInteger, nullable=False, server_default=db.text("0")) ninja_progress = db.Column(db.SmallInteger, nullable=False, server_default=db.text("0")) fire_ninja_rank = db.Column(db.SmallInteger, nullable=False, server_default=db.text("0")) @@ -151,3 +152,11 @@ class Login(db.Model): date = db.Column(db.DateTime, nullable=False, server_default=db.text("now()")) ip_address = db.Column(db.CHAR(255), nullable=False) minutes_played = db.Column(db.Integer, nullable=False, server_default=db.text("0")) + + +class EpfComMessage(db.Model): + __tablename__ = 'epf_com_message' + + message = db.Column(db.Text, nullable=False) + character_id = db.Column(db.ForeignKey('character.id', ondelete='RESTRICT', onupdate='CASCADE'), nullable=False) + date = db.Column(db.DateTime, nullable=False, server_default=db.text("now()")) diff --git a/houdini/handlers/play/epf.py b/houdini/handlers/play/epf.py index 1e0162a..1116273 100644 --- a/houdini/handlers/play/epf.py +++ b/houdini/handlers/play/epf.py @@ -4,10 +4,24 @@ from houdini.handlers.play.mail import handle_start_mail_engine from houdini.data.item import Item from houdini.data.mail import PenguinPostcard +from houdini.data.penguin import EpfComMessage +from houdini.constants import ClientType import datetime +import time import random +from aiocache import cached + + +@cached(alias='default', key='com_messages') +async def get_com_messages(p): + async with p.server.db.transaction(): + messages = [] + async for message in EpfComMessage.query.order_by(EpfComMessage.date.desc()).gino.iterate(): + messages.append(f'{message.message}|{int(time.mktime(message.date.timetuple()))}|{message.character_id}') + return '%'.join(messages) + @handlers.handler(XTPacket('l', 'mst'), before=handle_start_mail_engine) async def handle_send_job_mail(p): @@ -102,3 +116,14 @@ async def handle_buy_epf_item(p, item: Item): return await p.send_error(401) await p.add_epf_inventory(item) + + +@handlers.handler(XTPacket('f', 'epfgm'), client=ClientType.Vanilla) +@handlers.allow_once +async def handle_get_com_messages(p): + unread_com_message = await EpfComMessage.query.where( + EpfComMessage.date > p.com_message_read_date).gino.scalar() + if unread_com_message: + await p.server.cache.delete('com_messages') + await p.update(com_message_read_date=datetime.datetime.now()).apply() + await p.send_xt('epfgm', int(bool(unread_com_message)), await get_com_messages(p))