Пример #1
0
		public static void Release(Packet p) {
			if (p != null)
				p.Release();
		}
Пример #2
0
		public static void Release(ref Packet p) {
			if (p != null)
				p.Release();

			p = null;
		}
Пример #3
0
		public static Packet SetStatic(Packet p) {
			p.SetStatic();
			return p;
		}
Пример #4
0
		public static Packet Acquire(Packet p) {
			p.Acquire();
			return p;
		}
Пример #5
0
		public virtual void Send(Packet p) {
			if (mSocket == null || mBlockAllPackets) {
				p.OnSend();
				return;
			}

			PacketSendProfile prof = PacketSendProfile.Acquire(p.GetType());

			int length;
			byte[] buffer = p.Compile(out length);
			if (buffer == null) {
				CConsole.ErrorLine("{0}: null buffer send, disconnecting...", this);

				Dispose();
				return;
			}

			if (buffer.Length <= 0 || length <= 0) {
				p.OnSend();
				return;
			}

			if (prof != null) {
				prof.Start();
			}

			if (mEncoder != null) {
				mEncoder.EncodeOutgoingPacket(this, ref buffer, ref length);
			}

			try {
				Int16 pID = BitConverter.ToInt16(buffer, 0);
				CConsole.DebugLine("{0}: sending Packet 0x{1:X4}", this, pID);
				mSocket.BeginSend(buffer, 0, length, SocketFlags.None, mOnSend, mSocket);
			} catch (Exception ex) {
				Dispose(false);
				throw;
			}

			p.OnSend();

			if (prof != null) {
				prof.Finish(length);
			}
		}