完成红点逻辑

This commit is contained in:
aozhiwei 2020-10-12 17:04:08 +08:00
parent 2c7a02b062
commit 910a5835f1
11 changed files with 219 additions and 1 deletions

View File

@ -33,6 +33,7 @@ void Guild::Init()
for (size_t i = 0; i < kGuildJobMax; ++i) {
job_hash_.push_back(std::set<std::string>());
}
RecalcRedPoint();
}
void Guild::UnInit()
@ -1082,6 +1083,39 @@ void Guild::Active()
}
}
bool Guild::CheckRedPoint()
{
if (has_red_point_) {
return true;
}
if (App::Instance()->nowtime - last_check_red_point_time_ < 15) {
return true;
}
RecalcRedPoint();
return false;
}
bool Guild::HasApply()
{
return has_red_point_;
}
void Guild::SyncNewApply()
{
std::vector<int> jobs = {kGuildAdmin, kGuildElite, kGuildMember};
for (int job : jobs) {
std::set<std::string>* members = GetJobMembers(job);
if (members) {
for (const std::string& member_id : *members) {
ss::SS_GS_PushGuildRedPoint respmsg;
respmsg.set_account_id(member_id);
respmsg.set_has_apply(1);
GuildMgr::Instance()->SendMsg(0, respmsg);
}
}
}
}
int Guild::GetJobMemberNum(int job)
{
std::set<std::string>* members = GetJobMembers(job);
@ -1552,3 +1586,58 @@ void Guild::GuildAgreeCb(int socket_handle, const ss::MFIMMsgConext& context, co
msg.apply().base_data().account_id()
);
}
void Guild::RecalcRedPoint()
{
last_check_red_point_time_ = App::Instance()->nowtime;
{
auto on_ok =
[] (a8::XParams& param, const f8::DataSet* data_set)
{
if (data_set && !data_set->empty()) {
Guild* guild = GuildMgr::Instance()->GetGuild(param.sender);
if (guild) {
guild->has_red_point_ = 1;
}
}
};
auto on_error =
[] (a8::XParams& param, int error_code, const std::string& error_msg)
{
};
a8::XObject conn_info = DBEngine::Instance()->GetConnInfo(GuildId());
DBEngine::Instance()->ExecAsyncQuery
(
conn_info,
"SELECT idx, applyid "
"FROM guild_apply "
"WHERE idx > %d AND A.status=0 LIMIT 1;",
{
0
},
a8::XParams()
.SetSender(GuildId()),
on_ok,
on_error,
GuildId()
);
}
{
a8::Timer::Instance()->AddDeadLineTimerAndAttach
(
1000 * 10,
a8::XParams()
.SetSender(this),
[] (const a8::XParams& param)
{
Guild* guild = (Guild*)param.sender.GetUserData();
guild->has_red_point_ = 0;
},
&timer_attacher_.timer_list_,
[] (const a8::XParams& param)
{
});
}
}

View File

@ -39,6 +39,9 @@ public:
void UpdateMemberOnline(const std::string& account_id);
void UpdateMemberOffline(const std::string& account_id);
void Active();
bool CheckRedPoint();
bool HasApply();
void SyncNewApply();
private:
bool IsFull();
@ -70,9 +73,12 @@ private:
void RemoveHandledApply();
void CombineRepeatApply();
void GuildAgreeCb(int socket_handle, const ss::MFIMMsgConext& context, const cs::CMGuildAgree& msg);
void RecalcRedPoint();
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;

View File

@ -1,6 +1,7 @@
#include "precompile.h"
#include <a8/openssl.h>
#include <a8/timer.h>
#include <a8/mutable_xobject.h>
#include "guild.h"
@ -140,6 +141,41 @@ void GuildMgr::_SS_IM_PushGuildUserOnlineState(f8::MsgHdr& hdr, const ss::SS_IM_
}
}
void GuildMgr::_SS_IM_GuildRecalcRedPoint(f8::MsgHdr& hdr, const ss::SS_IM_GuildRecalcRedPoint& msg)
{
Guild* guild = GetGuild(msg.guild_id());
if (guild) {
int wait_time = 0;
if (!guild->CheckRedPoint()) {
wait_time = 2;
}
a8::Timer::Instance()->AddDeadLineTimer
(
1000 * wait_time,
a8::XParams()
.SetSender(msg.context().user_info().base_data().account_id())
.SetParam1(msg.guild_id()),
[] (const a8::XParams& param)
{
Guild* guild = GuildMgr::Instance()->GetGuild(param.param1);
if (guild) {
ss::SS_GS_PushGuildRedPoint respmsg;
respmsg.set_account_id(param.sender.GetString());
respmsg.set_has_apply(guild->HasApply() ? 1 : 0);
GuildMgr::Instance()->SendMsg(0, respmsg);
}
});
}
}
void GuildMgr::_SS_IM_GuildNewApply(f8::MsgHdr& hdr, const ss::SS_IM_GuildNewApply& msg)
{
Guild* guild = GetGuild(msg.guild_id());
if (guild) {
guild->SyncNewApply();
}
}
void GuildMgr::CreateAsyncTask(int socket_handle, long long guild_id, AsyncGuildTask* task)
{
Guild* guild = GetGuild(guild_id);

View File

@ -7,6 +7,8 @@ namespace ss
class SS_IM_ForwardGuildSMMsg;
class SS_IM_RefeshGuildMemberInfo;
class SS_IM_PushGuildUserOnlineState;
class SS_IM_GuildRecalcRedPoint;
class SS_IM_GuildNewApply;
}
class Guild;
@ -48,6 +50,8 @@ class GuildMgr : public a8::Singleton<GuildMgr>
void _SS_IM_ForwardGuildSMMsg(f8::MsgHdr& hdr, const ss::SS_IM_ForwardGuildSMMsg& msg);
void _SS_IM_RefeshGuildMemberInfo(f8::MsgHdr& hdr, const ss::SS_IM_RefeshGuildMemberInfo& msg);
void _SS_IM_PushGuildUserOnlineState(f8::MsgHdr& hdr, const ss::SS_IM_PushGuildUserOnlineState& msg);
void _SS_IM_GuildRecalcRedPoint(f8::MsgHdr& hdr, const ss::SS_IM_GuildRecalcRedPoint& msg);
void _SS_IM_GuildNewApply(f8::MsgHdr& hdr, const ss::SS_IM_GuildNewApply& msg);
private:
void CreateAsyncTask(int socket_handle, long long guild_id, AsyncGuildTask* task);

View File

@ -68,10 +68,13 @@ void HandlerMgr::RegisterNetMsgHandlers()
RegisterNetMsgHandler(&imcmsghandler, &PlayerMgr::_SS_IM_GuildMemberQuitRequest);
RegisterNetMsgHandler(&imcmsghandler, &PlayerMgr::_SS_IM_GuildMemberUpdateRequest);
RegisterNetMsgHandler(&imcmsghandler, &PlayerMgr::_SS_GS_QueryGuildUserOnlineState);
RegisterNetMsgHandler(&imcmsghandler, &PlayerMgr::_SS_GS_PushGuildRedPoint);
RegisterNetMsgHandler(&imcmsghandler, &GuildMgr::_SS_IM_ForwardGuildCMMsg);
RegisterNetMsgHandler(&imcmsghandler, &GuildMgr::_SS_IM_RefeshGuildMemberInfo);
RegisterNetMsgHandler(&imcmsghandler, &GuildMgr::_SS_IM_PushGuildUserOnlineState);
RegisterNetMsgHandler(&imcmsghandler, &GuildMgr::_SS_IM_GuildRecalcRedPoint);
RegisterNetMsgHandler(&imcmsghandler, &GuildMgr::_SS_IM_GuildNewApply);
RegisterNetMsgHandler(&wsmsghandler, &WSListener::_SS_Ping);

View File

@ -65,7 +65,7 @@ void Player::Init()
}
#endif
SyncGuildMemberInfo();
a8::Timer::Instance()->AddRepeatTimerAndAttach
a8::Timer::Instance()->AddDeadLineTimerAndAttach
(
1000 * 2 + (rand() % 3000),
a8::XParams()
@ -74,6 +74,7 @@ void Player::Init()
{
Player* hum = (Player*)param.sender.GetUserData();
hum->SyncGuildMemberInfo();
hum->SyncGuildRedPoint();
},
&timer_attacher.timer_list_
);
@ -756,6 +757,19 @@ void Player::_CMGuildJoin(f8::MsgHdr& hdr, const cs::CMGuildJoin& msg)
}
++role_data.today_apply_guild_times;
ForwardGuildCMMsg(hdr, msg.guild_id());
a8::Timer::Instance()->AddDeadLineTimerAndAttach
(
1000 * 2 + (rand() % 3000),
a8::XParams()
.SetSender(this)
.SetParam1(msg.guild_id()),
[] (const a8::XParams& param)
{
Player* hum = (Player*)param.sender.GetUserData();
hum->SyncGuildNewApply(param.param1);
},
&timer_attacher.timer_list_
);
}
void Player::_CMGuildAgree(f8::MsgHdr& hdr, const cs::CMGuildAgree& msg)
@ -1346,6 +1360,14 @@ void Player::FillSMLogin(cs::SMLogin& respmsg)
respmsg.mutable_account_info()->set_user_sign(user_sign_);
}
void Player::UpdateGuildRedPoint(long long guild_id, int has_apply)
{
if (has_apply) {
a8::SetBitFlag(hum->red_point_flags_, RPF_GuildApply);
SyncRedPoint();
}
}
void Player::FillApplyList(const cs::MFPaging& paging, cs::SMFriendApplyList& respmsg)
{
RemoveHandledApply();
@ -1542,6 +1564,11 @@ long long Player::GuildId()
return myself.base_data.guild_id;
}
int Player::GuildJob()
{
return myself.base_data.guild_job;
}
int Player::GetFriendNum()
{
return friend_hash_.size();
@ -2050,3 +2077,21 @@ void Player::SyncGuildMemberInfo()
FillIMMsgConext(msg.mutable_context());
SendGSMsg(msg);
}
void Player::SyncGuildRedPoint()
{
if (GuildId() != 0 && (GuildJob() == kGuildOwner || GuildJob() == kGuildAdmin)) {
ss::SS_IM_GuildRecalcRedPoint msg;
FillIMMsgConext(msg.mutable_context());
msg.set_guild_id(GuildId());
SendGSMsg(msg);
}
}
void Player::SyncGuildNewApply(long long guild_id)
{
ss::SS_IM_GuildNewApply msg;
FillIMMsgConext(msg.mutable_context());
msg.set_guild_id(GuildId());
SendGSMsg(msg);
}

View File

@ -135,12 +135,14 @@ class Player
Friend* GetBlackListById(const std::string& friend_id);
void UpdateGuildData(long long guild_id, int guild_job);
void FillSMLogin(cs::SMLogin& respmsg);
void UpdateGuildRedPoint(long long guild_id, int has_apply);
const std::string AccountId();
const std::string SessionId();
const std::string NickName();
const std::string AvatarUrl();
long long GuildId();
int GuildJob();
int GetFriendNum();
void SaveToDB(a8::XParams param, f8::AsyncDBOnOkFunc on_ok, f8::AsyncDBOnErrorFunc on_error);
@ -184,6 +186,8 @@ private:
void ShowErrorMsg(const std::string& msg);
void InternalRemoveFriend(const std::string& account_id, bool need_sync, bool auto_delete);
void SyncGuildMemberInfo();
void SyncGuildRedPoint();
void SyncGuildNewApply(long long guild_id);
private:
bool dirty_ = false;

View File

@ -252,6 +252,14 @@ void PlayerMgr::_SS_GS_QueryGuildUserOnlineState(f8::MsgHdr& hdr, const ss::SS_G
}
void PlayerMgr::_SS_GS_PushGuildRedPoint(f8::MsgHdr& hdr, const ss::SS_GS_PushGuildRedPoint& msg)
{
Player* hum = GetPlayerByAccountId(msg.account_id());
if (hum) {
hum->UpdateGuildRedPoint(msg.guild_id(), msg.has_apply());
}
}
void PlayerMgr::_CMLoginOld(f8::MsgHdr& hdr, const cs::CMLoginOld& msg)
{
cs::CMLogin new_msg;

View File

@ -27,6 +27,7 @@ namespace ss
class SS_IM_GuildMemberUpdateRequest;
class SS_IM_GuildMemberUpdateResponse;
class SS_GS_QueryGuildUserOnlineState;
class SS_GS_PushGuildRedPoint;
}
class Player;
@ -62,6 +63,7 @@ class PlayerMgr : public a8::Singleton<PlayerMgr>
void _SS_IM_UpdateUserInfo(f8::MsgHdr& hdr, const ss::SS_IM_UpdateUserInfo& msg);
void _SS_GS_QueryGuildUserOnlineState(f8::MsgHdr& hdr, const ss::SS_GS_QueryGuildUserOnlineState& msg);
void _SS_GS_PushGuildRedPoint(f8::MsgHdr& hdr, const ss::SS_GS_PushGuildRedPoint& msg);
void _CMLoginOld(f8::MsgHdr& hdr, const cs::CMLoginOld& msg);
void _CMLogin(f8::MsgHdr& hdr, const cs::CMLogin& msg);

View File

@ -50,4 +50,6 @@ enum SSMessageId_e
_SS_IM_RefeshGuildMemberInfo = 1035;
_SS_GS_QueryGuildUserOnlineState = 1036;
_SS_IM_PushGuildUserOnlineState = 1037;
_SS_IM_GuildRecalcRedPoint = 1038;
_SS_GS_PushGuildRedPoint = 1039;
}

View File

@ -374,3 +374,22 @@ message SS_IM_PushGuildUserOnlineState
optional int64 guild_id = 2;
repeated string online_users = 3;
}
message SS_IM_GuildRecalcRedPoint
{
optional MFIMMsgConext context = 1;
optional int64 guild_id = 2;
}
message SS_GS_PushGuildRedPoint
{
optional int64 guild_id = 1;
optional string account_id = 2;
optional int32 has_apply = 3;
}
message SS_IM_GuildNewApply
{
optional MFIMMsgConext context = 1;
optional int64 guild_id = 2;
}