diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index 21fad1106..87d73190d 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -44,18 +44,6 @@ using namespace std; using namespace mwmp; -void printWithWidth(ostringstream &sstr, string str, size_t width) -{ - sstr << left << setw(width) << setfill(' ') << str; -} - -string intToHexStr(unsigned val) -{ - ostringstream sstr; - sstr << "0x" << setfill('0') << setw(8) << uppercase << hex << val; - return sstr.str(); -} - string comparePlugins(PacketPreInit::PluginContainer checksums, PacketPreInit::PluginContainer checksumsResponse) { std::ostringstream sstr; @@ -78,7 +66,7 @@ string comparePlugins(PacketPreInit::PluginContainer checksums, PacketPreInit::P string plugin = checksums.at(i).first; - sstr << plugin << " (" << intToHexStr(checksums.at(i).second[0]) << ")"; + sstr << plugin << " (" << Utils::intToHexStr(checksums.at(i).second[0]) << ")"; lineLength = lineLength + plugin.size() + 13; } @@ -105,7 +93,7 @@ string comparePlugins(PacketPreInit::PluginContainer checksums, PacketPreInit::P if (responseHashSize > 0) { - sstr << intToHexStr(checksumsResponse.at(i).second[0]); + sstr << Utils::intToHexStr(checksumsResponse.at(i).second[0]); if (responseHashSize > 1) sstr << " & " << (responseHashSize - 1) << " more"; @@ -136,12 +124,12 @@ string comparePluginsMonospaced(PacketPreInit::PluginContainer checksums, Packet pluginNameLen2 = checksumsResponse[i].first.size(); sstr << "Your plugins or their load order don't match the server's.\n\n"; - printWithWidth(sstr, "Your current plugins are:", pluginNameLen1 + 16); + Utils::printWithWidth(sstr, "Your current plugins are:", pluginNameLen1 + 16); sstr << "To join this server, use:\n"; - printWithWidth(sstr, "name", pluginNameLen1 + 2); - printWithWidth(sstr, "hash", 14); - printWithWidth(sstr, "name", pluginNameLen2 + 2); + Utils::printWithWidth(sstr, "name", pluginNameLen1 + 2); + Utils::printWithWidth(sstr, "hash", 14); + Utils::printWithWidth(sstr, "name", pluginNameLen2 + 2); sstr << "hash\n"; for (size_t i = 0; i < checksums.size() || i < checksumsResponse.size(); i++) @@ -154,24 +142,22 @@ string comparePluginsMonospaced(PacketPreInit::PluginContainer checksums, Packet plugin = checksums.at(i).first; val = checksums.at(i).second[0]; - printWithWidth(sstr, plugin, pluginNameLen1 + 2); - printWithWidth(sstr, intToHexStr(val), 14); + Utils::printWithWidth(sstr, plugin, pluginNameLen1 + 2); + Utils::printWithWidth(sstr, Utils::intToHexStr(val), 14); } else - { - printWithWidth(sstr, "", pluginNameLen1 + 16); - } + Utils::printWithWidth(sstr, "", pluginNameLen1 + 16); if (i < checksumsResponse.size()) { - printWithWidth(sstr, checksumsResponse[i].first, pluginNameLen2 + 2); + Utils::printWithWidth(sstr, checksumsResponse[i].first, pluginNameLen2 + 2); if (checksumsResponse[i].second.size() > 0) { if (full) for (size_t j = 0; j < checksumsResponse[i].second.size(); j++) - printWithWidth(sstr, intToHexStr(checksumsResponse[i].second[j]), 14); + Utils::printWithWidth(sstr, Utils::intToHexStr(checksumsResponse[i].second[j]), 14); else - sstr << intToHexStr(checksumsResponse[i].second[0]); + sstr << Utils::intToHexStr(checksumsResponse[i].second[0]); } else sstr << "any"; diff --git a/components/openmw-mp/Utils.cpp b/components/openmw-mp/Utils.cpp index 60ea82931..6f1886d4e 100644 --- a/components/openmw-mp/Utils.cpp +++ b/components/openmw-mp/Utils.cpp @@ -12,6 +12,7 @@ #include #include #include +#include using namespace std; @@ -147,3 +148,15 @@ unsigned int ::Utils::crc32checksum(const std::string &file) } return crc32.checksum(); } + +void Utils::printWithWidth(ostringstream &sstr, string str, size_t width) +{ + sstr << left << setw(width) << setfill(' ') << str; +} + +string Utils::intToHexStr(unsigned val) +{ + ostringstream sstr; + sstr << "0x" << setfill('0') << setw(8) << uppercase << hex << val; + return sstr.str(); +} \ No newline at end of file diff --git a/components/openmw-mp/Utils.hpp b/components/openmw-mp/Utils.hpp index 88ad2b1b7..50bbb37ad 100644 --- a/components/openmw-mp/Utils.hpp +++ b/components/openmw-mp/Utils.hpp @@ -6,6 +6,7 @@ #define UTILS_HPP #include +#include #ifdef _WIN32 int setenv(const char *name, const char *value, int overwrite); @@ -30,5 +31,9 @@ namespace Utils long int FileLength(const char *file); unsigned int crc32checksum(const std::string &file); + + + void printWithWidth(std::ostringstream &sstr, std::string str, size_t width); + std::string intToHexStr(unsigned val); } #endif //UTILS_HPP