1
This commit is contained in:
parent
0444971968
commit
9916740715
@ -10,38 +10,52 @@
|
||||
#include "cs_proto.pb.h"
|
||||
#include "ss_proto.pb.h"
|
||||
|
||||
struct QueryUserStatusTask
|
||||
struct AsyncTaskContext
|
||||
{
|
||||
long long seqid = 0;
|
||||
std::string account_id;
|
||||
int socket_handle = 0;
|
||||
Player* hum = nullptr;
|
||||
|
||||
bool IsValid()
|
||||
{
|
||||
if (PlayerMgr::Instance()->GetPlayerByAccountId(account_id) != hum) {
|
||||
return false;
|
||||
}
|
||||
if (hum->socket_handle != socket_handle) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
struct QueryUserStatusTask
|
||||
{
|
||||
AsyncTaskContext context;
|
||||
std::map<std::string, bool> users;
|
||||
|
||||
void Done()
|
||||
{
|
||||
if (PlayerMgr::Instance()->GetPlayerByAccountId(account_id) != hum) {
|
||||
return;
|
||||
}
|
||||
if (hum->socket_handle != socket_handle) {
|
||||
return;
|
||||
}
|
||||
if (context.IsValid()) {
|
||||
cs::SMQueryUserStatus msg;
|
||||
for (auto& pair : users) {
|
||||
cs::MFUserStatus* user = msg.add_status_list();
|
||||
user->set_account_id(pair.first);
|
||||
user->set__online(pair.second ? 1 : 0);
|
||||
}
|
||||
hum->SendMsg(msg);
|
||||
context.hum->SendMsg(msg);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct RecommandFriendTask
|
||||
{
|
||||
AsyncTaskContext context;
|
||||
|
||||
void Done()
|
||||
{
|
||||
|
||||
if (context.IsValid()) {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -58,9 +72,6 @@ void AsyncTaskMgr::UnInit()
|
||||
void AsyncTaskMgr::CreateQueryUserStatusTask(Player* hum, std::vector<std::string>& account_ids)
|
||||
{
|
||||
QueryUserStatusTask* task = new QueryUserStatusTask();
|
||||
task->account_id = hum->AccountId();
|
||||
task->socket_handle = hum->socket_handle;
|
||||
task->hum = hum;
|
||||
{
|
||||
ss::SS_IM_QueryUserOnlineState msg;
|
||||
hum->FillIMMsgConext(msg.mutable_context());
|
||||
@ -72,8 +83,8 @@ void AsyncTaskMgr::CreateQueryUserStatusTask(Player* hum, std::vector<std::strin
|
||||
for (auto& account_id : account_ids) {
|
||||
task->users[account_id] = false;
|
||||
}
|
||||
task->seqid = msg.context().seqid();
|
||||
query_user_status_tasks_[task->seqid] = task;
|
||||
FillAsyncTaskContext(hum, &task->context, msg.context().seqid());
|
||||
query_user_status_tasks_[task->context.seqid] = task;
|
||||
}
|
||||
a8::Timer::Instance()->AddDeadLineTimer
|
||||
(
|
||||
@ -88,7 +99,44 @@ void AsyncTaskMgr::CreateQueryUserStatusTask(Player* hum, std::vector<std::strin
|
||||
[] (const a8::XParams& param)
|
||||
{
|
||||
QueryUserStatusTask* task = (QueryUserStatusTask*)param.sender.GetUserData();
|
||||
AsyncTaskMgr::Instance()->RemoveQueryUserStatusTask(task->seqid);
|
||||
AsyncTaskMgr::Instance()->RemoveQueryUserStatusTask(task->context.seqid);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void AsyncTaskMgr::CreateRecommandFriendTask(Player* hum)
|
||||
{
|
||||
RecommandFriendTask* task = new RecommandFriendTask();
|
||||
{
|
||||
#if 0
|
||||
ss::SS_IM_QueryUserOnlineState msg;
|
||||
hum->FillIMMsgConext(msg.mutable_context());
|
||||
for (auto& account_id : account_ids) {
|
||||
msg.add_account_ids(account_id);
|
||||
}
|
||||
hum->SendSSMsg(hum->myself, msg);
|
||||
|
||||
for (auto& account_id : account_ids) {
|
||||
task->users[account_id] = false;
|
||||
}
|
||||
FillAsyncTaskContext(hum, &task->context, msg.context().seqid());
|
||||
#endif
|
||||
recommand_friend_tasks_[task->context.seqid] = task;
|
||||
}
|
||||
a8::Timer::Instance()->AddDeadLineTimer
|
||||
(
|
||||
200,
|
||||
a8::XParams()
|
||||
.SetSender(task),
|
||||
[] (const a8::XParams& param)
|
||||
{
|
||||
RecommandFriendTask* task = (RecommandFriendTask*)param.sender.GetUserData();
|
||||
task->Done();
|
||||
},
|
||||
[] (const a8::XParams& param)
|
||||
{
|
||||
RecommandFriendTask* task = (RecommandFriendTask*)param.sender.GetUserData();
|
||||
AsyncTaskMgr::Instance()->RemoveRecommandFriendTask(task->context.seqid);
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -135,3 +183,11 @@ void AsyncTaskMgr::RemoveRecommandFriendTask(long long seqid)
|
||||
recommand_friend_tasks_.erase(itr);
|
||||
}
|
||||
}
|
||||
|
||||
void AsyncTaskMgr::FillAsyncTaskContext(Player* hum, AsyncTaskContext* context, long long seqid)
|
||||
{
|
||||
context->seqid = seqid;
|
||||
context->account_id = hum->AccountId();
|
||||
context->socket_handle = hum->socket_handle;
|
||||
context->hum = hum;
|
||||
}
|
||||
|
@ -5,14 +5,9 @@ namespace ss
|
||||
class SS_IM_PushUserOnlineState;
|
||||
}
|
||||
|
||||
enum AsyncTaskType
|
||||
{
|
||||
kAttQueryUserStatus = 0,
|
||||
kAttMax
|
||||
};
|
||||
|
||||
struct QueryUserStatusTask;
|
||||
struct RecommandFriendTask;
|
||||
struct AsyncTaskContext;
|
||||
class Player;
|
||||
class AsyncTaskMgr : public a8::Singleton<AsyncTaskMgr>
|
||||
{
|
||||
@ -25,6 +20,7 @@ public:
|
||||
void UnInit();
|
||||
|
||||
void CreateQueryUserStatusTask(Player* hum, std::vector<std::string>& account_ids);
|
||||
void CreateRecommandFriendTask(Player* hum);
|
||||
|
||||
void _SS_IM_PushUserOnlineState(f8::MsgHdr& hdr, const ss::SS_IM_PushUserOnlineState& msg);
|
||||
|
||||
@ -33,6 +29,7 @@ private:
|
||||
void RemoveQueryUserStatusTask(long long seqid);
|
||||
RecommandFriendTask* GetRecommandFriendTask(long long seqid);
|
||||
void RemoveRecommandFriendTask(long long seqid);
|
||||
void FillAsyncTaskContext(Player* hum, AsyncTaskContext* context, long long seqid);
|
||||
|
||||
private:
|
||||
std::map<long long, QueryUserStatusTask*> query_user_status_tasks_;
|
||||
|
@ -401,6 +401,8 @@ void Player::_CMFriendAddBlack(f8::MsgHdr& hdr, const cs::CMFriendAddBlack& msg)
|
||||
SendMsg(notifymsg);
|
||||
}
|
||||
}
|
||||
cs::SMFriendAddBlack respmsg;
|
||||
SendMsg(respmsg);
|
||||
}
|
||||
|
||||
void Player::_CMFriendDeleteBlack(f8::MsgHdr& hdr, const cs::CMFriendDeleteBlack& msg)
|
||||
@ -416,6 +418,8 @@ void Player::_CMFriendDeleteBlack(f8::MsgHdr& hdr, const cs::CMFriendDeleteBlack
|
||||
black_hash_.erase(friend_data->base_data.account_id);
|
||||
A8_SAFE_DELETE(friend_data);
|
||||
MarkDirty();
|
||||
cs::SMFriendDeleteBlack respmsg;
|
||||
SendMsg(respmsg);
|
||||
}
|
||||
}
|
||||
|
||||
@ -430,7 +434,7 @@ void Player::_CMQueryUserStatus(f8::MsgHdr& hdr, const cs::CMQueryUserStatus& ms
|
||||
|
||||
void Player::_CMRecommandFriend(f8::MsgHdr& hdr, const cs::CMRecommandFriend& msg)
|
||||
{
|
||||
|
||||
AsyncTaskMgr::Instance()->CreateRecommandFriendTask(this);
|
||||
}
|
||||
|
||||
void Player::_CMSendChatMsg(f8::MsgHdr& hdr, const cs::CMSendChatMsg& msg)
|
||||
|
@ -258,3 +258,13 @@ message SS_IM_OnUserOffline
|
||||
{
|
||||
repeated string account_ids = 3;
|
||||
}
|
||||
|
||||
message SS_IM_RandomUsersRequest
|
||||
{
|
||||
repeated string exclude_account_ids = 3;
|
||||
}
|
||||
|
||||
message SS_IM_RandomUsersResponse
|
||||
{
|
||||
repeated string exclude_account_ids = 3;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user