def invalidateArenaInfo(self): #debug('battle: invalidateArenaInfo') if self.battle_page: if battle_loading.isBattleLoadingShowed(): if 'battleLoading' in self.battle_page.as_getComponentsVisibilityS( ): battleLoading = self.battle_page.getComponent( BATTLE_VIEW_ALIASES.BATTLE_LOADING) if battleLoading: battle_loading._setBattleLoading(False) try: battleLoading.invalidateArenaInfo() except Exception: err(traceback.format_exc()) ctrl = self.battle_page.getComponent( BATTLE_VIEW_ALIASES.BATTLE_STATISTIC_DATA_CONTROLLER) if ctrl and not isinstance(ctrl, EpicStatisticsDataController): ctrl._dispose() ctrl._populate() # update vehicles data for (vehicleID, vData) in avatar_getter.getArena().vehicles.iteritems(): self.updatePlayerState(vehicleID, INV.ALL) g_eventBus.handleEvent( events.HasCtxEvent(XVM_BATTLE_EVENT.ARENA_INFO_INVALIDATED))
def tokenUpdated(): type = SystemMessages.SM_TYPE.Warning msg = _getXvmMessageHeader() status = config.token.status if status is None: msg += '{{l10n:token/services_unavailable}}\n\n%s' % utils.hide_guid( config.token.errStr) elif status == 'badToken' or status == 'inactive': msg += '{{l10n:token/services_inactive}}' elif status == 'blocked': msg += '{{l10n:token/blocked}}' elif status == 'active': type = SystemMessages.SM_TYPE.GameGreeting msg += '{{l10n:token/active}}\n' s = time.time() e = config.token.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 >= 11 else 'time_left_warn' msg += '{{l10n:token/%s:%d:%02d:%02d}}' % (token_name, days_left, hours_left, mins_left) else: type = SystemMessages.SM_TYPE.Error msg += '{{l10n:token/unknown_status}}\n%s' % status msg += '</textformat>' g_eventBus.handleEvent( events.HasCtxEvent(XVM_EVENT.SYSTEM_MESSAGE, { 'msg': msg, 'type': type }))
def onVMCommand(self, cmd, *args): try: if cmd == XVM_VM_COMMAND.LOG: log(*args) elif cmd == XVM_VM_COMMAND.INITIALIZED: self.initialized = True self.guiType = BigWorld.player().arena.guiType log('[VM] initialized') elif cmd == XVM_COMMAND.REQUEST_CONFIG: self.respondConfig() elif cmd == XVM_BATTLE_COMMAND.REQUEST_BATTLE_GLOBAL_DATA: self.respondGlobalBattleData() elif cmd == XVM_COMMAND.PYTHON_MACRO: self.call(XVM_VM_COMMAND.AS_CMD_RESPONSE, python_macro.process_python_macro(args[0])) elif cmd == XVM_COMMAND.GET_CLAN_ICON: self.call(XVM_VM_COMMAND.AS_CMD_RESPONSE, stats.getClanIcon(int(args[0]))) elif cmd == XVM_COMMAND.LOAD_STAT_BATTLE: stats.getBattleStat(args, self.call) # profiler elif cmd in (XVM_PROFILER_COMMAND.BEGIN, XVM_PROFILER_COMMAND.END): g_eventBus.handleEvent(events.HasCtxEvent(cmd, args[0])) else: warn('Unknown command: {}'.format(cmd)) except Exception, ex: err(traceback.format_exc())
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))
def invalidateArenaInfo(self): #debug('battle: invalidateArenaInfo') if self.battle_page: if battle_loading.isBattleLoadingShowed(): if 'battleLoading' in self.battle_page.as_getComponentsVisibilityS( ): battleLoading = self.battle_page.getComponent( BATTLE_VIEW_ALIASES.BATTLE_LOADING) if battleLoading: battle_loading._setBattleLoading(False) battleLoading.invalidateArenaInfo() ctrl = self.battle_page.getComponent( BATTLE_VIEW_ALIASES.BATTLE_STATISTIC_DATA_CONTROLLER) if ctrl: ctrl._BattleStatisticsDataController__setPersonalStatus() ctrl._BattleStatisticsDataController__setArenaDescription() arenaDP = ctrl._battleCtx.getArenaDP() ctrl.invalidateVehiclesInfo(arenaDP) ctrl.invalidateVehiclesStats(arenaDP) # update vehicles data for (vehicleID, vData) in avatar_getter.getArena().vehicles.iteritems(): self.updatePlayerState(vehicleID, INV.ALL) g_eventBus.handleEvent( events.HasCtxEvent(XVM_BATTLE_EVENT.ARENA_INFO_INVALIDATED))
def _NotificationsActionsHandlers_handleAction(base, self, model, typeID, entityID, actionName): if actionName == 'XVM_CHECK_ACTIVATION': g_eventBus.handleEvent(events.HasCtxEvent(XVM_EVENT.CHECK_ACTIVATION)) elif typeID == NOTIFICATION_TYPE.MESSAGE and re.match( 'https?://', actionName, re.I): BigWorld.wg_openWebBrowser(actionName) else: base(self, model, typeID, entityID, actionName)
def respondGlobalBattleData(self): #s = time.clock() try: if self.active: self.call(XVM_BATTLE_COMMAND.AS_RESPONSE_BATTLE_GLOBAL_DATA, *shared.getGlobalBattleData()) g_eventBus.handleEvent( events.HasCtxEvent( XVM_BATTLE_EVENT.VM_INVALIDATE_ARENA_INFO)) except Exception, ex: err(traceback.format_exc())
def on_bindok(self, unused_frame): """Invoked by pika when the Queue.Bind method has completed. At this point we will start consuming messages by calling start_consuming which will invoke the needed RPC commands to start the process. :param pika.frame.Method unused_frame: The Queue.BindOk response frame """ debug('[XMQP] Queue bound') self._reconnect_attempts = 0 g_eventBus.handleEvent(events.HasCtxEvent(XVM_BATTLE_EVENT.XMQP_CONNECTED))
def load(e): global config_autoreload global config_data global lang_data try: # TODO: config selection filename = e.ctx.get('filename', XVM.CONFIG_FILE) config_data = None lang_data = None config_data = _load_xvm_xc(filename, config_autoreload) regionDetected = 'region' not in config_data or config_data[ 'region'].lower() == XVM.REGION_AUTO_DETECTION if regionDetected: config_data['region'] = getRegion() languageDetected = 'language' not in config_data or config_data[ 'language'] == XVM.LOCALE_AUTO_DETECTION if languageDetected: config_data['language'] = getLanguage() lang_data = _load_locale_file() log('Config loaded. Region: {} ({}), Language: {} ({})'.format( get('region'), 'detected' if regionDetected else 'config', get('language'), 'detected' if languageDetected else 'config')) if config_autoreload is not True: config_autoreload = get('autoReloadConfig', False) if config_autoreload: try: import xfw_filewatcher.python as xfw_filewatcher if not xfw_filewatcher.watcher_is_exists( XVM_EVENT.RELOAD_CONFIG): xfw_filewatcher.watcher_add(XVM_EVENT.RELOAD_CONFIG, XVM.CONFIG_DIR, \ "import BigWorld;"\ "from gui.shared import g_eventBus, events;" \ "BigWorld.callback(0, lambda: g_eventBus.handleEvent(events.HasCtxEvent('%s', {'filename':'%s'})))" % (XVM_EVENT.RELOAD_CONFIG, XVM.CONFIG_FILE), \ True) xfw_filewatcher.watcher_start(XVM_EVENT.RELOAD_CONFIG) except Exception: log('[WARNING] XFW Filewatcher is not available. Config reload was disabled.' ) except Exception: err(traceback.format_exc()) g_eventBus.handleEvent(events.HasCtxEvent(XVM_EVENT.CONFIG_LOADED))
def start(): debug('start') g_appLoader.onGUISpaceEntered += g_xvm.onGUISpaceEntered g_eventBus.addListener(XFWCOMMAND.XFW_CMD, g_xvm.onXfwCommand) g_eventBus.addListener(XVM_EVENT.RELOAD_CONFIG, config.load) g_eventBus.addListener(XVM_EVENT.CONFIG_LOADED, g_xvm.onConfigLoaded) g_eventBus.addListener(XVM_EVENT.SYSTEM_MESSAGE, g_xvm.onSystemMessage) g_eventBus.addListener(events.AppLifeCycleEvent.INITIALIZED, g_xvm.onAppInitialized) g_eventBus.addListener(events.AppLifeCycleEvent.DESTROYED, g_xvm.onAppDestroyed) # config already loaded, just send event to apply required code g_eventBus.handleEvent(events.HasCtxEvent(XVM_EVENT.CONFIG_LOADED, {'fromInitStage':True}))
def next_data_timing(): global _xvm_play_data if _xvm_play_data['value']: if _xvm_play_data['value']['m'] == 'XMQP': g_eventBus.handleEvent(events.HasCtxEvent(XVM_BATTLE_EVENT.XMQP_MESSAGE, _xvm_play_data['value']['d'])) _xvm_play_data['value'] = None if _xvm_play_data['timing']: if _xvm_play_data['period'] < _xvm_play_data['timing'][0]['p']: return _xvm_play_data['value'] = _xvm_play_data['timing'].pop(0) if _xvm_play_data['period'] > _xvm_play_data['value']['p']: BigWorld.callback(0, next_data_timing) else: BigWorld.callback(_xvm_play_data['value']['t'] - g_replayCtrl.currentTime, next_data_timing)
def xfw_module_init(): try: log_version() BigWorld.callback(0, start) # load config config.load( events.HasCtxEvent(XVM_EVENT.RELOAD_CONFIG, {'filename': XVM.CONFIG_FILE})) global __xvm_main_loaded __xvm_main_loaded = True except Exception: err(traceback.format_exc())
def start(): debug('start') dependency.instance( IAppLoader).onGUISpaceEntered += g_xvm.onGUISpaceEntered g_eventBus.addListener(XFW_COMMAND.XFW_CMD, g_xvm.onXfwCommand) g_eventBus.addListener(XFW_EVENT.APP_INITIALIZED, g_xvm.onAppInitialized) g_eventBus.addListener(XFW_EVENT.APP_DESTROYED, g_xvm.onAppDestroyed) g_eventBus.addListener(XVM_EVENT.RELOAD_CONFIG, config.load) g_eventBus.addListener(XVM_EVENT.CONFIG_LOADED, g_xvm.onConfigLoaded) g_eventBus.addListener(XVM_EVENT.SYSTEM_MESSAGE, g_xvm.onSystemMessage) g_eventBus.addListener(XVM_EVENT.CHECK_ACTIVATION, g_xvm.onCheckActivation) # config already loaded, just send event to apply required code g_eventBus.handleEvent( events.HasCtxEvent(XVM_EVENT.CONFIG_LOADED, {'fromInitStage': True}))
def onCheckActivation(self, e=None): # log('xvm.onCheckActivation') status = config.token.status if status == 'active': svcmsg.tokenUpdated() else: self.xvmServicesInitialized = False self.initializeXvmServices() status = config.token.status if status == 'badToken' or status == 'inactive': svcmsg.sendXvmSystemMessage( SystemMessages.SM_TYPE.Warning, '{{l10n:token/services_not_activated}}') else: g_eventBus.handleEvent( events.HasCtxEvent(XVM_EVENT.CONFIG_LOADED)) svcmsg.tokenUpdated() self.showXvmServicesLobbyMessage()
def on_message(self, unused_channel, basic_deliver, properties, body): """Invoked by pika when a message is delivered from RabbitMQ. The channel is passed for your convenience. The basic_deliver object that is passed in carries the exchange, delivery tag and a redelivered flag for the message. The properties passed in is an instance of BasicProperties with the message properties and the body is the message that was sent. :param pika.channel.Channel unused_channel: The channel object :param pika.Spec.Basic.Deliver: basic_deliver method :param pika.Spec.BasicProperties: properties :param str|unicode body: The message body """ if self._closing: return try: #debug('[XMQP] Received message #%s: %s' % (basic_deliver.delivery_tag, body)) debug('[XMQP] recv: %s' % body) #debug(basic_deliver) #if body != 'ok': # debug('[XMQP] Received message #%s: %s' % (basic_deliver.delivery_tag, body)) if self._exchange_correlation_id == properties.correlation_id: response = simplejson.loads(body) if 'exchange' in response: self._exchange_name = response['exchange'] global players_capabilities for accountDBID, data in response['users'].iteritems(): players_capabilities[int( accountDBID)] = simplejson.loads( data) if data else {} self.bind_channel() else: log("[XMQP] ERROR: response='{}'".format(body)) self.stop() else: #elif basic_deliver.exchange: #debug('[XMQP] recv: {} {}'.format(properties.headers.get('userId', None), body)) response = simplejson.loads(body) g_eventBus.handleEvent( events.HasCtxEvent(XVM_BATTLE_EVENT.XMQP_MESSAGE, response)) except Exception as ex: err(traceback.format_exc())
def load(e): global config_data global lang_data try: # TODO: config selection filename = e.ctx.get('filename', XVM.CONFIG_FILE) configwatchdog.stopConfigWatchdog() autoreload = get('autoReloadConfig', False) config_data = None lang_data = None config_data = _load_xvm_xc(filename, autoreload) regionDetected = 'region' not in config_data or config_data[ 'region'].lower() == XVM.REGION_AUTO_DETECTION if regionDetected: config_data['region'] = GAME_REGION languageDetected = 'language' not in config_data or config_data[ 'language'] == XVM.LOCALE_AUTO_DETECTION if languageDetected: config_data['language'] = GAME_LANGUAGE lang_data = _load_locale_file() log('Config loaded. Region: {} ({}), Language: {} ({})'.format( get('region'), 'detected' if regionDetected else 'config', get('language'), 'detected' if languageDetected else 'config')) except Exception: err(traceback.format_exc()) if get('autoReloadConfig', False) == True: configwatchdog.startConfigWatchdog() g_eventBus.handleEvent(events.HasCtxEvent(XVM_EVENT.CONFIG_LOADED))
def initializeXvmServices(self): if self.xvmServicesInitialized: return accountDBID = utils.getAccountDBID() if accountDBID is None and not isReplay(): return self.xvmServicesInitialized = True self.xvmLobbyMessageShown = False self.xvmServerMessageLastInfo = None 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) g_eventBus.handleEvent( events.HasCtxEvent(XVM_EVENT.XVM_SERVICES_INITIALIZED))
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))
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 sendXvmSystemMessage(type, msg): msg = _XVM_MESSAGE_HEADER + '\n\n' + msg + '</textformat>' g_eventBus.handleEvent(events.HasCtxEvent(XVM_EVENT.SYSTEM_MESSAGE, {'msg': msg, 'type': type}))
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)
wot_ver = ResMgr.openSection(VERSION_FILE_PATH).readString('version') if 'Supertest v.ST ' in wot_ver: wot_ver = wot_ver.replace('Supertest v.ST ', 'v.') wot_ver = wot_ver[2:wot_ver.index('#') - 1] wot_ver = wot_ver if not ' ' in wot_ver else wot_ver[:wot_ver.index( ' ')] # X.Y.Z or X.Y.Z.a log(" XVM Version : %s" % XVM.XVM_VERSION) log(" XVM Revision : %s" % __revision__) log(" XVM Branch : %s" % __branch__) log(" XVM Hash : %s" % __node__) # log(" WoT Supported : %s" % ", ".join(XFW_MOD_INFO['GAME_VERSIONS'])) log(" WoT Current : %s" % wot_ver) log(" Current Time : %s %+05d" % (datetime.now().strftime('%Y-%m-%d %H:%M:%S'), round((round( (datetime.now() - datetime.utcnow()).total_seconds()) / 1800) / 2) * 100)) xvm_fonts_arr = glob(os.environ['WINDIR'] + '/Fonts/*xvm*') if len(xvm_fonts_arr): warn('Following XVM fonts installed: %s' % xvm_fonts_arr) log("---------------------------") except Exception, ex: err(traceback.format_exc()) # load config config.load( events.HasCtxEvent(XVM_EVENT.RELOAD_CONFIG, {'filename': XVM.CONFIG_FILE}))
def sendData(self, cmd): g_eventBus.handleEvent( events.HasCtxEvent(BROWSER_BRIDGE_EVENT, ctx=cmd.data))