mirror of
https://github.com/solero/houdini.git
synced 2024-11-25 15:07:24 +00:00
EPF com message handlers
This commit is contained in:
parent
c59e6fa8c4
commit
cfe274e67f
@ -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()"))
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user