From 32d60e8d91293c5c20999918ad7646cea303a3c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=94=E5=BF=B5?= <1@72wo.cn> Date: Tue, 28 Oct 2025 22:08:27 +0800 Subject: [PATCH] =?UTF-8?q?fix(socket):=20=E7=A7=BB=E9=99=A4=E6=9C=AA?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=9A=84=E5=8C=85=E5=AF=BC=E5=85=A5=E5=92=8C?= =?UTF-8?q?=E8=B0=83=E8=AF=95=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除了 `blazing/cool` 和 `context` 包的导入,以及不再需要的调试日志输出。 feat(fight): 增强玩家初始化检查并返回结果 修改 `initplayer` 方法以在没有宠物时返回 false,并在 `NewFight` 中增加对初始化结果的检查,若失败则返回 nil。 --- common/socket/codec/SocketCodec_Tomee.go | 4 +--- logic/service/fight/fightc.go | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/common/socket/codec/SocketCodec_Tomee.go b/common/socket/codec/SocketCodec_Tomee.go index bd138e21..716690a3 100644 --- a/common/socket/codec/SocketCodec_Tomee.go +++ b/common/socket/codec/SocketCodec_Tomee.go @@ -1,8 +1,6 @@ package codec import ( - "blazing/cool" - "context" "encoding/binary" "errors" "io" @@ -60,7 +58,7 @@ func (codec TomeeSocketCodec) Decode(c gnet.Conn) ([]byte, error) { } bodyLen := binary.BigEndian.Uint32(lenBuf) - cool.Loger.Print(context.TODO(), "lenBuf", bodyLen) + if bodyLen > maxBodyLen { return nil, errors.New("packet body exceeds max length") } diff --git a/logic/service/fight/fightc.go b/logic/service/fight/fightc.go index 0d9353a7..d0604224 100644 --- a/logic/service/fight/fightc.go +++ b/logic/service/fight/fightc.go @@ -94,8 +94,11 @@ func (f *FightC) LoadPercent(c common.PlayerI, percent int32) { }) } -func (f *FightC) initplayer(c common.PlayerI, opp bool) { +func (f *FightC) initplayer(c common.PlayerI, opp bool) bool { + if len(c.GetInfo().PetList) == 0 { + return false + } temp := input.NewInput(f, c) temp.AllPet = make([]*info.BattlePetEntity, 0) @@ -153,7 +156,7 @@ func (f *FightC) initplayer(c common.PlayerI, opp bool) { } temp.CurrentPet = temp.AllPet[0] - + return true } // 创建新战斗,邀请方和被邀请方,或者玩家和野怪方 @@ -174,9 +177,15 @@ func NewFight(mode, status info.EnumBattleMode, p1 common.PlayerI, p2 common.Pla Status: status, } - f.initplayer(p1, false) + ok := f.initplayer(p1, false) + if !ok { + return nil + } - f.initplayer(p2, true) + ok = f.initplayer(p2, true) + if !ok { + return nil + } defer func() { rr := Fightpool.Submit(f.battleLoop)