def _pingAsync(self): try: res = dict() for host in self.hosts: res[host['name']] = l10n_macros_replace(config.get('hangar/pingServers/errorString', '--') if g_hangarSpace.inited else config.get('login/pingServers/errorString', '--')) if os.path.exists(LINUX_PING_PATH_IN_WINE): (pattern, processes) = self._pingAsyncLinux() else: (pattern, processes) = self._pingAsyncWindows() # Parse ping output best_ping = 999 for x in self.hosts: proc = processes[x['name']] out, er = proc.communicate() errCode = proc.wait() if errCode != 0: continue found = re.search(pattern, out) if not found: res[x['name']] = '?' debug('Ping regexp not found in %s' % out.replace('\n', '\\n')) continue res[x['name']] = found.group(1) best_ping = min(best_ping, int(found.group(1))) if (g_hangarSpace.inited and config.get('hangar/pingServers/showTitle')) or (not g_hangarSpace.inited and config.get('login/pingServers/showTitle')): res['###best_ping###'] = best_ping # will be first in sorting by server, key is replaced by localized "Ping" except Exception, ex: err('_pingAsync() exception: ' + traceback.format_exc())
def _getOnlineAsync(self): try: res = {} for host in self.hosts: res[host] = l10n_macros_replace(config.get('hangar/onlineServers/errorString', '--k') if g_hangarSpace.inited else config.get('login/onlineServers/errorString', '--k')) req = "onlineUsersCount/0" server = XVM.SERVERS[randint(0, len(XVM.SERVERS) - 1)] (response, delay, error) = loadUrl(server, req, showLog=False) # typical response: #{ # "eu": [{"players_online":4297,"server":"EU2"},{"players_online":8331,"server":"EU1"}], # "na": [{"players_online":22740,"server":"NA EAST"},{"players_online":7431,"server":"NA WEST"}], # "asia":[{"players_online":6603,"server":"ASIA"}], # "kr": [{"players_online":868,"server":"KR"}], # "ru": [{"players_online":14845,"server":"RU8"},{"players_online":8597,"server":"RU2"},{"players_online":9847,"server":"RU1"},{"players_online":3422,"server":"RU3"},{"players_online":11508,"server":"RU6"},{"players_online":6795,"server":"RU5"},{"players_online":3354,"server":"RU4"}] #} region = GAME_REGION.lower() if 'CT' in URLS.WG_API_SERVERS and region == 'ct': # CT is uncommented in xfw.constants to check on test server region = 'ru' response_data = None if response is None else simplejson.loads(response).get(region, []) best_online = 0 if not error and type(response_data) is list: for host in response_data: if host['server'].find('NA ') == 0: # API returns "NA EAST" instead of "US East" => can't determine current server host['server'] = 'US ' + host['server'][3:].capitalize() res[str(host['server'])] = host['players_online'] best_online = max(best_online, int(host['players_online'])) if (g_hangarSpace.inited and config.get('hangar/onlineServers/showTitle')) or (not g_hangarSpace.inited and config.get('login/onlineServers/showTitle')): res['###best_online###'] = str(best_online) # will be first in sorting, key is replaced by localized "Online" except Exception, ex: err('_getOnlineAsync() exception: ' + traceback.format_exc())
def VehicleParamsField_getValue(base, self): # log('VehicleParamsField_getValue') try: global carousel_tooltips_cache vehicle = self._tooltip.item context_name = self._tooltip.context.getComponent() cache_result = carousel_tooltips_cache.get(vehicle.intCD, {}).get(context_name) if cache_result: return cache_result result = list() configuration = self._tooltip.context.getParamsConfiguration(vehicle) params = configuration.params crew = configuration.crew eqs = configuration.eqs devices = configuration.devices veh_descr = vehicle.descriptor gun = vehicle.gun.descriptor turret = vehicle.turret.descriptor vehicleCommonParams = dict(ItemsParameters.g_instance.getParameters(veh_descr)) vehicleRawParams = dict(ParametersCache.g_instance.getParameters(veh_descr)) result.append([]) veh_type_inconfig = vehicle.type.replace('AT-SPG', 'TD') clipGunInfoShown = False premium_shells = {} for shell in vehicle.shells: premium_shells[shell.intCompactDescr] = shell.isPremium if params: values = config.get('tooltips/%s' % veh_type_inconfig) if values and len(values): params_list = values # overriding parameters else: params_list = self.PARAMS.get(vehicle.type, 'default') # original parameters for paramName in params_list: if paramName == 'turretArmor' and not vehicle.hasTurrets: continue #inner name, for example - ussr:R100_SU122A if paramName == 'innerName': result[-1].append([h1_pad(vehicle.name), '']) continue #maxHealth if paramName == 'maxHealth': result[-1].append([h1_pad(i18n.makeString('#menu:vehicleInfo/params/maxHealth')), h1_pad(veh_descr.maxHealth)]) continue #battle tiers if paramName == 'battleTiers': (minTier, maxTier) = getTiers(vehicle.level, vehicle.type, vehicle.name) result[-1].append([h1_pad(l10n('Battle tiers')), h1_pad('%s..%s' % (minTier, maxTier))]) continue #gravity if paramName == 'gravity': gravity_str = '%g' % round(veh_descr.shot['gravity'], 2) result[-1].append([h1_pad(l10n('gravity')), h1_pad(gravity_str)]) continue #camo coeffitients if paramName == 'camo_coeff': topTurret = veh_descr.type.turrets[0][-1] camo_coeff_arr = getCamoValues(vehicle.name, turret['name'] == topTurret['name'], gun['name']) camo_coeff_str = '/'.join(map(camo_smart_round, camo_coeff_arr)) result[-1].append([h1_pad(l10n('camoCoeff') + ' <p>(%)</p>'), h1_pad(camo_coeff_str)]) continue #radioRange if paramName == 'radioRange': radioRange_str = '%s' % int(vehicle.radio.descriptor['distance']) result[-1].append([i18n.makeString('#menu:moduleInfo/params/radioDistance').replace('h>', 'h1>'), h1_pad(radioRange_str)]) continue #explosionRadius if paramName == 'explosionRadius': explosionRadiusMin = 999 explosionRadiusMax = 0 for shot in gun['shots']: if 'explosionRadius' in shot['shell']: if shot['shell']['explosionRadius'] < explosionRadiusMin: explosionRadiusMin = shot['shell']['explosionRadius'] if shot['shell']['explosionRadius'] > explosionRadiusMax: explosionRadiusMax = shot['shell']['explosionRadius'] if explosionRadiusMax == 0: # no HE continue explosionRadius_str = '%g' % round(explosionRadiusMin, 2) if explosionRadiusMin != explosionRadiusMax: explosionRadius_str += '/%s' % gold_pad('%g' % round(explosionRadiusMax, 2)) result[-1].append([self._getParameterValue(paramName, vehicleCommonParams, vehicleRawParams)[0], h1_pad(explosionRadius_str)]) continue #shellSpeedSummary if paramName == 'shellSpeedSummary': shellSpeedSummary_arr = [] for shot in gun['shots']: shellSpeed_str = '%g' % round(shot['speed'] * 1.25) if premium_shells[shot['shell']['compactDescr']]: shellSpeed_str = gold_pad(shellSpeed_str) shellSpeedSummary_arr.append(shellSpeed_str) shellSpeedSummary_str = '/'.join(shellSpeedSummary_arr) result[-1].append([h1_pad('%s <p>%s</p>' % (l10n('shellSpeed'), l10n('(m/sec)'))), h1_pad(shellSpeedSummary_str)]) continue #piercingPowerAvg if paramName == 'piercingPowerAvg': piercingPowerAvg = '%g' % veh_descr.shot['piercingPower'][0] result[-1].append([i18n.makeString('#menu:moduleInfo/params/avgPiercingPower').replace('h>', 'h1>'), h1_pad(piercingPowerAvg)]) continue #piercingPowerAvgSummary if paramName == 'piercingPowerAvgSummary': piercingPowerAvgSummary_arr = [] for shot in gun['shots']: piercingPower_str = '%g' % shot['piercingPower'][0] if premium_shells[shot['shell']['compactDescr']]: piercingPower_str = gold_pad(piercingPower_str) piercingPowerAvgSummary_arr.append(piercingPower_str) piercingPowerAvgSummary_str = '/'.join(piercingPowerAvgSummary_arr) result[-1].append([i18n.makeString('#menu:moduleInfo/params/avgPiercingPower').replace('h>', 'h1>'), h1_pad(piercingPowerAvgSummary_str)]) continue #damageAvgSummary if paramName == 'damageAvgSummary': damageAvgSummary_arr = [] for shot in gun['shots']: damageAvg_str = '%g' % shot['shell']['damage'][0] if premium_shells[shot['shell']['compactDescr']]: damageAvg_str = gold_pad(damageAvg_str) damageAvgSummary_arr.append(damageAvg_str) damageAvgSummary_str = '/'.join(damageAvgSummary_arr) result[-1].append([i18n.makeString('#menu:moduleInfo/params/avgDamage').replace('h>', 'h1>'), h1_pad(damageAvgSummary_str)]) continue #magazine loading if (paramName == 'reloadTimeSecs' or paramName == 'rateOfFire') and vehicle.gun.isClipGun(): if clipGunInfoShown: continue (shellsCount, shellReloadingTime) = gun['clip'] reloadMagazineTime = gun['reloadTime'] shellReloadingTime_str = '%g' % round(shellReloadingTime, 2) reloadMagazineTime_str = '%g' % round(reloadMagazineTime, 2) result[-1].append([i18n.makeString('#menu:moduleInfo/params/shellsCount').replace('h>', 'h1>'), h1_pad(shellsCount)]) result[-1].append([i18n.makeString('#menu:moduleInfo/params/shellReloadingTime').replace('h>', 'h1>'), h1_pad(shellReloadingTime_str)]) result[-1].append([i18n.makeString('#menu:moduleInfo/params/reloadMagazineTime').replace('h>', 'h1>'), h1_pad(reloadMagazineTime_str)]) clipGunInfoShown = True continue #rate of fire if paramName == 'rateOfFire' and not vehicle.gun.isClipGun(): rateOfFire_str = '%g' % round(60 / gun['reloadTime'], 2) result[-1].append([i18n.makeString('#menu:moduleInfo/params/reloadTime').replace('h>', 'h1>'), h1_pad(rateOfFire_str)]) continue # gun traverse limits if paramName == 'traverseLimits' and gun['turretYawLimits']: (traverseMin, traverseMax) = gun['turretYawLimits'] traverseLimits_str = '%g..+%g' % (round(degrees(traverseMin)), round(degrees(traverseMax))) result[-1].append([h1_pad(l10n('traverseLimits')), h1_pad(traverseLimits_str)]) continue # elevation limits (front) if paramName == 'pitchLimits': (pitchMax, pitchMin) = calcPitchLimitsFromDesc(0, gun['pitchLimits']) pitchLimits_str = '%g..+%g' % (round(degrees(-pitchMin)), round(degrees(-pitchMax))) result[-1].append([h1_pad(l10n('pitchLimits')), h1_pad(pitchLimits_str)]) continue # elevation limits (side) if paramName == 'pitchLimitsSide': if gun['turretYawLimits'] and abs(degrees(gun['turretYawLimits'][0])) < 89: continue # can't look aside 90 degrees (pitchMax, pitchMin) = calcPitchLimitsFromDesc(pi / 2, gun['pitchLimits']) pitchLimits_str = '%g..+%g' % (round(degrees(-pitchMin)), round(degrees(-pitchMax))) result[-1].append([h1_pad(l10n('pitchLimitsSide')), h1_pad(pitchLimits_str)]) continue # elevation limits (rear) if paramName == 'pitchLimitsRear': if gun['turretYawLimits']: continue # can't look back (pitchMax, pitchMin) = calcPitchLimitsFromDesc(pi, gun['pitchLimits']) pitchLimits_str = '%g..+%g' % (round(degrees(-pitchMin)), round(degrees(-pitchMax))) result[-1].append([h1_pad(l10n('pitchLimitsRear')), h1_pad(pitchLimits_str)]) continue # shooting range if paramName == 'shootingRadius': viewRange, shellRadius, artiRadius = _getRanges(turret, gun, vehicle.nationName, vehicle.type) if vehicle.type == 'SPG': result[-1].append([h1_pad('%s <p>%s</p>' % (l10n('shootingRadius'), l10n('(m)'))), h1_pad(artiRadius)]) elif shellRadius < 707: result[-1].append([h1_pad('%s <p>%s</p>' % (l10n('shootingRadius'), l10n('(m)'))), h1_pad(shellRadius)]) continue #reverse max speed if paramName == 'speedLimits': (speedLimitForward, speedLimitReverse) = veh_descr.physics['speedLimits'] speedLimits_str = str(int(speedLimitForward * 3.6)) + '/' + str(int(speedLimitReverse * 3.6)) result[-1].append([self._getParameterValue(paramName, vehicleCommonParams, vehicleRawParams)[0], speedLimits_str]) continue #turret rotation speed if paramName == 'turretRotationSpeed': if not vehicle.hasTurrets: paramName = 'gunRotationSpeed' turretRotationSpeed_str = str(int(degrees(veh_descr.turret['rotationSpeed']))) result[-1].append([self._getParameterValue(paramName, vehicleCommonParams, vehicleRawParams)[0], turretRotationSpeed_str]) continue #terrain resistance if paramName == 'terrainResistance': resistances_arr = [] for key in veh_descr.chassis['terrainResistance']: resistances_arr.append('%g' % round(key, 2)) terrainResistance_str = '/'.join(resistances_arr) result[-1].append([h1_pad(l10n('terrainResistance')), h1_pad(terrainResistance_str)]) continue #custom text if paramName.startswith('TEXT:'): customtext = paramName[5:] result[-1].append([h1_pad(l10n_macros_replace(customtext)), '']) continue if paramName in vehicleCommonParams or paramName in vehicleRawParams: result[-1].append(self._getParameterValue(paramName, vehicleCommonParams, vehicleRawParams)) if vehicle.isInInventory: # optional devices icons, must be in the end if 'optDevicesIcons' in params_list: optDevicesIcons_arr = [] for key in vehicle.optDevices: if key: imgPath = 'img://gui' + key.icon.lstrip('.') else: imgPath = 'img://gui/maps/icons/artefact/empty.png' optDevicesIcons_arr.append('<img src="%s" height="16" width="16">' % imgPath) optDevicesIcons_str = ' '.join(optDevicesIcons_arr) result[-1].append([optDevicesIcons_str, '']) # equipment icons, must be in the end if 'equipmentIcons' in params_list: equipmentIcons_arr = [] for key in vehicle.eqs: if key: imgPath = 'img://gui' + key.icon.lstrip('.') else: imgPath = 'img://gui/maps/icons/artefact/empty.png' equipmentIcons_arr.append('<img src="%s" height="16" width="16">' % imgPath) equipmentIcons_str = ' '.join(equipmentIcons_arr) if config.get('tooltips/combineIcons') and optDevicesIcons_str: result[-1][-1][0] += ' ' + equipmentIcons_str else: result[-1].append([equipmentIcons_str, '']) # crew roles icons, must be in the end if 'crewRolesIcons' in params_list: imgPath = 'img://../mods/shared_resources/xvm/res/icons/tooltips/roles' crewRolesIcons_arr = [] for tankman_role in vehicle.descriptor.type.crewRoles: crewRolesIcons_arr.append('<img src="%s/%s.png" height="16" width="16">' % (imgPath, tankman_role[0])) crewRolesIcons_str = ''.join(crewRolesIcons_arr) result[-1].append([crewRolesIcons_str, '']) result.append([]) if config.get('tooltips/hideBottomText'): pass else: if crew: currentCrewSize = 0 if vehicle.isInInventory: currentCrewSize = len([ x for _, x in vehicle.crew if x is not None ]) result[-1].append({'label': 'crew', 'current': currentCrewSize, 'total': len(vehicle.descriptor.type.crewRoles)}) if eqs: result[-1].append({'label': 'equipments', 'current': len([ x for x in vehicle.eqs if x ]), 'total': len(vehicle.eqs)}) if devices: result[-1].append({'label': 'devices', 'current': len([ x for x in vehicle.descriptor.optionalDevices if x ]), 'total': len(vehicle.descriptor.optionalDevices)}) if vehicle.intCD not in carousel_tooltips_cache: carousel_tooltips_cache[vehicle.intCD] = {} carousel_tooltips_cache[vehicle.intCD][context_name] = result return result except Exception as ex: err(traceback.format_exc()) return base(self)