Пример #1
0
        public void Send(Packet packet)
        {
            if (packet == null)
            {
                throw new ArgumentNullException("packet");
            }
            if (Playback.Active && !(packet is PPing))
            {
                return;
            }
            if (!(packet is PUseRequest))
            {
                if (!(packet is PPickupItem))
                {
                    goto label_6;
                }
            }
            Engine.PushAction();
label_6:
            try
            {
                byte[] buffer = packet.Compile();
                if (buffer.Length <= 0)
                {
                    return;
                }
                if (this._networkDiagnostics != null)
                {
                    for (int index = 0; index < this._networkDiagnostics.Count; ++index)
                    {
                        this._networkDiagnostics[index].PacketSent(packet, buffer, 0, buffer.Length);
                    }
                }
                if (packet.Encode)
                {
                    this._crypto.Encrypt(buffer, 0, buffer.Length, (IConsolidator)this._outputQueue);
                }
                else
                {
                    this._outputQueue.Enqueue(buffer, 0, buffer.Length);
                }
                OutputQueue.Gram gram = this._outputQueue.Query();
                if (gram == null)
                {
                    return;
                }
                this.Dispatch(gram);
            }
            catch (Exception ex)
            {
                this.HandleError(ex);
            }
            finally
            {
                packet.Dispose();
            }
        }
Пример #2
0
 public void Flush()
 {
     OutputQueue.Gram gram = this._outputQueue.Flush();
     if (gram == null)
     {
         return;
     }
     this.Dispatch(gram);
 }
Пример #3
0
 public static OutputQueue.Gram Acquire(IBufferPolicy bufferPolicy)
 {
     lock (OutputQueue.Gram._pool)
     {
         OutputQueue.Gram local_0 = OutputQueue.Gram._pool.Count <= 0 ? new OutputQueue.Gram() : OutputQueue.Gram._pool.Pop();
         local_0._bufferPolicy = bufferPolicy;
         local_0._buffer       = bufferPolicy.Acquire();
         local_0._length       = 0;
         return(local_0);
     }
 }
Пример #4
0
 public OutputQueue.Gram Query()
 {
     lock (this._syncRoot)
     {
         OutputQueue.Gram local_0 = (OutputQueue.Gram)null;
         if (this._pending.Count > 0 && !this._isWorking)
         {
             local_0         = this._pending.Peek();
             this._isWorking = true;
         }
         return(local_0);
     }
 }
Пример #5
0
 private void Dispatch(OutputQueue.Gram gram)
 {
     if (!this._isOpen)
     {
         return;
     }
     try
     {
         this._socket.BeginSend(gram.Buffer, 0, gram.Length, SocketFlags.None, this._sendCallback, (object)null);
     }
     catch (Exception ex)
     {
         this.HandleError(ex);
     }
 }
Пример #6
0
 public void Clear()
 {
     lock (this._syncRoot)
     {
         if (this._buffered != null)
         {
             this._buffered.Release();
             this._buffered = (OutputQueue.Gram)null;
         }
         while (this._pending.Count > 0)
         {
             this._pending.Dequeue().Release();
         }
         this._isWorking = false;
     }
 }
Пример #7
0
 public OutputQueue.Gram Flush()
 {
     lock (this._syncRoot)
     {
         OutputQueue.Gram local_0 = (OutputQueue.Gram)null;
         if (this._buffered != null)
         {
             if (this._pending.Count == 0)
             {
                 local_0 = this._buffered;
             }
             this._pending.Enqueue(this._buffered);
             this._buffered = (OutputQueue.Gram)null;
         }
         this._isWorking = local_0 != null;
         return(local_0);
     }
 }
Пример #8
0
 private void OnSend(IAsyncResult asyncResult)
 {
     try
     {
         if (this._socket.EndSend(asyncResult) > 0)
         {
             OutputQueue.Gram gram = this._outputQueue.Proceed();
             if (gram == null)
             {
                 return;
             }
             this.Dispatch(gram);
         }
         else
         {
             this.GracefulShutdown();
         }
     }
     catch (Exception ex)
     {
         this.HandleError(ex);
     }
 }
Пример #9
0
 public void Enqueue(byte[] buffer, int offset, int length)
 {
     if (buffer == null)
     {
         throw new ArgumentNullException("buffer");
     }
     if (offset < 0 || offset >= buffer.Length)
     {
         throw new ArgumentOutOfRangeException("offset", (object)offset, "Offset must be greater than or equal to zero and less than the size of the buffer.");
     }
     if (length < 0 || length > buffer.Length)
     {
         throw new ArgumentOutOfRangeException("length", (object)length, "Length cannot be less than zero or greater than the size of the buffer.");
     }
     if (buffer.Length - offset < length)
     {
         throw new ArgumentException("Offset and length do not point to a valid segment within the buffer.");
     }
     lock (this._syncRoot)
     {
         while (length > 0)
         {
             if (this._buffered == null)
             {
                 this._buffered = OutputQueue.Gram.Acquire(this._bufferPolicy);
             }
             int local_0 = this._buffered.Write(buffer, offset, length);
             offset += local_0;
             length -= local_0;
             if (this._buffered.IsFull)
             {
                 this._pending.Enqueue(this._buffered);
                 this._buffered = (OutputQueue.Gram)null;
             }
         }
     }
 }
Пример #10
0
 public OutputQueue.Gram Proceed()
 {
     lock (this._syncRoot)
     {
         OutputQueue.Gram local_0 = (OutputQueue.Gram)null;
         if (this._pending.Count > 0)
         {
             this._pending.Dequeue().Release();
             if (this._pending.Count > 0)
             {
                 local_0 = this._pending.Peek();
             }
             else
             {
                 this._isWorking = false;
             }
         }
         else
         {
             this._isWorking = false;
         }
         return(local_0);
     }
 }