Knowledge Base

Preserving for the future: Shell scripts, AoC, and more

aoe2de protocol handler for Linux

Overview

The url using a custom protocol aoe2de://1/12394872348 can be used by Age of Empires 2: Definitive Edition to directly join or spectate a game. This behavior can be established in GNU/Linux with some easy customization.

Making the protocol links work

  1. Modify xdg-open.

    By default, xdg-open does not recognize protocol aoe2de:// as a URL because of the digit. It treats the protocol as a file instead of a url, so I had to modify /usr/bin/xdg-open:

    sudo sed -i.bup -r -e '/grep -q.\*:alpha:.\*then/s/:alpha:/:alnum:/g;' /usr/bin/xdg-open
    

    Alternatively, you just need to modify the regular expression inside function to use alnum:

    # Returns true if argument is a file:// URL or path
    is_file_url_or_path()
    {
        if echo "$1" | grep -q '^file://' \
                || ! echo "$1" | egrep -q '^[[:alnum:]+\.\-]+:'; then
            return 0
        else
            return 1
        fi
    }
    
  2. Establish script to run AOEURLHelper.exe.

    I named it ~/bin/aoe2de-protocol.

    #!/bin/sh
    # Startdate: 2023-11-14-3 19:51
    # Author: bgstack15
    # Documentation:
    #    Because I use Proton Experimental, I use that path.
    #    813780 = steamid for Age of Empires 2 Definitive Edition
    STEAM_COMPAT_CLIENT_INSTALL_PATH=~/.steampath STEAM_COMPAT_DATA_PATH="${HOME}/.local/share/Steam/steamapps/compatdata/813780" ${HOME}/.local/share/Steam/steamapps/common/Proton\ -\ Experimental/proton runinprefix "${HOME}/.local/share/Steam/steamapps/compatdata/813780/pfx/drive_c/Program Files (x86)/AOE URL Helper/AOEURLHelper.exe" "${@}"
  3. Establish desktop file with mimetype handler.

    I named mine ~/.local/share/applications/aoe2de-protocol.desktop.

    [Desktop Entry]
    Name=AOEURLHelper
    Comment=Load url for Age of Empires 2: Definitive Edition
    Exec=aoe2de-protocol %u
    Icon=steam_icon_813780
    Terminal=false
    Type=Application
    Categories=Game;
    MimeType=x-scheme-handler/aoe2de;
    
  4. Ensure this desktop file is used with xdg-open.

    Run these commands.

    $ xdg-mime default aoe2de-protocol.desktop x-scheme-handler/aoe2de
    $ xdg-mime query default x-scheme-handler/aoe2de
    aoe2de-protocol.desktop
    
  5. Configure Firefox-based web browser to use this application for links of this protocol.

    In about:config, set a new boolean network.protocol-handler.expose.aoe2de = false. Then visit one of the lobby browsers (below) and find a join link. Select the link, and choose your new .desktop file.

    The first time, it failed. When I tried again, the web browser showed the second menu item named "AOEURLHelper" which is what I put in that "Name" field and it did invoke my shell script and then try to join the game.

Additional thoughts

The xdg-open aoe2de://0/123412341234 invocation works when the game is not already running, and when the game is already running. Of course, due to how long it takes the game to load, loading a aoe2de link loads faster if the game is already running.

Protocol description

This is not a specification because I don't know of any that has been published.

aoe2de://0/126811196

This link tries to join game id 126811196. You can learn your game id when you are the host, from the button in the upper-right of the lobby screen.

aoe2de://1/123498272

The top virtual directory /1/ indicates that the program should try to spectate the match.

Lobby browsers

If these are working at any given moment, here are a few that I found:

  1. Lobby Browser - Age of Empires 2 - AoE2 Insights
  2. AoE2.net

References

Weblinks

  1. xdg - Create a custom URL Protocol Handler - Unix & Linux Stack Exchange
  2. linux - Ubuntu custom URL protocol handler - Stack Overflow
  3. [RESOLVED] AoE2.net Spectate button no longer working. Someone please help me!!! | AoEZone - The International Age of Empires Community
  4. Running a second program inside a proton prefix. : linux_gaming
  5. Set custom protocol handler in Firefox? - Stack Overflow
  6. Register protocol - MozillaZine Knowledge Base

Web search

  1. steam run command in proton context
  2. firefox handle protocol

My blog

  1. Download voobly mods from browser

Comments