fixed SourceServerQuery shared buffer errors

This commit is contained in:
Garry Newman 2019-12-06 14:27:38 +00:00
parent 127de84c8c
commit 2e6db5fe37
2 changed files with 18 additions and 16 deletions

View File

@ -32,7 +32,7 @@ internal static async Task<Dictionary<string, string>> GetRules( ServerInfo serv
}
catch ( System.Exception e )
{
Console.Error.WriteLine( e.Message );
//Console.Error.WriteLine( e.Message );
return null;
}
}
@ -54,14 +54,14 @@ static async Task<Dictionary<string, string>> GetRules( UdpClient client )
var numRules = br.ReadUInt16();
for ( int index = 0; index < numRules; index++ )
{
rules.Add( br.ReadNullTerminatedUTF8String( readBuffer ), br.ReadNullTerminatedUTF8String( readBuffer ) );
rules.Add( br.ReadNullTerminatedUTF8String(), br.ReadNullTerminatedUTF8String() );
}
}
return rules;
}
static byte[] readBuffer = new byte[1024 * 8];
static async Task<byte[]> Receive( UdpClient client )
{
@ -120,10 +120,10 @@ private static async Task<byte[]> GetChallengeData( UdpClient client )
return challengeData;
}
static byte[] sendBuffer = new byte[1024];
static async Task Send( UdpClient client, byte[] message )
{
var sendBuffer = new byte[message.Length + 4];
sendBuffer[0] = 0xFF;
sendBuffer[1] = 0xFF;
sendBuffer[2] = 0xFF;

View File

@ -80,20 +80,22 @@ public static string FormatPrice(string currency, double price)
}
}
public static string ReadNullTerminatedUTF8String( this BinaryReader br, byte[] buffer = null )
{
if ( buffer == null )
buffer = new byte[1024];
static byte[] readBuffer = new byte[1024 * 8];
public static string ReadNullTerminatedUTF8String( this BinaryReader br )
{
lock ( readBuffer )
{
byte chr;
int i = 0;
while ( (chr = br.ReadByte()) != 0 && i < buffer.Length )
while ( (chr = br.ReadByte()) != 0 && i < readBuffer.Length )
{
buffer[i] = chr;
readBuffer[i] = chr;
i++;
}
return Encoding.UTF8.GetString( buffer, 0, i );
return Encoding.UTF8.GetString( readBuffer, 0, i );
}
}
}
}