Ejemplo n.º 1
0
        public void TimerCallback(object state)
        {
            if (m_CounterDisplay != null)
            {
                DateTime lastTenSeconds = DateTime.Now - TimeSpan.FromSeconds(10.0);

                int sentPackets = 0, sentPacketsSize = 0;
                int recvPackets = 0, recvPacketsSize = 0;

                for (int i = m_Packets.Count - 1; i > 0; i--)
                {
                    TimePacket tPacket = (TimePacket)m_Packets[i];
                    if (tPacket.Time < lastTenSeconds)
                    {
                        break;
                    }

                    Packet packet = tPacket.Packet;
                    if (packet.Send)
                    {
                        sentPackets++;
                        sentPacketsSize += packet.Data.Length;
                    }
                    else
                    {
                        recvPackets++;
                        recvPacketsSize += packet.Data.Length;
                    }
                }

                m_CounterDisplay.DisplayCounter(sentPackets / 10, sentPacketsSize / 10, recvPackets / 10, recvPacketsSize / 10);
            }
        }
Ejemplo n.º 2
0
 private void OnPacket(TimePacket packet)
 {
     if (m_PacketFilter.Filter(packet))
     {
         AddPacket(packet);
     }
 }
Ejemplo n.º 3
0
		public bool Filter( TimePacket timePacket )
		{
			Packet packet = timePacket.Packet;

			byte cmd = packet.Cmd;
			if ( !m_Table[cmd] )
				return false;

			PacketProp[] props = packet.GetPacketProperties();
			if ( props != null )
			{
				string[] filterProps = m_PropsTable[cmd];
				bool[] mustHave = m_PropsHave[cmd];
				for ( int i = 0; i < props.Length; i++ )
				{
					if ( mustHave[i] )
					{
						if ( filterProps[i] != null && !FilterProp( filterProps[i], props[i].GetStringValue() ) )
							return false;
					}
					else
					{
						if ( filterProps[i] != null && FilterProp( filterProps[i], props[i].GetStringValue() ) )
							return false;
					}
				}
			}

			return true;
		}
Ejemplo n.º 4
0
        private void UpdateTables(TimePacket packet)
        {
            if (packet.Packet is WorldItem)
            {
                WorldItem item = (WorldItem)packet.Packet;
                m_Items[item.Serial] = packet.Packet;

                if (m_Books[item.Serial] != null)
                {
                    ((BookInfo)m_Books[item.Serial]).Item = item;
                }
            }
            else if (packet.Packet is BookHeader)
            {
                BookHeader header = (BookHeader)packet.Packet;

                if (m_Books[header.Serial] != null)
                {
                    BookInfo book = (BookInfo)m_Books[header.Serial];

                    book.Title    = header.Title;
                    book.Author   = header.Author;
                    book.Writable = header.Writable;

                    if (book.Lines.Length != header.PagesCount)
                    {
                        book.Lines = new string[header.PagesCount][];
                    }
                }
                else
                {
                    BookInfo book = new BookInfo(header.Serial, header.Title, header.Author, header.Writable, header.PagesCount);

                    if (m_Items[book.Serial] != null)
                    {
                        book.Item = (WorldItem)m_Items[book.Serial];
                    }

                    m_Books[book.Serial] = book;
                }
            }
            else if (packet.Packet is BookPageDetails)
            {
                BookPageDetails details = (BookPageDetails)packet.Packet;

                if (m_Books[details.Serial] != null)
                {
                    BookInfo book = (BookInfo)m_Books[details.Serial];

                    for (int i = 0; i < details.Pages.Length; i++)
                    {
                        if (!details.Pages[i].Request && details.Pages[i].Index - 1 < book.Lines.Length)
                        {
                            book.Lines[details.Pages[i].Index - 1] = details.Pages[i].Lines;
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
		public PacketListViewItem( TimePacket packet, DateTime baseTime, DateTime lastTime ) : base( GetPacketType( packet ) )
		{
			m_TimePacket = packet;

			SubItems.Add( GetMessage() );
			SubItems.Add( GetTime() );
			SubItems.Add( GetRelTime( baseTime ) );
			SubItems.Add( GetDifTime( lastTime ) );
			SubItems.Add( GetPacket() );
			SubItems.Add( GetASCII() );
			SubItems.Add( GetLength() );
		}
Ejemplo n.º 6
0
        public void SaveHex(StreamWriter writer)
        {
            writer.WriteLine("Logs created on {0} by SpyUO", DateTime.Now);
            writer.WriteLine();
            writer.WriteLine();

            foreach (PacketListViewItem item in lvPackets.Items)
            {
                TimePacket tPacket = item.TimePacket;
                Packet     packet  = tPacket.Packet;
                byte[]     data    = packet.Data;

                writer.WriteLine(" {0} - {1} (command: 0x{2:X}, length: 0x{3:X})",
                                 packet.Send ? "Send" : "Recv", tPacket.Time.ToString(@"H\:mm\:ss.ff"), packet.Cmd, data.Length);

                for (int l = 0; l < data.Length; l += 0x10)
                {
                    writer.Write("{0:X4}:", l);

                    for (int i = l; i < l + 0x10; i++)
                    {
                        writer.Write(" {0}", i < data.Length ? data[i].ToString("X2") : "--");
                    }

                    writer.Write("\t");

                    for (int i = l; i < l + 0x10; i++)
                    {
                        if (i >= data.Length)
                        {
                            break;
                        }

                        byte b = data[i];
                        char c;
                        if (b >= 0x20 && b < 0x80)
                        {
                            c = (char)b;
                        }
                        else
                        {
                            c = '.';
                        }

                        writer.Write(c);
                    }

                    writer.WriteLine();
                }

                writer.WriteLine();
            }
        }
Ejemplo n.º 7
0
        private void AddPacket(TimePacket packet)
        {
            PacketListViewItem item = new PacketListViewItem(packet, m_BaseTime, m_LastTime);

            lvPackets.Items.Add(item);
            if (m_AutoScrolling)
            {
                lvPackets.EnsureVisible(lvPackets.Items.Count - 1);
            }

            m_LastTime = packet.Time;
        }
Ejemplo n.º 8
0
        public PacketListViewItem(TimePacket packet, DateTime baseTime, DateTime lastTime) : base(GetPacketType(packet))
        {
            m_TimePacket = packet;

            SubItems.Add(GetMessage());
            SubItems.Add(GetTime());
            SubItems.Add(GetRelTime(baseTime));
            SubItems.Add(GetDifTime(lastTime));
            SubItems.Add(GetPacket());
            SubItems.Add(GetASCII());
            SubItems.Add(GetLength());
        }
Ejemplo n.º 9
0
        public void Add(TimePacketBuilder packetBuilder)
        {
            try
            {
                if (packetBuilder != null && packetBuilder.DataLength > 0)
                {
                    TimePacket packet = packetBuilder.ToTimePacket();

                    m_Packets.Add(packet);

                    UpdateTables(packet);
                }
            }
            catch { }
        }
Ejemplo n.º 10
0
        public void PacketPumpDequeue(PacketPump packetPump)
        {
            TimePacket packet = packetPump.Dequeue();

            if (packet != null)
            {
                m_Packets.Add(packet);

                UpdateTables(packet);

                if (OnPacket != null)
                {
                    OnPacket(packet);
                }
            }
        }
Ejemplo n.º 11
0
        public void LoadBin(BinaryReader reader)
        {
            int version = reader.ReadInt32();
            int count   = reader.ReadInt32();

            for (int i = 0; i < count; i++)
            {
                bool     send = reader.ReadBoolean();
                DateTime time = new DateTime(reader.ReadInt64());

                int    length = reader.ReadInt32();
                byte[] data   = reader.ReadBytes(length);

                Packet     packet  = Packet.Create(data, send);
                TimePacket tPacket = new TimePacket(packet, time);

                m_Packets.Add(tPacket);
                UpdateTables(tPacket);
            }
        }
Ejemplo n.º 12
0
        public bool Filter(TimePacket timePacket)
        {
            Packet packet = timePacket.Packet;

            byte cmd = packet.Cmd;

            if (!m_Table[cmd])
            {
                return(false);
            }

            PacketProp[] props = packet.GetPacketProperties();
            if (props != null)
            {
                string[] filterProps = m_PropsTable[cmd];
                bool[]   mustHave    = m_PropsHave[cmd];
                for (int i = 0; i < props.Length; i++)
                {
                    if (mustHave[i])
                    {
                        if (filterProps[i] != null && !FilterProp(filterProps[i], props[i].GetStringValue()))
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        if (filterProps[i] != null && FilterProp(filterProps[i], props[i].GetStringValue()))
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 13
0
        public static string GetPacketType(TimePacket timePacket)
        {
            Packet packet = timePacket.Packet;

            return(string.Format("{0} ({1:X2}) - {2}", packet.GetType().Name, packet.PacketID, packet.Send ? "Send" : "Receive"));
        }
Ejemplo n.º 14
0
		private void AddPacket( TimePacket packet )
		{
			PacketListViewItem item = new PacketListViewItem( packet, m_BaseTime, m_LastTime );

			lvPackets.Items.Add( item );
			if ( m_AutoScrolling )
				lvPackets.EnsureVisible( lvPackets.Items.Count - 1 );

			m_LastTime = packet.Time;
		}
Ejemplo n.º 15
0
		public void LoadBin( BinaryReader reader )
		{
			int version = reader.ReadInt32();

			Clear();

			int count = reader.ReadInt32();

			for ( int i = 0; i < count; i++ )
			{
				bool send = reader.ReadBoolean();
				DateTime time = new DateTime( reader.ReadInt64() );

				int length = reader.ReadInt32();
				byte[] data = reader.ReadBytes( length );

				Packet packet = Packet.Create( data, send );
				TimePacket tPacket = new TimePacket( packet, time );

				m_Packets.Add( tPacket );
				UpdateTables( tPacket );
			}
		}
Ejemplo n.º 16
0
		private void UpdateTables( TimePacket packet )
		{
			if ( packet.Packet is WorldItem )
			{
				WorldItem item = (WorldItem)packet.Packet;
				m_Items[item.Serial] = packet.Packet;

				if ( m_Books[item.Serial] != null )
				{
					((BookInfo)m_Books[item.Serial]).Item = item;
				}
			}
			else if ( packet.Packet is BookHeader )
			{
				BookHeader header = (BookHeader)packet.Packet;

				if ( m_Books[header.Serial] != null )
				{
					BookInfo book = (BookInfo)m_Books[header.Serial];

					book.Title = header.Title;
					book.Author = header.Author;
					book.Writable = header.Writable;

					if ( book.Lines.Length != header.PagesCount )
						book.Lines = new string[header.PagesCount][];
				}
				else
				{
					BookInfo book = new BookInfo( header.Serial, header.Title, header.Author, header.Writable, header.PagesCount );

					if ( m_Items[book.Serial] != null )
						book.Item = (WorldItem)m_Items[book.Serial];

					m_Books[book.Serial] = book;
				}
			}
			else if ( packet.Packet is BookPageDetails )
			{
				BookPageDetails details = (BookPageDetails)packet.Packet;

				if ( m_Books[details.Serial] != null )
				{
					BookInfo book = (BookInfo)m_Books[details.Serial];

					for ( int i = 0; i < details.Pages.Length; i++ )
					{
						if ( !details.Pages[i].Request && details.Pages[i].Index - 1 < book.Lines.Length )
						{
							book.Lines[details.Pages[i].Index - 1] = details.Pages[i].Lines;
						}
					}
				}
			}
		}
Ejemplo n.º 17
0
		private void OnPacket( TimePacket packet )
		{
			if ( m_PacketFilter.Filter( packet ) )
				AddPacket( packet );
		}
Ejemplo n.º 18
0
		public static string GetPacketType( TimePacket timePacket )
		{
			Packet packet = timePacket.Packet;

			return string.Format( "{0} ({1:X2}) - {2}", packet.GetType().Name, packet.Cmd, packet.Send ? "Send" : "Receive" );
		}
Ejemplo n.º 19
0
        public bool Filter(TimePacket timePacket)
        {
            Packet packet = timePacket.Packet;
            byte   id     = packet.PacketID;
            ushort com    = 0;

            if (id == 0xBF)
            {
                com = packet.Command;

                if (com < 0x100 && !m_CommandTable[com])
                {
                    return(false);
                }
            }
            else if (!m_Table[id])
            {
                return(false);
            }

            PacketProp[] props = packet.GetPacketProperties();

            if (props != null)
            {
                string[] filterProps = null;
                bool[]   mustHave    = null;

                if (id == 0xBF)
                {
                    if (com < 0x100)
                    {
                        filterProps = m_CommandPropsTable[com];
                        mustHave    = m_CommandPropsHave[com];
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    filterProps = m_PropsTable[id];
                    mustHave    = m_PropsHave[id];
                }

                for (int i = 0; i < props.Length; i++)
                {
                    if (mustHave[i])
                    {
                        if (filterProps[i] != null && !FilterProp(filterProps[i], props[i].GetStringValue()))
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        if (filterProps[i] != null && FilterProp(filterProps[i], props[i].GetStringValue()))
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }