Beispiel #1
0
    def __init__(self, service, plugins):
        # Register a function to listen to the game events. 
        self.service = service
        self.service.listen().addCallback(self.self_notify)

        # Storage for our messages
        self.messages = []

        # Implement the path conventions
        self.confdir = os.path.join(self.service.settings['plugins-confdir'], self.name())
        self.libdir = os.path.join(self.service.settings['plugins-libdir'], self.name())
        self.logdir = os.path.join(self.service.settings['plugins-logdir'], self.name())

        # Initialize logdir, and make sure we have write permissions.
        # If not, turn off logging.
        self.logging = True
        if not os.path.exists(self.logdir):
            try:
                os.makedirs(self.logdir)
            except OSError:
                self.logging = False
        elif not os.access(self.logdir, os.W_OK):
            self.logging = False

        # Initialize the pollable using the recommended timeout.
        Pollable.__init__(self, self.service.settings.get('poll-timeout', 30))
Beispiel #2
0
    def __init__(self, service, plugins):
        # Storage for tables
        self.tables = []

        # Store the relationship between tables and games
        self.game2table = {}

        # Depends on the activity plugin (to know when players are online)
        for plugin in plugins:
            if plugin.name() == 'activity':
                self.activity_plugin = plugin
        assert self.activity_plugin

        # Register a function to know when players go online/offline
        self.activity_plugin.listen().addCallback(self.on_activity_notification)

        # Register a function to listen to the game events.
        self.service = service
        self.service.listen().addCallback(self.on_service_notification)

        # Implement the path conventions
        self.confdir = os.path.join(self.service.settings['plugins-confdir'], self.name())
        self.libdir = os.path.join(self.service.settings['plugins-libdir'], self.name())

        # Initialize the pollable using the recommended timeout.
        Pollable.__init__(self, self.service.settings.get('poll-timeout', 30))
Beispiel #3
0
 def __init__(self, service, plugins):
     # 
     # The example depends on another plugin and checks
     # that it has been loaded before it. It relies on the
     # name() method to identify the plugin.
     #
     for plugin in plugins:
         if plugin.name() == 'another':
             self.another = plugin
     assert self.another
     #
     # Register a function to listen to the game events. 
     # check the documentation of the self_notify method.
     #
     self.service = service
     self.service.listen().addCallback(self.accept)
     #
     # Implement the path conventions as described above ( look for plugins-confdir )
     #
     self.confdir = os.path.join(self.service.settings['plugins-confdir'], self.name())
     self.libdir = os.path.join(self.service.settings['plugins-libdir'], self.name())
     #
     # initialize the pollable using the service parameters. There is
     # no reason to improve or change these parameters.
     #
     Pollable.__init__(self, self.service.settings.get('poll-timeout', 30))
Beispiel #4
0
    def __init__(self, service, plugins):
        # Register a function to listen to the game events.
        self.service = service
        self.service.listen().addCallback(self.self_notify)

        # Storage for our messages
        self.messages = []

        # Implement the path conventions
        self.confdir = os.path.join(self.service.settings['plugins-confdir'],
                                    self.name())
        self.libdir = os.path.join(self.service.settings['plugins-libdir'],
                                   self.name())
        self.logdir = os.path.join(self.service.settings['plugins-logdir'],
                                   self.name())

        # Initialize logdir, and make sure we have write permissions.
        # If not, turn off logging.
        self.logging = True
        if not os.path.exists(self.logdir):
            try:
                os.makedirs(self.logdir)
            except OSError:
                self.logging = False
        elif not os.access(self.logdir, os.W_OK):
            self.logging = False

        # Initialize the pollable using the recommended timeout.
        Pollable.__init__(self, self.service.settings.get('poll-timeout', 30))
Beispiel #5
0
 def __init__(self, service, plugins):
     #
     # The example depends on another plugin and checks
     # that it has been loaded before it. It relies on the
     # name() method to identify the plugin.
     #
     for plugin in plugins:
         if plugin.name() == 'another':
             self.another = plugin
     assert self.another
     #
     # Register a function to listen to the game events.
     # check the documentation of the self_notify method.
     #
     self.service = service
     self.service.listen().addCallback(self.accept)
     #
     # Implement the path conventions as described above ( look for plugins-confdir )
     #
     self.confdir = os.path.join(self.service.settings['plugins-confdir'],
                                 self.name())
     self.libdir = os.path.join(self.service.settings['plugins-libdir'],
                                self.name())
     #
     # initialize the pollable using the service parameters. There is
     # no reason to improve or change these parameters.
     #
     Pollable.__init__(self, self.service.settings.get('poll-timeout', 30))
Beispiel #6
0
    def __init__(self, service, plugins):
        # Register a function to listen to the game events. 
        self.service = service
        self.service.listen().addCallback(self.self_notify)

        # Implement the path conventions
        self.confdir = os.path.join(self.service.settings['plugins-confdir'], self.name())
        self.libdir = os.path.join(self.service.settings['plugins-libdir'], self.name())

        # Load bots logic
        brain = NLWordMatcherBrain(self)

        # Load configuration and instantiate bots
        self.settings = objectify.parse(open(os.path.join(self.confdir, 'bot.xml'))).getroot()
        self.delays = {}
        self.bots = []
        for node in self.settings.iterchildren():
            if node.tag == "delay":
                self.delays[node.get('type')] = {'base': int(node.get('base')),
                                                 'random': int(node.get('random'))}
            elif node.tag == "botinstance":
                bot = Bot(self, brain, int(node.get('player_id')))
                self.bots.append(bot)

        # Store enable_join per game.
        self.enable_join = {}

        # Initialize the pollable using the recommended timeout.
        Pollable.__init__(self, self.service.settings.get('poll-timeout', 30))
Beispiel #7
0
 def __init__(self, service, id=None):
     self.service = service
     self.settings = service.settings
     self.id = id
     self.owner_id = None
     self.players = []
     self.invited = []
     Pollable.__init__(self, self.settings.get('poll-timeout', 30))
Beispiel #8
0
    def __init__(self, table_plugin):
        self.table_plugin = table_plugin
        self.activity_plugin = self.table_plugin.activity_plugin
        self.service = self.table_plugin.service
        self.games_ids = []
        self.last_owners_ids = []
        self.next_owner_id = None

        Pollable.__init__(self, self.service.settings.get("poll - timeout", 30))
Beispiel #9
0
    def __init__(self, service, plugins):
        self.service = service
        self.observers = []
        self.online_players = {}

        self.service.listen().addCallback(self.on_service_notification)

        # Implement the path conventions
        self.confdir = os.path.join(self.service.settings['plugins-confdir'], self.name())
        self.libdir = os.path.join(self.service.settings['plugins-libdir'], self.name())

        # Initialize the pollable using the recommended timeout.
        Pollable.__init__(self, self.service.settings.get('poll-timeout', 30))
Beispiel #10
0
    def __init__(self, service, plugins):
        self.service = service
        self.observers = []
        self.online_players = {}

        self.service.listen().addCallback(self.on_service_notification)

        # Implement the path conventions
        self.confdir = os.path.join(self.service.settings['plugins-confdir'],
                                    self.name())
        self.libdir = os.path.join(self.service.settings['plugins-libdir'],
                                   self.name())

        # Initialize the pollable using the recommended timeout.
        Pollable.__init__(self, self.service.settings.get('poll-timeout', 30))
Beispiel #11
0
    def __init__(self, table_plugin):
        self.table_plugin = table_plugin
        self.activity_plugin = self.table_plugin.activity_plugin
        self.service = self.table_plugin.service
        # A list of game IDs of all games ever played in this table,
        # in chronological order (oldest game comes first in the list,
        # while the last game in the list is the most recent, "current" game
        # of the table.
        self.games_ids = []
        # A list of new games that were created as next_games of the table, but didn't
        # yet reach the 'invitation' state. The first pending game that reaches
        # 'invitation' state is promoted to be the next_game, while any other
        # pending game is spun off into its own, brand new table.
        self.pending_games = []
        # A list of unique IDs of all users that were chosen to be the next_owner
        # at some point (even if they failed to create the next game),
        # in reverse chronological order (owner that was the most recent next_owner
        # comes first in the list). Keeping track of them for the sole purpose of
        # being able to cycle between next owners when the time to update next_owner_id comes.
        self.chosen_owners_ids = []
        # The ID of the player who is currently chosen as the next owner.
        self.next_owner_id = None
        # Timer that keeps track of how long it takes the next_owner to create the next
        # game and make it "playable" (move it into invitation state). If the next owner
        # doesn't manage to do that in under NEXT_GAME_TIMEOUT seconds, another next_owner
        # is chosen instead.
        self.next_game_timer = None
        # When current game is completed, self.next_game_promoted is set to False until one
        # of the pending games that get created is promoted to be the new current game.
        self.next_game_promoted = None
        # If self.next_owner_id is currently (asynchonously) being updated,
        # self.next_owner_deferred is set to a deferred that will fire once the update_next_owner_id
        # operation completes. Set to None when no next_owner update is in progress.
        self._next_owner_deferred = None
        # update_next_owner_id is asynchronous because its waiting for results of get_active_players
        # operation. We store this as an attribute of the table, so that we are able to cancel the
        # deferred attached to the get_active_players result and start a new one in case a new
        # update_next_owner_id request is made before the one already in progress completes.
        # This is an implementation detail.
        self._active_players_deferred = None

        Pollable.__init__(self, self.service.settings.get('poll - timeout', 30))
Beispiel #12
0
 def __init__(self):
     Pollable.__init__(self, 200000000000)