public override void OnActivate() { _myPublishedMods.Clear(); string text = Language.GetTextValue("tModLoader.MenuModBrowser") + " " + Language.GetTextValue("tModLoader.MBOfflineWithReason", Language.GetTextValue("tModLoader.MBUnknown")); TextPanel.SetText(text, 0.8f, true); string response = string.Empty; try { ServicePointManager.Expect100Continue = false; string url = "http://javid.ddns.net/tModLoader/listmymods.php"; var values = new NameValueCollection { { "steamid64", ModLoader.SteamID64 }, { "modloaderversion", BuildInfo.versionedName }, { "passphrase", ModLoader.modBrowserPassphrase }, }; byte[] result = IO.UploadFile.UploadFiles(url, null, values); response = Encoding.UTF8.GetString(result); } catch (WebException e) { if (e.Status == WebExceptionStatus.Timeout) { TextPanel.SetText(Language.GetTextValue("tModLoader.MenuModBrowser") + " " + Language.GetTextValue("tModLoader.MBOfflineWithReason", Language.GetTextValue("tModLoader.MBBusy")), 0.8f, true); return; } TextPanel.SetText(Language.GetTextValue("tModLoader.MenuModBrowser") + " " + Language.GetTextValue("tModLoader.MBOfflineWithReason", ""), 0.8f, true); return; } catch (Exception e) { UIModBrowser.LogModBrowserException(e); return; } try { JArray a; try { a = JArray.Parse(response); } catch (Exception e) { throw new Exception($"Manage Published Error Response: {response}", e); } foreach (JObject o in a.Children <JObject>()) { var modItem = new UIModManageItem( (string)o["displayname"], (string)o["name"], (string)o["version"], (string)o["author"], (int)o["downloads"], (int)o["downloadsversion"], (string)o["modloaderversion"] ); _myPublishedMods.Add(modItem); } } catch (Exception e) { UIModBrowser.LogModBrowserException(e); } }
internal void Unpublish(UIMouseEvent evt, UIElement listeningElement) { if (ModLoader.modBrowserPassphrase == "") { Main.menuMode = Interface.enterPassphraseMenuID; Interface.enterPassphraseMenu.SetGotoMenu(Interface.managePublishedID); return; } Main.PlaySound(12); try { ServicePointManager.Expect100Continue = false; string url = "http://javid.ddns.net/tModLoader/unpublishmymod.php"; var values = new NameValueCollection { { "name", this.name }, { "steamid64", ModLoader.SteamID64 }, { "modloaderversion", ModLoader.versionedName }, { "passphrase", ModLoader.modBrowserPassphrase }, }; byte[] result = UploadFile.UploadFiles(url, null, values); string s = System.Text.Encoding.UTF8.GetString(result, 0, result.Length); UIModBrowser.LogModUnpublishInfo(s); } catch (Exception e) { UIModBrowser.LogModBrowserException(e); } }
private void PublishUploadDataComplete(object s, UploadDataCompletedEventArgs e, TmodFile theTModFile) { if (e.Error != null) { if (e.Cancelled) { Main.menuMode = Interface.modSourcesID; return; } UIModBrowser.LogModBrowserException(e.Error); return; } var result = e.Result; int responseLength = result.Length; if (result.Length > 256 && result[result.Length - 256 - 1] == '~') { using (var fileStream = File.Open(theTModFile.path, FileMode.Open, FileAccess.ReadWrite)) using (var fileReader = new BinaryReader(fileStream)) using (var fileWriter = new BinaryWriter(fileStream)) { fileReader.ReadBytes(4); // "TMOD" fileReader.ReadString(); // ModLoader.version.ToString() fileReader.ReadBytes(20); // hash if (fileStream.Length - fileStream.Position > 256) // Extrememly basic check in case ReadString errors? { fileWriter.Write(result, result.Length - 256, 256); } } responseLength -= 257; } string response = Encoding.UTF8.GetString(result, 0, responseLength); UIModBrowser.LogModPublishInfo(response); }
private void PublishMod(UIMouseEvent evt, UIElement listeningElement) { if (ModLoader.modBrowserPassphrase == "") { Main.menuMode = Interface.enterPassphraseMenuID; Interface.enterPassphraseMenu.SetGotoMenu(Interface.modSourcesID, Interface.modSourcesID); return; } SoundEngine.PlaySound(10); try { if (ModLoader.GetMod(_builtMod.Name) == null) { if (!_builtMod.Enabled) { _builtMod.Enabled = true; } Main.menuMode = Interface.reloadModsID; ModLoader.OnSuccessfulLoad += () => { PublishMod(null, null); }; return; } var modFile = _builtMod.modFile; var bp = _builtMod.properties; PublishModInner(modFile, bp); } catch (WebException e) { UIModBrowser.LogModBrowserException(e); } }
internal void UnpublishMod(UIMouseEvent evt, UIElement listeningElement) { // TODO: Confimation window or change text to "Ctrl Click to Confirm" if (ModLoader.modBrowserPassphrase == string.Empty) { Main.menuMode = Interface.enterPassphraseMenuID; Interface.enterPassphraseMenu.SetGotoMenu(Interface.managePublishedID, Interface.modSourcesID); return; } SoundEngine.PlaySound(12); try { ServicePointManager.Expect100Continue = false; var values = new NameValueCollection { { "name", Name }, { "steamid64", ModLoader.SteamID64 }, { "modloaderversion", BuildInfo.versionedName }, { "passphrase", ModLoader.modBrowserPassphrase }, }; byte[] result = UploadFile.UploadFiles(UNPUBLISH_URL, null, values); string s = System.Text.Encoding.UTF8.GetString(result, 0, result.Length); UIModBrowser.LogModUnpublishInfo(s); } catch (Exception e) { UIModBrowser.LogModBrowserException(e); } }
public override void OnActivate() { if (string.IsNullOrEmpty(_info)) { _uIElement.Append(_loaderElement); _loading = true; _ready = false; _cts = new CancellationTokenSource(); Task.Factory.StartNew(() => { try { ServicePointManager.Expect100Continue = false; const string url = "http://javid.ddns.net/tModLoader/moddescription.php"; var values = new NameValueCollection { { "modname", _modDisplayName } }; using (WebClient client = new WebClient()) { ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, policyErrors) => policyErrors == SslPolicyErrors.None; client.UploadValuesCompleted += ReceiveModInfo; client.UploadValuesAsync(new Uri(url), "POST", values); } } catch (Exception e) { UIModBrowser.LogModBrowserException(e); } }, _cts.Token); } else { _loading = false; _ready = true; } }
private void PopulateModBrowser() { loading = true; SpecialModPackFilter = null; SpecialModPackFilterTitle = null; reloadButton.SetText(Language.GetTextValue("tModLoader.MBGettingData")); SetHeading(Language.GetTextValue("tModLoader.MenuModBrowser")); uIPanel.Append(uILoader); modList.Clear(); items.Clear(); modList.Deactivate(); try { ServicePointManager.Expect100Continue = false; string url = "http://javid.ddns.net/tModLoader/listmods.php"; var values = new NameValueCollection { { "modloaderversion", ModLoader.versionedName }, { "platform", ModLoader.compressedPlatformRepresentation }, }; using (WebClient client = new WebClient()) { ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback((sender, certificate, chain, policyErrors) => { return(true); }); client.UploadValuesCompleted += new UploadValuesCompletedEventHandler(UploadComplete); client.UploadValuesAsync(new Uri(url), "POST", values); } } catch (WebException e) { ShowOfflineTroubleshootingMessage(); if (e.Status == WebExceptionStatus.Timeout) { SetHeading(Language.GetTextValue("tModLoader.MenuModBrowser") + " " + Language.GetTextValue("tModLoader.MBOfflineWithReason", Language.GetTextValue("tModLoader.MBBusy"))); return; } if (e.Status == WebExceptionStatus.ProtocolError) { var resp = (HttpWebResponse)e.Response; if (resp.StatusCode == HttpStatusCode.NotFound) { SetHeading(Language.GetTextValue("tModLoader.MenuModBrowser") + " " + Language.GetTextValue("tModLoader.MBOfflineWithReason", resp.StatusCode)); return; } SetHeading(Language.GetTextValue("tModLoader.MenuModBrowser") + " " + Language.GetTextValue("tModLoader.MBOfflineWithReason", resp.StatusCode)); return; } } catch (Exception e) { UIModBrowser.LogModBrowserException(e); return; } }
private static void PublishUploadDataComplete(object s, UploadDataCompletedEventArgs e, TmodFile theTModFile) { if (e.Error != null) { if (e.Cancelled) { Main.menuMode = Interface.modSourcesID; return; } UIModBrowser.LogModBrowserException(e.Error); return; } ModLoader.GetMod(theTModFile.name)?.Close(); var result = e.Result; string response = HandlePublishResponse(theTModFile, result); UIModBrowser.LogModPublishInfo(response); }
private void PublishMod(UIMouseEvent evt, UIElement listeningElement) { if (ModLoader.modBrowserPassphrase == "") { Main.menuMode = Interface.enterPassphraseMenuID; Interface.enterPassphraseMenu.SetGotoMenu(Interface.modSourcesID); return; } Main.PlaySound(10); try { var modFile = _builtMod.modFile; var bp = _builtMod.properties; PublishModInner(modFile, bp); } catch (WebException e) { UIModBrowser.LogModBrowserException(e); } }
internal void RequestMoreinfo(UIMouseEvent evt, UIElement listeningElement) { Main.PlaySound(SoundID.MenuOpen); try { ServicePointManager.Expect100Continue = false; string url = "http://javid.ddns.net/tModLoader/moddescription.php"; var values = new NameValueCollection { { "modname", mod }, }; using (WebClient client = new WebClient()) { ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback((sender, certificate, chain, policyErrors) => { return(true); }); client.UploadValuesCompleted += new UploadValuesCompletedEventHandler(Moreinfo); client.UploadValuesAsync(new Uri(url), "POST", values); } } catch (Exception e) { UIModBrowser.LogModBrowserException(e); return; } }
private void Publish(UIMouseEvent evt, UIElement listeningElement) { if (ModLoader.modBrowserPassphrase == "") { Main.menuMode = Interface.enterPassphraseMenuID; Interface.enterPassphraseMenu.SetGotoMenu(Interface.modSourcesID); return; } Main.PlaySound(10); try { var modFile = builtMod.modFile; var bp = builtMod.properties; var files = new List <UploadFile>(); files.Add(new UploadFile { Name = "file", Filename = Path.GetFileName(modFile.path), // ContentType = "text/plain", Content = File.ReadAllBytes(modFile.path) }); if (modFile.HasFile("icon.png")) { files.Add(new UploadFile { Name = "iconfile", Filename = "icon.png", Content = modFile.GetBytes("icon.png") }); } if (bp.beta) { throw new WebException(Language.GetTextValue("tModLoader.BetaModCantPublishError")); } if (bp.buildVersion != modFile.tModLoaderVersion) { throw new WebException(Language.GetTextValue("OutdatedModCantPublishError.BetaModCantPublishError")); } var values = new NameValueCollection { { "displayname", bp.displayName }, { "name", modFile.name }, { "version", "v" + bp.version }, { "author", bp.author }, { "homepage", bp.homepage }, { "description", bp.description }, { "steamid64", ModLoader.SteamID64 }, { "modloaderversion", "tModLoader v" + modFile.tModLoaderVersion }, { "passphrase", ModLoader.modBrowserPassphrase }, { "modreferences", String.Join(", ", bp.modReferences.Select(x => x.mod)) }, { "modside", bp.side.ToFriendlyString() }, }; if (values["steamid64"].Length != 17) { throw new WebException($"The steamid64 '{values["steamid64"]}' is invalid, verify that you are logged into Steam and don't have a pirated copy of Terraria."); } if (string.IsNullOrEmpty(values["author"])) { throw new WebException($"You need to specify an author in build.txt"); } ServicePointManager.Expect100Continue = false; string url = "http://javid.ddns.net/tModLoader/publishmod.php"; using (PatientWebClient client = new PatientWebClient()) { ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, policyErrors) => true; Interface.uploadMod.SetDownloading(modFile.name); Interface.uploadMod.SetCancel(() => { Main.menuMode = Interface.modSourcesID; client.CancelAsync(); }); client.UploadProgressChanged += (s, e) => Interface.uploadMod.SetProgress(e); client.UploadDataCompleted += (s, e) => PublishUploadDataComplete(s, e, modFile); var boundary = "---------------------------" + DateTime.Now.Ticks.ToString("x", System.Globalization.NumberFormatInfo.InvariantInfo); client.Headers["Content-Type"] = "multipart/form-data; boundary=" + boundary; //boundary = "--" + boundary; byte[] data = UploadFile.GetUploadFilesRequestData(files, values); client.UploadDataAsync(new Uri(url), data); } Main.menuMode = Interface.uploadModID; } catch (WebException e) { UIModBrowser.LogModBrowserException(e); } }
internal void DownloadMod(UIMouseEvent evt, UIElement listeningElement) { Main.PlaySound(SoundID.MenuTick); try { if (UIModBrowser.PlatformSupportsTls12) // Needed for downloads from Github { ServicePointManager.SecurityProtocol |= (SecurityProtocolType)3072; // SecurityProtocolType.Tls12 } using (WebClient client = new WebClient()) { ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback((sender, certificate, chain, policyErrors) => { return(true); }); Interface.modBrowser.selectedItem = this; Interface.downloadMod.SetDownloading(displayname); Interface.downloadMod.SetCancel(client.CancelAsync); client.DownloadProgressChanged += (s, e) => { Interface.downloadMod.SetProgress(e); }; client.DownloadFileCompleted += (s, e) => { Main.menuMode = Interface.modBrowserID; if (e.Error != null) { if (e.Cancelled) { } else { // TODO yuck HttpStatusCode httpStatusCode = GetHttpStatusCode(e.Error); if (httpStatusCode == HttpStatusCode.ServiceUnavailable) { Interface.errorMessage.Show(Language.GetTextValue("tModLoader.MBExceededBandwidth"), 0); } else { Interface.errorMessage.Show(Language.GetTextValue("tModLoader.MBUnknownMBError"), 0); } } } else if (!e.Cancelled) { // Downloaded OK File.Copy(ModLoader.ModPath + Path.DirectorySeparatorChar + "temporaryDownload.tmod", ModLoader.ModPath + Path.DirectorySeparatorChar + mod + ".tmod", true); if (!update) { Interface.modBrowser.aNewModDownloaded = true; } else { Interface.modBrowser.aModUpdated = true; } RemoveChild(updateButton); } // Clean up: Delete temp File.Delete(ModLoader.ModPath + Path.DirectorySeparatorChar + "temporaryDownload.tmod"); }; client.DownloadFileAsync(new Uri(download), ModLoader.ModPath + Path.DirectorySeparatorChar + "temporaryDownload.tmod"); //client.DownloadFileAsync(new Uri(download), ModLoader.ModPath + Path.DirectorySeparatorChar + mod + ".tmod"); } Main.menuMode = Interface.downloadModID; } catch (WebException e) { UIModBrowser.LogModBrowserException(e); } }
private void PublishMod(UIMouseEvent evt, UIElement listeningElement) { if (ModLoader.modBrowserPassphrase == "") { Main.menuMode = Interface.enterPassphraseMenuID; Interface.enterPassphraseMenu.SetGotoMenu(Interface.modSourcesID); return; } SoundEngine.PlaySound(10); try { if (ModLoader.GetMod(_builtMod.Name) == null) { if (!_builtMod.Enabled) { _builtMod.Enabled = true; } Main.menuMode = Interface.reloadModsID; ModLoader.OnSuccessfulLoad += () => { PublishMod(null, null); }; return; } var modFile = _builtMod.modFile; var bp = _builtMod.properties; var files = new List <UploadFile>(); files.Add(new UploadFile { Name = "file", Filename = Path.GetFileName(modFile.path), // ContentType = "text/plain", Content = File.ReadAllBytes(modFile.path) }); if (modFile.HasFile("icon.png")) { using (modFile.Open()) files.Add(new UploadFile { Name = "iconfile", Filename = "icon.png", Content = modFile.GetBytes("icon.png") }); } if (bp.beta) { throw new WebException(Language.GetTextValue("tModLoader.BetaModCantPublishError")); } if (bp.buildVersion != modFile.tModLoaderVersion) { throw new WebException(Language.GetTextValue("OutdatedModCantPublishError.BetaModCantPublishError")); } var values = new NameValueCollection { { "displayname", bp.displayName }, { "displaynameclean", string.Join("", ChatManager.ParseMessage(bp.displayName, Color.White).Where(x => x.GetType() == typeof(TextSnippet)).Select(x => x.Text)) }, { "name", modFile.name }, { "version", "v" + bp.version }, { "author", bp.author }, { "homepage", bp.homepage }, { "description", bp.description }, { "steamid64", ModLoader.SteamID64 }, { "modloaderversion", "tModLoader v" + modFile.tModLoaderVersion }, { "passphrase", ModLoader.modBrowserPassphrase }, { "modreferences", String.Join(", ", bp.modReferences.Select(x => x.mod)) }, { "modside", bp.side.ToFriendlyString() }, }; if (values["steamid64"].Length != 17) { throw new WebException($"The steamid64 '{values["steamid64"]}' is invalid, verify that you are logged into Steam and don't have a pirated copy of Terraria."); } if (string.IsNullOrEmpty(values["author"])) { throw new WebException($"You need to specify an author in build.txt"); } ServicePointManager.Expect100Continue = false; string url = "http://javid.ddns.net/tModLoader/publishmod.php"; uploadTimer = new Stopwatch(); uploadTimer.Start(); using (PatientWebClient client = new PatientWebClient()) { ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, policyErrors) => true; Interface.progress.Show(displayText: $"Uploading: {modFile.name}", gotoMenu: Interface.modSourcesID, cancel: client.CancelAsync); client.UploadProgressChanged += (s, e) => { double elapsedSeconds = uploadTimer.Elapsed.TotalSeconds; double speed = elapsedSeconds > 0.0 ? e.BytesSent / elapsedSeconds : 0.0; Interface.progress.SubProgressText = $"{UIMemoryBar.SizeSuffix(e.BytesSent, 2)} / {UIMemoryBar.SizeSuffix(e.TotalBytesToSend, 2)} " + $"({UIMemoryBar.SizeSuffix((long)speed, 2)}/s)"; Interface.progress.Progress = (float)e.BytesSent / e.TotalBytesToSend; }; client.UploadDataCompleted += (s, e) => PublishUploadDataComplete(s, e, modFile); var boundary = "---------------------------" + DateTime.Now.Ticks.ToString("x", System.Globalization.NumberFormatInfo.InvariantInfo); client.Headers["Content-Type"] = "multipart/form-data; boundary=" + boundary; //boundary = "--" + boundary; byte[] data = UploadFile.GetUploadFilesRequestData(files, values, boundary); client.UploadDataAsync(new Uri(url), data); } } catch (WebException e) { UIModBrowser.LogModBrowserException(e); } }
private void PopulateFromJSON(LocalMod[] installedMods, string json) { string tls = PlatformSupportsTls12 ? "&tls12=y" : ""; try { JObject jsonObject; try { jsonObject = JObject.Parse(json); } catch (Exception e) { throw new Exception("Bad JSON: " + json, e); } JObject updateObject = (JObject)jsonObject["update"]; if (updateObject != null) { updateAvailable = true; updateText = (string)updateObject["message"]; updateURL = (string)updateObject["url"]; } JArray modlist = (JArray)jsonObject["modlist"]; foreach (JObject mod in modlist.Children <JObject>()) { string displayname = (string)mod["displayname"]; //reloadButton.SetText("Adding " + displayname + "..."); string name = (string)mod["name"]; string version = (string)mod["version"]; string author = (string)mod["author"]; string download = (string)mod["download"] + tls; int downloads = (int)mod["downloads"]; int hot = (int)mod["hot"]; // for now, hotness is just downloadsYesterday string timeStamp = (string)mod["updateTimeStamp"]; //string[] modreferences = ((string)mod["modreferences"]).Split(','); string modreferences = (string)mod["modreferences"]; ModSide modside = ModSide.Both; // TODO: add filter option for modside. string modIconURL = (string)mod["iconurl"]; string modsideString = (string)mod["modside"]; if (modsideString == "Client") { modside = ModSide.Client; } if (modsideString == "Server") { modside = ModSide.Server; } if (modsideString == "NoSync") { modside = ModSide.NoSync; } //bool exists = false; // unused? bool update = false; bool updateIsDowngrade = false; var installed = installedMods.FirstOrDefault(m => m.Name == name); if (installed != null) { //exists = true; var cVersion = new Version(version.Substring(1)); if (cVersion > installed.modFile.version) { update = true; } else if (cVersion < installed.modFile.version) { update = updateIsDowngrade = true; } } UIModDownloadItem modItem = new UIModDownloadItem(displayname, name, version, author, modreferences, modside, modIconURL, download, downloads, hot, timeStamp, update, updateIsDowngrade, installed); items.Add(modItem); } updateNeeded = true; } catch (Exception e) { UIModBrowser.LogModBrowserException(e); return; } }