You've already forked lidgren-network-gen3
mirror of
https://github.com/lidgren/lidgren-network-gen3.git
synced 2026-05-19 00:26:30 +09:00
XML comments added to remove all warnings; Documentation.chm updated
This commit is contained in:
Binary file not shown.
@@ -3,12 +3,19 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace Lidgren.Network
|
namespace Lidgren.Network
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interface for an encryption algorithm
|
||||||
|
/// </summary>
|
||||||
public interface INetEncryption
|
public interface INetEncryption
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Encrypt an outgoing message in place
|
||||||
|
/// </summary>
|
||||||
bool Encrypt(NetOutgoingMessage msg);
|
bool Encrypt(NetOutgoingMessage msg);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Decrypt an incoming message in place
|
||||||
|
/// </summary>
|
||||||
bool Decrypt(NetIncomingMessage msg);
|
bool Decrypt(NetIncomingMessage msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ namespace Lidgren.Network
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract int BlockSize { get; }
|
public abstract int BlockSize { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// NetBlockEncryptionBase constructor
|
||||||
|
/// </summary>
|
||||||
public NetBlockEncryptionBase()
|
public NetBlockEncryptionBase()
|
||||||
{
|
{
|
||||||
m_tmp = new byte[BlockSize];
|
m_tmp = new byte[BlockSize];
|
||||||
@@ -72,7 +75,14 @@ namespace Lidgren.Network
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Encrypt a block of bytes
|
||||||
|
/// </summary>
|
||||||
protected abstract void EncryptBlock(byte[] source, int sourceOffset, byte[] destination);
|
protected abstract void EncryptBlock(byte[] source, int sourceOffset, byte[] destination);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Decrypt a block of bytes
|
||||||
|
/// </summary>
|
||||||
protected abstract void DecryptBlock(byte[] source, int sourceOffset, byte[] destination);
|
protected abstract void DecryptBlock(byte[] source, int sourceOffset, byte[] destination);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,16 +11,25 @@ namespace Lidgren.Network
|
|||||||
{
|
{
|
||||||
private byte[] m_key;
|
private byte[] m_key;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// NetXorEncryption constructor
|
||||||
|
/// </summary>
|
||||||
public NetXorEncryption(byte[] key)
|
public NetXorEncryption(byte[] key)
|
||||||
{
|
{
|
||||||
m_key = key;
|
m_key = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// NetXorEncryption constructor
|
||||||
|
/// </summary>
|
||||||
public NetXorEncryption(string key)
|
public NetXorEncryption(string key)
|
||||||
{
|
{
|
||||||
m_key = Encoding.ASCII.GetBytes(key);
|
m_key = Encoding.ASCII.GetBytes(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Encrypt an outgoing message
|
||||||
|
/// </summary>
|
||||||
public bool Encrypt(NetOutgoingMessage msg)
|
public bool Encrypt(NetOutgoingMessage msg)
|
||||||
{
|
{
|
||||||
int numBytes = msg.LengthBytes;
|
int numBytes = msg.LengthBytes;
|
||||||
@@ -32,6 +41,9 @@ namespace Lidgren.Network
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Decrypt an incoming message
|
||||||
|
/// </summary>
|
||||||
public bool Decrypt(NetIncomingMessage msg)
|
public bool Decrypt(NetIncomingMessage msg)
|
||||||
{
|
{
|
||||||
int numBytes = msg.LengthBytes;
|
int numBytes = msg.LengthBytes;
|
||||||
|
|||||||
@@ -36,6 +36,9 @@ namespace Lidgren.Network
|
|||||||
private readonly uint[] m_sum0;
|
private readonly uint[] m_sum0;
|
||||||
private readonly uint[] m_sum1;
|
private readonly uint[] m_sum1;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the block size for this cipher
|
||||||
|
/// </summary>
|
||||||
public override int BlockSize { get { return c_blockSize; } }
|
public override int BlockSize { get { return c_blockSize; } }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -83,6 +86,9 @@ namespace Lidgren.Network
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Encrypts a block of bytes
|
||||||
|
/// </summary>
|
||||||
protected override void EncryptBlock(byte[] source, int sourceOffset, byte[] destination)
|
protected override void EncryptBlock(byte[] source, int sourceOffset, byte[] destination)
|
||||||
{
|
{
|
||||||
uint v0 = BytesToUInt(source, sourceOffset);
|
uint v0 = BytesToUInt(source, sourceOffset);
|
||||||
@@ -100,6 +106,9 @@ namespace Lidgren.Network
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Decrypts a block of bytes
|
||||||
|
/// </summary>
|
||||||
protected override void DecryptBlock(byte[] source, int sourceOffset, byte[] destination)
|
protected override void DecryptBlock(byte[] source, int sourceOffset, byte[] destination)
|
||||||
{
|
{
|
||||||
// Pack bytes into integers
|
// Pack bytes into integers
|
||||||
|
|||||||
@@ -36,6 +36,9 @@ namespace Lidgren.Network
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public int Capacity { get { return m_capacity; } }
|
public int Capacity { get { return m_capacity; } }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// NetBitVector constructor
|
||||||
|
/// </summary>
|
||||||
public NetBitVector(int bitsCapacity)
|
public NetBitVector(int bitsCapacity)
|
||||||
{
|
{
|
||||||
m_capacity = bitsCapacity;
|
m_capacity = bitsCapacity;
|
||||||
@@ -80,6 +83,9 @@ namespace Lidgren.Network
|
|||||||
m_data[lenMinusOne] = cur;
|
m_data[lenMinusOne] = cur;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the first (lowest) index set to true
|
||||||
|
/// </summary>
|
||||||
public int GetFirstSetIndex()
|
public int GetFirstSetIndex()
|
||||||
{
|
{
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
|
|||||||
@@ -169,6 +169,9 @@ namespace Lidgren.Network
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reads the specified number of bits into an UInt32
|
||||||
|
/// </summary>
|
||||||
[CLSCompliant(false)]
|
[CLSCompliant(false)]
|
||||||
#if UNSAFE
|
#if UNSAFE
|
||||||
public static unsafe uint ReadUInt32(byte[] fromBuffer, int numberOfBits, int readBitOffset)
|
public static unsafe uint ReadUInt32(byte[] fromBuffer, int numberOfBits, int readBitOffset)
|
||||||
@@ -183,6 +186,7 @@ namespace Lidgren.Network
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
||||||
public static uint ReadUInt32(byte[] fromBuffer, int numberOfBits, int readBitOffset)
|
public static uint ReadUInt32(byte[] fromBuffer, int numberOfBits, int readBitOffset)
|
||||||
{
|
{
|
||||||
NetException.Assert(((numberOfBits > 0) && (numberOfBits <= 32)), "ReadUInt32() can only read between 1 and 32 bits");
|
NetException.Assert(((numberOfBits > 0) && (numberOfBits <= 32)), "ReadUInt32() can only read between 1 and 32 bits");
|
||||||
@@ -234,6 +238,9 @@ namespace Lidgren.Network
|
|||||||
//[CLSCompliant(false)]
|
//[CLSCompliant(false)]
|
||||||
//public static ulong ReadUInt64(byte[] fromBuffer, int numberOfBits, int readBitOffset)
|
//public static ulong ReadUInt64(byte[] fromBuffer, int numberOfBits, int readBitOffset)
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes the specified number of bits into a byte array
|
||||||
|
/// </summary>
|
||||||
[CLSCompliant(false)]
|
[CLSCompliant(false)]
|
||||||
public static int WriteUInt32(uint source, int numberOfBits, byte[] destination, int destinationBitOffset)
|
public static int WriteUInt32(uint source, int numberOfBits, byte[] destination, int destinationBitOffset)
|
||||||
{
|
{
|
||||||
@@ -277,6 +284,9 @@ namespace Lidgren.Network
|
|||||||
return returnValue;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes the specified number of bits into a byte array
|
||||||
|
/// </summary>
|
||||||
[CLSCompliant(false)]
|
[CLSCompliant(false)]
|
||||||
public static int WriteUInt64(ulong source, int numberOfBits, byte[] destination, int destinationBitOffset)
|
public static int WriteUInt64(ulong source, int numberOfBits, byte[] destination, int destinationBitOffset)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -50,6 +50,9 @@ namespace Lidgren.Network
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the connection status of the server connection (or NetConnectionStatus.Disconnected if no connection)
|
||||||
|
/// </summary>
|
||||||
public NetConnectionStatus ConnectionStatus
|
public NetConnectionStatus ConnectionStatus
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -61,12 +64,22 @@ namespace Lidgren.Network
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// NetClient constructor
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="config"></param>
|
||||||
public NetClient(NetPeerConfiguration config)
|
public NetClient(NetPeerConfiguration config)
|
||||||
: base(config)
|
: base(config)
|
||||||
{
|
{
|
||||||
config.AcceptIncomingConnections = false;
|
config.AcceptIncomingConnections = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Connect to a remote server
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="remoteEndpoint">The remote endpoint to connect to</param>
|
||||||
|
/// <param name="hailMessage">The hail message to pass</param>
|
||||||
|
/// <returns>server connection, or null if already connected</returns>
|
||||||
public override NetConnection Connect(IPEndPoint remoteEndpoint, NetOutgoingMessage hailMessage)
|
public override NetConnection Connect(IPEndPoint remoteEndpoint, NetOutgoingMessage hailMessage)
|
||||||
{
|
{
|
||||||
lock (m_connections)
|
lock (m_connections)
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ namespace Lidgren.Network
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public float AverageRoundtripTime { get { return m_averageRoundtripTime; } }
|
public float AverageRoundtripTime { get { return m_averageRoundtripTime; } }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Time offset between this peer and the remote peer
|
||||||
|
/// </summary>
|
||||||
public float RemoteTimeOffset { get { return (float)m_remoteTimeOffset; } }
|
public float RemoteTimeOffset { get { return (float)m_remoteTimeOffset; } }
|
||||||
|
|
||||||
// this might happen more than once
|
// this might happen more than once
|
||||||
|
|||||||
@@ -28,21 +28,33 @@ namespace Lidgren.Network
|
|||||||
[Serializable]
|
[Serializable]
|
||||||
public sealed class NetException : Exception
|
public sealed class NetException : Exception
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// NetException constructor
|
||||||
|
/// </summary>
|
||||||
public NetException()
|
public NetException()
|
||||||
: base()
|
: base()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// NetException constructor
|
||||||
|
/// </summary>
|
||||||
public NetException(string message)
|
public NetException(string message)
|
||||||
: base(message)
|
: base(message)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// NetException constructor
|
||||||
|
/// </summary>
|
||||||
public NetException(string message, Exception inner)
|
public NetException(string message, Exception inner)
|
||||||
: base(message, inner)
|
: base(message, inner)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// NetException constructor
|
||||||
|
/// </summary>
|
||||||
private NetException(SerializationInfo info, StreamingContext context)
|
private NetException(SerializationInfo info, StreamingContext context)
|
||||||
: base(info, context)
|
: base(info, context)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -69,9 +69,9 @@ namespace Lidgren.Network
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
/// <summary>
|
||||||
// 1 bit
|
/// Reads a boolean value (stored as a single bit) written using Write(bool)
|
||||||
//
|
/// </summary>
|
||||||
public bool ReadBoolean()
|
public bool ReadBoolean()
|
||||||
{
|
{
|
||||||
NetException.Assert(m_bitLength - m_readPosition >= 1, c_readOverflowError);
|
NetException.Assert(m_bitLength - m_readPosition >= 1, c_readOverflowError);
|
||||||
@@ -80,9 +80,9 @@ namespace Lidgren.Network
|
|||||||
return (retval > 0 ? true : false);
|
return (retval > 0 ? true : false);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
/// <summary>
|
||||||
// 8 bit
|
/// Reads a byte
|
||||||
//
|
/// </summary>
|
||||||
public byte ReadByte()
|
public byte ReadByte()
|
||||||
{
|
{
|
||||||
NetException.Assert(m_bitLength - m_readPosition >= 8, c_readOverflowError);
|
NetException.Assert(m_bitLength - m_readPosition >= 8, c_readOverflowError);
|
||||||
@@ -91,7 +91,9 @@ namespace Lidgren.Network
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reads a signed byte
|
||||||
|
/// </summary>
|
||||||
[CLSCompliant(false)]
|
[CLSCompliant(false)]
|
||||||
public sbyte ReadSByte()
|
public sbyte ReadSByte()
|
||||||
{
|
{
|
||||||
@@ -101,13 +103,20 @@ namespace Lidgren.Network
|
|||||||
return (sbyte)retval;
|
return (sbyte)retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reads 1 to 8 bits into a byte
|
||||||
|
/// </summary>
|
||||||
public byte ReadByte(int numberOfBits)
|
public byte ReadByte(int numberOfBits)
|
||||||
{
|
{
|
||||||
|
NetException.Assert(numberOfBits > 0 && numberOfBits < 8);
|
||||||
byte retval = NetBitWriter.ReadByte(m_data, numberOfBits, m_readPosition);
|
byte retval = NetBitWriter.ReadByte(m_data, numberOfBits, m_readPosition);
|
||||||
m_readPosition += numberOfBits;
|
m_readPosition += numberOfBits;
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reads the specified number of bytes
|
||||||
|
/// </summary>
|
||||||
public byte[] ReadBytes(int numberOfBytes)
|
public byte[] ReadBytes(int numberOfBytes)
|
||||||
{
|
{
|
||||||
NetException.Assert(m_bitLength - m_readPosition + 7 >= (numberOfBytes * 8), c_readOverflowError);
|
NetException.Assert(m_bitLength - m_readPosition + 7 >= (numberOfBytes * 8), c_readOverflowError);
|
||||||
@@ -118,6 +127,12 @@ namespace Lidgren.Network
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reads the specified number of bytes into a preallocated array
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="into">The destination array</param>
|
||||||
|
/// <param name="offset">The offset where to start writing in the destination array</param>
|
||||||
|
/// <param name="numberOfBytes">The number of bytes to read</param>
|
||||||
public void ReadBytes(byte[] into, int offset, int numberOfBytes)
|
public void ReadBytes(byte[] into, int offset, int numberOfBytes)
|
||||||
{
|
{
|
||||||
NetException.Assert(m_bitLength - m_readPosition + 7 >= (numberOfBytes * 8), c_readOverflowError);
|
NetException.Assert(m_bitLength - m_readPosition + 7 >= (numberOfBytes * 8), c_readOverflowError);
|
||||||
@@ -128,6 +143,12 @@ namespace Lidgren.Network
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reads the specified number of bits into a preallocated array
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="into">The destination array</param>
|
||||||
|
/// <param name="offset">The offset where to start writing in the destination array</param>
|
||||||
|
/// <param name="numberOfBits">The number of bits to read</param>
|
||||||
public void ReadBits(byte[] into, int offset, int numberOfBits)
|
public void ReadBits(byte[] into, int offset, int numberOfBits)
|
||||||
{
|
{
|
||||||
NetException.Assert(m_bitLength - m_readPosition >= numberOfBits, c_readOverflowError);
|
NetException.Assert(m_bitLength - m_readPosition >= numberOfBits, c_readOverflowError);
|
||||||
@@ -145,9 +166,9 @@ namespace Lidgren.Network
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
/// <summary>
|
||||||
// 16 bit
|
/// Reads a 16 bit signed integer written using Write(Int16)
|
||||||
//
|
/// </summary>
|
||||||
public Int16 ReadInt16()
|
public Int16 ReadInt16()
|
||||||
{
|
{
|
||||||
NetException.Assert(m_bitLength - m_readPosition >= 16, c_readOverflowError);
|
NetException.Assert(m_bitLength - m_readPosition >= 16, c_readOverflowError);
|
||||||
@@ -156,6 +177,9 @@ namespace Lidgren.Network
|
|||||||
return (short)retval;
|
return (short)retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reads a 16 bit unsigned integer written using Write(UInt16)
|
||||||
|
/// </summary>
|
||||||
[CLSCompliant(false)]
|
[CLSCompliant(false)]
|
||||||
public UInt16 ReadUInt16()
|
public UInt16 ReadUInt16()
|
||||||
{
|
{
|
||||||
@@ -165,9 +189,9 @@ namespace Lidgren.Network
|
|||||||
return (ushort)retval;
|
return (ushort)retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
/// <summary>
|
||||||
// 32 bit
|
/// Reads a 32 bit signed integer written using Write(Int32)
|
||||||
//
|
/// </summary>
|
||||||
public Int32 ReadInt32()
|
public Int32 ReadInt32()
|
||||||
{
|
{
|
||||||
NetException.Assert(m_bitLength - m_readPosition >= 32, c_readOverflowError);
|
NetException.Assert(m_bitLength - m_readPosition >= 32, c_readOverflowError);
|
||||||
@@ -176,6 +200,9 @@ namespace Lidgren.Network
|
|||||||
return (Int32)retval;
|
return (Int32)retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reads a signed integer stored in 1 to 32 bits, written using Write(Int32, Int32)
|
||||||
|
/// </summary>
|
||||||
public Int32 ReadInt32(int numberOfBits)
|
public Int32 ReadInt32(int numberOfBits)
|
||||||
{
|
{
|
||||||
NetException.Assert((numberOfBits > 0 && numberOfBits <= 32), "ReadInt() can only read between 1 and 32 bits");
|
NetException.Assert((numberOfBits > 0 && numberOfBits <= 32), "ReadInt() can only read between 1 and 32 bits");
|
||||||
@@ -200,6 +227,9 @@ namespace Lidgren.Network
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reads an 32 bit unsigned integer written using Write(UInt32)
|
||||||
|
/// </summary>
|
||||||
[CLSCompliant(false)]
|
[CLSCompliant(false)]
|
||||||
public UInt32 ReadUInt32()
|
public UInt32 ReadUInt32()
|
||||||
{
|
{
|
||||||
@@ -209,6 +239,9 @@ namespace Lidgren.Network
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reads an unsigned integer stored in 1 to 32 bits, written using Write(UInt32, Int32)
|
||||||
|
/// </summary>
|
||||||
[CLSCompliant(false)]
|
[CLSCompliant(false)]
|
||||||
public UInt32 ReadUInt32(int numberOfBits)
|
public UInt32 ReadUInt32(int numberOfBits)
|
||||||
{
|
{
|
||||||
@@ -220,9 +253,9 @@ namespace Lidgren.Network
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
/// <summary>
|
||||||
// 64 bit
|
/// Reads a 64 bit unsigned integer written using Write(UInt64)
|
||||||
//
|
/// </summary>
|
||||||
[CLSCompliant(false)]
|
[CLSCompliant(false)]
|
||||||
public UInt64 ReadUInt64()
|
public UInt64 ReadUInt64()
|
||||||
{
|
{
|
||||||
@@ -238,6 +271,9 @@ namespace Lidgren.Network
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reads a 64 bit signed integer written using Write(Int64)
|
||||||
|
/// </summary>
|
||||||
public Int64 ReadInt64()
|
public Int64 ReadInt64()
|
||||||
{
|
{
|
||||||
NetException.Assert(m_bitLength - m_readPosition >= 64, c_readOverflowError);
|
NetException.Assert(m_bitLength - m_readPosition >= 64, c_readOverflowError);
|
||||||
@@ -249,6 +285,9 @@ namespace Lidgren.Network
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reads an unsigned integer stored in 1 to 64 bits, written using Write(UInt64, Int32)
|
||||||
|
/// </summary>
|
||||||
[CLSCompliant(false)]
|
[CLSCompliant(false)]
|
||||||
public UInt64 ReadUInt64(int numberOfBits)
|
public UInt64 ReadUInt64(int numberOfBits)
|
||||||
{
|
{
|
||||||
@@ -269,20 +308,26 @@ namespace Lidgren.Network
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reads a signed integer stored in 1 to 64 bits, written using Write(Int64, Int32)
|
||||||
|
/// </summary>
|
||||||
public Int64 ReadInt64(int numberOfBits)
|
public Int64 ReadInt64(int numberOfBits)
|
||||||
{
|
{
|
||||||
NetException.Assert(((numberOfBits > 0) && (numberOfBits < 65)), "ReadInt64(bits) can only read between 1 and 64 bits");
|
NetException.Assert(((numberOfBits > 0) && (numberOfBits < 65)), "ReadInt64(bits) can only read between 1 and 64 bits");
|
||||||
return (long)ReadUInt64(numberOfBits);
|
return (long)ReadUInt64(numberOfBits);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
/// <summary>
|
||||||
// Floating point
|
/// Reads a 32 bit floating point value written using Write(Single)
|
||||||
//
|
/// </summary>
|
||||||
public float ReadFloat()
|
public float ReadFloat()
|
||||||
{
|
{
|
||||||
return ReadSingle();
|
return ReadSingle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reads a 32 bit floating point value written using Write(Single)
|
||||||
|
/// </summary>
|
||||||
public float ReadSingle()
|
public float ReadSingle()
|
||||||
{
|
{
|
||||||
NetException.Assert(m_bitLength - m_readPosition >= 32, c_readOverflowError);
|
NetException.Assert(m_bitLength - m_readPosition >= 32, c_readOverflowError);
|
||||||
@@ -299,6 +344,9 @@ namespace Lidgren.Network
|
|||||||
return BitConverter.ToSingle(bytes, 0); // endianness is handled inside BitConverter.ToSingle
|
return BitConverter.ToSingle(bytes, 0); // endianness is handled inside BitConverter.ToSingle
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reads a 64 bit floating point value written using Write(Double)
|
||||||
|
/// </summary>
|
||||||
public double ReadDouble()
|
public double ReadDouble()
|
||||||
{
|
{
|
||||||
NetException.Assert(m_bitLength - m_readPosition >= 64, c_readOverflowError);
|
NetException.Assert(m_bitLength - m_readPosition >= 64, c_readOverflowError);
|
||||||
@@ -320,7 +368,7 @@ namespace Lidgren.Network
|
|||||||
//
|
//
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reads a UInt32 written using WriteVariableUInt32()
|
/// Reads a variable sized UInt32 written using WriteVariableUInt32()
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[CLSCompliant(false)]
|
[CLSCompliant(false)]
|
||||||
public uint ReadVariableUInt32()
|
public uint ReadVariableUInt32()
|
||||||
@@ -338,7 +386,7 @@ namespace Lidgren.Network
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reads a Int32 written using WriteVariableInt32()
|
/// Reads a variable sized Int32 written using WriteVariableInt32()
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int ReadVariableInt32()
|
public int ReadVariableInt32()
|
||||||
{
|
{
|
||||||
@@ -347,7 +395,7 @@ namespace Lidgren.Network
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reads a Int64 written using WriteVariableInt64()
|
/// Reads a variable sized Int64 written using WriteVariableInt64()
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Int64 ReadVariableInt64()
|
public Int64 ReadVariableInt64()
|
||||||
{
|
{
|
||||||
@@ -356,7 +404,7 @@ namespace Lidgren.Network
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reads a UInt32 written using WriteVariableInt64()
|
/// Reads a variable sized UInt32 written using WriteVariableInt64()
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[CLSCompliant(false)]
|
[CLSCompliant(false)]
|
||||||
public UInt64 ReadVariableUInt64()
|
public UInt64 ReadVariableUInt64()
|
||||||
@@ -377,8 +425,10 @@ namespace Lidgren.Network
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reads a float written using WriteSignedSingle()
|
/// Reads a 32 bit floating point value written using WriteSignedSingle()
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="numberOfBits">The number of bits used when writing the value</param>
|
||||||
|
/// <returns>A floating point value larger or equal to -1 and smaller or equal to 1</returns>
|
||||||
public float ReadSignedSingle(int numberOfBits)
|
public float ReadSignedSingle(int numberOfBits)
|
||||||
{
|
{
|
||||||
uint encodedVal = ReadUInt32(numberOfBits);
|
uint encodedVal = ReadUInt32(numberOfBits);
|
||||||
@@ -387,8 +437,10 @@ namespace Lidgren.Network
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reads a float written using WriteUnitSingle()
|
/// Reads a 32 bit floating point value written using WriteUnitSingle()
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="numberOfBits">The number of bits used when writing the value</param>
|
||||||
|
/// <returns>A floating point value larger or equal to 0 and smaller or equal to 1</returns>
|
||||||
public float ReadUnitSingle(int numberOfBits)
|
public float ReadUnitSingle(int numberOfBits)
|
||||||
{
|
{
|
||||||
uint encodedVal = ReadUInt32(numberOfBits);
|
uint encodedVal = ReadUInt32(numberOfBits);
|
||||||
@@ -397,8 +449,12 @@ namespace Lidgren.Network
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reads a float written using WriteRangedSingle() using the same MIN and MAX values
|
/// Reads a 32 bit floating point value written using WriteRangedSingle()
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="min">The minimum value used when writing the value</param>
|
||||||
|
/// <param name="max">The maximum value used when writing the value</param>
|
||||||
|
/// <param name="numberOfBits">The number of bits used when writing the value</param>
|
||||||
|
/// <returns>A floating point value larger or equal to MIN and smaller or equal to MAX</returns>
|
||||||
public float ReadRangedSingle(float min, float max, int numberOfBits)
|
public float ReadRangedSingle(float min, float max, int numberOfBits)
|
||||||
{
|
{
|
||||||
float range = max - min;
|
float range = max - min;
|
||||||
@@ -409,8 +465,11 @@ namespace Lidgren.Network
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reads an integer written using WriteRangedInteger() using the same min/max values
|
/// Reads a 32 bit integer value written using WriteRangedInteger()
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="min">The minimum value used when writing the value</param>
|
||||||
|
/// <param name="max">The maximum value used when writing the value</param>
|
||||||
|
/// <returns>A signed integer value larger or equal to MIN and smaller or equal to MAX</returns>
|
||||||
public int ReadRangedInteger(int min, int max)
|
public int ReadRangedInteger(int min, int max)
|
||||||
{
|
{
|
||||||
uint range = (uint)(max - min);
|
uint range = (uint)(max - min);
|
||||||
@@ -421,7 +480,7 @@ namespace Lidgren.Network
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reads a string
|
/// Reads a string written using Write(string)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string ReadString()
|
public string ReadString()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -104,6 +104,11 @@ namespace Lidgren.Network
|
|||||||
m_isFragment = false;
|
m_isFragment = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Decrypt a message
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="encryption">The encryption algorithm used to encrypt the message</param>
|
||||||
|
/// <returns>true on success</returns>
|
||||||
public bool Decrypt(INetEncryption encryption)
|
public bool Decrypt(INetEncryption encryption)
|
||||||
{
|
{
|
||||||
return encryption.Decrypt(this);
|
return encryption.Decrypt(this);
|
||||||
|
|||||||
@@ -28,20 +28,78 @@ namespace Lidgren.Network
|
|||||||
[SuppressMessage("Microsoft.Design", "CA1027:MarkEnumsWithFlags")]
|
[SuppressMessage("Microsoft.Design", "CA1027:MarkEnumsWithFlags")]
|
||||||
public enum NetIncomingMessageType
|
public enum NetIncomingMessageType
|
||||||
{
|
{
|
||||||
|
//
|
||||||
// library note: values are power-of-two, but they are not flags - it's a convenience for NetPeerConfiguration.DisabledMessageTypes
|
// library note: values are power-of-two, but they are not flags - it's a convenience for NetPeerConfiguration.DisabledMessageTypes
|
||||||
|
//
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Error; this value should never appear
|
||||||
|
/// </summary>
|
||||||
Error = 0,
|
Error = 0,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Status for a connection changed
|
||||||
|
/// </summary>
|
||||||
StatusChanged = 1 << 0, // Data (string)
|
StatusChanged = 1 << 0, // Data (string)
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Data sent using SendUnconnectedMessage
|
||||||
|
/// </summary>
|
||||||
UnconnectedData = 1 << 1, // Data Based on data received
|
UnconnectedData = 1 << 1, // Data Based on data received
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Connection approval is needed
|
||||||
|
/// </summary>
|
||||||
ConnectionApproval = 1 << 2, // Data
|
ConnectionApproval = 1 << 2, // Data
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Application data
|
||||||
|
/// </summary>
|
||||||
Data = 1 << 3, // Data Based on data received
|
Data = 1 << 3, // Data Based on data received
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Receipt of delivery
|
||||||
|
/// </summary>
|
||||||
Receipt = 1 << 4, // Data
|
Receipt = 1 << 4, // Data
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Discovery request for a response
|
||||||
|
/// </summary>
|
||||||
DiscoveryRequest = 1 << 5, // (no data)
|
DiscoveryRequest = 1 << 5, // (no data)
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Discovery response to a request
|
||||||
|
/// </summary>
|
||||||
DiscoveryResponse = 1 << 6, // Data
|
DiscoveryResponse = 1 << 6, // Data
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Verbose debug message
|
||||||
|
/// </summary>
|
||||||
VerboseDebugMessage = 1 << 7, // Data (string)
|
VerboseDebugMessage = 1 << 7, // Data (string)
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Debug message
|
||||||
|
/// </summary>
|
||||||
DebugMessage = 1 << 8, // Data (string)
|
DebugMessage = 1 << 8, // Data (string)
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Warning message
|
||||||
|
/// </summary>
|
||||||
WarningMessage = 1 << 9, // Data (string)
|
WarningMessage = 1 << 9, // Data (string)
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Error message
|
||||||
|
/// </summary>
|
||||||
ErrorMessage = 1 << 10, // Data (string)
|
ErrorMessage = 1 << 10, // Data (string)
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// NAT introduction was successful
|
||||||
|
/// </summary>
|
||||||
NatIntroductionSuccess = 1 << 11, // Data (as passed to master server)
|
NatIntroductionSuccess = 1 << 11, // Data (as passed to master server)
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A roundtrip was measured and NetConnection.AverageRoundtripTime was updated
|
||||||
|
/// </summary>
|
||||||
ConnectionLatencyUpdated = 1 << 12, // Seconds as a Single
|
ConnectionLatencyUpdated = 1 << 12, // Seconds as a Single
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,9 +114,9 @@ namespace Lidgren.Network
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
/// <summary>
|
||||||
// 1 bit
|
/// Writes a boolean value using 1 bit
|
||||||
//
|
/// </summary>
|
||||||
public void Write(bool value)
|
public void Write(bool value)
|
||||||
{
|
{
|
||||||
EnsureBufferSize(m_bitLength + 1);
|
EnsureBufferSize(m_bitLength + 1);
|
||||||
@@ -124,9 +124,9 @@ namespace Lidgren.Network
|
|||||||
m_bitLength += 1;
|
m_bitLength += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
/// <summary>
|
||||||
// 8 bit
|
/// Write a byte
|
||||||
//
|
/// </summary>
|
||||||
public void Write(byte source)
|
public void Write(byte source)
|
||||||
{
|
{
|
||||||
EnsureBufferSize(m_bitLength + 8);
|
EnsureBufferSize(m_bitLength + 8);
|
||||||
@@ -134,6 +134,9 @@ namespace Lidgren.Network
|
|||||||
m_bitLength += 8;
|
m_bitLength += 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes a signed byte
|
||||||
|
/// </summary>
|
||||||
[CLSCompliant(false)]
|
[CLSCompliant(false)]
|
||||||
public void Write(sbyte source)
|
public void Write(sbyte source)
|
||||||
{
|
{
|
||||||
@@ -142,6 +145,9 @@ namespace Lidgren.Network
|
|||||||
m_bitLength += 8;
|
m_bitLength += 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes 1 to 8 bits of a byte
|
||||||
|
/// </summary>
|
||||||
public void Write(byte source, int numberOfBits)
|
public void Write(byte source, int numberOfBits)
|
||||||
{
|
{
|
||||||
NetException.Assert((numberOfBits > 0 && numberOfBits <= 8), "Write(byte, numberOfBits) can only write between 1 and 8 bits");
|
NetException.Assert((numberOfBits > 0 && numberOfBits <= 8), "Write(byte, numberOfBits) can only write between 1 and 8 bits");
|
||||||
@@ -150,6 +156,9 @@ namespace Lidgren.Network
|
|||||||
m_bitLength += numberOfBits;
|
m_bitLength += numberOfBits;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes all bytes in an array
|
||||||
|
/// </summary>
|
||||||
public void Write(byte[] source)
|
public void Write(byte[] source)
|
||||||
{
|
{
|
||||||
if (source == null)
|
if (source == null)
|
||||||
@@ -160,6 +169,9 @@ namespace Lidgren.Network
|
|||||||
m_bitLength += bits;
|
m_bitLength += bits;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes the specified number of bytes from an array
|
||||||
|
/// </summary>
|
||||||
public void Write(byte[] source, int offsetInBytes, int numberOfBytes)
|
public void Write(byte[] source, int offsetInBytes, int numberOfBytes)
|
||||||
{
|
{
|
||||||
if (source == null)
|
if (source == null)
|
||||||
@@ -170,9 +182,10 @@ namespace Lidgren.Network
|
|||||||
m_bitLength += bits;
|
m_bitLength += bits;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
/// <summary>
|
||||||
// 16 bit
|
/// Writes an unsigned 16 bit integer
|
||||||
//
|
/// </summary>
|
||||||
|
/// <param name="source"></param>
|
||||||
[CLSCompliant(false)]
|
[CLSCompliant(false)]
|
||||||
public void Write(UInt16 source)
|
public void Write(UInt16 source)
|
||||||
{
|
{
|
||||||
@@ -181,6 +194,9 @@ namespace Lidgren.Network
|
|||||||
m_bitLength += 16;
|
m_bitLength += 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes an unsigned integer using 1 to 16 bits
|
||||||
|
/// </summary>
|
||||||
[CLSCompliant(false)]
|
[CLSCompliant(false)]
|
||||||
public void Write(UInt16 source, int numberOfBits)
|
public void Write(UInt16 source, int numberOfBits)
|
||||||
{
|
{
|
||||||
@@ -190,6 +206,9 @@ namespace Lidgren.Network
|
|||||||
m_bitLength += numberOfBits;
|
m_bitLength += numberOfBits;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes a signed 16 bit integer
|
||||||
|
/// </summary>
|
||||||
public void Write(Int16 source)
|
public void Write(Int16 source)
|
||||||
{
|
{
|
||||||
EnsureBufferSize(m_bitLength + 16);
|
EnsureBufferSize(m_bitLength + 16);
|
||||||
@@ -197,10 +216,10 @@ namespace Lidgren.Network
|
|||||||
m_bitLength += 16;
|
m_bitLength += 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// 32 bit
|
|
||||||
//
|
|
||||||
#if UNSAFE
|
#if UNSAFE
|
||||||
|
/// <summary>
|
||||||
|
/// Writes a 32 bit signed integer
|
||||||
|
/// </summary>
|
||||||
public unsafe void Write(Int32 source)
|
public unsafe void Write(Int32 source)
|
||||||
{
|
{
|
||||||
EnsureBufferSize(m_bitLength + 32);
|
EnsureBufferSize(m_bitLength + 32);
|
||||||
@@ -220,6 +239,9 @@ namespace Lidgren.Network
|
|||||||
m_bitLength += 32;
|
m_bitLength += 32;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
/// <summary>
|
||||||
|
/// Writes a 32 bit signed integer
|
||||||
|
/// </summary>
|
||||||
public void Write(Int32 source)
|
public void Write(Int32 source)
|
||||||
{
|
{
|
||||||
EnsureBufferSize(m_bitLength + 32);
|
EnsureBufferSize(m_bitLength + 32);
|
||||||
@@ -229,6 +251,9 @@ namespace Lidgren.Network
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if UNSAFE
|
#if UNSAFE
|
||||||
|
/// <summary>
|
||||||
|
/// Writes a 32 bit unsigned integer
|
||||||
|
/// </summary>
|
||||||
public unsafe void Write(UInt32 source)
|
public unsafe void Write(UInt32 source)
|
||||||
{
|
{
|
||||||
EnsureBufferSize(m_bitLength + 32);
|
EnsureBufferSize(m_bitLength + 32);
|
||||||
@@ -249,6 +274,9 @@ namespace Lidgren.Network
|
|||||||
m_bitLength += 32;
|
m_bitLength += 32;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
/// <summary>
|
||||||
|
/// Writes a 32 bit unsigned integer
|
||||||
|
/// </summary>
|
||||||
[CLSCompliant(false)]
|
[CLSCompliant(false)]
|
||||||
public void Write(UInt32 source)
|
public void Write(UInt32 source)
|
||||||
{
|
{
|
||||||
@@ -258,6 +286,9 @@ namespace Lidgren.Network
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes a 32 bit signed integer
|
||||||
|
/// </summary>
|
||||||
[CLSCompliant(false)]
|
[CLSCompliant(false)]
|
||||||
public void Write(UInt32 source, int numberOfBits)
|
public void Write(UInt32 source, int numberOfBits)
|
||||||
{
|
{
|
||||||
@@ -267,6 +298,9 @@ namespace Lidgren.Network
|
|||||||
m_bitLength += numberOfBits;
|
m_bitLength += numberOfBits;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes a signed integer using 1 to 32 bits
|
||||||
|
/// </summary>
|
||||||
public void Write(Int32 source, int numberOfBits)
|
public void Write(Int32 source, int numberOfBits)
|
||||||
{
|
{
|
||||||
NetException.Assert((numberOfBits > 0 && numberOfBits <= 32), "Write(int, numberOfBits) can only write between 1 and 32 bits");
|
NetException.Assert((numberOfBits > 0 && numberOfBits <= 32), "Write(int, numberOfBits) can only write between 1 and 32 bits");
|
||||||
@@ -287,9 +321,9 @@ namespace Lidgren.Network
|
|||||||
m_bitLength += numberOfBits;
|
m_bitLength += numberOfBits;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
/// <summary>
|
||||||
// 64 bit
|
/// Writes a 64 bit unsigned integer
|
||||||
//
|
/// </summary>
|
||||||
[CLSCompliant(false)]
|
[CLSCompliant(false)]
|
||||||
public void Write(UInt64 source)
|
public void Write(UInt64 source)
|
||||||
{
|
{
|
||||||
@@ -298,6 +332,9 @@ namespace Lidgren.Network
|
|||||||
m_bitLength += 64;
|
m_bitLength += 64;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes an unsigned integer using 1 to 64 bits
|
||||||
|
/// </summary>
|
||||||
[CLSCompliant(false)]
|
[CLSCompliant(false)]
|
||||||
public void Write(UInt64 source, int numberOfBits)
|
public void Write(UInt64 source, int numberOfBits)
|
||||||
{
|
{
|
||||||
@@ -306,6 +343,9 @@ namespace Lidgren.Network
|
|||||||
m_bitLength += numberOfBits;
|
m_bitLength += numberOfBits;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes a 64 bit signed integer
|
||||||
|
/// </summary>
|
||||||
public void Write(Int64 source)
|
public void Write(Int64 source)
|
||||||
{
|
{
|
||||||
EnsureBufferSize(m_bitLength + 64);
|
EnsureBufferSize(m_bitLength + 64);
|
||||||
@@ -314,6 +354,9 @@ namespace Lidgren.Network
|
|||||||
m_bitLength += 64;
|
m_bitLength += 64;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes a signed integer using 1 to 64 bits
|
||||||
|
/// </summary>
|
||||||
public void Write(Int64 source, int numberOfBits)
|
public void Write(Int64 source, int numberOfBits)
|
||||||
{
|
{
|
||||||
EnsureBufferSize(m_bitLength + numberOfBits);
|
EnsureBufferSize(m_bitLength + numberOfBits);
|
||||||
@@ -326,6 +369,9 @@ namespace Lidgren.Network
|
|||||||
// Floating point
|
// Floating point
|
||||||
//
|
//
|
||||||
#if UNSAFE
|
#if UNSAFE
|
||||||
|
/// <summary>
|
||||||
|
/// Writes a 32 bit floating point value
|
||||||
|
/// </summary>
|
||||||
public unsafe void Write(float source)
|
public unsafe void Write(float source)
|
||||||
{
|
{
|
||||||
uint val = *((uint*)&source);
|
uint val = *((uint*)&source);
|
||||||
@@ -335,6 +381,9 @@ namespace Lidgren.Network
|
|||||||
Write(val);
|
Write(val);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
/// <summary>
|
||||||
|
/// Writes a 32 bit floating point value
|
||||||
|
/// </summary>
|
||||||
public void Write(float source)
|
public void Write(float source)
|
||||||
{
|
{
|
||||||
byte[] val = BitConverter.GetBytes(source);
|
byte[] val = BitConverter.GetBytes(source);
|
||||||
@@ -352,6 +401,9 @@ namespace Lidgren.Network
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if UNSAFE
|
#if UNSAFE
|
||||||
|
/// <summary>
|
||||||
|
/// Writes a 64 bit floating point value
|
||||||
|
/// </summary>
|
||||||
public unsafe void Write(double source)
|
public unsafe void Write(double source)
|
||||||
{
|
{
|
||||||
ulong val = *((ulong*)&source);
|
ulong val = *((ulong*)&source);
|
||||||
@@ -361,6 +413,9 @@ namespace Lidgren.Network
|
|||||||
Write(val);
|
Write(val);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
/// <summary>
|
||||||
|
/// Writes a 64 bit floating point value
|
||||||
|
/// </summary>
|
||||||
public void Write(double source)
|
public void Write(double source)
|
||||||
{
|
{
|
||||||
byte[] val = BitConverter.GetBytes(source);
|
byte[] val = BitConverter.GetBytes(source);
|
||||||
|
|||||||
@@ -71,6 +71,13 @@ namespace Lidgren.Network
|
|||||||
return mtu;
|
return mtu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Send a message to a list of connections
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="msg">The message to send</param>
|
||||||
|
/// <param name="recipients">The list of recipients to send to</param>
|
||||||
|
/// <param name="method">How to deliver the message</param>
|
||||||
|
/// <param name="sequenceChannel">Sequence channel within the delivery method</param>
|
||||||
public void SendMessage(NetOutgoingMessage msg, IList<NetConnection> recipients, NetDeliveryMethod method, int sequenceChannel)
|
public void SendMessage(NetOutgoingMessage msg, IList<NetConnection> recipients, NetDeliveryMethod method, int sequenceChannel)
|
||||||
{
|
{
|
||||||
if (msg == null)
|
if (msg == null)
|
||||||
|
|||||||
@@ -85,6 +85,9 @@ namespace Lidgren.Network
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public NetPeerConfiguration Configuration { get { return m_configuration; } }
|
public NetPeerConfiguration Configuration { get { return m_configuration; } }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// NetPeer constructor
|
||||||
|
/// </summary>
|
||||||
public NetPeer(NetPeerConfiguration config)
|
public NetPeer(NetPeerConfiguration config)
|
||||||
{
|
{
|
||||||
m_configuration = config;
|
m_configuration = config;
|
||||||
@@ -132,6 +135,9 @@ namespace Lidgren.Network
|
|||||||
Thread.Sleep(10);
|
Thread.Sleep(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the connection, if any, for a certain remote endpoint
|
||||||
|
/// </summary>
|
||||||
public NetConnection GetConnection(IPEndPoint ep)
|
public NetConnection GetConnection(IPEndPoint ep)
|
||||||
{
|
{
|
||||||
NetConnection retval;
|
NetConnection retval;
|
||||||
@@ -253,6 +259,9 @@ namespace Lidgren.Network
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
|
/// <summary>
|
||||||
|
/// Send raw bytes; only used for debugging
|
||||||
|
/// </summary>
|
||||||
public void RawSend(byte[] arr, int offset, int length, IPEndPoint destination)
|
public void RawSend(byte[] arr, int offset, int length, IPEndPoint destination)
|
||||||
{
|
{
|
||||||
// wrong thread - this miiiight crash with network thread... but what's a boy to do.
|
// wrong thread - this miiiight crash with network thread... but what's a boy to do.
|
||||||
|
|||||||
@@ -59,6 +59,9 @@ namespace Lidgren.Network
|
|||||||
internal float m_expandMTUFrequency;
|
internal float m_expandMTUFrequency;
|
||||||
internal int m_expandMTUFailAttempts;
|
internal int m_expandMTUFailAttempts;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// NetPeerConfiguration constructor
|
||||||
|
/// </summary>
|
||||||
public NetPeerConfiguration(string appIdentifier)
|
public NetPeerConfiguration(string appIdentifier)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(appIdentifier))
|
if (string.IsNullOrEmpty(appIdentifier))
|
||||||
|
|||||||
@@ -57,6 +57,9 @@ namespace Lidgren.Network
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public int Capacity { get { return m_items.Length; } }
|
public int Capacity { get { return m_items.Length; } }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// NetQueue constructor
|
||||||
|
/// </summary>
|
||||||
public NetQueue(int initialCapacity)
|
public NetQueue(int initialCapacity)
|
||||||
{
|
{
|
||||||
m_lock = new object();
|
m_lock = new object();
|
||||||
|
|||||||
@@ -72,6 +72,9 @@ namespace Lidgren.Network
|
|||||||
Reinitialise(seed);
|
Reinitialise(seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a semi-random seed based on an object
|
||||||
|
/// </summary>
|
||||||
public int GetSeed(object forObject)
|
public int GetSeed(object forObject)
|
||||||
{
|
{
|
||||||
// mix some semi-random properties
|
// mix some semi-random properties
|
||||||
|
|||||||
@@ -123,6 +123,9 @@ namespace Lidgren.Network
|
|||||||
return B.ToByteArrayUnsigned();
|
return B.ToByteArrayUnsigned();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Compute intermediate value U
|
||||||
|
/// </summary>
|
||||||
public static byte[] ComputeU(byte[] clientPublicEphemeral, byte[] serverPublicEphemeral)
|
public static byte[] ComputeU(byte[] clientPublicEphemeral, byte[] serverPublicEphemeral)
|
||||||
{
|
{
|
||||||
// u = SHA-1(A || B)
|
// u = SHA-1(A || B)
|
||||||
@@ -140,6 +143,9 @@ namespace Lidgren.Network
|
|||||||
return new NetBigInteger(NetUtility.ToHexString(ccHashed), 16).ToByteArrayUnsigned();
|
return new NetBigInteger(NetUtility.ToHexString(ccHashed), 16).ToByteArrayUnsigned();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Computes the server session value
|
||||||
|
/// </summary>
|
||||||
public static byte[] ComputeServerSessionValue(byte[] clientPublicEphemeral, byte[] verifier, byte[] udata, byte[] serverPrivateEphemeral)
|
public static byte[] ComputeServerSessionValue(byte[] clientPublicEphemeral, byte[] verifier, byte[] udata, byte[] serverPrivateEphemeral)
|
||||||
{
|
{
|
||||||
// S = (Av^u) ^ b (mod N)
|
// S = (Av^u) ^ b (mod N)
|
||||||
@@ -153,6 +159,9 @@ namespace Lidgren.Network
|
|||||||
return retval.ToByteArrayUnsigned();
|
return retval.ToByteArrayUnsigned();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Computes the client session value
|
||||||
|
/// </summary>
|
||||||
public static byte[] ComputeClientSessionValue(byte[] serverPublicEphemeral, byte[] xdata, byte[] udata, byte[] clientPrivateEphemeral)
|
public static byte[] ComputeClientSessionValue(byte[] serverPublicEphemeral, byte[] xdata, byte[] udata, byte[] clientPrivateEphemeral)
|
||||||
{
|
{
|
||||||
// (B - kg^x) ^ (a + ux) (mod N)
|
// (B - kg^x) ^ (a + ux) (mod N)
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ namespace Lidgren.Network
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class NetServer : NetPeer
|
public class NetServer : NetPeer
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// NetServer constructor
|
||||||
|
/// </summary>
|
||||||
public NetServer(NetPeerConfiguration config)
|
public NetServer(NetPeerConfiguration config)
|
||||||
: base(config)
|
: base(config)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -118,6 +118,9 @@ namespace Lidgren.Network
|
|||||||
return best;
|
return best;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the physical (MAC) address for the first usable network interface
|
||||||
|
/// </summary>
|
||||||
public static PhysicalAddress GetMacAddress()
|
public static PhysicalAddress GetMacAddress()
|
||||||
{
|
{
|
||||||
NetworkInterface ni = GetNetworkInterface();
|
NetworkInterface ni = GetNetworkInterface();
|
||||||
@@ -126,11 +129,17 @@ namespace Lidgren.Network
|
|||||||
return ni.GetPhysicalAddress();
|
return ni.GetPhysicalAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a hex string from an Int64 value
|
||||||
|
/// </summary>
|
||||||
public static string ToHexString(long data)
|
public static string ToHexString(long data)
|
||||||
{
|
{
|
||||||
return ToHexString(BitConverter.GetBytes(data));
|
return ToHexString(BitConverter.GetBytes(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a hex string from an array of bytes
|
||||||
|
/// </summary>
|
||||||
public static string ToHexString(byte[] data)
|
public static string ToHexString(byte[] data)
|
||||||
{
|
{
|
||||||
char[] c = new char[data.Length * 2];
|
char[] c = new char[data.Length * 2];
|
||||||
@@ -283,6 +292,9 @@ namespace Lidgren.Network
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the window size used internally in the library for a certain delivery method
|
||||||
|
/// </summary>
|
||||||
public static int GetWindowSize(NetDeliveryMethod method)
|
public static int GetWindowSize(NetDeliveryMethod method)
|
||||||
{
|
{
|
||||||
switch (method)
|
switch (method)
|
||||||
|
|||||||
@@ -49,6 +49,9 @@ namespace UnitTests
|
|||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Helper method
|
||||||
|
/// </summary>
|
||||||
public static NetIncomingMessage CreateIncomingMessage(byte[] fromData, int bitLength)
|
public static NetIncomingMessage CreateIncomingMessage(byte[] fromData, int bitLength)
|
||||||
{
|
{
|
||||||
NetIncomingMessage inc = (NetIncomingMessage)Activator.CreateInstance(typeof(NetIncomingMessage), true);
|
NetIncomingMessage inc = (NetIncomingMessage)Activator.CreateInstance(typeof(NetIncomingMessage), true);
|
||||||
|
|||||||
Reference in New Issue
Block a user