1
This commit is contained in:
parent
16f794e695
commit
53a2339386
@ -51,9 +51,8 @@ void HandlerMgr::RegisterNetMsgHandlers()
|
||||
RegisterNetMsgHandler(&imcmsghandler, &PlayerMgr::_SS_IM_SendChatMsg);
|
||||
RegisterNetMsgHandler(&imcmsghandler, &PlayerMgr::_SS_IM_SendCustomMsg);
|
||||
RegisterNetMsgHandler(&imcmsghandler, &PlayerMgr::_SS_IM_UpdateUserInfo);
|
||||
|
||||
RegisterNetMsgHandler(&imcmsghandler, &Player::_SS_IM_FriendAgreeRequest);
|
||||
RegisterNetMsgHandler(&imcmsghandler, &Player::_SS_IM_FriendDeleteRequest);
|
||||
RegisterNetMsgHandler(&imcmsghandler, &PlayerMgr::_SS_IM_FriendAgreeRequest);
|
||||
RegisterNetMsgHandler(&imcmsghandler, &PlayerMgr::_SS_IM_FriendDeleteRequest);
|
||||
|
||||
RegisterNetMsgHandler(&wsmsghandler, &WSListener::_SS_Ping);
|
||||
|
||||
|
@ -35,7 +35,7 @@ void Player::Init()
|
||||
|
||||
void Player::UnInit()
|
||||
{
|
||||
SaveToDB();
|
||||
SaveToDB(a8::XParams(), nullptr, nullptr);
|
||||
timer_attacher.ClearTimerList();
|
||||
for (auto& pair : friend_hash_) {
|
||||
if (!list_empty(&pair.second->watch_node)) {
|
||||
@ -431,12 +431,58 @@ void Player::_CMGroupRename(f8::MsgHdr& hdr, const cs::CMGroupRename& msg)
|
||||
|
||||
void Player::_SS_IM_FriendAgreeRequest(f8::MsgHdr& hdr, const ss::SS_IM_FriendAgreeRequest& msg)
|
||||
{
|
||||
f8::MsgHdr* hdr_copy = hdr.Clone();
|
||||
ss::SS_IM_FriendAgreeRequest* msg_copy = new ss::SS_IM_FriendAgreeRequest;
|
||||
*msg_copy = msg;
|
||||
SaveToDB
|
||||
(
|
||||
a8::XParams()
|
||||
.SetSender(hdr_copy)
|
||||
.SetParam1(msg_copy),
|
||||
[] (a8::XParams& param, const f8::DataSet* data_set)
|
||||
{
|
||||
f8::MsgHdr* hdr_copy = (f8::MsgHdr*)param.sender.GetUserData();
|
||||
ss::SS_IM_FriendAgreeRequest* msg_copy = (ss::SS_IM_FriendAgreeRequest*)param.param1.GetUserData();
|
||||
|
||||
f8::MsgHdr::Destroy(hdr_copy);
|
||||
delete msg_copy;
|
||||
},
|
||||
[] (a8::XParams& param, int error_code, const std::string& error_msg)
|
||||
{
|
||||
f8::MsgHdr* hdr_copy = (f8::MsgHdr*)param.sender.GetUserData();
|
||||
ss::SS_IM_FriendAgreeRequest* msg_copy = (ss::SS_IM_FriendAgreeRequest*)param.param1.GetUserData();
|
||||
f8::MsgHdr::Destroy(hdr_copy);
|
||||
delete msg_copy;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void Player::_SS_IM_FriendDeleteRequest(f8::MsgHdr& hdr, const ss::SS_IM_FriendDeleteRequest& msg)
|
||||
{
|
||||
f8::MsgHdr* hdr_copy = hdr.Clone();
|
||||
ss::SS_IM_FriendDeleteRequest* msg_copy = new ss::SS_IM_FriendDeleteRequest;
|
||||
*msg_copy = msg;
|
||||
SaveToDB
|
||||
(
|
||||
a8::XParams()
|
||||
.SetSender(hdr_copy)
|
||||
.SetParam1(msg_copy),
|
||||
[] (a8::XParams& param, const f8::DataSet* data_set)
|
||||
{
|
||||
f8::MsgHdr* hdr_copy = (f8::MsgHdr*)param.sender.GetUserData();
|
||||
ss::SS_IM_FriendDeleteRequest* msg_copy = (ss::SS_IM_FriendDeleteRequest*)param.param1.GetUserData();
|
||||
|
||||
f8::MsgHdr::Destroy(hdr_copy);
|
||||
delete msg_copy;
|
||||
},
|
||||
[] (a8::XParams& param, int error_code, const std::string& error_msg)
|
||||
{
|
||||
f8::MsgHdr* hdr_copy = (f8::MsgHdr*)param.sender.GetUserData();
|
||||
ss::SS_IM_FriendDeleteRequest* msg_copy = (ss::SS_IM_FriendDeleteRequest*)param.param1.GetUserData();
|
||||
f8::MsgHdr::Destroy(hdr_copy);
|
||||
delete msg_copy;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void Player::ReLogin(f8::MsgHdr& hdr, const cs::CMLogin& msg)
|
||||
@ -485,64 +531,53 @@ void Player::MarkDirty()
|
||||
{
|
||||
if (!dirty_) {
|
||||
dirty_ = true;
|
||||
dirty_timer_ = a8::Timer::Instance()->
|
||||
AddDeadLineTimerAndAttach(1000 * 60,
|
||||
a8::XParams()
|
||||
.SetSender((void*)this),
|
||||
[] (const a8::XParams& param)
|
||||
{
|
||||
Player* hum = (Player*)param.sender.GetUserData();
|
||||
hum->SaveToDB();
|
||||
},
|
||||
&timer_attacher.timer_list_,
|
||||
[] (const a8::XParams& param)
|
||||
{
|
||||
Player* hum = (Player*)param.sender.GetUserData();
|
||||
hum->dirty_timer_ = nullptr;
|
||||
}
|
||||
);
|
||||
dirty_timer_ = a8::Timer::Instance()->AddDeadLineTimerAndAttach
|
||||
(1000 * 60,
|
||||
a8::XParams()
|
||||
.SetSender((void*)this),
|
||||
[] (const a8::XParams& param)
|
||||
{
|
||||
Player* hum = (Player*)param.sender.GetUserData();
|
||||
hum->SaveToDB(a8::XParams(), nullptr, nullptr);
|
||||
},
|
||||
&timer_attacher.timer_list_,
|
||||
[] (const a8::XParams& param)
|
||||
{
|
||||
Player* hum = (Player*)param.sender.GetUserData();
|
||||
hum->dirty_timer_ = nullptr;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void Player::SaveToDB()
|
||||
void Player::SaveToDB(a8::XParams param, f8::AsyncDBOnOkFunc on_ok, f8::AsyncDBOnErrorFunc on_error)
|
||||
{
|
||||
ss::MFUserDB user_db;
|
||||
Serialize(user_db);
|
||||
std::string friend_data;
|
||||
user_db.SerializeToString(&friend_data);
|
||||
|
||||
auto on_ok =
|
||||
[] (a8::XParams& param, const f8::DataSet* data_set)
|
||||
{
|
||||
|
||||
};
|
||||
auto on_error =
|
||||
[] (a8::XParams& param, int error_code, const std::string& error_msg)
|
||||
{
|
||||
printf("xxxxx=n");
|
||||
};
|
||||
|
||||
a8::XObject conn_info = DBEngine::Instance()->GetConnInfo(myself.crc32_code);
|
||||
DBEngine::Instance()->
|
||||
ExecAsyncScript(
|
||||
conn_info,
|
||||
"UPDATE `user` SET friend_data='%s', modifytime=%d, "
|
||||
" nickname='%s', avatar_url='%s', sex=%d, data_version1=%d "
|
||||
"WHERE account_id='%s';",
|
||||
{
|
||||
friend_data,
|
||||
App::Instance()->nowtime,
|
||||
myself.base_data.nickname,
|
||||
myself.base_data.avatar_url,
|
||||
myself.base_data.sex,
|
||||
myself.base_data.base_data_version,
|
||||
myself.base_data.account_id
|
||||
},
|
||||
a8::XParams(),
|
||||
on_ok,
|
||||
on_error,
|
||||
myself.crc32_code
|
||||
);
|
||||
DBEngine::Instance()->ExecAsyncScript
|
||||
(
|
||||
conn_info,
|
||||
"UPDATE `user` SET friend_data='%s', modifytime=%d, "
|
||||
" nickname='%s', avatar_url='%s', sex=%d, data_version1=%d "
|
||||
"WHERE account_id='%s';",
|
||||
{
|
||||
friend_data,
|
||||
App::Instance()->nowtime,
|
||||
myself.base_data.nickname,
|
||||
myself.base_data.avatar_url,
|
||||
myself.base_data.sex,
|
||||
myself.base_data.base_data_version,
|
||||
myself.base_data.account_id
|
||||
},
|
||||
a8::XParams(),
|
||||
on_ok,
|
||||
on_error,
|
||||
myself.crc32_code
|
||||
);
|
||||
}
|
||||
|
||||
Friend* Player::GetFriendById(const std::string& friend_id)
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "cs_proto.pb.h"
|
||||
#include "ss_proto.pb.h"
|
||||
#include "WSListener.h"
|
||||
#include "dbengine.h"
|
||||
|
||||
struct Friend;
|
||||
struct timer_list;
|
||||
@ -104,7 +105,7 @@ private:
|
||||
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();
|
||||
void SaveToDB(a8::XParams param, f8::AsyncDBOnOkFunc on_ok, f8::AsyncDBOnErrorFunc on_error);
|
||||
Friend* GetFriendById(const std::string& friend_id);
|
||||
void FillApplyList(const cs::MFPaging& paging, cs::SMFriendApplyList& respmsg);
|
||||
void MarkDirty();
|
||||
|
@ -56,6 +56,22 @@ void PlayerMgr::_SS_IM_SendCustomMsg(f8::MsgHdr& hdr, const ss::SS_IM_SendCustom
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerMgr::_SS_IM_FriendAgreeRequest(f8::MsgHdr& hdr, const ss::SS_IM_FriendAgreeRequest& msg)
|
||||
{
|
||||
Player* hum = GetPlayerByAccountId(msg.target_id());
|
||||
if (hum) {
|
||||
hum->_SS_IM_FriendAgreeRequest(hdr, msg);
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerMgr::_SS_IM_FriendDeleteRequest(f8::MsgHdr& hdr, const ss::SS_IM_FriendDeleteRequest& msg)
|
||||
{
|
||||
Player* hum = GetPlayerByAccountId(msg.target_id());
|
||||
if (hum) {
|
||||
hum->_SS_IM_FriendDeleteRequest(hdr, 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());
|
||||
|
@ -34,6 +34,8 @@ class PlayerMgr : public a8::Singleton<PlayerMgr>
|
||||
void _SS_MS_PushUserList(f8::MsgHdr& hdr, const ss::SS_MS_PushUserList& msg);
|
||||
void _SS_IM_SendChatMsg(f8::MsgHdr& hdr, const ss::SS_IM_SendChatMsg& msg);
|
||||
void _SS_IM_SendCustomMsg(f8::MsgHdr& hdr, const ss::SS_IM_SendCustomMsg& msg);
|
||||
void _SS_IM_FriendAgreeRequest(f8::MsgHdr& hdr, const ss::SS_IM_FriendAgreeRequest& msg);
|
||||
void _SS_IM_FriendDeleteRequest(f8::MsgHdr& hdr, const ss::SS_IM_FriendDeleteRequest& msg);
|
||||
|
||||
void _SS_IM_UpdateUserInfo(f8::MsgHdr& hdr, const ss::SS_IM_UpdateUserInfo& msg);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user