예제 #1
0
 /// <summary>
 /// Copy all data from another packet and init private fields if any
 /// </summary>
 /// <param name="pak"></param>
 /// <returns>The target packet instance (this)</returns>
 public virtual Packet CopyFrom(Packet pak)
 {
     m_code      = pak.m_code;
     m_direction = pak.m_direction;
     m_time      = pak.m_time;
     m_protocol  = pak.m_protocol;
     SetLength(0);
     Position     = 0;
     pak.Position = 0;
     pak.WriteTo(this);
     return(this);
 }
        public static int ParseHeader(string line, out int code, out ePacketDirection dir, out ePacketProtocol prot, out TimeSpan time)
        {
            code = Convert.ToInt32(line.Substring(38, 4), 16);

            if (string.Compare(line, 1, "SEND", 0, 4, false) == 0)
                dir = ePacketDirection.ClientToServer;
            else if (string.Compare(line, 1, "RECV", 0, 4, false) == 0)
                dir = ePacketDirection.ServerToClient;
            else
                throw new Exception("unknown packet direction: "+line.Substring(1, 4));

            if (string.Compare(line, 6, "TCP", 0, 3, false) == 0)
                prot = ePacketProtocol.TCP;
            else if (string.Compare(line, 6, "UDP", 0, 3, false) == 0)
                prot = ePacketProtocol.UDP;
            else
                throw new Exception("unknown packet protocol: "+line.Substring(6, 3));

            int hours, minutes, seconds, milliseconds;
            if (Util.ParseDecFast(line, 16, 2, out hours)
                && Util.ParseDecFast(line, 19, 2, out minutes)
                && Util.ParseDecFast(line, 22, 2, out seconds)
                && Util.ParseDecFast(line, 25, 3, out milliseconds))
            {
                time = new TimeSpan(0, hours, minutes, seconds, milliseconds);
            }
            else
            {
                time = TimeSpan.Zero;
                return -1;
            }

            int pakSize;
            if (!Util.ParseDecFast(line, 48, line.Length - 49, out pakSize))
                return -1;

            return pakSize;
        }
예제 #3
0
        public static int ParseHeader(string line, out int code, out ePacketDirection dir, out ePacketProtocol prot, out TimeSpan time)
        {
            code = Convert.ToInt32(line.Substring(38, 4), 16);

            if (string.Compare(line, 1, "SEND", 0, 4, false) == 0)
            {
                dir = ePacketDirection.ClientToServer;
            }
            else if (string.Compare(line, 1, "RECV", 0, 4, false) == 0)
            {
                dir = ePacketDirection.ServerToClient;
            }
            else
            {
                throw new Exception("unknown packet direction: " + line.Substring(1, 4));
            }

            if (string.Compare(line, 6, "TCP", 0, 3, false) == 0)
            {
                prot = ePacketProtocol.TCP;
            }
            else if (string.Compare(line, 6, "UDP", 0, 3, false) == 0)
            {
                prot = ePacketProtocol.UDP;
            }
            else
            {
                throw new Exception("unknown packet protocol: " + line.Substring(6, 3));
            }

            int hours, minutes, seconds, milliseconds;

            if (Util.ParseDecFast(line, 16, 2, out hours) &&
                Util.ParseDecFast(line, 19, 2, out minutes) &&
                Util.ParseDecFast(line, 22, 2, out seconds) &&
                Util.ParseDecFast(line, 25, 3, out milliseconds))
            {
                time = new TimeSpan(0, hours, minutes, seconds, milliseconds);
            }
            else
            {
                time = TimeSpan.Zero;
                return(-1);
            }

            int pakSize;

            if (!Util.ParseDecFast(line, 48, line.Length - 49, out pakSize))
            {
                return(-1);
            }

            return(pakSize);
        }
예제 #4
0
		/// <summary>
		/// Copy all data from another packet and init private fields if any
		/// </summary>
		/// <param name="pak"></param>
		/// <returns>The target packet instance (this)</returns>
		public virtual Packet CopyFrom(Packet pak)
		{
			m_code = pak.m_code;
			m_direction = pak.m_direction;
			m_time = pak.m_time;
			m_protocol = pak.m_protocol;
			SetLength(0);
			Position = 0;
			pak.Position = 0;
			pak.WriteTo(this);
			return this;
		}