コード例 #1
0
        private void DispatchRequest(IAWObject requestObject)
        {
            IMessage message = new Message();

            if (requestObject.IsNull(AWProtocolCodec.CONTROLLER_ID))
            {
                throw new AWCodecError("Request rejected: No Controller ID in request!");
            }
            if (requestObject.IsNull(AWProtocolCodec.ACTION_ID))
            {
                throw new AWCodecError("Request rejected: No Action ID in request!");
            }
            message.Id      = Convert.ToInt32(requestObject.GetShort(AWProtocolCodec.ACTION_ID));
            message.Content = requestObject.GetSFSObject(AWProtocolCodec.PARAM_ID);
            message.IsUDP   = requestObject.ContainsKey(AWProtocolCodec.UDP_PACKET_ID);
            if (message.IsUDP)
            {
                message.PacketId = requestObject.GetLong(AWProtocolCodec.UDP_PACKET_ID);
            }
            int @byte = (int)requestObject.GetByte(AWProtocolCodec.CONTROLLER_ID);

            UnityEngine.Debug.Log("@byte" + @byte);
            IController controller = this.bitSwarm.GetController(@byte);

            if (controller == null)
            {
                throw new AWError("Cannot handle server response. Unknown controller, id: " + @byte);
            }
            controller.HandleMessage(message);
        }
コード例 #2
0
        public void HandleHandShake(BaseEvent evt)
        {
            IAWObject iAWObject = evt.Params["message"] as IAWObject;

            if (iAWObject.IsNull(BaseRequest.KEY_ERROR_CODE))
            {
                this.sessionToken = iAWObject.GetUtfString(HandshakeRequest.KEY_SESSION_TOKEN);
                this.bitSwarm.CompressionThreshold = iAWObject.GetInt(HandshakeRequest.KEY_COMPRESSION_THRESHOLD);
                this.bitSwarm.MaxMessageSize       = iAWObject.GetInt(HandshakeRequest.KEY_MAX_MESSAGE_SIZE);
                if (this.debug)
                {
                    this.log.Debug(new string[]
                    {
                        string.Format("Handshake response: tk => {0}, ct => {1}", this.sessionToken, this.bitSwarm.CompressionThreshold)
                    });
                }
                if (this.bitSwarm.IsReconnecting)
                {
                    this.bitSwarm.IsReconnecting = false;
                    this.DispatchEvent(new AWEvent(AWEvent.CONNECTION_RESUME));
                }
                else
                {
                    this.isConnecting = false;
                    Hashtable hashtable = new Hashtable();
                    hashtable["success"] = true;
                    this.DispatchEvent(new AWEvent(AWEvent.CONNECTION, hashtable));
                }
            }
            else
            {
                short     @short       = iAWObject.GetShort(BaseRequest.KEY_ERROR_CODE);
                string    errorMessage = AWErrorCodes.GetErrorMessage((int)@short, this.log, iAWObject.GetUtfStringArray(BaseRequest.KEY_ERROR_PARAMS));
                Hashtable hashtable2   = new Hashtable();
                hashtable2["success"]      = false;
                hashtable2["errorMessage"] = errorMessage;
                hashtable2["errorCode"]    = @short;
                this.DispatchEvent(new AWEvent(AWEvent.CONNECTION, hashtable2));
            }
        }