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 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 _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 _load_xtdb_data_callback(url, bytes): try: if bytes: if url is not None: userprefs.set('cache/xtdb.json.gz', bytes) global _xtdb_data _xtdb_data = simplejson.loads(gzip.GzipFile(fileobj=StringIO.StringIO(bytes)).read()) 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)) 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 _set_reserved(self, vehCD, to_reserve): try: vehinfo.updateReserve(vehCD, to_reserve) if to_reserve: if vehCD not in self.reserve_cache: self.reserve_cache.append(vehCD) userprefs.set(USERPREFS.CAROUSEL_RESERVE, self.reserve_cache) else: if vehCD in self.reserve_cache: self.reserve_cache.remove(vehCD) userprefs.set(USERPREFS.CAROUSEL_RESERVE, self.reserve_cache) except Exception as ex: err('_set_reserved() exception: ' + traceback.format_exc())
def _load_wn8_data_callback(url, bytes): try: if bytes: if url is not None: userprefs.set('cache/wn8exp.json.gz', bytes) data = simplejson.loads(gzip.GzipFile(fileobj=StringIO.StringIO(bytes)).read()) for x in data['data']: vinfo = getVehicleInfoData(int(x['IDNum'])) if vinfo is not None: vinfo['wn8expDamage'] = float(x['expDamage']) vinfo['wn8expSpot'] = float(x['expSpot']) vinfo['wn8expWinRate'] = float(x['expWinRate']) vinfo['wn8expDef'] = float(x['expDef']) vinfo['wn8expFrag'] = float(x['expFrag']) except Exception, ex: err(traceback.format_exc())
def _load_xte_data_callback(url, bytes): try: if bytes: if url is not None: userprefs.set('cache/xte.json.gz', bytes) global _xte_data _xte_data = simplejson.loads(gzip.GzipFile(fileobj=StringIO.StringIO(bytes)).read()) for k, v in _xte_data.iteritems(): vinfo = getVehicleInfoData(int(k)) if vinfo is not None: vinfo['avgdmg'] = float(v['ad']) vinfo['topdmg'] = float(v['td']) vinfo['avgfrg'] = float(v['af']) vinfo['topfrg'] = float(v['tf']) 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 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 saveLastAccountDBID(self): #trace('config.token.saveLastAccountDBID') if self.accountDBID: userprefs.set('tokens/lastAccountDBID', self.accountDBID)
def saveToken(self): #trace('config.token.saveToken') if self.accountDBID: userprefs.set('tokens/{0}'.format(self.accountDBID), self.__dict__)
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)