Exemple #1
0
async def claim_invite(request):
    user = await check_authorized(request)
    data = await request.json()
    room = Room.get_or_none(invitation_code=data["code"])
    if room is None:
        return web.HTTPNotFound()
    else:
        if user.name != room.creator and not PlayerRoom.get_or_none(
                player=user, room=room):
            PlayerRoom.create(player=user, room=room)

            for csid in state.get_sids(user=room.creator, room=room):
                await sio.emit(
                    "Room.Info.Players.Add",
                    {
                        "id": user.id,
                        "name": user.name
                    },
                    room=csid,
                    namespace="/planarally",
                )
        return web.json_response({
            "sessionUrl":
            f"/game/{urllib.parse.quote(room.creator.name, safe='')}/{urllib.parse.quote(room.name, safe='')}"
        })
Exemple #2
0
async def claim_invite(request):
    user = await check_authorized(request)
    data = await request.json()
    room = Room.get_or_none(invitation_code=data["code"])
    if room is None:
        return web.HTTPNotFound()
    else:
        if user != room.creator and not PlayerRoom.get_or_none(player=user,
                                                               room=room):
            query = PlayerRoom.select().where(PlayerRoom.room == room)
            try:
                loc = query.where(
                    PlayerRoom.role == Role.PLAYER)[0].active_location
            except IndexError:
                loc = query.where(
                    PlayerRoom.role == Role.DM)[0].active_location
            PlayerRoom.create(player=user,
                              room=room,
                              role=Role.PLAYER,
                              active_location=loc)

            for csid in game_state.get_sids(player=room.creator, room=room):
                await sio.emit(
                    "Room.Info.Players.Add",
                    {
                        "id": user.id,
                        "name": user.name
                    },
                    room=csid,
                    namespace="/planarally",
                )
        return web.json_response({
            "sessionUrl":
            f"/game/{urllib.parse.quote(room.creator.name, safe='')}/{urllib.parse.quote(room.name, safe='')}"
        })
Exemple #3
0
async def claim_invite(request):
    user = await check_authorized(request)
    room = Room.get_or_none(invitation_code=request.match_info["code"])
    if room is None:
        return web.HTTPNotFound()
    else:
        if user.name != room.creator and not PlayerRoom.get_or_none(
                player=user, room=room):
            PlayerRoom.create(player=user, room=room)
        return web.HTTPFound(f"/rooms/{room.creator.name}/{room.name}")
Exemple #4
0
async def claim_invite(request):
    user = await check_authorized(request)
    data = await request.json()
    room = Room.get_or_none(invitation_code=data["code"])
    if room is None:
        return web.HTTPNotFound()
    else:
        if user.name != room.creator and not PlayerRoom.get_or_none(
                player=user, room=room):
            PlayerRoom.create(player=user, room=room)
        return web.json_response(
            {"sessionUrl": f"/game/{room.creator.name}/{room.name}"})
Exemple #5
0
async def kick_player(sid: int, player_id: int):
    pr: PlayerRoom = game_state.get(sid)

    if pr.role != Role.DM:
        logger.warning(f"{pr.player.name} attempted to refresh the invitation code.")
        return

    pr = PlayerRoom.get_or_none(player=player_id, room=pr.room)
    if pr:
        for psid in game_state.get_sids(player=pr.player, room=pr.room):
            await sio.disconnect(psid, namespace=GAME_NS)
        pr.delete_instance(True)
Exemple #6
0
async def kick_player(sid, playerId):
    sid_data = state.sid_map[sid]
    user = sid_data["user"]
    room = sid_data["room"]

    if room.creator != user:
        logger.warning(
            f"{user.name} attempted to refresh the invitation code.")
        return

    pr = PlayerRoom.get_or_none(player=playerId, room=room)
    if pr:
        for psid in state.get_sids(user=pr.player, room=room):
            await sio.disconnect(psid, namespace="/planarally")
        pr.delete_instance(True)
Exemple #7
0
async def kick_player(sid: str, player_id: int):
    pr: PlayerRoom = game_state.get(sid)

    if pr.role != Role.DM:
        logger.warning(f"{pr.player.name} attempted to refresh the invitation code.")
        return

    pr = PlayerRoom.get_or_none(player=player_id, room=pr.room)
    if pr is None:
        return

    creator: User = pr.room.creator

    if pr.player != creator and creator == pr.player:
        logger.warning(f"{pr.player.name} attempted to kick the campaign creator")
        return

    for psid in game_state.get_sids(player=pr.player, room=pr.room):
        await sio.disconnect(psid, namespace=GAME_NS)
    pr.delete_instance(True)