def initBattleSwf(self, flashObject): trace('initBattleSwf') try: self.battleFlashObject = flashObject # Save/restore arena data player = BigWorld.player() fileName = 'arenas_data/{0}'.format(player.arenaUniqueID) mcdata = minimap_circles.getMinimapCirclesData() vehId = player.vehicleTypeDescriptor.type.compactDescr if vehId and mcdata is not None and vehId == mcdata.get('vehId', None): # Normal battle start. Update data and save to userprefs cache userprefs.set(fileName, { 'ver': '1.0', 'minimap_circles': minimap_circles.getMinimapCirclesData(), }) else: # Replay, training or restarted battle after crash. Try to restore data. arena_data = userprefs.get(fileName) if arena_data is None: # Set default vehicle data if it is not available.in the cache. minimap_circles.updateMinimapCirclesData(player.vehicleTypeDescriptor) else: # Apply restored data. minimap_circles.setMinimapCirclesData(arena_data['minimap_circles']) except Exception, ex: err(traceback.format_exc())
def onXvmCommand(self, proxy, id, cmd, *args): try: # debug("id=" + str(id) + " cmd=" + str(cmd) + " args=" + simplejson.dumps(args)) if IS_DEVELOPMENT and cmd in _LOG_COMMANDS: debug("cmd=" + str(cmd) + " args=" + simplejson.dumps(args)) res = None if cmd == AS2COMMAND.LOG: log(*args) elif cmd == AS2COMMAND.GET_SCREEN_SIZE: # return res = simplejson.dumps(list(GUI.screenResolution())) elif cmd == AS2COMMAND.LOAD_BATTLE_STAT: stats.getBattleStat(args, proxy) elif cmd == AS2COMMAND.LOAD_SETTINGS: res = userprefs.get(args[0]) elif cmd == AS2COMMAND.SAVE_SETTINGS: userprefs.set(args[0], args[1]) elif cmd == AS2COMMAND.CAPTURE_BAR_GET_BASE_NUM: n = int(args[0]) res = getBattleSubTypeBaseNumder(BigWorld.player().arenaTypeID, n & 0x3, n >> 2) else: return proxy.movie.invoke(('xvm.respond', [id] + res if isinstance(res, list) else [id, res])) except Exception, ex: err(traceback.format_exc())
def _initializeXvmToken(): #debug('_initializeXvmToken') global _tdataPrev clearToken() # use last player id for replays playerId = getCurrentPlayerId() if not isReplay() else userprefs.get('tokens.lastPlayerId') if playerId is None: return tdataActive = _getXvmActiveTokenData() (tdata, errStr) = _checkToken(playerId, None if tdataActive is None else tdataActive['token']) if tdata is None: tdata = _tdataPrev if not isReplay(): type = SystemMessages.SM_TYPE.Warning msg = _getXvmMessageHeader() if tdata is None: msg += '{{l10n:token/services_unavailable}}\n\n%s' % utils.hide_guid(errStr) elif tdata['status'] == 'badToken' or tdata['status'] == 'inactive': msg += '{{l10n:token/services_inactive}}' elif tdata['status'] == 'blocked': msg += '{{l10n:token/blocked}}' elif tdata['status'] == 'active': type = SystemMessages.SM_TYPE.GameGreeting msg += '{{l10n:token/active}}\n' s = time.time() e = tdata['expires_at'] / 1000 days_left = int((e - s) / 86400) hours_left = int((e - s) / 3600) % 24 mins_left = int((e - s) / 60) % 60 token_name = 'time_left' if days_left >= 3 else 'time_left_warn' msg += '{{l10n:token/%s:%d:%02d:%02d}}\n' % (token_name, days_left, hours_left, mins_left) msg += '{{l10n:token/cnt:%d}}' % tdata['cnt'] else: type = SystemMessages.SM_TYPE.Error msg += '{{l10n:token/unknown_status}}\n%s' % utils.hide_guid(simplejson.dumps(tdata)) msg += '</textformat>' if _tdataPrev is None or _tdataPrev['status'] != 'active' or tdata is None or tdata['status'] != 'active': g_eventBus.handleEvent(events.HasCtxEvent(XVM_EVENT.SYSTEM_MESSAGE, {'msg':msg,'type':type})) if tdata is not None: _tdataPrev = tdata if tdata['status'] == 'active': if 'token' not in tdata and tdataActive is not None: tdata['token'] = tdataActive['token'] else: if 'token' in tdata: del tdata['token'] userprefs.set('tokens.{0}'.format(playerId), tdata) userprefs.set('tokens.lastPlayerId', playerId) global networkServicesSettings networkServicesSettings = _makeNetworkServicesSettings(tdata) global _token _token = '' if tdata is None else tdata.get('token', '').encode('ascii')
def _getXvmActiveTokenData(): #debug('_getXvmActiveTokenData') # use last player id for replays playerId = getCurrentPlayerId() if not isReplay() else userprefs.get('tokens.lastPlayerId') if playerId is None: return None tdata = userprefs.get('tokens.{0}'.format(playerId)) if tdata is not None and 'token' not in tdata: tdata = None if tdata is not None: global _token _token = tdata.get('token', '').encode('ascii') global networkServicesSettings networkServicesSettings = _makeNetworkServicesSettings(tdata) return tdata
def _update_reserve_cache(self, accountDBID): self.accountDBID = accountDBID vehinfo.resetReserve() if self.accountDBID is None: self.reserve_cache = [] else: self.reserve_cache = userprefs.get(USERPREFS.CAROUSEL_RESERVE, []) for vehCD in self.reserve_cache: vehinfo.updateReserve(vehCD, True)
def onXfwCommand(self, cmd, *args): try: if IS_DEVELOPMENT and cmd in _LOG_COMMANDS: debug("cmd=" + str(cmd) + " args=" + simplejson.dumps(args)) if cmd == XVM_COMMAND.REQUEST_CONFIG: self.respondConfig() return (None, True) if cmd == XVM_COMMAND.GET_BATTLE_LEVEL: arena = getattr(BigWorld.player(), 'arena', None) if arena is not None: return (arena.extraData.get('battleLevel', 0), True) return (None, True) if cmd == XVM_COMMAND.GET_BATTLE_TYPE: arena = getattr(BigWorld.player(), 'arena', None) if arena is not None: return (arena.bonusType, True) return (None, True) if cmd == XVM_COMMAND.REQUEST_DOSSIER: dossier.requestDossier(args) return (None, True) if cmd == XVM_COMMAND.GET_SVC_SETTINGS: token.getToken() return (token.networkServicesSettings, True) if cmd == XVM_COMMAND.LOAD_SETTINGS: default = None if len(args) < 2 else args[1] return (userprefs.get(args[0], default), True) if cmd == XVM_COMMAND.LOAD_STAT_BATTLE: stats.getBattleStat(args) return (None, True) if cmd == XVM_COMMAND.LOAD_STAT_BATTLE_RESULTS: stats.getBattleResultsStat(args) return (None, True) if cmd == XVM_COMMAND.LOAD_STAT_USER: stats.getUserData(args) return (None, True) if cmd == XVM_COMMAND.OPEN_URL: if len(args[0]): utils.openWebBrowser(args[0], False) return (None, True) if cmd == XVM_COMMAND.SAVE_SETTINGS: userprefs.set(args[0], args[1]) return (None, True) except Exception, ex: err(traceback.format_exc()) return (None, True)
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())
def _checkVersion(): playerId = getCurrentPlayerId() # fallback to the last player id if replay is running if playerId is None and isReplay(): playerId = userprefs.get('tokens.lastPlayerId') if playerId is None: return global versionChecked versionChecked = True try: req = "checkVersion/%d" % playerId server = XVM.SERVERS[randint(0, len(XVM.SERVERS) - 1)] (response, duration, errStr) = loadUrl(server, req) # response = """ { "topClans":{"MGRD":{"rank":"747","cid":"156781"},...}, "persistClans":{"WG-A":{"rank":"0","cid":"17996"},...}, "info":{"RU": {"message":"www.modxvm.com","ver":"5.2.1-test2"},...} }""" global _clansInfo, _verInfo _clansInfo = None _verInfo = None if not response: # err('Empty response or parsing error') pass else: try: if response is not None: response = response.strip() if response not in ('', '[]'): data = simplejson.loads(response) if data is not None: _clansInfo = _processClansInfo(data) _verInfo = data.get('info', None) global isOnline isOnline = True except Exception, ex: err(' Bad answer: ' + response) err(traceback.format_exc()) _clansInfo = None _verInfo = None except Exception, ex: err(traceback.format_exc())
def save_or_restore(self): try: # Save/restore arena data player = BigWorld.player() fileName = 'arenas_data.zip/{0}'.format(player.arenaUniqueID) vehCD = player.vehicleTypeDescriptor.type.compactDescr if vehCD and self.minimapCirclesData and vehCD == self.minimapCirclesData.get('vehCD', None): # Normal battle start. Update data and save to userprefs cache userprefs.set(fileName, { 'ver': '1.1', 'minimap_circles': self.minimapCirclesData, }) else: # Replay, training or restarted battle after crash. Try to restore data. arena_data = userprefs.get(fileName) if arena_data is None: # Set default vehicle data if it is not available.in the cache. self.updateMinimapCirclesData(player.vehicleTypeDescriptor) else: # Apply restored data. self.setMinimapCirclesData(arena_data['minimap_circles']) except Exception, ex: err(traceback.format_exc())
def _init(): res = [_UNKNOWN_VEHICLE_DATA] try: for nation in nations.NAMES: nationID = nations.INDICES[nation] for (id, descr) in vehicles.g_list.getList(nationID).iteritems(): if descr.name.endswith('training'): continue item = vehicles.g_cache.vehicle(nationID, id) #log('%i %i %s %s' % (descr.level, descr.compactDescr, descr.name, descr.shortUserString)) data = dict() data['vehCD'] = descr.compactDescr data['key'] = descr.name data['nation'] = nation data['level'] = descr.level data['vclass'] = tuple(vehicles.VEHICLE_CLASS_TAGS & descr.tags)[0] data['localizedName'] = descr.shortUserString data['localizedShortName'] = descr.shortUserString data['localizedFullName'] = descr.userString data['premium'] = 'premium' in descr.tags data['special'] = 'special' in descr.tags stockTurret = item.turrets[0][0] topTurret = item.turrets[0][-1] topGun = topTurret.guns[-1] #if len(item.hulls) != 1: # log('WARNING: TODO: len(hulls) != 1 for vehicle ' + descr.name) data['hpStock'] = item.hulls[0].maxHealth + stockTurret.maxHealth data['hpTop'] = item.hulls[0].maxHealth + topTurret.maxHealth data['turret'] = _getTurretType(item, nation) (data['visRadius'], data['firingRadius'], data['artyRadius']) = \ _getRanges(topTurret, topGun, nation, data['vclass']) (data['tierLo'], data['tierHi']) = vehinfo_tiers.getTiers(data['level'], data['vclass'], data['key']) data['shortName'] = vehinfo_short.getShortName(data['key'], data['level'], data['vclass']) data['isReserved'] = False #log(data) res.append(data) ResMgr.purge(_VEHICLE_TYPE_XML_PATH + nation + '/components/guns.xml', True) vehinfo_short.checkNames(res) global _vehicleInfoData _vehicleInfoData = {x['vehCD']:x for x in res} # load cached values _load_xvmscale_data_callback(None, userprefs.get('cache/xvmscales.json.gz')) _load_wn8_data_callback(None, userprefs.get('cache/wn8exp.json.gz')) _load_xte_data_callback(None, userprefs.get('cache/xte.json.gz')) _load_xtdb_data_callback(None, userprefs.get('cache/xtdb.json.gz')) # request latest values filecache.get_url(_XVMSCALE_DATA_URL, _load_xvmscale_data_callback) filecache.get_url(_WN8_DATA_URL, _load_wn8_data_callback) filecache.get_url(_XTE_DATA_URL, _load_xte_data_callback) filecache.get_url(_XTDB_DATA_URL, _load_xtdb_data_callback) except Exception, ex: err(traceback.format_exc())
def onXfwCommand(self, cmd, *args): try: if IS_DEVELOPMENT and cmd in _LOG_COMMANDS: debug("cmd=" + str(cmd) + " args=" + simplejson.dumps(args)) # common if cmd == XVM_COMMAND.REQUEST_CONFIG: self.respondConfig() return (None, True) if cmd == XVM_COMMAND.PYTHON_MACRO: return (python_macro.process_python_macro(args[0]), True) if cmd == XVM_COMMAND.GET_PLAYER_ID: return (getCurrentAccountDBID(), True) if cmd == XVM_COMMAND.GET_PLAYER_NAME: return (avatar_getter.getPlayerName(), True) if cmd == XVM_COMMAND.GET_PLAYER_CLAN_ID: return (utils.getClanDBID(), True) if cmd == XVM_COMMAND.GET_PLAYER_CLAN_NAME: return (utils.getClanAbbrev(), True) if cmd == XVM_COMMAND.GET_PLAYER_DOSSIER_VALUE: return (dossier.getAccountDossierValue(args[0]), True) if cmd == XVM_COMMAND.GET_CURRENT_VEH_CD: return (g_currentVehicle.item.intCD if g_currentVehicle.item else 0, True) if cmd == XVM_COMMAND.GET_SVC_SETTINGS: return (config.networkServicesSettings.__dict__, True) if cmd == XVM_COMMAND.LOAD_SETTINGS: default = None if len(args) < 2 else args[1] return (userprefs.get(args[0], default), True) if cmd == XVM_COMMAND.SAVE_SETTINGS: userprefs.set(args[0], args[1]) return (None, True) if cmd == XVM_COMMAND.IS_IN_BOOTCAMP: return (isInBootcamp(), True) # battle if cmd == XVM_COMMAND.GET_CLAN_ICON: return (stats.getClanIcon(int(args[0])), True) # lobby if cmd == XVM_COMMAND.REQUEST_DOSSIER: dossier.requestDossier(args) return (None, True) # stat if cmd == XVM_COMMAND.LOAD_STAT_BATTLE: stats.getBattleStat(args, as_xfw_cmd) return (None, True) if cmd == XVM_COMMAND.LOAD_STAT_BATTLE_RESULTS: stats.getBattleResultsStat(args) return (None, True) if cmd == XVM_COMMAND.LOAD_STAT_USER: stats.getUserData(args) return (None, True) # profiler if cmd in (XVM_PROFILER_COMMAND.BEGIN, XVM_PROFILER_COMMAND.END): g_eventBus.handleEvent(events.HasCtxEvent(cmd, args[0])) return (None, True) except Exception, ex: err(traceback.format_exc()) return (None, True)
def onXfwCommand(self, cmd, *args): try: if IS_DEVELOPMENT and cmd in _LOG_COMMANDS: debug("cmd=" + str(cmd) + " args=" + simplejson.dumps(args)) # common if cmd == XVM_COMMAND.REQUEST_CONFIG: self.respondConfig() return (None, True) if cmd == XVM_COMMAND.PYTHON_MACRO: return (python_macro.process_python_macro(args[0]), True) if cmd == XVM_COMMAND.GET_PLAYER_NAME: return (BigWorld.player().name, True) if cmd == XVM_COMMAND.GET_SVC_SETTINGS: return (config.networkServicesSettings.__dict__, True) if cmd == XVM_COMMAND.LOAD_SETTINGS: default = None if len(args) < 2 else args[1] return (userprefs.get(args[0], default), True) if cmd == XVM_COMMAND.SAVE_SETTINGS: userprefs.set(args[0], args[1]) return (None, True) # battle if cmd == XVM_COMMAND.GET_CLAN_ICON: return (stats.getClanIcon(int(args[0])), True) # lobby if cmd == XVM_COMMAND.REQUEST_DOSSIER: dossier.requestDossier(args) return (None, True) # stat if cmd == XVM_COMMAND.LOAD_STAT_BATTLE: stats.getBattleStat(args, as_xfw_cmd) return (None, True) if cmd == XVM_COMMAND.LOAD_STAT_BATTLE_RESULTS: stats.getBattleResultsStat(args) return (None, True) if cmd == XVM_COMMAND.LOAD_STAT_USER: stats.getUserData(args) return (None, True) # profiler if cmd in (XVM_PROFILER_COMMAND.BEGIN, XVM_PROFILER_COMMAND.END): g_eventBus.handleEvent(events.HasCtxEvent(cmd, args[0])) return (None, True) except Exception, ex: err(traceback.format_exc()) return (None, True)
def _init(): res = [_UNKNOWN_VEHICLE_DATA] try: for nation in nations.NAMES: nationID = nations.INDICES[nation] for (id, descr) in vehicles.g_list.getList(nationID).iteritems(): if descr.name.endswith('training'): continue item = vehicles.g_cache.vehicle(nationID, id) #log('%i %i %s %s' % (descr.level, descr.compactDescr, descr.name, descr.shortUserString)) data = dict() data['vehCD'] = descr.compactDescr data['key'] = descr.name data['nation'] = nation data['level'] = descr.level data['vclass'] = tuple(vehicles.VEHICLE_CLASS_TAGS & descr.tags)[0] data['localizedName'] = descr.shortUserString data['localizedShortName'] = descr.shortUserString data['localizedFullName'] = descr.userString data['premium'] = 'premium' in descr.tags stockTurret = item.turrets[0][0] topTurret = item.turrets[0][-1] topGun = topTurret.guns[-1] #if len(item.hulls) != 1: # log('WARNING: TODO: len(hulls) != 1 for vehicle ' + descr.name) data['hpStock'] = item.hulls[0].maxHealth + stockTurret.maxHealth data['hpTop'] = item.hulls[0].maxHealth + topTurret.maxHealth data['turret'] = _getTurretType(item, nation) (data['visRadius'], data['firingRadius'], data['artyRadius']) = \ _getRanges(topTurret, topGun, nation, data['vclass']) (data['tierLo'], data['tierHi']) = vehinfo_tiers.getTiers(data['level'], data['vclass'], data['key']) data['shortName'] = vehinfo_short.getShortName(data['key'], data['level'], data['vclass']) data['isReserved'] = False #log(data) res.append(data) ResMgr.purge(_VEHICLE_TYPE_XML_PATH + nation + '/components/guns.xml', True) vehinfo_short.checkNames(res) global _vehicleInfoData _vehicleInfoData = {x['vehCD']:x for x in res} # load cached values _load_xvmscale_data_callback(None, userprefs.get('cache/xvmscales.json.gz')) _load_wn8_data_callback(None, userprefs.get('cache/wn8exp.json.gz')) _load_xte_data_callback(None, userprefs.get('cache/xte.json.gz')) _load_xtdb_data_callback(None, userprefs.get('cache/xtdb.json.gz')) # request latest values filecache.get_url(_XVMSCALE_DATA_URL, _load_xvmscale_data_callback) filecache.get_url(_WN8_DATA_URL, _load_wn8_data_callback) filecache.get_url(_XTE_DATA_URL, _load_xte_data_callback) filecache.get_url(_XTDB_DATA_URL, _load_xtdb_data_callback) except Exception, ex: err(traceback.format_exc())
def getAccountDBID(): accountDBID = getCurrentAccountDBID() if not isReplay() else None if accountDBID is None: accountDBID = userprefs.get('tokens/lastAccountDBID') return accountDBID