internal override void Encode()
        {
            this.Data.AddInt(0);
            this.Data.AddInt(this.Players.Count);

            foreach (var Player in Players)
            {
                this.Data.AddLong(Player.Avatar.UserId);
                this.Data.AddBool(true);
                this.Data.AddLong(Player.Avatar.UserId);
                this.Data.AddString(Player.Avatar.Name);
                this.Data.AddString(Player.Avatar.Facebook.Identifier);
                this.Data.AddString(Player.Avatar.Google.Identifier);
                this.Data.AddInt(26180);
                this.Data.AddInt(Player.Avatar.Level);
                this.Data.AddInt(Player.Avatar.League);
                this.Data.AddInt(Player.Avatar.Trophies);
                this.Data.AddString(null);
                this.Data.AddInt(0);

                this.Data.AddBool(Player.Avatar.ClanId > 0);

                if (Player.Avatar.ClanId > 0)
                {
                    Logic.Clan _Clan = Resources.Clans.Get(Player.Avatar.ClanId, false);
                    this.Data.AddLong(Player.Avatar.ClanId);
                    this.Data.AddInt(_Clan.Badge);
                    this.Data.AddString(_Clan.Name);
                    this.Data.AddInt((int)_Clan.Members[Player.Avatar.UserId].Role);
                    this.Data.AddInt(_Clan.Level);
                    this.Data.AddBool(false);
                }
            }
        }
示例#2
0
 public static void Save(Logic.Clan alliance)
 {
     try
     {
         using (MysqlEntities ctx = new MysqlEntities())
         {
             ctx.Configuration.AutoDetectChangesEnabled = false;
             var c = ctx.Clan.Find((int)alliance.Clan_ID);
             if (c != null)
             {
                 c.Data             = JsonConvert.SerializeObject(alliance, Settings2);
                 ctx.Entry(c).State = EntityState.Modified;
             }
             ctx.SaveChanges();
         }
     }
     catch (DbEntityValidationException ex)
     {
         ExceptionLogger.Log(ex,
                             $"Exception while trying to save a clan {alliance.Clan_ID} to the database. Check error for more information.");
         foreach (var entry in ex.EntityValidationErrors)
         {
             foreach (var errs in entry.ValidationErrors)
             {
                 Logger.Error($"{errs.PropertyName}:{errs.ErrorMessage}");
             }
         }
         throw;
     }
     catch (Exception ex)
     {
         ExceptionLogger.Log(ex, $"Exception while trying to save a clan {alliance.Clan_ID} to the database.");
         throw;
     }
 }
示例#3
0
        public static void RemoveAlliance(Logic.Clan alliance)
        {
            long Id = alliance.Clan_ID;

            using (MysqlEntities ctx = new MysqlEntities())
            {
                var clan = ctx.Clan.Find(Id);
                if (clan != null)
                {
                    ctx.Clan.Remove(clan);
                    ctx.SaveChanges();
                }
            }

            ObjectManager.RemoveInMemoryAlliance(Id);
        }
示例#4
0
        public static void CreateAlliance(Logic.Clan alliance)
        {
            try
            {
                using (var ctx = new MysqlEntities())
                {
                    var newClan = new clan
                    {
                        Id   = alliance.Clan_ID,
                        Data = JsonConvert.SerializeObject(alliance, Settings2)
                    };

                    ctx.Clan.Add(newClan1);
                    ctx.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                ExceptionLogger.Log(ex, "Exception while trying to create a new alliance in database.");
            }
        }
示例#5
0
        // Used whenever the clients searches for an alliance however no alliances is loaded in memory.
        public static List <Logic.Clan> GetAllAlliances()
        {
            var alliances = new List <Logic.Clan>();

            try
            {
                using (var ctx = new MysqlEntities())
                {
                    var clans = ctx.Clan;
                    Parallel.ForEach(clans, c =>
                    {
                        Logic.Clan clan = default(Logic.Clan);
                        clan            = JsonConvert.DeserializeObject <Logic.Clan>(c.Data, Settings2);
                        alliances.Add(clan);
                    });
                }
            }
            catch (Exception ex)
            {
                ExceptionLogger.Log(ex, "Exception while trying to get all alliances from database.");
            }

            return(alliances);
        }