Blackhole room support

This commit is contained in:
Ben 2020-02-14 21:44:21 +00:00
parent beee263e88
commit f2924d9a54
2 changed files with 22 additions and 0 deletions

View File

@ -116,7 +116,14 @@ class Room(db.Model, RoomMixin):
RoomMixin.__init__(self, *args, **kwargs)
super().__init__(*args, **kwargs)
self.blackhole_penguins = {}
async def add_penguin(self, p):
if self.blackhole and p.is_vanilla_client:
self.blackhole_penguins[p.id] = p.room
p.room = self
return await p.send_xt('jnbhg', self.id)
await RoomMixin.add_penguin(self, p)
if self.game:
@ -127,6 +134,13 @@ class Room(db.Model, RoomMixin):
await p.send_xt('jr', self.id, await self.get_string())
await self.send_xt('ap', await p.string)
async def remove_penguin(self, p):
await RoomMixin.remove_penguin(self, p)
async def leave_blackhole(self, p):
if p.id in self.blackhole_penguins and p.is_vanilla_client:
p.room = self.blackhole_penguins.pop(p.id)
class PenguinIglooRoom(db.Model, RoomMixin):
__tablename__ = 'penguin_igloo_room'

View File

@ -0,0 +1,8 @@
from houdini import handlers
from houdini.handlers import XTPacket
@handlers.handler(XTPacket('bh', 'lnbhg'))
async def handle_leave_non_blackhole_game(p):
if p.room.blackhole:
await p.room.leave_blackhole(p)