aozhiwei 692aed8c05 1
2020-06-15 19:31:10 +08:00

125 lines
4.2 KiB
C++

#pragma once
#include "cs_proto.pb.h"
#include "ss_proto.pb.h"
#include "WSListener.h"
struct Friend;
struct timer_list;
class Player
{
public:
enum { HID = HID_Player };
public:
int socket_handle = 0;
a8::TimerAttacher timer_attacher;
Friend data;
int today_invite_times = 0;
int last_invite_time = 0;
public:
void Init();
void UnInit();
void Deserialize(const ss::MFUserDB& friend_db);
void Serialize(ss::MFUserDB& friend_db);
template <typename T>
void SendMsg(T& msg)
{
WSListener::Instance()->SendToClient(socket_handle, 0, msg);
}
template <typename T>
void SendSSMsg(const Friend& friend_data, T& msg)
{
static int msgid = f8::Net_GetMessageId(msg);
InternalSendSSMsg(friend_data, msgid, msg);
}
template <typename T>
void SendSSMsg(const std::vector<Friend*> friend_list, T& msg)
{
static int msgid = f8::Net_GetMessageId(msg);
for (auto& friend_data : friend_list) {
InternalSendSSMsg(*friend_data, msgid, msg);
}
}
template <typename T>
void BoradcastSSMsg(const T& msg)
{
static int msgid = f8::Net_GetMessageId(msg);
InternalSendSSMsg(data, msgid, msg);
BoradcastExcludeSSMsg(msg);
}
template <typename T>
void BoradcastExcludeSSMsg(const T& msg)
{
static int msgid = f8::Net_GetMessageId(msg);
for (auto& pair : friend_hash_) {
InternalSendSSMsg(pair.second, msgid, msg);
}
}
void _CMUpdateUserInfo(f8::MsgHdr& hdr, const cs::CMUpdateUserInfo& msg);
void _CMUpdateTempCustomData(f8::MsgHdr& hdr, const cs::CMUpdateTempCustomData& msg);
void _CMFriendList(f8::MsgHdr& hdr, const cs::CMFriendList& msg);
void _CMFriendApply(f8::MsgHdr& hdr, const cs::CMFriendApply& msg);
void _CMFriendApplyList(f8::MsgHdr& hdr, const cs::CMFriendApplyList& msg);
void _CMFriendAgree(f8::MsgHdr& hdr, const cs::CMFriendAgree& msg);
void _CMFriendIgnore(f8::MsgHdr& hdr, const cs::CMFriendIgnore& msg);
void _CMFriendDelete(f8::MsgHdr& hdr, const cs::CMFriendDelete& msg);
void _CMFriendBlackList(f8::MsgHdr& hdr, const cs::CMFriendBlackList& msg);
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);
void _CMGroupKick(f8::MsgHdr& hdr, const cs::CMGroupKick& msg);
void _CMGroupQuit(f8::MsgHdr& hdr, const cs::CMGroupQuit& msg);
void _CMGroupDismiss(f8::MsgHdr& hdr, const cs::CMGroupDismiss& msg);
void _CMGroupRename(f8::MsgHdr& hdr, const cs::CMGroupRename& msg);
void ReLogin(f8::MsgHdr& hdr, const cs::CMLogin& msg);
void NotifyOnline();
void NotifyOffline();
void NotifyUserInfoUpdate(Friend* friend_data);
const std::string AccountId();
private:
void FillFriendList(::google::protobuf::RepeatedPtrField< ::cs::MFUserInfo >* friend_list);
void FillIMMsgConext(f8::MsgHdr& hdr, ss::MFIMMsgConext* conext);
void FillMFUserInfo(cs::MFUserInfo* user_info);
void ForwardGroupCMMsg(f8::MsgHdr& hdr, long long hash_code);
void SaveToDB();
Friend* GetFriendById(const std::string& friend_id);
void FillApplyList(const cs::MFPaging& paging, cs::SMFriendApplyList& respmsg);
void SyncLocToMasterServer();
void MarkDirty();
void OnDataVersion1Change();
void OnTempCustomDataChange();
void InternalSendSSMsg(const Friend& friend_data,
int msgid,
::google::protobuf::Message& msg);
void InternalUpdateUserInfo();
private:
bool dirty_ = false;
timer_list* dirty_timer_ = nullptr;
timer_list* update_user_info_timer_ = nullptr;
long long last_apply_idx_ = 0;
std::map<std::string, Friend> friend_hash_;
std::map<long long, FriendApply*> apply_hash_;
std::list<FriendApply> apply_list_;
};