467 lines
13 KiB
C++
467 lines
13 KiB
C++
////////////////////////////////////////////////////////////////////////////////
|
|
// (c) Copyright, Ubisoft Entertainment Inc. || Created by Harbour //
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
#include "ubiservices/facade.h"
|
|
#include "ubiservices/facadeInternal.h"
|
|
#include "ubiservices/core/configs/configpriv.h"
|
|
#include "ubiservices/core/debug/assert.h"
|
|
#include "ubiservices/core/encoding/aesCryptographyHelper.h"
|
|
#include "ubiservices/core/encoding/obfuscationHelper.h"
|
|
#include "ubiservices/core/errors/errorCodes.h"
|
|
#include "ubiservices/core/helpers/helpers.h"
|
|
#include "ubiservices/core/helpers/facadesManager.h"
|
|
#include "ubiservices/core/helpers/instancesManager.h"
|
|
#include "ubiservices/services/parameters/parametersClient.h"
|
|
#include "ubiservices/sessionManager.h"
|
|
|
|
namespace US_NS {;
|
|
|
|
/// @note
|
|
/// The Facade has a SmartPtr of FacadeInternal so the SDK can control the life of the facade instance
|
|
/// There was a case where a game would delete the Facade just after a transition from background to foreground.
|
|
/// This transition launch the JobResumeFocusMaster, that requires Facade(s) to be valid during its execution.
|
|
/// The SmartPtr allow the SDK to keep the FacadeInternal alive while JobResumeFocusMaster runs.
|
|
/// The Facade(s) will be deleted once the JobResumeFocusMaster is done.
|
|
|
|
Facade::Facade()
|
|
{
|
|
US_LOG_WHERE(LogLevel::Debug, LogCategory::Core, "Creating");
|
|
|
|
// Decide if the facade is valid or invalid upon construction instead of at login since some
|
|
// clients do not need to be logged-in to work properly.
|
|
InstancesManager* mgr = InstancesManager::getInstance();
|
|
if(mgr == nullptr)
|
|
{
|
|
// It is not possible to output log since the EventLog is created by the InstanceManager.
|
|
return;
|
|
}
|
|
|
|
// Creating FacadeInternal
|
|
// We are assigning the FacadeInternal here because one of our test validate an assert occurs when
|
|
// the Facade is created before the SDK init. If the US_NEW is in the declaration above, there is
|
|
// an exception in EAL, because EAL is not initialized, so it make the test crash.
|
|
m_facadeInternal = US_NEW(FacadeInternal);
|
|
m_facadeInternal->init(this);
|
|
|
|
|
|
US_LOG_WHERE(LogLevel::Debug, LogCategory::Core, "m_facadeInternal Ptr: " << m_facadeInternal.getPtr() << " Count: " << m_facadeInternal->getRefCount());
|
|
|
|
if (!mgr->getFacadesManager().registerInstance(m_facadeInternal))
|
|
{
|
|
US_LOG(LogLevel::Error, LogCategory::Core, "Unable to register facade to the FacadesManager: " << this);
|
|
return;
|
|
}
|
|
|
|
US_LOG_WHERE(LogLevel::Debug, LogCategory::Core, "Leaving m_facadeInternal Ptr: " << m_facadeInternal.getPtr() << " Count: " << m_facadeInternal->getRefCount());
|
|
}
|
|
|
|
Facade::~Facade()
|
|
{
|
|
US_LOG_WHERE(LogLevel::Debug, LogCategory::Core, "Deleting m_facadeInternal Ptr: " << m_facadeInternal.getPtr() << " Count: " << m_facadeInternal->getRefCount());
|
|
|
|
InstancesManager* mgr = InstancesManager::getInstance();
|
|
if(mgr == nullptr)
|
|
{
|
|
US_ASSERT(false, "Facade deletion should happen before US_NS::uninitializeSdk is called");
|
|
return;
|
|
}
|
|
|
|
if (m_facadeInternal->m_valid)
|
|
{
|
|
m_facadeInternal->stopFacade();
|
|
}
|
|
|
|
// If not valid, it is not registered hence no need to unregister.
|
|
if (m_facadeInternal->m_valid && !mgr->getFacadesManager().unregisterInstance(m_facadeInternal))
|
|
{
|
|
US_LOG(LogLevel::Error, LogCategory::Core, "Failed to unregister this facade from the facadesManager: " << this);
|
|
}
|
|
|
|
US_LOG_WHERE(LogLevel::Debug, LogCategory::Core, "Leaving m_facadeInternal Ptr: " << m_facadeInternal.getPtr() << " Count: " << m_facadeInternal->getRefCount());
|
|
}
|
|
|
|
#if defined(US_SDK_SERVER)
|
|
AsyncResult<Empty> Facade::createSession(const String& secret,
|
|
const String& ubiCertificateKeyPublic,
|
|
const String& ubiCertificateKeyPrivate,
|
|
const Vector<String>& parametersGroupApplication,
|
|
const Vector<String>& parametersGroupSpace,
|
|
const SpaceId& spaceId)
|
|
{
|
|
// Obfuscation is done as soon as we receive the private key as a security measure.
|
|
// In order to prevent the visible key from being kept in memory for too long.
|
|
const Vector<uint8> ubiCertificateKeyPrivateObfuscated = ObfuscationHelper::obfuscate(ubiCertificateKeyPrivate);
|
|
m_facadeInternal->getManager().setUbiCertificateKeyPrivateObfuscated(ubiCertificateKeyPrivateObfuscated);
|
|
m_facadeInternal->getManager().setUbiCertificateKeyPublic(ubiCertificateKeyPublic);
|
|
|
|
if (spaceId.isSet())
|
|
{
|
|
m_facadeInternal->getManager().setServerCreateSessionOverrideSpaceId(spaceId);
|
|
}
|
|
|
|
return m_facadeInternal->createSession(secret, parametersGroupApplication, parametersGroupSpace);
|
|
}
|
|
|
|
AsyncResult<Empty> Facade::createSessionEx(const String& secret,
|
|
const Vector<String>& parametersGroupApplication,
|
|
const Vector<String>& parametersGroupSpace,
|
|
const String& ubiCertificateKeyPublic,
|
|
const String& ubiCertificateKeyPrivate,
|
|
const SpaceId& spaceId)
|
|
{
|
|
|
|
if (!ubiCertificateKeyPrivate.isEmpty())
|
|
{
|
|
const Vector<uint8> ubiCertificateKeyPrivateObfuscated = ObfuscationHelper::obfuscate(ubiCertificateKeyPrivate);
|
|
m_facadeInternal->getManager().setUbiCertificateKeyPrivateObfuscated(ubiCertificateKeyPrivateObfuscated);
|
|
}
|
|
|
|
if (!ubiCertificateKeyPublic.isEmpty())
|
|
{
|
|
m_facadeInternal->getManager().setUbiCertificateKeyPublic(ubiCertificateKeyPublic);
|
|
}
|
|
|
|
if (spaceId.isSet())
|
|
{
|
|
m_facadeInternal->getManager().setServerCreateSessionOverrideSpaceId(spaceId);
|
|
}
|
|
|
|
return m_facadeInternal->createSession(secret, parametersGroupApplication, parametersGroupSpace);
|
|
|
|
}
|
|
|
|
|
|
#else
|
|
AsyncResult<Empty> Facade::createSession(const PlayerCredentialsBase& credentials,
|
|
const Vector<String>& parametersGroupApplication,
|
|
const Vector<String>& parametersGroupSpace,
|
|
const EventsParams& eventsParams
|
|
, const String& connectionMetaData
|
|
, const DynamicPopulationCustomParams& populationParams
|
|
#if defined(US_PRIMARY_STORE_WITHOUT_API)
|
|
, const PrimaryStoreParams& primaryStoreParams
|
|
#endif
|
|
)
|
|
{
|
|
return m_facadeInternal->createSession(credentials, parametersGroupApplication, parametersGroupSpace,
|
|
eventsParams, connectionMetaData , populationParams
|
|
#if defined(US_PRIMARY_STORE_WITHOUT_API)
|
|
, primaryStoreParams
|
|
#endif
|
|
);
|
|
}
|
|
#endif
|
|
|
|
AsyncResult<Empty> Facade::deleteSession()
|
|
{
|
|
return m_facadeInternal->deleteSession();
|
|
}
|
|
|
|
SpaceId Facade::getWorkingSpaceId() const
|
|
{
|
|
return m_facadeInternal->getManager().getWorkingSpaceId();
|
|
}
|
|
|
|
|
|
/// Client accessors - All flavors (including modules)
|
|
#if defined(US_MODULE_APPLICATION)
|
|
const ApplicationClient& Facade::getApplicationClient() const
|
|
{
|
|
return m_facadeInternal->getApplicationClient();
|
|
}
|
|
|
|
ApplicationClient& Facade::getApplicationClient()
|
|
{
|
|
return m_facadeInternal->getApplicationClient();
|
|
}
|
|
#endif
|
|
|
|
const AuthenticationClient& Facade::getAuthenticationClient() const
|
|
{
|
|
return m_facadeInternal->getAuthenticationClient();
|
|
}
|
|
|
|
AuthenticationClient& Facade::getAuthenticationClient()
|
|
{
|
|
return m_facadeInternal->getAuthenticationClient();
|
|
}
|
|
|
|
#if defined(US_MODULE_BATTLEPASS)
|
|
const BattlepassClient& Facade::getBattlepassClient() const
|
|
{
|
|
return m_facadeInternal->getBattlepassClient();
|
|
}
|
|
|
|
BattlepassClient& Facade::getBattlepassClient()
|
|
{
|
|
return m_facadeInternal->getBattlepassClient();
|
|
}
|
|
#endif
|
|
|
|
#if defined(US_MODULE_BLOCKLIST)
|
|
const BlocklistClient& Facade::getBlocklistClient() const
|
|
{
|
|
return m_facadeInternal->getBlocklistClient();
|
|
}
|
|
|
|
BlocklistClient& Facade::getBlocklistClient()
|
|
{
|
|
return m_facadeInternal->getBlocklistClient();
|
|
}
|
|
#endif
|
|
|
|
#if defined(US_MODULE_CHALLENGE)
|
|
const ChallengeClient& Facade::getChallengeClient() const
|
|
{
|
|
return m_facadeInternal->getChallengeClient();
|
|
}
|
|
|
|
ChallengeClient& Facade::getChallengeClient()
|
|
{
|
|
return m_facadeInternal->getChallengeClient();
|
|
}
|
|
#endif
|
|
|
|
#if defined(US_MODULE_CLUB)
|
|
ClubClient& Facade::getClubClient()
|
|
{
|
|
return m_facadeInternal->getClubClient();
|
|
}
|
|
#endif
|
|
|
|
#if defined(US_MODULE_ENTITY)
|
|
EntityClient& Facade::getEntityClient()
|
|
{
|
|
return m_facadeInternal->getEntityClient();
|
|
}
|
|
#endif
|
|
|
|
#if defined(US_MODULE_FRIEND)
|
|
FriendClient& Facade::getFriendClient()
|
|
{
|
|
return m_facadeInternal->getFriendClient();
|
|
}
|
|
#endif
|
|
|
|
#if defined(US_MODULE_GAMESPLAYED)
|
|
GamesPlayedClient& Facade::getGamesPlayedClient()
|
|
{
|
|
return m_facadeInternal->getGamesPlayedClient();
|
|
}
|
|
#endif
|
|
|
|
const EventClient& Facade::getEventClient() const
|
|
{
|
|
return m_facadeInternal->getEventClient();
|
|
}
|
|
|
|
EventClient& Facade::getEventClient()
|
|
{
|
|
return m_facadeInternal->getEventClient();
|
|
}
|
|
HttpClient& Facade::getHttpClient()
|
|
{
|
|
return m_facadeInternal->getHttpClient();
|
|
}
|
|
|
|
#if defined(US_MODULE_LEADERBOARD)
|
|
LeaderboardClient& Facade::getLeaderboardClient()
|
|
{
|
|
return m_facadeInternal->getLeaderboardClient();
|
|
}
|
|
#endif
|
|
|
|
#if defined(US_MODULE_LOCALIZATION)
|
|
LocalizationClient& Facade::getLocalizationClient()
|
|
{
|
|
return m_facadeInternal->getLocalizationClient();
|
|
}
|
|
#endif
|
|
|
|
#if defined(US_MODULE_MATCHMAKING)
|
|
const MatchmakingClient& Facade::getMatchmakingClient() const
|
|
{
|
|
return m_facadeInternal->getMatchmakingClient();
|
|
}
|
|
|
|
MatchmakingClient& Facade::getMatchmakingClient()
|
|
{
|
|
return m_facadeInternal->getMatchmakingClient();
|
|
}
|
|
#endif
|
|
|
|
#if defined(US_MODULE_MODERATION)
|
|
const ModerationClient& Facade::getModerationClient() const
|
|
{
|
|
return m_facadeInternal->getModerationClient();
|
|
}
|
|
|
|
ModerationClient& Facade::getModerationClient()
|
|
{
|
|
return m_facadeInternal->getModerationClient();
|
|
}
|
|
#endif
|
|
|
|
const ParametersClient& Facade::getParametersClient() const
|
|
{
|
|
return m_facadeInternal->getParametersClient();
|
|
}
|
|
|
|
ParametersClient& Facade::getParametersClient()
|
|
{
|
|
return m_facadeInternal->getParametersClient();
|
|
}
|
|
|
|
#if defined(US_MODULE_PERSONA)
|
|
const PersonaClient& Facade::getPersonaClient() const
|
|
{
|
|
return m_facadeInternal->getPersonaClient();
|
|
}
|
|
|
|
PersonaClient& Facade::getPersonaClient()
|
|
{
|
|
return m_facadeInternal->getPersonaClient();
|
|
}
|
|
#endif
|
|
|
|
#if defined(US_MODULE_PLAYER_ONLINE_STATUS)
|
|
const PlayerOnlineStatusClient& Facade::getPlayerOnlineStatusClient() const
|
|
{
|
|
return m_facadeInternal->getPlayerOnlineStatusClient();
|
|
}
|
|
|
|
PlayerOnlineStatusClient& Facade::getPlayerOnlineStatusClient()
|
|
{
|
|
return m_facadeInternal->getPlayerOnlineStatusClient();
|
|
}
|
|
#endif
|
|
|
|
#if defined(US_MODULE_PLAYERREPORTS)
|
|
const PlayerReportsClient& Facade::getPlayerReportsClient() const
|
|
{
|
|
return m_facadeInternal->getPlayerReportsClient();
|
|
}
|
|
|
|
PlayerReportsClient& Facade::getPlayerReportsClient()
|
|
{
|
|
return m_facadeInternal->getPlayerReportsClient();
|
|
}
|
|
#endif
|
|
|
|
#if defined(US_MODULE_PROFILE)
|
|
ProfileClient& Facade::getProfileClient()
|
|
{
|
|
return m_facadeInternal->getProfileClient();
|
|
}
|
|
#endif
|
|
|
|
#if defined(US_MODULE_SSI)
|
|
SecondaryStoreInstantiationClient& Facade::getSecondaryStoreInstantiationClient()
|
|
{
|
|
return m_facadeInternal->getSecondaryStoreInstantiationClient();
|
|
}
|
|
#endif
|
|
|
|
#if defined(US_PRIMARY_STORE_ENABLED) || defined(US_PRIMARY_STORE_MOBILE_ENABLED)
|
|
PrimaryStoreClient& Facade::getPrimaryStoreClient()
|
|
{
|
|
return m_facadeInternal->getPrimaryStoreClient();
|
|
}
|
|
#endif
|
|
|
|
#if defined(US_MODULE_RECOMMENDATIONS)
|
|
const RecommendationsClient& Facade::getRecommendationsClient() const
|
|
{
|
|
return m_facadeInternal->getRecommendationsClient();
|
|
}
|
|
|
|
RecommendationsClient& Facade::getRecommendationsClient()
|
|
{
|
|
return m_facadeInternal->getRecommendationsClient();
|
|
}
|
|
#endif
|
|
|
|
RemoteLogClient& Facade::getRemoteLogClient()
|
|
{
|
|
return m_facadeInternal->getRemoteLogClient();
|
|
}
|
|
|
|
#if defined(US_MODULE_STATS)
|
|
StatsClient& Facade::getStatsClient()
|
|
{
|
|
return m_facadeInternal->getStatsClient();
|
|
}
|
|
#endif
|
|
|
|
#if defined(US_MODULE_STORE)
|
|
SecondaryStoreClient& Facade::getSecondaryStoreClient()
|
|
{
|
|
return m_facadeInternal->getSecondaryStoreClient();
|
|
}
|
|
#endif
|
|
|
|
#if defined(US_MODULE_TLOG) && defined(US_TARGET_WINDOWS)
|
|
TLogClient& Facade::getTLogClient()
|
|
{
|
|
return m_facadeInternal->getTLogClient();
|
|
}
|
|
#endif
|
|
|
|
#if defined(US_ENABLE_UPLAY)
|
|
UplayClient& Facade::getUplayClient()
|
|
{
|
|
return m_facadeInternal->getUplayClient();
|
|
}
|
|
#endif
|
|
|
|
#if defined(US_MODULE_UGC)
|
|
const UserGeneratedContentsClient& Facade::getUserGeneratedContentsClient() const
|
|
{
|
|
return m_facadeInternal->getUserGeneratedContentsClient();
|
|
}
|
|
|
|
UserGeneratedContentsClient& Facade::getUserGeneratedContentsClient()
|
|
{
|
|
return m_facadeInternal->getUserGeneratedContentsClient();
|
|
}
|
|
#endif // US_MODULE_UGC
|
|
|
|
#if defined(US_MODULE_USER)
|
|
UserClient& Facade::getUserClient()
|
|
{
|
|
return m_facadeInternal->getUserClient();
|
|
}
|
|
#endif
|
|
|
|
#if defined(US_MODULE_VOICECHAT)
|
|
VoicechatClient& Facade::getVoicechatClient()
|
|
{
|
|
return m_facadeInternal->getVoicechatClient();
|
|
}
|
|
#endif
|
|
|
|
/// Client accessors - Client that shouldn't be in Server SDK
|
|
#if defined(US_MODULE_NEWS)
|
|
NewsClient& Facade::getNewsClient()
|
|
{
|
|
return m_facadeInternal->getNewsClient();
|
|
}
|
|
#endif
|
|
|
|
#if !defined(US_SDK_SERVER)
|
|
WebSocketClient& Facade::getWebsocketClient()
|
|
{
|
|
return m_facadeInternal->getWebsocketClient();
|
|
}
|
|
|
|
NotificationClient& Facade::getNotificationClient()
|
|
{
|
|
return m_facadeInternal->getNotificationClient();
|
|
}
|
|
|
|
PopulationClient& Facade::getPopulationsClient()
|
|
{
|
|
return m_facadeInternal->getPopulationsClient();
|
|
}
|
|
#endif // !defined(US_SDK_SERVER)
|
|
};
|