1
This commit is contained in:
parent
6995184d29
commit
8a39ab289d
@ -656,3 +656,14 @@ long long App::NewSeqId()
|
|||||||
{
|
{
|
||||||
return ++seq_id_;
|
return ++seq_id_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
time_t App::BetweenDays(time_t time1, time_t time2)
|
||||||
|
{
|
||||||
|
const int g_time_zone = 8;
|
||||||
|
return (time1 + g_time_zone*3600)/3600/24 - (time2 + g_time_zone*3600)/3600/24;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool App::IsTimeToReset(int time)
|
||||||
|
{
|
||||||
|
return BetweenDays(nowtime - 60 * SYS_RESET_TIME, time - 60 * SYS_RESET_TIME) > 0;
|
||||||
|
}
|
||||||
|
@ -34,6 +34,8 @@ class App : public a8::Singleton<App>
|
|||||||
bool HasFlag(int flag);
|
bool HasFlag(int flag);
|
||||||
long long NewUUID();
|
long long NewUUID();
|
||||||
long long NewSeqId();
|
long long NewSeqId();
|
||||||
|
time_t BetweenDays(time_t time1, time_t time2);
|
||||||
|
bool IsTimeToReset(int time);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void QuickExecute();
|
void QuickExecute();
|
||||||
|
@ -44,3 +44,6 @@ const int MAX_INSTANCE_ID = 1023;
|
|||||||
|
|
||||||
const int MAX_FRIEND_NUM = 50;
|
const int MAX_FRIEND_NUM = 50;
|
||||||
const int DAILY_JOIN_FRIEND_TIMES = 100;
|
const int DAILY_JOIN_FRIEND_TIMES = 100;
|
||||||
|
const int DAILY_APPLY_FRIEND_TIMES = 100;
|
||||||
|
|
||||||
|
const int SYS_RESET_TIME = 2*60; //每日两点重置
|
||||||
|
@ -48,6 +48,9 @@ void Player::Init()
|
|||||||
red_point_flags_ = 1;
|
red_point_flags_ = 1;
|
||||||
SyncRedPoint();
|
SyncRedPoint();
|
||||||
#endif
|
#endif
|
||||||
|
if (App::Instance()->IsTimeToReset(role_data.last_save_time)) {
|
||||||
|
OnDailyReset();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::UnInit()
|
void Player::UnInit()
|
||||||
@ -71,6 +74,9 @@ void Player::Deserialize(const ss::MFUserDB& user_db)
|
|||||||
TypeConvert::Convert(friend_db.base_data(), friendobj->base_data);
|
TypeConvert::Convert(friend_db.base_data(), friendobj->base_data);
|
||||||
AddFriend(friendobj);
|
AddFriend(friendobj);
|
||||||
}
|
}
|
||||||
|
role_data.today_apply_times = user_db.role_data().today_apply_times();
|
||||||
|
role_data.save_count = user_db.role_data().save_count();
|
||||||
|
role_data.last_save_time = user_db.role_data().last_save_time();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::Serialize(ss::MFUserDB& user_db)
|
void Player::Serialize(ss::MFUserDB& user_db)
|
||||||
@ -79,6 +85,9 @@ void Player::Serialize(ss::MFUserDB& user_db)
|
|||||||
auto p = user_db.add_friends();
|
auto p = user_db.add_friends();
|
||||||
TypeConvert::Convert(pair.second->base_data, *(p->mutable_base_data()));
|
TypeConvert::Convert(pair.second->base_data, *(p->mutable_base_data()));
|
||||||
}
|
}
|
||||||
|
user_db.mutable_role_data()->set_today_apply_times(role_data.today_apply_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);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::_CMPing(f8::MsgHdr& hdr, const cs::CMPing& msg)
|
void Player::_CMPing(f8::MsgHdr& hdr, const cs::CMPing& msg)
|
||||||
@ -139,11 +148,25 @@ void Player::_CMFriendApply(f8::MsgHdr& hdr, const cs::CMFriendApply& msg)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (msg.friend_id() == AccountId()) {
|
if (msg.friend_id() == AccountId()) {
|
||||||
respmsg.set_errcode(21);
|
respmsg.set_errcode(2);
|
||||||
respmsg.set_errmsg("不能邀请自己");
|
respmsg.set_errmsg("不能邀请自己");
|
||||||
SendMsg(respmsg);
|
SendMsg(respmsg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (f8::ExtractGameIdFromAccountId(AccountId()) !=
|
||||||
|
f8::ExtractGameIdFromAccountId(msg.friend_id())) {
|
||||||
|
respmsg.set_errcode(3);
|
||||||
|
respmsg.set_errmsg("不能邀请其他游戏玩家");
|
||||||
|
SendMsg(respmsg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (role_data.today_apply_times > DAILY_APPLY_FRIEND_TIMES) {
|
||||||
|
respmsg.set_errcode(4);
|
||||||
|
respmsg.set_errmsg("今天邀请次数已经用完不能再邀请");
|
||||||
|
SendMsg(respmsg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
++role_data.today_apply_times;
|
||||||
SendMsg(respmsg);
|
SendMsg(respmsg);
|
||||||
DBHelper::Instance()->AddFriendApply(this, msg.friend_id());
|
DBHelper::Instance()->AddFriendApply(this, msg.friend_id());
|
||||||
}
|
}
|
||||||
@ -616,6 +639,8 @@ void Player::SaveToDB(a8::XParams param, f8::AsyncDBOnOkFunc on_ok, f8::AsyncDBO
|
|||||||
on_error,
|
on_error,
|
||||||
myself.crc32_code
|
myself.crc32_code
|
||||||
);
|
);
|
||||||
|
++role_data.save_count;
|
||||||
|
role_data.last_save_time = App::Instance()->nowtime;
|
||||||
}
|
}
|
||||||
|
|
||||||
Friend* Player::GetFriendById(const std::string& friend_id)
|
Friend* Player::GetFriendById(const std::string& friend_id)
|
||||||
@ -789,6 +814,10 @@ void Player::Update(long long tick)
|
|||||||
{
|
{
|
||||||
last_run_tick_ = tick;
|
last_run_tick_ = tick;
|
||||||
ProcessEvent();
|
ProcessEvent();
|
||||||
|
if (App::Instance()->nowtime - role_data.last_save_time > 1000 * 60) {
|
||||||
|
role_data.last_save_time = App::Instance()->nowtime;
|
||||||
|
SaveToDB(a8::XParams(), nullptr, nullptr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string Player::AccountId()
|
const std::string Player::AccountId()
|
||||||
@ -882,7 +911,9 @@ void Player::ProcessEventTimerFunc()
|
|||||||
{
|
{
|
||||||
std::string account_id = param.sender.GetString();
|
std::string account_id = param.sender.GetString();
|
||||||
long long curr_max_event_idx = param.param1;
|
long long curr_max_event_idx = param.param1;
|
||||||
|
#if 0
|
||||||
long long last_event_idx = param.param2;
|
long long last_event_idx = param.param2;
|
||||||
|
#endif
|
||||||
Player* hum = PlayerMgr::Instance()->GetPlayerByAccountId(account_id);
|
Player* hum = PlayerMgr::Instance()->GetPlayerByAccountId(account_id);
|
||||||
if (hum) {
|
if (hum) {
|
||||||
hum->OnFetchEvent(curr_max_event_idx, data_set);
|
hum->OnFetchEvent(curr_max_event_idx, data_set);
|
||||||
@ -1005,3 +1036,8 @@ void Player::SyncRedPoint()
|
|||||||
notifymsg.set_red_point_flags(red_point_flags_);
|
notifymsg.set_red_point_flags(red_point_flags_);
|
||||||
SendMsg(notifymsg);
|
SendMsg(notifymsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Player::OnDailyReset()
|
||||||
|
{
|
||||||
|
role_data.today_apply_times = 0;
|
||||||
|
}
|
||||||
|
@ -128,6 +128,7 @@ private:
|
|||||||
void OnFriendDeleteEvent(Event& event);
|
void OnFriendDeleteEvent(Event& event);
|
||||||
bool CanAddFriend(const std::string& account_id);
|
bool CanAddFriend(const std::string& account_id);
|
||||||
void SyncRedPoint();
|
void SyncRedPoint();
|
||||||
|
void OnDailyReset();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool dirty_ = false;
|
bool dirty_ = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user