Beispiel #1
0
async def disconnect(sid):
    if not game_state.has_sid(sid):
        return

    user = game_state.get_user(sid)

    logger.info(f"User {user.name} disconnected with identifier {sid}")
    await game_state.remove_sid(sid)
Beispiel #2
0
async def set_asset_options(sid: str, asset_options: AssetOptions):
    pr: PlayerRoom = game_state.get(sid)

    if pr.role != Role.DM:
        logger.warning(f"{pr.player.name} attempted to set asset options")
        return

    asset = Asset.get_or_none(id=asset_options["asset"])
    if asset is None:
        asset = Asset.create(name="T", owner=game_state.get_user(sid),)
    asset.options = asset_options["options"]
    asset.save()
Beispiel #3
0
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)
Beispiel #4
0
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)
Beispiel #5
0
async def set_visibility(sid: str, data: LabelVisibilityMessage):
    pr: PlayerRoom = game_state.get(sid)

    label = Label.get_or_none(uuid=data["uuid"])

    if label is None:
        logger.warn(f"{pr.player.name} tried to change a non-existing label.")
        return

    if label.user != pr.player:
        logger.warn(f"{pr.player.name} tried to change another user's label.")
        return

    label.visible = data["visible"]
    label.save()

    for psid in game_state.get_sids(skip_sid=sid, room=pr.room):
        if game_state.get_user(psid) == pr.player:
            await sio.emit(
                "Label.Visibility.Set",
                {
                    "user": label.pr.player.name,
                    **data
                },
                room=psid,
                namespace=GAME_NS,
            )
        else:
            if data["visible"]:
                await sio.emit("Label.Add",
                               label.as_dict(),
                               room=psid,
                               namespace=GAME_NS)
            else:
                await sio.emit(
                    "Label.Delete",
                    {
                        "uuid": label.uuid,
                        "user": label.user.name
                    },
                    room=psid,
                    namespace=GAME_NS,
                )
Beispiel #6
0
async def add(sid: str, data: Dict[str, Any]):
    pr: PlayerRoom = game_state.get(sid)

    label = Label.get_or_none(uuid=data)

    if label is not None:
        logger.warn(
            f"{pr.player.name} tried to add a label with an id that already exists."
        )
        return

    if data["user"] != pr.player.name:
        logger.warn(f"{pr.player.name} tried to add a label for someone else.")
        return

    data["user"] = User.by_name(data["user"])
    label = Label.create(**data)

    for psid in game_state.get_sids(skip_sid=sid, room=pr.room):
        if game_state.get_user(psid) == pr.player or label.visible:
            await sio.emit("Label.Add",
                           label.as_dict(),
                           room=psid,
                           namespace=GAME_NS)