diff --git a/source/glest_game/network/network_message.cpp b/source/glest_game/network/network_message.cpp index 8015fad4e..d9a7117b2 100644 --- a/source/glest_game/network/network_message.cpp +++ b/source/glest_game/network/network_message.cpp @@ -109,10 +109,11 @@ NetworkMessageIntro::NetworkMessageIntro(int32 sessionId,const string &versionSt bool NetworkMessageIntro::receive(Socket* socket) { bool result = NetworkMessage::receive(socket, &data, sizeof(data), true); + fromEndian(); data.name.nullTerminate(); data.versionString.nullTerminate(); data.language.nullTerminate(); - fromEndian(); + if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] get nmtIntro, data.playerIndex = %d, data.sessionId = %d\n",__FILE__,__FUNCTION__,__LINE__,data.playerIndex,data.sessionId); return result; } diff --git a/source/shared_lib/include/platform/common/byte_order.h b/source/shared_lib/include/platform/common/byte_order.h index 781f5fa2f..eaa8b0855 100644 --- a/source/shared_lib/include/platform/common/byte_order.h +++ b/source/shared_lib/include/platform/common/byte_order.h @@ -17,14 +17,18 @@ namespace Shared{ namespace PlatformByteOrder { template T EndianReverse(T t) { - unsigned char uc[sizeof t]; - memcpy(uc, &t, sizeof t); +// unsigned char uc[sizeof t]; +// memcpy(uc, &t, sizeof t); +// +// for (unsigned char *b = uc, *e = uc + sizeof(T) - 1; b < e; ++b, --e) { +// std::swap(*b, *e); +// } +// memcpy(&t, uc, sizeof t); +// return t; - for (unsigned char *b = uc, *e = uc + sizeof(T) - 1; b < e; ++b, --e) { - std::swap(*b, *e); - } - memcpy(&t, uc, sizeof t); - return t; + char& raw = reinterpret_cast(t); + std::reverse(&raw, &raw + sizeof(T)); + return t; } static bool isBigEndian() {