Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Copyright 2015 Dirt Productions. All rights reserved.
- #pragma once
- #include "GameFramework/GameSession.h"
- #include "Public/Data/DHGameSessionData.h"
- #include "DHGameSession.generated.h"
- /** FNetworkSessionParams
- * Declared: DHGameSessionData.h
- *
- * Holds properties about a network game session
- */
- struct FNetworkSessionParams
- {
- public:
- /** Default constructor */
- FNetworkSessionParams() : SessionID(NAME_None), bIsPresence(false), BestSessionIndex(NULL), SessionHostType(ENetworkSessionHostType::HostLocalUnauthed) {}
- /** Constructor with values
- *
- * @param SessionID Identifier of session
- * @param bIsPresence True if presence is enabled, otherwise false
- * @param BestSessionIndex Index of current search result choice
- * @param SessionHostType Host type of session
- * @param HostID Identifier of player host
- */
- FNetworkSessionParams(FName InSessionID, bool bInIsPresence, int32 InBestSessionIndex, ENetworkSessionHostType InSessionHostType, TSharedPtr<FUniqueNetId> InHostID)
- {
- SessionID = InSessionID;
- bIsPresence = bInIsPresence;
- BestSessionIndex = InBestSessionIndex;
- SessionHostType = InSessionHostType;
- HostID = InHostID;
- }
- /* ///////////////////////// VARIABLES ///////////////////////// */
- public:
- /** Identifier of session */
- FName SessionID;
- /** True if presence is enabled, otherwise false */
- bool bIsPresence;
- /** Index of current search result choice */
- int32 BestSessionIndex;
- /** Network host type */
- ENetworkSessionHostType SessionHostType;
- /** Identifier of player host */
- TSharedPtr<FUniqueNetId> HostID;
- };
- /** ADHGameSession : AGameSession
- * Declared: DHGameSession.h
- *
- * Manages sessions of game
- */
- UCLASS()
- class DISTANTHOME_API ADHGameSession : public AGameSession
- {
- GENERATED_BODY()
- public:
- /** Default constructor */
- ADHGameSession(const FObjectInitializer& ObjectInitializer);
- /* ///////////////////////// VARIABLES ///////////////////////// */
- protected:
- /* ////////// SESSION DELEGATES ////////// */
- /** Delegate for creating a new session */
- FOnCreateSessionCompleteDelegate OnCreateSessionCompleteDelegate;
- /** Delegate after starting a session */
- FOnStartSessionCompleteDelegate OnStartSessionCompleteDelegate;
- /** Delegate for destroying a session */
- FOnDestroySessionCompleteDelegate OnDestroySessionCompleteDelegate;
- /** Delegate for searching for sessions */
- FOnFindSessionsCompleteDelegate OnFindSessionsCompleteDelegate;
- /** Delegate after joining a session */
- FOnJoinSessionCompleteDelegate OnJoinSessionCompleteDelegate;
- /* ////////// SESSION VARIABLES ////////// */
- /** Transient properties of a session curing game creation/matchmaking */
- FNetworkSessionParams CurrentSessionParams;
- /** Current host settings */
- TSharedPtr<FNetworkSessionParams> HostSettings;
- /* ///////////////////////// FUNCTIONS ///////////////////////// */
- protected:
- /* ////////// SESSION DELEGATES ////////// */
- /** Delegate fired when session start request has been completed
- *
- * @param SessionName The session's name this callback corresponds to
- * @param bWasSuccessful True if the async action has succeeded, otherwise false
- */
- virtual void OnCreateSessionComplete(FName SessionName, bool bWasSuccessful);
- /** Delegate fired when session start request has been completed
- *
- * @param bWasSuccessful True if the async action has succeeded, otherwise false
- */
- void OnStartOnlineGameComplete(FName SessionName, bool bWasSuccessful);
- /** Delegate fired when a session search query has completed
- *
- * @param SessionName The session's name this callback corresponds to
- * @param Result Result of the async action
- */
- void OnJoinSessionComplete(FName SessionName, EOnJoinSessionCompleteResult::Type Result);
- /** Delegate fired when destroying a session is completed
- *
- * @param SessionName The session's name this callback corresponds to
- * @param bWasSuccessful True if the async action has succeeded, otherwise false
- */
- virtual void OnDestroySessionComplete(FName SessionName, bool bWasSuccessful);
- /* ////////// SESSION FUNCTIONS ////////// */
- /** Resets the variables keeping track of session join attempts */
- void ResetBestSessionVars();
- /** Choose the best session from a list of search results based on game criteria */
- void ChooseBestSession();
- /** Entry point for matchmaking after search results are returned */
- void StartMatchmaking();
- /** Return point after each attempt to join a search result */
- void ContinueMatchmaking();
- /** Delegate triggered when no more search results are available */
- void OnNoMatchesAvailable();
- /** Event fired when a presence session is created
- *
- * @param SessionName Name of session that was created
- * @param bWasSuccessful Was the session creation successful?
- */
- DECLARE_EVENT_TwoParams(ADHGameSession, FOnCreatePresenseSessionComplete, FName, bool);
- FOnCreatePresenseSessionComplete CreatePresenseSessionCompleteEvent;
- /** Event fired when a session is joined
- *
- * @param SessioNname Name of session that was joined
- * @param Result Result of session join action
- */
- DECLARE_EVENT_OneParam(ADHGameSession, FOnJoinSessionComplete, EOnJoinSessionCompleteResult::Type);
- FOnJoinSessionComplete JoinSessionCompleteEvent;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement