예제 #1
0
        private void Delete(Session session, Packet packet)
        {
            if (!session.Player.IsInTribe)
            {
                ReplyError(session, packet, Error.TribeIsNull);
                return;
            }

            ITribe tribe = session.Player.Tribesman.Tribe;

            CallbackLock.CallbackLockHandler lockHandler = delegate
            {
                var locks =
                    strongholdManager.StrongholdsForTribe(tribe)
                    .SelectMany(stronghold => stronghold.LockList())
                    .ToList();

                locks.AddRange(tribe.Tribesmen);

                return(locks.ToArray());
            };

            locker.Lock(lockHandler, new object[] {}, tribe).Do(() =>
            {
                if (!session.Player.Tribesman.Tribe.IsOwner(session.Player))
                {
                    ReplyError(session, packet, Error.TribesmanNotAuthorized);
                    return;
                }

                var result = tribeManager.Remove(tribe);
                ReplyWithResult(session, packet, result);
            });
        }
예제 #2
0
        private string Delete(Session session, string[] parms)
        {
            bool   help      = false;
            string tribeName = string.Empty;

            try
            {
                var p = new OptionSet
                {
                    { "?|help|h", v => help = true },
                    { "tribe=", v => tribeName = v.TrimMatchingQuotes() },
                };
                p.Parse(parms);
            }
            catch (Exception)
            {
                help = true;
            }

            if (help || string.IsNullOrEmpty(tribeName))
            {
                return("TribeDelete --name=tribe_name");
            }

            uint tribeId;

            if (!tribeManager.FindTribeId(tribeName, out tribeId))
            {
                return("Tribe not found");
            }

            ITribe tribe;

            if (!world.TryGetObjects(tribeId, out tribe))
            {
                return("Tribe not found");
            }

            CallbackLock.CallbackLockHandler lockHandler = delegate
            {
                var locks = strongholdManager.StrongholdsForTribe(tribe)
                            .SelectMany(stronghold => stronghold.LockList())
                            .ToList();

                locks.AddRange(tribe.Tribesmen);

                return(locks.ToArray());
            };

            locker.Lock(lockHandler, new object[] {}, tribe).Do(() =>
            {
                tribeManager.Remove(tribe);
            });

            return("OK!");
        }