From 603c33c832b2d535994cfb6e346a5b301a01504b Mon Sep 17 00:00:00 2001 From: 1 <1@72wo.cn> Date: Tue, 4 Nov 2025 14:01:17 +0000 Subject: [PATCH 01/11] =?UTF-8?q?refactor(logic):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=88=98=E6=96=97=E7=8A=B6=E6=80=81=E6=95=88=E6=9E=9C=E6=8C=81?= =?UTF-8?q?=E7=BB=AD=E6=97=B6=E9=97=B4=E8=AE=A1=E7=AE=97=E5=8F=8A=E6=B8=85?= =?UTF-8?q?=E7=90=86=E5=86=97=E4=BD=99=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logic/controller/task.go | 4 ++-- logic/service/fight/fightc.go | 4 ++-- logic/service/fight/input/fight.go | 2 +- logic/service/fight/input/input.go | 1 + login/main.go | 28 +--------------------------- 5 files changed, 7 insertions(+), 32 deletions(-) diff --git a/logic/controller/task.go b/logic/controller/task.go index 97482e8ee..3d40f83f6 100644 --- a/logic/controller/task.go +++ b/logic/controller/task.go @@ -39,14 +39,14 @@ func (h Controller) AddTaskBuf(data *task.AddTaskBufInboundInfo, c *player.Playe // if data.Head.CMD != 2204 { //判断是每日任务 // isdaliy = true // } - result = &task.AddTaskBufOutboundInfo{} + c.Service.Task(data.TaskId, func(te *model.TaskEX) bool { te.Data = data.TaskList return true }) - return &task.AddTaskBufOutboundInfo{}, 0 + return result, 0 } /** diff --git a/logic/service/fight/fightc.go b/logic/service/fight/fightc.go index aaeb23992..f5748090e 100644 --- a/logic/service/fight/fightc.go +++ b/logic/service/fight/fightc.go @@ -565,11 +565,11 @@ func (f *FightC) enterturn(fattack, sattack *action.SelectSkillAction) { t := f.First.GetEffect(input.EffectType.Status, i) if t != nil { //状态都是叠层类的 - ret.FAttack.Status[i] = int8(t.Duration()) + ret.FAttack.Status[i] = int8(t.Duration()) + 1 } t = f.Second.GetEffect(input.EffectType.Status, i) if t != nil { - ret.SAttack.Status[i] = int8(t.Duration()) + ret.SAttack.Status[i] = int8(t.Duration()) + 1 } } diff --git a/logic/service/fight/input/fight.go b/logic/service/fight/input/fight.go index f8638e972..d70806773 100644 --- a/logic/service/fight/input/fight.go +++ b/logic/service/fight/input/fight.go @@ -311,7 +311,7 @@ func (i *Input) CalculatePower(deftype *Input, skill *info.SkillEntity) decimal. Add(decimal.NewFromInt(2)) var typeRate decimal.Decimal - fmt.Println(skill.Type().ID, deftype.CurrentPet.Type().ID) + //fmt.Println(skill.Type().ID, deftype.CurrentPet.Type().ID) t, _ := element.NewElementCalculator().GetOffensiveMultiplier(skill.Type().ID, deftype.CurrentPet.Type().ID) typeRate = decimal.NewFromFloat(t) diff --git a/logic/service/fight/input/input.go b/logic/service/fight/input/input.go index 6de2d6e0c..decd678c9 100644 --- a/logic/service/fight/input/input.go +++ b/logic/service/fight/input/input.go @@ -56,6 +56,7 @@ func (i *Input) GetPetInfo() *info.BattlePetEntity { } func (i *Input) ResetAttackValue() { i.AttackValue.SkillID = 0 + i.AttackValue.IsCritical = 0 } diff --git a/login/main.go b/login/main.go index 4d1628395..326b4a4ba 100644 --- a/login/main.go +++ b/login/main.go @@ -1,14 +1,9 @@ package main import ( - "fmt" - "reflect" - "strings" - _ "github.com/gogf/gf/contrib/nosql/redis/v2" _ "blazing/contrib/drivers/pgsql" - "blazing/modules/base/service" _ "blazing/contrib/files/local" @@ -27,11 +22,10 @@ import ( "blazing/login/internal/cmd" "github.com/gogf/gf/v2/os/gctx" - "github.com/gogf/gf/v2/util/gconv" ) func main() { - service.TestSendVerificationCode() + //service.TestSendVerificationCode() cmd.Main.Run(gctx.New()) } @@ -47,23 +41,3 @@ func kick(id int) { // fmt.Println(err) // }() } - -type ssss struct { - ttt int `cmd:"111|222"` -} - -func Test_kick() { - value := reflect.ValueOf(ssss{}) - - // 获取类型 - typ := value.Type() - // 遍历结构体字段 - // fmt.Printf("结构体 %s 的字段信息:\n", t.Name()) - for i := 0; i < typ.NumField(); i++ { - field := typ.Field(i) - t := field.Tag.Get("cmd") - //t1 := strings.Split(t, "|") - t2 := gconv.SliceUint32(strings.Split(t, "|")) - fmt.Println(t2) - } -} From f7b1e6ce081c632d13228260f8cbe4fdcd70783d Mon Sep 17 00:00:00 2001 From: 1 <1@72wo.cn> Date: Tue, 4 Nov 2025 14:16:52 +0000 Subject: [PATCH 02/11] =?UTF-8?q?refactor(fight):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E6=95=88=E6=9E=9C=E8=8E=B7=E5=8F=96=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E5=A2=9E=E5=8A=A0=E5=AD=98=E6=B4=BB=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logic/service/fight/fightc.go | 2 ++ logic/service/fight/input/node.go | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/logic/service/fight/fightc.go b/logic/service/fight/fightc.go index f5748090e..15cbbedbe 100644 --- a/logic/service/fight/fightc.go +++ b/logic/service/fight/fightc.go @@ -565,7 +565,9 @@ func (f *FightC) enterturn(fattack, sattack *action.SelectSkillAction) { t := f.First.GetEffect(input.EffectType.Status, i) if t != nil { //状态都是叠层类的 + ret.FAttack.Status[i] = int8(t.Duration()) + 1 + } t = f.Second.GetEffect(input.EffectType.Status, i) if t != nil { diff --git a/logic/service/fight/input/node.go b/logic/service/fight/input/node.go index f76f3d9c4..9b0089ef5 100644 --- a/logic/service/fight/input/node.go +++ b/logic/service/fight/input/node.go @@ -70,7 +70,7 @@ func (c *Input) GetProp(id int, istue bool) int { func (c *Input) GetEffect(etype EnumEffectType, id int) Effect { var ret []Effect for _, v := range c.Effects { - if v.ID() == id { + if v.ID() == id &&v.Alive(){ ret = append(ret, v) } From e398c31834a0a4ed7679bd0aef6a14b239802e07 Mon Sep 17 00:00:00 2001 From: 1 <1@72wo.cn> Date: Tue, 4 Nov 2025 16:55:14 +0000 Subject: [PATCH 03/11] =?UTF-8?q?refactor(fight):=20=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=E6=8A=80=E8=83=BD=E6=94=BB=E5=87=BB=E5=A4=84=E7=90=86=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E4=BC=98=E5=8C=96=E6=9A=B4=E5=87=BB=E7=A0=B4?= =?UTF-8?q?=E9=98=B2=E6=9D=A1=E4=BB=B6=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logic/service/fight/fightc.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/logic/service/fight/fightc.go b/logic/service/fight/fightc.go index 15cbbedbe..378bf8c06 100644 --- a/logic/service/fight/fightc.go +++ b/logic/service/fight/fightc.go @@ -260,7 +260,7 @@ func (f *FightC) processSkillAttack(attacker, defender *input.Input, a *action.S attacker.Exec(func(t input.Effect) bool { //计算命中 miss改命中 t.Skill_Hit(input.Ctx{ //计算变威力 - Input: attacker, + Input: defender, SelectSkillAction: a, }) //相当于先调整基础命中,不光调整命中,这里还能调整技能属性,暴击率 @@ -295,9 +295,10 @@ func (f *FightC) processSkillAttack(attacker, defender *input.Input, a *action.S if attacker.AttackValue.IsCritical == 1 { //暴击破防 - if a.SkillEntity.Category() == info.Category.PHYSICAL { + if a.SkillEntity.Category() == info.Category.PHYSICAL && defender.Prop[1] > 0 { + defender.Prop[1] = 0 - } else if a.SkillEntity.Category() == info.Category.SPECIAL { + } else if a.SkillEntity.Category() == info.Category.SPECIAL && defender.Prop[3] > 0 { defender.Prop[3] = 0 } From ed08006786fa59af38e6cede1474f9498284af3a Mon Sep 17 00:00:00 2001 From: 1 <1@72wo.cn> Date: Wed, 5 Nov 2025 13:37:01 +0000 Subject: [PATCH 04/11] =?UTF-8?q?refactor(fight):=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=88=98=E6=96=97=E6=8E=A7=E5=88=B6=E5=99=A8=E7=A9=BA=E6=8C=87?= =?UTF-8?q?=E9=92=88=E6=A3=80=E6=9F=A5=EF=BC=8C=E4=BC=98=E5=8C=96=E9=80=83?= =?UTF-8?q?=E8=B7=91=E5=92=8C=E5=88=87=E6=8D=A2=E7=B2=BE=E7=81=B5=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logic/controller/fight.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/logic/controller/fight.go b/logic/controller/fight.go index 06b2cb9c1..d70efe0a9 100644 --- a/logic/controller/fight.go +++ b/logic/controller/fight.go @@ -164,15 +164,17 @@ func (h Controller) UseSkill(data *fight.UseSkillInInfo, c *player.Player) (resu // 战斗逃跑 func (h Controller) Escape(data *fight.EscapeFightInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { - - c.FightC.Over(c, info.BattleOverReason.PlayerEscape) + if c.FightC != nil { + c.FightC.Over(c, info.BattleOverReason.PlayerEscape) + } return nil, 0 } // 切换精灵 func (h Controller) ChangePet(data *fight.ChangePetInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { - - c.FightC.ChangePet(c, data.CatchTime) + if c.FightC != nil { + c.FightC.ChangePet(c, data.CatchTime) + } return nil, -1 } From 4d7064e59fb3d0dcda7457bf25b3b1fdc39ac863 Mon Sep 17 00:00:00 2001 From: 1 <1@72wo.cn> Date: Wed, 5 Nov 2025 17:06:08 +0000 Subject: [PATCH 05/11] =?UTF-8?q?refactor(fight):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=88=98=E6=96=97=E9=80=BB=E8=BE=91=E4=BB=A3=E7=A0=81=E7=BB=93?= =?UTF-8?q?=E6=9E=84=EF=BC=8C=E6=B8=85=E7=90=86=E5=86=97=E4=BD=99=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logic/controller/fight.go | 4 +--- logic/controller/pet.go | 20 +++++++++----------- logic/service/player/fight.go | 2 +- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/logic/controller/fight.go b/logic/controller/fight.go index d70efe0a9..0df5b7e51 100644 --- a/logic/controller/fight.go +++ b/logic/controller/fight.go @@ -126,9 +126,7 @@ func (h Controller) OnReadyToFight(data *fight.ReadyToFightInboundInfo, c *playe // 接收战斗或者取消战斗的包 func (h Controller) OnPlayerHandleFightInvite(data *fight.HandleFightInviteInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { - if !c.CanFight() { - return nil, errorcode.ErrorCodes.ErrPokemonNotEligible - } + if ok, p1 := c.AgreeBattle(data.UserID, data.Flag, data.Mode); ok { fight.NewFight(data.Mode, info.BattleStatus.FIGHT_WITH_PLAYER, c, p1) ///开始对战,房主方以及被邀请方 } diff --git a/logic/controller/pet.go b/logic/controller/pet.go index f04cac3d4..7b310c0e5 100644 --- a/logic/controller/pet.go +++ b/logic/controller/pet.go @@ -70,23 +70,21 @@ func (h *Controller) PetRelease( switch data.Flag { case 0: - removeIndex := -1 - for i, v := range c.Info.PetList { - if v.CatchTime == uint32(data.CatchTime) { - removeIndex = i - break // 只移除第一个匹配值,若需移除所有,可省略 break 继续循环 - } - - } - if removeIndex != -1 { + n, v, ok := utils.FindWithIndex(c.Info.PetList, func(item model.PetInfo) bool { + return item.CatchTime == data.CatchTime + }) + if ok { c.Service.PetInfo_One_exec(data.CatchTime, func(t *model.PetEX) { - t.Data = c.Info.PetList[removeIndex] + t.Data = *v t.InBag = 0 }) - c.Info.PetList = append(c.Info.PetList[:removeIndex], c.Info.PetList[removeIndex+1:]...) + + c.Info.PetList = append(c.Info.PetList[:n], c.Info.PetList[n+1:]...) + } + // break // 只移除第一个匹配值,若需移除所有,可省略 break 继续循环 case 1: //todo 背包 c.Service.PetInfo_One_exec(data.CatchTime, func(t *model.PetEX) { diff --git a/logic/service/player/fight.go b/logic/service/player/fight.go index 0470caa6a..fd44749a5 100644 --- a/logic/service/player/fight.go +++ b/logic/service/player/fight.go @@ -88,7 +88,7 @@ func (lw *Player) AgreeBattle(userid, flag uint32, mode info.EnumBattleMode) (bo return false, nil } if v.Info.UserID == userid && v.PVPinfo.Mode == mode { //成功找到,同意对战 - if lw.CanFight() { + if lw.CanFight() &&v.CanFight(){ ret.Result = 1 v.SendPack(t1.Pack(ret)) From 3aff7f7ad63a1dfe6a1247f056f293d0d934dfb3 Mon Sep 17 00:00:00 2001 From: 1 <1@72wo.cn> Date: Wed, 5 Nov 2025 17:19:09 +0000 Subject: [PATCH 06/11] =?UTF-8?q?refactor(fight):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=88=98=E6=96=97=E9=80=BB=E8=BE=91=E4=BB=A3=E7=A0=81=E7=BB=93?= =?UTF-8?q?=E6=9E=84=EF=BC=8C=E6=B8=85=E7=90=86=E5=86=97=E4=BD=99=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logic/controller/fight.go | 10 ++++++++-- logic/controller/pet.go | 21 +++++++++++---------- logic/service/common/fight.go | 2 +- logic/service/fight/fightc.go | 4 ++++ 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/logic/controller/fight.go b/logic/controller/fight.go index 0df5b7e51..e718c33d2 100644 --- a/logic/controller/fight.go +++ b/logic/controller/fight.go @@ -162,9 +162,15 @@ func (h Controller) UseSkill(data *fight.UseSkillInInfo, c *player.Player) (resu // 战斗逃跑 func (h Controller) Escape(data *fight.EscapeFightInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) { - if c.FightC != nil { - c.FightC.Over(c, info.BattleOverReason.PlayerEscape) + if c.FightC == nil { + + return nil, 0 } + if !c.FightC.CanEscape() { + + return nil, 0 + } + c.FightC.Over(c, info.BattleOverReason.PlayerEscape) return nil, 0 } diff --git a/logic/controller/pet.go b/logic/controller/pet.go index 7b310c0e5..b41b05963 100644 --- a/logic/controller/pet.go +++ b/logic/controller/pet.go @@ -69,21 +69,22 @@ func (h *Controller) PetRelease( switch data.Flag { case 0: + var temp []model.PetInfo - n, v, ok := utils.FindWithIndex(c.Info.PetList, func(item model.PetInfo) bool { - return item.CatchTime == data.CatchTime - }) - if ok { - c.Service.PetInfo_One_exec(data.CatchTime, func(t *model.PetEX) { - t.Data = *v - t.InBag = 0 + for _, v := range c.Info.PetList { + if v.CatchTime == uint32(data.CatchTime) { + c.Service.PetInfo_One_exec(data.CatchTime, func(t *model.PetEX) { + t.Data = v + t.InBag = 0 - }) + }) - c.Info.PetList = append(c.Info.PetList[:n], c.Info.PetList[n+1:]...) + } else { + temp = append(temp, v) + } } - + c.Info.PetList = temp // break // 只移除第一个匹配值,若需移除所有,可省略 break 继续循环 case 1: //todo 背包 diff --git a/logic/service/common/fight.go b/logic/service/common/fight.go index cfdbd8bd1..8f3e4f82f 100644 --- a/logic/service/common/fight.go +++ b/logic/service/common/fight.go @@ -15,6 +15,6 @@ type FightI interface { Capture(c PlayerI, id uint32) GetRand() *rand.Rand LoadPercent(c PlayerI, percent int32) - + CanEscape() bool IsFirst(c PlayerI) bool } diff --git a/logic/service/fight/fightc.go b/logic/service/fight/fightc.go index 378bf8c06..e7a5ec573 100644 --- a/logic/service/fight/fightc.go +++ b/logic/service/fight/fightc.go @@ -36,6 +36,10 @@ type FightC struct { closefight bool } +func (f *FightC) CanEscape() bool { + + return f.Info.Status != info.BattleStatus.FIGHT_WITH_PLAYER +} func (f *FightC) Ownerid() uint32 { return f.ownerID From cfde50db42e1df31da9adca8cc851f931e402a80 Mon Sep 17 00:00:00 2001 From: 1 <1@72wo.cn> Date: Wed, 5 Nov 2025 17:37:32 +0000 Subject: [PATCH 07/11] =?UTF-8?q?refactor(fight):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=88=98=E6=96=97=E9=80=BB=E8=BE=91=E4=BB=A3=E7=A0=81=E7=BB=93?= =?UTF-8?q?=E6=9E=84=EF=BC=8C=E6=B8=85=E7=90=86=E5=86=97=E4=BD=99=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logic/service/fight/playeraction.go | 1 - 1 file changed, 1 deletion(-) diff --git a/logic/service/fight/playeraction.go b/logic/service/fight/playeraction.go index 9c2f60d8d..974fce65d 100644 --- a/logic/service/fight/playeraction.go +++ b/logic/service/fight/playeraction.go @@ -92,7 +92,6 @@ func (f *FightC) UseSkill(c common.PlayerI, id int32) { ret := &action.SelectSkillAction{ BaseAction: action.NewBaseAction(c.GetInfo().UserID), } - //ret.PetInfo = f.GetInputByPlayer(c, false).CurrentPet for _, v := range f.GetInputByPlayer(c, false).CurrentPet.Skills { From 5092186b4edc932d0fa93ea862b8a4274e530062 Mon Sep 17 00:00:00 2001 From: 1 <1@72wo.cn> Date: Wed, 5 Nov 2025 22:07:46 +0000 Subject: [PATCH 08/11] =?UTF-8?q?refactor(fight):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=88=98=E6=96=97=E9=80=BB=E8=BE=91=E4=BB=A3=E7=A0=81=E7=BB=93?= =?UTF-8?q?=E6=9E=84=EF=BC=8C=E6=B8=85=E7=90=86=E5=86=97=E4=BD=99=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logic/go.mod | 1 + logic/go.sum | 2 ++ logic/service/player/SocketHandler_Tomee.go | 10 +++++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/logic/go.mod b/logic/go.mod index 77e3c6c74..67cafc6cb 100644 --- a/logic/go.mod +++ b/logic/go.mod @@ -22,6 +22,7 @@ require ( github.com/BurntSushi/toml v1.4.0 // indirect github.com/antlabs/stl v0.0.2 // indirect github.com/bits-and-blooms/bitset v1.5.0 // indirect + github.com/bruceshao/lockfree v1.1.2 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/clbanning/mxj/v2 v2.7.0 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect diff --git a/logic/go.sum b/logic/go.sum index 9269a0094..8a9d7583e 100644 --- a/logic/go.sum +++ b/logic/go.sum @@ -8,6 +8,8 @@ github.com/barkimedes/go-deepcopy v0.0.0-20220514131651-17c30cfc62df h1:GSoSVRLo github.com/barkimedes/go-deepcopy v0.0.0-20220514131651-17c30cfc62df/go.mod h1:hiVxq5OP2bUGBRNS3Z/bt/reCLFNbdcST6gISi1fiOM= github.com/bits-and-blooms/bitset v1.5.0 h1:NpE8frKRLGHIcEzkR+gZhiioW1+WbYV6fKwD6ZIpQT8= github.com/bits-and-blooms/bitset v1.5.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA= +github.com/bruceshao/lockfree v1.1.2 h1:V3j7bZWS+yDjazffbobpR+ZCVq98DNJcZMvO8vWFLmc= +github.com/bruceshao/lockfree v1.1.2/go.mod h1:zkhImea4VTfzWvFF1Lleo1esCZeJLGgrYN+mUuqNrMA= github.com/brunoga/deep v1.2.5 h1:bigq4eooqbeJXfvTfZBn3AH3B1iW+rtetxVeh0GiLrg= github.com/brunoga/deep v1.2.5/go.mod h1:GDV6dnXqn80ezsLSZ5Wlv1PdKAWAO4L5PnKYtv2dgaI= github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs= diff --git a/logic/service/player/SocketHandler_Tomee.go b/logic/service/player/SocketHandler_Tomee.go index 0fa9fa864..346ce717b 100644 --- a/logic/service/player/SocketHandler_Tomee.go +++ b/logic/service/player/SocketHandler_Tomee.go @@ -12,6 +12,7 @@ import ( "fmt" "reflect" + "github.com/bruceshao/lockfree" "github.com/gobwas/ws" "github.com/gobwas/ws/wsutil" "github.com/gogf/gf/v2/os/glog" @@ -205,11 +206,13 @@ type ClientData struct { Wsmsg *WsCodec Conn gnet.Conn SaveL sync.Once //保存锁 - SaveDone chan struct{} + LF *lockfree.Lockfree[[]byte] + //SaveDone chan struct{} } func NewClientData(c gnet.Conn) *ClientData { // 创建事件处理器 + // 创建消费端串行处理的Lockfree cd := ClientData{ @@ -217,6 +220,11 @@ func NewClientData(c gnet.Conn) *ClientData { Conn: c, Wsmsg: &WsCodec{}, } + // cd.LF = lockfree.NewLockfree[[]byte]( + // 1024*1024, + // cd, + // lockfree.NewSleepBlockStrategy(time.Millisecond), + // ) return &cd } From bd43c75dce36729d0c3cbbc4f6eddb32470c2003 Mon Sep 17 00:00:00 2001 From: 1 <1@72wo.cn> Date: Wed, 5 Nov 2025 22:17:03 +0000 Subject: [PATCH 09/11] =?UTF-8?q?refactor(fight):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=88=98=E6=96=97=E9=80=BB=E8=BE=91=E4=BB=A3=E7=A0=81=E7=BB=93?= =?UTF-8?q?=E6=9E=84=EF=BC=8C=E6=B8=85=E7=90=86=E5=86=97=E4=BD=99=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/socket/ServerEvent.go | 9 +++++--- logic/service/player/SocketHandler_Tomee.go | 23 ++++++++++++--------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/common/socket/ServerEvent.go b/common/socket/ServerEvent.go index 04847a09a..85326db6a 100644 --- a/common/socket/ServerEvent.go +++ b/common/socket/ServerEvent.go @@ -48,8 +48,10 @@ func (s *Server) OnClose(c gnet.Conn, _ error) (action gnet.Action) { }() atomic.AddInt64(&s.connected, -1) + //logging.Infof("conn[%v] disconnected", c.RemoteAddr().String()) v, _ := c.Context().(*player.ClientData) + v.LF.Close() if v.Player != nil { v.SaveL.Do(func() { //使用保存锁,确保在踢人和掉线的时候只保存一次 //cool.Loger.Info(context.TODO(), "准备保存", v.Player.Info.UserID) @@ -140,7 +142,8 @@ func (s *Server) OnTraffic(c gnet.Conn) (action gnet.Action) { //client := conn.RemoteAddr().String() s.workerPool.Submit(func() { //TODO 这里可能存在顺序执行问题,待修复 for _, msg := range messages { - t.OnEvent(msg.Payload) + t.LF.Producer().Write(msg.Payload) + //t.OnEvent(msg.Payload) } }) @@ -164,8 +167,8 @@ func (s *Server) handleTcp(conn gnet.Conn) (action gnet.Action) { } s.workerPool.Submit(func() { //TODO 这里可能存在顺序执行问题,待修复 - conn.Context().(*player.ClientData).OnEvent(data) - + //conn.Context().(*player.ClientData).OnEvent(data) + conn.Context().(*player.ClientData).LF.Producer().Write(data) }) if conn.InboundBuffered() > 0 { diff --git a/logic/service/player/SocketHandler_Tomee.go b/logic/service/player/SocketHandler_Tomee.go index 346ce717b..d4acc7081 100644 --- a/logic/service/player/SocketHandler_Tomee.go +++ b/logic/service/player/SocketHandler_Tomee.go @@ -5,6 +5,7 @@ import ( "blazing/common/utils/bytearray" "blazing/cool" "sync" + "time" "context" @@ -214,18 +215,20 @@ func NewClientData(c gnet.Conn) *ClientData { // 创建事件处理器 // 创建消费端串行处理的Lockfree - cd := ClientData{ + cd := &ClientData{ - Player: nil, - Conn: c, - Wsmsg: &WsCodec{}, + Conn: c, } - // cd.LF = lockfree.NewLockfree[[]byte]( - // 1024*1024, - // cd, - // lockfree.NewSleepBlockStrategy(time.Millisecond), - // ) - return &cd + cd.LF = lockfree.NewLockfree[[]byte]( + 1024*1024, + cd, + lockfree.NewSleepBlockStrategy(time.Millisecond), + ) + // 启动Lockfree + if err := cd.LF.Start(); err != nil { + panic(err) + } + return cd } From 4263e4050ce087f845e173bbdab4d71711d3a55c Mon Sep 17 00:00:00 2001 From: 1 <1@72wo.cn> Date: Wed, 5 Nov 2025 22:18:29 +0000 Subject: [PATCH 10/11] =?UTF-8?q?refactor(fight):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=88=98=E6=96=97=E9=80=BB=E8=BE=91=E4=BB=A3=E7=A0=81=E7=BB=93?= =?UTF-8?q?=E6=9E=84=EF=BC=8C=E6=B8=85=E7=90=86=E5=86=97=E4=BD=99=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logic/service/player/SocketHandler_Tomee.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/logic/service/player/SocketHandler_Tomee.go b/logic/service/player/SocketHandler_Tomee.go index d4acc7081..d6e8af626 100644 --- a/logic/service/player/SocketHandler_Tomee.go +++ b/logic/service/player/SocketHandler_Tomee.go @@ -255,7 +255,14 @@ 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. 打印错误信息 + cool.Loger.Error(context.TODO(), "panic 错误:", err) + + } + }() header := TomeeHeader{} tempdata := bytearray.CreateByteArray(v) From f687599d1a8c56a3e11ee8c68059ea836cfc9bea Mon Sep 17 00:00:00 2001 From: 1 <1@72wo.cn> Date: Wed, 5 Nov 2025 22:34:03 +0000 Subject: [PATCH 11/11] =?UTF-8?q?refactor(fight):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=88=98=E6=96=97=E9=80=BB=E8=BE=91=E4=BB=A3=E7=A0=81=E7=BB=93?= =?UTF-8?q?=E6=9E=84=EF=BC=8C=E6=B8=85=E7=90=86=E5=86=97=E4=BD=99=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logic/service/player/SocketHandler_Tomee.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/logic/service/player/SocketHandler_Tomee.go b/logic/service/player/SocketHandler_Tomee.go index d6e8af626..7247c4263 100644 --- a/logic/service/player/SocketHandler_Tomee.go +++ b/logic/service/player/SocketHandler_Tomee.go @@ -217,7 +217,8 @@ func NewClientData(c gnet.Conn) *ClientData { cd := &ClientData{ - Conn: c, + Conn: c, + Wsmsg: &WsCodec{}, } cd.LF = lockfree.NewLockfree[[]byte]( 1024*1024,