diff --git a/common/socket/ServerEvent.go b/common/socket/ServerEvent.go index b127962f5..581877cb8 100644 --- a/common/socket/ServerEvent.go +++ b/common/socket/ServerEvent.go @@ -2,8 +2,11 @@ package socket import ( "context" + "fmt" "log" + "net" "os" + "strings" "sync/atomic" "time" @@ -37,7 +40,7 @@ func (s *Server) Stop() error { return nil } -func (s *Server) OnClose(c gnet.Conn, _ error) (action gnet.Action) { +func (s *Server) OnClose(c gnet.Conn, err error) (action gnet.Action) { defer func() { if err := recover(); err != nil { // 恢复 panic,err 为 panic 错误值 // 1. 打印错误信息 @@ -46,7 +49,16 @@ func (s *Server) OnClose(c gnet.Conn, _ error) (action gnet.Action) { } }() + // 识别 RST 导致的连接中断(错误信息含 "connection reset") + if err != nil && (strings.Contains(err.Error(), "connection reset") || strings.Contains(err.Error(), "reset by peer")) { + remoteIP := c.RemoteAddr().(*net.TCPAddr).IP.String() + log.Printf("RST 攻击检测: 来源 %s, 累计攻击次数 %d", remoteIP) + + // 防护逻辑:临时封禁异常 IP(可扩展为 IP 黑名单) + // go s.tempBlockIP(remoteIP, 5*time.Minute) + } + fmt.Println(err, c.RemoteAddr().String(), "断开连接") atomic.AddInt64(&s.connected, -1) //logging.Infof("conn[%v] disconnected", c.RemoteAddr().String()) diff --git a/logic/service/fight/action/BattleAction.go b/logic/service/fight/action/BattleAction.go index 69e28d89d..783ad3f57 100644 --- a/logic/service/fight/action/BattleAction.go +++ b/logic/service/fight/action/BattleAction.go @@ -1,7 +1,6 @@ package action import ( - "blazing/logic/service/common" "blazing/logic/service/fight/info" "github.com/tnnmigga/enum" @@ -91,8 +90,6 @@ func (u *UseItemAction) Priority() int { type EscapeAction struct { BaseAction Reason info.EnumBattleOverReason - Our common.PlayerI - Opp common.PlayerI } // Priority 返回动作优先级 @@ -104,8 +101,6 @@ func (e *EscapeAction) Priority() int { type OverTimeAction struct { BaseAction Reason info.FightOverInfo - Our common.PlayerI - Opp common.PlayerI } func (e *OverTimeAction) GetInfo() info.FightOverInfo {