[Client] Print plugin discrepancies, not just plugin lists side by side

0.6.2
David Cernat 7 years ago
parent a639d3494a
commit 0cc86c04d1

@ -45,72 +45,99 @@
using namespace std; using namespace std;
using namespace mwmp; using namespace mwmp;
string comparePlugins(PacketPreInit::PluginContainer checksums, PacketPreInit::PluginContainer checksumsResponse) string listDiscrepancies(PacketPreInit::PluginContainer checksums, PacketPreInit::PluginContainer checksumsResponse)
{ {
std::ostringstream sstr; std::ostringstream sstr;
sstr << "Your plugins or their load order don't match the server's.\n\n"; 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";
sstr << "Your current plugins are:\n";
const int maxLineLength = 100;
int lineLength = 0;
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) if (fileIndex >= checksumsResponse.size())
sstr << ", "; {
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"; discrepancyCount++;
lineLength = 0;
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"; if (checksumsResponse.at(fileIndex).second.size() > 0)
lineLength = 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 (checksumIndex != 0)
{ eligibleChecksums = eligibleChecksums + " or ";
if (i != 0)
sstr << ", ";
if (lineLength > maxLineLength) eligibleChecksums = eligibleChecksums + serverChecksum;
{
sstr << "\n";
lineLength = 0;
}
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 (discrepancyCount > 1)
sstr << "\n";
if (responseHashSize > 0)
{
sstr << Utils::intToHexStr(checksumsResponse.at(i).second[0]);
if (responseHashSize > 1) sstr << fileIndex << ": ";
sstr << " & " << (responseHashSize - 1) << " more";
}
else
sstr << "any";
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(); return sstr.str();
} }
string comparePluginsMonospaced(PacketPreInit::PluginContainer checksums, PacketPreInit::PluginContainer checksumsResponse, string listComparison(PacketPreInit::PluginContainer checksums, PacketPreInit::PluginContainer checksumsResponse,
bool full = false) bool full = false)
{ {
std::ostringstream sstr; std::ostringstream sstr;
@ -124,7 +151,6 @@ string comparePluginsMonospaced(PacketPreInit::PluginContainer checksums, Packet
if (pluginNameLen2 < checksum.first.size()) if (pluginNameLen2 < checksum.first.size())
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); Utils::printWithWidth(sstr, "Your current plugins are:", pluginNameLen1 + 16);
sstr << "To join this server, use:\n"; 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<std::string> &content, Files::Collections &collections) void Networking::preInit(std::vector<std::string> &content, Files::Collections &collections)
{ {
std::string errmsg = "";
PacketPreInit::PluginContainer checksums; PacketPreInit::PluginContainer checksums;
vector<string>::const_iterator it(content.begin()); vector<string>::const_iterator it(content.begin());
for (int idx = 0; it != content.end(); ++it, ++idx) for (int idx = 0; it != content.end(); ++it, ++idx)
@ -379,16 +404,10 @@ void Networking::preInit(std::vector<std::string> &content, Files::Collections &
if (!checksumsResponse.empty()) // something wrong if (!checksumsResponse.empty()) // something wrong
{ {
#if defined(__WINDOWS) std::string errmsg = listDiscrepancies(checksums, checksumsResponse);
errmsg = comparePlugins(checksums, checksumsResponse);
#else
errmsg = comparePluginsMonospaced(checksums, checksumsResponse);
#endif
}
if (!errmsg.empty()) LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, listDiscrepancies(checksums, checksumsResponse).c_str());
{ LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, listComparison(checksums, checksumsResponse, true).c_str());
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, comparePluginsMonospaced(checksums, checksumsResponse, true).c_str());
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "tes3mp", errmsg.c_str(), 0); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "tes3mp", errmsg.c_str(), 0);
connected = false; connected = false;
} }

Loading…
Cancel
Save