refactor(socket): 移除未使用的网络相关导入和注释掉的 RST 攻击检测逻辑

移除了 `ServerEvent.go` 中未使用的 `net` 和 `strings` 包导入。同时,
将原有的 RST 攻击检测及防护逻辑代码注释掉,便于后续重新设计或彻底删除。

fix(logic): 调整 fight pool 初始化与释放策略

将 `fight/action.go` 中的 `Fightpool` 类型从 `*ants.MultiPool`
改为 `*ants.Pool`,并调整其初始化方式为 `NewPool(-1)` 以适应动态扩容。
此外,在 `main.go` 中将 `ReleaseTimeout` 参数由 100 调整为 0,
确保立即清理超时任务。

feat(fight): 优化战斗输入状态重置逻辑

在 `fight/action.go` 的 `ReadyFight` 方法中提前设置
`GetInputByPlayer(c, false).Finished = true`,避免重复赋值。
同时更新了状态睡眠效果的处理流程,并简化了输入模块的状态缓存机制,
移除了冗余的 `Initeffectcache` 函数调用及相关逻辑。

perf(fight): 动态计算玩家动作等待时间

在 `loop.go` 的 `collectPlayerActions` 方法中,
将固定超时时间替换为基于 `waittime` 的动态等待时间计算公式,
提高响应灵活性。同时修复通道关闭判断条件以增强稳定性。

refactor(fight): 更新技能效果解析和状态持续逻辑

修改 `input.go` 中 `GenSataus` 方法以正确初始化状态数组;
在 `Turn.go` 中重构 `Turn_End` 方法内的执行逻辑,
确保仅在我方后手时增加回合数,提升战斗流程准确性。

chore(service): 删除废弃文件 SocketHandler_Tomee.go

完全移除已弃用的 `SocketHandler_Tomee.go` 文件及其全部内容,
减少项目冗余代码。
```
This commit is contained in:
2025-11-13 05:05:05 +08:00
parent f281b949ba
commit 6e01848b04
8 changed files with 34 additions and 77 deletions

View File

@@ -3,9 +3,7 @@ package socket
import ( import (
"context" "context"
"log" "log"
"net"
"os" "os"
"strings"
"sync/atomic" "sync/atomic"
"time" "time"
@@ -49,14 +47,14 @@ func (s *Server) OnClose(c gnet.Conn, err error) (action gnet.Action) {
} }
}() }()
// 识别 RST 导致的连接中断(错误信息含 "connection reset" // 识别 RST 导致的连接中断(错误信息含 "connection reset"
if err != nil && (strings.Contains(err.Error(), "connection reset") || strings.Contains(err.Error(), "reset by peer")) { // if err != nil && (strings.Contains(err.Error(), "connection reset") || strings.Contains(err.Error(), "reset by peer")) {
remoteIP := c.RemoteAddr().(*net.TCPAddr).IP.String() // remoteIP := c.RemoteAddr().(*net.TCPAddr).IP.String()
log.Printf("RST 攻击检测: 来源 %s, 累计攻击次数 %d", remoteIP) // log.Printf("RST 攻击检测: 来源 %s, 累计攻击次数 %d", remoteIP)
// 防护逻辑:临时封禁异常 IP可扩展为 IP 黑名单) // // 防护逻辑:临时封禁异常 IP可扩展为 IP 黑名单)
// go s.tempBlockIP(remoteIP, 5*time.Minute) // // go s.tempBlockIP(remoteIP, 5*time.Minute)
} // }
//fmt.Println(err, c.RemoteAddr().String(), "断开连接") //fmt.Println(err, c.RemoteAddr().String(), "断开连接")
atomic.AddInt64(&s.connected, -1) atomic.AddInt64(&s.connected, -1)

View File

@@ -33,7 +33,7 @@ func PprofWeb() {
} }
} }
func signalHandlerForMain(sig os.Signal) { func signalHandlerForMain(sig os.Signal) {
fight.Fightpool.ReleaseTimeout(100) fight.Fightpool.ReleaseTimeout(0)
player.Mainplayer.Range(func(key uint32, value *player.Player) bool { player.Mainplayer.Range(func(key uint32, value *player.Player) bool {
value.Save() value.Save()

View File

@@ -146,13 +146,13 @@ func (f *FightC) ReadyFight(c common.PlayerI) {
rett.Info2.UserID = f.Info.OpponentInfo.UserID rett.Info2.UserID = f.Info.OpponentInfo.UserID
rrsult := func() { //传回函数 rrsult := func() { //传回函数
i := Fightpool.Free() // i := Fightpool.Free()
if i <= 0 { // if i <= 0 {
Fightpool.Tune(Fightpool.Cap() + 1) // Fightpool.Tune(Fightpool.Cap() + 1)
cool.Loger.Error(context.Background(), "Fightpool is full") // cool.Loger.Error(context.Background(), "Fightpool is full")
} // }
rr := Fightpool.Submit(f.battleLoop) rr := Fightpool.Submit(f.battleLoop)
if rr != nil { if rr != nil {
panic(rr) panic(rr)
@@ -164,11 +164,10 @@ func (f *FightC) ReadyFight(c common.PlayerI) {
//然后开始战斗循环 //然后开始战斗循环
} }
f.GetInputByPlayer(c, false).Finished = true
switch f.Info.Status { switch f.Info.Status {
case info.BattleStatus.FIGHT_WITH_PLAYER: //pvp case info.BattleStatus.FIGHT_WITH_PLAYER: //pvp
f.GetInputByPlayer(c, false).Finished = true
if f.GetInputByPlayer(c, true).Finished { if f.GetInputByPlayer(c, true).Finished {
rrsult() rrsult()
} }
@@ -187,9 +186,9 @@ func (f *FightC) ReadyFight(c common.PlayerI) {
} }
} }
var Fightpool *ants.MultiPool var Fightpool *ants.Pool
func init() { func init() {
Fightpool, _ = ants.NewMultiPool(10, 100, ants.LeastTasks) Fightpool, _ = ants.NewPool(-1)
//defer p.Release() //defer p.Release()
} }

View File

@@ -63,11 +63,8 @@ func (e *StatusSleep) Skill_Use_ex() bool {
if e.Ctx().SkillEntity == nil { if e.Ctx().SkillEntity == nil {
return true return true
} }
if e.Ctx().SkillEntity.Category() != info.Category.STATUS { if e.Ctx().Category() != info.Category.STATUS {
t := e.Input.GetEffect(input.EffectType.Status, int(info.PetStatus.Sleep)) e.Alive(false)
if t != nil {
t.Alive(false)
}
} }
return true return true
} }

View File

@@ -65,7 +65,7 @@ func (our *Input) SetOPP(t *Input) {
} }
func (our *Input) GenSataus() { func (our *Input) GenSataus() {
our.Status = [20]int8{}
for i := 0; i < 20; i++ { //堆叠状态剩余回合 for i := 0; i < 20; i++ { //堆叠状态剩余回合
t := our.GetEffect(EffectType.Status, i) t := our.GetEffect(EffectType.Status, i)
@@ -143,26 +143,11 @@ func (our *Input) GetStatusBonus() float64 {
return maxBonus return maxBonus
} }
func (our *Input) Initeffectcache() {
for _, v := range our.Effects {
if v.Alive() { //说明存活效果而且是延续类效果,将之添加到初始化列表中
//这里添加的效果是已经生效的效果对effect的复制,相当于技能施的效果的前置比如改命中的效果等
our.EffectCache = append(our.EffectCache, v)
}
}
}
// 解析并 施加effect // 解析并 施加effect
func (our *Input) Parseskill(defender *Input, skill *action.SelectSkillAction) { func (our *Input) Parseskill(defender *Input, skill *action.SelectSkillAction) {
our.EffectCache = make([]Effect, 0) //先把上一回合数据清空,但是应该把本身延续类效果集成过来 our.EffectCache = make([]Effect, 0) //先把上一回合数据清空,但是应该把本身延续类效果集成过来
our.Effect_Lost = make([]Effect, 0) our.Effect_Lost = make([]Effect, 0)
our.Initeffectcache() //这里说明是延续的效果,每次复制出来一个新的就好了 // our.Initeffectcache() //这里说明是延续的效果,每次复制出来一个新的就好了
//i.NewEffects = make([]Effect, 0) //这里说明是新增的效果 //i.NewEffects = make([]Effect, 0) //这里说明是新增的效果
temparg := skill.SideEffectArgS temparg := skill.SideEffectArgS

View File

@@ -52,16 +52,19 @@ func (f *FightC) battleLoop() {
// 收集玩家动作(含超时判定) // 收集玩家动作(含超时判定)
func (f *FightC) collectPlayerActions(ourID, oppID uint32) map[uint32]action.BattleActionI { func (f *FightC) collectPlayerActions(ourID, oppID uint32) map[uint32]action.BattleActionI {
actions := make(map[uint32]action.BattleActionI) actions := make(map[uint32]action.BattleActionI)
timeout := time.After(60*time.Second + time.Duration(f.waittime))
waitr := time.Duration(f.waittime)*time.Millisecond*10 + 30*time.Second
fmt.Println("开始收集玩家动作", waitr)
timeout := time.After(waitr)
for len(actions) < 2 { for len(actions) < 2 {
select { select {
case <-f.quit: case <-f.quit:
f.closefight = true f.closefight = true
return actions return actions
case paction, ok := <-f.actionChan: case paction, ok := <-f.actionChan:
if !ok || f.closefight { if !ok {
f.closefight = true f.closefight = true
return actions return actions
} }
@@ -142,7 +145,8 @@ func (f *FightC) resolveRound(p1Action, p2Action action.BattleActionI) {
switch a := b1.(type) { switch a := b1.(type) {
case *action.ActiveSwitchAction: case *action.ActiveSwitchAction:
if _, ok := b2.(*action.SelectSkillAction); ok { if b2k, ok := b2.(*action.SelectSkillAction); ok {
f.waittime = b2k.CD
f.enterturn(b2.(*action.SelectSkillAction), nil) f.enterturn(b2.(*action.SelectSkillAction), nil)
} else { } else {
@@ -151,7 +155,8 @@ func (f *FightC) resolveRound(p1Action, p2Action action.BattleActionI) {
case *action.UseItemAction: case *action.UseItemAction:
f.handleItemAction(a) f.handleItemAction(a)
if _, ok := b2.(*action.SelectSkillAction); ok { if b2k, ok := b2.(*action.SelectSkillAction); ok {
f.waittime = b2k.CD
f.enterturn(b2.(*action.SelectSkillAction), nil) f.enterturn(b2.(*action.SelectSkillAction), nil)
} else { } else {
if a1, ok := b2.(*action.UseItemAction); ok { if a1, ok := b2.(*action.UseItemAction); ok {

View File

@@ -19,14 +19,14 @@ func (e *EffectNode) Turn_End() {
e.Alive(false) e.Alive(false)
} else { } else {
// e.trunl.Do(func() { e.trunl.Do(func() {
// if e.Ctx().Opp.FightC.IsFirst(e.Ctx().Opp.Player) { //如果对方先手 if !e.Ctx().Our.FightC.IsFirst(e.Ctx().Our.Player) { //如果我方后手,那就给回合+1
// e.duration++ e.duration++
// // e.Alive(true) // e.Alive(true)
// } }
// }) })
e.duration-- e.duration--
} }

View File

@@ -100,33 +100,6 @@ func (h *TomeeHeader) Pack(data any) []byte { //组包
} }
// var _ Blazingservice = (*TomeeHeader)(nil)
// type Blazingservice interface {
// Ret() []byte
// }
// MergeBytes 将多个字节数组合并为一个
func MergeBytes(arrays ...[]byte) []byte {
// 计算所有数组的总长度
totalLen := 0
for _, arr := range arrays {
totalLen += len(arr)
}
// 创建结果切片
result := make([]byte, totalLen)
// 逐个复制数组内容
currentIndex := 0
for _, arr := range arrays {
copy(result[currentIndex:], arr)
currentIndex += len(arr)
}
return result
}
// 遍历结构体方法并执行RECV_cmd // 遍历结构体方法并执行RECV_cmd
func (h *ClientData) Recv(data TomeeHeader) { func (h *ClientData) Recv(data TomeeHeader) {