Esempio n. 1
0
 public static bool CanAttemptToConnectToCDN()
 {
                 #if RC_BUILD
     return(true);
                 #else
     CloudStorageAPI        cloudStorageAPI        = new CloudStorageAPI(null);
     StreamingAssetsStorage streamingAssetsStorage = new StreamingAssetsStorage(Game.None, null);
     bool ret = true;
     streamingAssetsStorage.LoadStreamingAssetsFile(cloudStorageAPI.cloudData.P12Path, (error, p12Bytes) =>
     {
         if (!string.IsNullOrEmpty(error))
         {
             Log.Warning("Unable to load " + cloudStorageAPI.cloudData.P12Path);
             ret = false;
         }
     }, true);
     if (string.IsNullOrEmpty(cloudStorageAPI.cloudData.Password))
     {
         Log.Warning("No cloudData.Password specified " + cloudStorageAPI.cloudData.Password);
         ret = false;
     }
     if (!ret)
     {
         Log.Warning("You need to have both a .p12 file and password to run this locally");
     }
     return(ret);
                 #endif
 }
Esempio n. 2
0
        /// <summary>
        /// Plays the trailer
        /// </summary>
        /// <param name="showVideoControls">If set to <c>true</c> show video controls.</param>
        public IEnumerator PlayTrailer(bool showVideoControls = false)
        {
            StreamingAssetsStorage storage = new StreamingAssetsStorage(Game.ForceVision, null);
            string introVideoPath          = "";

            //copying to persistent data may work, you can also try prefixing the path with "jar://"
                        #if UNITY_ANDROID
            PersistentDataStorage persistentStorage = new PersistentDataStorage(Game.ForceVision);

            if (persistentStorage.FileExists(StarWarsIntroVideo) == false)
            {
                storage.LoadStreamingAssetsFile(StarWarsIntroVideo, (string error, byte[] bytes) =>
                {
                    if (string.IsNullOrEmpty(error))
                    {
                        //save file in persistentdata
                        bool writeSuccess = persistentStorage.SaveBytes(StarWarsIntroVideo, bytes);
                        if (writeSuccess)
                        {
                            introVideoPath = persistentStorage.GetPersistentDataPath(StarWarsIntroVideo);
                        }
                        else
                        {
                            //handle error
                            Log.Error("Error! Unable to save the video file to persistent data.");
                        }
                    }
                    else
                    {
                        //handle error
                        Log.Error("Error! Unable to load from streaming assets.");
                    }
                }, true);
            }
            else
            {
                introVideoPath = persistentStorage.GetPersistentDataPath(StarWarsIntroVideo);
            }
                        #else
            introVideoPath = storage.GetStreamingAssetPath(StarWarsIntroVideo);
                        #endif

            // checking that path is valid string
            if (!string.IsNullOrEmpty(introVideoPath))
            {
                if (PlayCount > 0)
                {
                    // setting button state
                    if (TrailerPlayButton)
                    {
                        TrailerPlayButton.interactable = false;
                    }

                    // stopping background music
                    AudioEvent.Play(AudioEventName.Ftue.Stereo.BackgroundMusicPause, gameObject);
                }

                if (Application.isEditor)
                {
                    Debug.Log("Playing Trailer (Trailer cannot play in Editor)");
                }
                else
                {
                    // playing intro video
                    Handheld.PlayFullScreenMovie(introVideoPath,
                                                 Color.black,
                                                 showVideoControls ? FullScreenMovieControlMode.CancelOnInput : FullScreenMovieControlMode.Hidden);
                }

                // adding pause
                yield return(new WaitForSeconds(1.5f));

                if (PlayCount > 0)
                {
                    // setting button state
                    if (TrailerPlayButton)
                    {
                        TrailerPlayButton.interactable = true;
                    }

                    // starting background music
                    AudioEvent.Play(AudioEventName.Ftue.Stereo.BackgroundMusicResume, gameObject);
                }

                // setting new play count
                StereoStorage.SetPrefInt(IntroPlayedCountKey, PlayCount + 1);
            }
        }
Esempio n. 3
0
        public void AuthenticateWithGAE(Action <Response> callback = null, Action <float> fileProgressCallback = null, Func <string, Dictionary <string, string>, Dictionary <string, string>, int> OverrideRequestMethod = null)
        {
            Log.Debug("[DEBUG-AUTH] CloudStorageAPI AuthenticateWithGAE", Log.LogChannel.General);

                        #if RC_BUILD
            callback(null);
            return;
                        #endif

            Dictionary <string, string> requestFields = new Dictionary <string, string>();
            Dictionary <string, string> headers       = new Dictionary <string, string>();
            X509Certificate2            cert;
            try
            {
                StreamingAssetsStorage streamingAssetsStorage = new StreamingAssetsStorage(Game.None, null);
                byte[] bytes = null;
                streamingAssetsStorage.LoadStreamingAssetsFile(cloudData.P12Path, (success, p12Bytes) =>
                {
                    bytes = p12Bytes;
                }, true);

                Log.Debug("p12 bytes length =  " + bytes.Length);

                cert = new X509Certificate2(bytes, cloudData.Password, X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet);

                RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
                rsa.FromXmlString(cert.PrivateKey.ToXmlString(true));

                long assertionTime = GetTimeInSeconds();

                string claimSet = string.Format(ClaimSetSchema, cloudData.ServiceAccountEmail, ScopeStorageReadOnly, ApiEndpoint, assertionTime, assertionTime + expiration);

                string headerClaim = string.Format("{0}.{1}", Convert.ToBase64String(Encoding.UTF8.GetBytes(ClaimHeader)), Convert.ToBase64String(Encoding.UTF8.GetBytes(claimSet)));

                byte[] dataToSign = Encoding.UTF8.GetBytes(headerClaim);
                byte[] signedData = rsa.SignData(dataToSign, "SHA256");
                string sgn        = Convert.ToBase64String(signedData);
                string jwt        = string.Format("{0}.{1}", headerClaim, sgn);

                requestFields["grant_type"]     = "assertion";
                requestFields["assertion_type"] = AssertionType;
                requestFields["assertion"]      = jwt;

                headers["Content-Type"] = "application/x-www-form-urlencoded";
            }
            catch (Exception e)
            {
                                #if CI_BUILD || QA_BUILD || RC_BUILD
                Log.Exception(e);
                                #else
                Log.Warning("missing p12 file: " + cloudData.P12Path + e.Message);
                                #endif
                callback(null);
                return;
            }
            if (OverrideRequestMethod != null)
            {
                OverrideRequestMethod(ApiEndpoint, headers, requestFields);
            }
            else
            {
                Request authRequest = new Request(requestRunner, callback, "authRequest", ApiEndpoint, headers, requestFields, fileProgressCallback);
                authRequest.PostData();
            }
        }