Пример #1
0
    // "" for success, otherwise error message
    public static string Setup(string phpScriptsLocation)
    {
        Debug.Log("AccountSystem: Setting up PHP scripts..");

        if (phpScriptsLocation == "")
        {
            Debug.LogError("Php Script Location not set..!");
            return("Php Script Location not set..!");
        }

        // Location of the setup script
        string url = phpScriptsLocation + setupPhp;

        // Create a new form
        WWWForm form = new WWWForm();

        // Add the credentials
        form.AddCredentials();

        // Connect to the script
        WWW www = new WWW(url, form);

        // Wait for it to respond
        Debug.Log("AccountSystem: Connecting to " + url);

        float timeLeft = timeOut;

        while (!www.isDone && timeLeft > 0)
        {
            Debug.Log("Time Left " + timeLeft.ToString("#.00"));
            timeLeft -= Time.fixedDeltaTime;

            if (timeLeft / timeOut > 0)
            {
                EditorUtility.DisplayProgressBar(
                    "Connecting to " + url + "..",
                    "Timing out in " + timeLeft.ToString("#.") + " seconds",
                    timeLeft / timeOut);
            }
            else
            {
                EditorUtility.ClearProgressBar();
            }
        }

        if (timeLeft <= 0)
        {
            return("Connection timed out!\nCheck your credentials, internet connection and firewall and try again.");
        }

        EditorUtility.ClearProgressBar();

        // Check for errors
        if (www.error != null)
        {
            Debug.LogError("AccountSystem: WWW Error:\n" + www.error);
            if (www.error.ToLower().Contains("could not resolve"))
            {
                return("Could not access the provided PHP Script Location.\nPlease check your credentials." + "\nCheck Debug.Log for more info.");
            }
            if (www.error.ToLower().Contains("404"))
            {
                return("Could not find SETUP.PHP at " + AS_Credentials.phpScriptsLocation.ToUpper() + "\nHave you uploaded all the scripts from the folder 'Server-Side Scripts'?" + "\nCheck Debug.Log for more info.");
            }

            return("WWW Error: \n" + www.error + "\nCheck Debug.Log for more info.");
        }
        if (www.text.ToLower().Contains("error"))
        {
            Debug.LogError("AccountSystem: PHP/MySQL Error:\n" + www.text);
            if (www.text.ToLower().Contains("could not locate file"))
            {
                return("Could not find one of the PHP files at " + AS_Credentials.phpScriptsLocation.ToUpper() + "\nHave you uploaded all the scripts from the folder 'Server-Side Scripts'?" + "\nCheck Debug.Log for more info.");
            }

            return("PHP/MySQL Error - Check Debug.Log for more info");
        }

        if (www.text.ToLower().Contains("success"))
        {
            Debug.Log("AccountSystem: PHP Scripts were setup successfully - You can now Initialize the Database!!\n" + www.text);
            return("");
        }
        else
        {
            Debug.LogWarning("AccountSystem: PHP Scripts could not be set up - Check Message:\n" + www.text);
            return("PHP Scripts could not be set up - Check Debug.Log for more info");
        }
    }