169 lines
6.6 KiB
C++
169 lines
6.6 KiB
C++
#pragma once
|
|
|
|
#include <a8/timer_attacher.h>
|
|
|
|
#include "cs_proto.pb.h"
|
|
#include "ss_proto.pb.h"
|
|
|
|
struct timer_list;
|
|
class Guild
|
|
{
|
|
public:
|
|
enum { HID = HID_Guild };
|
|
|
|
public:
|
|
|
|
void Init();
|
|
void UnInit();
|
|
|
|
void _CMGuildInfo(f8::MsgHdr& hdr, const cs::CMGuildInfo& msg);
|
|
void _CMGuildJoin(f8::MsgHdr& hdr, const cs::CMGuildJoin& msg);
|
|
void _CMGuildAgree(f8::MsgHdr& hdr, const cs::CMGuildAgree& msg);
|
|
void _CMGuildRefuse(f8::MsgHdr& hdr, const cs::CMGuildRefuse& msg);
|
|
void _CMGuildKick(f8::MsgHdr& hdr, const cs::CMGuildKick& msg);
|
|
void _CMGuildQuit(f8::MsgHdr& hdr, const cs::CMGuildQuit& msg);
|
|
void _CMGuildChange(f8::MsgHdr& hdr, const cs::CMGuildChange& msg);
|
|
void _CMGuildMemberList(f8::MsgHdr& hdr, const cs::CMGuildMemberList& msg);
|
|
void _CMGuildApplyList(f8::MsgHdr& hdr, const cs::CMGuildApplyList& msg);
|
|
void _CMGuildLog(f8::MsgHdr& hdr, const cs::CMGuildLog& msg);
|
|
void _CMGuildMemberSetJob(f8::MsgHdr& hdr, const cs::CMGuildMemberSetJob& msg);
|
|
void _CMGuildAgreeInvite(f8::MsgHdr& hdr, const cs::CMGuildAgreeInvite& msg);
|
|
void _CMGuildGainExp(f8::MsgHdr& hdr, const cs::CMGuildGainExp& msg);
|
|
void _CMGuildSearchMember(f8::MsgHdr& hdr, const cs::CMGuildSearchMember& msg);
|
|
|
|
long long GuildId() { return guild_id_; }
|
|
int GuildLv() { return guild_lv_; }
|
|
int GuildExp() { return guild_exp_; }
|
|
const std::string GuildName() { return guild_name_; }
|
|
int GetMemberJob(const std::string& account_id);
|
|
int Status() { return guild_status_; }
|
|
int GetGameId() { return gameid_; }
|
|
int GetChannel() { return channel_; }
|
|
std::set<std::string>* GetJobMembers(int job);
|
|
int GetJobMemberNum(int job);
|
|
int GetMemberNum();
|
|
void UpdateMemberInfo(const cs::MFUserInfo& user_info);
|
|
void UpdateMemberOnline(const std::string& account_id);
|
|
void UpdateMemberOffline(const std::string& account_id);
|
|
void Active();
|
|
bool CheckRedPoint();
|
|
bool HasApply();
|
|
void SyncNewApply();
|
|
void TraverseMember(std::function<void (GuildMember*)> callback);
|
|
|
|
private:
|
|
bool IsFull();
|
|
void MarkDirty();
|
|
void SyncData();
|
|
void SendUpdate();
|
|
GuildMember* GetMember(const std::string& account_id);
|
|
void AddMember(GuildMember* member);
|
|
void RemoveMember(const std::string& sender_id,
|
|
const std::string& target_id,
|
|
int reason);
|
|
|
|
void FillGuildBasic(cs::MFGuildBasic* guild_basic);
|
|
void FillGuildDB(ss::MFGuildDB& guild_pb);
|
|
void SerializeMembers(std::string& guild_members);
|
|
void SaveToDB();
|
|
void GenSortedMembers();
|
|
void FillApplyList(const std::string& account_id, cs::MFPaging& paging, cs::SMGuildApplyList& respmsg);
|
|
void ClearApplyBySenderId(const std::string& sender_id);
|
|
void ClearApplyByIdx(long long idx);
|
|
void Deserialize(const std::string& guild_data,
|
|
const std::string& guild_members,
|
|
const std::string& guild_log);
|
|
void SendErrorMsg(int sokcet_handle, const ss::MFIMMsgConext& context, const std::string& errmsg);
|
|
void QueryMemberOnlineState();
|
|
GuildMember* ChooseLeader(std::set<std::string>* members);
|
|
void GuildRenameCb(int socket_handle, const ss::MFIMMsgConext& context, const cs::CMGuildChange& msg);
|
|
void RemoveHandledApply();
|
|
void CombineRepeatApply();
|
|
void GuildAgreeCb(int socket_handle, const ss::MFIMMsgConext& context, const cs::CMGuildAgree& msg);
|
|
void RecalcRedPoint();
|
|
void SetNewLeader(GuildMember* member);
|
|
void ForceSetJob(GuildMember* member, int new_job);
|
|
|
|
private:
|
|
bool dirty_ = false;
|
|
int has_red_point_ = false;
|
|
int last_check_red_point_time_ = 0;
|
|
long long last_apply_idx_ = 0;
|
|
timer_list* dirty_timer_ = nullptr;
|
|
timer_list* sync_timer_ = nullptr;
|
|
std::map<std::string, GuildMember*> member_hash_;
|
|
std::vector<GuildMember*> sorted_members_;
|
|
ss::MFGuildLogDB* logdb_ = nullptr;
|
|
std::map<long long, GuildApply*> apply_hash_;
|
|
std::map<std::string, int> member_job_hash_;
|
|
std::vector<std::set<std::string>> job_hash_;
|
|
|
|
int gameid_ = 0;
|
|
int channel_ = 0;
|
|
long long guild_id_ = 0;
|
|
std::string guild_name_;
|
|
int guild_lv_ = 0;
|
|
double guild_exp_ = 0;
|
|
int guild_badge_ = 0;
|
|
int guild_apply_num_ = 0;
|
|
std::string guild_notice_;
|
|
std::string guild_declaration_;
|
|
std::string owner_id_;
|
|
std::string owner_name_;
|
|
std::string owner_avatar_url_;
|
|
int owner_vip_lv_ = 0;
|
|
int owner_head_ = 0;
|
|
int owner_sex_ = 0;
|
|
std::string creator_id_;
|
|
std::string creator_name_;
|
|
std::string creator_avatar_url_;
|
|
int creator_vip_lv_ = 0;
|
|
int creator_head_ = 0;
|
|
int creator_sex_ = 0;
|
|
int guild_status_ = 0;
|
|
int join_unlimited_ = 0;
|
|
int join_cond1_ = 0;
|
|
int join_cond2_ = 0;
|
|
int createtime_ = 0;
|
|
|
|
time_t last_query_member_time_ = 0;
|
|
a8::TimerAttacher timer_attacher_;
|
|
|
|
time_t last_active_time_ = 0;
|
|
time_t last_saveok_time_ = 0;
|
|
|
|
public:
|
|
static Guild* CreateGuild(int gameid,
|
|
long long guild_id,
|
|
const std::string& guild_name,
|
|
int guild_lv,
|
|
int guild_exp,
|
|
int guild_badge,
|
|
int guild_apply_num,
|
|
const std::string& guild_members,
|
|
const std::string& guild_notice,
|
|
const std::string& guild_declaration,
|
|
const std::string& guild_log,
|
|
const std::string& owner_id,
|
|
const std::string& owner_name,
|
|
const std::string& owner_avatar_url,
|
|
const std::string& creator_id,
|
|
const std::string& creator_name,
|
|
const std::string& creator_avatar_url,
|
|
const std::string& guild_data,
|
|
int guild_status,
|
|
int join_unlimited,
|
|
int join_cond1,
|
|
int join_cond2,
|
|
int createtime,
|
|
int channel,
|
|
int owner_vip_lv,
|
|
int owner_head,
|
|
int creator_vip_lv,
|
|
int creator_head,
|
|
int owner_sex,
|
|
int creator_sex
|
|
);
|
|
static void GenGuildData(Player* hum, long long guild_id, std::string& guild_data);
|
|
};
|