예제 #1
0
        private static void PublishModInner(TmodFile modFile, BuildProperties bp, bool commandLine = false)
        {
            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"))               // Test this on server
            {
                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";

            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);

                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);
                if (commandLine)
                {
                    var    result   = client.UploadData(new Uri(url), data);                // could use async version for progress output maybe
                    string response = HandlePublishResponse(modFile, result);
                    Console.WriteLine(Language.GetTextValue("tModLoader.MBServerResponse", response));
                    if (result.Length <= 256 || result[result.Length - 256 - 1] != '~')
                    {
                        throw new Exception("Publish failed due to invalid response from server");
                    }
                }
                else
                {
                    client.UploadDataCompleted   += (s, e) => PublishUploadDataComplete(s, e, modFile);
                    client.UploadProgressChanged += (s, e) => Interface.progress.Progress = (float)e.BytesSent / e.TotalBytesToSend;
                    client.UploadDataAsync(new Uri(url), data);
                }
            }
        }
예제 #2
0
        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);
            }
        }
예제 #3
0
        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);
            }
        }