public static long CreateGroup(string name, bool guest, string parent, byte r, byte g, byte b, SQLiteConnector conn, string[] nodes = null, string prefix = null, string suffix = null)
        {
            long id;
            using (var bl = new SQLiteQueryBuilder(Plugin.SQLSafeName))
            {
                bl.InsertInto(TableDefinition.TableName,
                    new DataParameter(TableDefinition.ColumnNames.Name, name),
                    new DataParameter(TableDefinition.ColumnNames.ApplyToGuests, guest),
                    new DataParameter(TableDefinition.ColumnNames.Parent, parent),
                    new DataParameter(TableDefinition.ColumnNames.Chat_Red, r),
                    new DataParameter(TableDefinition.ColumnNames.Chat_Green, g),
                    new DataParameter(TableDefinition.ColumnNames.Chat_Blue, b),
                    new DataParameter(TableDefinition.ColumnNames.Chat_Prefix, prefix),
                    new DataParameter(TableDefinition.ColumnNames.Chat_Suffix, suffix)
                );

                id = ((IDataConnector)conn).ExecuteInsert(bl);
            }

            if (nodes != null)
                foreach (var nd in nodes)
                {
                    var nodeId = PermissionTable.InsertRecord(conn, nd, false);
                    GroupPermissionsTable.InsertRecord(conn, id, nodeId);
                }

            return id;
        }
Beispiel #2
0
 public void Initialise(SQLiteConnector conn)
 {
     if (!TableDefinition.Exists(conn))
     {
         ProgramLog.Admin.Log("Permission node table does not exist and will now be created");
         TableDefinition.Create(conn);
     }
 }
 public void Initialise(SQLiteConnector conn)
 {
     if (!TableDefinition.Exists(conn))
     {
         ProgramLog.Admin.Log("Permission node table does not exist and will now be created");
         TableDefinition.Create(conn);
     }
 }
 public long FindOrCreate(SQLiteConnector conn, string node, bool deny)
 {
     var existing = Find(node, deny);
     if (existing == null)
     {
         return Insert(conn, node, deny);
     }
     return existing.Value.Id;
 }
        public static bool DeleteGroup(string name, SQLiteConnector conn)
        {
            using (var bl = new SQLiteQueryBuilder(Plugin.SQLSafeName))
            {
                bl.Delete(TableDefinition.TableName, new WhereFilter(TableDefinition.ColumnNames.Name, name));

                return ((IDataConnector)conn).ExecuteNonQuery(bl) > 0;
            }
        }
            public static bool Exists(SQLiteConnector conn)
            {
                using (var bl = new SQLiteQueryBuilder(Plugin.SQLSafeName))
                {
                    bl.TableExists(TableName);

                    return ((IDataConnector)conn).Execute(bl);
                }
            }
            public static bool Create(SQLiteConnector conn)
            {
                using (var bl = new SQLiteQueryBuilder(Plugin.SQLSafeName))
                {
                    bl.TableCreate(TableName, Columns);

                    return ((IDataConnector)conn).ExecuteNonQuery(bl) > 0;
                }
            }
Beispiel #8
0
            public static bool Exists(SQLiteConnector conn)
            {
                using (var bl = new SQLiteQueryBuilder(Plugin.SQLSafeName))
                {
                    bl.TableExists(TableName);

                    return(((IDataConnector)conn).Execute(bl));
                }
            }
        public static bool DeleteGroup(string name, SQLiteConnector conn)
        {
            using (var bl = new SQLiteQueryBuilder(Plugin.SQLSafeName))
            {
                bl.Delete(TableDefinition.TableName, new WhereFilter(TableDefinition.ColumnNames.Name, name));

                return(((IDataConnector)conn).ExecuteNonQuery(bl) > 0);
            }
        }
Beispiel #10
0
            public static bool Create(SQLiteConnector conn)
            {
                using (var bl = new SQLiteQueryBuilder(Plugin.SQLSafeName))
                {
                    bl.TableCreate(TableName, Columns);

                    return(((IDataConnector)conn).ExecuteNonQuery(bl) > 0);
                }
            }
Beispiel #11
0
        public long FindOrCreate(SQLiteConnector conn, string node, bool deny)
        {
            var existing = Find(node, deny);

            if (existing == null)
            {
                return(Insert(conn, node, deny));
            }
            return(existing.Value.Id);
        }
        public static bool DeleteLink(SQLiteConnector conn, long userId, long groupId)
        {
            using (var bl = new SQLiteQueryBuilder(Plugin.SQLSafeName))
            {
                bl.Delete(TableDefinition.TableName,
                          new WhereFilter(TableDefinition.ColumnNames.UserId, userId.ToString()),
                          new WhereFilter(TableDefinition.ColumnNames.GroupId, groupId.ToString()));

                return(((IDataConnector)conn).ExecuteNonQuery(bl) > 0);
            }
        }
        public static bool DeleteLink(SQLiteConnector conn, long userId, long groupId)
        {
            using (var bl = new SQLiteQueryBuilder(Plugin.SQLSafeName))
            {
                bl.Delete(TableDefinition.TableName,
                    new WhereFilter(TableDefinition.ColumnNames.UserId, userId.ToString()),
                    new WhereFilter(TableDefinition.ColumnNames.GroupId, groupId.ToString()));

                return ((IDataConnector)conn).ExecuteNonQuery(bl) > 0;
            }
        }
        public bool Delete(SQLiteConnector conn, long userId, long groupId)
        {
            var res = DeleteLink(conn, userId, groupId);

            //Alternatively we could reload, but this shouldn't be called often
            if (res)
            {
                _data = _data.Where(x => x.UserId != userId || x.GroupId != groupId).ToArray();
            }

            return(res);
        }
        public bool Delete(string name, SQLiteConnector conn)
        {
            var res = DeleteGroup(name, conn);

            //Alternatively we could reload, but this shouldn't be called often
            if (res)
            {
                _data = _data.Where(x => x.Name != name).ToArray();
            }

            return(res);
        }
        public static long InsertRecord(SQLiteConnector conn, string node, bool deny)
        {
            using (var bl = new SQLiteQueryBuilder(Plugin.SQLSafeName))
            {
                bl.InsertInto(TableDefinition.TableName,
                    new DataParameter(TableDefinition.ColumnNames.Node, node),
                    new DataParameter(TableDefinition.ColumnNames.Deny, deny)
                );

                return ((IDataConnector)conn).ExecuteInsert(bl);
            }
        }
        public bool Delete(SQLiteConnector conn, long groupId, long permissionId)
        {
            var res = DeleteRecord(conn, groupId, permissionId);

            //Alternatively we could reload, but this shouldn't be called often
            if (res)
            {
                _data = _data.Where(x => x.GroupId != groupId || x.PermissionId != permissionId).ToArray();
            }

            return res;
        }
        public static long InsertRecord(SQLiteConnector conn, long groupId, long permissionId)
        {
            using (var bl = new SQLiteQueryBuilder(Plugin.SQLSafeName))
            {
                bl.InsertInto(TableDefinition.TableName,
                    new DataParameter(TableDefinition.ColumnNames.GroupId, groupId),
                    new DataParameter(TableDefinition.ColumnNames.PermissionId, permissionId)
                );

                return ((IDataConnector)conn).ExecuteInsert(bl);
            }
        }
        public bool Delete(SQLiteConnector conn, long userId, long groupId)
        {
            var res = DeleteLink(conn, userId, groupId);

            //Alternatively we could reload, but this shouldn't be called often
            if (res)
            {
                _data = _data.Where(x => x.UserId != userId || x.GroupId != groupId).ToArray();
            }

            return res;
        }
Beispiel #20
0
        public static long InsertRecord(SQLiteConnector conn, string node, bool deny)
        {
            using (var bl = new SQLiteQueryBuilder(Plugin.SQLSafeName))
            {
                bl.InsertInto(TableDefinition.TableName,
                              new DataParameter(TableDefinition.ColumnNames.Node, node),
                              new DataParameter(TableDefinition.ColumnNames.Deny, deny)
                              );

                return(((IDataConnector)conn).ExecuteInsert(bl));
            }
        }
Beispiel #21
0
        public static long InsertRecord(SQLiteConnector conn, long groupId, long permissionId)
        {
            using (var bl = new SQLiteQueryBuilder(Plugin.SQLSafeName))
            {
                bl.InsertInto(TableDefinition.TableName,
                              new DataParameter(TableDefinition.ColumnNames.GroupId, groupId),
                              new DataParameter(TableDefinition.ColumnNames.PermissionId, permissionId)
                              );

                return(((IDataConnector)conn).ExecuteInsert(bl));
            }
        }
Beispiel #22
0
        public bool Delete(SQLiteConnector conn, long groupId, long permissionId)
        {
            var res = DeleteRecord(conn, groupId, permissionId);

            //Alternatively we could reload, but this shouldn't be called often
            if (res)
            {
                _data = _data.Where(x => x.GroupId != groupId || x.PermissionId != permissionId).ToArray();
            }

            return(res);
        }
        void OnReadConfig(ref HookContext ctx, ref HookArgs.ConfigurationLine args)
        {
            switch (args.Key)
            {
            case "sqlite":
                if (_connector == null)
                {
                    var cn = new SQLiteConnector(args.Value);

                    cn.Open();

                    Storage.SetConnector(cn);

                    _connector = cn;
                }
                break;
            }
        }
Beispiel #24
0
        public long Insert(SQLiteConnector conn, string node, bool deny)
        {
            var id = InsertRecord(conn, node, deny);

            //Alternatively we could reload, but this shouldn't be called often
            if (id > 0L)
            {
                Array.Resize(ref _data, _data.Length + 1);
                _data[_data.Length - 1] = new PermissionNode()
                {
                    Id   = id,
                    Node = node,
                    Deny = deny
                };
            }

            return(id);
        }
        void OnReadConfig(ref HookContext ctx, ref HookArgs.ConfigurationLine args)
        {
            switch (args.Key)
            {
                case "sqlite":
                    if (_connector == null)
                    {
                        var cn = new SQLiteConnector(args.Value);

                        cn.Open();

                        Storage.SetConnector(cn);

                        _connector = cn;
                    }
                    break;
            }
        }
            public static bool Create(SQLiteConnector conn)
            {
                try
                {
                    using (var bl = new SQLiteQueryBuilder(Plugin.SQLSafeName))
                    {
                        bl.TableCreate(TableName, Columns);

                        ((IDataConnector)conn).ExecuteNonQuery(bl);
                    }

                    //Set defaults
                    var pc = CommandParser.GetAvailableCommands(AccessLevel.PLAYER);
                    var ad = CommandParser.GetAvailableCommands(AccessLevel.OP);
                    var op = CommandParser.GetAvailableCommands(AccessLevel.CONSOLE); //Funny how these have now changed

                    CreateGroup("Guest", true, null, 255, 255, 255, conn, pc
                                .Where(x => !String.IsNullOrEmpty(x.Value.Node))
                                .Select(x => x.Value.Node)
                                .Distinct()
                                .ToArray());
                    CreateGroup("Admin", false, "Guest", 240, 131, 77, conn, ad
                                .Where(x => !String.IsNullOrEmpty(x.Value.Node))
                                .Select(x => x.Value.Node)
                                .Distinct()
                                .ToArray());
                    CreateGroup("Operator", false, "Admin", 77, 166, 240, conn, op
                                .Where(x => !String.IsNullOrEmpty(x.Value.Node))
                                .Select(x => x.Value.Node)
                                .Distinct()
                                .ToArray());

                    return(true);
                }
                catch (Exception e)
                {
                    ProgramLog.Log(e);
                    return(false);
                }
            }
        public long Insert(SQLiteConnector conn, long userId, long groupId)
        {
            var id = CreateLink(conn, userId, groupId);

            //Alternatively we could reload, but this shouldn't be called often
            if (id > 0L)
            {
                if (_data == null)
                {
                    _data = new TDSM.Data.SQLite.UserGroup[0];
                }
                Array.Resize(ref _data, _data.Length + 1);
                _data[_data.Length - 1] = new TDSM.Data.SQLite.UserGroup()
                {
                    Id      = id,
                    UserId  = userId,
                    GroupId = groupId
                };
            }

            return(id);
        }
Beispiel #28
0
        public long Insert(SQLiteConnector conn, long groupId, long permissionId)
        {
            var id = InsertRecord(conn, groupId, permissionId);

            //Alternatively we could reload, but this shouldn't be called often
            if (id > 0L)
            {
                if (_data == null)
                {
                    _data = new TDSM.Data.SQLite.GroupPermission[0];
                }
                Array.Resize(ref _data, _data.Length + 1);
                _data[_data.Length - 1] = new GroupPermission()
                {
                    Id           = id,
                    GroupId      = groupId,
                    PermissionId = permissionId
                };
            }

            return(id);
        }
        public static bool UpdateGroup(string name, bool guest, string parent, byte r, byte g, byte b, SQLiteConnector conn, string prefix = null, string suffix = null)
        {
            using (var bl = new SQLiteQueryBuilder(Plugin.SQLSafeName))
            {
                bl.Update(TableDefinition.TableName, new DataParameter[]
                    {
                        new DataParameter(TableDefinition.ColumnNames.Name, name),
                        new DataParameter(TableDefinition.ColumnNames.ApplyToGuests, guest),
                        new DataParameter(TableDefinition.ColumnNames.Parent, parent),
                        new DataParameter(TableDefinition.ColumnNames.Chat_Red, r),
                        new DataParameter(TableDefinition.ColumnNames.Chat_Green, g),
                        new DataParameter(TableDefinition.ColumnNames.Chat_Blue, b),
                        new DataParameter(TableDefinition.ColumnNames.Chat_Prefix, prefix),
                        new DataParameter(TableDefinition.ColumnNames.Chat_Suffix, suffix)
                    }, new WhereFilter(TableDefinition.ColumnNames.Name, name));

                return ((IDataConnector)conn).ExecuteNonQuery(bl) > 0;
            }
        }
        public long Insert(string name, bool guest, string parent, byte r, byte g, byte b, SQLiteConnector conn, string[] nodes = null, string prefix = null, string suffix = null)
        {
            var id = CreateGroup(name, guest, parent, r, g, b, conn, nodes, prefix, suffix);

            //Alternatively we could reload, but this shouldn't be called often
            if (id > 0L)
            {
                if (_data == null)
                {
                    _data = new Group[0];
                }
                Array.Resize(ref _data, _data.Length + 1);
                _data[_data.Length - 1] = new Group()
                {
                    Id            = id,
                    Name          = name,
                    ApplyToGuests = guest,
                    Parent        = parent,
                    Chat_Red      = r,
                    Chat_Green    = g,
                    Chat_Prefix   = prefix,
                    Chat_Suffix   = suffix
                };
            }

            return(id);
        }
        public static bool UpdateGroup(string name, bool guest, string parent, byte r, byte g, byte b, SQLiteConnector conn, string prefix = null, string suffix = null)
        {
            using (var bl = new SQLiteQueryBuilder(Plugin.SQLSafeName))
            {
                bl.Update(TableDefinition.TableName, new DataParameter[]
                {
                    new DataParameter(TableDefinition.ColumnNames.Name, name),
                    new DataParameter(TableDefinition.ColumnNames.ApplyToGuests, guest),
                    new DataParameter(TableDefinition.ColumnNames.Parent, parent),
                    new DataParameter(TableDefinition.ColumnNames.Chat_Red, r),
                    new DataParameter(TableDefinition.ColumnNames.Chat_Green, g),
                    new DataParameter(TableDefinition.ColumnNames.Chat_Blue, b),
                    new DataParameter(TableDefinition.ColumnNames.Chat_Prefix, prefix),
                    new DataParameter(TableDefinition.ColumnNames.Chat_Suffix, suffix)
                }, new WhereFilter(TableDefinition.ColumnNames.Name, name));

                return(((IDataConnector)conn).ExecuteNonQuery(bl) > 0);
            }
        }
        public bool Delete(string name, SQLiteConnector conn)
        {
            var res = DeleteGroup(name, conn);

            //Alternatively we could reload, but this shouldn't be called often
            if (res)
            {
                _data = _data.Where(x => x.Name != name).ToArray();
            }

            return res;
        }
        public long Insert(string name, bool guest, string parent, byte r, byte g, byte b, SQLiteConnector conn, string[] nodes = null, string prefix = null, string suffix = null)
        {
            var id = CreateGroup(name, guest, parent, r, g, b, conn, nodes, prefix, suffix);

            //Alternatively we could reload, but this shouldn't be called often
            if (id > 0L)
            {
                if (_data == null)
                    _data = new Group[0];
                Array.Resize(ref _data, _data.Length + 1);
                _data[_data.Length - 1] = new Group()
                {
                    Id = id,
                    Name = name,
                    ApplyToGuests = guest,
                    Parent = parent,
                    Chat_Red = r,
                    Chat_Green = g,
                    Chat_Prefix = prefix,
                    Chat_Suffix = suffix
                };
            }

            return id;
        }
        public long Insert(SQLiteConnector conn, string node, bool deny)
        {
            var id = InsertRecord(conn, node, deny);

            //Alternatively we could reload, but this shouldn't be called often
            if (id > 0L)
            {
                Array.Resize(ref _data, _data.Length + 1);
                _data[_data.Length - 1] = new PermissionNode()
                {
                    Id = id,
                    Node = node,
                    Deny = deny
                };
            }

            return id;
        }
        public long Insert(SQLiteConnector conn, long groupId, long permissionId)
        {
            var id = InsertRecord(conn, groupId, permissionId);

            //Alternatively we could reload, but this shouldn't be called often
            if (id > 0L)
            {
                if (_data == null)
                    _data = new TDSM.Data.SQLite.GroupPermission[0];
                Array.Resize(ref _data, _data.Length + 1);
                _data[_data.Length - 1] = new GroupPermission()
                {
                    Id = id,
                    GroupId = groupId,
                    PermissionId = permissionId
                };
            }

            return id;
        }
            public static bool Create(SQLiteConnector conn)
            {
                try
                {
                    using (var bl = new SQLiteQueryBuilder(Plugin.SQLSafeName))
                    {
                        bl.TableCreate(TableName, Columns);

                        ((IDataConnector)conn).ExecuteNonQuery(bl);
                    }

                    //Set defaults
                    var pc = CommandParser.GetAvailableCommands(AccessLevel.PLAYER);
                    var ad = CommandParser.GetAvailableCommands(AccessLevel.OP);
                    var op = CommandParser.GetAvailableCommands(AccessLevel.CONSOLE); //Funny how these have now changed

                    CreateGroup("Guest", true, null, 255, 255, 255, conn, pc
                        .Where(x => !String.IsNullOrEmpty(x.Value.Node))
                        .Select(x => x.Value.Node)
                        .Distinct()
                        .ToArray());
                    CreateGroup("Admin", false, "Guest", 240, 131, 77, conn, ad
                        .Where(x => !String.IsNullOrEmpty(x.Value.Node))
                        .Select(x => x.Value.Node)
                        .Distinct()
                        .ToArray());
                    CreateGroup("Operator", false, "Admin", 77, 166, 240, conn, op
                        .Where(x => !String.IsNullOrEmpty(x.Value.Node))
                        .Select(x => x.Value.Node)
                        .Distinct()
                        .ToArray());

                    return true;
                }
                catch (Exception e)
                {
                    ProgramLog.Log(e);
                    return false;
                }
            }
        public static long CreateGroup(string name, bool guest, string parent, byte r, byte g, byte b, SQLiteConnector conn, string[] nodes = null, string prefix = null, string suffix = null)
        {
            long id;

            using (var bl = new SQLiteQueryBuilder(Plugin.SQLSafeName))
            {
                bl.InsertInto(TableDefinition.TableName,
                              new DataParameter(TableDefinition.ColumnNames.Name, name),
                              new DataParameter(TableDefinition.ColumnNames.ApplyToGuests, guest),
                              new DataParameter(TableDefinition.ColumnNames.Parent, parent),
                              new DataParameter(TableDefinition.ColumnNames.Chat_Red, r),
                              new DataParameter(TableDefinition.ColumnNames.Chat_Green, g),
                              new DataParameter(TableDefinition.ColumnNames.Chat_Blue, b),
                              new DataParameter(TableDefinition.ColumnNames.Chat_Prefix, prefix),
                              new DataParameter(TableDefinition.ColumnNames.Chat_Suffix, suffix)
                              );

                id = ((IDataConnector)conn).ExecuteInsert(bl);
            }

            if (nodes != null)
            {
                foreach (var nd in nodes)
                {
                    var nodeId = PermissionTable.InsertRecord(conn, nd, false);
                    GroupPermissionsTable.InsertRecord(conn, id, nodeId);
                }
            }

            return(id);
        }
        public long Insert(SQLiteConnector conn, long userId, long groupId)
        {
            var id = CreateLink(conn, userId, groupId);

            //Alternatively we could reload, but this shouldn't be called often
            if (id > 0L)
            {
                if (_data == null)
                    _data = new TDSM.Data.SQLite.UserGroup[0];
                Array.Resize(ref _data, _data.Length + 1);
                _data[_data.Length - 1] = new TDSM.Data.SQLite.UserGroup()
                {
                    Id = id,
                    UserId = userId,
                    GroupId = groupId
                };
            }

            return id;
        }