From 167f1018e83452c601f84fa12e0d42fa47cf7ae4 Mon Sep 17 00:00:00 2001
From: hxp <ale99527@vip.qq.com>
Date: 星期五, 28 十二月 2018 11:55:22 +0800
Subject: [PATCH] 5424 【后端】【1.4】跨服竞技场开发(未同步的PK信息增加存储DB,防止服务器维护后数据丢失)

---
 ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/CrossRealmPK.py |   87 +++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 82 insertions(+), 5 deletions(-)

diff --git a/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/CrossRealmPK.py b/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/CrossRealmPK.py
index 238badb..611fc5c 100644
--- a/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/CrossRealmPK.py
+++ b/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/CrossRealmPK.py
@@ -1634,6 +1634,44 @@
         
     return
 
+#跨服竞技场未通知玩家的比赛结果,注意该类只处理数据逻辑,功能相关逻辑不要写在该类,不然重读脚本不会生效
+class CrossPKUnNotifyOverInfoManager(object):
+    
+    def __init__(self):
+        self.__unNotifyOverInfoDict = {} # {playerID:tagDBCrossPKUnNotifyOverInfo, ...}
+        return
+    
+    def AddUnNotifyOverInfo(self, playerID, overInfoData):
+        self.__unNotifyOverInfoDict[playerID] = overInfoData
+        return
+    
+    def GetPlayerUnNotifyOverInfo(self, playerID): return self.__unNotifyOverInfoDict.pop(playerID, None)
+    
+    # 保存数据 存数据库和realtimebackup
+    def GetSaveData(self):
+        savaData = ""
+        cntData = ""
+        cnt = 0
+        for overInfoData in self.__unNotifyOverInfoDict.values():
+            cnt += 1
+            savaData += overInfoData.getBuffer()
+                
+        GameWorld.Log("SaveDBCrossPKUnNotifyOverInfo cnt :%s" % cnt)
+        return CommFunc.WriteDWORD(cntData, cnt) + savaData
+    
+    # 从数据库载入数据
+    def LoadPyGameData(self, datas, pos, dataslen):
+        cnt, pos = CommFunc.ReadDWORD(datas, pos)
+        GameWorld.Log("LoadDBCrossPKUnNotifyOverInfo cnt :%s" % cnt)
+        
+        for _ in xrange(cnt):
+            overInfoData = PyGameDataStruct.tagDBCrossPKUnNotifyOverInfo()
+            overInfoData.clear()
+            pos += overInfoData.readData(datas, pos, dataslen)
+            self.__unNotifyOverInfoDict[overInfoData.PlayerID] = overInfoData
+            
+        return pos
+    
 def CrossServerMsg_PKOverInfo(playerOverDict):
     ## 子服接收跨服PK结果信息
     
@@ -1651,7 +1689,24 @@
         player = GameWorld.GetPlayerManager().FindPlayerByID(playerID)
         if not player or PlayerControl.GetIsTJG(player):
             GameWorld.Log("    玩家不在线 或脱机中,先缓存,玩家上线后再同步,playerID=%s" % (playerID))
-            PyGameData.g_crossPKUnNotifyOverInfo[playerID] = sendMapOverInfo
+            overInfoData = PyGameDataStruct.tagDBCrossPKUnNotifyOverInfo()
+            overInfoData.clear()
+            overInfoData.ZoneID = zoneID
+            overInfoData.SeasonID = seasonID
+            overInfoData.RoomID = roomID
+            overInfoData.TimeStr = timeStr
+            overInfoData.OverType = overType
+            overInfoData.PlayerID = playerID
+            overInfoData.WinnerID = winnerID
+            overInfoData.RoundWinnerInfo = str(roundWinnerIDList)
+            overInfoData.RoundWinnerLen = len(overInfoData.RoundWinnerInfo)
+            overInfoData.PKScore = pkScore
+            overInfoData.DanLV = danLV
+            overInfoData.CWinCount = cWinCount
+            overInfoData.AddScore = addScore
+            overInfoData.TagPlayerID = tagPlayerID
+            overInfoData.TagPlayerName = tagPlayerName
+            PyDataManager.GetCrossPKUnNotifyOverInfoManager().AddUnNotifyOverInfo(playerID, overInfoData)
             continue
         
         PlayerControl.SetVsRoomId(player, 0)
@@ -1663,14 +1718,36 @@
 
 def __OnLoginNotifyPKOverInfo(curPlayer):
     playerID = curPlayer.GetPlayerID()
-    if playerID not in PyGameData.g_crossPKUnNotifyOverInfo:
+    overInfoData = PyDataManager.GetCrossPKUnNotifyOverInfoManager().GetPlayerUnNotifyOverInfo(playerID)
+    if not overInfoData:
         return
-    overInfo = PyGameData.g_crossPKUnNotifyOverInfo.pop(playerID)
     PlayerControl.SetCrossRealmState(curPlayer, 0)
     PlayerControl.SetVsRoomId(curPlayer, 0)
-    sysMsg = str(overInfo)
+    
+    zoneID = overInfoData.ZoneID
+    seasonID = overInfoData.SeasonID
+    roomID = overInfoData.RoomID
+    timeStr = overInfoData.TimeStr
+    overType = overInfoData.OverType
+    #playerID = overInfoData.PlayerID
+    winnerID = overInfoData.WinnerID
+    roundWinnerIDList = []
+    try:
+        roundWinnerIDList = eval(overInfoData.RoundWinnerInfo)
+    except:
+        GameWorld.ErrLog("__OnLoginNotifyPKOverInfo roundWinnerIDList eval error! RoundWinnerInfo=%s" % overInfoData.RoundWinnerInfo, playerID)
+    pkScore = overInfoData.PKScore
+    danLV = overInfoData.DanLV
+    cWinCount = overInfoData.CWinCount
+    addScore = overInfoData.AddScore
+    tagPlayerID = overInfoData.TagPlayerID
+    tagPlayerName = overInfoData.TagPlayerName
+    notifyState = 0 # 登录才通知的默认未通知
+    sendMapOverInfo = [roomID, zoneID, seasonID, timeStr, overType, winnerID, roundWinnerIDList, pkScore, danLV, cWinCount, addScore, tagPlayerID, tagPlayerName, notifyState]
+    sysMsg = str(sendMapOverInfo)
     curPlayer.MapServer_QueryPlayerResult(0, 0, "CrossPKOverInfo", sysMsg, len(sysMsg))
-    GameWorld.Log("玩家上线通知地图未结算的跨服PK结算: mapID=%s,overInfo=%s" % (curPlayer.GetMapID(), overInfo), playerID)
+    GameWorld.Log("玩家上线通知地图未结算的跨服PK结算: roomID=%s,zoneID=%s,seasonID=%s,timeStr=%s,overType=%s,winnerID=%s,roundWinnerIDList=%s, pkScore=%s,danLV=%s,cWinCount=%s,addScore=%s,tagPlayerID=%s,notifyState=%s,mapID=%s" 
+                  % (roomID, zoneID, seasonID, timeStr, overType, winnerID, roundWinnerIDList, pkScore, danLV, cWinCount, addScore, tagPlayerID, notifyState, curPlayer.GetMapID()), playerID)
     return
 
 

--
Gitblit v1.8.0