Exemplo n.º 1
0
        public void EnterSceneInfo(NetState netstate, TradeAge.Server.Entity.Character.SimplePlayer player)
        {
            var           pw            = PacketWriter.AcquireContent(1101);
            PacketProfile packetProfile = PacketProfile.GetOutgoingProfile(1101);

            if (packetProfile != null)
            {
                packetProfile.RegConstruct();
            }
            SimplePlayerWriteProxy.Write(player, pw);
            netstate.Send(pw);
            if (packetProfile != null)
            {
                packetProfile.Record(pw.Length);
            }
            PacketWriter.ReleaseContent(pw);
        }
        public void CreatePlayerResult(NetState netstate, TradeAge.Server.Entity.Login.CraetePlayerResult result)
        {
            var           pw            = PacketWriter.AcquireContent(1003);
            PacketProfile packetProfile = PacketProfile.GetOutgoingProfile(1003);

            if (packetProfile != null)
            {
                packetProfile.RegConstruct();
            }
            pw.Write((byte)result);
            netstate.Send(pw);
            if (packetProfile != null)
            {
                packetProfile.Record(pw.Length);
            }
            PacketWriter.ReleaseContent(pw);
        }
        public void SpriteLeave(NetState netstate, int playerId)
        {
            var           pw            = PacketWriter.AcquireContent(1104);
            PacketProfile packetProfile = PacketProfile.GetOutgoingProfile(1104);

            if (packetProfile != null)
            {
                packetProfile.RegConstruct();
            }
            pw.Write(playerId);
            netstate.Send(pw);
            if (packetProfile != null)
            {
                packetProfile.Record(pw.Length);
            }
            PacketWriter.ReleaseContent(pw);
        }
Exemplo n.º 4
0
        public void SyncServerTime(NetState netstate, DateTime serverTime, int id)
        {
            var           pw            = PacketWriter.AcquireContent(2);
            PacketProfile packetProfile = PacketProfile.GetOutgoingProfile(2);

            if (packetProfile != null)
            {
                packetProfile.RegConstruct();
            }
            pw.Write(serverTime.Ticks);
            pw.Write(id);
            netstate.Send(pw);
            if (packetProfile != null)
            {
                packetProfile.Record(pw.Length);
            }
            PacketWriter.ReleaseContent(pw);
        }
        public void EnterSceneInfo(NetState netstate, TradeAge.Server.Entity.Common.Vector3 postion, TradeAge.Server.Entity.Common.Vector3 direction)
        {
            var           pw            = PacketWriter.AcquireContent(1101);
            PacketProfile packetProfile = PacketProfile.GetOutgoingProfile(1101);

            if (packetProfile != null)
            {
                packetProfile.RegConstruct();
            }
            Vector3WriteProxy.Write(postion, pw);
            Vector3WriteProxy.Write(direction, pw);
            netstate.Send(pw);
            if (packetProfile != null)
            {
                packetProfile.Record(pw.Length);
            }
            PacketWriter.ReleaseContent(pw);
        }
Exemplo n.º 6
0
        public void SpriteLeave(NetState netstate, System.Int32[] spriteId)
        {
            var           pw            = PacketWriter.AcquireContent(1104);
            PacketProfile packetProfile = PacketProfile.GetOutgoingProfile(1104);

            if (packetProfile != null)
            {
                packetProfile.RegConstruct();
            }
            int spriteIdlen = spriteId == null ? 0:spriteId.Length; pw.Write(spriteIdlen);

            for (int i = 0; i < spriteIdlen; i++)
            {
                pw.Write(spriteId[i]);
            }
            netstate.Send(pw);
            if (packetProfile != null)
            {
                packetProfile.Record(pw.Length);
            }
            PacketWriter.ReleaseContent(pw);
        }
Exemplo n.º 7
0
        public void SpriteEnter(NetState netstate, TradeAge.Server.Entity.Character.SceneSprite[] sprite)
        {
            var           pw            = PacketWriter.AcquireContent(1102);
            PacketProfile packetProfile = PacketProfile.GetOutgoingProfile(1102);

            if (packetProfile != null)
            {
                packetProfile.RegConstruct();
            }
            int spritelen = sprite == null ? 0:sprite.Length; pw.Write(spritelen);

            for (int i = 0; i < spritelen; i++)
            {
                SceneSpriteWriteProxy.Write(sprite[i], pw);
            }
            netstate.Send(pw);
            if (packetProfile != null)
            {
                packetProfile.Record(pw.Length);
            }
            PacketWriter.ReleaseContent(pw);
        }
Exemplo n.º 8
0
        public void SpriteMove(NetState netstate, int spriteId, DateTime time, DogSE.Library.Maths.Vector3 postion, DogSE.Library.Maths.Quaternion rotation, float speed, float rotationRate, TradeAge.Server.Entity.Ship.SpeedUpTypes speedUpType)
        {
            var           pw            = PacketWriter.AcquireContent(1103);
            PacketProfile packetProfile = PacketProfile.GetOutgoingProfile(1103);

            if (packetProfile != null)
            {
                packetProfile.RegConstruct();
            }
            pw.Write(spriteId);
            pw.Write(time.Ticks);
            Vector3WriteProxy.Write(postion, pw);
            QuaternionWriteProxy.Write(rotation, pw);
            pw.Write(speed);
            pw.Write(rotationRate);
            pw.Write((byte)speedUpType);
            netstate.Send(pw);
            if (packetProfile != null)
            {
                packetProfile.Record(pw.Length);
            }
            PacketWriter.ReleaseContent(pw);
        }
Exemplo n.º 9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="netState"></param>
        internal static void MessagePump_ProcessReceive(object sender, NetStateEventArgs eventArgs)
        {
            LOGs.WriteLine(LogMessageType.MSG_HACK, "ProcessNet.MessagePump_ProcessReceive(...){0}", Thread.CurrentThread.Name);

            if (eventArgs.NetState == null)
            {
                Debug.WriteLine("ProcessNet.EventDelegateProcessReceive(...) - netState == null error!");
                return;
            }

            ReceiveQueue l_ReceiveQueueBuffer = eventArgs.NetState.ReceiveBuffer;

            if (l_ReceiveQueueBuffer == null)
            {
                Debug.WriteLine("ProcessNet.MessagePump_ProcessReceive(...) - byteQueueBuffer == null error!");
                return;
            }

            LOGs.WriteLine(LogMessageType.MSG_HACK, "ProcessNet.MessagePump_ProcessReceive(...)-Length={0},{1}", l_ReceiveQueueBuffer.Length, Thread.CurrentThread.Name);

            if (l_ReceiveQueueBuffer.Length < PACKAGE_HEAD)
            {
                                                              // 等待数据包的完整
                return;
            }

            long l_iReceiveBufferLength = l_ReceiveQueueBuffer.Length; // 隔段时间就会有数据过来,所以可以不用锁定的,锁定了也没用,很难保证多线程中处理了所有的数据

            while (l_iReceiveBufferLength >= PACKAGE_HEAD)
            {
                // ReceiveQueue内部已经有锁定
                long l_iPacketSize = l_ReceiveQueueBuffer.GetPacketLength();
                if (l_iPacketSize < PACKAGE_HEAD)
                {
                    Debug.WriteLine("ProcessNet.MessagePump_ProcessReceive(...) - iPacketSize <= 0 error!");

                    eventArgs.NetState.Dispose(); // 断开
                    return;
                }

                if (l_iReceiveBufferLength < l_iPacketSize)
                {
                                                              // 等待数据包的完整
                    break;
                }

                if (l_iPacketSize > BUFFER_SIZE)   // 数据包过大
                {
                    Debug.WriteLine("ProcessNet.MessagePump_ProcessReceive(...) - iPacketSize > BUFFER_SIZE error!");

                    eventArgs.NetState.Dispose(); // 断开
                    return;
                }

                // 获取空数据
                byte[] l_PacketBuffer = m_ProcessorBuffers.AcquireBuffer();

                // ReceiveQueue内部已经有锁定
                long l_iReturnPacketSize = l_ReceiveQueueBuffer.Dequeue(ref l_PacketBuffer, 0, l_iPacketSize);

                // 获取的数据不相同
                if (l_iReturnPacketSize != l_iPacketSize)
                {
                    Debug.WriteLine("ProcessNet.MessagePump_ProcessReceive(...) - iReturnPacketSize != iPacketSize error!");

                    // 返回内存池
                    m_ProcessorBuffers.ReleaseBuffer(l_PacketBuffer);

                    eventArgs.NetState.Dispose(); // 断开
                    return;
                }

                //////////////////////////////////////////////////////////////////////////
                using (StreamWriter streamWriter = new StreamWriter("PreIn_Packets.log", true))
                {
                    byte[] byteBuffer = l_PacketBuffer;

                    if (byteBuffer.Length > 0)
                    {
                        streamWriter.WriteLine("客户端:  {0}  未经解密过的信息包 长度 = 0x{1:X4} ID = Unknown", eventArgs.NetState, l_iPacketSize);
                        streamWriter.WriteLine("--------------------------------------------------------------------------");
                    }

                    using (MemoryStream memoryStream = new MemoryStream(byteBuffer))
                        Utility.FormatBuffer(streamWriter, memoryStream, l_iPacketSize);

                    streamWriter.WriteLine();
                    streamWriter.WriteLine();
                }
                //////////////////////////////////////////////////////////////////////////

                try
                {
                    // 解密数据包
                    ROSECrypt.CryptPacket(ref l_PacketBuffer, eventArgs.NetState.EncoderSeed);
                }
                catch
                {
                    Debug.WriteLine("ProcessNet.MessagePump_ProcessReceive(...) - ROSECrypt.CryptPacket(...) Exception error!");

                    // 返回内存池
                    m_ProcessorBuffers.ReleaseBuffer(l_PacketBuffer);

                    eventArgs.NetState.Dispose(); // 断开
                    return;
                }

                // 读取的数据包
                PacketReader l_PacketReader = new PacketReader(l_PacketBuffer, l_iPacketSize, PACKAGE_HEAD /*包的长度大小-2个字节、ID大小-2个字节、未用数据大小-2个字节, 6个字节跳过*/);

                //////////////////////////////////////////////////////////////////////////
                using (StreamWriter streamWriter = new StreamWriter("In_Packets.log", true))
                {
                    byte[] byteBuffer = l_PacketBuffer;

                    if (byteBuffer.Length > 0)
                    {
                        streamWriter.WriteLine("客户端:  {0}  经解密过的信息包 长度 = 0x{1:X4} ID = 0x{2:X4}", eventArgs.NetState, l_iPacketSize, l_PacketReader.GetPacketID());
                        streamWriter.WriteLine("--------------------------------------------------------------------------");
                    }

                    using (MemoryStream memoryStream = new MemoryStream(byteBuffer))
                        Utility.FormatBuffer(streamWriter, memoryStream, l_iPacketSize);

                    streamWriter.WriteLine();
                    streamWriter.WriteLine();
                }
                //////////////////////////////////////////////////////////////////////////

                // 获取数据包命令的ID
                long l_iPacketID = l_PacketReader.GetPacketID();

                LOGs.WriteLine(LogMessageType.MSG_HACK, "ProcessNet.MessagePump_ProcessReceive(...)-Packet ID = 0x{0:X4}", l_iPacketID);

                // 获取处理数据包的实例
                PacketHandler l_PacketHandler = PacketHandlers.GetHandler(l_iPacketID);
                if (l_PacketHandler == null)   // 说明还没有解开当前的数据包内容
                {
                    l_PacketReader.Trace(eventArgs.NetState);

                    // 返回内存池
                    m_ProcessorBuffers.ReleaseBuffer(l_PacketBuffer);

                    // 获取剩下的数据长度
                    l_iReceiveBufferLength = l_ReceiveQueueBuffer.Length;

                    continue;
                }

                // 当前需处理的数据包的大小
                long l_iPacketHandlerLength = l_PacketHandler.Length;
                if (l_iPacketHandlerLength > l_iReturnPacketSize)   // 包需求的数据大小大于得到的数据大小
                {
                    // 返回内存池
                    m_ProcessorBuffers.ReleaseBuffer(l_PacketBuffer);

                    eventArgs.NetState.Dispose(); // 断开
                    return;
                }

                PacketProfile l_PacketProfile = PacketProfile.GetIncomingProfile(l_iPacketID);
                DateTime      dateTimeStart   = (l_PacketProfile == null ? DateTime.MinValue : DateTime.Now);
                {
                    l_PacketHandler.OnReceive(eventArgs.NetState, l_PacketReader);
                }
                if (l_PacketProfile != null)
                {
                    l_PacketProfile.Record(l_iPacketHandlerLength, DateTime.Now - dateTimeStart);
                }

                // 返回内存池
                m_ProcessorBuffers.ReleaseBuffer(l_PacketBuffer);

                // 获取剩下的数据长度
                l_iReceiveBufferLength = l_ReceiveQueueBuffer.Length;
            }
        }