Exemple #1
0
        /// <summary>
        /// Returns a BufferSegment that is at least of the given size.
        /// </summary>
        /// <param name="payloadSize"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentOutOfRangeException">In case that the payload exceeds the SegmentSize of the largest buffer available.</exception>
        public static BufferSegment GetSegment(int payloadSize)
        {
            if (payloadSize <= Tiny.SegmentSize)
            {
                return(Tiny.CheckOut());
            }
            if (payloadSize <= Small.SegmentSize)
            {
                return(Small.CheckOut());
            }
            if (payloadSize <= Default.SegmentSize)
            {
                return(Default.CheckOut());
            }
            if (payloadSize <= Large.SegmentSize)
            {
                return(Large.CheckOut());
            }
            if (payloadSize <= ExtraLarge.SegmentSize)
            {
                return(ExtraLarge.CheckOut());
            }

            throw new ArgumentOutOfRangeException("Required buffer is way too big: " + payloadSize);
        }
Exemple #2
0
		public void TestBufferManagerEtc()
		{
			var mgr = new BufferManager(2, 128);

			var segment1 = mgr.CheckOut();	// 1st buffer
			Assert.AreEqual(1, mgr.AvailableSegmentsCount);

			var segment2 = mgr.CheckOut();	// 1st buffer
			Assert.AreEqual(1, mgr.TotalBufferCount);
			Assert.AreEqual(0, mgr.AvailableSegmentsCount);
			//Assert.AreEqual(2, segment2.Buffer.UsedSegmentCount);

			var segment3 = mgr.CheckOut(); // 2nd buffer
			Assert.AreEqual(2, mgr.TotalBufferCount);
			Assert.AreEqual(1, mgr.AvailableSegmentsCount);
			//Assert.AreEqual(1, segment3.Buffer.UsedSegmentCount);

			segment3.DecrementUsage();
			Assert.AreEqual(2, mgr.AvailableSegmentsCount);
			//Assert.AreEqual(0, segment3.Buffer.UsedSegmentCount);

			using (var outPacket = new RealmPacketOut(RealmServerOpCode.CMSG_ACCEPT_TRADE))
			{
				outPacket.Position = outPacket.HeaderSize;
				outPacket.Write(1);
				outPacket.WriteCString("abc");

				var inPacket = DisposableRealmPacketIn.CreateFromOutPacket(segment1, outPacket);
				Assert.AreEqual(1, inPacket.ReadInt32());
				Assert.AreEqual("abc", inPacket.ReadCString());
			}

			using (var outPacket = new RealmPacketOut(RealmServerOpCode.CMSG_ACCEPT_TRADE))
			{
				outPacket.Position = outPacket.HeaderSize;
				outPacket.WriteCString("def");
				outPacket.Write(2);

				var inPacket = DisposableRealmPacketIn.CreateFromOutPacket(segment2, outPacket);
				Assert.AreEqual("def", inPacket.ReadCString());
				Assert.AreEqual(2, inPacket.ReadInt32());
			}
		}
Exemple #3
0
 /// <summary>Default constructor</summary>
 /// <param name="server">The server this client is connected to.</param>
 protected ClientBase(ServerBase server)
 {
     _server        = server;
     _bufferSegment = Buffers.CheckOut();
 }
Exemple #4
0
		public void TestUpdatePacket()
		{
			var mgr = new BufferManager(2, 128);

			var segment1 = mgr.CheckOut();	// 1st buffer
			Assert.AreEqual(1, mgr.AvailableSegmentsCount);

			var segment2 = mgr.CheckOut();	// 1st buffer
			Assert.AreEqual(1, mgr.TotalBufferCount);
			Assert.AreEqual(0, mgr.AvailableSegmentsCount);
			//Assert.AreEqual(2, segment2.Buffer.UsedSegmentCount);

			var segment3 = mgr.CheckOut(); // 2nd buffer
			Assert.AreEqual(2, mgr.TotalBufferCount);
			Assert.AreEqual(1, mgr.AvailableSegmentsCount);
			//Assert.AreEqual(1, segment3.Buffer.UsedSegmentCount);

			segment3.DecrementUsage();
			Assert.AreEqual(2, mgr.AvailableSegmentsCount);
			//Assert.AreEqual(0, segment3.Buffer.UsedSegmentCount);

			//using (var outPacket = new UpdatePacket(segment2))
			using (var outPacket = new UpdatePacket(128))
			{
				Assert.AreEqual(outPacket.PacketId, (PacketId)RealmServerOpCode.SMSG_UPDATE_OBJECT);

				outPacket.Write(15);
				outPacket.WriteCString("abc");

				using (var inPacket = DisposableRealmPacketIn.CreateFromOutPacket(segment1, outPacket))
				{
					Assert.AreEqual(0, inPacket.ReadInt32());			//update count

					Assert.AreEqual(15, inPacket.ReadInt32());
					Assert.AreEqual("abc", inPacket.ReadCString());
				}

				outPacket.Reset();
				Assert.AreEqual(outPacket.PacketId, (PacketId)RealmServerOpCode.SMSG_UPDATE_OBJECT);

				outPacket.WriteCString("def");
				outPacket.WriteUShortBE(300);


				using (var inPacket = DisposableRealmPacketIn.CreateFromOutPacket(segment1, outPacket))
				{
					Assert.AreEqual(0, inPacket.ReadInt32());			//update count
					Assert.AreEqual((byte)0, inPacket.ReadByte());			//block count

					Assert.AreEqual("def", inPacket.ReadCString());
					Assert.AreEqual((ushort)300, inPacket.ReadUInt16BE());
				}
			}
		}
Exemple #5
0
		/// <summary>
		/// Returns a BufferSegment that is at least of the given size.
		/// </summary>
		/// <param name="payloadSize"></param>
		/// <returns></returns>
		/// <exception cref="ArgumentOutOfRangeException">In case that the payload exceeds the SegmentSize of the largest buffer available.</exception>
		public static BufferSegment GetSegment(int payloadSize)
		{
			if (payloadSize <= Tiny.SegmentSize)
			{
				return Tiny.CheckOut();
			}
			if (payloadSize <= Small.SegmentSize)
			{
				return Small.CheckOut();
			}
			if (payloadSize <= Default.SegmentSize)
			{
				return Default.CheckOut();
			}
			if (payloadSize <= Large.SegmentSize)
			{
				return Large.CheckOut();
			}
			if (payloadSize <= ExtraLarge.SegmentSize)
			{
				return ExtraLarge.CheckOut();
			}
            if (payloadSize <= ExtraLarge.SegmentSize)
            {
                return SuperSized.CheckOut();
            }
            else
            { 
                BufferManager MegaSized = new BufferManager(2, payloadSize);
                return MegaSized.CheckOut();
            }

			throw new ArgumentOutOfRangeException("Required buffer is way too big: " + payloadSize);
		}