From b4488bc3020cf5da3bf9fe4a0b27ba59b2d9f8cc Mon Sep 17 00:00:00 2001
From: hxp <ale99527@vip.qq.com>
Date: 星期五, 12 十二月 2025 20:18:02 +0800
Subject: [PATCH] 389 流向记录(每日累计在线时长流向 OnlineTimeToday)
---
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GameWorldLogic/GameWorldEvent.py | 1
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/DataRecordPack.py | 7 +++
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/ChPlayer.py | 2
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerControl.py | 59 +++++++++++++++++++++++++++++
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerEventCounter.py | 2
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/ChConfig.py | 4 +-
6 files changed, 71 insertions(+), 4 deletions(-)
diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/ChConfig.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/ChConfig.py
index 0ebf652..57ac194 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/ChConfig.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/ChConfig.py
@@ -3274,8 +3274,8 @@
Def_PDict_EquipViewCacheState = "EquipViewCacheState" # 本次上线是否同步过装备缓存
Def_PDict_PackDataSyncState = "PackDataSyncState" # 本次上线打包数据同步状态,按位存储是否同步 0-本服,1-跨服
Def_PDict_PackDataSyncFightPower = "PackDataSyncFightPower" # 本次上线打包数据同步时的战力,用于对比,只对比求余亿部分即可
-Def_PDict_DayOnlineTime = "OnlineTime" # 当日在线时长
-Def_PDict_OnlineStartTick = "OnlineStartTime" # 在线计算时间
+Def_PDict_DayOnlineTime = "DayOnlineTime" # 当日在线时长
+Def_PDict_DayOnlineCalcTime = "DayOLCalcTime" # 当日在线计算时间
Def_PDict_LVAwardGetRecord = "LVAwardGetRecord" # 等级奖励领取信息记录,按二进制位标示
Def_PDict_LVAwardVIPGetRecord = "LVAwardVIPGetRecord" # 等级奖励vip领取信息记录,按二进制位标示
Def_PDict_HistoryChargeAwardGetRecord = "HTotalGoldAwardRecord" # 历史累计充值奖励领取信息记录,按二进制位标示
diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/DataRecordPack.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/DataRecordPack.py
index 0b7f4e6..be8839f 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/DataRecordPack.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/DataRecordPack.py
@@ -181,6 +181,13 @@
SendEventPack("LogInOut", dataDict, curPlayer)
return
+def DR_OnlineTimeToday(curPlayer, onlineTime):
+ ## 今日累计在线时长
+ dataDict = {'PlayerID':curPlayer.GetPlayerID(), 'PlayerName':curPlayer.GetPlayerName(),
+ 'AccID':curPlayer.GetAccID(), 'OnlineTime':onlineTime}
+ SendEventPack("OnlineTimeToday", dataDict)
+ return
+
## 新增第一次登陆
# @param accID: 账号ID
# @param ip: ip
diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GameWorldLogic/GameWorldEvent.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GameWorldLogic/GameWorldEvent.py
index 824a5dd..03b3c43 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GameWorldLogic/GameWorldEvent.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GameWorldLogic/GameWorldEvent.py
@@ -308,6 +308,7 @@
#GameWorldActionControl.Dispose_OperationActionState()
#GameWorldActionControl.Dispose_DailyActionState()
#GameWorldActionControl.Dispose_FBStateTime()
+ PlayerControl.OnMinute(curTime)
PlayerFamily.OnMinute()
PlayerOnline.OnMinute()
BattleObj.OnMinute()
diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/ChPlayer.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/ChPlayer.py
index 46f6a15..df3b473 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/ChPlayer.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/ChPlayer.py
@@ -696,7 +696,7 @@
curPlayer.SetState(0) # 脱机挂恢复为正常上线
curPlayer.SetCountryLastWeekHornor(0) # 通知数据库是否保存还是下线,做一次恢复,1为保存 0为正常下线
- PlayerControl.DoGMForbidenTalkOnLogin(curPlayer)
+ PlayerControl.OnPlayerLogin(curPlayer)
DataRecordPack.DR_PlayerLogin(curPlayer) # 放最后,记录等级、经验等信息
return
diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerControl.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerControl.py
index acbabed..b7fb12e 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerControl.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerControl.py
@@ -968,6 +968,64 @@
playerIDList.remove(playerID)
return
+
+def OnPlayerLogin(curPlayer):
+ DoGMForbidenTalkOnLogin(curPlayer)
+ curPlayer.SetDict(ChConfig.Def_PDict_DayOnlineCalcTime, int(time.time()))
+ return
+
+def PlayerOnDay(curPlayer):
+
+ PayCoinOnDay(curPlayer)
+
+ # 重置今日累计在线时长统计
+ NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DayOnlineTime, 0)
+ curPlayer.SetDict(ChConfig.Def_PDict_DayOnlineCalcTime, int(time.time()))
+ return
+
+def OnMinute(serverTime):
+
+ # 定时记录当前在线玩家今日总在线时长
+ if [serverTime.hour, serverTime.minute] in [[23, 55], [23, 59]]:
+ playerManager = GameWorld.GetPlayerManager()
+ for i in xrange(playerManager.GetPlayerCount()):
+ curPlayer = playerManager.GetPlayerByIndex(i)
+ if not GameWorld.IsNormalPlayer(curPlayer):
+ continue
+ RecordTodayOnlineTime(curPlayer)
+ return
+
+def RecordTodayOnlineTime(curPlayer):
+ '''更新记录今日累计在线时长
+ 【注】不能在onday调用,不然可能导致流向记录是错误的
+ 比如玩家离线了多天后上线,会触发onday,此时记录的在线时长实际是上一次离线天的在线时长
+
+ 【正确调用时机】
+ 1. 每次离线
+ 2. 每日的 23:59 分触发一次,理论上可能最多少统计1分钟,暂无视
+ '''
+ onlineTime = GetOnlineTimeToday(curPlayer)
+ DataRecordPack.DR_OnlineTimeToday(curPlayer, onlineTime)
+ return
+
+def GetOnlineTimeToday(curPlayer):
+ ## 获取今日累计在线时长,即使不离线过天也需要重置重新计算
+ curTime = int(time.time())
+ onlineTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DayOnlineTime)
+ calcTime = curPlayer.GetDictByKey(ChConfig.Def_PDict_DayOnlineCalcTime) # 计算用,不用存db
+ if not calcTime:
+ calcTime = curTime
+ curPlayer.SetDict(ChConfig.Def_PDict_DayOnlineCalcTime, curTime)
+
+ passTime = curTime - calcTime
+ if passTime > 0:
+ onlineTime += passTime
+ onlineTime = min(onlineTime, 86400) # 3600*24=86400 # 最大累计1天时长
+ GameWorld.DebugLogEx("今日累计在线时长: %s, passTime=%s", onlineTime, passTime, curPlayer.GetPlayerID())
+ NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DayOnlineTime, onlineTime)
+ return onlineTime
+
+
##更新保存玩家在线时间
# @param curPlayer 玩家实例
# @param tick 时间tick
@@ -1058,6 +1116,7 @@
#宠物下线逻辑, 这里要进行排行榜, 优先做, 避免玩家光环等属性影响宠物属性失效
PetControl.DoLogic_PetInfo_OnLeaveServer(curPlayer, tick)
+ RecordTodayOnlineTime(curPlayer)
#清除下线消失的buff, 在更新排行榜之前
__DisconnectClearBuff(curPlayer, tick)
diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerEventCounter.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerEventCounter.py
index de47b2e..824208a 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerEventCounter.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerEventCounter.py
@@ -276,7 +276,7 @@
PlayerLove.DoPlayerOnDay(curPlayer)
#仙宫
PlayerXiangong.PlayerOnDay(curPlayer)
- PlayerControl.PayCoinOnDay(curPlayer)
+ PlayerControl.PlayerOnDay(curPlayer)
ChPlayer.PlayerOnDay(curPlayer)
PlayerActivity.OnDay(curPlayer)
PlayerLLMJ.PlayerOnDay(curPlayer)
--
Gitblit v1.8.0