def handle_CHAT(self, message): message=hexskip(message) print repr(message) parsedMessage=message.split('::') headerText=parsedMessage[0] if headerText == 'ADDNEWGROUP': username=parsedMessage[1] groupId=addGroup(genIndex(),[str(self.name),str(username)]) logging.info("New Gorup %d created by User %s in pair with %s" %(groupId,self.name,username)) lineText="GID::"+str(groupId)+"::"+username self.sendLine(lineText) if headerText == 'ADDMEMBER': groupId=int (parsedMessage[1]) username=parsedMessage[2] if username not in self.data['friends']: self.sendLine("MSG::"+str(groupId)+"::testdata::Sorry You cannot invite that user") else: addMember(groupId,username) message='MSG::'+str(groupId)+"::hello::"+username+" is added to the group by "+self.name print message for name in groups[groupId]: for keyname,protocol in self.users.iteritems(): if name == keyname: protocol.sendLine(message) if headerText == 'MSG': groupId=int(parsedMessage[1]) message=str("< %s >"%self.name+parsedMessage[2]) message="MSG::"+str(groupId)+"::"+getUsersListInGroup(groupId)+"::"+message print message for name in groups[groupId]: for keyname,protocol in self.users.iteritems(): if name == keyname and protocol != self: protocol.sendLine(message) if headerText=='ADDFRIEND': friendName=parsedMessage[1] response=self.addFriends(friendName) self.sendLine("POP::"+response) if message =='quit': if self.users.has_key(self.name): del self.users[self.name] self.factory.users.remove(self) print self.name +' has quit'
def handle_GETNAME(self, name): name=hexskip(name) print repr(name) if(self.checkLogin(name,'name')): logging.info("new user %s Loggedin Successfully " %name) self.sendLine(" ") self.name = name self.users[name] = self self.state = "CHAT" try: self.showFriendlist("Thread-1",2) except: logging.warning("showFriendlist Thread Couldnot Be started") else: logging.info("login failed") self.sendLine("sorry invalid Credentials")