From fdeffeb65ec9c765280fc4130722570e2c3c3b76 Mon Sep 17 00:00:00 2001 From: flowtron Date: Sat, 5 Feb 2022 13:25:46 +0100 Subject: [PATCH] delayed connectprotocol till AfterAuth --- install_connectprotocol.sh | 61 ++++++++++++++++++++++++++++ source/dev_tools/packaging_guide.txt | 2 + source/src/main.cpp | 46 ++++++++++++++++++++- 3 files changed, 107 insertions(+), 2 deletions(-) create mode 100755 install_connectprotocol.sh diff --git a/install_connectprotocol.sh b/install_connectprotocol.sh new file mode 100755 index 00000000..53c1476f --- /dev/null +++ b/install_connectprotocol.sh @@ -0,0 +1,61 @@ +#!/bin/bash +# Adds a custom menuitem for AssaultCube to your Desktop's launcher. + +CUBE_DIR=$(dirname "$(readlink -f "${0}")") +CUBE_EXEC=assaultcube.sh +LAUNCHERPATH="${HOME}/.local/share/applications/" + +LAUNCHERFILE=assaultcube-connectprotocol.desktop +LAUNCHERTITLE="AssaultCube Connect Protocol" + +# Remove existing desktop entries, if they exist: +# avoiding clashing with menuitem scripts & filenames which look for "assaultcube*" +EXISTINGEXEC=`find "${LAUNCHERPATH}" -name "connectprotocol-assaultcube*" | xargs` +if [ "$EXISTINGEXEC" != "" ]; then + echo "The following entries currently exist:" + echo "$EXISTINGEXEC" + read -p "Would you like them all to be deleted? (y/N): " -r REPLY + if [ "$REPLY" = "y" ] || [ "$REPLY" = "yes" ] || [ "$REPLY" = "Y" ] || [ "$REPLY" = "YES" ]; then + find "${LAUNCHERPATH}" -name "connectprotocol-assaultcube*" -delete + echo "Deleted entries as requested." && echo "" + exit 0 + else + echo "The existing entries will remain." && echo "" + fi +fi + +mkdir -p "${LAUNCHERPATH}" +cat > "${LAUNCHERPATH}"${LAUNCHERFILE} << EOF +[Desktop Entry] +Type=Application +Name=$LAUNCHERTITLE +StartupNotify=false +Exec=$CUBE_DIR/$CUBE_EXEC %u +MimeType=x-scheme-handler/assaultcube; +EOF + +havexdgmime=$(which xdg-mime) +if [ "$havexdgmime" != "" ]; then + # ignoring any previously registered handler. this should be the current default. + xdg-mime default assaultcube-connectprotocol.desktop x-scheme-handler/assaultcube + worked=$(xdg-mime query default x-scheme-handler/assaultcube 2>/dev/null) + if [ "$worked" != "${LAUNCHERFILE}" ]; then + # non-empty output should be the desktop filename + # due to the EXISTINGEXEC routine we can leave the desktop entry for analysis + echo "The AssaultCube desktop entry could not be hooked to the x-scheme-handler/assaultcube mimetype." + exit 1 + fi +else + echo "your system does not appear to have xdg-mime to register an x-scheme-handler for the AssaultCube connect protocol." + # you are welcome to provide a patch via PR on our github https://github.com/assaultcube/AC/ +fi + +if [ -f "${LAUNCHERPATH}"${LAUNCHERFILE} ]; then + echo "The AssaultCube connect protocol desktop entry has been successfully created at" + echo "${LAUNCHERPATH}"${LAUNCHERFILE} + exit 0 +else + echo "For some reason, we're unable to install the AssaultCube connect protocol desktop entry." + exit 1 +fi + diff --git a/source/dev_tools/packaging_guide.txt b/source/dev_tools/packaging_guide.txt index 4548540b..3b257df8 100644 --- a/source/dev_tools/packaging_guide.txt +++ b/source/dev_tools/packaging_guide.txt @@ -47,6 +47,8 @@ II. fill packaging area 4. Copy the whole content from htdocs/docs/ folder in the latest release tag in assaultcube.github.io repository to docs/ folder. If the Path-B:build has newer content update both website and Path-C:pack. 5. Archive config/autoexec.cfg, config/favourites.cfg, config/pcksources.cfg into config/configtemplates.zip (see commit 41fd31d). [[ https://github.com/assaultcube/AC/commit/41fd31d ]] Example: user@machine:/usr/local/src/AC/PACKAGE/pack/config$ zip configtemplates.zip autoexec.cfg favourites.cfg pcksources.cfg; for stale in autoexec favourites pcksources; do rm ${stale}.cfg; done + 6. fix the install_or_remove_menuitem.sh + The values for LAUNCHERFILE and LAUNCHERTITLE should have the "(_)dev" parts removed (at least). III. clean out packaging area 1. If you used 'git clone' in I.1: Delete .git folder, .gitignore, .travis.yml, if existent. diff --git a/source/src/main.cpp b/source/src/main.cpp index 8a853b97..bc60c251 100644 --- a/source/src/main.cpp +++ b/source/src/main.cpp @@ -1127,6 +1127,26 @@ void connectprotocol(char *protocolstring) // assaultcube://example.org[:28763][ DELSTRING(passwd); } +int bakshowmenuonstartup = -1; +static char *aaconnect = NULL; +void afterauth() +{ + // currently only for delayed connectprotocol + if(aaconnect) + { + conoutf("\fUAfter Auth"); + if(bakshowmenuonstartup > -1) + { + alias("showmenuonstartup",bakshowmenuonstartup==1?"1":"0",false,false); + } + } + if(aaconnect) + { + connectprotocol(aaconnect); + DELSTRING(aaconnect); + } +} + #ifdef THISISNOTDEFINED //WIN32 static char *parsecommandline(const char *src, vector &args) { @@ -1226,6 +1246,7 @@ int main(int argc, char **argv) if(*stream_capabilities()) clientlogf("info: %s", stream_capabilities()); + bool waitforauth = false; initing = INIT_RESET; for(int i = 1; ilastflush+60000) { fflush(stdout); lastflush = millis; } #endif pollautodownloadresponse(); + if(onceauthed && sk) + { + onceauthed = false; + afterauth(); + } } quit();