コード例 #1
0
ファイル: hpfeeds_server.py プロジェクト: Bifrozt/honssh
	def publish(self, channel, **kwargs):
		try:
			self.send(msgpublish(self.ident, channel, json.dumps(kwargs).encode('latin1')))
		except Exception, e:
			log.err('[PLUGIN][HPFEEDS] - connection to hpfriends lost: {0}'.format(e))
			log.err('[PLUGIN][HPFEEDS] - connecting')
			self.connect()
			self.send(msgpublish(self.ident, channel, json.dumps(kwargs).encode('latin1')))
コード例 #2
0
 def publish(self, channel, **kwargs):
     try:
         self.send(msgpublish(self.ident, channel, json.dumps(kwargs).encode('latin1')))
     except Exception, e:
         log.err('[PLUGIN][HPFEEDS] - connection to hpfriends lost: {0}'.format(e))
         log.err('[PLUGIN][HPFEEDS] - connecting')
         self.connect()
         self.send(msgpublish(self.ident, channel, json.dumps(kwargs).encode('latin1')))
コード例 #3
0
ファイル: hpfeeds_server.py プロジェクト: Bifrozt/honssh
	def read(self):
		if not self.s: return
		try: d = self.s.recv(BUFSIZ)
		except socket.timeout:
			return

		if not d:
			self.close()
			return

		self.unpacker.feed(d)
		try:
			for opcode, data in self.unpacker:
				log.msg(log.LCYAN, '[PLUGIN][HPFEEDS]', 'hpclient msg opcode {0} data {1}'.format(opcode, data))
				if opcode == OP_INFO:
					name, rand = strunpack8(data)
					log.msg(log.LCYAN, '[PLUGIN][HPFEEDS]', 'hpclient server name {0} rand {1}'.format(name, rand))
					self.send(msgauth(rand, self.ident, self.secret))
					self.state = 'GOTINFO'

				elif opcode == OP_PUBLISH:
					ident, data = strunpack8(data)
					chan, data = strunpack8(data)
					log.msg(log.LCYAN, '[PLUGIN][HPFEEDS]', 'publish to {0} by {1}: {2}'.format(chan, ident, data))

				elif opcode == OP_ERROR:
					log.err('[PLUGIN][HPFEEDS] - errormessage from server: {0}'.format(data))
				else:
					log.err('[PLUGIN][HPFEEDS] - unknown opcode message: {0}'.format(opcode))
		except BadClient:
			log.err('[PLUGIN][HPFEEDS] - unpacker error, disconnecting.')
			self.close()
コード例 #4
0
    def read(self):
        if not self.s: return
        try:
            d = self.s.recv(BUFSIZ)
        except socket.timeout:
            return

        if not d:
            self.close()
            return

        self.unpacker.feed(d)
        try:
            for opcode, data in self.unpacker:
                log.msg(log.LCYAN, '[PLUGIN][HPFEEDS]', 'hpclient msg opcode {0} data {1}'.format(opcode, data))
                if opcode == OP_INFO:
                    name, rand = strunpack8(data)
                    log.msg(log.LCYAN, '[PLUGIN][HPFEEDS]', 'hpclient server name {0} rand {1}'.format(name, rand))
                    self.send(msgauth(rand, self.ident, self.secret))
                    self.state = 'GOTINFO'

                elif opcode == OP_PUBLISH:
                    ident, data = strunpack8(data)
                    chan, data = strunpack8(data)
                    log.msg(log.LCYAN, '[PLUGIN][HPFEEDS]', 'publish to {0} by {1}: {2}'.format(chan, ident, data))

                elif opcode == OP_ERROR:
                    log.err('[PLUGIN][HPFEEDS] - errormessage from server: {0}'.format(data))
                else:
                    log.err('[PLUGIN][HPFEEDS] - unknown opcode message: {0}'.format(opcode))
        except BadClient:
            log.err('[PLUGIN][HPFEEDS] - unpacker error, disconnecting.')
            self.close()