KnossosNET / Knossos.NET

Repository for the Knossos.NET launcher, currently in development.
GNU General Public License v3.0
23 stars 10 forks source link

Feature discussion: knossos:// URI #103

Open notimaginative opened 8 months ago

notimaginative commented 8 months ago

To help promote ease of use we should introduce a knossos:// URI for interacting with kNet from websites. This could allow such things as setting certain configuration options (e.g., PXO creds), launching a particular mod/version (e.g., for multi games), searching for or showing details of a mod (e.g., mod announcements/websites), etc..

Configuration differs based on the platform. On Windows the installer can set it up easily, and manual instructions can also be provided. On Linux, setup via manual instructions is likely the best route. On Mac, this can be set via the Info.plist in the app bundle.

For all platforms, clicking on a knossos:// link would launch kNet with the full URI as a command line option. From there we validate it, break it down, and act accordingly.

However to make this function properly we need to make kNet run as a single instance, as it will otherwise launch a new instance of kNet every time a knossos:// link is clicked. Mac app bundles are already single instance so we mostly just have to worry about Linux and Windows.

This issue can be used to discuss how best to use the URI and track what requirements or changes might be needed to best implement it.

notimaginative commented 8 months ago

The URI would probably be broken down like so: the host element would be a command, the next section of the URI would be an action based on that command, the query string would contain optional (or even required) elements.

Some examples:

Setting you PXO credentials: knossos://config/pxo?login=1234&password=abcde Playing a mod: knossos://play/my_cool_mod?version=1.0.0 Exploring a mod: knossos://explore/my_cool_mod Install/update: knossos://install/my_cool_mod

notimaginative commented 8 months ago

Functional but useless code to show the possible breakdown of the URI argument on the command line:

if (arg.StartsWith("knossos://"))
{
    var uri = new Uri(arg);

    string command = uri.Host.ToLower();

    if (command == "config")
    {
        if (uri.Segments.Length != 2)
        {
            Console.WriteLine($"ERROR: Invalid segment count for {command}");
        }
        else
        {
            string section = uri.Segments[1].ToLower().Replace("/", "");

            if (section == "pxo")
            {
                var login = HttpUtility.ParseQueryString(uri.Query).Get("login");
                var password = HttpUtility.ParseQueryString(uri.Query).Get("password");

                Console.WriteLine($"setting PXO login to \"{login}\" and password to \"{password}\"");
            }
            else
            {
                Console.WriteLine($"section: {section}");
            }
        }
    }
    else if (command == "play")
    {
        if (uri.Segments.Length != 2)
        {
            Console.WriteLine($"ERROR: Invalid segment count for {command}");
        }
        else
        {
            var modid = uri.Segments[1].Replace("/", "");
            var modver = HttpUtility.ParseQueryString(uri.Query).Get("version");

            if (modver != string.Empty)
            {
                Console.WriteLine($"playing mod: {modid}, version {modver}");
            }
            else
            {
                Console.WriteLine($"playing mod: {modid}");
            }
        }
    }
    else
    {
        Console.WriteLine($"command: {command}");
    }
}
JohnAFernandez commented 8 months ago

That kind of demystifies things.

notimaginative commented 7 months ago

Adding a couple of mental notes I had late last week...

As a basic safety check the config command should show a popup of some sort to confirm any changes about to be made. Seems obvious in hindsight, but it didn't occur to me originally.

The play command should also allow an engine build to be specified. A necessity for multi sessions, plus it might be helpful when asking someone to test a mod/build where you simply give them a knossos:// link and everything just works.

And the addition of some sort of UI/UX for constructing a knossos:// link would be quite handy as well. A visit to the wiki shouldn't be required to get a functional link to share.

MjnMixael commented 5 months ago

I know this is a year after the fact, but I was just wondering if KNet could do this since the original Knossos can. I tested clicking the FSO:// buttons on Nebula and it did nothing. Could be my environment or could be KNet. I'm unsure.

Either way, this kind of functionality would go a long way to simplifying things for players even further.

JohnAFernandez commented 1 month ago

Totally missed this comment. Interesting. @notimaginative FSO:// might already exist!

Originally came here to add, as noted on Knossos internal, we are likely going to need to enforce a single instance of Knet to support URI.