diff --git a/server/imserver/player.cc b/server/imserver/player.cc index cb082ec..6666d88 100644 --- a/server/imserver/player.cc +++ b/server/imserver/player.cc @@ -307,7 +307,7 @@ void Player::_CMFriendDeleteBlack(f8::MsgHdr& hdr, const cs::CMFriendDeleteBlack void Player::_CMSendChatMsg(f8::MsgHdr& hdr, const cs::CMSendChatMsg& msg) { ss::SS_IM_SendChatMsg ss_msg; - FillIMMsgConext(hdr, ss_msg.mutable_context()); + FillIMMsgConext(ss_msg.mutable_context()); ss_msg.set_chat_channel(msg.chat_channel()); ss_msg.set_msg(msg.msg()); Friend* friend_data = GetFriendById(msg.target()); @@ -319,7 +319,7 @@ void Player::_CMSendChatMsg(f8::MsgHdr& hdr, const cs::CMSendChatMsg& msg) void Player::_CMSendCustomMsg(f8::MsgHdr& hdr, const cs::CMSendCustomMsg& msg) { ss::SS_IM_SendCustomMsg ss_msg; - FillIMMsgConext(hdr, ss_msg.mutable_context()); + FillIMMsgConext(ss_msg.mutable_context()); ss_msg.set_msg(msg.msg()); ss_msg.set_param1(msg.param1()); ss_msg.set_param2(msg.param2()); @@ -521,7 +521,7 @@ void Player::FillFriendList(::google::protobuf::RepeatedPtrField< ::cs::MFUserIn } } -void Player::FillIMMsgConext(f8::MsgHdr& hdr, ss::MFIMMsgConext* context) +void Player::FillIMMsgConext(ss::MFIMMsgConext* context) { FillMFUserInfo(context->mutable_user_info()); context->set_seqid(App::Instance()->NewSeqId()); @@ -530,7 +530,7 @@ void Player::FillIMMsgConext(f8::MsgHdr& hdr, ss::MFIMMsgConext* context) void Player::ForwardGroupCMMsg(f8::MsgHdr& hdr, long long hash_code) { ss::SS_MS_ForwardGroupCMMsg msg; - FillIMMsgConext(hdr, msg.mutable_context()); + FillIMMsgConext(msg.mutable_context()); if (hdr.buflen > 0) { msg.mutable_payload()->assign(hdr.buf, hdr.buflen); } diff --git a/server/imserver/player.h b/server/imserver/player.h index 0f316c6..574fbff 100644 --- a/server/imserver/player.h +++ b/server/imserver/player.h @@ -97,12 +97,12 @@ class Player void NotifyOnline(); void NotifyOffline(); void NotifyUserInfoUpdate(Friend* friend_data); + void FillIMMsgConext(ss::MFIMMsgConext* context); const std::string AccountId(); private: void FillFriendList(::google::protobuf::RepeatedPtrField< ::cs::MFUserInfo >* friend_list); - void FillIMMsgConext(f8::MsgHdr& hdr, ss::MFIMMsgConext* context); void FillMFUserInfo(cs::MFUserInfo* user_info); void ForwardGroupCMMsg(f8::MsgHdr& hdr, long long hash_code); void SaveToDB(a8::XParams param, f8::AsyncDBOnOkFunc on_ok, f8::AsyncDBOnErrorFunc on_error); diff --git a/server/imserver/synchelper.cc b/server/imserver/synchelper.cc index 7ba4b18..5f5fd88 100644 --- a/server/imserver/synchelper.cc +++ b/server/imserver/synchelper.cc @@ -1,6 +1,7 @@ #include "precompile.h" #include +#include #include "synchelper.h" #include "player.h" @@ -22,16 +23,58 @@ void SyncHelper::UnInit() void SyncHelper::SyncNewFriend(Player* hum, const std::string& target_id) { - ss::SS_IM_FriendAgreeRequest notifymsg; - notifymsg.set_target_id(target_id); - BroadcastIMConnMsg(notifymsg); + ss::SS_IM_FriendAgreeRequest* notifymsg = new ss::SS_IM_FriendAgreeRequest; + hum->FillIMMsgConext(notifymsg->mutable_context()); + notifymsg->set_target_id(target_id); + BroadcastIMConnMsg(*notifymsg); + pending_request_hash_[notifymsg->context().seqid()] = + a8::Timer::Instance()->AddDeadLineTimer + ( + 1000 * 10, + a8::XParams() + .SetSender(notifymsg) + .SetParam1(notifymsg->context().seqid()), + [] (const a8::XParams& param) + { + ss::SS_IM_FriendAgreeRequest* notifymsg = + (ss::SS_IM_FriendAgreeRequest*)param.sender.GetUserData(); + }, + [] (const a8::XParams& param) + { + ss::SS_IM_FriendAgreeRequest* notifymsg = + (ss::SS_IM_FriendAgreeRequest*)param.sender.GetUserData(); + delete notifymsg; + SyncHelper::Instance()->RemovePendingRequest(param.param1); + } + ); } void SyncHelper::SyncDeleteFriend(Player* hum, const std::string& target_id) { - ss::SS_IM_FriendDeleteRequest notifymsg; - notifymsg.set_target_id(target_id); - BroadcastIMConnMsg(notifymsg); + ss::SS_IM_FriendDeleteRequest* notifymsg = new ss::SS_IM_FriendDeleteRequest(); + hum->FillIMMsgConext(notifymsg->mutable_context()); + notifymsg->set_target_id(target_id); + BroadcastIMConnMsg(*notifymsg); + pending_request_hash_[notifymsg->context().seqid()] = + a8::Timer::Instance()->AddDeadLineTimer + ( + 1000 * 10, + a8::XParams() + .SetSender(notifymsg) + .SetParam1(notifymsg->context().seqid()), + [] (const a8::XParams& param) + { + ss::SS_IM_FriendDeleteRequest* notifymsg = + (ss::SS_IM_FriendDeleteRequest*)param.sender.GetUserData(); + }, + [] (const a8::XParams& param) + { + ss::SS_IM_FriendDeleteRequest* notifymsg = + (ss::SS_IM_FriendDeleteRequest*)param.sender.GetUserData(); + delete notifymsg; + SyncHelper::Instance()->RemovePendingRequest(param.param1); + } + ); } void SyncHelper::SyncUpdateFriend(Player* hum, const std::string& target_id) @@ -72,10 +115,23 @@ void SyncHelper::BroadcastIMConnMsg(int msgid, ::google::protobuf::Message& msg) void SyncHelper::_SS_IM_FriendAgreeResponse(f8::MsgHdr& hdr, const ss::SS_IM_FriendAgreeResponse& msg) { - + auto itr = pending_request_hash_.find(msg.context().seqid()); + if (itr != pending_request_hash_.end()) { + a8::Timer::Instance()->DeleteTimer(itr->second); + RemovePendingRequest(msg.context().seqid()); + } } void SyncHelper::_SS_IM_FriendDeleteResponse(f8::MsgHdr& hdr, const ss::SS_IM_FriendDeleteResponse& msg) { - + auto itr = pending_request_hash_.find(msg.context().seqid()); + if (itr != pending_request_hash_.end()) { + a8::Timer::Instance()->DeleteTimer(itr->second); + RemovePendingRequest(msg.context().seqid()); + } +} + +void SyncHelper::RemovePendingRequest(long long seqid) +{ + pending_request_hash_.erase(seqid); } diff --git a/server/imserver/synchelper.h b/server/imserver/synchelper.h index 895eb37..85a8c48 100644 --- a/server/imserver/synchelper.h +++ b/server/imserver/synchelper.h @@ -7,16 +7,17 @@ namespace ss } class Player; +struct timer_list; class SyncHelper : public a8::Singleton { - public: +public: enum { HID = HID_SyncHelper }; - private: +private: SyncHelper() {}; friend class a8::Singleton; - public: +public: void Init(); void UnInit(); @@ -27,7 +28,11 @@ class SyncHelper : public a8::Singleton void _SS_IM_FriendAgreeResponse(f8::MsgHdr& hdr, const ss::SS_IM_FriendAgreeResponse& msg); void _SS_IM_FriendDeleteResponse(f8::MsgHdr& hdr, const ss::SS_IM_FriendDeleteResponse& msg); - private: +private: + + void RemovePendingRequest(long long seqid); + +private: template void BroadcastIMConnMsg(T& msg) { @@ -36,4 +41,6 @@ class SyncHelper : public a8::Singleton } void BroadcastIMConnMsg(int msgid, ::google::protobuf::Message& msg); + + std::map pending_request_hash_; };