Beispiel #1
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();
        }
Beispiel #2
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();
        }
Beispiel #3
0
        private static void HandleComm( Buffer *inBuff, Buffer *outBuff, Queue queue, PacketPath path )
        {
            CommMutex.WaitOne();
            while ( inBuff->Length > 0 )
            {
                byte *buff = (&inBuff->Buff0) + inBuff->Start;

                int len = 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, IsDynLength( buff[0] ) );
                    if ( filter )
                        p = MakePacketFrom( pr );
                }
                else if ( filter )
                {
                    byte[] temp = new byte[len];
                    fixed ( byte *ptr = temp )
                        memcpy( ptr, buff, len );
                    p = new Packet( temp, len, IsDynLength( buff[0] ) );
                }

                bool blocked = false;
                switch ( path )
                {
                        // yes it should be this way
                    case PacketPath.ClientToServer:
                    {
                        blocked = !PacketPlayer.ClientPacket( p );
                        if ( !blocked )
                            blocked = PacketHandler.OnClientPacket( buff[0], pr, p );
                        break;
                    }
                    case PacketPath.ServerToClient:
                    {
                        if ( !PacketPlayer.Playing )
                        {
                            blocked = PacketHandler.OnServerPacket( buff[0], pr, p );
                        }
                        else
                        {
                            blocked = true;
                            if ( p != null && p.PacketID == 0x1C )
                            {
                                // 0, 1, 2
                                Serial serial = p.ReadUInt32(); // 3, 4, 5, 6
                                ushort body = p.ReadUInt16(); // 7, 8
                                MessageType type = (MessageType)p.ReadByte(); // 9
                                ushort hue = p.ReadUInt16(); // 10, 11
                                ushort font = p.ReadUInt16();
                                string name = p.ReadStringSafe( 30 );
                                string text = p.ReadStringSafe();

                                if ( World.Player != null && serial == Serial.Zero && body == 0 && type == MessageType.Regular && hue == 0xFFFF && font == 0xFFFF && name == "SYSTEM" )
                                {
                                    p.Seek( 3, SeekOrigin.Begin );
                                    p.WriteAsciiFixed( "", (int)p.Length-3 );

                                    // CHEAT UO.exe 1/2 251--
                                    // 1 = 2d
                                    // 2 = 3d!

                                    DoFeatures( World.Player.Features );
                                }
                            }
                        }

                        if ( !blocked )
                            blocked = !PacketPlayer.ServerPacket( 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 );
                }

                if ( !PacketPlayer.Playing )
                {
                    while ( queue.Count > 0 )
                    {
                        p = (Packet)queue.Dequeue();
                        if ( PacketPlayer.Recording )
                        {
                            switch ( path )
                            {
                                case PacketPath.ClientToServer:
                                    PacketPlayer.ClientPacket( p );
                                    break;
                                case PacketPath.ServerToClient:
                                    PacketPlayer.ServerPacket( p );
                                    break;
                            }
                        }

                        byte[] data = p.Compile();
                        fixed ( byte *ptr = data )
                        {
                            CopyToBuffer( outBuff, ptr, data.Length );
                            Packet.Log( (PacketPath)(((int)path)+1), ptr, data.Length );
                        }
                    }
                }
                else
                {
                    queue.Clear();
                }
            }
            CommMutex.ReleaseMutex();
        }
Beispiel #4
0
 public static unsafe void Log(PacketPath path, byte *buff, int len)
 {
     Log(path, buff, len, false);
 }
Beispiel #5
0
        public static unsafe void Log(PacketPath path, byte *buff, int len, bool blocked)

        {
            if (!m_Logging)
            {
                return;
            }



            try

            {
                using (StreamWriter sw = new StreamWriter(PacketsLogFile, true))

                {
                    sw.AutoFlush = true;



                    string pathStr;

                    switch (path)

                    {
                    case PacketPath.ClientToServer:

                        pathStr = "Client -> Server";

                        break;

                    case PacketPath.RazorToServer:

                        pathStr = "Razor -> Server";

                        break;

                    case PacketPath.ServerToClient:

                        pathStr = "Server -> Client";

                        break;

                    case PacketPath.RazorToClient:

                        pathStr = "Razor -> Client";

                        break;

                    case PacketPath.PacketVideo:

                        pathStr = "PacketVideo -> Client";

                        break;

                    default:

                        pathStr = "Unknown -> Unknown";

                        break;
                    }



                    //sw.WriteLine( "{0}: {1}{2}0x{3:X2} (Length: {4})", Engine.MistedDateTime.ToString( "HH:mm:ss.ffff" ), pathStr, blocked ? " [BLOCKED] " : " ", buff[0], len );

                    //if ( buff[0] != 0x80 && buff[0] != 0x91 )

                    // Utility.FormatBuffer( sw, buff, len );

                    //else

                    //	sw.WriteLine( "[Censored for Security Reasons]" );



                    sw.WriteLine();

                    sw.WriteLine();
                }
            }

            catch

            {
            }
        }