Exemple #1
0
    def __init__(self, username, password, localAddress, remoteServerPort):
        """ Create a local server and a local client for the chat and start GUI """

        # Create a local client and a local server as we are peer to peer
        self.__client = ChatClient(localAddress, remoteServerPort, username,
                                   password, self)
        self.__server = ChatServer(localAddress, username, self)

        # Start GUI
        self.__gui = EurechatInterface(username, localAddress,
                                       remoteServerPort)
        curses.wrapper(self.__gui.start)

        # Authenticate the user and bind to port for chatting
        self.__client.authenticate()
Exemple #2
0
    def __init__(self, username, password, localAddress, remoteServerPort):
        """ Create a local server and a local client for the chat and start GUI """

        # Create a local client and a local server as we are peer to peer
        self.__client = ChatClient(localAddress, remoteServerPort, username, password, self)
        self.__server = ChatServer(localAddress, username, self)

        # Start GUI
        self.__gui = EurechatInterface(username, localAddress, remoteServerPort)
        curses.wrapper(self.__gui.start)

        # Authenticate the user and bind to port for chatting
        self.__client.authenticate()
Exemple #3
0
class Agent:
    """ Chat Agent is the core class of our chat application. It invokes 
        one client and one local server to send and accept messages, plus 
        the GUI class using the curses package. """

    def __init__(self, username, password, localAddress, remoteServerPort):
        """ Create a local server and a local client for the chat and start GUI """

        # Create a local client and a local server as we are peer to peer
        self.__client = ChatClient(localAddress, remoteServerPort, username, password, self)
        self.__server = ChatServer(localAddress, username, self)

        # Start GUI
        self.__gui = EurechatInterface(username, localAddress, remoteServerPort)
        curses.wrapper(self.__gui.start)

        # Authenticate the user and bind to port for chatting
        self.__client.authenticate()

    
    def prompt(self, showIntro = False):
        """ Start the simple prompt that acccepts user input.
            A few words about secret command, because of the behaviour of GLADOS,
            that speaks back to the port we opened to send him a message, we use 
            this special function to interact with her to get the secret token. 
            All the messages from other users are received at the binded port on 
            the directory server. """

        while True: 
            try:
                self.__gui.printHeader()

                # Wait for user input
                input = self.__gui.getInput()
                self.printMessage(input)

                if re.search("^bye$", input):
                    self.quit()
                    break
                elif (input.find('chat') == 0):
                    match = re.search('^chat ([a-zA-Z0-9]+) (.*)$', input)
                    username = match.group(1)
                    message = match.group(2)
                    self.__result = self.__client.chat(username, message)
                elif (input.find('list') == 0):
                    match = re.search('^list ([a-zA-Z0-9]+)$', input)
                    if (match):
                        self.__result = self.__client.search(match.group(1))
                    else:
                        self.__result = self.__client.listAll()
                elif (input.find('ping') == 0):
                    match = re.search('^ping ([a-zA-Z0-9]+)$', input)
                    if (match):
                        self.__result = self.__client.ping(match.group(1))
                elif (input.find('secret') == 0):
                    match = re.search('^secret ([a-zA-Z0-9]+) (.*)$', input)
                    username = match.group(1)
                    message = match.group(2)
                    self.__client.getSecret(username, message)
                elif re.search("^help$", input):
                    self.printMessage("Available commands:", "help")
                    self.printMessage("chat user message    : Chat with another user.", "help")
                    self.printMessage("secret user message  : Get final secret from bot_user", "help")
                    self.printMessage("list                 : List all online users.", "help")
                    self.printMessage("ping user            : Ping user.", "help")
                    self.printMessage("bye                  : I think its obvious ;)", "help")
                else:
                    raise Exception

            except Exception,e:
                self.printMessage("Invalid command, type help to list all the available commands." + str(e) + input, "error")

            except KeyboardInterrupt:
                self.quit() 
                return
Exemple #4
0
 def buildProtocol(self, addr):
     return ChatClient()
Exemple #5
0
class Agent:
    """ Chat Agent is the core class of our chat application. It invokes 
        one client and one local server to send and accept messages, plus 
        the GUI class using the curses package. """
    def __init__(self, username, password, localAddress, remoteServerPort):
        """ Create a local server and a local client for the chat and start GUI """

        # Create a local client and a local server as we are peer to peer
        self.__client = ChatClient(localAddress, remoteServerPort, username,
                                   password, self)
        self.__server = ChatServer(localAddress, username, self)

        # Start GUI
        self.__gui = EurechatInterface(username, localAddress,
                                       remoteServerPort)
        curses.wrapper(self.__gui.start)

        # Authenticate the user and bind to port for chatting
        self.__client.authenticate()

    def prompt(self, showIntro=False):
        """ Start the simple prompt that acccepts user input.
            A few words about secret command, because of the behaviour of GLADOS,
            that speaks back to the port we opened to send him a message, we use 
            this special function to interact with her to get the secret token. 
            All the messages from other users are received at the binded port on 
            the directory server. """

        while True:
            try:
                self.__gui.printHeader()

                # Wait for user input
                input = self.__gui.getInput()
                self.printMessage(input)

                if re.search("^bye$", input):
                    self.quit()
                    break
                elif (input.find('chat') == 0):
                    match = re.search('^chat ([a-zA-Z0-9]+) (.*)$', input)
                    username = match.group(1)
                    message = match.group(2)
                    self.__result = self.__client.chat(username, message)
                elif (input.find('list') == 0):
                    match = re.search('^list ([a-zA-Z0-9]+)$', input)
                    if (match):
                        self.__result = self.__client.search(match.group(1))
                    else:
                        self.__result = self.__client.listAll()
                elif (input.find('ping') == 0):
                    match = re.search('^ping ([a-zA-Z0-9]+)$', input)
                    if (match):
                        self.__result = self.__client.ping(match.group(1))
                elif (input.find('secret') == 0):
                    match = re.search('^secret ([a-zA-Z0-9]+) (.*)$', input)
                    username = match.group(1)
                    message = match.group(2)
                    self.__client.getSecret(username, message)
                elif re.search("^help$", input):
                    self.printMessage("Available commands:", "help")
                    self.printMessage(
                        "chat user message    : Chat with another user.",
                        "help")
                    self.printMessage(
                        "secret user message  : Get final secret from bot_user",
                        "help")
                    self.printMessage(
                        "list                 : List all online users.",
                        "help")
                    self.printMessage("ping user            : Ping user.",
                                      "help")
                    self.printMessage(
                        "bye                  : I think its obvious ;)",
                        "help")
                else:
                    raise Exception

            except Exception, e:
                self.printMessage(
                    "Invalid command, type help to list all the available commands."
                    + str(e) + input, "error")

            except KeyboardInterrupt:
                self.quit()
                return