Exemple #1
0
 def create_client(self, addr):
     '''
     Create a client given it's address
     '''
     Console.print(f"[UDP] |{addr[0]}| Connected.")
     client = Client(addr)
     self.add_client(client)
Exemple #2
0
 def start(self):
     '''
     Start a infinite loop in another thread to listen to the server.
     '''
     self.running = True
     self._thread = threading.Thread(target=self.run)
     self._thread.start()
     Console.print("[UDP] Started client's thread.")
Exemple #3
0
 def call(traceback, warning=False):
     
     if warning:
         call_type = '[WARNING]'
     else:
         call_type = '[ERROR]'
     
     Console.print('[UDP]', call_type, traceback)
Exemple #4
0
    def call(traceback, id=None, warning=False):

        if warning:
            call_type = "[WARNING]"
        else:
            call_type = "[ERROR]"

        if id == None:
            Console.print("[TCP]", call_type, traceback)
        else:
            Console.print(f"[TCP] |{id}| {call_type} {traceback}")
Exemple #5
0
 def call(traceback, warning=False):
     '''
     Display a message in the terminal.  
     In the format: `"[TCP] [call type] traceback"`
     '''
     if warning:
         call_type = "WARNING"
     else:
         call_type = "ERROR"
     
     Console.print(f"[TCP] [{call_type}] {traceback}")
Exemple #6
0
    def run(self):
        '''
        Loop that wait for connections.  
        Execute on_connection method.  
        To end execution, set running attribute to False.
        '''

        while self._running:

            conn, addr = self._socket.accept()

            Console.print(f'[TCP] |{addr[0]}| Connected.')

            self.on_connection(conn, addr)
Exemple #7
0
    def display_msg(self, msg: Message):
        '''
        Display the Message to the terminal
        in a pretty printing way.
        '''
        if type(msg.content) is str and '\n' in msg.content:
            content = ''
        elif type(msg.content) is np.ndarray:
            content = ''

        # player stats
        elif msg.identifier == 'rpd':
            content = msg.content['username']

        else:
            content = str(msg.content)

        Console.print('[TCP] {' + msg.identifier + '} ' + content)
Exemple #8
0
    def print(self, string, *strings, warning=False):
        '''
        Print a string to the terminal.  
        '''

        # compose string
        for _str in strings:
            string += ' ' + _str

        if self.logged:
            id = self.username
        else:
            id = self.ip

        if warning:
            Console.print(f'[TCP] |{id}| [WARNING] {string}')
        else:
            Console.print(f'[TCP] |{id}| {string}')