// .h
void LoginWithEpicAccountServices(const EOS_ELoginCredentialType Type, TFunction<void()> OnSuccess, TFunction<void()> OnFailure);
char* GetExchangeCodeFromCommandLine();
// .cpp
void UEOSManager::LoginWithEpicAccountServices(const EOS_ELoginCredentialType Type, TFunction<void()> OnSuccess, TFunction<void()> OnFailure)
{
if (!this->EosPlatform)
{
UE_LOG(LogTemp, Error, TEXT("Failed to login. EOS Platform is null, please Initialize."));
OnFailure();
return;
}
this->EosAuth = EOS_Platform_GetAuthInterface(this->EosPlatform);
EOS_Auth_Credentials Credentials = {};
Credentials.ApiVersion = EOS_AUTH_CREDENTIALS_API_LATEST;
Credentials.Type = Type;
Credentials.Token = GetExchangeCodeFromCommandLine();
EOS_Auth_LoginOptions LoginOptions = {};
LoginOptions.ApiVersion = EOS_AUTH_LOGIN_API_LATEST;
LoginOptions.Credentials = &Credentials;
LoginOptions.ScopeFlags = EOS_EAuthScopeFlags::EOS_AS_NoFlags;
FEosLoginContext* ClientData = new FEosLoginContext;
ClientData->Self = this;
ClientData->OnSuccess = [OnSuccess]() { OnSuccess(); };
ClientData->OnFailure = [OnFailure]() { OnFailure(); };
EOS_Auth_Login(this->EosAuth, &LoginOptions, ClientData,[](const EOS_Auth_LoginCallbackInfo* Data)
{
const FEosLoginContext* Context = static_cast<FEosLoginContext*>(Data->ClientData);
if (Data->ResultCode == EOS_EResult::EOS_Success)
{
const EOS_EpicAccountId EpicId = Data->LocalUserId;
Context->Self->EpicAccountId = EpicId;
Context->OnSuccess();
}
else
{
UE_LOG(LogTemp, Error, TEXT("Epic Account login failed: %s"), *FString(EOS_EResult_ToString(Data->ResultCode)));
Context->OnFailure();
}
});
}
char* UEOSManager::GetExchangeCodeFromCommandLine()
{
FString AuthPassword;
if (FParse::Value(FCommandLine::Get(), TEXT("AUTH_PASSWORD="), AuthPassword))
{
UE_LOG(LogTemp, Log, TEXT("ExchangeCode: %s"), *AuthPassword);
return StringToChars(AuthPassword);
}
UE_LOG(LogTemp, Warning, TEXT("AUTH_PASSWORD parameter not found!"));
return const_cast<char*>("");
}