Example #1
0
    public ReportAck Report(params MetricPoint[] points)
    {
        ReportAck rsp = new ReportAck();

        if (!enable)
        {
            Logger.Warn("Metrics is disabled");
            rsp.Status = 400;
            return(rsp);
        }

        PodMetrics podMetrics = new PodMetrics()
        {
            Meta = meta,
        };

        for (int i = 0; i < points.Length; i++)
        {
            podMetrics.Usages.Insert(i, points[i]);
        }

        Report req = new Report()
        {
            Metrics = podMetrics,
        };

        var reply = SendMsg(ByteUtils.ObjectToByteString(req), (UInt32)MetricCMD.Report);

        if (reply == null)
        {
            rsp.Status = 500;
        }
        else
        {
            ByteUtils.ByteStringToObject(rsp, reply.Message);
        }
        return(rsp);
    }
    public override IMessage OnHotelBroadCast(ByteString msg)
    {
        HotelBroadcast broadcast = new HotelBroadcast();

        ByteUtils.ByteStringToObject(broadcast, msg);
        Logger.Info("HotelBroadcast start, userID:{0} gameID:{1} roomID:{2} cpProto:{3}", broadcast.UserID, broadcast.GameID, broadcast.RoomID, broadcast.CpProto.ToStringUtf8());

        HotelBroadcastAck broadcastAck = new HotelBroadcastAck()
        {
            UserID = broadcast.UserID, Status = (UInt32)ErrorCode.Ok
        };

        PushToHotelMsg pushMsg = new PushToHotelMsg()
        {
            PushType = PushMsgType.UserTypeAll,
            GameID   = broadcast.GameID,
            RoomID   = broadcast.RoomID,
            CpProto  = broadcast.CpProto,
        };

        pushMsg.DstUids.Add(broadcast.UserID);

        PushToHotel(broadcast.RoomID, pushMsg);

        //测试主动推送给MVS的两个消息
        string str = broadcast.CpProto.ToStringUtf8();

        Logger.Info("HotelBroadcast, str = {0}", str);

        String[] result = str.Split("|");
        if (result.Length > 1)
        {
            if (result[0] == "joinover")
            {
                String[] param = result[1].Split(",");
                if (param.Length > 1)
                {
                    UInt64 roomID = UInt64.Parse(param[0]);
                    UInt32 gameID = UInt32.Parse(param[1]);
                    PushJoinOver(roomID, gameID);
                }
            }
            else if (result[0] == "joinopen")
            {
                PushJoinOpen(broadcast.RoomID, broadcast.GameID);
            }
            else if (result[0] == "kickplayer")
            {
                String[] param = result[1].Split(",");
                if (param.Length > 2)
                {
                    UInt64 roomID = UInt64.Parse(param[0]);
                    UInt32 destID = UInt32.Parse(param[1]);
                    PushKickPlayer(roomID, destID);
                }
            }
            else if (result[0] == "getRoomDetail")
            {
                String[] param = result[1].Split(",");
                if (param.Length > 1)
                {
                    UInt32 gameID = UInt32.Parse(param[0]);
                    UInt64 roomID = UInt64.Parse(param[1]);
                    PushGetRoomDetail(roomID, gameID, 2);
                }
            }
            else if (result[0] == "setRoomProperty")
            {
                ByteString roomProperty = Google.Protobuf.ByteString.CopyFromUtf8(result[1]);
                PushSetRoomProperty(broadcast.RoomID, broadcast.GameID, roomProperty);
            }
            else if (result[0] == "createRoom")
            {
                CreateRoom request = new CreateRoom()
                {
                    GameID   = broadcast.GameID,
                    Ttl      = 600,
                    RoomInfo = new RoomInfo()
                    {
                        RoomName     = "game server room",
                        MaxPlayer    = 2,
                        Mode         = 1,
                        CanWatch     = 1,
                        Visibility   = 1,
                        RoomProperty = Google.Protobuf.ByteString.CopyFromUtf8("hello"),
                    },
                    WatchSetting = new WatchSetting()
                    {
                        MaxWatch        = 3,
                        WatchPersistent = false,
                        WatchDelayMs    = 10 * 1000,
                        CacheTime       = 60 * 1000,
                    },
                };
                var reply = CreateRoom(request);
                Logger.Debug("create room request: {0}, reply: {1}", request, reply);
            }
            else if (result[0] == "touchRoom")
            {
                String[]  param   = result[1].Split(",");
                TouchRoom request = new TouchRoom()
                {
                    GameID = broadcast.GameID,
                    RoomID = UInt64.Parse(param[0]),
                    Ttl    = UInt32.Parse(param[1]),
                };
                var reply = TouchRoom(request);
                Logger.Debug("touch room request: {0}, reply: {1}", request, reply);
            }
            else if (result[0] == "destroyRoom")
            {
                DestroyRoom request = new DestroyRoom()
                {
                    GameID = broadcast.GameID,
                    RoomID = UInt64.Parse(result[1]),
                };
                var reply = DestroyRoom(request);
                Logger.Debug("destroy room request: {0}, reply: {1}", request, reply);
            }
            else if (result[0] == "setFrameSyncRate")
            {
                if (result.Length < 3)
                {
                    Logger.Error("set frame sync rate error: no cacheFrameMS");
                    return(new HotelBroadcastAck()
                    {
                        UserID = broadcast.UserID, Status = (UInt32)ErrorCode.BadRequest
                    });
                }

                var rate         = UInt32.Parse(result[1]);
                var cacheFrameMS = Int32.Parse(result[2]);
                SetFrameSyncRate(broadcast.RoomID, broadcast.GameID, rate, 1, cacheFrameMS);
                Logger.Debug("set frame sync rate: {0}", rate);
            }
            else if (result[0] == "getCacheData")
            {
                Int32 cacheFrameMS = Int32.Parse(result[1]);
                GetCacheData(broadcast.RoomID, broadcast.GameID, cacheFrameMS);
                Logger.Debug("get cache frame data: {0}", cacheFrameMS);
            }
            else if (result[0] == "frameBroadcast")
            {
                var cpProto = result[1];
                FrameBroadcast(broadcast.RoomID, broadcast.GameID, ByteString.CopyFromUtf8(cpProto), 2);
                Logger.Info("frame broadcast: {0}", cpProto);
            }
            else if (result[0] == "metric")
            {
                if (result.Length >= 3)
                {
                    string      name  = result[1];
                    double      value = double.Parse(result[2]);
                    MetricPoint point = new MetricPoint()
                    {
                        Name  = name,
                        Value = value,
                        Attr  = MetricAttr.Custom,
                    };
                    ReportAck ack = ReportMetrics(point);
                    Logger.Info("Set matric response: {0}", ack);
                }
            }
        }

        Logger.Info("HotelBroadcast end, userID:{0} gameID:{1} roomID:{2} cpProto:{3}", broadcast.UserID, broadcast.GameID, broadcast.RoomID, broadcast.CpProto.ToStringUtf8());

        return(broadcastAck);
    }