 func           = require 'lang/func'
 type           = require 'lang/type'
 event          = require 'util/event'
+prefs          = require 'util/prefs'
 dateForElement = (require 'dom/date').forElement
 dir            = require 'io/dir'
 file           = require 'io/file'

    logger.warn args... if args.length
    delete @tmp.account

  actionTimeoutDuration: 60000 # 1m
  globalTimeoutDuration: 300000 # 5m
  securityTimeoutDuration: 180000 # 3m

  setErrorTimeout: (timeoutType) ->
    duration = @["#{timeoutType}TimeoutDuration"]
    tt = @_timeouts
    tt ||= @_timeouts = {}

    @clearErrorTimeout timeoutType

    logger.debug "Timeout ", timeoutType, " set (", duration, ")"

    tt[timeoutType] = setTimeout =>
      event.trigger this, 'timeout', [timeoutType]
      return if @job.done
      logger.error "Timeout ", timeoutType, " (", duration, ") reached, abandoning job"
      tryCatch "Player#setErrorTimeout(page dump)", =>
        @page?.dumpPrivately()
      @job.fail 504, "timeout.#{timeoutType}"
    , duration

  clearErrorTimeout: (timeoutType) ->
    if @_timeouts?[timeoutType]

{Pathway}      = require 'xpath'

{tryThrow, tryCatch} = require 'util/try'

DEFAULT_TIMEOUTS =
  action:    60 # 1m
  global:   300 # 5m
  security: 180 # 3m

class Player
  @register: (params) ->
