In SourceServerQuery, read strings as UTF8

This commit is contained in:
Garry Newman 2018-04-03 09:55:11 +01:00
parent ff1d866374
commit 46f56c24f3
3 changed files with 14 additions and 13 deletions

View File

@ -406,9 +406,10 @@ public void Rules()
filter.Add( "gamedir", "rust" );
filter.Add( "secure", "1" );
filter.Add( "addr", "185.97.254.146" );
using ( var query = client.ServerList.Internet( filter ) )
{
for ( int i = 0; i < 1000; i++ )
{
GC.Collect();
@ -416,8 +417,8 @@ public void Rules()
GC.Collect();
System.Threading.Thread.Sleep( 10 );
if ( query.Responded.Count > 20 )
break;
// if ( query.Responded.Count > 20 )
// break;
if ( query.Finished )
break;
@ -425,15 +426,12 @@ public void Rules()
query.Dispose();
var servers = query.Responded.Take( 10 );
var servers = query.Responded.Take( 100 );
foreach ( var server in servers )
{
server.FetchRules();
}
foreach ( var server in servers )
{
int i = 0;
while ( !server.HasRules )
{
@ -447,7 +445,10 @@ public void Rules()
if ( server.HasRules )
{
Console.WriteLine( "SERVER HAS RULES :D" );
Console.WriteLine( "" );
Console.WriteLine( "" );
Console.WriteLine( server.Address );
Console.WriteLine( "" );
foreach ( var rule in server.Rules )
{

View File

@ -79,7 +79,7 @@ internal static string FormatPrice(string currency, ulong price)
}
}
public static string ReadAnsiString( this BinaryReader br, byte[] buffer = null )
public static string ReadNullTerminatedUTF8String( this BinaryReader br, byte[] buffer = null )
{
if ( buffer == null )
buffer = new byte[1024];
@ -92,7 +92,7 @@ public static string ReadAnsiString( this BinaryReader br, byte[] buffer = null
i++;
}
return Encoding.ASCII.GetString( buffer, 0, i );
return Encoding.UTF8.GetString( buffer, 0, i );
}
}

View File

@ -100,7 +100,7 @@ void GetRules()
var numRules = br.ReadUInt16();
for ( int index = 0; index < numRules; index++ )
{
rules.Add( br.ReadAnsiString( readBuffer ), br.ReadAnsiString( readBuffer ) );
rules.Add( br.ReadNullTerminatedUTF8String( readBuffer ), br.ReadNullTerminatedUTF8String( readBuffer ) );
}
}