def join(self, ctx, callback=None): prbID = ctx.getID() if not AutoInvitesNotifier.hasInvite(prbID): SystemMessages.pushI18nMessage( I18N_SYSTEM_MESSAGES.ARENA_START_ERRORS_JOIN_NOT_FOUND, type=SystemMessages.SM_TYPE.Error) if callback: callback(False) return peripheryID = AutoInvitesNotifier.getInvite(prbID).peripheryID if self.lobbyContext.isAnotherPeriphery(peripheryID): hostName = self.lobbyContext.getPeripheryName(peripheryID) if hostName: message = i18n.makeString( I18N_SYSTEM_MESSAGES. ARENA_START_ERRORS_JOIN_WRONG_PERIPHERY_KNOWN, hostName) else: message = i18n.makeString( I18N_SYSTEM_MESSAGES. ARENA_START_ERRORS_JOIN_WRONG_PERIPHERY_UNKNOWN) SystemMessages.pushMessage(message, type=SystemMessages.SM_TYPE.Warning) if callback: callback(False) else: super(BattleSessionEntryPoint, self).join(ctx, callback)
def init(self): if self.__invitesManager is None: self.__invitesManager = InvitesManager(self) self.__invitesManager.init() if self.__autoNotifier is None: self.__autoNotifier = AutoInvitesNotifier(self) if self.__peripheriesHandler is None: self.__peripheriesHandler = _PrbPeripheriesHandler(self) if self.__storage is None: self.__storage = PrbStorageDecorator() self.__storage.init() return
def init(self): """ Loader initializations work: subscribe to required events. Routine must invoke in BWPersonality module. """ if self.__invitesManager is None: self.__invitesManager = InvitesManager(self) self.__invitesManager.init() if self.__autoNotifier is None: self.__autoNotifier = AutoInvitesNotifier(self) if self.__peripheriesHandler is None: self.__peripheriesHandler = _PrbPeripheriesHandler(self) if self.__storage is None: self.__storage = PrbStorageDecorator() self.__storage.init() return
class _PrbControlLoader(object): """ Loader for for next entities: - prebattle dispatcher. When player login to server, it creates prebattle dispatcher. And when GUI says isEnabled, it starts prebattle dispatcher. When player come to battle or login page, it removes prebattle dispatcher; - invites manager for invitation to prebattle; - notifier of auto invites. """ __slots__ = ('__prbDispatcher', '__invitesManager', '__autoNotifier', '__peripheriesHandler', '__storage', '__isEnabled') def __init__(self): """ Constructor for default initialization. """ super(_PrbControlLoader, self).__init__() self.__prbDispatcher = None self.__invitesManager = None self.__autoNotifier = None self.__peripheriesHandler = None self.__storage = None self.__isEnabled = False return def init(self): """ Loader initializations work: subscribe to required events. Routine must invoke in BWPersonality module. """ if self.__invitesManager is None: self.__invitesManager = InvitesManager(self) self.__invitesManager.init() if self.__autoNotifier is None: self.__autoNotifier = AutoInvitesNotifier(self) if self.__peripheriesHandler is None: self.__peripheriesHandler = _PrbPeripheriesHandler(self) if self.__storage is None: self.__storage = PrbStorageDecorator() self.__storage.init() g_playerEvents.onBootcampShowGUI += self.pe_onBootcampShowGUI return def fini(self): """ Loader finalizes work: unsubscribe from events, removes prebattle dispatcher. Routine must invoke in BWPersonality module. """ self.__removeDispatcher() if self.__invitesManager is not None: self.__invitesManager.fini() self.__invitesManager = None if self.__autoNotifier is not None: self.__autoNotifier.fini() self.__autoNotifier = None if self.__peripheriesHandler is not None: self.__peripheriesHandler.fini() self.__peripheriesHandler = None if self.__storage is not None: self.__storage.fini() self.__storage = None g_playerEvents.onBootcampShowGUI -= self.pe_onBootcampShowGUI return def getDispatcher(self): """ Gets prebattle dispatcher. Returns: prebattle dispatcher or None. Returns None when player come to battle or login page. """ return self.__prbDispatcher def getInvitesManager(self): """ Gets manager for prebattle invites. Returns: invites manager """ return self.__invitesManager def getAutoInvitesNotifier(self): """ Gets notifier for auto invites. Returns: auto notifier """ return self.__autoNotifier def getPeripheriesHandler(self): """ Gets notifier for auto invites. Returns: peripheries handler """ return self.__peripheriesHandler def getStorage(self): """ Gets storage decorator to hold local client settings. Returns: storage """ return self.__storage def isEnabled(self): """ Is dispatcher enabled. Returns: obvious one - is dispatcher enabled. """ return self.__isEnabled def setEnabled(self, enabled): """ Sets dispatcher enabled. Args: enabled: new state """ if self.__isEnabled ^ enabled: self.__isEnabled = enabled if self.__isEnabled and self.__prbDispatcher is not None: self.__doStart() return def onAccountShowGUI(self, ctx): """ Listener for player event - show gui. Initializes dispatcher if needed. Args: ctx: gui init context """ if self.__prbDispatcher is None: self.__prbDispatcher = _PreBattleDispatcher() if self.__isEnabled: self.__doStart() return def onAccountBecomeNonPlayer(self): """ Listener for player event - on become non player. Deletes dispatcher. """ self.__isEnabled = False self.__removeDispatcher() def onAvatarBecomePlayer(self): """ Listener for player event - on become avatar. Deletes dispatcher. """ self.__isEnabled = False self.__removeDispatcher() self.__invitesManager.onAvatarBecomePlayer() self.__storage.onAvatarBecomePlayer() def onDisconnected(self): """ Listener for connection manager event - on disconnected. Deletes dispatcher and clears all related data. """ self.__isEnabled = False self.__removeDispatcher() self.__autoNotifier.stop() if self.__invitesManager is not None: self.__invitesManager.clear() if self.__autoNotifier is not None: self.__autoNotifier.stop() if self.__storage is not None: self.__storage.clear() return def __doStart(self): """ Do all the job related to loader statr. """ self.__storage.swap() self.__prbDispatcher.start() self.__invitesManager.start() self.__autoNotifier.start() self.__peripheriesHandler.activate() def __removeDispatcher(self): """ Removes prebattle dispatcher. """ if self.__prbDispatcher is not None: self.__prbDispatcher.stop() self.__prbDispatcher = None return def pe_onBootcampShowGUI(self, prbEnable): self.onAccountShowGUI({}) if prbEnable: self.setEnabled(True)
class _PrbControlLoader(IPrbControlLoader): __slots__ = ('__prbDispatcher', '__invitesManager', '__autoNotifier', '__peripheriesHandler', '__storage', '__isEnabled') def __init__(self): super(_PrbControlLoader, self).__init__() self.__prbDispatcher = None self.__invitesManager = None self.__autoNotifier = None self.__peripheriesHandler = None self.__storage = None self.__isEnabled = False return def init(self): if self.__invitesManager is None: self.__invitesManager = InvitesManager(self) self.__invitesManager.init() if self.__autoNotifier is None: self.__autoNotifier = AutoInvitesNotifier(self) if self.__peripheriesHandler is None: self.__peripheriesHandler = _PrbPeripheriesHandler(self) if self.__storage is None: self.__storage = PrbStorageDecorator() self.__storage.init() return def fini(self): self.__removeDispatcher() if self.__invitesManager is not None: self.__invitesManager.fini() self.__invitesManager = None if self.__autoNotifier is not None: self.__autoNotifier.fini() self.__autoNotifier = None if self.__peripheriesHandler is not None: self.__peripheriesHandler.fini() self.__peripheriesHandler = None if self.__storage is not None: self.__storage.fini() self.__storage = None return def createBattleDispatcher(self): if self.__prbDispatcher is None: self.__prbDispatcher = _PreBattleDispatcher() if self.__isEnabled: self.__doStart() return def getDispatcher(self): return self.__prbDispatcher def getInvitesManager(self): return self.__invitesManager def getAutoInvitesNotifier(self): return self.__autoNotifier def getPeripheriesHandler(self): return self.__peripheriesHandler def getStorage(self): return self.__storage def isEnabled(self): return self.__isEnabled def setEnabled(self, enabled): if self.__isEnabled ^ enabled: self.__isEnabled = enabled if self.__isEnabled and self.__prbDispatcher is not None: self.__doStart() return def onAccountShowGUI(self, ctx): self.createBattleDispatcher() def onAccountBecomeNonPlayer(self): self.__isEnabled = False self.__removeDispatcher() def onAvatarBecomePlayer(self): self.__isEnabled = False self.__removeDispatcher() self.__invitesManager.onAvatarBecomePlayer() self.__storage.onAvatarBecomePlayer() def onDisconnected(self): self.__isEnabled = False self.__removeDispatcher() self.__autoNotifier.stop() if self.__invitesManager is not None: self.__invitesManager.clear() if self.__autoNotifier is not None: self.__autoNotifier.stop() if self.__storage is not None: self.__storage.clear() return def __doStart(self): self.__storage.swap() self.__prbDispatcher.start() self.__invitesManager.start() self.__autoNotifier.start() self.__peripheriesHandler.activate() def __removeDispatcher(self): if self.__prbDispatcher is not None: self.__prbDispatcher.stop() self.__prbDispatcher = None return