This commit is contained in:
aozhiwei 2020-06-24 16:57:28 +08:00
parent 263ae31018
commit d685206b27
5 changed files with 38 additions and 7 deletions

View File

@ -492,8 +492,10 @@ void Player::_SS_IM_FriendAgreeRequest(f8::MsgHdr& hdr, const ss::SS_IM_FriendAg
} }
QueryUserOnline({friendobj->base_data.account_id}); QueryUserOnline({friendobj->base_data.account_id});
} else { } else {
SyncHelper::Instance()->SyncDeleteFriend(this, SyncHelper::Instance()->SyncDeleteFriend
msg.context().user_info().base_data().account_id()); (this,
msg.context().user_info().base_data().account_id(),
1);
} }
} }
RemoveHandledApply(); RemoveHandledApply();
@ -531,7 +533,34 @@ void Player::_SS_IM_FriendAgreeRequest(f8::MsgHdr& hdr, const ss::SS_IM_FriendAg
void Player::_SS_IM_FriendDeleteRequest(f8::MsgHdr& hdr, const ss::SS_IM_FriendDeleteRequest& msg) void Player::_SS_IM_FriendDeleteRequest(f8::MsgHdr& hdr, const ss::SS_IM_FriendDeleteRequest& msg)
{ {
if (GetFriendById(msg.context().user_info().base_data().account_id())) { if (GetFriendById(msg.context().user_info().base_data().account_id())) {
#ifdef DEBUG
a8::UdpLog::Instance()->Debug("SS_IM_FriendDeleteRequest %s",
{
msg.context().user_info().base_data().account_id()
});
#endif
RemoveFriend(msg.context().user_info().base_data().account_id(), false); RemoveFriend(msg.context().user_info().base_data().account_id(), false);
a8::Timer::Instance()->AddDeadLineTimerAndAttach
(
1000 * 2,
a8::XParams()
.SetSender(this),
[] (const a8::XParams& param)
{
Player* hum = (Player*)param.sender.GetUserData();
cs::SMFriendAgree respmsg;
respmsg.set_errcode(4);
respmsg.set_errmsg("添加失败,对方的好友数已达到上限");
hum->SendMsg(respmsg);
#ifdef DEBUG
a8::UdpLog::Instance()->Debug("添加失败,对方的好友数已达到上限 %s",
{
hum->AccountId()
});
#endif
},
&timer_attacher.timer_list_
);
} }
f8::MsgHdr* hdr_copy = hdr.Clone(); f8::MsgHdr* hdr_copy = hdr.Clone();
ss::SS_IM_FriendDeleteRequest* msg_copy = new ss::SS_IM_FriendDeleteRequest; ss::SS_IM_FriendDeleteRequest* msg_copy = new ss::SS_IM_FriendDeleteRequest;
@ -805,7 +834,7 @@ void Player::RemoveFriend(const std::string& account_id, bool need_sync)
SendMsg(notifymsg); SendMsg(notifymsg);
} }
if (need_sync) { if (need_sync) {
SyncHelper::Instance()->SyncDeleteFriend(this, friendobj->base_data.account_id); SyncHelper::Instance()->SyncDeleteFriend(this, friendobj->base_data.account_id, 0);
} }
PlayerMgr::Instance()->UnWatchPlayer(friendobj); PlayerMgr::Instance()->UnWatchPlayer(friendobj);
friend_hash_.erase(account_id); friend_hash_.erase(account_id);
@ -1025,7 +1054,7 @@ void Player::OnFriendAgreeEvent(Event& event)
return; return;
} }
if (!CanAddFriend(event.sender_id)) { if (!CanAddFriend(event.sender_id)) {
SyncHelper::Instance()->SyncDeleteFriend(this, event.sender_id); SyncHelper::Instance()->SyncDeleteFriend(this, event.sender_id, 0);
return; return;
} }
Friend* friendobj = new Friend; Friend* friendobj = new Friend;
@ -1275,4 +1304,3 @@ void Player::QueryUserFromDB()
} }
} }
} }

View File

@ -139,6 +139,7 @@ private:
void QueryUserOnline(std::vector<std::string> account_ids); void QueryUserOnline(std::vector<std::string> account_ids);
void QueryUserFromDB(); void QueryUserFromDB();
private: private:
bool dirty_ = false; bool dirty_ = false;
timer_list* dirty_timer_ = nullptr; timer_list* dirty_timer_ = nullptr;

View File

@ -51,11 +51,12 @@ void SyncHelper::SyncNewFriend(Player* hum, const std::string& target_id)
); );
} }
void SyncHelper::SyncDeleteFriend(Player* hum, const std::string& target_id) void SyncHelper::SyncDeleteFriend(Player* hum, const std::string& target_id, int reason)
{ {
ss::SS_IM_FriendDeleteRequest* notifymsg = new ss::SS_IM_FriendDeleteRequest(); ss::SS_IM_FriendDeleteRequest* notifymsg = new ss::SS_IM_FriendDeleteRequest();
hum->FillIMMsgConext(notifymsg->mutable_context()); hum->FillIMMsgConext(notifymsg->mutable_context());
notifymsg->set_target_id(target_id); notifymsg->set_target_id(target_id);
notifymsg->set_reason(reason);
BroadcastIMConnMsg(*notifymsg); BroadcastIMConnMsg(*notifymsg);
pending_request_hash_[notifymsg->context().seqid()] = pending_request_hash_[notifymsg->context().seqid()] =
a8::Timer::Instance()->AddDeadLineTimer a8::Timer::Instance()->AddDeadLineTimer

View File

@ -24,7 +24,7 @@ public:
void UnInit(); void UnInit();
void SyncNewFriend(Player* hum, const std::string& target_id); void SyncNewFriend(Player* hum, const std::string& target_id);
void SyncDeleteFriend(Player* hum, const std::string& target_id); void SyncDeleteFriend(Player* hum, const std::string& target_id, int reason);
void SyncUpdateFriend(Player* hum, const std::string& target_id); void SyncUpdateFriend(Player* hum, const std::string& target_id);
void SyncApplyFriend(Player* hum, const std::string& target_id); void SyncApplyFriend(Player* hum, const std::string& target_id);

View File

@ -221,6 +221,7 @@ message SS_IM_FriendDeleteRequest
{ {
optional MFIMMsgConext context = 1; optional MFIMMsgConext context = 1;
optional string target_id = 3; optional string target_id = 3;
optional int32 reason = 4;
} }
message SS_IM_FriendDeleteResponse message SS_IM_FriendDeleteResponse