From c2d45420190e02447a79a680199ab4636ce986e2 Mon Sep 17 00:00:00 2001
From: hxp <ale99527@vip.qq.com>
Date: 星期二, 20 五月 2025 15:49:29 +0800
Subject: [PATCH] 16 卡牌服务端(优化备档存取逻辑,GetServerID改为取接口;调整单服StartDB渠口、启动加载数据流程,支持服层级每秒、每分Process)

---
 ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/DB/DBDataMgr.py |   45 ++++++++++++++++-----------------------------
 1 files changed, 16 insertions(+), 29 deletions(-)

diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/DB/DBDataMgr.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/DB/DBDataMgr.py
index 99738ed..f5ea998 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/DB/DBDataMgr.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/DB/DBDataMgr.py
@@ -15,6 +15,7 @@
 #"""Version = 2025-05-09 12:20"""
 #-------------------------------------------------------------------------------
 
+import CommFunc
 import GameWorld
 import PyGameData
 import DBEventTrig
@@ -23,20 +24,14 @@
 import DBFamily
 import DBMail
 
-import binascii
 import time
-import zlib
 import os
 
 BakRoot = "C:\ServerRealTimeBackup"
 BakFileType = ".bak"
+BackupCopyMax = 3
 
-#临时变量,之后优化
 g_loadErr = False
-Map2ServerID = {
-                10010:87,
-                10090:89,
-                }
     
 def OnServerStart():
     GameWorld.DebugLog("地图服务器启动")
@@ -70,10 +65,8 @@
 def LoadServerDataBackup():
     ## 服务器公共数据备档加载
     global g_loadErr
-    mapID = GameWorld.GetMap().GetMapID()
-    if mapID not in Map2ServerID:
-        return
-    serverName = "S%s" % Map2ServerID[mapID]
+    serverID = GameWorld.GetGameWorld().GetServerID()
+    serverName = "S%s" % serverID
     BakDir = os.path.join(BakRoot, serverName)
     GameWorld.Log("加载备档: %s" % BakDir)
     bakFileList = GetBakFileSortList(BakDir)
@@ -84,13 +77,11 @@
     GameWorld.Log("读取备档: %s" % bakFilePath)
     
     f = open(bakFilePath, 'rb')
-    compressed_data = f.read().strip()
+    compressed_data = f.read()
     f.close()
     
-    try:
-        decompressed_data = zlib.decompress(compressed_data)
-        bakData = binascii.a2b_hex(decompressed_data)
-    except:
+    bakData = CommFunc.Decompress(compressed_data)
+    if not bakData:
         g_loadErr = True
         raise 
     
@@ -100,14 +91,11 @@
 def ServerDataBackup():
     ## 服务器公共数据定时备档,暂时直接存盘
     if g_loadErr:
-        GameWorld.ErrLog("加载备档已异常,暂时不在存储备档")
+        GameWorld.ErrLog("加载备档已异常,暂时不再存储备档,防止已经错误加载的数据覆盖")
         return
-    mapID = GameWorld.GetMap().GetMapID()
-    if mapID not in Map2ServerID:
-        return
-    serverName = "S%s" % Map2ServerID[mapID]
+    serverID = GameWorld.GetGameWorld().GetServerID()
+    serverName = "S%s" % serverID
     BakDir = os.path.join(BakRoot, serverName)
-    BackupCopyMax = 3
     GameWorld.Log("服务器备档: %s" % serverName)
     
     if not os.path.exists(BakDir):
@@ -117,9 +105,13 @@
     bakFilePath = os.path.join(BakDir, "%s_%s%s" % (serverName, curTime, BakFileType))
     bakData = GetSavePyData()
     GameWorld.Log("Bak:%s, len=%s, %s" % (serverName, len(bakData), bakFilePath))
+    compressed_data = CommFunc.Compress(bakData)
+    if not compressed_data:
+        GameWorld.SendGameError("ServerDataBackupError")
+        return
+    GameWorld.Log("compress len=%s" % len(compressed_data))
+    
     try:
-        compressed_data = zlib.compress(bakData, 9)    #最大压缩
-        GameWorld.Log("compress len=%s" % len(compressed_data))
         fp = open(bakFilePath, "wb")
         fp.write(compressed_data)
         fp.close()
@@ -144,12 +136,7 @@
     pyGameDataMgr = GetDBDataMgr()
     result = pyGameDataMgr.GetSaveData()
     GameWorld.Log("GetSavePyData!! id = %s-%s"%(id(pyGameDataMgr), len(result)))
-    result = binascii.b2a_hex(result)
-    #GameWorld.DebugLog("GetSavePyData!! result = %s-%s"%(result, len(result)))
-    # 字节码在C++转化会发生错误must be string without null bytes, not str,但是可以正常保存,错误会在下次调用便宜接口才会触发
-    # 暂时改成字符串返回,暂无解决方案
     return result
-#    return str(len(result)) + "|" + result
 
 def LoadPyGameData(gameBuffer, pos):
     pyGameDataMgr = GetDBDataMgr()

--
Gitblit v1.8.0