123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- using System.Security.Cryptography.X509Certificates;
- using System.Net.Security;
- using System.Net;
- using System.Collections;
- using UnityEngine;
- namespace SimpleFirebaseUnity
- {
- #if UNITY_EDITOR
- using EditorCoroutines;
- #endif
- internal class FirebaseRoot : FirebaseDatabase
- {
- protected static bool firstTimeInitiated = true;
- protected string host;
- protected string cred;
- /// <summary>
- /// Returns .json endpoint to this Firebase point
- /// </summary>
- public override string Endpoint
- {
- get
- {
- return "https://" + root.Host + "/.json";
- }
- }
- /// <summary>
- /// Credential for auth parameter
- /// </summary>
- public override string Credential
- {
- get
- {
- return cred;
- }
- set
- {
- cred = value;
- }
- }
- /// <summary>
- /// Returns .json endpoint to Firebase Rules.
- /// </summary>
- public override string RulesEndpoint
- {
- get
- {
- return "https://" + root.Host + "/.settings/rules.json";
- }
- }
- /// <summary>
- /// Copy this instance.
- /// </summary>
- public FirebaseRoot Copy()
- {
- return new FirebaseRoot (host, cred);
- }
- /// <summary>
- /// Initializes a new instance of the <see cref="SimpleFirebaseUnity.FirebaseRoot"/> class.
- /// </summary>
- /// <param name="_host">Host.</param>
- /// <param name="_cred">Cred.</param>
- public FirebaseRoot(string _host, string _cred = "")
- {
- if (firstTimeInitiated)
- {
- ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidationCallback;
- firstTimeInitiated = false;
- }
- root = this;
- host = _host;
- cred = _cred;
- }
- /// <summary>
- /// Returns main host of Firebase
- /// </summary>
- public override string Host
- {
- get
- {
- return host;
- }
- }
- private static bool RemoteCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
- {
- return true; // override certificate, we trust Firebase :D
- }
- /// <summary>
- /// Starts the coroutine.
- /// </summary>
- /// <param name="routine">Routine.</param>
- public void StartCoroutine(IEnumerator routine)
- {
- if (!Application.isPlaying)
- {
-
- #if UNITY_EDITOR
- EditorCoroutines.StartCoroutine(routine, this);
- #endif
- }
- else
- {
- FirebaseManager.Instance.StartCoroutine(routine);
- }
-
- }
- /// <summary>
- /// Stops the coroutine.
- /// </summary>
- /// <param name="routine">Routine.</param>
- public void StopCoroutine(IEnumerator routine)
- {
- if (!Application.isPlaying)
- {
- #if UNITY_EDITOR
- EditorCoroutines.StartCoroutine(routine, this);
- #endif
- }
- else
- {
- FirebaseManager.Instance.StopCoroutine(routine);
- }
- }
- }
- }
|