Пример #1
0
        private void onFeedbackMessage(ulong videoId, int msgId, MessageReader reader)
        {
            MessageReader.StreamReader stream = reader.Reader;
            switch (msgId)
            {
            case 0x12211:     // Msg_CtrlCam_Result
            {
                int    result = stream.ReadInt32();
                string reason = stream.ReadString();
                onCtrlCamResult(videoId, result, reason);
            }
            break;

            case 0x12221:     // Msg_Onoff_Name
            {
                int onoffCount = stream.ReadInt32();
                for (int i = 0; i < onoffCount; i++)
                {
                    stream.ReadString();
                    stream.ReadInt32();
                }
                for (int i = 1; i <= 4; i++)
                {
                    onSwitchState(videoId, i, stream.ReadInt32());
                }
                if (reader.BytesLeft > 0)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        stream.ReadString();
                    }
                }
                if (reader.BytesLeft > 0)
                {
                    for (int i = 5; i <= 9; i++)
                    {
                        onSwitchState(videoId, i, stream.ReadInt32());
                    }
                }
                if (reader.BytesLeft > 0)
                {
                    onSwitchState(videoId, 10, stream.ReadInt32());
                }
            }
            break;

            case 0x12251:     // Msg_Onoff_State
            {
                int index = stream.ReadInt32();
                int state = stream.ReadInt32();
                onSwitchState(videoId, -index, state);
            }
            break;
            }
        }
Пример #2
0
        private void onMessage(byte[] message)
        {
            MessageReader reader = new MessageReader(message);

            MessageReader.StreamReader stream = reader.Reader;
            switch (reader.MessageID)
            {
            case 0x11017:     // Msg_NetCtrl_Nodebase_Name
                _serverName = stream.ReadString();
                break;

            case 0x11013:     // Msg_NetCtrl_User_Params
            {
                string user  = stream.ReadString();
                bool   valid = stream.ReadInt32() != 0;
                if (valid)
                {
                    if (!Ready)
                    {
                        _userStage  = stream.ReadInt32();
                        _userRights = stream.ReadInt32();
                        _serverID   = stream.ReadUInt64();
                        int len = stream.ReadInt32();
                        _userAuth = new ulong[len];
                        for (int i = 0; i < len; i++)
                        {
                            _userAuth[i] = stream.ReadUInt64();
                        }
                        Ready = true;
                        fireOnAuthentication(true);

                        sendGetRealtimeMessage();
                    }
                }
                else
                {
                    Ready = false;
                    cancelLoginChecker();
                    fireOnAuthentication(false);
                    _connection.Reconnect();
                }
            }
            break;

            case 0x11015:     // Msg_NetCtrl_ID
                _netctrlID = stream.ReadInt32();
                break;

            case 0x10030:     // Msg_Tree_Info
                break;

            case 0x10032:     // Msg_Xml_Tree
            {
                bool   up           = stream.ReadInt32() != 0;
                int    size         = stream.ReadInt32();
                int    uncompSize   = stream.ReadInt32();
                byte[] compressed   = stream.ReadBytes(size - sizeof(Int32));
                byte[] uncompressed = ZLibUtil.Uncompress(compressed, uncompSize);
                string xml          = Encoding.Default.GetString(uncompressed);
                if (xml.Last() == 0)
                {
                    xml = xml.Substring(0, xml.Length - 1);
                }

                VideoParser.Node tree = null;
                if (xml != _lastBaseXml && VideoParser.TryParseNode(xml, out tree))
                {
                    fireOnNodeTree(tree, xml);
                    _lastBaseXml = xml;
                    updateTree(tree);
                }
            }
            break;

            case 0x11021:     // Msg_Video_Port
            {
                ulong videoID   = stream.ReadUInt64();
                int   oldPort   = stream.ReadInt32();
                int   bandwidth = stream.ReadInt32();
                int   port      = stream.ReadInt32();
                fireOnVideoPort(videoID, port, bandwidth);
            }
            break;

            case 0x11022:     // Msg_Video_Miss
            {
                ulong videoID = stream.ReadUInt64();
                fireOnVideoMiss(videoID);
            }
            break;

            case 0x100B1:     //Msg_Realtime_Info
            {
                string             xml    = stream.ReadString();
                VideoParser.Camera camera = null;
                VideoParser.GPS    gps    = null;
                if (VideoParser.TryParseRealtime(xml, out camera) || VideoParser.TryParseRealtime(xml, out gps))
                {
                    fireOnRealtimeInfo(camera, gps);
                }
            }
            break;

            case 0x11028:     // Msg_Video_Ctrl
            {
                ulong videoId = stream.ReadUInt64();
                int   msgId   = stream.ReadInt32();
                onFeedbackMessage(videoId, msgId, reader);
            }
            break;
            }
        }