aozhiwei d83e8d047f 1
2020-09-24 10:05:42 +08:00

189 lines
7.3 KiB
C++

#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;
int gameid = 0;
int channel = 0;
long ip_saddr = 0;
int account_registertime = 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(myself, 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 _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 _CMGuildInfo(f8::MsgHdr& hdr, const cs::CMGuildInfo& msg);
void _CMGuildCreate(f8::MsgHdr& hdr, const cs::CMGuildCreate& msg);
void _CMGuildJoin(f8::MsgHdr& hdr, const cs::CMGuildJoin& msg);
void _CMGuildAgree(f8::MsgHdr& hdr, const cs::CMGuildAgree& msg);
void _CMGuildKick(f8::MsgHdr& hdr, const cs::CMGuildKick& msg);
void _CMGuildQuit(f8::MsgHdr& hdr, const cs::CMGuildQuit& msg);
void _CMGuildDismiss(f8::MsgHdr& hdr, const cs::CMGuildDismiss& msg);
void _CMGuildRename(f8::MsgHdr& hdr, const cs::CMGuildRename& msg);
void _CMGuildSearch(f8::MsgHdr& hdr, const cs::CMGuildSearch& msg);
void _CMGuildRank(f8::MsgHdr& hdr, const cs::CMGuildRank& msg);
void _CMGuildMemberList(f8::MsgHdr& hdr, const cs::CMGuildMemberList& msg);
void _CMGuildLog(f8::MsgHdr& hdr, const cs::CMGuildLog& 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);
std::set<std::string>& GetExcludeAccountIds();
Friend* GetFriendById(const std::string& friend_id);
Friend* GetBlackListById(const std::string& friend_id);
const std::string AccountId();
const std::string SessionId();
const std::string NickName();
const std::string AvatarUrl();
long long GuildId();
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 ForwardGuildCMMsg(f8::MsgHdr& hdr, long long hash_code);
void SaveToDB(a8::XParams param, f8::AsyncDBOnOkFunc on_ok, f8::AsyncDBOnErrorFunc on_error);
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<std::string> account_ids);
void QueryUserFromDB();
void ShowErrorMsg(const std::string& msg);
void InternalRemoveFriend(const std::string& account_id, bool need_sync, bool auto_delete);
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<long long, Event> event_hash_;
int red_point_flags_ = 0;
std::set<std::string> exclude_account_ids_;
std::map<std::string, Friend*> friend_hash_;
std::map<std::string, Friend*> black_hash_;
std::map<long long, FriendApply*> apply_hash_;
};