def stringReceived(self, line): """ Handle received messages """ if not self._parse(line): tosend = cmd.addFirst(line, self.peername) self.relay(tosend)
def connectedUsers(self): """ Tells the client about already connected users """ for name, ip in self.factory.getUsers(): line = cmd.addFirst(cmd.clientcmd('add', str(ip)), name) print line self.sendLine(line)
def lineReceived(self, line): """ Handle recived lines """ if not self._parse(line): log.msg('Received %s from %s' % (line, self.peername)) msg = cmd.addFirst(line, self.peername) self.relay(msg)
def lineReceived(self, line): """ Handle recived lines """ if not self._parse(line): log.msg('Received %s from %s' %(line, self.peername)) msg = cmd.addFirst(line, self.peername) self.relay(msg)
def connectionLost(self, reason): """ safely disconnect user """ self.factory.removeClients(self) self.factory.removeUsers(self.peername, self.peer) msg = cmd.addFirst(cmd.clientcmd('rem', str(self.peer)), self.peername) self.relay(msg) self._logConnectionLost(reason)
def _parse(self, line): """ Parse line for commands returns True if line contains a command and calls the command otherwise simply returns False """ comd, value = cmd.parse(line, CLIENT_PREFIX) if comd == 'reg': self.peername = value log.msg('PeerName of %s is %s' %(self.peer, self.peername)) self.factory.updateUsers(self.peername, self.peer) # register name and ip with factory msg = cmd.addFirst(cmd.clientcmd('add', str(self.peer)), self.peername) self.relay(msg) else: return False return True
def _parse(self, line): """ Parse line for commands returns True if line contains a command and calls the command otherwise simply returns False """ comd, value = cmd.parse(line, CLIENT_PREFIX) if comd == 'reg': self.peername = value log.msg('PeerName of %s is %s' % (self.peer, self.peername)) self.factory.updateUsers( self.peername, self.peer) # register name and ip with factory msg = cmd.addFirst(cmd.clientcmd('add', str(self.peer)), self.peername) self.relay(msg) else: return False return True
def _parse(self, line): """ Parse line for commands returns True if line contains a command and calls the command otherwise simply returns False """ comd, value = cmd.parse(line, CLIENT_PREFIX) if comd == 'reg': self.peername = value elif comd == 'eof': self._reset() msg = cmd.clientcmd(comd, value) msg = cmd.addFirst(msg, self.peername) self.sendString(msg) elif comd == 'fail': self._reset() else: return False return True
def test_addFirst(self): line = 'do' + self.sep + 'dummy' add = 'first' result = cmd.addFirst(line, add, self.sep) self.assertTrue(result.startswith(add + self.sep))