feat 踢人功能

This commit is contained in:
2026-01-08 22:57:58 +08:00
parent 265e522aff
commit 5af027b35c
5 changed files with 15 additions and 2 deletions

2
go.mod
View File

@@ -4,7 +4,7 @@ go 1.23.1
require ( require (
bou.ke/monkey v1.0.2 bou.ke/monkey v1.0.2
git.hlsq.asia/mmorpg/service-common v0.0.0-20260107061047-e02e56781e78 git.hlsq.asia/mmorpg/service-common v0.0.0-20260108144540-69e82ec0fe77
github.com/alicebob/miniredis/v2 v2.35.0 github.com/alicebob/miniredis/v2 v2.35.0
github.com/gin-contrib/cors v1.7.6 github.com/gin-contrib/cors v1.7.6
github.com/gin-gonic/gin v1.11.0 github.com/gin-gonic/gin v1.11.0

2
go.sum
View File

@@ -4,6 +4,8 @@ filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
git.hlsq.asia/mmorpg/service-common v0.0.0-20260107061047-e02e56781e78 h1:4CP8w5jHDOdN7hym8YrtioxNDd7PS2WcZDrO6dtY344= git.hlsq.asia/mmorpg/service-common v0.0.0-20260107061047-e02e56781e78 h1:4CP8w5jHDOdN7hym8YrtioxNDd7PS2WcZDrO6dtY344=
git.hlsq.asia/mmorpg/service-common v0.0.0-20260107061047-e02e56781e78/go.mod h1:xv6m1I2jUA6mudKVznygpnzMoshBQarthHD1QnkW4qc= git.hlsq.asia/mmorpg/service-common v0.0.0-20260107061047-e02e56781e78/go.mod h1:xv6m1I2jUA6mudKVznygpnzMoshBQarthHD1QnkW4qc=
git.hlsq.asia/mmorpg/service-common v0.0.0-20260108144540-69e82ec0fe77 h1:39SVfV3+uysM25P+dSnJMvtJJI9l2aZ+/n/ooTdHqxk=
git.hlsq.asia/mmorpg/service-common v0.0.0-20260108144540-69e82ec0fe77/go.mod h1:xv6m1I2jUA6mudKVznygpnzMoshBQarthHD1QnkW4qc=
github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0= github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0=
github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/alicebob/miniredis/v2 v2.35.0 h1:QwLphYqCEAo1eu1TqPRN2jgVMPBweeQcR21jeqDCONI= github.com/alicebob/miniredis/v2 v2.35.0 h1:QwLphYqCEAo1eu1TqPRN2jgVMPBweeQcR21jeqDCONI=

View File

@@ -59,5 +59,8 @@ func (s *Server) ToClient(server grpc_pb.Gateway_ToClientServer) error {
} }
func (s *Server) KickUser(ctx context.Context, req *grpc_pb.KickUserReq) (*grpc_pb.KickUserResp, error) { func (s *Server) KickUser(ctx context.Context, req *grpc_pb.KickUserReq) (*grpc_pb.KickUserResp, error) {
if cli := client.UserMgr.GetByUSN(req.USN); cli != nil {
cli.CloseClient()
}
return &grpc_pb.KickUserResp{}, nil return &grpc_pb.KickUserResp{}, nil
} }

View File

@@ -3,8 +3,10 @@ package client
import ( import (
"context" "context"
"fmt" "fmt"
"git.hlsq.asia/mmorpg/service-common/db/redis"
"git.hlsq.asia/mmorpg/service-common/log" "git.hlsq.asia/mmorpg/service-common/log"
"git.hlsq.asia/mmorpg/service-common/net/socket" "git.hlsq.asia/mmorpg/service-common/net/socket"
"git.hlsq.asia/mmorpg/service-gateway/internal/global"
"go.uber.org/zap" "go.uber.org/zap"
"runtime/debug" "runtime/debug"
"sync" "sync"
@@ -103,6 +105,7 @@ func (c *Client) onClose() {
} }
c.Status = 2 c.Status = 2
UserMgr.Delete(c.USN) UserMgr.Delete(c.USN)
redis.GetClient().HDel(c.ctx, fmt.Sprintf(global.KeyGatewayInfo, c.USN), global.HFieldInfoGatewaySID)
c.onLeave() c.onLeave()
c.Done() c.Done()
} }

View File

@@ -1,9 +1,13 @@
package client package client
import ( import (
"context"
"fmt"
"git.hlsq.asia/mmorpg/service-common/db/redis"
"git.hlsq.asia/mmorpg/service-common/net/grpc/service" "git.hlsq.asia/mmorpg/service-common/net/grpc/service"
"git.hlsq.asia/mmorpg/service-common/proto/sc/sc_pb" "git.hlsq.asia/mmorpg/service-common/proto/sc/sc_pb"
"git.hlsq.asia/mmorpg/service-common/proto/ss/grpc_pb" "git.hlsq.asia/mmorpg/service-common/proto/ss/grpc_pb"
"git.hlsq.asia/mmorpg/service-gateway/internal/global"
"git.hlsq.asia/mmorpg/service-gateway/internal/grpc_server/stream_client" "git.hlsq.asia/mmorpg/service-gateway/internal/grpc_server/stream_client"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
"time" "time"
@@ -42,6 +46,7 @@ func (c *Client) handle(event Event) {
if c.Status == 0 { if c.Status == 0 {
c.Status = 1 c.Status = 1
UserMgr.Add(c.USN, c) UserMgr.Add(c.USN, c)
redis.GetClient().HSet(c.ctx, fmt.Sprintf(global.KeyGatewayInfo, c.USN), global.HFieldInfoGatewaySID, GatewaySID)
c.WriteMessage(sc_pb.MessageID_MESSAGE_ID_LOGIN_SUCCESS, &sc_pb.S2C_LoginSuccess{ c.WriteMessage(sc_pb.MessageID_MESSAGE_ID_LOGIN_SUCCESS, &sc_pb.S2C_LoginSuccess{
InstanceID: 1, InstanceID: 1,
}) })
@@ -79,7 +84,7 @@ func (c *Client) onLeave() {
c.logger.Errorf("SceneNewClient err: %v", err) c.logger.Errorf("SceneNewClient err: %v", err)
return return
} }
_, err = client.Leave(c.ctx, &grpc_pb.LeaveReq{ _, err = client.Leave(context.Background(), &grpc_pb.LeaveReq{
USN: c.USN, USN: c.USN,
UniqueNo: c.UniqueNo, UniqueNo: c.UniqueNo,
}) })