This commit is contained in:
aozhiwei 2020-06-19 14:33:14 +08:00
parent 8235f6016f
commit 9c711f3e62
4 changed files with 80 additions and 17 deletions

View File

@ -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);
}

View File

@ -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);

View File

@ -1,6 +1,7 @@
#include "precompile.h"
#include <a8/openssl.h>
#include <a8/timer.h>
#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);
}

View File

@ -7,16 +7,17 @@ namespace ss
}
class Player;
struct timer_list;
class SyncHelper : public a8::Singleton<SyncHelper>
{
public:
public:
enum { HID = HID_SyncHelper };
private:
private:
SyncHelper() {};
friend class a8::Singleton<SyncHelper>;
public:
public:
void Init();
void UnInit();
@ -27,7 +28,11 @@ class SyncHelper : public a8::Singleton<SyncHelper>
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 <typename T>
void BroadcastIMConnMsg(T& msg)
{
@ -36,4 +41,6 @@ class SyncHelper : public a8::Singleton<SyncHelper>
}
void BroadcastIMConnMsg(int msgid, ::google::protobuf::Message& msg);
std::map<long long, timer_list*> pending_request_hash_;
};