You've already forked lidgren-network-gen3
mirror of
https://github.com/lidgren/lidgren-network-gen3.git
synced 2026-05-15 22:56: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
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface for an encryption algorithm
|
||||
/// </summary>
|
||||
public interface INetEncryption
|
||||
{
|
||||
/// <summary>
|
||||
/// Encrypt an outgoing message in place
|
||||
/// </summary>
|
||||
bool Encrypt(NetOutgoingMessage msg);
|
||||
|
||||
/// <summary>
|
||||
/// Decrypt an incoming message in place
|
||||
/// </summary>
|
||||
bool Decrypt(NetIncomingMessage msg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,9 @@ namespace Lidgren.Network
|
||||
/// </summary>
|
||||
public abstract int BlockSize { get; }
|
||||
|
||||
/// <summary>
|
||||
/// NetBlockEncryptionBase constructor
|
||||
/// </summary>
|
||||
public NetBlockEncryptionBase()
|
||||
{
|
||||
m_tmp = new byte[BlockSize];
|
||||
@@ -72,7 +75,14 @@ namespace Lidgren.Network
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encrypt a block of bytes
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,16 +11,25 @@ namespace Lidgren.Network
|
||||
{
|
||||
private byte[] m_key;
|
||||
|
||||
/// <summary>
|
||||
/// NetXorEncryption constructor
|
||||
/// </summary>
|
||||
public NetXorEncryption(byte[] key)
|
||||
{
|
||||
m_key = key;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// NetXorEncryption constructor
|
||||
/// </summary>
|
||||
public NetXorEncryption(string key)
|
||||
{
|
||||
m_key = Encoding.ASCII.GetBytes(key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encrypt an outgoing message
|
||||
/// </summary>
|
||||
public bool Encrypt(NetOutgoingMessage msg)
|
||||
{
|
||||
int numBytes = msg.LengthBytes;
|
||||
@@ -32,6 +41,9 @@ namespace Lidgren.Network
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decrypt an incoming message
|
||||
/// </summary>
|
||||
public bool Decrypt(NetIncomingMessage msg)
|
||||
{
|
||||
int numBytes = msg.LengthBytes;
|
||||
|
||||
@@ -36,6 +36,9 @@ namespace Lidgren.Network
|
||||
private readonly uint[] m_sum0;
|
||||
private readonly uint[] m_sum1;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the block size for this cipher
|
||||
/// </summary>
|
||||
public override int BlockSize { get { return c_blockSize; } }
|
||||
|
||||
/// <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)
|
||||
{
|
||||
uint v0 = BytesToUInt(source, sourceOffset);
|
||||
@@ -100,6 +106,9 @@ namespace Lidgren.Network
|
||||
return;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decrypts a block of bytes
|
||||
/// </summary>
|
||||
protected override void DecryptBlock(byte[] source, int sourceOffset, byte[] destination)
|
||||
{
|
||||
// Pack bytes into integers
|
||||
|
||||
@@ -36,6 +36,9 @@ namespace Lidgren.Network
|
||||
/// </summary>
|
||||
public int Capacity { get { return m_capacity; } }
|
||||
|
||||
/// <summary>
|
||||
/// NetBitVector constructor
|
||||
/// </summary>
|
||||
public NetBitVector(int bitsCapacity)
|
||||
{
|
||||
m_capacity = bitsCapacity;
|
||||
@@ -80,6 +83,9 @@ namespace Lidgren.Network
|
||||
m_data[lenMinusOne] = cur;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the first (lowest) index set to true
|
||||
/// </summary>
|
||||
public int GetFirstSetIndex()
|
||||
{
|
||||
int idx = 0;
|
||||
|
||||
@@ -169,6 +169,9 @@ namespace Lidgren.Network
|
||||
return;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the specified number of bits into an UInt32
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
#if UNSAFE
|
||||
public static unsafe uint ReadUInt32(byte[] fromBuffer, int numberOfBits, int readBitOffset)
|
||||
@@ -183,6 +186,7 @@ namespace Lidgren.Network
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
||||
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");
|
||||
@@ -234,6 +238,9 @@ namespace Lidgren.Network
|
||||
//[CLSCompliant(false)]
|
||||
//public static ulong ReadUInt64(byte[] fromBuffer, int numberOfBits, int readBitOffset)
|
||||
|
||||
/// <summary>
|
||||
/// Writes the specified number of bits into a byte array
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public static int WriteUInt32(uint source, int numberOfBits, byte[] destination, int destinationBitOffset)
|
||||
{
|
||||
@@ -277,6 +284,9 @@ namespace Lidgren.Network
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the specified number of bits into a byte array
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
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
|
||||
{
|
||||
get
|
||||
@@ -61,12 +64,22 @@ namespace Lidgren.Network
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// NetClient constructor
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
public NetClient(NetPeerConfiguration config)
|
||||
: base(config)
|
||||
{
|
||||
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)
|
||||
{
|
||||
lock (m_connections)
|
||||
|
||||
@@ -17,6 +17,9 @@ namespace Lidgren.Network
|
||||
/// </summary>
|
||||
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; } }
|
||||
|
||||
// this might happen more than once
|
||||
|
||||
@@ -28,21 +28,33 @@ namespace Lidgren.Network
|
||||
[Serializable]
|
||||
public sealed class NetException : Exception
|
||||
{
|
||||
/// <summary>
|
||||
/// NetException constructor
|
||||
/// </summary>
|
||||
public NetException()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// NetException constructor
|
||||
/// </summary>
|
||||
public NetException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// NetException constructor
|
||||
/// </summary>
|
||||
public NetException(string message, Exception inner)
|
||||
: base(message, inner)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// NetException constructor
|
||||
/// </summary>
|
||||
private NetException(SerializationInfo info, StreamingContext context)
|
||||
: base(info, context)
|
||||
{
|
||||
|
||||
@@ -69,9 +69,9 @@ namespace Lidgren.Network
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// 1 bit
|
||||
//
|
||||
/// <summary>
|
||||
/// Reads a boolean value (stored as a single bit) written using Write(bool)
|
||||
/// </summary>
|
||||
public bool ReadBoolean()
|
||||
{
|
||||
NetException.Assert(m_bitLength - m_readPosition >= 1, c_readOverflowError);
|
||||
@@ -79,10 +79,10 @@ namespace Lidgren.Network
|
||||
m_readPosition += 1;
|
||||
return (retval > 0 ? true : false);
|
||||
}
|
||||
|
||||
//
|
||||
// 8 bit
|
||||
//
|
||||
|
||||
/// <summary>
|
||||
/// Reads a byte
|
||||
/// </summary>
|
||||
public byte ReadByte()
|
||||
{
|
||||
NetException.Assert(m_bitLength - m_readPosition >= 8, c_readOverflowError);
|
||||
@@ -90,8 +90,10 @@ namespace Lidgren.Network
|
||||
m_readPosition += 8;
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Reads a signed byte
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public sbyte ReadSByte()
|
||||
{
|
||||
@@ -101,13 +103,20 @@ namespace Lidgren.Network
|
||||
return (sbyte)retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads 1 to 8 bits into a byte
|
||||
/// </summary>
|
||||
public byte ReadByte(int numberOfBits)
|
||||
{
|
||||
NetException.Assert(numberOfBits > 0 && numberOfBits < 8);
|
||||
byte retval = NetBitWriter.ReadByte(m_data, numberOfBits, m_readPosition);
|
||||
m_readPosition += numberOfBits;
|
||||
return retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the specified number of bytes
|
||||
/// </summary>
|
||||
public byte[] ReadBytes(int numberOfBytes)
|
||||
{
|
||||
NetException.Assert(m_bitLength - m_readPosition + 7 >= (numberOfBytes * 8), c_readOverflowError);
|
||||
@@ -118,6 +127,12 @@ namespace Lidgren.Network
|
||||
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)
|
||||
{
|
||||
NetException.Assert(m_bitLength - m_readPosition + 7 >= (numberOfBytes * 8), c_readOverflowError);
|
||||
@@ -128,6 +143,12 @@ namespace Lidgren.Network
|
||||
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)
|
||||
{
|
||||
NetException.Assert(m_bitLength - m_readPosition >= numberOfBits, c_readOverflowError);
|
||||
@@ -145,9 +166,9 @@ namespace Lidgren.Network
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// 16 bit
|
||||
//
|
||||
/// <summary>
|
||||
/// Reads a 16 bit signed integer written using Write(Int16)
|
||||
/// </summary>
|
||||
public Int16 ReadInt16()
|
||||
{
|
||||
NetException.Assert(m_bitLength - m_readPosition >= 16, c_readOverflowError);
|
||||
@@ -156,6 +177,9 @@ namespace Lidgren.Network
|
||||
return (short)retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a 16 bit unsigned integer written using Write(UInt16)
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public UInt16 ReadUInt16()
|
||||
{
|
||||
@@ -165,9 +189,9 @@ namespace Lidgren.Network
|
||||
return (ushort)retval;
|
||||
}
|
||||
|
||||
//
|
||||
// 32 bit
|
||||
//
|
||||
/// <summary>
|
||||
/// Reads a 32 bit signed integer written using Write(Int32)
|
||||
/// </summary>
|
||||
public Int32 ReadInt32()
|
||||
{
|
||||
NetException.Assert(m_bitLength - m_readPosition >= 32, c_readOverflowError);
|
||||
@@ -176,6 +200,9 @@ namespace Lidgren.Network
|
||||
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)
|
||||
{
|
||||
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)]
|
||||
public UInt32 ReadUInt32()
|
||||
{
|
||||
@@ -209,6 +239,9 @@ namespace Lidgren.Network
|
||||
return retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads an unsigned integer stored in 1 to 32 bits, written using Write(UInt32, Int32)
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public UInt32 ReadUInt32(int numberOfBits)
|
||||
{
|
||||
@@ -220,9 +253,9 @@ namespace Lidgren.Network
|
||||
return retval;
|
||||
}
|
||||
|
||||
//
|
||||
// 64 bit
|
||||
//
|
||||
/// <summary>
|
||||
/// Reads a 64 bit unsigned integer written using Write(UInt64)
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public UInt64 ReadUInt64()
|
||||
{
|
||||
@@ -238,6 +271,9 @@ namespace Lidgren.Network
|
||||
return retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a 64 bit signed integer written using Write(Int64)
|
||||
/// </summary>
|
||||
public Int64 ReadInt64()
|
||||
{
|
||||
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)]
|
||||
public UInt64 ReadUInt64(int numberOfBits)
|
||||
{
|
||||
@@ -269,20 +308,26 @@ namespace Lidgren.Network
|
||||
return retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a signed integer stored in 1 to 64 bits, written using Write(Int64, Int32)
|
||||
/// </summary>
|
||||
public Int64 ReadInt64(int numberOfBits)
|
||||
{
|
||||
NetException.Assert(((numberOfBits > 0) && (numberOfBits < 65)), "ReadInt64(bits) can only read between 1 and 64 bits");
|
||||
return (long)ReadUInt64(numberOfBits);
|
||||
}
|
||||
|
||||
//
|
||||
// Floating point
|
||||
//
|
||||
/// <summary>
|
||||
/// Reads a 32 bit floating point value written using Write(Single)
|
||||
/// </summary>
|
||||
public float ReadFloat()
|
||||
{
|
||||
return ReadSingle();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a 32 bit floating point value written using Write(Single)
|
||||
/// </summary>
|
||||
public float ReadSingle()
|
||||
{
|
||||
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
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a 64 bit floating point value written using Write(Double)
|
||||
/// </summary>
|
||||
public double ReadDouble()
|
||||
{
|
||||
NetException.Assert(m_bitLength - m_readPosition >= 64, c_readOverflowError);
|
||||
@@ -320,7 +368,7 @@ namespace Lidgren.Network
|
||||
//
|
||||
|
||||
/// <summary>
|
||||
/// Reads a UInt32 written using WriteVariableUInt32()
|
||||
/// Reads a variable sized UInt32 written using WriteVariableUInt32()
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public uint ReadVariableUInt32()
|
||||
@@ -338,7 +386,7 @@ namespace Lidgren.Network
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a Int32 written using WriteVariableInt32()
|
||||
/// Reads a variable sized Int32 written using WriteVariableInt32()
|
||||
/// </summary>
|
||||
public int ReadVariableInt32()
|
||||
{
|
||||
@@ -347,7 +395,7 @@ namespace Lidgren.Network
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a Int64 written using WriteVariableInt64()
|
||||
/// Reads a variable sized Int64 written using WriteVariableInt64()
|
||||
/// </summary>
|
||||
public Int64 ReadVariableInt64()
|
||||
{
|
||||
@@ -356,7 +404,7 @@ namespace Lidgren.Network
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a UInt32 written using WriteVariableInt64()
|
||||
/// Reads a variable sized UInt32 written using WriteVariableInt64()
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public UInt64 ReadVariableUInt64()
|
||||
@@ -377,8 +425,10 @@ namespace Lidgren.Network
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a float written using WriteSignedSingle()
|
||||
/// Reads a 32 bit floating point value written using WriteSignedSingle()
|
||||
/// </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)
|
||||
{
|
||||
uint encodedVal = ReadUInt32(numberOfBits);
|
||||
@@ -387,8 +437,10 @@ namespace Lidgren.Network
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a float written using WriteUnitSingle()
|
||||
/// Reads a 32 bit floating point value written using WriteUnitSingle()
|
||||
/// </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)
|
||||
{
|
||||
uint encodedVal = ReadUInt32(numberOfBits);
|
||||
@@ -397,8 +449,12 @@ namespace Lidgren.Network
|
||||
}
|
||||
|
||||
/// <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>
|
||||
/// <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)
|
||||
{
|
||||
float range = max - min;
|
||||
@@ -409,8 +465,11 @@ namespace Lidgren.Network
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads an integer written using WriteRangedInteger() using the same min/max values
|
||||
/// Reads a 32 bit integer value written using WriteRangedInteger()
|
||||
/// </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)
|
||||
{
|
||||
uint range = (uint)(max - min);
|
||||
@@ -421,7 +480,7 @@ namespace Lidgren.Network
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a string
|
||||
/// Reads a string written using Write(string)
|
||||
/// </summary>
|
||||
public string ReadString()
|
||||
{
|
||||
|
||||
@@ -104,6 +104,11 @@ namespace Lidgren.Network
|
||||
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)
|
||||
{
|
||||
return encryption.Decrypt(this);
|
||||
|
||||
@@ -28,20 +28,78 @@ namespace Lidgren.Network
|
||||
[SuppressMessage("Microsoft.Design", "CA1027:MarkEnumsWithFlags")]
|
||||
public enum NetIncomingMessageType
|
||||
{
|
||||
//
|
||||
// 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,
|
||||
|
||||
/// <summary>
|
||||
/// Status for a connection changed
|
||||
/// </summary>
|
||||
StatusChanged = 1 << 0, // Data (string)
|
||||
|
||||
/// <summary>
|
||||
/// Data sent using SendUnconnectedMessage
|
||||
/// </summary>
|
||||
UnconnectedData = 1 << 1, // Data Based on data received
|
||||
|
||||
/// <summary>
|
||||
/// Connection approval is needed
|
||||
/// </summary>
|
||||
ConnectionApproval = 1 << 2, // Data
|
||||
|
||||
/// <summary>
|
||||
/// Application data
|
||||
/// </summary>
|
||||
Data = 1 << 3, // Data Based on data received
|
||||
|
||||
/// <summary>
|
||||
/// Receipt of delivery
|
||||
/// </summary>
|
||||
Receipt = 1 << 4, // Data
|
||||
|
||||
/// <summary>
|
||||
/// Discovery request for a response
|
||||
/// </summary>
|
||||
DiscoveryRequest = 1 << 5, // (no data)
|
||||
|
||||
/// <summary>
|
||||
/// Discovery response to a request
|
||||
/// </summary>
|
||||
DiscoveryResponse = 1 << 6, // Data
|
||||
|
||||
/// <summary>
|
||||
/// Verbose debug message
|
||||
/// </summary>
|
||||
VerboseDebugMessage = 1 << 7, // Data (string)
|
||||
|
||||
/// <summary>
|
||||
/// Debug message
|
||||
/// </summary>
|
||||
DebugMessage = 1 << 8, // Data (string)
|
||||
|
||||
/// <summary>
|
||||
/// Warning message
|
||||
/// </summary>
|
||||
WarningMessage = 1 << 9, // Data (string)
|
||||
|
||||
/// <summary>
|
||||
/// Error message
|
||||
/// </summary>
|
||||
ErrorMessage = 1 << 10, // Data (string)
|
||||
|
||||
/// <summary>
|
||||
/// NAT introduction was successful
|
||||
/// </summary>
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,9 +114,9 @@ namespace Lidgren.Network
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// 1 bit
|
||||
//
|
||||
/// <summary>
|
||||
/// Writes a boolean value using 1 bit
|
||||
/// </summary>
|
||||
public void Write(bool value)
|
||||
{
|
||||
EnsureBufferSize(m_bitLength + 1);
|
||||
@@ -124,9 +124,9 @@ namespace Lidgren.Network
|
||||
m_bitLength += 1;
|
||||
}
|
||||
|
||||
//
|
||||
// 8 bit
|
||||
//
|
||||
/// <summary>
|
||||
/// Write a byte
|
||||
/// </summary>
|
||||
public void Write(byte source)
|
||||
{
|
||||
EnsureBufferSize(m_bitLength + 8);
|
||||
@@ -134,6 +134,9 @@ namespace Lidgren.Network
|
||||
m_bitLength += 8;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a signed byte
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public void Write(sbyte source)
|
||||
{
|
||||
@@ -142,6 +145,9 @@ namespace Lidgren.Network
|
||||
m_bitLength += 8;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes 1 to 8 bits of a byte
|
||||
/// </summary>
|
||||
public void Write(byte source, int numberOfBits)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes all bytes in an array
|
||||
/// </summary>
|
||||
public void Write(byte[] source)
|
||||
{
|
||||
if (source == null)
|
||||
@@ -160,6 +169,9 @@ namespace Lidgren.Network
|
||||
m_bitLength += bits;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the specified number of bytes from an array
|
||||
/// </summary>
|
||||
public void Write(byte[] source, int offsetInBytes, int numberOfBytes)
|
||||
{
|
||||
if (source == null)
|
||||
@@ -170,9 +182,10 @@ namespace Lidgren.Network
|
||||
m_bitLength += bits;
|
||||
}
|
||||
|
||||
//
|
||||
// 16 bit
|
||||
//
|
||||
/// <summary>
|
||||
/// Writes an unsigned 16 bit integer
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
[CLSCompliant(false)]
|
||||
public void Write(UInt16 source)
|
||||
{
|
||||
@@ -181,6 +194,9 @@ namespace Lidgren.Network
|
||||
m_bitLength += 16;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes an unsigned integer using 1 to 16 bits
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public void Write(UInt16 source, int numberOfBits)
|
||||
{
|
||||
@@ -190,6 +206,9 @@ namespace Lidgren.Network
|
||||
m_bitLength += numberOfBits;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a signed 16 bit integer
|
||||
/// </summary>
|
||||
public void Write(Int16 source)
|
||||
{
|
||||
EnsureBufferSize(m_bitLength + 16);
|
||||
@@ -197,10 +216,10 @@ namespace Lidgren.Network
|
||||
m_bitLength += 16;
|
||||
}
|
||||
|
||||
//
|
||||
// 32 bit
|
||||
//
|
||||
#if UNSAFE
|
||||
/// <summary>
|
||||
/// Writes a 32 bit signed integer
|
||||
/// </summary>
|
||||
public unsafe void Write(Int32 source)
|
||||
{
|
||||
EnsureBufferSize(m_bitLength + 32);
|
||||
@@ -220,6 +239,9 @@ namespace Lidgren.Network
|
||||
m_bitLength += 32;
|
||||
}
|
||||
#else
|
||||
/// <summary>
|
||||
/// Writes a 32 bit signed integer
|
||||
/// </summary>
|
||||
public void Write(Int32 source)
|
||||
{
|
||||
EnsureBufferSize(m_bitLength + 32);
|
||||
@@ -229,6 +251,9 @@ namespace Lidgren.Network
|
||||
#endif
|
||||
|
||||
#if UNSAFE
|
||||
/// <summary>
|
||||
/// Writes a 32 bit unsigned integer
|
||||
/// </summary>
|
||||
public unsafe void Write(UInt32 source)
|
||||
{
|
||||
EnsureBufferSize(m_bitLength + 32);
|
||||
@@ -249,6 +274,9 @@ namespace Lidgren.Network
|
||||
m_bitLength += 32;
|
||||
}
|
||||
#else
|
||||
/// <summary>
|
||||
/// Writes a 32 bit unsigned integer
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public void Write(UInt32 source)
|
||||
{
|
||||
@@ -258,6 +286,9 @@ namespace Lidgren.Network
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Writes a 32 bit signed integer
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public void Write(UInt32 source, int numberOfBits)
|
||||
{
|
||||
@@ -267,6 +298,9 @@ namespace Lidgren.Network
|
||||
m_bitLength += numberOfBits;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a signed integer using 1 to 32 bits
|
||||
/// </summary>
|
||||
public void Write(Int32 source, int numberOfBits)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
//
|
||||
// 64 bit
|
||||
//
|
||||
/// <summary>
|
||||
/// Writes a 64 bit unsigned integer
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public void Write(UInt64 source)
|
||||
{
|
||||
@@ -298,6 +332,9 @@ namespace Lidgren.Network
|
||||
m_bitLength += 64;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes an unsigned integer using 1 to 64 bits
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public void Write(UInt64 source, int numberOfBits)
|
||||
{
|
||||
@@ -306,6 +343,9 @@ namespace Lidgren.Network
|
||||
m_bitLength += numberOfBits;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a 64 bit signed integer
|
||||
/// </summary>
|
||||
public void Write(Int64 source)
|
||||
{
|
||||
EnsureBufferSize(m_bitLength + 64);
|
||||
@@ -314,6 +354,9 @@ namespace Lidgren.Network
|
||||
m_bitLength += 64;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a signed integer using 1 to 64 bits
|
||||
/// </summary>
|
||||
public void Write(Int64 source, int numberOfBits)
|
||||
{
|
||||
EnsureBufferSize(m_bitLength + numberOfBits);
|
||||
@@ -326,6 +369,9 @@ namespace Lidgren.Network
|
||||
// Floating point
|
||||
//
|
||||
#if UNSAFE
|
||||
/// <summary>
|
||||
/// Writes a 32 bit floating point value
|
||||
/// </summary>
|
||||
public unsafe void Write(float source)
|
||||
{
|
||||
uint val = *((uint*)&source);
|
||||
@@ -335,6 +381,9 @@ namespace Lidgren.Network
|
||||
Write(val);
|
||||
}
|
||||
#else
|
||||
/// <summary>
|
||||
/// Writes a 32 bit floating point value
|
||||
/// </summary>
|
||||
public void Write(float source)
|
||||
{
|
||||
byte[] val = BitConverter.GetBytes(source);
|
||||
@@ -352,6 +401,9 @@ namespace Lidgren.Network
|
||||
#endif
|
||||
|
||||
#if UNSAFE
|
||||
/// <summary>
|
||||
/// Writes a 64 bit floating point value
|
||||
/// </summary>
|
||||
public unsafe void Write(double source)
|
||||
{
|
||||
ulong val = *((ulong*)&source);
|
||||
@@ -361,6 +413,9 @@ namespace Lidgren.Network
|
||||
Write(val);
|
||||
}
|
||||
#else
|
||||
/// <summary>
|
||||
/// Writes a 64 bit floating point value
|
||||
/// </summary>
|
||||
public void Write(double source)
|
||||
{
|
||||
byte[] val = BitConverter.GetBytes(source);
|
||||
|
||||
@@ -71,6 +71,13 @@ namespace Lidgren.Network
|
||||
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)
|
||||
{
|
||||
if (msg == null)
|
||||
|
||||
@@ -85,6 +85,9 @@ namespace Lidgren.Network
|
||||
/// </summary>
|
||||
public NetPeerConfiguration Configuration { get { return m_configuration; } }
|
||||
|
||||
/// <summary>
|
||||
/// NetPeer constructor
|
||||
/// </summary>
|
||||
public NetPeer(NetPeerConfiguration config)
|
||||
{
|
||||
m_configuration = config;
|
||||
@@ -132,6 +135,9 @@ namespace Lidgren.Network
|
||||
Thread.Sleep(10);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the connection, if any, for a certain remote endpoint
|
||||
/// </summary>
|
||||
public NetConnection GetConnection(IPEndPoint ep)
|
||||
{
|
||||
NetConnection retval;
|
||||
@@ -253,6 +259,9 @@ namespace Lidgren.Network
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
/// <summary>
|
||||
/// Send raw bytes; only used for debugging
|
||||
/// </summary>
|
||||
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.
|
||||
|
||||
@@ -59,6 +59,9 @@ namespace Lidgren.Network
|
||||
internal float m_expandMTUFrequency;
|
||||
internal int m_expandMTUFailAttempts;
|
||||
|
||||
/// <summary>
|
||||
/// NetPeerConfiguration constructor
|
||||
/// </summary>
|
||||
public NetPeerConfiguration(string appIdentifier)
|
||||
{
|
||||
if (string.IsNullOrEmpty(appIdentifier))
|
||||
|
||||
@@ -57,6 +57,9 @@ namespace Lidgren.Network
|
||||
/// </summary>
|
||||
public int Capacity { get { return m_items.Length; } }
|
||||
|
||||
/// <summary>
|
||||
/// NetQueue constructor
|
||||
/// </summary>
|
||||
public NetQueue(int initialCapacity)
|
||||
{
|
||||
m_lock = new object();
|
||||
|
||||
@@ -72,6 +72,9 @@ namespace Lidgren.Network
|
||||
Reinitialise(seed);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a semi-random seed based on an object
|
||||
/// </summary>
|
||||
public int GetSeed(object forObject)
|
||||
{
|
||||
// mix some semi-random properties
|
||||
|
||||
@@ -123,6 +123,9 @@ namespace Lidgren.Network
|
||||
return B.ToByteArrayUnsigned();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compute intermediate value U
|
||||
/// </summary>
|
||||
public static byte[] ComputeU(byte[] clientPublicEphemeral, byte[] serverPublicEphemeral)
|
||||
{
|
||||
// u = SHA-1(A || B)
|
||||
@@ -140,6 +143,9 @@ namespace Lidgren.Network
|
||||
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)
|
||||
{
|
||||
// S = (Av^u) ^ b (mod N)
|
||||
@@ -153,6 +159,9 @@ namespace Lidgren.Network
|
||||
return retval.ToByteArrayUnsigned();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes the client session value
|
||||
/// </summary>
|
||||
public static byte[] ComputeClientSessionValue(byte[] serverPublicEphemeral, byte[] xdata, byte[] udata, byte[] clientPrivateEphemeral)
|
||||
{
|
||||
// (B - kg^x) ^ (a + ux) (mod N)
|
||||
|
||||
@@ -8,6 +8,9 @@ namespace Lidgren.Network
|
||||
/// </summary>
|
||||
public class NetServer : NetPeer
|
||||
{
|
||||
/// <summary>
|
||||
/// NetServer constructor
|
||||
/// </summary>
|
||||
public NetServer(NetPeerConfiguration config)
|
||||
: base(config)
|
||||
{
|
||||
|
||||
@@ -118,6 +118,9 @@ namespace Lidgren.Network
|
||||
return best;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the physical (MAC) address for the first usable network interface
|
||||
/// </summary>
|
||||
public static PhysicalAddress GetMacAddress()
|
||||
{
|
||||
NetworkInterface ni = GetNetworkInterface();
|
||||
@@ -126,11 +129,17 @@ namespace Lidgren.Network
|
||||
return ni.GetPhysicalAddress();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a hex string from an Int64 value
|
||||
/// </summary>
|
||||
public static string ToHexString(long data)
|
||||
{
|
||||
return ToHexString(BitConverter.GetBytes(data));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a hex string from an array of bytes
|
||||
/// </summary>
|
||||
public static string ToHexString(byte[] data)
|
||||
{
|
||||
char[] c = new char[data.Length * 2];
|
||||
@@ -283,6 +292,9 @@ namespace Lidgren.Network
|
||||
return retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the window size used internally in the library for a certain delivery method
|
||||
/// </summary>
|
||||
public static int GetWindowSize(NetDeliveryMethod method)
|
||||
{
|
||||
switch (method)
|
||||
|
||||
@@ -49,6 +49,9 @@ namespace UnitTests
|
||||
Console.ReadKey();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper method
|
||||
/// </summary>
|
||||
public static NetIncomingMessage CreateIncomingMessage(byte[] fromData, int bitLength)
|
||||
{
|
||||
NetIncomingMessage inc = (NetIncomingMessage)Activator.CreateInstance(typeof(NetIncomingMessage), true);
|
||||
|
||||
Reference in New Issue
Block a user