1
0
This commit is contained in:
2020-12-13 18:01:13 +03:00
commit dd42f84140
3764 changed files with 596895 additions and 0 deletions

View File

@ -0,0 +1,179 @@
/**
* Copyright 1998-2013 Epic Games, Inc. All Rights Reserved.
*
* This is the base class for Facebook integration (each platform has a subclass
*/
class FacebookWindows extends FacebookIntegration
native
config(Engine)
inherits(FTickableObject)
;
`include(Engine\Classes\HttpStatusCodes.uci)
var const native private{private} transient pointer ChildProcHandle{void};
native function bool Init();
native function bool Authorize();
native function bool IsAuthorized();
native function Disconnect();
function FacebookRequest(string GraphRequest)
{
class'HttpFactory'.static.CreateRequest()
.SetURL("https://graph.facebook.com/"@GraphRequest@"?access_token="$AccessToken)
.SetVerb("GET")
.SetProcessRequestCompleteDelegate(FacebookRequestCallback)
.ProcessRequest();
}
native function ProcessFacebookRequest(string Payload, INT ResponseCode);
/** Delegate to use for Facebook requests. */
function FacebookRequestCallback(HttpRequestInterface OriginalRequest, HttpResponseInterface Response, bool bDidSucceed)
{
local string Payload;
if (bDidSucceed)
{
Payload = Response.GetContentAsString();
}
ProcessFacebookRequest(Payload, bDidSucceed ? Response.GetResponseCode() : `HTTP_STATUS_BAD_REQUEST);
}
private event RequestFacebookMeInfo()
{
Username = "";
UserId = "";
class'HttpFactory'.static.CreateRequest()
.SetURL("https://graph.facebook.com/me?access_token="$AccessToken)
.SetHeader("Content-Type", "application/json")
.SetVerb("GET")
.SetProcessRequestCompleteDelegate(OnFacebookMeRequestComplete)
.ProcessRequest();
}
private function OnFacebookMeRequestComplete(HttpRequestInterface OriginalRequest, HttpResponseInterface Response, bool bDidSucceed)
{
local string JsonPayload;
local JsonObject ParsedJson;
local PlatformInterfaceDelegateResult DelegateResult;
if (bDidSucceed &&
Response.GetResponseCode() == `HTTP_STATUS_OK)
{
JsonPayload = Response.GetContentAsString();
`log(`location@""
$"JsonPayload="$JsonPayload);
if (Len(JsonPayload) > 0)
{
DelegateResult.bSuccessful = true;
ParsedJson = class'JsonObject'.static.DecodeJson(JsonPayload);
if (ParsedJson != None)
{
Username = ParsedJson.GetStringValue("name");
UserId = ParsedJson.GetStringValue("id");
}
else
{
`log(`location@"Failed to parse JSON");
}
}
else
{
`log(`location@"JSON payload is empty");
}
CallDelegates(FID_AuthorizationComplete,DelegateResult);
// kick off request to get FB friends
RequestFacebookFriends();
}
else
{
`log(`location@"Failed to get valid response: "
$" code="$Response.GetResponseCode());
DelegateResult.bSuccessful = false;
DelegateResult.Data.Type = PIDT_String;
DelegateResult.Data.StringValue = "Failed to request user id and name";
CallDelegates(FID_AuthorizationComplete,DelegateResult);
}
}
private event RequestFacebookFriends()
{
FriendsList.Length = 0;
class'HttpFactory'.static.CreateRequest()
.SetURL("https://graph.facebook.com/me/friends?access_token="$AccessToken)
.SetHeader("Content-Type", "application/json")
.SetVerb("GET")
.SetProcessRequestCompleteDelegate(OnFacebookFriendsRequestComplete)
.ProcessRequest();
}
private function OnFacebookFriendsRequestComplete(HttpRequestInterface OriginalRequest, HttpResponseInterface Response, bool bDidSucceed)
{
local string JsonPayload;
local JsonObject ParsedJson,FriendsJson;
local int JsonIndex;
local PlatformInterfaceDelegateResult DelegateResult;
local FacebookFriend Friend;
if (bDidSucceed &&
Response.GetResponseCode() == `HTTP_STATUS_OK)
{
JsonPayload = Response.GetContentAsString();
`log(`location@""
$"JsonPayload="$JsonPayload);
if (Len(JsonPayload) > 0)
{
ParsedJson = class'JsonObject'.static.DecodeJson(JsonPayload);
if (ParsedJson != None)
{
FriendsJson = ParsedJson.GetObject("data");
if (FriendsJson != None)
{
DelegateResult.bSuccessful = true;
for (JsonIndex=0; JsonIndex < FriendsJson.ObjectArray.Length; JsonIndex++)
{
Friend.Name = FriendsJson.ObjectArray[JsonIndex].GetStringValue("name");
Friend.Id = FriendsJson.ObjectArray[JsonIndex].GetStringValue("id");
FriendsList.AddItem(Friend);
}
}
else
{
`log(`location@"Missing data entry in JSON");
}
}
else
{
`log(`location@"Failed to parse JSON");
}
}
else
{
`log(`location@"JSON payload is empty");
}
CallDelegates(FID_FriendsListComplete,DelegateResult);
}
else
{
`log(`location@"Failed to get valid response: "
$" code="$Response.GetResponseCode());
DelegateResult.bSuccessful = false;
DelegateResult.Data.Type = PIDT_String;
DelegateResult.Data.StringValue = "Failed to request friends list";
CallDelegates(FID_FriendsListComplete,DelegateResult);
}
}

View File

@ -0,0 +1,28 @@
/**
* Default Windows implementation for HttpRequest.
* See HttpRequestInterface for documentation details.
*
* Copyright 1998-2013 Epic Games, Inc. All Rights Reserved.
*/
class HttpRequestWindows extends HttpRequestInterface
native;
var private {private} const native transient pointer Request{class FHttpRequestWinInet};
var private {private} const native string RequestVerb;
var private {private} const native transient pointer RequestURL{class FURLWinInet};
var private {private} const native array<byte> Payload;
native function String GetHeader(String HeaderName);
native function array<String> GetHeaders();
native function String GetURLParameter(String ParameterName);
native function String GetContentType();
native function int GetContentLength();
native function String GetURL();
native function GetContent(out array<byte> Content);
native function String GetVerb();
native function HttpRequestInterface SetVerb(String Verb);
native function HttpRequestInterface SetURL(String URL);
native function HttpRequestInterface SetContent(const out array<byte> ContentPayload);
native function HttpRequestInterface SetContentAsString(String ContentString);
native function HttpRequestInterface SetHeader(String HeaderName, String HeaderValue);
native function bool ProcessRequest();

View File

@ -0,0 +1,41 @@
/**
* MCP specific HTTP request implementation
*
* Copyright 1998-2013 Epic Games, Inc. All Rights Reserved.
*/
class HttpRequestWindowsMcp extends HttpRequestWindows
config(Engine);
/** The app id value to append to the URL */
var const config string AppID;
/** The app secret value to append to the URL */
var const config string AppSecret;
/** Automatically appends the specified app id and app secret values to the URL if going to MCP */
function bool ProcessRequest()
{
local string Url;
Url = GetURL();
if (InStr(Url, "appspot.com") != INDEX_NONE ||
InStr(Url, "localhost:8888") != INDEX_NONE)
{
// Append the app id and secret value to the URL
if (InStr(Url, "?") != INDEX_NONE)
{
Url $= "&appKey=" $ AppID;
}
else
{
Url $= "?appKey=" $ AppID;
}
Url $= "&appSecret=" $ AppSecret;
SetURL(Url);
}
return Super.ProcessRequest();
}
defaultproperties
{
}

View File

@ -0,0 +1,21 @@
/**
* Default Windows implementation for HttpResponse.
* See HttpResponseInterface for documentation details.
*
* Copyright 1998-2013 Epic Games, Inc. All Rights Reserved.
*/
class HttpResponseWindows extends HttpResponseInterface
native;
var private {private} const native transient pointer Response{class FHttpResponseWinInet};
var private {private} const native array<byte> Payload;
native function String GetHeader(String HeaderName);
native function array<String> GetHeaders();
native function String GetURLParameter(String ParameterName);
native function String GetContentType();
native function int GetContentLength();
native function String GetURL();
native function GetContent(out array<byte> Content);
native function String GetContentAsString();
native function int GetResponseCode();