Skip to content

Commit dcae393

Browse files
authored
Merge pull request #4 from cyilcode/response-header-strip-miscalculation
Response header strip miscalculation
2 parents 8f8bf9f + 1b0ca76 commit dcae393

File tree

3 files changed

+36
-15
lines changed

3 files changed

+36
-15
lines changed

SteamQueryNet/SteamQueryNet/Models/Player.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,18 @@ public string TotalDurationAsString
3535
get
3636
{
3737
TimeSpan totalSpan = TimeSpan.FromSeconds(Duration);
38-
string parsedHours = totalSpan.Hours >= 10 ? totalSpan.Hours.ToString() : $"0{totalSpan.Hours}";
39-
string parsedMinutes = totalSpan.Minutes >= 10 ? totalSpan.Minutes.ToString() : $"0{totalSpan.Minutes}";
40-
string parsedSeconds = totalSpan.Seconds >= 10 ? totalSpan.Seconds.ToString() : $"0{totalSpan.Seconds}";
38+
string parsedHours = totalSpan.Hours >= 10
39+
? totalSpan.Hours.ToString()
40+
: $"0{totalSpan.Hours}";
41+
42+
string parsedMinutes = totalSpan.Minutes >= 10
43+
? totalSpan.Minutes.ToString()
44+
: $"0{totalSpan.Minutes}";
45+
46+
string parsedSeconds = totalSpan.Seconds >= 10
47+
? totalSpan.Seconds.ToString()
48+
: $"0{totalSpan.Seconds}";
49+
4150
return $"{parsedHours}:{parsedMinutes}:{parsedSeconds}";
4251
}
4352
}

SteamQueryNet/SteamQueryNet/ServerQuery.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

SteamQueryNet/SteamQueryNet/SteamQueryNet.csproj

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<Authors>Cem YILMAZ</Authors>
66
<Company>Cem YILMAZ</Company>
7-
<Version>1.0.3</Version>
8-
<AssemblyVersion>1.0.0.3</AssemblyVersion>
7+
<Version>1.0.5</Version>
8+
<AssemblyVersion>1.0.0.5</AssemblyVersion>
99
<NeutralLanguage>en</NeutralLanguage>
1010
<PackageTags>steam,query,net,steamquery,steamquerynet</PackageTags>
11-
<FileVersion>1.0.0.3</FileVersion>
12-
<PackageReleaseNotes>Add async API support</PackageReleaseNotes>
11+
<FileVersion>1.0.0.5</FileVersion>
12+
<PackageReleaseNotes>Fix response header strip miscalculation</PackageReleaseNotes>
13+
<Description>SteamQueryNet is a C# wrapper for Steam Server Queries UDP protocol. It is;
14+
15+
Light
16+
Dependency free
17+
Written in .net standard 2.0 so that it works with both .NET framework 4.6+ and core.</Description>
18+
<Copyright />
19+
<license>https://github.com/cyilcode/SteamQueryNet/blob/master/LICENSE</license>
20+
<PackageProjectUrl>https://github.com/cyilcode/SteamQueryNet</PackageProjectUrl>
21+
<PackageIconUrl>https://github.com/cyilcode/SteamQueryNet</PackageIconUrl>
22+
<RepositoryUrl>https://github.com/cyilcode/SteamQueryNet</RepositoryUrl>
23+
<RepositoryType>git</RepositoryType>
1324
</PropertyGroup>
1425

1526
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

0 commit comments

Comments
 (0)