Overhauled BaseCrumbsCollection class

This commit is contained in:
Ben 2019-10-12 00:12:04 +01:00
parent 8c492bae7f
commit 2712aad24e
21 changed files with 267 additions and 299 deletions

View File

@ -247,7 +247,7 @@ class RoomConverter(IConverter):
async def convert(self, ctx):
room_id = int(ctx.argument)
if room_id in ctx.p.server.rooms:
return await ctx.p.server.rooms.get(room_id)
return ctx.p.server.rooms[room_id]
return None
@ -258,7 +258,7 @@ class ItemConverter(IConverter):
async def convert(self, ctx):
item_id = int(ctx.argument)
if item_id in ctx.p.server.items:
return await ctx.p.server.items.get(item_id)
return ctx.p.server.items[item_id]
return None
@ -269,7 +269,7 @@ class IglooConverter(IConverter):
async def convert(self, ctx):
igloo_id = int(ctx.argument)
if igloo_id in ctx.p.server.igloos:
return await ctx.p.server.igloos.get(igloo_id)
return ctx.p.server.igloos[igloo_id]
return None
@ -280,7 +280,7 @@ class FurnitureConverter(IConverter):
async def convert(self, ctx):
furniture_id = int(ctx.argument)
if furniture_id in ctx.p.server.furniture:
return await ctx.p.server.furniture.get(furniture_id)
return ctx.p.server.furniture[furniture_id]
return None
@ -291,7 +291,7 @@ class FlooringConverter(IConverter):
async def convert(self, ctx):
flooring_id = int(ctx.argument)
if flooring_id in ctx.p.server.flooring:
return await ctx.p.server.flooring.get(flooring_id)
return ctx.p.server.flooring[flooring_id]
return None
@ -302,7 +302,7 @@ class LocationConverter(IConverter):
async def convert(self, ctx):
location_id = int(ctx.argument)
if location_id in ctx.p.server.locations:
return await ctx.p.server.locations.get(location_id)
return ctx.p.server.locations[location_id]
return None
@ -313,7 +313,7 @@ class StampConverter(IConverter):
async def convert(self, ctx):
stamp_id = int(ctx.argument)
if stamp_id in ctx.p.server.stamps:
return await ctx.p.server.stamps.get(stamp_id)
return ctx.p.server.stamps[stamp_id]
return None

View File

@ -1,73 +1,57 @@
from gino import Gino
from collections.abc import Mapping
db = Gino()
class BaseCrumbsCollection(dict):
class AbstractDataCollection(Mapping):
def __init__(self, *args, **kwargs):
super().__init__()
def __init__(self, filter_lookup=None):
self.__collection = dict()
self._db = db
self._model = kwargs.get('model')
self._key = kwargs.get('key')
self._inventory_model = kwargs.get('inventory_model')
self._inventory_key = kwargs.get('inventory_key')
self._inventory_value = kwargs.get('inventory_value')
self._inventory_id = kwargs.get('inventory_id')
self.__model = getattr(self.__class__, '__model__')
self.__indexby = getattr(self.__class__, '__indexby__')
self._model_key_column = getattr(self._model, self._key)
self.__filterby = getattr(self.__class__, '__filterby__')
self.__filter_lookup = getattr(self.__model, self.__filterby)
self.__filter_lookup = filter_lookup or self.__filter_lookup
self._is_inventory = self._inventory_model is not None and self._inventory_id is not None
def __delitem__(self, key):
raise TypeError(f'Use {self.__class__.__name__}.delete to remove an item from this collection')
if self._is_inventory:
self._inventory_key_column = getattr(self._inventory_model, self._inventory_key)
self._inventory_value_column = getattr(self._inventory_model, self._inventory_value)
def __setitem__(self, key, value):
raise TypeError(f'Use {self.__class__.__name__}.insert to add an item to this collection')
async def get(self, k):
try:
return self[k]
except KeyError as e:
query = self._inventory_model.query.where(
(self._inventory_key_column == self._inventory_id) & (self._inventory_value_column == k)
) if self._is_inventory else self._model.query.where(self._model_key_column == k)
result = await query.gino.first()
if result:
self[k] = result
return result
raise e
def __len__(self):
return len(self.__collection)
async def set(self, k=None, **kwargs):
if self._is_inventory:
kwargs = {self._inventory_key: self._inventory_id, self._inventory_value: k, **kwargs}
model_instance = await self._inventory_model.create(**kwargs)
k = getattr(model_instance, self._inventory_value)
self[k] = model_instance
else:
model_instance = await self._model.create(**kwargs)
k = getattr(model_instance, self._key)
self[k] = model_instance
return self[k]
def __iter__(self):
return iter(self.__collection)
async def delete(self, k):
query = self._inventory_model.delete.where(
(self._inventory_key_column == self._inventory_id) & (self._inventory_value_column == k)
) if self._is_inventory else self._model.delete.where(self._model_key_column == k)
await query.gino.status()
if k in self:
del self[k]
def __getitem__(self, item):
return self.__collection[item]
async def insert(self, **kwargs):
kwargs = {self.__filterby: self.__filter_lookup, **kwargs}
model_instance = await self.__model.create(**kwargs)
key = getattr(model_instance, self.__indexby)
self.__collection[key] = model_instance
return model_instance
async def delete(self, key):
model_instance = self.__collection.pop(key)
await model_instance.delete()
async def __collect(self):
query = self._inventory_model.query.where(
self._inventory_key_column == self._inventory_id
) if self._is_inventory else self._model.query
filter_column = getattr(self.__model, self.__filterby)
query = self.__model.query.where(filter_column == self.__filter_lookup)
async with db.transaction():
collected = query.gino.iterate()
self.update({
getattr(model_instance, self._inventory_value if self._is_inventory else self._key): model_instance
async for model_instance in collected
})
async for model_instance in collected:
collection_index = getattr(model_instance, self.__indexby)
self.__collection[collection_index] = model_instance
@classmethod
async def get_collection(cls, *args, **kwargs):

View File

@ -1,4 +1,4 @@
from houdini.data import db, BaseCrumbsCollection
from houdini.data import db, AbstractDataCollection
class BuddyList(db.Model):
@ -45,51 +45,31 @@ class CharacterBuddy(db.Model):
best_buddy = db.Column(db.Boolean, nullable=False, server_default=db.text("false"))
class BuddyListCollection(BaseCrumbsCollection):
def __init__(self, inventory_id=None):
super().__init__(model=BuddyList,
key='buddy_id',
inventory_model=BuddyList,
inventory_key='penguin_id',
inventory_value='buddy_id',
inventory_id=inventory_id)
class BuddyListCollection(AbstractDataCollection):
__model__ = BuddyList
__filterby__ = 'penguin_id'
__indexby__ = 'buddy_id'
class IgnoreListCollection(BaseCrumbsCollection):
def __init__(self, inventory_id=None):
super().__init__(model=IgnoreList,
key='ignore_id',
inventory_model=IgnoreList,
inventory_key='penguin_id',
inventory_value='ignore_id',
inventory_id=inventory_id)
class IgnoreListCollection(AbstractDataCollection):
__model__ = IgnoreList
__filterby__ = 'penguin_id'
__indexby__ = 'ignore_id'
class BuddyRequestCollection(BaseCrumbsCollection):
def __init__(self, inventory_id=None):
super().__init__(model=BuddyRequest,
key='requester_id',
inventory_model=BuddyRequest,
inventory_key='penguin_id',
inventory_value='requester_id',
inventory_id=inventory_id)
class BuddyRequestCollection(AbstractDataCollection):
__model__ = BuddyRequest
__filterby__ = 'penguin_id'
__indexby__ = 'requester_id'
class CharacterCrumbsCollection(BaseCrumbsCollection):
def __init__(self):
super().__init__(model=Character, key='id')
class CharacterCollection(AbstractDataCollection):
__model__ = Character
__filterby__ = 'id'
__indexby__ = 'id'
class CharacterBuddyCollection(BaseCrumbsCollection):
def __init__(self, inventory_id=None):
super().__init__(model=CharacterBuddy,
key='character_id',
inventory_model=CharacterBuddy,
inventory_key='penguin_id',
inventory_value='character_id',
inventory_id=inventory_id)
class CharacterBuddyCollection(AbstractDataCollection):
__model__ = CharacterBuddy
__filterby__ = 'penguin_id'
__indexby__ = 'character_id'

View File

@ -1,4 +1,4 @@
from houdini.data import db, BaseCrumbsCollection
from houdini.data import db, AbstractDataCollection
class Flooring(db.Model):
@ -103,45 +103,49 @@ class PenguinFlooring(db.Model):
nullable=False)
class IglooCrumbsCollection(BaseCrumbsCollection):
def __init__(self, inventory_id=None):
super().__init__(model=Igloo,
key='id',
inventory_model=PenguinIgloo,
inventory_key='penguin_id',
inventory_value='igloo_id',
inventory_id=inventory_id)
class IglooCollection(AbstractDataCollection):
__model__ = Igloo
__indexby__ = 'id'
__filterby__ = 'id'
class LocationCrumbsCollection(BaseCrumbsCollection):
def __init__(self, inventory_id=None):
super().__init__(model=Location,
key='id',
inventory_model=PenguinLocation,
inventory_key='penguin_id',
inventory_value='location_id',
inventory_id=inventory_id)
class PenguinIglooCollection(AbstractDataCollection):
__model__ = PenguinIgloo
__indexby__ = 'igloo_id'
__filterby__ = 'penguin_id'
class FurnitureCrumbsCollection(BaseCrumbsCollection):
def __init__(self, inventory_id=None):
super().__init__(model=Furniture,
key='id',
inventory_model=PenguinFurniture,
inventory_key='penguin_id',
inventory_value='furniture_id',
inventory_id=inventory_id)
class LocationCollection(AbstractDataCollection):
__model__ = Location
__indexby__ = 'id'
__filterby__ = 'id'
class FlooringCrumbsCollection(BaseCrumbsCollection):
class PenguinLocationCollection(AbstractDataCollection):
__model__ = PenguinLocation
__indexby__ = 'location_id'
__filterby__ = 'penguin_id'
def __init__(self, inventory_id=None):
super().__init__(model=Flooring,
key='id',
inventory_model=PenguinFlooring,
inventory_key='penguin_id',
inventory_value='flooring_id',
inventory_id=inventory_id)
class FurnitureCollection(AbstractDataCollection):
__model__ = Furniture
__indexby__ = 'id'
__filterby__ = 'id'
class PenguinFurnitureCollection(AbstractDataCollection):
__model__ = PenguinFurniture
__indexby__ = 'furniture_id'
__filterby__ = 'penguin_id'
class FlooringCollection(AbstractDataCollection):
__model__ = Flooring
__indexby__ = 'id'
__filterby__ = 'id'
class PenguinFlooringCollection(AbstractDataCollection):
__model__ = PenguinFlooring
__indexby__ = 'flooring_id'
__filterby__ = 'penguin_id'

View File

@ -1,4 +1,4 @@
from houdini.data import db, BaseCrumbsCollection
from houdini.data import db, AbstractDataCollection
class Item(db.Model):
@ -55,12 +55,13 @@ class PenguinItem(db.Model):
primary_key=True, nullable=False)
class ItemCrumbsCollection(BaseCrumbsCollection):
class ItemCollection(AbstractDataCollection):
__model__ = Item
__indexby__ = 'id'
__filterby__ = 'id'
def __init__(self, inventory_id=None):
super().__init__(model=Item,
key='id',
inventory_model=PenguinItem,
inventory_key='penguin_id',
inventory_value='item_id',
inventory_id=inventory_id)
class PenguinItemCollection(AbstractDataCollection):
__model__ = PenguinItem
__indexby__ = 'item_id'
__filterby__ = 'penguin_id'

View File

@ -1,4 +1,4 @@
from houdini.data import db, BaseCrumbsCollection
from houdini.data import db, AbstractDataCollection
class Postcard(db.Model):
@ -24,12 +24,7 @@ class PenguinPostcard(db.Model):
has_read = db.Column(db.Boolean, nullable=False, server_default=db.text("false"))
class PostcardCrumbsCollection(BaseCrumbsCollection):
def __init__(self, inventory_id=None):
super().__init__(model=Postcard,
key='id',
inventory_model=PenguinPostcard,
inventory_key='penguin_id',
inventory_value='id',
inventory_id=inventory_id)
class PostcardCollection(AbstractDataCollection):
__model__ = Postcard
__indexby__ = 'id'
__filterby__ = 'id'

View File

@ -1,4 +1,4 @@
from houdini.data import db
from houdini.data import db, AbstractDataCollection
class Ban(db.Model):
@ -21,7 +21,6 @@ class Warning(db.Model):
expires = db.Column(db.DateTime, primary_key=True, nullable=False)
class Report(db.Model):
__tablename__ = 'report'
@ -33,3 +32,17 @@ class Report(db.Model):
server_id = db.Column(db.Integer, nullable=False)
room_id = db.Column(db.ForeignKey('room.id', ondelete='CASCADE', onupdate='CASCADE'), nullable=False)
class ChatFilterRule(db.Model):
__tablename__ = 'chat_filter_rule'
word = db.Column(db.Text, primary_key=True)
filter = db.Column(db.Boolean, nullable=False, server_default=db.text("false"))
warn = db.Column(db.Boolean, nullable=False, server_default=db.text("false"))
ban = db.Column(db.Boolean, nullable=False, server_default=db.text("false"))
class ChatFilterRuleCollection(AbstractDataCollection):
__model__ = ChatFilterRule
__filterby__ = 'word'
__indexby__ = 'word'

View File

@ -1,4 +1,4 @@
from houdini.data import db, BaseCrumbsCollection
from houdini.data import db
class PenguinTrack(db.Model):

View File

@ -1,4 +1,4 @@
from houdini.data import db, BaseCrumbsCollection
from houdini.data import db, AbstractDataCollection
class Card(db.Model):
@ -24,12 +24,13 @@ class PenguinCard(db.Model):
quantity = db.Column(db.SmallInteger, nullable=False, server_default=db.text("1"))
class CardCrumbsCollection(BaseCrumbsCollection):
class CardCollection(AbstractDataCollection):
__model__ = Card
__indexby__ = 'id'
__filterby__ = 'id'
def __init__(self, inventory_id=None):
super().__init__(model=Card,
key='id',
inventory_key='penguin_id',
inventory_value='card_id',
inventory_model=PenguinCard,
inventory_id=inventory_id)
class PenguinCardCollection(AbstractDataCollection):
__model__ = PenguinCard
__indexby__ = 'card_id'
__filterby__ = 'penguin_id'

View File

@ -2,15 +2,15 @@ from datetime import datetime, date
from houdini.data import db
from houdini.data.permission import PermissionCrumbsCollection
from houdini.data.item import ItemCrumbsCollection
from houdini.data.igloo import IglooCrumbsCollection, FurnitureCrumbsCollection, FlooringCrumbsCollection, \
LocationCrumbsCollection
from houdini.data.stamp import StampCrumbsCollection
from houdini.data.ninja import CardCrumbsCollection
from houdini.data.pet import PuffleCrumbsCollection, PuffleItemCrumbsCollection
from houdini.data.buddy import BuddyListCollection, BuddyRequestCollection, CharacterBuddyCollection, \
IgnoreListCollection
from houdini.data.permission import PenguinPermissionCollection
from houdini.data.item import PenguinItemCollection
from houdini.data.igloo import PenguinIglooCollection, PenguinFurnitureCollection, \
PenguinFlooringCollection, PenguinLocationCollection
from houdini.data.stamp import PenguinStampCollection
from houdini.data.ninja import PenguinCardCollection
from houdini.data.pet import PenguinPuffleCollection, PenguinPuffleItemCollection
from houdini.data.buddy import BuddyListCollection, BuddyRequestCollection, \
CharacterBuddyCollection, IgnoreListCollection
from houdini.data.room import PenguinIglooRoomCollection
@ -108,17 +108,17 @@ class Penguin(db.Model):
super().__init__(*args, **kwargs)
async def load_inventories(self):
self.inventory = await ItemCrumbsCollection.get_collection(self.id)
self.permissions = await PermissionCrumbsCollection.get_collection(self.id)
self.igloos = await IglooCrumbsCollection.get_collection(self.id)
self.inventory = await PenguinItemCollection.get_collection(self.id)
self.permissions = await PenguinPermissionCollection.get_collection(self.id)
self.igloos = await PenguinIglooCollection.get_collection(self.id)
self.igloo_rooms = await PenguinIglooRoomCollection.get_collection(self.id)
self.furniture = await FurnitureCrumbsCollection.get_collection(self.id)
self.flooring = await FlooringCrumbsCollection.get_collection(self.id)
self.locations = await LocationCrumbsCollection.get_collection(self.id)
self.stamps = await StampCrumbsCollection.get_collection(self.id)
self.cards = await CardCrumbsCollection.get_collection(self.id)
self.puffles = await PuffleCrumbsCollection.get_collection(self.id)
self.puffle_items = await PuffleItemCrumbsCollection.get_collection(self.id)
self.furniture = await PenguinFurnitureCollection.get_collection(self.id)
self.flooring = await PenguinFlooringCollection.get_collection(self.id)
self.locations = await PenguinLocationCollection.get_collection(self.id)
self.stamps = await PenguinStampCollection.get_collection(self.id)
self.cards = await PenguinCardCollection.get_collection(self.id)
self.puffles = await PenguinPuffleCollection.get_collection(self.id)
self.puffle_items = await PenguinPuffleItemCollection.get_collection(self.id)
self.buddies = await BuddyListCollection.get_collection(self.id)
self.buddy_requests = await BuddyRequestCollection.get_collection(self.id)
self.character_buddies = await CharacterBuddyCollection.get_collection(self.id)
@ -142,13 +142,13 @@ class Penguin(db.Model):
@property
def approval(self):
return int('{}{}0{}{}{}{}'.format(self.approval_ru * 1, self.approval_de * 1, self.approval_es * 1,
self.approval_fr * 1, self.approval_pt * 1, self.approval_en * 1), 2)
return int(f'{self.approval_ru * 1}{self.approval_de * 1}0{self.approval_es * 1}'
f'{self.approval_fr * 1}{self.approval_pt * 1}{self.approval_en * 1}', 2)
@property
def rejection(self):
return int('{}{}0{}{}{}{}'.format(self.rejection_ru * 1, self.rejection_de * 1, self.rejection_es * 1,
self.rejection_fr * 1, self.rejection_pt * 1, self.rejection_en * 1), 2)
return int(f'{self.rejection_ru * 1}{self.rejection_de * 1}0{self.rejection_es * 1}'
f'{self.rejection_fr * 1}{self.rejection_pt * 1}{self.rejection_en * 1}', 2)
class ActivationKey(db.Model):

View File

@ -1,4 +1,4 @@
from houdini.data import db, BaseCrumbsCollection
from houdini.data import db, AbstractDataCollection
class Permission(db.Model):
@ -16,19 +16,13 @@ class PenguinPermission(db.Model):
permission_id = db.Column(db.ForeignKey(u'permission.id', ondelete=u'CASCADE', onupdate=u'CASCADE'), nullable=False)
class PermissionCrumbsCollection(BaseCrumbsCollection):
class PermissionCollection(AbstractDataCollection):
__model__ = Permission
__indexby__ = 'name'
__filterby__ = 'name'
def __init__(self, inventory_id=None):
super().__init__(model=Permission,
key='name',
inventory_model=PenguinPermission,
inventory_key='penguin_id',
inventory_value='permission_id',
inventory_id=inventory_id)
async def register(self, permission_name):
try:
permission = await self.get(permission_name)
except KeyError:
permission = await self.set(name=permission_name)
return permission
class PenguinPermissionCollection(AbstractDataCollection):
__model__ = PenguinPermission
__indexby__ = 'permission_id'
__filterby__ = 'penguin_id'

View File

@ -1,4 +1,4 @@
from houdini.data import db, BaseCrumbsCollection
from houdini.data import db, AbstractDataCollection
class Puffle(db.Model):
@ -110,23 +110,25 @@ class PenguinLaunchGame(db.Model):
turbo = db.Column(db.Boolean, nullable=False, server_default=db.text("false"))
class PuffleCrumbsCollection(BaseCrumbsCollection):
def __init__(self, inventory_id=None):
super().__init__(model=Puffle,
key='id',
inventory_model=PenguinPuffle,
inventory_key='penguin_id',
inventory_value='id',
inventory_id=inventory_id)
class PuffleCollection(AbstractDataCollection):
__model__ = Puffle
__indexby__ = 'id'
__filterby__ = 'id'
class PuffleItemCrumbsCollection(BaseCrumbsCollection):
class PenguinPuffleCollection(AbstractDataCollection):
__model__ = PenguinPuffle
__indexby__ = 'id'
__filterby__ = 'penguin_id'
def __init__(self, inventory_id=None):
super().__init__(model=PuffleItem,
key='id',
inventory_model=PenguinPuffleItem,
inventory_key='penguin_id',
inventory_value='item_id',
inventory_id=inventory_id)
class PuffleItemCollection(AbstractDataCollection):
__model__ = PuffleItem
__indexby__ = 'id'
__filterby__ = 'id'
class PenguinPuffleItemCollection(AbstractDataCollection):
__model__ = PenguinPuffleItem
__indexby__ = 'item_id'
__filterby__ = 'penguin_id'

View File

@ -1,4 +1,4 @@
from houdini.data import db, BaseCrumbsCollection
from houdini.data import db, AbstractDataCollection
class RoomMixin:
@ -158,17 +158,6 @@ class PenguinIglooRoom(db.Model, RoomMixin):
del p.server.igloos_by_penguin_id[self.penguin_id]
class PenguinIglooRoomCollection(BaseCrumbsCollection):
def __init__(self, inventory_id=None):
super().__init__(model=PenguinIglooRoom,
key='id',
inventory_model=PenguinIglooRoom,
inventory_key='penguin_id',
inventory_value='id',
inventory_id=inventory_id)
class RoomTable(db.Model):
__tablename__ = 'room_table'
@ -279,22 +268,29 @@ class RoomWaddle(db.Model):
return self.penguins.index(p)
class RoomCrumbsCollection(BaseCrumbsCollection):
class PenguinIglooRoomCollection(AbstractDataCollection):
__model__ = PenguinIglooRoom
__indexby__ = 'id'
__filterby__ = 'penguin_id'
def __init__(self):
super().__init__(model=Room,
key='id')
class RoomCollection(AbstractDataCollection):
__model__ = Room
__indexby__ = 'id'
__filterby__ = 'id'
@property
def spawn_rooms(self):
return [room for room in self.values() if room.spawn]
async def setup_tables(self):
async with self._db.transaction():
async with db.transaction():
async for table in RoomTable.query.gino.iterate():
self[table.room_id].tables[table.id] = table
async def setup_waddles(self):
async with self._db.transaction():
async with db.transaction():
async for waddle in RoomWaddle.query.gino.iterate():
self[waddle.room_id].waddles[waddle.id] = waddle

View File

@ -1,4 +1,4 @@
from houdini.data import db, BaseCrumbsCollection
from houdini.data import db, AbstractDataCollection
class Stamp(db.Model):
@ -56,12 +56,13 @@ class PenguinStamp(db.Model):
recent = db.Column(db.Boolean, nullable=False, server_default=db.text("true"))
class StampCrumbsCollection(BaseCrumbsCollection):
class StampCollection(AbstractDataCollection):
__model__ = Stamp
__indexby__ = 'id'
__filterby__ = 'id'
def __init__(self, inventory_id=None):
super().__init__(model=Stamp,
key='id',
inventory_model=PenguinStamp,
inventory_key='penguin_id',
inventory_value='stamp_id',
inventory_id=inventory_id)
class PenguinStampCollection(AbstractDataCollection):
__model__ = PenguinStamp
__indexby__ = 'stamp_id'
__filterby__ = 'penguin_id'

View File

@ -113,7 +113,7 @@ async def handle_buddy_request(p, buddy_id: int):
buddy = p.server.penguins_by_id[buddy_id]
if buddy.client_type == ClientType.Vanilla and p.data.id not in buddy.data.buddy_requests:
await buddy.data.buddy_requests.set(p.data.id)
await buddy.data.buddy_requests.insert(buddy_id=p.data.id)
elif p.data.id not in buddy.buddy_requests:
buddy.buddy_requests.add(p.data.id)
else:
@ -133,11 +133,11 @@ async def handle_buddy_accept(p, buddy_id: int):
else:
return
await p.data.buddies.set(buddy_id)
await p.data.buddies.insert(buddy_id=buddy_id)
if buddy_id in p.server.penguins_by_id:
buddy = p.server.penguins_by_id[buddy_id]
await buddy.data.buddies.set(p.data.id)
await buddy.data.buddies.insert(buddy_id=p.data.id)
await buddy.send_xt('ba', p.data.id, p.data.nickname, 1)
await p.send_xt('ba', buddy.data.id, buddy.data.nickname, 1)
@ -169,7 +169,7 @@ async def handle_buddy_remove(p, buddy_id: int):
async def handle_character_request(p, character_id: int):
if character_id in p.server.characters and character_id not in p.data.character_buddies:
character = p.server.characters[character_id]
await p.data.character_buddies.set(character_id)
await p.data.character_buddies.insert(character_id=character_id)
await p.send_xt('cr', character_id, 0)
await p.send_xt('caon', character_id, p.server.server_config['Id'], p.room.id)

View File

@ -95,8 +95,7 @@ async def create_first_igloo(p, penguin_id):
if igloo is None:
if penguin_id in p.server.penguins_by_id:
penguin = p.server.penguins_by_id[penguin_id]
igloo = await penguin.data.igloo_rooms.set(PenguinIglooRoom.id, penguin_id=penguin_id, type=1,
flooring=0, location=1)
igloo = await penguin.data.igloo_rooms.insert(penguin_id=penguin_id, type=1, flooring=0, location=1)
await penguin.data.update(igloo=igloo.id).apply()
else:
igloo = await PenguinIglooRoom.create(penguin_id=penguin_id, type=1, flooring=0, location=1)
@ -319,7 +318,7 @@ async def handle_is_player_igloo_open(p, penguin_id: int):
@handlers.handler(XTPacket('g', 'al'), client=ClientType.Vanilla)
async def handle_add_igloo_layout(p):
if len(p.data.igloo_rooms) < 4:
igloo = await p.data.igloo_rooms.set(PenguinIglooRoom.id, penguin_id=p.data.id, type=1, flooring=0, location=1)
igloo = await p.data.igloo_rooms.insert(penguin_id=p.data.id, type=1, flooring=0, location=1)
slot_id = len(p.data.igloo_rooms)
await p.send_xt('al', p.data.id, f'{igloo.id}:{slot_id}:0:{int(igloo.locked)}:{igloo.music}:{igloo.flooring}:'

View File

@ -32,5 +32,5 @@ async def handle_ignore_add(p, ignored_id: int):
nickname = p.server.penguins_by_id[ignored_id].data.nickname
else:
nickname = await Penguin.select('nickname').where(Penguin.id == ignored_id).gino.scalar()
await p.data.ignore.set(ignored_id)
await p.data.ignore.insert(ignore_id=ignored_id)
await p.send_xt('an', ignored_id, nickname)

View File

@ -1,6 +1,6 @@
from houdini import handlers
from houdini.handlers import XTPacket
from houdini.data.item import Item, ItemCrumbsCollection
from houdini.data.item import Item, PenguinItemCollection
import time
from aiocache import cached
@ -20,7 +20,7 @@ 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)
inventory = await PenguinItemCollection.get_collection(player_id)
def get_string(pin):
unix = int(time.mktime(pin.release_date.timetuple()))
@ -37,7 +37,7 @@ 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)
inventory = await PenguinItemCollection.get_collection(player_id)
awards = [str(award) for award in inventory.keys() if p.server.items[award].is_award()]
return '%'.join(awards)

View File

@ -1,7 +1,7 @@
from houdini import handlers
from houdini.handlers import XTPacket
from houdini.handlers.play.navigation import handle_join_server
from houdini.data.stamp import Stamp, CoverStamp, CoverItem, StampCrumbsCollection
from houdini.data.stamp import Stamp, CoverStamp, CoverItem, PenguinStampCollection
from houdini.data.penguin import Penguin
from aiocache import cached
@ -43,7 +43,7 @@ async def get_player_stamps_string(p, player_id):
if player_id in p.server.penguins_by_id:
stamp_inventory = p.server.penguins_by_id[player_id].data.stamps
else:
stamp_inventory = await StampCrumbsCollection.get_collection(player_id)
stamp_inventory = await PenguinStampCollection.get_collection(player_id)
return '|'.join(map(str, stamp_inventory.keys()))

View File

@ -15,16 +15,16 @@ import aioredis
from aiocache import SimpleMemoryCache, caches
from houdini.data import db
from houdini.data.item import ItemCrumbsCollection
from houdini.data.igloo import IglooCrumbsCollection, FurnitureCrumbsCollection, \
LocationCrumbsCollection, FlooringCrumbsCollection
from houdini.data.room import RoomCrumbsCollection
from houdini.data.stamp import StampCrumbsCollection
from houdini.data.ninja import CardCrumbsCollection
from houdini.data.mail import PostcardCrumbsCollection
from houdini.data.pet import PuffleCrumbsCollection, PuffleItemCrumbsCollection
from houdini.data.permission import PermissionCrumbsCollection
from houdini.data.buddy import CharacterCrumbsCollection
from houdini.data.item import ItemCollection
from houdini.data.igloo import IglooCollection, FurnitureCollection, \
LocationCollection, FlooringCollection
from houdini.data.room import RoomCollection
from houdini.data.stamp import StampCollection
from houdini.data.ninja import CardCollection
from houdini.data.mail import PostcardCollection
from houdini.data.pet import PuffleCollection, PuffleItemCollection
from houdini.data.permission import PermissionCollection
from houdini.data.buddy import CharacterCollection
try:
import uvloop
@ -187,46 +187,46 @@ class Houdini:
await self.xml_listeners.setup(houdini.handlers, 'houdini.handlers.login.login')
self.logger.info('Login server started')
self.items = await ItemCrumbsCollection.get_collection()
self.items = await ItemCollection.get_collection()
self.logger.info(f'Loaded {len(self.items)} clothing items')
self.igloos = await IglooCrumbsCollection.get_collection()
self.igloos = await IglooCollection.get_collection()
self.logger.info(f'Loaded {len(self.igloos)} igloos')
self.furniture = await FurnitureCrumbsCollection.get_collection()
self.furniture = await FurnitureCollection.get_collection()
self.logger.info(f'Loaded {len(self.furniture)} furniture items')
self.locations = await LocationCrumbsCollection.get_collection()
self.locations = await LocationCollection.get_collection()
self.logger.info(f'Loaded {len(self.locations)} igloo locations')
self.flooring = await FlooringCrumbsCollection.get_collection()
self.flooring = await FlooringCollection.get_collection()
self.logger.info(f'Loaded {len(self.flooring)} igloo flooring')
self.rooms = await RoomCrumbsCollection.get_collection()
self.rooms = await RoomCollection.get_collection()
self.spawn_rooms = self.rooms.spawn_rooms
await self.rooms.setup_tables()
await self.rooms.setup_waddles()
self.logger.info(f'Loaded {len(self.rooms)} rooms ({len(self.spawn_rooms)} spawn)')
self.postcards = await PostcardCrumbsCollection.get_collection()
self.postcards = await PostcardCollection.get_collection()
self.logger.info(f'Loaded {len(self.postcards)} postcards')
self.stamps = await StampCrumbsCollection.get_collection()
self.stamps = await StampCollection.get_collection()
self.logger.info(f'Loaded {len(self.stamps)} stamps')
self.cards = await CardCrumbsCollection.get_collection()
self.cards = await CardCollection.get_collection()
self.logger.info(f'Loaded {len(self.cards)} ninja cards')
self.puffles = await PuffleCrumbsCollection.get_collection()
self.puffles = await PuffleCollection.get_collection()
self.logger.info(f'Loaded {len(self.puffles)} puffles')
self.puffle_items = await PuffleItemCrumbsCollection.get_collection()
self.puffle_items = await PuffleItemCollection.get_collection()
self.logger.info(f'Loaded {len(self.puffle_items)} puffle care items')
self.characters = await CharacterCrumbsCollection.get_collection()
self.characters = await CharacterCollection.get_collection()
self.logger.info(f'Loaded {len(self.characters)} characters')
self.permissions = await PermissionCrumbsCollection.get_collection()
self.permissions = await PermissionCollection.get_collection()
self.logger.info(f'Multi-client support is '
f'{"enabled" if self.config.client["MultiClientSupport"] else "disabled"}')

View File

@ -67,7 +67,7 @@ class Penguin(Spheniscidae):
if item.id in self.data.inventory:
return False
await self.data.inventory.set(item.id)
await self.data.inventory.insert(item_id=item.id)
await self.data.update(coins=self.data.coins - item.cost).apply()
if notify:
@ -87,7 +87,7 @@ class Penguin(Spheniscidae):
if item.id in self.data.inventory:
return False
await self.data.inventory.set(item.id)
await self.data.inventory.insert(item_id=item.id)
await self.data.update(agent_medals=self.data.agent_medals - item.cost).apply()
if notify:
@ -99,7 +99,7 @@ class Penguin(Spheniscidae):
if igloo.id in self.data.igloos:
return False
await self.data.igloos.set(igloo.id)
await self.data.igloos.insert(igloo_id=igloo.id)
await self.data.update(coins=self.data.coins - igloo.cost).apply()
if notify:
@ -118,7 +118,7 @@ class Penguin(Spheniscidae):
await penguin_care_item.update(
quantity=penguin_care_item.quantity + quantity).apply()
else:
await self.data.puffle_items.set(care_item.id)
await self.data.puffle_items.insert(item_id=care_item.id)
await self.data.update(coins=self.data.coins - care_item.cost).apply()
@ -138,7 +138,7 @@ class Penguin(Spheniscidae):
await penguin_furniture.update(
quantity=penguin_furniture.quantity + quantity).apply()
else:
await self.data.furniture.set(furniture.id)
await self.data.furniture.insert(furniture_id=furniture.id)
await self.data.update(coins=self.data.coins - furniture.cost).apply()
@ -156,7 +156,7 @@ class Penguin(Spheniscidae):
await penguin_card.update(
quantity=penguin_card.quantity + quantity).apply()
else:
await self.data.cards.set(card.id)
await self.data.cards.insert(card_id=card.id)
self.logger.info(f'{self.data.username} added \'{card.name}\' to their ninja deck')
@ -166,7 +166,7 @@ class Penguin(Spheniscidae):
if flooring.id in self.data.flooring:
return False
await self.data.flooring.set(flooring.id)
await self.data.flooring.insert(flooring_id=flooring.id)
await self.data.update(coins=self.data.coins - flooring.cost).apply()
if notify:
@ -180,7 +180,7 @@ class Penguin(Spheniscidae):
if location.id in self.data.locations:
return False
await self.data.locations.set(location.id)
await self.data.locations.insert(location_id=location.id)
await self.data.update(coins=self.data.coins - location.cost).apply()
if notify:
@ -194,7 +194,7 @@ class Penguin(Spheniscidae):
if stamp.id in self.data.stamps:
return False
await self.data.stamps.set(stamp.id)
await self.data.stamps.insert(stamp_id=stamp.id)
if notify:
await self.send_xt('aabs', stamp.id)
@ -205,15 +205,13 @@ class Penguin(Spheniscidae):
return True
async def add_inbox(self, postcard, sender_name="sys", sender_id=None, details=""):
penguin_postcard = await self.data.postcards.set(penguin_id=self.data.id,
sender_id=sender_id, postcard_id=postcard.id,
details=details)
penguin_postcard = await self.data.postcards.insert(penguin_id=self.data.id, sender_id=sender_id, postcard_id=postcard.id, details=details)
await self.send_xt('mr', sender_name, 0, postcard.id, details, int(time.time()), penguin_postcard.id)
async def add_permission(self, permission):
if permission not in self.data.permissions:
await self.data.permissions.set(permission)
await self.data.permissions.insert(name=permission)
self.logger.info(f'{self.data.username} was assigned permission \'{permission}\'')