diff --git a/.travis.yml b/.travis.yml index 6bfad3c3b..ec12c9989 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ os: matrix: fast_finish: true env: - - CMAKE_CONFIGURE_OPTIONS="-DWITH_NEL_TESTS=OFF -DWITH_LUA51=ON -DWITH_RYZOM_SERVER=OFF -DWITH_RYZOM_TOOLS=OFF -DWITH_NEL_TOOLS=OFF" + - CMAKE_CONFIGURE_OPTIONS="-DWITH_NEL_TESTS=OFF -DWITH_NEL_SAMPLES=OFF -DWITH_LUA51=ON -DWITH_RYZOM_SERVER=OFF -DWITH_RYZOM_TOOLS=OFF -DWITH_NEL_TOOLS=OFF" - CMAKE_CONFIGURE_OPTIONS="-DCPPTEST_LIBRARY_DEBUG:STRING=/usr/lib/libcpptest.so" CMAKE_BUILD_OPTIONS="--target nel_unit_test -- -j 2" RUN="build/bin/nel_unit_test" diff --git a/code/nel/include/nel/misc/common.h b/code/nel/include/nel/misc/common.h index 180139ec0..eb70fce9e 100644 --- a/code/nel/include/nel/misc/common.h +++ b/code/nel/include/nel/misc/common.h @@ -233,6 +233,26 @@ char toLower ( const char ch ); // convert only one character std::string toUpper ( const std::string &str); void toUpper ( char *str); + +/** + * Convert to an hexadecimal std::string + */ +std::string toHexa(const uint8 &b); +std::string toHexa(const uint8 *data, uint size); +std::string toHexa(const std::string &str); +std::string toHexa(const char *str); + +/** +* Convert from an hexadecimal std::string +*/ +bool fromHexa(const std::string &hexa, uint8 &b); +bool fromHexa(const std::string &hexa, uint8 *data); +bool fromHexa(const std::string &hexa, std::string &str); +bool fromHexa(const char *hexa, uint8 &b); +bool fromHexa(const char *hexa, uint8 *data); +bool fromHexa(const char *hexa, std::string &str); +bool fromHexa(const char hexa, uint8 &b); + // Remove all the characters <= 32 (tab, space, new line, return, vertical tab etc..) at the beginning and at the end of a string template T trim (const T &str) { diff --git a/code/nel/include/nel/misc/fixed_size_allocator.h b/code/nel/include/nel/misc/fixed_size_allocator.h index ffc975250..643217f5d 100644 --- a/code/nel/include/nel/misc/fixed_size_allocator.h +++ b/code/nel/include/nel/misc/fixed_size_allocator.h @@ -53,7 +53,7 @@ public: uint getNumAllocatedBlocks() const { return _NumAlloc; } private: class CChunk; - + class NL_ALIGN(NL_DEFAULT_MEMORY_ALIGNMENT) CNode { public: diff --git a/code/nel/include/nel/misc/mouse_smoother.h b/code/nel/include/nel/misc/mouse_smoother.h index f909cde96..18d741996 100644 --- a/code/nel/include/nel/misc/mouse_smoother.h +++ b/code/nel/include/nel/misc/mouse_smoother.h @@ -46,7 +46,7 @@ public: double getSamplingPeriod() const { return _SamplingPeriod; } // Reset smoother. The next returned position will be the exact position of mouse (no smoothing with previous position is done) void reset(); - // \return trueif no sampling has occurred since last resetor construction + // \return true if no sampling has occurred since last resetor construction bool isReseted() const { return !_Init; } // Sample pos, and return smoothed position CVector2f samplePos(const CVector2f &wantedPos, double date); diff --git a/code/nel/src/gui/group_menu.cpp b/code/nel/src/gui/group_menu.cpp index d2e11a2c9..7d002cfd6 100644 --- a/code/nel/src/gui/group_menu.cpp +++ b/code/nel/src/gui/group_menu.cpp @@ -1802,7 +1802,7 @@ namespace NLGUI return 0; } - // ------------------------------------------------------------------------------------------------ + // ------------------------------------------------------------------------------------------------ int CGroupSubMenu::luaAddIconLine(CLuaState &ls) { const char *funcName = "addIconLine"; diff --git a/code/nel/src/misc/common.cpp b/code/nel/src/misc/common.cpp index 23b02e668..db605f4f1 100644 --- a/code/nel/src/misc/common.cpp +++ b/code/nel/src/misc/common.cpp @@ -633,7 +633,7 @@ void toLower(char *str) } } -std::string toUpper(const std::string &str) +std::string toUpper(const std::string &str) { string res; res.reserve(str.size()); @@ -647,7 +647,7 @@ std::string toUpper(const std::string &str) return res; } -void toUpper(char *str) +void toUpper(char *str) { if (str == 0) return; @@ -662,6 +662,109 @@ void toUpper(char *str) } } +std::string toHexa(const uint8 &b) +{ + return toString("%02hhx", b); +} + +std::string toHexa(const uint8 *data, uint size) +{ + std::string res; + + // hexadecimal string will be always twice the original size + res.reserve(size * 2); + + // process each byte + for (uint i = 0; i < size; ++i) + { + res += toHexa(data[i]); + } + + return res; +} + +std::string toHexa(const std::string &str) +{ + return toHexa((uint8*)str.c_str(), (uint)str.length()); +} + +std::string toHexa(const char *str) +{ + return toHexa((uint8*)str, (uint)strlen(str)); +} + +bool fromHexa(const std::string &hexa, uint8 &b) +{ + return fromHexa(hexa.c_str(), b); +} + +bool fromHexa(const std::string &hexa, uint8 *data) +{ + return fromHexa(hexa.c_str(), data); +} + +bool fromHexa(const std::string &hexa, std::string &str) +{ + return fromHexa(hexa.c_str(), str); +} + +bool fromHexa(const char *hexa, uint8 &b) +{ + char c1 = *hexa; + char c2 = *(hexa+1); + uint8 x1, x2; + if (!fromHexa(c1, x1)) return false; + if (!fromHexa(c2, x2)) return false; + + b = (x1 << 4) | x2; + + return true; +} + +bool fromHexa(const char *hexa, uint8 *data) +{ + // length of the string + uint len = strlen(hexa); + + // process each byte + for (uint i = 0; i < len; i += 2) + { + if (!fromHexa(hexa + i, *(data++))) return false; + } + + return true; +} + +bool fromHexa(const char *hexa, std::string &str) +{ + str.resize(strlen(hexa) * 2); + + return fromHexa(hexa, (uint8*)str.c_str()); +} + +bool fromHexa(const char hexa, uint8 &b) +{ + if (hexa >= '0' && hexa <= '9') + { + b = hexa - '0'; + return true; + } + + if (hexa >= 'A' && hexa <= 'F') + { + b = hexa - 'A' + 10; + return true; + } + + if (hexa >= 'a' && hexa <= 'f') + { + b = hexa - 'a' + 10; + return true; + } + + return false; +} + std::string formatThousands(const std::string& s) { sint i, k; @@ -1253,7 +1356,7 @@ std::string escapeArgument(const std::string &arg) // we can't escape %VARIABLE% on command-line under Windows return arg; #else - // characters to escapce, only " and $ (to prevent a $something replaced by an environment variable) + // characters to escape, only " and $ (to prevent a $something replaced by an environment variable) static const char s_charsToEscape[] = "\"$"; std::string res; diff --git a/code/nel/src/misc/md5.cpp b/code/nel/src/misc/md5.cpp index eaf9df6cc..052bfa0b2 100644 --- a/code/nel/src/misc/md5.cpp +++ b/code/nel/src/misc/md5.cpp @@ -118,31 +118,6 @@ CHashKeyMD5 getMD5(const uint8 *buffer, uint32 size) return Message_Digest; } -// **************************************************************************** -// Helper -// **************************************************************************** -static bool fromHex(char c, uint8 &x) -{ - if (c >= '0' && c <= '9') - { - x = c - '0'; - return true; - } - else if (c >= 'A' && c <= 'F') - { - x = c - 'A' + 10; - return true; - } - else if (c >= 'a' && c <= 'f') - { - x = c - 'a' + 10; - return true; - } - - nlwarning("cannot convert to hexa"); - return false; -} - // **************************************************************************** // **************************************************************************** // CHashKeyMD5 @@ -159,10 +134,7 @@ void CHashKeyMD5::clear() // **************************************************************************** string CHashKeyMD5::toString() const { - string sTmp; - for (uint32 i = 0; i < 16; ++i) - sTmp += NLMISC::toString("%02x", Data[i]); - return sTmp; + return toHexa(Data, 16); } // **************************************************************************** @@ -174,16 +146,7 @@ bool CHashKeyMD5::fromString(const std::string &in) return false; } - for (uint32 i = 0; i < 16; ++i) - { - char c1 = in[2*i]; - char c2 = in[2*i+1]; - uint8 x1, x2; - if (!fromHex(c1, x1)) return false; - if (!fromHex(c2, x2)) return false; - Data[i] = (x1 << 4) | x2; - } - return true; + return fromHexa(in, Data); } // **************************************************************************** diff --git a/code/nel/src/net/unified_network.cpp b/code/nel/src/net/unified_network.cpp index 3a57b4b0d..2589e1cbf 100644 --- a/code/nel/src/net/unified_network.cpp +++ b/code/nel/src/net/unified_network.cpp @@ -828,7 +828,6 @@ void CUnifiedNetwork::addService(const string &name, const vector for (uint i = 0; i < addr.size(); i++) { // first we have to look if we have a network that can established the connection - uint j = 0; // it's loopback ip address, it's ok diff --git a/code/ryzom/client/src/client.cpp b/code/ryzom/client/src/client.cpp index c92bb887b..4c0121d2e 100644 --- a/code/ryzom/client/src/client.cpp +++ b/code/ryzom/client/src/client.cpp @@ -205,6 +205,19 @@ int main(int argc, char **argv) { LoginPassword = Args.getAdditionalArg("password").front(); + // password in hexadecimal + if (LoginPassword.compare(0, 2, "0x") == 0) + { + std::string decodedPassword; + + // decode password + if (fromHexa(LoginPassword.substr(2), decodedPassword)) + { + // only use it if real hexadecimal + LoginPassword = decodedPassword; + } + } + if (Args.haveAdditionalArg("shard_id")) sLoginShardId = Args.getAdditionalArg("shard_id").front(); } diff --git a/code/ryzom/client/src/entities.cpp b/code/ryzom/client/src/entities.cpp index b46d7ce29..2e5555b79 100644 --- a/code/ryzom/client/src/entities.cpp +++ b/code/ryzom/client/src/entities.cpp @@ -800,7 +800,8 @@ bool CEntityManager::setupInstance(uint32 idx, const vector &keys, const if (param == "transparency") { uint t; - if( fromString( values[i], t ) ) { + if (fromString(values[i], t)) + { t = max(0, min((int)t, 255)); makeInstanceTransparent(instance, t, t == 255); } @@ -864,9 +865,12 @@ bool CEntityManager::setupInstance(uint32 idx, const vector &keys, const float v; CVector pos = getInstancePos(idx); - if( getRelativeFloatFromString( values[i], v ) ) { + if (getRelativeFloatFromString(values[i], v)) + { updateVector(param, pos, v, true); - } else { + } + else + { updateVector(param, pos, v, false); } setInstancePos(idx, pos); @@ -877,9 +881,12 @@ bool CEntityManager::setupInstance(uint32 idx, const vector &keys, const float v; CVector rot = getInstanceRot(idx); - if( getRelativeFloatFromString( values[i], v ) ) { + if (getRelativeFloatFromString(values[i], v)) + { updateVector(param, rot, v, true); - } else { + } + else + { updateVector(param, rot, v, false); } setInstanceRot(idx, rot); @@ -889,9 +896,12 @@ bool CEntityManager::setupInstance(uint32 idx, const vector &keys, const float v; CVector scale = instance.getScale(); - if( getRelativeFloatFromString( values[i], v ) ) { + if (getRelativeFloatFromString(values[i], v)) + { updateVector(param, scale, v, true); - } else { + } + else + { updateVector(param, scale, v, false); } instance.setScale(scale); @@ -909,9 +919,12 @@ bool CEntityManager::setupInstance(uint32 idx, const vector &keys, const CVector size = CVector(width, depth, height); float v; - if( getRelativeFloatFromString( values[i], v ) ) { + if (getRelativeFloatFromString(values[i], v)) + { updateVector(param, size, v, true); - } else { + } + else + { updateVector(param, size, v, false); } primitive->setSize(size.x, size.y); @@ -922,9 +935,12 @@ bool CEntityManager::setupInstance(uint32 idx, const vector &keys, const CVector pos = instance.getPos(); float v; - if( getRelativeFloatFromString( values[i], v ) ) { + if (getRelativeFloatFromString(values[i], v)) + { updateVector(param, _ShapeInstances[idx].PrimRelativePos, v, false); - } else { + } + else + { if (param == "col pos x") _ShapeInstances[idx].PrimRelativePos.x = v - pos.x; if (param == "col pos y") @@ -1023,7 +1039,8 @@ CShapeInstanceReference CEntityManager::getShapeInstanceUnderPos(float x, float // if intersect the bbox NLMISC::CAABBox bbox; //= _ShapeInstances[i].SelectionBox; - if(!_ShapeInstances[i].Instance.empty()) { + if(!_ShapeInstances[i].Instance.empty()) + { _ShapeInstances[i].Instance.getShapeAABBox(bbox); CVector bbox_min; CVector bbox_max; diff --git a/code/ryzom/client/src/login_patch.cpp b/code/ryzom/client/src/login_patch.cpp index f13d1a782..5cf77aae7 100644 --- a/code/ryzom/client/src/login_patch.cpp +++ b/code/ryzom/client/src/login_patch.cpp @@ -1033,10 +1033,11 @@ void CPatchManager::executeBatchFile() if (!LoginLogin.empty()) { arguments.push_back(LoginLogin); - + if (!LoginPassword.empty()) { - arguments.push_back(LoginPassword); + // encode password in hexadecimal to avoid invalid characters on command-line + arguments.push_back("0x" + toHexa(LoginPassword)); if (!r2Mode) { diff --git a/code/ryzom/client/src/steam_client.cpp b/code/ryzom/client/src/steam_client.cpp index db03f9496..ac12324bc 100644 --- a/code/ryzom/client/src/steam_client.cpp +++ b/code/ryzom/client/src/steam_client.cpp @@ -25,6 +25,11 @@ #include "nel/misc/cmd_args.h" #include +#include + +#ifdef DEBUG_NEW +#define new DEBUG_NEW +#endif // prototypes definitions for Steam API functions we'll call typedef bool (__cdecl *SteamAPI_InitFuncPtr)(); @@ -222,18 +227,8 @@ public: // if expired or error, ticket is not available if (!_AuthSessionTicketCallbackCalled || _AuthSessionTicketCallbackError || _AuthSessionTicketCallbackTimeout) return ""; - std::string authSessionTicket; - - // optimize string by allocating the final string size - authSessionTicket.reserve(_AuthSessionTicketSize*2); - // convert buffer to hexadecimal string - for (uint32 i = 0; i < _AuthSessionTicketSize; ++i) - { - authSessionTicket += NLMISC::toString("%02x", _AuthSessionTicketData[i]); - } - - return authSessionTicket; + return NLMISC::toHexa(_AuthSessionTicketData, _AuthSessionTicketSize); } private: diff --git a/code/ryzom/common/src/game_share/entity_types.h b/code/ryzom/common/src/game_share/entity_types.h index 189e7c803..23f4bd700 100644 --- a/code/ryzom/common/src/game_share/entity_types.h +++ b/code/ryzom/common/src/game_share/entity_types.h @@ -560,17 +560,6 @@ inline CLFECOMMON::TCoord getAbsoluteCoordinateFrom64( uint64 posvalue ) }*/ -inline std::string toHexaString(const std::vector &v) -{ - std::string res; - for (uint i = 0; i < v.size(); i++) - { - res += NLMISC::toString("%x",v[i]); - } - return res; -} - - #endif // NL_ENTITY_TYPES_H /* End of entity_types.h */