예제 #1
0
        public void Send(Peer peer, short opcode, ISerializablePacket packet)
        {
            if (peer == null || !peer.IsConnected)
            {
                return;
            }

            using (PooledNetWriter w = NetWriterPool.GetWriter())
            {
                MessageHelper.CreateAndFinalize(w, opcode, packet);
                var segment = w.ToArraySegment();
                if (NetLogFilter.messageDiagnostics)
                {
                    NetDiagnostics.OnSend(opcode, segment.Count, 1);
                }
                if (!isSimulated)
                {
                    peer.SendMessage(segment, UDPTransport.Source.Server);
                }
                else
                {
                    peer.SendSimulatedMessage(segment, UDPTransport.Source.Server);
                }
            }
        }
예제 #2
0
 public void Send(short opcode, ISerializablePacket packet)
 {
     using (PooledNetWriter w = NetWriterPool.GetWriter())
     {
         MessageHelper.CreateAndFinalize(w, opcode, packet);
         var segment = w.ToArraySegment();
         if (NetLogFilter.messageDiagnostics)
         {
             NetDiagnostics.OnSend(opcode, segment.Count, connectedPeers.Values.Count);
         }
         if (!isSimulated)
         {
             foreach (var peer in connectedPeers.Values)
             {
                 peer.SendMessage(segment, UDPTransport.Source.Server);
             }
         }
         else
         {
             foreach (var peer in connectedPeers.Values)
             {
                 peer.SendSimulatedMessage(segment, UDPTransport.Source.Server);
             }
         }
     }
 }
예제 #3
0
        public static PooledNetWriter GetWriter()
        {
            if (pool.Count != 0)
            {
                PooledNetWriter writer = pool.Pop();
                // reset cached writer length and position
                writer.SetLength(0);
                return writer;
            }

            return new PooledNetWriter();
        }
예제 #4
0
        /// <summary>
        ///     Sends a message to server.
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="qos"></param>
        public void Send(short opcode, ISerializablePacket packet)/* OutgoingMessage msg)*/
        {
            if (!IsConnected)
            {
                return;
            }

            using (PooledNetWriter w = NetWriterPool.GetWriter())
            {
                MessageHelper.CreateAndFinalize(w, opcode, packet);
                var segment = w.ToArraySegment();
                if (NetLogFilter.messageDiagnostics)
                {
                    NetDiagnostics.OnSend(opcode, segment.Count, 1);
                }
                Send(segment);
            }
        }
예제 #5
0
 public static void Recycle(PooledNetWriter writer)
 {
     pool.Push(writer);
 }