JD2022-TU1/main/extern/UbiServices/custom/client-sdk/private/ubiservices/services/facadeInterface.h

326 lines
13 KiB
C++

////////////////////////////////////////////////////////////////////////////////
// (c) Copyright, Ubisoft Entertainment Inc. || Created by Harbour //
////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "ubiservices/core/configs/config.h"
#include "ubiservices/core/configs/environment.h"
#include "ubiservices/core/helpers/instancesManager.h"
#include "ubiservices/core/helpers/mockServiceHelper.h"
#include "ubiservices/core/http/httpRequestConfig.h"
#include "ubiservices/core/log/eventLogConstants.h"
#include "ubiservices/core/tasks/asyncResult.h"
#include "ubiservices/core/tasks/asyncResultInternal.h"
#include "ubiservices/core/tasks/JobManager.h"
#if defined(US_SDK_SERVER)
#include "ubiservices/core/types/typesId/applicationId.h"
#else
#include "ubiservices/core/types/typesId/profileId.h"
#endif
#include "ubiservices/core/types/typesId/sessionId.h"
#include "ubiservices/core/types/typesId/spaceId.h"
#if !defined(US_SDK_SERVER)
#include "ubiservices/core/types/typesId/userId.h"
#endif
#include "ubiservices/services/preflightEndpoint.h"
#include "ubiservices/services/http/httpHeader.h"
#if defined(US_SDK_SERVER)
#include "ubiservices/services/http/httpRequestSignType.h"
#endif
#include "ubiservices/services/http/request/httpRetryConfig.h"
#include "ubiservices/services/parameters/featureSwitchId.h"
#include "ubiservices/services/parameters/gatewayResources.h"
#if defined(US_PRIMARY_STORE_ENABLED) || defined(US_PRIMARY_STORE_MOBILE_ENABLED)
#include "ubiservices/services/primaryStore/primaryStoreClient.h"
#include "ubiservices/services/primaryStore/primaryStoreInventoryItem.h"
#endif // defined(US_PRIMARY_STORE_ENABLED)
#if !defined(US_SDK_SERVER)
#include "ubiservices/services/populations/populationInfo.h"
#endif
namespace US_NS {;
class HttpPost;
class HttpRequest;
class HttpResponse;
class PopulationInfo;
class ClubNotification;
class NotificationCustom;
class NotificationUbiServices;
class EventClientImpl;
class RemoteLogSession;
class SessionInfo;
struct AuthenticationNotification;
struct ParametersNotification;
struct EventNotification;
class FriendNotification;
struct SecondaryStoreNotification;
#if defined(US_MODULE_SSI)
class SecondaryStoreInstantiationNotification;
#endif
struct StoreItemsMapping;
struct ParametersInfo;
struct ConfigInfoSdk;
class DynamicPopulationCustomParams;
struct ParametersGroupInfo;
#if defined(US_MODULE_BATTLEPASS)
class BattlepassNotification;
#endif
#if defined(US_MODULE_BLOCKLIST)
class BlocklistNotification;
#endif
#if defined(US_MODULE_CHALLENGE)
class ChallengeNotification;
#endif
struct ParametersGroupUpdate;
class FacadeInternal;
class SessionManager;
class SessionManagerClub;
class SessionManagerOverlay;
class SessionManagerPopulations;
class SessionManagerStore;
//typedef Map<String, ParametersGroupInfo> ParametersInfo;
enum class CallingContextForApplyDynamicUpdate {
Undefined,
CreatingNewSession, //!< Applying dynamic update while creating a new session
TransitioningFromSuspended, //!< Applying dynamic update, reloading parameters
TransitioningFromBackground, //!< Applying dynamic update, don't reload parameters
CallFromUser //!< Applying dynamic update while coming back from suspended
};
class FacadeInterface
{
public:
FacadeInterface(FacadeInternal& facade);
FacadeInterface(const FacadeInterface& facade);
const FacadeInternal& getFacade() const;
FacadeInternal& getFacade();
bool hasValidSession() const;
void invalidateSessionInfo();
const SessionInfo& getSessionInfoRO() const;
void setSessionInfo(const SessionInfo& sessionInfo, bool restartJob);
const SessionManager& getSession() const;
SessionManager& getSessionRW();
void resetCreateSessionRestPeriod();
#if defined(US_TARGET_PS4) || defined(US_TARGET_PS5)
bool getCurrentUserId(SceUserServiceUserId& userId) const;
#endif
Environment getDetectedEnvironment() const;
void setEnvironmentOnError(Environment environment);
const String& getLocaleCode() const;
bool isSwitchEnabled(FeatureSwitchId id) const;
EventClientImpl& getEventInterface();
AsyncResult<Empty> sendEvents();
void restartExtendSessionJob();
bool areParametersReady() const;
const ParametersInfo& getParametersInfo() const;
ParametersInfo& getParametersInfoRW();
bool setParametersGroupApplication(const Map<String, ParametersGroupInfo>& parametersApplication);
bool setParametersGroupSpace(const Map<String, ParametersGroupInfo>& ParametersSpace);
HttpHeader getResourcesHeader(const MockServiceId& serviceName = MockServiceId::ENUM_END, bool addTicket = true, bool isJsonContentType = true) const;
// We add less headers when communicating to Tencent to not divulge UbiServices related information
HttpHeader getResourcesHeaderForTencent() const;
StringUrl getResourceUrl(GatewayResource::Key id, Environment environment = InstancesManager::getInstance()->getEnvironment(), bool isPreflight = false) const;
StringUrl getResourceUrlPlaceHolder(GatewayResource::Key id, const char* placeholder, const String& value) const;
StringUrl getResourceUrlPlaceHolder(GatewayResource::Key id, const SpaceId& guid) const;
#if !defined(US_SDK_SERVER)
StringUrl getResourceUrlPlaceHolder(GatewayResource::Key id, const ProfileId& guid) const;
StringUrl getResourceUrlPlaceHolder(GatewayResource::Key id, const UserId& guid) const;
#endif
StringUrl getResourceUrlHardcoded(GatewayResource::Key id, Environment environment = InstancesManager::getInstance()->getEnvironment(),
OnlineAccessContext onlineAccessContext = InstancesManager::getInstance()->getOnlineAccessContext()) const;
HttpRetryConfig getSdkHttpRetryConfig() const;
AsyncResult<HttpResponse> sendRequest(const HttpRequest& request, LogCategory category, const String& owner,
HttpRequestConfig::LogRemoteMode logRemoteMode = HttpRequestConfig::LogRemoteMode::All);
AsyncResult<HttpResponse> sendRequest(const HttpRequest& request, LogCategory category, const String& owner,
const HttpRetryConfig& httpRetryConfig, HttpRequestConfig::LogRemoteMode logRemoteMode = HttpRequestConfig::LogRemoteMode::All);
const Vector<String>& getParametersGroupListApplication() const;
Vector<String>& getParametersGroupListApplicationRW();
const Vector<String>& getParametersGroupListSpace() const;
Vector<String>& getParametersGroupListSpaceRW();
const SessionManagerOverlay& getSessionManagerOverlay() const;
SessionManagerOverlay& getSessionManagerOverlayRW();
void pushNotification(const AuthenticationNotification& notification);
void pushNotification(const EventNotification& notification);
void pushNotification(const ParametersNotification& notification);
#if defined(US_MODULE_CLUB)
void pushNotification(const ClubNotification& notification);
const SessionManagerClub& getSessionManagerClub() const;
SessionManagerClub& getSessionManagerClubRW();
#endif // defined(US_MODULE_CLUB)
#if defined(US_MODULE_BATTLEPASS)
void pushNotification(const BattlepassNotification& notification);
#endif
#if defined(US_MODULE_BLOCKLIST)
void pushNotification(const BlocklistNotification& notification);
#endif
#if defined(US_MODULE_CHALLENGE)
void pushNotification(const ChallengeNotification& notification);
#endif // US_MODULE_CHALLENGE
#if defined(US_MODULE_FRIEND)
void pushNotification(const FriendNotification& notification);
#endif
#if defined(US_MODULE_STORE)
#if defined(US_PRIMARY_STORE_ENABLED)
#if defined(US_PRIMARY_STORE_WITH_API)
AsyncResult<Vector<PrimaryStoreInventoryItem> > requestPrimaryStoreItemsInventory(PrimaryStoreClient::InventoryItemFilter filter
#if defined(US_TARGET_WITH_GDK)
, const uint64 xuid = 0 // Instead of using PlayerCredentials::XUID we use uint64, in order to avoid including playerCredentials.h in this file.
#endif
);
#if !defined(US_TARGET_SWITCH)
AsyncResult<Vector<PrimaryStoreItem> > requestPrimaryStoreItemsCatalog();
#endif // !defined(US_TARGET_SWITCH)
#endif // defined(US_PRIMARY_STORE_WITH_API)
#if defined(US_TARGET_SWITCH)
void primaryStoreSyncAndSendEvent(const SpaceId& spaceId, const CallingContextForApplyDynamicUpdate callingContext);
#elif defined(US_PRIMARY_STORE_WITH_API)
void primaryStoreSyncAndSendEvent(const SpaceId& spaceId, const bool forceSync = false);
#elif defined(US_PRIMARY_STORE_WITHOUT_API)
void primaryStoreSyncAndSendEvent(const SpaceId& spaceId,
const Vector<PrimaryStoreInventoryItem>& primaryStoreInventoryResult = Vector<PrimaryStoreInventoryItem>()
, const bool forceSync = false, const bool populationUpdateDone = false);
#endif // defined(US_TARGET_SWITCH)
AsyncResultInternal<Vector<StoreItemsMapping> > requestProductMapping(const SpaceId& spaceId);
#endif // defined(US_PRIMARY_STORE_ENABLED)
const SessionManagerStore& getStoreManager() const;
SessionManagerStore& getStoreManagerRW();
void pushNotification(const SecondaryStoreNotification& notification);
#endif // defined(US_MODULE_STORE)
#if defined(US_MODULE_SSI)
void pushNotification(const SecondaryStoreInstantiationNotification& notification);
#endif
#if !defined(US_SDK_SERVER)
void pushNotification(const NotificationCustom& notification);
void pushNotification(const NotificationUbiServices& notification);
bool hasDefaultSession() const;
bool hasUserAccountLinked() const;
const SessionManagerPopulations& getPopulationManager() const;
SessionManagerPopulations& getPopulationManagerRW();
// Warning : Caller must ensure not being in suspended mode while calling this method
AsyncResult<Vector<PopulationInfo> > applyDynamicUpdates(const DynamicPopulationCustomParams& customData,
const CallingContextForApplyDynamicUpdate callingContext);
const StringKeyMap<String>& getParametersRelatedPopulations() const;
bool updateApplicationGroupParameters(const ParametersGroupUpdate& update);
bool updateSpaceGroupParameters(const ParametersGroupUpdate& update);
StringUrl getClubServicesUrl(const String& name) const;
StringUrl getClubServicesUrlPlaceHolder(const String& name, Environment env) const;
String getClubGameCode() const;
StringUrl getUplayServicesUrl(const String& name) const;
AsyncResult<Empty> terminateConnection(bool skipClosingHandshake);
void launchWebsocketInit1();
void launchWebsocketInit2();
bool signRequest(HttpRequest& request, const ProfileId& profile, const SessionId& session, const String& sessionKey);
#else
bool signRequest(HttpRequest& request, const ApplicationId& application,
const String& sessionKey, const String& decryptionKey, const String& decryptionIV);
#endif // !defined(US_SDK_SERVER)
template <typename T>
void StartTask(typename T::JobAsyncType& async)
{
async.startTask(US_NEW(T, async, getFacade()));
}
template <typename T, typename P1>
void StartTask(typename T::JobAsyncType& async, P1& p1)
{
async.startTask(US_NEW(T, async, getFacade(), p1));
}
template <typename T, typename P1, typename P2>
void StartTask(typename T::JobAsyncType& async, P1& p1, P2& p2)
{
async.startTask(US_NEW(T, async, getFacade(), p1, p2));
}
template <typename T, typename P1, typename P2, typename P3>
void StartTask(typename T::JobAsyncType& async, const P1& p1, const P2& p2, const P3& p3)
{
async.startTask(US_NEW(T, async, getFacade(), p1, p2, p3));
}
template <typename T, typename P1>
void StartTask(JobManager& manager, typename T::JobAsyncType& async, const P1& p1)
{
manager.launch(async, US_NEW(T, async, getFacade(), p1));
}
template <typename T, typename P1, typename P2>
void StartTask(JobManager& manager, typename T::JobAsyncType& async, const P1& p1, const P2& p2)
{
manager.launch(async, US_NEW(T, async, getFacade(), p1, p2));
}
template <typename T, typename P1, typename P2, typename P3, typename P4>
void StartTask(JobManager& manager, typename T::JobAsyncType& async, const P1& p1, const P2& p2, P3& p3, P4& p4)
{
manager.launch(async, US_NEW(T, async, getFacade(), p1, p2, p3, p4));
}
private:
US_CLASS_DEFAULT_CTOR_NOT_ALLOWED(FacadeInterface);
//US_CLASS_COPY_NOT_ALLOWED(FacadeInterface);
FacadeInterface& operator=(FacadeInterface&); // Assignment operator not allowed
SmartPtr<FacadeInternal> m_facade;
SmartPtr<SessionInfo> m_sessionInfo;
// passed on Login to recover extra parameters from the parameters service
SmartPtrEx<String>::SmartPointer m_localeCodeCurrent;
#if !defined(US_SDK_SERVER)
const String m_populationsInfoHeader;
#endif
String getMockScenarioToUse(const MockServiceId& serviceName) const;
};
};