1
0
mirror of https://github.com/lidgren/lidgren-network-gen3.git synced 2026-05-16 15:16:33 +09:00

NetConnection.LocalHailMessage exposed. WriteVariableInt64 and ReadVariableInt64 added.

This commit is contained in:
lidgren
2010-12-28 13:13:00 +00:00
parent b83ec10d8d
commit eb056bc9aa
4 changed files with 58 additions and 3 deletions

View File

@@ -60,6 +60,11 @@ namespace Lidgren.Network
/// </summary>
public long RemoteUniqueIdentifier { get { return m_remoteUniqueIdentifier; } }
/// <summary>
/// Gets the local hail message that was sent as part of the handshake
/// </summary>
public NetOutgoingMessage LocalHailMessage { get { return m_localHailMessage; } }
// gets the time before automatically resending an unacked message
internal float GetResendDelay()
{

View File

@@ -363,6 +363,29 @@ namespace Lidgren.Network
}
}
/// <summary>
/// Reads a Int64 written using WriteVariableInt64()
/// </summary>
public Int64 ReadVariableInt64()
{
Int64 num1 = 0;
int num2 = 0;
while (true)
{
if (num2 == 0x23)
throw new FormatException("Bad 7-bit encoded integer");
byte num3 = this.ReadByte();
num1 |= (Int64)((Int64)(num3 & 0x7f) << (num2 & 0x1f));
num2 += 7;
if ((num3 & 0x80) == 0)
{
Int64 sign = (num1 << 63) >> 63;
return sign ^ (num1 >> 1);
}
}
}
/// <summary>
/// Reads a UInt32 written using WriteVariableInt64()
/// </summary>

View File

@@ -429,6 +429,24 @@ namespace Lidgren.Network
return retval;
}
/// <summary>
/// Write Base128 encoded variable sized signed integer
/// </summary>
/// <returns>number of bytes written</returns>
public int WriteVariableInt64(Int64 value)
{
int retval = 1;
UInt64 num1 = (UInt64)((value << 1) ^ (value >> 31));
while (num1 >= 0x80)
{
this.Write((byte)(num1 | 0x80));
num1 = num1 >> 7;
retval++;
}
this.Write((byte)num1);
return retval;
}
/// <summary>
/// Write Base128 encoded variable sized unsigned integer
/// </summary>