def GetOffice(self, corpID=None): if not session.stationid2: return uthread.Lock(self, 'populatingItemIDOfficeFolderIDByCorporationID') try: if self.itemIDOfficeFolderIDByCorporationID is None: corpStationMgr = self.GetCorpStationManager() corpStationMgr.Bind() offices = corpStationMgr.GetCorporateStationOffice() self.itemIDOfficeFolderIDByCorporationID = IndexRowset( ['corporationID', 'itemID', 'officeFolderID', 'stationID'], [], 'corporationID') for office in offices: self.itemIDOfficeFolderIDByCorporationID[ office.corporationID] = [ office.corporationID, office.itemID, office.officeFolderID ] finally: uthread.UnLock(self, 'populatingItemIDOfficeFolderIDByCorporationID') if corpID is None: corpID = eve.session.corpid if self.itemIDOfficeFolderIDByCorporationID.has_key(corpID): return self.itemIDOfficeFolderIDByCorporationID[corpID]
def GetProcessInfo(self, minutes = 0, useIncrementalStartPos = False): """ returns cpu, memory and network statistics as list of dicts. """ uthread.Lock(self) try: if blue.os.GetWallclockTime() - self.cache.cacheTime < 25 * const.SEC and self.cache.minutes == minutes: return self.cache.cache startTime = blue.os.GetWallclockTime() blueLines = self.GetBlueDataAsDictList(minutes) lastLine = {} if useIncrementalStartPos: startPos = self.lastStartPos else: startPos = 0 for blueLine in blueLines: pyLine, startPos = self.FindClosestPythonLine(blueLine, startPos) if pyLine: lastLine = pyLine blueLine.update(pyLine) else: blueLine.update(lastLine) diff = (blue.os.GetWallclockTime() - startTime) / float(const.SEC) self.lastStartPos = startPos self.cache.minutes = minutes self.cache.cacheTime = blue.os.GetWallclockTime() self.cache.cache = blueLines return blueLines finally: uthread.UnLock(self)
def SampleStats(self, state): self.currentState = state try: uthread.Lock(self, 'sampleStats') if self.entries.has_key(state): stats = self.entries[state] else: stats = {} lastStageSampleTime = self.lastStageSampleTime self.lastStageSampleTime = time.clock() stats[STAT_TIME_SINCE_LAST_STATE] = int((self.lastStageSampleTime - lastStageSampleTime) * 1000) if state < STATE_GAMEEXITING: stats[STAT_MACHONET_AVG_PINGTIME] = self.GetMachoPingTime() if len(blue.pyos.cpuUsage) > 0: memdata = blue.pyos.cpuUsage[-1][2] if len(memdata) >= 2: stats[STAT_PYTHONMEMORY] = memdata[0] else: stats[STAT_PYTHONMEMORY] = 0L else: stats[STAT_PYTHONMEMORY] = 0L cpuProcessTime = blue.sysinfo.GetProcessTimes() cpuProcessTime = cpuProcessTime.userTime + cpuProcessTime.systemTime stats[STAT_CPU] = int(cpuProcessTime * 10000000.0) self.entries[state] = stats self.stateMask = self.stateMask + state if not hasattr(self, 'prevContents'): self.Persist() blue.SetCrashKeyValues(u'ClientStatsState', unicode(SHORT_STATE_STRINGS.get(state, u'Unknown'))) except Exception as e: log.LogException('Error while sampling clientStats') sys.exc_clear() finally: uthread.UnLock(self, 'sampleStats')
def _MakeShipActive(self, shipID, oldShipID): myCharID = session.charid self.LoadItem(myCharID) uthread.Lock(self, 'makeShipActive') try: while not session.IsItSafe(): self.LogInfo('MakeShipActive - session is mutating. Sleeping for 250ms') blue.pyos.synchro.SleepSim(250) if shipID is None: log.LogTraceback('Unexpectedly got shipID = None') return self.shipIDBeingDisembarked = self.GetCurrentShipID() shipDogmaItem = self.GetDogmaItem(shipID) self.StartPassiveEffects(shipID, shipDogmaItem.typeID) self.scatterAttributeChanges = False try: self.selectedDronesTracker.Clear() if oldShipID is not None: self.UnfitItemFromLocation(oldShipID, myCharID) if shipID != oldShipID: self.UnloadItem(oldShipID) self.ApplyBrainEffects(shipID, myCharID) finally: self.shipIDBeingDisembarked = None self.scatterAttributeChanges = True finally: uthread.UnLock(self, 'makeShipActive')
def ProcessSessionChange(self, isRemote, session, change, cheat=0): uthread.ReentrantLock(self) try: if 'solarsystemid' in change: self.Refresh(session.solarsystemid2) finally: uthread.UnLock(self)
def _MakeShipActive(self, shipID, shipState): self.LoadItem(session.charid) uthread.Lock(self, 'makeShipActive') self.shipIDBeingDisembarked = self.shipID try: if self.shipID == shipID: return while not session.IsItSafe(): self.LogInfo('MakeShipActive - session is mutating. Sleeping for 250ms') blue.pyos.synchro.SleepSim(250) if shipID is None: log.LogTraceback('Unexpectedly got shipID = None') return charItem = self.dogmaItems[session.charid] oldShipID = charItem.locationID if oldShipID == shipID: return self.UpdateRemoteDogmaLocation() oldShipID = self.shipID self.shipID = shipID if shipState is not None: self.instanceCache, self.instanceFlagQuantityCache, self.wbData = shipState else: try: self.instanceCache, self.instanceFlagQuantityCache, self.wbData = self.remoteShipMgr.ActivateShip(shipID, oldShipID) except Exception: self.shipID = oldShipID raise charItems = charItem.GetFittedItems() self.scatterAttributeChanges = False try: self.LoadItem(self.shipID) if oldShipID is not None: self.UnfitItemFromLocation(oldShipID, session.charid) for skill in charItems.itervalues(): for effectID in skill.activeEffects.keys(): self.StopEffect(effectID, skill.itemID) if shipID is not None: self.OnCharacterEmbarkation(session.charid, shipID, switching=oldShipID is not None) for skill in charItems.itervalues(): self.StartPassiveEffects(skill.itemID, skill.typeID) shipInv = self.broker.invCache.GetInventoryFromId(shipID, locationID=session.stationid2) self.LoadShipFromInventory(shipID, shipInv) self.SetWeaponBanks(self.shipID, self.wbData) sm.ChainEvent('ProcessActiveShipChanged', shipID, oldShipID) self.UnloadItem(oldShipID) if oldShipID: sm.ScatterEvent('OnCapacityChange', oldShipID) finally: self.scatterAttributeChanges = True self.ClearInstanceCache() finally: self.shipIDBeingDisembarked = None uthread.UnLock(self, 'makeShipActive')
def GetSystemsFromCurrent(self, cnt): uthread.ReentrantLock(self) try: self.Refresh(eve.session.solarsystemid2) if cnt in self.systemsByJumpCount[self.routeType]: return self.systemsByJumpCount[self.routeType][cnt] return [] finally: uthread.UnLock(self)
def Reconstruct(self, animate = False): uthread.Lock(self) try: self.ConstructTopIcons() if animate: uicore.animations.FadeOut(self.mainCont, sleep=True, duration=0.3) self.ConstructInfoPanels() uicore.animations.FadeIn(self.mainCont, duration=0.6) finally: uthread.UnLock(self)
def GetDogmaLocation(self, charBrain=None, *args): uthread.Lock('GetDogmaLocation') try: if self.dogmaLocation is None: self.dogmaLocation = DogmaLocation(self, charBrain) self.LogInfo('Created client dogmaLocation', id(self.dogmaLocation)) finally: uthread.UnLock('GetDogmaLocation') return self.dogmaLocation
def LoadWorldSpaceInstance(self, instanceID, worldSpaceTypeID = None): uthread.Lock(self, 'Worldspace', instanceID) try: self.LogInfo('Loading WorldSpaceInstance') if instanceID not in self.instances: if worldSpaceTypeID is None: worldSpaceTypeID = self.GetWorldSpaceTypeIDFromWorldSpaceID(instanceID) newWorldSpace = self._LoadWorldSpaceFromServer(instanceID, worldSpaceTypeID) finally: self.LogInfo('Done loading WorldSpaceInstance') uthread.UnLock(self, 'Worldspace', instanceID)
def GetMyPaperDollData(self, charID): currentCharsPaperDollData = self.currentCharsPaperDollData.get(charID, None) if currentCharsPaperDollData is not None: return currentCharsPaperDollData uthread.Lock(self) try: if self.currentCharsPaperDollData.get(charID, None) is None: self.currentCharsPaperDollData[charID] = sm.RemoteSvc('paperDollServer').GetMyPaperDollData(charID) return self.currentCharsPaperDollData.get(charID, None) finally: uthread.UnLock(self)
def GetRecentlyChangedSkills(self): if self._recentlyChangedSkills is not None: return self._recentlyChangedSkills uthread.Lock(self, 'GetRecentlyChangedSkills') try: if self._recentlyChangedSkills is None: self._recentlyChangedSkills = sm.GetService( 'skills').GetRecentlyTrainedSkills() finally: uthread.UnLock(self, 'GetRecentlyChangedSkills') return self._recentlyChangedSkills
def GetMultiJumpCounts(self, solarSystemPairs): uthread.Lock(self, 'JumpCalculation') try: ret = {} self.PrepareCache() for fromID, toID in solarSystemPairs: self.Refresh(fromID, toID) ret[fromID, toID] = self.cache[self.routeType][toID][0] return ret finally: uthread.UnLock(self, 'JumpCalculation')
def ResetWindow(self, bShowIfVisible=0): uthread.Lock(self) try: self.panels = {} self.votewindows = {} self.ResetPanels() wnd = self.GetWnd() if wnd and not wnd.destroyed: wnd.Close() if bShowIfVisible: self.Show() finally: uthread.UnLock(self)
def GetSecurityStatus(self, solarSystemID, getColor=False): if self.securityInfo is None: uthread.Lock(self) try: self.securityInfo = {} for systemID, each in cfg.mapSystemCache.iteritems(): self.securityInfo[systemID] = each.pseudoSecurity finally: uthread.UnLock(self) return util.FmtSystemSecStatus( self.securityInfo.get(solarSystemID, 0.0), getColor)
def GetFittingDogmaLocation(self, force=False, *args): uthread.Lock('GetFittingDogmaLocation') try: if self.fittingDogmaLocation is None or force: from eve.client.script.ui.shared.fittingGhost.fittingDogmaLocation import FittingDogmaLocation charBrain = self._GetBrainForGhostFitting() self.fittingDogmaLocation = FittingDogmaLocation( self, charBrain=charBrain) self.LogInfo('Created client fittingDogmaLocation', id(self.fittingDogmaLocation)) finally: uthread.UnLock('GetFittingDogmaLocation') return self.fittingDogmaLocation
def OnDblClick(self, *args): if eve.rookieState and eve.rookieState < 22: return self.sr.clicktime = None solarsystemID = eve.session.solarsystemid uthread.Lock(self) try: if solarsystemID != eve.session.solarsystemid: return if self.notdbl: return if uicore.uilib.Key(uiconst.VK_SHIFT ) and eve.session.role & service.ROLE_CONTENT: return x, y = uicore.uilib.x, uicore.uilib.y if uicore.uilib.rightbtn or uicore.uilib.mouseTravel > 6: return cameraSvc = sm.GetService('camera') if cameraSvc.dungeonHack.IsFreeLook(): picktype, pickobject = self.GetPick() if pickobject: cameraSvc.LookAt(pickobject.translationCurve.id) return scene = sm.GetService('sceneManager').GetRegisteredScene('default') camera = sm.GetService('sceneManager').GetRegisteredCamera( 'default') if camera is not None: proj = camera.projectionMatrix.transform view = camera.viewMatrix.transform pickDir = scene.PickInfinity(uicore.ScaleDpi(x), uicore.ScaleDpi(y), proj, view) if pickDir: bp = sm.GetService('michelle').GetRemotePark() if bp is not None: if solarsystemID != eve.session.solarsystemid: return try: bp.CmdGotoDirection(pickDir[0], pickDir[1], pickDir[2]) sm.ScatterEvent( 'OnClientEvent_MoveWithDoubleClick') sm.GetService('menu').ClearAlignTargets() sm.GetService('flightPredictionSvc').GotoDirection( pickDir) except RuntimeError as what: if what.args[0] != 'MonikerSessionCheckFailure': raise what finally: uthread.UnLock(self)
def GetSecurityStatus(self, solarSystemID): if self.securityInfo is None: uthread.Lock(self) try: self.securityInfo = {} for each in cfg.solarsystems: self.securityInfo[each.solarSystemID] = each.pseudoSecurity finally: uthread.UnLock(self) if solarSystemID in self.securityInfo: return util.FmtSystemSecStatus(self.securityInfo[solarSystemID]) return 0.0
def Index(self, colname): if self in self.__immutable__: uthread.Lock(self, '__immutable__', colname) try: if colname not in self.__immutable__[self][0]: ret = IndexRowset(self.header, self.lines, colname) self.__immutable__[self][0][colname] = ret ret.MakeImmutable() return self.__immutable__[self][0][colname] finally: uthread.UnLock(self, '__immutable__', colname) else: return IndexRowset(self.header, self.lines, colname)
def Filter(self, colname, colname2 = None): if self in self.__immutable__: k = (colname, colname2) uthread.Lock(self, '__immutable__', k) try: if k not in self.__immutable__[self][1]: ret = FilterRowset(self.header, self.lines, colname, idName2=colname2) ret.MakeImmutable() self.__immutable__[self][1][k] = ret return self.__immutable__[self][1][k] finally: uthread.UnLock(self, '__immutable__', k) else: return FilterRowset(self.header, self.lines, colname, idName2=colname2)
def UnloadWorldSpaceInstance(self, instanceID): if self.IsInstanceLoaded(instanceID): uthread.Lock(self, 'Worldspace', instanceID) try: if self.IsInstanceLoaded(instanceID) and (session.worldspaceid is None or session.worldspaceid and session.worldspaceid != instanceID): self.LogInfo('Unloading worldspace instance', instanceID) instance = self.instances[instanceID] proximity = sm.GetService('proximity') proximity.UnloadInstance(instance) sm.ChainEvent('ProcessWorldSpaceUnloading', instanceID) BaseWorldSpaceService.UnloadWorldSpaceInstance(self, instanceID) sm.ScatterEvent('OnWorldSpaceUnloaded', instanceID) finally: self.LogInfo('Unloaded worldspace instance', instanceID) uthread.UnLock(self, 'Worldspace', instanceID)
def CryptoAPI_GetCryptoContext(): global cryptoAPI_cryptoContext if cryptoAPI_cryptoContext is not None: return cryptoAPI_cryptoContext uthread.Lock('CryptoAPI_GetCryptoContext') try: if cryptoAPI_cryptoContext is not None: return cryptoAPI_cryptoContext cryptoAPI_cryptoContext = blue.crypto.CryptAcquireContext( None, cryptoAPI_cryptoProvider, cryptoAPI_PROV_cryptoProviderType, blue.crypto.CRYPT_VERIFYCONTEXT | blue.crypto.CRYPT_SILENT) finally: uthread.UnLock('CryptoAPI_GetCryptoContext') return cryptoAPI_cryptoContext
def GetCharCreationInfo(self): if self.charCreationInfo is None: uthread.Lock(self) try: if self.charCreationInfo is None: o = uiutil.Bunch() o.update( sm.RemoteSvc('charUnboundMgr').GetCharCreationInfo()) o.update( sm.RemoteSvc( 'charUnboundMgr').GetCharNewExtraCreationInfo()) self.charCreationInfo = o finally: uthread.UnLock(self) return self.charCreationInfo
def GetDogmaLocation(self, *args): """ We currently just have one dogmaLocation which is the one where you handle the ship you are in. In the future I hope to have more dogmaLocations, at least one to handle virtual ships you are not in. """ uthread.Lock('GetDogmaLocation') try: if self.dogmaLocation is None: self.dogmaLocation = dogmax.DogmaLocation(self) self.LogInfo('Created client dogmaLocation', id(self.dogmaLocation)) finally: uthread.UnLock('GetDogmaLocation') return self.dogmaLocation
def Get(self, key, flush=0): key = int(key) if flush or not self.data.has_key(key): if boot.role != 'server': self.Prime([key]) else: uthread.Lock(self, key) try: if flush or not self.data.has_key(key): self.__LoadData(key) finally: uthread.UnLock(self, key) if self.data.has_key(key): return self.rowclass(self, key) raise KeyError('RecordNotFound', key)
def Write(self, message): if self.transport: MachoTransport.Write(self, message) try: uthread.Lock(self, 'httpReaders') if len( self.readers ) > 0 and message.command == const.cluster.MACHONETMSG_TYPE_NOTIFICATION: with bluepy.Timer( 'machoNet::StreamingHTTPMachoTransport::Write::MPT-Megahack' ): sent = False try: data = message.__getstate__() if data[0] == 12: if data[2].__getstate__()[1] == '__MultiEvent': self.LogInfo( 'Splitting __MultiEvent into multiple chunks' ) jsonMessage = json.loads( httpUtil.ToComplexJSON(data)) innerMessages = jsonMessage[4][0][1][1][1] innerMessage = (12, None, [[], None], None, [[0, [0, [1, None]]]]) with bluepy.Timer( 'machoNet::StreamingHTTPMachoTransport::Write::MPT-Megahack::Multiplex' ): for msg in innerMessages: innerMessage[2][1] = msg[0] innerMessage[4][0][1][1][1] = msg[1] for reader in self.readers: reader.write(innerMessage) sent = True except: self.LogError('MultiEvent exception', message) log.LogException() with bluepy.Timer( 'machoNet::StreamingHTTPMachoTransport::Write::Multiplex' ): if not sent: for reader in self.readers.copy(): reader.write(message) finally: uthread.UnLock(self, 'httpReaders')
def SendContentsToServer(self, contents = None): """ Transmits any data loaded in from a saved clientStats.dat file to the server. This is called shortly after authentication during the login process. """ try: if not sm.services['machoNet'].IsConnected(): return except: sys.exc_clear() return if contents is None: contents = self.prevContents if contents is None or contents[0] != self.version: contents = {} else: contents = contents[1] build = boot.GetValue('build', None) contentType = CONTENT_TYPE_PREMIUM operatingSystem = PLATFORM_WINDOWS if blue.win32.IsTransgaming(): operatingSystem = PLATFORM_MACOS blendedContents = self.entries blendedStateMask = self.stateMask self.entries = dict() self.stateMask = 0 if contents.has_key(STATE_DISCONNECT): blendedContents[STATE_DISCONNECT] = contents[STATE_DISCONNECT] blendedStateMask += STATE_DISCONNECT if contents.has_key(STATE_GAMESHUTDOWN): blendedContents[STATE_GAMESHUTDOWN] = contents[STATE_GAMESHUTDOWN] blendedStateMask += STATE_GAMESHUTDOWN header = (self.version, blendedStateMask, build, operatingSystem, contentType) data = (header, blendedContents) try: uthread.Lock(self, 'sendContents') sm.RemoteSvc('clientStatsMgr').SubmitStats(data) if hasattr(self, 'prevContents'): delattr(self, 'prevContents') return True finally: uthread.UnLock(self, 'sendContents')
def GetJumpCountFromCurrent(self, toID, locationID=None): uthread.Lock(self, 'JumpCalculation') try: self.PrepareCache() if locationID is None: locationID = eve.session.solarsystemid2 if type(toID) == types.ListType: ret = [] for systemID in toID: self.Refresh(locationID, systemID) ret.append(self.cache[self.routeType][systemID][0]) return ret self.Refresh(locationID, toID) return self.cache[self.routeType][toID][0] finally: uthread.UnLock(self, 'JumpCalculation')
def GetSecurityStatus(self, solarSystemID, getColor = False): """ returns 'pseudo' security for 'solarSystemID' in the following format: Rounds the security to the nearest one digit precision with the following exeption: 0.0 < sec < 0.05 is rounded up to 0.1 but not down to 0.0 example: 0.08 -> 0.1, -0.22 -> -0.2, 0.451 -> 0.5, 0.449 -> 0.4, -0.26 -> -0.3 """ if self.securityInfo is None: uthread.Lock(self) try: self.securityInfo = {} for systemID, each in cfg.mapSystemCache.iteritems(): self.securityInfo[systemID] = each.pseudoSecurity finally: uthread.UnLock(self) return util.FmtSystemSecStatus(self.securityInfo.get(solarSystemID, 0.0), getColor)
def GetStaticHeader(self): """ Return a bunch of information in the response header about the server if he has not authenticated yet. The reason this is only returned into the header when you are not authenticated is that this is quite a lot of data that we don't want to be shoveling out with every request. The proxy only returns a subset of the data while the server returns the whole thing. Nothing is returned on the client Most of the information here is fetched once and then stored but online user count is fetched every 5 minutes. """ uthread.Lock('http.GetStaticHeader') try: if self.staticHeader is None: self.staticHeader = {} self.staticHeader['CCP-codename'] = boot.codename self.staticHeader['CCP-version'] = boot.version self.staticHeader['CCP-build'] = boot.build self.staticHeader['CCP-sync'] = boot.sync self.staticHeader['CCP-clustermode'] = prefs.GetValue('clusterMode', 'n/a') if boot.role == 'server': product = sm.GetService('cache').Setting('zsystem', 'Product') ebsVersion = sm.GetService('DB2').CallProc('zsystem.Versions_Select', product)[0].version bsdChangeList = sm.GetService('DB2').SQLInt('TOP 1 changeID', 'zstatic.changes', 'submitDate IS NOT NULL', 'submitDate DESC', 'branchID', sm.GetService('BSD').Setting(1)) self.staticHeader['CCP-product'] = product self.staticHeader['CCP-EBS'] = ebsVersion self.staticHeader['CCP-StaticBranch'] = sm.GetService('BSD').BranchName() if len(bsdChangeList) > 0: self.staticHeader['CCP-StaticCL'] = bsdChangeList[0].changeID if boot.role == 'proxy': machoNet = sm.GetService('machoNet') onlineCountEve = machoNet.GetClusterSessionCounts('EVE:Online')[0] onlineCountDust = machoNet.GetClusterSessionCounts('DUST:Online')[0] acl = machoNet.CheckACL(None, espCheck=True) vipMode = machoNet.vipMode self.staticHeader['CCP-onlineCount'] = onlineCountEve + onlineCountDust self.staticHeader['CCP-onlineCountEve'] = onlineCountEve self.staticHeader['CCP-onlineCountDust'] = onlineCountDust self.staticHeader['CCP-ACL'] = acl[1] if acl else None self.staticHeader['CCP-VIP'] = machoNet.vipMode except Exception: self.staticHeader = {'BADHEADER': ''} log.LogException() finally: uthread.UnLock('http.GetStaticHeader') return self.staticHeader