-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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(); | ||
} | ||
} | ||
} |
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.
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)); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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> { } | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 | ||
{ | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.