Skip to content

Commit

Permalink
Steam Web API puts illegal characters from server names into the XML,…
Browse files Browse the repository at this point in the history
… which will then cause .NET XmlSerializer to throw an exception.

This release replaces invalid characters with spaces.
  • Loading branch information
PredatH0r committed Sep 14, 2019
1 parent b30c59d commit 63c9c3e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
15 changes: 15 additions & 0 deletions QueryMaster/QueryMaster/MasterServerWebApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.ObjectModel;
using System.IO;
using System.Net;
using System.Text;
using System.Threading;
using System.Xml.Serialization;

Expand Down Expand Up @@ -70,6 +71,20 @@ public override void GetAddresses(Region region, MasterIpCallback callback, IpFi
var url = $"https://api.steampowered.com/IGameServersService/GetServerList/v1/?key={SteamWebApiKey}&format=xml&filter={filters}&limit={GetAddressesLimit}";
var xml = cli.DownloadString(url);
var ser = new XmlSerializer(typeof (Response));

// replace invalid XML chars ( < 32 ) with char reference
var sb = new StringBuilder(xml);
for (int i = 0, c = xml.Length; i < c; i++)
{
if (sb[i] < 32 && !char.IsWhiteSpace(sb[i]))
//{
// sb.Insert(i+1, "#" + ((int)sb[i]).ToString() + ";");
// sb[i] = '&';
//}
sb[i] = ' ';
}
xml = sb.ToString();

var resp = (Response) ser.Deserialize(new StringReader(xml));

var endpoints = new List<Tuple<IPEndPoint,ServerInfo>>();
Expand Down
12 changes: 8 additions & 4 deletions QueryMaster/QueryMaster/QueryMaster.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@
<AssemblyName>QueryMaster</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
<SccProjectName>
</SccProjectName>
<SccLocalPath>
</SccLocalPath>
<SccAuxPath>
</SccAuxPath>
<SccProvider>
</SccProvider>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion ServerBrowser/ServerBrowserForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace ServerBrowser
{
public partial class ServerBrowserForm : XtraForm
{
private const string Version = "2.50";
private const string Version = "2.51";
private const string DevExpressVersion = "v19.1";
private const string SteamWebApiText = "<Steam Web API>";
private const string CustomDetailColumnPrefix = "ServerInfo.";
Expand Down

0 comments on commit 63c9c3e

Please sign in to comment.