Ejemplo n.º 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);
            });
        }
Ejemplo n.º 2
0
        private void ListAll(Session session, Packet packet)
        {
            locker.Lock(session.Player).Do(() =>
            {
                if (!session.Player.IsInTribe)
                {
                    ReplyError(session, packet, Error.TribesmanNotPartOfTribe);
                    return;
                }

                var reply       = new Packet(packet);
                var strongholds = strongholdManager.StrongholdsForTribe(session.Player.Tribesman.Tribe).ToList();
                reply.AddInt16((short)strongholds.Count);
                foreach (var stronghold in strongholds)
                {
                    reply.AddUInt32(stronghold.ObjectId);
                    reply.AddString(stronghold.Name);
                    reply.AddByte(stronghold.Lvl);
                    reply.AddUInt32(stronghold.PrimaryPosition.X);
                    reply.AddUInt32(stronghold.PrimaryPosition.Y);
                }

                session.Write(reply);
            });
        }
Ejemplo n.º 3
0
        public IEnumerable <Tribe.IncomingListItem> GetIncomingList(ITribe tribe)
        {
            var incomingTroops = (from tribesmen in tribe.Tribesmen
                                  from city in tribesmen.Player.GetCityList()
                                  from notification in city.Notifications
                                  where
                                  notification.Action is IActionTime &&
                                  notification.Action.Category == ActionCategory.Attack &&
                                  notification.GameObject.City != city && notification.Subscriptions.Count > 0
                                  select
                                  new Tribe.IncomingListItem
            {
                Source = notification.GameObject.City,
                Target = city,
                EndTime = ((IActionTime)notification.Action).EndTime
            }).ToList();

            incomingTroops.AddRange(from stronghold in strongholdManager.StrongholdsForTribe(tribe)
                                    from notification in stronghold.Notifications
                                    where
                                    notification.Action is IActionTime &&
                                    notification.Action.Category == ActionCategory.Attack &&
                                    notification.Subscriptions.Count > 0 &&
                                    (!notification.GameObject.City.Owner.IsInTribe ||
                                     notification.GameObject.City.Owner.Tribesman.Tribe != tribe)
                                    select
                                    new Tribe.IncomingListItem
            {
                Source  = notification.GameObject.City,
                Target  = stronghold,
                EndTime = ((IActionTime)notification.Action).EndTime
            });

            return(incomingTroops.OrderBy(i => i.EndTime));
        }
Ejemplo n.º 4
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!");
        }
Ejemplo n.º 5
0
        public void Remove(Session session, Packet packet)
        {
            uint playerId;

            try
            {
                playerId = packet.GetUInt32();
            }
            catch (Exception)
            {
                ReplyError(session, packet, Error.Unexpected);
                return;
            }

            IPlayer playerToBeRemoved;

            if (!world.TryGetObjects(playerId, out playerToBeRemoved))
            {
                ReplyError(session, packet, Error.PlayerNotFound);
                return;
            }

            CallbackLock.CallbackLockHandler lockHandler = delegate
            {
                var tribe = session.Player.IsInTribe ? session.Player.Tribesman.Tribe : null;

                if (tribe == null)
                {
                    return(new ILockable[] {});
                }

                var locks =
                    strongholdManager.StrongholdsForTribe(tribe)
                    .SelectMany(stronghold => stronghold.LockList())
                    .ToList();

                locks.Add(tribe);

                return(locks.ToArray());
            };

            locker.Lock(lockHandler, new object[] {}, session.Player, playerToBeRemoved).Do(() =>
            {
                if (!session.Player.IsInTribe || !playerToBeRemoved.IsInTribe ||
                    playerToBeRemoved.Tribesman.Tribe != session.Player.Tribesman.Tribe)
                {
                    ReplyError(session, packet, Error.TribeIsNull);
                    return;
                }

                ITribe tribe = session.Player.Tribesman.Tribe;
                if (!tribe.HasRight(session.Player.PlayerId, TribePermission.Kick))
                {
                    ReplyError(session, packet, Error.TribesmanNotAuthorized);
                    return;
                }

                if (tribe.IsOwner(playerToBeRemoved))
                {
                    ReplyError(session, packet, Error.TribesmanIsOwner);
                    return;
                }

                var result = session.Player.Tribesman.Tribe.KickTribesman(playerToBeRemoved, session.Player);

                ReplyWithResult(session, packet, result);
            });
        }
Ejemplo n.º 6
0
        public static void AddTribeInfo(IStrongholdManager strongholdManager,
                                        ITribeManager tribeManager,
                                        Session session,
                                        ITribe tribe,
                                        Packet packet)
        {
            if (session.Player.IsInTribe && tribe.Id == session.Player.Tribesman.Tribe.Id)
            {
                packet.AddByte(1);
                packet.AddUInt32(tribe.Id);
                packet.AddUInt32(tribe.Owner.PlayerId);
                packet.AddByte(tribe.Level);
                packet.AddString(tribe.Name);
                packet.AddString(tribe.Description);
                packet.AddString(tribe.PublicDescription);
                packet.AddFloat((float)tribe.VictoryPoint);
                packet.AddUInt32(UnixDateTime.DateTimeToUnix(tribe.Created));
                AddToPacket(tribe.Resource, packet);

                packet.AddInt16((short)tribe.Count);
                foreach (var tribesman in tribe.Tribesmen)
                {
                    packet.AddUInt32(tribesman.Player.PlayerId);
                    packet.AddString(tribesman.Player.Name);
                    packet.AddInt32(tribesman.Player.GetCityCount());
                    packet.AddByte(tribesman.Rank.Id);
                    packet.AddUInt32(tribesman.Player.IsLoggedIn ? 0 : UnixDateTime.DateTimeToUnix(tribesman.Player.LastLogin));
                    AddToPacket(tribesman.Contribution, packet);
                }

                // Incoming List
                var incomingList = tribeManager.GetIncomingList(tribe).ToList();
                packet.AddInt16((short)incomingList.Count());
                foreach (var incoming in incomingList)
                {
                    AddToPacket(incoming.Target, packet);
                    AddToPacket(incoming.Source, packet);

                    packet.AddUInt32(UnixDateTime.DateTimeToUnix(incoming.EndTime.ToUniversalTime()));
                }

                // Assignment List
                packet.AddInt16(tribe.AssignmentCount);
                foreach (var assignment in tribe.Assignments)
                {
                    AddToPacket(assignment, packet);
                }

                // Strongholds
                var strongholds = strongholdManager.StrongholdsForTribe(tribe).ToList();
                packet.AddInt16((short)strongholds.Count);
                foreach (var stronghold in strongholds)
                {
                    packet.AddUInt32(stronghold.ObjectId);
                    packet.AddString(stronghold.Name);
                    packet.AddByte((byte)stronghold.StrongholdState);
                    packet.AddByte(stronghold.Lvl);
                    packet.AddFloat((float)stronghold.Gate);
                    packet.AddInt32(stronghold.GateMax);
                    packet.AddUInt32(stronghold.PrimaryPosition.X);
                    packet.AddUInt32(stronghold.PrimaryPosition.Y);
                    packet.AddInt32(stronghold.Troops.StationedHere().Sum(x => x.Upkeep));
                    packet.AddFloat((float)stronghold.VictoryPointRate);
                    packet.AddUInt32(UnixDateTime.DateTimeToUnix(stronghold.DateOccupied.ToUniversalTime()));
                    packet.AddUInt32(stronghold.GateOpenTo == null ? 0 : stronghold.GateOpenTo.Id);
                    packet.AddString(stronghold.GateOpenTo == null ? string.Empty : stronghold.GateOpenTo.Name);
                    if (stronghold.GateBattle != null)
                    {
                        packet.AddByte(1);
                        packet.AddUInt32(stronghold.GateBattle.BattleId);
                    }
                    else if (stronghold.MainBattle != null)
                    {
                        packet.AddByte(2);
                        packet.AddUInt32(stronghold.MainBattle.BattleId);
                    }
                    else
                    {
                        packet.AddByte(0);
                    }
                }

                // Attackable Strongholds
                strongholds = strongholdManager.OpenStrongholdsForTribe(tribe).ToList();
                packet.AddInt16((short)strongholds.Count);
                foreach (var stronghold in strongholds)
                {
                    packet.AddUInt32(stronghold.ObjectId);
                    packet.AddString(stronghold.Name);
                    packet.AddUInt32(stronghold.Tribe == null ? 0 : stronghold.Tribe.Id);
                    packet.AddString(stronghold.Tribe == null ? string.Empty : stronghold.Tribe.Name);
                    packet.AddByte((byte)stronghold.StrongholdState);
                    packet.AddByte(stronghold.Lvl);
                    packet.AddUInt32(stronghold.PrimaryPosition.X);
                    packet.AddUInt32(stronghold.PrimaryPosition.Y);
                    if (stronghold.GateBattle != null)
                    {
                        packet.AddByte(1);
                        packet.AddUInt32(stronghold.GateBattle.BattleId);
                    }
                    else if (stronghold.MainBattle != null)
                    {
                        packet.AddByte(2);
                        packet.AddUInt32(stronghold.MainBattle.BattleId);
                    }
                    else
                    {
                        packet.AddByte(0);
                    }
                }
            }
            else
            {
                packet.AddByte(0);
                packet.AddUInt32(tribe.Id);
                packet.AddString(tribe.Name);
                packet.AddString(tribe.PublicDescription);
                packet.AddByte(tribe.Level);
                packet.AddUInt32(UnixDateTime.DateTimeToUnix(tribe.Created));

                packet.AddByte((byte)tribe.Ranks.Count());
                foreach (var rank in tribe.Ranks)
                {
                    packet.AddString(rank.Name);
                }

                packet.AddInt16((short)tribe.Count);
                foreach (var tribesman in tribe.Tribesmen)
                {
                    packet.AddUInt32(tribesman.Player.PlayerId);
                    packet.AddString(tribesman.Player.Name);
                    packet.AddInt32(tribesman.Player.GetCityCount());
                    packet.AddByte(tribesman.Rank.Id);
                }

                var strongholds = strongholdManager.StrongholdsForTribe(tribe).ToList();
                packet.AddInt16((short)strongholds.Count);
                foreach (var stronghold in strongholds)
                {
                    packet.AddUInt32(stronghold.ObjectId);
                    packet.AddString(stronghold.Name);
                    packet.AddByte(stronghold.Lvl);
                    packet.AddUInt32(stronghold.PrimaryPosition.X);
                    packet.AddUInt32(stronghold.PrimaryPosition.Y);
                }
            }
        }