123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- package http
- import (
- "io/ioutil"
- pb "go-common/app/service/main/broadcast/api/grpc/v1"
- "go-common/library/ecode"
- bm "go-common/library/net/http/blademaster"
- "github.com/gogo/protobuf/proto"
- )
- func connect(ctx *bm.Context) {
- query := ctx.Request.URL.Query()
- if token, err := c.Get("httpToken").String(); err != nil || token != query.Get("token") {
- ctx.Protobuf(nil, ecode.Unauthorized)
- return
- }
- b, err := ioutil.ReadAll(ctx.Request.Body)
- if err != nil {
- ctx.Protobuf(nil, err)
- return
- }
- var req pb.ConnectReq
- if err = proto.Unmarshal(b, &req); err != nil {
- ctx.Protobuf(nil, err)
- return
- }
- mid, key, room, platform, accepts, err := srv.Connect(ctx, req.Server, req.ServerKey, req.Cookie, req.Token)
- if err != nil {
- ctx.Protobuf(nil, err)
- return
- }
- ctx.Protobuf(&pb.ConnectReply{Mid: mid, Key: key, RoomID: room, Accepts: accepts, Platform: platform}, nil)
- }
- func disconnect(ctx *bm.Context) {
- query := ctx.Request.URL.Query()
- if token, err := c.Get("httpToken").String(); err != nil || token != query.Get("token") {
- ctx.Protobuf(nil, ecode.Unauthorized)
- return
- }
- b, err := ioutil.ReadAll(ctx.Request.Body)
- if err != nil {
- ctx.Protobuf(nil, err)
- return
- }
- var req pb.DisconnectReq
- if err = proto.Unmarshal(b, &req); err != nil {
- ctx.Protobuf(nil, err)
- return
- }
- has, err := srv.Disconnect(ctx, req.Mid, req.Key, req.Server)
- if err != nil {
- ctx.Protobuf(nil, err)
- return
- }
- ctx.Protobuf(&pb.DisconnectReply{Has: has}, nil)
- }
- func heartbeat(ctx *bm.Context) {
- query := ctx.Request.URL.Query()
- if token, err := c.Get("httpToken").String(); err != nil || token != query.Get("token") {
- ctx.Protobuf(nil, ecode.Unauthorized)
- return
- }
- b, err := ioutil.ReadAll(ctx.Request.Body)
- if err != nil {
- ctx.Protobuf(nil, err)
- return
- }
- var req pb.HeartbeatReq
- if err = proto.Unmarshal(b, &req); err != nil {
- ctx.Protobuf(nil, err)
- return
- }
- if err := srv.Heartbeat(ctx, req.Mid, req.Key, req.Server); err != nil {
- ctx.Protobuf(nil, err)
- return
- }
- ctx.Protobuf(&pb.HeartbeatReply{}, nil)
- }
- func renewOnline(ctx *bm.Context) {
- query := ctx.Request.URL.Query()
- if token, err := c.Get("httpToken").String(); err != nil || token != query.Get("token") {
- ctx.Protobuf(nil, ecode.Unauthorized)
- return
- }
- b, err := ioutil.ReadAll(ctx.Request.Body)
- if err != nil {
- ctx.Protobuf(nil, err)
- return
- }
- var req pb.OnlineReq
- if err = proto.Unmarshal(b, &req); err != nil {
- ctx.Protobuf(nil, err)
- return
- }
- roomCount, err := srv.RenewOnline(ctx, req.Server, req.Sharding, req.RoomCount)
- if err != nil {
- ctx.Protobuf(nil, err)
- return
- }
- ctx.Protobuf(&pb.OnlineReply{RoomCount: roomCount}, nil)
- }
|