Beispiel #1
0
        /// <summary>
        /// Creates the specified entity.
        /// </summary>
        /// <param name="Entity">The entity.</param>
        /// <param name="Store">Whether it has to be stored.</param>
        public static async Task <Clan> Create(Clan Entity = null, bool Store = true)
        {
            if (Entity == null)
            {
                Entity = new Clan();
            }

            Entity.HighId = Clans.HighSeed;
            Entity.LowId  = Interlocked.Increment(ref Clans.LowSeed);

            await ClanDb.Create(Entity);

            if (Store)
            {
                Clans.Add(Entity);
            }

            return(Entity);
        }
Beispiel #2
0
        /// <summary>
        /// Gets the entity using the specified identifiers.
        /// </summary>
        /// <param name="HighId">The high identifier.</param>
        /// <param name="LowId">The low identifier.</param>
        /// <param name="Store">Whether it has to be stored.</param>
        public static async Task <Clan> Get(int HighId, int LowId, bool Store = true)
        {
            Logging.Warning(typeof(Clans), "Get(" + HighId + ", " + LowId + ") has been called.");

            long ClanId = (long)HighId << 32 | (uint)LowId;

            ClanDb ClanDb = await ClanDb.Load(HighId, LowId);

            Clan Clan = null;

            if (Clans.Entities.TryGetValue(ClanId, out Clan))
            {
                return(Clan);
            }
            else
            {
                if (ClanDb != null)
                {
                    if (ClanDb.Deserialize(out Clan))
                    {
                        Clan.LoadingFinished();

                        if (Store)
                        {
                            Clans.Add(Clan);
                        }

                        return(Clan);
                    }
                    else
                    {
                        Logging.Error(typeof(Clans), "ClanDb.Deserialize(out Clan) != true at Get(" + HighId + ", " + LowId + ").");
                    }
                }
                else
                {
                    Logging.Warning(typeof(Clans), "ClanDb == null at Get(HighId, LowId).");
                }
            }

            return(Clan);
        }
Beispiel #3
0
        /// <summary>
        /// Removes the specified entity.
        /// </summary>
        /// <param name="Entity">The entity.</param>
        public static async Task Remove(Player Entity)
        {
            Player TmpPlayer;

            if (Entity.GameMode != null)
            {
                if (Entity.GameMode.CommandManager.AvailableServerCommands.Count > 0)
                {
                    foreach (Command Command in Entity.GameMode.CommandManager.AvailableServerCommands.Values.ToArray())
                    {
                        if (Command.IsServerCommand)
                        {
                            Command.Execute(Entity.GameMode);
                        }
                    }
                }

                if (Entity.IsInAlliance)
                {
                    Clan Clan = Clans.Get(Entity.ClanHighId, Entity.ClanLowId).Result;

                    if (Clan != null)
                    {
                        await Clan.Members.TryRemoveOnlineMember(Entity);
                    }
                }

                if (Entity.GameMode.Battle != null)
                {
                    foreach (Player Player2 in Entity.GameMode.Battle.Players)
                    {
                        if (Player2 != null)
                        {
                            Player2.GameMode.SectorManager.OpponentLeftMatch();
                        }
                    }
                }
            }

            await Players.Save(Entity);
        }
Beispiel #4
0
 /// <summary>
 /// Removes the specified entity.
 /// </summary>
 /// <param name="Entity">The entity.</param>
 public static async Task Remove(Clan Entity)
 {
     await Clans.Save(Entity);
 }