Ejemplo n.º 1
0
        private unsafe bool OnSend(ref byte[] data, ref int length)
        {
            m_Out += (uint)length;
            fixed(byte *ptr = data)
            {
                bool result = true;
                byte id     = data[0];

                PacketReader reader   = null;
                Packet       packet   = null;
                bool         isView   = PacketHandler.HasClientViewer(id);
                bool         isFilter = PacketHandler.HasClientFilter(id);

                if (isView)
                {
                    reader = new PacketReader(ptr, length, PacketsTable.IsDynLength(id));
                    result = !PacketHandler.OnClientPacket(id, reader, packet);
                }
                else if (isFilter)
                {
                    packet = new Packet(data, length, PacketsTable.IsDynLength(id));
                    result = !PacketHandler.OnClientPacket(id, reader, packet);

                    data   = packet.Compile();
                    length = (int)packet.Length;
                }

                return(result);
            }
        }
Ejemplo n.º 2
0
        private void HandleComm(Buffer *inBuff, Buffer *outBuff, Queue <Packet> queue, PacketPath path)
        {
            CommMutex.WaitOne();
            while (inBuff->Length > 0)
            {
                byte *buff = (&inBuff->Buff0) + inBuff->Start;

                short len = PacketsTable.GetPacketLength(buff, inBuff->Length);
                if (len > inBuff->Length || len <= 0)
                {
                    break;
                }

                inBuff->Start  += len;
                inBuff->Length -= len;

                bool viewer = false;
                bool filter = false;

                switch (path)
                {
                case PacketPath.ClientToServer:
                    viewer = PacketHandler.HasClientViewer(buff[0]);
                    filter = PacketHandler.HasClientFilter(buff[0]);
                    break;

                case PacketPath.ServerToClient:
                    viewer = PacketHandler.HasServerViewer(buff[0]);
                    filter = PacketHandler.HasServerFilter(buff[0]);
                    break;
                }

                Packet       p  = null;
                PacketReader pr = null;
                if (viewer)
                {
                    pr = new PacketReader(buff, len, PacketsTable.IsDynLength(buff[0]));
                    if (filter)
                    {
                        p = MakePacketFrom(pr);
                    }
                }
                else if (filter)
                {
                    byte[] temp = new byte[len];

                    fixed(byte *ptr = temp)
                    Platform.memcpy(ptr, buff, len);

                    p = new Packet(temp, len, PacketsTable.IsDynLength(buff[0]));
                }

                bool blocked = false;
                switch (path)
                {
                // yes it should be this way
                case PacketPath.ClientToServer:
                {
                    blocked = PacketHandler.OnClientPacket(buff[0], pr, p);
                    break;
                }

                case PacketPath.ServerToClient:
                {
                    blocked = PacketHandler.OnServerPacket(buff[0], pr, p);
                    break;
                }
                }

                if (filter)
                {
                    byte[] data = p.Compile();
                    fixed(byte *ptr = data)
                    {
                        Packet.Log(path, ptr, data.Length, blocked);
                        if (!blocked)
                        {
                            CopyToBuffer(outBuff, ptr, data.Length);
                        }
                    }
                }
                else
                {
                    Packet.Log(path, buff, len, blocked);
                    if (!blocked)
                    {
                        CopyToBuffer(outBuff, buff, len);
                    }
                }

                while (queue.Count > 0)
                {
                    p = (Packet)queue.Dequeue();
                    byte[] data = p.Compile();
                    fixed(byte *ptr = data)
                    {
                        CopyToBuffer(outBuff, ptr, data.Length);
                        Packet.Log((PacketPath)(((int)path) + 1), ptr, data.Length);
                    }
                }
            }

            CommMutex.ReleaseMutex();
        }
Ejemplo n.º 3
0
        private unsafe void HandleComm(Buffer *inBuff, Buffer *outBuff, ConcurrentQueue <Packet> queue, PacketPath path)
        {
            CommMutex.WaitOne();
            while (inBuff->Length > 0)
            {
                byte *buff = (&inBuff->Buff0) + inBuff->Start;

                int len = DLLImport.Razor.GetPacketLength(buff, inBuff->Length);
                if (len > inBuff->Length || len <= 0)
                {
                    break;
                }

                inBuff->Start  += len;
                inBuff->Length -= len;

                bool viewer = false;
                bool filter = false;

                switch (path)
                {
                case PacketPath.ClientToServer:
                    viewer = PacketHandler.HasClientViewer(buff[0]);
                    filter = PacketHandler.HasClientFilter(buff[0]);
                    break;

                case PacketPath.ServerToClient:
                    viewer = PacketHandler.HasServerViewer(buff[0]);
                    filter = PacketHandler.HasServerFilter(buff[0]);
                    break;
                }

                Packet       p  = null;
                PacketReader pr = null;
                if (viewer)
                {
                    pr = new PacketReader(buff, len, DLLImport.Razor.IsDynLength(buff[0]));
                    if (filter)
                    {
                        p = MakePacketFrom(pr);
                    }
                }
                else if (filter)
                {
                    byte[] temp = new byte[len];

                    fixed(byte *ptr = temp)
                    DLLImport.Win.memcpy(ptr, buff, len);

                    p = new Packet(temp, len, DLLImport.Razor.IsDynLength(buff[0]));

                    /*byte[] temp = new byte[len];
                     * fixed (byte* ptr = temp)
                     * {
                     *      IntPtr to = (IntPtr)ptr;
                     *      IntPtr from = (IntPtr)buff;
                     *      DLLImport.Win.memcpy(to, from, new UIntPtr((uint)len));
                     * }
                     * p = new Packet(temp, len, DLLImport.Razor.IsDynLength(buff[0]));
                     */
                }

                bool blocked = false;
                switch (path)
                {
                // yes it should be this way
                case PacketPath.ClientToServer:
                {
                    blocked = PacketHandler.OnClientPacket(buff[0], pr, p);
                    break;
                }

                case PacketPath.ServerToClient:
                {
                    blocked = PacketHandler.OnServerPacket(buff[0], pr, p);
                    break;
                }
                }


                if (filter)
                {
                    byte[] data = p.Compile();
                    if (data[0] == 0xc8 || data[0] == 0x73 || data[0] == 0xbf || data[0] == 0xdc)
                    {
                    }
                    else
                    {
                        //int something = len;
                        //Debug.WriteLine("Packet id 0x{0:X}", data[0]);
                    }

                    fixed(byte *ptr = data)
                    {
                        Packet.Log(path, ptr, data.Length, blocked);
                        if (!blocked)
                        {
                            CopyToBuffer(outBuff, ptr, data.Length);
                        }
                    }
                }
                else
                {
                    //Packet.Log(path, buff, len, blocked);
                    if (!blocked)
                    {
                        CopyToBuffer(outBuff, buff, len);
                    }
                }

                while (queue.Count > 0)
                {
                    if (!queue.TryDequeue(out p))
                    {
                        continue;
                    }

                    byte[] data = p.Compile();
                    fixed(byte *ptr = data)
                    {
                        CopyToBuffer(outBuff, ptr, data.Length);
                        //Packet.Log((PacketPath)(((int)path) + 1), ptr, data.Length);
                    }
                }
            }
            CommMutex.ReleaseMutex();
        }