mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Improve error message when map for demo cannot be found
Previously the playback did not start and no error messages was shown, when the map file cannot be found and no map data is embedded in the demo file. Minor refactoring: Replace instances of `return pError` with semantically identical `return nullptr` to improve readability.
This commit is contained in:
parent
3f1b702b90
commit
63d0c8e170
|
@ -1299,7 +1299,6 @@ static void FormatMapDownloadFilename(const char *pName, const SHA256_DIGEST *pS
|
|||
|
||||
const char *CClient::LoadMapSearch(const char *pMapName, SHA256_DIGEST *pWantedSha256, int WantedCrc)
|
||||
{
|
||||
const char *pError = 0;
|
||||
char aBuf[512];
|
||||
char aWanted[SHA256_MAXSTRSIZE + 16];
|
||||
aWanted[0] = 0;
|
||||
|
@ -1316,15 +1315,15 @@ const char *CClient::LoadMapSearch(const char *pMapName, SHA256_DIGEST *pWantedS
|
|||
|
||||
// try the normal maps folder
|
||||
str_format(aBuf, sizeof(aBuf), "maps/%s.map", pMapName);
|
||||
pError = LoadMap(pMapName, aBuf, pWantedSha256, WantedCrc);
|
||||
const char *pError = LoadMap(pMapName, aBuf, pWantedSha256, WantedCrc);
|
||||
if(!pError)
|
||||
return pError;
|
||||
return nullptr;
|
||||
|
||||
// try the downloaded maps
|
||||
FormatMapDownloadFilename(pMapName, pWantedSha256, WantedCrc, false, aBuf, sizeof(aBuf));
|
||||
pError = LoadMap(pMapName, aBuf, pWantedSha256, WantedCrc);
|
||||
if(!pError)
|
||||
return pError;
|
||||
return nullptr;
|
||||
|
||||
// backward compatibility with old names
|
||||
if(pWantedSha256)
|
||||
|
@ -1332,16 +1331,22 @@ const char *CClient::LoadMapSearch(const char *pMapName, SHA256_DIGEST *pWantedS
|
|||
FormatMapDownloadFilename(pMapName, 0, WantedCrc, false, aBuf, sizeof(aBuf));
|
||||
pError = LoadMap(pMapName, aBuf, pWantedSha256, WantedCrc);
|
||||
if(!pError)
|
||||
return pError;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// search for the map within subfolders
|
||||
char aFilename[IO_MAX_PATH_LENGTH];
|
||||
str_format(aFilename, sizeof(aFilename), "%s.map", pMapName);
|
||||
if(Storage()->FindFile(aFilename, "maps", IStorage::TYPE_ALL, aBuf, sizeof(aBuf)))
|
||||
{
|
||||
pError = LoadMap(pMapName, aBuf, pWantedSha256, WantedCrc);
|
||||
if(!pError)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return pError;
|
||||
static char s_aErrorMsg[256];
|
||||
str_format(s_aErrorMsg, sizeof(s_aErrorMsg), "Could not find map '%s'", pMapName);
|
||||
return s_aErrorMsg;
|
||||
}
|
||||
|
||||
void CClient::ProcessConnlessPacket(CNetChunk *pPacket)
|
||||
|
@ -3903,7 +3908,10 @@ const char *CClient::DemoPlayer_Play(const char *pFilename, int StorageType)
|
|||
if(pError)
|
||||
{
|
||||
if(!m_DemoPlayer.ExtractMap(Storage()))
|
||||
{
|
||||
DisconnectWithReason(pError);
|
||||
return pError;
|
||||
}
|
||||
|
||||
Sha = m_DemoPlayer.GetMapInfo()->m_Sha256;
|
||||
pError = LoadMapSearch(pMapInfo->m_aName, &Sha, Crc);
|
||||
|
|
Loading…
Reference in a new issue