def someone_add_me(self, from_id): if from_id in self.mf.accepting or str(from_id) in self.mf.friends: return self.mf.accepting.append(from_id) self.mf.save() msg = protomsg.NewFriendNotify() self._msg_friend(msg.friend, from_id, FRIEND_APPLY) publish_to_char(self.char_id, pack_msg(msg))
def add(self, target_id=None, target_name=None): if not target_id and not target_name: raise SanguoException( errormsg.BAD_MESSAGE, self.char_id, "Friend Add", "no target_id and no target_name" ) self.check_max_amount("Friend Add") if target_id: try: c = MongoCharacter.objects.get(id=target_id) except DoesNotExist: raise SanguoException( errormsg.CHARACTER_NOT_FOUND, self.char_id, "Friend Add", "character id {0} not found".format(target_id) ) else: try: c = MongoCharacter.objects.get(name=target_name, server_id=self.char.mc.server_id) except DoesNotExist: raise SanguoException( errormsg.CHARACTER_NOT_FOUND, self.char_id, "Friend Add", u"can not found character {0} in server {1}".format(target_name, self.char.mc.server_id) ) if str(c.id) in self.mf.friends: if self.mf.friends[str(c.id)] == FRIEND_OK: raise SanguoException( errormsg.FRIEND_ALREADY_ADD, self.char_id, "Friend Add", "character {0} already has beed added".format(c.id) ) return self.mf.friends[str(c.id)] = FRIEND_ACK self.mf.save() target_char_friend = Friend(c.id) target_char_friend.someone_add_me(self.char_id) # notify msg = protomsg.NewFriendNotify() self._msg_friend(msg.friend, c.id, FRIEND_ACK) publish_to_char(self.char_id, pack_msg(msg)) self.send_friends_amount_notify()
def someone_add_me(self, from_id): from_id = int(from_id) if from_id in self.mf.accepting or from_id in self.mf.pending or from_id in self.mf.accepting: return self.mf.accepting.append(from_id) self.mf.save() msg = protomsg.NewFriendNotify() self._msg_friend(msg.friend, from_id, FRIEND_APPLY) publish_to_char(self.char_id, pack_msg(msg)) self.send_friends_amount_notify()
def send_new_friend_notify(self, friend_id, status=FRIEND_OK): msg = protomsg.NewFriendNotify() self._msg_friend(msg.friend, friend_id, status) publish_to_char(self.char_id, pack_msg(msg))