示例#1
0
 def stringReceived(self, line):
     """
     Handle received messages
     """
     if not self._parse(line):
         tosend = cmd.addFirst(line, self.peername)
         self.relay(tosend)
示例#2
0
 def stringReceived(self, line):
     """
     Handle received messages
     """
     if not self._parse(line):
         tosend = cmd.addFirst(line, self.peername)
         self.relay(tosend)
示例#3
0
 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)
示例#4
0
 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)
示例#5
0
 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)
示例#6
0
 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)
示例#7
0
 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)
示例#8
0
 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)
示例#9
0
 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
示例#10
0
 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
示例#11
0
 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
示例#12
0
 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
示例#13
0
 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))