295 lines
11 KiB
C++
295 lines
11 KiB
C++
////////////////////////////////////////////////////////////////////////////////
|
|
// (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<WebSocketConnection> WebSocketConnectionPtr;
|
|
#endif
|
|
typedef Map<String, ParametersGroupInfo> 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<String>& getParametersGroupListApplicationRW();
|
|
const Vector<String>& getParametersGroupListApplication() const;
|
|
|
|
Vector<String>& getParametersGroupListSpaceRW();
|
|
const Vector<String>& 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<String, ParametersGroupInfo>& parameters);
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
// For blocking mutual execution. Create Session
|
|
AsyncResult<Empty>& 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<String> mergeNotificationTypes(const Vector<String>& types1, const Vector<String>& types2) const;
|
|
|
|
Map<String, ParametersGroupInfo> getUpdatedParameterGroupInfo(const ParametersGroupUpdate& parametersGroupUpdate);
|
|
bool updateApplicationGroupParameters(const ParametersGroupUpdate& parametersGroupUpdate);
|
|
bool updateSpaceGroupParameters(const ParametersGroupUpdate& parametersGroupUpdate);
|
|
|
|
const SessionManagerPopulations& getSessionManagerPopulations() const;
|
|
SessionManagerPopulations& getSessionManagerPopulationsRW();
|
|
|
|
const SmartPtr<PlayerCredentials>& getStoredCredentials() const;
|
|
SmartPtr<PlayerCredentials>& 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<String>& 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<uint8>& ubiCertificateKeyPrivateObfuscated);
|
|
const Vector<uint8>& 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<SessionInfo> m_sessionInfoSnapshot; // Snapshot the jobs use to perform asynchronous tasks
|
|
SessionInfo m_sessionInfo;
|
|
|
|
RestPeriod m_restPeriod;
|
|
|
|
Optional<Environment> m_environmentOnError;
|
|
|
|
ParametersInfo m_parameters;
|
|
Vector<String> m_parametersGroupListApplication;
|
|
Vector<String> 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<Empty> m_createSessionResult;
|
|
Map<MutualExecutionBlocker::BlockingCallType, ExecutionBlocker> m_executionBlockers;
|
|
|
|
#if !defined(US_SDK_SERVER)
|
|
SessionManager::WebSocketInit m_webSocketInit;
|
|
|
|
ProfileId m_storedProfileId;
|
|
SmartPtr<PlayerCredentials> 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<String> 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<uint8> 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)
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|