Exemple #1
0
        public static SCData Create()
        {
            SCData packet = ReferencePool.Acquire <SCData>();

            if (packet.m_ExtensionObject == null)
            {
                packet.m_ExtensionObject = new DataResponse();
            }
            return(packet);
        }
        public Packet DeserializePacket(IPacketHeader packetHeader, Stream source, out object customErrorData)
        {
            customErrorData = null;

            SCPacketHeader scPacketHeader = packetHeader as SCPacketHeader;

            if (scPacketHeader == null)
            {
                Log.Warning("Packet header is invalid.");
                return(null);
            }

            Packet packet = null;

            if (scPacketHeader.IsValid)
            {
                if (scPacketHeader.Id == 4)
                {
                    //BinaryReader r = new BinaryReader(source);
                    //byte[] message = r.ReadBytes((int)(source.Length - source.Position));

                    //string returnStr = string.Empty;
                    //for (int i = 0; i < message.Length; i++)
                    //{
                    //    returnStr += message[i].ToString("X2");
                    //}

                    SCData scData = SCData.Create();
                    ((DataResponse)scData.GetExtensionObject()).MergeFrom(source);
                    //Log.Info("data response {0}", scData);
                    packet = scData;
                }
                else
                {
                    packet = SCHeartBeat.Create();
                    Log.Info("heart response ");
                }
            }
            else
            {
                Log.Warning("Packet header is invalid.");
            }
            ReferencePool.Release(scPacketHeader);
            return(packet);
        }
Exemple #3
0
        public override void Handle(object sender, Packet packet)
        {
            SCData packetImpl = (SCData)packet;
            //Log.Info("Receive packet '{0}'.", packetImpl.Id.ToString());

            DataResponse dataResponse = (DataResponse)packetImpl.GetExtensionObject();

            for (int i = 0; i < dataResponse.Objs.Count; i++)
            {
                ObjData objData = dataResponse.Objs[i];
                for (int j = 0; j < GameData.g_listAircreaft.Count; j++)
                {
                    Aircraft aircraft = GameData.g_listAircreaft[j];
                    if (aircraft.Id == objData.SerialId)
                    {
                        aircraft.m_fixv3RenderPosition = new FixVector3(
                            Fix64.FromRaw(objData.X),
                            Fix64.FromRaw(objData.Y),
                            Fix64.FromRaw(objData.Z));
                        aircraft.r_isFire = objData.IsFire;
                    }
                }
            }
        }