コード例 #1
0
ファイル: app.py プロジェクト: zachdonovan/muddragon
def player_data():
    if not request.json or 'player' not in request.json:
        print(request, request.json)
        abort(400)

    db = get_db()

    player_data = request.json['player']
    friends = player_data['friends']
    puzzle_data = player_data['puzzle_data']
    del player_data['friends']
    del player_data['puzzle_data']

    player = Player.get_or_create(player_data)
    db.session.query(Player).filter(
        Player.social_id == player.social_id).update(player_data)

    for friend_social_id in friends:
        friend = Player.get_or_create({"social_id": friend_social_id})
        player.add_friendship(friend)

    for index, puzzle_id in enumerate(puzzle_data['puzzles']):
        Score.maybe_update_score({
            'player_social_id': player.social_id,
            'puzzle_id': puzzle_id,
            'score': puzzle_data['scores'][index],
            'stars': puzzle_data['stars'][index]})

    db.session.commit()

    return jsonify(
        _assemble_response(player))
コード例 #2
0
 def post(self):
     sig, payload = self.request.get('signed_request').split('.',1)
     sr = decode_signed_req(payload)
     
     if 'oauth_token' not in sr:
         self.response.out.write(template.render('index.html',{
             'signed_request': self.request.get('signed_request'),
             'not_authorised': True,
             }))
         return
     
     logging.warning('oauth_token provided')
     
     graph = get_facebook_data('graph',sr['oauth_token'])
     friends = get_facebook_data('friends',sr['oauth_token'])
     
     player = Player.get_or_create('facebook',graph['id'],graph['name'])
     
     action = self.request.get('action')
     
     if action:
         try:
             target = Player.get_or_create(self.request.get('target_network'),
                                           self.request.get('target_id'),
                                           self.request.get('target_username'))
             act(player,target,action,self.request.get('narration'))
             player = Player.get_by_key_name('facebook|%s' % graph['id']) # TODO: figure out why I have this step and comment on it
         except Alert, a:
             logging.warning(a)           
コード例 #3
0
 def get_players(self, battle_results):
     players = {}
     names = battle_results['collected'].keys()
     for name in names:
         path = battle_results['players_modules'][name]
         player, _ = Player.get_or_create(name=name, path=path)
         players[name] = player
     return players
コード例 #4
0
    def add_win(self, data, win_type):
        win = Win.create()
        total_kills = 0
        for discord_id, kills in data.items():
            player, created = Player.get_or_create(discord_id=discord_id)
            exec('player.total_{} += {}'.format(self.__win_type[win_type],
                                                kills))
            player.total_kills += kills
            player.save()

            Winner.create(win=win, player=player, kills=kills)
            total_kills += kills
        win.total_kills = total_kills
        win.win_type = win_type
        win.save()
コード例 #5
0
ファイル: views.py プロジェクト: warownia1/TheResistance
def join():
    """
    Route invoked when a new player joins the room.
    Adds player to the room and sets his session cookie.
    Posts the join message to other players in the room.
    """
    username = request.forms.get("username")
    if len(username) == 0:
        return HTTPError(403, "Username too short")
    room_code = request.forms.get("room").upper()
    try:
        room = Room.select(Room).where(Room.code == room_code).get()
    except Room.DoesNotExist:
        return HTTPError(404, "Room does not exist")

    sessid = request.cookies.get("sessid", generate_sessid())
    player, created = Player.get_or_create(sessid=sessid, room=room, defaults={"name": username})
    if created:
        message_data = {"player": {"id": player.id, "name": player.name}}
        post_message([Msg("join", message_data)], room=room)
    response.set_cookie("sessid", sessid, path="/")
    return redirect("/game/%s/lobby" % room.code)