#pragma once #include "cs_proto.pb.h" #include "ss_proto.pb.h" #include "WSListener.h" #include "dbengine.h" struct Friend; struct timer_list; class Player { public: enum { HID = HID_Player }; public: int socket_handle = 0; a8::TimerAttacher timer_attacher; Friend myself; RoleData role_data; long ip_saddr = 0; int account_registertime = 0; std::set exclude_account_ids; public: void Init(); void UnInit(); void Deserialize(const ss::MFUserDB& friend_db); void Serialize(ss::MFUserDB& friend_db); template void SendMsg(T& msg) { WSListener::Instance()->SendToClient(socket_handle, 0, msg); } template void SendSSMsg(const Friend& friend_data, T& msg) { static int msgid = f8::Net_GetMessageId(msg); InternalSendSSMsg(friend_data, msgid, msg); } template void SendSSMsg(const std::vector friend_list, T& msg) { static int msgid = f8::Net_GetMessageId(msg); for (auto& friend_data : friend_list) { InternalSendSSMsg(*friend_data, msgid, msg); } } template void BoradcastSSMsg(const T& msg) { static int msgid = f8::Net_GetMessageId(msg); InternalSendSSMsg(myself, msgid, msg); BoradcastExcludeSSMsg(msg); } template void BoradcastExcludeSSMsg(const T& msg) { static int msgid = f8::Net_GetMessageId(msg); for (auto& pair : friend_hash_) { InternalSendSSMsg(pair.second, msgid, msg); } } void _CMPing(f8::MsgHdr& hdr, const cs::CMPing& 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 _CMFriendRefuse(f8::MsgHdr& hdr, const cs::CMFriendRefuse& 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 _CMQueryUserStatus(f8::MsgHdr& hdr, const cs::CMQueryUserStatus& msg); void _CMRecommandFriend(f8::MsgHdr& hdr, const cs::CMRecommandFriend& 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 _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_FriendApply(f8::MsgHdr& hdr, const ss::SS_IM_FriendApply& msg); void ReLogin(f8::MsgHdr& hdr, const cs::CMLogin& msg); void NotifyOnline(); void NotifyOffline(); void NotifyUserInfoUpdate(Friend* friend_data); void FillIMMsgConext(ss::MFIMMsgConext* context); void Update(long long tick); void FillMFUserInfo(cs::MFUserInfo* user_info); const std::string AccountId(); const std::string SessionId(); const std::string NickName(); int GetFriendNum(); private: void FillFriendList(::google::protobuf::RepeatedPtrField< ::cs::MFUserInfo >* friend_list); void FillBlackList(::google::protobuf::RepeatedPtrField< ::cs::MFUserInfo >* black_list); void ForwardGroupCMMsg(f8::MsgHdr& hdr, long long hash_code); void SaveToDB(a8::XParams param, f8::AsyncDBOnOkFunc on_ok, f8::AsyncDBOnErrorFunc on_error); Friend* GetFriendById(const std::string& friend_id); Friend* GetBlackListById(const std::string& friend_id); void FillApplyList(const cs::MFPaging& paging, cs::SMFriendApplyList& respmsg); void MarkDirty(); void OnDataVersion1Change(); void OnTempCustomDataChange(); void InternalSendSSMsg(const Friend& friend_data, int msgid, ::google::protobuf::Message& msg); void InternalUpdateUserInfo(); int AddFriend(Friend* friendobj); void AddBlackList(Friend* friendobj); void RemoveFriend(const std::string& account_id, bool need_sync); void PushFriendList(); void PushBlackList(); void SyncOtherFriend(); void ProcessEventTimerFunc(); void OnFetchEvent(const f8::DataSet* data_set); void ProcessEvent(); void OnFriendAgreeEvent(Event& event); void OnFriendDeleteEvent(Event& event); bool CanAddFriend(const std::string& account_id); void SyncRedPoint(); void OnDailyReset(); void RecalcRedPoint(); void ClearApplyByIdx(long long idx); void ClearApplyBySenderId(const std::string& sender_id); void RefreshFriendData(); void RemoveHandledApply(); void CombineRepeatApply(); void QueryUserOnline(std::vector account_ids); void QueryUserFromDB(); void ShowErrorMsg(const std::string& msg); private: bool dirty_ = false; timer_list* dirty_timer_ = nullptr; timer_list* update_user_info_timer_ = nullptr; long long last_apply_idx_ = 0; long long last_event_idx_ = 0; long long curr_max_event_idx_ = 0; bool event_fetching_ = false; long long last_run_tick_ = 0; std::map event_hash_; int red_point_flags_ = 0; std::map friend_hash_; std::map black_hash_; std::map apply_hash_; };