Exemple #1
0
        private bool DidDownloadSucceed(UnityWebRequest request, bool showError)
        {
            string error = null;

            if (request.result == UnityWebRequest.Result.ConnectionError || request.result == UnityWebRequest.Result.DataProcessingError)
            {
                error = "There was a communication error: " + request.error;
            }
            else if (request.result == UnityWebRequest.Result.ProtocolError)
            {
                error = "There was an HTTP error: " + request.error;
            }

            if (!string.IsNullOrEmpty(error))
            {
                // Failure
                Debug.Log(error);
                if (showError)
                {
                    InfoDialog.Create("", error.ToString());
                }

                return(false);
            }

            return(true);
        }
        private IEnumerator RequestMissionData()
        {
            ProgressDialog progressDialog = ProgressDialog.Create("Fetching Missions");

            using (UnityWebRequest request = UnityWebRequest.Get(WebConfig.webAPI + "mission/get_missions.php"))
            {
                progressDialog.SetWebRequest(request);

                yield return(request.SendWebRequest());

                string error = WebConfig.GetErrorString(request);

                if (string.IsNullOrEmpty(error))
                {
                    // Success
                    MissionResponse response = MissionResponse.FromJson(request.downloadHandler.text);
                    m_Missions = response.missions;

                    PopulateMissions(m_MissionFilter);
                }
                else
                {
                    // Failure
                    Debug.Log(error);
                    InfoDialog.Create("", error.ToString());
                }
            }

            progressDialog.Close();
        }
Exemple #3
0
        private void OnSelected_UploadFilePath(string path)
        {
            // Require DLL uploads to specify a GitHub link
            if (Path.GetExtension(path).ToLowerInvariant().Contains("dll"))
            {
                if (m_txtGitHub.text == GitHubDefaultText)
                {
                    InfoDialog.Create("GitHub Link Required", "A GitHub link is required to certify your DLL.");
                    return;
                }
            }

            if (!string.IsNullOrEmpty(path))
            {
                StartCoroutine(RequestUploadFile(path));
            }
        }
Exemple #4
0
        private IEnumerator RequestUpdateMission()
        {
            ProgressDialog progressDialog = ProgressDialog.Create("Updating Mission");

            // Perform request
            Dictionary <string, string> formData = new Dictionary <string, string>();

            formData.Add("UserID", AppController.localUser.userID.ToString());
            formData.Add("SessionToken", AppController.localUser.sessionToken);
            formData.Add("MissionID", missionData.missionID.ToString());
            formData.Add("MissionName", m_InputTitle.text);
            formData.Add("MissionDescription", m_InputDescription.text);
            formData.Add("GitHubLink", m_txtGitHub.text);

            using (UnityWebRequest request = UnityWebRequest.Post(WebConfig.webAPI + "mission/update_mission.php", formData))
            {
                progressDialog.SetWebRequest(request);

                yield return(request.SendWebRequest());

                string error = WebConfig.GetErrorString(request);

                if (string.IsNullOrEmpty(error))
                {
                    // Success
                    onUpdatedMissionCB?.Invoke();
                }
                else
                {
                    // Failure
                    Debug.Log(error);
                    InfoDialog.Create("", error.ToString());

                    if (WebConfig.DidSessionExpire(request))
                    {
                        AppController.LogOut();
                    }
                }
            }

            progressDialog.Close();
        }
Exemple #5
0
        private IEnumerator RequestDeleteFile(string fileName)
        {
            ProgressDialog progressDialog = ProgressDialog.Create("Deleting File");

            // Perform request
            Dictionary <string, string> formData = new Dictionary <string, string>();

            formData.Add("UserID", AppController.localUser.userID.ToString());
            formData.Add("SessionToken", AppController.localUser.sessionToken);
            formData.Add("MissionID", missionData.missionID.ToString());
            formData.Add("FileName", fileName);

            using (UnityWebRequest request = UnityWebRequest.Post(WebConfig.webAPI + "mission/remove_file.php", formData))
            {
                progressDialog.SetWebRequest(request);

                yield return(request.SendWebRequest());

                string error = WebConfig.GetErrorString(request);

                if (string.IsNullOrEmpty(error))
                {
                    // Success
                    onUpdatedMissionCB?.Invoke();
                }
                else
                {
                    // Failure
                    Debug.Log(error);
                    InfoDialog.Create("", error.ToString());

                    if (WebConfig.DidSessionExpire(request))
                    {
                        AppController.LogOut();
                    }
                }
            }

            progressDialog.Close();
        }
Exemple #6
0
        private IEnumerator RequestUploadFile(string filePath)
        {
            ProgressDialog progressDialog = ProgressDialog.Create("Uploading File");

            // Perform request
            List <IMultipartFormSection> multipartData = new List <IMultipartFormSection>();

            multipartData.Add(new MultipartFormDataSection("UserID", AppController.localUser.userID.ToString(), "form-data"));
            multipartData.Add(new MultipartFormDataSection("SessionToken", AppController.localUser.sessionToken, "form-data"));
            multipartData.Add(new MultipartFormDataSection("MissionID", missionData.missionID.ToString(), "form-data"));
            multipartData.Add(new MultipartFormFileSection("MissionFile", File.ReadAllBytes(filePath), Path.GetFileName(filePath), "file"));

            using (UnityWebRequest request = UnityWebRequest.Post(WebConfig.webAPI + "mission/add_file.php", multipartData))
            {
                progressDialog.SetWebRequest(request, true);

                yield return(request.SendWebRequest());

                string error = WebConfig.GetErrorString(request);

                if (string.IsNullOrEmpty(error))
                {
                    // Success
                    onUpdatedMissionCB?.Invoke();
                }
                else
                {
                    // Failure
                    Debug.Log(error);
                    InfoDialog.Create("", error.ToString());

                    if (WebConfig.DidSessionExpire(request))
                    {
                        AppController.LogOut();
                    }
                }
            }

            progressDialog.Close();
        }
Exemple #7
0
        public void OnClick_Install()
        {
            // Get the cached mission details
            string      json       = File.ReadAllText(CachePath.GetMissionDetailsFilePath(missionData.missionID));
            MissionData localData  = JsonUtility.FromJson <MissionData>(json);
            string      sdkVersion = CachePath.GetSDKVersion(localData);

            // Do not allow installation if mission files already exist
            foreach (string fileName in localData.fileNames)
            {
                string filePath = Path.Combine(UserPrefs.gameDirectory, fileName);

                if (File.Exists(filePath))
                {
                    InfoDialog.Create("Installation Failed", "The file '" + fileName + "' already exists in your game directory. Please remove it to continue.");
                    return;
                }
            }

            List <string> installedFiles = new List <string>();

            // Need to export plugin for standard mission OPM file
            if (m_IsStandardMission)
            {
                string opmFileName = localData.fileNames.FirstOrDefault((string fileName) => Path.GetExtension(fileName).ToLowerInvariant().Contains("opm"));
                string opmFilePath = Path.Combine(CachePath.GetMissionDirectory(localData.missionID), opmFileName);

                string pluginFileName = Path.ChangeExtension(opmFileName, ".dll");
                string pluginPath     = Path.Combine(UserPrefs.gameDirectory, pluginFileName);

                // Don't allow install if the plugin will overwrite another DLL of the same name
                if (File.Exists(pluginPath))
                {
                    InfoDialog.Create("Install Failed", "There is already a plugin named " + pluginFileName);
                    return;
                }

                // Export plugin
                MissionRoot root = MissionReader.GetMissionData(opmFilePath);
                PluginExporter.ExportPlugin(pluginPath, root.sdkVersion, root.levelDetails);

                FileReference.AddReference(pluginFileName);

                installedFiles.Add(pluginFileName);
            }

            // Install mission from cache into game folder
            foreach (string fileName in localData.fileNames)
            {
                string filePath = Path.Combine(CachePath.GetMissionDirectory(localData.missionID), fileName);

                InstallFile(fileName, filePath);

                installedFiles.Add(fileName);
            }

            // Install SDK
            if (!string.IsNullOrEmpty(sdkVersion))
            {
                InstallFile(CachePath.GetSDKFileName(sdkVersion), CachePath.GetSDKFilePath(sdkVersion));
                InstallFile(CachePath.DotNetInteropFileName, CachePath.GetInteropFilePath(), true);

                installedFiles.Add(CachePath.GetSDKFileName(sdkVersion));
                installedFiles.Add(CachePath.DotNetInteropFileName);
            }

            // Write installed files to cache
            using (FileStream fs = new FileStream(CachePath.GetMissionInstalledMetaFilePath(localData.missionID), FileMode.Create, FileAccess.Write, FileShare.Read))
                using (StreamWriter writer = new StreamWriter(fs))
                {
                    foreach (string fileName in installedFiles)
                    {
                        writer.WriteLine(fileName);
                    }
                }

            // Set buttons
            m_BtnInstall.gameObject.SetActive(false);
            m_BtnUninstall.gameObject.SetActive(true);
            m_BtnDelete.interactable = false;
        }