예제 #1
0
        public static DisposableRealmPacketIn Create(PacketId opCode, byte[] outPacketContent, int contentOffset,
                                                     int contentLength, BufferSegment segment)
        {
            if (!Enum.IsDefined(typeof(RealmServerOpCode), (object)opCode.RawId))
            {
                throw new Exception("Packet had undefined Opcode: " + (object)opCode);
            }
            int num1   = contentLength > (int)short.MaxValue ? 7 : 6;
            int length = contentLength + num1;
            int num2   = length - (num1 - 4);

            if (num1 == 7)
            {
                segment.Buffer.Array[segment.Offset]     = (byte)(num2 >> 16 | 128);
                segment.Buffer.Array[segment.Offset + 1] = (byte)(num2 >> 8);
                segment.Buffer.Array[segment.Offset + 2] = (byte)num2;
                segment.Buffer.Array[segment.Offset + 3] = (byte)opCode.RawId;
                segment.Buffer.Array[segment.Offset + 4] = (byte)(opCode.RawId >> 8);
            }
            else
            {
                segment.Buffer.Array[segment.Offset]     = (byte)(num2 >> 8);
                segment.Buffer.Array[segment.Offset + 1] = (byte)num2;
                segment.Buffer.Array[segment.Offset + 2] = (byte)opCode.RawId;
                segment.Buffer.Array[segment.Offset + 3] = (byte)(opCode.RawId >> 8);
            }

            Array.Copy((Array)outPacketContent, contentOffset, (Array)segment.Buffer.Array, segment.Offset + num1,
                       contentLength);
            return(new DisposableRealmPacketIn(segment, 0, length, contentLength, (RealmServerOpCode)opCode.RawId));
        }
예제 #2
0
        /// <summary>
        /// Registers a packet handler delegate for a specific packet.
        /// </summary>
        /// <param name="packetId">the PacketID of the packet to register the handler for</param>
        /// <param name="fn">the handler delegate to register for the specified packet type</param>
        public void Register(PacketId packetId, Action <C, P> fn, bool isGamePacket, bool requiresLogin)
        {
            if (m_handlers[packetId.RawId] != null)
            {
                s_log.Debug(string.Format(Resources.HandlerAlreadyRegistered, packetId, m_handlers[packetId.RawId].Handler, fn));
            }

            m_handlers[packetId.RawId] = new PacketHandler <C, P>(fn, isGamePacket, requiresLogin);
        }
예제 #3
0
 public PacketHandler <C, P> this[PacketId packetId]
 {
     get
     {
         return(m_handlers[packetId.RawId]);
     }
     set
     {
         m_handlers[packetId.RawId] = value;
     }
 }
예제 #4
0
		/// <summary>
		/// Dumps the array to string form, using hexadecimal as the formatter
		/// </summary>
		/// <returns>hexadecimal representation of the data parsed</returns>
		public static string ToHex(PacketId packetId, byte[] arr, int start, int count)
		{
			var hexDump = new StringBuilder();

			hexDump.Append('\n');
			hexDump.Append("{SERVER} " + string.Format("Packet: ({0}) {1} PacketSize = {2}\n" +
													   "|------------------------------------------------|----------------|\n" +
													   "|00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F |0123456789ABCDEF|\n" +
													   "|------------------------------------------------|----------------|\n",
													   "0x" + ((short)packetId.RawId).ToString("X4"), packetId, count));

			int end = start + count;
			for (int i = start; i < end; i += 16)
			{
				var text = new StringBuilder();
				var hex = new StringBuilder();
				hex.Append("|");

				for (int j = 0; j < 16; j++)
				{
					if (j + i < end)
					{
						byte val = arr[j + i];
						hex.Append(arr[j + i].ToString("X2"));
						hex.Append(" ");
						if (val >= 32 && val <= 127)
						{
							text.Append((char)val);
						}
						else
						{
							text.Append(".");
						}
					}
					else
					{
						hex.Append("   ");
						text.Append(" ");
					}
				}
				hex.Append("|");
				hex.Append(text + "|");
				hex.Append('\n');
				hexDump.Append(hex.ToString());
			}

			hexDump.Append("-------------------------------------------------------------------");

			return hexDump.ToString();
		}
예제 #5
0
 /// <summary>
 /// Registers a packet handler delegate for a specific packet.
 /// </summary>
 /// <param name="packetId">the PacketID of the packet to register the handler for</param>
 /// <param name="fn">the handler delegate to register for the specified packet type</param>
 public void Register(PacketId packetId, Action <C, P> fn, bool isGamePacket, bool requiresLogin)
 {
     if (this.m_handlers[packetId.RawId] != null)
     {
         this.s_log.Debug(string.Format(WCell_Core.HandlerAlreadyRegistered, (object)packetId,
                                        (object)this.m_handlers[packetId.RawId].Handler, (object)fn));
     }
     if (fn != null)
     {
         this.m_handlers[packetId.RawId] = new PacketHandler <C, P>(fn, isGamePacket, requiresLogin);
     }
     else
     {
         this.m_handlers[packetId.RawId] = (PacketHandler <C, P>)null;
     }
 }
예제 #6
0
		public static DisposableRealmPacketIn Create(PacketId opCode, byte[] outPacketContent, int contentOffset, int contentLength,
			BufferSegment segment)
		{
#if DEBUG
			if (!Enum.IsDefined(typeof(RealmServerOpCode), opCode.RawId))
			{
				throw new Exception("Packet had undefined Opcode: " + opCode);
			}
#endif

			int headerSize = (contentLength > WCellDef.HEADER_CHANGE_THRESHOLD ? LARGE_PACKET_HEADER_SIZE : HEADER_SIZE);

			var totalLength = contentLength + headerSize;

			var packetSize = totalLength - (headerSize - 4);

			if (headerSize == LARGE_PACKET_HEADER_SIZE)
			{
				segment.Buffer.Array[segment.Offset] = (byte)((packetSize >> 16) | 0x80);
				segment.Buffer.Array[segment.Offset + 1] = (byte)(packetSize >> 8);
				segment.Buffer.Array[segment.Offset + 2] = (byte)packetSize;

				segment.Buffer.Array[segment.Offset + 3] = (byte)((int)opCode.RawId);
				segment.Buffer.Array[segment.Offset + 4] = (byte)(((int)opCode.RawId) >> 8);
			}
			else
			{
				segment.Buffer.Array[segment.Offset] = (byte)(packetSize >> 8);
				segment.Buffer.Array[segment.Offset + 1] = (byte)packetSize;

				segment.Buffer.Array[segment.Offset + 2] = (byte)((int)opCode.RawId);
				segment.Buffer.Array[segment.Offset + 3] = (byte)(((int)opCode.RawId) >> 8);
			}

			Array.Copy(outPacketContent, contentOffset, segment.Buffer.Array, segment.Offset + headerSize, contentLength);

			return new DisposableRealmPacketIn(segment, 0, totalLength,
																contentLength, (RealmServerOpCode)opCode.RawId);
		}
예제 #7
0
        public static DisposableRealmPacketIn Create(PacketId opCode, byte[] outPacketContent, int contentOffset, int contentLength,
                                                     BufferSegment segment)
        {
#if DEBUG
            if (!Enum.IsDefined(typeof(RealmServerOpCode), opCode.RawId))
            {
                throw new Exception("Packet had undefined Opcode: " + opCode);
            }
#endif

            int headerSize = (contentLength > WCellConstants.HEADER_CHANGE_THRESHOLD ? LARGE_PACKET_HEADER_SIZE : HEADER_SIZE);

            var totalLength = contentLength + headerSize;

            var packetSize = totalLength - (headerSize - 4);

            if (headerSize == LARGE_PACKET_HEADER_SIZE)
            {
                segment.Buffer.Array[segment.Offset]     = (byte)((packetSize >> 16) | 0x80);
                segment.Buffer.Array[segment.Offset + 1] = (byte)(packetSize >> 8);
                segment.Buffer.Array[segment.Offset + 2] = (byte)packetSize;

                segment.Buffer.Array[segment.Offset + 3] = (byte)((int)opCode.RawId);
                segment.Buffer.Array[segment.Offset + 4] = (byte)(((int)opCode.RawId) >> 8);
            }
            else
            {
                segment.Buffer.Array[segment.Offset]     = (byte)(packetSize >> 8);
                segment.Buffer.Array[segment.Offset + 1] = (byte)packetSize;

                segment.Buffer.Array[segment.Offset + 2] = (byte)((int)opCode.RawId);
                segment.Buffer.Array[segment.Offset + 3] = (byte)(((int)opCode.RawId) >> 8);
            }

            Array.Copy(outPacketContent, contentOffset, segment.Buffer.Array, segment.Offset + headerSize, contentLength);

            return(new DisposableRealmPacketIn(segment, 0, totalLength,
                                               contentLength, (RealmServerOpCode)opCode.RawId));
        }
예제 #8
0
 public PacketDefinition(PacketId packetId, PacketSender sender, PacketSegmentStructure structure)
 {
     PacketIds = new[] { packetId };
     Sender = sender;
     Structure = structure ?? new ComplexPacketSegmentStructure();
 }
예제 #9
0
 public PacketDefinition(PacketId[] packetIds, PacketSender sender, List<PacketSegmentStructure> structure)
     : this(packetIds, sender, new ComplexPacketSegmentStructure(null, structure))
 {
 }
예제 #10
0
 public PacketDefinition(PacketId[] packetIds, PacketSender sender, params PacketSegmentStructure[] structure)
     : this(packetIds, sender, new ComplexPacketSegmentStructure(structure))
 {
 }
예제 #11
0
 public void SetPacketID(PacketId id)
 {
     _packetID = id;
 }
예제 #12
0
 /// <summary>
 /// Gets the PacketDefinition for the PacketId
 /// </summary>
 public static PacketDefinition GetDefinition(PacketId packetId, PacketSender sender)
 {
     return GetDefinition(PacketDefinitions[(uint)packetId.Service], packetId.RawId, sender);
 }
예제 #13
0
 /// <summary>Constructs an empty packet with the given packet ID.</summary>
 /// <param name="id">the ID of the packet</param>
 protected PacketOut(PacketId id)
     : base((Stream)BufferManager.Default.CheckOutStream())
 {
     this.m_id = id;
 }
예제 #14
0
		//public static void WriteHeader(byte[] buffer, int offset, int length, PacketId opcode)
		//{

		//}

		public RealmPacketOut(PacketId packetId)
			: this(packetId, 128)
		{
		}
예제 #15
0
 public RealmPacketOut(PacketId packetId, int maxContentLength)
     : base(packetId, maxContentLength + 4)
 {
     this.Position += 2L;
     this.Write((ushort)packetId.RawId);
 }
예제 #16
0
        public static DisposableRealmPacketIn Create(PacketId opCode, byte[] outPacketContent)
        {
            var segment = BufferManager.GetSegment(outPacketContent.Length + HEADER_SIZE);

            return(Create(opCode, outPacketContent, 0, outPacketContent.Length, segment));
        }
예제 #17
0
 /// <summary>
 /// Constructs an empty packet with an initial capacity of exactly or greater than the specified amount.
 /// </summary>
 /// <param name="id">the ID of the packet</param>
 /// <param name="maxCapacity">the minimum space required for the packet</param>
 protected PacketOut(PacketId id, int maxCapacity)
     : base(BufferManager.GetSegmentStream(maxCapacity))
     //: base(new MemoryStream(maxCapacity))
 {
     m_id = id;
 }
예제 #18
0
 /// <summary>
 /// Constructs an empty packet with the given packet ID.
 /// </summary>
 /// <param name="id">the ID of the packet</param>
 protected PacketOut(PacketId id)
     : base(BufferManager.Default.CheckOutStream())
     //: base(new MemoryStream())
 {
     m_id = id;
 }
예제 #19
0
		private static bool ValidateOpCode(PacketId packetId)
		{
			return packetId == RealmServerOpCode.SMSG_GAMEOBJECT_QUERY_RESPONSE;
		}
예제 #20
0
		public RealmPacketOut(PacketId packetId, int maxContentLength)
			: base(packetId, maxContentLength + HEADER_SIZE)
		{
			Position += 2;						// length
			Write((ushort)packetId.RawId);
		}
예제 #21
0
 public PacketHandlerAttribute(PacketId identifier)
 {
     this.Id            = identifier;
     this.IsGamePacket  = true;
     this.RequiresLogin = true;
 }
예제 #22
0
 public RealmPacketOut(PacketId packetId, int maxContentLength)
     : base(packetId, maxContentLength + HEADER_SIZE)
 {
     Position += 2;                                              // length
     Write((ushort)packetId.RawId);
 }
예제 #23
0
		public static DisposableRealmPacketIn Create(PacketId opCode, byte[] outPacketContent)
		{
			var segment = BufferManager.GetSegment(outPacketContent.Length + HEADER_SIZE);
			return Create(opCode, outPacketContent, 0, outPacketContent.Length, segment);
		}
예제 #24
0
		public PinnedRealmPacketIn(byte[] bytes, int offset, int length, ushort contentLength, PacketId packetId)
			: this(bytes, offset, length)
		{
			_payloadSize = contentLength;
			_packetID = packetId;
		}
예제 #25
0
        //public static void WriteHeader(byte[] buffer, int offset, int length, PacketId opcode)
        //{

        //}

        public RealmPacketOut(PacketId packetId)
            : this(packetId, 128)
        {
        }
예제 #26
0
        public void TestPacketManagementFunctions()
        {
            MemoryStream memStream = new MemoryStream();
            BinaryWriter bWriter = new BinaryWriter(memStream);

            byte[] firstTwentyBytes = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x01, 0x02, 0x03, 0x04, 0x05, 
                                                   0x01, 0x02, 0x03, 0x04, 0x05, 0x01, 0x02, 0x03, 0x04, 0x05 };
            byte[] lastThreeBytes = new byte[] { 0x09, 0x13, 0x41 };

            // we'll write 23 random bytes.
            bWriter.Write(firstTwentyBytes);
            bWriter.Write(lastThreeBytes);

			byte[] memStreamArr = memStream.ToArray();

			TestPacketIn packet = new TestPacketIn(memStreamArr);

            Assert.AreEqual((long)10, packet.Seek(10, SeekOrigin.Begin));

            Assert.AreEqual((long)20, packet.Seek(10, SeekOrigin.Current));

            Assert.AreEqual((long)23, packet.Seek(0, SeekOrigin.End));

            packet.Position = 0;

            Assert.AreEqual(0, packet.Position);

            packet.SkipBytes(9);

            Assert.AreEqual(9, packet.Position);

            PacketId serviceId = new PacketId(ServiceType.Authentication, 1);

            packet.SetPacketID(serviceId);

            Assert.AreEqual(serviceId, packet.PacketId);
        }
예제 #27
0
 /// <summary>Gets the name of the packet ID. (ie. CMSG_PING)</summary>
 /// <returns>a string containing the packet's canonical name</returns>
 public override string ToString()
 {
     return(PacketId.ToString());
 }
예제 #28
0
 public void Unregister(PacketId type)
 {
     m_handlers[type.RawId] = null;
 }
예제 #29
0
		public TestPacketOut(PacketId id, int capcity)
			: base(id, capcity)
		{
			Position += 2;
			WriteUShort(id.RawId);
		}
예제 #30
0
 public PacketHandlerAttribute(PacketId identifier)
 {
     Id            = identifier;
     IsGamePacket  = true;
     RequiresLogin = true;
 }
예제 #31
0
 public PacketDefinition(PacketId[] packetIds, PacketSender sender, PacketSegmentStructure structure)
 {
     PacketIds = packetIds;
     Sender = sender;
     Structure = structure ?? new ComplexPacketSegmentStructure();
 }
예제 #32
0
 public ClientPacketHandlerAttribute(PacketId identifier)
     : base(identifier)
 {
 }
예제 #33
0
 public PacketDefinition(PacketId packetId, PacketSender sender, params PacketSegmentStructure[] structure)
     : this(new[] { packetId }, sender, new ComplexPacketSegmentStructure(structure))
 {
 }
예제 #34
0
        public static DisposableRealmPacketIn Create(PacketId opCode, byte[] outPacketContent)
        {
            BufferSegment segment = BufferManager.GetSegment(outPacketContent.Length + 6);

            return(DisposableRealmPacketIn.Create(opCode, outPacketContent, 0, outPacketContent.Length, segment));
        }
예제 #35
0
 public PacketDefinition(PacketId packetId, PacketSender sender, List<PacketSegmentStructure> structure)
     : this(new[] { packetId }, sender, new ComplexPacketSegmentStructure(null, structure))
 {
 }
예제 #36
0
        public PacketHandlerAttribute(PacketId identifier)
        {
            Id = identifier;
            IsGamePacket = true;
			RequiresLogin = true;
        }
예제 #37
0
 public void Unregister(PacketId type)
 {
     this.m_handlers[type.RawId] = (PacketHandler <C, P>)null;
 }
예제 #38
0
        public ClientPacketHandlerAttribute(PacketId identifier)
			: base(identifier)
        {
        }
예제 #39
0
		private static bool CanDump(PacketId id)
		{
			return Dumps &&
				   IgnoredOpcodes.Where(filter =>
					   id.ToString().IndexOf(filter, StringComparison.InvariantCultureIgnoreCase) != -1).Count() == 0;
		}
예제 #40
0
 public static bool IsDefined(PacketId packetId, PacketSender sender)
 {
     return GetDefinition(PacketDefinitions[(uint)packetId.Service], packetId.RawId, sender) != null;
 }
예제 #41
0
 /// <summary>
 /// Constructs an empty packet with an initial capacity of exactly or greater than the specified amount.
 /// </summary>
 /// <param name="id">the ID of the packet</param>
 /// <param name="maxCapacity">the minimum space required for the packet</param>
 protected PacketOut(PacketId id, int maxCapacity)
     : base((Stream)BufferManager.GetSegmentStream(maxCapacity))
 {
     this.m_id = id;
 }
예제 #42
0
 public PinnedRealmPacketIn(byte[] bytes, int offset, int length, ushort contentLength, PacketId packetId)
     : this(bytes, offset, length)
 {
     _payloadSize = contentLength;
     _packetID    = packetId;
 }