This commit is contained in:
2025-07-04 23:41:19 +08:00
parent 7c2c32a31a
commit f0fd00d706
27 changed files with 1206 additions and 163 deletions

View File

@@ -3,10 +3,38 @@ package server
import (
"common/log"
"common/proto/gen/common"
"context"
"common/proto/gen/cs"
"common/proto/gen/grpc_pb"
"gateway/handler/ws_handler"
"sync"
)
func (s *Server) SendMessage(ctx context.Context, req *common.Empty) (*common.Empty, error) {
log.Infof("未实现函数")
return nil, nil
func (s *Server) ToClient(server grpc_pb.Gateway_ToClientServer) error {
wg := &sync.WaitGroup{}
wg.Add(1)
go func() {
defer wg.Done()
defer func() {
if err := recover(); err != nil {
log.Errorf("Action panic: %v", err)
}
}()
for {
if args, err := server.Recv(); err != nil {
return
} else {
if args.UID == -1 {
for _, client := range ws_handler.UserMgr.GetAll() {
client.WriteBytes(cs.MessageID(args.MessageID), args.Payload)
}
} else {
if client := ws_handler.UserMgr.GetByUID(int(args.UID)); client != nil {
client.WriteBytes(cs.MessageID(args.MessageID), args.Payload)
}
}
}
}
}()
wg.Wait()
return server.SendAndClose(&common.Empty{})
}

View File

@@ -4,6 +4,7 @@ import (
"common/discover/common"
"common/net/grpc/service"
"common/proto/gen/grpc_pb"
"gateway/handler/ws_handler"
"google.golang.org/grpc"
)
@@ -25,6 +26,7 @@ func NewServer(ttl int64) *Server {
}
func (s *Server) OnInit(serve *grpc.Server) {
ws_handler.GatewaySID = s.SID
grpc_pb.RegisterGatewayServer(serve, s)
}