```
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

feat(player): 启用panic恢复机制处理客户端事件

在ClientData的OnEvent方法中启用defer函数来捕获和处理panic异常,
确保程序在遇到运行时错误时能够正常记录日志并继续运行,提高服务稳定性。

当发生panic时,会记录服务器ID、用户ID和错误信息到日志中。
```
This commit is contained in:
昔念
2026-03-03 23:42:23 +08:00
parent 907517595c
commit 1cbe5d60e7

View File

@@ -91,23 +91,23 @@ func XORDecryptU(encryptedData []byte, key uint32) []byte {
// 遍历结构体方法并执行RECV_cmd
func (h *ClientData) OnEvent(data common.TomeeHeader) {
// defer func() {
// if err := recover(); err != nil { // 恢复 panicerr 为 panic 错误值
// // 1. 打印错误信息
// if h.Player != nil {
// if h.Player.Info != nil {
// cool.Logger.Error(context.TODO(), "panic 错误:", cool.Config.ServerInfo.OnlineID, h.Player.Info.UserID, err)
// } else {
// cool.Logger.Error(context.TODO(), "panic 错误:", cool.Config.ServerInfo.OnlineID, err)
defer func() {
if err := recover(); err != nil { // 恢复 panicerr 为 panic 错误值
// 1. 打印错误信息
if h.Player != nil {
if h.Player.Info != nil {
cool.Logger.Error(context.TODO(), "panic 错误:", cool.Config.ServerInfo.OnlineID, h.Player.Info.UserID, err)
} else {
cool.Logger.Error(context.TODO(), "panic 错误:", cool.Config.ServerInfo.OnlineID, err)
// }
}
// } else {
// cool.Logger.Error(context.TODO(), "panic 错误:", err)
// }
} else {
cool.Logger.Error(context.TODO(), "panic 错误:", err)
}
// }
// }()
}
}()
if data.CMD > 1001 {
if h.Player == nil {