@ -45,72 +45,99 @@
using namespace std ;
using namespace mwmp ;
string comparePlugin s( PacketPreInit : : PluginContainer checksums , PacketPreInit : : PluginContainer checksumsResponse )
string listDiscrepancie s( 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 " ;
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 " ;
const int maxLineLength = 100 ;
int lineLength = 0 ;
int discrepancyCount = 0 ;
for ( size_t i = 0 ; i < checksums . size ( ) ; i+ + )
for ( size_t f ileIndex = 0 ; f ileIndex < checksums . size ( ) | | fileIndex < checksumsResponse . size ( ) ; f ileIndex + + )
{
if ( i ! = 0 )
sstr < < " , " ;
if ( fileIndex > = checksumsResponse . size ( ) )
{
discrepancyCount + + ;
if ( discrepancyCount > 1 )
sstr < < " \n " ;
if ( lineLength > maxLineLength )
string clientFilename = checksums . at ( fileIndex ) . first ;
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 \n To 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 ( discrepancyCount > 1 )
sstr < < " \n " ;
if ( responseHashSize > 0 )
{
sstr < < Utils : : intToHexStr ( checksumsResponse . at ( i ) . second [ 0 ] ) ;
sstr < < fileIndex < < " : " ;
if ( responseHashSize > 1 )
sstr < < " & " < < ( responseHashSize - 1 ) < < " more " ;
}
else
sstr < < " any " ;
if ( ! filenameMatches )
sstr < < clientFilename < < " doesn't match " < < serverFilename ;
sstr < < " ) " ;
if ( ! filenameMatches & & ! checksumMatches )
sstr < < " , " ;
lineLength + = + plugin . size ( ) + 13 ;
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 < std : : string > & content , Files : : Collections & collections )
{
std : : string errmsg = " " ;
PacketPreInit : : PluginContainer checksums ;
vector < string > : : const_iterator it ( content . begin ( ) ) ;
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 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 ;
}