Esempio n. 1
0
        /// <summary>
        /// **WITHIN THREAD**
        /// The entrance of protocol bytes
        /// Called by HoxisClient
        /// </summary>
        /// <param name="data"></param>
        public void ProtocolEntry(byte[] data)
        {
            string        json  = FF.BytesToString(data);
            HoxisProtocol proto = FF.JsonToObject <HoxisProtocol>(json);

            _protoQueue.Enqueue(proto);
        }
        /// <summary>
        /// **WITHIN THREAD**
        /// The entrance of protocol bytes
        /// </summary>
        /// <param name="data"></param>
        public void ProtocolEntry(byte[] data)
        {
            string        json  = FF.BytesToString(data);
            HoxisProtocol proto = FF.JsonToObject <HoxisProtocol>(json);

            switch (proto.type)
            {
            case ProtocolType.Synchronization:
                switch (proto.receiver.type)
                {
                case ReceiverType.Cluster:
                    if (realtimeData.parentCluster == null)
                    {
                        return;
                    }
                    realtimeData.parentCluster.ProtocolBroadcast(proto);
                    break;

                case ReceiverType.Team:
                    if (realtimeData.parentTeam == null)
                    {
                        return;
                    }
                    realtimeData.parentTeam.ProtocolBroadcast(proto);
                    break;

                case ReceiverType.User:
                    HoxisUser user = HoxisServer.Ins.GetUser(proto.receiver.uid);
                    // todo send
                    break;
                }
                break;

            case ProtocolType.Request:
                // Request check
                Ret ret;
                CheckRequest(proto, out ret);
                if (ret.code != 0)
                {
                    ResponseError(proto.handle, C.RESP_CHECK_FAILED, ret.desc);
                    return;
                }
                // Check ok
                if (!respTable.ContainsKey(proto.action.method))
                {
                    if (DebugRecorder.LogEnable(_logger))
                    {
                        _logger.LogError(FF.StringFormat("invalid request: {0}", proto.action.method), "", true);
                    }
                    ResponseError(proto.handle, C.RESP_CHECK_FAILED, FF.StringFormat("invalid request: {0}", proto.action.method));
                    return;
                }
                respTable[proto.action.method](proto.handle, proto.action.args);
                break;

            default:
                if (DebugRecorder.LogEnable(_logger))
                {
                    _logger.LogError(FF.StringFormat("invalid protocol type: {0}", proto.type), "");
                }
                break;
            }
        }