[Helpful knowledge]How to register PA to a custom protocol

Discussion in 'Mod Discussions' started by cola_colin, April 20, 2014.

  1. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,074
    Likes Received:
    16,221
    ... and pass useful information into it.

    So the idea is i.e. that in the future PA Stats may have a link like startpa://replay=replayid that, if you click it, opens PA and starts the replay. Other ideas are startpa://gamedata={jsonblob} to i.e. have a link on a tournament page that directly starts PA and puts you in a lobby vs your opponent. Or puts you in a lobby with some default planet. Or adds a planet to your systems. Or other things that I can't think of right now.

    So here is how this can be done:

    Currently I base this on the parameter --username of pa.exe. It seems to be unused and the value is given to the javascript layer so we can use it.

    First let's see how to get the value in the javascript layer:

    You need a small handler in the start scene like this:
    Code:
    var myData = undefined;
    
        var oldSetupInfo = handlers.setup_info;
        handlers.setup_info = function(payload) {
            oldSetupInfo(payload);
            if (payload.username && payload.username.indexOf("startpa://") === 0) {
               // this removes some junk that is added by the protocol handling
                payload.username = payload.username.replace("startpa://", "").replace("/", "");
                 // check if the key myawesomedata= is given, if so use it
                if (payload.username.indexOf("myawesomedata=") === 0) { // for the example I
                    myData= payload.username.substring("myawesomedata=".length, payload.username.length);
                }
            }
        };
    
        model.inMainMenu.subscribe(function(v) {
            if (v && myData && model.signedInToUbernet()) { // means the user logged in and myData has the special data
    // invoke whatever magic you want based on the string myData
            }
        });
    So this is all code you need to get the value of a parameter that is given to you. Now we need to make some sort of link that webpages can give so pa is opened.

    The command that needs to be run is this:
    pa.exe --username "startpa://awesomedata=blablabla/"

    Note that people should use specific names for the key, so there are no conflicts for the keyname. Maybe somebody should make this a framework, but I am too lazy for that now.

    To register the protocol startpa:// on windows you can add a bit of stuff to the registry. The reg file should look like this, with the paths (PA.exe) replaced for the correct ones:

    Code:
    Windows Registry Editor Version 5.00
    
    [HKEY_CLASSES_ROOT\Wow6432Node\startpa]
    @=""
    "URL Protocol"=""
    
    [HKEY_CLASSES_ROOT\Wow6432Node\startpa\shell]
    
    [HKEY_CLASSES_ROOT\Wow6432Node\startpa\shell\open]
    
    [HKEY_CLASSES_ROOT\Wow6432Node\startpa\shell\open\command]
    @="PA.exe --username \"%1\""
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\startpa]
    @=""
    "URL Protocol"=""
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\startpa\shell]
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\startpa\shell\open]
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\startpa\shell\open\command]
    @="PA.exe --username \"%1\""
    That's all.
    For linux a bit more research is needed, but I am sure there is a way. Maybe somebody wants to add it here. Or I might check it out, but not now.
    Last edited: April 27, 2014
  2. gameg1rl

    gameg1rl Member

    Messages:
    17
    Likes Received:
    28
    Hi,
    Please let me know whether this information is still relevant as several builds and updates have occurred since your post.
    Thank you!
    --Gameg1rl

Share This Page