Exemple #1
0
    private IEnumerator initialize()
    {
        ftp ftpClient = new ftp(Accessories.FTP_ADDRESS(key), Accessories.FTP_USERNAME(key), Accessories.FTP_PASSWORD(key));

        if (Directory.Exists(LOCAL_DATA_ROOT_PATH) == false) //If the data folder doesn't exist
        {
            Directory.CreateDirectory(LOCAL_DATA_ROOT_PATH); //Create it
        }

        if (File.Exists(LOCAL_DATA_ROOT_PATH + REGISTERED_USERS_FILE_PATH)) //If the registered users file is still there
        {
            File.Delete(LOCAL_DATA_ROOT_PATH + REGISTERED_USERS_FILE_PATH); //Remove it
        }

        //Download the files
        CoroutineWithData cd = new CoroutineWithData(this, ftpClient.downloadAsync(WEB_DATA_ROOT_PATH + REGISTERED_USERS_FILE_PATH, LOCAL_DATA_ROOT_PATH + REGISTERED_USERS_FILE_PATH));

        yield return(cd.coroutine);

        //Once everything has been downloaded (or not)

        if (cd.result.ToString().Equals(ftp.sucessMessage))   //If the ftp file download succeeded

        {
            SplitRegisteredUserFile(); //Attempt to

            CheckForCurrentCredentials();

            MultiSceneVariables.Instance.Online = true;

            LoginCanvasManager.current.EnableCanvas(); //Disable the canvas
            //OfflineCanvasManager.current.DisableCanvas(); //Enable the offline option
        }
        else if (cd.result.ToString().Equals(ftp.failMessage))   //If the ftp file download failed
        {
            print("Running fail");

            NotificationManager.Instance.ShowNotification(NotificationType.TOP, "Unable to Connect to server", Mathf.Infinity, Color.red);

            MultiSceneVariables.Instance.Online = false;

            LoginCanvasManager.current.DisableCanvas(); //Disable the canvas
            //OfflineCanvasManager.current.EnableCanvas(); //Enable the offline option
        }
    }
    private IEnumerator timerWithSave(string scene, float duration)
    {
        loadingScene = true;
        BlackScreenCanvas.Instance.FadeIn(duration); //Fade the black screen in
        yield return(new WaitForSeconds(duration));  //Wait

        bool usingCheats = false;

        if (ShopManager.Instance != null)
        {
            usingCheats = ShopManager.Instance.isUsingCheats;
        }

        //Save the game stats to Mr Computers
        if (MultiSceneVariables.Instance.Online && usingCheats == false)   //If the player is online and is not using cheats

        {
            string key      = "117TMHR@Con";                         //The password for accessing the ftp login credentials
            string username = MultiSceneVariables.Instance.Username; //Get the username

            //File paths
            string DATA_FILE_PATH       = "users/" + username + "_data.txt";
            string LOCAL_DATA_ROOT_PATH = Accessories.LOCAL_DATA_ROOT_PATH;
            string WEB_DATA_ROOT_PATH   = Accessories.WEB_DATA_ROOT_PATH;

            if (Directory.Exists(LOCAL_DATA_ROOT_PATH + "users") == false)                                                       //Check if the user's folder exists
            {
                Directory.CreateDirectory(LOCAL_DATA_ROOT_PATH + "users");                                                       //If not, create it
            }
            ftp ftpClient = new ftp(Accessories.FTP_ADDRESS(key), Accessories.FTP_USERNAME(key), Accessories.FTP_PASSWORD(key)); //Make instance of ftp class

            //Download the files
            CoroutineWithData cd = new CoroutineWithData(this, ftpClient.downloadAsync(WEB_DATA_ROOT_PATH + DATA_FILE_PATH, LOCAL_DATA_ROOT_PATH + DATA_FILE_PATH));

            yield return(cd.coroutine);                                 //Wait until it's completed

            if (cd.result.ToString().Equals(ftp.sucessMessage))         //If the ftp file download succeeded
            {
                if (File.Exists(LOCAL_DATA_ROOT_PATH + DATA_FILE_PATH)) //If the file exists
                {
                    DateTime localTime = DateTime.Now;

                    //Construct entry text
                    string entry =
                        localTime.ToString("g") + "," +
                        username + "," +
                        GameManager.Score + "," +
                        GameManager.TimePlayed + "," +
                        GameManager.WavesCompleted + "," +
                        GameManager.EnemiesKilled + "," +
                        GameManager.HealthBought + "," +
                        GameManager.TimesRevived + "\n";

                    File.AppendAllText(LOCAL_DATA_ROOT_PATH + DATA_FILE_PATH, entry); //Record entry locally to a current list of the user's games

                    //Upload the data file
                    CoroutineWithData cd2 = new CoroutineWithData(this, ftpClient.uploadAsync(WEB_DATA_ROOT_PATH + DATA_FILE_PATH, LOCAL_DATA_ROOT_PATH + DATA_FILE_PATH));
                }
            }
        }

        loadingScene = false;
        NotificationManager.Instance.CancelAllNotifications(); //Cancel any notifications
        StopAllCoroutines();                                   //Stop any coroutines that are running (there shouldn't be any coroutines running between scenes)
        SceneManager.LoadScene(scene);                         //Load the scene
    }