v0.2.2: updated Lidgren, railgun shells can be bought, autorestart server, netstats, tutorial moloch spawning in a wall fix, misc error checks

This commit is contained in:
Regalis
2015-10-18 22:44:30 +03:00
parent aa3882a815
commit 0e5e86e363
85 changed files with 2763 additions and 1866 deletions
+32 -10
View File
@@ -4,6 +4,10 @@ using System.Text;
using System.Reflection;
using System.Net;
#if !__NOIPENDPOINT__
using NetEndPoint = System.Net.IPEndPoint;
#endif
namespace Lidgren.Network
{
/// <summary>
@@ -311,7 +315,7 @@ namespace Lidgren.Network
else
{
retval = NetBitWriter.ReadUInt32(m_data, 32, m_readPosition);
retval |= NetBitWriter.ReadUInt32(m_data, numberOfBits - 32, m_readPosition) << 32;
retval |= (UInt64)NetBitWriter.ReadUInt32(m_data, numberOfBits - 32, m_readPosition + 32) << 32;
}
m_readPosition += numberOfBits;
return retval;
@@ -406,7 +410,7 @@ namespace Lidgren.Network
{
int num1 = 0;
int num2 = 0;
while (true)
while (m_bitLength - m_readPosition >= 8)
{
byte num3 = this.ReadByte();
num1 |= (num3 & 0x7f) << num2;
@@ -414,6 +418,9 @@ namespace Lidgren.Network
if ((num3 & 0x80) == 0)
return (uint)num1;
}
// ouch; failed to find enough bytes; malformed variable length number?
return (uint)num1;
}
/// <summary>
@@ -424,7 +431,7 @@ namespace Lidgren.Network
{
int num1 = 0;
int num2 = 0;
while (true)
while (m_bitLength - m_readPosition >= 8)
{
byte num3;
if (ReadByte(out num3) == false)
@@ -440,6 +447,8 @@ namespace Lidgren.Network
return true;
}
}
result = (uint)num1;
return false;
}
/// <summary>
@@ -468,7 +477,7 @@ namespace Lidgren.Network
{
UInt64 num1 = 0;
int num2 = 0;
while (true)
while (m_bitLength - m_readPosition >= 8)
{
//if (num2 == 0x23)
// throw new FormatException("Bad 7-bit encoded integer");
@@ -479,6 +488,9 @@ namespace Lidgren.Network
if ((num3 & 0x80) == 0)
return num1;
}
// ouch; failed to find enough bytes; malformed variable length number?
return num1;
}
/// <summary>
@@ -543,10 +555,20 @@ namespace Lidgren.Network
{
int byteLen = (int)ReadVariableUInt32();
if (byteLen == 0)
if (byteLen <= 0)
return String.Empty;
NetException.Assert(m_bitLength - m_readPosition >= (byteLen * 8), c_readOverflowError);
if ((ulong)(m_bitLength - m_readPosition) < ((ulong)byteLen * 8))
{
// not enough data
#if DEBUG
throw new NetException(c_readOverflowError);
#else
m_readPosition = m_bitLength;
return null; // unfortunate; but we need to protect against DDOS
#endif
}
if ((m_readPosition & 7) == 0)
{
@@ -572,7 +594,7 @@ namespace Lidgren.Network
return false;
}
if (byteLen == 0)
if (byteLen <= 0)
{
result = String.Empty;
return true;
@@ -620,14 +642,14 @@ namespace Lidgren.Network
/// <summary>
/// Reads a stored IPv4 endpoint description
/// </summary>
public IPEndPoint ReadIPEndPoint()
public NetEndPoint ReadIPEndPoint()
{
byte len = ReadByte();
byte[] addressBytes = ReadBytes(len);
int port = (int)ReadUInt16();
IPAddress address = new IPAddress(addressBytes);
return new IPEndPoint(address, port);
var address = NetUtility.CreateAddressFromBytes(addressBytes);
return new NetEndPoint(address, port);
}
/// <summary>