This commit is contained in:
aozhiwei 2020-07-02 15:27:28 +08:00
parent 4af9244511
commit aa6d5c94d7
3 changed files with 27 additions and 19 deletions

View File

@ -379,7 +379,7 @@ void Player::_CMFriendAddBlack(f8::MsgHdr& hdr, const cs::CMFriendAddBlack& msg)
SendMsg(notifymsg);
}
black_hash_[p->base_data.account_id] = p;
RemoveFriend(p->base_data.account_id, true);
InternalRemoveFriend(p->base_data.account_id, true, false);
MarkDirty();
}
ShowErrorMsg("成功添加到黑名单");
@ -968,21 +968,7 @@ void Player::AddBlackList(Friend* friendobj)
void Player::RemoveFriend(const std::string& account_id, bool need_sync)
{
Friend* friendobj = GetFriendById(account_id);
if (friendobj) {
{
cs::SMDeleteFriendNotify notifymsg;
notifymsg.add_user_list(account_id);
SendMsg(notifymsg);
}
if (need_sync) {
SyncHelper::Instance()->SyncDeleteFriend(this, friendobj->base_data.account_id, 0);
}
PlayerMgr::Instance()->UnWatchPlayer(friendobj);
friend_hash_.erase(account_id);
delete friendobj;
MarkDirty();
}
InternalRemoveFriend(account_id, need_sync, true);
}
void Player::Update(long long tick)
@ -1469,3 +1455,24 @@ void Player::ShowErrorMsg(const std::string& msg)
notifymsg.set_msg(msg);
SendMsg(notifymsg);
}
void Player::InternalRemoveFriend(const std::string& account_id, bool need_sync, bool auto_delete)
{
Friend* friendobj = GetFriendById(account_id);
if (friendobj) {
{
cs::SMDeleteFriendNotify notifymsg;
notifymsg.add_user_list(account_id);
SendMsg(notifymsg);
}
if (need_sync) {
SyncHelper::Instance()->SyncDeleteFriend(this, friendobj->base_data.account_id, 0);
}
PlayerMgr::Instance()->UnWatchPlayer(friendobj);
friend_hash_.erase(account_id);
if (auto_delete) {
delete friendobj;
}
MarkDirty();
}
}

View File

@ -105,6 +105,8 @@ class Player
void Update(long long tick);
void FillMFUserInfo(cs::MFUserInfo* user_info);
std::set<std::string>& GetExcludeAccountIds();
Friend* GetFriendById(const std::string& friend_id);
Friend* GetBlackListById(const std::string& friend_id);
const std::string AccountId();
const std::string SessionId();
@ -116,8 +118,6 @@ private:
void FillBlackList(::google::protobuf::RepeatedPtrField< ::cs::MFUserInfo >* black_list);
void ForwardGroupCMMsg(f8::MsgHdr& hdr, long long hash_code);
void SaveToDB(a8::XParams param, f8::AsyncDBOnOkFunc on_ok, f8::AsyncDBOnErrorFunc on_error);
Friend* GetFriendById(const std::string& friend_id);
Friend* GetBlackListById(const std::string& friend_id);
void FillApplyList(const cs::MFPaging& paging, cs::SMFriendApplyList& respmsg);
void MarkDirty();
void OnDataVersion1Change();
@ -149,6 +149,7 @@ private:
void QueryUserOnline(std::vector<std::string> account_ids);
void QueryUserFromDB();
void ShowErrorMsg(const std::string& msg);
void InternalRemoveFriend(const std::string& account_id, bool need_sync, bool auto_delete);
private:
bool dirty_ = false;

View File

@ -50,7 +50,7 @@ void PlayerMgr::_SS_IM_SendChatMsg(f8::MsgHdr& hdr, const ss::SS_IM_SendChatMsg&
void PlayerMgr::_SS_IM_SendCustomMsg(f8::MsgHdr& hdr, const ss::SS_IM_SendCustomMsg& msg)
{
Player* hum = GetPlayerByAccountId(msg.target());
if (hum) {
if (hum && !hum->GetBlackListById(msg.target())) {
cs::SMCustomMsgNotify notifymsg;
notifymsg.set_sender(msg.context().user_info().base_data().account_id());
notifymsg.set_msg(msg.msg());