From 0cc86c04d1b012e4b7da36ac97d87a090a846cd0 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sat, 6 Jan 2018 05:39:25 +0200 Subject: [PATCH] [Client] Print plugin discrepancies, not just plugin lists side by side --- apps/openmw/mwmp/Networking.cpp | 125 ++++++++++++++++++-------------- 1 file changed, 72 insertions(+), 53 deletions(-) diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index 38dd17245..ae0eb5eda 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -45,72 +45,99 @@ using namespace std; using namespace mwmp; -string comparePlugins(PacketPreInit::PluginContainer checksums, PacketPreInit::PluginContainer checksumsResponse) +string listDiscrepancies(PacketPreInit::PluginContainer checksums, PacketPreInit::PluginContainer checksumsResponse) { std::ostringstream sstr; - sstr << "Your plugins or their load order don't match the server's.\n\n"; - sstr << "Your current plugins are:\n"; - - const int maxLineLength = 100; - int lineLength = 0; + sstr << "Your plugins or their load order don't match the server's. A full comparison is included in your client console and latest log file. In short, the following discrepancies have been found:\n\n"; - for (size_t i = 0; i < checksums.size(); i++) + int discrepancyCount = 0; + + for (size_t fileIndex = 0; fileIndex < checksums.size() || fileIndex < checksumsResponse.size(); fileIndex++) { - if (i != 0) - sstr << ", "; + if (fileIndex >= checksumsResponse.size()) + { + discrepancyCount++; + + if (discrepancyCount > 1) + sstr << "\n"; + + string clientFilename = checksums.at(fileIndex).first; - if (lineLength > maxLineLength) + sstr << fileIndex << ": "; + sstr << clientFilename << " is past the number of plugins used by the server"; + } + else if (fileIndex >= checksums.size()) { - sstr << "\n"; - lineLength = 0; + discrepancyCount++; + + if (discrepancyCount > 1) + sstr << "\n"; + + string serverFilename = checksumsResponse.at(fileIndex).first; + + sstr << fileIndex << ": "; + sstr << serverFilename << " is completely missing from the client but required by the server"; } + else + { + string clientFilename = checksums.at(fileIndex).first; + string serverFilename = checksumsResponse.at(fileIndex).first; - string plugin = checksums.at(i).first; + string clientChecksum = Utils::intToHexStr(checksums.at(fileIndex).second.at(0)); - sstr << plugin << " (" << Utils::intToHexStr(checksums.at(i).second[0]) << ")"; + bool filenameMatches = false; + bool checksumMatches = false; + string eligibleChecksums = ""; - lineLength += + plugin.size() + 13; - } + if (Misc::StringUtils::ciEqual(clientFilename, serverFilename)) + filenameMatches = true; - sstr << "\n\nTo join this server, use:\n"; - lineLength = 0; + if (checksumsResponse.at(fileIndex).second.size() > 0) + { + for (size_t checksumIndex = 0; checksumIndex < checksumsResponse.at(fileIndex).second.size(); checksumIndex++) + { + string serverChecksum = Utils::intToHexStr(checksumsResponse.at(fileIndex).second.at(checksumIndex)); - for (size_t i = 0; i < checksumsResponse.size(); i++) - { - if (i != 0) - sstr << ", "; + if (checksumIndex != 0) + eligibleChecksums = eligibleChecksums + " or "; - if (lineLength > maxLineLength) - { - sstr << "\n"; - lineLength = 0; - } + eligibleChecksums = eligibleChecksums + serverChecksum; - string plugin = checksumsResponse.at(i).first; + if (Misc::StringUtils::ciEqual(clientChecksum, serverChecksum)) + { + checksumMatches = true; + break; + } + } + } + else + checksumMatches = true; - sstr << plugin << " ("; + if (!filenameMatches || !checksumMatches) + { + discrepancyCount++; - int responseHashSize = checksumsResponse[i].second.size(); - - if (responseHashSize > 0) - { - sstr << Utils::intToHexStr(checksumsResponse.at(i).second[0]); + if (discrepancyCount > 1) + sstr << "\n"; - if (responseHashSize > 1) - sstr << " & " << (responseHashSize - 1) << " more"; - } - else - sstr << "any"; + sstr << fileIndex << ": "; - sstr << ")"; + if (!filenameMatches) + sstr << clientFilename << " doesn't match " << serverFilename; - lineLength += + plugin.size() + 13; + if (!filenameMatches && !checksumMatches) + sstr << ", "; + + if (!checksumMatches) + sstr << "checksum " << clientChecksum << " doesn't match " << eligibleChecksums; + } + } } return sstr.str(); } -string comparePluginsMonospaced(PacketPreInit::PluginContainer checksums, PacketPreInit::PluginContainer checksumsResponse, +string listComparison(PacketPreInit::PluginContainer checksums, PacketPreInit::PluginContainer checksumsResponse, bool full = false) { std::ostringstream sstr; @@ -124,7 +151,6 @@ string comparePluginsMonospaced(PacketPreInit::PluginContainer checksums, Packet if (pluginNameLen2 < checksum.first.size()) pluginNameLen2 = checksum.first.size(); - sstr << "Your plugins or their load order don't match the server's.\n\n"; Utils::printWithWidth(sstr, "Your current plugins are:", pluginNameLen1 + 16); sstr << "To join this server, use:\n"; @@ -318,7 +344,6 @@ void Networking::connect(const std::string &ip, unsigned short port, std::vector void Networking::preInit(std::vector &content, Files::Collections &collections) { - std::string errmsg = ""; PacketPreInit::PluginContainer checksums; vector::const_iterator it(content.begin()); for (int idx = 0; it != content.end(); ++it, ++idx) @@ -379,16 +404,10 @@ void Networking::preInit(std::vector &content, Files::Collections & if (!checksumsResponse.empty()) // something wrong { -#if defined(__WINDOWS) - errmsg = comparePlugins(checksums, checksumsResponse); -#else - errmsg = comparePluginsMonospaced(checksums, checksumsResponse); -#endif - } + std::string errmsg = listDiscrepancies(checksums, checksumsResponse); - if (!errmsg.empty()) - { - LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, comparePluginsMonospaced(checksums, checksumsResponse, true).c_str()); + LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, listDiscrepancies(checksums, checksumsResponse).c_str()); + LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, listComparison(checksums, checksumsResponse, true).c_str()); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "tes3mp", errmsg.c_str(), 0); connected = false; }