Exemplo n.º 1
0
        public static bool AddGroup(string name, bool isDefaultGroup, bool canBuild, string prefix, string suffix, char color)
        {
            Group g = new Group();

            if(name == "" || name == null)
                return false;

            g.Name = name;

            if(isDefaultGroup)
                Group.DefaultGroup = g;

            g.CanBuild = canBuild;

            if(prefix == null)
                prefix = "";

            g.Prefix = prefix;

            if(suffix == null)
                suffix = "";

            g.Suffix = suffix;

            if(!Color.IsColorValid(color))
                return false;

            g.GroupColor = color.ToString();
            Group tempG = Group.FindGroup(g.Name);
            if (tempG != null)
                return false;

            Group.GroupList.Add(g);
            return true;
        }
Exemplo n.º 2
0
 public static bool AddGroupInheritance(Group g, Group addg)
 {
     if (!g.InheritanceList.Contains(addg))
     {
         g.InheritanceList.Add(addg);  //TODO: add inherited permissions
         UpdateGroupPermissions(g);
         return true;
     }
     return false;
 }
Exemplo n.º 3
0
 public static bool AddSubGroup(Player p, Group g)
 {
     if(!p.SubGroups.Contains(g))
     {
         p.SubGroups.Add(g);
         return true;
     }
     else
     {
         return false;
     }
 }
Exemplo n.º 4
0
 public static void ChangeGroupSuffix(Group g, string suffix)
 {
     g.Suffix = suffix;
 }
Exemplo n.º 5
0
 public static void ChangeGroupPrefix(Group g, string prefix)
 {
     g.Prefix = prefix;
 }
Exemplo n.º 6
0
 public static bool ChangeGroupColor(Group g, char color)
 {
     if (Color.IsColorValid(color))
     {
         g.GroupColor = "§" + color;
         return true;
     }
     return false;
 }
Exemplo n.º 7
0
 public static void ChangeCanBuild(Group g, bool cb)
 {
     g.CanBuild = cb;
 }
Exemplo n.º 8
0
        public static void LoadGroups()
        {
            System.Data.DataTable dt = new System.Data.DataTable();

            try
            {
                dt = Server.SQLiteDB.GetDataTable("SELECT * FROM Groups;");
            }
            catch{Logger.Log("Something went wrong loading groups");}

            for(int i = 0; i < dt.Rows.Count; i++)
            {
                Group g = new Group();

                g.Name = dt.Rows[i]["Name"].ToString();

                g.PermLevel = int.Parse(dt.Rows[i]["PermLevel"].ToString());

                if (dt.Rows[i]["IsDefault"].ToString() == "1")
                {
                    g.IsDefaultGroup = true;
                    Group.DefaultGroup = g;
                }

                if (dt.Rows[i]["CanBuild"].ToString() == "1")
                    g.CanBuild = true;

                g.Prefix = dt.Rows[i]["Prefix"].ToString();
                g.Suffix = dt.Rows[i]["Suffix"].ToString();

                g.GroupColor = dt.Rows[i]["Color"].ToString();

                if (g.GroupColor.Length == 2 && g.GroupColor[0] == '%' || g.GroupColor[0] == '§' || g.GroupColor[0] == '&')
                    if (Color.IsColorValid((char)g.GroupColor[1]))
                        g.GroupColor = "§" + g.GroupColor[1];
                else if (g.GroupColor.Length == 1 && Color.IsColorValid((char)g.GroupColor[0]))
                 	g.GroupColor = "§" + g.GroupColor[1];

                string[] perms = dt.Rows[i]["Permissions"].ToString().Replace(" ", "").Split(',');
                foreach(string s in perms)
                {
                    string perm;
                    if (s[0] == '-')
                        perm = "-" + Server.SQLiteDB.ExecuteScalar("SELECT Node FROM Permission WHERE ID = '" + s.Substring(1) + "';");
                    else
                        perm = Server.SQLiteDB.ExecuteScalar("SELECT Node FROM Permission WHERE ID = '" + s + "';");

                    if (perm.Substring(0,1) == "-" && !g.PermissionList.Contains(perm.Substring(1)))
                        g.PermissionList.Add(perm);
                    else if (perm.Substring(0,1) != "-" && !g.PermissionList.Contains("-" + perm))
                        g.PermissionList.Add(perm);
                }

                string temp = dt.Rows[i]["Inheritance"].ToString().Replace(" ", "");
                string[] inheritance = temp.Split(',');
                if (inheritance.Length >= 1)
                {
                    foreach(string s in inheritance)
                    {
                        if (!String.IsNullOrEmpty(s))
                            g.tempInheritanceList.Add(Server.SQLiteDB.ExecuteScalar("SELECT Name FROM Groups WHERE ID = '" + s + "';"));
                    }
                }

                Group.GroupList.Add(g);
            }

            foreach(Group g in Group.GroupList)
            {
                foreach(string s in g.tempInheritanceList)
                {
                    Group gr = Group.FindGroup(s);
                    if (gr != null)
                    {
                        GroupUtils.AddGroupInheritance(g, gr);
                    }
                }
            }

            LoadTracks();
        }
Exemplo n.º 9
0
 public static bool SetRank(Player p, Group g)
 {
     if(Group.GroupList.Contains(g))
     {
         p.group = g;
         return true;
     }
     else
         return false;
 }
Exemplo n.º 10
0
 public static bool RemoveSubGroup(Player p, Group g)
 {
     if(p.SubGroups.Contains(g))
         {
             p.SubGroups.Remove(g);
             return true;
         }
     else
         return false;
 }
Exemplo n.º 11
0
        /// <summary>
        /// Finds if GroupA is higher rank than GroupB, will return false if they are equal.
        /// </summary>
        /// <param name="groupA">
        /// A <see cref="Group"/>
        /// </param>
        /// <param name="groupB">
        /// A <see cref="Group"/>
        /// </param>
        /// <returns>
        /// A <see cref="System.Boolean"/>
        /// </returns>
        public static bool IsHigherRank(Group groupA, Group groupB)
        {
            //TODO: add a better system, that doesn't require any user input
            if (groupA.PermLevel > groupB.PermLevel)
                return true;

            return false;
        }
Exemplo n.º 12
0
 public static bool DelGroupPermission(Group g, string perm)
 {
     if (g.PermissionList.Contains(perm))
     {
         g.PermissionList.Remove(perm);
         return true;
     }
     return false;
 }
Exemplo n.º 13
0
 public static bool DelGroupInheritance(Group g, Group delg)
 {
     if (!g.InheritanceList.Contains(delg))
     {
         g.InheritanceList.Remove(delg);
         UpdateGroupPermissions(g);
         return true;
     }
     return false;
 }
Exemplo n.º 14
0
        public static bool DelGroup(Group g)
        {
            foreach(Player p in Player.players)
            {
                if (p.group == g)
                {
                    return false;
                }
            }

            if (Group.GroupList.Contains(g))
            {
                Group.GroupList.Remove(g);
                return true;
            }
            return false;
        }
Exemplo n.º 15
0
 public static bool AddGroupPermission(Group g, string perm)
 {
     if (!g.PermissionList.Contains(perm))
     {
         g.PermissionList.Add(perm);
         return true;
     }
     return false;
 }
Exemplo n.º 16
0
        private void LoadAttributes()
        {
            System.Data.DataTable DT = new System.Data.DataTable();
            DT = Server.SQLiteDB.GetDataTable("SELECT * FROM Player WHERE Name = '" + username + "';");

            if(DT.Rows.Count > 0)
            {
                NickName = DT.Rows[0]["NickName"].ToString();

                //short sout = 0;
                //if(Int16.TryParse(DT.Rows[0]["Exp"].ToString(), out sout));
                //	this.Experience.Add(this, sout);

                if (DT.Rows[0]["CanBuild"].ToString() == "1")
                    CanBuild = true;
                else
                    CanBuild = false;

                Prefix = DT.Rows[0]["Prefix"].ToString();
                Suffix = DT.Rows[0]["Suffix"].ToString();

                string tcolor = DT.Rows[0]["Color"].ToString();

                if (!String.IsNullOrEmpty(tcolor))
                    {
                if (tcolor.Length == 2 && tcolor[0] == '%' || tcolor[0] == '§' || tcolor[0] == '&')
                    if (Color.IsColorValid((char)tcolor[1]))
                        color = "§" + tcolor[1];
                else if (tcolor.Length == 1 && Color.IsColorValid((char)tcolor[0]))
                 	color = "§" + tcolor[1];
                }

                if (DT.Rows[0]["DND"].ToString() == "1")
                    DoNotDisturb = true;
                else
                    DoNotDisturb = false;

                if (DT.Rows[0]["GodMode"].ToString() == "1")
                    GodMode = true;
                else
                    GodMode = false;

                //TODO Accounts
                #region ECONOMY
                //TODO
                #endregion

                #region GROUPS
                string groupid = DT.Rows[0]["GroupID"].ToString();

                Group gr = Group.FindGroup(Server.SQLiteDB.ExecuteScalar("SELECT Name FROM Groups WHERE ID = '" + groupid + "';"));

                if (gr != null)
                    this.group = gr;
                else
                    this.group = Group.DefaultGroup;

                string temp = DT.Rows[0]["SubGroups"].ToString().Replace(" ", "");
                string[] subgroups = temp.Split(',');
                if (subgroups.Length >= 1)
                {
                    foreach(string s in subgroups)
                    {
                        if (!String.IsNullOrEmpty(s))
                        {
                            Group g = Group.FindGroup(Server.SQLiteDB.ExecuteScalar("SELCT Name FROM Groups WHERE ID = '" + s + "';"));

                            if (g != null)
                                this.SubGroups.Add(g);
                        }
                    }
                }

                string[] perms = DT.Rows[0]["ExtraPerms"].ToString().Replace(" ", "").Split(',');
                foreach(string s in perms)
                {
                    if (String.IsNullOrEmpty(s)) continue;
                    string perm;
                    if (s[0] == '-')
                        perm = "-" + Server.SQLiteDB.ExecuteScalar("SELECT Node FROM Permission WHERE ID = '" + s.Substring(1) + "';");
                    else
                        perm = Server.SQLiteDB.ExecuteScalar("SELECT Node FROM Permission WHERE ID = '" + s + "';");

                    if (perm.Substring(0,1) == "-" && !this.AdditionalPermissions.Contains(perm.Substring(1)))
                        this.AdditionalPermissions.Add(perm);
                    else if (perm.Substring(0,1) != "-" && !this.AdditionalPermissions.Contains("-" + perm))
                        this.AdditionalPermissions.Add(perm);
                }
                #endregion

                #region INVENTORY
                string invid = DT.Rows[0]["InventoryID"].ToString();

                if(!String.IsNullOrEmpty(invid))
                {
                    System.Data.DataTable invDT = new System.Data.DataTable();
                    invDT = Server.SQLiteDB.GetDataTable("Select * FROM Inventory WHERE ID = '" + invid + "';");
                    if (invDT.Rows.Count == 0) CreateInventory();

                    for (int i = 0; i <= 44; i++)
                    {
                        string data = invDT.Rows[0]["slot" + i].ToString();
                        string[] item = data.Split(':');
                        short id = -1;
                        short meta = 0;
                        byte count = 1;

                        if (!Int16.TryParse(item[0], out id))
                        {
                            continue;
                        }
                        if (item.Length >= 2)
                        {
                            if(!Int16.TryParse(item[1], out meta))
                            {
                                meta = 0;
                            }
                        }
                        if (item.Length >= 3)
                        {
                            if(!Byte.TryParse(item[2], out count))
                            {
                                count = 1;
                            }
                        }
                        if (count > 64) count = 64;

                        if (id > 0 && count > 0)
                        {
                            this.inventory.Add(id, count, meta, i);
                        }
                    }
                }
                else CreateInventory();

                #endregion

            }
            else
            {
                Server.Log(String.Format("Creating new Database entry for {0}.", this.username));

                this.group = Group.DefaultGroup;
                //TODO Set Default to default group, setup accounts etc
                SaveAttributes(true);
            }
        }
Exemplo n.º 17
0
        public static void UpdateGroupPermissions(Group g)
        {
            //TODO: Fix
            g.InheritedPermissionList.Clear();

            foreach(Group gr in g.InheritanceList)
            {
                foreach(string s in gr.PermissionList)
                {
                    bool denied = false;
                    if(s.Contains("-"))
                    {
                       	s.Remove(0, 1);
                        denied = true;
                    }

                    if(!g.PermissionList.Contains(s) && !g.PermissionList.Contains("-" + s) && !g.InheritedPermissionList.Contains(s) && !g.InheritedPermissionList.Contains("-" + s))
                    {
                        if (denied)
                            g.InheritedPermissionList.Add("-" + s);
                        else
                            g.InheritedPermissionList.Add(s);
                    }
                }
            }
        }