From 9e9b005b3be7fb9f0d9b4e739282f32d6ece53ac Mon Sep 17 00:00:00 2001 From: kervala Date: Sat, 2 Dec 2017 16:44:38 +0100 Subject: [PATCH 1/5] Changed: Centralize hexadecimal conversions --HG-- branch : develop --- code/nel/include/nel/misc/common.h | 20 ++++ code/nel/src/misc/common.cpp | 103 ++++++++++++++++++ code/nel/src/misc/md5.cpp | 41 +------ .../common/src/game_share/entity_types.h | 11 -- 4 files changed, 125 insertions(+), 50 deletions(-) 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/src/misc/common.cpp b/code/nel/src/misc/common.cpp index 23b02e668..bb6badd18 100644 --- a/code/nel/src/misc/common.cpp +++ b/code/nel/src/misc/common.cpp @@ -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; 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/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 */ From d799dde5add26a6e4f0d94e55bc03eb2a1333d4d Mon Sep 17 00:00:00 2001 From: kervala Date: Sat, 2 Dec 2017 16:45:12 +0100 Subject: [PATCH 2/5] Added: Steam client support --HG-- branch : develop --- code/ryzom/client/src/steam_client.cpp | 434 +++++++++++++++++++++++++ code/ryzom/client/src/steam_client.h | 65 ++++ 2 files changed, 499 insertions(+) create mode 100644 code/ryzom/client/src/steam_client.cpp create mode 100644 code/ryzom/client/src/steam_client.h diff --git a/code/ryzom/client/src/steam_client.cpp b/code/ryzom/client/src/steam_client.cpp new file mode 100644 index 000000000..ac12324bc --- /dev/null +++ b/code/ryzom/client/src/steam_client.cpp @@ -0,0 +1,434 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + + +#include "stdpch.h" + +#ifdef RZ_USE_STEAM + +#include "steam_client.h" + +#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)(); +typedef void (__cdecl *SteamAPI_ShutdownFuncPtr)(); +typedef HSteamUser (__cdecl *SteamAPI_GetHSteamUserFuncPtr)(); +typedef HSteamPipe (__cdecl *SteamAPI_GetHSteamPipeFuncPtr)(); +typedef void* (__cdecl *SteamInternal_CreateInterfaceFuncPtr)(const char *ver); +typedef void (__cdecl *SteamAPI_RegisterCallbackFuncPtr)(class CCallbackBase *pCallback, int iCallback); +typedef void (__cdecl *SteamAPI_UnregisterCallbackFuncPtr)(class CCallbackBase *pCallback); +typedef void (__cdecl *SteamAPI_RunCallbacksFuncPtr)(); + +// macros to simplify dynamic functions loading +#define NL_DECLARE_SYMBOL(symbol) symbol##FuncPtr nl##symbol = NULL +#define NL_LOAD_SYMBOL(symbol) \ +nl##symbol = (symbol##FuncPtr)NLMISC::nlGetSymbolAddress(_Handle, #symbol); \ +if (nl##symbol == NULL) return false + +NL_DECLARE_SYMBOL(SteamAPI_Init); +NL_DECLARE_SYMBOL(SteamAPI_Shutdown); + +NL_DECLARE_SYMBOL(SteamAPI_GetHSteamUser); +NL_DECLARE_SYMBOL(SteamAPI_GetHSteamPipe); +NL_DECLARE_SYMBOL(SteamInternal_CreateInterface); + +NL_DECLARE_SYMBOL(SteamAPI_RegisterCallback); +NL_DECLARE_SYMBOL(SteamAPI_UnregisterCallback); +NL_DECLARE_SYMBOL(SteamAPI_RunCallbacks); + +// instances of classes +static ISteamClient *s_SteamClient = NULL; +static ISteamUser *s_SteamUser = NULL; +static ISteamApps *s_SteamApps = NULL; +static ISteamFriends *s_SteamFriends = NULL; +static ISteamUtils *s_SteamUtils = NULL; + +// taken from steam_api.h, we needed to change it to use our dynamically loaded functions + +// Declares a callback member function plus a helper member variable which +// registers the callback on object creation and unregisters on destruction. +// The optional fourth 'var' param exists only for backwards-compatibility +// and can be ignored. +#define NL_STEAM_CALLBACK( thisclass, func, .../*callback_type, [deprecated] var*/ ) \ + _NL_STEAM_CALLBACK_SELECT( ( __VA_ARGS__, 4, 3 ), ( /**/, thisclass, func, __VA_ARGS__ ) ) + +//----------------------------------------------------------------------------- +// The following macros are implementation details, not intended for public use +//----------------------------------------------------------------------------- +#define _NL_STEAM_CALLBACK_AUTO_HOOK( thisclass, func, param ) +#define _NL_STEAM_CALLBACK_HELPER( _1, _2, SELECTED, ... ) _NL_STEAM_CALLBACK_##SELECTED +#define _NL_STEAM_CALLBACK_SELECT( X, Y ) _NL_STEAM_CALLBACK_HELPER X Y +#define _NL_STEAM_CALLBACK_3( extra_code, thisclass, func, param ) \ + struct CCallbackInternal_ ## func : private CSteamCallbackImpl< sizeof( param ) > { \ + CCallbackInternal_ ## func () { extra_code nlSteamAPI_RegisterCallback( this, param::k_iCallback ); } \ + CCallbackInternal_ ## func ( const CCallbackInternal_ ## func & ) { extra_code nlSteamAPI_RegisterCallback( this, param::k_iCallback ); } \ + CCallbackInternal_ ## func & operator=( const CCallbackInternal_ ## func & ) { return *this; } \ + private: virtual void Run( void *pvParam ) { _NL_STEAM_CALLBACK_AUTO_HOOK( thisclass, func, param ) \ + thisclass *pOuter = reinterpret_cast( reinterpret_cast(this) - offsetof( thisclass, m_steamcallback_ ## func ) ); \ + pOuter->func( reinterpret_cast( pvParam ) ); \ + } \ + } m_steamcallback_ ## func ; void func( param *pParam ) +#define _NL_STEAM_CALLBACK_4( _, thisclass, func, param, var ) \ + CSteamCallback< thisclass, param > var; void func( param *pParam ) + +//----------------------------------------------------------------------------- +// Purpose: templated base for callbacks - internal implementation detail +//----------------------------------------------------------------------------- +template< int sizeof_P > +class CSteamCallbackImpl : protected CCallbackBase +{ +public: + ~CSteamCallbackImpl() { if ( m_nCallbackFlags & k_ECallbackFlagsRegistered ) nlSteamAPI_UnregisterCallback( this ); } + void SetGameserverFlag() { m_nCallbackFlags |= k_ECallbackFlagsGameServer; } + +protected: + virtual void Run( void *pvParam ) = 0; + virtual void Run( void *pvParam, bool /*bIOFailure*/, SteamAPICall_t /*hSteamAPICall*/ ) { Run( pvParam ); } + virtual int GetCallbackSizeBytes() { return sizeof_P; } +}; + +//----------------------------------------------------------------------------- +// Purpose: maps a steam callback to a class member function +// template params: T = local class, P = parameter struct, +// bGameserver = listen for gameserver callbacks instead of client callbacks +//----------------------------------------------------------------------------- +template< class T, class P, bool bGameserver = false > +class CSteamCallback : public CSteamCallbackImpl< sizeof( P ) > +{ +public: + typedef void (T::*func_t)(P*); + + // NOTE: If you can't provide the correct parameters at construction time, you should + // use the CCallbackManual callback object (STEAM_CALLBACK_MANUAL macro) instead. + CSteamCallback( T *pObj, func_t func ) : m_pObj( NULL ), m_Func( NULL ) + { + if ( bGameserver ) + { + this->SetGameserverFlag(); + } + Register( pObj, func ); + } + + // manual registration of the callback + void Register( T *pObj, func_t func ) + { + if ( !pObj || !func ) + return; + + if ( this->m_nCallbackFlags & CCallbackBase::k_ECallbackFlagsRegistered ) + Unregister(); + + m_pObj = pObj; + m_Func = func; + // SteamAPI_RegisterCallback sets k_ECallbackFlagsRegistered + nlSteamAPI_RegisterCallback( this, P::k_iCallback ); + } + + void Unregister() + { + // SteamAPI_UnregisterCallback removes k_ECallbackFlagsRegistered + nlSteamAPI_UnregisterCallback( this ); + } + +protected: + virtual void Run( void *pvParam ) + { + (m_pObj->*m_Func)( (P *)pvParam ); + } + + T *m_pObj; + func_t m_Func; +}; + +extern NLMISC::CCmdArgs Args; + +// listener called by Steam when AuthSessionTicket is available +class CAuthSessionTicketListener +{ +public: + CAuthSessionTicketListener():_AuthSessionTicketResponse(this, &CAuthSessionTicketListener::OnAuthSessionTicketResponse) + { + _AuthSessionTicketHandle = 0; + _AuthSessionTicketSize = 0; + + _AuthSessionTicketCallbackCalled = false; + _AuthSessionTicketCallbackError = false;; + _AuthSessionTicketCallbackTimeout = false; + } + + // wait until a ticket is available or return if no ticket received after specified ms + bool waitTicket(uint32 ms) + { + // call Steam method + _AuthSessionTicketHandle = s_SteamUser->GetAuthSessionTicket(_AuthSessionTicketData, sizeof(_AuthSessionTicketData), &_AuthSessionTicketSize); + + nldebug("GetAuthSessionTicket returned %u bytes, handle %u", _AuthSessionTicketSize, _AuthSessionTicketHandle); + + nlinfo("Waiting for Steam GetAuthSessionTicket callback..."); + + // define expiration time + NLMISC::TTime expirationTime = NLMISC::CTime::getLocalTime() + ms; + + // wait until callback method is called or expiration + while(!_AuthSessionTicketCallbackCalled && !_AuthSessionTicketCallbackTimeout) + { + // call registered callbacks + nlSteamAPI_RunCallbacks(); + + // check if expired + if (NLMISC::CTime::getLocalTime() > expirationTime) + _AuthSessionTicketCallbackTimeout = true; + } + + // expired + if (_AuthSessionTicketCallbackTimeout) + { + nlwarning("GetAuthSessionTicket callback never called"); + return false; + } + + nlinfo("GetAuthSessionTicket called"); + + // got an error + if (_AuthSessionTicketCallbackError) + { + nlwarning("GetAuthSessionTicket callback returned error"); + return false; + } + + return true; + } + + // return ticket if available in hexadecimal + std::string getTicket() const + { + // if expired or error, ticket is not available + if (!_AuthSessionTicketCallbackCalled || _AuthSessionTicketCallbackError || _AuthSessionTicketCallbackTimeout) return ""; + + // convert buffer to hexadecimal string + return NLMISC::toHexa(_AuthSessionTicketData, _AuthSessionTicketSize); + } + +private: + // ticket handle + HAuthTicket _AuthSessionTicketHandle; + + // buffer of ticket data + uint8 _AuthSessionTicketData[1024]; + + // size of buffer + uint32 _AuthSessionTicketSize; + + // different states of callback + bool _AuthSessionTicketCallbackCalled; + bool _AuthSessionTicketCallbackError; + bool _AuthSessionTicketCallbackTimeout; + + // callback declaration + NL_STEAM_CALLBACK(CAuthSessionTicketListener, OnAuthSessionTicketResponse, GetAuthSessionTicketResponse_t, _AuthSessionTicketResponse); +}; + +// method called by Steam +void CAuthSessionTicketListener::OnAuthSessionTicketResponse(GetAuthSessionTicketResponse_t *inCallback) +{ + _AuthSessionTicketCallbackCalled = true; + + if (inCallback->m_eResult != k_EResultOK) + { + _AuthSessionTicketCallbackError = true; + } +} + +CSteamClient::CSteamClient():_Handle(NULL), _Initialized(false) +{ +} + +CSteamClient::~CSteamClient() +{ + release(); +} + +static void SteamWarningMessageHook(int severity, const char *message) +{ + switch(severity) + { + case 1: // warning + nlwarning("%s", message); + break; + + case 0: // message + nlinfo("%s", message); + break; + + default: // unknown + nlwarning("Unknown severity %d: %s", severity, message); + break; + } +} + +bool CSteamClient::init() +{ + std::string filename; + +#if defined(NL_OS_WIN64) + filename = "steam_api64.dll"; +#elif defined(NL_OS_WINDOWS) + filename = "steam_api.dll"; +#elif defined(NL_OS_MAC) + filename = "libsteam_api.dylib"; +#else + filename = "libsteam_api.so"; +#endif + + // try to load library with absolute path + _Handle = NLMISC::nlLoadLibrary(Args.getProgramPath() + filename); + + if (!_Handle) + { + // try to load library with relative path (will search in system paths) + _Handle = NLMISC::nlLoadLibrary(filename); + + if (!_Handle) + { + nlwarning("Unable to load Steam client"); + return false; + } + } + + // load Steam functions + NL_LOAD_SYMBOL(SteamAPI_Init); + NL_LOAD_SYMBOL(SteamAPI_Shutdown); + + // check if function was found + if (!nlSteamAPI_Init) + { + nlwarning("Unable to get a pointer on SteamAPI_Init"); + return false; + } + + // initialize Steam API + if (!nlSteamAPI_Init()) + { + nlwarning("Unable to initialize Steam client"); + return false; + } + + _Initialized = true; + + // load more Steam functions + NL_LOAD_SYMBOL(SteamAPI_GetHSteamUser); + NL_LOAD_SYMBOL(SteamAPI_GetHSteamPipe); + NL_LOAD_SYMBOL(SteamInternal_CreateInterface); + + HSteamUser hSteamUser = nlSteamAPI_GetHSteamUser(); + HSteamPipe hSteamPipe = nlSteamAPI_GetHSteamPipe(); + + if (!hSteamPipe) + { + nlwarning("Unable to get Steam pipe"); + return false; + } + + // instanciate all used Steam classes + s_SteamClient = (ISteamClient*)nlSteamInternal_CreateInterface(STEAMCLIENT_INTERFACE_VERSION); + if (!s_SteamClient) + return false; + + s_SteamUser = s_SteamClient->GetISteamUser(hSteamUser, hSteamPipe, STEAMUSER_INTERFACE_VERSION); + if (!s_SteamUser) + return false; + + s_SteamApps = s_SteamClient->GetISteamApps(hSteamUser, hSteamPipe, STEAMAPPS_INTERFACE_VERSION); + if (!s_SteamApps) + return false; + + s_SteamFriends = s_SteamClient->GetISteamFriends(hSteamUser, hSteamPipe, STEAMFRIENDS_INTERFACE_VERSION); + if (!s_SteamFriends) + return false; + + s_SteamUtils = s_SteamClient->GetISteamUtils(hSteamPipe, STEAMUTILS_INTERFACE_VERSION); + if (!s_SteamUtils) + return false; + + // set warning messages hook + s_SteamClient->SetWarningMessageHook(SteamWarningMessageHook); + + bool loggedOn = s_SteamUser->BLoggedOn(); + + nlinfo("Steam AppID: %u", s_SteamUtils->GetAppID()); + nlinfo("Steam login: %s", s_SteamFriends->GetPersonaName()); + nlinfo("Steam user logged: %s", loggedOn ? "yes":"no"); + + const char *lang = s_SteamApps->GetCurrentGameLanguage(); + + if (lang && strlen(lang) > 0) + { + nlinfo("Steam language: %s", lang); + NLMISC::CI18N::setSystemLanguageCode(lang); + } + + // don't need to continue, if not connected + if (!loggedOn) return false; + + // load symbols used by AuthSessionTicket + NL_LOAD_SYMBOL(SteamAPI_RegisterCallback); + NL_LOAD_SYMBOL(SteamAPI_UnregisterCallback); + NL_LOAD_SYMBOL(SteamAPI_RunCallbacks); + + CAuthSessionTicketListener listener; + + // wait 5 seconds to get ticket + if (!listener.waitTicket(5000)) return false; + + // save ticket + _AuthSessionTicket = listener.getTicket(); + + nldebug("Auth ticket: %s", _AuthSessionTicket.c_str()); + + return true; +} + +bool CSteamClient::release() +{ + if (!_Handle) return false; + + if (_Initialized) + { + // only shutdown Steam if initialized + nlSteamAPI_Shutdown(); + + _Initialized = false; + } + + // free Steam library from memory + bool res = NLMISC::nlFreeLibrary(_Handle); + + _Handle = NULL; + + return res; +} + + +#endif diff --git a/code/ryzom/client/src/steam_client.h b/code/ryzom/client/src/steam_client.h new file mode 100644 index 000000000..b11f3c6d1 --- /dev/null +++ b/code/ryzom/client/src/steam_client.h @@ -0,0 +1,65 @@ +// Ryzom - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + + +#ifndef CL_STEAM_CLIENT_H +#define CL_STEAM_CLIENT_H + +#include "nel/misc/types_nl.h" +#include "nel/misc/dynloadlib.h" + +/** + * Steam API helper to be able to call Steam functions/methods without linking to any library. + * The library is dynamically loaded and is optional. + * + * \author Cedric 'Kervala' OCHS + * \date 2016 + */ +class CSteamClient +{ +public: + CSteamClient(); + ~CSteamClient(); + + /** + * Dynamically load Steam client library and functions pointers. + * Also retrieve authentication session ticket if available. + * If no authentication session ticket retrieved, returns false. + */ + bool init(); + + /** + * Shutdown Steam client and unload library. + */ + bool release(); + + /** + * Return the authentication session ticket if available. + */ + std::string getAuthSessionTicket() const { return _AuthSessionTicket; } + +private: + // handle on Steam DLL + NLMISC::NL_LIB_HANDLE _Handle; + + // true if succeeded to initialize (must call shutdown) + bool _Initialized; + + // the retrieved authentication session ticket + std::string _AuthSessionTicket; +}; + +#endif From 7b2b0c93109a5b2d85c5c02407109efdbba6aafa Mon Sep 17 00:00:00 2001 From: kervala Date: Sat, 2 Dec 2017 16:46:17 +0100 Subject: [PATCH 3/5] Fixed: Encode password in hexadecimal on command-line when patching to avoid invalid characters --HG-- branch : develop --- code/ryzom/client/src/client.cpp | 13 +++++++++++++ code/ryzom/client/src/login_patch.cpp | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) 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/login_patch.cpp b/code/ryzom/client/src/login_patch.cpp index f13d1a782..27ade135e 100644 --- a/code/ryzom/client/src/login_patch.cpp +++ b/code/ryzom/client/src/login_patch.cpp @@ -1036,7 +1036,8 @@ void CPatchManager::executeBatchFile() 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) { From e2dda1585d3225cebb33ed06bb915d7d74f54cb1 Mon Sep 17 00:00:00 2001 From: kervala Date: Sat, 2 Dec 2017 16:46:44 +0100 Subject: [PATCH 4/5] Changed: Minor changes --HG-- branch : develop --- .../include/nel/misc/fixed_size_allocator.h | 2 +- code/nel/include/nel/misc/mouse_smoother.h | 2 +- code/nel/src/gui/group_menu.cpp | 2 +- code/nel/src/misc/common.cpp | 6 +-- code/nel/src/net/unified_network.cpp | 1 - code/ryzom/client/src/entities.cpp | 41 +++++++++++++------ code/ryzom/client/src/login_patch.cpp | 2 +- 7 files changed, 36 insertions(+), 20 deletions(-) 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 bb6badd18..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; @@ -1356,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/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/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 27ade135e..5cf77aae7 100644 --- a/code/ryzom/client/src/login_patch.cpp +++ b/code/ryzom/client/src/login_patch.cpp @@ -1033,7 +1033,7 @@ void CPatchManager::executeBatchFile() if (!LoginLogin.empty()) { arguments.push_back(LoginLogin); - + if (!LoginPassword.empty()) { // encode password in hexadecimal to avoid invalid characters on command-line From 403f34215601fb8032c8bac1f652b89a88d2ab4e Mon Sep 17 00:00:00 2001 From: kervala Date: Sat, 2 Dec 2017 16:49:48 +0100 Subject: [PATCH 5/5] Changed: Disable NeL samples for Travis --HG-- branch : develop --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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"