public void OnWebLoad() { string rawLink = pastebinInput.text; try { string requestLink = WebLinkUtils.ParseToDirectDownloadLink(rawLink); byte[] downloadedBytes = WebUtils.ReadUrlToByteArray(requestLink); string downloadedString = Encoding.Default.GetString(downloadedBytes); // try to decompress the map, or load directly if it's not compressed try { byte[] compressedBytes = Convert.FromBase64String(downloadedString); byte[] pasteBytes = Decompress(compressedBytes); string pasteString = Encoding.Default.GetString(pasteBytes); GameManager.Instance.LoadMap(pasteString); } catch { GameManager.Instance.LoadMap(downloadedString); } } catch (Exception ex) { Debug.LogWarning("Unable to load map from: " + rawLink); if (Debug.isDebugBuild) { Debug.LogError(ex); } } finally { window.HideWindow(); } }
private void PostMapToPastebin(int expirationValueIndex, Action <AsyncOperation> completedCallback) { pastebinButton.interactable = false; webVersionButton.interactable = false; Map map = GameManager.Instance.Map; if (!map) { return; } XmlDocument document = new XmlDocument(); map.Serialize(document, null); byte[] bytes = Encoding.Default.GetBytes(document.OuterXml); byte[] compressedBytes = Compress(bytes); string base64String = Convert.ToBase64String(compressedBytes); WWWForm form = new WWWForm(); form.AddField("api_dev_key", "24844c99ae9971a2da79a2f7d0da7642"); form.AddField("api_paste_private", "1"); form.AddField("api_paste_name", "DeedPlanner map"); form.AddField("api_option", "paste"); form.AddField("api_paste_expire_date", ParseExpirationDateIndex(expirationValueIndex)); form.AddField("api_paste_code", base64String); const string pastebinApiEndpoint = "https://pastebin.com/api/api_post.php"; string requestLink = WebLinkUtils.AsCrossOriginLink(pastebinApiEndpoint); currentPastebinRequest = UnityWebRequest.Post(requestLink, form); UnityWebRequestAsyncOperation operation = currentPastebinRequest.SendWebRequest(); operation.completed += completedCallback; }