Documentation for the Unreal C++ Library
Loading...
Searching...
No Matches
PVROMultiplayerModule.cpp
Go to the documentation of this file.
1// Copyright(c) 2023 PixoVR, LLC. All Rights Reserved.
2
4#include "CoreMinimal.h"
5#include "Modules/ModuleManager.h"
6#include "Developer/Settings/Public/ISettingsModule.h"
7#include "OnlineSubsystemModule.h"
8#include "OnlineSubsystemNames.h"
9#include "OnlineSubsystem.h"
10#include "PVROSubsystem.h"
11
12#define LOCTEXT_NAMESPACE "PixoVRMultiplayer"
13
15
16DEFINE_LOG_CATEGORY_STATIC(LogPixoVRMultiplayer, Log, All);
17
18#define Log(pmt, ...) UE_LOG(LogPixoVRMultiplayer, Log, TEXT(pmt), ##__VA_ARGS__)
19#define Warn(pmt, ...) UE_LOG(LogPixoVRMultiplayer, Warning, TEXT(pmt), ##__VA_ARGS__)
20#define Error(pmt, ...) UE_LOG(LogPixoVRMultiplayer, Error, TEXT(pmt), ##__VA_ARGS__)
21#define Fatal(pmt, ...) UE_LOG(LogPixoVRMultiplayer, Fatal, TEXT(pmt), ##__VA_ARGS__)
22
27{
28public:
29
32
33 virtual IOnlineSubsystemPtr CreateSubsystem(FName InstanceName)
34 {
35 FPVROSubsystemPtr OnlineSub = MakeShared<FPVROSubsystem, ESPMode::ThreadSafe>(InstanceName);
36 if (OnlineSub->IsEnabled())
37 {
38 if(!OnlineSub->Init())
39 {
40 Warn("PixoVR API failed to initialize!");
41 OnlineSub->Shutdown();
42 OnlineSub = nullptr;
43 }
44 }
45 else
46 {
47 Warn("PixoVR API disabled!");
48 OnlineSub->Shutdown();
49 OnlineSub = nullptr;
50 }
51
52 return OnlineSub;
53 }
54};
55
57{
58 Log("Starting up PixoVR Multiplayer Module.");
60
61 // Create and register our singleton factory with the main online subsystem for easy access
62 FOnlineSubsystemModule& OSS = FModuleManager::GetModuleChecked<FOnlineSubsystemModule>("OnlineSubsystem");
63 OSS.RegisterPlatformService(PVR_MP_SUBSYSTEM, Factory);
64
65 if (!FModuleManager::Get().IsModuleLoaded("WebSockets"))
66 {
67 Log("WebSockets module was not loaded. Loading now.");
68 FModuleManager::Get().LoadModule("WebSockets");
69 }
70
71 if (!FModuleManager::Get().IsModuleLoaded("Agones"))
72 {
73 Log("Agones module was not loaded. Loading now.");
74 FModuleManager::Get().LoadModule("Agones");
75 }
76
77 if (!FModuleManager::Get().IsModuleLoaded("OnlineSubsystem"))
78 {
79 Log("OnlineSubsystem module was not loaded. Loading now.");
80 FModuleManager::Get().LoadModule("OnlineSubsystem");
81 }
82
83 if (!FModuleManager::Get().IsModuleLoaded("OnlineSubsystemUtils"))
84 {
85 Log("OnlineSubsystemUtils module was not loaded. Loading now.");
86 FModuleManager::Get().LoadModule("OnlineSubsystemUtils");
87 }
88
89 TArray<FName> ExistingOnlineSubsystemModules;
90 FModuleManager::Get().FindModules(TEXT("OnlineSubsystem*"), ExistingOnlineSubsystemModules);
91
92 if (ExistingOnlineSubsystemModules.Num() > 2)
93 {
94 ExistingOnlineSubsystemModules.Remove("OnlineSubsystem");
95 ExistingOnlineSubsystemModules.Remove("OnlineSubsystemUtils");
96 FString OnlineSubsystemModuleString;
97 for (int ModuleIndex = 0; ModuleIndex < ExistingOnlineSubsystemModules.Num(); ModuleIndex++)
98 {
99 OnlineSubsystemModuleString += ExistingOnlineSubsystemModules[ModuleIndex].ToString() + ", ";
100 }
101 Error("There are additional Online Subsystems plugins that are enabled. Disable those plugins before using the PixoVR Multiplayer plugin.\n%s", *OnlineSubsystemModuleString);
102 }
103}
104
106{
107 FOnlineSubsystemModule& OSS = FModuleManager::GetModuleChecked<FOnlineSubsystemModule>("OnlineSubsystem");
108 OSS.UnregisterPlatformService(PVR_MP_SUBSYSTEM);
109
110 delete Factory;
111 Factory = NULL;
112}
113
114#undef Fatal
115#undef Error
116#undef Warn
117#undef Log
118
119#undef LOCTEXT_NAMESPACE
#define Error(pmt,...)
#define Log(pmt,...)
#define Warn(pmt,...)
DEFINE_LOG_CATEGORY_STATIC(LogPixoVRMultiplayer, Log, All)
IMPLEMENT_MODULE(FPVROMultiplayerModule, PixoVRMultiplayer)
#define Log(pmt,...)
#define PVR_MP_SUBSYSTEM
TSharedPtr< FPVROSubsystem, ESPMode::ThreadSafe > FPVROSubsystemPtr
virtual IOnlineSubsystemPtr CreateSubsystem(FName InstanceName)
virtual void ShutdownModule() override
FPVROMultiplayerFactory * Factory
virtual void StartupModule() override