feat: argument parsing for joinscript/ticket
This commit is contained in:
parent
7312842e7d
commit
1e693cabc2
|
|
@ -9,7 +9,8 @@ namespace Kiseki.Launcher
|
|||
public class Controller
|
||||
{
|
||||
private readonly string BaseURL;
|
||||
private readonly string[] Arguments;
|
||||
private readonly string JoinScriptURL;
|
||||
private readonly string Ticket;
|
||||
|
||||
public event EventHandler<string>? PageHeadingChanged;
|
||||
public event EventHandler<int>? ProgressBarChanged;
|
||||
|
|
@ -19,7 +20,26 @@ namespace Kiseki.Launcher
|
|||
public Controller(string BaseURL, string[] Arguments)
|
||||
{
|
||||
this.BaseURL = BaseURL;
|
||||
this.Arguments = Arguments;
|
||||
|
||||
// TODO: handle these more gracefully
|
||||
if (Arguments.Length != 0 || Arguments[0] != "launch")
|
||||
{
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
||||
if (!Helpers.IsBase64String(Arguments[0]))
|
||||
{
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
||||
string payload = Helpers.ConvertBase64ToString(Arguments[0]);
|
||||
if (payload.Split("|").Length != 2) // joinscripturl, ticket; TODO: this will also include launchmode (ide/play)
|
||||
{
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
||||
JoinScriptURL = payload.Split("|")[0];
|
||||
Ticket = payload.Split("|")[1];
|
||||
}
|
||||
|
||||
public async void Start()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
using System.Text;
|
||||
|
||||
namespace Kiseki.Launcher
|
||||
{
|
||||
public static class Helpers
|
||||
{
|
||||
// https://stackoverflow.com/a/54143400
|
||||
public static bool IsBase64String(string base64)
|
||||
{
|
||||
Span<byte> buffer = new(new byte[base64.Length]);
|
||||
|
||||
return Convert.TryFromBase64String(base64, buffer, out _);
|
||||
}
|
||||
|
||||
public static string ConvertBase64ToString(string base64)
|
||||
{
|
||||
Span<byte> buffer = new(new byte[base64.Length]);
|
||||
Convert.TryFromBase64String(base64, buffer, out _);
|
||||
|
||||
return Encoding.UTF8.GetString(buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue