Пример #1
0
        private static string GetLicenseIdFromCombinedKey(string combinedKey)
        {
            var combinedKeyBase64 = combinedKey.Substring(172, combinedKey.Length - 172);
            var combinedKeyParsed = Convert.FromBase64String(combinedKeyBase64);

            var compinedKeyAscii = new ASCIIEncoding().GetString(combinedKeyParsed);

            return(compinedKeyAscii.ToLower());
        }
        private void downloadMap(LavaMapBrowserData mapData)
        {
            if (mapData == null)
            {
                return;
            }
            int    id   = mapData.id;
            string name = mapData.name.ToLower().Replace(" ", "_");

            downloadThread = new System.Threading.Thread(new System.Threading.ThreadStart(delegate
            {
                byte[] data;
                string dataStr;
                using (WebClient WEB = new WebClient())
                {
                    try
                    {
                        if (name == Server.mainLevel.name.ToLower())
                        {
                            MessageBox.Show("Error: You cannot overwrite the main level!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            goto end;
                        }
                        if (File.Exists("levels/" + name + ".lvl"))
                        {
                            if (MessageBox.Show("Map \"" + name + "\" already exists. Do you want to overwrite it?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No)
                            {
                                goto end;
                            }
                        }

                        data = WEB.DownloadData(downloadUrl + "?id=" + id + "&mode=lvl");
                        if (data.Length < 1)
                        {
                            MessageBox.Show("No data was recieved.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            goto end;
                        }
                        dataStr = new ASCIIEncoding().GetString(data).Trim();
                        if (dataStr.ToLower().StartsWith("error") || dataStr == "")
                        {
                            MessageBox.Show(dataStr, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            goto end;
                        }
                        FileStream fs = File.Create("levels/" + name + ".lvl");
                        fs.Write(data, 0, data.Length);
                        fs.Dispose();

                        data = WEB.DownloadData(downloadUrl + "?id=" + id + "&mode=properties");
                        if (data.Length < 1)
                        {
                            MessageBox.Show("No data was recieved.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            goto end;
                        }
                        dataStr = new ASCIIEncoding().GetString(data).Trim();
                        if (dataStr.ToLower().StartsWith("error"))
                        {
                            MessageBox.Show(dataStr, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            goto end;
                        }
                        fs = File.Create("properties/lavasurvival/" + name + ".properties");
                        fs.Write(data, 0, data.Length);
                        fs.Dispose();

                        MessageBox.Show("Map \"" + name + "\" has been downloaded!", "Complete", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        end:
                        downloadTextTimer.Stop();
                        downloadBtnReset();
                    }
                    catch (Exception ex) { Server.ErrorLog(ex); MessageBox.Show("An unknown error occurred.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
                }
            }));
            downloadThread.Start();

            btnDownload.Enabled = false;
            btnDownload.Text    = "Downloading   ";
            downloadTextTimer.Start();
        }