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 unsigned int getCurrentReplayIndex() const
{ return m_current_index; } { 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 }; // GhostController
#endif #endif

View File

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

View File

@ -137,17 +137,26 @@ bool ReplayPlay::addReplayFile(const std::string& fn, bool custom_replay)
char s1[1024]; char s1[1024];
char display_name_encoded[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!"); Log::warn("Replay", "Could not read ghost karts info!");
break; break;
} } else {
rd.m_kart_list.push_back(std::string(s1)); rd.m_kart_list.push_back(std::string(s1));
rd.m_name_list.push_back(StringUtils::xmlDecode(std::string(display_name_encoded)));
if (rd.m_name_list.size() == 1) { if (scanned == 2) {
// First user is the game master and the "owner" of this replay file // If username of kart is present, use it
rd.m_user_name = rd.m_name_list[0]; 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("");
}
} }
} }