4#include "HAL/RunnableThread.h"
8#include "VoiceInterfaceImpl.h"
10#include "Misc/CommandLine.h"
14#define Verbose(pmt, ...) UE_LOG(LogPVROSubSystem, Verbose, TEXT(pmt), ##__VA_ARGS__)
15#define Log(pmt, ...) UE_LOG(LogPVROSubSystem, Log, TEXT(pmt), ##__VA_ARGS__)
16#define Warn(pmt, ...) UE_LOG(LogPVROSubSystem, Warning, TEXT(pmt), ##__VA_ARGS__)
17#define Error(pmt, ...) UE_LOG(LogPVROSubSystem, Error, TEXT(pmt), ##__VA_ARGS__)
18#define Fatal(pmt, ...) UE_LOG(LogPVROSubSystem, Fatal, TEXT(pmt), ##__VA_ARGS__)
155 if (!FOnlineSubsystemImpl::Tick(DeltaTime))
179void static PrintToScreen(int32 Key,
float Time, FColor MessageColor, FString Message)
182 GEngine->AddOnScreenDebugMessage(Key, Time, MessageColor, Message);
188 bool bCouldLoad =
false;
189 FString SubsystemFilePath = FPaths::Combine(FPaths::ProjectPersistentDownloadDir(), TEXT(
"pixo_onlinesubsystem.ini"));
190 Log(
"Trying to parse subsystem file: %s", *SubsystemFilePath);
191 IPlatformFile& FileManager = FPlatformFileManager::Get().GetPlatformFile();
192 if (FileManager.FileExists(*SubsystemFilePath))
194 FString SubsystemConfigContent;
195 if (FFileHelper::LoadFileToString(SubsystemConfigContent, *SubsystemFilePath))
197 Log(
"Successfully loaded file.");
198 if (!SubsystemConfigContent.IsEmpty())
200 TMap<FString, FString> ParsedConfig;
201 bCouldLoad =
ParseConfig(SubsystemConfigContent, ParsedConfig);
204 bool bIgnoreVersion =
false;
205 if (ParsedConfig.Contains(
"ignoreVersion"))
207 bIgnoreVersion = ParsedConfig[
"ignoreVersion"].ToBool();
208 Log(
"%s configuration file version.", bIgnoreVersion ? TEXT(
"Will ignore") : TEXT(
"Will not ignore"));
211 if (ParsedConfig.Contains(
"version") && !bIgnoreVersion)
213 FString ConfigVersion = ParsedConfig[
"version"];
216 Log(
"Versions are different. Not loading config.")
221 if (ParsedConfig.Contains(
"url") && bCouldLoad)
232 Log(
"No multiplayer subsystem config file exists at %s.", *SubsystemFilePath);
240 TArray<FString> ConfigLines;
241 ConfigContent.ParseIntoArrayLines(ConfigLines);
244 if (ConfigLines.Num() < 0)
250 for (
int ConfigIndex = 0; ConfigIndex < ConfigLines.Num(); ConfigIndex++)
252 if (ConfigLines[ConfigIndex].Split(TEXT(
"="), &Key, &Value))
254 ConfigValues.Add(Key.ToLower(), Value);
263 bool bCouldSave =
true;
264 FString SubsystemFilePath = FPaths::Combine(FPaths::ProjectPersistentDownloadDir(), TEXT(
"pixo_onlinesubsystem.ini"));
268 if (!FFileHelper::SaveStringToFile(ConfigContent, *SubsystemFilePath))
271 Warn(
"Failed to save file %s", *SubsystemFilePath);
279 const bool bPixoVRInit =
true;
281 Log(
"Initializing the PVROSubsystem!");
284 FString SubsystemFilePath = FPaths::Combine(FPaths::ProjectPersistentDownloadDir(), TEXT(
"pixo_onlinesubsystem.ini"));
285 IPlatformFile& FileManager = FPlatformFileManager::Get().GetPlatformFile();
287 if (!GConfig->GetString(TEXT(
"/Script/ApexSDK.ApexSDKSettings"), TEXT(
"ModuleVersion"),
ModuleVersion, GEngineIni))
289 int MajorVersion = 0, MinorVersion = 0, PatchVersion = 0;
290 GConfig->GetInt(TEXT(
"/Script/ApexSDK.ApexSDKSettings"), TEXT(
"MajorVerison"), MajorVersion, GEngineIni);
291 GConfig->GetInt(TEXT(
"/Script/ApexSDK.ApexSDKSettings"), TEXT(
"MinorVersion"), MinorVersion, GEngineIni);
292 GConfig->GetInt(TEXT(
"/Script/ApexSDK.ApexSDKSettings"), TEXT(
"PatchVersion"), PatchVersion, GEngineIni);
293 ModuleVersion = FString::Printf(TEXT(
"%i.%.2i.%.2i"), MajorVersion, MinorVersion, PatchVersion);
296 GConfig->GetInt(TEXT(
"/Script/ApexSDK.ApexSDKSettings"), TEXT(
"ModuleId"),
ModuleId, GEngineIni);
300 Log(
"Config failed to load, defaulting to variables in config.");
301 if (!GConfig->GetString(TEXT(
"PixoVRMultiplayer"), TEXT(
"ServerURI"),
MultiplayerURL, GGameIni))
303 Log(
"Could not find configuration value in the game ini, checking engine ini as a back up.");
304 if (!GConfig->GetString(TEXT(
"PixoVRMultiplayer"), TEXT(
"ServerURI"),
MultiplayerURL, GEngineIni))
306 Warn(
"Failed to get the Server URI, falling back to 127.0.0.1.");
315 FString ConnectionString =
"wss://";
318 ConnectionString =
"ws://";
319 Warn(
"This looks to be a normal web socket. Make sure you use this only for testing.");
349 void {
Warn(
"Web socket disconnected %s w/ status code %d for reason %s", bWasClean ?
"cleanly" :
"not cleanly", StatusCode, *Reason); });
372 FOnlineSubsystemImpl::Shutdown();
399#define DESTRUCT_INTERFACE(Interface) \
400 if (Interface.IsValid()) \
402 ensure(Interface.IsUnique()); \
403 Interface = nullptr; \
410#undef DESTRUCT_INTERFACE
422 if (FOnlineSubsystemImpl::Exec(InWorld, Cmd, Ar))
430 return NSLOCTEXT(
"PixoVRMultiplayer",
"OnlineServiceName",
"PixoVR");
458 if (!InUserName.IsEmpty())
463 if (!InModuleVersion.IsEmpty())
471 Error(
"Invalid OrgId or ModuleId used when finding a session.");
478 bool bCanFindSession =
true;
489 return bCanFindSession;
#define DESTRUCT_INTERFACE(Interface)
DEFINE_LOG_CATEGORY_STATIC(LogPVROSubSystem, Log, All)
static FString ServerVersion
virtual bool Init() override
virtual FString GetAppId() const override
virtual IOnlineUserCloudPtr GetUserCloudInterface() const override
virtual IOnlineEventsPtr GetEventsInterface() const override
bool ParseConfig(FString ConfigContent, TMap< FString, FString > &ConfigValues)
class FRunnableThread * TaskThread
virtual IOnlineStatsPtr GetStatsInterface() const override
virtual FText GetOnlineServiceName() const override
virtual IOnlineAchievementsPtr GetAchievementsInterface() const override
bool FindSessions(int InOrgId=-1, int InModuleId=-1, FString InUserName="", FString InModuleVersion="")
void SetModuleInfo(int InModuleId, FString InModuleVersion)
virtual IOnlineEntitlementsPtr GetEntitlementsInterface() const override
virtual IOnlineSessionPtr GetSessionInterface() const override
FPVROnlineSessionPtr SessionInterface
virtual IOnlinePresencePtr GetPresenceInterface() const override
virtual IOnlineUserPtr GetUserInterface() const override
virtual IOnlineSharingPtr GetSharingInterface() const override
virtual IOnlineTurnBasedPtr GetTurnBasedInterface() const override
virtual IOnlineLeaderboardsPtr GetLeaderboardsInterface() const override
virtual IOnlineGroupsPtr GetGroupsInterface() const override
virtual IOnlineFriendsPtr GetFriendsInterface() const override
void QueueAsyncTask(class FOnlineAsyncTask *AsyncTask)
virtual bool Tick(float DeltaTime) override
virtual IOnlineTitleFilePtr GetTitleFileInterface() const override
bool bVoiceInterfaceInitialized
virtual IOnlineMessagePtr GetMessageInterface() const override
virtual IOnlinePartyPtr GetPartyInterface() const override
virtual IOnlineSharedCloudPtr GetSharedCloudInterface() const override
void SetUserInfo(FString InUserName, int InUserOrgId)
MultiplayerWebSocket WebSocket
virtual IOnlineIdentityPtr GetIdentityInterface() const override
virtual IOnlineChatPtr GetChatInterface() const override
virtual bool Exec(class UWorld *InWorld, const TCHAR *Cmd, FOutputDevice &Ar) override
FOnlineVoiceImplPtr VoiceInterface
class FPVROAsyncTaskManager * TaskThreadManager
virtual IOnlineVoicePtr GetVoiceInterface() const override
virtual bool Shutdown() override
virtual IOnlineTimePtr GetTimeInterface() const override
virtual IOnlineTournamentPtr GetTournamentInterface() const override
virtual IOnlineExternalUIPtr GetExternalUIInterface() const override
static FThreadSafeCounter TaskCounter
FPVROIdentityPtr IdentityInterface
FSocketDisconnected & OnWebSocketDisconnected()
FSocketConnected & OnWebSocketConnected()
void RequestMatchMake(int OrgId, int ModuleId)
bool IsWebsocketConnected()
FSocketConnectFailed & OnWebSocketConnectFailed()
bool AttemptConnect(FString Uri, FString Protocol="wss")