Backwards compatibility: use kart name if username is not in replay

This commit is contained in:
Geoffrey Mon 2017-08-02 14:13:26 -04:00
parent ca5258a46c
commit 9ec2ff5c4a
3 changed files with 21 additions and 9 deletions

View File

@ -76,7 +76,10 @@ public:
unsigned int getCurrentReplayIndex() const
{ return m_current_index; }
// ------------------------------------------------------------------------
core::stringw getName() const OVERRIDE { return m_display_name; }
/** Return the display name; if not set, use default display name (kart name) */
core::stringw getName() const OVERRIDE { return m_display_name.empty() ?
Controller::getName() :
m_display_name; }
}; // GhostController
#endif

View File

@ -81,7 +81,7 @@ protected:
/** Returns the version number of the replay file. This is used to check
* that a loaded replay file can still be understood by this
* executable. */
unsigned int getReplayVersion() const { return 4; }
unsigned int getReplayVersion() const { return 3; }
public:
ReplayBase();

View File

@ -137,17 +137,26 @@ bool ReplayPlay::addReplayFile(const std::string& fn, bool custom_replay)
char s1[1024];
char display_name_encoded[1024];
if (sscanf(s,"kart: %s %[^\n]", s1, display_name_encoded) != 2)
int scanned = sscanf(s,"kart: %s %[^\n]", s1, display_name_encoded);
if (scanned < 1)
{
Log::warn("Replay", "Could not read ghost karts info!");
break;
}
rd.m_kart_list.push_back(std::string(s1));
rd.m_name_list.push_back(StringUtils::xmlDecode(std::string(display_name_encoded)));
} else {
rd.m_kart_list.push_back(std::string(s1));
if (rd.m_name_list.size() == 1) {
// First user is the game master and the "owner" of this replay file
rd.m_user_name = rd.m_name_list[0];
if (scanned == 2) {
// If username of kart is present, use it
rd.m_name_list.push_back(StringUtils::xmlDecode(std::string(display_name_encoded)));
if (rd.m_name_list.size() == 1) {
// First user is the game master and the "owner" of this replay file
rd.m_user_name = rd.m_name_list[0];
}
} else { // scanned == 1
// If username is not present, kart display name will default to kart name
// (see GhostController::getName)
rd.m_name_list.push_back("");
}
}
}