delayed connectprotocol till AfterAuth

This commit is contained in:
flowtron
2022-02-05 13:25:46 +01:00
parent 76aaa12b73
commit fdeffeb65e
3 changed files with 107 additions and 2 deletions
+61
View File
@@ -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
+2
View File
@@ -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.
+44 -2
View File
@@ -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<char *> &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; i<argc; i++)
{
@@ -1294,7 +1315,9 @@ int main(int argc, char **argv)
}
else if(!strncmp(argv[i], "assaultcube://", 14)) // browser direct connection
{
connectprotocol(argv[i]);
waitforauth = true;
conoutf("\fUwill \f2connect\fU when authenticated."); // individual notification - usually first in console, so off screen when menu pops up
aaconnect = newstring(argv[i]);//triggers connectprotocol(argv[i]); during afterauth()
}
else conoutf("\f3unknown commandline argument: %c", argv[i][0]);
}
@@ -1303,6 +1326,10 @@ int main(int argc, char **argv)
entropy_init(time(NULL) + (uint)(size_t)&initscript + (uint)(size_t)entropy_init);
initclientlog();
if(quitdirectly) return EXIT_SUCCESS;
if(waitforauth)
{
hudoutf("\f5.. \f2waiting \f4for \fUauth\f5entication .."); // general notification - more prominent to show things are about to happen
}
createconfigtemplates("config" PATHDIVS "configtemplates.zip");
@@ -1437,9 +1464,18 @@ int main(int argc, char **argv)
}
autostartscripts("_aftersaved_");
exechook(HOOK_SP_MP, "afterinit", "");
if(waitforauth)
{
bakshowmenuonstartup = !strcmp(getalias("showmenuonstartup"),"1")?1:0;
alias("showmenuonstartup","0");
}
autostartscripts(""); // all remaining scripts
execfile("config/autoexec.cfg");
exechook(HOOK_SP_MP, "autoexec", "");
initing = NOT_INITING;
uniformtexres = !hirestextures;
@@ -1474,6 +1510,7 @@ int main(int argc, char **argv)
inputgrab(grabinput = true);
inmainloop = true;
static bool onceauthed = true;
#ifdef _DEBUG
int lastflush = 0;
#endif
@@ -1493,7 +1530,7 @@ int main(int argc, char **argv)
limitfps(millis, totalmillis);
int elapsed = millis-totalmillis;
entropy_add_byte(elapsed);
if(multiplayer(NULL))
if(multiplayer(NULL))
{
if(ispaused) curtime = 0;
else curtime = elapsed;
@@ -1552,6 +1589,11 @@ int main(int argc, char **argv)
if(millis>lastflush+60000) { fflush(stdout); lastflush = millis; }
#endif
pollautodownloadresponse();
if(onceauthed && sk)
{
onceauthed = false;
afterauth();
}
}
quit();