This commit is contained in:
aozhiwei 2020-05-05 11:42:39 +08:00
parent 4a1310c0e8
commit ae45a76bba
4 changed files with 69 additions and 7 deletions

View File

@ -4,7 +4,7 @@
#include "player.h" #include "player.h"
#include "playermgr.h" #include "playermgr.h"
#include "WSListener.h" #include "dbengine.h"
void Player::Init() void Player::Init()
{ {
@ -14,6 +14,7 @@ void Player::Init()
); );
SyncLocToMasterServer(); SyncLocToMasterServer();
NotifyOnline(); NotifyOnline();
AsyncGetFriendList();
} }
void Player::UnInit() void Player::UnInit()
@ -23,22 +24,34 @@ void Player::UnInit()
void Player::_CMFriendList(f8::MsgHdr& hdr, const cs::CMFriendList& msg) void Player::_CMFriendList(f8::MsgHdr& hdr, const cs::CMFriendList& msg)
{ {
cs::SMFriendList respmsg;
if (friend_list_syncok_) {
FillFriendList(respmsg.mutable_friend_list());
} else {
if (!reading_friends_list_) {
AsyncGetFriendList();
}
respmsg.set_error_code(1);
}
SendMsg(respmsg);
} }
void Player::_CMFriendInvite(f8::MsgHdr& hdr, const cs::CMFriendInvite& msg) void Player::_CMFriendInvite(f8::MsgHdr& hdr, const cs::CMFriendInvite& msg)
{ {
cs::SMFriendInvite respmsg;
SendMsg(respmsg);
} }
void Player::_CMFriendIgnore(f8::MsgHdr& hdr, const cs::CMFriendIgnore& msg) void Player::_CMFriendIgnore(f8::MsgHdr& hdr, const cs::CMFriendIgnore& msg)
{ {
cs::SMFriendIgnore respmsg;
SendMsg(respmsg);
} }
void Player::_CMFriendDelete(f8::MsgHdr& hdr, const cs::CMFriendDelete& msg) void Player::_CMFriendDelete(f8::MsgHdr& hdr, const cs::CMFriendDelete& msg)
{ {
cs::SMFriendDelete respmsg;
SendMsg(respmsg);
} }
void Player::_CMGroupCreate(f8::MsgHdr& hdr, const cs::CMGroupCreate& msg) void Player::_CMGroupCreate(f8::MsgHdr& hdr, const cs::CMGroupCreate& msg)
@ -98,3 +111,19 @@ void Player::NotifyOffline()
{ {
} }
void Player::AsyncGetFriendList()
{
}
void Player::FillFriendList(::google::protobuf::RepeatedPtrField< ::cs::MFUserInfo >* friend_list)
{
for (auto& pair : friend_hash_) {
auto p = friend_list->Add();
p->set_account_id(pair.second.account_id);
p->set_nickname(pair.second.nickname);
p->set_avatar_url(pair.second.avatar_url);
p->set_sex(pair.second.sex);
p->set_online(pair.second.online);
}
}

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "cs_proto.pb.h" #include "cs_proto.pb.h"
#include "WSListener.h"
class Player class Player
{ {
@ -17,12 +18,20 @@ class Player
std::string avatar_url; std::string avatar_url;
int sex = 0; int sex = 0;
long long group_id = 0; long long group_id = 0;
int today_invite_times = 0;
int last_invite_time = 0;
int data_version1 = 0; int data_version1 = 0;
public: public:
void Init(); void Init();
void UnInit(); void UnInit();
template <typename T>
void SendMsg(T& msg)
{
WSListener::Instance()->SendToClient(socket_handle, 0, msg);
}
void _CMFriendList(f8::MsgHdr& hdr, const cs::CMFriendList& msg); void _CMFriendList(f8::MsgHdr& hdr, const cs::CMFriendList& msg);
void _CMFriendInvite(f8::MsgHdr& hdr, const cs::CMFriendInvite& msg); void _CMFriendInvite(f8::MsgHdr& hdr, const cs::CMFriendInvite& msg);
void _CMFriendIgnore(f8::MsgHdr& hdr, const cs::CMFriendIgnore& msg); void _CMFriendIgnore(f8::MsgHdr& hdr, const cs::CMFriendIgnore& msg);
@ -40,4 +49,13 @@ class Player
void SyncLocToMasterServer(); void SyncLocToMasterServer();
void NotifyOnline(); void NotifyOnline();
void NotifyOffline(); void NotifyOffline();
private:
void AsyncGetFriendList();
void FillFriendList(::google::protobuf::RepeatedPtrField< ::cs::MFUserInfo >* friend_list);
private:
std::map<std::string, Friend> friend_hash_;
bool reading_friends_list_ = false;
bool friend_list_syncok_ = false;
}; };

View File

@ -11,3 +11,16 @@ struct PerfMonitor
long long in_data_size = 0; long long in_data_size = 0;
long long read_count = 0; long long read_count = 0;
}; };
struct Friend
{
std::string account_id;
std::string nickname;
std::string avatar_url;
int sex = 0;
int online = 0;
int data_version1 = 0;
unsigned int crc32_code = 0;
};

View File

@ -21,7 +21,7 @@ message MFUserInfo
optional string nickname = 2; optional string nickname = 2;
optional string avatar_url = 3; optional string avatar_url = 3;
optional int32 sex = 4; optional int32 sex = 4;
optional int32 status = 5; optional int32 online = 5;
} }
// //
@ -44,7 +44,9 @@ message CMFriendList
} }
message SMFriendList message SMFriendList
{ {
repeated MFUserInfo user_infos = 1; optional int32 error_code = 1;
optional string error_msg = 2;
repeated MFUserInfo friend_list = 3;
} }
message CMFriendInvite message CMFriendInvite