mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-28 01:55:38 -05:00
Added checking level ladder status before submitting
This commit is contained in:
parent
2fa40fb2db
commit
2f378106ca
2 changed files with 25 additions and 17 deletions
|
@ -95,7 +95,7 @@ module.exports = class MyMatchesTabView extends CocoView
|
|||
success = => @setRankingButtonText(button, 'ranked')
|
||||
failure = => @setRankingButtonText(button, 'failed')
|
||||
|
||||
ajaxData = { session: sessionID, levelID: @level.attributes.original, levelMajorVersion: @level.attributes.version.major }
|
||||
ajaxData = { session: sessionID, levelID: @level.id, originalLevelID: @level.attributes.original, levelMajorVersion: @level.attributes.version.major }
|
||||
$.ajax '/queue/scoring', {
|
||||
type: 'POST'
|
||||
data: ajaxData
|
||||
|
|
|
@ -8,6 +8,7 @@ db = require './../routes/db'
|
|||
mongoose = require 'mongoose'
|
||||
queues = require '../commons/queue'
|
||||
LevelSession = require '../levels/sessions/LevelSession'
|
||||
Level = require '../levels/Level'
|
||||
TaskLog = require './task/ScoringTask'
|
||||
bayes = new (require 'bayesian-battle')()
|
||||
|
||||
|
@ -48,7 +49,8 @@ addPairwiseTaskToQueue = (taskPair, cb) ->
|
|||
|
||||
module.exports.createNewTask = (req, res) ->
|
||||
requestSessionID = req.body.session
|
||||
requestLevelID = req.body.levelID
|
||||
requestLevelID = req.body.originalLevelID
|
||||
requestCurrentLevelID = req.body.levelID
|
||||
requestLevelMajorVersion = parseInt(req.body.levelMajorVersion)
|
||||
|
||||
validatePermissions req, requestSessionID, (error, permissionsAreValid) ->
|
||||
|
@ -56,21 +58,27 @@ module.exports.createNewTask = (req, res) ->
|
|||
unless permissionsAreValid then return errors.forbidden res, "You do not have the permissions to submit that game to the leaderboard"
|
||||
|
||||
return errors.badInput res, "The session ID is invalid" unless typeof requestSessionID is "string"
|
||||
Level.findOne({_id: requestCurrentLevelID}).lean().select('type').exec (err, levelWithType) ->
|
||||
if err? then return errors.serverError res, "There was an error finding the level type"
|
||||
|
||||
fetchSessionToSubmit requestSessionID, (err, sessionToSubmit) ->
|
||||
if err? then return errors.serverError res, "There was an error finding the given session."
|
||||
if not levelWithType.type or levelWithType.type isnt "ladder"
|
||||
console.log "The level type of level with ID #{requestLevelID} is #{levelWithType.type}"
|
||||
return errors.badInput res, "That level isn't a ladder level"
|
||||
|
||||
updateSessionToSubmit sessionToSubmit, (err, data) ->
|
||||
if err? then return errors.serverError res, "There was an error updating the session"
|
||||
opposingTeam = calculateOpposingTeam(sessionToSubmit.team)
|
||||
fetchInitialSessionsToRankAgainst opposingTeam,requestLevelID, requestLevelMajorVersion, (err, sessionsToRankAgainst) ->
|
||||
if err? then return errors.serverError res, "There was an error fetching the sessions to rank against"
|
||||
fetchSessionToSubmit requestSessionID, (err, sessionToSubmit) ->
|
||||
if err? then return errors.serverError res, "There was an error finding the given session."
|
||||
|
||||
taskPairs = generateTaskPairs(sessionsToRankAgainst, sessionToSubmit)
|
||||
sendEachTaskPairToTheQueue taskPairs, (taskPairError) ->
|
||||
if taskPairError? then return errors.serverError res, "There was an error sending the task pairs to the queue"
|
||||
updateSessionToSubmit sessionToSubmit, (err, data) ->
|
||||
if err? then return errors.serverError res, "There was an error updating the session"
|
||||
opposingTeam = calculateOpposingTeam(sessionToSubmit.team)
|
||||
fetchInitialSessionsToRankAgainst opposingTeam,requestLevelID, requestLevelMajorVersion, (err, sessionsToRankAgainst) ->
|
||||
if err? then return errors.serverError res, "There was an error fetching the sessions to rank against"
|
||||
|
||||
sendResponseObject req, res, {"message":"All task pairs were succesfully sent to the queue"}
|
||||
taskPairs = generateTaskPairs(sessionsToRankAgainst, sessionToSubmit)
|
||||
sendEachTaskPairToTheQueue taskPairs, (taskPairError) ->
|
||||
if taskPairError? then return errors.serverError res, "There was an error sending the task pairs to the queue"
|
||||
|
||||
sendResponseObject req, res, {"message":"All task pairs were succesfully sent to the queue"}
|
||||
|
||||
module.exports.dispatchTaskToConsumer = (req, res) ->
|
||||
if isUserAnonymous(req) then return errors.forbidden res, "You need to be logged in to simulate games"
|
||||
|
|
Loading…
Reference in a new issue