示例#1
0
def get_encoded_server_time(request):
    return HttpResponse(
        json.dumps({
            'token':
            utils.vigenere('my_pasta', str(int(time.time() * 10000)),
                           'encrypt')
        }))
示例#2
0
文件: views.py 项目: ceko/cekolabs
def magicka_trainer_save_history(request):    
    history = json.loads(request.POST.get('history'))
    label = json.loads(request.POST.get('label'))
    additional_attributes = json.loads(request.POST.get('additional_attributes'))
    leaderboard_name = request.POST.get('leaderboard_name')
    sec_tokens = json.loads(request.POST.get('tokens'))
    
    leaderboard_country = request.POST.get("leaderboard_country")
    if leaderboard_country and len(leaderboard_country) == 0:
        leaderboard_country = None
    
    round_history = core_models.TrainerRoundHistory()
    round_history.leaderboard_name = leaderboard_name
    round_history.country_code = leaderboard_country
    try:
        round_history.round_check_start = float(utils.vigenere('my_pasta', sec_tokens[0], 'decrypt')) / 10000.0
        if len(sec_tokens) > 1:
            round_history.round_check_end = float(utils.vigenere('my_pasta', sec_tokens[1], 'decrypt')) / 10000.0
        else:
            round_history.round_check_end = time.time()
    except Exception as e:
        round_history.flag_for_review = True
        
    #oops
    if label == 'olympic':
        round_history.mode = 'M'
    else:    
        round_history.mode = label[0].upper()
    round_history.submitted_by = get_client_ip(request)
    round_history.save()
    
    for entry in history:
        combo = core_models.TrainerComboHistory()
        combo.fumbled = entry['fumble']
        combo.round = round_history
        combo.time_to_complete = entry['time_to_complete']
        
        combo.save()
        for element in entry['element_queue']:
            combo_element = core_models.ComboElement()
            combo_element.combo = combo
            combo_element.element = element
            combo_element.save()
     
    #offensive mode
    if round_history.mode == 'O':
        offensive_mode_stats = core_models.OffensiveModeAttributes()
        offensive_mode_stats.round = round_history
        offensive_mode_stats.enemy_health = int(additional_attributes['enemy_health'])
        offensive_mode_stats.spell_delay_modifier = float(additional_attributes['spell_delay_modifier'])
        offensive_mode_stats.save()    
    elif round_history.mode == 'M':
        olympic_mode_stats = core_models.OlympicModeAttributes()
        olympic_mode_stats.round = round_history
        olympic_mode_stats.round_length = round_history.normalized_time_to_complete()
        olympic_mode_stats.save()
     
    if round_history.round_check_end and round_history.round_check_start:
        #simple check to see if they're cheating, obviously not foolproof
        check_diff_ms = (round_history.round_check_end - round_history.round_check_start) * 1000    
        if  abs(check_diff_ms - round_history.normalized_time_to_complete()) / float(check_diff_ms) > .05:
            round_history.flag_for_review = True
            round_history.save()
            
    return HttpResponse(json.dumps({ 'status': 'success', 'id': round_history.id }))   
示例#3
0
文件: views.py 项目: ceko/cekolabs
def get_encoded_server_time(request):
    return HttpResponse(json.dumps({ 'token': utils.vigenere('my_pasta', str(int(time.time()*10000)), 'encrypt') }))
示例#4
0
def magicka_trainer_save_history(request):
    history = json.loads(request.POST.get('history'))
    label = json.loads(request.POST.get('label'))
    additional_attributes = json.loads(
        request.POST.get('additional_attributes'))
    leaderboard_name = request.POST.get('leaderboard_name')
    sec_tokens = json.loads(request.POST.get('tokens'))

    leaderboard_country = request.POST.get("leaderboard_country")
    if leaderboard_country and len(leaderboard_country) == 0:
        leaderboard_country = None

    round_history = core_models.TrainerRoundHistory()
    round_history.leaderboard_name = leaderboard_name
    round_history.country_code = leaderboard_country
    try:
        round_history.round_check_start = float(
            utils.vigenere('my_pasta', sec_tokens[0], 'decrypt')) / 10000.0
        if len(sec_tokens) > 1:
            round_history.round_check_end = float(
                utils.vigenere('my_pasta', sec_tokens[1], 'decrypt')) / 10000.0
        else:
            round_history.round_check_end = time.time()
    except Exception as e:
        round_history.flag_for_review = True

    #oops
    if label == 'olympic':
        round_history.mode = 'M'
    else:
        round_history.mode = label[0].upper()
    round_history.submitted_by = get_client_ip(request)
    round_history.save()

    for entry in history:
        combo = core_models.TrainerComboHistory()
        combo.fumbled = entry['fumble']
        combo.round = round_history
        combo.time_to_complete = entry['time_to_complete']

        combo.save()
        for element in entry['element_queue']:
            combo_element = core_models.ComboElement()
            combo_element.combo = combo
            combo_element.element = element
            combo_element.save()

    #offensive mode
    if round_history.mode == 'O':
        offensive_mode_stats = core_models.OffensiveModeAttributes()
        offensive_mode_stats.round = round_history
        offensive_mode_stats.enemy_health = int(
            additional_attributes['enemy_health'])
        offensive_mode_stats.spell_delay_modifier = float(
            additional_attributes['spell_delay_modifier'])
        offensive_mode_stats.save()
    elif round_history.mode == 'M':
        olympic_mode_stats = core_models.OlympicModeAttributes()
        olympic_mode_stats.round = round_history
        olympic_mode_stats.round_length = round_history.normalized_time_to_complete(
        )
        olympic_mode_stats.save()

    if round_history.round_check_end and round_history.round_check_start:
        #simple check to see if they're cheating, obviously not foolproof
        check_diff_ms = (round_history.round_check_end -
                         round_history.round_check_start) * 1000
        if abs(check_diff_ms - round_history.normalized_time_to_complete()
               ) / float(check_diff_ms) > .05:
            round_history.flag_for_review = True
            round_history.save()

    return HttpResponse(
        json.dumps({
            'status': 'success',
            'id': round_history.id
        }))