完成玩家状态查询协议
This commit is contained in:
parent
191c12cd03
commit
a5d5af84db
@ -1,15 +1,39 @@
|
|||||||
#include "precompile.h"
|
#include "precompile.h"
|
||||||
|
|
||||||
|
#include <a8/timer.h>
|
||||||
|
|
||||||
#include "asynctaskmgr.h"
|
#include "asynctaskmgr.h"
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
|
#include "playermgr.h"
|
||||||
|
|
||||||
#include "cs_proto.pb.h"
|
#include "cs_proto.pb.h"
|
||||||
#include "ss_proto.pb.h"
|
#include "ss_proto.pb.h"
|
||||||
|
|
||||||
struct QueryUserStatusTask
|
struct QueryUserStatusTask
|
||||||
{
|
{
|
||||||
std::vector<std::string> account_ids;
|
long long seqid = 0;
|
||||||
|
std::string account_id;
|
||||||
|
int socket_handle = 0;
|
||||||
|
Player* hum = nullptr;
|
||||||
|
std::map<std::string, bool> users;
|
||||||
|
|
||||||
|
void Done()
|
||||||
|
{
|
||||||
|
if (PlayerMgr::Instance()->GetPlayerByAccountId(account_id) != hum) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (hum->socket_handle != socket_handle) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void AsyncTaskMgr::Init()
|
void AsyncTaskMgr::Init()
|
||||||
@ -24,11 +48,10 @@ void AsyncTaskMgr::UnInit()
|
|||||||
|
|
||||||
void AsyncTaskMgr::CreateQueryUserStatusTask(Player* hum, std::vector<std::string>& account_ids)
|
void AsyncTaskMgr::CreateQueryUserStatusTask(Player* hum, std::vector<std::string>& account_ids)
|
||||||
{
|
{
|
||||||
long long seqid = App::Instance()->NewSeqId();
|
|
||||||
QueryUserStatusTask* task = new QueryUserStatusTask();
|
QueryUserStatusTask* task = new QueryUserStatusTask();
|
||||||
task->account_ids = account_ids;
|
task->account_id = hum->AccountId();
|
||||||
query_user_status_tasks_[seqid] = task;
|
task->socket_handle = hum->socket_handle;
|
||||||
|
task->hum = hum;
|
||||||
{
|
{
|
||||||
ss::SS_IM_QueryUserOnlineState msg;
|
ss::SS_IM_QueryUserOnlineState msg;
|
||||||
hum->FillIMMsgConext(msg.mutable_context());
|
hum->FillIMMsgConext(msg.mutable_context());
|
||||||
@ -36,11 +59,55 @@ void AsyncTaskMgr::CreateQueryUserStatusTask(Player* hum, std::vector<std::strin
|
|||||||
msg.add_account_ids(account_id);
|
msg.add_account_ids(account_id);
|
||||||
}
|
}
|
||||||
hum->SendSSMsg(hum->myself, msg);
|
hum->SendSSMsg(hum->myself, msg);
|
||||||
}
|
|
||||||
|
|
||||||
|
for (auto& account_id : account_ids) {
|
||||||
|
task->users[account_id] = false;
|
||||||
|
}
|
||||||
|
task->seqid = msg.context().seqid();
|
||||||
|
query_user_status_tasks_[task->seqid] = task;
|
||||||
|
}
|
||||||
|
a8::Timer::Instance()->AddDeadLineTimer
|
||||||
|
(
|
||||||
|
200,
|
||||||
|
a8::XParams()
|
||||||
|
.SetSender(task),
|
||||||
|
[] (const a8::XParams& param)
|
||||||
|
{
|
||||||
|
QueryUserStatusTask* task = (QueryUserStatusTask*)param.sender.GetUserData();
|
||||||
|
task->Done();
|
||||||
|
},
|
||||||
|
[] (const a8::XParams& param)
|
||||||
|
{
|
||||||
|
QueryUserStatusTask* task = (QueryUserStatusTask*)param.sender.GetUserData();
|
||||||
|
AsyncTaskMgr::Instance()->RemoveQueryUserStatusTask(task->seqid);
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AsyncTaskMgr::_SS_IM_PushUserOnlineState(f8::MsgHdr& hdr, const ss::SS_IM_PushUserOnlineState& msg)
|
void AsyncTaskMgr::_SS_IM_PushUserOnlineState(f8::MsgHdr& hdr, const ss::SS_IM_PushUserOnlineState& msg)
|
||||||
{
|
{
|
||||||
|
QueryUserStatusTask* task = GetQueryUserStatusTask(msg.context().seqid());
|
||||||
|
if (task) {
|
||||||
|
for (auto& user : msg.user_infos()) {
|
||||||
|
if (task->users.find(user.base_data().account_id()) !=
|
||||||
|
task->users.end()) {
|
||||||
|
task->users[user.base_data().account_id()] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QueryUserStatusTask* AsyncTaskMgr::GetQueryUserStatusTask(long long seqid)
|
||||||
|
{
|
||||||
|
auto itr = query_user_status_tasks_.find(seqid);
|
||||||
|
return itr != query_user_status_tasks_.end() ? itr->second : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AsyncTaskMgr::RemoveQueryUserStatusTask(long long seqid)
|
||||||
|
{
|
||||||
|
auto itr = query_user_status_tasks_.find(seqid);
|
||||||
|
if (itr != query_user_status_tasks_.end()) {
|
||||||
|
delete itr->second;
|
||||||
|
query_user_status_tasks_.erase(itr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,10 @@ public:
|
|||||||
|
|
||||||
void _SS_IM_PushUserOnlineState(f8::MsgHdr& hdr, const ss::SS_IM_PushUserOnlineState& msg);
|
void _SS_IM_PushUserOnlineState(f8::MsgHdr& hdr, const ss::SS_IM_PushUserOnlineState& msg);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QueryUserStatusTask* GetQueryUserStatusTask(long long seqid);
|
||||||
|
void RemoveQueryUserStatusTask(long long seqid);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<long long, QueryUserStatusTask*> query_user_status_tasks_;
|
std::map<long long, QueryUserStatusTask*> query_user_status_tasks_;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user