Esempio n. 1
0
        public ActionResult Rate(int id, int?difficulty, int?rating)
        {
            var db  = new ZkDataContext();
            var rat = db.Ratings.SingleOrDefault(x => x.MissionID == id && x.AccountID == Global.Account.AccountID);

            if (rat == null)
            {
                rat = new Rating();
                db.Ratings.InsertOnSubmit(rat);
            }
            rat.MissionID = id;
            rat.AccountID = Global.Account.AccountID;
            if (difficulty.HasValue)
            {
                rat.Difficulty = difficulty;
            }
            if (rating.HasValue)
            {
                rat.Rating1 = rating;
            }
            db.SubmitChanges();

            var mis = db.Missions.Single(x => x.MissionID == id);

            mis.Rating     = (float?)mis.Ratings.Average(x => x.Rating1);
            mis.Difficulty = (float?)mis.Ratings.Average(x => x.Difficulty);
            db.SubmitChanges();

            return(Content(""));
        }
Esempio n. 2
0
        public ActionResult ChangeFeaturedOrder(int id, float?featuredOrder, string script)
        {
            var db  = new ZkDataContext();
            var mis = db.Missions.SingleOrDefault(x => x.MissionID == id);

            mis.FeaturedOrder = featuredOrder;
            if (mis.IsScriptMission && !string.IsNullOrEmpty(script))
            {
                mis.Script = script;
            }
            db.SubmitChanges();

            var order = 1;

            if (featuredOrder.HasValue)
            {
                foreach (var m in db.Missions.Where(x => x.FeaturedOrder != null).OrderBy(x => x.FeaturedOrder))
                {
                    m.FeaturedOrder = order++;
                }
            }
            db.SubmitChanges();

            return(RedirectToAction("Index"));
        }
Esempio n. 3
0
        public ActionResult PollVote(int pollID)
        {
            var key      = Request.Form.AllKeys.Where(x => !string.IsNullOrEmpty(x)).First(x => x.StartsWith("option"));
            var optionID = Convert.ToInt32(key.Substring(6));

            var db   = new ZkDataContext();
            var poll = Global.Account.ValidPolls(db).Single(x => x.PollID == pollID);

            if (!poll.PollOptions.Any(x => x.OptionID == optionID))
            {
                return(Content("Invalid option"));
            }

            var entry = poll.PollVotes.SingleOrDefault(x => x.AccountID == Global.AccountID);

            if (entry == null)
            {
                entry = new PollVote()
                {
                    PollID = poll.PollID, AccountID = Global.AccountID
                };
                poll.PollVotes.Add(entry);
            }
            entry.OptionID = optionID;

            db.SubmitChanges();
            foreach (var opt in poll.PollOptions)
            {
                opt.Votes = opt.PollVotes.Count(x => x.PollID == poll.PollID);
            }
            db.SubmitChanges();

            return(PartialView("PollView", poll));
        }
        public ActionResult Tag(int id,
                                int?sea,
                                int?hills,
                                bool?assymetrical,
                                string author,
                                bool?supported,
                                float?featuredOrder,
                                bool?isTeams,
                                bool?is1v1,
                                bool?ffa,
                                bool?chickens,
                                int?ffaTeams,
                                bool?special,
                                string springieCommands)
        {
            var db = new ZkDataContext();
            var r  = db.Resources.Single(x => x.ResourceID == id);

            r.TaggedByAccountID = Global.AccountID;
            r.MapIsSpecial      = special;
            r.MapWaterLevel     = sea;
            r.MapHills          = hills;
            r.MapIsAssymetrical = assymetrical;
            r.AuthorName        = author;
            r.MapIsTeams        = isTeams;
            r.MapIs1v1          = is1v1;
            r.MapIsFfa          = ffa;
            r.MapIsChickens     = chickens;
            if (Global.Account.IsZeroKAdmin)
            {
                r.MapIsSupported      = supported;
                r.FeaturedOrder       = featuredOrder;
                r.MapFFAMaxTeams      = ffaTeams;
                r.MapSpringieCommands = springieCommands;
            }
            db.SubmitChanges();
            var order = 1;

            if (featuredOrder.HasValue)
            {
                foreach (var map in db.Resources.Where(x => x.FeaturedOrder != null).OrderBy(x => x.FeaturedOrder))
                {
                    map.FeaturedOrder = order++;
                }
            }
            db.SubmitChanges();
            return(RedirectToAction("Detail", new { id = id }));
        }
Esempio n. 5
0
        public ActionResult Index()
        {
            if (Request[GlobalConst.ASmallCakeCookieName] != null)
            {
                return(RedirectToAction("Index", new {}));
            }
            var db = new ZkDataContext();

            var result = new IndexResult()
            {
                Spotlight    = SpotlightHandler.GetRandom(),
                Top10Players =
                    db.Accounts.Where(x => x.SpringBattlePlayers.Any(y => y.SpringBattle.StartTime > DateTime.UtcNow.AddMonths(-1))).OrderByDescending(
                        x => x.Elo1v1).Take(10)
            };

            result.LobbyStats = AuthServiceClient.GetLobbyStats();
            result.News       = db.News.Where(x => x.Created < DateTime.UtcNow).OrderByDescending(x => x.Created);
            if (Global.Account != null)
            {
                result.Headlines =
                    db.News.Where(
                        x => x.Created <DateTime.UtcNow && x.HeadlineUntil != null && x.HeadlineUntil> DateTime.UtcNow && (Global.Account.LastNewsRead == null || (x.Created > Global.Account.LastNewsRead))).
                    OrderByDescending(x => x.Created);

                if (result.Headlines.Any())
                {
                    db.Accounts.Single(x => x.AccountID == Global.AccountID).LastNewsRead = DateTime.UtcNow;
                    db.SubmitChanges();
                }
            }
            else
            {
                result.Headlines = new List <News>();
            }


            var accessibleThreads = db.ForumThreads.Where(x => x.RestrictedClanID == null || x.RestrictedClanID == Global.ClanID);

            if (!Global.IsAccountAuthorized)
            {
                result.NewThreads = accessibleThreads.OrderByDescending(x => x.LastPost).Take(10).Select(x => new NewThreadEntry()
                {
                    ForumThread = x
                });
            }
            else
            {
                result.NewThreads = (from t in accessibleThreads
                                     let read = t.ForumThreadLastReads.SingleOrDefault(x => x.AccountID == Global.AccountID)
                                                where read == null || t.LastPost > read.LastRead
                                                orderby t.LastPost descending
                                                select new NewThreadEntry {
                    ForumThread = t, WasRead = read != null, WasWritten = read != null && read.LastPosted != null
                }).
                                    Take(10);
            }

            return(View(result));
        }
Esempio n. 6
0
        public static void RecountForumVotes()
        {
            ZkDataContext db       = new ZkDataContext();
            var           accounts = db.Accounts.Where(x => x.ForumTotalUpvotes > 0 || x.ForumTotalDownvotes > 0).ToList();

            foreach (var acc in accounts)
            {
                acc.ForumTotalUpvotes   = 0;
                acc.ForumTotalDownvotes = 0;
            }

            var votes = db.AccountForumVotes.ToList();

            foreach (var vote in votes)
            {
                Account poster = vote.ForumPost.Account;
                int     delta  = vote.Vote;
                if (delta > 0)
                {
                    poster.ForumTotalUpvotes = poster.ForumTotalUpvotes + delta;
                }
                else if (delta < 0)
                {
                    poster.ForumTotalDownvotes = poster.ForumTotalDownvotes - delta;
                }
            }
            db.SubmitChanges();
        }
Esempio n. 7
0
        public static void RemoveTechStructures(bool bRefund, bool removeDefs)
        {
            ZkDataContext db = new ZkDataContext();

            foreach (PlanetStructure structure in db.PlanetStructures.Where(x => x.StructureType.Unlock != null && x.StructureType.Unlock.UnlockType == ZkData.UnlockTypes.Unit))
            {
                db.PlanetStructures.DeleteOnSubmit(structure);
                if (bRefund)
                {
                    var refund = structure.StructureType.Cost;
                    if (structure.Account != null)
                    {
                        structure.Account.ProduceMetal(refund);
                    }
                    else
                    {
                        structure.Planet.Faction.ProduceMetal(refund);
                    }
                }
            }
            if (removeDefs)
            {
                foreach (StructureType structType in db.StructureTypes.Where(x => x.Unlock != null && x.Unlock.UnlockType == ZkData.UnlockTypes.Unit))
                {
                    db.StructureTypes.DeleteOnSubmit(structType);
                }
            }
            db.SubmitChanges();
        }
Esempio n. 8
0
        public ActionResult JoinFaction(int id)
        {
            if (Global.Account.FactionID != null)
            {
                return(Content("Already in faction"));
            }
            if (Global.Account.Clan != null && Global.Account.Clan.FactionID != id)
            {
                return(Content("Must leave current clan first"));
            }
            var     db  = new ZkDataContext();
            Account acc = db.Accounts.Single(x => x.AccountID == Global.AccountID);

            acc.FactionID = id;

            Faction faction = db.Factions.Single(x => x.FactionID == id);

            if (faction.IsDeleted && !(Global.Account.Clan != null && Global.Account.Clan.FactionID == id))
            {
                throw new ApplicationException("Cannot join deleted faction");
            }
            db.Events.InsertOnSubmit(Global.CreateEvent("{0} joins {1}", acc, faction));
            db.SubmitChanges();
            return(RedirectToAction("Index", "Factions"));
        }
Esempio n. 9
0
        protected void btnUpdateClick(object sender, EventArgs e)
        {
            if (!Global.Account.IsZeroKAdmin)
            {
                throw new ApplicationException("You are not an admin!");
            }
            var data = (List <StructureType>) new DataContractSerializer(typeof(List <StructureType>)).ReadObject(XmlReader.Create(new StringReader(tbData.Text)));

            var db2 = new ZkDataContext();
            //using (var scope = new TransactionScope())
            {
                using (var db = new ZkDataContext())
                {
                    // first pass insert structures but without interdependencies links
                    foreach (var s in data)
                    {
                        var org = db2.StructureTypes.SingleOrDefault(x => x.StructureTypeID == s.StructureTypeID);
                        if (org != null)
                        {
                            db.StructureTypes.Attach(s, org);
                        }
                        else
                        {
                            db.StructureTypes.InsertOnSubmit(s);
                        }
                    }

                    db.SubmitChanges();
                }

                //scope.Complete();
            }
        }
 void client_ChannelUserAdded(object sender, TasEventArgs e)
 {
     Task.Factory.StartNew(() =>
     {
         try
         {
             var name = e.ServerParams[1];
             var chan = e.ServerParams[0];
             List <LobbyMessage> messages;
             using (var db = new ZkDataContext())
             {
                 messages = db.LobbyMessages.Where(x => x.TargetName == name && x.Channel == chan).ToList();
                 db.LobbyMessages.DeleteAllOnSubmit(messages);
                 db.SubmitChanges();
             }
             foreach (var m in messages)
             {
                 var text = string.Format("!pm|{0}|{1}|{2}|{3}", m.Channel, m.SourceName, m.Created.ToString(CultureInfo.InvariantCulture), m.Message);
                 client.Say(TasClient.SayPlace.User, name, text, false);
                 Thread.Sleep(MessageDelay);
             }
         }
         catch (Exception ex)
         {
             Trace.TraceError("Error adding user: {0}", ex);
         }
     });
 }
Esempio n. 11
0
        static void ImportSpringiePlayers()
        {
            var db = new ZkDataContext();

            foreach (var line in File.ReadLines("springie.csv").AsParallel())
            {
                var m = Regex.Match(line, "\"[0-9]+\";\"([^\"]+)\";\"[0-9]+\";\"[0-9]+\";\"([^\"]+)\";\"([^\"]+)\"");
                if (m.Success)
                {
                    string name = m.Groups[1].Value;
                    double elo  = double.Parse(m.Groups[2].Value, CultureInfo.InvariantCulture);
                    double w    = double.Parse(m.Groups[3].Value, CultureInfo.InvariantCulture);
                    if (elo != 1500 || w != 1)
                    {
                        foreach (var a in db.Accounts.Where(x => x.Name == name))
                        {
                            a.Elo       = (float)elo;
                            a.EloWeight = (float)w;
                        }
                        Console.WriteLine(name);
                    }
                }
            }
            db.SubmitChanges();
        }
        public void StoreBoxes(BattleContext context, List <RectInfo> rects)
        {
            var db          = new ZkDataContext();
            var map         = db.Resources.Single(x => x.InternalName == context.Map && x.TypeID == ResourceType.Map);
            var orgCommands = map.MapSpringieCommands;
            var newCommands = "!clearbox\n";

            foreach (var r in rects.OrderBy(x => x.Number))
            {
                if (r.X != 0 || r.Y != 0 || r.Width != 0 || r.Height != 0)
                {
                    newCommands += string.Format("!addbox {0} {1} {2} {3} {4}\n", r.X, r.Y, r.Width, r.Height, r.Number + 1);
                }
            }

            if (!string.IsNullOrEmpty(orgCommands))
            {
                foreach (var line in orgCommands.Lines().Where(x => !string.IsNullOrEmpty(x)))
                {
                    if (!line.StartsWith("!addbox") && !line.StartsWith("!clearbox") && !line.StartsWith("!corners") && !line.StartsWith("!split "))
                    {
                        newCommands += line + "\n";
                    }
                }
            }
            map.MapSpringieCommands = newCommands;
            db.SubmitChanges();
        }
        public ActionResult ChangePermissions(int accountID, int adminAccountID, int springieLevel, bool zkAdmin, bool vpnException)
        {
            var     db       = new ZkDataContext();
            Account acc      = db.Accounts.Single(x => x.AccountID == accountID);
            Account adminAcc = db.Accounts.Single(x => x.AccountID == adminAccountID);

            Global.Server.GhostChanSay(GlobalConst.ModeratorChannel, string.Format("Permissions changed for {0} {1} by {2}", acc.Name, Url.Action("Detail", "Users", new { id = acc.AccountID }, "http"), adminAcc.Name));
            if (acc.SpringieLevel != springieLevel)
            {
                Global.Server.GhostChanSay(GlobalConst.ModeratorChannel, string.Format(" - Springie rights: {0} -> {1}", acc.SpringieLevel, springieLevel));
                acc.SpringieLevel = springieLevel;
            }
            if (acc.IsZeroKAdmin != zkAdmin)
            {
                //reset chat priviledges to 2 if removing adminhood; remove NW subsciption to admin channel
                // FIXME needs to also terminate forbidden clan/faction subscriptions
                if (zkAdmin == false)
                {
                    Global.Server.GhostChanSay(GlobalConst.ModeratorChannel, string.Format(" - Springie rights: {0} -> {1}", acc.SpringieLevel, 2));
                    acc.SpringieLevel = 2;
                }
                Global.Server.GhostChanSay(GlobalConst.ModeratorChannel, string.Format(" - Admin status: {0} -> {1}", acc.IsZeroKAdmin, zkAdmin));
                acc.IsZeroKAdmin = zkAdmin;
            }
            if (acc.HasVpnException != vpnException)
            {
                Global.Server.GhostChanSay(GlobalConst.ModeratorChannel, string.Format(" - VPN exception: {0} -> {1}", acc.HasVpnException, vpnException));
                acc.HasVpnException = vpnException;
            }
            db.SubmitChanges();

            Global.Server.PublishAccountUpdate(acc);

            return(RedirectToAction("Detail", "Users", new { id = acc.AccountID }));
        }
        public ActionResult JoinClan(int id, string password)
        {
            var db   = new ZkDataContext();
            var clan = db.Clans.Single(x => x.ClanID == id && !x.IsDeleted);

            if (clan.CanJoin(Global.Account))
            {
                if (!string.IsNullOrEmpty(clan.Password) && clan.Password != password)
                {
                    return(View(clan.ClanID));
                }
                else
                {
                    var acc = db.Accounts.Single(x => x.AccountID == Global.AccountID);
                    acc.ClanID    = clan.ClanID;
                    acc.FactionID = clan.FactionID;
                    db.Events.InsertOnSubmit(Global.CreateEvent("{0} joins clan {1}", acc, clan));
                    db.SubmitChanges();
                    return(RedirectToAction("Detail", new { id = clan.ClanID }));
                }
            }
            else
            {
                return(Content("You cannot join this clan - its full, or has password, or is different faction"));
            }
        }
        public ActionResult CancelVotePost(int forumPostID)
        {
            var db = new ZkDataContext();
            AccountForumVote existingVote = db.AccountForumVotes.SingleOrDefault(x => x.ForumPostID == forumPostID && x.AccountID == Global.AccountID);

            if (existingVote == null)
            {
                return(Content("No existing vote to remove"));
            }

            ForumPost post   = db.ForumPosts.First(x => x.ForumPostID == forumPostID);
            Account   author = post.Account;

            int delta = existingVote.Vote;

            // reverse vote effects
            if (delta > 0)
            {
                author.ForumTotalUpvotes = author.ForumTotalUpvotes - delta;
                post.Upvotes             = post.Upvotes - delta;
            }
            else if (delta < 0)
            {
                author.ForumTotalDownvotes = author.ForumTotalDownvotes + delta;
                post.Downvotes             = post.Downvotes + delta;
            }
            db.AccountForumVotes.DeleteOnSubmit(existingVote);

            db.SubmitChanges();

            return(RedirectToAction("Thread", new { id = post.ForumThreadID, postID = forumPostID }));
        }
        public ActionResult ChangePermissions(int accountID, int adminAccountID, int springieLevel, bool zkAdmin, bool vpnException)
        {
            var     db       = new ZkDataContext();
            Account acc      = db.Accounts.Single(x => x.AccountID == accountID);
            Account adminAcc = db.Accounts.Single(x => x.AccountID == adminAccountID);

            Global.Nightwatch.Tas.Say(SayPlace.Channel, AuthService.ModeratorChannel, string.Format("Permissions changed for {0} {1} by {2}", acc.Name, Url.Action("Detail", "Users", new { id = acc.AccountID }, "http"), adminAcc.Name), true);
            if (acc.SpringieLevel != springieLevel)
            {
                Global.Nightwatch.Tas.Say(SayPlace.Channel, AuthService.ModeratorChannel, string.Format(" - Springie rights: {0} -> {1}", acc.SpringieLevel, springieLevel), true);
                acc.SpringieLevel = springieLevel;
            }
            if (acc.IsZeroKAdmin != zkAdmin)
            {
                //reset chat priviledges to 2 if removing adminhood
                if (zkAdmin == false)
                {
                    Global.Nightwatch.Tas.Say(SayPlace.Channel, AuthService.ModeratorChannel, string.Format(" - Springie rights: {0} -> {1}", acc.SpringieLevel, 2), true);
                    acc.SpringieLevel = 2;
                }
                Global.Nightwatch.Tas.Say(SayPlace.Channel, AuthService.ModeratorChannel, string.Format(" - Admin status: {0} -> {1}", acc.IsZeroKAdmin, zkAdmin), true);
                acc.IsZeroKAdmin = zkAdmin;
            }
            if (acc.HasVpnException != vpnException)
            {
                Global.Nightwatch.Tas.Say(SayPlace.Channel, AuthService.ModeratorChannel, string.Format(" - VPN exception: {0} -> {1}", acc.HasVpnException, vpnException), true);
                acc.HasVpnException = vpnException;
            }
            db.SubmitChanges();
            Global.Nightwatch.Tas.Extensions.PublishAccountData(acc);

            return(RedirectToAction("Detail", "Users", new { id = acc.AccountID }));
        }
Esempio n. 17
0
        public void SendLobbyMessage(Account account, string text)
        {
            User ex;

            if (client.ExistingUsers.TryGetValue(account.Name, out ex))
            {
                client.Say(SayPlace.User, account.Name, text, false);
            }
            else
            {
                var message = new LobbyMessage
                {
                    SourceLobbyID = client.MyUser != null ? client.MyUser.AccountID : 0,
                    SourceName    = client.UserName,
                    Created       = DateTime.UtcNow,
                    Message       = text,
                    TargetName    = account.Name,
                    TargetLobbyID = account.AccountID
                };
                using (var db = new ZkDataContext())
                {
                    db.LobbyMessages.InsertOnSubmit(message);
                    db.SubmitChanges();
                }
            }
        }
        void client_UserAdded(object sender, User user)
        {
            Task.Factory.StartNew(() =>
            {
                try
                {
                    List <LobbyMessage> messages;
                    using (var db = new ZkDataContext())

                    {
                        messages = db.LobbyMessages.Where(x => (x.TargetLobbyID == user.AccountID || x.TargetName == user.Name) && x.Channel == null).ToList();
                        db.LobbyMessages.DeleteAllOnSubmit(messages);
                        db.SubmitChanges();
                    }
                    foreach (var m in messages)
                    {
                        var text = string.Format("!pm|{0}|{1}|{2}|{3}", m.Channel, m.SourceName, m.Created.ToString(CultureInfo.InvariantCulture), m.Message);
                        client.Say(SayPlace.User, user.Name, text, false);
                        Thread.Sleep(MessageDelay);
                    }
                }

                catch (Exception ex)
                {
                    Trace.TraceError("Error sending PM:{0}", ex);
                }
            });
        }
 void client_ChannelUserAdded(object sender, ChannelUserInfo e)
 {
     Task.Run(async() =>
     {
         try
         {
             var chan = e.Channel.Name;
             List <LobbyMessage> messages;
             foreach (var user in e.Users)
             {
                 using (var db = new ZkDataContext()) {
                     messages = db.LobbyMessages.Where(x => x.TargetName == user.Name && x.Channel == chan).ToList();
                     db.LobbyMessages.DeleteAllOnSubmit(messages);
                     db.SubmitChanges();
                 }
                 foreach (var m in messages)
                 {
                     var text = string.Format("!pm|{0}|{1}|{2}|{3}", m.Channel, m.SourceName, m.Created.ToString(CultureInfo.InvariantCulture), m.Message);
                     await client.Say(SayPlace.User, user.Name, text, false);
                     await Task.Delay(MessageDelay);
                 }
             }
         }
         catch (Exception ex)
         {
             Trace.TraceError("Error adding user: {0}", ex);
         }
     });
 }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (!Global.Account.IsZeroKAdmin)
            {
                throw new ApplicationException("You are not an admin!");
            }
            var db     = new ZkDataContext();
            var unlock = new Unlock()
            {
                Code             = tbCode.Text,
                Name             = tbName.Text,
                XpCost           = int.Parse(tbXpCost.Text),
                Description      = tbDescription.Text,
                NeededLevel      = int.Parse(tbMinLevel.Text),
                RequiredUnlockID = GetInt(tbPreq.Text),
                UnlockType       = (UnlockTypes)int.Parse(ddType.SelectedValue),
                MorphLevel       = GetInt(tbMorphLevel.Text) ?? 0,
                MaxModuleCount   = GetInt(tbMaxCount.Text) ?? 1,
                LimitForChassis  = tbChassisLimit.Text,
                MetalCost        = GetInt(tbMetalCost.Text),
                MetalCostMorph2  = GetInt(tbMorph2.Text),
                MetalCostMorph3  = GetInt(tbMorph3.Text),
                MetalCostMorph4  = GetInt(tbMorph4.Text),
                MetalCostMorph5  = GetInt(tbMorph5.Text)
            };

            db.Unlocks.InsertOnSubmit(unlock);
            db.SubmitChanges();
            GridView1.DataBind();
        }
        public ActionResult Index(int?campaignID = null)
        {
            var db = new ZkDataContext();

            Campaign camp;

            if (campaignID != null)
            {
                camp = db.Campaigns.Single(x => x.CampaignID == campaignID);
            }
            else
            {
                camp = db.Campaigns.Single(x => x.CampaignID == 1);
            }
            string cachePath = Server.MapPath(string.Format("/img/galaxies/campaign/render_{0}.jpg", camp.CampaignID));

            // /*
            if (camp.IsDirty || !System.IO.File.Exists(cachePath))
            {
                using (Bitmap im = GenerateGalaxyImage(camp.CampaignID)) {
                    im.SaveJpeg(cachePath, 85);
                    camp.IsDirty   = false;
                    camp.MapWidth  = im.Width;
                    camp.MapHeight = im.Height;
                    db.SubmitChanges();
                }
            }
            // */
            return(View("CampaignMap", camp));
        }
Esempio n. 22
0
        public static void MassBan(string name, int startIndex, int endIndex, string reason, int banHours, bool banSite = false, bool banLobby = true, bool banIP = false, bool banID = false)
        {
            ZkDataContext db = new ZkDataContext();

            for (int i = startIndex; i <= endIndex; i++)
            {
                Account acc = db.Accounts.FirstOrDefault(x => x.Name == name + i);
                if (acc != null)
                {
                    int?   userID = banID ? (int?)acc.AccountUserIDs.OrderByDescending(x => x.LastLogin).FirstOrDefault().UserID : null;
                    string userIP = banIP ? acc.AccountIPs.OrderByDescending(x => x.LastLogin).FirstOrDefault().IP : null;
                    System.Console.WriteLine(acc.Name, userID, userIP);
                    Punishment punishment = new Punishment
                    {
                        Time             = DateTime.UtcNow,
                        Reason           = reason,
                        BanSite          = banSite,
                        BanLobby         = banLobby,
                        BanExpires       = DateTime.UtcNow.AddHours(banHours),
                        BanIP            = userIP,
                        CreatedAccountID = 5806,
                        UserID           = userID,
                    };
                    acc.PunishmentsByAccountID.Add(punishment);
                }
            }
            db.SubmitChanges();
        }
        public ActionResult Punish(int accountID,
                                   string reason,
                                   bool deleteXP,
                                   bool deleteInfluence,
                                   bool banMute,
                                   bool banCommanders,
                                   bool banSite,
                                   bool banLobby,
                                   bool banUnlocks,
                                   bool banForum,
                                   bool setRightsToZero,
                                   string banIP,
                                   long?banUserID,
                                   double banHours)
        {
            ZkDataContext db  = new ZkDataContext();
            Account       acc = db.Accounts.Single(x => x.AccountID == accountID);

            if (banHours > MaxBanHours)
            {
                banHours = MaxBanHours;                         // todo show some notification
            }
            Punishment punishment = new Punishment
            {
                Time             = DateTime.UtcNow,
                Reason           = reason,
                BanMute          = banMute,
                BanCommanders    = banCommanders,
                BanSite          = banSite,
                BanLobby         = banLobby,
                BanExpires       = DateTime.UtcNow.AddHours(banHours),
                BanUnlocks       = banUnlocks,
                BanIP            = banIP,
                BanForum         = banForum,
                SetRightsToZero  = setRightsToZero,
                DeleteXP         = deleteXP,
                DeleteInfluence  = deleteInfluence,
                CreatedAccountID = Global.AccountID,
                UserID           = banUserID
            };

            acc.PunishmentsByAccountID.Add(punishment);
            db.SubmitChanges();

            // notify lobby of changes and post log message
            try
            {
                Global.Server.KickFromServer(Global.Account.Name, acc.Name, reason);

                Global.Server.GhostChanSay(GlobalConst.ModeratorChannel, string.Format("New penalty for {0} {1}  ", acc.Name, Url.Action("Detail", "Users", new { id = acc.AccountID }, "http")));
                Global.Server.GhostChanSay(GlobalConst.ModeratorChannel, string.Format("Reason: {0} ", reason));
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());
                Global.Server.GhostChanSay(GlobalConst.ModeratorChannel, ex.ToString());
            }
            return(RedirectToAction("Detail", new { id = accountID }));
        }
Esempio n. 24
0
        public static void RandomizePlanetOwners(int galaxyID, double proportionNeutral = 0.25)
        {
            using (var db = new ZkDataContext())
            {
                System.Console.WriteLine(String.Format("Randomly assigning planets in galaxy {0} to factions", galaxyID));
                var gal         = db.Galaxies.Single(x => x.GalaxyID == galaxyID);
                var factions    = db.Factions.Where(x => !x.IsDeleted).ToList();
                int numFactions = factions.ToList().Count;
                int index       = 1;

                List <int> forceNeutral = new List <int>(new int[] { 3930, 3964 });

                List <List <Account> > accountsByFaction = new List <List <Account> >();
                foreach (Faction f in factions)
                {
                    accountsByFaction.Add(f.Accounts.Where(x => x.LastLogin > DateTime.UtcNow.AddDays(-15)).OrderByDescending(x => x.EloPw).ToList());
                }
                List <Account> alreadyAssigned = new List <Account>();

                Random rng = new Random();
                //List<Account> alreadyHavePlanets = new List<Account>;

                foreach (var p in gal.Planets)
                {
                    double rand    = rng.NextDouble();
                    bool   neutral = false;
                    foreach (int otherPlanet in forceNeutral)
                    {
                        if (IsPlanetNeighbour(p.PlanetID, otherPlanet) > 0)
                        {
                            neutral = true;
                        }
                    }
                    if (neutral || rand < proportionNeutral)
                    {
                        p.Faction = null;
                        p.Account = null;
                        System.Console.WriteLine(String.Format("\tPlanet {0} is neutral", p.Name));
                    }

                    else
                    {
                        Faction faction = factions.Where(x => x.FactionID == index).FirstOrDefault();
                        Account acc     = accountsByFaction[index - 1].FirstOrDefault(x => !alreadyAssigned.Contains(x));
                        p.Faction = faction;
                        p.Account = acc;
                        index++;
                        if (index > numFactions)
                        {
                            index = 1;
                        }
                        alreadyAssigned.Add(acc);
                        System.Console.WriteLine(String.Format("\tGiving planet {0} to {1} of {2}", p.Name, acc, p.Faction));
                    }
                }
                gal.IsDirty = true;
                db.SubmitChanges();
            }
        }
Esempio n. 25
0
        public ActionResult Delete(int id)
        {
            var db = new ZkDataContext();

            db.Missions.First(x => x.MissionID == id).IsDeleted = true;
            db.SubmitChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 26
0
        /// <summary>
        /// Reset all the user's unlocks
        /// </summary>
        public ActionResult Reset()
        {
            var db = new ZkDataContext();

            db.AccountUnlocks.DeleteAllOnSubmit(db.AccountUnlocks.Where(x => x.AccountID == Global.AccountID));
            db.SubmitChanges();
            return(RedirectToAction("UnlockList"));
        }
        public Mission GetMission(string missionName)
        {
            var db   = new ZkDataContext();
            var prev = db.Missions.Where(x => x.Name == missionName).Include(x => x.Mutator).SingleOrDefault();

            db.SubmitChanges();
            return(prev);
        }
        public Mission GetMissionByID(int missionID)
        {
            var db   = new ZkDataContext();
            var prev = db.Missions.Where(x => x.MissionID == missionID).Include(x => x.Mutator).SingleOrDefault();

            db.SubmitChanges();
            return(prev);
        }
        protected void LinqDataSource1_Deleting(object sender, LinqDataSourceDeleteEventArgs e)
        {
            var db     = new ZkDataContext();
            var unlock = db.Unlocks.Single(x => x.UnlockID == ((Unlock)e.OriginalObject).UnlockID);

            db.CommanderModules.DeleteAllOnSubmit(db.CommanderModules.Where(x => x.ModuleUnlockID == unlock.UnlockID));
            db.Unlocks.DeleteOnSubmit(unlock);
            db.SubmitChanges();
        }
        public ActionResult RemovePlanetIcon(int resourceID)
        {
            var db  = new ZkDataContext();
            var res = db.Resources.Single(x => x.ResourceID == resourceID);

            res.MapPlanetWarsIcon = null;
            db.SubmitChanges();
            return(RedirectToAction("Detail", new { id = res.ResourceID }));
        }