ret阻断
This commit is contained in:
@@ -2,8 +2,11 @@ package socket
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -37,7 +40,7 @@ func (s *Server) Stop() error {
|
|||||||
return nil
|
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() {
|
defer func() {
|
||||||
if err := recover(); err != nil { // 恢复 panic,err 为 panic 错误值
|
if err := recover(); err != nil { // 恢复 panic,err 为 panic 错误值
|
||||||
// 1. 打印错误信息
|
// 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)
|
atomic.AddInt64(&s.connected, -1)
|
||||||
|
|
||||||
//logging.Infof("conn[%v] disconnected", c.RemoteAddr().String())
|
//logging.Infof("conn[%v] disconnected", c.RemoteAddr().String())
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package action
|
package action
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"blazing/logic/service/common"
|
|
||||||
"blazing/logic/service/fight/info"
|
"blazing/logic/service/fight/info"
|
||||||
|
|
||||||
"github.com/tnnmigga/enum"
|
"github.com/tnnmigga/enum"
|
||||||
@@ -91,8 +90,6 @@ func (u *UseItemAction) Priority() int {
|
|||||||
type EscapeAction struct {
|
type EscapeAction struct {
|
||||||
BaseAction
|
BaseAction
|
||||||
Reason info.EnumBattleOverReason
|
Reason info.EnumBattleOverReason
|
||||||
Our common.PlayerI
|
|
||||||
Opp common.PlayerI
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Priority 返回动作优先级
|
// Priority 返回动作优先级
|
||||||
@@ -104,8 +101,6 @@ func (e *EscapeAction) Priority() int {
|
|||||||
type OverTimeAction struct {
|
type OverTimeAction struct {
|
||||||
BaseAction
|
BaseAction
|
||||||
Reason info.FightOverInfo
|
Reason info.FightOverInfo
|
||||||
Our common.PlayerI
|
|
||||||
Opp common.PlayerI
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *OverTimeAction) GetInfo() info.FightOverInfo {
|
func (e *OverTimeAction) GetInfo() info.FightOverInfo {
|
||||||
|
|||||||
Reference in New Issue
Block a user