From 33ed11278be2a4f877d990182a906f4879313003 Mon Sep 17 00:00:00 2001 From: VollRahm Date: Mon, 29 Mar 2021 20:13:40 +0200 Subject: [PATCH] - Uploaded source --- src/App.config | 6 +++ src/Log.cs | 37 +++++++++++++ src/Program.cs | 53 +++++++++++++++++++ src/Properties/AssemblyInfo.cs | 36 +++++++++++++ src/R6dbAPI.cs | 95 ++++++++++++++++++++++++++++++++++ src/UplayNameChecker.csproj | 55 ++++++++++++++++++++ 6 files changed, 282 insertions(+) create mode 100644 src/App.config create mode 100644 src/Log.cs create mode 100644 src/Program.cs create mode 100644 src/Properties/AssemblyInfo.cs create mode 100644 src/R6dbAPI.cs create mode 100644 src/UplayNameChecker.csproj diff --git a/src/App.config b/src/App.config new file mode 100644 index 0000000..193aecc --- /dev/null +++ b/src/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/Log.cs b/src/Log.cs new file mode 100644 index 0000000..4ae737a --- /dev/null +++ b/src/Log.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +public static class Log +{ + public static void Info(object value) + { + Log.Color(ConsoleColor.Yellow); + Console.WriteLine("[!] " + value.ToString()); + Log.Color(); + } + + public static void Critical(object value) + { + Log.Color(ConsoleColor.Cyan); + Console.WriteLine("[+] " + value.ToString()); + } + + public static void Error(object value) + { + Log.Color(ConsoleColor.Red); + Console.WriteLine("[-] " + value.ToString()); + Log.Color(); + } + + public static void Fatal(object value) + { + Error(value); + Console.ReadLine(); + Environment.Exit(-1); + } + + private static void Color(ConsoleColor color = ConsoleColor.White) => Console.ForegroundColor = color; +} diff --git a/src/Program.cs b/src/Program.cs new file mode 100644 index 0000000..b50e0f2 --- /dev/null +++ b/src/Program.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UplayNameChecker +{ + class Program + { + static void Main(string[] args) + { + Program.MainAsync().GetAwaiter().GetResult(); + } + + static async Task MainAsync() + { + if (!File.Exists("names.txt")) + Log.Fatal("names.txt not found."); + + Log.Info("Reading names.txt..."); + string[] namesToCheck; + + try + { + namesToCheck = File.ReadAllLines("names.txt"); + } + catch (Exception ex) + { + Log.Error("Could not read names.txt: " + ex.Message); + return; + } + + R6dbAPI r6db = new R6dbAPI(); + + await Task.Delay(100); + Log.Info("Starting to check...\n"); + + foreach (var name in namesToCheck) + { + bool available = await r6db.IsNameAvailable(name); + Log.Critical($"{name} is {(available ? "" : "not ")} available."); + + if (available) + File.AppendAllLines("availableNames.txt", new string[] { name }); + } + Console.WriteLine(); + Log.Info("Written results to availableNames.txt."); + Console.ReadLine(); + } + } +} diff --git a/src/Properties/AssemblyInfo.cs b/src/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..8513be8 --- /dev/null +++ b/src/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("UplayNameChecker")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("UplayNameChecker")] +[assembly: AssemblyCopyright("Copyright © 2021")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("324bda05-3e1b-456c-8cd9-a364846db2cd")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/R6dbAPI.cs b/src/R6dbAPI.cs new file mode 100644 index 0000000..b77321e --- /dev/null +++ b/src/R6dbAPI.cs @@ -0,0 +1,95 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; + +namespace UplayNameChecker +{ + public class R6dbAPI + { + private HttpClient httpClient = new HttpClient(); + private const string URI = "https://api.statsdb.net/r6/namecheck/"; + + public async Task IsNameAvailable(string name) + { + try + { + var reqUri = URI + System.Net.WebUtility.UrlEncode(name); + var timestamp = GetCurrentTimestamp(); + var apiKey = GenerateAuthToken(timestamp); + + HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, reqUri); + request.Headers.Add("x-api-key", apiKey); + request.Headers.Add("origin", "https://r6db.net"); + + var response = await httpClient.SendAsync(request); + return (await response.Content.ReadAsStringAsync()).Contains("exists\":false"); + } + catch (Exception ex) + { + Log.Error($"Could not check name {name}: {ex.Message}"); + return false; + } + } + + public string GenerateAuthToken(ulong timestamp) + { + var seed = "a3d6b18fa919072d65d890c47b336f1f78fc11c4"; + var sTimestamp = timestamp.ToString(); + var code = ""; + + for(int i = 0; i < sTimestamp.Length; i++) + { + var t = int.Parse(sTimestamp[i].ToString()); + var c = (int)seed[i % seed.Length]; + switch (t) + { + case 0: break; + case 1: + c = c - 1; + break; + case 2: + c = c >> 1; + break; + case 3: + c = c << 1; + break; + case 4: + c = (int)Math.Pow(t, c % 4); + break; + case 5: + c = (int)Math.Round(Math.Sqrt(c)); + break; + case 6: + c = c << t; + goto case 7; + case 7: + c = c - 12; + break; + case 8: + c = 0; + break; + default: + c = -69420; + break; + } + if (c == -69420) continue; + code += c.ToString(); + } + var str2 = "authscript:" + code + ":" + timestamp + $":{GetTodaysTimestamp()}"; + return Convert.ToBase64String(Encoding.UTF8.GetBytes(str2)); + } + + private ulong GetCurrentTimestamp() + { + return (ulong)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; + } + + private ulong GetTodaysTimestamp() + { + return (ulong)DateTime.Today.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; + } + } +} diff --git a/src/UplayNameChecker.csproj b/src/UplayNameChecker.csproj new file mode 100644 index 0000000..9ef36f0 --- /dev/null +++ b/src/UplayNameChecker.csproj @@ -0,0 +1,55 @@ + + + + + Debug + AnyCPU + {324BDA05-3E1B-456C-8CD9-A364846DB2CD} + Exe + UplayNameChecker + UplayNameChecker + v4.8 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file