Beispiel #1
0
    def handleData(self, data):
        """
    Handles incoming data from the mud.  We wrap it in a MudEvent
    and toss it on the queue.

    @param data: the incoming data from the mud
    @type  data: bytes
    """
        global BELL

        # handle the bell
        count = data.count(BELL)
        for i in range(count):
            event.SpamEvent(hookname="bell_hook",
                            argmap={
                                "session": self._session
                            }).enqueue()
        data = data.replace(BELL, b"")

        # handle telnet option stuff
        if IAC in data:
            data = self.handleNego(data)

        if not self._config.get("promptdetection") or data.endswith(b"\n"):
            event.MudEvent(self._session,
                           data.decode(settings.REMOTE_ENCODING)).enqueue()
        else:
            event.SpamEvent(hookname="prompt_hook",
                            argmap={
                                "session": self._session,
                                "prompt": data.decode(settings.REMOTE_ENCODING)
                            }).enqueue()
Beispiel #2
0
  def runtimer(self):
    """
    This timer thread sleeps for a second, then calls everything
    in the queue with the current tick.
    """
    from time import time
    
    self._current_tick = 0
    wakeup_time = current_time = time()

    import threading
    ev = threading.Event()
    exported.hook_register("shutdown_hook", lambda *_: ev.set())

    while not ev.isSet():
      try:
        tout = wakeup_time - current_time
        if tout > 0:
          ev.wait(timeout = tout)
          current_time = time()
        elif tout < -10:
          # we are late too much; drop 10 ticks
          wakeup_time += 10
          continue
        event.SpamEvent(hookname="timer_hook", 
                        argmap={"tick": self._current_tick}
                       ).enqueue()
        self._current_tick += 1
        wakeup_time += 1
      except KeyboardInterrupt:
        return
      except SystemExit:
        return
      except:
        exported.write_traceback("ticker: ticker hiccupped.")
Beispiel #3
0
    def runtimer(self):
        """
    This timer thread sleeps for a second, then calls everything
    in the queue with the current tick.

    Note: This will almost always be slightly behind and will
    get worse as there are more things that get executed each
    tick.
    """
        import time, event

        self._current_tick = 0
        while not self._shutdownflag:
            try:
                time.sleep(1)
                event.SpamEvent(hookname="timer_hook",
                                argmap={
                                    "tick": self._current_tick
                                }).enqueue()
                self._current_tick += 1
            except KeyboardInterrupt:
                return
            except SystemExit:
                return
            except:
                exported.write_traceback("ticker: ticker hiccupped.")