Beispiel #1
0
    def getSecret(self, username, message):
        """ Start chatting with the bot server. GLADOS replies back to the client socket
            so we have to keep the connection open and wait to receive replies from bot. """

        try:
            if len(self.__userList) == 0:
                raise Exception, 'Use the list command to see the online users'

            if (username in self.__userList):

                uIp, uP = self.__userList[username]
                c = ConnectionManager(uIp, uP)
                c.connect()
                c.send(p.T_MESSAGE, [self.__username], message)

                # We wait for four replies from GLADOS to receive the final token
                # The application is going to block until GLADOS replies.
                # Quick and dirty solution as GLaDOS speaks "differently" from
                # the way this client is implemented. So, the message is printed
                # in raw format just to get the final token.
                for i in range(0, 3):
                    r = c.receive()
                    self.__agent.printMessage(str(r), 'Bot user')
                    if (r.type == p.T_PING):
                        c.send(p.T_PONG, [self.__username])
                c.disconnect()
            else:
                raise Exception, 'User %s can\'t be reached.' % username

        except Exception, e:
            self.__handleError('Chat', e)
Beispiel #2
0
    def getSecret(self, username, message):
        """ Start chatting with the bot server. GLADOS replies back to the client socket
            so we have to keep the connection open and wait to receive replies from bot. """

        try:
            if len(self.__userList) == 0:
                raise Exception, 'Use the list command to see the online users'

            if (username in self.__userList):
   
                uIp, uP = self.__userList[username]
                c = ConnectionManager(uIp, uP)
                c.connect()
                c.send(p.T_MESSAGE, [self.__username], message)
                
                # We wait for four replies from GLADOS to receive the final token
                # The application is going to block until GLADOS replies.
                # Quick and dirty solution as GLaDOS speaks "differently" from
                # the way this client is implemented. So, the message is printed
                # in raw format just to get the final token. 
                for i in range(0,3):
                    r = c.receive()
                    self.__agent.printMessage(str(r),'Bot user')
                    if(r.type == p.T_PING):
                        c.send(p.T_PONG, [self.__username])
                c.disconnect()
            else:
                raise Exception, 'User %s can\'t be reached.' % username

        except Exception,e:
            self.__handleError('Chat', e)
Beispiel #3
0
    def chat(self, username, message, getSecret=False):
        """ Start chatting with a specific user """

        try:
            if len(self.__userList) == 0:
                raise Exception, 'Use the list command to see the online users'

            if (username in self.__userList):

                # Setup a new socket connection with the other user and send data.
                # The user can reply at the binded port from the directory server
                uIp, uP = self.__userList[username]
                c = ConnectionManager(uIp, uP)
                c.connect()
                c.send(p.T_MESSAGE, [self.__username], message)
                c.disconnect()

            else:
                raise Exception, 'User %s can\'t be reached.' % username

        except Exception, e:
            self.__handleError('Chat', e)
Beispiel #4
0
    def chat(self, username, message, getSecret = False):
        """ Start chatting with a specific user """

        try:
            if len(self.__userList) == 0:
                raise Exception, 'Use the list command to see the online users'

            if (username in self.__userList):
   
                # Setup a new socket connection with the other user and send data.
                # The user can reply at the binded port from the directory server
                uIp, uP = self.__userList[username]
                c = ConnectionManager(uIp, uP)
                c.connect()
                c.send(p.T_MESSAGE, [self.__username], message)
                c.disconnect()

            else:
                raise Exception, 'User %s can\'t be reached.' % username

        except Exception,e:
            self.__handleError('Chat', e)
Beispiel #5
0
    def ping(self, username):
        """ Ping user """

        try:
            if len(self.__userList) == 0:
                raise Exception, 'Use the list command to see the online users'

            if (username in self.__userList):

                uIp, uP = self.__userList[username]
                c = ConnectionManager(uIp, uP)

                c.connect()
                c.send(p.T_PING, [self.__username])

                pong = c.receive()
                self.__agent.printMessage(pong.type, pong.args.pop())

                c.disconnect()
            else:
                raise Exception, 'User %s can\'t be pinged.' % username

        except Exception, e:
            self.__handleError('Ping', e)
Beispiel #6
0
    def ping(self, username):
        """ Ping user """

        try:       
            if len(self.__userList) == 0:
                raise Exception, 'Use the list command to see the online users'

            if (username in self.__userList):
   
                uIp, uP = self.__userList[username]
                c = ConnectionManager(uIp, uP)

                c.connect()
                c.send(p.T_PING, [self.__username])

                pong = c.receive()
                self.__agent.printMessage(pong.type, pong.args.pop())

                c.disconnect()
            else:
                raise Exception, 'User %s can\'t be pinged.' % username

        except Exception,e:
            self.__handleError('Ping', e)
Beispiel #7
0
class ChatClient:
    """ Chat client handles all outcoming requests like (authentication, user searching and of course chatting. The general idea of the client is to
    open a connection for sending messages and receive all the incoming messages
    at the server port that is known through the directory server."""
    def __init__(self, host, port, username, password, agent):
        self.__host = host
        self.__port = port
        self.__username = username
        self.__password = password
        self.__agent = agent
        self.__cm = None
        self.__userList = {}

    def __connect(self):
        self.__cm = ConnectionManager(self.__host, self.__port)
        self.__cm.connect()

    def __disconnect(self):
        self.__cm.disconnect()

    def __trigger(self, toBeExecuted, args=[]):
        """ Trigger function uses the power of functinal programing to execute the functions 
            that are passed as parameters. In details, its a wrapper for every command that
            requires re-authentication with the directory server. """

        self.__connect()
        [f(args) for f in toBeExecuted]
        self.__disconnect()

    def authenticate(self):
        self.__trigger([self.__login, self.__bind])

    def search(self, username):
        self.__trigger([self.__login, self.__searchUser], [username])

    def listAll(self):
        self.__trigger([self.__login, self.__searchUser])

    def leave(self):
        self.__trigger([self.__login, self.__unregister])

    def chat(self, username, message, getSecret=False):
        """ Start chatting with a specific user """

        try:
            if len(self.__userList) == 0:
                raise Exception, 'Use the list command to see the online users'

            if (username in self.__userList):

                # Setup a new socket connection with the other user and send data.
                # The user can reply at the binded port from the directory server
                uIp, uP = self.__userList[username]
                c = ConnectionManager(uIp, uP)
                c.connect()
                c.send(p.T_MESSAGE, [self.__username], message)
                c.disconnect()

            else:
                raise Exception, 'User %s can\'t be reached.' % username

        except Exception, e:
            self.__handleError('Chat', e)
Beispiel #8
0
class ButtleManager(QtCore.QObject):
    """
        This class catches events from QML, and manages them by calling the right manager or the right methods in core.
        It's like the front manager, which delegate to other managers.
        This class also catches events from QML about undo / redo.
    """
    def init(self):
        self._nodeManager = NodeManager()
        self._connectionManager = ConnectionManager()
        self._viewerManager = ViewerManager()

        # connect undoRedoChanged signal
        self._nodeManager.undoRedoChanged.connect(self.emitUndoRedoChanged)
        self._connectionManager.undoRedoChanged.connect(
            self.emitUndoRedoChanged)
        self._viewerManager.undoRedoChanged.connect(self.emitUndoRedoChanged)

        return self

    ############### getters ###############

    def getNodeManager(self):
        return self._nodeManager

    def getConnectionManager(self):
        return self._connectionManager

    def getViewerManager(self):
        return self._viewerManager

    ############### UNDO & REDO ###############

    @QtCore.Slot()
    def undo(self):
        """
            Calls the cmdManager to undo the last command.
        """
        cmdManager = CommandManager()
        cmdManager.undo()

        # emit undo/redo display
        self.emitUndoRedoChanged()

        # if we need to update params or viewer
        buttleData = ButtleDataSingleton().get()
        buttleData.currentParamNodeChanged.emit()
        buttleData.currentViewerNodeChanged.emit()

    @QtCore.Slot()
    def redo(self):
        """
            Calls the cmdManager to redo the last command.
        """
        cmdManager = CommandManager()
        cmdManager.redo()

        # emit undo/redo display
        self.emitUndoRedoChanged()

        # if we need to update params or viewer
        buttleData = ButtleDataSingleton().get()
        buttleData.currentParamNodeChanged.emit()
        buttleData.currentViewerNodeChanged.emit()

    def signalUndoRedo(self):
        self.undoRedoChanged.emit()

    def canUndo(self):
        """
            Calls the cmdManager to return if we can undo or not.
        """
        cmdManager = CommandManager()
        return cmdManager.canUndo()

    def canRedo(self):
        """
            Calls the cmdManager to return if we can redo or not.
        """
        cmdManager = CommandManager()
        return cmdManager.canRedo()

    ############### DELETION ###############
    @QtCore.Slot()
    def deleteSelection(self):
        buttleData = ButtleDataSingleton().get()
        if (buttleData.currentConnectionWrapper):
            self._connectionManager.disconnect(
                buttleData.currentConnectionWrapper)
        else:
            self._nodeManager.destructionNodes()

    ################################################## DATA EXPOSED TO QML ##################################################

    @QtCore.Signal
    def changed(self):
        pass

    def emitUndoRedoChanged(self):
        self.changed.emit()

    # undo redo
    canUndo = QtCore.Property(bool, canUndo, notify=changed)
    canRedo = QtCore.Property(bool, canRedo, notify=changed)

    # managers
    nodeManager = QtCore.Property(QtCore.QObject,
                                  getNodeManager,
                                  constant=True)
    connectionManager = QtCore.Property(QtCore.QObject,
                                        getConnectionManager,
                                        constant=True)
    viewerManager = QtCore.Property(QtCore.QObject,
                                    getViewerManager,
                                    constant=True)
Beispiel #9
0
class ButtleManager(QtCore.QObject):
    """
        This class catches events from QML, and manages them by calling the right manager or the right methods in core.
        It's like the front manager, which delegate to other managers.
        This class also catches events from QML about undo / redo.
    """

    def init(self):
        self._nodeManager = NodeManager()
        self._connectionManager = ConnectionManager()
        self._viewerManager = ViewerManager()

        # connect undoRedoChanged signal
        self._nodeManager.undoRedoChanged.connect(self.emitUndoRedoChanged)
        self._connectionManager.undoRedoChanged.connect(self.emitUndoRedoChanged)
        self._viewerManager.undoRedoChanged.connect(self.emitUndoRedoChanged)

        return self

    ############### getters ###############

    def getNodeManager(self):
        return self._nodeManager

    def getConnectionManager(self):
        return self._connectionManager

    def getViewerManager(self):
        return self._viewerManager

    ############### UNDO & REDO ###############

    @QtCore.Slot()
    def undo(self):
        """
            Calls the cmdManager to undo the last command.
        """
        cmdManager = CommandManager()
        cmdManager.undo()

        # emit undo/redo display
        self.emitUndoRedoChanged()

        # if we need to update params or viewer
        buttleData = ButtleDataSingleton().get()
        buttleData.currentParamNodeChanged.emit()
        buttleData.currentViewerNodeChanged.emit()

    @QtCore.Slot()
    def redo(self):
        """
            Calls the cmdManager to redo the last command.
        """
        cmdManager = CommandManager()
        cmdManager.redo()

        # emit undo/redo display
        self.emitUndoRedoChanged()

        # if we need to update params or viewer
        buttleData = ButtleDataSingleton().get()
        buttleData.currentParamNodeChanged.emit()
        buttleData.currentViewerNodeChanged.emit()

    def signalUndoRedo(self):
        self.undoRedoChanged.emit()

    def canUndo(self):
        """
            Calls the cmdManager to return if we can undo or not.
        """
        cmdManager = CommandManager()
        return cmdManager.canUndo()

    def canRedo(self):
        """
            Calls the cmdManager to return if we can redo or not.
        """
        cmdManager = CommandManager()
        return cmdManager.canRedo()

    ############### DELETION ###############
    @QtCore.Slot()
    def deleteSelection(self):
        buttleData = ButtleDataSingleton().get()
        if(buttleData.currentConnectionWrapper):
            self._connectionManager.disconnect(buttleData.currentConnectionWrapper)
        else:
            self._nodeManager.destructionNodes()

    ################################################## DATA EXPOSED TO QML ##################################################

    @QtCore.Signal
    def changed(self):
        pass

    def emitUndoRedoChanged(self):
        self.changed.emit()

    # undo redo
    canUndo = QtCore.Property(bool, canUndo, notify=changed)
    canRedo = QtCore.Property(bool, canRedo, notify=changed)

    # managers
    nodeManager = QtCore.Property(QtCore.QObject, getNodeManager, constant=True)
    connectionManager = QtCore.Property(QtCore.QObject, getConnectionManager, constant=True)
    viewerManager = QtCore.Property(QtCore.QObject, getViewerManager, constant=True)
Beispiel #10
0
class ChatClient:
    """ Chat client handles all outcoming requests like (authentication, user searching and of course chatting. The general idea of the client is to
    open a connection for sending messages and receive all the incoming messages
    at the server port that is known through the directory server."""

    def __init__(self, host, port, username, password, agent):
        self.__host = host
        self.__port = port
        self.__username = username
        self.__password = password
        self.__agent = agent
        self.__cm = None
        self.__userList = {}

    def __connect(self):
        self.__cm = ConnectionManager(self.__host, self.__port)
        self.__cm.connect()
        
    def __disconnect(self):
        self.__cm.disconnect()

    def __trigger(self, toBeExecuted, args = []):
        """ Trigger function uses the power of functinal programing to execute the functions 
            that are passed as parameters. In details, its a wrapper for every command that
            requires re-authentication with the directory server. """

        self.__connect()
        [ f(args) for f in toBeExecuted ]
        self.__disconnect()

    def authenticate(self):
        self.__trigger([self.__login, self.__bind])

    def search(self, username):
        self.__trigger([self.__login, self.__searchUser], [username])

    def listAll(self):
        self.__trigger([self.__login, self.__searchUser])

    def leave(self):
        self.__trigger([self.__login, self.__unregister])

    def chat(self, username, message, getSecret = False):
        """ Start chatting with a specific user """

        try:
            if len(self.__userList) == 0:
                raise Exception, 'Use the list command to see the online users'

            if (username in self.__userList):
   
                # Setup a new socket connection with the other user and send data.
                # The user can reply at the binded port from the directory server
                uIp, uP = self.__userList[username]
                c = ConnectionManager(uIp, uP)
                c.connect()
                c.send(p.T_MESSAGE, [self.__username], message)
                c.disconnect()

            else:
                raise Exception, 'User %s can\'t be reached.' % username

        except Exception,e:
            self.__handleError('Chat', e)