You've already forked lidgren-network-gen3
mirror of
https://github.com/lidgren/lidgren-network-gen3.git
synced 2026-05-16 07:06:30 +09:00
NetConnection.LocalHailMessage exposed. WriteVariableInt64 and ReadVariableInt64 added.
This commit is contained in:
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -22,11 +22,18 @@ namespace UnitTests
|
||||
msg.Write(true);
|
||||
|
||||
msg.WritePadBits();
|
||||
|
||||
|
||||
int bcnt = 0;
|
||||
|
||||
msg.Write(45.0f);
|
||||
msg.Write(46.0);
|
||||
msg.WriteVariableInt32(-47);
|
||||
bcnt += msg.WriteVariableInt32(-47);
|
||||
msg.WriteVariableInt32(470000);
|
||||
msg.WriteVariableUInt32(48);
|
||||
bcnt += msg.WriteVariableInt64(-49);
|
||||
|
||||
if (bcnt != 2)
|
||||
throw new NetException("WriteVariable* wrote too many bytes!");
|
||||
|
||||
byte[] data = msg.PeekDataBuffer();
|
||||
|
||||
@@ -51,9 +58,11 @@ namespace UnitTests
|
||||
bdr.Append(inc.ReadSingle());
|
||||
bdr.Append(inc.ReadDouble());
|
||||
bdr.Append(inc.ReadVariableInt32());
|
||||
bdr.Append(inc.ReadVariableInt32());
|
||||
bdr.Append(inc.ReadVariableUInt32());
|
||||
bdr.Append(inc.ReadVariableInt64());
|
||||
|
||||
if (bdr.ToString().Equals("False-342duke of earl4344True4546-4748"))
|
||||
if (bdr.ToString().Equals("False-342duke of earl4344True4546-4747000048-49"))
|
||||
Console.WriteLine("Read/write tests OK");
|
||||
else
|
||||
throw new NetException("Read/write tests FAILED!");
|
||||
|
||||
Reference in New Issue
Block a user