From 290e6785590255c7bf5eb2249b43a9bede76aa55 Mon Sep 17 00:00:00 2001 From: 1 <1@72wo.cn> Date: Sat, 27 Sep 2025 17:35:12 +0000 Subject: [PATCH] =?UTF-8?q?refactor(socket):=20=E4=BC=98=E5=8C=96TCP?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=94=99=E8=AF=AF=E8=BF=9E=E6=8E=A5=E8=AE=A1?= =?UTF-8?q?=E6=95=B0=E5=B9=B6=E8=B0=83=E6=95=B4=E8=BF=94=E5=9B=9E=E5=80=BC?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/socket/ServerEvent.go | 12 ++++++++---- logic/service/player/player.go | 5 +---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/common/socket/ServerEvent.go b/common/socket/ServerEvent.go index 75e0bdce..d5707bfc 100644 --- a/common/socket/ServerEvent.go +++ b/common/socket/ServerEvent.go @@ -84,8 +84,8 @@ func (s *Server) OnTraffic(c gnet.Conn) (action gnet.Action) { ws := c.Context().(*player.ClientData).Wsmsg if ws.Tcp { //升级失败时候防止缓冲区溢出 - s.handleTcp(c) - return gnet.None + FF := s.handleTcp(c) + return FF } tt, len1 := ws.ReadBufferBytes(c) @@ -97,7 +97,7 @@ func (s *Server) OnTraffic(c gnet.Conn) (action gnet.Action) { ok, action := ws.Upgrade(c) if !ok { //升级失败,说明是tcp连接 s.handleTcp(c) - return gnet.None + return action } else { // fmt.Println(ws.Buf.Bytes()) c.Read(make([]byte, len1)) @@ -132,6 +132,10 @@ func (s *Server) handleTcp(conn gnet.Conn) (action gnet.Action) { } data, err := s.codec.Decode(conn) if err != nil { + if conn.Context().(*player.ClientData).ERROR_CONNUT > 5 { + action = gnet.Close + } + conn.Context().(*player.ClientData).ERROR_CONNUT += 1 break } @@ -140,7 +144,7 @@ func (s *Server) handleTcp(conn gnet.Conn) (action gnet.Action) { s.parser(conn, data) }) - return gnet.None + return } if conn.InboundBuffered() > 0 { diff --git a/logic/service/player/player.go b/logic/service/player/player.go index 80ecfe57..6de89651 100644 --- a/logic/service/player/player.go +++ b/logic/service/player/player.go @@ -41,7 +41,7 @@ type ClientData struct { IsCrossDomain bool //是否跨域过 Player *Player //客户实体 //UserID uint32 - + ERROR_CONNUT int Wsmsg *WsCodec } @@ -252,8 +252,6 @@ func (p *Player) SendPack(b []byte) error { return err } - - func (p *Player) Cheak(b error) { if b != nil { g.Log().Error(context.Background(), "出现错误", p.Info.UserID, b.Error()) @@ -261,7 +259,6 @@ func (p *Player) Cheak(b error) { } - func LeaveMap(c common.PlayerI) { t := NewTomeeHeader(2002, c.GetInfo().UserID)