public ActionResult LeaveClan()
        {
            var clan = PerformLeaveClan(Global.AccountID);

            if (clan == null)
            {
                return(Content("This clan is too big to leave"));
            }
            PlanetwarsController.SetPlanetOwners();

            return(RedirectToAction("Index", new { id = clan.ClanID }));
        }
        public ActionResult KickPlayerFromClan(int clanID, int accountID)
        {
            var db   = new ZkDataContext();
            var clan = db.Clans.Single(c => clanID == c.ClanID);

            if (!(Global.Account.HasClanRight(x => x.RightKickPeople) && clan.ClanID == Global.Account.ClanID))
            {
                return(Content("Unauthorized"));
            }
            PerformLeaveClan(accountID);
            db.SubmitChanges();
            PlanetwarsController.SetPlanetOwners();
            return(RedirectToAction("Detail", new { id = clanID }));
        }
Beispiel #3
0
        public static Faction PerformLeaveFaction(int accountID, bool keepClan = false, ZkDataContext db = null)
        {
            if (db == null)
            {
                db = new ZkDataContext();
            }
            Account acc     = db.Accounts.Single(x => x.AccountID == Global.AccountID);
            Faction faction = acc.Faction;

            if (!keepClan && acc.Clan != null)
            {
                ClansController.PerformLeaveClan(Global.AccountID);
            }
            db.AccountRoles.DeleteAllOnSubmit(acc.AccountRolesByAccountID.Where(x => !keepClan || x.ClanID == null));
            acc.ResetQuotas();

            foreach (var ps in acc.PlanetStructures)
            {
                ps.OwnerAccountID = null;
            }

            foreach (var planet in acc.Planets)
            {
                planet.OwnerAccountID = null;
            }

            // delete channel subscription
            if (!acc.IsZeroKAdmin || acc.IsZeroKAdmin)
            {
                var channelSub = db.LobbyChannelSubscriptions.FirstOrDefault(x => x.Account == acc && x.Channel == acc.Faction.Name);
                db.LobbyChannelSubscriptions.DeleteOnSubmit(channelSub);
            }

            db.Events.InsertOnSubmit(Global.CreateEvent("{0} leaves faction {1}", acc, acc.Faction));
            db.SubmitChanges();
            PlanetwarsController.SetPlanetOwners(db);


            using (var db2 = new ZkDataContext())
            {
                Account acc2 = db2.Accounts.Single(x => x.AccountID == Global.AccountID);
                acc2.FactionID = null;
                db2.SubmitAndMergeChanges();

                PlanetwarsController.SetPlanetOwners(db2);
            }
            return(faction);
        }