Esempio n. 1
0
        /// <summary>
        /// Gets a <see cref="PacketWriter"/> to use from the internal pool. It is important that this
        /// <see cref="PacketWriter"/> is disposed of properly when done.
        /// </summary>
        /// <param name="id">The <see cref="ClientPacketID"/> that this <see cref="PacketWriter"/> will be writing.</param>
        /// <returns>The <see cref="PacketWriter"/> to use.</returns>
        public static PacketWriter GetWriter(ClientPacketID id)
        {
            var pw = _writerPool.Acquire();

            Debug.Assert(pw.LengthBits == 0);
            pw.Write(id);
            return(pw);
        }
Esempio n. 2
0
 void ProcessReceivedMessage(ClientState client, ClientPacketID id, byte[] message)
 {
     _handlers.TryGetValue(id, out var handler);
     if (handler != null)
     {
         handler.ProcessMessage(client, message);
     }
 }
Esempio n. 3
0
        public void SendNetMessage <T>(ClientPacketID id, T message, bool compress = false) where T : BaseMessage
        {
            var  body   = ZeroFormatterSerializer.Serialize(message);
            var  header = new PacketHeader((byte)id, compress, (ushort)body.Length);
            uint size   = 0;

            if (compress)
            {
                var compressedBody = CLZF2.Compress(body);
                header.ContentLength = (ushort)compressedBody.Length;
                _client.Send(NetworkUtils.CreateMessageBytes(header, compressedBody, out size));
            }
            else
            {
                _client.Send(NetworkUtils.CreateMessageBytes(header, body, out size));
            }
            _bytesSent += size;
            _packetsSent++;
        }
Esempio n. 4
0
 /// <summary>
 /// Gets a <see cref="PacketWriter"/> to use from the internal pool. It is important that this
 /// <see cref="PacketWriter"/> is disposed of properly when done.
 /// </summary>
 /// <param name="id">The <see cref="ClientPacketID"/> that this <see cref="PacketWriter"/> will be writing.</param>
 /// <returns>The <see cref="PacketWriter"/> to use.</returns>
 public static PacketWriter GetWriter(ClientPacketID id)
 {
     var pw = _writerPool.Acquire();
     Debug.Assert(pw.LengthBits == 0);
     pw.Write(id);
     return pw;
 }
Esempio n. 5
0
 /// <summary>
 /// Writes a <see cref="ClientPacketID"/> to the BitStream.
 /// </summary>
 /// <param name="bitStream">BitStream to write to.</param>
 /// <param name="clientPacketID">ClientPacketID to write.</param>
 public static void Write(this BitStream bitStream, ClientPacketID clientPacketID)
 {
     bitStream.Write((uint)clientPacketID, _clientPacketIDBits);
 }
Esempio n. 6
0
 /// <summary>
 /// Writes a <see cref="ClientPacketID"/> to the BitStream.
 /// </summary>
 /// <param name="bitStream">BitStream to write to.</param>
 /// <param name="clientPacketID">ClientPacketID to write.</param>
 public static void Write(this BitStream bitStream, ClientPacketID clientPacketID)
 {
     bitStream.Write((uint)clientPacketID, _clientPacketIDBits);
 }