fix(socket): 移除debug.Stack并统一使用cool.Loger记录panic错误
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"log"
|
||||
"os"
|
||||
"runtime/debug"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
@@ -45,9 +44,9 @@ func (s *Server) OnClose(c gnet.Conn, _ error) (action gnet.Action) {
|
||||
defer func() {
|
||||
if err := recover(); err != nil { // 恢复 panic,err 为 panic 错误值
|
||||
// 1. 打印错误信息
|
||||
log.Printf("捕获到 panic 错误:%v", err)
|
||||
// 2. 打印完整调用堆栈(debug.Stack() 获取堆栈字节流,转为字符串)
|
||||
log.Printf("panic 详细堆栈:\n%s", debug.Stack())
|
||||
|
||||
cool.Loger.Error(context.TODO(), "panic 错误:", err)
|
||||
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -104,9 +103,9 @@ func (s *Server) OnTraffic(c gnet.Conn) (action gnet.Action) {
|
||||
defer func() {
|
||||
if err := recover(); err != nil { // 恢复 panic,err 为 panic 错误值
|
||||
// 1. 打印错误信息
|
||||
log.Printf("捕获到 panic 错误:%v", err)
|
||||
// 2. 打印完整调用堆栈(debug.Stack() 获取堆栈字节流,转为字符串)
|
||||
log.Printf("panic 详细堆栈:\n%s", debug.Stack())
|
||||
|
||||
cool.Loger.Error(context.TODO(), "panic 错误:", err)
|
||||
|
||||
}
|
||||
}()
|
||||
if s.network != "tcp" {
|
||||
|
||||
@@ -514,14 +514,16 @@ func (f *FightC) enterturn(fattack, sattack *action.SelectSkillAction) {
|
||||
// 伤害值
|
||||
|
||||
// 根据攻击方归属设置当前战斗的主/次攻击方属性
|
||||
if fattack != nil {
|
||||
if fattack.GetPlayerID() == f.ownerID {
|
||||
f.First, f.Second = f.Our, f.Opp // 攻击方为我方时,主攻击方是我方
|
||||
|
||||
if fattack.GetPlayerID() == f.ownerID {
|
||||
f.First, f.Second = f.Our, f.Opp // 攻击方为我方时,主攻击方是我方
|
||||
|
||||
} else {
|
||||
f.First, f.Second = f.Opp, f.Our // 攻击方为对方时,主攻击方是对方
|
||||
} else {
|
||||
f.First, f.Second = f.Opp, f.Our // 攻击方为对方时,主攻击方是对方
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
f.First.InitAttackValue()
|
||||
f.Second.InitAttackValue()
|
||||
|
||||
|
||||
@@ -409,7 +409,18 @@ func (p *Player) Save() {
|
||||
|
||||
}
|
||||
if p.FightC != nil {
|
||||
go p.FightC.Over(p, info.BattleOverReason.PlayerOffline) //玩家逃跑,但是不能锁线程
|
||||
go func() {
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil { // 恢复 panic,err 为 panic 错误值
|
||||
// 1. 打印错误信息
|
||||
|
||||
cool.Loger.Error(context.TODO(), "panic 错误:", err)
|
||||
|
||||
}
|
||||
}()
|
||||
p.FightC.Over(p, info.BattleOverReason.PlayerOffline) //玩家逃跑,但是不能锁线程
|
||||
}()
|
||||
|
||||
}
|
||||
p.Info.TimeToday = p.Info.TimeToday + uint32(time.Now().Unix()) - uint32(p.Onlinetime) //保存电池时间
|
||||
|
||||
@@ -77,3 +77,9 @@ func (c *BlazingController) GetSession(ctx context.Context, req *SessionReq) (re
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
type MockReq struct {
|
||||
g.Meta `path:"/mock" method:"GET"`
|
||||
Email string `json:"email" v:"required|email"`
|
||||
Password string `json:"password" v:"required"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user