1
This commit is contained in:
@@ -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 { // 恢复 panic,err 为 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 {
|
||||
|
||||
Reference in New Issue
Block a user