Skip to content

Commit

Permalink
Use SDK.Core SteamId and improve converter
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeBiellik committed Nov 15, 2019
1 parent baab4cd commit 256d56d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 88 deletions.
32 changes: 29 additions & 3 deletions Configuration/SteamIdConverter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Text.RegularExpressions;
using NFive.SDK.Core.Configuration;
using NFive.SDK.Core.Plugins;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
Expand All @@ -13,6 +15,10 @@ namespace NFive.SDK.Plugins.Configuration
/// <seealso cref="IYamlTypeConverter" />
public class SteamIdConverter : IYamlTypeConverter
{
private static readonly Regex Steam2Regex = new Regex("^STEAM_0:[0-1]:([0-9]{1,10})$", RegexOptions.IgnoreCase | RegexOptions.Compiled);
private static readonly Regex Steam32Regex = new Regex("^\\[?U:1:([0-9]{1,10})\\]?$", RegexOptions.IgnoreCase | RegexOptions.Compiled);
private static readonly Regex Steam64Regex = new Regex("^7656119([0-9]{10})$", RegexOptions.Compiled);

/// <inheritdoc />
/// <summary>
/// Gets a value indicating whether the current converter supports converting the specified type.
Expand All @@ -25,9 +31,29 @@ public class SteamIdConverter : IYamlTypeConverter
/// </summary>
public object ReadYaml(IParser parser, Type type)
{
var value = ((Scalar)parser.Current).Value;
var value = ((Scalar)parser.Current).Value.Trim();
parser.MoveNext();
return new SteamId(value).ToSteam64();

long id;

if (Steam64Regex.IsMatch(value))
{
id = long.Parse(value);
}
else if (Steam2Regex.IsMatch(value))
{
id = SteamId.FromSteamId2(value);
}
else if (Steam32Regex.IsMatch(value))
{
id = SteamId.FromSteamId32(value);
}
else
{
throw new YamlException("YML input not in valid SteamID 2, 32 or 64 format");
}

return new SteamId(id);
}

/// <inheritdoc />
Expand All @@ -36,7 +62,7 @@ public object ReadYaml(IParser parser, Type type)
/// </summary>
public void WriteYaml(IEmitter emitter, object value, Type type)
{
emitter.Emit(new Scalar(new SteamId(value.ToString()).ToSteam64().ToString()));
emitter.Emit(new Scalar(value.ToString()));
}
}
}
7 changes: 3 additions & 4 deletions NFive.SDK.Plugins.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<HintPath>packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="NFive.SDK.Core.net, Version=0.1.0.57, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\NFive.SDK.Core.0.1.0.57\lib\net452\NFive.SDK.Core.net.dll</HintPath>
<Reference Include="NFive.SDK.Core.net, Version=0.1.0.60, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\NFive.SDK.Core.0.1.0.60\lib\net452\NFive.SDK.Core.net.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="SemVer, Version=1.2.2.0, Culture=neutral, PublicKeyToken=a89bb7dc6f7a145c, processorArchitecture=MSIL">
Expand Down Expand Up @@ -76,7 +76,6 @@
<Compile Include="DefinitionGraph.cs" />
<Compile Include="Plugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SteamId.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down
79 changes: 0 additions & 79 deletions SteamId.cs

This file was deleted.

4 changes: 2 additions & 2 deletions packages.config
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="JetBrains.Annotations" version="2019.1.3" targetFramework="net452" />
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net452" />
<package id="NFive.SDK.Core" version="0.1.0.57" targetFramework="net452" />
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net452" />
<package id="NFive.SDK.Core" version="0.1.0.60" targetFramework="net452" />
<package id="SemanticVersioning" version="1.2.2" targetFramework="net452" />
<package id="YamlDotNet" version="8.0.0" targetFramework="net452" />
</packages>

0 comments on commit 256d56d

Please sign in to comment.