@@ -81,7 +81,7 @@ public interface IServerQuery
8181
8282 public class ServerQuery : IServerQuery , IDisposable
8383 {
84- private const int RESPONSE_HEADER_COUNT = 6 ;
84+ private const int RESPONSE_HEADER_COUNT = 5 ;
8585 private const int RESPONSE_CODE_INDEX = 5 ;
8686
8787 private readonly UdpClient _client = new UdpClient ( new IPEndPoint ( IPAddress . Any , 0 ) ) ;
@@ -211,7 +211,6 @@ public async Task<List<Rule>> GetRulesAsync()
211211 byte [ ] response = await SendRequestAsync ( RequestHeaders . A2S_RULES , BitConverter . GetBytes ( _currentChallenge ) ) ;
212212 if ( response . Length > 0 )
213213 {
214- var rls = ExtractListData < Rule > ( response ) ;
215214 return ExtractListData < Rule > ( response ) ;
216215 }
217216 else
@@ -330,7 +329,7 @@ private IEnumerable<byte> ExtractData<TObject>(TObject objectRef, byte[] dataSou
330329
331330 // We can be a good guy and ask for any extra jobs :)
332331 IEnumerable < byte > enumerableSource = stripHeaders
333- ? dataSource . Skip ( RESPONSE_HEADER_COUNT )
332+ ? dataSource . Skip ( RESPONSE_HEADER_COUNT )
334333 : dataSource ;
335334
336335 // We get every property that does not contain ParseCustom and NotParsable attributes on them to iterate through all and parse/assign their values.
@@ -369,8 +368,10 @@ private IEnumerable<byte> ExtractData<TObject>(TObject objectRef, byte[] dataSou
369368 */
370369 if ( property . PropertyType == typeof ( string ) )
371370 {
372- // Take till the termination.
373- takenBytes = enumerableSource . TakeWhile ( x => x != 0 ) ;
371+ // Clear the buffer first then take till the termination.
372+ takenBytes = enumerableSource
373+ . SkipWhile ( x => x == 0 )
374+ . TakeWhile ( x => x != 0 ) ;
374375
375376 // Parse it into a string.
376377 property . SetValue ( objectRef , Encoding . UTF8 . GetString ( takenBytes . ToArray ( ) ) ) ;
@@ -386,11 +387,11 @@ private IEnumerable<byte> ExtractData<TObject>(TObject objectRef, byte[] dataSou
386387 : property . PropertyType ;
387388
388389 // Extract the value and the size from the source.
389- ( object result , int size ) = ExtractMarshalType ( enumerableSource , typeOfProperty ) ;
390+ ( object result , int size ) = ExtractMarshalType ( enumerableSource . SkipWhile ( x => x == 0 ) , typeOfProperty ) ;
390391
391392 /* If the property is an enum we should parse it first then assign its value,
392393 * if not we can just give it to SetValue since it was converted by ExtractMarshalType already.*/
393- property . SetValue ( objectRef , property . PropertyType . IsEnum
394+ property . SetValue ( objectRef , property . PropertyType . IsEnum
394395 ? Enum . Parse ( property . PropertyType , result . ToString ( ) )
395396 : result ) ;
396397
0 commit comments