From 13961db6a8942e3641b6668025c2dc4f6a08eb2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 30 Aug 2022 21:44:08 +0200 Subject: [PATCH] Allow demo/map arguments to be relative paths, allow using `play` When passing .demo or .map paths as command line arguments, first check if the path can be found in the storage and then try resolving an absolute path. Also delay execution of the `play` command until the client is ready so the command can be used from the command line. Although it doesn't work if there is only one argument, as this interferes with the .demo file handling. --- src/engine/client/client.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index 247456c68..6fa34e564 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -3198,7 +3198,9 @@ void CClient::Run() // handle pending demo play if(m_aCmdPlayDemo[0]) { - const char *pError = DemoPlayer_Play(m_aCmdPlayDemo, IStorage::TYPE_ABSOLUTE); + const char *pError = DemoPlayer_Play(m_aCmdPlayDemo, IStorage::TYPE_ALL); + if(pError && !fs_is_relative_path(m_aCmdPlayDemo)) + pError = DemoPlayer_Play(m_aCmdPlayDemo, IStorage::TYPE_ABSOLUTE); if(pError) dbg_msg("demo_player", "playing passed demo file '%s' failed: %s", m_aCmdPlayDemo, pError); m_aCmdPlayDemo[0] = 0; @@ -3207,7 +3209,9 @@ void CClient::Run() // handle pending map edits if(m_aCmdEditMap[0]) { - int Result = m_pEditor->Load(m_aCmdEditMap, IStorage::TYPE_ABSOLUTE); + int Result = m_pEditor->Load(m_aCmdEditMap, IStorage::TYPE_ALL); + if(!Result && !fs_is_relative_path(m_aCmdEditMap)) + m_pEditor->Load(m_aCmdEditMap, IStorage::TYPE_ABSOLUTE); if(Result) g_Config.m_ClEditor = true; else @@ -3502,7 +3506,7 @@ bool CClient::CtrlShiftKey(int Key, bool &Last) void CClient::Con_Connect(IConsole::IResult *pResult, void *pUserData) { CClient *pSelf = (CClient *)pUserData; - str_copy(pSelf->m_aCmdConnect, pResult->GetString(0)); + pSelf->HandleConnectLink(pResult->GetString(0)); } void CClient::Con_Disconnect(IConsole::IResult *pResult, void *pUserData) @@ -3975,9 +3979,7 @@ const char *CClient::DemoPlayer_Render(const char *pFilename, int StorageType, c void CClient::Con_Play(IConsole::IResult *pResult, void *pUserData) { CClient *pSelf = (CClient *)pUserData; - const char *pError = pSelf->DemoPlayer_Play(pResult->GetString(0), IStorage::TYPE_ALL); - if(pError) - pSelf->m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "demo_player", pError); + pSelf->HandleDemoPath(pResult->GetString(0)); } void CClient::Con_DemoPlay(IConsole::IResult *pResult, void *pUserData) @@ -4531,7 +4533,10 @@ void CClient::HandleConnectAddress(const NETADDR *pAddr) void CClient::HandleConnectLink(const char *pLink) { - str_copy(m_aCmdConnect, pLink + sizeof(CONNECTLINK) - 1); + if(str_startswith(pLink, CONNECTLINK)) + str_copy(m_aCmdConnect, pLink + sizeof(CONNECTLINK) - 1); + else + str_copy(m_aCmdConnect, pLink); } void CClient::HandleDemoPath(const char *pPath)