Esempio n. 1
0
def handle_new_socket(path, event):
    dirname, filename = os.path.split(path)
    if ":" not in filename or not filename.endswith(".sock"): return
    username = filename[:filename.index(":")]
    abspath = os.path.abspath(path)
    if event == DirectoryWatcher.CREATE:
        if abspath in processes: return # Created by us

        # Find a game_info with this socket path
        game_info = find_game_info(dirname, filename)

        # Create process handler
        process = CrawlProcessHandler(game_info, username,
                                      unowned_process_logger)
        processes[abspath] = process
        process.connect(abspath)
        process.logger.info("Found a %s game.", game_info["id"])

        # Notify lobbys
        if config.dgl_mode:
            update_all_lobbys(process)
    elif event == DirectoryWatcher.DELETE:
        if abspath not in processes: return
        process = processes[abspath]
        if process.process: return # Handled by us, will be removed later
        process.handle_process_end()
        process.logger.info("Game ended.")
        remove_in_lobbys(process)
        del processes[abspath]
Esempio n. 2
0
 def set_where_info(self, newwhere):
     interesting = False
     for key in CrawlProcessHandlerBase.interesting_info:
         if self.where.get(key) != newwhere.get(key):
             interesting = True
     self.where = newwhere
     if interesting:
         update_all_lobbys(self)
Esempio n. 3
0
    def set_where_info(self, newwhere):
        # milestone doesn't count as "interesting" but the field is directly
        # handled when sending lobby info by looking at last_milestone
        milestone = bool(newwhere.get("milestone"))
        interesting = (milestone or newwhere.get("status") == "chargen"
                       or any([
                           self.where.get(key) != newwhere.get(key)
                           for key in CrawlProcessHandlerBase.interesting_info
                       ]))

        # ignore milestone sync messages for where purposes
        if newwhere.get("status") != "milestone_only":
            self.where = newwhere
        if milestone:
            self.last_milestone = newwhere
        if interesting:
            update_all_lobbys(self)
Esempio n. 4
0
    def update_watcher_description(self):
        try:
            player_url_template = config.player_url
        except:
            player_url_template = None

        def wrap_name(watcher, is_player=False):
            if is_player:
                class_type = 'player'
            else:
                class_type = 'watcher'
            n = watcher
            if (watcher in self.muted):
                n += " (muted)"
            if player_url_template is None:
                return "<span class='{0}'>{1}</span>".format(class_type, n)
            player_url = player_url_template.replace("%s", watcher.lower())
            username = "******".format(
                player_url, class_type, n)
            return username

        player_name, watchers = self.get_watchers(True)

        watcher_names = []
        if player_name is not None:
            watcher_names.append(wrap_name(player_name, True))
        watcher_names += [wrap_name(w) for w in watchers]

        anon_count = len(self.get_anon())
        s = ", ".join(watcher_names)
        if len(watcher_names) > 0 and anon_count > 0:
            s = s + " and %i Anon" % anon_count
        elif anon_count > 0:
            s = "%i Anon" % anon_count
        self.send_to_all("update_spectators",
                         count=self.watcher_count(),
                         names=s)

        if config.dgl_mode:
            update_all_lobbys(self)
Esempio n. 5
0
 def check_idle(self):
     if self.is_idle() != self._was_idle:
         self._was_idle = self.is_idle()
         if config.dgl_mode:
             update_all_lobbys(self)
Esempio n. 6
0
    def log_milestone(self, milestone):
        # Use the updated where info in the milestone
        self.where = milestone

        self.last_milestone = milestone
        update_all_lobbys(self)