server.go 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Package server generate by warden_gen
  2. package server
  3. import (
  4. "context"
  5. "net"
  6. pb "go-common/app/service/main/broadcast/api/grpc/v1"
  7. "go-common/app/service/main/broadcast/service"
  8. "go-common/library/conf/paladin"
  9. "go-common/library/net/rpc/warden"
  10. "google.golang.org/grpc"
  11. // use gzip decoder
  12. _ "google.golang.org/grpc/encoding/gzip"
  13. )
  14. // New Zerg warden rpc server
  15. func New(svr *service.Service) (*warden.Server, string) {
  16. var rc struct {
  17. Server *warden.ServerConfig
  18. }
  19. if err := paladin.Get("grpc.toml").UnmarshalTOML(&rc); err != nil {
  20. panic(err)
  21. }
  22. _, port, _ := net.SplitHostPort(rc.Server.Addr)
  23. ws := warden.NewServer(rc.Server, grpc.MaxRecvMsgSize(32*1024*1024), grpc.MaxSendMsgSize(32*1024*1024))
  24. pb.RegisterZergServer(ws.Server(), &server{svr})
  25. return ws, port
  26. }
  27. type server struct {
  28. srv *service.Service
  29. }
  30. var _ pb.ZergServer = &server{}
  31. // Ping Service
  32. func (s *server) Ping(ctx context.Context, req *pb.PingReq) (*pb.PingReply, error) {
  33. return &pb.PingReply{}, nil
  34. }
  35. // Close Service
  36. func (s *server) Close(ctx context.Context, req *pb.CloseReq) (*pb.CloseReply, error) {
  37. return &pb.CloseReply{}, nil
  38. }
  39. // Connect connect a conn.
  40. func (s *server) Connect(ctx context.Context, req *pb.ConnectReq) (*pb.ConnectReply, error) {
  41. mid, key, room, platform, accepts, err := s.srv.Connect(ctx, req.Server, req.ServerKey, req.Cookie, req.Token)
  42. if err != nil {
  43. return &pb.ConnectReply{}, err
  44. }
  45. return &pb.ConnectReply{Mid: mid, Key: key, RoomID: room, Accepts: accepts, Platform: platform}, nil
  46. }
  47. // Disconnect disconnect a conn.
  48. func (s *server) Disconnect(ctx context.Context, req *pb.DisconnectReq) (*pb.DisconnectReply, error) {
  49. has, err := s.srv.Disconnect(ctx, req.Mid, req.Key, req.Server)
  50. if err != nil {
  51. return &pb.DisconnectReply{}, err
  52. }
  53. return &pb.DisconnectReply{Has: has}, nil
  54. }
  55. // Heartbeat beartbeat a conn.
  56. func (s *server) Heartbeat(ctx context.Context, req *pb.HeartbeatReq) (*pb.HeartbeatReply, error) {
  57. if err := s.srv.Heartbeat(ctx, req.Mid, req.Key, req.Server); err != nil {
  58. return &pb.HeartbeatReply{}, err
  59. }
  60. return &pb.HeartbeatReply{}, nil
  61. }
  62. // RenewOnline renew server online.
  63. func (s *server) RenewOnline(ctx context.Context, req *pb.OnlineReq) (*pb.OnlineReply, error) {
  64. roomCount, err := s.srv.RenewOnline(ctx, req.Server, req.Sharding, req.RoomCount)
  65. if err != nil {
  66. return &pb.OnlineReply{}, err
  67. }
  68. return &pb.OnlineReply{RoomCount: roomCount}, nil
  69. }
  70. // Receive receive a message.
  71. func (s *server) Receive(ctx context.Context, req *pb.ReceiveReq) (*pb.ReceiveReply, error) {
  72. if err := s.srv.Receive(ctx, req.Mid, req.Proto); err != nil {
  73. return &pb.ReceiveReply{}, err
  74. }
  75. return &pb.ReceiveReply{}, nil
  76. }
  77. // ServerList return server list.
  78. func (s *server) ServerList(ctx context.Context, req *pb.ServerListReq) (*pb.ServerListReply, error) {
  79. return s.srv.ServerList(ctx, req.Platform), nil
  80. }