Beispiel #1
0
def addOpenedPuzzlePiece():
    result = dict(
        type=ProtocolTypes.AddPuzzlePiece,
        result=ResultCodes.Success
        )

    writeDirtyLog('addOpenedPuzzlePiece: ' + request.form['data'])

    if request.form['data']:
        got_data = json.loads(request.form['data'])
        from_keys = [
            'session_id',
            # 'puzzle_index', 'condition'
        ]
        if checkContainKeys(from_keys, got_data):
            result['result'], got_user = checkSessionId(got_data['session_id'])

            if got_user:
                find_puzzle_piece = OpenedPuzzlePiece.query.filter_by(
                    user_id=got_user.id, puzzle_index=got_data['puzzle_index']).first()
                if find_puzzle_piece:
                    find_puzzle_piece.condition = got_data['condition']
                    db_session.add(find_puzzle_piece)
                else:
                    made_puzzle_piece = OpenedPuzzlePiece(
                        got_user.id, got_data['puzzle_index'], got_data['condition'])
                    db_session.add(made_puzzle_piece)

                result['result'] = commitData()
        else:
            result['result'] = ResultCodes.InputParamError
    else:
        result['result'] = ResultCodes.AccessError

    return str(json.dumps(result))
Beispiel #2
0
def useFriendShipPoint():
    writeDirtyLog('useFriendShipPoint: ' + request.form['data'])
    result = dict(
        type=ProtocolTypes.UseFriendShipPoint,
        result=ResultCodes.Success
    )

    if request.form['data']:
        got_data = json.loads(request.form['data'])

        from_keys = ['session_id']
        if checkContainKeys(from_keys, got_data):
            result['result'], got_user = checkSessionId(got_data['session_id'])

            if got_user:
                max_friendship_point = Config.query.filter_by(str_key='max_friendship_point').first()
                if max_friendship_point:
                    if got_user.friendship_point >= int(max_friendship_point.str_value):
                        got_user.friendship_point -= int(max_friendship_point.str_value)


                        import random

                        got_cash_rates = [16] + [7] * 12
                        found_rate = random.random() * 100
                        rate_sum = 0
                        got_cash_amount = 0

                        for x in range(len(got_cash_rates)):
                            rate_sum += got_cash_rates[x]

                            if found_rate <= rate_sum:
                                got_cash_amount = x + 1
                                break

                        except_amount = range(1, 14)
                        except_amount.remove(got_cash_amount)

                        dummy_amount = list()

                        for num in range(4):
                            got_num = random.choice(except_amount)
                            except_amount.remove(got_num)
                            dummy_amount.append(got_num)


                        got_user.cash += got_cash_amount
                        db_session.add(got_user)
                        result['result'] = commitData()
                        result['cash_amount'] = got_cash_amount
                        result['dummy_amount'] = dummy_amount
                    else:
                        result['result'] = ResultCodes.InputParamError
                else:
                    result['result'] = ResultCodes.NoData
        else:
            result['result'] = ResultCodes.InputParamError
    else:
        result['result'] = ResultCodes.AccessError

    return str(json.dumps(result))