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

@@ -249,9 +249,13 @@ func handle(c gnet.Conn) {
func (s *Server) onevent(c gnet.Conn, data []byte) { func (s *Server) onevent(c gnet.Conn, data []byte) {
if t, ok := c.Context().(*player.ClientData); ok { if t, ok := c.Context().(*player.ClientData); ok {
s.workerPool.Submit(func() { //提交任务
t.OnEvent(data) if t.LF.Running() {
}) t.LF.Producer().Write(data)
}
// s.workerPool.Submit(func() { //提交任务
// t.OnEvent(data)
// })
} }
} }

View File

@@ -21,7 +21,13 @@ func (h Controller) EggGamePlay(data1 *egg.C2S_EGG_GAME_PLAY, c *player.Player)
data1.EggNum = 10 data1.EggNum = 10
} }
r := c.Service.Item.CheakItem(400501) r := c.Service.Item.CheakItem(400501)
if r < int32(data1.EggNum) { if data1.EggNum > 10 || data1.EggNum <= 0 {
}
if r < 0 {
return nil, errorcode.ErrorCode(errorcode.ErrorCodes.ErrGachaTicketsInsufficient)
}
if data1.EggNum > uint32(r) {
return nil, errorcode.ErrorCode(errorcode.ErrorCodes.ErrGachaTicketsInsufficient) return nil, errorcode.ErrorCode(errorcode.ErrorCodes.ErrGachaTicketsInsufficient)
} }

View File

@@ -9,7 +9,7 @@ import (
// 对应原 C# 的 C2S_EGG_GAME_PLAY // 对应原 C# 的 C2S_EGG_GAME_PLAY
type C2S_EGG_GAME_PLAY struct { type C2S_EGG_GAME_PLAY struct {
Head common.TomeeHeader `cmd:"3201" struc:"skip"` Head common.TomeeHeader `cmd:"3201" struc:"skip"`
EggNum int32 `struc:"uint32"` // 抽蛋次数标识1 = 1次 2 = 5次 3 = 10次 EggNum uint32 `struc:"uint32"` // 抽蛋次数标识1 = 1次 2 = 5次 3 = 10次
// 注Go 中 uint 是平台相关类型32/64位游戏开发中推荐用 uint32 明确匹配 C# 的 uint // 注Go 中 uint 是平台相关类型32/64位游戏开发中推荐用 uint32 明确匹配 C# 的 uint
} }

View File

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

View File

@@ -34,7 +34,7 @@ func (s *ItemService) GetItemCount(id uint32) data.ItemInfo {
} }
return res return res
} }
func (s *ItemService) GetEgg(count int32) []data.ItemInfo { func (s *ItemService) GetEgg(count uint32) []data.ItemInfo {
var item []model.ItemGift var item []model.ItemGift
cool.DBM(s.Model).Where("is_egg", 1).Where("is_enabled", 1).Cache(gdb.CacheOption{ cool.DBM(s.Model).Where("is_egg", 1).Where("is_enabled", 1).Cache(gdb.CacheOption{
// Duration: time.Hour, // Duration: time.Hour,