Skip to content
This repository has been archived by the owner on Jul 16, 2023. It is now read-only.

Commit

Permalink
Merge branch 'upstream'
Browse files Browse the repository at this point in the history
  • Loading branch information
paulpach committed Jul 4, 2020
2 parents b80a575 + d944291 commit 023409d
Show file tree
Hide file tree
Showing 94 changed files with 2,585 additions and 3,860 deletions.
12 changes: 12 additions & 0 deletions Assets/Mirror/Cloud.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 61 additions & 0 deletions Assets/Mirror/Cloud/ApiConnector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using Mirror.Cloud.ListServerService;
using UnityEngine;

namespace Mirror.Cloud
{
/// <summary>
/// Used to requests and responses from the mirror api
/// </summary>
public interface IApiConnector
{
ListServer ListServer { get; }
}

/// <summary>
/// Used to requests and responses from the mirror api
/// </summary>
[DisallowMultipleComponent]
[AddComponentMenu("Network/CloudServices/ApiConnector")]
[HelpURL("https://mirror-networking.com/docs/CloudServices/ApiConnector.html")]
public class ApiConnector : MonoBehaviour, IApiConnector, ICoroutineRunner
{
#region Inspector
[Header("Settings")]

[Tooltip("Base URL of api, including https")]
[SerializeField] string ApiAddress = "";

[Tooltip("Api key required to access api")]
[SerializeField] string ApiKey = "";

[Header("Events")]

[Tooltip("Triggered when server list updates")]
[SerializeField] ServerListEvent _onServerListUpdated = new ServerListEvent();
#endregion

IRequestCreator requestCreator;

public ListServer ListServer { get; private set; }

void Awake()
{
requestCreator = new RequestCreator(ApiAddress, ApiKey, this);

InitListServer();
}

void InitListServer()
{
IListServerServerApi serverApi = new ListServerServerApi(this, requestCreator);
IListServerClientApi clientApi = new ListServerClientApi(this, requestCreator, _onServerListUpdated);
ListServer = new ListServer(serverApi, clientApi);
}

public void OnDestroy()
{
ListServer.ServerApi.Shutdown();
ListServer.ClientApi.Shutdown();
}
}
}
15 changes: 15 additions & 0 deletions Assets/Mirror/Cloud/ApiConnector.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions Assets/Mirror/Cloud/Core/BaseApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;

namespace Mirror.Cloud
{
public interface IBaseApi
{
/// <summary>
/// Cleans up any data created by the instance
/// <para>For Example: removing server from list</para>
/// </summary>
void Shutdown();
}

public abstract class BaseApi
{
protected readonly ICoroutineRunner runner;
protected readonly IRequestCreator requestCreator;

protected BaseApi(ICoroutineRunner runner, IRequestCreator requestCreator)
{
this.runner = runner ?? throw new ArgumentNullException(nameof(runner));
this.requestCreator = requestCreator ?? throw new ArgumentNullException(nameof(requestCreator));
}
}
}
11 changes: 11 additions & 0 deletions Assets/Mirror/Cloud/Core/BaseApi.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Assets/Mirror/Cloud/Core/Events.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using Mirror.Cloud.ListServerService;
using UnityEngine.Events;

namespace Mirror.Cloud
{
[Serializable]
public class ServerListEvent : UnityEvent<ServerCollectionJson> { }

[Serializable]
public class MatchFoundEvent : UnityEvent<ServerJson> { }
}
11 changes: 11 additions & 0 deletions Assets/Mirror/Cloud/Core/Events.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Assets/Mirror/Cloud/Core/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using UnityEngine.Networking;

namespace Mirror.Cloud
{
public static class Extensions
{
public static bool IsOk(this UnityWebRequest webRequest)
{
return 200 <= webRequest.responseCode && webRequest.responseCode <= 299;
}
}
}
11 changes: 11 additions & 0 deletions Assets/Mirror/Cloud/Core/Extensions.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Assets/Mirror/Cloud/Core/ICoroutineRunner.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Collections;
using UnityEngine;

namespace Mirror.Cloud
{
public interface ICoroutineRunner : IUnityEqualCheck
{
Coroutine StartCoroutine(IEnumerator routine);
void StopCoroutine(IEnumerator routine);
void StopCoroutine(Coroutine routine);
}
}
11 changes: 11 additions & 0 deletions Assets/Mirror/Cloud/Core/ICoroutineRunner.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions Assets/Mirror/Cloud/Core/IRequestCreator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.Collections;
using UnityEngine.Networking;

namespace Mirror.Cloud
{
public delegate void RequestSuccess(string responseBody);

public delegate void RequestFail(string responseBody);

/// <summary>
/// Objects that can be sent to the Api must have this interface
/// </summary>
public interface ICanBeJson { }

/// <summary>
/// Methods to create and send UnityWebRequest
/// </summary>
public interface IRequestCreator
{
UnityWebRequest Delete(string page);
UnityWebRequest Get(string page);
UnityWebRequest Patch<T>(string page, T json) where T : struct, ICanBeJson;
UnityWebRequest Post<T>(string page, T json) where T : struct, ICanBeJson;

/// <summary>
/// Sends Request to api and invokes callback when finished
/// <para>Starts Coroutine of SendRequestEnumerator</para>
/// </summary>
/// <param name="request"></param>
/// <param name="onSuccess"></param>
/// <param name="onFail"></param>
void SendRequest(UnityWebRequest request, RequestSuccess onSuccess = null, RequestFail onFail = null);
/// <summary>
/// Sends Request to api and invokes callback when finished
/// </summary>
/// <param name="request"></param>
/// <param name="onSuccess"></param>
/// <param name="onFail"></param>
/// <returns></returns>
IEnumerator SendRequestEnumerator(UnityWebRequest request, RequestSuccess onSuccess = null, RequestFail onFail = null);
}
}
11 changes: 11 additions & 0 deletions Assets/Mirror/Cloud/Core/IRequestCreator.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions Assets/Mirror/Cloud/Core/IUnityEqualCheck.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using UnityEngine;

namespace Mirror.Cloud
{
/// <summary>
/// Adds Extension to check if unity object is null.
/// <para>Use these methods to stop MissingReferenceException</para>
/// </summary>
public interface IUnityEqualCheck
{

}

public static class UnityEqualCheckExtension
{
public static bool IsNull(this IUnityEqualCheck obj)
{
return (obj as Object) == null;
}

public static bool IsNotNull(this IUnityEqualCheck obj)
{
return (obj as Object) != null;
}
}
}
11 changes: 11 additions & 0 deletions Assets/Mirror/Cloud/Core/IUnityEqualCheck.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions Assets/Mirror/Cloud/Core/JsonStructs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;

namespace Mirror.Cloud
{
[Serializable]
public struct CreatedIdJson : ICanBeJson
{
public string id;
}

[Serializable]
public struct ErrorJson : ICanBeJson
{
public string code;
public string message;

public int HtmlCode => int.Parse(code);
}

[Serializable]
public struct EmptyJson : ICanBeJson
{
}
}
11 changes: 11 additions & 0 deletions Assets/Mirror/Cloud/Core/JsonStructs.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 023409d

Please sign in to comment.