You've already forked lidgren-network-gen3
mirror of
https://github.com/lidgren/lidgren-network-gen3.git
synced 2026-05-15 14:46:29 +09:00
NetIncomingMessage and NetOutgoingMessage common parts unified in NetBuffer; which is now a base class for the former
This commit is contained in:
@@ -67,6 +67,12 @@
|
||||
<Compile Include="NetBigInteger.cs" />
|
||||
<Compile Include="NetBitVector.cs" />
|
||||
<Compile Include="NetBitWriter.cs" />
|
||||
<Compile Include="NetBuffer.cs" />
|
||||
<Compile Include="NetBuffer.Peek.cs" />
|
||||
<Compile Include="NetBuffer.Read.cs" />
|
||||
<Compile Include="NetBuffer.Read.Reflection.cs" />
|
||||
<Compile Include="NetBuffer.Write.cs" />
|
||||
<Compile Include="NetBuffer.Write.Reflection.cs" />
|
||||
<Compile Include="NetClient.cs" />
|
||||
<Compile Include="NetConnection.cs" />
|
||||
<Compile Include="NetConnection.Handshake.cs" />
|
||||
@@ -79,16 +85,10 @@
|
||||
<Compile Include="NetException.cs" />
|
||||
<Compile Include="NetFragmentationHelper.cs" />
|
||||
<Compile Include="NetIncomingMessage.cs" />
|
||||
<Compile Include="NetIncomingMessage.Peek.cs" />
|
||||
<Compile Include="NetIncomingMessage.Read.cs" />
|
||||
<Compile Include="NetIncomingMessage.Read.Reflection.cs" />
|
||||
<Compile Include="NetIncomingMessage.Write.cs" />
|
||||
<Compile Include="NetIncomingMessageType.cs" />
|
||||
<Compile Include="NetMessageType.cs" />
|
||||
<Compile Include="NetNatIntroduction.cs" />
|
||||
<Compile Include="NetOutgoingMessage.cs" />
|
||||
<Compile Include="NetOutgoingMessage.Write.cs" />
|
||||
<Compile Include="NetOutgoingMessage.Write.Reflection.cs" />
|
||||
<Compile Include="NetPeer.cs" />
|
||||
<Compile Include="NetPeer.Discovery.cs" />
|
||||
<Compile Include="NetPeer.Fragmentation.cs" />
|
||||
|
||||
312
Lidgren.Network/NetBuffer.Peek.cs
Normal file
312
Lidgren.Network/NetBuffer.Peek.cs
Normal file
@@ -0,0 +1,312 @@
|
||||
/* Copyright (c) 2010 Michael Lidgren
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
and associated documentation files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom
|
||||
the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||
USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
*/
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Net;
|
||||
|
||||
namespace Lidgren.Network
|
||||
{
|
||||
public partial class NetBuffer
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the internal data buffer
|
||||
/// </summary>
|
||||
public byte[] PeekDataBuffer() { return m_data; }
|
||||
|
||||
//
|
||||
// 1 bit
|
||||
//
|
||||
/// <summary>
|
||||
/// Reads a 1-bit Boolean without advancing the read pointer
|
||||
/// </summary>
|
||||
public bool PeekBoolean()
|
||||
{
|
||||
NetException.Assert(m_bitLength - m_readPosition >= 1, c_readOverflowError);
|
||||
byte retval = NetBitWriter.ReadByte(m_data, 1, m_readPosition);
|
||||
return (retval > 0 ? true : false);
|
||||
}
|
||||
|
||||
//
|
||||
// 8 bit
|
||||
//
|
||||
/// <summary>
|
||||
/// Reads a Byte without advancing the read pointer
|
||||
/// </summary>
|
||||
public byte PeekByte()
|
||||
{
|
||||
NetException.Assert(m_bitLength - m_readPosition >= 8, c_readOverflowError);
|
||||
byte retval = NetBitWriter.ReadByte(m_data, 8, m_readPosition);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads an SByte without advancing the read pointer
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public sbyte PeekSByte()
|
||||
{
|
||||
NetException.Assert(m_bitLength - m_readPosition >= 8, c_readOverflowError);
|
||||
byte retval = NetBitWriter.ReadByte(m_data, 8, m_readPosition);
|
||||
return (sbyte)retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the specified number of bits into a Byte without advancing the read pointer
|
||||
/// </summary>
|
||||
public byte PeekByte(int numberOfBits)
|
||||
{
|
||||
byte retval = NetBitWriter.ReadByte(m_data, numberOfBits, m_readPosition);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the specified number of bytes without advancing the read pointer
|
||||
/// </summary>
|
||||
public byte[] PeekBytes(int numberOfBytes)
|
||||
{
|
||||
NetException.Assert(m_bitLength - m_readPosition >= (numberOfBytes * 8), c_readOverflowError);
|
||||
|
||||
byte[] retval = new byte[numberOfBytes];
|
||||
NetBitWriter.ReadBytes(m_data, numberOfBytes, m_readPosition, retval, 0);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the specified number of bytes without advancing the read pointer
|
||||
/// </summary>
|
||||
public void PeekBytes(byte[] into, int offset, int numberOfBytes)
|
||||
{
|
||||
NetException.Assert(m_bitLength - m_readPosition >= (numberOfBytes * 8), c_readOverflowError);
|
||||
NetException.Assert(offset + numberOfBytes <= into.Length);
|
||||
|
||||
NetBitWriter.ReadBytes(m_data, numberOfBytes, m_readPosition, into, offset);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// 16 bit
|
||||
//
|
||||
/// <summary>
|
||||
/// Reads an Int16 without advancing the read pointer
|
||||
/// </summary>
|
||||
public Int16 PeekInt16()
|
||||
{
|
||||
NetException.Assert(m_bitLength - m_readPosition >= 16, c_readOverflowError);
|
||||
uint retval = NetBitWriter.ReadUInt32(m_data, 16, m_readPosition);
|
||||
return (short)retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a UInt16 without advancing the read pointer
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public UInt16 PeekUInt16()
|
||||
{
|
||||
NetException.Assert(m_bitLength - m_readPosition >= 16, c_readOverflowError);
|
||||
uint retval = NetBitWriter.ReadUInt32(m_data, 16, m_readPosition);
|
||||
return (ushort)retval;
|
||||
}
|
||||
|
||||
//
|
||||
// 32 bit
|
||||
//
|
||||
/// <summary>
|
||||
/// Reads an Int32 without advancing the read pointer
|
||||
/// </summary>
|
||||
public Int32 PeekInt32()
|
||||
{
|
||||
NetException.Assert(m_bitLength - m_readPosition >= 32, c_readOverflowError);
|
||||
uint retval = NetBitWriter.ReadUInt32(m_data, 32, m_readPosition);
|
||||
return (Int32)retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the specified number of bits into an Int32 without advancing the read pointer
|
||||
/// </summary>
|
||||
public Int32 PeekInt32(int numberOfBits)
|
||||
{
|
||||
NetException.Assert((numberOfBits > 0 && numberOfBits <= 32), "ReadInt() can only read between 1 and 32 bits");
|
||||
NetException.Assert(m_bitLength - m_readPosition >= numberOfBits, c_readOverflowError);
|
||||
|
||||
uint retval = NetBitWriter.ReadUInt32(m_data, numberOfBits, m_readPosition);
|
||||
|
||||
if (numberOfBits == 32)
|
||||
return (int)retval;
|
||||
|
||||
int signBit = 1 << (numberOfBits - 1);
|
||||
if ((retval & signBit) == 0)
|
||||
return (int)retval; // positive
|
||||
|
||||
// negative
|
||||
unchecked
|
||||
{
|
||||
uint mask = ((uint)-1) >> (33 - numberOfBits);
|
||||
uint tmp = (retval & mask) + 1;
|
||||
return -((int)tmp);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a UInt32 without advancing the read pointer
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public UInt32 PeekUInt32()
|
||||
{
|
||||
NetException.Assert(m_bitLength - m_readPosition >= 32, c_readOverflowError);
|
||||
uint retval = NetBitWriter.ReadUInt32(m_data, 32, m_readPosition);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the specified number of bits into a UInt32 without advancing the read pointer
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public UInt32 PeekUInt32(int numberOfBits)
|
||||
{
|
||||
NetException.Assert((numberOfBits > 0 && numberOfBits <= 32), "ReadUInt() can only read between 1 and 32 bits");
|
||||
//NetException.Assert(m_bitLength - m_readBitPtr >= numberOfBits, "tried to read past buffer size");
|
||||
|
||||
UInt32 retval = NetBitWriter.ReadUInt32(m_data, numberOfBits, m_readPosition);
|
||||
return retval;
|
||||
}
|
||||
|
||||
//
|
||||
// 64 bit
|
||||
//
|
||||
/// <summary>
|
||||
/// Reads a UInt64 without advancing the read pointer
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public UInt64 PeekUInt64()
|
||||
{
|
||||
NetException.Assert(m_bitLength - m_readPosition >= 64, c_readOverflowError);
|
||||
|
||||
ulong low = NetBitWriter.ReadUInt32(m_data, 32, m_readPosition);
|
||||
ulong high = NetBitWriter.ReadUInt32(m_data, 32, m_readPosition + 32);
|
||||
|
||||
ulong retval = low + (high << 32);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads an Int64 without advancing the read pointer
|
||||
/// </summary>
|
||||
public Int64 PeekInt64()
|
||||
{
|
||||
NetException.Assert(m_bitLength - m_readPosition >= 64, c_readOverflowError);
|
||||
unchecked
|
||||
{
|
||||
ulong retval = PeekUInt64();
|
||||
long longRetval = (long)retval;
|
||||
return longRetval;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the specified number of bits into an UInt64 without advancing the read pointer
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public UInt64 PeekUInt64(int numberOfBits)
|
||||
{
|
||||
NetException.Assert((numberOfBits > 0 && numberOfBits <= 64), "ReadUInt() can only read between 1 and 64 bits");
|
||||
NetException.Assert(m_bitLength - m_readPosition >= numberOfBits, c_readOverflowError);
|
||||
|
||||
ulong retval;
|
||||
if (numberOfBits <= 32)
|
||||
{
|
||||
retval = (ulong)NetBitWriter.ReadUInt32(m_data, numberOfBits, m_readPosition);
|
||||
}
|
||||
else
|
||||
{
|
||||
retval = NetBitWriter.ReadUInt32(m_data, 32, m_readPosition);
|
||||
retval |= NetBitWriter.ReadUInt32(m_data, numberOfBits - 32, m_readPosition) << 32;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the specified number of bits into an Int64 without advancing the read pointer
|
||||
/// </summary>
|
||||
public Int64 PeekInt64(int numberOfBits)
|
||||
{
|
||||
NetException.Assert(((numberOfBits > 0) && (numberOfBits < 65)), "ReadInt64(bits) can only read between 1 and 64 bits");
|
||||
return (long)PeekUInt64(numberOfBits);
|
||||
}
|
||||
|
||||
//
|
||||
// Floating point
|
||||
//
|
||||
/// <summary>
|
||||
/// Reads a 32-bit Single without advancing the read pointer
|
||||
/// </summary>
|
||||
public float PeekFloat()
|
||||
{
|
||||
return PeekSingle();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a 32-bit Single without advancing the read pointer
|
||||
/// </summary>
|
||||
public float PeekSingle()
|
||||
{
|
||||
NetException.Assert(m_bitLength - m_readPosition >= 32, c_readOverflowError);
|
||||
|
||||
if ((m_readPosition & 7) == 0) // read directly
|
||||
{
|
||||
float retval = BitConverter.ToSingle(m_data, m_readPosition >> 3);
|
||||
return retval;
|
||||
}
|
||||
|
||||
byte[] bytes = PeekBytes(4);
|
||||
return BitConverter.ToSingle(bytes, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a 64-bit Double without advancing the read pointer
|
||||
/// </summary>
|
||||
public double PeekDouble()
|
||||
{
|
||||
NetException.Assert(m_bitLength - m_readPosition >= 64, c_readOverflowError);
|
||||
|
||||
if ((m_readPosition & 7) == 0) // read directly
|
||||
{
|
||||
// read directly
|
||||
double retval = BitConverter.ToDouble(m_data, m_readPosition >> 3);
|
||||
return retval;
|
||||
}
|
||||
|
||||
byte[] bytes = PeekBytes(8);
|
||||
return BitConverter.ToDouble(bytes, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a string without advancing the read pointer
|
||||
/// </summary>
|
||||
public string PeekString()
|
||||
{
|
||||
int wasReadPosition = m_readPosition;
|
||||
string retval = ReadString();
|
||||
m_readPosition = wasReadPosition;
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
103
Lidgren.Network/NetBuffer.Read.Reflection.cs
Normal file
103
Lidgren.Network/NetBuffer.Read.Reflection.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
/* Copyright (c) 2010 Michael Lidgren
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
and associated documentation files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom
|
||||
the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||
USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Lidgren.Network
|
||||
{
|
||||
public partial class NetBuffer
|
||||
{
|
||||
/// <summary>
|
||||
/// Reads all public and private declared instance fields of the object in alphabetical order using reflection
|
||||
/// </summary>
|
||||
public void ReadAllFields(object target)
|
||||
{
|
||||
ReadAllFields(target, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads all fields with the specified binding of the object in alphabetical order using reflection
|
||||
/// </summary>
|
||||
public void ReadAllFields(object target, BindingFlags flags)
|
||||
{
|
||||
if (target == null)
|
||||
return;
|
||||
Type tp = target.GetType();
|
||||
|
||||
FieldInfo[] fields = tp.GetFields(flags);
|
||||
NetUtility.SortMembersList(fields);
|
||||
|
||||
foreach (FieldInfo fi in fields)
|
||||
{
|
||||
object value;
|
||||
|
||||
// find read method
|
||||
MethodInfo readMethod;
|
||||
if (s_readMethods.TryGetValue(fi.FieldType, out readMethod))
|
||||
{
|
||||
// read value
|
||||
value = readMethod.Invoke(this, null);
|
||||
|
||||
// set the value
|
||||
fi.SetValue(target, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads all public and private declared instance fields of the object in alphabetical order using reflection
|
||||
/// </summary>
|
||||
public void ReadAllProperties(object target)
|
||||
{
|
||||
ReadAllProperties(target, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads all fields with the specified binding of the object in alphabetical order using reflection
|
||||
/// </summary>
|
||||
public void ReadAllProperties(object target, BindingFlags flags)
|
||||
{
|
||||
if (target == null)
|
||||
throw new ArgumentNullException("target");
|
||||
|
||||
if (target == null)
|
||||
return;
|
||||
Type tp = target.GetType();
|
||||
|
||||
PropertyInfo[] fields = tp.GetProperties(flags);
|
||||
NetUtility.SortMembersList(fields);
|
||||
foreach (PropertyInfo fi in fields)
|
||||
{
|
||||
object value;
|
||||
|
||||
// find read method
|
||||
MethodInfo readMethod;
|
||||
if (s_readMethods.TryGetValue(fi.PropertyType, out readMethod))
|
||||
{
|
||||
// read value
|
||||
value = readMethod.Invoke(this, null);
|
||||
|
||||
// set the value
|
||||
MethodInfo setMethod = fi.GetSetMethod((flags & BindingFlags.NonPublic) == BindingFlags.NonPublic);
|
||||
setMethod.Invoke(target, new object[] { value });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
641
Lidgren.Network/NetBuffer.Read.cs
Normal file
641
Lidgren.Network/NetBuffer.Read.cs
Normal file
@@ -0,0 +1,641 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Reflection;
|
||||
using System.Net;
|
||||
|
||||
namespace Lidgren.Network
|
||||
{
|
||||
public partial class NetBuffer
|
||||
{
|
||||
private const string c_readOverflowError = "Trying to read past the buffer size - likely caused by mismatching Write/Reads, different size or order.";
|
||||
|
||||
/// <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);
|
||||
byte retval = NetBitWriter.ReadByte(m_data, 1, m_readPosition);
|
||||
m_readPosition += 1;
|
||||
return (retval > 0 ? true : false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a byte
|
||||
/// </summary>
|
||||
public byte ReadByte()
|
||||
{
|
||||
NetException.Assert(m_bitLength - m_readPosition >= 8, c_readOverflowError);
|
||||
byte retval = NetBitWriter.ReadByte(m_data, 8, m_readPosition);
|
||||
m_readPosition += 8;
|
||||
return retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a byte and returns true or false for success
|
||||
/// </summary>
|
||||
public bool ReadByte(out byte result)
|
||||
{
|
||||
if (m_bitLength - m_readPosition < 8)
|
||||
{
|
||||
result = 0;
|
||||
return false;
|
||||
}
|
||||
result = NetBitWriter.ReadByte(m_data, 8, m_readPosition);
|
||||
m_readPosition += 8;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a signed byte
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public sbyte ReadSByte()
|
||||
{
|
||||
NetException.Assert(m_bitLength - m_readPosition >= 8, c_readOverflowError);
|
||||
byte retval = NetBitWriter.ReadByte(m_data, 8, m_readPosition);
|
||||
m_readPosition += 8;
|
||||
return (sbyte)retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads 1 to 8 bits into a byte
|
||||
/// </summary>
|
||||
public byte ReadByte(int numberOfBits)
|
||||
{
|
||||
NetException.Assert(numberOfBits > 0 && numberOfBits <= 8, "ReadByte(bits) can only read between 1 and 8 bits");
|
||||
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);
|
||||
|
||||
byte[] retval = new byte[numberOfBytes];
|
||||
NetBitWriter.ReadBytes(m_data, numberOfBytes, m_readPosition, retval, 0);
|
||||
m_readPosition += (8 * numberOfBytes);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the specified number of bytes and returns true for success
|
||||
/// </summary>
|
||||
public bool ReadBytes(int numberOfBytes, out byte[] result)
|
||||
{
|
||||
if (m_bitLength - m_readPosition + 7 < (numberOfBytes * 8))
|
||||
{
|
||||
result = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
result = new byte[numberOfBytes];
|
||||
NetBitWriter.ReadBytes(m_data, numberOfBytes, m_readPosition, result, 0);
|
||||
m_readPosition += (8 * numberOfBytes);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <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);
|
||||
NetException.Assert(offset + numberOfBytes <= into.Length);
|
||||
|
||||
NetBitWriter.ReadBytes(m_data, numberOfBytes, m_readPosition, into, offset);
|
||||
m_readPosition += (8 * numberOfBytes);
|
||||
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);
|
||||
NetException.Assert(offset + NetUtility.BytesToHoldBits(numberOfBits) <= into.Length);
|
||||
|
||||
int numberOfWholeBytes = numberOfBits / 8;
|
||||
int extraBits = numberOfBits - (numberOfWholeBytes * 8);
|
||||
|
||||
NetBitWriter.ReadBytes(m_data, numberOfWholeBytes, m_readPosition, into, offset);
|
||||
m_readPosition += (8 * numberOfWholeBytes);
|
||||
|
||||
if (extraBits > 0)
|
||||
into[offset + numberOfWholeBytes] = ReadByte(extraBits);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a 16 bit signed integer written using Write(Int16)
|
||||
/// </summary>
|
||||
public Int16 ReadInt16()
|
||||
{
|
||||
NetException.Assert(m_bitLength - m_readPosition >= 16, c_readOverflowError);
|
||||
uint retval = NetBitWriter.ReadUInt32(m_data, 16, m_readPosition);
|
||||
m_readPosition += 16;
|
||||
return (short)retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a 16 bit unsigned integer written using Write(UInt16)
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public UInt16 ReadUInt16()
|
||||
{
|
||||
NetException.Assert(m_bitLength - m_readPosition >= 16, c_readOverflowError);
|
||||
uint retval = NetBitWriter.ReadUInt32(m_data, 16, m_readPosition);
|
||||
m_readPosition += 16;
|
||||
return (ushort)retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a 32 bit signed integer written using Write(Int32)
|
||||
/// </summary>
|
||||
public Int32 ReadInt32()
|
||||
{
|
||||
NetException.Assert(m_bitLength - m_readPosition >= 32, c_readOverflowError);
|
||||
uint retval = NetBitWriter.ReadUInt32(m_data, 32, m_readPosition);
|
||||
m_readPosition += 32;
|
||||
return (Int32)retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a 32 bit signed integer written using Write(Int32)
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public bool ReadInt32(out Int32 result)
|
||||
{
|
||||
if (m_bitLength - m_readPosition < 32)
|
||||
{
|
||||
result = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
result = (Int32)NetBitWriter.ReadUInt32(m_data, 32, m_readPosition);
|
||||
m_readPosition += 32;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <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, "ReadInt32(bits) can only read between 1 and 32 bits");
|
||||
NetException.Assert(m_bitLength - m_readPosition >= numberOfBits, c_readOverflowError);
|
||||
|
||||
uint retval = NetBitWriter.ReadUInt32(m_data, numberOfBits, m_readPosition);
|
||||
m_readPosition += numberOfBits;
|
||||
|
||||
if (numberOfBits == 32)
|
||||
return (int)retval;
|
||||
|
||||
int signBit = 1 << (numberOfBits - 1);
|
||||
if ((retval & signBit) == 0)
|
||||
return (int)retval; // positive
|
||||
|
||||
// negative
|
||||
unchecked
|
||||
{
|
||||
uint mask = ((uint)-1) >> (33 - numberOfBits);
|
||||
uint tmp = (retval & mask) + 1;
|
||||
return -((int)tmp);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads an 32 bit unsigned integer written using Write(UInt32)
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public UInt32 ReadUInt32()
|
||||
{
|
||||
NetException.Assert(m_bitLength - m_readPosition >= 32, c_readOverflowError);
|
||||
uint retval = NetBitWriter.ReadUInt32(m_data, 32, m_readPosition);
|
||||
m_readPosition += 32;
|
||||
return retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads an 32 bit unsigned integer written using Write(UInt32) and returns true for success
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public bool ReadUInt32(out UInt32 result)
|
||||
{
|
||||
if (m_bitLength - m_readPosition < 32)
|
||||
{
|
||||
result = 0;
|
||||
return false;
|
||||
}
|
||||
result = NetBitWriter.ReadUInt32(m_data, 32, m_readPosition);
|
||||
m_readPosition += 32;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads an unsigned integer stored in 1 to 32 bits, written using Write(UInt32, Int32)
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public UInt32 ReadUInt32(int numberOfBits)
|
||||
{
|
||||
NetException.Assert(numberOfBits > 0 && numberOfBits <= 32, "ReadUInt32(bits) can only read between 1 and 32 bits");
|
||||
//NetException.Assert(m_bitLength - m_readBitPtr >= numberOfBits, "tried to read past buffer size");
|
||||
|
||||
UInt32 retval = NetBitWriter.ReadUInt32(m_data, numberOfBits, m_readPosition);
|
||||
m_readPosition += numberOfBits;
|
||||
return retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a 64 bit unsigned integer written using Write(UInt64)
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public UInt64 ReadUInt64()
|
||||
{
|
||||
NetException.Assert(m_bitLength - m_readPosition >= 64, c_readOverflowError);
|
||||
|
||||
ulong low = NetBitWriter.ReadUInt32(m_data, 32, m_readPosition);
|
||||
m_readPosition += 32;
|
||||
ulong high = NetBitWriter.ReadUInt32(m_data, 32, m_readPosition);
|
||||
|
||||
ulong retval = low + (high << 32);
|
||||
|
||||
m_readPosition += 32;
|
||||
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);
|
||||
unchecked
|
||||
{
|
||||
ulong retval = ReadUInt64();
|
||||
long longRetval = (long)retval;
|
||||
return longRetval;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads an unsigned integer stored in 1 to 64 bits, written using Write(UInt64, Int32)
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public UInt64 ReadUInt64(int numberOfBits)
|
||||
{
|
||||
NetException.Assert(numberOfBits > 0 && numberOfBits <= 64, "ReadUInt64(bits) can only read between 1 and 64 bits");
|
||||
NetException.Assert(m_bitLength - m_readPosition >= numberOfBits, c_readOverflowError);
|
||||
|
||||
ulong retval;
|
||||
if (numberOfBits <= 32)
|
||||
{
|
||||
retval = (ulong)NetBitWriter.ReadUInt32(m_data, numberOfBits, m_readPosition);
|
||||
}
|
||||
else
|
||||
{
|
||||
retval = NetBitWriter.ReadUInt32(m_data, 32, m_readPosition);
|
||||
retval |= NetBitWriter.ReadUInt32(m_data, numberOfBits - 32, m_readPosition) << 32;
|
||||
}
|
||||
m_readPosition += numberOfBits;
|
||||
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 <= 64)), "ReadInt64(bits) can only read between 1 and 64 bits");
|
||||
return (long)ReadUInt64(numberOfBits);
|
||||
}
|
||||
|
||||
/// <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);
|
||||
|
||||
if ((m_readPosition & 7) == 0) // read directly
|
||||
{
|
||||
float retval = BitConverter.ToSingle(m_data, m_readPosition >> 3);
|
||||
m_readPosition += 32;
|
||||
return retval;
|
||||
}
|
||||
|
||||
byte[] bytes = ReadBytes(4);
|
||||
return BitConverter.ToSingle(bytes, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a 32 bit floating point value written using Write(Single)
|
||||
/// </summary>
|
||||
public bool ReadSingle(out float result)
|
||||
{
|
||||
if (m_bitLength - m_readPosition < 32)
|
||||
{
|
||||
result = 0.0f;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((m_readPosition & 7) == 0) // read directly
|
||||
{
|
||||
result = BitConverter.ToSingle(m_data, m_readPosition >> 3);
|
||||
m_readPosition += 32;
|
||||
return true;
|
||||
}
|
||||
|
||||
byte[] bytes = ReadBytes(4);
|
||||
result = BitConverter.ToSingle(bytes, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <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);
|
||||
|
||||
if ((m_readPosition & 7) == 0) // read directly
|
||||
{
|
||||
// read directly
|
||||
double retval = BitConverter.ToDouble(m_data, m_readPosition >> 3);
|
||||
m_readPosition += 64;
|
||||
return retval;
|
||||
}
|
||||
|
||||
byte[] bytes = ReadBytes(8);
|
||||
return BitConverter.ToDouble(bytes, 0);
|
||||
}
|
||||
|
||||
//
|
||||
// Variable bit count
|
||||
//
|
||||
|
||||
/// <summary>
|
||||
/// Reads a variable sized UInt32 written using WriteVariableUInt32()
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public uint ReadVariableUInt32()
|
||||
{
|
||||
int num1 = 0;
|
||||
int num2 = 0;
|
||||
while (true)
|
||||
{
|
||||
byte num3 = this.ReadByte();
|
||||
num1 |= (num3 & 0x7f) << num2;
|
||||
num2 += 7;
|
||||
if ((num3 & 0x80) == 0)
|
||||
return (uint)num1;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a variable sized UInt32 written using WriteVariableUInt32() and returns true for success
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public bool ReadVariableUInt32(out uint result)
|
||||
{
|
||||
int num1 = 0;
|
||||
int num2 = 0;
|
||||
while (true)
|
||||
{
|
||||
byte num3;
|
||||
if (ReadByte(out num3) == false)
|
||||
{
|
||||
result = 0;
|
||||
return false;
|
||||
}
|
||||
num1 |= (num3 & 0x7f) << num2;
|
||||
num2 += 7;
|
||||
if ((num3 & 0x80) == 0)
|
||||
{
|
||||
result = (uint)num1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a variable sized Int32 written using WriteVariableInt32()
|
||||
/// </summary>
|
||||
public int ReadVariableInt32()
|
||||
{
|
||||
uint n = ReadVariableUInt32();
|
||||
return (int)(n >> 1) ^ -(int)(n & 1); // decode zigzag
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a variable sized Int64 written using WriteVariableInt64()
|
||||
/// </summary>
|
||||
public Int64 ReadVariableInt64()
|
||||
{
|
||||
UInt64 n = ReadVariableUInt64();
|
||||
return (Int64)(n >> 1) ^ -(long)(n & 1); // decode zigzag
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a variable sized UInt32 written using WriteVariableInt64()
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public UInt64 ReadVariableUInt64()
|
||||
{
|
||||
UInt64 num1 = 0;
|
||||
int num2 = 0;
|
||||
while (true)
|
||||
{
|
||||
//if (num2 == 0x23)
|
||||
// throw new FormatException("Bad 7-bit encoded integer");
|
||||
|
||||
byte num3 = this.ReadByte();
|
||||
num1 |= ((UInt64)num3 & 0x7f) << num2;
|
||||
num2 += 7;
|
||||
if ((num3 & 0x80) == 0)
|
||||
return num1;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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);
|
||||
int maxVal = (1 << numberOfBits) - 1;
|
||||
return ((float)(encodedVal + 1) / (float)(maxVal + 1) - 0.5f) * 2.0f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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);
|
||||
int maxVal = (1 << numberOfBits) - 1;
|
||||
return (float)(encodedVal + 1) / (float)(maxVal + 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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;
|
||||
int maxVal = (1 << numberOfBits) - 1;
|
||||
float encodedVal = (float)ReadUInt32(numberOfBits);
|
||||
float unit = encodedVal / (float)maxVal;
|
||||
return min + (unit * range);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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);
|
||||
int numBits = NetUtility.BitsToHoldUInt(range);
|
||||
|
||||
uint rvalue = ReadUInt32(numBits);
|
||||
return (int)(min + rvalue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a string written using Write(string)
|
||||
/// </summary>
|
||||
public string ReadString()
|
||||
{
|
||||
int byteLen = (int)ReadVariableUInt32();
|
||||
|
||||
if (byteLen == 0)
|
||||
return String.Empty;
|
||||
|
||||
NetException.Assert(m_bitLength - m_readPosition >= (byteLen * 8), c_readOverflowError);
|
||||
|
||||
if ((m_readPosition & 7) == 0)
|
||||
{
|
||||
// read directly
|
||||
string retval = System.Text.Encoding.UTF8.GetString(m_data, m_readPosition >> 3, byteLen);
|
||||
m_readPosition += (8 * byteLen);
|
||||
return retval;
|
||||
}
|
||||
|
||||
byte[] bytes = ReadBytes(byteLen);
|
||||
return System.Text.Encoding.UTF8.GetString(bytes, 0, bytes.Length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a string written using Write(string) and returns true for success
|
||||
/// </summary>
|
||||
public bool ReadString(out string result)
|
||||
{
|
||||
uint byteLen;
|
||||
if (ReadVariableUInt32(out byteLen) == false)
|
||||
{
|
||||
result = String.Empty;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (byteLen == 0)
|
||||
{
|
||||
result = String.Empty;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (m_bitLength - m_readPosition < (byteLen * 8))
|
||||
{
|
||||
result = String.Empty;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((m_readPosition & 7) == 0)
|
||||
{
|
||||
// read directly
|
||||
result = System.Text.Encoding.UTF8.GetString(m_data, m_readPosition >> 3, (int)byteLen);
|
||||
m_readPosition += (8 * (int)byteLen);
|
||||
return true;
|
||||
}
|
||||
|
||||
byte[] bytes;
|
||||
if (ReadBytes((int)byteLen, out bytes) == false)
|
||||
{
|
||||
result = String.Empty;
|
||||
return false;
|
||||
}
|
||||
|
||||
result = System.Text.Encoding.UTF8.GetString(bytes, 0, bytes.Length);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a stored IPv4 endpoint description
|
||||
/// </summary>
|
||||
public IPEndPoint ReadIPEndpoint()
|
||||
{
|
||||
byte len = ReadByte();
|
||||
byte[] addressBytes = ReadBytes(len);
|
||||
int port = (int)ReadUInt16();
|
||||
|
||||
IPAddress address = new IPAddress(addressBytes);
|
||||
return new IPEndPoint(address, port);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pads data with enough bits to reach a full byte. Decreases cpu usage for subsequent byte writes.
|
||||
/// </summary>
|
||||
public void SkipPadBits()
|
||||
{
|
||||
m_readPosition = ((m_readPosition + 7) >> 3) * 8;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pads data with enough bits to reach a full byte. Decreases cpu usage for subsequent byte writes.
|
||||
/// </summary>
|
||||
public void ReadPadBits()
|
||||
{
|
||||
m_readPosition = ((m_readPosition + 7) >> 3) * 8;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pads data with the specified number of bits.
|
||||
/// </summary>
|
||||
public void SkipPadBits(int numberOfBits)
|
||||
{
|
||||
m_readPosition += numberOfBits;
|
||||
}
|
||||
}
|
||||
}
|
||||
91
Lidgren.Network/NetBuffer.Write.Reflection.cs
Normal file
91
Lidgren.Network/NetBuffer.Write.Reflection.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
/* Copyright (c) 2010 Michael Lidgren
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
and associated documentation files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom
|
||||
the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||
USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Lidgren.Network
|
||||
{
|
||||
public partial class NetBuffer
|
||||
{
|
||||
/// <summary>
|
||||
/// Writes all public and private declared instance fields of the object in alphabetical order using reflection
|
||||
/// </summary>
|
||||
public void WriteAllFields(object ob)
|
||||
{
|
||||
WriteAllFields(ob, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes all fields with specified binding in alphabetical order using reflection
|
||||
/// </summary>
|
||||
public void WriteAllFields(object ob, BindingFlags flags)
|
||||
{
|
||||
if (ob == null)
|
||||
return;
|
||||
Type tp = ob.GetType();
|
||||
|
||||
FieldInfo[] fields = tp.GetFields(flags);
|
||||
NetUtility.SortMembersList(fields);
|
||||
|
||||
foreach (FieldInfo fi in fields)
|
||||
{
|
||||
object value = fi.GetValue(ob);
|
||||
|
||||
// find the appropriate Write method
|
||||
MethodInfo writeMethod;
|
||||
if (s_writeMethods.TryGetValue(fi.FieldType, out writeMethod))
|
||||
writeMethod.Invoke(this, new object[] { value });
|
||||
else
|
||||
throw new NetException("Failed to find write method for type " + fi.FieldType);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes all public and private declared instance properties of the object in alphabetical order using reflection
|
||||
/// </summary>
|
||||
public void WriteAllProperties(object ob)
|
||||
{
|
||||
WriteAllProperties(ob, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes all properties with specified binding in alphabetical order using reflection
|
||||
/// </summary>
|
||||
public void WriteAllProperties(object ob, BindingFlags flags)
|
||||
{
|
||||
if (ob == null)
|
||||
return;
|
||||
Type tp = ob.GetType();
|
||||
|
||||
PropertyInfo[] fields = tp.GetProperties(flags);
|
||||
NetUtility.SortMembersList(fields);
|
||||
|
||||
foreach (PropertyInfo fi in fields)
|
||||
{
|
||||
MethodInfo getMethod = fi.GetGetMethod((flags & BindingFlags.NonPublic) == BindingFlags.NonPublic);
|
||||
object value = getMethod.Invoke(ob, null);
|
||||
|
||||
// find the appropriate Write method
|
||||
MethodInfo writeMethod;
|
||||
if (s_writeMethods.TryGetValue(fi.PropertyType, out writeMethod))
|
||||
writeMethod.Invoke(this, new object[] { value });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
614
Lidgren.Network/NetBuffer.Write.cs
Normal file
614
Lidgren.Network/NetBuffer.Write.cs
Normal file
@@ -0,0 +1,614 @@
|
||||
/* Copyright (c) 2010 Michael Lidgren
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
and associated documentation files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom
|
||||
the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||
USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Lidgren.Network
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public struct SingleUIntUnion
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public float SingleValue;
|
||||
|
||||
[FieldOffset(0)]
|
||||
[CLSCompliant(false)]
|
||||
public uint UIntValue;
|
||||
}
|
||||
|
||||
public partial class NetBuffer
|
||||
{
|
||||
/// <summary>
|
||||
/// Ensures the buffer can hold this number of bits
|
||||
/// </summary>
|
||||
public void EnsureBufferSize(int numberOfBits)
|
||||
{
|
||||
int byteLen = ((numberOfBits + 7) >> 3);
|
||||
if (m_data == null)
|
||||
{
|
||||
m_data = new byte[byteLen + c_overAllocateAmount];
|
||||
return;
|
||||
}
|
||||
if (m_data.Length < byteLen)
|
||||
Array.Resize<byte>(ref m_data, byteLen + c_overAllocateAmount);
|
||||
return;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensures the buffer can hold this number of bits
|
||||
/// </summary>
|
||||
internal void InternalEnsureBufferSize(int numberOfBits)
|
||||
{
|
||||
int byteLen = ((numberOfBits + 7) >> 3);
|
||||
if (m_data == null)
|
||||
{
|
||||
m_data = new byte[byteLen];
|
||||
return;
|
||||
}
|
||||
if (m_data.Length < byteLen)
|
||||
Array.Resize<byte>(ref m_data, byteLen);
|
||||
return;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a boolean value using 1 bit
|
||||
/// </summary>
|
||||
public void Write(bool value)
|
||||
{
|
||||
EnsureBufferSize(m_bitLength + 1);
|
||||
NetBitWriter.WriteByte((value ? (byte)1 : (byte)0), 1, m_data, m_bitLength);
|
||||
m_bitLength += 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write a byte
|
||||
/// </summary>
|
||||
public void Write(byte source)
|
||||
{
|
||||
EnsureBufferSize(m_bitLength + 8);
|
||||
NetBitWriter.WriteByte(source, 8, m_data, m_bitLength);
|
||||
m_bitLength += 8;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a signed byte
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public void Write(sbyte source)
|
||||
{
|
||||
EnsureBufferSize(m_bitLength + 8);
|
||||
NetBitWriter.WriteByte((byte)source, 8, m_data, m_bitLength);
|
||||
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");
|
||||
EnsureBufferSize(m_bitLength + numberOfBits);
|
||||
NetBitWriter.WriteByte(source, numberOfBits, m_data, m_bitLength);
|
||||
m_bitLength += numberOfBits;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes all bytes in an array
|
||||
/// </summary>
|
||||
public void Write(byte[] source)
|
||||
{
|
||||
if (source == null)
|
||||
throw new ArgumentNullException("source");
|
||||
int bits = source.Length * 8;
|
||||
EnsureBufferSize(m_bitLength + bits);
|
||||
NetBitWriter.WriteBytes(source, 0, source.Length, m_data, m_bitLength);
|
||||
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)
|
||||
throw new ArgumentNullException("source");
|
||||
int bits = numberOfBytes * 8;
|
||||
EnsureBufferSize(m_bitLength + bits);
|
||||
NetBitWriter.WriteBytes(source, offsetInBytes, numberOfBytes, m_data, m_bitLength);
|
||||
m_bitLength += bits;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes an unsigned 16 bit integer
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
[CLSCompliant(false)]
|
||||
public void Write(UInt16 source)
|
||||
{
|
||||
EnsureBufferSize(m_bitLength + 16);
|
||||
NetBitWriter.WriteUInt32((uint)source, 16, m_data, m_bitLength);
|
||||
m_bitLength += 16;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes an unsigned integer using 1 to 16 bits
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public void Write(UInt16 source, int numberOfBits)
|
||||
{
|
||||
NetException.Assert((numberOfBits > 0 && numberOfBits <= 16), "Write(ushort, numberOfBits) can only write between 1 and 16 bits");
|
||||
EnsureBufferSize(m_bitLength + numberOfBits);
|
||||
NetBitWriter.WriteUInt32((uint)source, numberOfBits, m_data, m_bitLength);
|
||||
m_bitLength += numberOfBits;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a signed 16 bit integer
|
||||
/// </summary>
|
||||
public void Write(Int16 source)
|
||||
{
|
||||
EnsureBufferSize(m_bitLength + 16);
|
||||
NetBitWriter.WriteUInt32((uint)source, 16, m_data, m_bitLength);
|
||||
m_bitLength += 16;
|
||||
}
|
||||
|
||||
#if UNSAFE
|
||||
/// <summary>
|
||||
/// Writes a 32 bit signed integer
|
||||
/// </summary>
|
||||
public unsafe void Write(Int32 source)
|
||||
{
|
||||
EnsureBufferSize(m_bitLength + 32);
|
||||
|
||||
// can write fast?
|
||||
if (m_bitLength % 8 == 0)
|
||||
{
|
||||
fixed (byte* numRef = &Data[m_bitLength / 8])
|
||||
{
|
||||
*((int*)numRef) = source;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NetBitWriter.WriteUInt32((UInt32)source, 32, Data, m_bitLength);
|
||||
}
|
||||
m_bitLength += 32;
|
||||
}
|
||||
#else
|
||||
/// <summary>
|
||||
/// Writes a 32 bit signed integer
|
||||
/// </summary>
|
||||
public void Write(Int32 source)
|
||||
{
|
||||
EnsureBufferSize(m_bitLength + 32);
|
||||
NetBitWriter.WriteUInt32((UInt32)source, 32, m_data, m_bitLength);
|
||||
m_bitLength += 32;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if UNSAFE
|
||||
/// <summary>
|
||||
/// Writes a 32 bit unsigned integer
|
||||
/// </summary>
|
||||
public unsafe void Write(UInt32 source)
|
||||
{
|
||||
EnsureBufferSize(m_bitLength + 32);
|
||||
|
||||
// can write fast?
|
||||
if (m_bitLength % 8 == 0)
|
||||
{
|
||||
fixed (byte* numRef = &Data[m_bitLength / 8])
|
||||
{
|
||||
*((uint*)numRef) = source;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NetBitWriter.WriteUInt32(source, 32, Data, m_bitLength);
|
||||
}
|
||||
|
||||
m_bitLength += 32;
|
||||
}
|
||||
#else
|
||||
/// <summary>
|
||||
/// Writes a 32 bit unsigned integer
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public void Write(UInt32 source)
|
||||
{
|
||||
EnsureBufferSize(m_bitLength + 32);
|
||||
NetBitWriter.WriteUInt32(source, 32, m_data, m_bitLength);
|
||||
m_bitLength += 32;
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Writes a 32 bit signed integer
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public void Write(UInt32 source, int numberOfBits)
|
||||
{
|
||||
NetException.Assert((numberOfBits > 0 && numberOfBits <= 32), "Write(uint, numberOfBits) can only write between 1 and 32 bits");
|
||||
EnsureBufferSize(m_bitLength + numberOfBits);
|
||||
NetBitWriter.WriteUInt32(source, numberOfBits, m_data, m_bitLength);
|
||||
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");
|
||||
EnsureBufferSize(m_bitLength + numberOfBits);
|
||||
|
||||
if (numberOfBits != 32)
|
||||
{
|
||||
// make first bit sign
|
||||
int signBit = 1 << (numberOfBits - 1);
|
||||
if (source < 0)
|
||||
source = (-source - 1) | signBit;
|
||||
else
|
||||
source &= (~signBit);
|
||||
}
|
||||
|
||||
NetBitWriter.WriteUInt32((uint)source, numberOfBits, m_data, m_bitLength);
|
||||
|
||||
m_bitLength += numberOfBits;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a 64 bit unsigned integer
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public void Write(UInt64 source)
|
||||
{
|
||||
EnsureBufferSize(m_bitLength + 64);
|
||||
NetBitWriter.WriteUInt64(source, 64, m_data, m_bitLength);
|
||||
m_bitLength += 64;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes an unsigned integer using 1 to 64 bits
|
||||
/// </summary>
|
||||
[CLSCompliant(false)]
|
||||
public void Write(UInt64 source, int numberOfBits)
|
||||
{
|
||||
EnsureBufferSize(m_bitLength + numberOfBits);
|
||||
NetBitWriter.WriteUInt64(source, numberOfBits, m_data, m_bitLength);
|
||||
m_bitLength += numberOfBits;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a 64 bit signed integer
|
||||
/// </summary>
|
||||
public void Write(Int64 source)
|
||||
{
|
||||
EnsureBufferSize(m_bitLength + 64);
|
||||
ulong usource = (ulong)source;
|
||||
NetBitWriter.WriteUInt64(usource, 64, m_data, m_bitLength);
|
||||
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);
|
||||
ulong usource = (ulong)source;
|
||||
NetBitWriter.WriteUInt64(usource, numberOfBits, m_data, m_bitLength);
|
||||
m_bitLength += numberOfBits;
|
||||
}
|
||||
|
||||
//
|
||||
// Floating point
|
||||
//
|
||||
#if UNSAFE
|
||||
/// <summary>
|
||||
/// Writes a 32 bit floating point value
|
||||
/// </summary>
|
||||
public unsafe void Write(float source)
|
||||
{
|
||||
uint val = *((uint*)&source);
|
||||
#if BIGENDIAN
|
||||
val = NetUtility.SwapByteOrder(val);
|
||||
#endif
|
||||
Write(val);
|
||||
}
|
||||
#else
|
||||
/// <summary>
|
||||
/// Writes a 32 bit floating point value
|
||||
/// </summary>
|
||||
public void Write(float source)
|
||||
{
|
||||
// Use union to avoid BitConverter.GetBytes() which allocates memory on the heap
|
||||
SingleUIntUnion su;
|
||||
su.UIntValue = 0; // must initialize every member of the union to avoid warning
|
||||
su.SingleValue = source;
|
||||
|
||||
#if BIGENDIAN
|
||||
// swap byte order
|
||||
su.UIntValue = NetUtility.SwapByteOrder(su.UIntValue);
|
||||
#endif
|
||||
Write(su.UIntValue);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if UNSAFE
|
||||
/// <summary>
|
||||
/// Writes a 64 bit floating point value
|
||||
/// </summary>
|
||||
public unsafe void Write(double source)
|
||||
{
|
||||
ulong val = *((ulong*)&source);
|
||||
#if BIGENDIAN
|
||||
val = NetUtility.SwapByteOrder(val);
|
||||
#endif
|
||||
Write(val);
|
||||
}
|
||||
#else
|
||||
/// <summary>
|
||||
/// Writes a 64 bit floating point value
|
||||
/// </summary>
|
||||
public void Write(double source)
|
||||
{
|
||||
byte[] val = BitConverter.GetBytes(source);
|
||||
#if BIGENDIAN
|
||||
// 0 1 2 3 4 5 6 7
|
||||
|
||||
// swap byte order
|
||||
byte tmp = val[7];
|
||||
val[7] = val[0];
|
||||
val[0] = tmp;
|
||||
|
||||
tmp = val[6];
|
||||
val[6] = val[1];
|
||||
val[1] = tmp;
|
||||
|
||||
tmp = val[5];
|
||||
val[5] = val[2];
|
||||
val[2] = tmp;
|
||||
|
||||
tmp = val[4];
|
||||
val[4] = val[3];
|
||||
val[3] = tmp;
|
||||
#endif
|
||||
Write(val);
|
||||
}
|
||||
#endif
|
||||
|
||||
//
|
||||
// Variable bits
|
||||
//
|
||||
|
||||
/// <summary>
|
||||
/// Write Base128 encoded variable sized unsigned integer of up to 32 bits
|
||||
/// </summary>
|
||||
/// <returns>number of bytes written</returns>
|
||||
[CLSCompliant(false)]
|
||||
public int WriteVariableUInt32(uint value)
|
||||
{
|
||||
int retval = 1;
|
||||
uint num1 = (uint)value;
|
||||
while (num1 >= 0x80)
|
||||
{
|
||||
this.Write((byte)(num1 | 0x80));
|
||||
num1 = num1 >> 7;
|
||||
retval++;
|
||||
}
|
||||
this.Write((byte)num1);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write Base128 encoded variable sized signed integer of up to 32 bits
|
||||
/// </summary>
|
||||
/// <returns>number of bytes written</returns>
|
||||
public int WriteVariableInt32(int value)
|
||||
{
|
||||
uint zigzag = (uint)(value << 1) ^ (uint)(value >> 31);
|
||||
return WriteVariableUInt32(zigzag);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write Base128 encoded variable sized signed integer of up to 64 bits
|
||||
/// </summary>
|
||||
/// <returns>number of bytes written</returns>
|
||||
public int WriteVariableInt64(Int64 value)
|
||||
{
|
||||
ulong zigzag = (ulong)(value << 1) ^ (ulong)(value >> 63);
|
||||
return WriteVariableUInt64(zigzag);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write Base128 encoded variable sized unsigned integer of up to 64 bits
|
||||
/// </summary>
|
||||
/// <returns>number of bytes written</returns>
|
||||
[CLSCompliant(false)]
|
||||
public int WriteVariableUInt64(UInt64 value)
|
||||
{
|
||||
int retval = 1;
|
||||
UInt64 num1 = (UInt64)value;
|
||||
while (num1 >= 0x80)
|
||||
{
|
||||
this.Write((byte)(num1 | 0x80));
|
||||
num1 = num1 >> 7;
|
||||
retval++;
|
||||
}
|
||||
this.Write((byte)num1);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compress (lossy) a float in the range -1..1 using numberOfBits bits
|
||||
/// </summary>
|
||||
public void WriteSignedSingle(float value, int numberOfBits)
|
||||
{
|
||||
NetException.Assert(((value >= -1.0) && (value <= 1.0)), " WriteSignedSingle() must be passed a float in the range -1 to 1; val is " + value);
|
||||
|
||||
float unit = (value + 1.0f) * 0.5f;
|
||||
int maxVal = (1 << numberOfBits) - 1;
|
||||
uint writeVal = (uint)(unit * (float)maxVal);
|
||||
|
||||
Write(writeVal, numberOfBits);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compress (lossy) a float in the range 0..1 using numberOfBits bits
|
||||
/// </summary>
|
||||
public void WriteUnitSingle(float value, int numberOfBits)
|
||||
{
|
||||
NetException.Assert(((value >= 0.0) && (value <= 1.0)), " WriteUnitSingle() must be passed a float in the range 0 to 1; val is " + value);
|
||||
|
||||
int maxValue = (1 << numberOfBits) - 1;
|
||||
uint writeVal = (uint)(value * (float)maxValue);
|
||||
|
||||
Write(writeVal, numberOfBits);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compress a float within a specified range using a certain number of bits
|
||||
/// </summary>
|
||||
public void WriteRangedSingle(float value, float min, float max, int numberOfBits)
|
||||
{
|
||||
NetException.Assert(((value >= min) && (value <= max)), " WriteRangedSingle() must be passed a float in the range MIN to MAX; val is " + value);
|
||||
|
||||
float range = max - min;
|
||||
float unit = ((value - min) / range);
|
||||
int maxVal = (1 << numberOfBits) - 1;
|
||||
Write((UInt32)((float)maxVal * unit), numberOfBits);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes an integer with the least amount of bits need for the specified range
|
||||
/// Returns number of bits written
|
||||
/// </summary>
|
||||
public int WriteRangedInteger(int min, int max, int value)
|
||||
{
|
||||
NetException.Assert(value >= min && value <= max, "Value not within min/max range!");
|
||||
|
||||
uint range = (uint)(max - min);
|
||||
int numBits = NetUtility.BitsToHoldUInt(range);
|
||||
|
||||
uint rvalue = (uint)(value - min);
|
||||
Write(rvalue, numBits);
|
||||
|
||||
return numBits;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write a string
|
||||
/// </summary>
|
||||
public void Write(string source)
|
||||
{
|
||||
if (string.IsNullOrEmpty(source))
|
||||
{
|
||||
EnsureBufferSize(m_bitLength + 8);
|
||||
WriteVariableUInt32(0);
|
||||
return;
|
||||
}
|
||||
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(source);
|
||||
EnsureBufferSize(m_bitLength + 8 + (bytes.Length * 8));
|
||||
WriteVariableUInt32((uint)bytes.Length);
|
||||
Write(bytes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes an endpoint description
|
||||
/// </summary>
|
||||
public void Write(IPEndPoint endPoint)
|
||||
{
|
||||
byte[] bytes = endPoint.Address.GetAddressBytes();
|
||||
Write((byte)bytes.Length);
|
||||
Write(bytes);
|
||||
Write((ushort)endPoint.Port);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the local time to a message; readable (and convertable to local time) by the remote host using ReadTime()
|
||||
/// </summary>
|
||||
public void WriteTime(double localTime, bool highPrecision)
|
||||
{
|
||||
if (highPrecision)
|
||||
Write(localTime);
|
||||
else
|
||||
Write((float)localTime);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pads data with enough bits to reach a full byte. Decreases cpu usage for subsequent byte writes.
|
||||
/// </summary>
|
||||
public void WritePadBits()
|
||||
{
|
||||
m_bitLength = ((m_bitLength + 7) >> 3) * 8;
|
||||
EnsureBufferSize(m_bitLength);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pads data with the specified number of bits.
|
||||
/// </summary>
|
||||
public void WritePadBits(int numberOfBits)
|
||||
{
|
||||
m_bitLength += numberOfBits;
|
||||
EnsureBufferSize(m_bitLength);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Append all the bits of message to this message
|
||||
/// </summary>
|
||||
public void Write(NetOutgoingMessage message)
|
||||
{
|
||||
EnsureBufferSize(m_bitLength + (message.LengthBytes * 8));
|
||||
|
||||
Write(message.m_data, 0, message.LengthBytes);
|
||||
|
||||
// did we write excessive bits?
|
||||
int bitsInLastByte = (message.m_bitLength % 8);
|
||||
if (bitsInLastByte != 0)
|
||||
{
|
||||
int excessBits = 8 - bitsInLastByte;
|
||||
m_bitLength -= excessBits;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Append all the bits of message to this message
|
||||
/// </summary>
|
||||
public void Write(NetIncomingMessage message)
|
||||
{
|
||||
EnsureBufferSize(m_bitLength + (message.LengthBytes * 8));
|
||||
|
||||
Write(message.m_data, 0, message.LengthBytes);
|
||||
|
||||
// did we write excessive bits?
|
||||
int bitsInLastByte = (message.m_bitLength % 8);
|
||||
if (bitsInLastByte != 0)
|
||||
{
|
||||
int excessBits = 8 - bitsInLastByte;
|
||||
m_bitLength -= excessBits;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
103
Lidgren.Network/NetBuffer.cs
Normal file
103
Lidgren.Network/NetBuffer.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Lidgren.Network
|
||||
{
|
||||
public partial class NetBuffer
|
||||
{
|
||||
// @TODO Add ReadTime() to incomingmessage class
|
||||
private const int c_overAllocateAmount = 4;
|
||||
|
||||
private static readonly Dictionary<Type, MethodInfo> s_readMethods;
|
||||
private static readonly Dictionary<Type, MethodInfo> s_writeMethods;
|
||||
|
||||
internal byte[] m_data;
|
||||
internal int m_bitLength;
|
||||
internal int m_readPosition;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the internal data buffer
|
||||
/// </summary>
|
||||
public byte[] Data
|
||||
{
|
||||
get { return m_data; }
|
||||
set { m_data = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the length of the used portion of the buffer in bytes
|
||||
/// </summary>
|
||||
public int LengthBytes
|
||||
{
|
||||
get { return ((m_bitLength + 7) >> 3); }
|
||||
set
|
||||
{
|
||||
m_bitLength = value * 8;
|
||||
InternalEnsureBufferSize(m_bitLength);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the length of the used portion of the buffer in bits
|
||||
/// </summary>
|
||||
public int LengthBits
|
||||
{
|
||||
get { return m_bitLength; }
|
||||
set
|
||||
{
|
||||
m_bitLength = value;
|
||||
InternalEnsureBufferSize(m_bitLength);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the read position in the buffer, in bits (not bytes)
|
||||
/// </summary>
|
||||
public long Position
|
||||
{
|
||||
get { return (long)m_readPosition; }
|
||||
set { m_readPosition = (int)value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the position in the buffer in bytes; note that the bits of the first returned byte may already have been read - check the Position property to make sure.
|
||||
/// </summary>
|
||||
public int PositionInBytes
|
||||
{
|
||||
get { return (int)(m_readPosition / 8); }
|
||||
}
|
||||
|
||||
static NetBuffer()
|
||||
{
|
||||
Type[] integralTypes = typeof(Byte).Assembly.GetTypes();
|
||||
|
||||
s_readMethods = new Dictionary<Type, MethodInfo>();
|
||||
MethodInfo[] methods = typeof(NetIncomingMessage).GetMethods(BindingFlags.Instance | BindingFlags.Public);
|
||||
foreach (MethodInfo mi in methods)
|
||||
{
|
||||
if (mi.GetParameters().Length == 0 && mi.Name.StartsWith("Read", StringComparison.InvariantCulture))
|
||||
{
|
||||
string n = mi.Name.Substring(4);
|
||||
foreach (Type it in integralTypes)
|
||||
{
|
||||
if (it.Name == n)
|
||||
s_readMethods[it] = mi;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
s_writeMethods = new Dictionary<Type, MethodInfo>();
|
||||
methods = typeof(NetOutgoingMessage).GetMethods(BindingFlags.Instance | BindingFlags.Public);
|
||||
foreach (MethodInfo mi in methods)
|
||||
{
|
||||
if (mi.Name.Equals("Write", StringComparison.InvariantCulture))
|
||||
{
|
||||
ParameterInfo[] pis = mi.GetParameters();
|
||||
if (pis.Length == 1)
|
||||
s_writeMethods[pis[0].ParameterType] = mi;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -184,12 +184,12 @@ namespace Lidgren.Network
|
||||
{
|
||||
if (m_localHailMessage != null)
|
||||
{
|
||||
byte[] hi = m_localHailMessage.PeekDataBuffer();
|
||||
byte[] hi = m_localHailMessage.Data;
|
||||
if (hi != null && hi.Length >= m_localHailMessage.LengthBytes)
|
||||
{
|
||||
if (om.LengthBytes + m_localHailMessage.LengthBytes > m_peerConfiguration.m_maximumTransmissionUnit - 10)
|
||||
throw new NetException("Hail message too large; can maximally be " + (m_peerConfiguration.m_maximumTransmissionUnit - 10 - om.LengthBytes));
|
||||
om.Write(m_localHailMessage.PeekDataBuffer(), 0, m_localHailMessage.LengthBytes);
|
||||
om.Write(m_localHailMessage.Data, 0, m_localHailMessage.LengthBytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,10 +26,8 @@ namespace Lidgren.Network
|
||||
/// Incoming message either sent from a remote peer or generated within the library
|
||||
/// </summary>
|
||||
[DebuggerDisplay("Type={MessageType} LengthBits={LengthBits}")]
|
||||
public partial class NetIncomingMessage
|
||||
public sealed class NetIncomingMessage : NetBuffer
|
||||
{
|
||||
internal byte[] m_data;
|
||||
internal int m_bitLength;
|
||||
internal NetIncomingMessageType m_incomingMessageType;
|
||||
internal IPEndPoint m_senderEndpoint;
|
||||
internal NetConnection m_senderConnection;
|
||||
@@ -68,23 +66,6 @@ namespace Lidgren.Network
|
||||
/// </summary>
|
||||
public double ReceiveTime { get { return m_receiveTime; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the length of the message payload in bytes
|
||||
/// </summary>
|
||||
public int LengthBytes
|
||||
{
|
||||
get { return ((m_bitLength + 7) >> 3); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the length of the message payload in bits
|
||||
/// </summary>
|
||||
public int LengthBits
|
||||
{
|
||||
get { return m_bitLength; }
|
||||
internal set { m_bitLength = value; }
|
||||
}
|
||||
|
||||
internal NetIncomingMessage()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -25,17 +25,6 @@ using System.Runtime.InteropServices;
|
||||
|
||||
namespace Lidgren.Network
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public struct SingleUIntUnion
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public float SingleValue;
|
||||
|
||||
[FieldOffset(0)]
|
||||
[CLSCompliant(false)]
|
||||
public uint UIntValue;
|
||||
}
|
||||
|
||||
public sealed partial class NetOutgoingMessage
|
||||
{
|
||||
private const int c_overAllocateAmount = 4;
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Lidgren.Network
|
||||
/// Outgoing message used to send data to remote peer(s)
|
||||
/// </summary>
|
||||
[DebuggerDisplay("LengthBits={LengthBits}")]
|
||||
public sealed partial class NetOutgoingMessage
|
||||
public sealed class NetOutgoingMessage : NetBuffer
|
||||
{
|
||||
internal NetMessageType m_messageType;
|
||||
internal bool m_isSent;
|
||||
|
||||
@@ -5,10 +5,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChatClient", "ChatClient\Ch
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChatServer", "ChatServer\ChatServer.csproj", "{388FD8FC-6B0B-403F-B4B1-6AC2F025C00F}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SamplesCommon", "..\SamplesCommon\SamplesCommon\SamplesCommon.csproj", "{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lidgren.Network", "..\..\Lidgren.Network\Lidgren.Network.csproj", "{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SamplesCommon", "..\SamplesCommon\SamplesCommon.csproj", "{773069DA-B66E-4667-ADCB-0D215AD8CF3E}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -39,16 +39,6 @@ Global
|
||||
{388FD8FC-6B0B-403F-B4B1-6AC2F025C00F}.Release|Mixed Platforms.Build.0 = Release|x86
|
||||
{388FD8FC-6B0B-403F-B4B1-6AC2F025C00F}.Release|x86.ActiveCfg = Release|x86
|
||||
{388FD8FC-6B0B-403F-B4B1-6AC2F025C00F}.Release|x86.Build.0 = Release|x86
|
||||
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
@@ -59,6 +49,16 @@ Global
|
||||
{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -72,10 +72,6 @@
|
||||
<Project>{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}</Project>
|
||||
<Name>Lidgren.Network</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\SamplesCommon\SamplesCommon\SamplesCommon.csproj">
|
||||
<Project>{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}</Project>
|
||||
<Name>SamplesCommon</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
||||
@@ -72,10 +72,6 @@
|
||||
<Project>{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}</Project>
|
||||
<Name>Lidgren.Network</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\SamplesCommon\SamplesCommon\SamplesCommon.csproj">
|
||||
<Project>{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}</Project>
|
||||
<Name>SamplesCommon</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
||||
@@ -81,10 +81,6 @@
|
||||
<Project>{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}</Project>
|
||||
<Name>Lidgren.Network</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\SamplesCommon\SamplesCommon\SamplesCommon.csproj">
|
||||
<Project>{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}</Project>
|
||||
<Name>SamplesCommon</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
||||
@@ -5,10 +5,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageServer", "ImageServer\
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageClient", "ImageClient\ImageClient.csproj", "{6629DBA5-4805-462C-A959-CB0CF44FBA55}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SamplesCommon", "..\SamplesCommon\SamplesCommon\SamplesCommon.csproj", "{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lidgren.Network", "..\..\Lidgren.Network\Lidgren.Network.csproj", "{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SamplesCommon", "..\SamplesCommon\SamplesCommon.csproj", "{773069DA-B66E-4667-ADCB-0D215AD8CF3E}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -39,16 +39,6 @@ Global
|
||||
{6629DBA5-4805-462C-A959-CB0CF44FBA55}.Release|Mixed Platforms.Build.0 = Release|x86
|
||||
{6629DBA5-4805-462C-A959-CB0CF44FBA55}.Release|x86.ActiveCfg = Release|x86
|
||||
{6629DBA5-4805-462C-A959-CB0CF44FBA55}.Release|x86.Build.0 = Release|x86
|
||||
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
@@ -59,6 +49,16 @@ Global
|
||||
{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -72,10 +72,6 @@
|
||||
<Project>{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}</Project>
|
||||
<Name>Lidgren.Network</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\SamplesCommon\SamplesCommon\SamplesCommon.csproj">
|
||||
<Project>{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}</Project>
|
||||
<Name>SamplesCommon</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
||||
@@ -1,71 +1,63 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.488
|
||||
// Runtime Version:4.0.30319.239
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace SpeedClient.Properties
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||
/// </summary>
|
||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources
|
||||
{
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cached ResourceManager instance used by this class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager
|
||||
{
|
||||
get
|
||||
{
|
||||
if ((resourceMan == null))
|
||||
{
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SpeedClient.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the current thread's CurrentUICulture property for all
|
||||
/// resource lookups using this strongly typed resource class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture
|
||||
{
|
||||
get
|
||||
{
|
||||
return resourceCulture;
|
||||
}
|
||||
set
|
||||
{
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
namespace SpeedTestClient.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||
/// </summary>
|
||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cached ResourceManager instance used by this class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SpeedTestClient.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the current thread's CurrentUICulture property for all
|
||||
/// resource lookups using this strongly typed resource class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,30 +1,26 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.488
|
||||
// Runtime Version:4.0.30319.239
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace SpeedClient.Properties
|
||||
{
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
|
||||
{
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
|
||||
public static Settings Default
|
||||
{
|
||||
get
|
||||
{
|
||||
return defaultInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
namespace SpeedTestClient.Properties {
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
|
||||
public static Settings Default {
|
||||
get {
|
||||
return defaultInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
@@ -10,7 +10,7 @@
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>SpeedTestClient</RootNamespace>
|
||||
<AssemblyName>SpeedTestClient</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<SccProjectName>
|
||||
</SccProjectName>
|
||||
@@ -20,6 +20,27 @@
|
||||
</SccAuxPath>
|
||||
<SccProvider>
|
||||
</SccProvider>
|
||||
<FileUpgradeFlags>
|
||||
</FileUpgradeFlags>
|
||||
<UpgradeBackupLocation>
|
||||
</UpgradeBackupLocation>
|
||||
<OldToolsVersion>3.5</OldToolsVersion>
|
||||
<TargetFrameworkProfile />
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
<UpdateEnabled>false</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@@ -29,6 +50,7 @@
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
@@ -37,6 +59,7 @@
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
@@ -66,7 +89,9 @@
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
<DesignTime>True</DesignTime>
|
||||
</Compile>
|
||||
<None Include="app.config" />
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
@@ -87,6 +112,23 @@
|
||||
<Name>SamplesCommon</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>Windows Installer 3.1</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||
# Visual Studio 2010
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpeedClient", "SpeedClient\SpeedClient.csproj", "{AB22D8FF-34F6-4F4C-8757-44F01998D8C3}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpeedServer", "SpeedServer\SpeedServer.csproj", "{45E3AFF8-75A1-4C56-8902-5574F2325811}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SamplesCommon", "..\..\SamplesCommon\SamplesCommon\SamplesCommon.csproj", "{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lidgren.Network", "..\..\..\Lidgren.Network\Lidgren.Network.csproj", "{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpeedTestServer", "SpeedServer\SpeedTestServer.csproj", "{A994C246-8EEC-452D-ACA6-554463B2892B}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpeedTestClient", "SpeedClient\SpeedTestClient.csproj", "{838DA9DF-D162-4CD7-A427-3399BD76FF1F}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SamplesCommon", "..\..\SamplesCommon\SamplesCommon.csproj", "{773069DA-B66E-4667-ADCB-0D215AD8CF3E}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -19,36 +19,6 @@ Global
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{AB22D8FF-34F6-4F4C-8757-44F01998D8C3}.Debug|Any CPU.ActiveCfg = Debug|x86
|
||||
{AB22D8FF-34F6-4F4C-8757-44F01998D8C3}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
|
||||
{AB22D8FF-34F6-4F4C-8757-44F01998D8C3}.Debug|Mixed Platforms.Build.0 = Debug|x86
|
||||
{AB22D8FF-34F6-4F4C-8757-44F01998D8C3}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{AB22D8FF-34F6-4F4C-8757-44F01998D8C3}.Debug|x86.Build.0 = Debug|x86
|
||||
{AB22D8FF-34F6-4F4C-8757-44F01998D8C3}.Release|Any CPU.ActiveCfg = Release|x86
|
||||
{AB22D8FF-34F6-4F4C-8757-44F01998D8C3}.Release|Mixed Platforms.ActiveCfg = Release|x86
|
||||
{AB22D8FF-34F6-4F4C-8757-44F01998D8C3}.Release|Mixed Platforms.Build.0 = Release|x86
|
||||
{AB22D8FF-34F6-4F4C-8757-44F01998D8C3}.Release|x86.ActiveCfg = Release|x86
|
||||
{AB22D8FF-34F6-4F4C-8757-44F01998D8C3}.Release|x86.Build.0 = Release|x86
|
||||
{45E3AFF8-75A1-4C56-8902-5574F2325811}.Debug|Any CPU.ActiveCfg = Debug|x86
|
||||
{45E3AFF8-75A1-4C56-8902-5574F2325811}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
|
||||
{45E3AFF8-75A1-4C56-8902-5574F2325811}.Debug|Mixed Platforms.Build.0 = Debug|x86
|
||||
{45E3AFF8-75A1-4C56-8902-5574F2325811}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{45E3AFF8-75A1-4C56-8902-5574F2325811}.Debug|x86.Build.0 = Debug|x86
|
||||
{45E3AFF8-75A1-4C56-8902-5574F2325811}.Release|Any CPU.ActiveCfg = Release|x86
|
||||
{45E3AFF8-75A1-4C56-8902-5574F2325811}.Release|Mixed Platforms.ActiveCfg = Release|x86
|
||||
{45E3AFF8-75A1-4C56-8902-5574F2325811}.Release|Mixed Platforms.Build.0 = Release|x86
|
||||
{45E3AFF8-75A1-4C56-8902-5574F2325811}.Release|x86.ActiveCfg = Release|x86
|
||||
{45E3AFF8-75A1-4C56-8902-5574F2325811}.Release|x86.Build.0 = Release|x86
|
||||
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{64D2482A-3C16-4D1F-A3F6-058FC3D73E21}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
@@ -59,6 +29,36 @@ Global
|
||||
{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{A994C246-8EEC-452D-ACA6-554463B2892B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A994C246-8EEC-452D-ACA6-554463B2892B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A994C246-8EEC-452D-ACA6-554463B2892B}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{A994C246-8EEC-452D-ACA6-554463B2892B}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{A994C246-8EEC-452D-ACA6-554463B2892B}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{A994C246-8EEC-452D-ACA6-554463B2892B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A994C246-8EEC-452D-ACA6-554463B2892B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{A994C246-8EEC-452D-ACA6-554463B2892B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{A994C246-8EEC-452D-ACA6-554463B2892B}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{A994C246-8EEC-452D-ACA6-554463B2892B}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{838DA9DF-D162-4CD7-A427-3399BD76FF1F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{838DA9DF-D162-4CD7-A427-3399BD76FF1F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{838DA9DF-D162-4CD7-A427-3399BD76FF1F}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{838DA9DF-D162-4CD7-A427-3399BD76FF1F}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{838DA9DF-D162-4CD7-A427-3399BD76FF1F}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{838DA9DF-D162-4CD7-A427-3399BD76FF1F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{838DA9DF-D162-4CD7-A427-3399BD76FF1F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{838DA9DF-D162-4CD7-A427-3399BD76FF1F}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{838DA9DF-D162-4CD7-A427-3399BD76FF1F}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{838DA9DF-D162-4CD7-A427-3399BD76FF1F}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{773069DA-B66E-4667-ADCB-0D215AD8CF3E}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -1,71 +1,63 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.488
|
||||
// Runtime Version:4.0.30319.239
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace SpeedServer.Properties
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||
/// </summary>
|
||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources
|
||||
{
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cached ResourceManager instance used by this class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager
|
||||
{
|
||||
get
|
||||
{
|
||||
if ((resourceMan == null))
|
||||
{
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SpeedServer.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the current thread's CurrentUICulture property for all
|
||||
/// resource lookups using this strongly typed resource class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture
|
||||
{
|
||||
get
|
||||
{
|
||||
return resourceCulture;
|
||||
}
|
||||
set
|
||||
{
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
namespace SpeedTestServer.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||
/// </summary>
|
||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cached ResourceManager instance used by this class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SpeedTestServer.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the current thread's CurrentUICulture property for all
|
||||
/// resource lookups using this strongly typed resource class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,30 +1,26 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.488
|
||||
// Runtime Version:4.0.30319.239
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace SpeedServer.Properties
|
||||
{
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
|
||||
{
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
|
||||
public static Settings Default
|
||||
{
|
||||
get
|
||||
{
|
||||
return defaultInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
namespace SpeedTestServer.Properties {
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
|
||||
public static Settings Default {
|
||||
get {
|
||||
return defaultInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
@@ -10,7 +10,7 @@
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>SpeedTestServer</RootNamespace>
|
||||
<AssemblyName>SpeedTestServer</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<SccProjectName>
|
||||
</SccProjectName>
|
||||
@@ -20,6 +20,28 @@
|
||||
</SccAuxPath>
|
||||
<SccProvider>
|
||||
</SccProvider>
|
||||
<FileUpgradeFlags>
|
||||
</FileUpgradeFlags>
|
||||
<UpgradeBackupLocation>
|
||||
</UpgradeBackupLocation>
|
||||
<OldToolsVersion>3.5</OldToolsVersion>
|
||||
<TargetFrameworkProfile>
|
||||
</TargetFrameworkProfile>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
<UpdateEnabled>false</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@@ -29,6 +51,7 @@
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
@@ -37,6 +60,7 @@
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
@@ -67,7 +91,9 @@
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
<DesignTime>True</DesignTime>
|
||||
</Compile>
|
||||
<None Include="app.config" />
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
@@ -80,7 +106,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\..\Lidgren.Network\Lidgren.Network.csproj">
|
||||
<Project>{AE483C29-042E-4226-BA52-D247CE7676DA}</Project>
|
||||
<Project>{49BA1C69-6104-41AC-A5D8-B54FA9F696E8}</Project>
|
||||
<Name>Lidgren.Network</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\SamplesCommon\SamplesCommon.csproj">
|
||||
@@ -88,6 +114,23 @@
|
||||
<Name>SamplesCommon</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>Windows Installer 3.1</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace UnitTests
|
||||
if (bcnt != 2)
|
||||
throw new NetException("WriteVariable* wrote too many bytes!");
|
||||
|
||||
byte[] data = msg.PeekDataBuffer();
|
||||
byte[] data = msg.Data;
|
||||
|
||||
NetIncomingMessage inc = Program.CreateIncomingMessage(data, msg.LengthBits);
|
||||
|
||||
@@ -119,7 +119,7 @@ namespace UnitTests
|
||||
|
||||
tmp.WriteAllFields(test, BindingFlags.Public | BindingFlags.Instance);
|
||||
|
||||
data = tmp.PeekDataBuffer();
|
||||
data = tmp.Data;
|
||||
|
||||
inc = Program.CreateIncomingMessage(data, tmp.LengthBits);
|
||||
|
||||
@@ -135,7 +135,7 @@ namespace UnitTests
|
||||
byte[] tmparr = new byte[] { 5, 6, 7, 8, 9 };
|
||||
msg.Write(tmparr);
|
||||
|
||||
inc = Program.CreateIncomingMessage(msg.PeekDataBuffer(), msg.LengthBits);
|
||||
inc = Program.CreateIncomingMessage(msg.Data, msg.LengthBits);
|
||||
byte[] result = inc.ReadBytes(tmparr.Length);
|
||||
|
||||
for (int i = 0; i < tmparr.Length; i++)
|
||||
|
||||
Reference in New Issue
Block a user