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

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) {
if cli := client.UserMgr.GetByUSN(req.USN); cli != nil {
cli.CloseClient()
}
return &grpc_pb.KickUserResp{}, nil
}

View File

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

View File

@@ -1,9 +1,13 @@
package client
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/proto/sc/sc_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"
"google.golang.org/protobuf/proto"
"time"
@@ -42,6 +46,7 @@ func (c *Client) handle(event Event) {
if c.Status == 0 {
c.Status = 1
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{
InstanceID: 1,
})
@@ -79,7 +84,7 @@ func (c *Client) onLeave() {
c.logger.Errorf("SceneNewClient err: %v", err)
return
}
_, err = client.Leave(c.ctx, &grpc_pb.LeaveReq{
_, err = client.Leave(context.Background(), &grpc_pb.LeaveReq{
USN: c.USN,
UniqueNo: c.UniqueNo,
})