This commit is contained in:
aozhiwei 2020-06-13 22:41:57 +08:00
parent 4d8542cbfd
commit 2a218d6dd5
4 changed files with 103 additions and 47 deletions

View File

@ -57,6 +57,9 @@ void HandlerMgr::RegisterNetMsgHandlers()
RegisterNetMsgHandler(&wsmsghandler, &Player::_CMFriendAddBlack);
RegisterNetMsgHandler(&wsmsghandler, &Player::_CMFriendDeleteBlack);
RegisterNetMsgHandler(&wsmsghandler, &Player::_CMSendChatMsg);
RegisterNetMsgHandler(&wsmsghandler, &Player::_CMSendCustomMsg);
RegisterNetMsgHandler(&wsmsghandler, &Player::_CMGroupCreate);
RegisterNetMsgHandler(&wsmsghandler, &Player::_CMGroupJoin);
RegisterNetMsgHandler(&wsmsghandler, &Player::_CMGroupAgree);

View File

@ -16,8 +16,8 @@
void Player::Init()
{
crc32_code = a8::openssl::Crc32(
(unsigned char*)account_id.data(),
account_id.size()
(unsigned char*)data.base_data.account_id.data(),
data.base_data.account_id.size()
);
SyncLocToMasterServer();
NotifyOnline();
@ -34,8 +34,8 @@ void Player::Deserialize(const ss::MFUserDB& user_db)
Friend friendobj;
TypeConvert::Convert(friend_db.base_data(), friendobj.base_data);
friendobj.crc32_code = a8::openssl::Crc32(
(unsigned char*)account_id.data(),
account_id.size()
(unsigned char*)data.base_data.account_id.data(),
data.base_data.account_id.size()
);;
friend_hash_[friendobj.base_data.account_id] = friendobj;
}
@ -51,12 +51,40 @@ void Player::Serialize(ss::MFUserDB& user_db)
void Player::_CMUpdateUserInfo(f8::MsgHdr& hdr, const cs::CMUpdateUserInfo& msg)
{
if (msg.has_nickname()) {
data.base_data.nickname = msg.nickname();
}
if (msg.has_avatar_url()) {
data.base_data.avatar_url = msg.avatar_url();
}
if (msg.has_sex()) {
data.base_data.sex = msg.sex();
}
if (msg.has_user_value1()) {
data.base_data.user_value1 = msg.user_value1();
}
if (msg.has_user_value2()) {
data.base_data.user_value2 = msg.user_value2();
}
if (msg.has_user_value3()) {
data.base_data.user_value3 = msg.user_value3();
}
++data.base_data.data_version1;
OnDataVersion1Change();
}
void Player::_CMUpdateTempCustomData(f8::MsgHdr& hdr, const cs::CMUpdateTempCustomData& msg)
{
if (msg.temp_custom_data().has_value1()) {
data.temp_custom_data.value1 = msg.temp_custom_data().value1();
}
if (msg.temp_custom_data().has_value2()) {
data.temp_custom_data.value2 = msg.temp_custom_data().value2();
}
if (msg.temp_custom_data().has_value3()) {
data.temp_custom_data.value2 = msg.temp_custom_data().value3();
}
OnTempCustomDataChange();
}
void Player::_CMFriendList(f8::MsgHdr& hdr, const cs::CMFriendList& msg)
@ -101,12 +129,12 @@ void Player::_CMFriendApply(f8::MsgHdr& hdr, const cs::CMFriendApply& msg)
{
App::Instance()->NewUUID(),
msg.friend_id(),
account_id,
nickname,
avatar_url,
sex,
group_id,
data_version1,
data.base_data.account_id,
data.base_data.nickname,
data.base_data.avatar_url,
data.base_data.sex,
data.base_data.group_id,
data.base_data.data_version1,
App::Instance()->nowtime
},
a8::XParams(),
@ -178,10 +206,10 @@ void Player::_CMFriendApplyList(f8::MsgHdr& hdr, const cs::CMFriendApplyList& ms
"FROM friend_apply WHERE %d > idx AND target_id='%s';",
{
last_apply_idx_,
account_id
data.base_data.account_id
},
a8::XParams()
.SetSender(account_id)
.SetSender(data.base_data.account_id)
.SetParam1(hdr.socket_handle)
.SetParam2(paging_copy),
on_ok,
@ -228,9 +256,19 @@ void Player::_CMFriendDeleteBlack(f8::MsgHdr& hdr, const cs::CMFriendDeleteBlack
}
void Player::_CMSendChatMsg(f8::MsgHdr& hdr, const cs::CMSendChatMsg& msg)
{
}
void Player::_CMSendCustomMsg(f8::MsgHdr& hdr, const cs::CMSendCustomMsg& msg)
{
}
void Player::_CMGroupCreate(f8::MsgHdr& hdr, const cs::CMGroupCreate& msg)
{
if (group_id != 0) {
if (data.base_data.group_id != 0) {
cs::SMGroupCreate respmsg;
respmsg.set_errcode(1);
respmsg.set_errmsg("你已经有群");
@ -242,74 +280,74 @@ void Player::_CMGroupCreate(f8::MsgHdr& hdr, const cs::CMGroupCreate& msg)
void Player::_CMGroupJoin(f8::MsgHdr& hdr, const cs::CMGroupJoin& msg)
{
if (group_id != 0) {
if (data.base_data.group_id != 0) {
cs::SMGroupJoin respmsg;
respmsg.set_errcode(1);
respmsg.set_errmsg("你已经有群");
SendMsg(respmsg);
return;
}
ForwardGroupCMMsg(hdr, group_id);
ForwardGroupCMMsg(hdr, data.base_data.group_id);
}
void Player::_CMGroupAgree(f8::MsgHdr& hdr, const cs::CMGroupAgree& msg)
{
if (group_id == 0) {
if (data.base_data.group_id == 0) {
cs::SMGroupAgree respmsg;
respmsg.set_errcode(2);
respmsg.set_errmsg("你还没有群");
SendMsg(respmsg);
return;
}
ForwardGroupCMMsg(hdr, group_id);
ForwardGroupCMMsg(hdr, data.base_data.group_id);
}
void Player::_CMGroupKick(f8::MsgHdr& hdr, const cs::CMGroupKick& msg)
{
if (group_id == 0) {
if (data.base_data.group_id == 0) {
cs::SMGroupKick respmsg;
respmsg.set_errcode(2);
respmsg.set_errmsg("你还没有群");
SendMsg(respmsg);
return;
}
ForwardGroupCMMsg(hdr, group_id);
ForwardGroupCMMsg(hdr, data.base_data.group_id);
}
void Player::_CMGroupQuit(f8::MsgHdr& hdr, const cs::CMGroupQuit& msg)
{
if (group_id == 0) {
if (data.base_data.group_id == 0) {
cs::SMGroupQuit respmsg;
respmsg.set_errcode(2);
respmsg.set_errmsg("你还没有群");
SendMsg(respmsg);
return;
}
ForwardGroupCMMsg(hdr, group_id);
ForwardGroupCMMsg(hdr, data.base_data.group_id);
}
void Player::_CMGroupDismiss(f8::MsgHdr& hdr, const cs::CMGroupDismiss& msg)
{
if (group_id == 0) {
if (data.base_data.group_id == 0) {
cs::SMGroupQuit respmsg;
respmsg.set_errcode(2);
respmsg.set_errmsg("你还没有群");
SendMsg(respmsg);
return;
}
ForwardGroupCMMsg(hdr, group_id);
ForwardGroupCMMsg(hdr, data.base_data.group_id);
}
void Player::_CMGroupRename(f8::MsgHdr& hdr, const cs::CMGroupRename& msg)
{
if (group_id == 0) {
if (data.base_data.group_id == 0) {
cs::SMGroupRename respmsg;
respmsg.set_errcode(2);
respmsg.set_errmsg("你还没有群");
SendMsg(respmsg);
return;
}
ForwardGroupCMMsg(hdr, group_id);
ForwardGroupCMMsg(hdr, data.base_data.group_id);
}
void Player::ReLogin(f8::MsgHdr& hdr, const cs::CMLogin& msg)
@ -347,10 +385,10 @@ void Player::FillFriendList(::google::protobuf::RepeatedPtrField< ::cs::MFUserIn
void Player::FillIMMsgConext(f8::MsgHdr& hdr, ss::MFIMMsgConext* conext)
{
conext->set_socket_handle(hdr.socket_handle);
conext->set_account_id(account_id);
conext->set_nickname(nickname);
conext->set_avatar_url(avatar_url);
conext->set_sex(sex);
conext->set_account_id(data.base_data.account_id);
conext->set_nickname(data.base_data.nickname);
conext->set_avatar_url(data.base_data.avatar_url);
conext->set_sex(data.base_data.sex);
#if 1
conext->set_online(true);
#else
@ -420,12 +458,12 @@ void Player::SaveToDB()
{
friend_data,
App::Instance()->nowtime,
nickname,
avatar_url,
sex,
group_id,
data_version1,
account_id
data.base_data.nickname,
data.base_data.avatar_url,
data.base_data.sex,
data.base_data.group_id,
data.base_data.data_version1,
data.base_data.account_id
},
a8::XParams(),
on_ok,
@ -453,3 +491,13 @@ void Player::FillApplyList(const cs::MFPaging& paging, cs::SMFriendApplyList& re
*respmsg.mutable_paging() = paging;
respmsg.mutable_paging()->set_total_page(ceil(i / paging.page_size()));
}
void Player::OnDataVersion1Change()
{
}
void Player::OnTempCustomDataChange()
{
}

View File

@ -44,6 +44,9 @@ class Player
void _CMFriendAddBlack(f8::MsgHdr& hdr, const cs::CMFriendAddBlack& msg);
void _CMFriendDeleteBlack(f8::MsgHdr& hdr, const cs::CMFriendDeleteBlack& msg);
void _CMSendChatMsg(f8::MsgHdr& hdr, const cs::CMSendChatMsg& msg);
void _CMSendCustomMsg(f8::MsgHdr& hdr, const cs::CMSendCustomMsg& msg);
void _CMGroupCreate(f8::MsgHdr& hdr, const cs::CMGroupCreate& msg);
void _CMGroupJoin(f8::MsgHdr& hdr, const cs::CMGroupJoin& msg);
void _CMGroupAgree(f8::MsgHdr& hdr, const cs::CMGroupAgree& msg);
@ -65,6 +68,8 @@ private:
void SaveToDB();
Friend* GetFriendById(const std::string& friend_id);
void FillApplyList(const cs::MFPaging& paging, cs::SMFriendApplyList& respmsg);
void OnDataVersion1Change();
void OnTempCustomDataChange();
private:
bool dirty_ = false;

View File

@ -280,15 +280,15 @@ void PlayerMgr::AsyncLoginOnOk(const std::string& account_id,
{
hum = new Player();
hum->socket_handle = hdr->socket_handle;
hum->account_id = account_id;
hum->nickname = nickname;
hum->avatar_url = avatar_url;
hum->sex = sex;
hum->group_id = group_id;
hum->data_version1 = data_version1;
hum->user_value1 = user_value1;
hum->user_value2 = user_value2;
hum->user_value3 = user_value3;
hum->data.base_data.account_id = account_id;
hum->data.base_data.nickname = nickname;
hum->data.base_data.avatar_url = avatar_url;
hum->data.base_data.sex = sex;
hum->data.base_data.group_id = group_id;
hum->data.base_data.data_version1 = data_version1;
hum->data.base_data.user_value1 = user_value1;
hum->data.base_data.user_value2 = user_value2;
hum->data.base_data.user_value3 = user_value3;
hum->Init();
{
ss::MFUserDB user_db;
@ -331,7 +331,7 @@ void PlayerMgr::OnClientSocketDisconnect(int socket_handle)
hum->NotifyOffline();
hum->UnInit();
socket_hash_.erase(socket_handle);
accountid_hash_.erase(hum->account_id);
accountid_hash_.erase(hum->data.base_data.account_id);
}
}
#ifdef DEBUG