Beispiel #1
0
class CaptchaController(Controller):
    __api = CAPTCHA_API_CLASS()
    __battlesTillCaptcha = 99
    __triesLeft = 3
    _CLIENT_ERROR_CODES = {'enqueue-failure': i18n.makeString('#captcha:error-codes/enqueue-failure'),
     'response-is-empty': i18n.makeString('#captcha:error-codes/response-is-empty'),
     'challenge-is-empty': i18n.makeString('#captcha:error-codes/challenge-is-empty')}

    def __init__(self, proxy):
        super(CaptchaController, self).__init__(proxy)
        self.__tryReset = False
        self.__weaver = None
        self.onCaptchaInputCanceled = Event.Event()
        return

    def fini(self):
        self.onCaptchaInputCanceled.clear()
        self.__stop()
        self.__tryReset = False
        super(CaptchaController, self).fini()

    def onLobbyInited(self, event):
        self.__weaver = Weaver()
        BigWorld.player().stats.get('battlesTillCaptcha', self.__pc_onReceiveBattlesTillCaptcha)
        BigWorld.player().stats.get('captchaTriesLeft', self.__pc_onReceiveCaptchaTriesLeft)
        g_playerEvents.onEnqueueRandomFailure += self.__pe_onEnqueueRandomFailure
        g_playerEvents.onEnqueueEventBattlesFailure += self.__pe_onEnqueueEventBattlesFailure
        g_clientUpdateManager.addCallbacks({'stats.battlesTillCaptcha': self.__onBattlesTillCaptcha,
         'stats.captchaTriesLeft': self.__onCaptchaTriesLeft})

    def onDisconnected(self):
        self.__stop()

    def onAvatarBecomePlayer(self):
        self.__stop()

    def showCaptcha(self, callback):
        if self.__triesLeft <= CAPTCHA_TRIES_LEFT_NOTIFY_THESHOLD:
            errorText = i18n.makeString('#captcha:notification/remains-to-attempt', self.__triesLeft if self.__triesLeft > 0 else 0)
        else:
            errorText = None
        _showDialog(errorText, callback)
        return

    def getCaptchaServerError(self, errorCode):
        errorText = self.__api.getI18nServerErrorText(errorCode)
        if errorCode == self.__api._RESPONSE_IS_INCORRECT_CODE:
            triesLeftString = i18n.makeString('#captcha:notification/remains-to-attempt', self.__triesLeft)
            errorText = '{0:>s} {1:>s}'.format(errorText, triesLeftString)
        return errorText

    def getCaptchaClientError(self, errorCode):
        if errorCode in self._CLIENT_ERROR_CODES:
            errorMsg = i18n.makeString(self._CLIENT_ERROR_CODES[errorCode])
        else:
            errorMsg = errorCode
        return errorMsg

    def isCaptchaRequired(self):
        return False

    def getTriesLeft(self):
        return self.__triesLeft

    def getPublicKey(self):
        settings = BigWorld.player().serverSettings
        if settings.has_key('captchaKey'):
            return settings['captchaKey']
        else:
            return None

    def getCaptchaRegex(self):
        return BigWorld.player().serverSettings.get('reCaptchaParser', '')

    def getImageSource(self):
        return self.__api.getImageSource(self.getPublicKey(), self.getCaptchaRegex())

    def getImageSize(self):
        return self.__api._IMAGE_SIZE

    @async
    def verify(self, challenge, response, callback = None):
        BigWorld.player().challengeCaptcha(challenge, response, partial(self.__pc_onCaptchaChecked, callback))

    def tryBattlesTillCaptchaReset(self):
        if self.__tryReset:
            return
        if self.__triesLeft > 1:
            self.__tryReset = True
            LOG_WARNING('Client try battlesTillCaptcha reset')
            BigWorld.player().challengeCaptcha('', '', lambda resultID, errorCode: None)

    def __stop(self):
        if self.__weaver is not None:
            self.__weaver.clear()
            self.__weaver = None
        g_clientUpdateManager.removeObjectCallbacks(self)
        g_playerEvents.onEnqueueEventBattlesFailure -= self.__pe_onEnqueueEventBattlesFailure
        g_playerEvents.onEnqueueRandomFailure -= self.__pe_onEnqueueRandomFailure
        return

    def __pe_onEnqueueRandomFailure(self, errorCode, _):
        if errorCode != JOIN_FAILURE.CAPTCHA:
            return

        def callback(result):
            if result:
                from CurrentVehicle import g_currentVehicle
                BigWorld.player().enqueueRandom(g_currentVehicle.invID)
            else:
                from gui.Scaleform.Waiting import Waiting
                Waiting.rollback()
                self.onCaptchaInputCanceled()

        _showDialog(i18n.makeString(self._CLIENT_ERROR_CODES['enqueue-failure']), callback)

    def __pe_onEnqueueEventBattlesFailure(self, errorCode, _):
        if errorCode != JOIN_FAILURE.CAPTCHA:
            return

        def callback(result):
            if result:
                from CurrentVehicle import g_currentVehicle
                BigWorld.player().enqueueEventBattles(g_currentVehicle.invID)
            else:
                from gui.Scaleform.Waiting import Waiting
                Waiting.rollback()
                self.onCaptchaInputCanceled()

        _showDialog(i18n.makeString(self._CLIENT_ERROR_CODES['enqueue-failure']), callback)

    def __onBattlesTillCaptcha(self, value):
        self.__battlesTillCaptcha = value
        if self.isCaptchaRequired():
            if self.__weaver.findPointcut(ShowCaptchaPointcut) is -1:
                self.__weaver.weave(pointcut=ShowCaptchaPointcut, aspects=[ShowCaptchaAspect(self)])

    def __onCaptchaTriesLeft(self, value):
        self.__triesLeft = value

    def __pc_onReceiveBattlesTillCaptcha(self, resultID, value):
        if resultID < 0:
            LOG_ERROR('Server return error: ', resultID, value)
            return
        self.__battlesTillCaptcha = value
        if self.isCaptchaRequired():
            if self.__weaver.findPointcut(ShowCaptchaPointcut) is -1:
                self.__weaver.weave(pointcut=ShowCaptchaPointcut, aspects=[ShowCaptchaAspect(self)])

    def __pc_onReceiveCaptchaTriesLeft(self, resultID, value):
        if resultID < 0:
            LOG_ERROR('Server return error: ', resultID, value)
            return
        self.__triesLeft = value

    def __pc_onCaptchaChecked(self, callback, resultID, responseCode):
        isVerified = resultID == AccountCommands.RES_SUCCESS
        if isVerified:
            self.__weaver.clear(idx=self.__weaver.findPointcut(ShowCaptchaPointcut))
        callback((isVerified, responseCode))
class CaptchaController(object):
    __api = CAPTCHA_API_CLASS()
    __battlesTillCaptcha = 99
    __triesLeft = 3
    _CLIENT_ERROR_CODES = {
        "enqueue-failure": i18n.makeString("#captcha:error-codes/enqueue-failure"),
        "response-is-empty": i18n.makeString("#captcha:error-codes/response-is-empty"),
        "challenge-is-empty": i18n.makeString("#captcha:error-codes/challenge-is-empty"),
    }

    def init(self):
        self.__tryReset = False
        self.__weaver = Weaver()

    def fini(self):
        self.stop()
        self.__tryReset = False
        if self.__weaver is not None:
            self.__weaver.clear()
            self.__weaver = None
        return

    def start(self):
        BigWorld.player().stats.get("battlesTillCaptcha", self.__pc_onReceiveBattlesTillCaptcha)
        BigWorld.player().stats.get("captchaTriesLeft", self.__pc_onReceiveCaptchaTriesLeft)
        g_playerEvents.onEnqueueRandomFailure += self.__pe_onEnqueueFailure
        g_clientUpdateManager.addCallbacks(
            {
                "stats.battlesTillCaptcha": self.__onBattlesTillCaptcha,
                "stats.captchaTriesLeft": self.__onCaptchaTriesLeft,
            }
        )

    def stop(self):
        g_clientUpdateManager.removeObjectCallbacks(self)
        g_playerEvents.onEnqueueRandomFailure -= self.__pe_onEnqueueFailure

    def showCaptcha(self, callback):
        if self.__triesLeft <= CAPTCHA_TRIES_LEFT_NOTIFY_THESHOLD:
            errorText = i18n.makeString(
                "#captcha:notification/remains-to-attempt", self.__triesLeft if self.__triesLeft > 0 else 0
            )
        else:
            errorText = None
        _showDialog(errorText, callback)
        return

    def getCaptchaServerError(self, errorCode):
        errorText = self.__api.getI18nServerErrorText(errorCode)
        if errorCode == self.__api._RESPONSE_IS_INCORRECT_CODE:
            triesLeftString = i18n.makeString("#captcha:notification/remains-to-attempt", self.__triesLeft)
            errorText = "{0:>s} {1:>s}".format(errorText, triesLeftString)
        return errorText

    def getCaptchaClientError(self, errorCode):
        if errorCode in self._CLIENT_ERROR_CODES:
            errorMsg = i18n.makeString(self._CLIENT_ERROR_CODES[errorCode])
        else:
            errorMsg = errorCode
        return errorMsg

    def isCaptchaRequired(self):
        return self.__battlesTillCaptcha <= 0

    def getTriesLeft(self):
        return self.__triesLeft

    def getPublicKey(self):
        settings = BigWorld.player().serverSettings
        if settings.has_key("captchaKey"):
            return settings["captchaKey"]
        else:
            return None

    def getCaptchaRegex(self):
        return BigWorld.player().serverSettings.get("reCaptchaParser", "")

    def getImageSource(self):
        return self.__api.getImageSource(self.getPublicKey(), self.getCaptchaRegex())

    def getImageSize(self):
        return self.__api._IMAGE_SIZE

    @async
    def verify(self, challenge, response, callback=None):
        BigWorld.player().challengeCaptcha(challenge, response, partial(self.__pc_onCaptchaChecked, callback))

    def tryBattlesTillCaptchaReset(self):
        if self.__tryReset:
            return
        if self.__triesLeft > 1:
            self.__tryReset = True
            LOG_WARNING("Client try battlesTillCaptcha reset")
            BigWorld.player().challengeCaptcha("", "", lambda resultID, errorCode: None)

    def __pe_onEnqueueFailure(self, errorCode, _):
        if errorCode != JOIN_FAILURE.CAPTCHA:
            return
        _showDialog(i18n.makeString(self._CLIENT_ERROR_CODES["enqueue-failure"]))

    def __onBattlesTillCaptcha(self, value):
        self.__battlesTillCaptcha = value
        if self.isCaptchaRequired():
            if self.__weaver.findPointcut(ShowCaptchaPointcut) is -1:
                self.__weaver.weave(pointcut=ShowCaptchaPointcut, aspects=[ShowCaptchaAspect(self)])

    def __onCaptchaTriesLeft(self, value):
        self.__triesLeft = value

    def __pc_onReceiveBattlesTillCaptcha(self, resultID, value):
        if resultID < 0:
            LOG_ERROR("Server return error: ", resultID, value)
            return
        self.__battlesTillCaptcha = value
        if self.isCaptchaRequired():
            if self.__weaver.findPointcut(ShowCaptchaPointcut) is -1:
                self.__weaver.weave(pointcut=ShowCaptchaPointcut, aspects=[ShowCaptchaAspect(self)])

    def __pc_onReceiveCaptchaTriesLeft(self, resultID, value):
        if resultID < 0:
            LOG_ERROR("Server return error: ", resultID, value)
            return
        self.__triesLeft = value

    def __pc_onCaptchaChecked(self, callback, resultID, responseCode):
        isVerified = resultID == AccountCommands.RES_SUCCESS
        if isVerified:
            self.__weaver.clear(idx=self.__weaver.findPointcut(ShowCaptchaPointcut))
        callback((isVerified, responseCode))
Beispiel #3
0
class WalletController(IWalletController):
    itemsCache = dependency.descriptor(IItemsCache)
    settingsCore = dependency.descriptor(ISettingsCore)

    class STATUS(CONST_CONTAINER):
        SYNCING = 0
        NOT_AVAILABLE = 1
        AVAILABLE = 2

    def __init__(self):
        super(WalletController, self).__init__()
        self.onWalletStatusChanged = Event.Event()
        self.__currentStatus = None
        self.__currentCallbackId = None
        self.__useGold = False
        self.__useFreeXP = False
        self.__weaver = None
        return

    def init(self):
        g_clientUpdateManager.addCallbacks({'cache.mayConsumeWalletResources': self.__onWalletStatusChanged})

    def fini(self):
        g_clientUpdateManager.removeObjectCallbacks(self, force=True)
        self.__clearCallback()
        self.__clearWeaver()
        super(WalletController, self).fini()

    def onLobbyStarted(self, ctx):
        wallet = BigWorld.player().serverSettings['wallet']
        self.__useGold = bool(wallet[0])
        self.__useFreeXP = bool(wallet[1])
        if self.__useFreeXP:
            self.__checkFreeXPConditions()
        if self.itemsCache.items.stats.mayConsumeWalletResources:
            status = self.STATUS.AVAILABLE
        else:
            status = self.STATUS.SYNCING
        self.__processStatus(status, True)

    def onAvatarBecomePlayer(self):
        self.__clearWeaver()

    def onDisconnected(self):
        self.__clearWeaver()

    @property
    def status(self):
        return self.__currentStatus

    @property
    def componentsStatuses(self):
        return {'gold': self.__currentStatus if self.__useGold else self.STATUS.AVAILABLE,
         'freeXP': self.__currentStatus if self.__useFreeXP else self.STATUS.AVAILABLE,
         'credits': self.__currentStatus if constants.IS_SINGAPORE else self.STATUS.AVAILABLE,
         'crystal': self.STATUS.AVAILABLE}

    @property
    def isSyncing(self):
        return self.__checkStatus(self.STATUS.SYNCING)

    @property
    def isNotAvailable(self):
        return self.__checkStatus(self.STATUS.NOT_AVAILABLE)

    @property
    def isAvailable(self):
        return self.__checkStatus(self.STATUS.AVAILABLE)

    @property
    def useGold(self):
        return self.__useGold

    @property
    def useFreeXP(self):
        return self.__useFreeXP

    def cleanWeave(self, obj):
        if self.__weaver:
            for value in obj:
                self.__weaver.clear(idx=self.__weaver.findPointcut(value))

    def __clearWeaver(self):
        if self.__weaver is not None:
            self.__weaver.clear()
            self.__weaver = None
        return

    def __processCallback(self):
        self.__currentCallbackId = None
        if self.isSyncing:
            self.__processStatus(self.STATUS.NOT_AVAILABLE)
            message = '#system_messages:wallet/not_available'
            if constants.IS_SINGAPORE:
                message += '_asia'
            if not self.__useFreeXP:
                message += '_gold'
            elif not self.__useGold:
                message += '_freexp'
            SystemMessages.pushI18nMessage(message, type=SM_TYPE.Warning)
        return

    def __clearCallback(self):
        if self.__currentCallbackId is not None:
            BigWorld.cancelCallback(self.__currentCallbackId)
            self.__currentCallbackId = None
        return

    def __processStatus(self, status, initialize = False):
        if self.__currentStatus != status:
            self.__currentStatus = status
            self.__notify()
            LOG_DEBUG('Wallet status changed:', self.__currentStatus)
            if self.isAvailable:
                self.__clearCallback()
                if not initialize:
                    message = '#system_messages:wallet/available'
                    if constants.IS_SINGAPORE:
                        message += '_asia'
                    if not self.__useFreeXP:
                        message += '_gold'
                    elif not self.__useGold:
                        message += '_freexp'
                    SystemMessages.pushI18nMessage(message, type=SM_TYPE.Information)
            elif self.isSyncing and self.__currentCallbackId is None:
                self.__currentCallbackId = BigWorld.callback(30, self.__processCallback)
        return

    def __onWalletStatusChanged(self, available):
        status = self.__currentStatus
        if available and not self.isAvailable:
            status = self.STATUS.AVAILABLE
        elif not available and self.isAvailable:
            status = self.STATUS.SYNCING
        self.__processStatus(status)

    def __checkStatus(self, status):
        return self.__currentStatus == status

    def __notify(self):
        self.onWalletStatusChanged(self.componentsStatuses)

    def __checkFreeXPConditions(self):
        from account_helpers.AccountSettings import AccountSettings, GUI_START_BEHAVIOR
        defaults = AccountSettings.getFilterDefault(GUI_START_BEHAVIOR)
        filters = self.settingsCore.serverSettings.getSection(GUI_START_BEHAVIOR, defaults)
        if filters['isFreeXPInfoDialogShowed']:
            return
        self.__weaver = Weaver()
        if self.__weaver.findPointcut(ResearchViewPointcut) == -1:
            self.__weaver.weave(pointcut=ResearchViewPointcut, aspects=[ShowXPInfoDialogAspect(self.cleanWeave)])
        if self.__weaver.findPointcut(ExchangeFreeXPToTankmanPointcut) == -1:
            self.__weaver.weave(pointcut=ExchangeFreeXPToTankmanPointcut, aspects=[ShowXPInfoDialogAspect(self.cleanWeave)])
Beispiel #4
0
class WalletController(Controller):

    class STATUS(CONST_CONTAINER):
        SYNCING = 0
        NOT_AVAILABLE = 1
        AVAILABLE = 2

    def __init__(self, proxy):
        super(WalletController, self).__init__(proxy)
        self.onWalletStatusChanged = Event.Event()
        self.__currentStatus = None
        self.__currentCallbackId = None
        self.__useGold = False
        self.__useFreeXP = False
        self.__weaver = None
        return

    def init(self):
        g_clientUpdateManager.addCallbacks({'cache.mayConsumeWalletResources': self.__onWalletStatusChanged})

    def fini(self):
        g_clientUpdateManager.removeObjectCallbacks(self, force=True)
        self.__clearCallback()
        self.__clearWeaver()
        super(WalletController, self).fini()

    def onLobbyStarted(self, ctx):
        wallet = BigWorld.player().serverSettings['wallet']
        self.__useGold = bool(wallet[0])
        self.__useFreeXP = bool(wallet[1])
        if self.__useFreeXP:
            self.__checkFreeXPConditions()
        self.__processStatus(self.STATUS.AVAILABLE if g_itemsCache.items.stats.mayConsumeWalletResources else self.STATUS.SYNCING, True)

    def onAvatarBecomePlayer(self):
        self.__clearWeaver()

    def onDisconnected(self):
        self.__clearWeaver()

    @property
    def status(self):
        return self.__currentStatus

    @property
    def componentsStatuses(self):
        return {'gold': self.__currentStatus if self.__useGold else self.STATUS.AVAILABLE,
         'freeXP': self.__currentStatus if self.__useFreeXP else self.STATUS.AVAILABLE}

    @property
    def isSyncing(self):
        return self.__checkStatus(self.STATUS.SYNCING)

    @property
    def isNotAvailable(self):
        return self.__checkStatus(self.STATUS.NOT_AVAILABLE)

    @property
    def isAvailable(self):
        return self.__checkStatus(self.STATUS.AVAILABLE)

    @property
    def useGold(self):
        return self.__useGold

    @property
    def useFreeXP(self):
        return self.__useFreeXP

    def cleanWeave(self, obj):
        if self.__weaver:
            for value in obj:
                self.__weaver.clear(idx=self.__weaver.findPointcut(value))

    def __clearWeaver(self):
        if self.__weaver is not None:
            self.__weaver.clear()
            self.__weaver = None
        return

    def __processCallback(self):
        self.__currentCallbackId = None
        if self.isSyncing:
            self.__processStatus(self.STATUS.NOT_AVAILABLE)
            message = '#system_messages:wallet/not_available'
            if not self.__useFreeXP:
                message += '_gold'
            elif not self.__useGold:
                message += '_freexp'
            SystemMessages.g_instance.pushI18nMessage(message, type=SM_TYPE.Warning)
        return

    def __clearCallback(self):
        if self.__currentCallbackId is not None:
            BigWorld.cancelCallback(self.__currentCallbackId)
            self.__currentCallbackId = None
        return

    def __processStatus(self, status, initialize = False):
        if self.__currentStatus != status:
            self.__currentStatus = status
            self.__notify()
            LOG_DEBUG('Wallet status changed:', self.__currentStatus)
            if self.isAvailable:
                self.__clearCallback()
                if not initialize:
                    message = '#system_messages:wallet/available'
                    if not self.__useFreeXP:
                        message += '_gold'
                    elif not self.__useGold:
                        message += '_freexp'
                    SystemMessages.g_instance.pushI18nMessage(message, type=SM_TYPE.Information)
            elif self.isSyncing and self.__currentCallbackId is None:
                self.__currentCallbackId = BigWorld.callback(30, self.__processCallback)
        return

    def __onWalletStatusChanged(self, available):
        status = self.__currentStatus
        if available and not self.isAvailable:
            status = self.STATUS.AVAILABLE
        elif not available and self.isAvailable:
            status = self.STATUS.SYNCING
        self.__processStatus(status)

    def __checkStatus(self, status):
        return self.__currentStatus == status

    def __notify(self):
        self.onWalletStatusChanged(self.componentsStatuses)

    def __checkFreeXPConditions(self):
        from account_helpers.AccountSettings import AccountSettings, GUI_START_BEHAVIOR
        from account_helpers.settings_core.SettingsCore import g_settingsCore
        defaults = AccountSettings.getFilterDefault(GUI_START_BEHAVIOR)
        filters = g_settingsCore.serverSettings.getSection(GUI_START_BEHAVIOR, defaults)
        if filters['isFreeXPInfoDialogShowed']:
            return
        self.__weaver = Weaver()
        if self.__weaver.findPointcut(ResearchViewPointcut) is -1:
            self.__weaver.weave(pointcut=ResearchViewPointcut, aspects=[ShowXPInfoDialogAspect(self.cleanWeave)])
        if self.__weaver.findPointcut(ExchangeFreeXPToTankmanPointcut) is -1:
            self.__weaver.weave(pointcut=ExchangeFreeXPToTankmanPointcut, aspects=[ShowXPInfoDialogAspect(self.cleanWeave)])
Beispiel #5
0
class CaptchaController(object):
    __api = CAPTCHA_API_CLASS()
    __battlesTillCaptcha = 99
    __triesLeft = 3
    _CLIENT_ERROR_CODES = {
        'enqueue-failure':
        i18n.makeString('#captcha:error-codes/enqueue-failure'),
        'response-is-empty':
        i18n.makeString('#captcha:error-codes/response-is-empty'),
        'challenge-is-empty':
        i18n.makeString('#captcha:error-codes/challenge-is-empty')
    }

    def init(self):
        self.__tryReset = False
        self.__weaver = Weaver()

    def fini(self):
        self.stop()
        self.__tryReset = False
        if self.__weaver is not None:
            self.__weaver.clear()
            self.__weaver = None
        return

    def start(self):
        BigWorld.player().stats.get('battlesTillCaptcha',
                                    self.__pc_onReceiveBattlesTillCaptcha)
        BigWorld.player().stats.get('captchaTriesLeft',
                                    self.__pc_onReceiveCaptchaTriesLeft)
        g_playerEvents.onEnqueueRandomFailure += self.__pe_onEnqueueFailure
        g_clientUpdateManager.addCallbacks({
            'stats.battlesTillCaptcha':
            self.__onBattlesTillCaptcha,
            'stats.captchaTriesLeft':
            self.__onCaptchaTriesLeft
        })

    def stop(self):
        g_clientUpdateManager.removeObjectCallbacks(self)
        g_playerEvents.onEnqueueRandomFailure -= self.__pe_onEnqueueFailure

    def showCaptcha(self, callback):
        if self.__triesLeft <= CAPTCHA_TRIES_LEFT_NOTIFY_THESHOLD:
            errorText = i18n.makeString(
                '#captcha:notification/remains-to-attempt',
                self.__triesLeft if self.__triesLeft > 0 else 0)
        else:
            errorText = None
        _showDialog(errorText, callback)
        return

    def getCaptchaServerError(self, errorCode):
        errorText = self.__api.getI18nServerErrorText(errorCode)
        if errorCode == self.__api._RESPONSE_IS_INCORRECT_CODE:
            triesLeftString = i18n.makeString(
                '#captcha:notification/remains-to-attempt', self.__triesLeft)
            errorText = '{0:>s} {1:>s}'.format(errorText, triesLeftString)
        return errorText

    def getCaptchaClientError(self, errorCode):
        if errorCode in self._CLIENT_ERROR_CODES:
            errorMsg = i18n.makeString(self._CLIENT_ERROR_CODES[errorCode])
        else:
            errorMsg = errorCode
        return errorMsg

    def isCaptchaRequired(self):
        return self.__battlesTillCaptcha <= 0

    def getTriesLeft(self):
        return self.__triesLeft

    def getPublicKey(self):
        settings = BigWorld.player().serverSettings
        if settings.has_key('captchaKey'):
            return settings['captchaKey']
        else:
            return None

    def getCaptchaRegex(self):
        return BigWorld.player().serverSettings.get('reCaptchaParser', '')

    def getImageSource(self):
        return self.__api.getImageSource(self.getPublicKey(),
                                         self.getCaptchaRegex())

    def getImageSize(self):
        return self.__api._IMAGE_SIZE

    @async
    def verify(self, challenge, response, callback=None):
        BigWorld.player().challengeCaptcha(
            challenge, response, partial(self.__pc_onCaptchaChecked, callback))

    def tryBattlesTillCaptchaReset(self):
        if self.__tryReset:
            return
        if self.__triesLeft > 1:
            self.__tryReset = True
            LOG_WARNING('Client try battlesTillCaptcha reset')
            BigWorld.player().challengeCaptcha(
                '', '', lambda resultID, errorCode: None)

    def __pe_onEnqueueFailure(self, errorCode, _):
        if errorCode != JOIN_FAILURE.CAPTCHA:
            return
        _showDialog(
            i18n.makeString(self._CLIENT_ERROR_CODES['enqueue-failure']))

    def __onBattlesTillCaptcha(self, value):
        self.__battlesTillCaptcha = value
        if self.isCaptchaRequired():
            if self.__weaver.findPointcut(ShowCaptchaPointcut) is -1:
                self.__weaver.weave(pointcut=ShowCaptchaPointcut,
                                    aspects=[ShowCaptchaAspect(self)])

    def __onCaptchaTriesLeft(self, value):
        self.__triesLeft = value

    def __pc_onReceiveBattlesTillCaptcha(self, resultID, value):
        if resultID < 0:
            LOG_ERROR('Server return error: ', resultID, value)
            return
        self.__battlesTillCaptcha = value
        if self.isCaptchaRequired():
            if self.__weaver.findPointcut(ShowCaptchaPointcut) is -1:
                self.__weaver.weave(pointcut=ShowCaptchaPointcut,
                                    aspects=[ShowCaptchaAspect(self)])

    def __pc_onReceiveCaptchaTriesLeft(self, resultID, value):
        if resultID < 0:
            LOG_ERROR('Server return error: ', resultID, value)
            return
        self.__triesLeft = value

    def __pc_onCaptchaChecked(self, callback, resultID, responseCode):
        isVerified = resultID == AccountCommands.RES_SUCCESS
        if isVerified:
            self.__weaver.clear(
                idx=self.__weaver.findPointcut(ShowCaptchaPointcut))
        callback((isVerified, responseCode))
Beispiel #6
0
class WalletController(IWalletController):
    itemsCache = dependency.descriptor(IItemsCache)
    settingsCore = dependency.descriptor(ISettingsCore)

    class STATUS(CONST_CONTAINER):
        SYNCING = 0
        NOT_AVAILABLE = 1
        AVAILABLE = 2

    def __init__(self):
        super(WalletController, self).__init__()
        self.onWalletStatusChanged = Event.Event()
        self.__currentStatus = None
        self.__currentCallbackId = None
        self.__useGold = False
        self.__useFreeXP = False
        self.__weaver = None
        return

    def init(self):
        _logger.debug('WalletController init')
        g_clientUpdateManager.addCallbacks({'cache.mayConsumeWalletResources': self.__onWalletStatusChanged})

    def fini(self):
        _logger.debug('WalletController fini')
        g_clientUpdateManager.removeObjectCallbacks(self, force=True)
        self.__clearCallback()
        self.__clearWeaver()
        super(WalletController, self).fini()

    def onLobbyStarted(self, event):
        wallet = BigWorld.player().serverSettings['wallet']
        self.__useGold = bool(wallet[0])
        self.__useFreeXP = bool(wallet[1])
        if self.__useFreeXP:
            self.__checkFreeXPConditions()
        if self.itemsCache.items.stats.mayConsumeWalletResources:
            status = self.STATUS.AVAILABLE
        else:
            status = self.STATUS.SYNCING
        self.__processStatus(status, True)

    def onAvatarBecomePlayer(self):
        self.__clearWeaver()

    def onDisconnected(self):
        self.__clearWeaver()

    @property
    def status(self):
        return self.__currentStatus

    @property
    def componentsStatuses(self):
        return {'gold': self.__currentStatus if self.__useGold else self.STATUS.AVAILABLE,
         'freeXP': self.__currentStatus if self.__useFreeXP else self.STATUS.AVAILABLE,
         'credits': self.__currentStatus if not constants.IS_CHINA else self.STATUS.AVAILABLE,
         'crystal': self.__currentStatus if not constants.IS_CHINA else self.STATUS.AVAILABLE,
         'eventCoin': self.__currentStatus if not constants.IS_CHINA else self.STATUS.AVAILABLE,
         'bpcoin': self.__currentStatus if not constants.IS_CHINA else self.STATUS.AVAILABLE}

    @property
    def dynamicComponentsStatuses(self):
        return {currencyCode:(self.__currentStatus if not constants.IS_CHINA else self.STATUS.AVAILABLE) for currencyCode in self.itemsCache.items.stats.dynamicCurrencies.keys()}

    @property
    def isSyncing(self):
        return self.__checkStatus(self.STATUS.SYNCING)

    @property
    def isNotAvailable(self):
        return self.__checkStatus(self.STATUS.NOT_AVAILABLE)

    @property
    def isAvailable(self):
        return self.__checkStatus(self.STATUS.AVAILABLE)

    @property
    def useGold(self):
        return self.__useGold

    @property
    def useFreeXP(self):
        return self.__useFreeXP

    def cleanWeave(self, pointcuts):
        if self.__weaver:
            for pointcut in pointcuts:
                self.__weaver.clear(idx=self.__weaver.findPointcut(pointcut))

    def __clearWeaver(self):
        if self.__weaver is not None:
            self.__weaver.clear()
            self.__weaver = None
        return

    def __processCallback(self):
        self.__currentCallbackId = None
        if self.isSyncing:
            self.__processStatus(self.STATUS.NOT_AVAILABLE)
            self.__sendNotification(status='not_available')
        return

    def __clearCallback(self):
        if self.__currentCallbackId is not None:
            BigWorld.cancelCallback(self.__currentCallbackId)
            self.__currentCallbackId = None
        return

    def __processStatus(self, status, initialize=False):
        if self.__currentStatus != status:
            self.__currentStatus = status
            self.__notify()
            _logger.info('Wallet status changed: %s(%s)', self.STATUS.getKeyByValue(self.__currentStatus), self.__currentStatus)
            if self.isAvailable:
                self.__clearCallback()
                if not initialize:
                    self.__sendNotification(status='available')
            elif self.isSyncing and self.__currentCallbackId is None:
                self.__currentCallbackId = BigWorld.callback(30, self.__processCallback)
        return

    def __onWalletStatusChanged(self, available):
        status = self.__currentStatus
        if available and not self.isAvailable:
            status = self.STATUS.AVAILABLE
        elif not available and self.isAvailable:
            status = self.STATUS.SYNCING
        self.__processStatus(status)

    def __checkStatus(self, status):
        return self.__currentStatus == status

    def __notify(self):
        self.onWalletStatusChanged(self.componentsStatuses)

    def __checkFreeXPConditions(self):
        defaults = AccountSettings.getFilterDefault(GUI_START_BEHAVIOR)
        filters = self.settingsCore.serverSettings.getSection(GUI_START_BEHAVIOR, defaults)
        if filters['isFreeXPInfoDialogShowed']:
            return
        self.__weaver = Weaver()
        if self.__weaver.findPointcut(UnlockItemPointcut) == -1:
            self.__weaver.weave(pointcut=UnlockItemPointcut, aspects=[ShowXPInfoDialogAspect(self.cleanWeave)])
        if self.__weaver.findPointcut(ExchangeFreeXPToTankmanPointcut) == -1:
            self.__weaver.weave(pointcut=ExchangeFreeXPToTankmanPointcut, aspects=[ShowXPInfoDialogAspect(self.cleanWeave)])

    def __sendNotification(self, status):
        msgType = SM_TYPE.Information if status == 'available' else SM_TYPE.Warning
        if constants.IS_CHINA:
            if not self.__useFreeXP:
                status += '_gold'
            elif not self.__useGold:
                status += '_freexp'
        SystemMessages.pushI18nMessage(SYSTEM_MESSAGES.getWalletStatus(status), type=msgType)