async def add_filter(sid: str, uuid: str): pr: PlayerRoom = game_state.get(sid) label = Label.get_or_none(uuid=uuid) LabelSelection.create(label=label, user=pr.player, room=pr.room) for psid in game_state.get_sids(skip_sid=sid, room=pr.room): if game_state.get_user(psid) == pr.player: await sio.emit("Labels.Filter.Add", uuid, room=psid, namespace=GAME_NS)
async def add_filter(sid, uuid): sid_data = state.sid_map[sid] user = sid_data["user"] room = sid_data["room"] label = Label.get_or_none(uuid=uuid) LabelSelection.create(label=label, user=user, room=room) for psid in state.get_sids(skip_sid=sid, room=room): if state.get_user(psid) == user: await sio.emit("Labels.Filter.Add", uuid, room=psid, namespace="/planarally")
async def remove_filter(sid: str, uuid: str): pr: PlayerRoom = game_state.get(sid) label = Label.get_or_none(uuid=uuid) ls = LabelSelection.get_or_none(label=label, room=pr.room, user=pr.player) if ls: ls.delete_instance(True) for psid in game_state.get_sids(skip_sid=sid, room=pr.room): if game_state.get_user(psid) == pr.player: await sio.emit("Labels.Filter.Remove", uuid, room=psid, namespace=GAME_NS)
async def remove_filter(sid, uuid): sid_data = state.sid_map[sid] user = sid_data["user"] room = sid_data["room"] label = Label.get_or_none(uuid=uuid) ls = LabelSelection.get_or_none(label=label, room=room, user=user) if ls: ls.delete_instance(True) for psid in state.get_sids(skip_sid=sid, room=room): if state.get_user(psid) == user: await sio.emit("Labels.Filter.Remove", uuid, room=psid, namespace="/planarally")
async def connect(sid, environ): user = await authorized_userid(environ["aiohttp.request"]) if user is None: await sio.emit("redirect", "/", room=sid, namespace="/planarally") else: ref = { k.split("=")[0]: k.split("=")[1] for k in unquote(environ["QUERY_STRING"]).strip().split("&") } try: room = ( Room.select() .join(User) .where((Room.name == ref["room"]) & (User.name == ref["user"]))[0] ) except IndexError: return False else: for pr in room.players: if pr.player == user: if pr.role != Role.DM and room.is_locked: return False break else: return False pr = PlayerRoom.get(room=room, player=user) # todo: just store PlayerRoom as it has all the info await game_state.add_sid(sid, pr) logger.info(f"User {user.name} connected with identifier {sid}") labels = Label.select().where((Label.user == user) | (Label.visible == True)) label_filters = LabelSelection.select().where( (LabelSelection.user == user) & (LabelSelection.room == room) ) sio.enter_room(sid, pr.active_location.get_path(), namespace="/planarally") await sio.emit("Username.Set", user.name, room=sid, namespace="/planarally") await sio.emit( "Labels.Set", [l.as_dict() for l in labels], room=sid, namespace="/planarally", ) await sio.emit( "Labels.Filters.Set", [l.label.uuid for l in label_filters], room=sid, namespace="/planarally", ) await sio.emit( "Room.Info.Set", { "name": room.name, "creator": room.creator.name, "invitationCode": str(room.invitation_code), "isLocked": room.is_locked, "default_options": room.default_options.as_dict(), "players": [ { "id": rp.player.id, "name": rp.player.name, "location": rp.active_location.id, } for rp in room.players ], }, room=sid, namespace="/planarally", ) await sio.emit( "Asset.List.Set", Asset.get_user_structure(user), room=sid, namespace="/planarally", ) if pr.role == Role.DM: await sio.emit( "Locations.Settings.Set", { l.name: {} if l.options is None else l.options.as_dict() for l in pr.room.locations }, room=sid, namespace="/planarally", ) await load_location(sid, pr.active_location)
async def connect(sid, environ): user = await authorized_userid(environ["aiohttp.request"]) if user is None: await sio.emit("redirect", "/", room=sid, namespace="/planarally") else: ref = { k.split("=")[0]: k.split("=")[1] for k in unquote(environ["QUERY_STRING"]).strip().split("&") } try: room = (Room.select().join(User).where( (Room.name == ref["room"]) & (User.name == ref["user"]))[0]) except IndexError: return False else: if user != room.creator and ( user not in [pr.player for pr in room.players] or room.is_locked): return False if room.creator == user: location = Location.get(room=room, name=room.dm_location) else: location = Location.get(room=room, name=room.player_location) state.add_sid(sid, user=user, room=room, location=location) logger.info(f"User {user.name} connected with identifier {sid}") labels = Label.select().where((Label.user == user) | (Label.visible == True)) label_filters = LabelSelection.select().where( (LabelSelection.user == user) & (LabelSelection.room == room)) sio.enter_room(sid, location.get_path(), namespace="/planarally") await sio.emit("Username.Set", user.name, room=sid, namespace="/planarally") await sio.emit( "Labels.Set", [l.as_dict() for l in labels], room=sid, namespace="/planarally", ) await sio.emit( "Labels.Filters.Set", [l.label.uuid for l in label_filters], room=sid, namespace="/planarally", ) await sio.emit( "Room.Info.Set", { "name": room.name, "creator": room.creator.name, "invitationCode": str(room.invitation_code), "isLocked": room.is_locked, "players": [{ "id": rp.player.id, "name": rp.player.name } for rp in room.players], }, room=sid, namespace="/planarally", ) await sio.emit( "Asset.List.Set", Asset.get_user_structure(user), room=sid, namespace="/planarally", ) await load_location(sid, location)