This repository has been archived by the owner on Aug 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Note: Console unique certificate is stubbed out; you will need a valid dumped client cert from your console in .p12 format with the password "switch". The Discord webhook for integration with the Reswitched server has similarly been censored.
- Loading branch information
Showing
13 changed files
with
885 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 14 | ||
VisualStudioVersion = 14.0.25123.0 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HacVersionListBot", "HacVersionListBot\HacVersionListBot.csproj", "{BCFB87CC-64A3-4C2D-B472-18354CC57358}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{BCFB87CC-64A3-4C2D-B472-18354CC57358}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{BCFB87CC-64A3-4C2D-B472-18354CC57358}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{BCFB87CC-64A3-4C2D-B472-18354CC57358}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{BCFB87CC-64A3-4C2D-B472-18354CC57358}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using HacVersionListBot.Properties; | ||
|
||
namespace HacVersionListBot | ||
{ | ||
|
||
|
||
class DiscordUtils | ||
{ | ||
private static readonly string discord_webhook_url = Resources.DiscordWebhook; | ||
|
||
public static void SendMessage(string message, byte[] version_list, string filename) | ||
{ | ||
if (!discord_webhook_url.StartsWith("http")) | ||
{ | ||
Program.Log($"Discord webhook not set up."); | ||
return; | ||
} | ||
try | ||
{ | ||
using (var form = new MultipartFormDataContent()) | ||
using (var httpC = new HttpClient()) | ||
{ | ||
|
||
form.Add(new StringContent(message), "content"); | ||
form.Add(new StringContent(filename), "Filename"); | ||
form.Add(new ByteArrayContent(version_list, 0, version_list.Length), "hac_versionlist", filename); | ||
|
||
var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30)); | ||
var response = httpC.PostAsync(new Uri(discord_webhook_url), form, cts.Token).Result; | ||
Program.Log(response.ToString()); | ||
} | ||
} | ||
catch (WebException wex) | ||
{ | ||
Program.Log($"Failed to post to discord: {wex.Message}"); | ||
} | ||
} | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
HacVersionListBot/HacVersionListBot/HacVersionListBot.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{BCFB87CC-64A3-4C2D-B472-18354CC57358}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>HacVersionListBot</RootNamespace> | ||
<AssemblyName>HacVersionListBot</AssemblyName> | ||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="DSharpPlus, Version=2.5.4.0, Culture=neutral, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\DSharpPlus.2.5.4\lib\net45\DSharpPlus.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="DiscordUtils.cs" /> | ||
<Compile Include="NetworkUtils.cs" /> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="Properties\Resources.Designer.cs"> | ||
<AutoGen>True</AutoGen> | ||
<DesignTime>True</DesignTime> | ||
<DependentUpon>Resources.resx</DependentUpon> | ||
</Compile> | ||
<Compile Include="ShogunUtils.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="App.config" /> | ||
<None Include="packages.config" /> | ||
<None Include="Resources\ConsoleCert.p12" /> | ||
<None Include="Resources\ShopN.p12" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<EmbeddedResource Include="Properties\Resources.resx"> | ||
<Generator>ResXFileCodeGenerator</Generator> | ||
<LastGenOutput>Resources.Designer.cs</LastGenOutput> | ||
<SubType>Designer</SubType> | ||
</EmbeddedResource> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
using System; | ||
using System.IO; | ||
using System.Net; | ||
using System.Security.Cryptography.X509Certificates; | ||
using HacVersionListBot.Properties; | ||
|
||
|
||
namespace HacVersionListBot | ||
{ | ||
class NetworkUtils | ||
{ | ||
private static X509Certificate ShopNCert = new X509Certificate(Resources.ShopN, Resources.ShopN_Password); | ||
private static X509Certificate ConsoleCert = new X509Certificate(Resources.ConsoleCert, Resources.ConsoleCert_Password); | ||
|
||
public static byte[] TryDownload(string file) | ||
{ | ||
try | ||
{ | ||
return new WebClient().DownloadData(file); | ||
} | ||
catch (WebException) | ||
{ | ||
Program.Log($"Failed to download {file}."); | ||
return null; | ||
} | ||
} | ||
|
||
public static byte[] TryCertifiedDownload(string file, X509Certificate x509, string userAgent = "") | ||
{ | ||
try | ||
{ | ||
return new CertificateWebClient(x509, userAgent).DownloadData(file); | ||
} | ||
catch (WebException) | ||
{ | ||
Program.Log($"Failed to download {file}."); | ||
return null; | ||
} | ||
} | ||
|
||
public static byte[] TryConsoleDownload(string file) | ||
{ | ||
return TryCertifiedDownload(file, ConsoleCert); | ||
} | ||
|
||
public static string TryMakeCertifiedRequest(string URL, X509Certificate clientCert, bool json = true, string userAgent = "") | ||
{ | ||
var wr = WebRequest.Create(new Uri(URL)) as HttpWebRequest; | ||
wr.UserAgent = userAgent; | ||
if (json) | ||
wr.Accept = "application/json"; | ||
wr.Method = WebRequestMethods.Http.Get; | ||
wr.ClientCertificates.Clear(); | ||
wr.ClientCertificates.Add(clientCert); | ||
try | ||
{ | ||
using (var resp = wr.GetResponse() as HttpWebResponse) | ||
{ | ||
return new StreamReader(resp.GetResponseStream()).ReadToEnd().Replace("\n", "\\n").Replace("\r", "\\r").Replace("\t", "\\t"); | ||
} | ||
} | ||
catch (WebException ex) | ||
{ | ||
Program.Log($"Error: Failed to make request to {URL} -- WebException {ex.Message}."); | ||
} | ||
catch (NullReferenceException nex) | ||
{ | ||
Program.Log($"Error: Failed to make request to {URL} -- NullReferenceException {nex.Message}."); | ||
} | ||
return null; | ||
} | ||
|
||
public static string TryMakeShogunRequest(string URL) | ||
{ | ||
return TryMakeCertifiedRequest(URL, ShopNCert); | ||
} | ||
|
||
public static string TryMakeConsoleRequest(string URL) | ||
{ | ||
return TryMakeCertifiedRequest(URL, ConsoleCert); | ||
} | ||
|
||
private class CertificateWebClient : WebClient | ||
{ | ||
private X509Certificate client_cert; | ||
private readonly string user_agent; | ||
|
||
public CertificateWebClient(X509Certificate cert, string ua = "") : base() | ||
{ | ||
client_cert = cert; | ||
user_agent = ua; | ||
} | ||
|
||
protected override WebRequest GetWebRequest(Uri address) | ||
{ | ||
var request = (HttpWebRequest)WebRequest.Create(address); | ||
request.ClientCertificates.Clear(); | ||
request.ClientCertificates.Add(client_cert); | ||
request.UserAgent = user_agent; | ||
return request; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.