Ejemplo n.º 1
0
        public ActionResult DownloadSandboxToDfJson(uint id, string userGuid)
        {
            WeenieChange wc = null;

            if (string.IsNullOrWhiteSpace(userGuid))
            {
                // no userGuid specified, assume your own sandbox
                wc = SandboxContentProviderHost.CurrentProvider.GetMySandboxedChange(GetUserToken(), id);
            }
            else
            {
                // validate dev/admin or matches your id
                if (User.IsInRole("Developer") || GetUserGuid() == userGuid)
                {
                    wc = SandboxContentProviderHost.CurrentProvider.GetSandboxedChange(Guid.Parse(userGuid), id);
                }
                else
                {
                    return(new HttpNotFoundResult());
                }
            }

            if (wc == null)
            {
                return(new HttpNotFoundResult());
            }

            JsonSerializerSettings s = new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            };
            string content  = JsonConvert.SerializeObject(wc.Weenie, Formatting.None, s);
            string filename = $"{id}.json";

            return(File(Encoding.UTF8.GetBytes(content), "application/json", filename));
        }
Ejemplo n.º 2
0
        public void DeleteWeenieChange(string changeOwnerGuid, WeenieChange wc)
        {
            string userGuidString = changeOwnerGuid;
            uint   wcid           = wc.Weenie.WeenieId;
            Guid   userGuid       = Guid.Parse(userGuidString);

            string weenieFolder = Path.Combine(_cacheDirectory, "weenies", userGuid.ToString());

            if (!Directory.Exists(weenieFolder))
            {
                Directory.CreateDirectory(weenieFolder);
            }

            if (_weenieCache[userGuid].ContainsKey(wc.Weenie.WeenieId))
            {
                _weenieCache[userGuid].Remove(wc.Weenie.WeenieId);
            }

            string weenieFile = Path.Combine(weenieFolder, $"{wcid}.json");

            if (File.Exists(weenieFile))
            {
                File.Delete(weenieFile);
            }
        }
Ejemplo n.º 3
0
        public ActionResult AddDiscussionComment(string userGuid, int weenieClassId, string discussionComment, string source)
        {
            string currentUser = GetUserGuid();

            if (!(User.IsInRole("Developer") || userGuid == currentUser))
            {
                // only the submitter and developers can comment
                return(RedirectToAction(source));
            }

            List <WeenieChange> temp   = SandboxContentProviderHost.CurrentProvider.GetAllWeenieChanges();
            WeenieChange        change = temp.FirstOrDefault(x => x.UserGuid == userGuid && x.Weenie.WeenieClassId == weenieClassId);

            if (change == null)
            {
                return(RedirectToAction(source));
            }

            change.Discussion.Add(new ChangeDiscussionEntry()
            {
                Comment  = discussionComment,
                Created  = DateTime.Now,
                UserName = GetUserName(),
                UserGuid = Guid.Parse(GetUserGuid())
            });

            SandboxContentProviderHost.CurrentProvider.UpdateWeenieChange(userGuid, change);

            return(RedirectToAction(source));
        }
Ejemplo n.º 4
0
        public ActionResult DownloadSandbox(uint id, string userGuid)
        {
            WeenieChange wc = null;

            if (string.IsNullOrWhiteSpace(userGuid))
            {
                // no userGuid specified, assume your own sandbox
                wc = SandboxContentProviderHost.CurrentProvider.GetMySandboxedChange(GetUserToken(), id);
            }
            else
            {
                // validate dev/admin or matches your id
                if (User.IsInRole("Developer") || GetUserGuid() == userGuid)
                {
                    wc = SandboxContentProviderHost.CurrentProvider.GetSandboxedChange(Guid.Parse(userGuid), id);
                }
                else
                {
                    return(new HttpNotFoundResult());
                }
            }

            if (wc == null)
            {
                return(new HttpNotFoundResult());
            }

            return(DownloadWeenie(wc.Weenie));
        }
Ejemplo n.º 5
0
        public ActionResult CreateSubmission(uint id)
        {
            List <WeenieChange> data = SandboxContentProviderHost.CurrentProvider.GetMyWeenieChanges(GetUserToken());

            WeenieChange theOne = data.FirstOrDefault(wc => wc.Weenie.WeenieId == id);

            if (theOne != null)
            {
                theOne.Submitted      = true;
                theOne.SubmissionTime = DateTime.Now;
                SandboxContentProviderHost.CurrentProvider.UpdateWeenieChange(GetUserGuid(), theOne);

                WeenieSubmissionEvent wse = new WeenieSubmissionEvent();
                wse.SubmittingUserGuid = theOne.UserGuid;
                wse.ChangelogComment   = theOne.Weenie.UserChangeSummary;
                wse.SubmittingUser     = CurrentUser.DisplayName;
                wse.WeenieId           = theOne.Weenie.WeenieId;

                // icon generation data for thumbnail
                wse.ItemType   = theOne.Weenie.ItemType;
                wse.UnderlayId = theOne.Weenie.UnderlayId;
                wse.OverlayId  = theOne.Weenie.OverlayId;
                wse.IconId     = theOne.Weenie.IconId;
                wse.UiEffects  = theOne.Weenie.UIEffects;

                wse.WeenieName     = theOne.Weenie.Name;
                wse.SubmissionTime = DateTimeOffset.Now;
                DiscordController.PostToDiscordAsync(wse);
            }

            return(new EmptyResult()); // RedirectToAction("Sandbox");
        }
Ejemplo n.º 6
0
        public ActionResult RejectChange(string userGuid, int weenieClassId, string rejectionComment)
        {
            List <WeenieChange> temp   = SandboxContentProviderHost.CurrentProvider.GetAllWeenieChanges();
            WeenieChange        change = temp.FirstOrDefault(x => x.Submitted && x.UserGuid == userGuid && x.Weenie.WeenieClassId == weenieClassId);

            BaseModel baseModel = CurrentBaseModel ?? new BaseModel();

            if (change != null)
            {
                change.Submitted = false;
                change.Discussion.Add(new ChangeDiscussionEntry()
                {
                    Comment  = rejectionComment,
                    Created  = DateTime.Now,
                    UserGuid = Guid.Parse(GetUserGuid()),
                    UserName = GetUserName()
                });

                SandboxContentProviderHost.CurrentProvider.UpdateWeenieChange(change.UserGuid, change);
                baseModel.SuccessMessages.Add("Weenie updated.");
                CurrentBaseModel = baseModel;
            }

            return(RedirectToAction("Submissions"));
        }
Ejemplo n.º 7
0
        private bool SaveWeenie(string token, Weenie weenie)
        {
            if (_weenieCache == null)
            {
                throw new ApplicationException("Sandboxing is not configured correctly.  See error logs for details.");
            }

            JsonSerializerSettings settings = new JsonSerializerSettings();

            settings.NullValueHandling = NullValueHandling.Ignore;

            string userGuidString = JwtCookieManager.GetUserGuid(token);
            Guid   userGuid       = Guid.Parse(userGuidString);
            string weenieFolder   = Path.Combine(_cacheDirectory, "weenies", userGuid.ToString());

            if (!Directory.Exists(weenieFolder))
            {
                Directory.CreateDirectory(weenieFolder);
            }

            WeenieChange wc         = null;
            string       weenieFile = Path.Combine(weenieFolder, $"{weenie.WeenieId}.json");

            if (File.Exists(weenieFile))
            {
                // replace the weenie
                wc           = JsonConvert.DeserializeObject <WeenieChange>(File.ReadAllText(weenieFile));
                wc.Weenie    = weenie;
                wc.Submitted = false;
            }
            else
            {
                wc                = new WeenieChange();
                wc.UserGuid       = JwtCookieManager.GetUserGuid(token);
                wc.Weenie         = weenie;
                wc.UserName       = JwtCookieManager.GetUserDisplayName(token);
                wc.SubmissionTime = DateTime.Now;
            }

            string content = JsonConvert.SerializeObject(wc, settings);

            File.WriteAllText(weenieFile, content);

            if (!_weenieCache.ContainsKey(userGuid))
            {
                _weenieCache.TryAdd(userGuid, new Dictionary <uint, string>());
            }

            if (!_weenieCache[userGuid].ContainsKey(weenie.WeenieId))
            {
                _weenieCache[userGuid].Add(weenie.WeenieId, weenieFile);
            }

            return(true);
        }
Ejemplo n.º 8
0
        public WeenieChange GetSandboxedChange(Guid userGuid, uint weenieClassId)
        {
            if (_weenieCache.ContainsKey(userGuid) && _weenieCache[userGuid].ContainsKey(weenieClassId))
            {
                string       fileName = _weenieCache[userGuid][weenieClassId];
                WeenieChange wc       = JsonConvert.DeserializeObject <WeenieChange>(File.ReadAllText(fileName));
                return(wc);
            }

            return(null);
        }
Ejemplo n.º 9
0
        public ActionResult DeleteSandboxWeenie(uint id)
        {
            List <WeenieChange> data = SandboxContentProviderHost.CurrentProvider.GetMyWeenieChanges(GetUserToken());

            WeenieChange theOne = data.FirstOrDefault(wc => wc.Weenie.WeenieClassId == id);

            if (theOne != null)
            {
                SandboxContentProviderHost.CurrentProvider.DeleteWeenieChange(theOne.UserGuid, theOne);
            }

            return(RedirectToAction("Sandbox"));
        }
Ejemplo n.º 10
0
        public WeenieChange GetMySandboxedChange(string token, uint weenieClassId)
        {
            string userGuidString = JwtCookieManager.GetUserGuid(token);
            Guid   userGuid       = Guid.Parse(userGuidString);

            if (_weenieCache.ContainsKey(userGuid) && _weenieCache[userGuid].ContainsKey(weenieClassId))
            {
                string       fileName = _weenieCache[userGuid][weenieClassId];
                WeenieChange wc       = JsonConvert.DeserializeObject <WeenieChange>(File.ReadAllText(fileName));
                return(wc);
            }

            return(null);
        }
Ejemplo n.º 11
0
        public ActionResult WithdrawSubmission(uint id)
        {
            List <WeenieChange> data = SandboxContentProviderHost.CurrentProvider.GetMyWeenieChanges(GetUserToken());

            WeenieChange theOne = data.FirstOrDefault(wc => wc.Weenie.WeenieClassId == id);

            if (theOne != null)
            {
                theOne.Submitted = false;
                SandboxContentProviderHost.CurrentProvider.UpdateWeenieChange(GetUserGuid(), theOne);
            }

            return(RedirectToAction("Sandbox"));
        }
Ejemplo n.º 12
0
        public void UpdateWeenieChange(string changeOwnerGuid, WeenieChange wc)
        {
            string userGuidString = changeOwnerGuid;
            uint   wcid           = wc.Weenie.WeenieId;
            Guid   userGuid       = Guid.Parse(userGuidString);

            string weenieFolder = Path.Combine(_cacheDirectory, "weenies", userGuid.ToString());

            if (!Directory.Exists(weenieFolder))
            {
                Directory.CreateDirectory(weenieFolder);
            }

            string weenieFile = Path.Combine(weenieFolder, $"{wcid}.json");
            string content    = JsonConvert.SerializeObject(wc);

            File.WriteAllText(weenieFile, content);
        }
Ejemplo n.º 13
0
        public Weenie GetWeenie(string token, uint weenieClassId)
        {
            if (token != null)
            {
                string userGuidString = JwtCookieManager.GetUserGuid(token);

                Guid userGuid = Guid.Parse(userGuidString);

                if (_weenieCache != null && _weenieCache.ContainsKey(userGuid) &&
                    _weenieCache[userGuid].ContainsKey(weenieClassId))
                {
                    string       file = _weenieCache[userGuid][weenieClassId];
                    WeenieChange wc   = JsonConvert.DeserializeObject <WeenieChange>(File.ReadAllText(file));
                    return(wc.Weenie);
                }
            }

            return(_backingProvider.GetWeenie(token, weenieClassId));
        }
Ejemplo n.º 14
0
        public ActionResult AcceptChange(uint id, string userGuid)
        {
            List <WeenieChange> temp   = SandboxContentProviderHost.CurrentProvider.GetAllWeenieChanges();
            WeenieChange        change = temp.FirstOrDefault(x => x.Submitted && x.UserGuid == userGuid && x.Weenie.WeenieClassId == id);

            BaseModel baseModel = CurrentBaseModel ?? new BaseModel();

            if (change != null)
            {
                // apply the changelog
                if (!string.IsNullOrWhiteSpace(change.Weenie.UserChangeSummary))
                {
                    change.Weenie.Changelog.Add(new ChangelogEntry()
                    {
                        Author  = change.UserName,
                        Created = change.SubmissionTime,
                        Comment = change.Weenie.UserChangeSummary
                    });
                }

                // this goes to DF.com, and requires the current token, not a substituted one
                SandboxContentProviderHost.CurrentProvider.UpdateWeenieInSource(GetUserToken(), change.Weenie);
                baseModel.SuccessMessages.Add("Weenie updated.");
                CurrentBaseModel = baseModel;

                WeenieAcceptanceEvent wae = new WeenieAcceptanceEvent();
                wae.AcceptanceTime   = DateTimeOffset.Now;
                wae.AcceptingUser    = CurrentUser.DisplayName;
                wae.ChangelogComment = change.Weenie.UserChangeSummary;
                wae.SubmittingUser   = change.UserName;
                wae.WeenieId         = id;
                wae.WeenieName       = change.Weenie.Name;
                DiscordController.PostToDiscordAsync(wae);

                // delete the change request
                SandboxContentProviderHost.CurrentProvider.DeleteWeenieChange(change.UserGuid, change);
            }

            return(RedirectToAction("Submissions"));
        }
Ejemplo n.º 15
0
        public ActionResult CreateSubmission(uint id)
        {
            List <WeenieChange> data = SandboxContentProviderHost.CurrentProvider.GetMyWeenieChanges(GetUserToken());

            WeenieChange theOne = data.FirstOrDefault(wc => wc.Weenie.WeenieClassId == id);

            if (theOne != null)
            {
                theOne.Submitted = true;
                SandboxContentProviderHost.CurrentProvider.UpdateWeenieChange(GetUserGuid(), theOne);

                WeenieSubmissionEvent wse = new WeenieSubmissionEvent();
                wse.SubmittingUserGuid = theOne.UserGuid;
                wse.ChangelogComment   = theOne.Weenie.UserChangeSummary;
                wse.SubmittingUser     = CurrentUser.DisplayName;
                wse.WeenieId           = theOne.Weenie.DataObjectId;
                wse.WeenieName         = theOne.Weenie.Name;
                wse.SubmissionTime     = DateTimeOffset.Now;
                DiscordController.PostToDiscordAsync(wse);
            }

            return(RedirectToAction("Sandbox"));
        }
Ejemplo n.º 16
0
        static void Main(string[] args)
        {
            // original DF directory that has both /weenies and /sandboxes
            string src = @"C:\dev\behemoth\Lifestoned-DF-Server-Data";

            // output new gdle directory
            string dst = @"C:\dev\behemoth\Lifestoned-GDLE-Server-Data";

            var    sourceFiles  = Directory.EnumerateFiles(src + "\\weenies");
            string weenieOutput = dst + @"\weenies";

            if (!Directory.Exists(weenieOutput))
            {
                Directory.CreateDirectory(weenieOutput);
            }

            int       weenieMigrations = 0;
            int       weenieFails      = 0;
            Stopwatch repoMigration    = new Stopwatch();

            repoMigration.Start();

            foreach (string sourceFile in sourceFiles)
            {
                string   content  = File.ReadAllText(sourceFile);
                DfWeenie dfWeenie = JsonConvert.DeserializeObject <DfWeenie>(content);

                Console.WriteLine($"Migrating {dfWeenie.WeenieClassId}, {dfWeenie.Name}...");

                if (dfWeenie.IntProperties?.FirstOrDefault(i => i.IntPropertyId == 9007) == null)
                {
                    Console.WriteLine("... is not possible - missing Weenie Type.");
                    continue;
                }

                try
                {
                    Weenie gdleWeenie = Weenie.ConvertFromWeenie(dfWeenie);
                    string migrated   = JsonConvert.SerializeObject(gdleWeenie);
                    File.WriteAllText(Path.Combine(weenieOutput, gdleWeenie.WeenieClassId + ".json"), migrated);

                    weenieMigrations++;
                    Console.WriteLine($"... done.");
                }
                catch (Exception ex)
                {
                    weenieFails++;
                    Console.WriteLine($"... failed.");
                }
            }
            repoMigration.Stop();

            int       sandboxMigrations  = 0;
            int       sandboxWeenies     = 0;
            int       sandboxWeenieFails = 0;
            Stopwatch sandboxMigration   = new Stopwatch();

            string tmp = Path.Combine(dst, "sandboxes");

            if (!Directory.Exists(tmp))
            {
                Directory.CreateDirectory(tmp);
            }

            tmp = Path.Combine(tmp, "weenies");
            if (!Directory.Exists(tmp))
            {
                Directory.CreateDirectory(tmp);
            }

            sandboxMigration.Start();
            var sandboxes = Directory.EnumerateDirectories(src + @"\sandboxes\weenies");

            foreach (var sandbox in sandboxes)
            {
                sourceFiles = Directory.EnumerateFiles(sandbox);
                foreach (string sourceFile in sourceFiles)
                {
                    string         content       = File.ReadAllText(sourceFile);
                    DfWeenieChange dfChange      = JsonConvert.DeserializeObject <DfWeenieChange>(content);
                    string         sandboxId     = sandbox.Substring(sandbox.LastIndexOf("\\") + 1);
                    string         sandboxFolder = dst + @"\sandboxes\weenies\" + sandboxId;

                    Console.WriteLine($"Migrating sandbox {sandboxId} - Weenie {dfChange.Weenie.WeenieClassId}, {dfChange.Weenie.Name}...");

                    if (dfChange.Weenie.IntProperties?.FirstOrDefault(i => i.IntPropertyId == 9007) == null)
                    {
                        Console.WriteLine("... is not possible - missing Weenie Type.");
                        continue;
                    }

                    if (!Directory.Exists(sandboxFolder))
                    {
                        Directory.CreateDirectory(sandboxFolder);
                    }

                    try
                    {
                        WeenieChange gdleWeenieChange = WeenieChange.ConvertFromDF(dfChange);
                        string       migrated         = JsonConvert.SerializeObject(gdleWeenieChange);
                        File.WriteAllText(Path.Combine(sandboxFolder, gdleWeenieChange.Weenie.WeenieClassId + ".json"), migrated);

                        sandboxWeenies++;
                        Console.WriteLine($"... done.");
                    }
                    catch (Exception ex)
                    {
                        sandboxWeenieFails++;
                        Console.WriteLine($"... failed.");
                    }
                }

                sandboxMigrations++;
            }
            sandboxMigration.Stop();

            Console.WriteLine($"{weenieMigrations} repository weenies migrated successfully ({weenieFails} failed) in {repoMigration.ElapsedMilliseconds} milliseconds.");
            Console.WriteLine($"{sandboxWeenies} weenies in {sandboxMigrations} sandboxes migrated successfully ({sandboxWeenieFails} failed) in {sandboxMigration.ElapsedMilliseconds} milliseconds.");
            Console.WriteLine("Press Enter to continue.");
            Console.ReadLine();
        }
Ejemplo n.º 17
0
        public ActionResult SendChangeToServer()
        {
            DownloadChangeModel model = CurrentDownload;
            WeenieChange        wc    = SandboxContentProviderHost.CurrentProvider.GetSandboxedChange(Guid.Parse(model.FromUserGuid), model.WeenieId);

            if (wc == null)
            {
                return(RedirectToAction("Sandbox"));
            }

            ApiAccountModel user = CurrentUser;

            if (user.SelectedManagedWorldGuid == null)
            {
                if (user.ManagedWorlds?.Count == 1)
                {
                    // use the only server they have
                    model.TargetServerGuid = user.ManagedWorlds[0].ManagedServerGuid.ToString();
                }
                else
                {
                    // user needs to select a managed server
                    return(RedirectToAction("SelectManagedWorld"));
                }
            }
            else
            {
                model.TargetServerGuid = user.SelectedManagedWorldGuid.ToString();
            }

            CurrentDownload = model;

            ManagedServerModel managedWorld = user.ManagedWorlds.FirstOrDefault(w => w.ManagedServerGuid.ToString() == model.TargetServerGuid);

            if (managedWorld == null)
            {
                return(RedirectToAction("SelectManagedWorld"));
            }

            if (string.IsNullOrWhiteSpace(managedWorld.CachedToken))
            {
                return(RedirectToAction("LogIntoManagedWorld"));
            }

            IRestResponse restResponse;

            if (model.PreviewOnly)
            {
                wc.Weenie.ReplaceLiveObjects = true;
                restResponse = ContentProviderHost.ManagedWorldProvider.PreviewWeenie(managedWorld.Address, managedWorld.CachedToken, wc.Weenie);
            }
            else
            {
                restResponse = ContentProviderHost.ManagedWorldProvider.UpdateWeenie(managedWorld.Address, managedWorld.CachedToken, wc.Weenie);
            }

            if (restResponse.StatusCode == System.Net.HttpStatusCode.OK)
            {
                BaseModel baseModel = CurrentBaseModel ?? new BaseModel();
                baseModel.SuccessMessages.Add("Weenie sent to server.");
                CurrentBaseModel = baseModel;
                return(RedirectToAction("Sandbox"));
            }

            if (restResponse.StatusCode == System.Net.HttpStatusCode.Unauthorized)
            {
                model.ErrorMessages.Add("Authorization denied.");
                CurrentDownload = model;
                return(RedirectToAction("LogIntoManagedWorld"));
            }

            model.InfoMessages.Add($"Unexpected result from server: {restResponse.StatusCode} - {restResponse.Content}");
            CurrentDownload = model;
            return(RedirectToAction("LogIntoManagedWorld"));
        }