Skip to content

Commit

Permalink
Add Soulbreak Parser and Soulbreak Tracker API Link
Browse files Browse the repository at this point in the history
Added extra handler to proxy when accessing party screen to retrieve list of Soulbreaks and upload them to https://ffrk.gigaforge.com Soulbreak Tracker if the user has entered an API key.
  • Loading branch information
gigaforge committed Nov 19, 2022
1 parent 6f48c2c commit 3bb2bf7
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 37 deletions.
78 changes: 50 additions & 28 deletions FFRK-LabMem/Config/UI/ConfigForm.Designer.cs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions FFRK-LabMem/Config/UI/ConfigForm.cs
Expand Up @@ -144,6 +144,7 @@ private void ConfigForm_Load(object sender, EventArgs e)
numericUpDownCountersRarity.Value = configHelper.GetInt("counters.materialsRarityFilter", 6);
textBoxLogFolder.Text = configHelper.GetString("console.logFolder", "");
textBoxScreenshotFolder.Text = configHelper.GetString("adb.screenshotFolder", "");
textBoxSoulbreakApiKey.Text = configHelper.GetString("soulbreak.api","");

// Load lab .json
LoadConfigs();
Expand Down Expand Up @@ -236,6 +237,8 @@ private async void ButtonOk_Click(object sender, EventArgs e)
configHelper.SetValue("console.logging", checkBoxLogging.Checked);
configHelper.SetValue("console.debugCategories", (short)buttonDebug.Tag);
configHelper.SetValue("console.logFolder", textBoxLogFolder.Text);
configHelper.SetValue("soulbreak.api", textBoxSoulbreakApiKey.Text);
SoulbreakSync.APIKEY = textBoxSoulbreakApiKey.Text;
ColorConsole.Timestamps = checkBoxTimestamps.Checked;
ColorConsole.LogBuffer.Enabled = checkBoxLogging.Checked;
ColorConsole.LogBuffer.UpdateFolderOrDefault(textBoxLogFolder.Text);
Expand Down
4 changes: 2 additions & 2 deletions FFRK-LabMem/Config/UI/ConfigForm.resx
Expand Up @@ -128,7 +128,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1Y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MwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA
Expand Down
1 change: 1 addition & 0 deletions FFRK-LabMem/FFRK-LabMem.csproj
Expand Up @@ -138,6 +138,7 @@
<Compile Include="Services\Clipboard.cs" />
<Compile Include="Services\ConsoleTasks.cs" />
<Compile Include="Services\Scheduler.cs" />
<Compile Include="Services\SoulbreakSync.cs" />
<Compile Include="Services\Tray.cs" />
<Compile Include="Services\Tyro.cs" />
<Compile Include="Services\Updates.cs" />
Expand Down
1 change: 1 addition & 0 deletions FFRK-LabMem/Machines/Lab.cs
Expand Up @@ -346,6 +346,7 @@ private async void Watchdog_BattleLoop(object sender, LabWatchdog.WatchdogEventA

public override void RegisterWithProxy(Proxy Proxy)
{
Proxy.AddRegistration("party/list_buddy", parser.ParseSoulbreaks);
Proxy.AddRegistration("get_display_paintings", parser.ParseDisplayPaintings);
Proxy.AddRegistration("select_painting", async (args) =>
{
Expand Down
14 changes: 14 additions & 0 deletions FFRK-LabMem/Machines/LabParser.cs
@@ -1,4 +1,5 @@
using FFRK_LabMem.Data;
using FFRK_LabMem.Services;
using FFRK_Machines;
using Newtonsoft.Json.Linq;
using System;
Expand Down Expand Up @@ -83,6 +84,19 @@ public async Task ParseDataChanged(JObject data)
}
}

}
public async Task ParseSoulbreaks(RegistrationHandlerArgs args)
{
var soulbreaks = args.Data["soul_strikes"];
string sb_string = "";
foreach (var sb in soulbreaks)
{
sb_string += sb["id"] + ",";
}
sb_string = sb_string.Remove(sb_string.Length - 1, 1);
await SoulbreakSync.Sync(sb_string);


}

public async Task ParseDisplayPaintings(RegistrationHandlerArgs args)
Expand Down
7 changes: 7 additions & 0 deletions FFRK-LabMem/Program.cs
Expand Up @@ -50,6 +50,7 @@ static void Main(string[] args)
Console.Title = versionTitle;
if (config.GetBool("updates.checkForUpdates", false))
_ = Updates.Check(config.GetBool("updates.includePrerelease", false));
SoulbreakSync.APIKEY = config.GetString("soulbreak.api", "");

LabController controller = null;
try
Expand All @@ -61,6 +62,12 @@ static void Main(string[] args)
ColorConsole.WriteLine(ConsoleColor.DarkYellow, "Japanese output: click treasure chest in top left then Properties and change Font to MS Gothic");
ColorConsole.WriteLine(ConsoleColor.DarkYellow, "See Readme.md on GitHub for more information");

// Soulbreak Synchronization Prompts
if (SoulbreakSync.APIKEY.Length < 1)
Console.WriteLine("Enter an API Key from https://ffrk.gigaforge.com to begin tracking Soulbreaks.");
else
Console.WriteLine("Soulbreaks will synchronize with https://ffrk.gigaforge.com when you enter the Party menu.");

// Ad-hoc command loop
Console.WriteLine("Press 'D' to Disable, 'E' to Enable, 'C' for Config, 'S' for Stats, 'Ctrl+X' to Exit");
Console.WriteLine("Type ? for help");
Expand Down
10 changes: 5 additions & 5 deletions FFRK-LabMem/Properties/AssemblyInfo.cs
Expand Up @@ -6,11 +6,11 @@
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("FFRK-LabMem")]
[assembly: AssemblyDescription("Labyrinth bot for FFRK")]
[assembly: AssemblyDescription("Labyrinth bot and Soulbreak Tracker for FFRK (JP)")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("bover87")]
[assembly: AssemblyCompany("trgKai")]
[assembly: AssemblyProduct("FFRK-LabMem")]
[assembly: AssemblyCopyright("Copyright © HughJeffner, mendicant, bover87 2022")]
[assembly: AssemblyCopyright("Copyright © HughJeffner, mendicant, bover87, trgKai 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -32,5 +32,5 @@
// 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("8.3.1.0")]
[assembly: AssemblyFileVersion("8.3.1.0")]
[assembly: AssemblyVersion("9.0.0.0")]
[assembly: AssemblyFileVersion("9.0.0.0")]
71 changes: 71 additions & 0 deletions FFRK-LabMem/Services/SoulbreakSync.cs
@@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using FFRK_Machines;
using FFRK_Machines.Services.Adb;
using Newtonsoft.Json.Linq;
using Semver;
using Syroot.Windows.IO;

namespace FFRK_LabMem.Services
{
class SoulbreakSync
{

private String Endpoint { get; set; }
private Boolean IncludePreRelease { get; set; }
private HttpClient httpClient;
private const String WEB_URL = "https://ffrk.gigaforge.com/ffrk_sync.php";
public static string APIKEY = "";
private const string GITHUB_USER = "gigaforge";
private const string GITHUB_REPO = "FFRK-LabMem-SBTracker";

public SoulbreakSync()
{

this.Endpoint = WEB_URL;
ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;
httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add("User-Agent", String.Format("{0} {1}", GetName(), GetVersionCode("")));
}

public static String GetVersionCode(String preRelease = "jp")
{
var version = Assembly.GetExecutingAssembly().GetName().Version;
var suffix = (String.IsNullOrEmpty(preRelease)) ? "" : "-" + preRelease;
return string.Format("v{0}.{1}.{2}{3}", version.Major, version.Minor, version.Build, suffix);
}

public static String GetName()
{
return Assembly.GetExecutingAssembly().GetName().Name;
}

public static async Task<bool> Sync(string soulbreaks)
{
if (APIKEY.Length > 1)
{
ColorConsole.WriteLine(ConsoleColor.DarkYellow, "Sending Soulbreaks to http://ffrk.gigaforge.com/ tracker (may appear multiple times)...");
var checker = new SoulbreakSync();
var values = new Dictionary<string, string>
{
{ "sb_list", soulbreaks },
{ "api_key", APIKEY }
};
var content = new FormUrlEncodedContent(values);
var response = await checker.httpClient.PostAsync(WEB_URL, content);
}

return true;
}


}
}
5 changes: 3 additions & 2 deletions FFRK-LabMem/Services/Updates.cs
Expand Up @@ -23,8 +23,8 @@ class Updates
private HttpClient httpClient;
private const String API_URL = "https://api.github.com/repos/{0}/{1}/releases";
private const String WEB_URL = "https://github.com/{0}/{1}/releases";
private const string GITHUB_USER = "bover87";
private const string GITHUB_REPO = "HMB-FFRK-JP-LabMem";
private const string GITHUB_USER = "gigaforge";
private const string GITHUB_REPO = "FFRK-LabMem-SBTracker";

public Updates(bool includePreRelease)
{
Expand All @@ -51,6 +51,7 @@ public static String GetName()

public static async Task<bool> Check(bool includePreRelease)
{
return false;
ColorConsole.WriteLine(ConsoleColor.DarkYellow, "Checking for newer releases...");
var checker = new Updates(includePreRelease);
try
Expand Down

0 comments on commit 3bb2bf7

Please sign in to comment.