initial commit

This commit is contained in:
Jo 2025-01-07 02:06:59 +01:00
parent 6715289efe
commit 788c3389af
37645 changed files with 2526849 additions and 80 deletions

View file

@ -0,0 +1,12 @@
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("Unity.Services.Core.Editor")]
// Test assemblies
#if UNITY_INCLUDE_TESTS
[assembly: InternalsVisibleTo("Unity.Services.Core.Tests")]
[assembly: InternalsVisibleTo("Unity.Services.Core.EditorTests")]
[assembly: InternalsVisibleTo("Unity.Services.Core.TestUtils.Tests")]
[assembly: InternalsVisibleTo("Unity.Services.Core.TestUtils.EditorTests")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
#endif

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 18566762fc26b7949ab81cd5526fd740
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,15 @@
using System;
using Unity.Services.Core.Networking.Internal;
namespace Unity.Services.Core.Networking
{
[Serializable]
struct HttpServiceConfig
{
public string ServiceId;
public string BaseUrl;
public HttpOptions DefaultOptions;
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0958b116e385d7549a65117ca9ed24d5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,3 @@
// This file is generated. Do not modify by hand.
// XML documentation file not found. To check if public methods have XML comments,
// make sure the XML doc file is present and located next to the scraped dll

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 0bc813267d884254f93e1477fe12263b
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,16 @@
{
"name": "Unity.Services.Core.Networking",
"references": [
"Unity.Services.Core",
"Unity.Services.Core.Internal"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": false,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 4fc462806a32aa245a7b28367381bf24
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,130 @@
using System;
using System.Collections.Generic;
using System.IO;
using UnityEngine.Networking;
using Unity.Services.Core.Internal;
using Unity.Services.Core.Networking.Internal;
namespace Unity.Services.Core.Networking
{
class UnityWebRequestClient : IHttpClient
{
/// <summary>
/// Key: The identifier of the service.
/// Value: The configuration of the HTTP client for the service.
/// </summary>
readonly Dictionary<string, HttpServiceConfig> m_ServiceIdToConfig
= new Dictionary<string, HttpServiceConfig>();
/// <inheritdoc/>
public string GetBaseUrlFor(string serviceId)
{
return m_ServiceIdToConfig[serviceId].BaseUrl;
}
/// <inheritdoc/>
public HttpOptions GetDefaultOptionsFor(string serviceId)
{
return m_ServiceIdToConfig[serviceId].DefaultOptions;
}
/// <inheritdoc/>
public HttpRequest CreateRequestForService(string serviceId, string resourcePath)
{
var serviceConfig = m_ServiceIdToConfig[serviceId];
var url = CombinePaths(serviceConfig.BaseUrl, resourcePath);
var request = new HttpRequest()
.SetUrl(url)
.SetOptions(serviceConfig.DefaultOptions);
return request;
}
internal static string CombinePaths(string path1, string path2)
{
//Replace '\' by '/' to unify separators used in the URL and make sure it is compatible with all platforms.
return Path.Combine(path1, path2)
.Replace('\\', '/');
}
/// <inheritdoc/>
public IAsyncOperation<ReadOnlyHttpResponse> Send(HttpRequest request)
{
var operation = new AsyncOperation<ReadOnlyHttpResponse>();
operation.SetInProgress();
try
{
var webRequest = ConvertToWebRequest(request);
webRequest.SendWebRequest()
.completed += OnWebRequestCompleted;
}
catch (Exception reason)
{
operation.Fail(reason);
}
return operation;
void OnWebRequestCompleted(UnityEngine.AsyncOperation unityOperation)
{
var callbackWebRequest = ((UnityWebRequestAsyncOperation)unityOperation).webRequest;
var response = ConvertToResponse(callbackWebRequest)
.SetRequest(request);
var responseHandle = new ReadOnlyHttpResponse(response);
callbackWebRequest.Dispose();
operation.Succeed(responseHandle);
}
}
static UnityWebRequest ConvertToWebRequest(HttpRequest request)
{
var webRequest = new UnityWebRequest(request.Url, request.Method)
{
downloadHandler = new DownloadHandlerBuffer(),
redirectLimit = request.Options.RedirectLimit,
timeout = request.Options.RequestTimeoutInSeconds
};
if (!(request.Body is null)
&& request.Body.Length > 0)
{
webRequest.uploadHandler = new UploadHandlerRaw(request.Body);
}
if (!(request.Headers is null))
{
foreach (var header in request.Headers)
{
webRequest.SetRequestHeader(header.Key, header.Value);
}
}
return webRequest;
}
static HttpResponse ConvertToResponse(UnityWebRequest webRequest)
{
var response = new HttpResponse()
.SetHeaders(webRequest.GetResponseHeaders())
.SetData(webRequest.downloadHandler?.data)
.SetStatusCode(webRequest.responseCode)
.SetErrorMessage(webRequest.error)
#if UNITY_2020_2_OR_NEWER
.SetIsHttpError(webRequest.result == UnityWebRequest.Result.ProtocolError)
.SetIsNetworkError(webRequest.result == UnityWebRequest.Result.ConnectionError);
#else
.SetIsHttpError(webRequest.isHttpError)
.SetIsNetworkError(webRequest.isNetworkError);
#endif
return response;
}
internal void SetServiceConfig(HttpServiceConfig config)
{
m_ServiceIdToConfig[config.ServiceId] = config;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d9d20055a871be64386d2366d3b00a23
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: