Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,72 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <AzCore/Component/ComponentBus.h>
#include <AzCore/EBus/EBus.h>
#include <AzCore/RTTI/BehaviorContext.h>
#include <AzCore/RTTI/BehaviorContext.h>
#include <GridMate/NetworkGridMateSessionEvents.h>
namespace GridMate
{
class GridSession;
class GridSearch;
struct SearchInfo;
}
namespace Multiplayer
{
struct SessionDesc;
struct GridSearchTicket;
}
namespace AZ
{
AZ_TYPE_INFO_SPECIALIZE(Multiplayer::GridSearchTicket, "{1C8A155B-123F-4E71-8B33-C043248FB164}");
AZ_TYPE_INFO_SPECIALIZE(GridMate::GridSearch, "{5FDCA36D-8284-46DC-9387-81A7A70EDBA8}");
AZ_TYPE_INFO_SPECIALIZE(GridMate::SearchInfo, "{D7BBA18F-5F7C-4E28-8446-6E0E709B1CDD}");
}
namespace Multiplayer
{
/**
* An interface to expose Grid searching for an EBus
*/
class GridSearchInterface
: public AZ::ComponentBus
{
public:
// Signal events
virtual const GridSearchTicket* StartSearch(const SessionDesc& sessionDesc) = 0;
virtual bool StopSearch(GridSearchTicket* search) = 0;
virtual bool JoinSession(const GridMate::SearchInfo* searchInfo) = 0;
// Sink callbacks
virtual void OnSearchComplete(const GridSearchTicket* gridSearch) = 0;
virtual void OnSearchError(const GridMate::string& errorMsg) = 0;
virtual void OnSearchInfo(const GridMate::SearchInfo* searchInfo) = 0;
virtual void OnSearchClosed(bool isJoiningSession) = 0;
virtual void OnJoinComplete(const GridMate::GridSession* gridSession) = 0;
};
using GridSearchBus = AZ::EBus<GridSearchInterface>;
/**
* Exposes Grid searching events and callbacks to a behavior context such as Lua
*/
namespace GridSearchBehavior
{
void Reflect(AZ::ReflectContext* reflectContext);
}
}
@@ -0,0 +1,112 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <AzCore/RTTI/BehaviorContext.h>
#include <GridMate/NetworkGridMateSessionEvents.h>
#include <GridMate/Types.h>
#include "Multiplayer/MultiplayerEventsComponent.h"
namespace GridMate
{
class GridSession;
class GridSearch;
struct SearchInfo;
struct CarrierDesc;
};
namespace Multiplayer
{
class GridMateServiceWrapper;
struct GridMateServiceParams;
};
namespace Multiplayer
{
/**
* Allows behavior contexts to describe network session parameters
*/
struct SessionDesc
{
public:
AZ_TYPE_INFO(SessionDesc, "{AC88F475-C5E1-4FC9-ADFB-D4C595E05CD6}");
SessionDesc()
: m_gamePort(34003)
, m_maxPlayerSlots(16)
, m_enableDisconnectDetection(true)
, m_connectionTimeoutMS(500)
, m_threadUpdateTimeMS(30)
, m_mapName()
, m_serverName()
, m_serviceType(GridMate::ST_MAX)
{
}
AZ::u16 m_gamePort;
AZ::u16 m_maxPlayerSlots;
bool m_enableDisconnectDetection;
AZ::u32 m_connectionTimeoutMS;
AZ::s32 m_threadUpdateTimeMS;
AZStd::string m_mapName;
AZStd::string m_serverName;
GridMate::ServiceType m_serviceType;
};
/**
* Exposes network session management from behavior contexts
*/
class SessionManagerInterface
: public AZ::ComponentBus
{
public:
// EBusTraits
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
// Signal events
virtual bool StartHost(const SessionDesc& sessionDesc) = 0;
virtual bool Close() = 0;
// Sink events
virtual void OnHostSessionStarted(GridMate::GridSession* session) = 0;
};
using SessionManagerBus = AZ::EBus<SessionManagerInterface>;
/**
* The GridMate system component methods
*/
namespace GridMateSystemContext
{
/**
* registers the GridMate system for behavior contexts
*/
void Reflect(AZ::ReflectContext* reflectContext);
/**
* helper method for fetch parameters from a session description or the console where the 'param' is filled out when this returns true
*/
bool FetchParam(const char* key, SessionDesc sessionDesc, GridMate::GridSessionParam& param);
/**
* helper method to fill out a CarrierDesc for behavior contexts
*/
void InitCarrierDesc(const GridMateServiceParams& gridMateServiceParams, GridMate::CarrierDesc& carrierDesc);
/**
* Creates a MultiplayerLobbyServiceWrapper based on the GridMate::ServiceType for an entity
*/
GridMateServiceWrapper* RegisterServiceWrapper(GridMate::ServiceType gridServiceType);
};
}
@@ -0,0 +1,36 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include "Multiplayer/GridMateServiceWrapper/GridMateServiceWrapper.h"
namespace Multiplayer
{
class GridMateLANServiceWrapper
: public GridMateServiceWrapper
{
public:
AZ_CLASS_ALLOCATOR(GridMateLANServiceWrapper, AZ::SystemAllocator, 0);
bool SanityCheck(GridMate::IGridMate* gridMate) override;
bool StartSessionService(GridMate::IGridMate* gridMate) override;
void StopSessionService(GridMate::IGridMate* gridMate) override;
protected:
GridMate::GridSession* CreateServerForService(GridMate::IGridMate* gridMate, GridMate::CarrierDesc& carrierDesc, const GridMateServiceParams& params) override;
GridMate::GridSearch* ListServersForService(GridMate::IGridMate* gridMate, const GridMateServiceParams& params) override;
GridMate::GridSession* JoinSessionForService(GridMate::IGridMate* gridMate, GridMate::CarrierDesc& carrierDesc, const GridMate::SearchInfo* searchInfo) override;
private:
int GetServerPort(const GridMateServiceParams& params) const;
};
}
@@ -0,0 +1,104 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <AzCore/Memory/SystemAllocator.h>
#include <GridMate/Session/Session.h>
namespace Multiplayer
{
namespace Convert
{
template <typename T>
T GridSessionParam(const GridMate::GridSessionParam& param, T orDefault)
{
static_assert(AZStd::is_pod<T>::value == false, "ConvertGridSessionParam requires a conversion specialization.");
return orDefault;
}
template <>
int GridSessionParam(const GridMate::GridSessionParam& param, int orDefault);
template <>
float GridSessionParam(const GridMate::GridSessionParam& param, float orDefault);
template <>
long long GridSessionParam(const GridMate::GridSessionParam& param, long long orDefault);
template <>
double GridSessionParam(const GridMate::GridSessionParam& param, double orDefault);
}
struct GridMateServiceParams
{
explicit GridMateServiceParams(const GridMate::SessionParams& sessionParams, AZStd::function<GridMate::GridSessionParam(const char*)> cb)
: m_sessionParams(sessionParams)
, m_version(1)
, m_fetchSessionParam(cb)
{}
void AssignSessionParams(GridMate::SessionParams& other) const
{
other = m_sessionParams;
}
GridMate::string FetchString(const char* varName) const
{
if (m_fetchSessionParam)
{
GridMate::GridSessionParam p = m_fetchSessionParam(varName);
if (p.m_type == GridMate::GridSessionParam::VT_STRING)
{
return AZStd::move(p.m_value);
}
}
return GridMate::string();
}
template <typename T>
T FetchValueOrDefault(const char* varName, T orDefault) const
{
if (m_fetchSessionParam)
{
return Convert::GridSessionParam<T>(m_fetchSessionParam(varName), orDefault);
}
return orDefault;
}
const GridMate::SessionParams& m_sessionParams;
GridMate::VersionType m_version;
AZStd::function<GridMate::GridSessionParam(const char*)> m_fetchSessionParam;
};
class GridMateServiceWrapper
{
public:
AZ_CLASS_ALLOCATOR(GridMateServiceWrapper, AZ::SystemAllocator, 0);
public:
virtual ~GridMateServiceWrapper() = default;
virtual bool SanityCheck(GridMate::IGridMate* gridMate) = 0;
virtual bool StartSessionService(GridMate::IGridMate* gridMate) = 0;
virtual void StopSessionService(GridMate::IGridMate* gridMate) = 0;
GridMate::GridSession* CreateServer(GridMate::IGridMate* gridMate, GridMate::CarrierDesc& carrierDesc, const GridMateServiceParams& params);
GridMate::GridSearch* ListServers(GridMate::IGridMate* gridMate, const GridMateServiceParams& params);
GridMate::GridSession* JoinSession(GridMate::IGridMate* gridMate, GridMate::CarrierDesc& carrierDesc, const GridMate::SearchInfo* searchInfo);
protected:
virtual GridMate::GridSession* CreateServerForService(GridMate::IGridMate* gridMate, GridMate::CarrierDesc& carrierDesc, const GridMateServiceParams& params) = 0;
virtual GridMate::GridSearch* ListServersForService(GridMate::IGridMate* gridMate, const GridMateServiceParams& params) = 0;
virtual GridMate::GridSession* JoinSessionForService(GridMate::IGridMate* gridMate, GridMate::CarrierDesc& carrierDesc, const GridMate::SearchInfo* searchInfo) = 0;
};
}
@@ -0,0 +1,62 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <AzCore/EBus/EBus.h>
#include <GridMate/Session/Session.h>
#include <GridMate/Carrier/DefaultSimulator.h>
namespace GridMate
{
class SecureSocketDriver;
}
namespace Multiplayer
{
class MultiplayerRequests
: public AZ::EBusTraits
{
public:
//////////////////////////////////////////////////////////////////////////
// EBusTraits overrides
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
//////////////////////////////////////////////////////////////////////////
//! Returns whether or not Network Security is enabled.
virtual bool IsNetSecEnabled() const = 0;
//! Returns whether or not Network Security is verifying the client
virtual bool IsNetSecVerifyClient() const = 0;
//! Enforces SecureSocketDriver over default(non-encrypted) socket driver. Works only for platforms supporting SecureSocketDriver (See NET_SUPPORT_SECURE_SOCKET_DRIVER compile option)
virtual void RegisterSecureDriver(GridMate::SecureSocketDriver* driver) = 0;
//! Retrieve current session
virtual GridMate::GridSession* GetSession() = 0;
//! Sets the current session
virtual void RegisterSession(GridMate::GridSession* gridSession) = 0;
//! Retrieve current network simulator or null if there is none
virtual GridMate::Simulator* GetSimulator() = 0;
//! Enable network simulator
virtual void EnableSimulator() = 0;
//! Disable network simulator
virtual void DisableSimulator() = 0;
};
using MultiplayerRequestBus = AZ::EBus<MultiplayerRequests>;
} // namespace Multiplayer
@@ -0,0 +1,98 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <AzCore/Component/ComponentBus.h>
#include <AzCore/Component/Component.h>
#include <AzCore/EBus/EBus.h>
#include <AzCore/Memory/SystemAllocator.h>
#include <AzCore/std/string/string.h>
#include <AzCore/RTTI/BehaviorContext.h>
#include <GridMate/NetworkGridMateSessionEvents.h>
namespace AZ
{
class ReflectContext;
};
namespace GridMate
{
class GridSession;
class GridMember;
};
namespace AZ
{
AZ_TYPE_INFO_SPECIALIZE(GridMate::IGridMate, "{36719AC6-5034-4C59-B27C-D1CE9E84EC11}");
AZ_TYPE_INFO_SPECIALIZE(GridMate::GridSession, "{E7DAD8D4-0A6F-43F0-B9D7-943F28BCA3F6}");
AZ_TYPE_INFO_SPECIALIZE(GridMate::GridMember, "{6776F991-3C8A-439B-81A5-0C8FEE4A58AC}");
AZ_TYPE_INFO_SPECIALIZE(GridMate::string, "{9ED5D0E0-E278-4471-BD68-890F1141D4B5}");
AZ_TYPE_INFO_SPECIALIZE(GridMate::gridmate_string, "{27C4D9CF-EEB5-4204-9EAE-4CF03E8CC636}");
AZ_TYPE_INFO_SPECIALIZE(GridMate::PlayerId, "{1D45BA71-220A-48A3-B8BF-BC7949DFA7D0}");
};
namespace Multiplayer
{
/**
* Pass thru behavior for GridMate::SessionEventBus::Handler
*/
class SessionEventBusBehaviorHandler
: public GridMate::SessionEventBus::Handler
, public AZ::BehaviorEBusHandler
{
public:
AZ_EBUS_BEHAVIOR_BINDER(SessionEventBusBehaviorHandler, "{31E5EA10-42F6-4152-A924-7F6DAE1588BC}", AZ::SystemAllocator
, OnSessionServiceReady
, OnSessionCreated
, OnSessionDelete
, OnMemberJoined
, OnMemberLeaving
, OnMemberKicked
, OnSessionJoined
, OnSessionError
, OnSessionStart
, OnSessionEnd
);
// GridMate::SessionEventBus
void OnSessionServiceReady() override;
void OnMemberJoined(GridMate::GridSession* session, GridMate::GridMember* member) override;
void OnMemberLeaving(GridMate::GridSession* session, GridMate::GridMember* member) override;
void OnMemberKicked(GridMate::GridSession* session, GridMate::GridMember* member, AZ::u8 kickreason) override;
void OnSessionCreated(GridMate::GridSession* session) override;
void OnSessionJoined(GridMate::GridSession* session) override;
void OnSessionDelete(GridMate::GridSession* session) override;
void OnSessionError(GridMate::GridSession* session, const GridMate::string& errorMsg) override;
void OnSessionStart(GridMate::GridSession* session) override;
void OnSessionEnd(GridMate::GridSession* session) override;
};
class MultiplayerEventsComponent
: public AZ::Component
{
public:
AZ_COMPONENT(MultiplayerEventsComponent,"{5969EE34-A090-4367-A6B5-464D1D5F3BF4}");
// for behavior reflection
static void Reflect(AZ::ReflectContext* reflectContext);
protected:
// AZ::Component
void Init() override;
void Activate() override;
void Deactivate() override;
};
}
@@ -0,0 +1,48 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#ifndef GEMS_MULTIPLAYER_MULTIPLAYERLOBBYBUS_H
#define GEMS_MULTIPLAYER_MULTIPLAYERLOBBYBUS_H
#include <AzCore/Component/ComponentBus.h>
namespace GridMate
{
struct SessionParams;
}
namespace Multiplayer
{
class MultiplayerLobbyInterface
: public AZ::ComponentBus
{
public:
// EBusTraits
static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
// MultiplayerLobbyInterface
virtual int GetGamePort() const = 0;
virtual void ShowError(const char* error) = 0;
virtual void DismissError(bool force = false) = 0;
virtual void ShowBusyScreen() = 0;
virtual void DismissBusyScreen(bool force = false) = 0;
virtual void ConfigureSessionParams(GridMate::SessionParams& sessionParams) = 0;
};
using MultiplayerLobbyBus = AZ::EBus<MultiplayerLobbyInterface>;
}
#endif
@@ -0,0 +1,154 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#ifndef GEMS_MULTIPLAYER_MULTIPLAYERLOBBYCOMPONENT_H
#define GEMS_MULTIPLAYER_MULTIPLAYERLOBBYCOMPONENT_H
#include <AzCore/Component/Component.h>
#include <GridMate/GridMate.h>
#include <GridMate/Session/Session.h>
#include <GameLift/Session/GameLiftClientServiceEventsBus.h>
#include <LyShine/ILyShine.h>
#include <LyShine/Bus/UiCanvasBus.h>
#include "Multiplayer/MultiplayerLobbyBus.h"
#include "Multiplayer/MultiplayerLobbyServiceWrapper/MultiplayerLobbyServiceWrapper.h"
namespace Multiplayer
{
class MultiplayerLobbyServiceWrapper;
class MultiplayerDedicatedHostTypeSelectionCanvas;
class MultiplayerGameLiftLobbyCanvas;
class MultiplayerLANGameLobbyCanvas;
class MultiplayerBusyAndErrorCanvas;
class MultiplayerLobbyComponent
: public AZ::Component
, public GridMate::SessionEventBus::Handler
, public Multiplayer::MultiplayerLobbyBus::Handler
#if defined(BUILD_GAMELIFT_CLIENT)
, public GridMate::GameLiftClientServiceEventsBus::Handler
#endif
{
public:
AZ_COMPONENT(MultiplayerLobbyComponent,"{916E8722-7CCF-4FBA-B2B2-81A7407B2272}");
static void Reflect(AZ::ReflectContext* reflectContext);
MultiplayerLobbyComponent();
virtual ~MultiplayerLobbyComponent();
// AZ::Component
void Activate() override;
void Deactivate() override;
// SessionEventBus
void OnSessionCreated(GridMate::GridSession* session) override;
void OnSessionError(GridMate::GridSession* session, const GridMate::string& errorMsg) override;
void OnGridSearchComplete(GridMate::GridSearch* search) override;
// MultiplayerLobbyBus
int GetGamePort() const;
void ConfigureSessionParams(GridMate::SessionParams& sessionParams);
protected:
enum class LobbyMode
{
Unknown,
LobbySelection, // Provides selection to enter LAN/GAMELIFT
GameliftLobby, // GameLift lobby
ServiceWrapperLobby // LAN lobby
};
// MultiplayerLobbyComponent
void ShowSelectionLobby();
void ShowLobby(LobbyMode lobbyType);
void HideLobby();
virtual bool StartSessionService(LobbyMode lobbyType);
virtual void StopSessionService();
void CreateServer();
void ListServers();
void ClearSearches();
void JoinServer();
bool JoinSession(const GridMate::SearchInfo* searchInfo);
virtual bool SanityCheck();
virtual bool SanityCheckGameLift();
void SelectLANServerType();
void SelectGameLiftServerType();
void StartGameLiftMatchmaking();
MultiplayerLANGameLobbyCanvas* m_lanGameLobbyCanvas;
MultiplayerGameLiftLobbyCanvas* m_gameLiftLobbyCanvas;
MultiplayerBusyAndErrorCanvas* m_busyAndErrorCanvas;
MultiplayerDedicatedHostTypeSelectionCanvas* m_dedicatedHostTypeSelectionCanvas;
// Wrapped Session Service
MultiplayerLobbyServiceWrapper* m_multiplayerLobbyServiceWrapper;
// Shared Configuration
GridMate::GridSearch* m_listSearch;
// Gamelift Configuration
GridMate::GridSearch* m_gameliftCreationSearch;
private:
// ServiceWrapperLobby Functions
bool SanityCheckWrappedSessionService();
void CreateServerForWrappedService();
void ListServersForWrappedService();
bool ValidateGameLiftConfig();
#if defined(BUILD_GAMELIFT_CLIENT)
bool StartGameLiftSession();
void StopGameLiftSession();
void CreateServerForGameLift();
void ListServersForGameLift();
// GridMate::GameLiftSessionServiceEventsBus::Handler
void OnGameLiftSessionServiceReady(GridMate::GameLiftClientService*) override;
void OnGameLiftSessionServiceFailed(GridMate::GameLiftClientService*, const AZStd::string& message) override;
#endif
void ShowError(const char* error);
void DismissError(bool force = false);
void ShowBusyScreen();
void DismissBusyScreen(bool force = false);
LyShine::StringType GetMapName() const;
LyShine::StringType GetServerName() const;
// External Configuration
int m_maxPlayers;
int m_port;
bool m_enableDisconnectDetection;
unsigned int m_connectionTimeoutMS;
AZStd::string m_defaultMap;
AZStd::string m_defaultServerName;
AZStd::string m_defaultMatchmakingConfig;
bool m_unregisterGameliftServiceOnErrorDismiss;
bool m_hasGameliftSession;
LobbyMode m_lobbyMode;
};
}
#endif
@@ -0,0 +1,45 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#ifndef GEMS_MULTIPLAYER_MULTIPLAYERLOBBYSERVICEWRAPPER_MULTIPLAYERLOBBYLANSERVICEWRAPPER_H
#define GEMS_MULTIPLAYER_MULTIPLAYERLOBBYSERVICEWRAPPER_MULTIPLAYERLOBBYLANSERVICEWRAPPER_H
#include "Multiplayer/MultiplayerLobbyServiceWrapper/MultiplayerLobbyServiceWrapper.h"
namespace Multiplayer
{
class MultiplayerLobbyLANServiceWrapper
: public MultiplayerLobbyServiceWrapper
{
public:
AZ_CLASS_ALLOCATOR(MultiplayerLobbyLANServiceWrapper, AZ::SystemAllocator, 0);
MultiplayerLobbyLANServiceWrapper(const AZ::EntityId& multiplayerLobbyEntityId);
virtual ~MultiplayerLobbyLANServiceWrapper();
const char* GetLobbyTitle() const { return "LAN Servers"; }
bool SanityCheck(GridMate::IGridMate* gridMate) override;
bool StartSessionService(GridMate::IGridMate* gridMate) override;
void StopSessionService(GridMate::IGridMate* gridMate) override;
protected:
GridMate::GridSession* CreateServerForService(GridMate::IGridMate* gridMate, GridMate::CarrierDesc& carrierDesc) override;
GridMate::GridSearch* ListServersForService(GridMate::IGridMate* gridMate) override;
GridMate::GridSession* JoinSessionForService(GridMate::IGridMate* gridMate, GridMate::CarrierDesc& carrierDesc, const GridMate::SearchInfo* searchInfo) override;
private:
int GetServerPort() const;
};
}
#endif
@@ -0,0 +1,62 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#ifndef GEMS_MULTIPLAYER_MULTIPLAYERLOBBYSERVICEWRAPPER_MULTIPLAYERLOBBYSERVICEWRAPPER_H
#define GEMS_MULTIPLAYER_MULTIPLAYERLOBBYSERVICEWRAPPER_MULTIPLAYERLOBBYSERVICEWRAPPER_H
#include <AzCore/Memory/SystemAllocator.h>
#include <GridMate/GridMate.h>
#include "Multiplayer/MultiplayerLobbyBus.h"
namespace Multiplayer
{
class MultiplayerLobbyServiceWrapper
{
public:
AZ_CLASS_ALLOCATOR(MultiplayerLobbyServiceWrapper, AZ::SystemAllocator, 0);
protected:
MultiplayerLobbyServiceWrapper(const AZ::EntityId& multiplayerLobbyEntityId);
public:
virtual ~MultiplayerLobbyServiceWrapper();
// MultiplayerLobbyServiceWrapper
virtual const char* GetLobbyTitle() const = 0;
virtual bool SanityCheck(GridMate::IGridMate* gridMate) = 0;
virtual bool StartSessionService(GridMate::IGridMate* gridMate) = 0;
virtual void StopSessionService(GridMate::IGridMate* gridMate) = 0;
virtual GridMate::GridSession* CreateServer(GridMate::IGridMate* gridMate, GridMate::CarrierDesc& carrierDesc);
virtual GridMate::GridSearch* ListServers(GridMate::IGridMate* gridMate);
virtual GridMate::GridSession* JoinSession(GridMate::IGridMate* gridMate, GridMate::CarrierDesc& carrierDesc, const GridMate::SearchInfo* searchInfo);
protected:
const AZ::EntityId& GetTargetEntityId() const
{
return m_multiplayerLobbyEntityId;
}
virtual GridMate::GridSession* CreateServerForService(GridMate::IGridMate* gridMate, GridMate::CarrierDesc& carrierDesc) = 0;
virtual GridMate::GridSearch* ListServersForService(GridMate::IGridMate* gridMate) = 0;
virtual GridMate::GridSession* JoinSessionForService(GridMate::IGridMate* gridMate, GridMate::CarrierDesc& carrierDesc, const GridMate::SearchInfo* searchInfo) = 0;
private:
AZ::EntityId m_multiplayerLobbyEntityId;
};
}
#endif
@@ -0,0 +1,259 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#ifndef GEM_MULTIPLAYER_MULTIPLAYERUTILS_H
#define GEM_MULTIPLAYER_MULTIPLAYERUTILS_H
#include <AzCore/std/string/string.h>
#include <GridMate/GridMate.h>
#include <GridMate/Session/Session.h>
#include <GridMate/Session/LANSession.h>
#include <GridMate/Carrier/Driver.h>
namespace Platform
{
void InitCarrierDesc(GridMate::CarrierDesc& carrierDesc);
}
#pragma push_macro("max") // files included through gridmate undef max, which causes later compile issues for modules that have std:max in their header
#ifdef NET_SUPPORT_SECURE_SOCKET_DRIVER
# include <GridMate/Carrier/SecureSocketDriver.h>
#endif
#pragma pop_macro("max") // restore previous disabling of max
#include <Multiplayer/IMultiplayerGem.h>
#include <CertificateManager/ICertificateManagerGem.h>
namespace Multiplayer
{
struct Utils
{
static GridMate::Driver::BSDSocketFamilyType CVarToFamilyType(const char* str)
{
AZ_Assert(str, "Invalid value");
if (!azstricmp(str, "IPv4"))
{
return GridMate::Driver::BSD_AF_INET;
}
else if (!azstricmp(str, "IPv6"))
{
return GridMate::Driver::BSD_AF_INET6;
}
else
{
AZ_Warning("GridMate", false, "Invalid value '%s' for ip version", str);
return GridMate::Driver::BSD_AF_INET;
}
}
static void InitCarrierDesc(GridMate::CarrierDesc& carrierDesc)
{
if (!carrierDesc.m_simulator)
{
EBUS_EVENT_RESULT(carrierDesc.m_simulator,Multiplayer::MultiplayerRequestBus,GetSimulator);
}
carrierDesc.m_port = gEnv->pConsole->GetCVar("cl_clientport")->GetIVal();
carrierDesc.m_connectionTimeoutMS = 10000;
carrierDesc.m_threadUpdateTimeMS = 30;
carrierDesc.m_threadInstantResponse = true;
carrierDesc.m_driverIsCrossPlatform = true;
carrierDesc.m_securityData = gEnv->pConsole->GetCVar("gm_securityData")->GetString();
carrierDesc.m_familyType = CVarToFamilyType(gEnv->pConsole->GetCVar("gm_ipversion")->GetString());
carrierDesc.m_version = gEnv->pConsole->GetCVar("gm_version")->GetIVal();
ApplyDisconnectDetectionSettings(carrierDesc);
Platform::InitCarrierDesc(carrierDesc);
}
static void ApplyDisconnectDetectionSettings(GridMate::CarrierDesc& carrierDesc)
{
carrierDesc.m_enableDisconnectDetection = !!gEnv->pConsole->GetCVar("gm_disconnectDetection")->GetIVal();
if (gEnv->pConsole->GetCVar("gm_disconnectDetectionRttThreshold"))
{
carrierDesc.m_disconnectDetectionRttThreshold = gEnv->pConsole->GetCVar("gm_disconnectDetectionRttThreshold")->GetFVal();
}
if (gEnv->pConsole->GetCVar("gm_disconnectDetectionPacketLossThreshold"))
{
carrierDesc.m_disconnectDetectionPacketLossThreshold = gEnv->pConsole->GetCVar("gm_disconnectDetectionPacketLossThreshold")->GetFVal();
}
}
// Synchronize session state and load map if sv_map is passed via parameters
static void SynchronizeSessionState(const GridMate::GridSession* session)
{
if (session && session->IsHost())
{
AZStd::string mapName;
// Push any session parameters we may have received back to any matching CVars.
for (unsigned int i = 0; i < session->GetNumParams(); ++i)
{
if (strcmp(session->GetParam(i).m_id.c_str(),"sv_map") == 0)
{
mapName = session->GetParam(i).m_value.c_str();
}
else
{
ICVar* var = gEnv->pConsole->GetCVar(session->GetParam(i).m_id.c_str());
if (var)
{
var->Set(session->GetParam(i).m_value.c_str());
}
else
{
CryLogAlways("Unable to bind session property '%s:%s' to CVar. CVar does not exist.", session->GetParam(i).m_id.c_str(), session->GetParam(i).m_value.c_str());
}
}
}
if (!mapName.empty())
{
// If we have an actual level to load, load it.
AZStd::string loadCommand = "map ";
loadCommand += mapName;
gEnv->pConsole->ExecuteString(loadCommand.c_str(), false, true);
}
}
}
};
struct LAN
{
static void StartSessionService(GridMate::IGridMate* gridMate)
{
if (!GridMate::HasGridMateService<GridMate::LANSessionService>(gridMate))
{
GridMate::StartGridMateService<GridMate::LANSessionService>(gridMate, GridMate::SessionServiceDesc());
}
}
static void StopSessionService(GridMate::IGridMate* gridMate)
{
GridMate::StopGridMateService<GridMate::LANSessionService>(gridMate);
}
};
struct NetSec
{
friend class MultiplayerCVars;
friend class MultiplayerModule;
static bool CanCreateSecureSocketForHosting()
{
bool hasPublicKey = false;
bool hasPrivateKey = false;
EBUS_EVENT_RESULT(hasPublicKey,CertificateManager::CertificateManagerRequestsBus,HasPublicKey);
EBUS_EVENT_RESULT(hasPrivateKey,CertificateManager::CertificateManagerRequestsBus,HasPrivateKey);
return hasPublicKey && hasPrivateKey;
}
static bool CanCreateSecureSocketForJoining()
{
bool hasCertificateAuthority = false;
EBUS_EVENT_RESULT(hasCertificateAuthority,CertificateManager::CertificateManagerRequestsBus,HasCertificateAuthority);
return hasCertificateAuthority;
}
static void ConfigureCarrierDescForHost([[maybe_unused]] GridMate::CarrierDesc& carrierDesc)
{
bool netSecEnabled = false;
EBUS_EVENT_RESULT(netSecEnabled, Multiplayer::MultiplayerRequestBus,IsNetSecEnabled);
if (netSecEnabled)
{
#if defined(NET_SUPPORT_SECURE_SOCKET_DRIVER)
if (CanCreateSecureSocketForHosting())
{
GridMate::SecureSocketDesc desc;
EBUS_EVENT_RESULT(desc.m_privateKeyPEM,CertificateManager::CertificateManagerRequestsBus,RetrievePrivateKey);
EBUS_EVENT_RESULT(desc.m_certificatePEM,CertificateManager::CertificateManagerRequestsBus,RetrievePublicKey);
bool verifyClient = false;
EBUS_EVENT_RESULT(verifyClient,Multiplayer::MultiplayerRequestBus,IsNetSecVerifyClient);
desc.m_authenticateClient = verifyClient;
GridMate::SecureSocketDriver* secureDriver = aznew GridMate::SecureSocketDriver(desc);
EBUS_EVENT(Multiplayer::MultiplayerRequestBus,RegisterSecureDriver,secureDriver);
carrierDesc.m_driver = secureDriver;
}
else
{
CryLog("Unable to use a secure connection because of missing certificate or private key.");
}
#endif
}
}
static void ConfigureCarrierDescForJoin([[maybe_unused]] GridMate::CarrierDesc& carrierDesc)
{
bool netSecEnabled = false;
EBUS_EVENT_RESULT(netSecEnabled, Multiplayer::MultiplayerRequestBus,IsNetSecEnabled);
if (netSecEnabled)
{
#if defined(NET_SUPPORT_SECURE_SOCKET_DRIVER)
GridMate::SecureSocketDesc desc;
if (CanCreateSecureSocketForJoining())
{
EBUS_EVENT_RESULT(desc.m_certificateAuthorityPEM ,CertificateManager::CertificateManagerRequestsBus,RetrieveCertificateAuthority);
GridMate::SecureSocketDriver* secureDriver = aznew GridMate::SecureSocketDriver(desc);
EBUS_EVENT(Multiplayer::MultiplayerRequestBus,RegisterSecureDriver,secureDriver);
carrierDesc.m_driver = secureDriver;
}
else
{
CryLog("Unable to use a secure connection because of missing certificate or private key.");
}
#endif
}
}
static void OnSessionFailedToCreate([[maybe_unused]] GridMate::CarrierDesc& carrierDesc)
{
bool netSecEnabled = false;
EBUS_EVENT_RESULT(netSecEnabled, Multiplayer::MultiplayerRequestBus,IsNetSecEnabled);
if (netSecEnabled)
{
#if defined(NET_SUPPORT_SECURE_SOCKET_DRIVER)
// Clean up unused secure socket driver.
delete carrierDesc.m_driver;
carrierDesc.m_driver = nullptr;
EBUS_EVENT(Multiplayer::MultiplayerRequestBus,RegisterSecureDriver, nullptr);
#endif
}
}
private:
static int s_NetsecEnabled;
static int s_NetsecVerifyClient;
};
}
#endif