/// <summary>
        /// Handles the specified <see cref="Message"/>.
        /// </summary>
        /// <param name="Device">The device.</param>
        /// <param name="Message">The message.</param>
        /// <param name="Cancellation">The cancellation.</param>
        public static async Task Handle(Device Device, Message Message, CancellationToken Cancellation)
        {
            var AskForAllianceDataMessage = (AskForAllianceDataMessage)Message;

            if (AskForAllianceDataMessage == null)
            {
                throw new LogicException(typeof(AskForAllianceDataHandler), nameof(AskForAllianceDataMessage) + " == null at Handle(Device, Message, CancellationToken).");
            }

            Clan Clan = await Clans.Get(AskForAllianceDataMessage.HighId, AskForAllianceDataMessage.LowId);

            if (Clan != null)
            {
                Device.NetworkManager.SendMessage(new AllianceDataMessage(new AllianceFullEntry()
                {
                    Header      = Clan.HeaderEntry,
                    Members     = Clan.Members.Values.ToArray(),
                    Description = Clan.Description
                }));
            }
            else
            {
                Logging.Warning(typeof(AskForAllianceDataHandler), "Clan == null at Handle(Device, Message, CancellationToken).");
            }
        }
Example #2
0
        /// <summary>
        /// Handles the specified <see cref="Message"/>.
        /// </summary>
        /// <param name="Device">The device.</param>
        /// <param name="Message">The message.</param>
        /// <param name="Cancellation">The cancellation.</param>
        public static async Task Handle(Device Device, Message Message, CancellationToken Cancellation)
        {
            var EndClientTurnMessage = (EndClientTurnMessage)Message;

            if (EndClientTurnMessage == null)
            {
                throw new LogicException(typeof(EndClientTurnHandler), nameof(EndClientTurnMessage) + " == null at Handle(Device, Message, CancellationToken).");
            }

            if (EndClientTurnMessage.Commands != null)
            {
                EndClientTurnMessage.Commands.ForEach(Command =>
                {
                    if (Command.ExecuteTick <= EndClientTurnMessage.Tick)
                    {
                        Device.GameMode.CommandManager.AddCommand(Command);
                    }
                });
            }

            for (int I = Device.GameMode.Time; I < EndClientTurnMessage.Tick; I++)
            {
                Device.GameMode.UpdateOneTick();
            }

            Player Player = Device.GameMode.Player;

            if (Player.IsInAlliance)
            {
                Clan Clan = await Clans.Get(Player.ClanHighId, Player.ClanLowId);

                if (Clan != null)
                {
                    if (Clan.Members.TryGetValue(Player.PlayerId, out var Member))
                    {
                        Member.SetPlayer(Player);
                    }
                }
                else
                {
                    Logging.Error(typeof(EndClientTurnHandler), "Clan == null at Handle(Device, Message, CancellationToken).");
                }
            }

            /* if (Device.GameMode.State == HomeState.Home)
             * {
             *  if (EndClientTurnMessage.Checksum != Device.GameMode.Checksum)
             *  {
             *      Logging.Error(this.GetType(), "Player is out of sync (S: " + Device.GameMode.Checksum + ", C: " + EndClientTurnMessage.Checksum + ").");
             *      Device.NetworkManager.SendMessage(new OutOfSyncMessage(Device, EndClientTurnMessage.Checksum, Device.GameMode.Checksum));
             *  }
             * } */
        }
Example #3
0
        internal static Clan GetEntity(int HighId, int LowId)
        {
            LogicLong EntityId = new LogicLong(HighId, LowId);

            if (EntityId.IsZero == false)
            {
                var Clan = Clans.Get(EntityId.HigherInt, EntityId.LowerInt, false).Result;

                if (Clan != null)
                {
                    return(Clan);
                }
                else
                {
                    Console.WriteLine("[*] Invalid arguments, the specified clan doesn't exist.");
                }
            }
            else
            {
                Console.WriteLine("[*] Missing arguments, please select a clan first.");
            }

            return(null);
        }