def SetShipConfig(self, key, value): lock = locks.TempLock('%s:%s' % (self, self.shipid)) if lock.lockedWhen is not None: return with lock: self.ship.ConfigureShip(self.shipid, {key: value}) self.config[key] = value
def _OpenCorporationPanel_Planets_Callback(self): with locks.TempLock('OpenCorporationPanel_Planets', locks.RLock): if sm.GetService('planetSvc').GetMyPlanets(): self.cmd.OpenPlanets() else: systemData = sm.GetService('map').GetSolarsystemItems( session.solarsystemid2) systemPlanets = [] for orbitalBody in systemData: if orbitalBody.groupID == const.groupPlanet: systemPlanets.append(orbitalBody) planetID = systemPlanets[random.randrange( 0, len(systemPlanets))].itemID sm.GetService('planetUI').Open(planetID) if not settings.user.suppress.Get('suppress.PI_Info', None): ret, supp = sm.GetService('gameui').MessageBox( localization.GetByLabel('UI/PI/IntroText'), title=localization.GetByLabel( 'UI/Generic/Information'), buttons=uiconst.OK, modal=False, icon=uiconst.INFO, suppText=localization.GetByLabel( 'UI/Shared/Suppress1')) if supp: settings.user.suppress.Set('suppress.PI_Info', supp)
def OnLSC(self, channelID, estimatedMembercount, method, who, *args): """ React to a Large-Scale Chat Event. Monitors the chat on the Move-channel. Moving users that speak the phrase defined by self.movePhrase. Params: channelID - The id of the channel. Tuple or integer. estimatedMembercount - Estimated member count of the channel. method - The method used on the channel. who - The character using the method. *args - Arguments of the method used. """ if self.channelID is None: return if channelID != self.channelID: return charID = self.GetCharacterIDFromLSC(who) if charID == session.charid or charID in self.waitingList: return if method == 'SendMessage': if len(args[0]) == 0: return message = args[0][0] if message.lower() == self.movePhrase.lower(): with locks.TempLock('waitingList', locks.RLock): self.waitingList.insert(0, charID) sm.ScatterEvent('OnAutoMoveBotQueueChange', len(self.waitingList))
def ThrottledCall(key, boundMethod, *args): """ The idea here is that you should not have multiple identical outstanding calls to the server at the same time. So queue up those calls and share the result once the first one returns. Do not confuse this with a caching mechanism or a generic 'once-per-X-timeunits' throttle; it's a singleton call pattern. This should only be used for client-to-server calls. If you need specific singletoncall for any other type of remote call, use the SingletonCall decorator in the locks module to decorate your function. """ logger = sm.GetService('machoNet').LogInfo with locks.TempLock(key, locks.RLock) as t: if hasattr(t, 'result'): logger('No need to cross the wire for', key, 'found throttler result from', (blue.os.GetWallclockTime() - t.resultTime) / const.uSEC, 'microseconds ago:', repr(t.result)[:128]) ret = t.result if t.nWaiting == 0: logger('No more consumers, invalidating cached result', repr(t.result)[:128]) del t.result else: ret = boundMethod(*args) if t.nWaiting > 0: t.result = ret t.resultTime = blue.os.GetWallclockTime() logger('Sharing result for call', key, 'at', t.resultTime, 'for', t.nWaiting, 'waiting threads:', repr(t.result)[:128]) return ret
def GetShipConfig(self, shipID = None): if shipID is not None: return moniker.GetShipAccess().GetShipConfiguration(shipID) if util.GetActiveShip() != self.shipid: self._ClearCachedAttributes() with locks.TempLock('%s:%s' % (self, self.shipid)): if self.config is None: self.config = self.ship.GetShipConfiguration(self.shipid) return self.config
def MoveCharacterThread(self): while self.moveRunning is True: if len(self.waitingList) > 0: charID = None with locks.TempLock('waitingList', locks.RLock): charID = self.waitingList.pop() sm.ScatterEvent('OnAutoMoveBotQueueChange', len(self.waitingList)) self.MoveCharacter(charID) else: blue.pyos.synchro.SleepWallclock(2000)
def UpdateApplicationOffer(self, applicationID, characterID, corporationID, applicationText, status, applicationDateTime=None): with locks.TempLock('UpdateApplicationOffer', lockClass=locks.Lock): return self.GetCorpRegistry().UpdateApplicationOffer( applicationID, characterID, corporationID, applicationText, status, applicationDateTime)
def _PrimeService(self): with locks.TempLock((self, 'PrimeService')): if not self.__ready__: try: self.LogInfo('Priming clustersingleton service...') startTime = blue.os.GetWallclockTimeNow() self.PrimeService() self.LogNotice('Done priming clustersingleton service %s in %.3f seconds.' % (self.__logname__, (blue.os.GetWallclockTimeNow() - startTime) / float(const.SEC))) except Exception as e: log.LogException('Error priming Cluster Singleton service %s' % self.__logname__) finally: self.__ready__ = 1
def OnLSC(self, channelID, estimatedMembercount, method, who, *args): if self.channelID is None: return if channelID != self.channelID: return charID = self.GetCharacterIDFromLSC(who) if charID == session.charid or charID in self.waitingList: return if method == 'SendMessage': if len(args[0]) == 0: return message = args[0][0] if message.lower() == self.movePhrase.lower(): with locks.TempLock('waitingList', locks.RLock): self.waitingList.insert(0, charID) sm.ScatterEvent('OnAutoMoveBotQueueChange', len(self.waitingList))
def ThrottledCall(key, boundMethod, *args): logger = sm.GetService('machoNet').LogInfo with locks.TempLock(key, locks.RLock) as t: if hasattr(t, 'result'): logger('No need to cross the wire for', key, 'found throttler result from', (blue.os.GetWallclockTime() - t.resultTime) / const.uSEC, 'microseconds ago:', repr(t.result)[:128]) ret = t.result if t.nWaiting == 0: logger('No more consumers, invalidating cached result', repr(t.result)[:128]) del t.result else: ret = boundMethod(*args) if t.nWaiting > 0: t.result = ret t.resultTime = blue.os.GetWallclockTime() logger('Sharing result for call', key, 'at', t.resultTime, 'for', t.nWaiting, 'waiting threads:', repr(t.result)[:128]) return ret