Skip to content

Commit

Permalink
Merge branch 'steamkit' of https://github.com/Ni1kko/infiBanChecker
Browse files Browse the repository at this point in the history
Merge branch
  • Loading branch information
Ni1kko authored Oct 9, 2019
2 parents 248e04b + 01e5b4b commit b7bdcf1
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 50 deletions.
Binary file not shown.
4 changes: 2 additions & 2 deletions infiBanChecker/infiBanChecker/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal sealed class Program
// Major Version
// Minor Version
// Build Number
internal const string version = "3.0.0";
internal const string version = "3.1.3";
#endregion

#region EntryPoint
Expand All @@ -17,7 +17,7 @@ private static async Task Main()
#region Subscribe Assembly Resolver
AppDomain.CurrentDomain.AssemblyResolve += Utils.Helpers.getInstance().AssemblyResolver;
#endregion

#region Setup the console window parameters
Utils.Helpers.setupConsole(
$"{Utils.Helpers._assembly.GetName().Name}",
Expand Down
12 changes: 7 additions & 5 deletions infiBanChecker/infiBanChecker/Utils/API.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// ReSharper disable ArrangeAccessorOwnerBody
using System.Net.Http;
using SteamKit2;
using static infiBanChecker.Utils.Helpers;

namespace infiBanChecker.Utils
{
internal abstract class ApiData
{
private protected string _infiToken, _infiSteam64;
private protected SteamID _Steam64;
private protected string _infiToken;
private protected const string _endpoint = "https://api.infistar.de/";
private protected HttpResponseMessage _apiResponse;
private static string _statusCodeMessage;
Expand All @@ -16,10 +18,10 @@ public virtual string infiToken
get => _infiToken;
set => _infiToken = value;
}
public virtual string steamID
public virtual SteamID steamID
{
get => _infiSteam64;
set => _infiSteam64 = value;
get => _Steam64;
set => _Steam64 = value;
}
public virtual HttpResponseMessage response
{
Expand All @@ -38,6 +40,6 @@ public virtual string statusCodeMessage
internal class API : ApiData
{
public override string endpoint => $"{base.endpoint}arma/getGlobalBan";
public override string uri => $"{base.uri}&uid={base.steamID}";
public override string uri => $"{base.uri}&uid={new SteamID(base.steamID.ToString()).ConvertToUInt64()}";
}
}
84 changes: 42 additions & 42 deletions infiBanChecker/infiBanChecker/Utils/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,35 @@ internal sealed class Helpers
internal static API _api;
internal static Assembly _assembly = typeof(Helpers).Assembly;
internal static readonly string _config = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"{ _assembly.GetName().Name}.json");
private static bool isUrlParametersValid, isGlobalBanned, isSteam64Error, isTokenOk = false;
private static bool isUrlParametersValid, isGlobalBanned, isTokenOk = false;
#endregion

#region Resolve Embedded Assemblies
internal Assembly AssemblyResolver(object sender, ResolveEventArgs args)
{
AssemblyName askedAssembly = new AssemblyName(args.Name);
var askedAssembly = new AssemblyName(args.Name);

lock (this)
{
Assembly assembly = null;
Stream stream = _assembly.GetManifestResourceStream($"infiBanChecker.EmbeddedAssemblies.{askedAssembly.Name}.dll");
{
var stream = _assembly.GetManifestResourceStream($"infiBanChecker.EmbeddedAssemblies.{askedAssembly.Name}.dll");
if (stream == null) return null;

if (stream != null)
Assembly assembly = null;
try
{
var assemblyData = new byte[stream.Length];
try
{
stream.Read(assemblyData, 0, assemblyData.Length);
assembly = Assembly.Load(assemblyData);
}
catch (Exception e)
{
Console.WriteLine("Loading embedded assembly: {0}\r\nHas thrown a unhandled exception: {1}", askedAssembly.Name, e);
//Console.ReadKey();
}
finally
{
if(assembly != null)
Console.WriteLine("Loaded embedded assembly: {0}", askedAssembly.Name);
}
stream.Read(assemblyData, 0, assemblyData.Length);
assembly = Assembly.Load(assemblyData);
}
catch (Exception e)
{
Console.WriteLine("Loading embedded assembly: {0}\r\nHas thrown a unhandled exception: {1}", askedAssembly.Name, e);
_ = exitConsole(10);//unsure on this i've never used discards before.
}
finally
{
if(assembly != null)
Console.WriteLine("Loaded embedded assembly: {0}", askedAssembly.Name);
}
return assembly;
}
Expand All @@ -60,10 +58,10 @@ internal Assembly AssemblyResolver(object sender, ResolveEventArgs args)
private static string readSid64FromConsole
{
get
{
{
Console.Clear();
Console.WriteLine("{0}\n", Localization.Language.EnterSteam64Message);
Console.WriteLine("{0}: ", Localization.Language.Steam64);
Console.WriteLine("{0}\n", EnterSteam64Message);
Console.WriteLine("{0}: ", Steam64);
return Console.ReadLine();
}
}
Expand Down Expand Up @@ -173,28 +171,30 @@ private static HttpResponseMessage getUriResponseResult(string apiQuery, HttpCli
#endregion

return response;
}
}

#endregion

#region CheckSteamID
internal static async Task CheckSteam64(API api)
{
#region Check SteamID is valid SteamID number
api.steamID = "";
isSteam64Error = false;
while (api.steamID.Length < 17 || api.steamID.Length > 17 || isSteam64Error)
#region Check SteamID is valid SteamID number

var ci = readSid64FromConsole;
while (Regex.Matches(ci, @"[a-zA-Z]").Count > 0)
{
var stringCheck = stringContainsInteger(readSid64FromConsole);
isSteam64Error = (bool)stringCheck[0];
api.steamID = (string)stringCheck[1];
if (api.steamID.Length == 17 && !isSteam64Error)
{
Console.Clear();
Console.WriteLine("{0}: `{1}` {2}\n", Localization.Language.ValidatingSteam64Message, api.steamID, Localization.Language.ValidatingWithAPIMessage);
break;
}
ci = readSid64FromConsole;
if (Regex.Matches(ci, @"[a-zA-Z]").Count < 0) break;
}

api.steamID = ulong.Parse(ci);

if (api.steamID.IsValid)
{
Console.Clear();
Console.WriteLine("{0}: `{1}` {2}\n", ValidatingSteam64Message, api.steamID, ValidatingWithAPIMessage);
}

#endregion

#region Connect to api and get response
Expand Down Expand Up @@ -239,7 +239,7 @@ internal static async Task CheckSteam64(API api)
}
else
{
_api.statusCodeMessage = (data?.message.Length < 1) ? api?.response.ReasonPhrase : data?.message;
_api.statusCodeMessage = data?.message ?? api?.response.ReasonPhrase;
Console.WriteLine("{0} ({1})\r\n", (int)api?.response?.StatusCode, _api.statusCodeMessage);
}
#endregion
Expand Down Expand Up @@ -352,7 +352,7 @@ internal static async Task<bool> checkInfiStarToken(string tokenFromJson)
#region ExitConsole
internal static async Task exitConsole(int timeout = 10)
{
Console.WriteLine(Localization.Language.AnyKeyToExitMessage);
Console.WriteLine(AnyKeyToExitMessage);
Console.ReadKey();
while (timeout > 0)
{
Expand All @@ -361,7 +361,7 @@ internal static async Task exitConsole(int timeout = 10)
else
{
Console.Clear();
Console.WriteLine("{0} {1} {2}...", Localization.Language.ExitingInMessage, timeout, Localization.Language.Seconds);
Console.WriteLine("{0} {1} {2}...", ExitingInMessage, timeout, Seconds);
await Task.Delay(Helpers.timeSeconds(1));
}
}
Expand Down
9 changes: 8 additions & 1 deletion infiBanChecker/infiBanChecker/infiBanChecker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
<HintPath>EmbeddedAssemblies\Newtonsoft.Json.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="SteamKit2, Version=1.5.1.41089, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>EmbeddedAssemblies\SteamKit2.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand Down Expand Up @@ -72,6 +77,8 @@
<LastGenOutput>Language.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<EmbeddedResource Include="EmbeddedAssemblies\SteamKit2.dll" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

0 comments on commit b7bdcf1

Please sign in to comment.