添加已申请逻辑处理

This commit is contained in:
aozhiwei 2020-10-15 15:23:23 +08:00
parent 4fafae4a84
commit 5165f1fc2e
9 changed files with 141 additions and 5 deletions

View File

@ -284,6 +284,9 @@ void Guild::_CMGuildJoin(f8::MsgHdr& hdr, const cs::CMGuildJoin& msg)
} else {
DBHelper::Instance()->AddGuildApply(this, forward_msg->context().user_info());
GameLog::Instance()->GuildApply(this, forward_msg->context().user_info().base_data());
SyncHelper::Instance()->SyncGuildApplyed(this,
forward_msg->context().user_info().base_data().account_id()
);
}
}
@ -439,6 +442,9 @@ void Guild::_CMGuildRefuse(f8::MsgHdr& hdr, const cs::CMGuildRefuse& msg)
sender,
msg.apply().idx(),
msg.apply().base_data().account_id());
SyncHelper::Instance()->SyncGuildRefuse(this,
msg.apply().base_data().account_id()
);
}
void Guild::_CMGuildKick(f8::MsgHdr& hdr, const cs::CMGuildKick& msg)

View File

@ -115,7 +115,12 @@ void Player::Deserialize(const ss::MFUserDB& user_db)
role_data.save_count = user_db.role_data().save_count();
role_data.last_save_time = user_db.role_data().last_save_time();
for (auto& pair : user_db.role_data().applyed_guild_list()) {
applyed_guild_hash_[pair.key()] = pair.val();
if (a8::BetweenDays(App::Instance()->nowtime, pair.val()) < 10) {
applyed_guild_hash_[pair.key()] = pair.val();
}
}
if (GuildId() != 0) {
applyed_guild_hash_.clear();
}
}
@ -134,6 +139,14 @@ void Player::Serialize(ss::MFUserDB& user_db)
user_db.mutable_role_data()->set_today_create_guild_times(role_data.today_create_guild_times);
user_db.mutable_role_data()->set_save_count(role_data.save_count);
user_db.mutable_role_data()->set_last_save_time(role_data.last_save_time);
for (auto& pair : applyed_guild_hash_) {
auto p = user_db.mutable_role_data()->add_applyed_guild_list();
p->set_key(pair.first);
p->set_val(pair.second);
}
if (GuildId() != 0) {
applyed_guild_hash_.clear();
}
}
void Player::_CMPing(f8::MsgHdr& hdr, const cs::CMPing& msg)
@ -934,6 +947,13 @@ void Player::_CMGuildSearch(f8::MsgHdr& hdr, const cs::CMGuildSearch& msg)
params->SetVal("guild_name", msg.guild_name());
params->SetVal("curr_page", msg.paging().curr_page());
params->SetVal("page_size", msg.paging().page_size());
{
std::string applyed_guilds;
for (auto& pair : applyed_guild_hash_) {
applyed_guilds += a8::XValue(pair.first).GetString() + ",";
}
params->SetVal("applyed_guilds", applyed_guilds);
}
f8::HttpClientPool::Instance()->HttpGet
(
a8::XParams().
@ -1610,6 +1630,18 @@ void Player::Update(long long tick)
}
}
void Player::AddGuildApplyed(long long guild_id)
{
if (applyed_guild_hash_.size() < 100) {
applyed_guild_hash_[guild_id] = App::Instance()->nowtime;
}
}
void Player::RemoveGuildApplyed(long long guild_id)
{
applyed_guild_hash_.erase(guild_id);
}
const std::string Player::AccountId()
{
return myself.base_data.account_id;
@ -1841,6 +1873,9 @@ void Player::ProcessEvent()
} else if (event.event_name == EVENT_FRIEND_DELETE) {
OnFriendDeleteEvent(event);
DBHelper::Instance()->SetEventStatus(event.idx, AccountId(), 1);
} else if (event.event_name == EVENT_GUILD_REFUSE) {
OnGuildRefuseEvent(event);
DBHelper::Instance()->SetEventStatus(event.idx, AccountId(), 1);
}
processed_events.push_back(pair.first);
}
@ -1877,6 +1912,12 @@ void Player::OnFriendDeleteEvent(Event& event)
RemoveFriend(event.sender_id, false);
}
void Player::OnGuildRefuseEvent(Event& event)
{
long long refuse_guild_id = a8::XValue(event.param1);
RemoveGuildApplyed(refuse_guild_id);
}
bool Player::CanAddFriend(const std::string& account_id)
{
if (GetFriendNum() >= MAX_FRIEND_NUM) {

View File

@ -139,6 +139,8 @@ class Player
void UpdateGuildData(long long guild_id, int guild_job);
void FillSMLogin(cs::SMLogin& respmsg);
void UpdateGuildRedPoint(long long guild_id, int has_apply);
void AddGuildApplyed(long long guild_id);
void RemoveGuildApplyed(long long guild_id);
const std::string AccountId();
const std::string SessionId();
@ -175,6 +177,7 @@ private:
void ProcessEvent();
void OnFriendAgreeEvent(Event& event);
void OnFriendDeleteEvent(Event& event);
void OnGuildRefuseEvent(Event& event);
bool CanAddFriend(const std::string& account_id);
void SyncRedPoint();
void OnDailyReset();

View File

@ -262,7 +262,17 @@ void PlayerMgr::_SS_GS_PushGuildRedPoint(f8::MsgHdr& hdr, const ss::SS_GS_PushGu
void PlayerMgr::_SS_GS_ApplyChangeRequest(f8::MsgHdr& hdr, const ss::SS_GS_ApplyChangeRequest& msg)
{
Player* hum = GetPlayerByAccountId(msg.account_id());
if (hum) {
if (msg.is_refuse()) {
hum->RemoveGuildApplyed(msg.guild_id());
} else {
hum->AddGuildApplyed(msg.guild_id());
}
ss::SS_IM_ApplyChangeResponse respmsg;
respmsg.set_seqid(msg.seqid());
IMListener::Instance()->SendMsg(hdr.socket_handle, respmsg);
}
}
void PlayerMgr::_CMLoginOld(f8::MsgHdr& hdr, const cs::CMLoginOld& msg)

View File

@ -354,12 +354,59 @@ void SyncHelper::SyncGuildApplyed(Guild* guild,
const std::string& target_id
)
{
InternalSyncGuildApplyState(guild, target_id, 0);
}
void SyncHelper::SyncGuildRefuse(Guild* guild,
const std::string& target_id
)
{
InternalSyncGuildApplyState(guild, target_id, 1);
}
void SyncHelper::SS_GS_ApplyChangeRequest_TimeOut(ss::SS_GS_ApplyChangeRequest* msg)
{
if (msg->is_refuse()) {
DBHelper::Instance()->AddEvent
(
a8::XValue(msg->guild_id()).GetString(),
msg->account_id(),
EVENT_GUILD_REFUSE,
"",
a8::XValue(msg->guild_id()).GetString()
);
}
}
void SyncHelper::InternalSyncGuildApplyState(Guild* guild,
const std::string& target_id,
int is_refuse)
{
ss::SS_GS_ApplyChangeRequest* notifymsg = new ss::SS_GS_ApplyChangeRequest;
notifymsg->set_seqid(App::Instance()->NewUUID());
notifymsg->set_guild_id(guild->GuildId());
notifymsg->set_account_id(target_id);
notifymsg->set_is_refuse(is_refuse);
BroadcastIMConnMsg(*notifymsg);
pending_request_hash_[notifymsg->seqid()] =
a8::Timer::Instance()->AddDeadLineTimer
(
1000 * 3,
a8::XParams()
.SetSender(notifymsg)
.SetParam1(notifymsg->seqid()),
[] (const a8::XParams& param)
{
ss::SS_GS_ApplyChangeRequest* notifymsg =
(ss::SS_GS_ApplyChangeRequest*)param.sender.GetUserData();
SyncHelper::Instance()->SS_GS_ApplyChangeRequest_TimeOut(notifymsg);
},
[] (const a8::XParams& param)
{
ss::SS_GS_ApplyChangeRequest* notifymsg =
(ss::SS_GS_ApplyChangeRequest*)param.sender.GetUserData();
delete notifymsg;
SyncHelper::Instance()->RemovePendingRequest(param.param1);
}
);
}

View File

@ -12,6 +12,7 @@ namespace ss
class SS_IM_GuildMemberQuitResponse;
class SS_IM_GuildMemberUpdateRequest;
class SS_IM_GuildMemberUpdateResponse;
class SS_GS_ApplyChangeRequest;
class SS_IM_ApplyChangeResponse;
}
@ -73,6 +74,7 @@ private:
void SS_IM_FriendDeleteRequest_TimeOut(ss::SS_IM_FriendDeleteRequest* msg);
void SS_IM_GuildMemberQuitRequest_TimeOut(ss::SS_IM_GuildMemberQuitRequest* msg);
void SS_IM_GuildMemberUpdateRequest_TimeOut(ss::SS_IM_GuildMemberUpdateRequest* msg);
void SS_GS_ApplyChangeRequest_TimeOut(ss::SS_GS_ApplyChangeRequest* msg);
void InternalSyncGuildMemberUpdate(Guild* guild,
GuildMember* member,
@ -84,6 +86,9 @@ private:
const std::string& target_id,
int reason,
bool only_online);
void InternalSyncGuildApplyState(Guild* guild,
const std::string& target_id,
int is_refuse);
public:
template <typename T>

View File

@ -57,6 +57,11 @@ void TypeConvert::Convert(a8::XObject& xobj, cs::MFGuildBasic* guild_basic)
guild_basic->set_join_cond2(xobj.At("join_cond2")->AsXValue());
guild_basic->set__gameid(xobj.At("_gameid")->AsXValue());
guild_basic->set__channel(xobj.At("_channel")->AsXValue());
if (xobj.HasKey("applyed")) {
guild_basic->set_applyed(xobj.At("applyed")->AsXValue());
} else {
guild_basic->set_applyed(0);
}
}
void TypeConvert::Convert(a8::XObject& xobj, cs::MFPaging* paging)

View File

@ -294,6 +294,17 @@ void GuildMgr::__GuildSearch(f8::JsonHttpRequest* request)
int curr_page = request->request.At("curr_page")->AsXValue();
int page_size = request->request.At("page_size")->AsXValue();
std::string search_name = request->request.At("guild_name")->AsXValue().GetString();
std::set<long long> applyed_guilds;
if (request->request.HasKey("applyed_guilds")) {
std::string applyed_guilds_str = request->request.At("applyed_guilds")->AsXValue().GetString();
std::vector<std::string> tmp_strings;
a8::Split(applyed_guilds_str, tmp_strings, ',');
for (auto& str : tmp_strings) {
if (!str.empty()) {
applyed_guilds.insert(a8::XValue(str));
}
}
}
if (curr_page < 0) {
curr_page = 0;
}
@ -301,7 +312,7 @@ void GuildMgr::__GuildSearch(f8::JsonHttpRequest* request)
page_size = 1;
}
#if 1
page_size = 20;
page_size = 10;
#endif
request->resp_xobj->SetVal("errcode", 0);
@ -313,6 +324,7 @@ void GuildMgr::__GuildSearch(f8::JsonHttpRequest* request)
int total_count = 0;
int total_page = 0;
InternalSearch(account_id,
applyed_guilds,
guild_list,
search_name,
curr_page,
@ -902,6 +914,7 @@ std::set<long long>& GuildMgr::ForceSearchCache(const std::string& account_id, c
}
void GuildMgr::InternalSearch(const std::string& account_id,
std::set<long long>& applyed_guilds,
a8::MutableXObject* guild_list,
const std::string& search_name,
int curr_page,
@ -932,6 +945,11 @@ void GuildMgr::InternalSearch(const std::string& account_id,
}
a8::MutableXObject* guild_xobj = a8::MutableXObject::NewObject();
TypeConvert::Convert(guild, guild_xobj);
if (applyed_guilds.find(guild->guild_id()) != applyed_guilds.end()) {
guild_xobj->SetVal("applyed", 1);
} else {
guild_xobj->SetVal("applyed", 0);
}
guild_list->Push(*guild_xobj);
delete guild_xobj;
cache_guilds.insert(guild->guild_id());

View File

@ -53,6 +53,7 @@ class GuildMgr : public a8::Singleton<GuildMgr>
const std::string& raw_name);
void GuildRename(cs::MFGuildBasic* guild, const std::string& new_raw_name);
void InternalSearch(const std::string& account_id,
std::set<long long>& applyed_guilds,
a8::MutableXObject* guild_list,
const std::string& search_name,
int curr_page,