mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-02-17 08:50:58 -05:00
Make multiplayer work in esper mode
This commit is contained in:
parent
42b49975e8
commit
22007fff9b
5 changed files with 27 additions and 7 deletions
|
@ -125,7 +125,9 @@ module.exports = class LevelLoader extends CocoClass
|
|||
@sessionResource = @supermodel.loadModel(session, 'level_session', {cache: false})
|
||||
@session = @sessionResource.model
|
||||
if @opponentSessionID
|
||||
opponentSession = new LevelSession().setURL "/db/level.session/#{@opponentSessionID}"
|
||||
opponentURL = "/db/level.session/#{@opponentSessionID}"
|
||||
opponentURL += "?interpret=true" if utils.getQueryVariable 'esper'
|
||||
opponentSession = new LevelSession().setURL opponentURL
|
||||
opponentSession.project = session.project if @headless
|
||||
@opponentSessionResource = @supermodel.loadModel(opponentSession, 'opponent_session', {cache: false})
|
||||
@opponentSession = @opponentSessionResource.model
|
||||
|
@ -149,6 +151,12 @@ module.exports = class LevelLoader extends CocoClass
|
|||
else if codeLanguage = utils.getQueryVariable 'codeLanguage'
|
||||
session.set 'codeLanguage', codeLanguage
|
||||
@loadCodeLanguagesForSession session
|
||||
if compressed = session.get 'interpret'
|
||||
uncompressed = LZString.decompressFromUTF16 compressed
|
||||
code = session.get 'code'
|
||||
code[if session.get('team') is 'humans' then 'hero-placeholder' else 'hero-placeholder-1'].plan = uncompressed
|
||||
session.set 'code', code
|
||||
session.unset 'interpret'
|
||||
if session is @session
|
||||
@addSessionBrowserInfo session
|
||||
# hero-ladder games require the correct session team in level:loaded
|
||||
|
|
|
@ -224,7 +224,10 @@ module.exports = class PlayLevelView extends RootView
|
|||
opponentSpells = opponentSpells.concat spells
|
||||
if (not @session.get('teamSpells')) and @otherSession?.get('teamSpells')
|
||||
@session.set('teamSpells', @otherSession.get('teamSpells'))
|
||||
opponentCode = @otherSession?.get('transpiledCode') or {}
|
||||
if @getQueryVariable 'esper'
|
||||
opponentCode = @otherSession?.get('code') or {}
|
||||
else
|
||||
opponentCode = @otherSession?.get('transpiledCode') or {}
|
||||
myCode = @session.get('code') or {}
|
||||
for spell in opponentSpells
|
||||
[thang, spell] = spell.split '/'
|
||||
|
|
|
@ -2,6 +2,7 @@ SpellView = require './SpellView'
|
|||
SpellListTabEntryView = require './SpellListTabEntryView'
|
||||
{me} = require 'core/auth'
|
||||
{createAetherOptions} = require 'lib/aether_utils'
|
||||
utils = require 'core/utils'
|
||||
|
||||
module.exports = class Spell
|
||||
loaded: false
|
||||
|
@ -214,6 +215,7 @@ module.exports = class Spell
|
|||
|
||||
shouldUseTranspiledCode: ->
|
||||
# Determine whether this code has already been transpiled, or whether it's raw source needing transpilation.
|
||||
return false if utils.getQueryVariable 'esper' # Don't use transpiled code with interpreter
|
||||
return true if @spectateView # Use transpiled code for both teams if we're just spectating.
|
||||
return true if @isEnemySpell() # Use transpiled for enemy spells.
|
||||
# Players without permissions can't view the raw code.
|
||||
|
|
|
@ -70,6 +70,7 @@
|
|||
"gridfs-stream": "~1.1.1",
|
||||
"jsondiffpatch": "0.1.17",
|
||||
"lodash": "~2.4.1",
|
||||
"lz-string": "1.3.3",
|
||||
"mailchimp-api": "2.0.x",
|
||||
"moment": "~2.5.0",
|
||||
"mongodb": "^2.0.28",
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
LevelSession = require './../models/LevelSession'
|
||||
Handler = require '../commons/Handler'
|
||||
log = require 'winston'
|
||||
LZString = require 'lz-string'
|
||||
|
||||
TIMEOUT = 1000 * 30 # no activity for 30 seconds means it's not active
|
||||
|
||||
|
@ -14,14 +15,19 @@ class LevelSessionHandler extends Handler
|
|||
super(arguments...)
|
||||
|
||||
formatEntity: (req, document) ->
|
||||
documentObject = super(req, document)
|
||||
if req.user?.isAdmin() or
|
||||
document = super(req, document)
|
||||
submittedCode = document.submittedCode
|
||||
unless req.user?.isAdmin() or
|
||||
req.user?.id is document.creator or
|
||||
('employer' in (req.user?.get('permissions') ? [])) or
|
||||
not document.submittedCode # TODO: only allow leaderboard access to non-top-5 solutions
|
||||
return documentObject
|
||||
else
|
||||
return _.omit documentObject, @privateProperties
|
||||
document = _.omit document, @privateProperties
|
||||
if req.query.interpret
|
||||
plan = submittedCode[if document.team is 'humans' then 'hero-placeholder' else 'hero-placeholder-1'].plan
|
||||
plan = LZString.compressToUTF16 plan
|
||||
document.interpret = plan
|
||||
document.code = submittedCode
|
||||
return document
|
||||
|
||||
getActiveSessions: (req, res) ->
|
||||
return @sendForbiddenError(res) unless req.user?.isAdmin()
|
||||
|
|
Loading…
Reference in a new issue