4#include "Misc/CommandLine.h"
6#include "Misc/OutputDeviceRedirector.h"
9#include "SocketSubsystem.h"
10#include "OnlineError.h"
16#define Log(pmt, ...) UE_LOG(LogPVROMultiplayerIdentity, Log, TEXT(pmt), ##__VA_ARGS__)
17#define Warn(pmt, ...) UE_LOG(LogPVROMultiplayerIdentity, Warning, TEXT(pmt), ##__VA_ARGS__)
18#define Error(pmt, ...) UE_LOG(LogPVROMultiplayerIdentity, Error, TEXT(pmt), ##__VA_ARGS__)
19#define Fatal(pmt, ...) UE_LOG(LogPVROMultiplayerIdentity, Fatal, TEXT(pmt), ##__VA_ARGS__)
24 if (FoundAttr !=
nullptr)
26 OutAttrValue = *FoundAttr;
35 if (FoundAttr !=
nullptr)
37 OutAttrValue = *FoundAttr;
46 if (FoundAttr ==
nullptr || *FoundAttr != AttrValue)
57 if (!ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->GetHostName(HostName))
61 TSharedPtr<class FInternetAddr> Addr = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->GetLocalHostAddr(*GLog, bCanBindAll);
62 HostName = Addr->ToString(
false);
67 FString UserId = FString::Printf( TEXT(
"%s-%s" ), *HostName, *FPlatformMisc::GetLoginId().ToUpper() );
68 if(!FParse::Value(FCommandLine::Get(), TEXT(
"-PVRMP_SERVER_NAME="), UserId))
71 if(GConfig && !GConfig->GetString(TEXT(
"PixoVRMultiplayer"), TEXT(
"ServerName"), UserId, GEngineIni))
73 UserId =
"PVROServer";
83 return FString::Printf( TEXT(
"%s-%s" ), *HostName, *FGuid::NewGuid().ToString() );
89 TSharedPtr<FPVROUserAccount> UserAccountPtr;
92 if (LocalUserNum < 0 || LocalUserNum >= MAX_LOCAL_PLAYERS)
94 ErrorStr = FString::Printf(TEXT(
"Invalid LocalUserNum=%d"), LocalUserNum);
96 else if (AccountCredentials.Id.IsEmpty())
98 ErrorStr = TEXT(
"Invalid account id, string empty");
103 if (UserId ==
nullptr)
108 UserAccountPtr->UserAttributes.Add(USER_ATTR_ID, RandomUserId);
110#if ENGINE_MAJOR_VERSION >= 5
111 FUniqueNetIdPixoVRRef NewUserIdRef = FUniqueNetIdPixoVR::Create(RandomUserId);
112 UserAccounts.Add(*NewUserIdRef, UserAccountPtr.ToSharedRef());
114 FUniqueNetIdPixoVR NewUserId(RandomUserId);
115 UserAccounts.Add(NewUserId, UserAccountPtr.ToSharedRef());
118 UserIds.Add(LocalUserNum, UserAccountPtr->GetUserId());
122 const FUniqueNetIdPixoVR* UniqueIdStr = (FUniqueNetIdPixoVR*)(UserId->Get());
123 TSharedRef<FPVROUserAccount>* TempPtr =
UserAccounts.Find(*UniqueIdStr);
125 UserAccountPtr = *TempPtr;
129 if (!ErrorStr.IsEmpty())
131 Warn(
"Login request failed. %s", *ErrorStr);
132#if ENGINE_MAJOR_VERSION >= 5
133 TriggerOnLoginCompleteDelegates(LocalUserNum,
false, FUniqueNetIdPixoVR::EmptyId().Get(), ErrorStr);
135 TriggerOnLoginCompleteDelegates(LocalUserNum,
false, FUniqueNetIdPixoVR(), ErrorStr);
140 TriggerOnLoginCompleteDelegates(LocalUserNum,
true, UserAccountPtr->GetUserId().Get(), ErrorStr);
147 if (UserIdPtr.IsValid())
150#if ENGINE_MAJOR_VERSION >= 5
151 UserAccounts.Remove(FUniqueNetIdPixoVR::Cast(*UserIdPtr));
158 TriggerOnLogoutCompleteDelegates(LocalUserNum,
true);
164 Warn(
"No logged in user found for LocalUserNum=%d.", LocalUserNum);
165 TriggerOnLogoutCompleteDelegates(LocalUserNum,
false);
176 FParse::Value(FCommandLine::Get(), TEXT(
"AUTH_LOGIN="), LoginStr);
177 FParse::Value(FCommandLine::Get(), TEXT(
"AUTH_PASSWORD="), PasswordStr);
178 FParse::Value(FCommandLine::Get(), TEXT(
"AUTH_TYPE="), TypeStr);
180 bool bEnableWarning = LoginStr.Len() > 0 || PasswordStr.Len() > 0 || TypeStr.Len() > 0;
182 if (!LoginStr.IsEmpty())
184 if (!PasswordStr.IsEmpty())
186 if (!TypeStr.IsEmpty())
188 return Login(0, FOnlineAccountCredentials(TypeStr, LoginStr, PasswordStr));
190 else if (bEnableWarning)
192 Warn(
"AutoLogin missing AUTH_TYPE=<type>.");
195 else if (bEnableWarning)
197 Warn(
"AutoLogin missing AUTH_PASSWORD=<password>.");
200 else if (bEnableWarning)
202 Warn(
"AutoLogin missing AUTH_LOGIN=<login id>.");
210 TSharedPtr<FUserOnlineAccount> Result;
212#if ENGINE_MAJOR_VERSION >= 5
213 FUniqueNetIdPixoVR StringUserId = FUniqueNetIdPixoVR::Cast(UserId);
215 FUniqueNetIdPixoVR StringUserId(UserId);
217 const TSharedRef<FPVROUserAccount>* FoundUserAccount =
UserAccounts.Find(StringUserId);
218 if (FoundUserAccount !=
nullptr)
220 Result = *FoundUserAccount;
228 TArray<TSharedPtr<FUserOnlineAccount> > Result;
230 for (TMap<FUniqueNetIdPixoVR, TSharedRef<FPVROUserAccount>>::TConstIterator It(
UserAccounts); It; ++It)
232 Result.Add(It.Value());
241 if (FoundId !=
nullptr)
250 if (Bytes !=
nullptr && Size > 0)
252 FString StrId(Size, (TCHAR*)Bytes);
253#if ENGINE_MAJOR_VERSION >= 5
254 return FUniqueNetIdPixoVR::Create(StrId);
256 return MakeShareable(
new FUniqueNetIdPixoVR(StrId));
265#if ENGINE_MAJOR_VERSION >= 5
266 return FUniqueNetIdPixoVR::Create(Str);
268 return MakeShareable(
new FUniqueNetIdPixoVR(Str));
275 if (UserId.IsValid())
279 return ELoginStatus::NotLoggedIn;
284 TSharedPtr<FUserOnlineAccount> UserAccount =
GetUserAccount(UserId);
285 if (UserAccount.IsValid() &&
286 UserAccount->GetUserId()->IsValid())
288 return ELoginStatus::LoggedIn;
290 return ELoginStatus::NotLoggedIn;
296 if (UniqueId.IsValid())
298 return UniqueId->ToString();
301 return TEXT(
"PixoVRUser");
306 return UserId.ToString();
312 if (UniqueId.IsValid())
320 const FUniqueNetIdPixoVR* UniqueIdStr = (FUniqueNetIdPixoVR*)(&UserId);
321 TSharedRef<FPVROUserAccount>* UserAccountPtr =
UserAccounts.Find(*UniqueIdStr);
324 UserAccountPtr->Get().UserName = PlayerNickname;
331 if (UserId.IsValid())
333 TSharedPtr<FUserOnlineAccount> UserAccount =
GetUserAccount(*UserId);
334 if (UserAccount.IsValid())
336 return UserAccount->GetAccessToken();
344 Log(
"FPVROIdentity::RevokeAuthToken not implemented");
348 : Subsystem(InSubsystem)
351 Login(0, FOnlineAccountCredentials(TEXT(
"PVROGenericPlayer"), TEXT(
"PVROGenericUser"), TEXT(
"PVROGenericId")) );
360 Delegate.ExecuteIfBound(UserId, Privilege, (uint32)EPrivilegeResults::NoFailures);
365 for (
int LocalPlayerIndex = 0; LocalPlayerIndex < MAX_LOCAL_PLAYERS; ++LocalPlayerIndex)
368 if (CurrentUniqueId.IsValid() && (*CurrentUniqueId == UniqueNetId))
370#if ENGINE_MAJOR_VERSION >= 5
371 return GetPlatformUserIdFromLocalUserNum(LocalPlayerIndex);
373 return LocalPlayerIndex;
378 return PLATFORMUSERID_NONE;
DEFINE_LOG_CATEGORY_STATIC(LogPVROMultiplayerIdentity, Log, All)
FString GenerateRandomUserId(int32 LocalUserNum)
TSharedPtr< const FUniqueNetId > FUniqueNetIdPtr
virtual void SetPlayerNickname(int32 LocalUserNum, const FString PlayerNickname)
virtual ELoginStatus::Type GetLoginStatus(int32 LocalUserNum) const override
virtual FString GetPlayerNickname(int32 LocalUserNum) const override
virtual FUniqueNetIdPtr CreateUniquePlayerId(uint8 *Bytes, int32 Size) override
TMap< int32, FUniqueNetIdPtr > UserIds
virtual FString GetAuthToken(int32 LocalUserNum) const override
virtual bool Logout(int32 LocalUserNum) override
virtual bool AutoLogin(int32 LocalUserNum) override
virtual FPlatformUserId GetPlatformUserIdFromUniqueNetId(const FUniqueNetId &UniqueNetId) const override
virtual void GetUserPrivilege(const FUniqueNetId &UserId, EUserPrivileges::Type Privilege, const FOnGetUserPrivilegeCompleteDelegate &Delegate) override
TMap< FUniqueNetIdPixoVR, TSharedRef< FPVROUserAccount > > UserAccounts
virtual FUniqueNetIdPtr GetUniquePlayerId(int32 LocalUserNum) const override
virtual TArray< TSharedPtr< FUserOnlineAccount > > GetAllUserAccounts() const override
virtual FString GetAuthType() const override
virtual TSharedPtr< FUserOnlineAccount > GetUserAccount(const FUniqueNetId &UserId) const override
virtual bool Login(int32 LocalUserNum, const FOnlineAccountCredentials &AccountCredentials) override
virtual void RevokeAuthToken(const FUniqueNetId &UserId, const FOnRevokeAuthTokenCompleteDelegate &Delegate) override
TMap< FString, FString > UserAttributes
virtual bool GetAuthAttribute(const FString &AttrName, FString &OutAttrValue) const override
virtual bool GetUserAttribute(const FString &AttrName, FString &OutAttrValue) const override
TMap< FString, FString > AdditionalAuthData
virtual bool SetUserAttribute(const FString &AttrName, const FString &AttrValue) override