Example #1
0
        public virtual void Send(Packet p)
        {
            if (mSocket == null || mBlockAllPackets)
            {
                ServerConsole.ErrorLine("{0}: Socket is null! Packet {1:X4} ({2} bytes) cant be send", this, p.PacketID, p.Length);
                // Wont send packet, but trigger OnSend to free data..
                p.OnSend(this);
                Dispose();
                return;
            }

            // Allow APIs to break sending
            if (p.OnBeforeSend(this) == false)
            {
                // Didnt send the packet, so let the APIs know that (2nd param, false)
                p.OnSend(this, false);
                return;
            }
            PacketSendProfile prof = PacketSendProfile.Acquire(p.GetType());

            int length = 0;

            byte[] buffer = p.Compile(out length);
            if (buffer == null)
            {
                ServerConsole.ErrorLine("{0}: null buffer send, disconnecting...", this);
                using (StreamWriter op = new StreamWriter("null_send.log", true)) {
                    op.WriteLine("{0} Client", "{1}: null buffer send, disconnecting...", DateTime.Now, this);
                    op.WriteLine(new System.Diagnostics.StackTrace());
                }
                Dispose();
                return;
            }

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

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

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

            try {
                ServerConsole.DebugLine("{0}: sending Packet 0x{1:X4} ({2} bytes)", this, p.PacketID, length);
                mSocket.BeginSend(buffer, 0, length, SocketFlags.None, mOnSend, mSocket);
            } catch (Exception ex) {
                ExceptionHandler.Trace(ex);
                Dispose(false);
            }

            p.OnSend(this);

            if (prof != null)
            {
                prof.Finish(length);
            }
        }
Example #2
0
		public virtual void Send(Packet p) {
			if (mSocket == null || mBlockAllPackets) {
				ServerConsole.ErrorLine("{0}: Socket is null! Packet {1:X4} ({2} bytes) cant be send", this, p.PacketID, p.Length);
				// Wont send packet, but trigger OnSend to free data..
				p.OnSend(this);
				Dispose();
				return;
			}

			// Allow APIs to break sending
			if (p.OnBeforeSend(this) == false) {
				// Didnt send the packet, so let the APIs know that (2nd param, false)
				p.OnSend(this, false);
				return;
			}
			PacketSendProfile prof = PacketSendProfile.Acquire(p.GetType());

			int length = 0;
			byte[] buffer = p.Compile(out length);
			if (buffer == null) {
				ServerConsole.ErrorLine("{0}: null buffer send, disconnecting...", this);
				using (StreamWriter op = new StreamWriter("null_send.log", true)) {
					op.WriteLine("{0} Client", "{1}: null buffer send, disconnecting...", DateTime.Now, this);
					op.WriteLine(new System.Diagnostics.StackTrace());
				}
				Dispose();
				return;
			}

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

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

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

			try {
				ServerConsole.DebugLine("{0}: sending Packet 0x{1:X4} ({2} bytes)", this, p.PacketID, length);
				mSocket.BeginSend(buffer, 0, length, SocketFlags.None, mOnSend, mSocket);
			} catch (Exception ex) {
				ExceptionHandler.Trace(ex);
				Dispose(false);
			}

			p.OnSend(this);

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