This commit is contained in:
昔念
2026-02-10 10:49:01 +08:00
parent 89645c0f4c
commit c790b68d47
5 changed files with 44 additions and 7 deletions

View File

@@ -13,6 +13,7 @@ import (
"fmt"
"reflect"
"github.com/bruceshao/lockfree"
"github.com/gobwas/ws"
"github.com/gobwas/ws/wsutil"
"github.com/gogf/gf/v2/os/glog"
@@ -136,6 +137,7 @@ type ClientData struct {
ERROR_CONNUT int
Wsmsg *WsCodec
Conn gnet.Conn
LF *lockfree.Lockfree[[]byte]
//SaveL sync.Once //保存锁
//SaveDone chan struct{}
@@ -150,7 +152,15 @@ func NewClientData(c gnet.Conn) *ClientData {
Conn: c,
Wsmsg: &WsCodec{},
}
cd.LF = lockfree.NewLockfree[[]byte](
8,
cd,
lockfree.NewConditionBlockStrategy(),
)
// 启动Lockfree
if err := cd.LF.Start(); err != nil {
panic(err)
}
return cd
}
@@ -208,6 +218,23 @@ func XORDecrypt(encryptedData []byte, keyStr string) []byte {
return decrypted
}
func (h *ClientData) OnEvent(v []byte) {
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 错误:", h.Player.Info.UserID, err)
} else {
cool.Logger.Error(context.TODO(), "panic 错误:", err)
}
} else {
cool.Logger.Error(context.TODO(), "panic 错误:", err)
}
}
}()
t, ok := h.Conn.Context().(*ClientData)
if !ok {