This commit is contained in:
Alayan 2023-11-29 22:29:34 +01:00
parent a57ac415bb
commit 5bb5f5e86e
No known key found for this signature in database

View File

@ -231,14 +231,37 @@ bool ReplayPlay::addReplayFile(const std::string& fn, bool custom_replay, int ca
else
rd.m_minor_mode = "time-trial";
// sscanf always stops at whitespaces, but a track name may contain a whitespace
// Official tracks should avoid whitespaces in their name, but it
// unavoidably occurs with some addons or WIP tracks.
fgets(s, 1023, fd);
if (sscanf(s, "track: %1023s", s1) != 1)
if (std::strncmp(s, "track: ", 7) == 0)
{
int i = 0;
for(i = 7; s[i] != '\0'; i++)
{
// Break when newline is reached
if (s[i] == '\n' || s[i] == '\r')
break;
s1[i-7] = s[i];
}
s1[i-7] = '\0';
if (i >= 8)
{
rd.m_track_name = std::string(s1);
}
else
{
Log::warn("Replay", "Track name is empty in replay file, '%s'.", fn.c_str());
return false;
}
}
else
{
Log::warn("Replay", "Track info not found in replay file, '%s'.", fn.c_str());
return false;
}
rd.m_track_name = std::string(s1);
// If former official tracks are present as addons, show the matching replays.
if (rd.m_track_name.compare("greenvalley") == 0)