| | |
| | |
|
| | | import DBDataMgr
|
| | | import GameWorld
|
| | | import IpyGameDataPY
|
| | | import PlayerEventCounter
|
| | | import ShareDefine
|
| | | import PlayerTeam
|
| | | import PyGameData
|
| | |
|
| | | import datetime
|
| | |
| | |
|
| | | return Get_Server_Hour(), Get_Server_Day(), Get_Server_Week(), Get_Server_Month(), Get_Server_Year()
|
| | |
|
| | | #调用该函数时,C++已经设置好区服,如果改变区服需重启
|
| | | def StartDB(tick):
|
| | | #初始化数据库, 恢复备档(按区服记录), 加载静态表
|
| | | from PyMongoDB import PyMongoMain
|
| | | PyMongoMain.StartDB()
|
| | | InitGameWorld(tick)
|
| | | return
|
| | |
|
| | | def InitGameWorld(tick):
|
| | | ## GameWorld初始化
|
| | | if PyGameData.g_initGameTime:
|
| | | return
|
| | | PyGameData.g_initGameTime = int(time.time())
|
| | | serverID = GameWorld.GetServerID()
|
| | | serverID = GameWorld.GetGameWorld().GetServerID()
|
| | | GameWorld.Log("服务器启动初始化InitGameWorld: serverID=%s" % serverID)
|
| | | DBDataMgr.OnServerStart() # 优先加载公共数据
|
| | | LoadDBPlayer()
|
| | | PyGameData.g_initGameTime = int(time.time()) # 放到加载数据之后
|
| | |
|
| | | #初始话开服时间、星期几
|
| | | initOpenServerTime = DBDataMgr.GetEventTrigMgr().GetValue(ShareDefine.Def_InitOpenServerTime)
|
| | |
| | | else:
|
| | | serverGroupID = GameWorld.GetServerGroupID()
|
| | | GameWorld.Log("服务器启动成功: ServerGroupID=%s,serverID=%s" % (serverGroupID, serverID))
|
| | | GameWorld.GetGameWorld().SetGameWorldDict(ShareDefine.Def_WorldKey_GameWorldInitOK, 1)
|
| | | PyGameData.g_serverInitOK = True
|
| | | return
|
| | |
|
| | | def AllMapServerInitOK(tick):
|
| | |
| | | @param openServerTime: 开服时间戳
|
| | | @return: 1-成功;-1-设置的时间异常;-2-已经设置过且开服了,不能重复设置
|
| | | '''
|
| | | serverID = GameWorld.GetServerID()
|
| | | serverID = GameWorld.GetGameWorld().GetServerID()
|
| | | curTime = int(time.time())
|
| | | if openServerTime < curTime:
|
| | | GameWorld.ErrLog("当前时间已经超过设置的开服时间,不能设置! serverID=%s" % serverID)
|
| | |
| | | def OnNewServerOpen(tick):
|
| | | '''新服开启需要处理的逻辑'''
|
| | |
|
| | | serverID = GameWorld.GetServerID()
|
| | | serverID = GameWorld.GetGameWorld().GetServerID()
|
| | | GameWorld.Log("执行正式开服重置逻辑... serverID=%s" % serverID)
|
| | |
|
| | | setOpenServerTime = DBDataMgr.GetEventTrigMgr().GetValue(ShareDefine.Def_SetOpenServerTime)
|
| | |
| | |
|
| | | def OnHighProcess(tick):
|
| | | ## 每秒分钟执行一次
|
| | | if not PyGameData.g_initGameTime:
|
| | | return
|
| | | if tick - PyGameData.g_highProcessTick < 1000:
|
| | | return
|
| | | PyGameData.g_highProcessTick = tick
|
| | | OnMinute(tick)
|
| | | |
| | | # 其他逻辑
|
| | | |
| | | |
| | | |
| | | return
|
| | |
|
| | | def OnMinute(tick):
|
| | | ## 每整分钟执行一次
|
| | | curTime = GameWorld.GetCurrentTime()
|
| | | curMinute = curTime.minute
|
| | | if curMinute == PyGameData.g_minuteProcess:
|
| | | return
|
| | | PyGameData.g_minuteProcess = curMinute
|
| | | |
| | | #检查服务器正式开服
|
| | | DoCheckNewServerOpen(tick)
|
| | | DBDataMgr.OnMinute(curTime)
|
| | |
| | | #GameWorldActionControl.Dispose_OperationActionState()
|
| | | #GameWorldActionControl.Dispose_DailyActionState()
|
| | | #GameWorldActionControl.Dispose_FBStateTime()
|
| | | |
| | | PlayerTeam.OnCheckTeamPlayerDisconnectTimeout(tick)
|
| | | __CheckIpyDataRecycle(curTime)
|
| | | return
|
| | |
|
| | | def DoLogic_GameWorldEvenByTime(tick):
|
| | |
| | | PlayerEventCounter.DoLogic_OnYear(tick)
|
| | | return
|
| | |
|
| | |
|
| | | def __CheckIpyDataRecycle(timeNow):
|
| | | ## 检查IpyData数据回收
|
| | | playerCount = GameWorld.GetPlayerManager().OnlineCount()
|
| | | if playerCount:
|
| | | PyGameData.g_ipyDataRecycleCheckTime = 0
|
| | | #GameWorld.DebugLog("地图还有玩家在线! playerCount=%s" % playerCount)
|
| | | return
|
| | | |
| | | curTime = GameWorld.ChangeDatetimeToNum(timeNow)
|
| | | if not PyGameData.g_ipyDataRecycleCheckTime:
|
| | | PyGameData.g_ipyDataRecycleCheckTime = curTime
|
| | | #GameWorld.DebugLog("地图没有玩家在线")
|
| | | return
|
| | | |
| | | if PyGameData.g_ipyDataRecycleCheckTime == 1:
|
| | | # 已经回收了
|
| | | #GameWorld.DebugLog("本次已经回收过了")
|
| | | return
|
| | | |
| | | if curTime - PyGameData.g_ipyDataRecycleCheckTime < 24 * 3600:
|
| | | #GameWorld.DebugLog("还未到达回收时间, passSeconds=%s" % (curTime - PyGameData.g_ipyDataRecycleCheckTime))
|
| | | return
|
| | | PyGameData.g_ipyDataRecycleCheckTime = 1 |
| | | IpyGameDataPY.IPYData.Recycle()
|
| | | return
|