Example #1
0
def _exec(req, data=None, showLog=True, api=XVM.API_VERSION, params={}):
    url = None
    response = None
    errStr = None
    try:
        url = XVM.SERVERS[randint(0, len(XVM.SERVERS) - 1)]
        url = url.format(API=api, REQ=req)
        for k, v in params.iteritems():
            url = url.replace('{'+k+'}', '' if v is None else str(v))

        accountDBID = utils.getAccountDBID()
        if accountDBID is None:
            accountDBID = 0

        token = config.token.token
        if token is None:
            token = ''

        url = url.format(id=accountDBID, token=token)

        (response, duration, errStr) = loadUrl(url, None, data)

        return (None if not response else unicode_to_ascii(simplejson.loads(response)), errStr)
    except Exception as ex:
        err(traceback.format_exc())
        err('url = {}'.format(utils.hide_guid(url)))
        err('response = {}'.format(utils.hide_guid(response)))
        err('errStr = {}'.format(utils.hide_guid(errStr)))
        return (None, sys.exc_info()[0])
Example #2
0
    def initializeXvmServices(self):
        if self.xvmServicesInitialized:
            return

        accountDBID = utils.getAccountDBID()
        if accountDBID is None and not isReplay():
            return

        self.xvmServicesInitialized = True

        config.token = config.XvmServicesToken.restore()
        config.token.updateTokenFromApi()

        if config.networkServicesSettings.servicesActive and config.networkServicesSettings.statBattle:
            #data = xvmapi.getVersion()
            #topclans.clear()
            data = xvmapi.getVersionWithLimit(config.networkServicesSettings.topClansCount)
            topclans.update(data)
        else:
            data = xvmapi.getVersionWithLimit(config.networkServicesSettings.topClansCount)
            topclans.update(data)
        config.verinfo = config.XvmVersionInfo(data)

        if g_appLoader.getSpaceID() == GUI_GLOBAL_SPACE_ID.LOBBY:
            svcmsg.tokenUpdated()

        g_eventBus.handleEvent(events.HasCtxEvent(XVM_EVENT.XVM_SERVICES_INITIALIZED))
Example #3
0
    def initializeXvmServices(self):
        if self.xvmServicesInitialized:
            return

        accountDBID = utils.getAccountDBID()
        if accountDBID is None and not isReplay():
            return

        self.xvmServicesInitialized = True

        config.token = config.XvmServicesToken.restore()
        config.token.updateTokenFromApi()

        if config.networkServicesSettings.servicesActive and config.networkServicesSettings.statBattle:
            #data = xvmapi.getVersion()
            #topclans.clear()
            data = xvmapi.getVersionWithLimit(
                config.networkServicesSettings.topClansCount)
            topclans.update(data)
        else:
            data = xvmapi.getVersionWithLimit(
                config.networkServicesSettings.topClansCount)
            topclans.update(data)
        config.verinfo = config.XvmVersionInfo(data)

        if g_appLoader.getSpaceID() == GUI_GLOBAL_SPACE_ID.LOBBY:
            svcmsg.tokenUpdated()

        g_eventBus.handleEvent(
            events.HasCtxEvent(XVM_EVENT.XVM_SERVICES_INITIALIZED))
Example #4
0
 def restore():
     #trace('config.token.restore')
     try:
         accountDBID = utils.getAccountDBID()
         if accountDBID is None:
             return XvmServicesToken()
         new_token = XvmServicesToken(userprefs.get('tokens/{0}'.format(accountDBID)))
         global token
         if token:
             new_token.online = token.online
         return new_token
     except Exception:
         err(traceback.format_exc())
Example #5
0
 def restore():
     #trace('config.token.restore')
     try:
         accountDBID = utils.getAccountDBID()
         if accountDBID is None:
             return XvmServicesToken()
         new_token = XvmServicesToken(userprefs.get('tokens/{0}'.format(accountDBID)))
         global token
         if token:
             new_token.online = token.online
         return new_token
     except Exception:
         err(traceback.format_exc())
Example #6
0
    def _load_stat(self, playerVehicleID):
        requestList = []

        replay = isReplay()
        all_cached = True
        for (vehicleID, pl) in self.players.iteritems():
            cacheKey = "%d=%d" % (pl.accountDBID, pl.vehCD)

            if cacheKey not in self.cacheBattle:
                all_cached = False

            if pl.vehCD != 65281:
                requestList.append(
                    "%d=%d%s" % (pl.accountDBID, pl.vehCD, '=1' if not replay
                                 and pl.vehicleID == playerVehicleID else ''))

        if all_cached or not requestList:
            return

        try:
            accountDBID = utils.getAccountDBID()
            if config.networkServicesSettings.statBattle:
                data = self._load_data_online(accountDBID,
                                              ','.join(requestList))
            else:
                data = self._load_data_offline(accountDBID)

            if data is None:
                return

            for stat in data['players']:
                self._fix(stat)
                #log(stat)
                if 'nm' not in stat or not stat['nm']:
                    continue
                if 'b' not in stat or stat['b'] <= 0:
                    continue
                cacheKey = "%d=%d" % (stat['_id'], stat.get('v', {}).get(
                    'id', 0))
                self.cacheBattle[cacheKey] = stat

        except Exception:
            err(traceback.format_exc())
Example #7
0
    def _load_stat(self, isBattleResults, battleinfo=None):
        requestList = []

        replay = isReplay()
        all_cached = True
        for (vehicleID, pl) in self.players.iteritems():
            cacheKey = "%d=%d" % (pl.accountDBID, pl.vehCD)

            if cacheKey not in self.cacheBattle:
                all_cached = False

            requestList.append("{}={}={}".format(pl.accountDBID, pl.vehCD,
                                                 pl.team))

        if all_cached or not requestList:
            return

        try:
            accountDBID = utils.getAccountDBID()
            if config.networkServicesSettings.statBattle:
                data = self._load_data_online(accountDBID,
                                              ','.join(requestList),
                                              isBattleResults, battleinfo)
            else:
                data = self._load_data_offline(accountDBID)

            if data is None:
                return

            for stat in data['players']:
                self._fix(stat)
                #log(stat)
                if 'name_db' not in stat or not stat['name_db']:
                    continue
                if 'battles' not in stat or stat['battles'] <= 0:
                    continue
                cacheKey = "%d=%d" % (stat['player_id'], stat.get('v', {}).get(
                    'id', 0))
                self.cacheBattle[cacheKey] = stat

        except Exception:
            err(traceback.format_exc())
Example #8
0
    def _load_stat(self, playerVehicleID):
        requestList = []

        replay = isReplay()
        all_cached = True
        for (vehicleID, pl) in self.players.iteritems():
            cacheKey = "%d=%d" % (pl.accountDBID, pl.vehCD)

            if cacheKey not in self.cacheBattle:
                all_cached = False

            if pl.vehCD != 65281:
                requestList.append("%d=%d%s" % (
                    pl.accountDBID,
                    pl.vehCD,
                    '=1' if not replay and pl.vehicleID == playerVehicleID else ''))

        if all_cached or not requestList:
            return

        try:
            accountDBID = utils.getAccountDBID()
            if config.networkServicesSettings.statBattle:
                data = self._load_data_online(accountDBID, ','.join(requestList))
            else:
                data = self._load_data_offline(accountDBID)

            if data is None:
                return

            for stat in data['players']:
                self._fix(stat)
                #log(stat)
                if 'name_db' not in stat or not stat['name_db']:
                    continue
                if 'battles' not in stat or stat['battles'] <= 0:
                    continue
                cacheKey = "%d=%d" % (stat['player_id'], stat.get('v', {}).get('id', 0))
                self.cacheBattle[cacheKey] = stat

        except Exception:
            err(traceback.format_exc())
Example #9
0
 def get(self, key, default):
     fs = None
     try:
         if not key:
             return default
         if '{accountDBID}' in key:
             key = key.format(accountDBID=utils.getAccountDBID())
         fullFileName = os.path.join(self.cache_dir, '{0}.dat'.format(key))
         dirName = os.path.dirname(fullFileName)
         pkg = os.path.basename(dirName)
         fileName = os.path.basename(fullFileName)
         isZip = pkg.lower().endswith('.zip')
         if os.path.exists(dirName):
             if isZip:
                 fs = ZipFS(dirName, mode='r', compression='stored')
             else:
                 fs = OSFS(dirName, create=True)
             if fs.exists(fileName):
                 try:
                     #log(fileName)
                     #log(cPickle.loads(fs.getcontents(fileName)))
                     return cPickle.loads(fs.getcontents(fileName))
                 except Exception:
                     if isZip:
                         log('[WARNING] Broken file: %s' % fullFileName)
                     else:
                         log('[WARNING] Remove broken file: %s' %
                             fullFileName)
                         fs.remove(fileName)
                     raise
         return default
     except Exception:
         err(traceback.format_exc())
         return default
     finally:
         if fs is not None:
             fs.close()
Example #10
0
    def initializeXvmServices(self):
        if self.xvmServicesInitialized:
            return

        accountDBID = utils.getAccountDBID()
        if accountDBID is None and not isReplay():
            return

        self.xvmServicesInitialized = True

        config.token = config.XvmServicesToken.restore()
        config.token.updateTokenFromApi()

        data = xvmapi.getVersion(
            config.networkServicesSettings.topClansCountWgm,
            config.networkServicesSettings.topClansCountWsh)
        topclans.update(data)
        config.verinfo = config.XvmVersionInfo(data)

        if self.appLoader.getSpaceID() == GuiGlobalSpaceID.LOBBY:
            svcmsg.tokenUpdated()

        g_eventBus.handleEvent(
            events.HasCtxEvent(XVM_EVENT.XVM_SERVICES_INITIALIZED))
Example #11
0
def _getXvmMessageFooter():
    return '\n{{l10n:stats_link/svcmsg:%s}}\n\n' % (utils.getAccountDBID())