예제 #1
0
 public static void SQL_SynchronizeClans()
 {
     if (Core.DatabaseType.Equals("MYSQL"))
     {
         MySQL.Result result = MySQL.Query("SELECT * FROM `db_clans`;", true);
         if (result != null)
         {
             using (List <MySQL.Row> .Enumerator enumerator = result.Row.GetEnumerator())
             {
                 while (enumerator.MoveNext())
                 {
                     Predicate <ClanLevel> predicate = null;
                     Clans.Class3          @class    = new Clans.Class3();
                     @class.row_0 = enumerator.Current;
                     uint     asUInt = @class.row_0.Get("id").AsUInt;
                     ClanData clanData;
                     if (Clans.Database.ContainsKey(asUInt))
                     {
                         clanData = Clans.Get(asUInt);
                     }
                     else
                     {
                         Clans.Database.Add(asUInt, clanData = new ClanData(asUInt, null, null, 0uL, default(DateTime)));
                     }
                     if (!Clans.dictionary_0.ContainsKey(asUInt))
                     {
                         Clans.dictionary_0.Add(asUInt, 0uL);
                     }
                     if (Clans.Database[clanData.ID].Hash == Clans.dictionary_0[clanData.ID])
                     {
                         clanData.Name     = @class.row_0.Get("name").AsString;
                         clanData.Abbr     = @class.row_0.Get("abbrev").AsString;
                         clanData.LeaderID = @class.row_0.Get("leader_id").AsUInt64;
                         clanData.Created  = @class.row_0.Get("created").AsDateTime;
                         clanData.Flags    = @class.row_0.Get("flags").AsEnum <ClanFlags>();
                         clanData.Balance  = @class.row_0.Get("balance").AsUInt64;
                         clanData.Tax      = @class.row_0.Get("tax").AsUInt;
                         ClanData         clanData2 = clanData;
                         List <ClanLevel> levels    = Clans.Levels;
                         if (predicate == null)
                         {
                             predicate = new Predicate <ClanLevel>(@class.method_0);
                         }
                         clanData2.SetLevel(levels.Find(predicate));
                         clanData.Experience = @class.row_0.Get("experience").AsUInt64;
                         string[] array = @class.row_0.Get("location").AsString.Replace(", ", ",").Split(new char[]
                         {
                             ','
                         });
                         if (array.Length > 0)
                         {
                             float.TryParse(array[0].Trim(), out clanData.Location.x);
                         }
                         if (array.Length > 1)
                         {
                             float.TryParse(array[1].Trim(), out clanData.Location.y);
                         }
                         if (array.Length > 2)
                         {
                             float.TryParse(array[2].Trim(), out clanData.Location.z);
                         }
                         clanData.MOTD    = @class.row_0.Get("motd").AsString;
                         clanData.Penalty = @class.row_0.Get("penalty").AsDateTime;
                     }
                     else
                     {
                         Clans.SQL_Update(clanData, false);
                     }
                     Clans.dictionary_0[asUInt] = Clans.Database[asUInt].Hash;
                 }
             }
         }
     }
 }
예제 #2
0
        public static bool LoadAsTextFile()
        {
            Clans.Loaded = 0;
            bool result;

            if (!File.Exists(Clans.SaveFilePath))
            {
                result = false;
            }
            else
            {
                string text = File.ReadAllText(Clans.SaveFilePath);
                if (string.IsNullOrEmpty(text))
                {
                    result = false;
                }
                else
                {
                    string[] array = text.Split(new string[]
                    {
                        "\r\n",
                        "\n"
                    }, StringSplitOptions.RemoveEmptyEntries);
                    string   text2    = null;
                    Version  v        = null;
                    ClanData clanData = null;
                    string[] array2   = array;
                    for (int i = 0; i < array2.Length; i++)
                    {
                        string text3 = array2[i];
                        Predicate <ClanLevel> predicate = null;
                        Clans.Class0          @class    = new Clans.Class0();
                        if (text3.StartsWith("[") && text3.EndsWith("]"))
                        {
                            clanData = null;
                            if (!(v == null) && text2 != null)
                            {
                                uint num = text3.Substring(1, text3.Length - 2).ToUInt32();
                                if (num != 0u)
                                {
                                    if (Clans.Database.ContainsKey(num))
                                    {
                                        clanData = Clans.Database[num];
                                    }
                                    else
                                    {
                                        num      = Helper.NewSerial;
                                        clanData = new ClanData(num, null, null, 0uL, default(DateTime));
                                        Clans.Database.Add(num, clanData);
                                        Clans.Loaded++;
                                    }
                                }
                            }
                        }
                        else
                        {
                            @class.string_0 = text3.Split(new char[]
                            {
                                '='
                            });
                            if (@class.string_0.Length >= 2)
                            {
                                if (clanData == null)
                                {
                                    if (@class.string_0[0].Equals("VERSION", StringComparison.OrdinalIgnoreCase))
                                    {
                                        v = new Version(@class.string_0[1]);
                                    }
                                    if (@class.string_0[0].Equals("TITLE", StringComparison.OrdinalIgnoreCase))
                                    {
                                        text2 = @class.string_0[1];
                                    }
                                    if (@class.string_0[0].Equals("TIME", StringComparison.OrdinalIgnoreCase))
                                    {
                                        Convert.ToUInt32(@class.string_0[1]);
                                    }
                                }
                                else
                                {
                                    string text4 = @class.string_0[0].ToUpper();
                                    switch (text4)
                                    {
                                    case "NAME":
                                        clanData.Name = @class.string_0[1].Trim();
                                        break;

                                    case "ABBREV":
                                        clanData.Abbr = @class.string_0[1].Trim();
                                        break;

                                    case "LEADER":
                                        clanData.LeaderID = ulong.Parse(@class.string_0[1]);
                                        break;

                                    case "CREATED":
                                        clanData.Created = DateTime.Parse(@class.string_0[1]);
                                        break;

                                    case "FLAGS":
                                        clanData.Flags = @class.string_0[1].ToEnum <ClanFlags>();
                                        break;

                                    case "BALANCE":
                                        clanData.Balance = ulong.Parse(@class.string_0[1]);
                                        break;

                                    case "TAX":
                                        clanData.Tax = uint.Parse(@class.string_0[1]);
                                        break;

                                    case "LEVEL":
                                    {
                                        ClanData         clanData2 = clanData;
                                        List <ClanLevel> levels    = Clans.Levels;
                                        if (predicate == null)
                                        {
                                            predicate = new Predicate <ClanLevel>(@class.method_0);
                                        }
                                        clanData2.SetLevel(levels.Find(predicate));
                                        break;
                                    }

                                    case "EXPERIENCE":
                                        clanData.Experience = ulong.Parse(@class.string_0[1]);
                                        break;

                                    case "LOCATION":
                                        @class.string_0 = @class.string_0[1].Split(new char[]
                                        {
                                            ','
                                        });
                                        if (@class.string_0.Length > 0)
                                        {
                                            float.TryParse(@class.string_0[0].Trim(), out clanData.Location.x);
                                        }
                                        if (@class.string_0.Length > 1)
                                        {
                                            float.TryParse(@class.string_0[1].Trim(), out clanData.Location.y);
                                        }
                                        if (@class.string_0.Length > 2)
                                        {
                                            float.TryParse(@class.string_0[2].Trim(), out clanData.Location.z);
                                        }
                                        break;

                                    case "MOTD":
                                        clanData.MOTD = @class.string_0[1].Trim();
                                        break;

                                    case "PENALTY":
                                        clanData.Penalty = DateTime.Parse(@class.string_0[1]);
                                        break;

                                    case "HOSTILE":
                                        @class.string_0 = @class.string_0[1].Split(new char[]
                                        {
                                            ','
                                        });
                                        if (@class.string_0.Length >= 2)
                                        {
                                            clanData.Hostile.Add(@class.string_0[0].ToUInt32(), DateTime.Parse(@class.string_0[1]));
                                        }
                                        break;

                                    case "MEMBER":
                                    {
                                        @class.string_0 = @class.string_0[1].Split(new char[]
                                            {
                                                ','
                                            });
                                        ulong    steam_id  = ulong.Parse(@class.string_0[0]);
                                        UserData bySteamID = Users.GetBySteamID(steam_id);
                                        if (bySteamID != null)
                                        {
                                            for (int j = 1; j < @class.string_0.Length; j++)
                                            {
                                                @class.string_0[j - 1] = @class.string_0[j];
                                            }
                                            Array.Resize <string>(ref @class.string_0, @class.string_0.Length - 1);
                                            ClanMemberFlags value = string.Join(",", @class.string_0).ToEnum <ClanMemberFlags>();
                                            bySteamID.Clan = clanData;
                                            clanData.Members.Add(bySteamID, value);
                                        }
                                        break;
                                    }
                                    }
                                }
                            }
                        }
                    }
                    result = true;
                }
            }
            return(result);
        }
예제 #3
0
        public static bool LoadAsDatabaseSQL()
        {
            Predicate <ClanLevel> predicate = null;

            Clans.Class1 @class = new Clans.Class1();
            Clans.Loaded = 0;
            ClanData clanData = null;
            UserData userData = null;

            @class.row_0 = null;
            MySQL.Result result  = MySQL.Query("SELECT * FROM `db_clans`;", false);
            MySQL.Result result2 = MySQL.Query("SELECT * FROM `db_clans_members`;", false);
            MySQL.Result result3 = MySQL.Query("SELECT * FROM `db_clans_hostile`;", false);
            if (result2 != null && result != null)
            {
                foreach (MySQL.Row current in result2.Row)
                {
                    Clans.Class2 class2 = new Clans.Class2();
                    class2.class1_0 = @class;
                    ulong asUInt = current.Get("user_id").AsUInt64;
                    class2.uint_0 = current.Get("clan_id").AsUInt;
                    userData      = Users.GetBySteamID(asUInt);
                    if (userData != null && class2.uint_0 != 0u)
                    {
                        if (@class.row_0 == null || @class.row_0.Get("id").AsUInt != class2.uint_0)
                        {
                            @class.row_0 = result.Row.Find(new Predicate <MySQL.Row>(class2.method_0));
                        }
                        if (@class.row_0 == null)
                        {
                            MySQL.Query(string.Format(Clans.SQL_DELETE_MEMBER, asUInt), false);
                        }
                        else
                        {
                            ClanMemberFlags value = current.Get("privileges").AsEnum <ClanMemberFlags>();
                            if (clanData == null || clanData.ID != class2.uint_0)
                            {
                                clanData = Clans.Get(class2.uint_0);
                            }
                            if (clanData == null)
                            {
                                clanData          = new ClanData(class2.uint_0, null, null, 0uL, default(DateTime));
                                clanData.Name     = @class.row_0.Get("name").AsString;
                                clanData.Abbr     = @class.row_0.Get("abbrev").AsString;
                                clanData.LeaderID = @class.row_0.Get("leader_id").AsUInt64;
                                clanData.Created  = @class.row_0.Get("created").AsDateTime;
                                clanData.Flags    = @class.row_0.Get("flags").AsEnum <ClanFlags>();
                                clanData.Balance  = @class.row_0.Get("balance").AsUInt64;
                                clanData.Tax      = @class.row_0.Get("tax").AsUInt;
                                ClanData         clanData2 = clanData;
                                List <ClanLevel> levels    = Clans.Levels;
                                if (predicate == null)
                                {
                                    predicate = new Predicate <ClanLevel>(@class.method_0);
                                }
                                clanData2.SetLevel(levels.Find(predicate));
                                clanData.Experience = @class.row_0.Get("experience").AsUInt64;
                                string[] array = @class.row_0.Get("location").AsString.Split(new char[]
                                {
                                    ','
                                });
                                if (array.Length > 0)
                                {
                                    float.TryParse(array[0], out clanData.Location.x);
                                }
                                if (array.Length > 1)
                                {
                                    float.TryParse(array[1], out clanData.Location.y);
                                }
                                if (array.Length > 2)
                                {
                                    float.TryParse(array[2], out clanData.Location.z);
                                }
                                clanData.MOTD    = @class.row_0.Get("motd").AsString;
                                clanData.Penalty = @class.row_0.Get("penalty").AsDateTime;
                                if (result3 != null)
                                {
                                    foreach (MySQL.Row current2 in result3.Row)
                                    {
                                        if (current2.Get("clan_id").AsUInt == class2.uint_0)
                                        {
                                            clanData.Hostile.Add(current2.Get("hostile_id").AsUInt, current2.Get("ending").AsDateTime);
                                        }
                                    }
                                }
                                Clans.Database.Add(clanData.ID, clanData);
                                Clans.Loaded++;
                            }
                            clanData.Members.Add(userData, value);
                            userData.Clan = clanData;
                        }
                    }
                    else
                    {
                        MySQL.Query(string.Format(Clans.SQL_DELETE_MEMBER, asUInt), false);
                    }
                }
            }
            Clans.dictionary_0.Clear();
            foreach (uint current3 in Clans.Database.Keys)
            {
                Clans.dictionary_0.Add(current3, Clans.Database[current3].Hash);
            }
            return(true);
        }
예제 #4
0
        public static bool LoadAsDatabaseSQL()
        {
            Predicate <ClanLevel> match = null;
            Class1 class3 = new Class1();

            Loaded = 0;
            ClanData data = null;
            UserData key  = null;

            class3.row_0 = null;
            MySQL.Result result  = MySQL.Query("SELECT * FROM `db_clans`;", false);
            MySQL.Result result2 = MySQL.Query("SELECT * FROM `db_clans_members`;", false);
            MySQL.Result result3 = MySQL.Query("SELECT * FROM `db_clans_hostile`;", false);
            if ((result2 != null) && (result != null))
            {
                foreach (MySQL.Row row in result2.Row)
                {
                    Class2 class2 = new Class2 {
                        class1_0 = class3
                    };
                    ulong num = row.Get("user_id").AsUInt64;
                    class2.uint_0 = row.Get("clan_id").AsUInt;
                    key           = Users.GetBySteamID(num);
                    if ((key != null) && (class2.uint_0 != 0))
                    {
                        if ((class3.row_0 == null) || (class3.row_0.Get("id").AsUInt != class2.uint_0))
                        {
                            class3.row_0 = result.Row.Find(new Predicate <MySQL.Row>(class2.method_0));
                        }
                        if (class3.row_0 == null)
                        {
                            MySQL.Query(string.Format(SQL_DELETE_MEMBER, num), false);
                        }
                        else
                        {
                            ClanMemberFlags flags = row.Get("privileges").AsEnum <ClanMemberFlags>();
                            if ((data == null) || (data.ID != class2.uint_0))
                            {
                                data = Get(class2.uint_0);
                            }
                            if (data == null)
                            {
                                DateTime created = new DateTime();
                                data = new ClanData(class2.uint_0, null, null, 0L, created)
                                {
                                    Name     = class3.row_0.Get("name").AsString,
                                    Abbr     = class3.row_0.Get("abbrev").AsString,
                                    LeaderID = class3.row_0.Get("leader_id").AsUInt64,
                                    Created  = class3.row_0.Get("created").AsDateTime,
                                    Flags    = class3.row_0.Get("flags").AsEnum <ClanFlags>(),
                                    Balance  = class3.row_0.Get("balance").AsUInt64,
                                    Tax      = class3.row_0.Get("tax").AsUInt
                                };
                                if (match == null)
                                {
                                    match = new Predicate <ClanLevel>(class3.method_0);
                                }
                                data.SetLevel(Levels.Find(match));
                                data.Experience = class3.row_0.Get("experience").AsUInt64;
                                string[] strArray = class3.row_0.Get("location").AsString.Split(new char[] { ',' });
                                if (strArray.Length > 0)
                                {
                                    float.TryParse(strArray[0], out data.Location.x);
                                }
                                if (strArray.Length > 1)
                                {
                                    float.TryParse(strArray[1], out data.Location.y);
                                }
                                if (strArray.Length > 2)
                                {
                                    float.TryParse(strArray[2], out data.Location.z);
                                }
                                data.MOTD    = class3.row_0.Get("motd").AsString;
                                data.Penalty = class3.row_0.Get("penalty").AsDateTime;
                                if (result3 != null)
                                {
                                    foreach (MySQL.Row row2 in result3.Row)
                                    {
                                        if (row2.Get("clan_id").AsUInt == class2.uint_0)
                                        {
                                            data.Hostile.Add(row2.Get("hostile_id").AsUInt, row2.Get("ending").AsDateTime);
                                        }
                                    }
                                }
                                Database.Add(data.ID, data);
                                Loaded++;
                            }
                            data.Members.Add(key, flags);
                            key.Clan = data;
                        }
                    }
                    else
                    {
                        MySQL.Query(string.Format(SQL_DELETE_MEMBER, num), false);
                    }
                }
            }
            dictionary_0.Clear();
            foreach (uint num2 in Database.Keys)
            {
                dictionary_0.Add(num2, Database[num2].Hash);
            }
            return(true);
        }