1
This commit is contained in:
parent
f9b0747b38
commit
692aed8c05
@ -12,6 +12,7 @@
|
|||||||
#include "dbengine.h"
|
#include "dbengine.h"
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
#include "typeconvert.h"
|
#include "typeconvert.h"
|
||||||
|
#include "playermgr.h"
|
||||||
|
|
||||||
#include "IMConn.h"
|
#include "IMConn.h"
|
||||||
#include "IMConnMgr.h"
|
#include "IMConnMgr.h"
|
||||||
@ -20,7 +21,8 @@
|
|||||||
|
|
||||||
void Player::Init()
|
void Player::Init()
|
||||||
{
|
{
|
||||||
crc32_code = a8::openssl::Crc32
|
data.hum = this;
|
||||||
|
data.crc32_code = a8::openssl::Crc32
|
||||||
(
|
(
|
||||||
(unsigned char*)data.base_data.account_id.data(),
|
(unsigned char*)data.base_data.account_id.data(),
|
||||||
data.base_data.account_id.size()
|
data.base_data.account_id.size()
|
||||||
@ -32,6 +34,11 @@ void Player::Init()
|
|||||||
void Player::UnInit()
|
void Player::UnInit()
|
||||||
{
|
{
|
||||||
timer_attacher.ClearTimerList();
|
timer_attacher.ClearTimerList();
|
||||||
|
for (auto& pair : friend_hash_) {
|
||||||
|
if (!list_empty(&pair.second.watch_node)) {
|
||||||
|
PlayerMgr::Instance()->UnWatchPlayer(pair.second);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::Deserialize(const ss::MFUserDB& user_db)
|
void Player::Deserialize(const ss::MFUserDB& user_db)
|
||||||
@ -45,6 +52,11 @@ void Player::Deserialize(const ss::MFUserDB& user_db)
|
|||||||
);;
|
);;
|
||||||
friend_hash_[friendobj.base_data.account_id] = friendobj;
|
friend_hash_[friendobj.base_data.account_id] = friendobj;
|
||||||
}
|
}
|
||||||
|
for (auto& pair : friend_hash_) {
|
||||||
|
pair.second.hum = this;
|
||||||
|
INIT_LIST_HEAD(&pair.second.watch_node);
|
||||||
|
PlayerMgr::Instance()->WatchPlayer(pair.second);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::Serialize(ss::MFUserDB& user_db)
|
void Player::Serialize(ss::MFUserDB& user_db)
|
||||||
@ -154,7 +166,7 @@ void Player::_CMFriendApply(f8::MsgHdr& hdr, const cs::CMFriendApply& msg)
|
|||||||
void Player::_CMFriendApplyList(f8::MsgHdr& hdr, const cs::CMFriendApplyList& msg)
|
void Player::_CMFriendApplyList(f8::MsgHdr& hdr, const cs::CMFriendApplyList& msg)
|
||||||
{
|
{
|
||||||
if (last_apply_idx_ > 0 &&
|
if (last_apply_idx_ > 0 &&
|
||||||
last_apply_idx_ >= DBEngine::Instance()->GetFriendApplyCurrIdx(crc32_code)) {
|
last_apply_idx_ >= DBEngine::Instance()->GetFriendApplyCurrIdx(data.crc32_code)) {
|
||||||
cs::SMFriendApplyList respmsg;
|
cs::SMFriendApplyList respmsg;
|
||||||
FillApplyList(msg.paging(), respmsg);
|
FillApplyList(msg.paging(), respmsg);
|
||||||
SendMsg(respmsg);
|
SendMsg(respmsg);
|
||||||
@ -203,7 +215,7 @@ void Player::_CMFriendApplyList(f8::MsgHdr& hdr, const cs::CMFriendApplyList& ms
|
|||||||
|
|
||||||
cs::MFPaging* paging_copy = nullptr;
|
cs::MFPaging* paging_copy = nullptr;
|
||||||
*paging_copy = msg.paging();
|
*paging_copy = msg.paging();
|
||||||
a8::XObject conn_info = DBEngine::Instance()->GetConnInfo(crc32_code);
|
a8::XObject conn_info = DBEngine::Instance()->GetConnInfo(data.crc32_code);
|
||||||
DBEngine::Instance()->ExecAsyncScript
|
DBEngine::Instance()->ExecAsyncScript
|
||||||
(
|
(
|
||||||
conn_info,
|
conn_info,
|
||||||
@ -220,7 +232,7 @@ void Player::_CMFriendApplyList(f8::MsgHdr& hdr, const cs::CMFriendApplyList& ms
|
|||||||
.SetParam2(paging_copy),
|
.SetParam2(paging_copy),
|
||||||
on_ok,
|
on_ok,
|
||||||
on_error,
|
on_error,
|
||||||
crc32_code
|
data.crc32_code
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -464,7 +476,7 @@ void Player::SaveToDB()
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
a8::XObject conn_info = DBEngine::Instance()->GetConnInfo(crc32_code);
|
a8::XObject conn_info = DBEngine::Instance()->GetConnInfo(data.crc32_code);
|
||||||
DBEngine::Instance()->
|
DBEngine::Instance()->
|
||||||
ExecAsyncScript(
|
ExecAsyncScript(
|
||||||
conn_info,
|
conn_info,
|
||||||
@ -484,7 +496,7 @@ void Player::SaveToDB()
|
|||||||
a8::XParams(),
|
a8::XParams(),
|
||||||
on_ok,
|
on_ok,
|
||||||
on_error,
|
on_error,
|
||||||
crc32_code
|
data.crc32_code
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -608,3 +620,9 @@ void Player::InternalUpdateUserInfo()
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Player::NotifyUserInfoUpdate(Friend* friend_data)
|
||||||
|
{
|
||||||
|
cs::SMUserInfoUpdate msg;
|
||||||
|
SendMsg(msg);
|
||||||
|
}
|
||||||
|
@ -13,7 +13,6 @@ class Player
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
int socket_handle = 0;
|
int socket_handle = 0;
|
||||||
unsigned int crc32_code = 0;
|
|
||||||
a8::TimerAttacher timer_attacher;
|
a8::TimerAttacher timer_attacher;
|
||||||
|
|
||||||
Friend data;
|
Friend data;
|
||||||
@ -92,6 +91,7 @@ class Player
|
|||||||
void ReLogin(f8::MsgHdr& hdr, const cs::CMLogin& msg);
|
void ReLogin(f8::MsgHdr& hdr, const cs::CMLogin& msg);
|
||||||
void NotifyOnline();
|
void NotifyOnline();
|
||||||
void NotifyOffline();
|
void NotifyOffline();
|
||||||
|
void NotifyUserInfoUpdate(Friend* friend_data);
|
||||||
|
|
||||||
const std::string AccountId();
|
const std::string AccountId();
|
||||||
|
|
||||||
|
@ -42,7 +42,13 @@ void PlayerMgr::_SS_IM_SendCustomMsg(f8::MsgHdr& hdr, const ss::SS_IM_SendCustom
|
|||||||
|
|
||||||
void PlayerMgr::_SS_IM_UpdateUserInfo(f8::MsgHdr& hdr, const ss::SS_IM_UpdateUserInfo& msg)
|
void PlayerMgr::_SS_IM_UpdateUserInfo(f8::MsgHdr& hdr, const ss::SS_IM_UpdateUserInfo& msg)
|
||||||
{
|
{
|
||||||
|
auto itr = watch_players_.find(msg.user_info().base_data().account_id());
|
||||||
|
if (itr != watch_players_.end()) {
|
||||||
|
struct Friend *node, *tmp;
|
||||||
|
list_for_each_entry_safe(node, tmp, &itr->second, watch_node) {
|
||||||
|
node->hum->NotifyUserInfoUpdate(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerMgr::_CMLogin(f8::MsgHdr& hdr, const cs::CMLogin& msg)
|
void PlayerMgr::_CMLogin(f8::MsgHdr& hdr, const cs::CMLogin& msg)
|
||||||
@ -66,6 +72,40 @@ void PlayerMgr::_CMLogin(f8::MsgHdr& hdr, const cs::CMLogin& msg)
|
|||||||
AsyncLogin1(msg);
|
AsyncLogin1(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PlayerMgr::WatchPlayer(Friend& friend_data)
|
||||||
|
{
|
||||||
|
#ifdef DEBUG
|
||||||
|
if (!list_empty(&friend_data.watch_node)) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
auto itr = watch_players_.find(friend_data.base_data.account_id);
|
||||||
|
if (itr == watch_players_.end()) {
|
||||||
|
watch_players_[friend_data.base_data.account_id] = list_head();
|
||||||
|
itr = watch_players_.find(friend_data.base_data.account_id);
|
||||||
|
if (itr == watch_players_.end()) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
INIT_LIST_HEAD(&itr->second);
|
||||||
|
}
|
||||||
|
list_add(&friend_data.watch_node, &itr->second);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlayerMgr::UnWatchPlayer(Friend& friend_data)
|
||||||
|
{
|
||||||
|
if (!list_empty(&friend_data.watch_node)) {
|
||||||
|
list_del_init(&friend_data.watch_node);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
auto itr = watch_players_.find(friend_data.base_data.account_id);
|
||||||
|
if (itr != watch_players_.end()) {
|
||||||
|
if (list_empty(&itr->second)) {
|
||||||
|
watch_players_.erase(itr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int PlayerMgr::OnlineNum()
|
int PlayerMgr::OnlineNum()
|
||||||
{
|
{
|
||||||
return socket_hash_.size();
|
return socket_hash_.size();
|
||||||
|
@ -41,6 +41,8 @@ class PlayerMgr : public a8::Singleton<PlayerMgr>
|
|||||||
Player* GetPlayerByAccountId(const std::string& account_id);
|
Player* GetPlayerByAccountId(const std::string& account_id);
|
||||||
void ReBindSocket(int socket_handle, Player* hum);
|
void ReBindSocket(int socket_handle, Player* hum);
|
||||||
void OnWSProxyDisconnect(a8::XParams& param);
|
void OnWSProxyDisconnect(a8::XParams& param);
|
||||||
|
void WatchPlayer(Friend& friend_data);
|
||||||
|
void UnWatchPlayer(Friend& friend_data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int OnlineNum();
|
int OnlineNum();
|
||||||
@ -72,4 +74,6 @@ class PlayerMgr : public a8::Singleton<PlayerMgr>
|
|||||||
|
|
||||||
std::map<int, std::tuple<std::string, f8::MsgHdr*>> pending_socket_hash_;
|
std::map<int, std::tuple<std::string, f8::MsgHdr*>> pending_socket_hash_;
|
||||||
std::map<std::string, f8::MsgHdr*> pending_account_hash_;
|
std::map<std::string, f8::MsgHdr*> pending_account_hash_;
|
||||||
|
|
||||||
|
std::map<std::string, list_head> watch_players_;
|
||||||
};
|
};
|
||||||
|
@ -33,7 +33,14 @@ struct Friend
|
|||||||
std::string server_key;
|
std::string server_key;
|
||||||
long long server_instance_id = 0;
|
long long server_instance_id = 0;
|
||||||
|
|
||||||
|
class Player* hum = nullptr;
|
||||||
|
list_head watch_node;
|
||||||
unsigned int crc32_code = 0;
|
unsigned int crc32_code = 0;
|
||||||
|
|
||||||
|
Friend()
|
||||||
|
{
|
||||||
|
INIT_LIST_HEAD(&watch_node);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FriendApply
|
struct FriendApply
|
||||||
|
Loading…
x
Reference in New Issue
Block a user