//////////////////////////////////////////////////////////////////////////////// // (c) Copyright, Ubisoft Entertainment Inc. || Created by Harbour // //////////////////////////////////////////////////////////////////////////////// #pragma once #include "ubiservices/core/configs/config.h" #include "ubiservices/core/chrono/chronometer.h" #include "ubiservices/core/locks/mutualExecutionBlocker.h" #include "ubiservices/core/memory/smartPtr.h" #include "ubiservices/core/tasks/asyncResultInternal.h" #include "ubiservices/core/tasks/JobManager.h" #include "ubiservices/services/authentication/jobs/jobExtendSession.h" #include "ubiservices/services/authentication/jobs/jobInitWebsocket.h" #include "ubiservices/services/authentication/playerCredentials.h" #include "ubiservices/services/authentication/sessionInfo.h" #if defined(US_MODULE_CLUB) #include "ubiservices/services/club/sessionManagerClub.h" #endif #include "ubiservices/services/overlay/sessionManagerOverlay.h" #include "ubiservices/services/parameters/featureSwitch.h" #include "ubiservices/services/parameters/parametersGroupUpdate.h" #include "ubiservices/services/parameters/parametersInfo.h" #if !defined(US_SDK_SERVER) #include "ubiservices/services/populations/sessionManagerPopulations.h" #endif #if defined(US_MODULE_STORE) #include "ubiservices/services/secondaryStore/sessionManagerStore.h" #endif // defined(US_MODULE_STORE) namespace US_NS {; class FacadeInternal; #if !defined(US_SDK_SERVER) class PlayerCredentials; class WebSocketConnection; typedef SmartPtr WebSocketConnectionPtr; #endif typedef Map ParametersGroupInfoMap; // Manages accesses and changes to the session and parametersGroups information for a facade instance. // @note The m_sessionManagerStore, m_connection and m_storedCredentials instances remain here for // convenience (moving these members out would involve dynamic allocations for each instances when // constructing the facade). class SessionManager final : public RootObject { public: SessionManager(FacadeInternal& facade); ~SessionManager(); void init(); bool hasValidSessionInfoInternal() const; const SessionInfo& getSessionInfoRO() const; void invalidateSessionInfo(); void resetSessionInfo(); void setSessionInfo(const SessionInfo& sessionInfo, bool restartJob); void restartExtendSessionJob(); Environment getDetectedEnvironment(const SessionInfo* sessionInfo) const; void setEnvironmentOnError(Environment environment); void unsetEnvironmentOnError(); void resetParametersInfo(); void updateParametersSettings(); bool areParametersGroupsReady() const; // Is Configuration Ready bool isParametersApplicationReady() const; bool isParametersSpaceReady() const; const ParametersInfo& getParametersInfo() const; ParametersInfo& getParametersInfoRW(); bool setParametersGroupApplication(const ParametersGroupInfoMap& parametersGroupApplication); bool setParametersGroupSpace(const ParametersGroupInfoMap& parametersGroupSpace); Vector& getParametersGroupListApplicationRW(); const Vector& getParametersGroupListApplication() const; Vector& getParametersGroupListSpaceRW(); const Vector& getParametersGroupListSpace() const; const FeatureSwitch& getSwitchesContent() const; FeatureSwitch& getSwitchesContentRW(); void setSwitchesContent(const FeatureSwitch& switches); void enableSwitch(FeatureSwitchId feature, bool enableState); class RestPeriod { public: RestPeriod(); private: friend class AuthenticationClient; friend class FacadeInterface; HighResolutionChrono m_chrono; }; SessionManager::RestPeriod& getRestPeriod(); const SessionManagerOverlay& getSessionManagerOverlay() const; SessionManagerOverlay& getSessionManagerOverlayRW(); bool getIsFirstCallToLogin(); void setFirstCallToLoginDone(); bool isLogEnabledSdk(RemoteLogLevel::Enum logLevel, LogCategory logCategory) const; bool isLogEnabledCustom(RemoteLogLevel::Enum logLevel, const String& logCategory) const; void setWaitRemoteLogCompletionOnDeleteSessionParameter(bool state); // For test only SpaceId getWorkingSpaceId() const; void setWorkingSpaceId(const SpaceId& workingSpaceid); // This function assigns the Staging SpadeId to our Working SpaceId if the Staging SpadeId is present and valid in the Parameter Group. bool updateWorkingSpaceId(const Map& parameters); /////////////////////////////////////////////////////////////////////// // For blocking mutual execution. Create Session AsyncResult& getCreateSessionAsyncResultRW(); ExecutionBlocker& getExecutionBlocker(MutualExecutionBlocker::BlockingCallType blockingCallType); #if !defined(US_SDK_SERVER) class WebSocketInit { public: WebSocketInit(FacadeInternal& facade); void launchInitLogin(); void launchInitResume(); void cancelWebsocketInit(); private: FacadeInternal& m_facade; JobInitWebsocket::JobAsyncType m_result; JobManager m_manager; }; SessionManager::WebSocketInit& getWebSocketInitializer(); bool hasDefaultSessionInfo() const; const ProfileId& getStoredProfile() const; bool hasNotificationTypeChanged() const; DurationMilli getNotificationUpdateRandomDelay() const; Vector mergeNotificationTypes(const Vector& types1, const Vector& types2) const; Map getUpdatedParameterGroupInfo(const ParametersGroupUpdate& parametersGroupUpdate); bool updateApplicationGroupParameters(const ParametersGroupUpdate& parametersGroupUpdate); bool updateSpaceGroupParameters(const ParametersGroupUpdate& parametersGroupUpdate); const SessionManagerPopulations& getSessionManagerPopulations() const; SessionManagerPopulations& getSessionManagerPopulationsRW(); const SmartPtr& getStoredCredentials() const; SmartPtr& getStoredCredentialsRW(); void setStoredCredentials(const PlayerCredentials& credentials); bool isEventEndOfGame() const; void setEventEndOfGame(); const WebSocketConnectionPtr& getConnection() const; WebSocketConnectionPtr& getConnection(); String getConnectionMetaData(void) const; void setConnectionMetaData(const String& connectionMetaData); /////////////////////////////////////////////////////////////////////// // For blocking mutual execution. PopUnsentEvent AsyncResult& getPopUnsentEventsAsyncResultRW(); void setConcurrentConnectRestPeriodInProgress(bool enabled); const bool isConcurrentConnectRestPeriodInProgress(); #if defined(US_MODULE_CLUB) const SessionManagerClub& getSessionManagerClub() const; SessionManagerClub& getSessionManagerClubRW(); #endif // defined(US_MODULE_CLUB) #if defined(US_MODULE_STORE) const SessionManagerStore& getSessionManagerStore() const; SessionManagerStore& getSessionManagerStoreRW(); #endif // defined(US_MODULE_STORE) #if defined(US_TARGET_SWITCH) void setStoredUserHandle(const nn::account::UserHandle& userHandle); const nn::account::UserHandle& getStoredUserHandle() const; const bool isUserHandleSet() const; #elif defined(US_TARGET_PS4) || defined(US_TARGET_PS5) void setStoredUserId(const SceUserServiceUserId& userId); const SceUserServiceUserId& getStoredUserId() const; const bool isUserIdSet() const; #elif defined(US_TARGET_STADIA) void setStoredPlayerId(const ggp::PlayerId& playerId); const ggp::PlayerId& getStoredPlayerId() const; const bool isPlayerIdSet() const; #endif #elif defined(US_SDK_SERVER) void setUbiCertificateKeyPublic(const String& ubiCertificateKeyPublic); const String getUbiCertificateKeyPublic() const; void setUbiCertificateKeyPrivateObfuscated(const Vector& ubiCertificateKeyPrivateObfuscated); const Vector& getUbiCertificateKeyPrivateObfuscated() const; void setServerCreateSessionOverrideSpaceId(const SpaceId& spaceId); const SpaceId& getServerCreateSessionOverrideSpaceId() const; const bool isCertificatePublicSet() const; #endif // defined(US_SDK_SERVER) private: FacadeInternal& m_facade; // Instance host friend class FacadeInterface; SmartPtr m_sessionInfoSnapshot; // Snapshot the jobs use to perform asynchronous tasks SessionInfo m_sessionInfo; RestPeriod m_restPeriod; Optional m_environmentOnError; ParametersInfo m_parameters; Vector m_parametersGroupListApplication; Vector m_parametersGroupListSpace; FeatureSwitch m_spaceSwitches; FeatureSwitch m_applicationSwitches; FeatureSwitch m_killSwitch; JobManager m_jobManagerExtendSession; JobExtendSession::JobAsyncType m_extendSessionResult; SessionManagerOverlay m_sessionManagerOverlay; friend struct TestExtendSessionHelper; void reduceSessionDuration(uint64 expirationTimeMs); // Only used for test purposes. //TODO: REMOVE TEST-ONLY CODE FROM SDK bool m_isFirstCallToJobLogin; // The Working SpaceId is used everywhere in the SDK. It can be the Application, the Staging or the CrossPlay Spade Id. SpaceId m_workingSpaceId; /////////////////////////////////////////////////////////////////////// // For blocking mutual execution. Create Session AsyncResult m_createSessionResult; Map m_executionBlockers; #if !defined(US_SDK_SERVER) SessionManager::WebSocketInit m_webSocketInit; ProfileId m_storedProfileId; SmartPtr m_storedCredentials; // Tells if EventClient::popUnsentEventsEndOfGame() has been called, and that the event system is stopped bool m_isEventEndOfGame; #if defined(US_MODULE_STORE) SessionManagerStore m_sessionManagerStore; #endif #if defined(US_MODULE_CLUB) SessionManagerClub m_sessionManagerClub; #endif #if defined(US_TARGET_SWITCH) nn::account::UserHandle m_userHandle; bool m_isUserHandleSet; #elif defined(US_TARGET_PS4) || defined(US_TARGET_PS5) SceUserServiceUserId m_userId; bool m_isUserIdSet; #elif defined(US_TARGET_STADIA) ggp::PlayerId m_playerId; bool m_isPlayerIdSet; #endif SessionManagerPopulations m_sessionManagerPopulations; WebSocketConnectionPtr m_connection; // persistent connection holder String m_connectionMetaData; /////////////////////////////////////////////////////////////////////// // For blocking mutual execution. PopUnsentEvent AsyncResult m_popUnsentEventsResult; bool m_concurrentConnectRestPeriodInProgress; // Set to true just after receiving the US_CONCURRENT_CONNECT_DETECTED notification // Set back to false after a succeeded create session #else String m_certificateKeyPublic; Vector m_certificateKeyPrivateObfuscated; // Obfuscated Private Key from the certificate SpaceId m_serverCreateSessionOverrideSpaceId; // Override SpaceId set in facade.createSession() bool m_isCertificatePublicKeySet; #endif // !defined(US_SDK_SERVER) }; };