Example #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)
Example #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)
Example #3
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)
Example #4
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)