예제 #1
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);
            }
        }
예제 #2
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);
            }
        }
예제 #3
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);
                }
            }
        }
예제 #4
0
        private void Publish(UIMouseEvent evt, UIElement listeningElement)
        {
            if (ModLoader.modBrowserPassphrase == "")
            {
                Main.menuMode = Interface.enterPassphraseMenuID;
                Interface.enterPassphraseMenu.SetGotoMenu(Interface.modSourcesID);
                return;
            }
            Main.PlaySound(10, -1, -1, 1);
            try
            {
                TmodFile[] modFiles    = ModLoader.FindMods();
                bool       ok          = false;
                TmodFile   theTModFile = null;
                foreach (TmodFile tModFile in modFiles)
                {
                    if (Path.GetFileName(tModFile.path).Equals(@Path.GetFileName(mod) + @".tmod"))
                    {
                        ok          = true;
                        theTModFile = tModFile;
                    }
                }
                if (!ok)
                {
                    throw new Exception();
                }
                System.Net.ServicePointManager.Expect100Continue = false;
                string filename = @ModLoader.ModPath + @Path.DirectorySeparatorChar + @Path.GetFileName(mod) + @".tmod";
                string url      = "http://javid.ddns.net/tModLoader/publishmod.php";
                using (var iconStream = theTModFile.HasFile("icon.png") ? new MemoryStream(theTModFile.GetFile("icon.png")) : null)
                    using (var stream = File.Open(filename, FileMode.Open))
                    {
                        var files = new List <UploadFile>();
                        files.Add(new IO.UploadFile
                        {
                            Name     = "file",
                            Filename = Path.GetFileName(filename),
                            //    ContentType = "text/plain",
                            Stream = stream
                        }
                                  );
                        if (iconStream != null)
                        {
                            files.Add(new IO.UploadFile
                            {
                                Name     = "iconfile",
                                Filename = "icon.png",
                                Stream   = iconStream
                            }
                                      );
                        }
                        BuildProperties bp     = BuildProperties.ReadModFile(theTModFile);
                        var             values = new NameValueCollection
                        {
                            { "displayname", bp.displayName },
                            { "name", Path.GetFileNameWithoutExtension(filename) },
                            { "version", "v" + bp.version },
                            { "author", bp.author },
                            { "homepage", bp.homepage },
                            { "description", bp.description },
                            { "steamid64", ModLoader.SteamID64 },
                            { "modloaderversion", "tModLoader v" + theTModFile.tModLoaderVersion },
                            { "passphrase", ModLoader.modBrowserPassphrase },
                            { "modreferences", String.Join(", ", bp.modReferences.Select(x => x.mod)) },
                            { "modside", bp.side.ToFriendlyString() },
                        };
                        using (PatientWebClient client = new PatientWebClient())
                        {
                            ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback((sender, certificate, chain, policyErrors) => { return(true); });
                            Interface.uploadMod.SetDownloading(Path.GetFileNameWithoutExtension(filename));
                            Interface.uploadMod.SetCancel(() =>
                            {
                                Main.menuMode = Interface.modSourcesID;
                                client.CancelAsync();
                            });
                            client.UploadProgressChanged += (s, e) => Interface.uploadMod.SetProgress(e);
                            client.UploadDataCompleted   += (s, e) => PublishUploadDataComplete(s, e, theTModFile);

                            var boundary = "---------------------------" + DateTime.Now.Ticks.ToString("x", System.Globalization.NumberFormatInfo.InvariantInfo);
                            client.Headers["Content-Type"] = "multipart/form-data; boundary=" + boundary;
                            boundary = "--" + boundary;
                            byte[] data = IO.UploadFile.GetUploadFilesRequestData(files, values);
                            client.UploadDataAsync(new Uri(url), data);
                        }
                        Main.menuMode = Interface.uploadModID;
                    }
            }
            catch (WebException e)
            {
                ErrorLogger.LogModBrowserException(e);
            }
        }