コード例 #1
0
    def start(self, HOST, PORT):
        with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as serverSocket:
            serverSocket.bind((HOST, PORT))
            serverSocket.setblocking(False)
            serverSocket.listen()

            self._multiplexer.register(serverSocket, selectors.EVENT_READ,
                                       self)

            LogCat.log(f"MUTE server start listening at {HOST}:{PORT}")
            print(f"MUTE server start listening at {HOST}:{PORT}")

            while True:
                events = self._multiplexer.select(timeout=None)

                for io, mask in events:
                    io.data.on_socket(io.fileobj, mask)

                for guest in self._guests:
                    for msg in guest.msg_in:
                        print(f"{guest.user}: {msg}")

                        if msg.type in self._handlers:
                            self._handlers[msg.type](guest, **msg.kwargs)

                    guest.msg_in = []
コード例 #2
0
    def value(self, entity: str) -> float:
        try:
            value = self._cache[entity]
            LogCat.log(f'ValueComponent.value entity: {entity} value: {value}')
        except KeyError:
            LogCat.log(f'ValueComponent.value entity: {entity} keyError')
            value = 0

        return value
コード例 #3
0
    def _on_sign_in(self, guest, **kwargs):
        LogCat.log(f"id: {kwargs['user_id']} passwd {kwargs['passwd']}")
        print(f"id: {kwargs['user_id']} passwd {kwargs['passwd']}")

        guest.set_user(kwargs["user_id"])

        guest.send_msg(
            Message(Message.WELCOME,
                    who="MUTE",
                    guest=kwargs["user_id"],
                    text="welcome"))
コード例 #4
0
    def _check_input(self) -> None:
        try:
            e = self._window.get_wch()

            if e == 'q':
                Event.trigger(Event(Event.EXIT, self))
            elif e == curses.KEY_MOUSE:
                _, x, y, _, _ = curses.getmouse()

                Event.trigger(
                    Event(Event.CLICK, self._window_manager, x=x, y=y))
            elif type(e) == str:
                LogCat.log(f'keypressed: {e}')
                #        elif e > 0:
                Event.trigger(
                    Event(Event.KEY_PRESSED, self._window_manager.focus,
                          key=e))
            else:
                Event.trigger(Event(e, self._window_manager.focus))

        except curses.error:
            pass

        self._in_stream()
コード例 #5
0
 def _on_death(self, e: Event, entity: str = '') -> None:
     LogCat.log(f' ----------- ogt death event -=-----')
コード例 #6
0
 def move_cursor(self, x: int, y: int) -> None:
     self._win.move(y, x)
     y, x = self._win.getyx()
     LogCat.log(f'   move_cursor: x- {x} y- {y}')
コード例 #7
0
    def _on_msg_chat(self, from_who, who, text):
        LogCat.log(f"_on_msg_chat: from- {from_who} who- {who} text- {text}")

        for guest in self._guests:
            guest.send_msg(Message(Message.CHAT, who=who, text=text))