From 27cdb1e5698e165bc063f3167c043af6b0c8e195 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 4 Dec 2019 01:31:55 +0000 Subject: [PATCH] Minigame save state handlers --- houdini/data/pet.py | 11 ----------- houdini/handlers/games/__init__.py | 29 +++++++++++++++++++++++++++++ houdini/handlers/play/igloo.py | 10 ++++++++++ 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/houdini/data/pet.py b/houdini/data/pet.py index 362a0d2..79f66c7 100644 --- a/houdini/data/pet.py +++ b/houdini/data/pet.py @@ -99,17 +99,6 @@ class PenguinPuffleItem(db.Model): quantity = db.Column(db.SmallInteger, nullable=False, server_default=db.text("1")) -class PenguinLaunchGame(db.Model): - __tablename__ = 'penguin_launch_game' - - penguin_id = db.Column(db.ForeignKey('penguin.id', ondelete='CASCADE', onupdate='CASCADE'), primary_key=True, - nullable=False) - level = db.Column(db.SmallInteger, primary_key=True, nullable=False, server_default=db.text("0")) - puffle_os = db.Column(db.SmallInteger, nullable=False, server_default=db.text("0")) - best_time = db.Column(db.SmallInteger, nullable=False, server_default=db.text("600")) - turbo = db.Column(db.Boolean, nullable=False, server_default=db.text("false")) - - class PuffleCollection(AbstractDataCollection): __model__ = Puffle __indexby__ = 'id' diff --git a/houdini/handlers/games/__init__.py b/houdini/handlers/games/__init__.py index c19ac7f..e6584be 100644 --- a/houdini/handlers/games/__init__.py +++ b/houdini/handlers/games/__init__.py @@ -1,8 +1,13 @@ from houdini import handlers from houdini.handlers import XTPacket +from houdini.converters import OptionalConverter +from houdini.constants import ClientType from houdini.handlers.play.navigation import handle_join_room from houdini.handlers.play.moderation import cheat_ban from houdini.data.room import Room +from houdini.data.game import PenguinGameData + +from sqlalchemy.dialects.postgresql import insert import time @@ -91,3 +96,27 @@ async def handle_get_game_over(p, score: int): total_collected_stamps, total_game_stamps, total_stamps) + + +@handlers.handler(XTPacket('ggd', ext='z'), client=ClientType.Vanilla) +async def handle_get_game_data(p, index: int = None): + game_data = await PenguinGameData.select('data').where((PenguinGameData.penguin_id == p.id) & + (PenguinGameData.room_id == p.room.id) & + (PenguinGameData.index == index)).gino.scalar() + await p.send_xt('ggd', game_data or '') + + +@handlers.handler(XTPacket('sgd', ext='z'), client=ClientType.Vanilla) +@handlers.cooldown(5) +async def handle_set_game_data(p, index: OptionalConverter(int) = None, *, game_data: str): + if p.room.game: + data_insert = insert(PenguinGameData).values(penguin_id=p.id, room_id=p.room.id, index=index, data=game_data) + data_insert = data_insert.on_conflict_do_update( + constraint='penguin_game_data_pkey', + set_=dict(data=game_data), + where=((PenguinGameData.penguin_id == p.id) + & (PenguinGameData.room_id == p.room.id) + & (PenguinGameData.index == index)) + ) + + await data_insert.gino.scalar() diff --git a/houdini/handlers/play/igloo.py b/houdini/handlers/play/igloo.py index be7ff60..31ebfb9 100644 --- a/houdini/handlers/play/igloo.py +++ b/houdini/handlers/play/igloo.py @@ -16,6 +16,7 @@ from houdini.data.igloo import IglooFurniture, IglooLike, Igloo, Furniture, Floo PenguinIglooCollection, PenguinFurnitureCollection, \ PenguinFlooringCollection, PenguinLocationCollection from houdini.data.room import PenguinIglooRoomCollection +from houdini.data.game import PenguinGameData from sqlalchemy.dialects.postgresql import insert @@ -521,3 +522,12 @@ async def handle_get_furniture_inventory(p): locations = ','.join(f'{location_id}|0000000000' for location_id in p.locations.keys()) await p.send_xt('gii', furniture, flooring, igloos, locations) + + +@handlers.handler(XTPacket('g', 'ggd'), client=ClientType.Vanilla) +async def handle_get_dj3k_track(p, penguin_id: int, game_index: str): + room_id, index = game_index.split('|') + game_data = await PenguinGameData.select('data').where((PenguinGameData.penguin_id == penguin_id) & + (PenguinGameData.room_id == int(room_id)) & + (PenguinGameData.index == int(index))).gino.scalar() + await p.send_xt('ggd', game_data or '')