From 71a5b8c236d7538053a3a893adccaa0d59798521 Mon Sep 17 00:00:00 2001
From: hxp <ale99527@vip.qq.com>
Date: 星期六, 20 二月 2021 15:26:52 +0800
Subject: [PATCH] 4936 【工具】没有绿的异常报错增加发送运维邮件通知

---
 ServerPython/CoreServerGroup/GameServer/Script/NetPackCommon.py                                  |    8 --
 ServerPython/CoreServerGroup/GameServer/Script/GM/GMShell.py                                     |    5 -
 ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/CrossPlayerData.py    |    5 -
 Tool/RemoteTool/RemoteServer/webapp.py                                                           |   10 +++
 ServerPython/CoreServerGroup/GameServer/Script/Player/ChPlayer.py                                |    8 --
 ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/NetPackCommon.py             |    8 --
 ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/CrossRealmMsg.py                   |    9 --
 ServerPython/CoreServerGroup/GameServer/Script/GameWorld.py                                      |   24 +++++--
 ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/GameWorldProcess.py                |   14 +---
 ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/DataRecordPack.py            |    2 
 ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/ChPlayer.py           |    8 --
 ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GameWorld.py                 |   24 +++++--
 ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerEventCounter.py |    4 -
 13 files changed, 60 insertions(+), 69 deletions(-)

diff --git a/ServerPython/CoreServerGroup/GameServer/Script/GM/GMShell.py b/ServerPython/CoreServerGroup/GameServer/Script/GM/GMShell.py
index 7a34771..858d160 100644
--- a/ServerPython/CoreServerGroup/GameServer/Script/GM/GMShell.py
+++ b/ServerPython/CoreServerGroup/GameServer/Script/GM/GMShell.py
@@ -205,11 +205,8 @@
         callFunc(orderId, cmdDict)
         
     except BaseException:
-        GameWorld.Log('GM命令错误 - > %s'%(traceback.format_exc()))
-
         GMCommon.GMCommandResult(orderId, gmCmdDict, GMCommon.Def_GMGSEntranceFail)
-        if GameWorld.GetGameWorld().GetDebugLevel():
-            raise BaseException(str(traceback.format_exc()))
+        GameWorld.RaiseException('GM命令错误\r\n%s'%(traceback.format_exc()))
         return 
 
     return 
diff --git a/ServerPython/CoreServerGroup/GameServer/Script/GameWorld.py b/ServerPython/CoreServerGroup/GameServer/Script/GameWorld.py
index 44f3767..363a530 100644
--- a/ServerPython/CoreServerGroup/GameServer/Script/GameWorld.py
+++ b/ServerPython/CoreServerGroup/GameServer/Script/GameWorld.py
@@ -1049,15 +1049,25 @@
     
     return inputText
 
+def RaiseException(errorMsg, playerID=0):
+    ## 处理抛出异常信息,debug下直接抛出异常报错信息,否则发送运维邮件提醒
+    ErrLog(errorMsg, playerID)
+    if GetGameWorld().GetDebugLevel():
+        raise Exception(errorMsg)
+    else:
+        SendGameError("GameServerRaiseException", errorMsg)
+    return
 
-# 向运维发送邮件,用于需要紧急处理的信息
-# 此处不包含服务器报错的汇报
-def SendGameStateMail(msgInfo):
-    # 使用方式 向OpenStateUrl 发送Type为GameWarning,那么就会收到一封游戏内容警告邮件,信息为MsgInfo
+def SendGameError(errType, msgInfo=""):
+    ''' 向运维发送邮件,用于需要紧急处理的信息
+    @param errType: 错误类型,自定义即可
+    @param msgInfo: 错误信息,可选
+    '''
     getUrl = ReadChConfig.GetPyMongoConfig("EventReport", "OpenStateUrl")
     groupID = ReadChConfig.GetPyMongoConfig("platform", "GroupID")
     userDBName = ReadChConfig.GetPyMongoConfig("connect", "USER_DB_NAME")
-    getUrl = getUrl + "?Type=GameWarning&groupID=%s&userDBName=%s&MsgInfo=%s"%(groupID, userDBName, urllib.quote_plus(msgInfo))
-    
+    getUrl = getUrl + "?Type=%s&groupID=%s&userDBName=%s"%(errType, groupID, userDBName)
+    if msgInfo:
+        getUrl = getUrl + "&MsgInfo=%s" % urllib.quote_plus(msgInfo)
     GetGameWorld().EventReport_EventReport("", "", "", "", 0, getUrl)
-    
\ No newline at end of file
+    return
diff --git a/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/CrossRealmMsg.py b/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/CrossRealmMsg.py
index 5781ac3..4352872 100644
--- a/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/CrossRealmMsg.py
+++ b/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/CrossRealmMsg.py
@@ -122,9 +122,7 @@
             GameWorld.ErrLog("没有该信息类型逻辑处理!")
             
     except:
-        GameWorld.ErrLog("OnCrossServerReceiveMsg: %s" % (traceback.format_exc()))
-        if GameWorld.GetGameWorld().GetDebugLevel():
-            raise BaseException(str(traceback.format_exc()))
+        GameWorld.RaiseException("跨服服务器接收信息处理报错 \r\n%s" % str(traceback.format_exc()))
     return
 
 def ClientServerMsg_ServerInitOK(serverGroupID, tick):
@@ -315,10 +313,7 @@
             GameWorld.ErrLog("没有该信息类型逻辑处理!")
             
     except:
-        GameWorld.ErrLog("OnClientServerReceiveMsg: %s" % (traceback.format_exc()))
-        if GameWorld.GetGameWorld().GetDebugLevel():
-            raise BaseException(str(traceback.format_exc()))
-        
+        GameWorld.RaiseException("子服服务器接收信息处理报错\r\n%s" % str(traceback.format_exc()))
     return
 
 def MapServer_ClientServerReceiveMsg(msgType, msgData):
diff --git a/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/GameWorldProcess.py b/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/GameWorldProcess.py
index 59c2f77..4ad6cf0 100644
--- a/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/GameWorldProcess.py
+++ b/ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/GameWorldProcess.py
@@ -1842,20 +1842,12 @@
     if mapServerPack.GetState() not in [0,1,2,3] and curMap.GetState() != mapServerPack.GetState():
         # 记录服务器是否正常开启完毕, 避免重复发送
         GameWorld.DebugLog("MapServer_RunningStateRefresh--_%s"%([mapServerPack.GetState(), curMap.GetState(), mapServerPack.GetMapID(), curMap.GetID()]))
-        SendGameError("MapError")
+        GameWorld.SendGameError("MapError")
         
     curMap.SetState(mapServerPack.GetState())
     curMap.SetRefreshTick(tick)
     
     return
-
-
-def SendGameError(state):
-    getUrl = ReadChConfig.GetPyMongoConfig("EventReport", "OpenStateUrl")
-    groupID = ReadChConfig.GetPyMongoConfig("platform", "GroupID")
-    userDBName = ReadChConfig.GetPyMongoConfig("connect", "USER_DB_NAME")
-    getUrl = getUrl + "?Type=%s&groupID=%s&userDBName=%s"%(state, groupID, userDBName)
-    GameWorld.GetGameWorld().EventReport_EventReport("", "", "", "", 0, getUrl)
     
 ## 刷新地图服务器状态, 如果1分钟没有状态回报, 刷新为消失状态
 #  @param tick 当前时间
@@ -1883,7 +1875,7 @@
         curMap.SetState(IPY_GameServer.mssNone)
         if not isSendMapClose:
             # 避免多地图发送过多邮件, 如关服的时候
-            SendGameError("MapDisconnect")   # 状态报告
+            GameWorld.SendGameError("MapDisconnect")   # 状态报告
             isSendMapClose = True
 
     return
@@ -1942,6 +1934,6 @@
 def ChangeGameServerState(state):
     # 只接收大于等于mssPyError
     GameWorld.DebugLog("ChangeGameServerState:%s"%state)
-    SendGameError("GameServerError")
+    GameWorld.SendGameError("GameServerError")
     
     
\ No newline at end of file
diff --git a/ServerPython/CoreServerGroup/GameServer/Script/NetPackCommon.py b/ServerPython/CoreServerGroup/GameServer/Script/NetPackCommon.py
index dbde765..6ca8e2a 100644
--- a/ServerPython/CoreServerGroup/GameServer/Script/NetPackCommon.py
+++ b/ServerPython/CoreServerGroup/GameServer/Script/NetPackCommon.py
@@ -209,9 +209,7 @@
         curPackHeadRegDict["CallFunc"](index, curPackData, tick)
         
     except Exception:
-        Log("python自定义封包解析失败~~~~~\r\n%s" % traceback.format_exc())
-        if GameWorld.GetGameWorld().GetDebugLevel():
-            raise Exception("python自定义封包解析失败~~~~~\r\n%s" % traceback.format_exc())
+        GameWorld.RaiseException("python自定义封包解析失败\r\n%s" % traceback.format_exc())
         return 
     
     
@@ -299,9 +297,7 @@
         curPackHeadRegDict["CallFunc"](routeIndex, mapID, curPackData, tick)
         #Log("RecvMapPyPack: CallFunc curPackHead = %s"%curPackHead)
     except Exception:
-        Log("RecvMapPyPack python自定义封包解析失败~~~~~\r\n%s" % traceback.format_exc())
-        if GameWorld.GetGameWorld().GetDebugLevel():
-            raise Exception("RecGamePyPack python自定义封包解析失败~~~~~\r\n%s" % traceback.format_exc())
+        GameWorld.RaiseException("RecvMapPyPack python自定义封包解析失败\r\n%s" % traceback.format_exc())
         return 
     
 #-------------------------------------------------------------------------------
diff --git a/ServerPython/CoreServerGroup/GameServer/Script/Player/ChPlayer.py b/ServerPython/CoreServerGroup/GameServer/Script/Player/ChPlayer.py
index efdfb0b..7c76f53 100644
--- a/ServerPython/CoreServerGroup/GameServer/Script/Player/ChPlayer.py
+++ b/ServerPython/CoreServerGroup/GameServer/Script/Player/ChPlayer.py
@@ -90,9 +90,7 @@
     except:
         curPlayer.Kick(IPY_PlayerDefine.disWaitForPlayerLoinError)
         import traceback
-        GameWorld.ErrLog("玩家上线逻辑错误~~~~~\r\n%s" % traceback.format_exc())
-        if GameWorld.GetGameWorld().GetDebugLevel():
-            raise Exception("玩家上线逻辑错误~~~~\r\n%s" % traceback.format_exc())
+        GameWorld.RaiseException("玩家上线逻辑错误\r\n%s" % traceback.format_exc())
     return
 
 #---------------------------------------------------------------------
@@ -522,9 +520,7 @@
         __Func_PlayerDisconnect(curPlayer, tick)
     except:
         import traceback
-        GameWorld.ErrLog("玩家下线逻辑错误~~~~~\r\n%s" % traceback.format_exc())
-        if GameWorld.GetGameWorld().GetDebugLevel():
-            raise Exception("玩家下线逻辑错误~~~~\r\n%s" % traceback.format_exc())
+        GameWorld.RaiseException("玩家下线逻辑错误\r\n%s" % traceback.format_exc())
     #调用底层下线
     curPlayer.DoDisconnect()
     return
diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/DataRecordPack.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/DataRecordPack.py
index 7d66764..ad40b40 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/DataRecordPack.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/DataRecordPack.py
@@ -364,7 +364,7 @@
     SendEventPack("CTGError", dataDict, curPlayer)
     GameWorld.ErrLog("%s. %s" % (errorInfo, addDict), curPlayer.GetPlayerID())
     
-    GameWorld.SendGameStateMail("CTGError:%s - %s"%(errorInfo, dataDict))
+    GameWorld.SendGameError("GameWarning", "CTGError:%s - %s"%(errorInfo, dataDict))
     return
 
 def DR_CTGOK(curPlayer, addDict):
diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GameWorld.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GameWorld.py
index 7236d4b..21d0311 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GameWorld.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/GameWorld.py
@@ -2024,16 +2024,26 @@
     curPlayer.DebugAnswer(text)
     return
 
+def RaiseException(errorMsg, playerID=0):
+    ## 处理抛出异常信息,debug下直接抛出异常报错信息,否则发送运维邮件提醒
+    ErrLog(errorMsg, playerID)
+    if GetGameWorld().GetDebugLevel():
+        raise Exception(errorMsg)
+    else:
+        SendGameError("MapServerRaiseException", errorMsg)
+    return
 
-# 向运维发送邮件,用于需要紧急处理的信息
-# 此处不包含服务器报错的汇报
-def SendGameStateMail(msgInfo):
-    # 使用方式 向OpenStateUrl 发送Type为GameWarning,那么就会收到一封游戏内容警告邮件,信息为MsgInfo
+def SendGameError(errType, msgInfo=""):
+    ''' 向运维发送邮件,用于需要紧急处理的信息
+    @param errType: 错误类型,自定义即可
+    @param msgInfo: 错误信息,可选
+    '''
     getUrl = ReadChConfig.GetPyMongoConfig("EventReport", "OpenStateUrl")
     groupID = ReadChConfig.GetPyMongoConfig("platform", "GroupID")
     userDBName = ReadChConfig.GetPyMongoConfig("connect", "USER_DB_NAME")
-    getUrl = getUrl + "?Type=GameWarning&groupID=%s&userDBName=%s&MsgInfo=%s"%(groupID, userDBName, urllib.quote_plus(msgInfo))
-    
+    getUrl = getUrl + "?Type=%s&groupID=%s&userDBName=%s&mapID=%s"%(errType, groupID, userDBName, GetMap().GetMapID())
+    if msgInfo:
+        getUrl = getUrl + "&MsgInfo=%s" % urllib.quote_plus(msgInfo)
     GetGameWorld().EventReport_EventReport("", "", "", "", 0, getUrl)
-
+    return
 
diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/NetPackCommon.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/NetPackCommon.py
index c85c028..df5680d 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/NetPackCommon.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/NetPackCommon.py
@@ -208,9 +208,7 @@
         curPackHeadRegDict["CallFunc"](index, curPackData, tick)
         
     except Exception:
-        Log("!!!python自定义封包解析失败~~~~~\r\n%s" % traceback.format_exc())
-        if GameWorld.GetGameWorld().GetDebugLevel():
-            raise Exception("python自定义封包解析失败~~~~~\r\n%s" % traceback.format_exc())
+        GameWorld.RaiseException("!!!python自定义封包解析失败\r\n%s" % traceback.format_exc())
         return 
     
     
@@ -282,9 +280,7 @@
         curPackHeadRegDict["CallFunc"](curPackData, tick)
         #Log("RecGamePyPack: curPackHead = %s"%curPackHead)
     except Exception:
-        Log("RecGamePyPack python自定义封包解析失败~~~~~\r\n%s" % traceback.format_exc())
-        if GameWorld.GetGameWorld().GetDebugLevel():
-            raise Exception("RecGamePyPack python自定义封包解析失败~~~~~\r\n%s" % traceback.format_exc())
+        GameWorld.RaiseException("RecGamePyPack python自定义封包解析失败\r\n%s" % traceback.format_exc())
         return 
 #-------------------------------------------------------------------------------
 ##发送Map到GameServer的沟通包
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 3005231..311e42a 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/ChPlayer.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/ChPlayer.py
@@ -1182,9 +1182,7 @@
     except:
         curPlayer.Kick(IPY_GameWorld.disWaitForPlayerLoinError)
         import traceback
-        GameWorld.ErrLog("玩家上线逻辑错误~~~~~\r\n%s" % traceback.format_exc())
-        if GameWorld.GetGameWorld().GetDebugLevel():
-            raise Exception("玩家上线逻辑错误~~~~\r\n%s" % traceback.format_exc())
+        GameWorld.RaiseException("玩家上线逻辑错误\r\n%s" % traceback.format_exc())
     return
     
     
@@ -2810,9 +2808,7 @@
         DoPlayerDisconnect(curPlayer, tick)
     except:
         import traceback
-        GameWorld.ErrLog("玩家下线逻辑错误~~~~~\r\n%s" % traceback.format_exc())
-        if GameWorld.GetGameWorld().GetDebugLevel():
-            raise Exception("玩家下线逻辑错误~~~~~\r\n%s" % traceback.format_exc())
+        GameWorld.RaiseException("玩家下线逻辑错误\r\n%s" % traceback.format_exc())
         
     #调用底层使玩家下线
     curPlayer.DoDisconnect(tick)
diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/CrossPlayerData.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/CrossPlayerData.py
index 91f317a..cf03c51 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/CrossPlayerData.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/CrossPlayerData.py
@@ -132,10 +132,7 @@
             
     except BaseException:
         errorMsg = str(traceback.format_exc())
-        GameWorld.ErrLog('接收跨服变更玩家数据错误 - > %s' % errorMsg, curPlayer.GetPlayerID())
-        if GameWorld.GetGameWorld().GetDebugLevel():
-            raise Exception(errorMsg)
-        
+        GameWorld.RaiseException('接收跨服变更玩家数据错误 \r\n%s' % errorMsg, curPlayer.GetPlayerID())
     return
 
 ## ----------------------------------------------------------------------------------------------
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 b1c5d28..3b8585b 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerEventCounter.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerEventCounter.py
@@ -438,9 +438,7 @@
     except:
         curPlayer.Kick(IPY_GameWorld.disWaitForPlayerLoinError)
         import traceback
-        GameWorld.ErrLog("玩家上线逻辑错误~~~~~\r\n%s" % traceback.format_exc())
-        if GameWorld.GetGameWorld().GetDebugLevel():
-            raise Exception("玩家上线逻辑错误~~~~\r\n%s" % traceback.format_exc())
+        GameWorld.RaiseException("玩家上线逻辑错误\r\n%s" % traceback.format_exc())
     return
 
 #--------------------------------------------------------
diff --git a/Tool/RemoteTool/RemoteServer/webapp.py b/Tool/RemoteTool/RemoteServer/webapp.py
index bc77fbd..ad2220f 100644
--- a/Tool/RemoteTool/RemoteServer/webapp.py
+++ b/Tool/RemoteTool/RemoteServer/webapp.py
@@ -119,6 +119,14 @@
                                                        dataDict.get("userDBName", 0),
                                                        urllib.unquote_plus(dataDict.get("MsgInfo", 0)))
             SendEmail(ServerInfo)
+        elif stateType in ["MapServerRaiseException", "GameServerRaiseException", "RaiseException"]:
+            ServerInfo = "%s 抛出Try异常报错:服务器组:%s, dbname:%s, MapID:%s 异常信息:%s"%(
+                                                       stateType,
+                                                       dataDict.get("groupID", 0),
+                                                       dataDict.get("userDBName", 0),
+                                                       dataDict.get("mapID", 0),
+                                                       urllib.unquote_plus(dataDict.get("MsgInfo", 0)))
+            SendEmail(ServerInfo)
         elif stateType == "QueryMapOK":
             if g_AllMapCnt == 0:
                 if not os.path.exists(".\MapCount.txt"):
@@ -148,7 +156,7 @@
     sender = '2199274165@qq.com'
     
     # 这里可以填写需要接收汇报的邮件地址
-    receivers = ['305670599@qq.com']#, '1142397645@qq.com']  
+    receivers = ['305670599@qq.com']#, '1142397645@qq.com', '305670599@qq.com', '995275190@qq.com']  
      
     message = MIMEText('异常汇报:%s'%ServerInfo, 'plain', 'gbk')
     message['From'] = Header("游戏服务器异常汇报", 'gbk')

--
Gitblit v1.8.0