コード例 #1
0
        public static bool MemberJoin(ClanData clanData, UserData userData)
        {
            bool result;

            if (clanData != null && userData != null && !clanData.Members.ContainsKey(userData))
            {
                ClanMemberFlags clanMemberFlags = (ClanMemberFlags)0;
                if (clanData.LeaderID == userData.SteamID)
                {
                    clanMemberFlags |= (ClanMemberFlags.invite | ClanMemberFlags.dismiss | ClanMemberFlags.management);
                }
                if (Core.DatabaseType.Equals("MYSQL"))
                {
                    MySQL.Update(string.Format(Clans.SQL_INSERT_MEMBER, userData.SteamID, clanData.ID, clanMemberFlags.ToString().Replace(" ", "")));
                }
                clanData.Members.Add(userData, clanMemberFlags);
                userData.Clan = clanData;
                NetUser netUser = NetUser.FindByUserID(userData.SteamID);
                if (netUser != null)
                {
                    Broadcast.Message(netUser, Config.GetMessageClan("Command.Clan.PlayerJoined", clanData, null, userData), null, 0f);
                }
                result = true;
            }
            else
            {
                result = false;
            }
            return(result);
        }
コード例 #2
0
        public static bool MemberJoin(ClanData clanData, UserData userData)
        {
            if (((clanData == null) || (userData == null)) || clanData.Members.ContainsKey(userData))
            {
                return(false);
            }
            ClanMemberFlags flags = 0;

            if (clanData.LeaderID == userData.SteamID)
            {
                flags |= ClanMemberFlags.management | ClanMemberFlags.dismiss | ClanMemberFlags.invite;
            }
            if (Core.DatabaseType.Equals("MYSQL"))
            {
                MySQL.Update(string.Format(SQL_INSERT_MEMBER, userData.SteamID, clanData.ID, flags.ToString().Replace(" ", "")));
            }
            clanData.Members.Add(userData, flags);
            userData.Clan = clanData;
            NetUser player = NetUser.FindByUserID(userData.SteamID);

            if (player != null)
            {
                Broadcast.Message(player, Config.GetMessageClan("Command.Clan.PlayerJoined", clanData, null, userData), null, 0f);
            }
            return(true);
        }
コード例 #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 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);
        }
コード例 #5
0
        public static bool LoadAsTextFile()
        {
            Loaded = 0;
            if (!File.Exists(SaveFilePath))
            {
                return(false);
            }
            string str = File.ReadAllText(SaveFilePath);

            if (string.IsNullOrEmpty(str))
            {
                return(false);
            }
            string[] strArray = str.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);
            string   str2     = null;
            Version  version  = null;
            ClanData data     = null;

            foreach (string str3 in strArray)
            {
                UserData bySteamID;
                int      num3;
                Predicate <ClanLevel> match = null;
                Class0 class2 = new Class0();
                if (str3.StartsWith("[") && str3.EndsWith("]"))
                {
                    data = null;
                    if ((version != null) && (str2 != null))
                    {
                        uint key = str3.Substring(1, str3.Length - 2).ToUInt32();
                        if (key != 0)
                        {
                            if (Database.ContainsKey(key))
                            {
                                data = Database[key];
                            }
                            else
                            {
                                key = Helper.NewSerial;
                                DateTime created = new DateTime();
                                data = new ClanData(key, null, null, 0L, created);
                                Database.Add(key, data);
                                Loaded++;
                            }
                        }
                    }
                }
                else
                {
                    class2.string_0 = str3.Split(new char[] { '=' });
                    if (class2.string_0.Length >= 2)
                    {
                        if (data == null)
                        {
                            if (class2.string_0[0].Equals("VERSION", StringComparison.OrdinalIgnoreCase))
                            {
                                version = new Version(class2.string_0[1]);
                            }
                            if (class2.string_0[0].Equals("TITLE", StringComparison.OrdinalIgnoreCase))
                            {
                                str2 = class2.string_0[1];
                            }
                            if (class2.string_0[0].Equals("TIME", StringComparison.OrdinalIgnoreCase))
                            {
                                Convert.ToUInt32(class2.string_0[1]);
                            }
                        }
                        else
                        {
                            switch (class2.string_0[0].ToUpper())
                            {
                            case "NAME":
                                data.Name = class2.string_0[1].Trim();
                                break;

                            case "ABBREV":
                                data.Abbr = class2.string_0[1].Trim();
                                break;

                            case "LEADER":
                                data.LeaderID = ulong.Parse(class2.string_0[1]);
                                break;

                            case "CREATED":
                                data.Created = DateTime.Parse(class2.string_0[1]);
                                break;

                            case "FLAGS":
                                data.Flags = class2.string_0[1].ToEnum <ClanFlags>();
                                break;

                            case "BALANCE":
                                data.Balance = ulong.Parse(class2.string_0[1]);
                                break;

                            case "TAX":
                                data.Tax = uint.Parse(class2.string_0[1]);
                                break;

                            case "LEVEL":
                                if (match == null)
                                {
                                    match = new Predicate <ClanLevel>(class2.method_0);
                                }
                                data.SetLevel(Levels.Find(match));
                                break;

                            case "EXPERIENCE":
                                data.Experience = ulong.Parse(class2.string_0[1]);
                                break;

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

                            case "MOTD":
                                data.MOTD = class2.string_0[1].Trim();
                                break;

                            case "PENALTY":
                                data.Penalty = DateTime.Parse(class2.string_0[1]);
                                break;

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

                            case "MEMBER":
                                class2.string_0 = class2.string_0[1].Split(new char[] { ',' });
                                bySteamID       = Users.GetBySteamID(ulong.Parse(class2.string_0[0]));
                                if (bySteamID == null)
                                {
                                    break;
                                }
                                num3 = 1;
                                goto Label_05A2;
                            }
                        }
                    }
                }
                continue;
Label_0586:
                class2.string_0[num3 - 1] = class2.string_0[num3];
                num3++;
Label_05A2:
                if (num3 < class2.string_0.Length)
                {
                    goto Label_0586;
                }
                Array.Resize <string>(ref class2.string_0, class2.string_0.Length - 1);
                ClanMemberFlags flags = string.Join(",", class2.string_0).ToEnum <ClanMemberFlags>();
                bySteamID.Clan = data;
                data.Members.Add(bySteamID, flags);
            }
            return(true);
        }
コード例 #6
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);
        }