Esempio n. 1
0
    def run(self):
        # Initiate the connection to the server
        self.connection.connect((self.host, self.port))

        self.connected = True

        self.msg_parser = MessageParser()
        self.msg_receiver = MessageReceiver(self, self.connection)
        self.msg_receiver.start()

        while self.connected:
            inp = raw_input("command <content>:\n").split()
            command = inp[0]
            if command not in legal_requests:
                print("please type a legal command")
                continue

            content = None
            if command == 'login' or command == 'msg':
                if len(inp) <= 1:
                    print("please type <content>")
                    continue
                content = " ".join(inp[1:])

            data = {
                    'request': command,
                    'content': content}

            self.send_payload(json.dumps(data))

        self.msg_receiver.join()
Esempio n. 2
0
    def run(self):
        # Initiate the connection to the server
        self.connection.connect((self.host, self.server_port))
        receiver = MessageReceiver(self, self.connection)
        receiver.start()

        while True:
            command = input("> ")
            if len(command.split(" ")) > 1:  # It's a command with content
                command = command.split(" ")

                if command[0] == "login":
                    raw_message = {'request': 'login', 'content': command[1]}

                elif command[0] == "msg":
                    messageString = ""
                    for i in command[1:]:
                        messageString += i + ' '
                    messageString = messageString[:-1]
                    raw_message = {'request': 'msg', 'content': messageString}
                else:
                    print("Unknown command! Please try again.")
                    continue
            else:  # It's a command without content
                if command == 'logout' or command == 'help' or command == 'history' or command == 'names':
                    raw_message = {'request': command, 'content': None}
                else:
                    print("Unknown command! Please try again.")
                    continue
            JSON_message = json.dumps(raw_message)
            self.send_payload(JSON_message.encode("utf-8"))
Esempio n. 3
0
    def run(self):
        # Initiate the connection to the server
        self.connection.connect((self.host, self.server_port))
        self.thread = MessageReceiver(self, self.connection)
        self.thread.start()

        while True:
            text = input().split(' ', 1)
            if (len(text) > 0 and len(text) < 3):
                if (len(text) == 1):
                    text.append('')
                if (text[0] == 'login'):
                    payload = json.dumps({
                        'request': 'login',
                        'content': text[1]
                    })
                    self.send_payload(payload)
                elif (text[0] == 'logout'):
                    self.disconnect()
                elif (text[0] == 'names'):
                    payload = json.dumps({'request': 'names'})
                    self.send_payload(payload)
                elif (text[0] == 'help'):
                    payload = json.dumps({'request': 'help'})
                    self.send_payload(payload)
                elif (text[0] == 'msg'):
                    payload = json.dumps({
                        'request': 'msg',
                        'content': text[1]
                    })
                    self.send_payload(payload)
                else:
                    print('Unknown command, type "help" for help')
            else:
                print('Unknown command, type "help" for help')
Esempio n. 4
0
    def run(self):
        try:
            # Initiate the connection to the server
            self.connection.connect((self.host, self.server_port))
            messageReceiver = MessageReceiver(self, self.connection)
            messageReceiver.start()
        except socket.error as e:
            sys.exit("Connection to server refused.")

        while (not self.connection._closed):
            if self.state == State.LOGIN:
                print("Username:"******"Disconnected from server")
Esempio n. 5
0
    def run(self):
        # Initiate the connection to the server
        self.connection.connect((self.host, self.server_port))
        self.receiver = MessageReceiver(self, self.connection)
        self.MessagePars = MessageParser()

        while True:
            input_ = raw_input().split(' ')
            if len(input_) != 0:
                if (input_[0] == "login"):
                    self.send_payload({
                        'request': 'login',
                        'content': input_[1]
                    })
                elif (input_[0] == "logout"):
                    self.send_payload({
                        'request': 'logout',
                    })
                elif (input_[0] == "msg"):
                    self.send_payload({'request': 'msg', 'content': input_[1]})
                elif (input_[0] == "names"):
                    self.send_payload({'request': 'names'})
                elif (input_[0] == "help"):
                    self.send_payload({'request': 'help'})
                else:
                    print "Error, type 'help'"
Esempio n. 6
0
    def run(self):

        # Initiate the connection to the server
        self.connection.connect((self.host, self.server_port))



        self.message_receiver = MessageReceiver(self, self.connection)
        self.message_receiver.start()

        print(bcolors.HEADER + bcolors.BOLD + ' Urban Robot Advanced Chat System')
        print(' --------------------------------' + bcolors.ENDC)
        print('You are now connected')
        self.help()

        while True:
            time.sleep(0.03)

            request = input('>>> ').lower().lstrip().rstrip()
            request_lower = request.lower()

            if re.search('^login((  *[^\s]+)|((\s)*(?!.)))', request_lower):
                self.login(request[6:].lstrip())
            elif request_lower == 'logout':
                self.logout()
            elif re.search('^msg((  *[^\s]+)|((\s)*(?!.)))', request_lower):
                self.msg(request[4:].lstrip())
            elif request_lower == 'names':
                self.names()
            elif request_lower == 'help':
                self.help()
            else:
                # TODO : Do something here
                print(bcolors.FAIL + '\tInvalid command!' + bcolors.ENDC)
                self.help()
Esempio n. 7
0
    def run(self):
        # Initiate the connection to the server
        self.connection.connect((self.host, self.server_port))
        self.MessageReceiver = MessageReceiver(self, self.connection)
        self.MessageReceiver.start()

        while not self.disconnected:
            # Lager tom pakke som skal sendes til server:
            self.data = {'request': None, 'content': None}

            # Henter request fra bruker:
            self.request = input(" > ")
            if (self.request == ""):
                continue

            elif (self.request == "login"):
                self.data['request'] = self.request
                self.data['content'] = input("username: "******"names", "logout", "help"]):
                self.data['request'] = self.request

            else:  #Bare vanlig msg:
                self.data['request'] = "msg"
                self.data['content'] = self.request

            # Gjør om pakken til JSON:
            self.data_json = json.dumps(self.data)
            # Sender pakken til serveren:
            self.connection.send(self.data_json.encode())
            # Sleep så man rekker å disconnecte
            time.sleep(0.5)
Esempio n. 8
0
    def __init__(self, host, server_port):
        """
        This method is run when creating a new Client object
        """

        # Set up the socket connection to the server
        self.connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.host = host
        self.server_port = server_port

        self.run()

        receiver = MessageReceiver(self, self.connection)
        receiver.start()

        while alive:
            msg = raw_input()

            msg = msg.split()

            request = msg[0]
            if len(msg) == 2:
                content = msg[1]
            else:
                content = None

            payload = json.dumps({'request': request, 'content': content})

            self.send_payload(payload)

        receiver.join()
        self.disconnect()
Esempio n. 9
0
    def run(self):
        # Initiate the connection to the server
        self.connection.connect((self.host, self.server_port))
        while True:
            userInput = raw_input("")
            liste = []
            if " " in userInput:
                content = ""
                liste = userInput.split(" ")
                request = liste[0]
                for i in range(1, len(liste)):
                    content += liste[i]
                    if (i != len(liste) - 1):
                        content += " "
            else:
                request = userInput
                content = None

            self.send_payload(request, content)
            if request == "logout":
                self.disconnect()

            reciever = MessageReceiver(self, self.connection)
            reciever.daemon = True
            reciever.start()
Esempio n. 10
0
    def run(self):
        # Initiate the connection to the server
        s_thread = MessageReceiver(self, self.connection)
        s_thread.daemon = True
        s_thread.start()

        while self.active:
            self.get_input()
Esempio n. 11
0
 def run(self):
     # Initiate the connection to the server
     self.connection.connect((self.host, self.server_port))
     # print "[*] Kobling etablert"
     listener = MessageReceiver(self, self.connection)
     listener.daemon = True
     listener.start()
     # print "[*] Lytter startet."
     self.handle_input()
Esempio n. 12
0
    def __init__(self, host, server_port):
        """
        This method is run when creating a new Client object
        """

        # Set up the socket connection to the server
        self.connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.host = host
        self.server_port = server_port
        self.messageReceiver = MessageReceiver(self, self.connection)
        self.run()
Esempio n. 13
0
 def run(self):
     # Initiate the connection to the server
     self.connection.connect((self.host, self.server_port))
     self.thread = MessageReceiver(self, self.connection)
     self.thread.start()
     while True:
         txt = input().split(' ', 1)  #Split on first space
         if (len(txt) > 0
                 and len(txt) < 3):  # Dont accept more than 2 arguments
             if (len(txt) == 1):
                 txt.append('')  #What if short input?
             if (txt[0] == 'login'):
                 payload = json.dumps({
                     'request': 'login',
                     'content': txt[1]
                 })
                 self.send_payload(payload)
             elif (txt[0] == 'msg'):
                 payload = json.dumps({'request': 'msg', 'content': txt[1]})
                 self.send_payload(payload)
             elif (txt[0] == 'names'):
                 payload = json.dumps({
                     'request': 'names',
                     'content': txt[1]
                 })
                 self.send_payload(payload)
             elif (txt[0] == 'logout'):
                 payload = json.dumps({
                     'request': 'logout',
                     'content': txt[1]
                 })
                 self.send_payload(payload)
             elif (txt[0] == 'help'):
                 payload = json.dumps({
                     'request': 'help',
                     'content': txt[1]
                 })
                 self.send_payload(payload)
             elif (txt[0] == 'history'):
                 payload = json.dumps({
                     'request': 'history',
                     'content': txt[1]
                 })
                 self.send_payload(payload)
             else:
                 print(
                     'Oh oh! No such command, type "help" to see all possible commands'
                 )
         else:
             print(
                 'Oh oh! No such command, type "help" to see all possible commands'
             )
Esempio n. 14
0
    def run(self):
        # Initiate the connection to the server
        self.connection.connect((self.host, self.server_port))
        self.thread = MessageReceiver(self, self.connection)
        self.thread.start()
        while True:
            time.sleep(0.5)
            request_content = input("Type in your request:").split(' ', 1)

            try:
                request_content[0] = request_content[0].lower()
                request_content[1] = request_content[1].lower()
                print(request_content)

                if request_content[1] == "none":
                    if request_content[0] == "names":
                        self.send_payload({
                            "request": "names",
                            "content": "None"
                        })
                    elif request_content[0] == "help":
                        self.send_payload({
                            "request": "help",
                            "content": "None"
                        })
                else:
                    if request_content[0] == "logout":
                        self.disconnect()
                    elif request_content[0] == "names":
                        self.send_payload({
                            "request": "names",
                            "content": "None"
                        })
                    elif request_content[0] == "help":
                        self.send_payload({
                            "request": "help",
                            "content": "None"
                        })
                    elif request_content[0] == "login":
                        self.send_payload({
                            "request": "login",
                            "content": request_content[1]
                        })
                    elif request_content[0] == "msg":
                        self.send_payload({
                            "request": "msg",
                            "content": request_content[1]
                        })
                    else:
                        self.not_supported(request_content)
            except IndexError:
                print("Input not valid!")
Esempio n. 15
0
    def createReceiverService(self):
        self.messageReceiverObject = MessageReceiver()
        messageReceiverThread = QThread()
        self.messageReceiverObject.moveToThread(messageReceiverThread)

        messageReceiverThread.started.connect(self.messageReceiverObject.runReceiver)
        self.messageReceiverObject.updatedHosts.connect(self.updateAvailableHosts)
        self.messageReceiverObject.updatedHosts.connect(self.updateHostsToNotify)
        self.messageReceiverObject.votingUpdate.connect(self.updateVotings)
        self.messageReceiverObject.finished.connect(messageReceiverThread.quit)
        self.messageReceiverObject.finished.connect(self.messageReceiverObject.deleteLater)
        messageReceiverThread.finished.connect(messageReceiverThread.deleteLater)
        return messageReceiverThread
Esempio n. 16
0
    def run(self):

        self.connection.connect((self.host, self.server_port))
        message_receiver = MessageReceiver(self, self.connection)
        message_receiver.start()

        while True:
            message = raw_input('Enter command \n')
            self.send_payload(message)
            if message == 'logout':
                time.sleep(1)
                break
        self.disconnect()
Esempio n. 17
0
    def __init__(self, host, server_port):
        """
        This method is run when creating a new Client object
        """

        # Set up the socket connection to the server
        self.connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

        adress = ('localhost', 9998)
        self.connection.connect(adress)
        receiver = MessageReceiver(self, self.connection)
        receiver.start()
        self.running = True
        self.run()
Esempio n. 18
0
 def run(self):
     # Initiate the connection to the server
     self.connection.connect((self.host, self.server_port))
     worker = MessageReceiver(self, self.connection)
     worker.daemon = True
     worker.start()
     running = True
     while running:
         raw = raw_input()
         if raw == "exit":
             running = False
             self.disconnect()
         else:
             self.send_payload(raw)
Esempio n. 19
0
    def run(self):
        # Initiate the connection to the server
        self.connection.connect((self.host, self.server_port))
        self.thread = MessageReceiver(self, self.connection)
        self.thread.start()

        while (1):
            new_payload = self.take_input()

            if new_payload['request'] == 'disconnect':
                self.disconnect()
                exit()

            self.send_payload(json.dumps(new_payload))
            time.sleep(0.1)
Esempio n. 20
0
    def run(self):
        # Initiate the connection to the server
        self.connection.connect((self.server_host, self.server_port))

        # We kick off a background thread which'll listen for incoming messages from
        # the server. Whenever a message from the server is received, the MessageReceiver
        # will call the receive_message method in this class.

        thread = MessageReceiver(self, self.connection)
        thread.start()

        # We listen for user input and send it to the dispatcher for formatting.
        while True:
            input_string = str(input(""))
            self.dispatcher(input_string)
Esempio n. 21
0
    def run(self):
        # TODO
        # Initiate the connection to the server
        self.connection.connect((self.host, self.server_port))
        receiver = MessageReceiver(self, self.connection)
        receiver.start()

        running = True
        while running:
            print("What to do: ")
            client_input = input()
            if client_input == "exit":
                running = False
                self.disconnect()
            else:
                self.send_payload(client_input)
Esempio n. 22
0
    def run(self):

        # Initiate the connection to the server
        print "client: connecting"
        self.connection.connect((self.host, self.server_port))
        self.thread = MessageReceiver(self, self.connection)
        self.thread.start()
        print "client: connected"
        print "1. login <username>, 2. logout, 3. msg <message>, 4. history, 5. users,  6. help\n"

        while True:
            payload = self.create_response()
            self.send_payload(payload)
            if input is "logout":
                self.disconnect()
                break
Esempio n. 23
0
    def run(self):
        # Initiate the connection to the server
        self.connection.connect((self.host, self.server_port))
        self.message_receiver = MessageReceiver(self, self.connection)

        while True:
            user_input = input(">> ")
            try:
                req, cont = user_input.split(" ")
                payload = {
                    'request': req,
                    'content': cont
                }
                self.send_payload(payload)
            except ValueError:
                print("Input must be two words.")
Esempio n. 24
0
async def on_message(message):
    receiver = MessageReceiver(message)

    if receiver.is_author_bot() and not receiver.is_our_CLI():
        return
    if not receiver.is_command():
        return

    if receiver.command_head_is("hi"):
        await receiver.send("Hi!")
        return

    if receiver.command_head_is("help"):
        await receiver.help()
        return

    if receiver.command_head_is("open"):
        await receiver.open()
        return

    if receiver.command_head_is("join"):
        await receiver.join()
        return

    if receiver.command_head_is("quit"):
        await receiver.quit()
        return

    if receiver.command_head_is("set"):
        await receiver.set_status()
        return

    if receiver.command_head_is("member"):
        await receiver.member()
        return

    if receiver.command_head_is_status():
        await receiver.status()
        return

    if receiver.command_head_is("gm"):
        await receiver.gm()
        return

    if receiver.D_in_command():
        await receiver.dice()
        return
Esempio n. 25
0
    def __init__(self, host, server_port):
        """
        This method is run when creating a new Client object
        """

        # Set up the socket connection to the server
        self.connection = socket(AF_INET, SOCK_STREAM)
        self.host = host
        self.server_port = server_port

        self.message_reciever = MessageReceiver(self, self.connection)
        self.message_parser = MessageParser(self)

        self.received_answer = True
        self.is_logged_in = False

        self.run()
Esempio n. 26
0
    def __init__(self, host, server_port):
        """
        This method is run when creating a new Client object
        """
        self.loggedon = False
        # Set up the socket connection to the server
        try:
            self.connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        except socket.error as e:
            print "Failed to create socket. Error message:", e

        self.host = host
        self.server_port = server_port
        self.lastMessageRecieved = None
        self.parser = MessageParser()
        self.run()
        self.rcv = MessageReceiver(self, self.connection)
        self.rcv.start()
Esempio n. 27
0
    def __init__(self, host, server_port):
        """
        This method is run when creating a new Client object
        """
        # Set up the socket connection to the server
        self.connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.msg = MessageReceiver(self, self.connection)
        self.host = host
        self.server_port = server_port

        self.hasLoggedOn = False

        self.connection.connect((self.host, self.server_port))
        #msg is a request sent from the client to the server
        print("Messager Reciever started")
        self.msg.start()
        print("Run method started!")
        self.run()
Esempio n. 28
0
    def __init__(self, host, server_port):
        """
		This method is run when creating a new Client object
		"""

        # Set up the socket connection to the server
        self.connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.host = host
        self.server_port = server_port

        self.userLoggedIn = False

        self.messageReceiver = MessageReceiver(
            self, self.connection)  # is a thread by itself.
        self.userInput = UserInput(self)  # is a thread by itself.

        self.parser = MessageParser(self)

        self.run()
Esempio n. 29
0
    def run(self):
        # Initiate the connection to the server
        print 'Connecting to the server..'
        self.connection.connect((self.host, self.server_port))

        # Initialize a message reciver
        reciver = MessageReceiver(self, self.connection)
        reciver.start()

        # Wait a second for server response
        time.sleep(1)
        cin = str(raw_input())

        while cin != "exit":
            temp_dict = cin.partition(' ')
            payload = {"request": temp_dict[0], "content": temp_dict[2]}
            self.send_payload(json.dumps(payload))
            cin = str(raw_input())

        self.disconnect()
Esempio n. 30
0
    def __init__(self, host, server_port):
        """
        This method is run when creating a new Client object
        """
        # initialization
        self.server_port = server_port
        self.host = host

        self.screen_buffer = []
        
        # Set up the socket connection to the server
        self.connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        # Initiate the connection to the server
        self.connection.connect((self.host, self.server_port))

        # Start the message receiver
        self.message_receiver = MessageReceiver(self, self.connection)
        
        # TODO: Finish init process with necessary code
        self.run()